From 964b45eea8de92544f815ec0334acf29af55ea23 Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Wed, 10 Oct 2018 17:16:55 -0500 Subject: [PATCH] Checkpoint in creating ObjectPlot constructor. --- include/openmc/plot.h | 6 +- src/plot.cpp | 253 +++++++++++++++++++++++++++++++++++++++++- 2 files changed, 257 insertions(+), 2 deletions(-) diff --git a/include/openmc/plot.h b/include/openmc/plot.h index acc364812..a279dc9c0 100644 --- a/include/openmc/plot.h +++ b/include/openmc/plot.h @@ -8,6 +8,7 @@ #include "position.h" #include "openmc/constants.h" #include "openmc/particle.h" +#include "openmc/xml_interface.h" namespace openmc { @@ -19,7 +20,7 @@ namespace openmc { std::map plot_dict; - std::vector n_plots; + int n_plots; std::vector plots; @@ -52,6 +53,9 @@ namespace openmc { //=============================================================================== struct ObjectPlot { + + ObjectPlot(pugi::xml_node plot); + int id; int type; int color_by; diff --git a/src/plot.cpp b/src/plot.cpp index a1acebfe6..240697f0e 100644 --- a/src/plot.cpp +++ b/src/plot.cpp @@ -12,6 +12,7 @@ #include "openmc/mesh.h" #include "openmc/output.h" #include "openmc/hdf5_interface.h" +#include "openmc/random_lcg.h" namespace openmc { @@ -29,7 +30,7 @@ const int NULLRGB[3] = {0, 0, 0}; int openmc_plot_geometry() { int err; - for (auto i : n_plots) { + for(int i = 0; i < n_plots; i++) { ObjectPlot* pl = plots[i]; std::stringstream ss; @@ -51,6 +52,18 @@ int openmc_plot_geometry() { return 0; } +void read_plots(pugi::xml_node plots_node) { + + std::vector plot_nodes; + plot_nodes = get_child_nodes(plots_node, "plot"); + + n_plots = plot_nodes.size(); + + for(auto plot : plot_nodes) { + // ObjectPlot* pl = new ObjectPlot(plot); + } +} + //=============================================================================== // CREATE_PPM creates an image based on user input from a plots.xml // specification in the portable pixmap format (PPM) @@ -126,6 +139,244 @@ void create_ppm(ObjectPlot* pl) { } +ObjectPlot::ObjectPlot(pugi::xml_node plot_node) { + + // Copy data into plots + if (check_for_node(plot_node, "id")) { + id = std::stoi(get_node_value(plot_node, "id")); + } else { + fatal_error("Must specify plot id in plots XML file."); + } + + // Check to make sure 'id' hasn't been used + if (plot_dict.find(id) != plot_dict.end()) { + std::stringstream err_msg; + err_msg << "Two or more plots use the same unique ID: "; + err_msg << id; + fatal_error(err_msg.str()); + } + + // Copy plot type + // Default is slice + std::string type_str = "slice"; + if (check_for_node(plot_node, "type")) { + type_str = get_node_value(plot_node, "type"); + to_lower(type_str); + if (type_str == "slice") { + type = PLOT_TYPE::SLICE; + } + else if (type_str == "voxel") { + type = PLOT_TYPE::VOXEL; + } else { + std::stringstream err_msg; + err_msg << "Unsupported plot type '" << type_str + << "' in plot " << id; + fatal_error(err_msg.str()); + } + } + + // Set output file path + std::stringstream filename; + filename << "plot_" << id; + + if (check_for_node(plot_node, "filename")) { + switch(type) { + case PLOT_TYPE::SLICE: + filename << ".ppm"; + break; + case PLOT_TYPE::VOXEL: + filename << ".h5"; + break; + } + } + + // Copy plot pixel size + std::vector pxls; + if (PLOT_TYPE::SLICE == type) { + if (node_word_count(plot_node, "pixels") == 2) { + pxls = get_node_array(plot_node, "pixels"); + pixels[0] = pxls[0]; + pixels[1] = pxls[1]; + } else { + std::stringstream err_msg; + err_msg << " must be length 2 in slice plot " + << id; + fatal_error(err_msg.str()); + } + } else if (PLOT_TYPE::VOXEL == type) { + if (node_word_count(plot_node, "pixels") == 3) { + pxls = get_node_array(plot_node, "pixels"); + pixels[0] = pxls[0]; + pixels[1] = pxls[1]; + pixels[2] = pxls[2]; + } else { + std::stringstream err_msg; + err_msg << " must be length 3 in voxel plot " + << id; + fatal_error(err_msg.str()); + } + } + + // Copy plot background color + std::vector bg_rgb; + if (check_for_node(plot_node, "background")) { + if (PLOT_TYPE::VOXEL == type) { + if (openmc_master) { + std::stringstream err_msg; + err_msg << "Background color ignored in voxel plot " + << id; + warning(err_msg.str()); + } + } + if (node_word_count(plot_node, "background") == 3) { + bg_rgb = get_node_array(plot_node, "background"); + not_found.rgb[0] = bg_rgb[0]; + not_found.rgb[1] = bg_rgb[1]; + not_found.rgb[2] = bg_rgb[2]; + } else { + std::stringstream err_msg; + err_msg << "Bad background RGB in plot " + << id; + fatal_error(err_msg); + } + } else { + // default to a white background + not_found.rgb[0] = 255; + not_found.rgb[1] = 255; + not_found.rgb[2] = 255; + } + + // Copy plot basis + if (PLOT_TYPE::SLICE == type) { + std::string pl_basis = "xy"; + if (check_for_node(plot_node, "basis")) { + pl_basis = get_node_value(plot_node, "basis"); + } + to_lower(pl_basis); + if ("xy" == pl_basis) { + basis = PLOT_BASIS::XY; + } else if ("xz" == pl_basis) { + basis = PLOT_BASIS::XZ; + } else if ("yz" == pl_basis) { + basis = PLOT_BASIS::YZ; + } else { + std::stringstream err_msg; + err_msg << "Unsupported plot basis '" << pl_basis + << "' in plot " << id; + fatal_error(err_msg); + } + } + + // Copy plotting origin + std::vector pl_origin; + if (node_word_count(plot_node, "origin") == 3) { + pl_origin = get_node_array(plot_node, "origin"); + origin[0] = pl_origin[0]; + origin[1] = pl_origin[1]; + origin[2] = pl_origin[2]; + } else { + std::stringstream err_msg; + err_msg << "Origin must be length 3 in plot " + << id; + fatal_error(err_msg); + } + + // Copy plotting width + std::vector pl_width; + if (PLOT_TYPE::SLICE == type) { + if (node_word_count(plot_node, "width") == 2) { + pl_width = get_node_array(plot_node, "width"); + width[0] = pl_width[0]; + width[1] = pl_width[1]; + } else { + std::stringstream err_msg; + err_msg << " must be length 2 in slice plot " + << id; + fatal_error(err_msg); + } + } else if (PLOT_TYPE::VOXEL == type) { + if (node_word_count(plot_node, "width") == 3) { + pl_width = get_node_array(plot_node, "width"); + width[0] = pl_width[0]; + width[1] = pl_width[1]; + width[2] = pl_width[2]; + } else { + std::stringstream err_msg; + err_msg << " must be length 3 in voxel plot " + << id; + fatal_error(err_msg); + } + } + + // Copy plot universe level + if (check_for_node(plot_node, "level")) { + level = std::stoi(get_node_value(plot_node, "level")); + if (level < 0) { + std::stringstream err_msg; + err_msg << "Bad universe level in plot " << id ; + fatal_error(err_msg); + } + } else { + level = PLOT_LEVEL_LOWEST; + } + + // Copy plot color type and initialize all colors randomly + std::string pl_color_by = "cell"; + if (check_for_node(plot_node, "color_by")) { + pl_color_by = get_node_value(plot_node, "color_by"); + to_lower(pl_color_by); + } + if ("cell" == pl_color_by) { + color_by = PLOT_COLOR_BY::CELLS; + + // colors.resize(n_cells); + for(int i = 0; i < n_cells; i++) { + colors[i].rgb[0] = int(prn()*255); + colors[i].rgb[1] = int(prn()*255); + colors[i].rgb[2] = int(prn()*255); + } + + } else if("material" == pl_color_by) { + + color_by = PLOT_COLOR_BY::MATS; + + // colors.resize(materials.size()); + for(int i = 0; i < n_cells; i++) { + colors[i].rgb[0] = int(prn()*255); + colors[i].rgb[1] = int(prn()*255); + colors[i].rgb[2] = int(prn()*255); + } + } else { + std::stringstream err_msg; + err_msg << "Unsupported plot color type '" << pl_color_by + << "' in plot " << id; + fatal_error(err_msg); + } + + // Get the number of nodes and get a list of them + std::vector color_nodes; + color_nodes = get_child_nodes(plot_node, "color"); + + // Copy user-specified colors + if (0 != color_nodes.size()) { + + if (PLOT_TYPE::VOXEL == type) { + if (openmc_master) { + std::stringstream err_msg; + err_msg << "Color specifications ignored in voxel plot " + << id; + warning(err_msg); + } + } + + for(auto cn : color_nodes) { + + } + + } + +} // End ObjectPlot constructor + //=============================================================================== // POSITION_RGB computes the red/green/blue values for a given plot with the // current particle's position