From 0dde9ce202d54e127f1c4c3112269f8cab36973e Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Thu, 4 Oct 2018 08:58:55 -0500 Subject: [PATCH 001/105] Move plot header attributes/types to C++. --- include/openmc/plot.h | 55 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 54 insertions(+), 1 deletion(-) diff --git a/include/openmc/plot.h b/include/openmc/plot.h index 2048189f7..1e5c9616f 100644 --- a/include/openmc/plot.h +++ b/include/openmc/plot.h @@ -2,14 +2,67 @@ #define OPENMC_PLOT_H #include "hdf5.h" +#include "position.h" +#include namespace openmc { + int PLOT_LEVEL_LOWEST = -1; + + std::map plot_dict; + + enum PLOT_TYPE { + SLICE = 1, + VOXEL = 2 + }; + + enum PLOT_BASIS { + XY = 1, + XZ = 2, + YZ = 3 + }; + + enum PLOT_COLOR_BY { + CELLS = 1, + MATS = 2 + }; + +//=============================================================================== +// ObjectColor holds color information for plotted objects +//=============================================================================== + + class ObjectColor { + int rgb_[3]; + }; + +//=============================================================================== +// ObjectPlot holds plot information +//=============================================================================== + + class ObjectPlot { + + int id_; + std::string path_plot_; + int type_; + int color_by_; + Position origin_; + Position width_; + int basis_; + int pixels_[3]; + int meshlines_width_; + int level_; + int index_meshlines_mesh_; + ObjectColor meshlines_color_; + ObjectColor not_found_; + std::vector colors_; + + }; + extern "C" void voxel_init(hid_t file_id, const hsize_t* dims, hid_t* dspace, hid_t* dset, hid_t* memspace); extern "C" void voxel_write_slice(int x, hid_t dspace, hid_t dset, hid_t memspace, void* buf); extern "C" void voxel_finalize(hid_t dspace, hid_t dset, hid_t memspace); - + } // namespace openmc #endif // OPENMC_PLOT_H From cc257b7554bff46aee51988f70e03ad3546c6bb9 Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Sun, 7 Oct 2018 19:35:37 -0500 Subject: [PATCH 002/105] Moving remaining variables/attributes into plot header. --- include/openmc/plot.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/include/openmc/plot.h b/include/openmc/plot.h index 1e5c9616f..128374779 100644 --- a/include/openmc/plot.h +++ b/include/openmc/plot.h @@ -7,10 +7,16 @@ namespace openmc { + class ObjectPlot; + int PLOT_LEVEL_LOWEST = -1; std::map plot_dict; + std::vector n_plots; + + std::vector plots; + enum PLOT_TYPE { SLICE = 1, VOXEL = 2 From 7637db6774350c466fb83bb74b97edea0f995dbc Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Sun, 7 Oct 2018 19:55:45 -0500 Subject: [PATCH 003/105] Adding a skeleton function for plotting. --- include/openmc/plot.h | 4 +++- src/plot.cpp | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/include/openmc/plot.h b/include/openmc/plot.h index 128374779..67f1cc092 100644 --- a/include/openmc/plot.h +++ b/include/openmc/plot.h @@ -4,6 +4,7 @@ #include "hdf5.h" #include "position.h" #include +#include namespace openmc { @@ -38,6 +39,7 @@ namespace openmc { //=============================================================================== class ObjectColor { + public: int rgb_[3]; }; @@ -46,7 +48,7 @@ namespace openmc { //=============================================================================== class ObjectPlot { - + public: int id_; std::string path_plot_; int type_; diff --git a/src/plot.cpp b/src/plot.cpp index 79f04c47f..925fbea05 100644 --- a/src/plot.cpp +++ b/src/plot.cpp @@ -1,7 +1,40 @@ #include "openmc/plot.h" +#include "openmc/constants.h" +#include "openmc/settings.h" +#include "openmc/error.h" namespace openmc { +const int RED = 1; +const int GREEN = 2; +const int BLUE = 3; + + int openmc_plot_geometry() { + int err; + + for(auto i : n_plots) { + ObjectPlot* pl = plots[i]; + + std::stringstream ss; + ss << "Processing plot " << pl->id_ << ": " + << pl->path_plot_ << "..."; + write_message(ss.str(), 5); + + if (pl->type_ == PLOT_TYPE::SLICE) { + // create 2D image + // create_ppm(pl); + continue; + } else if (pl->type_ == PLOT_TYPE::VOXEL) { + // create voxel file for 3D viewing + // create_voxel(pl); + continue; + } + + } + + return 0; + } + void voxel_init(hid_t file_id, const hsize_t* dims, hid_t* dspace, hid_t* dset, hid_t* memspace) From 2f8e5a4c9dbe29c18b60507f6781d6996e158178 Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Mon, 8 Oct 2018 13:34:23 -0500 Subject: [PATCH 004/105] Adding skeleton for create_ppm. --- include/openmc/constants.h | 5 +- src/plot.cpp | 101 ++++++++++++++++++++++++++++++++----- 2 files changed, 92 insertions(+), 14 deletions(-) diff --git a/include/openmc/constants.h b/include/openmc/constants.h index d249e4cb5..c2b52b25a 100644 --- a/include/openmc/constants.h +++ b/include/openmc/constants.h @@ -82,7 +82,10 @@ constexpr double EXTSRC_REJECT_FRACTION {0.05}; constexpr double PI {3.1415926535898}; const double SQRT_PI {std::sqrt(PI)}; constexpr double INFTY {std::numeric_limits::max()}; - +constexpr double TWO {2.0}; +constexpr double HALF {0.5}; + + // Physical constants constexpr double MASS_NEUTRON {1.00866491588}; // mass of a neutron in amu constexpr double MASS_NEUTRON_EV {939.5654133e6}; // mass of a neutron in eV/c^2 diff --git a/src/plot.cpp b/src/plot.cpp index 925fbea05..bb4f1f756 100644 --- a/src/plot.cpp +++ b/src/plot.cpp @@ -2,6 +2,8 @@ #include "openmc/constants.h" #include "openmc/settings.h" #include "openmc/error.h" +#include "openmc/particle.h" +#include "openmc/geometry.h" namespace openmc { @@ -9,17 +11,21 @@ const int RED = 1; const int GREEN = 2; const int BLUE = 3; - int openmc_plot_geometry() { - int err; +//=============================================================================== +// RUN_PLOT controls the logic for making one or many plots +//=============================================================================== + +int openmc_plot_geometry() { + int err; - for(auto i : n_plots) { - ObjectPlot* pl = plots[i]; - - std::stringstream ss; - ss << "Processing plot " << pl->id_ << ": " - << pl->path_plot_ << "..."; + for(auto i : n_plots) { + ObjectPlot* pl = plots[i]; + + std::stringstream ss; + ss << "Processing plot " << pl->id_ << ": " + << pl->path_plot_ << "..."; write_message(ss.str(), 5); - + if (pl->type_ == PLOT_TYPE::SLICE) { // create 2D image // create_ppm(pl); @@ -30,11 +36,80 @@ const int BLUE = 3; continue; } - } - - return 0; } - + + return 0; +} + +//=============================================================================== +// CREATE_PPM creates an image based on user input from a plots.xml +// specification in the portable pixmap format (PPM) +//=============================================================================== + +void create_ppm(ObjectPlot* pl) { + + int width = pl->pixels_[0]; + int height = pl->pixels_[1]; + + double in_pixel = (pl->width_[0])/double(width); + double out_pixel = (pl->width_[1])/double(height); + + std::vector< std::vector< std::vector>> data; + + data.resize(width); + for (auto i : data) { + i.resize(height); + for (auto j : i) { j.resize(3); } + } + + int in_i, out_i; + double xyz[3]; + if (pl->basis_ == PLOT_BASIS::XY) { + in_i = 0; + out_i = 1; + xyz[0] = pl->origin_[0] - pl->width_[0] / TWO; + xyz[1] = pl->origin_[1] - pl->width_[1] / TWO; + xyz[2] = pl->origin_[2]; + } else if (pl->basis_ == PLOT_BASIS::XZ) { + in_i = 0; + out_i = 2; + xyz[0] = pl->origin_[0] - pl->width_[0] / TWO; + xyz[1] = pl->origin_[1]; + xyz[2] = pl->origin_[2] - pl->width_[1] / TWO; + } else if (pl->basis_ == PLOT_BASIS::YZ) { + in_i = 1; + out_i = 2; + xyz[0] = pl->origin_[0]; + xyz[1] = pl->origin_[1] - pl->width_[0] / TWO; + xyz[2] = pl->origin_[2] - pl->width_[1] / TWO; + } + + double dir[3]; + Particle *p = new Particle(); + p->initialize(); + std::copy(xyz, xyz+3, p->coord[0].xyz); + std::copy(dir, dir+3, p->coord[0].uvw); + p->coord[0].universe = openmc_root_universe; + + // local variables + int rgb[3]; + int id; + for(int y = 0; y < height; y++) { + p->coord[0].xyz[out_i] = xyz[out_i] - out_pixel*(y); + for(int x = 0; x < width; x++) { + p->coord[0].xyz[in_i] = xyz[in_i] + in_pixel*(x); + // position_rgb(p, pl, rgb, id); + + std::copy(rgb, rgb+3, &(data[x][y][0])); + } + } + + //output_ppm(pl, data); + +} + + + void voxel_init(hid_t file_id, const hsize_t* dims, hid_t* dspace, hid_t* dset, hid_t* memspace) From 964afd6b8e80941384d61a04577aac76d8437810 Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Mon, 8 Oct 2018 14:05:38 -0500 Subject: [PATCH 005/105] Adding position_rgb function. --- src/plot.cpp | 69 +++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 66 insertions(+), 3 deletions(-) diff --git a/src/plot.cpp b/src/plot.cpp index bb4f1f756..7b4a03590 100644 --- a/src/plot.cpp +++ b/src/plot.cpp @@ -4,6 +4,8 @@ #include "openmc/error.h" #include "openmc/particle.h" #include "openmc/geometry.h" +#include "openmc/cell.h" +#include "openmc/material.h" namespace openmc { @@ -11,6 +13,9 @@ const int RED = 1; const int GREEN = 2; const int BLUE = 3; +const int WHITE[3] = {255, 255, 255}; +const int NULLRGB[3] = {0, 0, 0}; + //=============================================================================== // RUN_PLOT controls the logic for making one or many plots //=============================================================================== @@ -28,7 +33,7 @@ int openmc_plot_geometry() { if (pl->type_ == PLOT_TYPE::SLICE) { // create 2D image - // create_ppm(pl); + create_ppm(pl); continue; } else if (pl->type_ == PLOT_TYPE::VOXEL) { // create voxel file for 3D viewing @@ -108,8 +113,66 @@ void create_ppm(ObjectPlot* pl) { } - - +//=============================================================================== +// POSITION_RGB computes the red/green/blue values for a given plot with the +// current particle's position +//=============================================================================== + +void position_rgb(Particle* p, ObjectPlot* pl, int rgb[3], int &id) { + bool found_cell; + + p->n_coord = 1; + + found_cell = find_cell(p, 0); + + int j = p->n_coord - 1; + + if (settings::check_overlaps) { check_cell_overlap(p); } + + // Set coordinate level if specified + if (pl->level_ >= 0) j = pl->level_ + 1; + + Cell* c; + + if (!found_cell) { + // If no cell, revert to default color + rgb = pl->not_found_.rgb_; + id = -1; + } else { + if (pl->color_by_ = PLOT_COLOR_BY::MATS) { + // Assign color based on material + c = cells[p->coord[j].cell]; + if (c->type_ == FILL_UNIVERSE) { + // If we stopped on a middle universe level, treat as if not found + rgb = pl->not_found_.rgb_; + id = -1; + } else if (p->material == MATERIAL_VOID) { + // By default, color void cells white + std::copy(WHITE, WHITE+3, rgb); + id = -1; + } else { + std::copy(pl->colors_[p->material].rgb_, + pl->colors_[p->material].rgb_ + 3, + rgb); + id = materials[p->material]->id; + } + + } else if (pl->color_by_ == PLOT_COLOR_BY::CELLS) { + // Assign color based on cell + std::copy(pl->colors_[p->coord[j].cell].rgb_, + pl->colors_[p->coord[j].cell].rgb_ + 3, + rgb); + id = cells[p->coord[j].cell]->id_; + } else { + std::copy(NULLRGB, NULLRGB+3, rgb); + id = -1; + } + + + } // endif found_cell + +} + void voxel_init(hid_t file_id, const hsize_t* dims, hid_t* dspace, hid_t* dset, hid_t* memspace) From 9d7ce59d823750213afca36947a34b56e4de592c Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Mon, 8 Oct 2018 20:16:13 -0500 Subject: [PATCH 006/105] Commenting create_ppm for now. --- src/plot.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plot.cpp b/src/plot.cpp index 7b4a03590..4139134a4 100644 --- a/src/plot.cpp +++ b/src/plot.cpp @@ -33,7 +33,7 @@ int openmc_plot_geometry() { if (pl->type_ == PLOT_TYPE::SLICE) { // create 2D image - create_ppm(pl); + // create_ppm(pl); continue; } else if (pl->type_ == PLOT_TYPE::VOXEL) { // create voxel file for 3D viewing From 7ec50db8f2e663be292426b5bfebb255c111b89b Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Tue, 9 Oct 2018 09:11:15 -0500 Subject: [PATCH 007/105] Removing underscores from ObjectPlot and ObjectColor classes for now. --- include/openmc/plot.h | 30 +++++++++++----------- src/plot.cpp | 59 +++++++++++++++++++++---------------------- 2 files changed, 44 insertions(+), 45 deletions(-) diff --git a/include/openmc/plot.h b/include/openmc/plot.h index 67f1cc092..8dcc9a940 100644 --- a/include/openmc/plot.h +++ b/include/openmc/plot.h @@ -40,7 +40,7 @@ namespace openmc { class ObjectColor { public: - int rgb_[3]; + int rgb[3]; }; //=============================================================================== @@ -49,20 +49,20 @@ namespace openmc { class ObjectPlot { public: - int id_; - std::string path_plot_; - int type_; - int color_by_; - Position origin_; - Position width_; - int basis_; - int pixels_[3]; - int meshlines_width_; - int level_; - int index_meshlines_mesh_; - ObjectColor meshlines_color_; - ObjectColor not_found_; - std::vector colors_; + int id; + std::string path_plot; + int type; + int color_by; + Position origin; + Position width; + int basis; + int pixels[3]; + int meshlines_width; + int level; + int index_meshlines_mesh; + ObjectColor meshlines_color; + ObjectColor not_found; + std::vector colors; }; diff --git a/src/plot.cpp b/src/plot.cpp index 4139134a4..0af83f154 100644 --- a/src/plot.cpp +++ b/src/plot.cpp @@ -27,15 +27,15 @@ int openmc_plot_geometry() { ObjectPlot* pl = plots[i]; std::stringstream ss; - ss << "Processing plot " << pl->id_ << ": " - << pl->path_plot_ << "..."; + ss << "Processing plot " << pl->id << ": " + << pl->path_plot << "..."; write_message(ss.str(), 5); - if (pl->type_ == PLOT_TYPE::SLICE) { + if (pl->type == PLOT_TYPE::SLICE) { // create 2D image // create_ppm(pl); continue; - } else if (pl->type_ == PLOT_TYPE::VOXEL) { + } else if (pl->type == PLOT_TYPE::VOXEL) { // create voxel file for 3D viewing // create_voxel(pl); continue; @@ -53,11 +53,11 @@ int openmc_plot_geometry() { void create_ppm(ObjectPlot* pl) { - int width = pl->pixels_[0]; - int height = pl->pixels_[1]; + int width = pl->pixels[0]; + int height = pl->pixels[1]; - double in_pixel = (pl->width_[0])/double(width); - double out_pixel = (pl->width_[1])/double(height); + double in_pixel = (pl->width[0])/double(width); + double out_pixel = (pl->width[1])/double(height); std::vector< std::vector< std::vector>> data; @@ -69,24 +69,24 @@ void create_ppm(ObjectPlot* pl) { int in_i, out_i; double xyz[3]; - if (pl->basis_ == PLOT_BASIS::XY) { + if (pl->basis == PLOT_BASIS::XY) { in_i = 0; out_i = 1; - xyz[0] = pl->origin_[0] - pl->width_[0] / TWO; - xyz[1] = pl->origin_[1] - pl->width_[1] / TWO; - xyz[2] = pl->origin_[2]; - } else if (pl->basis_ == PLOT_BASIS::XZ) { + xyz[0] = pl->origin[0] - pl->width[0] / TWO; + xyz[1] = pl->origin[1] - pl->width[1] / TWO; + xyz[2] = pl->origin[2]; + } else if (pl->basis == PLOT_BASIS::XZ) { in_i = 0; out_i = 2; - xyz[0] = pl->origin_[0] - pl->width_[0] / TWO; - xyz[1] = pl->origin_[1]; - xyz[2] = pl->origin_[2] - pl->width_[1] / TWO; - } else if (pl->basis_ == PLOT_BASIS::YZ) { + xyz[0] = pl->origin[0] - pl->width[0] / TWO; + xyz[1] = pl->origin[1]; + xyz[2] = pl->origin[2] - pl->width[1] / TWO; + } else if (pl->basis == PLOT_BASIS::YZ) { in_i = 1; out_i = 2; - xyz[0] = pl->origin_[0]; - xyz[1] = pl->origin_[1] - pl->width_[0] / TWO; - xyz[2] = pl->origin_[2] - pl->width_[1] / TWO; + xyz[0] = pl->origin[0]; + xyz[1] = pl->origin[1] - pl->width[0] / TWO; + xyz[2] = pl->origin[2] - pl->width[1] / TWO; } double dir[3]; @@ -130,37 +130,37 @@ void position_rgb(Particle* p, ObjectPlot* pl, int rgb[3], int &id) { if (settings::check_overlaps) { check_cell_overlap(p); } // Set coordinate level if specified - if (pl->level_ >= 0) j = pl->level_ + 1; + if (pl->level >= 0) j = pl->level + 1; Cell* c; if (!found_cell) { // If no cell, revert to default color - rgb = pl->not_found_.rgb_; + rgb = pl->not_found.rgb; id = -1; } else { - if (pl->color_by_ = PLOT_COLOR_BY::MATS) { + if (pl->color_by = PLOT_COLOR_BY::MATS) { // Assign color based on material c = cells[p->coord[j].cell]; if (c->type_ == FILL_UNIVERSE) { // If we stopped on a middle universe level, treat as if not found - rgb = pl->not_found_.rgb_; + rgb = pl->not_found.rgb; id = -1; } else if (p->material == MATERIAL_VOID) { // By default, color void cells white std::copy(WHITE, WHITE+3, rgb); id = -1; } else { - std::copy(pl->colors_[p->material].rgb_, - pl->colors_[p->material].rgb_ + 3, + std::copy(pl->colors[p->material].rgb, + pl->colors[p->material].rgb + 3, rgb); id = materials[p->material]->id; } - } else if (pl->color_by_ == PLOT_COLOR_BY::CELLS) { + } else if (pl->color_by == PLOT_COLOR_BY::CELLS) { // Assign color based on cell - std::copy(pl->colors_[p->coord[j].cell].rgb_, - pl->colors_[p->coord[j].cell].rgb_ + 3, + std::copy(pl->colors[p->coord[j].cell].rgb, + pl->colors[p->coord[j].cell].rgb + 3, rgb); id = cells[p->coord[j].cell]->id_; } else { @@ -168,7 +168,6 @@ void position_rgb(Particle* p, ObjectPlot* pl, int rgb[3], int &id) { id = -1; } - } // endif found_cell } From cb9e400074cacc64318410b36441837dde525b3c Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Tue, 9 Oct 2018 09:35:55 -0500 Subject: [PATCH 008/105] Binding C and F90 ObjectPlots. --- include/openmc/plot.h | 10 ++++++---- src/input_xml.F90 | 4 ++-- src/plot_header.F90 | 34 +++++++++++++++++----------------- 3 files changed, 25 insertions(+), 23 deletions(-) diff --git a/include/openmc/plot.h b/include/openmc/plot.h index 8dcc9a940..27b68b7b4 100644 --- a/include/openmc/plot.h +++ b/include/openmc/plot.h @@ -1,11 +1,13 @@ #ifndef OPENMC_PLOT_H #define OPENMC_PLOT_H -#include "hdf5.h" -#include "position.h" #include #include +#include "hdf5.h" +#include "position.h" +#include "openmc/constants.h" + namespace openmc { class ObjectPlot; @@ -50,7 +52,6 @@ namespace openmc { class ObjectPlot { public: int id; - std::string path_plot; int type; int color_by; Position origin; @@ -62,7 +63,8 @@ namespace openmc { int index_meshlines_mesh; ObjectColor meshlines_color; ObjectColor not_found; - std::vector colors; + ObjectColor colors[MAX_COORD]; + char path_plot[MAX_WORD_LEN]; }; diff --git a/src/input_xml.F90 b/src/input_xml.F90 index 466bff9e7..54c0538c9 100644 --- a/src/input_xml.F90 +++ b/src/input_xml.F90 @@ -2216,7 +2216,7 @@ contains case ("cell") pl % color_by = PLOT_COLOR_CELLS - allocate(pl % colors(n_cells)) + ! allocate(pl % colors(n_cells)) do j = 1, n_cells pl % colors(j) % rgb(1) = int(prn()*255) pl % colors(j) % rgb(2) = int(prn()*255) @@ -2226,7 +2226,7 @@ contains case ("material") pl % color_by = PLOT_COLOR_MATS - allocate(pl % colors(n_materials)) + ! allocate(pl % colors(n_materials)) do j = 1, n_materials pl % colors(j) % rgb(1) = int(prn()*255) pl % colors(j) % rgb(2) = int(prn()*255) diff --git a/src/plot_header.F90 b/src/plot_header.F90 index 761481b33..e4b9c7feb 100644 --- a/src/plot_header.F90 +++ b/src/plot_header.F90 @@ -11,29 +11,29 @@ module plot_header ! ObjectColor holds color information for plotted objects !=============================================================================== - type ObjectColor - integer :: rgb(3) + type, bind(C) :: ObjectColor + integer(C_INT) :: rgb(3) end type ObjectColor !=============================================================================== ! PLOTSLICE holds plot information !=============================================================================== - type ObjectPlot - integer :: id ! Unique ID - character(MAX_LINE_LEN) :: path_plot ! path for plot file - integer :: type ! Type - integer :: color_by ! quantity to color regions by - real(8) :: origin(3) ! xyz center of plot location - real(8) :: width(3) ! xyz widths of plot - integer :: basis ! direction of plot slice - integer :: pixels(3) ! pixel width/height of plot slice - integer :: meshlines_width ! pixel width of meshlines - integer :: level ! universe depth to plot the cells of - integer :: index_meshlines_mesh = -1 ! index of mesh to plot - type(ObjectColor) :: meshlines_color ! Color for meshlines - type(ObjectColor) :: not_found ! color for positions where no cell found - type(ObjectColor), allocatable :: colors(:) ! colors of cells/mats + type, bind(C) :: ObjectPlot + integer(C_INT) :: id ! Unique ID + integer(C_INT) :: type ! Type + integer(C_INT) :: color_by ! quantity to color regions by + real(C_DOUBLE) :: origin(3) ! xyz center of plot location + real(C_DOUBLE) :: width(3) ! xyz widths of plot + integer(C_INT) :: basis ! direction of plot slice + integer(C_INT) :: pixels(3) ! pixel width/height of plot slice + integer(C_INT) :: meshlines_width ! pixel width of meshlines + integer(C_INT) :: level ! universe depth to plot the cells of + integer(C_INT) :: index_meshlines_mesh = -1 ! index of mesh to plot + type(ObjectColor) :: meshlines_color ! Color for meshlines + type(ObjectColor) :: not_found ! color for positions where no cell found + type(ObjectColor) :: colors(MAX_COORD) ! colors of cells/mats + character(MAX_WORD_LEN) :: path_plot ! path for plot file end type ObjectPlot ! Plot type From 075473b475d0acdee10133abecebae73b9634508 Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Tue, 9 Oct 2018 09:46:00 -0500 Subject: [PATCH 009/105] Replacing position_rgb with C-side implementation. --- include/openmc/plot.h | 5 ++- src/plot.F90 | 98 ++++++++++++++++++++++++------------------- 2 files changed, 58 insertions(+), 45 deletions(-) diff --git a/include/openmc/plot.h b/include/openmc/plot.h index 27b68b7b4..92b8d89b3 100644 --- a/include/openmc/plot.h +++ b/include/openmc/plot.h @@ -7,6 +7,7 @@ #include "hdf5.h" #include "position.h" #include "openmc/constants.h" +#include "openmc/particle.h" namespace openmc { @@ -67,7 +68,9 @@ namespace openmc { char path_plot[MAX_WORD_LEN]; }; - + +extern "C" void position_rgb(Particle* p, ObjectPlot* pl, int rgb[3], int &id); + extern "C" void voxel_init(hid_t file_id, const hsize_t* dims, hid_t* dspace, hid_t* dset, hid_t* memspace); extern "C" void voxel_write_slice(int x, hid_t dspace, hid_t dset, diff --git a/src/plot.F90 b/src/plot.F90 index bfc8bc225..d2ebab166 100644 --- a/src/plot.F90 +++ b/src/plot.F90 @@ -25,6 +25,16 @@ module plot integer, parameter :: GREEN = 2 integer, parameter :: BLUE = 3 + interface + subroutine position_rgb(p, pl, rgb, id) bind(C) + import Particle, ObjectPlot, C_INT + type(Particle), intent(inout) :: p + type(ObjectPlot), intent(in) :: pl + integer(C_INT), intent(inout) :: rgb(3) + integer(C_INT), intent(inout) :: id + end subroutine position_rgb + end interface + contains !=============================================================================== @@ -60,56 +70,56 @@ contains ! current particle's position !=============================================================================== - subroutine position_rgb(p, pl, rgb, id) - type(Particle), intent(inout) :: p - type(ObjectPlot), intent(in) :: pl - integer, intent(out) :: rgb(3) - integer, intent(out) :: id + ! subroutine position_rgb(p, pl, rgb, id) + ! type(Particle), intent(inout) :: p + ! type(ObjectPlot), intent(in) :: pl + ! integer, intent(out) :: rgb(3) + ! integer, intent(out) :: id - integer :: j - logical :: found_cell + ! integer :: j + ! logical :: found_cell - p % n_coord = 1 + ! p % n_coord = 1 - call find_cell(p, found_cell) - j = p % n_coord - if (check_overlaps) call check_cell_overlap(p) + ! call find_cell(p, found_cell) + ! j = p % n_coord + ! if (check_overlaps) call check_cell_overlap(p) - ! Set coordinate level if specified - if (pl % level >= 0) j = pl % level + 1 + ! ! Set coordinate level if specified + ! if (pl % level >= 0) j = pl % level + 1 - if (.not. found_cell) then - ! If no cell, revert to default color - rgb = pl % not_found % rgb - id = -1 - else - if (pl % color_by == PLOT_COLOR_MATS) then - ! Assign color based on material - associate (c => cells(p % coord(j) % cell + 1)) - if (c % type() == FILL_UNIVERSE) then - ! If we stopped on a middle universe level, treat as if not found - rgb = pl % not_found % rgb - id = -1 - else if (p % material == MATERIAL_VOID) then - ! By default, color void cells white - rgb = 255 - id = -1 - else - rgb = pl % colors(p % material) % rgb - id = materials(p % material) % id() - end if - end associate - else if (pl % color_by == PLOT_COLOR_CELLS) then - ! Assign color based on cell - rgb = pl % colors(p % coord(j) % cell + 1) % rgb - id = cells(p % coord(j) % cell + 1) % id() - else - rgb = 0 - id = -1 - end if - end if + ! if (.not. found_cell) then + ! ! If no cell, revert to default color + ! rgb = pl % not_found % rgb + ! id = -1 + ! else + ! if (pl % color_by == PLOT_COLOR_MATS) then + ! ! Assign color based on material + ! associate (c => cells(p % coord(j) % cell + 1)) + ! if (c % type() == FILL_UNIVERSE) then + ! ! If we stopped on a middle universe level, treat as if not found + ! rgb = pl % not_found % rgb + ! id = -1 + ! else if (p % material == MATERIAL_VOID) then + ! ! By default, color void cells white + ! rgb = 255 + ! id = -1 + ! else + ! rgb = pl % colors(p % material) % rgb + ! id = materials(p % material) % id() + ! end if + ! end associate + ! else if (pl % color_by == PLOT_COLOR_CELLS) then + ! ! Assign color based on cell + ! rgb = pl % colors(p % coord(j) % cell + 1) % rgb + ! id = cells(p % coord(j) % cell + 1) % id() + ! else + ! rgb = 0 + ! id = -1 + ! end if + ! end if - end subroutine position_rgb + ! end subroutine position_rgb !=============================================================================== ! CREATE_PPM creates an image based on user input from a plots.xml From 539b9c10ec1f2571f43d0f8a58ed6c4f00129c6b Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Tue, 9 Oct 2018 10:42:39 -0500 Subject: [PATCH 010/105] Applying C-side implementation of position_rgb. --- include/openmc/plot.h | 6 ++-- src/plot.F90 | 64 ++----------------------------------------- src/plot.cpp | 35 ++++++++++++----------- src/plot_header.F90 | 28 +++++++++---------- 4 files changed, 38 insertions(+), 95 deletions(-) diff --git a/include/openmc/plot.h b/include/openmc/plot.h index 92b8d89b3..869d75989 100644 --- a/include/openmc/plot.h +++ b/include/openmc/plot.h @@ -41,8 +41,7 @@ namespace openmc { // ObjectColor holds color information for plotted objects //=============================================================================== - class ObjectColor { - public: + struct ObjectColor { int rgb[3]; }; @@ -50,8 +49,7 @@ namespace openmc { // ObjectPlot holds plot information //=============================================================================== - class ObjectPlot { - public: + struct ObjectPlot { int id; int type; int color_by; diff --git a/src/plot.F90 b/src/plot.F90 index d2ebab166..2bf390540 100644 --- a/src/plot.F90 +++ b/src/plot.F90 @@ -30,11 +30,11 @@ module plot import Particle, ObjectPlot, C_INT type(Particle), intent(inout) :: p type(ObjectPlot), intent(in) :: pl - integer(C_INT), intent(inout) :: rgb(3) - integer(C_INT), intent(inout) :: id + integer(C_INT), intent(out) :: rgb(3) + integer(C_INT), intent(out) :: id end subroutine position_rgb end interface - + contains !=============================================================================== @@ -65,62 +65,6 @@ contains err = 0 end function openmc_plot_geometry -!=============================================================================== -! POSITION_RGB computes the red/green/blue values for a given plot with the -! current particle's position -!=============================================================================== - - ! subroutine position_rgb(p, pl, rgb, id) - ! type(Particle), intent(inout) :: p - ! type(ObjectPlot), intent(in) :: pl - ! integer, intent(out) :: rgb(3) - ! integer, intent(out) :: id - - ! integer :: j - ! logical :: found_cell - - ! p % n_coord = 1 - - ! call find_cell(p, found_cell) - ! j = p % n_coord - ! if (check_overlaps) call check_cell_overlap(p) - - ! ! Set coordinate level if specified - ! if (pl % level >= 0) j = pl % level + 1 - - ! if (.not. found_cell) then - ! ! If no cell, revert to default color - ! rgb = pl % not_found % rgb - ! id = -1 - ! else - ! if (pl % color_by == PLOT_COLOR_MATS) then - ! ! Assign color based on material - ! associate (c => cells(p % coord(j) % cell + 1)) - ! if (c % type() == FILL_UNIVERSE) then - ! ! If we stopped on a middle universe level, treat as if not found - ! rgb = pl % not_found % rgb - ! id = -1 - ! else if (p % material == MATERIAL_VOID) then - ! ! By default, color void cells white - ! rgb = 255 - ! id = -1 - ! else - ! rgb = pl % colors(p % material) % rgb - ! id = materials(p % material) % id() - ! end if - ! end associate - ! else if (pl % color_by == PLOT_COLOR_CELLS) then - ! ! Assign color based on cell - ! rgb = pl % colors(p % coord(j) % cell + 1) % rgb - ! id = cells(p % coord(j) % cell + 1) % id() - ! else - ! rgb = 0 - ! id = -1 - ! end if - ! end if - - ! end subroutine position_rgb - !=============================================================================== ! CREATE_PPM creates an image based on user input from a plots.xml ! specification in the portable pixmap format (PPM) @@ -187,7 +131,6 @@ contains ! get pixel color call position_rgb(p, pl, rgb, id) - ! Create a pixel at (x,y) with color (r,g,b) data(:, x, y) = rgb end do @@ -436,7 +379,6 @@ contains do z = 1, pl % pixels(3) ! get voxel color call position_rgb(p, pl, rgb, id) - ! write to plot file data(z,y) = id diff --git a/src/plot.cpp b/src/plot.cpp index 0af83f154..a9db10fcb 100644 --- a/src/plot.cpp +++ b/src/plot.cpp @@ -19,18 +19,18 @@ const int NULLRGB[3] = {0, 0, 0}; //=============================================================================== // RUN_PLOT controls the logic for making one or many plots //=============================================================================== - + int openmc_plot_geometry() { int err; for(auto i : n_plots) { ObjectPlot* pl = plots[i]; - + std::stringstream ss; ss << "Processing plot " << pl->id << ": " << pl->path_plot << "..."; write_message(ss.str(), 5); - + if (pl->type == PLOT_TYPE::SLICE) { // create 2D image // create_ppm(pl); @@ -40,9 +40,9 @@ int openmc_plot_geometry() { // create_voxel(pl); continue; } - + } - + return 0; } @@ -110,7 +110,7 @@ void create_ppm(ObjectPlot* pl) { } //output_ppm(pl, data); - + } //=============================================================================== @@ -130,13 +130,15 @@ void position_rgb(Particle* p, ObjectPlot* pl, int rgb[3], int &id) { if (settings::check_overlaps) { check_cell_overlap(p); } // Set coordinate level if specified - if (pl->level >= 0) j = pl->level + 1; + if (pl->level >= 0) {j = pl->level + 1;} Cell* c; if (!found_cell) { // If no cell, revert to default color - rgb = pl->not_found.rgb; + std::copy(pl->not_found.rgb, + pl->not_found.rgb + 3, + rgb); id = -1; } else { if (pl->color_by = PLOT_COLOR_BY::MATS) { @@ -144,32 +146,33 @@ void position_rgb(Particle* p, ObjectPlot* pl, int rgb[3], int &id) { c = cells[p->coord[j].cell]; if (c->type_ == FILL_UNIVERSE) { // If we stopped on a middle universe level, treat as if not found - rgb = pl->not_found.rgb; + std::copy(pl->not_found.rgb, + pl->not_found.rgb + 3, + rgb); id = -1; } else if (p->material == MATERIAL_VOID) { // By default, color void cells white std::copy(WHITE, WHITE+3, rgb); id = -1; } else { - std::copy(pl->colors[p->material].rgb, - pl->colors[p->material].rgb + 3, + std::copy(pl->colors[p->material - 1].rgb, + pl->colors[p->material - 1].rgb + 3, rgb); - id = materials[p->material]->id; + id = materials[p->material - 1]->id; } } else if (pl->color_by == PLOT_COLOR_BY::CELLS) { // Assign color based on cell - std::copy(pl->colors[p->coord[j].cell].rgb, - pl->colors[p->coord[j].cell].rgb + 3, + std::copy(pl->colors[p->coord[j].cell - 1].rgb, + pl->colors[p->coord[j].cell - 1].rgb + 3, rgb); - id = cells[p->coord[j].cell]->id_; + id = cells[p->coord[j].cell - 1]->id_; } else { std::copy(NULLRGB, NULLRGB+3, rgb); id = -1; } } // endif found_cell - } void diff --git a/src/plot_header.F90 b/src/plot_header.F90 index e4b9c7feb..ad9aa3525 100644 --- a/src/plot_header.F90 +++ b/src/plot_header.F90 @@ -20,20 +20,20 @@ module plot_header !=============================================================================== type, bind(C) :: ObjectPlot - integer(C_INT) :: id ! Unique ID - integer(C_INT) :: type ! Type - integer(C_INT) :: color_by ! quantity to color regions by - real(C_DOUBLE) :: origin(3) ! xyz center of plot location - real(C_DOUBLE) :: width(3) ! xyz widths of plot - integer(C_INT) :: basis ! direction of plot slice - integer(C_INT) :: pixels(3) ! pixel width/height of plot slice - integer(C_INT) :: meshlines_width ! pixel width of meshlines - integer(C_INT) :: level ! universe depth to plot the cells of - integer(C_INT) :: index_meshlines_mesh = -1 ! index of mesh to plot - type(ObjectColor) :: meshlines_color ! Color for meshlines - type(ObjectColor) :: not_found ! color for positions where no cell found - type(ObjectColor) :: colors(MAX_COORD) ! colors of cells/mats - character(MAX_WORD_LEN) :: path_plot ! path for plot file + integer(C_INT) :: id ! Unique ID + integer(C_INT) :: type ! Type + integer(C_INT) :: color_by ! quantity to color regions by + real(C_DOUBLE) :: origin(3) ! xyz center of plot location + real(C_DOUBLE) :: width(3) ! xyz widths of plot + integer(C_INT) :: basis ! direction of plot slice + integer(C_INT) :: pixels(3) ! pixel width/height of plot slice + integer(C_INT) :: meshlines_width ! pixel width of meshlines + integer(C_INT) :: level ! universe depth to plot the cells of + integer(C_INT) :: index_meshlines_mesh = -1 ! index of mesh to plot + type(ObjectColor) :: meshlines_color ! Color for meshlines + type(ObjectColor) :: not_found ! color for positions where no cell found + type(ObjectColor) :: colors(MAX_COORD) ! colors of cells/mats + character(MAX_WORD_LEN, kind=C_CHAR) :: path_plot ! path for plot file end type ObjectPlot ! Plot type From 52aeae287816e210a0ccfeedb4c949e50d04914e Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Tue, 9 Oct 2018 11:56:24 -0500 Subject: [PATCH 011/105] Fortran style updates. --- src/plot.F90 | 14 +++++++------- src/plot_header.F90 | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/plot.F90 b/src/plot.F90 index 2bf390540..bc06610b4 100644 --- a/src/plot.F90 +++ b/src/plot.F90 @@ -26,13 +26,13 @@ module plot integer, parameter :: BLUE = 3 interface - subroutine position_rgb(p, pl, rgb, id) bind(C) - import Particle, ObjectPlot, C_INT - type(Particle), intent(inout) :: p - type(ObjectPlot), intent(in) :: pl - integer(C_INT), intent(out) :: rgb(3) - integer(C_INT), intent(out) :: id - end subroutine position_rgb + subroutine position_rgb(p, pl, rgb, id) bind(C) + import Particle, ObjectPlot, C_INT + type(Particle), intent(inout) :: p + type(ObjectPlot), intent(in) :: pl + integer(C_INT), intent(out) :: rgb(3) + integer(C_INT), intent(out) :: id + end subroutine position_rgb end interface contains diff --git a/src/plot_header.F90 b/src/plot_header.F90 index ad9aa3525..9937db7dd 100644 --- a/src/plot_header.F90 +++ b/src/plot_header.F90 @@ -33,7 +33,7 @@ module plot_header type(ObjectColor) :: meshlines_color ! Color for meshlines type(ObjectColor) :: not_found ! color for positions where no cell found type(ObjectColor) :: colors(MAX_COORD) ! colors of cells/mats - character(MAX_WORD_LEN, kind=C_CHAR) :: path_plot ! path for plot file + character(MAX_WORD_LEN, kind=C_CHAR) :: path_plot ! path for plot file end type ObjectPlot ! Plot type From f2403b8425e37ae027fc7146b238c61594bc812d Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Tue, 9 Oct 2018 13:59:10 -0500 Subject: [PATCH 012/105] Fixing false positive problem and style throughout to avoid the problem in the future. --- src/plot.cpp | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/plot.cpp b/src/plot.cpp index a9db10fcb..69dbf63ab 100644 --- a/src/plot.cpp +++ b/src/plot.cpp @@ -31,11 +31,11 @@ int openmc_plot_geometry() { << pl->path_plot << "..."; write_message(ss.str(), 5); - if (pl->type == PLOT_TYPE::SLICE) { + if (PLOT_TYPE::SLICE == pl->type) { // create 2D image // create_ppm(pl); continue; - } else if (pl->type == PLOT_TYPE::VOXEL) { + } else if (PLOT_TYPE::VOXEL == pl->type) { // create voxel file for 3D viewing // create_voxel(pl); continue; @@ -69,19 +69,19 @@ void create_ppm(ObjectPlot* pl) { int in_i, out_i; double xyz[3]; - if (pl->basis == PLOT_BASIS::XY) { + if (PLOT_BASIS::XY == pl->basis) { in_i = 0; out_i = 1; xyz[0] = pl->origin[0] - pl->width[0] / TWO; xyz[1] = pl->origin[1] - pl->width[1] / TWO; xyz[2] = pl->origin[2]; - } else if (pl->basis == PLOT_BASIS::XZ) { + } else if (PLOT_BASIS::XZ == pl->basis) { in_i = 0; out_i = 2; xyz[0] = pl->origin[0] - pl->width[0] / TWO; xyz[1] = pl->origin[1]; xyz[2] = pl->origin[2] - pl->width[1] / TWO; - } else if (pl->basis == PLOT_BASIS::YZ) { + } else if (PLOT_BASIS::YZ == pl->basis) { in_i = 1; out_i = 2; xyz[0] = pl->origin[0]; @@ -141,7 +141,7 @@ void position_rgb(Particle* p, ObjectPlot* pl, int rgb[3], int &id) { rgb); id = -1; } else { - if (pl->color_by = PLOT_COLOR_BY::MATS) { + if (PLOT_COLOR_BY::MATS == pl->color_by) { // Assign color based on material c = cells[p->coord[j].cell]; if (c->type_ == FILL_UNIVERSE) { @@ -161,12 +161,12 @@ void position_rgb(Particle* p, ObjectPlot* pl, int rgb[3], int &id) { id = materials[p->material - 1]->id; } - } else if (pl->color_by == PLOT_COLOR_BY::CELLS) { + } else if (PLOT_COLOR_BY::CELLS == pl->color_by) { // Assign color based on cell - std::copy(pl->colors[p->coord[j].cell - 1].rgb, - pl->colors[p->coord[j].cell - 1].rgb + 3, + std::copy(pl->colors[p->coord[j].cell].rgb, + pl->colors[p->coord[j].cell].rgb + 3, rgb); - id = cells[p->coord[j].cell - 1]->id_; + id = cells[p->coord[j].cell]->id_; } else { std::copy(NULLRGB, NULLRGB+3, rgb); id = -1; From 2a3b432859c216dafdddfc23949afe3d1e3cc2f6 Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Tue, 9 Oct 2018 14:03:42 -0500 Subject: [PATCH 013/105] Style updates. --- src/plot.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/plot.cpp b/src/plot.cpp index 69dbf63ab..bdc8f6933 100644 --- a/src/plot.cpp +++ b/src/plot.cpp @@ -23,7 +23,7 @@ const int NULLRGB[3] = {0, 0, 0}; int openmc_plot_geometry() { int err; - for(auto i : n_plots) { + for (auto i : n_plots) { ObjectPlot* pl = plots[i]; std::stringstream ss; @@ -99,12 +99,11 @@ void create_ppm(ObjectPlot* pl) { // local variables int rgb[3]; int id; - for(int y = 0; y < height; y++) { + for (int y = 0; y < height; y++) { p->coord[0].xyz[out_i] = xyz[out_i] - out_pixel*(y); - for(int x = 0; x < width; x++) { + for (int x = 0; x < width; x++) { p->coord[0].xyz[in_i] = xyz[in_i] + in_pixel*(x); // position_rgb(p, pl, rgb, id); - std::copy(rgb, rgb+3, &(data[x][y][0])); } } From 05192cc2d7e270868d4d1c4aa768e3a5ebd8c2f5 Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Tue, 9 Oct 2018 14:25:13 -0500 Subject: [PATCH 014/105] Adding output_ppm skeleton. --- src/plot.cpp | 39 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/src/plot.cpp b/src/plot.cpp index bdc8f6933..bf6996284 100644 --- a/src/plot.cpp +++ b/src/plot.cpp @@ -1,3 +1,5 @@ +#include + #include "openmc/plot.h" #include "openmc/constants.h" #include "openmc/settings.h" @@ -64,7 +66,9 @@ void create_ppm(ObjectPlot* pl) { data.resize(width); for (auto i : data) { i.resize(height); - for (auto j : i) { j.resize(3); } + for (auto j : i) { + j.resize(3); + } } int in_i, out_i; @@ -174,6 +178,39 @@ void position_rgb(Particle* p, ObjectPlot* pl, int rgb[3], int &id) { } // endif found_cell } +//=============================================================================== +// OUTPUT_PPM writes out a previously generated image to a PPM file +//=============================================================================== + + void output_ppm(ObjectPlot* pl, int* data, int data_size) +{ + + // check incoming data size + assert(data_size % 3 == 0); + + // Open PPM file for writing + std::ofstream of(pl->path_plot); + + // Write header + of << "P6" << std::endl; + of << pl->pixels[0] << " " << pl->pixels[1] << std::endl; + of << "255" << std::endl; + + int* rgb; + // Write color for each pixel + for (int y = 0; y < pl->pixels[1]; y++) { + for (int x = 0; x < pl->pixels[0]; x++) { + int idx = 3*(x + y*width); + rgb = &data[idx]; + of << itoa(rgb[0]) << itoa(rgb[1]) << itoa(rgb[2]); + } + } + + // Close file + of.close(); + +} + void voxel_init(hid_t file_id, const hsize_t* dims, hid_t* dspace, hid_t* dset, hid_t* memspace) From 562b8daf85324152be07d161b5787faf79d5f526 Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Tue, 9 Oct 2018 15:15:41 -0500 Subject: [PATCH 015/105] Moving to C++ create_ppm function. Need to workout output formatting. --- include/openmc/plot.h | 6 ++ src/plot.F90 | 134 ++++++++++++++++++++++-------------------- src/plot.cpp | 29 +++++---- 3 files changed, 92 insertions(+), 77 deletions(-) diff --git a/include/openmc/plot.h b/include/openmc/plot.h index 869d75989..b3c2236ac 100644 --- a/include/openmc/plot.h +++ b/include/openmc/plot.h @@ -67,6 +67,12 @@ namespace openmc { }; +extern "C" void output_ppm(ObjectPlot* pl, + const std::vector< std::vector< std::vector > > &data); + + +extern "C" void create_ppm(ObjectPlot* pl); + extern "C" void position_rgb(Particle* p, ObjectPlot* pl, int rgb[3], int &id); extern "C" void voxel_init(hid_t file_id, const hsize_t* dims, hid_t* dspace, diff --git a/src/plot.F90 b/src/plot.F90 index bc06610b4..7465df4f3 100644 --- a/src/plot.F90 +++ b/src/plot.F90 @@ -33,8 +33,14 @@ module plot integer(C_INT), intent(out) :: rgb(3) integer(C_INT), intent(out) :: id end subroutine position_rgb - end interface + + subroutine create_ppm(pl) bind(C) + import ObjectPlot + type(ObjectPlot), intent(in) :: pl + end subroutine create_ppm + + end interface contains !=============================================================================== @@ -70,80 +76,80 @@ contains ! specification in the portable pixmap format (PPM) !=============================================================================== - subroutine create_ppm(pl) - type(ObjectPlot), intent(in) :: pl +! subroutine create_ppm(pl) +! type(ObjectPlot), intent(in) :: pl - integer :: in_i - integer :: out_i - integer :: x, y ! pixel location - integer :: rgb(3) ! colors (red, green, blue) from 0-255 - integer :: id - integer :: height, width - real(8) :: in_pixel - real(8) :: out_pixel - real(8) :: xyz(3) - integer, allocatable :: data(:,:,:) - type(Particle) :: p +! integer :: in_i +! integer :: out_i +! integer :: x, y ! pixel location +! integer :: rgb(3) ! colors (red, green, blue) from 0-255 +! integer :: id +! integer :: height, width +! real(8) :: in_pixel +! real(8) :: out_pixel +! real(8) :: xyz(3) +! integer, allocatable :: data(:,:,:) +! type(Particle) :: p - width = pl % pixels(1) - height = pl % pixels(2) +! width = pl % pixels(1) +! height = pl % pixels(2) - in_pixel = pl % width(1)/dble(width) - out_pixel = pl % width(2)/dble(height) +! in_pixel = pl % width(1)/dble(width) +! out_pixel = pl % width(2)/dble(height) - ! Allocate and initialize results array - allocate(data(3, width, height)) - data(:,:,:) = 0 +! ! Allocate and initialize results array +! allocate(data(3, width, height)) +! data(:,:,:) = 0 - if (pl % basis == PLOT_BASIS_XY) then - in_i = 1 - out_i = 2 - xyz(1) = pl % origin(1) - pl % width(1) / TWO - xyz(2) = pl % origin(2) + pl % width(2) / TWO - xyz(3) = pl % origin(3) - else if (pl % basis == PLOT_BASIS_XZ) then - in_i = 1 - out_i = 3 - xyz(1) = pl % origin(1) - pl % width(1) / TWO - xyz(2) = pl % origin(2) - xyz(3) = pl % origin(3) + pl % width(2) / TWO - else if (pl % basis == PLOT_BASIS_YZ) then - in_i = 2 - out_i = 3 - xyz(1) = pl % origin(1) - xyz(2) = pl % origin(2) - pl % width(1) / TWO - xyz(3) = pl % origin(3) + pl % width(2) / TWO - end if +! if (pl % basis == PLOT_BASIS_XY) then +! in_i = 1 +! out_i = 2 +! xyz(1) = pl % origin(1) - pl % width(1) / TWO +! xyz(2) = pl % origin(2) + pl % width(2) / TWO +! xyz(3) = pl % origin(3) +! else if (pl % basis == PLOT_BASIS_XZ) then +! in_i = 1 +! out_i = 3 +! xyz(1) = pl % origin(1) - pl % width(1) / TWO +! xyz(2) = pl % origin(2) +! xyz(3) = pl % origin(3) + pl % width(2) / TWO +! else if (pl % basis == PLOT_BASIS_YZ) then +! in_i = 2 +! out_i = 3 +! xyz(1) = pl % origin(1) +! xyz(2) = pl % origin(2) - pl % width(1) / TWO +! xyz(3) = pl % origin(3) + pl % width(2) / TWO +! end if - ! allocate and initialize particle - call particle_initialize(p) - p % coord(1) % xyz = xyz - p % coord(1) % uvw = [ HALF, HALF, HALF ] - p % coord(1) % universe = root_universe +! ! allocate and initialize particle +! call particle_initialize(p) +! p % coord(1) % xyz = xyz +! p % coord(1) % uvw = [ HALF, HALF, HALF ] +! p % coord(1) % universe = root_universe -!$omp parallel do firstprivate(p) private(x, rgb, id) reduction(+ : data) - do y = 1, height - ! Set y coordinate - p % coord(1) % xyz(out_i) = xyz(out_i) - out_pixel*(y - 1) - do x = 1, width - ! Set x coordinate - p % coord(1) % xyz(in_i) = xyz(in_i) + in_pixel*(x - 1) +! !$omp parallel do firstprivate(p) private(x, rgb, id) reduction(+ : data) +! do y = 1, height +! ! Set y coordinate +! p % coord(1) % xyz(out_i) = xyz(out_i) - out_pixel*(y - 1) +! do x = 1, width +! ! Set x coordinate +! p % coord(1) % xyz(in_i) = xyz(in_i) + in_pixel*(x - 1) - ! get pixel color - call position_rgb(p, pl, rgb, id) - ! Create a pixel at (x,y) with color (r,g,b) - data(:, x, y) = rgb - end do - end do -!$omp end parallel do +! ! get pixel color +! call position_rgb(p, pl, rgb, id) +! ! Create a pixel at (x,y) with color (r,g,b) +! data(:, x, y) = rgb +! end do +! end do +! !$omp end parallel do - ! Draw tally mesh boundaries on the image if requested - if (pl % index_meshlines_mesh >= 0) call draw_mesh_lines(pl, data) +! ! Draw tally mesh boundaries on the image if requested +! if (pl % index_meshlines_mesh >= 0) call draw_mesh_lines(pl, data) - ! Write out the ppm to a file - call output_ppm(pl, data) +! ! Write out the ppm to a file +! call output_ppm(pl, data) - end subroutine create_ppm +! end subroutine create_ppm !=============================================================================== ! DRAW_MESH_LINES draws mesh line boundaries on an image diff --git a/src/plot.cpp b/src/plot.cpp index bf6996284..d846676b4 100644 --- a/src/plot.cpp +++ b/src/plot.cpp @@ -1,4 +1,6 @@ #include +#include +#include #include "openmc/plot.h" #include "openmc/constants.h" @@ -8,6 +10,7 @@ #include "openmc/geometry.h" #include "openmc/cell.h" #include "openmc/material.h" +#include "openmc/string_functions.h" namespace openmc { @@ -64,9 +67,9 @@ void create_ppm(ObjectPlot* pl) { std::vector< std::vector< std::vector>> data; data.resize(width); - for (auto i : data) { + for (auto & i : data) { i.resize(height); - for (auto j : i) { + for (auto & j : i) { j.resize(3); } } @@ -108,11 +111,13 @@ void create_ppm(ObjectPlot* pl) { for (int x = 0; x < width; x++) { p->coord[0].xyz[in_i] = xyz[in_i] + in_pixel*(x); // position_rgb(p, pl, rgb, id); - std::copy(rgb, rgb+3, &(data[x][y][0])); + data[x][y][0] = rgb[0]; + data[x][y][1] = rgb[1]; + data[x][y][2] = rgb[2]; } } - //output_ppm(pl, data); + output_ppm(pl, data); } @@ -182,27 +187,25 @@ void position_rgb(Particle* p, ObjectPlot* pl, int rgb[3], int &id) { // OUTPUT_PPM writes out a previously generated image to a PPM file //=============================================================================== - void output_ppm(ObjectPlot* pl, int* data, int data_size) + void output_ppm(ObjectPlot* pl, + const std::vector< std::vector< std::vector > > &data) { - // check incoming data size - assert(data_size % 3 == 0); - // Open PPM file for writing - std::ofstream of(pl->path_plot); + std::string fname = std::string(pl->path_plot); + fname = strtrim(fname); + std::ofstream of(fname); // Write header of << "P6" << std::endl; of << pl->pixels[0] << " " << pl->pixels[1] << std::endl; of << "255" << std::endl; - int* rgb; // Write color for each pixel for (int y = 0; y < pl->pixels[1]; y++) { for (int x = 0; x < pl->pixels[0]; x++) { - int idx = 3*(x + y*width); - rgb = &data[idx]; - of << itoa(rgb[0]) << itoa(rgb[1]) << itoa(rgb[2]); + std::vector rgb = data[x][y]; + of << (char)rgb[0] << (char)rgb[1] << (char)rgb[2]; } } From 37f73e8cdca187ae1dea6088e40350ec20aafd22 Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Tue, 9 Oct 2018 16:14:21 -0500 Subject: [PATCH 016/105] Replacing create_ppm and output_ppm with C++ implementation. --- include/openmc/plot.h | 5 ++- src/plot.F90 | 80 ------------------------------------------- src/plot.cpp | 28 ++++++++------- 3 files changed, 17 insertions(+), 96 deletions(-) diff --git a/include/openmc/plot.h b/include/openmc/plot.h index b3c2236ac..2b37869e8 100644 --- a/include/openmc/plot.h +++ b/include/openmc/plot.h @@ -67,9 +67,8 @@ namespace openmc { }; -extern "C" void output_ppm(ObjectPlot* pl, - const std::vector< std::vector< std::vector > > &data); - +void output_ppm(ObjectPlot* pl, + std::vector< std::vector< std::vector > > data); extern "C" void create_ppm(ObjectPlot* pl); diff --git a/src/plot.F90 b/src/plot.F90 index 7465df4f3..adc91c72d 100644 --- a/src/plot.F90 +++ b/src/plot.F90 @@ -71,86 +71,6 @@ contains err = 0 end function openmc_plot_geometry -!=============================================================================== -! CREATE_PPM creates an image based on user input from a plots.xml -! specification in the portable pixmap format (PPM) -!=============================================================================== - -! subroutine create_ppm(pl) -! type(ObjectPlot), intent(in) :: pl - -! integer :: in_i -! integer :: out_i -! integer :: x, y ! pixel location -! integer :: rgb(3) ! colors (red, green, blue) from 0-255 -! integer :: id -! integer :: height, width -! real(8) :: in_pixel -! real(8) :: out_pixel -! real(8) :: xyz(3) -! integer, allocatable :: data(:,:,:) -! type(Particle) :: p - -! width = pl % pixels(1) -! height = pl % pixels(2) - -! in_pixel = pl % width(1)/dble(width) -! out_pixel = pl % width(2)/dble(height) - -! ! Allocate and initialize results array -! allocate(data(3, width, height)) -! data(:,:,:) = 0 - -! if (pl % basis == PLOT_BASIS_XY) then -! in_i = 1 -! out_i = 2 -! xyz(1) = pl % origin(1) - pl % width(1) / TWO -! xyz(2) = pl % origin(2) + pl % width(2) / TWO -! xyz(3) = pl % origin(3) -! else if (pl % basis == PLOT_BASIS_XZ) then -! in_i = 1 -! out_i = 3 -! xyz(1) = pl % origin(1) - pl % width(1) / TWO -! xyz(2) = pl % origin(2) -! xyz(3) = pl % origin(3) + pl % width(2) / TWO -! else if (pl % basis == PLOT_BASIS_YZ) then -! in_i = 2 -! out_i = 3 -! xyz(1) = pl % origin(1) -! xyz(2) = pl % origin(2) - pl % width(1) / TWO -! xyz(3) = pl % origin(3) + pl % width(2) / TWO -! end if - -! ! allocate and initialize particle -! call particle_initialize(p) -! p % coord(1) % xyz = xyz -! p % coord(1) % uvw = [ HALF, HALF, HALF ] -! p % coord(1) % universe = root_universe - -! !$omp parallel do firstprivate(p) private(x, rgb, id) reduction(+ : data) -! do y = 1, height -! ! Set y coordinate -! p % coord(1) % xyz(out_i) = xyz(out_i) - out_pixel*(y - 1) -! do x = 1, width -! ! Set x coordinate -! p % coord(1) % xyz(in_i) = xyz(in_i) + in_pixel*(x - 1) - -! ! get pixel color -! call position_rgb(p, pl, rgb, id) -! ! Create a pixel at (x,y) with color (r,g,b) -! data(:, x, y) = rgb -! end do -! end do -! !$omp end parallel do - -! ! Draw tally mesh boundaries on the image if requested -! if (pl % index_meshlines_mesh >= 0) call draw_mesh_lines(pl, data) - -! ! Write out the ppm to a file -! call output_ppm(pl, data) - -! end subroutine create_ppm - !=============================================================================== ! DRAW_MESH_LINES draws mesh line boundaries on an image !=============================================================================== diff --git a/src/plot.cpp b/src/plot.cpp index d846676b4..589883113 100644 --- a/src/plot.cpp +++ b/src/plot.cpp @@ -1,6 +1,4 @@ #include -#include -#include #include "openmc/plot.h" #include "openmc/constants.h" @@ -64,7 +62,7 @@ void create_ppm(ObjectPlot* pl) { double in_pixel = (pl->width[0])/double(width); double out_pixel = (pl->width[1])/double(height); - std::vector< std::vector< std::vector>> data; + std::vector< std::vector< std::vector > > data; data.resize(width); for (auto & i : data) { @@ -80,23 +78,23 @@ void create_ppm(ObjectPlot* pl) { in_i = 0; out_i = 1; xyz[0] = pl->origin[0] - pl->width[0] / TWO; - xyz[1] = pl->origin[1] - pl->width[1] / TWO; + xyz[1] = pl->origin[1] + pl->width[1] / TWO; xyz[2] = pl->origin[2]; } else if (PLOT_BASIS::XZ == pl->basis) { in_i = 0; out_i = 2; xyz[0] = pl->origin[0] - pl->width[0] / TWO; xyz[1] = pl->origin[1]; - xyz[2] = pl->origin[2] - pl->width[1] / TWO; + xyz[2] = pl->origin[2] + pl->width[1] / TWO; } else if (PLOT_BASIS::YZ == pl->basis) { in_i = 1; out_i = 2; xyz[0] = pl->origin[0]; xyz[1] = pl->origin[1] - pl->width[0] / TWO; - xyz[2] = pl->origin[2] - pl->width[1] / TWO; + xyz[2] = pl->origin[2] + pl->width[1] / TWO; } - double dir[3]; + double dir[3] = {HALF, HALF, HALF}; Particle *p = new Particle(); p->initialize(); std::copy(xyz, xyz+3, p->coord[0].xyz); @@ -110,7 +108,7 @@ void create_ppm(ObjectPlot* pl) { p->coord[0].xyz[out_i] = xyz[out_i] - out_pixel*(y); for (int x = 0; x < width; x++) { p->coord[0].xyz[in_i] = xyz[in_i] + in_pixel*(x); - // position_rgb(p, pl, rgb, id); + position_rgb(p, pl, rgb, id); data[x][y][0] = rgb[0]; data[x][y][1] = rgb[1]; data[x][y][2] = rgb[2]; @@ -188,30 +186,34 @@ void position_rgb(Particle* p, ObjectPlot* pl, int rgb[3], int &id) { //=============================================================================== void output_ppm(ObjectPlot* pl, - const std::vector< std::vector< std::vector > > &data) + std::vector< std::vector< std::vector > > data) { // Open PPM file for writing std::string fname = std::string(pl->path_plot); fname = strtrim(fname); - std::ofstream of(fname); + std::ofstream of; + + of.open(fname); // Write header of << "P6" << std::endl; of << pl->pixels[0] << " " << pl->pixels[1] << std::endl; of << "255" << std::endl; + of.close(); + of.open(fname, std::ios::binary | std::ios::app); // Write color for each pixel for (int y = 0; y < pl->pixels[1]; y++) { for (int x = 0; x < pl->pixels[0]; x++) { std::vector rgb = data[x][y]; - of << (char)rgb[0] << (char)rgb[1] << (char)rgb[2]; + of.write((char*)&rgb[0], 1); + of.write((char*)&rgb[1], 1); + of.write((char*)&rgb[2], 1); } } - // Close file of.close(); - } void From f2e91f675ab8617831cd5f42f8c406512d69b1c2 Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Tue, 9 Oct 2018 17:35:38 -0500 Subject: [PATCH 017/105] Adding draw_mesh_lines on C++ side --- include/openmc/constants.h | 1 + include/openmc/plot.h | 6 ++- src/plot.F90 | 32 ----------- src/plot.cpp | 105 ++++++++++++++++++++++++++++++++++++- 4 files changed, 110 insertions(+), 34 deletions(-) diff --git a/include/openmc/constants.h b/include/openmc/constants.h index c2b52b25a..60a2e0691 100644 --- a/include/openmc/constants.h +++ b/include/openmc/constants.h @@ -82,6 +82,7 @@ constexpr double EXTSRC_REJECT_FRACTION {0.05}; constexpr double PI {3.1415926535898}; const double SQRT_PI {std::sqrt(PI)}; constexpr double INFTY {std::numeric_limits::max()}; +constexpr double ONE {1.0}; constexpr double TWO {2.0}; constexpr double HALF {0.5}; diff --git a/include/openmc/plot.h b/include/openmc/plot.h index 2b37869e8..e64ecc2f7 100644 --- a/include/openmc/plot.h +++ b/include/openmc/plot.h @@ -67,8 +67,12 @@ namespace openmc { }; +void draw_mesh_lines(ObjectPlot* pl, + std::vector< std::vector< std::vector > > &data); + + void output_ppm(ObjectPlot* pl, - std::vector< std::vector< std::vector > > data); + const std::vector< std::vector< std::vector > > &data); extern "C" void create_ppm(ObjectPlot* pl); diff --git a/src/plot.F90 b/src/plot.F90 index adc91c72d..075061beb 100644 --- a/src/plot.F90 +++ b/src/plot.F90 @@ -173,38 +173,6 @@ contains end subroutine draw_mesh_lines -!=============================================================================== -! OUTPUT_PPM writes out a previously generated image to a PPM file -!=============================================================================== - - subroutine output_ppm(pl, data) - type(ObjectPlot), intent(in) :: pl - integer, intent(in) :: data(:,:,:) - - integer :: y ! loop index for height - integer :: x ! loop index for width - integer :: unit_plot - - ! Open PPM file for writing - open(NEWUNIT=unit_plot, FILE=pl % path_plot) - - ! Write header - write(unit_plot, '(A2)') 'P6' - write(unit_plot, '(I0,'' '',I0)') pl % pixels(1), pl % pixels(2) - write(unit_plot, '(A)') '255' - - ! Write color for each pixel - do y = 1, pl % pixels(2) - do x = 1, pl % pixels(1) - write(unit_plot, '(3A1)', advance='no') achar(data(RED, x, y)), & - achar(data(GREEN, x, y)), achar(data(BLUE, x, y)) - end do - end do - - ! Close plot file - close(UNIT=unit_plot) - end subroutine output_ppm - !=============================================================================== ! CREATE_VOXEL outputs a binary file that can be input into silomesh for 3D ! geometry visualization. It works the same way as create_ppm by dragging a diff --git a/src/plot.cpp b/src/plot.cpp index 589883113..3e80bc901 100644 --- a/src/plot.cpp +++ b/src/plot.cpp @@ -9,6 +9,7 @@ #include "openmc/cell.h" #include "openmc/material.h" #include "openmc/string_functions.h" +#include "openmc/mesh.h" namespace openmc { @@ -115,6 +116,8 @@ void create_ppm(ObjectPlot* pl) { } } + if (pl->index_meshlines_mesh >= 0) { draw_mesh_lines(pl, data); } + output_ppm(pl, data); } @@ -186,7 +189,7 @@ void position_rgb(Particle* p, ObjectPlot* pl, int rgb[3], int &id) { //=============================================================================== void output_ppm(ObjectPlot* pl, - std::vector< std::vector< std::vector > > data) + const std::vector< std::vector< std::vector > > &data) { // Open PPM file for writing @@ -215,6 +218,106 @@ void position_rgb(Particle* p, ObjectPlot* pl, int rgb[3], int &id) { // Close file of.close(); } + +//=============================================================================== +// DRAW_MESH_LINES draws mesh line boundaries on an image +//=============================================================================== + +void draw_mesh_lines(ObjectPlot *pl, + std::vector< std::vector< std::vector > > &data) { + + std::vector rgb; rgb.resize(3); + rgb[0] = pl->meshlines_color.rgb[0]; + rgb[1] = pl->meshlines_color.rgb[1]; + rgb[2] = pl->meshlines_color.rgb[2]; + + int outer, inner; + switch(pl->basis){ + case PLOT_BASIS::XY : + outer = 0; + inner = 1; + break; + case PLOT_BASIS::XZ : + outer = 0; + inner = 2; + break; + case PLOT_BASIS::YZ : + outer = 1; + inner = 2; + break; + } + + double xyz_ll_plot[3], xyz_ur_plot[3]; + std::copy((double*)&pl->origin, (double*)&pl->origin + 3, xyz_ll_plot); + std::copy((double*)&pl->origin, (double*)&pl->origin + 3, xyz_ur_plot); + + xyz_ll_plot[outer] = pl->origin[outer] - pl->width[0] / TWO; + xyz_ll_plot[inner] = pl->origin[inner] - pl->width[1] / TWO; + xyz_ur_plot[outer] = pl->origin[outer] + pl->width[0] / TWO; + xyz_ur_plot[inner] = pl->origin[inner] + pl->width[1] / TWO; + + int width[3]; + width[0] = xyz_ur_plot[0] - xyz_ll_plot[0]; + width[1] = xyz_ur_plot[1] - xyz_ll_plot[1]; + width[2] = xyz_ur_plot[2] - xyz_ll_plot[2]; + + auto &m = meshes[pl->index_meshlines_mesh]; + + int ijk_ll[3], ijk_ur[3]; + bool in_mesh; + m->get_indices(Position(xyz_ll_plot), &(ijk_ll[0]), &in_mesh); + m->get_indices(Position(xyz_ur_plot), &(ijk_ur[0]), &in_mesh); + + double frac; + int outrange[3], inrange[3]; + double xyz_ll[3], xyz_ur[3]; + // sweep through all meshbins on this plane and draw borders + for (int i = ijk_ll[outer]; i < ijk_ur[outer]; i++) { + for (int j = ijk_ll[inner]; j < ijk_ur[inner]; j++) { + // check if we're in the mesh for this ijk + if (i > 0 && i <= m->shape_[outer] && j >0 && j <= m->shape_[inner] ) { + + // get xyz's of lower left and upper right of this mesh cell + xyz_ll[outer] = m->lower_left_[outer] + m->width_[outer] * (i - 1); + xyz_ll[inner] = m->lower_left_[inner] + m->width_[inner] * (j - 1); + xyz_ur[outer] = m->lower_left_[outer] + m->width_[outer] * i; + xyz_ur[inner] = m->lower_left_[inner] + m->width_[inner] * j; + + // map the xyz ranges to pixel ranges + frac = (xyz_ll[outer] - xyz_ll_plot[outer]) / width[outer]; + outrange[0] = int(frac * double(pl->pixels[0])); + frac = (xyz_ur[outer] - xyz_ll_plot[outer]) / width[outer]; + outrange[1] = int(frac * double(pl->pixels[0])); + + frac = (xyz_ur[inner] - xyz_ll_plot[inner]) / width[inner]; + inrange[0] = int((ONE - frac) * (double)pl->pixels[1]); + frac = (xyz_ll[inner] - xyz_ll_plot[inner]) / width[inner]; + inrange[1] = int((ONE - frac) * (double)pl->pixels[1]); + + // draw lines + for (int out_ = outrange[0]; out_ < outrange[1]; out_++) { + for (int plus = 0; plus < pl->meshlines_width; plus++) { + data[out_ + 1][inrange[0] + plus + 1] = rgb; + data[out_ + 1][inrange[1] + plus + 1] = rgb; + data[out_ + 1][inrange[0] - plus + 1] = rgb; + data[out_ + 1][inrange[1] - plus + 1] = rgb; + } + } + + for (int in_ = inrange[0]; in_ < inrange[1]; in_++) { + for (int plus = 0; plus < pl->meshlines_width; plus++) { + data[outrange[0] + plus + 1][in_ + 1] = rgb; + data[outrange[1] + plus + 1][in_ + 1] = rgb; + data[outrange[0] - plus + 1][in_ + 1] = rgb; + data[outrange[1] - plus + 1][in_ + 1] = rgb; + } + } + + } // end if(in mesh) + } + } // end outer loops + +} void voxel_init(hid_t file_id, const hsize_t* dims, hid_t* dspace, hid_t* dset, From 63a1f75692a6b103a2e1cd1cf05fa4ad14e91457 Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Tue, 9 Oct 2018 17:49:43 -0500 Subject: [PATCH 018/105] Making mesh lines some minimal width. --- src/plot.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/plot.cpp b/src/plot.cpp index 3e80bc901..427891781 100644 --- a/src/plot.cpp +++ b/src/plot.cpp @@ -296,7 +296,7 @@ void draw_mesh_lines(ObjectPlot *pl, // draw lines for (int out_ = outrange[0]; out_ < outrange[1]; out_++) { - for (int plus = 0; plus < pl->meshlines_width; plus++) { + for (int plus = 0; plus <= pl->meshlines_width; plus++) { data[out_ + 1][inrange[0] + plus + 1] = rgb; data[out_ + 1][inrange[1] + plus + 1] = rgb; data[out_ + 1][inrange[0] - plus + 1] = rgb; @@ -305,7 +305,7 @@ void draw_mesh_lines(ObjectPlot *pl, } for (int in_ = inrange[0]; in_ < inrange[1]; in_++) { - for (int plus = 0; plus < pl->meshlines_width; plus++) { + for (int plus = 0; plus <= pl->meshlines_width; plus++) { data[outrange[0] + plus + 1][in_ + 1] = rgb; data[outrange[1] + plus + 1][in_ + 1] = rgb; data[outrange[0] - plus + 1][in_ + 1] = rgb; From 6f3bdbf92144c86a72973abe62327177d74f17e3 Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Tue, 9 Oct 2018 17:52:42 -0500 Subject: [PATCH 019/105] Removing draw_mesh_lines F90 implementation. --- src/plot.F90 | 102 --------------------------------------------------- 1 file changed, 102 deletions(-) diff --git a/src/plot.F90 b/src/plot.F90 index 075061beb..d2e81308f 100644 --- a/src/plot.F90 +++ b/src/plot.F90 @@ -71,108 +71,6 @@ contains err = 0 end function openmc_plot_geometry -!=============================================================================== -! DRAW_MESH_LINES draws mesh line boundaries on an image -!=============================================================================== - - subroutine draw_mesh_lines(pl, data) - type(ObjectPlot), intent(in) :: pl - integer, intent(inout) :: data(:,:,:) - - logical :: in_mesh - integer :: out_, in_ ! pixel location - integer :: rgb(3) ! RGB color for meshlines pixels - integer :: outrange(2), inrange(2) ! range of pixel locations - integer :: i, j ! loop indices - integer :: plus - integer :: ijk_ll(3) ! mesh bin ijk indicies of plot lower left - integer :: ijk_ur(3) ! mesh bin ijk indicies of plot upper right - integer :: outer, inner - real(8) :: frac - real(8) :: width(3) ! real widths of the plot - real(8) :: xyz_ll_plot(3) ! lower left xyz of plot image - real(8) :: xyz_ur_plot(3) ! upper right xyz of plot image - real(8) :: xyz_ll(3) ! lower left xyz - real(8) :: xyz_ur(3) ! upper right xyz - type(RegularMesh) :: m - - rgb(:) = pl % meshlines_color % rgb - - select case (pl % basis) - case(PLOT_BASIS_XY) - outer = 1 - inner = 2 - case(PLOT_BASIS_XZ) - outer = 1 - inner = 3 - case(PLOT_BASIS_YZ) - outer = 2 - inner = 3 - end select - - xyz_ll_plot = pl % origin - xyz_ur_plot = pl % origin - - xyz_ll_plot(outer) = pl % origin(outer) - pl % width(1) / TWO - xyz_ll_plot(inner) = pl % origin(inner) - pl % width(2) / TWO - xyz_ur_plot(outer) = pl % origin(outer) + pl % width(1) / TWO - xyz_ur_plot(inner) = pl % origin(inner) + pl % width(2) / TWO - - width = xyz_ur_plot - xyz_ll_plot - - m = meshes(pl % index_meshlines_mesh) - call m % get_indices(xyz_ll_plot, ijk_ll(:m % n_dimension()), in_mesh) - call m % get_indices(xyz_ur_plot, ijk_ur(:m % n_dimension()), in_mesh) - - ! sweep through all meshbins on this plane and draw borders - do i = ijk_ll(outer), ijk_ur(outer) - do j = ijk_ll(inner), ijk_ur(inner) - ! check if we're in the mesh for this ijk - if (i > 0 .and. i <= m % dimension(outer) .and. & - j > 0 .and. j <= m % dimension(inner)) then - - ! get xyz's of lower left and upper right of this mesh cell - xyz_ll(outer) = m % lower_left(outer) + m % width(outer) * (i - 1) - xyz_ll(inner) = m % lower_left(inner) + m % width(inner) * (j - 1) - xyz_ur(outer) = m % lower_left(outer) + m % width(outer) * i - xyz_ur(inner) = m % lower_left(inner) + m % width(inner) * j - - ! map the xyz ranges to pixel ranges - - frac = (xyz_ll(outer) - xyz_ll_plot(outer)) / width(outer) - outrange(1) = int(frac * real(pl % pixels(1), 8)) - frac = (xyz_ur(outer) - xyz_ll_plot(outer)) / width(outer) - outrange(2) = int(frac * real(pl % pixels(1), 8)) - - frac = (xyz_ur(inner) - xyz_ll_plot(inner)) / width(inner) - inrange(1) = int((ONE - frac) * real(pl % pixels(2), 8)) - frac = (xyz_ll(inner) - xyz_ll_plot(inner)) / width(inner) - inrange(2) = int((ONE - frac) * real(pl % pixels(2), 8)) - - ! draw lines - do out_ = outrange(1), outrange(2) - do plus = 0, pl % meshlines_width - data(:, out_ + 1, inrange(1) + plus + 1) = rgb - data(:, out_ + 1, inrange(2) + plus + 1) = rgb - data(:, out_ + 1, inrange(1) - plus + 1) = rgb - data(:, out_ + 1, inrange(2) - plus + 1) = rgb - end do - end do - do in_ = inrange(1), inrange(2) - do plus = 0, pl % meshlines_width - data(:, outrange(1) + plus + 1, in_ + 1) = rgb - data(:, outrange(2) + plus + 1, in_ + 1) = rgb - data(:, outrange(1) - plus + 1, in_ + 1) = rgb - data(:, outrange(2) - plus + 1, in_ + 1) = rgb - end do - end do - - end if - end do - end do - - end subroutine draw_mesh_lines - !=============================================================================== ! CREATE_VOXEL outputs a binary file that can be input into silomesh for 3D ! geometry visualization. It works the same way as create_ppm by dragging a From fc67e62911847276afd8600eb9641287f2c63572 Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Tue, 9 Oct 2018 19:47:03 -0500 Subject: [PATCH 020/105] Correction to make sure results match current expected output. --- src/plot.cpp | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/src/plot.cpp b/src/plot.cpp index 427891781..d29eb377c 100644 --- a/src/plot.cpp +++ b/src/plot.cpp @@ -216,6 +216,8 @@ void position_rgb(Particle* p, ObjectPlot* pl, int rgb[3], int &id) { } } // Close file + // THIS IS HERE TO MATCH FORTRAN VERSION, NOT NECESSARY + of << std::endl; of.close(); } @@ -272,8 +274,8 @@ void draw_mesh_lines(ObjectPlot *pl, int outrange[3], inrange[3]; double xyz_ll[3], xyz_ur[3]; // sweep through all meshbins on this plane and draw borders - for (int i = ijk_ll[outer]; i < ijk_ur[outer]; i++) { - for (int j = ijk_ll[inner]; j < ijk_ur[inner]; j++) { + for (int i = ijk_ll[outer]; i <= ijk_ur[outer] + 1; i++) { + for (int j = ijk_ll[inner]; j <= ijk_ur[inner] + 1; j++) { // check if we're in the mesh for this ijk if (i > 0 && i <= m->shape_[outer] && j >0 && j <= m->shape_[inner] ) { @@ -295,21 +297,21 @@ void draw_mesh_lines(ObjectPlot *pl, inrange[1] = int((ONE - frac) * (double)pl->pixels[1]); // draw lines - for (int out_ = outrange[0]; out_ < outrange[1]; out_++) { + for (int out_ = outrange[0]; out_ <= outrange[1]; out_++) { for (int plus = 0; plus <= pl->meshlines_width; plus++) { - data[out_ + 1][inrange[0] + plus + 1] = rgb; - data[out_ + 1][inrange[1] + plus + 1] = rgb; - data[out_ + 1][inrange[0] - plus + 1] = rgb; - data[out_ + 1][inrange[1] - plus + 1] = rgb; + data[out_][inrange[0] + plus] = rgb; + data[out_][inrange[1] + plus] = rgb; + data[out_][inrange[0] - plus] = rgb; + data[out_][inrange[1] - plus] = rgb; } } - for (int in_ = inrange[0]; in_ < inrange[1]; in_++) { + for (int in_ = inrange[0]; in_ <= inrange[1]; in_++) { for (int plus = 0; plus <= pl->meshlines_width; plus++) { - data[outrange[0] + plus + 1][in_ + 1] = rgb; - data[outrange[1] + plus + 1][in_ + 1] = rgb; - data[outrange[0] - plus + 1][in_ + 1] = rgb; - data[outrange[1] - plus + 1][in_ + 1] = rgb; + data[outrange[0] + plus][in_] = rgb; + data[outrange[1] + plus][in_] = rgb; + data[outrange[0] - plus][in_] = rgb; + data[outrange[1] - plus][in_] = rgb; } } From 280452345b1dd8fff754cc774a8f0b38f5a97242 Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Tue, 9 Oct 2018 19:50:08 -0500 Subject: [PATCH 021/105] Making index conversion more obvious. --- src/plot.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/plot.cpp b/src/plot.cpp index d29eb377c..6c98225c0 100644 --- a/src/plot.cpp +++ b/src/plot.cpp @@ -270,12 +270,15 @@ void draw_mesh_lines(ObjectPlot *pl, m->get_indices(Position(xyz_ll_plot), &(ijk_ll[0]), &in_mesh); m->get_indices(Position(xyz_ur_plot), &(ijk_ur[0]), &in_mesh); + // Fortran/C++ index correction + ijk_ur[0]++; ijk_ur[1]++; ijk_ur[2]++; + double frac; int outrange[3], inrange[3]; double xyz_ll[3], xyz_ur[3]; // sweep through all meshbins on this plane and draw borders - for (int i = ijk_ll[outer]; i <= ijk_ur[outer] + 1; i++) { - for (int j = ijk_ll[inner]; j <= ijk_ur[inner] + 1; j++) { + for (int i = ijk_ll[outer]; i <= ijk_ur[outer]; i++) { + for (int j = ijk_ll[inner]; j <= ijk_ur[inner]; j++) { // check if we're in the mesh for this ijk if (i > 0 && i <= m->shape_[outer] && j >0 && j <= m->shape_[inner] ) { From 66adf061465da9649abb1f70f1aee804b62c2f1c Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Tue, 9 Oct 2018 19:56:32 -0500 Subject: [PATCH 022/105] Adding a typedef and removing some whitespace. --- include/openmc/plot.h | 22 ++++++++++++---------- src/plot.F90 | 2 +- src/plot.cpp | 30 +++++++++++++----------------- 3 files changed, 26 insertions(+), 28 deletions(-) diff --git a/include/openmc/plot.h b/include/openmc/plot.h index e64ecc2f7..be9030fa7 100644 --- a/include/openmc/plot.h +++ b/include/openmc/plot.h @@ -11,16 +11,18 @@ namespace openmc { + typedef std::vector< std::vector< std::vector > > ImageData; + class ObjectPlot; - + int PLOT_LEVEL_LOWEST = -1; std::map plot_dict; - + std::vector n_plots; std::vector plots; - + enum PLOT_TYPE { SLICE = 1, VOXEL = 2 @@ -48,7 +50,7 @@ namespace openmc { //=============================================================================== // ObjectPlot holds plot information //=============================================================================== - + struct ObjectPlot { int id; int type; @@ -64,25 +66,25 @@ namespace openmc { ObjectColor not_found; ObjectColor colors[MAX_COORD]; char path_plot[MAX_WORD_LEN]; - + }; void draw_mesh_lines(ObjectPlot* pl, std::vector< std::vector< std::vector > > &data); - + void output_ppm(ObjectPlot* pl, const std::vector< std::vector< std::vector > > &data); - + extern "C" void create_ppm(ObjectPlot* pl); - + extern "C" void position_rgb(Particle* p, ObjectPlot* pl, int rgb[3], int &id); - + extern "C" void voxel_init(hid_t file_id, const hsize_t* dims, hid_t* dspace, hid_t* dset, hid_t* memspace); extern "C" void voxel_write_slice(int x, hid_t dspace, hid_t dset, hid_t memspace, void* buf); extern "C" void voxel_finalize(hid_t dspace, hid_t dset, hid_t memspace); - + } // namespace openmc #endif // OPENMC_PLOT_H diff --git a/src/plot.F90 b/src/plot.F90 index d2e81308f..8e41dcb1b 100644 --- a/src/plot.F90 +++ b/src/plot.F90 @@ -39,7 +39,7 @@ module plot import ObjectPlot type(ObjectPlot), intent(in) :: pl end subroutine create_ppm - + end interface contains diff --git a/src/plot.cpp b/src/plot.cpp index 6c98225c0..9e5d34286 100644 --- a/src/plot.cpp +++ b/src/plot.cpp @@ -63,8 +63,7 @@ void create_ppm(ObjectPlot* pl) { double in_pixel = (pl->width[0])/double(width); double out_pixel = (pl->width[1])/double(height); - std::vector< std::vector< std::vector > > data; - + ImageData data; data.resize(width); for (auto & i : data) { i.resize(height); @@ -117,7 +116,7 @@ void create_ppm(ObjectPlot* pl) { } if (pl->index_meshlines_mesh >= 0) { draw_mesh_lines(pl, data); } - + output_ppm(pl, data); } @@ -188,17 +187,15 @@ void position_rgb(Particle* p, ObjectPlot* pl, int rgb[3], int &id) { // OUTPUT_PPM writes out a previously generated image to a PPM file //=============================================================================== - void output_ppm(ObjectPlot* pl, - const std::vector< std::vector< std::vector > > &data) +void output_ppm(ObjectPlot* pl, const ImageData &data) { - // Open PPM file for writing std::string fname = std::string(pl->path_plot); fname = strtrim(fname); std::ofstream of; of.open(fname); - + // Write header of << "P6" << std::endl; of << pl->pixels[0] << " " << pl->pixels[1] << std::endl; @@ -216,18 +213,17 @@ void position_rgb(Particle* p, ObjectPlot* pl, int rgb[3], int &id) { } } // Close file - // THIS IS HERE TO MATCH FORTRAN VERSION, NOT NECESSARY - of << std::endl; + // THIS IS HERE TO MATCH FORTRAN VERSION, NOT NECESSARY + of << std::endl; of.close(); } //=============================================================================== // DRAW_MESH_LINES draws mesh line boundaries on an image //=============================================================================== - -void draw_mesh_lines(ObjectPlot *pl, - std::vector< std::vector< std::vector > > &data) { +void draw_mesh_lines(ObjectPlot *pl, ImageData &data) +{ std::vector rgb; rgb.resize(3); rgb[0] = pl->meshlines_color.rgb[0]; rgb[1] = pl->meshlines_color.rgb[1]; @@ -272,16 +268,16 @@ void draw_mesh_lines(ObjectPlot *pl, // Fortran/C++ index correction ijk_ur[0]++; ijk_ur[1]++; ijk_ur[2]++; - + double frac; int outrange[3], inrange[3]; double xyz_ll[3], xyz_ur[3]; - // sweep through all meshbins on this plane and draw borders + // sweep through all meshbins on this plane and draw borders for (int i = ijk_ll[outer]; i <= ijk_ur[outer]; i++) { for (int j = ijk_ll[inner]; j <= ijk_ur[inner]; j++) { // check if we're in the mesh for this ijk if (i > 0 && i <= m->shape_[outer] && j >0 && j <= m->shape_[inner] ) { - + // get xyz's of lower left and upper right of this mesh cell xyz_ll[outer] = m->lower_left_[outer] + m->width_[outer] * (i - 1); xyz_ll[inner] = m->lower_left_[inner] + m->width_[inner] * (j - 1); @@ -321,9 +317,9 @@ void draw_mesh_lines(ObjectPlot *pl, } // end if(in mesh) } } // end outer loops - + } - + void voxel_init(hid_t file_id, const hsize_t* dims, hid_t* dspace, hid_t* dset, hid_t* memspace) From 379bb3d1664b5881679c37d38ffe3dd522edd796 Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Tue, 9 Oct 2018 20:29:08 -0500 Subject: [PATCH 023/105] Moving to a switch for the plot basis cases. --- src/plot.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/plot.cpp b/src/plot.cpp index 9e5d34286..2f6416d3b 100644 --- a/src/plot.cpp +++ b/src/plot.cpp @@ -74,24 +74,28 @@ void create_ppm(ObjectPlot* pl) { int in_i, out_i; double xyz[3]; - if (PLOT_BASIS::XY == pl->basis) { + switch(pl->basis) { + case PLOT_BASIS::XY : in_i = 0; out_i = 1; xyz[0] = pl->origin[0] - pl->width[0] / TWO; xyz[1] = pl->origin[1] + pl->width[1] / TWO; xyz[2] = pl->origin[2]; - } else if (PLOT_BASIS::XZ == pl->basis) { + break; + case PLOT_BASIS::XZ : in_i = 0; out_i = 2; xyz[0] = pl->origin[0] - pl->width[0] / TWO; xyz[1] = pl->origin[1]; xyz[2] = pl->origin[2] + pl->width[1] / TWO; - } else if (PLOT_BASIS::YZ == pl->basis) { + break; + case PLOT_BASIS::YZ : in_i = 1; out_i = 2; xyz[0] = pl->origin[0]; xyz[1] = pl->origin[1] - pl->width[0] / TWO; xyz[2] = pl->origin[2] + pl->width[1] / TWO; + break; } double dir[3] = {HALF, HALF, HALF}; From 2e48c8178ccbe6dc2e9236d82ebaa674a6be88c7 Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Tue, 9 Oct 2018 20:35:58 -0500 Subject: [PATCH 024/105] Updating rgb values to named indexing. --- src/plot.cpp | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/plot.cpp b/src/plot.cpp index 2f6416d3b..4bbd8b5a0 100644 --- a/src/plot.cpp +++ b/src/plot.cpp @@ -13,9 +13,9 @@ namespace openmc { -const int RED = 1; -const int GREEN = 2; -const int BLUE = 3; +const int RED = 0; +const int GREEN = 1; +const int BLUE = 2; const int WHITE[3] = {255, 255, 255}; const int NULLRGB[3] = {0, 0, 0}; @@ -113,9 +113,9 @@ void create_ppm(ObjectPlot* pl) { for (int x = 0; x < width; x++) { p->coord[0].xyz[in_i] = xyz[in_i] + in_pixel*(x); position_rgb(p, pl, rgb, id); - data[x][y][0] = rgb[0]; - data[x][y][1] = rgb[1]; - data[x][y][2] = rgb[2]; + data[x][y][RED] = rgb[RED]; + data[x][y][GREEN] = rgb[GREEN]; + data[x][y][BLUE] = rgb[BLUE]; } } @@ -211,9 +211,9 @@ void output_ppm(ObjectPlot* pl, const ImageData &data) for (int y = 0; y < pl->pixels[1]; y++) { for (int x = 0; x < pl->pixels[0]; x++) { std::vector rgb = data[x][y]; - of.write((char*)&rgb[0], 1); - of.write((char*)&rgb[1], 1); - of.write((char*)&rgb[2], 1); + of.write((char*)&rgb[RED], 1); + of.write((char*)&rgb[GREEN], 1); + of.write((char*)&rgb[BLUE], 1); } } // Close file @@ -229,9 +229,9 @@ void output_ppm(ObjectPlot* pl, const ImageData &data) void draw_mesh_lines(ObjectPlot *pl, ImageData &data) { std::vector rgb; rgb.resize(3); - rgb[0] = pl->meshlines_color.rgb[0]; - rgb[1] = pl->meshlines_color.rgb[1]; - rgb[2] = pl->meshlines_color.rgb[2]; + rgb[RED] = pl->meshlines_color.rgb[RED]; + rgb[GREEN] = pl->meshlines_color.rgb[GREEN]; + rgb[BLUE] = pl->meshlines_color.rgb[BLUE]; int outer, inner; switch(pl->basis){ From a83ea14a868bd4cf546b0c296f24d9856a48238d Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Tue, 9 Oct 2018 21:19:41 -0500 Subject: [PATCH 025/105] Adding create_voxel to c++. --- src/plot.cpp | 109 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 109 insertions(+) diff --git a/src/plot.cpp b/src/plot.cpp index 4bbd8b5a0..6f48eec22 100644 --- a/src/plot.cpp +++ b/src/plot.cpp @@ -10,6 +10,8 @@ #include "openmc/material.h" #include "openmc/string_functions.h" #include "openmc/mesh.h" +#include "openmc/output.h" +#include "openmc/hdf5_interface.h" namespace openmc { @@ -324,6 +326,113 @@ void draw_mesh_lines(ObjectPlot *pl, ImageData &data) } +//=============================================================================== +// CREATE_VOXEL outputs a binary file that can be input into silomesh for 3D +// geometry visualization. It works the same way as create_ppm by dragging a +// particle across the geometry for the specified number of voxels. The first +// 3 int(4)'s in the binary are the number of x, y, and z voxels. The next 3 +// real(8)'s are the widths of the voxels in the x, y, and z directions. The next +// 3 real(8)'s are the x, y, and z coordinates of the lower left point. Finally +// the binary is filled with entries of four int(4)'s each. Each 'row' in the +// binary contains four int(4)'s: 3 for x,y,z position and 1 for cell or material +// id. For 1 million voxels this produces a file of approximately 15MB. +//=============================================================================== + +void create_voxel(ObjectPlot *pl) { + + // compute voxel widths in each direction + double vox[3]; + vox[0] = pl->width[0]/(double)pl->pixels[0]; + vox[1] = pl->width[1]/(double)pl->pixels[1]; + vox[2] = pl->width[2]/(double)pl->pixels[2]; + + // initial particle position + double ll[3]; + ll[0] = pl->origin[0] - pl->width[0] / TWO; + ll[1] = pl->origin[1] - pl->width[1] / TWO; + ll[2] = pl->origin[2] - pl->width[2] / TWO; + + // allocate and initialize particle + double dir[3] = {HALF, HALF, HALF}; + Particle *p = new Particle(); + p->initialize(); + std::copy(ll, ll + 3, p->coord[0].xyz); + std::copy(dir, dir + 3, p->coord[0].uvw); + p->coord[0].universe = openmc_root_universe; + + // Open binary plot file for writing + std::ofstream of; + std::string fname = std::string(pl->path_plot); + fname = strtrim(fname); + hid_t file_id = file_open(fname, 'w'); + + // write header info + write_attribute(file_id, "filetype", 'voxel'); + write_attribute(file_id, "version", VERSION_VOXEL); + write_attribute(file_id, "openmc_version", VERSION); + +#ifdef GIT_SHA1 + write_attribute(file_id, "git_sha1", GIT_SHA1); +#endif + + // Write current date and time + // write_attribute(file_id, "date_and_time", time_stamp()); + hsize_t three = 3; + write_attr_int(file_id, 1, &three, "num_voxels", pl->pixels); + write_attr_double(file_id, 1, &three, "voxel_width", vox); + write_attr_double(file_id, 1, &three, "lower_left", ll); + + hsize_t dims[3]; + dims[0] = pl->pixels[0]; + dims[1] = pl->pixels[1]; + dims[2] = pl->pixels[2]; + hid_t dspace, dset, memspace; + voxel_init(file_id, &(dims[0]), &dspace, &dset, &memspace); + + ll[0] = ll[0] + vox[0] / TWO; + ll[1] = ll[1] + vox[1] / TWO; + ll[2] = ll[2] + vox[2] / TWO; + + ImageData data; + + + data.resize(pl->pixels[2]); + for (auto & i : data) { + i.resize(pl->pixels[1]); + for (auto & j : i) { + j.resize(1); + } + } + + int rgb[3], id; + for (int x = 0; x < pl->pixels[0]; x++) { + // progress bar here + for (int y = 0; y < pl->pixels[1]; y++) { + for(int z = 0; z < pl->pixels[2]; z++) { + // get voxel color + position_rgb(p, pl, rgb, id); + // advance particle in z direction + p->coord[0].xyz[2] = p->coord[0].xyz[2] + vox[2]; + } + // advance particle in y direction + p->coord[0].xyz[1] = p->coord[0].xyz[1] + vox[1]; + p->coord[0].xyz[2] = ll[2]; + } + // advance particle in x direction + p->coord[0].xyz[0] = p->coord[0].xyz[0] + vox[0]; + p->coord[0].xyz[1] = ll[1]; + p->coord[0].xyz[2] = ll[2]; + + // Write to HDF5 dataset + voxel_write_slice(x, dspace, dset, memspace, &(data[0])); + } + + voxel_finalize(dspace, dset, memspace); + file_close(file_id); + +} + + void voxel_init(hid_t file_id, const hsize_t* dims, hid_t* dspace, hid_t* dset, hid_t* memspace) From 3fab6fdb2e5cb962477e0aa70cddbfb09acf94a4 Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Tue, 9 Oct 2018 22:10:38 -0500 Subject: [PATCH 026/105] Exposing C++ create_voxel, fixing indexing bug, and removing fortran implementation. --- include/openmc/plot.h | 2 + src/plot.F90 | 131 ++---------------------------------------- src/plot.cpp | 33 +++++------ 3 files changed, 21 insertions(+), 145 deletions(-) diff --git a/include/openmc/plot.h b/include/openmc/plot.h index be9030fa7..689a156a7 100644 --- a/include/openmc/plot.h +++ b/include/openmc/plot.h @@ -78,6 +78,8 @@ void output_ppm(ObjectPlot* pl, extern "C" void create_ppm(ObjectPlot* pl); +extern "C" void create_voxel(ObjectPlot *pl); + extern "C" void position_rgb(Particle* p, ObjectPlot* pl, int rgb[3], int &id); extern "C" void voxel_init(hid_t file_id, const hsize_t* dims, hid_t* dspace, diff --git a/src/plot.F90 b/src/plot.F90 index 8e41dcb1b..79b286924 100644 --- a/src/plot.F90 +++ b/src/plot.F90 @@ -40,6 +40,11 @@ module plot type(ObjectPlot), intent(in) :: pl end subroutine create_ppm + subroutine create_voxel(pl) bind(C) + import ObjectPlot + type(ObjectPlot), intent(in) :: pl + end subroutine create_voxel + end interface contains @@ -71,130 +76,4 @@ contains err = 0 end function openmc_plot_geometry -!=============================================================================== -! CREATE_VOXEL outputs a binary file that can be input into silomesh for 3D -! geometry visualization. It works the same way as create_ppm by dragging a -! particle across the geometry for the specified number of voxels. The first -! 3 int(4)'s in the binary are the number of x, y, and z voxels. The next 3 -! real(8)'s are the widths of the voxels in the x, y, and z directions. The next -! 3 real(8)'s are the x, y, and z coordinates of the lower left point. Finally -! the binary is filled with entries of four int(4)'s each. Each 'row' in the -! binary contains four int(4)'s: 3 for x,y,z position and 1 for cell or material -! id. For 1 million voxels this produces a file of approximately 15MB. -!=============================================================================== - - subroutine create_voxel(pl) - type(ObjectPlot), intent(in) :: pl - - integer(C_INT) :: x, y, z ! voxel location indices - integer :: rgb(3) ! colors (red, green, blue) from 0-255 - integer :: id ! id of cell or material - integer(C_INT), target :: data(pl%pixels(3),pl%pixels(2)) - integer(HID_T) :: file_id - integer(HID_T) :: dspace - integer(HID_T) :: memspace - integer(HID_T) :: dset - integer(HSIZE_T) :: dims(3) - real(8) :: vox(3) ! x, y, and z voxel widths - real(8) :: ll(3) ! lower left starting point for each sweep direction - type(Particle) :: p - type(ProgressBar) :: progress - - interface - subroutine voxel_init(file_id, dims, dspace, dset, memspace) bind(C) - import HID_T, HSIZE_T - integer(HID_T), value :: file_id - integer(HSIZE_T), intent(in) :: dims(*) - integer(HID_T), intent(out) :: dspace - integer(HID_T), intent(out) :: dset - integer(HID_T), intent(out) :: memspace - end subroutine voxel_init - - subroutine voxel_write_slice(x, dspace, dset, memspace, buf) bind(C) - import C_INT, HID_T, C_PTR - integer(C_INT), value :: x - integer(HID_T), value :: dspace - integer(HID_T), value :: dset - integer(HID_T), value :: memspace - type(C_PTR), value :: buf - end subroutine voxel_write_slice - - subroutine voxel_finalize(dspace, dset, memspace) bind(C) - import HID_T - integer(HID_T), value :: dspace - integer(HID_T), value :: dset - integer(HID_T), value :: memspace - end subroutine voxel_finalize - end interface - - ! compute voxel widths in each direction - vox = pl % width/dble(pl % pixels) - - ! initial particle position - ll = pl % origin - pl % width / TWO - - ! allocate and initialize particle - call particle_initialize(p) - p % coord(1) % xyz = ll - p % coord(1) % uvw = [ HALF, HALF, HALF ] - p % coord(1) % universe = root_universe - - ! Open binary plot file for writing - file_id = file_open(pl%path_plot, 'w') - - ! write header info - call write_attribute(file_id, "filetype", 'voxel') - call write_attribute(file_id, "version", VERSION_VOXEL) - call write_attribute(file_id, "openmc_version", VERSION) -#ifdef GIT_SHA1 - call write_attribute(file_id, "git_sha1", GIT_SHA1) -#endif - - ! Write current date and time - call write_attribute(file_id, "date_and_time", time_stamp()) - - call write_attribute(file_id, "num_voxels", pl%pixels) - call write_attribute(file_id, "voxel_width", vox) - call write_attribute(file_id, "lower_left", ll) - - ! Create dataset for voxel data -- note that the dimensions are reversed - ! since we want the order in the file to be z, y, x - dims(:) = pl % pixels - call voxel_init(file_id, dims, dspace, dset, memspace) - - ! move to center of voxels - ll = ll + vox / TWO - - do x = 1, pl % pixels(1) - call progress % set_value(dble(x)/dble(pl % pixels(1))*100) - do y = 1, pl % pixels(2) - do z = 1, pl % pixels(3) - ! get voxel color - call position_rgb(p, pl, rgb, id) - ! write to plot file - data(z,y) = id - - ! advance particle in z direction - p % coord(1) % xyz(3) = p % coord(1) % xyz(3) + vox(3) - end do - - ! advance particle in y direction - p % coord(1) % xyz(2) = p % coord(1) % xyz(2) + vox(2) - p % coord(1) % xyz(3) = ll(3) - end do - - ! advance particle in y direction - p % coord(1) % xyz(1) = p % coord(1) % xyz(1) + vox(1) - p % coord(1) % xyz(2) = ll(2) - p % coord(1) % xyz(3) = ll(3) - - ! Write to HDF5 dataset - call voxel_write_slice(x, dspace, dset, memspace, c_loc(data)) - end do - - call voxel_finalize(dspace, dset, memspace) - call file_close(file_id) - - end subroutine create_voxel - end module plot diff --git a/src/plot.cpp b/src/plot.cpp index 6f48eec22..1042ccd78 100644 --- a/src/plot.cpp +++ b/src/plot.cpp @@ -376,33 +376,27 @@ void create_voxel(ObjectPlot *pl) { #endif // Write current date and time - // write_attribute(file_id, "date_and_time", time_stamp()); + // write_attribute(file_id, "date_and_time", time_stamp()); <-- RE-ADD!!! hsize_t three = 3; write_attr_int(file_id, 1, &three, "num_voxels", pl->pixels); write_attr_double(file_id, 1, &three, "voxel_width", vox); write_attr_double(file_id, 1, &three, "lower_left", ll); + // Create dataset for voxel data -- note that the dimensions are reversed + // since we want the order in the file to be z, y, x hsize_t dims[3]; dims[0] = pl->pixels[0]; dims[1] = pl->pixels[1]; dims[2] = pl->pixels[2]; hid_t dspace, dset, memspace; voxel_init(file_id, &(dims[0]), &dspace, &dset, &memspace); - + + // move to center of voxels ll[0] = ll[0] + vox[0] / TWO; ll[1] = ll[1] + vox[1] / TWO; ll[2] = ll[2] + vox[2] / TWO; - ImageData data; - - - data.resize(pl->pixels[2]); - for (auto & i : data) { - i.resize(pl->pixels[1]); - for (auto & j : i) { - j.resize(1); - } - } + int data[pl->pixels[1]][pl->pixels[2]]; int rgb[3], id; for (int x = 0; x < pl->pixels[0]; x++) { @@ -411,6 +405,8 @@ void create_voxel(ObjectPlot *pl) { for(int z = 0; z < pl->pixels[2]; z++) { // get voxel color position_rgb(p, pl, rgb, id); + // write to plot data + data[y][z] = id; // advance particle in z direction p->coord[0].xyz[2] = p->coord[0].xyz[2] + vox[2]; } @@ -419,12 +415,11 @@ void create_voxel(ObjectPlot *pl) { p->coord[0].xyz[2] = ll[2]; } // advance particle in x direction - p->coord[0].xyz[0] = p->coord[0].xyz[0] + vox[0]; - p->coord[0].xyz[1] = ll[1]; - p->coord[0].xyz[2] = ll[2]; - - // Write to HDF5 dataset - voxel_write_slice(x, dspace, dset, memspace, &(data[0])); + p->coord[0].xyz[0] = p->coord[0].xyz[0] + vox[0]; + p->coord[0].xyz[1] = ll[1]; + p->coord[0].xyz[2] = ll[2]; + // Write to HDF5 dataset + voxel_write_slice(x, dspace, dset, memspace, &(data[0])); } voxel_finalize(dspace, dset, memspace); @@ -456,7 +451,7 @@ voxel_init(hid_t file_id, const hsize_t* dims, hid_t* dspace, hid_t* dset, void voxel_write_slice(int x, hid_t dspace, hid_t dset, hid_t memspace, void* buf) { - hssize_t offset[3] {x - 1, 0, 0}; + hssize_t offset[3] {x, 0, 0}; H5Soffset_simple(dspace, offset); H5Dwrite(dset, H5T_NATIVE_INT, memspace, dspace, H5P_DEFAULT, buf); } From 7b93499d116bddc3c098b70534a3002317bfb170 Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Tue, 9 Oct 2018 22:24:59 -0500 Subject: [PATCH 027/105] Removing now-unused fortran code and cleaning up style a bit. --- include/openmc/plot.h | 22 +++++++++++----------- src/plot.F90 | 25 +------------------------ src/plot.cpp | 11 +++++------ 3 files changed, 17 insertions(+), 41 deletions(-) diff --git a/include/openmc/plot.h b/include/openmc/plot.h index 689a156a7..acc364812 100644 --- a/include/openmc/plot.h +++ b/include/openmc/plot.h @@ -69,24 +69,24 @@ namespace openmc { }; -void draw_mesh_lines(ObjectPlot* pl, - std::vector< std::vector< std::vector > > &data); - - -void output_ppm(ObjectPlot* pl, - const std::vector< std::vector< std::vector > > &data); extern "C" void create_ppm(ObjectPlot* pl); extern "C" void create_voxel(ObjectPlot *pl); - -extern "C" void position_rgb(Particle* p, ObjectPlot* pl, int rgb[3], int &id); -extern "C" void voxel_init(hid_t file_id, const hsize_t* dims, hid_t* dspace, +void draw_mesh_lines(ObjectPlot* pl, + std::vector< std::vector< std::vector > > &data); + +void output_ppm(ObjectPlot* pl, + const std::vector< std::vector< std::vector > > &data); + +void position_rgb(Particle* p, ObjectPlot* pl, int rgb[3], int &id); + +void voxel_init(hid_t file_id, const hsize_t* dims, hid_t* dspace, hid_t* dset, hid_t* memspace); -extern "C" void voxel_write_slice(int x, hid_t dspace, hid_t dset, +void voxel_write_slice(int x, hid_t dspace, hid_t dset, hid_t memspace, void* buf); -extern "C" void voxel_finalize(hid_t dspace, hid_t dset, hid_t memspace); +void voxel_finalize(hid_t dspace, hid_t dset, hid_t memspace); } // namespace openmc #endif // OPENMC_PLOT_H diff --git a/src/plot.F90 b/src/plot.F90 index 79b286924..329cbca55 100644 --- a/src/plot.F90 +++ b/src/plot.F90 @@ -2,18 +2,9 @@ module plot use, intrinsic :: ISO_C_BINDING - use constants - use error, only: fatal_error, write_message - use geometry, only: find_cell, check_cell_overlap - use geometry_header, only: Cell, root_universe, cells - use hdf5_interface - use output, only: time_stamp - use material_header, only: materials - use mesh_header, only: meshes, RegularMesh + use error, only: write_message use particle_header use plot_header - use progress_header, only: ProgressBar - use settings, only: check_overlaps use string, only: to_str implicit none @@ -21,20 +12,7 @@ module plot public :: openmc_plot_geometry - integer, parameter :: RED = 1 - integer, parameter :: GREEN = 2 - integer, parameter :: BLUE = 3 - interface - subroutine position_rgb(p, pl, rgb, id) bind(C) - import Particle, ObjectPlot, C_INT - type(Particle), intent(inout) :: p - type(ObjectPlot), intent(in) :: pl - integer(C_INT), intent(out) :: rgb(3) - integer(C_INT), intent(out) :: id - end subroutine position_rgb - - subroutine create_ppm(pl) bind(C) import ObjectPlot type(ObjectPlot), intent(in) :: pl @@ -44,7 +22,6 @@ module plot import ObjectPlot type(ObjectPlot), intent(in) :: pl end subroutine create_voxel - end interface contains diff --git a/src/plot.cpp b/src/plot.cpp index 1042ccd78..a1acebfe6 100644 --- a/src/plot.cpp +++ b/src/plot.cpp @@ -39,16 +39,15 @@ int openmc_plot_geometry() { if (PLOT_TYPE::SLICE == pl->type) { // create 2D image - // create_ppm(pl); + create_ppm(pl); continue; } else if (PLOT_TYPE::VOXEL == pl->type) { // create voxel file for 3D viewing - // create_voxel(pl); + create_voxel(pl); continue; } } - return 0; } @@ -397,7 +396,7 @@ void create_voxel(ObjectPlot *pl) { ll[2] = ll[2] + vox[2] / TWO; int data[pl->pixels[1]][pl->pixels[2]]; - + int rgb[3], id; for (int x = 0; x < pl->pixels[0]; x++) { // progress bar here @@ -424,10 +423,10 @@ void create_voxel(ObjectPlot *pl) { voxel_finalize(dspace, dset, memspace); file_close(file_id); - + } - + void voxel_init(hid_t file_id, const hsize_t* dims, hid_t* dspace, hid_t* dset, hid_t* memspace) From 2bffc33452e01d1197a723f778db4f36864ec24b Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Wed, 10 Oct 2018 09:33:29 -0500 Subject: [PATCH 028/105] Adding get_child_nodes function to C++ xml_interface. --- include/openmc/xml_interface.h | 7 +++++++ src/xml_interface.cpp | 16 ++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/include/openmc/xml_interface.h b/include/openmc/xml_interface.h index 85db26faa..8bf0f2174 100644 --- a/include/openmc/xml_interface.h +++ b/include/openmc/xml_interface.h @@ -50,5 +50,12 @@ xt::xarray get_node_xarray(pugi::xml_node node, const char* name, return xt::adapt(v, shape); } +//=============================================================================== +// GET_NODE_LIST is used to get a pointer to a list of sub-element nodes +//=============================================================================== + +std::vector +get_child_nodes(pugi::xml_node node, const char* name); + } // namespace openmc #endif // OPENMC_XML_INTERFACE_H diff --git a/src/xml_interface.cpp b/src/xml_interface.cpp index 60ae7ffca..c9b7bbcab 100644 --- a/src/xml_interface.cpp +++ b/src/xml_interface.cpp @@ -56,4 +56,20 @@ get_node_value_bool(pugi::xml_node node, const char* name) return false; } + + +std::vector +get_child_nodes(pugi::xml_node node, const char* name) +{ + pugi::xml_node current; + std::vector node_list; + + for (pugi::xml_node current : node.children(name)) { + node_list.push_back(current); + } + + return node_list; +} + + } // namespace openmc From fea2c3cc04d1de0108117a413beba446397b6cb0 Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Wed, 10 Oct 2018 16:09:01 -0500 Subject: [PATCH 029/105] Creating a common word_count functions for strings. --- include/openmc/string_functions.h | 2 ++ src/string_functions.cpp | 12 ++++++++++++ src/surface.cpp | 18 ------------------ 3 files changed, 14 insertions(+), 18 deletions(-) diff --git a/include/openmc/string_functions.h b/include/openmc/string_functions.h index a3da179a0..acbbe4e1d 100644 --- a/include/openmc/string_functions.h +++ b/include/openmc/string_functions.h @@ -14,5 +14,7 @@ char* strtrim(char* c_str); void to_lower(std::string& str); +int word_count(std::string const& str); + } // namespace openmc #endif // STRING_FUNCTIONS_H diff --git a/src/string_functions.cpp b/src/string_functions.cpp index f81b09aef..6c077c8c0 100644 --- a/src/string_functions.cpp +++ b/src/string_functions.cpp @@ -1,4 +1,5 @@ #include "openmc/string_functions.h" +#include namespace openmc { @@ -27,4 +28,15 @@ void to_lower(std::string& str) for (int i = 0; i < str.size(); i++) str[i] = std::tolower(str[i]); } +int word_count(std::string const& str) { + std::stringstream stream(str); + std::string dum; + int count = 0; + while(stream >> dum) { count++; } + return count; +} + } // namespace openmc + + + diff --git a/src/surface.cpp b/src/surface.cpp index bf1c2e58c..f535615e8 100644 --- a/src/surface.cpp +++ b/src/surface.cpp @@ -35,24 +35,6 @@ std::map surface_map; // Helper functions for reading the "coeffs" node of an XML surface element //============================================================================== -int word_count(const std::string &text) -{ - bool in_word = false; - int count {0}; - for (auto c = text.begin(); c != text.end(); c++) { - if (std::isspace(*c)) { - if (in_word) { - in_word = false; - count++; - } - } else { - in_word = true; - } - } - if (in_word) count++; - return count; -} - void read_coeffs(pugi::xml_node surf_node, int surf_id, double &c1) { // Check the given number of coefficients. From f725e2c532b33170f0b91b990fbf3d68fbfa86d2 Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Wed, 10 Oct 2018 16:09:34 -0500 Subject: [PATCH 030/105] Adding a C++ version of node_word_count --- include/openmc/xml_interface.h | 6 ++++-- src/xml_interface.cpp | 7 ++++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/include/openmc/xml_interface.h b/include/openmc/xml_interface.h index 8bf0f2174..e8248ca86 100644 --- a/include/openmc/xml_interface.h +++ b/include/openmc/xml_interface.h @@ -9,7 +9,7 @@ #include "pugixml.hpp" #include "xtensor/xarray.hpp" #include "xtensor/xadapt.hpp" - +#include "openmc/string_functions.h" namespace openmc { @@ -56,6 +56,8 @@ xt::xarray get_node_xarray(pugi::xml_node node, const char* name, std::vector get_child_nodes(pugi::xml_node node, const char* name); - + +int node_word_count(pugi::xml_node node, const char* name); + } // namespace openmc #endif // OPENMC_XML_INTERFACE_H diff --git a/src/xml_interface.cpp b/src/xml_interface.cpp index c9b7bbcab..82c59a27b 100644 --- a/src/xml_interface.cpp +++ b/src/xml_interface.cpp @@ -71,5 +71,10 @@ get_child_nodes(pugi::xml_node node, const char* name) return node_list; } - +int node_word_count(pugi::xml_node node, const char* name) +{ + std::string s = get_node_value(node, name); + return word_count(s); +} + } // namespace openmc From 964b45eea8de92544f815ec0334acf29af55ea23 Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Wed, 10 Oct 2018 17:16:55 -0500 Subject: [PATCH 031/105] 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 From 9599e1d92d1af4adb3fef69d84dfb5f99b8e20ed Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Wed, 10 Oct 2018 18:00:57 -0500 Subject: [PATCH 032/105] Another checkpoint. --- src/plot.cpp | 117 +++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 113 insertions(+), 4 deletions(-) diff --git a/src/plot.cpp b/src/plot.cpp index 240697f0e..f15690cf4 100644 --- a/src/plot.cpp +++ b/src/plot.cpp @@ -370,11 +370,120 @@ ObjectPlot::ObjectPlot(pugi::xml_node plot_node) { } for(auto cn : color_nodes) { - - } - - } + // Check and make sure 3 values are specified for RGB + if (node_word_count(cn, "rgb") != 3) { + std::stringstream err_msg; + err_msg << "Bad RGB in plot " << id; + fatal_error(err_msg); + } + + // Ensure that there is an id for this color specification + // Ensure that there is an id for this color specification + int col_id; + if (check_for_node(cn, "id")) { + col_id = std::stoi(get_node_value(cn, "id")); + } else { + std::stringstream err_msg; + err_msg << "Must specify id for color specification in plot " + << id; + fatal_error(err_msg); + } + // Add RGB + if (PLOT_COLOR_BY::CELLS == color_by) { + std::vector cell_rgb; + if (cell_map.find(col_id) != cell_map.end()) { + col_id = cell_map[col_id]; + cell_rgb = get_node_array(cn, "rgb"); + colors[col_id].rgb[0] = cell_rgb[0]; + colors[col_id].rgb[1] = cell_rgb[1]; + colors[col_id].rgb[2] = cell_rgb[2]; + } else { + std::stringstream err_msg; + err_msg << "Could not find cell " << col_id + << " specified in plot " << id; + fatal_error(err_msg); + } + } else if (PLOT_COLOR_BY::MATS == color_by) { + std::vector mat_rgb; + if (material_map.find(col_id) != material_map.end()) { + col_id = material_map[col_id]; + mat_rgb = get_node_array(cn, "rgb"); + colors[col_id].rgb[0] = mat_rgb[0]; + colors[col_id].rgb[1] = mat_rgb[1]; + colors[col_id].rgb[2] = mat_rgb[2]; + } else { + std::stringstream err_msg; + err_msg << "Could not find material " << col_id + << " specified in plot " << id; + fatal_error(err_msg); + } + } + } // color node loop + } + + + // Deal with meshlines + std::vector mesh_line_nodes; + mesh_line_nodes = get_child_nodes(plot_node, "meshlines"); + + int n_meshlines = mesh_line_nodes.size(); + + if (n_meshlines != 0) { + + if (PLOT_TYPE::VOXEL == type) { + std::stringstream msg; + msg << "Meshlines ignored in voxel plot " << id; + warning(msg); + } + + if (0 == n_meshlines) { + // Skip if no meshlines are specified + } else if (1 == n_meshlines) { + // Get first meshline node + pugi::xml_node meshlines_node = mesh_line_nodes[0]; + + // Check mesh type + std::string meshline_type; + if (check_for_node(meshlines_node, "meshtype")) { + meshline_type = get_node_value(meshlines_node, "meshtype"); + } else { + std::stringstream err_msg; + err_msg << "Must specify a meshtype for meshlines specification in plot " << id; + fatal_error(err_msg); + } + + // Check mesh type + std::string meshline_width; + if (check_for_node(meshlines_node, "linewidth")) { + meshline_width = get_node_value(meshlines_node, "linewidth"); + } else { + std::stringstream err_msg; + err_msg << "Must specify a linewidth for meshlines specification in plot " << id; + fatal_error(err_msg); + } + + // Check for color + std::vector ml_rgb; + if (check_for_node(meshlines_node, "color")) { + // Check and make sure 3 values are specified for RGB + if (node_word_count(meshlines_node, "color") != 3) { + std::stringstream err_msg; + err_msg << "Bad RGB for meshlines color in plot " << id; + fatal_error(err_msg); + } + ml_rgb = get_node_array(meshlines_node, "color"); + meshlines_color.rgb[0] = ml_rgb[0]; + meshlines_color.rgb[1] = ml_rgb[1]; + meshlines_color.rgb[2] = ml_rgb[2]; + } else { + meshlines_color.rgb[0] = 0; + meshlines_color.rgb[1] = 0; + meshlines_color.rgb[2] = 0; + } + + } + } } // End ObjectPlot constructor //=============================================================================== From ce2637f8c5418bdbb635565bfb0f59b28613e310 Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Thu, 11 Oct 2018 15:26:09 -0500 Subject: [PATCH 033/105] Finishing initial implementation in C++. --- src/plot.cpp | 85 ++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 82 insertions(+), 3 deletions(-) diff --git a/src/plot.cpp b/src/plot.cpp index f15690cf4..06ab0cc97 100644 --- a/src/plot.cpp +++ b/src/plot.cpp @@ -59,8 +59,9 @@ void read_plots(pugi::xml_node plots_node) { n_plots = plot_nodes.size(); - for(auto plot : plot_nodes) { - // ObjectPlot* pl = new ObjectPlot(plot); + for(int i = 0; i < plot_nodes.size(); i++) { + ObjectPlot* pl = new ObjectPlot(plot_nodes[i]); + plot_dict[pl->id] = i; } } @@ -482,8 +483,86 @@ ObjectPlot::ObjectPlot(pugi::xml_node plot_node) { meshlines_color.rgb[2] = 0; } - } + } } + + // Deal with masks + std::vector mask_nodes; + mask_nodes = get_child_nodes(plot_node, "mask"); + int n_masks = mask_nodes.size(); + + if (PLOT_TYPE::VOXEL == type) { + if (openmc_master) { + std::stringstream wrn_msg; + wrn_msg << "Mask ignored in voxel plot " << id; + warning(wrn_msg); + } + } + + if (1 == n_masks) { + // Get pointer to mask + pugi::xml_node mask_node = mask_nodes[0]; + + // Determine how many components there are and allocate + int n_comp; + n_comp = node_word_count(mask_node, "components"); + if (0 == n_comp) { + std::stringstream err_msg; + err_msg << "Missing in mask of plot " << id; + fatal_error(err_msg); + } + std::vector iarray = get_node_array(mask_node, "components"); + + // First we need to change the user-specified identifiers to indices + // in the cell and material arrays + int col_id; + for (int j = 0; j < iarray.size(); j++) { + col_id = iarray[j]; + + if (PLOT_COLOR_BY::CELLS == color_by) { + if (cell_map.find(col_id) != cell_map.end()) { + iarray[j] = cell_map[col_id]; + } + else { + std::stringstream err_msg; + err_msg << "Could not find cell " << col_id + << " specified in the mask in plot " << id; + fatal_error(err_msg); + } + } else if (PLOT_COLOR_BY::MATS == color_by) { + if (material_map.find(col_id) != material_map.end()) { + iarray[j] = material_map[col_id]; + } + else { + std::stringstream err_msg; + err_msg << "Could not find material " << col_id + << " specified in the mask in plot " << id; + fatal_error(err_msg); + } + } + } + + // Alter colors based on mask information + // TODO: + for(int j = 0; j < MAX_COORD; j++) { + if (std::find(iarray.begin(), iarray.end(), j) != iarray.end()) { + if (check_for_node(mask_node, "background")) { + std::vector bg_rgb = get_node_array(mask_node, "background"); + } else { + colors[j].rgb[0] = 255; + colors[j].rgb[1] = 255; + colors[j].rgb[2] = 255; + } + } + } + + } else { + std::stringstream err_msg; + err_msg << "Mutliple masks specified in plot " << id; + fatal_error(err_msg); + } + + } // End ObjectPlot constructor //=============================================================================== From 81d345309238ac9d58406918be4761571e7d1a99 Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Thu, 11 Oct 2018 17:39:07 -0500 Subject: [PATCH 034/105] Exposing C++ openmc_plot_geometry and applying plot.F90. Also including bug fixes to ObjectPlot settings. --- include/openmc/plot.h | 5 +- src/input_xml.F90 | 9 ++ src/plot.F90 | 9 +- src/plot.cpp | 218 ++++++++++++++++++++++++++++-------------- 4 files changed, 166 insertions(+), 75 deletions(-) diff --git a/include/openmc/plot.h b/include/openmc/plot.h index a279dc9c0..9fb2def1b 100644 --- a/include/openmc/plot.h +++ b/include/openmc/plot.h @@ -73,7 +73,10 @@ namespace openmc { }; - +extern "C" int openmc_plot_geometry_c(); + +extern "C" void read_plots(pugi::xml_node* plot_node); + extern "C" void create_ppm(ObjectPlot* pl); extern "C" void create_voxel(ObjectPlot *pl); diff --git a/src/input_xml.F90 b/src/input_xml.F90 index 54c0538c9..61468c898 100644 --- a/src/input_xml.F90 +++ b/src/input_xml.F90 @@ -97,6 +97,11 @@ module input_xml integer(C_INT) :: n end function maximum_levels + subroutine read_plots(node_ptr) bind(C) + import C_PTR + type(C_PTR) :: node_ptr + end subroutine read_plots + subroutine set_particle_energy_bounds(particle, E_min, E_max) bind(C) import C_INT, C_DOUBLE integer(C_INT), value :: particle @@ -2051,6 +2056,7 @@ contains type(XMLNode), allocatable :: node_mask_list(:) type(XMLNode), allocatable :: node_meshline_list(:) + ! Check if plots.xml exists filename = trim(path_input) // "plots.xml" inquire(FILE=filename, EXIST=file_exists) @@ -2066,6 +2072,9 @@ contains call doc % load_file(filename) root = doc % document_element() + call read_plots(root % ptr) + return + ! Get list pointer to XML call get_node_list(root, "plot", node_plot_list) diff --git a/src/plot.F90 b/src/plot.F90 index 329cbca55..98b16b45e 100644 --- a/src/plot.F90 +++ b/src/plot.F90 @@ -13,6 +13,11 @@ module plot public :: openmc_plot_geometry interface + function openmc_plot_geometry_c() bind(C) result(err) + import C_INT + integer(C_INT) :: err + end function openmc_plot_geometry_c + subroutine create_ppm(pl) bind(C) import ObjectPlot type(ObjectPlot), intent(in) :: pl @@ -31,9 +36,11 @@ contains function openmc_plot_geometry() result(err) bind(C) integer(C_INT) :: err - integer :: i ! loop index for plots + err = openmc_plot_geometry_c() + return + do i = 1, n_plots associate (pl => plots(i)) ! Display output message diff --git a/src/plot.cpp b/src/plot.cpp index 06ab0cc97..b1bca1820 100644 --- a/src/plot.cpp +++ b/src/plot.cpp @@ -27,7 +27,7 @@ const int NULLRGB[3] = {0, 0, 0}; // RUN_PLOT controls the logic for making one or many plots //=============================================================================== -int openmc_plot_geometry() { +int openmc_plot_geometry_c() { int err; for(int i = 0; i < n_plots; i++) { @@ -52,15 +52,17 @@ int openmc_plot_geometry() { return 0; } -void read_plots(pugi::xml_node plots_node) { + +void read_plots(pugi::xml_node* plots_node) { std::vector plot_nodes; - plot_nodes = get_child_nodes(plots_node, "plot"); + plot_nodes = get_child_nodes(*plots_node, "plot"); n_plots = plot_nodes.size(); for(int i = 0; i < plot_nodes.size(); i++) { ObjectPlot* pl = new ObjectPlot(plot_nodes[i]); + plots.push_back(pl); plot_dict[pl->id] = i; } } @@ -140,7 +142,8 @@ void create_ppm(ObjectPlot* pl) { } -ObjectPlot::ObjectPlot(pugi::xml_node plot_node) { + ObjectPlot::ObjectPlot(pugi::xml_node plot_node) : + index_meshlines_mesh(-1) { // Copy data into plots if (check_for_node(plot_node, "id")) { @@ -159,7 +162,8 @@ ObjectPlot::ObjectPlot(pugi::xml_node plot_node) { // Copy plot type // Default is slice - std::string type_str = "slice"; + std::string type_str = "slice"; + type = PLOT_TYPE::SLICE; if (check_for_node(plot_node, "type")) { type_str = get_node_value(plot_node, "type"); to_lower(type_str); @@ -181,6 +185,8 @@ ObjectPlot::ObjectPlot(pugi::xml_node plot_node) { filename << "plot_" << id; if (check_for_node(plot_node, "filename")) { + filename << get_node_value(plot_node, "filename"); + } else { switch(type) { case PLOT_TYPE::SLICE: filename << ".ppm"; @@ -190,7 +196,8 @@ ObjectPlot::ObjectPlot(pugi::xml_node plot_node) { break; } } - + std::strcpy(path_plot, filename.str().c_str()); + // Copy plot pixel size std::vector pxls; if (PLOT_TYPE::SLICE == type) { @@ -379,7 +386,6 @@ ObjectPlot::ObjectPlot(pugi::xml_node plot_node) { fatal_error(err_msg); } - // Ensure that there is an id for this color specification // Ensure that there is an id for this color specification int col_id; if (check_for_node(cn, "id")) { @@ -455,9 +461,20 @@ ObjectPlot::ObjectPlot(pugi::xml_node plot_node) { } // Check mesh type + std::string meshtype; + if (check_for_node(meshlines_node, "meshtype")) { + meshtype = get_node_value(meshlines_node, "meshtype"); + } else { + std::stringstream err_msg; + err_msg << "Must specify a meshtype for meshlines specification in plot " << id ; + fatal_error(err_msg); + } + + // Ensure that there is a linewidth for this meshlines specification std::string meshline_width; if (check_for_node(meshlines_node, "linewidth")) { meshline_width = get_node_value(meshlines_node, "linewidth"); + meshlines_width = std::stoi(meshline_width); } else { std::stringstream err_msg; err_msg << "Must specify a linewidth for meshlines specification in plot " << id; @@ -483,6 +500,59 @@ ObjectPlot::ObjectPlot(pugi::xml_node plot_node) { meshlines_color.rgb[2] = 0; } + // Set mesh based on type + if ("ufs" == meshtype) { + if (settings::index_ufs_mesh < 0) { + std::stringstream err_msg; + err_msg << "No UFS mesh for meshlines on plot " << id; + fatal_error(err_msg); + } else { + index_meshlines_mesh = settings::index_ufs_mesh; + } + // } else if ("cmfd" == meshtype) { + // if (!settings::cmfd_run) { + // std::stringstream err_msg; + // err_msg << "Need CMFD run to plot CMFD mesh for meshlines on plot " << id; + // fatal_error(err_msg); + // } else { + // index_meshlines_mesh = settings::index_cmfd_mesh; + // } + } else if ("entropy" == meshtype) { + if (settings::index_entropy_mesh < 0) { + std::stringstream err_msg; + err_msg <<"No entropy mesh for meshlines on plot " << id; + fatal_error(err_msg); + } else { + index_meshlines_mesh = settings::index_entropy_mesh; + } + } else if ("tally" == meshtype) { + // Ensure that there is a mesh id if the type is tally + int tally_mesh_id; + if (check_for_node(meshlines_node, "id")) { + int tally_mesh_id = std::stoi(get_node_value(meshlines_node, "id")); + } else { + std::stringstream err_msg; + err_msg << "Must specify a mesh id for meshlines tally " + << "mesh specification in plot " << id; + fatal_error(err_msg); + } + int idx; + int err = openmc_get_mesh_index(tally_mesh_id, &idx); + if (0 != err) { + std::stringstream err_msg; + err_msg << "Could not find mesh " << tally_mesh_id + << " specified in meshlines for plot " << id; + fatal_error(err_msg); + } + } else { + std::stringstream err_msg; + err_msg << "Invalid type for meshlines on plot " << id ; + fatal_error(err_msg); + } + } else { + std::stringstream err_msg; + err_msg << "Mutliple meshlines specified in plot " << id; + fatal_error(err_msg); } } @@ -491,78 +561,80 @@ ObjectPlot::ObjectPlot(pugi::xml_node plot_node) { mask_nodes = get_child_nodes(plot_node, "mask"); int n_masks = mask_nodes.size(); - if (PLOT_TYPE::VOXEL == type) { - if (openmc_master) { - std::stringstream wrn_msg; - wrn_msg << "Mask ignored in voxel plot " << id; - warning(wrn_msg); - } - } + if (n_masks > 0) { - if (1 == n_masks) { - // Get pointer to mask - pugi::xml_node mask_node = mask_nodes[0]; + if (PLOT_TYPE::VOXEL == type) { + if (openmc_master) { + std::stringstream wrn_msg; + wrn_msg << "Mask ignored in voxel plot " << id; + warning(wrn_msg); + } + } + + if (1 == n_masks) { + // Get pointer to mask + pugi::xml_node mask_node = mask_nodes[0]; - // Determine how many components there are and allocate - int n_comp; - n_comp = node_word_count(mask_node, "components"); - if (0 == n_comp) { + // Determine how many components there are and allocate + int n_comp; + n_comp = node_word_count(mask_node, "components"); + if (0 == n_comp) { + std::stringstream err_msg; + err_msg << "Missing in mask of plot " << id; + fatal_error(err_msg); + } + std::vector iarray = get_node_array(mask_node, "components"); + + // First we need to change the user-specified identifiers to indices + // in the cell and material arrays + int col_id; + for (int j = 0; j < iarray.size(); j++) { + col_id = iarray[j]; + + if (PLOT_COLOR_BY::CELLS == color_by) { + if (cell_map.find(col_id) != cell_map.end()) { + iarray[j] = cell_map[col_id]; + } + else { + std::stringstream err_msg; + err_msg << "Could not find cell " << col_id + << " specified in the mask in plot " << id; + fatal_error(err_msg); + } + } else if (PLOT_COLOR_BY::MATS == color_by) { + if (material_map.find(col_id) != material_map.end()) { + iarray[j] = material_map[col_id]; + } + else { + std::stringstream err_msg; + err_msg << "Could not find material " << col_id + << " specified in the mask in plot " << id; + fatal_error(err_msg); + } + } + } + + // Alter colors based on mask information + // TODO: + for(int j = 0; j < MAX_COORD; j++) { + if (std::find(iarray.begin(), iarray.end(), j) != iarray.end()) { + if (check_for_node(mask_node, "background")) { + std::vector bg_rgb = get_node_array(mask_node, "background"); + } else { + colors[j].rgb[0] = 255; + colors[j].rgb[1] = 255; + colors[j].rgb[2] = 255; + } + } + } + + } else { std::stringstream err_msg; - err_msg << "Missing in mask of plot " << id; + err_msg << "Mutliple masks specified in plot " << id; fatal_error(err_msg); } - std::vector iarray = get_node_array(mask_node, "components"); - - // First we need to change the user-specified identifiers to indices - // in the cell and material arrays - int col_id; - for (int j = 0; j < iarray.size(); j++) { - col_id = iarray[j]; - - if (PLOT_COLOR_BY::CELLS == color_by) { - if (cell_map.find(col_id) != cell_map.end()) { - iarray[j] = cell_map[col_id]; - } - else { - std::stringstream err_msg; - err_msg << "Could not find cell " << col_id - << " specified in the mask in plot " << id; - fatal_error(err_msg); - } - } else if (PLOT_COLOR_BY::MATS == color_by) { - if (material_map.find(col_id) != material_map.end()) { - iarray[j] = material_map[col_id]; - } - else { - std::stringstream err_msg; - err_msg << "Could not find material " << col_id - << " specified in the mask in plot " << id; - fatal_error(err_msg); - } - } - } - - // Alter colors based on mask information - // TODO: - for(int j = 0; j < MAX_COORD; j++) { - if (std::find(iarray.begin(), iarray.end(), j) != iarray.end()) { - if (check_for_node(mask_node, "background")) { - std::vector bg_rgb = get_node_array(mask_node, "background"); - } else { - colors[j].rgb[0] = 255; - colors[j].rgb[1] = 255; - colors[j].rgb[2] = 255; - } - } - } - - } else { - std::stringstream err_msg; - err_msg << "Mutliple masks specified in plot " << id; - fatal_error(err_msg); } - } // End ObjectPlot constructor //=============================================================================== @@ -637,7 +709,7 @@ void output_ppm(ObjectPlot* pl, const ImageData &data) std::string fname = std::string(pl->path_plot); fname = strtrim(fname); std::ofstream of; - + of.open(fname); // Write header From 9f32259a00e22cca153cf5b443c61b268eba337f Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Thu, 11 Oct 2018 20:44:03 -0500 Subject: [PATCH 035/105] Corrections to color indexing. --- src/plot.cpp | 34 +++++++++++++++++++-------- tests/regression_tests/plot/plots.xml | 1 + 2 files changed, 25 insertions(+), 10 deletions(-) diff --git a/src/plot.cpp b/src/plot.cpp index b1bca1820..205b8c75c 100644 --- a/src/plot.cpp +++ b/src/plot.cpp @@ -342,6 +342,11 @@ void create_ppm(ObjectPlot* pl) { colors[i].rgb[0] = int(prn()*255); colors[i].rgb[1] = int(prn()*255); colors[i].rgb[2] = int(prn()*255); + std::cout << "Cell " << i << " color:" << std::endl; + std::cout << "{" << colors[i].rgb[0] + << ", "<< colors[i].rgb[1] + << ", "<< colors[i].rgb[1] + << "}" << std::endl; } } else if("material" == pl_color_by) { @@ -349,10 +354,15 @@ void create_ppm(ObjectPlot* pl) { color_by = PLOT_COLOR_BY::MATS; // colors.resize(materials.size()); - for(int i = 0; i < n_cells; i++) { + for(int i = 0; i < materials.size(); i++) { colors[i].rgb[0] = int(prn()*255); colors[i].rgb[1] = int(prn()*255); colors[i].rgb[2] = int(prn()*255); + std::cout << "Material " << i << " color:" << std::endl; + std::cout << "{" << colors[i].rgb[0] + << ", "<< colors[i].rgb[1] + << ", "<< colors[i].rgb[1] + << "}" << std::endl; } } else { std::stringstream err_msg; @@ -396,15 +406,16 @@ void create_ppm(ObjectPlot* pl) { << id; fatal_error(err_msg); } + // Add RGB if (PLOT_COLOR_BY::CELLS == color_by) { std::vector cell_rgb; if (cell_map.find(col_id) != cell_map.end()) { col_id = cell_map[col_id]; cell_rgb = get_node_array(cn, "rgb"); - colors[col_id].rgb[0] = cell_rgb[0]; - colors[col_id].rgb[1] = cell_rgb[1]; - colors[col_id].rgb[2] = cell_rgb[2]; + colors[col_id - 1].rgb[0] = cell_rgb[0]; + colors[col_id - 1].rgb[1] = cell_rgb[1]; + colors[col_id - 1].rgb[2] = cell_rgb[2]; } else { std::stringstream err_msg; err_msg << "Could not find cell " << col_id @@ -416,9 +427,9 @@ void create_ppm(ObjectPlot* pl) { if (material_map.find(col_id) != material_map.end()) { col_id = material_map[col_id]; mat_rgb = get_node_array(cn, "rgb"); - colors[col_id].rgb[0] = mat_rgb[0]; - colors[col_id].rgb[1] = mat_rgb[1]; - colors[col_id].rgb[2] = mat_rgb[2]; + colors[col_id - 1].rgb[0] = mat_rgb[0]; + colors[col_id - 1].rgb[1] = mat_rgb[1]; + colors[col_id - 1].rgb[2] = mat_rgb[2]; } else { std::stringstream err_msg; err_msg << "Could not find material " << col_id @@ -620,10 +631,13 @@ void create_ppm(ObjectPlot* pl) { if (std::find(iarray.begin(), iarray.end(), j) != iarray.end()) { if (check_for_node(mask_node, "background")) { std::vector bg_rgb = get_node_array(mask_node, "background"); + colors[j - 1].rgb[0] = bg_rgb[0]; + colors[j - 1].rgb[1] = bg_rgb[1]; + colors[j - 1].rgb[2] = bg_rgb[2]; } else { - colors[j].rgb[0] = 255; - colors[j].rgb[1] = 255; - colors[j].rgb[2] = 255; + colors[j - 1].rgb[0] = 255; + colors[j - 1].rgb[1] = 255; + colors[j - 1].rgb[2] = 255; } } } diff --git a/tests/regression_tests/plot/plots.xml b/tests/regression_tests/plot/plots.xml index ecfe69125..a6ac96150 100644 --- a/tests/regression_tests/plot/plots.xml +++ b/tests/regression_tests/plot/plots.xml @@ -7,6 +7,7 @@ 200 200 + From 9bb4537a6b0ee28e5b52c42a5ccfd1e5ba004f08 Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Thu, 11 Oct 2018 22:08:59 -0500 Subject: [PATCH 036/105] Fix to version data output for voxel plots. Reverting a change to plots.xml in plots test. Undoing an indexing fix to match test results. --- src/plot.cpp | 38 ++++++++++++++------------- tests/regression_tests/plot/plots.xml | 1 - 2 files changed, 20 insertions(+), 19 deletions(-) diff --git a/src/plot.cpp b/src/plot.cpp index 205b8c75c..11fe9ab5a 100644 --- a/src/plot.cpp +++ b/src/plot.cpp @@ -1,4 +1,5 @@ #include +#include #include "openmc/plot.h" #include "openmc/constants.h" @@ -27,6 +28,17 @@ const int NULLRGB[3] = {0, 0, 0}; // RUN_PLOT controls the logic for making one or many plots //=============================================================================== + std::string time_stamp() + { + std::stringstream ts; + std::time_t t = std::time(0); // get time now + std::tm* now = std::localtime(&t); + ts << now->tm_year + 1990 << "-" << now->tm_mon + << "-" << now->tm_mday << " " << now->tm_hour + << ":" << now->tm_min << ":" << now->tm_sec; + return ts.str(); + } + int openmc_plot_geometry_c() { int err; @@ -342,11 +354,6 @@ void create_ppm(ObjectPlot* pl) { colors[i].rgb[0] = int(prn()*255); colors[i].rgb[1] = int(prn()*255); colors[i].rgb[2] = int(prn()*255); - std::cout << "Cell " << i << " color:" << std::endl; - std::cout << "{" << colors[i].rgb[0] - << ", "<< colors[i].rgb[1] - << ", "<< colors[i].rgb[1] - << "}" << std::endl; } } else if("material" == pl_color_by) { @@ -358,11 +365,6 @@ void create_ppm(ObjectPlot* pl) { colors[i].rgb[0] = int(prn()*255); colors[i].rgb[1] = int(prn()*255); colors[i].rgb[2] = int(prn()*255); - std::cout << "Material " << i << " color:" << std::endl; - std::cout << "{" << colors[i].rgb[0] - << ", "<< colors[i].rgb[1] - << ", "<< colors[i].rgb[1] - << "}" << std::endl; } } else { std::stringstream err_msg; @@ -631,13 +633,13 @@ void create_ppm(ObjectPlot* pl) { if (std::find(iarray.begin(), iarray.end(), j) != iarray.end()) { if (check_for_node(mask_node, "background")) { std::vector bg_rgb = get_node_array(mask_node, "background"); - colors[j - 1].rgb[0] = bg_rgb[0]; - colors[j - 1].rgb[1] = bg_rgb[1]; - colors[j - 1].rgb[2] = bg_rgb[2]; + colors[j].rgb[0] = bg_rgb[0]; + colors[j].rgb[1] = bg_rgb[1]; + colors[j].rgb[2] = bg_rgb[2]; } else { - colors[j - 1].rgb[0] = 255; - colors[j - 1].rgb[1] = 255; - colors[j - 1].rgb[2] = 255; + colors[j].rgb[0] = 255; + colors[j].rgb[1] = 255; + colors[j].rgb[2] = 255; } } } @@ -891,7 +893,7 @@ void create_voxel(ObjectPlot *pl) { hid_t file_id = file_open(fname, 'w'); // write header info - write_attribute(file_id, "filetype", 'voxel'); + write_attribute(file_id, "filetype", "voxel"); write_attribute(file_id, "version", VERSION_VOXEL); write_attribute(file_id, "openmc_version", VERSION); @@ -900,7 +902,7 @@ void create_voxel(ObjectPlot *pl) { #endif // Write current date and time - // write_attribute(file_id, "date_and_time", time_stamp()); <-- RE-ADD!!! + write_attribute(file_id, "date_and_time", time_stamp().c_str()); hsize_t three = 3; write_attr_int(file_id, 1, &three, "num_voxels", pl->pixels); write_attr_double(file_id, 1, &three, "voxel_width", vox); diff --git a/tests/regression_tests/plot/plots.xml b/tests/regression_tests/plot/plots.xml index a6ac96150..ecfe69125 100644 --- a/tests/regression_tests/plot/plots.xml +++ b/tests/regression_tests/plot/plots.xml @@ -7,7 +7,6 @@ 200 200 - From 9eef0884af2f188fa7fcbe95f8f5c5301d376d5e Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Fri, 12 Oct 2018 00:39:25 -0500 Subject: [PATCH 037/105] Fortran style updates. --- src/input_xml.F90 | 6 +++--- src/plot.F90 | 20 +------------------- 2 files changed, 4 insertions(+), 22 deletions(-) diff --git a/src/input_xml.F90 b/src/input_xml.F90 index 61468c898..37d9d7ca5 100644 --- a/src/input_xml.F90 +++ b/src/input_xml.F90 @@ -101,7 +101,7 @@ module input_xml import C_PTR type(C_PTR) :: node_ptr end subroutine read_plots - + subroutine set_particle_energy_bounds(particle, E_min, E_max) bind(C) import C_INT, C_DOUBLE integer(C_INT), value :: particle @@ -2056,7 +2056,7 @@ contains type(XMLNode), allocatable :: node_mask_list(:) type(XMLNode), allocatable :: node_meshline_list(:) - + ! Check if plots.xml exists filename = trim(path_input) // "plots.xml" inquire(FILE=filename, EXIST=file_exists) @@ -2074,7 +2074,7 @@ contains call read_plots(root % ptr) return - + ! Get list pointer to XML call get_node_list(root, "plot", node_plot_list) diff --git a/src/plot.F90 b/src/plot.F90 index 98b16b45e..faccb317c 100644 --- a/src/plot.F90 +++ b/src/plot.F90 @@ -17,7 +17,7 @@ module plot import C_INT integer(C_INT) :: err end function openmc_plot_geometry_c - + subroutine create_ppm(pl) bind(C) import ObjectPlot type(ObjectPlot), intent(in) :: pl @@ -40,24 +40,6 @@ contains err = openmc_plot_geometry_c() return - - do i = 1, n_plots - associate (pl => plots(i)) - ! Display output message - call write_message("Processing plot " // trim(to_str(pl % id)) & - // ": " // trim(pl % path_plot) // " ...", 5) - - if (pl % type == PLOT_TYPE_SLICE) then - ! create 2d image - call create_ppm(pl) - else if (pl % type == PLOT_TYPE_VOXEL) then - ! create dump for 3D silomesh utility script - call create_voxel(pl) - end if - end associate - end do - - err = 0 end function openmc_plot_geometry end module plot From 1b71af6baab8ea3f4c969d4e3c903e15cebdb8f8 Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Fri, 12 Oct 2018 10:46:21 -0500 Subject: [PATCH 038/105] Moving some attributes of ObjectPlot to C++ types. --- include/openmc/plot.h | 4 +- src/plot.cpp | 92 +++++++++++++++++++++---------------------- 2 files changed, 48 insertions(+), 48 deletions(-) diff --git a/include/openmc/plot.h b/include/openmc/plot.h index 9fb2def1b..585705d75 100644 --- a/include/openmc/plot.h +++ b/include/openmc/plot.h @@ -68,8 +68,8 @@ namespace openmc { int index_meshlines_mesh; ObjectColor meshlines_color; ObjectColor not_found; - ObjectColor colors[MAX_COORD]; - char path_plot[MAX_WORD_LEN]; + std::vector colors; + std::string path_plot; }; diff --git a/src/plot.cpp b/src/plot.cpp index 11fe9ab5a..ea0fda83f 100644 --- a/src/plot.cpp +++ b/src/plot.cpp @@ -38,7 +38,7 @@ const int NULLRGB[3] = {0, 0, 0}; << ":" << now->tm_min << ":" << now->tm_sec; return ts.str(); } - + int openmc_plot_geometry_c() { int err; @@ -157,7 +157,7 @@ void create_ppm(ObjectPlot* pl) { ObjectPlot::ObjectPlot(pugi::xml_node plot_node) : index_meshlines_mesh(-1) { - // Copy data into plots + // Copy data into plots if (check_for_node(plot_node, "id")) { id = std::stoi(get_node_value(plot_node, "id")); } else { @@ -208,8 +208,8 @@ void create_ppm(ObjectPlot* pl) { break; } } - std::strcpy(path_plot, filename.str().c_str()); - + path_plot = filename.str(); + // Copy plot pixel size std::vector pxls; if (PLOT_TYPE::SLICE == type) { @@ -228,7 +228,7 @@ void create_ppm(ObjectPlot* pl) { pxls = get_node_array(plot_node, "pixels"); pixels[0] = pxls[0]; pixels[1] = pxls[1]; - pixels[2] = pxls[2]; + pixels[2] = pxls[2]; } else { std::stringstream err_msg; err_msg << " must be length 3 in voxel plot " @@ -349,22 +349,22 @@ void create_ppm(ObjectPlot* pl) { 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); + colors.push_back(new ObjectColor()); + 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 < materials.size(); i++) { - colors[i].rgb[0] = int(prn()*255); - colors[i].rgb[1] = int(prn()*255); - colors[i].rgb[2] = int(prn()*255); + colors.push_back(new ObjectColor()); + 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; @@ -376,7 +376,7 @@ void create_ppm(ObjectPlot* pl) { // 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()) { @@ -408,16 +408,16 @@ void create_ppm(ObjectPlot* pl) { << id; fatal_error(err_msg); } - + // Add RGB if (PLOT_COLOR_BY::CELLS == color_by) { std::vector cell_rgb; if (cell_map.find(col_id) != cell_map.end()) { col_id = cell_map[col_id]; cell_rgb = get_node_array(cn, "rgb"); - colors[col_id - 1].rgb[0] = cell_rgb[0]; - colors[col_id - 1].rgb[1] = cell_rgb[1]; - colors[col_id - 1].rgb[2] = cell_rgb[2]; + colors[col_id - 1]->rgb[0] = cell_rgb[0]; + colors[col_id - 1]->rgb[1] = cell_rgb[1]; + colors[col_id - 1]->rgb[2] = cell_rgb[2]; } else { std::stringstream err_msg; err_msg << "Could not find cell " << col_id @@ -429,19 +429,19 @@ void create_ppm(ObjectPlot* pl) { if (material_map.find(col_id) != material_map.end()) { col_id = material_map[col_id]; mat_rgb = get_node_array(cn, "rgb"); - colors[col_id - 1].rgb[0] = mat_rgb[0]; - colors[col_id - 1].rgb[1] = mat_rgb[1]; - colors[col_id - 1].rgb[2] = mat_rgb[2]; + colors[col_id - 1]->rgb[0] = mat_rgb[0]; + colors[col_id - 1]->rgb[1] = mat_rgb[1]; + colors[col_id - 1]->rgb[2] = mat_rgb[2]; } else { std::stringstream err_msg; err_msg << "Could not find material " << col_id - << " specified in plot " << id; + << " specified in plot " << id; fatal_error(err_msg); } } } // color node loop } - + // Deal with meshlines std::vector mesh_line_nodes; @@ -462,7 +462,7 @@ void create_ppm(ObjectPlot* pl) { } else if (1 == n_meshlines) { // Get first meshline node pugi::xml_node meshlines_node = mesh_line_nodes[0]; - + // Check mesh type std::string meshline_type; if (check_for_node(meshlines_node, "meshtype")) { @@ -482,7 +482,7 @@ void create_ppm(ObjectPlot* pl) { err_msg << "Must specify a meshtype for meshlines specification in plot " << id ; fatal_error(err_msg); } - + // Ensure that there is a linewidth for this meshlines specification std::string meshline_width; if (check_for_node(meshlines_node, "linewidth")) { @@ -512,7 +512,7 @@ void create_ppm(ObjectPlot* pl) { meshlines_color.rgb[1] = 0; meshlines_color.rgb[2] = 0; } - + // Set mesh based on type if ("ufs" == meshtype) { if (settings::index_ufs_mesh < 0) { @@ -575,7 +575,7 @@ void create_ppm(ObjectPlot* pl) { int n_masks = mask_nodes.size(); if (n_masks > 0) { - + if (PLOT_TYPE::VOXEL == type) { if (openmc_master) { std::stringstream wrn_msg; @@ -583,7 +583,7 @@ void create_ppm(ObjectPlot* pl) { warning(wrn_msg); } } - + if (1 == n_masks) { // Get pointer to mask pugi::xml_node mask_node = mask_nodes[0]; @@ -598,7 +598,7 @@ void create_ppm(ObjectPlot* pl) { } std::vector iarray = get_node_array(mask_node, "components"); - // First we need to change the user-specified identifiers to indices + // First we need to change the user-specified identifiers to indices // in the cell and material arrays int col_id; for (int j = 0; j < iarray.size(); j++) { @@ -628,22 +628,22 @@ void create_ppm(ObjectPlot* pl) { } // Alter colors based on mask information - // TODO: - for(int j = 0; j < MAX_COORD; j++) { + // TODO: + for(int j = 0; j < colors.size(); j++) { if (std::find(iarray.begin(), iarray.end(), j) != iarray.end()) { if (check_for_node(mask_node, "background")) { std::vector bg_rgb = get_node_array(mask_node, "background"); - colors[j].rgb[0] = bg_rgb[0]; - colors[j].rgb[1] = bg_rgb[1]; - colors[j].rgb[2] = bg_rgb[2]; + colors[j]->rgb[0] = bg_rgb[0]; + colors[j]->rgb[1] = bg_rgb[1]; + colors[j]->rgb[2] = bg_rgb[2]; } else { - colors[j].rgb[0] = 255; - colors[j].rgb[1] = 255; - colors[j].rgb[2] = 255; + colors[j]->rgb[0] = 255; + colors[j]->rgb[1] = 255; + colors[j]->rgb[2] = 255; } } } - + } else { std::stringstream err_msg; err_msg << "Mutliple masks specified in plot " << id; @@ -652,7 +652,7 @@ void create_ppm(ObjectPlot* pl) { } } // End ObjectPlot constructor - + //=============================================================================== // POSITION_RGB computes the red/green/blue values for a given plot with the // current particle's position @@ -695,16 +695,16 @@ void position_rgb(Particle* p, ObjectPlot* pl, int rgb[3], int &id) { std::copy(WHITE, WHITE+3, rgb); id = -1; } else { - std::copy(pl->colors[p->material - 1].rgb, - pl->colors[p->material - 1].rgb + 3, + std::copy(pl->colors[p->material - 1]->rgb, + pl->colors[p->material - 1]->rgb + 3, rgb); id = materials[p->material - 1]->id; } } else if (PLOT_COLOR_BY::CELLS == pl->color_by) { // Assign color based on cell - std::copy(pl->colors[p->coord[j].cell].rgb, - pl->colors[p->coord[j].cell].rgb + 3, + std::copy(pl->colors[p->coord[j].cell]->rgb, + pl->colors[p->coord[j].cell]->rgb + 3, rgb); id = cells[p->coord[j].cell]->id_; } else { @@ -722,10 +722,10 @@ void position_rgb(Particle* p, ObjectPlot* pl, int rgb[3], int &id) { void output_ppm(ObjectPlot* pl, const ImageData &data) { // Open PPM file for writing - std::string fname = std::string(pl->path_plot); + std::string fname = pl->path_plot; fname = strtrim(fname); std::ofstream of; - + of.open(fname); // Write header From 96e50072761466ab9c36047134ff0cc402f20a30 Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Fri, 12 Oct 2018 16:16:38 -0500 Subject: [PATCH 039/105] Moving time stamp function to output. --- include/openmc/output.h | 9 +++++++++ src/output.cpp | 13 +++++++++++++ src/plot.cpp | 12 +----------- 3 files changed, 23 insertions(+), 11 deletions(-) diff --git a/include/openmc/output.h b/include/openmc/output.h index e396c07d8..793c9b727 100644 --- a/include/openmc/output.h +++ b/include/openmc/output.h @@ -4,6 +4,7 @@ #ifndef OPENMC_OUTPUT_H #define OPENMC_OUTPUT_H +#include namespace openmc { @@ -16,6 +17,14 @@ namespace openmc { void header(const char* msg, int level); + +//============================================================================== +//! Retrieve a time stamp with the format "yyyy-mm-dd hh:mm:ss" +//! +//============================================================================== + +std::string time_stamp(); + //============================================================================== //! Display information regarding cell overlap checking. //============================================================================== diff --git a/src/output.cpp b/src/output.cpp index 6a3abeed6..0eb6b204c 100644 --- a/src/output.cpp +++ b/src/output.cpp @@ -5,6 +5,7 @@ #include // for setw #include #include +#include #include "openmc/cell.h" #include "openmc/geometry.h" @@ -39,6 +40,18 @@ header(const char* msg, int level) { } } +std::string time_stamp() +{ + int base_year = 1990; + std::stringstream ts; + std::time_t t = std::time(0); // get time now + std::tm* now = std::localtime(&t); + ts << now->tm_year + base_year << "-" << now->tm_mon + << "-" << now->tm_mday << " " << now->tm_hour + << ":" << now->tm_min << ":" << now->tm_sec; + return ts.str(); +} + //============================================================================== void print_overlap_check() { diff --git a/src/plot.cpp b/src/plot.cpp index ea0fda83f..afb927252 100644 --- a/src/plot.cpp +++ b/src/plot.cpp @@ -1,5 +1,4 @@ #include -#include #include "openmc/plot.h" #include "openmc/constants.h" @@ -14,6 +13,7 @@ #include "openmc/output.h" #include "openmc/hdf5_interface.h" #include "openmc/random_lcg.h" +#include "openmc/output.h" namespace openmc { @@ -28,16 +28,6 @@ const int NULLRGB[3] = {0, 0, 0}; // RUN_PLOT controls the logic for making one or many plots //=============================================================================== - std::string time_stamp() - { - std::stringstream ts; - std::time_t t = std::time(0); // get time now - std::tm* now = std::localtime(&t); - ts << now->tm_year + 1990 << "-" << now->tm_mon - << "-" << now->tm_mday << " " << now->tm_hour - << ":" << now->tm_min << ":" << now->tm_sec; - return ts.str(); - } int openmc_plot_geometry_c() { int err; From 72bee8014203fdc74d7e17bc8cb6ce593828f044 Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Fri, 12 Oct 2018 17:10:06 -0500 Subject: [PATCH 040/105] Exposing openmc_plot_geom through C rather than plot.F90. --- CMakeLists.txt | 2 +- include/openmc/plot.h | 2 +- src/plot.F90 | 45 ------------------------------------------- src/plot.cpp | 4 ++-- src/plot_header.F90 | 4 ++++ 5 files changed, 8 insertions(+), 49 deletions(-) delete mode 100644 src/plot.F90 diff --git a/CMakeLists.txt b/CMakeLists.txt index 4ac9d9c5d..d3aacad71 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -344,7 +344,7 @@ add_library(libopenmc SHARED src/photon_physics.F90 src/physics_common.F90 src/physics.F90 - src/plot.F90 + src/physics_mg.F90 src/plot_header.F90 src/progress_header.F90 src/pugixml/pugixml_f.F90 diff --git a/include/openmc/plot.h b/include/openmc/plot.h index 585705d75..a5fc870e7 100644 --- a/include/openmc/plot.h +++ b/include/openmc/plot.h @@ -73,7 +73,7 @@ namespace openmc { }; -extern "C" int openmc_plot_geometry_c(); + //extern "C" int openmc_plot_geometry(); extern "C" void read_plots(pugi::xml_node* plot_node); diff --git a/src/plot.F90 b/src/plot.F90 deleted file mode 100644 index faccb317c..000000000 --- a/src/plot.F90 +++ /dev/null @@ -1,45 +0,0 @@ -module plot - - use, intrinsic :: ISO_C_BINDING - - use error, only: write_message - use particle_header - use plot_header - use string, only: to_str - - implicit none - private - - public :: openmc_plot_geometry - - interface - function openmc_plot_geometry_c() bind(C) result(err) - import C_INT - integer(C_INT) :: err - end function openmc_plot_geometry_c - - subroutine create_ppm(pl) bind(C) - import ObjectPlot - type(ObjectPlot), intent(in) :: pl - end subroutine create_ppm - - subroutine create_voxel(pl) bind(C) - import ObjectPlot - type(ObjectPlot), intent(in) :: pl - end subroutine create_voxel - end interface -contains - -!=============================================================================== -! RUN_PLOT controls the logic for making one or many plots -!=============================================================================== - - function openmc_plot_geometry() result(err) bind(C) - integer(C_INT) :: err - integer :: i ! loop index for plots - - err = openmc_plot_geometry_c() - return - end function openmc_plot_geometry - -end module plot diff --git a/src/plot.cpp b/src/plot.cpp index afb927252..61a22bde7 100644 --- a/src/plot.cpp +++ b/src/plot.cpp @@ -28,8 +28,8 @@ const int NULLRGB[3] = {0, 0, 0}; // RUN_PLOT controls the logic for making one or many plots //=============================================================================== - -int openmc_plot_geometry_c() { +extern "C" +int openmc_plot_geometry() { int err; for(int i = 0; i < n_plots; i++) { diff --git a/src/plot_header.F90 b/src/plot_header.F90 index 9937db7dd..81a8f7f9f 100644 --- a/src/plot_header.F90 +++ b/src/plot_header.F90 @@ -71,4 +71,8 @@ contains call plot_dict % clear() end subroutine free_memory_plot +!=============================================================================== +! RUN_PLOT controls the logic for making one or many plots +!=============================================================================== + end module plot_header From f57fa66983615c4a9f6d35c900b62dbf32436118 Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Fri, 12 Oct 2018 21:50:25 -0500 Subject: [PATCH 041/105] Remove free plots memory function. --- src/api.F90 | 1 - src/plot_header.F90 | 6 ------ 2 files changed, 7 deletions(-) diff --git a/src/api.F90 b/src/api.F90 index c5ab06f59..25a992c9f 100644 --- a/src/api.F90 +++ b/src/api.F90 @@ -85,7 +85,6 @@ contains call free_memory_geometry() call free_memory_surfaces() call free_memory_material() - call free_memory_plot() call free_memory_volume() call free_memory_simulation() call free_memory_nuclide() diff --git a/src/plot_header.F90 b/src/plot_header.F90 index 81a8f7f9f..0495d83d3 100644 --- a/src/plot_header.F90 +++ b/src/plot_header.F90 @@ -65,12 +65,6 @@ contains ! FREE_MEMORY_PLOT deallocates global arrays defined in this module !=============================================================================== - subroutine free_memory_plot() - n_plots = 0 - if (allocated(plots)) deallocate(plots) - call plot_dict % clear() - end subroutine free_memory_plot - !=============================================================================== ! RUN_PLOT controls the logic for making one or many plots !=============================================================================== From 4fda0e1e484317302815a3490f4c38759011304a Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Sat, 13 Oct 2018 02:10:40 -0500 Subject: [PATCH 042/105] Removing a lot of unused code from input_xml. --- src/input_xml.F90 | 421 ---------------------------------------------- 1 file changed, 421 deletions(-) diff --git a/src/input_xml.F90 b/src/input_xml.F90 index 37d9d7ca5..84e0d89eb 100644 --- a/src/input_xml.F90 +++ b/src/input_xml.F90 @@ -2073,427 +2073,6 @@ contains root = doc % document_element() call read_plots(root % ptr) - return - - ! Get list pointer to XML - call get_node_list(root, "plot", node_plot_list) - - ! Allocate plots array - n_plots = size(node_plot_list) - allocate(plots(n_plots)) - - READ_PLOTS: do i = 1, n_plots - pl => plots(i) - - ! Get pointer to plot XML node - node_plot = node_plot_list(i) - - ! Copy data into plots - if (check_for_node(node_plot, "id")) then - call get_node_value(node_plot, "id", pl % id) - else - call fatal_error("Must specify plot id in plots XML file.") - end if - - ! Check to make sure 'id' hasn't been used - if (plot_dict % has(pl % id)) then - call fatal_error("Two or more plots use the same unique ID: " & - // to_str(pl % id)) - end if - - ! Copy plot type - temp_str = 'slice' - if (check_for_node(node_plot, "type")) & - call get_node_value(node_plot, "type", temp_str) - temp_str = to_lower(temp_str) - select case (trim(temp_str)) - case ("slice") - pl % type = PLOT_TYPE_SLICE - case ("voxel") - pl % type = PLOT_TYPE_VOXEL - case default - call fatal_error("Unsupported plot type '" // trim(temp_str) & - // "' in plot " // trim(to_str(pl % id))) - end select - - ! Set output file path - filename = "plot_" // trim(to_str(pl % id)) - if (check_for_node(node_plot, "filename")) & - call get_node_value(node_plot, "filename", filename) - select case (pl % type) - case (PLOT_TYPE_SLICE) - pl % path_plot = trim(path_input) // trim(filename) // ".ppm" - case (PLOT_TYPE_VOXEL) - pl % path_plot = trim(path_input) // trim(filename) // ".h5" - end select - - ! Copy plot pixel size - if (pl % type == PLOT_TYPE_SLICE) then - if (node_word_count(node_plot, "pixels") == 2) then - call get_node_array(node_plot, "pixels", pl % pixels(1:2)) - else - call fatal_error(" must be length 2 in slice plot " & - // trim(to_str(pl % id))) - end if - else if (pl % type == PLOT_TYPE_VOXEL) then - if (node_word_count(node_plot, "pixels") == 3) then - call get_node_array(node_plot, "pixels", pl % pixels(1:3)) - else - call fatal_error(" must be length 3 in voxel plot " & - // trim(to_str(pl % id))) - end if - end if - - ! Copy plot background color - if (check_for_node(node_plot, "background")) then - if (pl % type == PLOT_TYPE_VOXEL) then - if (master) call warning("Background color ignored in voxel plot " & - // trim(to_str(pl % id))) - end if - if (node_word_count(node_plot, "background") == 3) then - call get_node_array(node_plot, "background", pl % not_found % rgb) - else - call fatal_error("Bad background RGB in plot " & - // trim(to_str(pl % id))) - end if - else - pl % not_found % rgb = (/ 255, 255, 255 /) - end if - - ! Copy plot basis - if (pl % type == PLOT_TYPE_SLICE) then - temp_str = 'xy' - if (check_for_node(node_plot, "basis")) & - call get_node_value(node_plot, "basis", temp_str) - temp_str = to_lower(temp_str) - select case (trim(temp_str)) - case ("xy") - pl % basis = PLOT_BASIS_XY - case ("xz") - pl % basis = PLOT_BASIS_XZ - case ("yz") - pl % basis = PLOT_BASIS_YZ - case default - call fatal_error("Unsupported plot basis '" // trim(temp_str) & - // "' in plot " // trim(to_str(pl % id))) - end select - end if - - ! Copy plotting origin - if (node_word_count(node_plot, "origin") == 3) then - call get_node_array(node_plot, "origin", pl % origin) - else - call fatal_error("Origin must be length 3 in plot " & - // trim(to_str(pl % id))) - end if - - ! Copy plotting width - if (pl % type == PLOT_TYPE_SLICE) then - if (node_word_count(node_plot, "width") == 2) then - call get_node_array(node_plot, "width", pl % width(1:2)) - else - call fatal_error(" must be length 2 in slice plot " & - // trim(to_str(pl % id))) - end if - else if (pl % type == PLOT_TYPE_VOXEL) then - if (node_word_count(node_plot, "width") == 3) then - call get_node_array(node_plot, "width", pl % width(1:3)) - else - call fatal_error(" must be length 3 in voxel plot " & - // trim(to_str(pl % id))) - end if - end if - - ! Copy plot cell universe level - if (check_for_node(node_plot, "level")) then - call get_node_value(node_plot, "level", pl % level) - - if (pl % level < 0) then - call fatal_error("Bad universe level in plot " & - // trim(to_str(pl % id))) - end if - else - pl % level = PLOT_LEVEL_LOWEST - end if - - ! Copy plot color type and initialize all colors randomly - temp_str = "cell" - if (check_for_node(node_plot, "color_by")) & - call get_node_value(node_plot, "color_by", temp_str) - temp_str = to_lower(temp_str) - select case (trim(temp_str)) - case ("cell") - - pl % color_by = PLOT_COLOR_CELLS - ! allocate(pl % colors(n_cells)) - do j = 1, n_cells - pl % colors(j) % rgb(1) = int(prn()*255) - pl % colors(j) % rgb(2) = int(prn()*255) - pl % colors(j) % rgb(3) = int(prn()*255) - end do - - case ("material") - - pl % color_by = PLOT_COLOR_MATS - ! allocate(pl % colors(n_materials)) - do j = 1, n_materials - pl % colors(j) % rgb(1) = int(prn()*255) - pl % colors(j) % rgb(2) = int(prn()*255) - pl % colors(j) % rgb(3) = int(prn()*255) - end do - - case default - call fatal_error("Unsupported plot color type '" // trim(temp_str) & - // "' in plot " // trim(to_str(pl % id))) - end select - - ! Get the number of nodes and get a list of them - call get_node_list(node_plot, "color", node_col_list) - n_cols = size(node_col_list) - - ! Copy user specified colors - if (n_cols /= 0) then - - if (pl % type == PLOT_TYPE_VOXEL) then - if (master) call warning("Color specifications ignored in voxel & - &plot " // trim(to_str(pl % id))) - end if - - do j = 1, n_cols - - ! Get pointer to color spec XML node - node_col = node_col_list(j) - - ! Check and make sure 3 values are specified for RGB - if (node_word_count(node_col, "rgb") /= 3) then - call fatal_error("Bad RGB in plot " & - // trim(to_str(pl % id))) - end if - - ! Ensure that there is an id for this color specification - if (check_for_node(node_col, "id")) then - call get_node_value(node_col, "id", col_id) - else - call fatal_error("Must specify id for color specification in & - &plot " // trim(to_str(pl % id))) - end if - - ! Add RGB - if (pl % color_by == PLOT_COLOR_CELLS) then - - if (cell_dict % has(col_id)) then - col_id = cell_dict % get(col_id) - call get_node_array(node_col, "rgb", pl % colors(col_id) % rgb) - else - call fatal_error("Could not find cell " // trim(to_str(col_id)) & - // " specified in plot " // trim(to_str(pl % id))) - end if - - else if (pl % color_by == PLOT_COLOR_MATS) then - - if (material_dict % has(col_id)) then - col_id = material_dict % get(col_id) - call get_node_array(node_col, "rgb", pl % colors(col_id) % rgb) - else - call fatal_error("Could not find material " & - // trim(to_str(col_id)) // " specified in plot " & - // trim(to_str(pl % id))) - end if - - end if - end do - end if - - ! Deal with meshlines - call get_node_list(node_plot, "meshlines", node_meshline_list) - n_meshlines = size(node_meshline_list) - if (n_meshlines /= 0) then - - if (pl % type == PLOT_TYPE_VOXEL) then - call warning("Meshlines ignored in voxel plot " & - // trim(to_str(pl % id))) - end if - - select case(n_meshlines) - case (0) - ! Skip if no meshlines are specified - case (1) - - ! Get pointer to meshlines - node_meshlines = node_meshline_list(1) - - ! Check mesh type - if (check_for_node(node_meshlines, "meshtype")) then - call get_node_value(node_meshlines, "meshtype", meshtype) - else - call fatal_error("Must specify a meshtype for meshlines & - &specification in plot " // trim(to_str(pl % id))) - end if - - ! Ensure that there is a linewidth for this meshlines specification - if (check_for_node(node_meshlines, "linewidth")) then - call get_node_value(node_meshlines, "linewidth", & - pl % meshlines_width) - else - call fatal_error("Must specify a linewidth for meshlines & - &specification in plot " // trim(to_str(pl % id))) - end if - - ! Check for color - if (check_for_node(node_meshlines, "color")) then - - ! Check and make sure 3 values are specified for RGB - if (node_word_count(node_meshlines, "color") /= 3) then - call fatal_error("Bad RGB for meshlines color in plot " & - // trim(to_str(pl % id))) - end if - - call get_node_array(node_meshlines, "color", & - pl % meshlines_color % rgb) - else - - pl % meshlines_color % rgb = (/ 0, 0, 0 /) - - end if - - ! Set mesh based on type - select case (trim(meshtype)) - case ('ufs') - - if (index_ufs_mesh < 0) then - call fatal_error("No UFS mesh for meshlines on plot " & - // trim(to_str(pl % id))) - end if - - pl % index_meshlines_mesh = index_ufs_mesh - - case ('cmfd') - - if (.not. cmfd_run) then - call fatal_error("Need CMFD run to plot CMFD mesh for & - &meshlines on plot " // trim(to_str(pl % id))) - end if - - pl % index_meshlines_mesh = index_cmfd_mesh - - case ('entropy') - - if (index_entropy_mesh < 0) then - call fatal_error("No entropy mesh for meshlines on plot " & - // trim(to_str(pl % id))) - end if - - pl % index_meshlines_mesh = index_entropy_mesh - - case ('tally') - - ! Ensure that there is a mesh id if the type is tally - if (check_for_node(node_meshlines, "id")) then - call get_node_value(node_meshlines, "id", meshid) - else - call fatal_error("Must specify a mesh id for meshlines tally & - &mesh specification in plot " // trim(to_str(pl % id))) - end if - - ! Check if the specified tally mesh exists - err = openmc_get_mesh_index(meshid, idx) - if (err /= 0) then - call fatal_error("Could not find mesh " & - // trim(to_str(meshid)) // " specified in meshlines for & - &plot " // trim(to_str(pl % id))) - end if - pl % index_meshlines_mesh = idx - - case default - call fatal_error("Invalid type for meshlines on plot " & - // trim(to_str(pl % id)) // ": " // trim(meshtype)) - end select - - case default - call fatal_error("Mutliple meshlines specified in plot " & - // trim(to_str(pl % id))) - end select - - end if - - ! Deal with masks - call get_node_list(node_plot, "mask", node_mask_list) - n_masks = size(node_mask_list) - if (n_masks /= 0) then - - if (pl % type == PLOT_TYPE_VOXEL) then - if (master) call warning("Mask ignored in voxel plot " & - // trim(to_str(pl % id))) - end if - - select case(n_masks) - case default - call fatal_error("Mutliple masks specified in plot " & - // trim(to_str(pl % id))) - case (1) - - ! Get pointer to mask - node_mask = node_mask_list(1) - - ! Determine how many components there are and allocate - n_comp = 0 - n_comp = node_word_count(node_mask, "components") - if (n_comp == 0) then - call fatal_error("Missing in mask of plot " & - // trim(to_str(pl % id))) - end if - allocate(iarray(n_comp)) - call get_node_array(node_mask, "components", iarray) - - ! First we need to change the user-specified identifiers to indices - ! in the cell and material arrays - do j=1, n_comp - col_id = iarray(j) - - if (pl % color_by == PLOT_COLOR_CELLS) then - - if (cell_dict % has(col_id)) then - iarray(j) = cell_dict % get(col_id) - else - call fatal_error("Could not find cell " & - // trim(to_str(col_id)) // " specified in the mask in & - &plot " // trim(to_str(pl % id))) - end if - - else if (pl % color_by == PLOT_COLOR_MATS) then - - if (material_dict % has(col_id)) then - iarray(j) = material_dict % get(col_id) - else - call fatal_error("Could not find material " & - // trim(to_str(col_id)) // " specified in the mask in & - &plot " // trim(to_str(pl % id))) - end if - - end if - end do - - ! Alter colors based on mask information - do j = 1, size(pl % colors) - if (.not. any(j == iarray)) then - if (check_for_node(node_mask, "background")) then - call get_node_array(node_mask, "background", pl % colors(j) % rgb) - else - pl % colors(j) % rgb(:) = [255, 255, 255] - end if - end if - end do - - deallocate(iarray) - - end select - - end if - - ! Add plot to dictionary - call plot_dict % set(pl % id, i) - - end do READ_PLOTS ! Close plots XML file call doc % clear() From 2f4ef9b8db34ace378765ce4836bb01e6936172d Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Sat, 13 Oct 2018 08:43:38 -0500 Subject: [PATCH 043/105] Adding print_plots function to C++ output. --- src/output.cpp | 57 ++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 55 insertions(+), 2 deletions(-) diff --git a/src/output.cpp b/src/output.cpp index 0eb6b204c..bf6f1a7d9 100644 --- a/src/output.cpp +++ b/src/output.cpp @@ -12,7 +12,7 @@ #include "openmc/message_passing.h" #include "openmc/capi.h" #include "openmc/settings.h" - +#include "openmc/plot.h" namespace openmc { @@ -54,7 +54,60 @@ std::string time_stamp() //============================================================================== -void print_overlap_check() { +//=============================================================================== +// PRINT_PLOT displays selected options for plotting +//=============================================================================== + +void print_plot() { + header("PLOTTING SUMMARY", 5); + + for (auto pl : plots) { + // Plot id + std::cout << "Plot ID: " << pl->id << std::endl; + // Plot filename + std::cout << "Plot file: " << pl->path_plot << std::endl; + // Plot level + std::cout << "Universe depth: " << pl->level << std::endl; + + // Plot type + if (PLOT_TYPE::SLICE == pl->type) { + std::cout << "Plot Type: Slice" << std::endl; + } else if (PLOT_TYPE::VOXEL == pl->type) { + std::cout << "Plot Type: Voxel" << std::endl; + } + + // Plot parameters + std::cout << "Origin: " << pl->origin[0] << " " + << pl->origin[1] << " " + << pl->origin[2] << std::endl; + + if (PLOT_TYPE::SLICE == pl->type) { + switch(pl->basis) { + case PLOT_BASIS::XY: + std::cout << "Basis: XY" << std::endl; + break; + case PLOT_BASIS::XZ: + std::cout << "Basis: XZ" << std::endl; + break; + case PLOT_BASIS::YZ: + std::cout << "Basis: YZ" << std::endl; + break; + } + std::cout << "Pixels: " << pl->pixels[0] << " " + << pl->pixels[1] << " " << std::endl; + } else if (PLOT_TYPE::VOXEL == pl->type) { + std::cout << "Voxel: " << pl->pixels[0] << " " + << pl->pixels[1] << " " + << pl->pixels[2] << std::endl; + } + + std::cout << std::endl; + + } +} + +void +print_overlap_check() { #ifdef OPENMC_MPI std::vector temp(overlap_check_count); int err = MPI_Reduce(temp.data(), overlap_check_count.data(), From d11b90aa47767eee7a82acdb4a5055df71a542cf Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Sat, 13 Oct 2018 20:09:53 -0500 Subject: [PATCH 044/105] Fixing global plot variable definitions. --- include/openmc/plot.h | 14 +++++++------- src/plot.cpp | 8 ++++++++ 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/include/openmc/plot.h b/include/openmc/plot.h index a5fc870e7..0f4b5166b 100644 --- a/include/openmc/plot.h +++ b/include/openmc/plot.h @@ -16,13 +16,13 @@ namespace openmc { class ObjectPlot; - int PLOT_LEVEL_LOWEST = -1; + extern int PLOT_LEVEL_LOWEST; - std::map plot_dict; + extern std::map plot_dict; - int n_plots; + extern int n_plots; - std::vector plots; + extern std::vector plots; enum PLOT_TYPE { SLICE = 1, @@ -55,7 +55,7 @@ namespace openmc { struct ObjectPlot { ObjectPlot(pugi::xml_node plot); - + int id; int type; int color_by; @@ -74,9 +74,9 @@ namespace openmc { }; //extern "C" int openmc_plot_geometry(); - + extern "C" void read_plots(pugi::xml_node* plot_node); - + extern "C" void create_ppm(ObjectPlot* pl); extern "C" void create_voxel(ObjectPlot *pl); diff --git a/src/plot.cpp b/src/plot.cpp index 61a22bde7..3c7d4cbb3 100644 --- a/src/plot.cpp +++ b/src/plot.cpp @@ -17,6 +17,14 @@ namespace openmc { + int PLOT_LEVEL_LOWEST = -1; + + std::map plot_dict; + + int n_plots; + + std::vector plots; + const int RED = 0; const int GREEN = 1; const int BLUE = 2; From 41b58e0b9bbc8aa05643d786e92617ae415dc3dd Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Sat, 13 Oct 2018 21:24:25 -0500 Subject: [PATCH 045/105] Exposing print_plot through C. Using in input_xml now. --- include/openmc/output.h | 2 ++ src/input_xml.F90 | 5 ++- src/output.F90 | 73 ----------------------------------------- src/output.cpp | 20 +++++++++++ 4 files changed, 26 insertions(+), 74 deletions(-) diff --git a/include/openmc/output.h b/include/openmc/output.h index 793c9b727..4ba1303ea 100644 --- a/include/openmc/output.h +++ b/include/openmc/output.h @@ -31,6 +31,8 @@ std::string time_stamp(); void print_overlap_check(); +extern "C" void print_plot(); + extern "C" void title(); } // namespace openmc diff --git a/src/input_xml.F90 b/src/input_xml.F90 index 84e0d89eb..40ea04840 100644 --- a/src/input_xml.F90 +++ b/src/input_xml.F90 @@ -23,7 +23,7 @@ module input_xml use mgxs_interface use nuclide_header use multipole_header - use output, only: title, header, print_plot + use output, only: title, header use photon_header use plot_header use random_lcg, only: prn @@ -102,6 +102,9 @@ module input_xml type(C_PTR) :: node_ptr end subroutine read_plots + subroutine print_plot() bind(C) + end subroutine print_plot + subroutine set_particle_energy_bounds(particle, E_min, E_max) bind(C) import C_INT, C_DOUBLE integer(C_INT), value :: particle diff --git a/src/output.F90 b/src/output.F90 index ef3d3259c..4215fc509 100644 --- a/src/output.F90 +++ b/src/output.F90 @@ -412,79 +412,6 @@ contains end subroutine print_batch_keff -!=============================================================================== -! PRINT_PLOT displays selected options for plotting -!=============================================================================== - - subroutine print_plot() - - integer :: i ! loop index for plots - type(ObjectPlot), pointer :: pl - - ! Display header for plotting - call header("PLOTTING SUMMARY", 5) - - do i = 1, n_plots - pl => plots(i) - - ! Plot id - write(ou,100) "Plot ID:", trim(to_str(pl % id)) - - ! Plot filename - write(ou,100) "Plot file:", trim(pl % path_plot) - - ! Plot level - write(ou,100) "Universe depth:", trim(to_str(pl % level)) - - ! Plot type - if (pl % type == PLOT_TYPE_SLICE) then - write(ou,100) "Plot Type:", "Slice" - else if (pl % type == PLOT_TYPE_VOXEL) then - write(ou,100) "Plot Type:", "Voxel" - end if - - ! Plot parameters - write(ou,100) "Origin:", trim(to_str(pl % origin(1))) // & - " " // trim(to_str(pl % origin(2))) // " " // & - trim(to_str(pl % origin(3))) - if (pl % type == PLOT_TYPE_SLICE) then - write(ou,100) "Width:", trim(to_str(pl % width(1))) // & - " " // trim(to_str(pl % width(2))) - else if (pl % type == PLOT_TYPE_VOXEL) then - write(ou,100) "Width:", trim(to_str(pl % width(1))) // & - " " // trim(to_str(pl % width(2))) // & - " " // trim(to_str(pl % width(3))) - end if - if (pl % color_by == PLOT_COLOR_CELLS) then - write(ou,100) "Coloring:", "Cells" - else if (pl % color_by == PLOT_COLOR_MATS) then - write(ou,100) "Coloring:", "Materials" - end if - if (pl % type == PLOT_TYPE_SLICE) then - select case (pl % basis) - case (PLOT_BASIS_XY) - write(ou,100) "Basis:", "xy" - case (PLOT_BASIS_XZ) - write(ou,100) "Basis:", "xz" - case (PLOT_BASIS_YZ) - write(ou,100) "Basis:", "yz" - end select - write(ou,100) "Pixels:", trim(to_str(pl % pixels(1))) // " " // & - trim(to_str(pl % pixels(2))) - else if (pl % type == PLOT_TYPE_VOXEL) then - write(ou,100) "Voxels:", trim(to_str(pl % pixels(1))) // " " // & - trim(to_str(pl % pixels(2))) // " " // trim(to_str(pl % pixels(3))) - end if - - write(ou,*) - - end do - - ! Format descriptor for columns -100 format (1X,A,T25,A) - - end subroutine print_plot - !=============================================================================== ! PRINT_RUNTIME displays the total time elapsed for the entire run, for ! initialization, for computation, and for intergeneration synchronization. diff --git a/src/output.cpp b/src/output.cpp index bf6f1a7d9..4eb33cb00 100644 --- a/src/output.cpp +++ b/src/output.cpp @@ -59,6 +59,7 @@ std::string time_stamp() //=============================================================================== void print_plot() { + header("PLOTTING SUMMARY", 5); for (auto pl : plots) { @@ -80,6 +81,25 @@ void print_plot() { std::cout << "Origin: " << pl->origin[0] << " " << pl->origin[1] << " " << pl->origin[2] << std::endl; + + if (PLOT_TYPE::SLICE == pl->type) { + std::cout << std::setprecision(4) + << "Width: " + << pl->width[0] << " " + << pl->width[1] << std::endl; + } else if (PLOT_TYPE::VOXEL == pl->type) { + std::cout << std::setprecision(4) + << "Width: " + << pl->width[0] << " " + << pl->width[1] << " " + << pl->width[2] << std::endl; + } + + if (PLOT_COLOR_BY::CELLS == pl->color_by) { + std::cout << "Coloring: Cells" << std::endl; + } else if (PLOT_COLOR_BY::MATS == pl->color_by) { + std::cout << "Coloring: Materials" << std::endl; + } if (PLOT_TYPE::SLICE == pl->type) { switch(pl->basis) { From 288937a5ef7af9e6d71710fd485425cafcfbacd8 Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Sat, 13 Oct 2018 21:52:46 -0500 Subject: [PATCH 046/105] Removing plot_header.: --- CMakeLists.txt | 1 - src/input_xml.F90 | 1 - src/plot_header.F90 | 72 --------------------------------------------- 3 files changed, 74 deletions(-) delete mode 100644 src/plot_header.F90 diff --git a/CMakeLists.txt b/CMakeLists.txt index d3aacad71..f9c34eeb3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -345,7 +345,6 @@ add_library(libopenmc SHARED src/physics_common.F90 src/physics.F90 src/physics_mg.F90 - src/plot_header.F90 src/progress_header.F90 src/pugixml/pugixml_f.F90 src/random_lcg.F90 diff --git a/src/input_xml.F90 b/src/input_xml.F90 index 40ea04840..4c131f0bd 100644 --- a/src/input_xml.F90 +++ b/src/input_xml.F90 @@ -2047,7 +2047,6 @@ contains character(MAX_LINE_LEN) :: filename ! absolute path to plots.xml character(MAX_LINE_LEN) :: temp_str character(MAX_WORD_LEN) :: meshtype - type(ObjectPlot), pointer :: pl => null() type(XMLDocument) :: doc type(XMLNode) :: root type(XMLNode) :: node_plot diff --git a/src/plot_header.F90 b/src/plot_header.F90 deleted file mode 100644 index 0495d83d3..000000000 --- a/src/plot_header.F90 +++ /dev/null @@ -1,72 +0,0 @@ -module plot_header - - use, intrinsic :: ISO_C_BINDING - - use constants - use dict_header, only: DictIntInt - - implicit none - -!=============================================================================== -! ObjectColor holds color information for plotted objects -!=============================================================================== - - type, bind(C) :: ObjectColor - integer(C_INT) :: rgb(3) - end type ObjectColor - -!=============================================================================== -! PLOTSLICE holds plot information -!=============================================================================== - - type, bind(C) :: ObjectPlot - integer(C_INT) :: id ! Unique ID - integer(C_INT) :: type ! Type - integer(C_INT) :: color_by ! quantity to color regions by - real(C_DOUBLE) :: origin(3) ! xyz center of plot location - real(C_DOUBLE) :: width(3) ! xyz widths of plot - integer(C_INT) :: basis ! direction of plot slice - integer(C_INT) :: pixels(3) ! pixel width/height of plot slice - integer(C_INT) :: meshlines_width ! pixel width of meshlines - integer(C_INT) :: level ! universe depth to plot the cells of - integer(C_INT) :: index_meshlines_mesh = -1 ! index of mesh to plot - type(ObjectColor) :: meshlines_color ! Color for meshlines - type(ObjectColor) :: not_found ! color for positions where no cell found - type(ObjectColor) :: colors(MAX_COORD) ! colors of cells/mats - character(MAX_WORD_LEN, kind=C_CHAR) :: path_plot ! path for plot file - end type ObjectPlot - - ! Plot type - integer, parameter :: PLOT_TYPE_SLICE = 1 - integer, parameter :: PLOT_TYPE_VOXEL = 2 - - ! Plot level - integer, parameter :: PLOT_LEVEL_LOWEST = -1 - - ! Plot basis plane - integer, parameter :: PLOT_BASIS_XY = 1 - integer, parameter :: PLOT_BASIS_XZ = 2 - integer, parameter :: PLOT_BASIS_YZ = 3 - - ! Indicate whether color refers to unique cell or unique material - integer, parameter :: PLOT_COLOR_CELLS = 1 - integer, parameter :: PLOT_COLOR_MATS = 2 - - integer(C_INT32_T), bind(C) :: n_plots ! # of plots - - type(ObjectPlot), allocatable, target :: plots(:) - - ! Dictionary that maps user IDs to indices in 'plots' - type(DictIntInt) :: plot_dict - -contains - -!=============================================================================== -! FREE_MEMORY_PLOT deallocates global arrays defined in this module -!=============================================================================== - -!=============================================================================== -! RUN_PLOT controls the logic for making one or many plots -!=============================================================================== - -end module plot_header From ec3c51e575112b51b99a8de15f39e7d6565984eb Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Sat, 13 Oct 2018 22:01:38 -0500 Subject: [PATCH 047/105] Removing unused variables in read_plots_xml. --- src/input_xml.F90 | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/src/input_xml.F90 b/src/input_xml.F90 index 4c131f0bd..6476f7d7f 100644 --- a/src/input_xml.F90 +++ b/src/input_xml.F90 @@ -2038,26 +2038,10 @@ contains subroutine read_plots_xml() - integer :: i, j - integer :: n_cols, col_id, n_comp, n_masks, n_meshlines - integer :: meshid - integer(C_INT) :: err, idx - integer, allocatable :: iarray(:) logical :: file_exists ! does plots.xml file exist? character(MAX_LINE_LEN) :: filename ! absolute path to plots.xml - character(MAX_LINE_LEN) :: temp_str - character(MAX_WORD_LEN) :: meshtype type(XMLDocument) :: doc type(XMLNode) :: root - type(XMLNode) :: node_plot - type(XMLNode) :: node_col - type(XMLNode) :: node_mask - type(XMLNode) :: node_meshlines - type(XMLNode), allocatable :: node_plot_list(:) - type(XMLNode), allocatable :: node_col_list(:) - type(XMLNode), allocatable :: node_mask_list(:) - type(XMLNode), allocatable :: node_meshline_list(:) - ! Check if plots.xml exists filename = trim(path_input) // "plots.xml" From e25b3342a893986f71d1e56d26c524fb42fa9deb Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Sat, 13 Oct 2018 22:43:24 -0500 Subject: [PATCH 048/105] Removing other plot_header references. --- src/api.F90 | 1 - src/input_xml.F90 | 1 - src/output.F90 | 1 - 3 files changed, 3 deletions(-) diff --git a/src/api.F90 b/src/api.F90 index 25a992c9f..bb99180cc 100644 --- a/src/api.F90 +++ b/src/api.F90 @@ -63,7 +63,6 @@ contains use geometry_header use material_header use photon_header - use plot_header use sab_header use settings use simulation_header diff --git a/src/input_xml.F90 b/src/input_xml.F90 index 6476f7d7f..74ca51223 100644 --- a/src/input_xml.F90 +++ b/src/input_xml.F90 @@ -25,7 +25,6 @@ module input_xml use multipole_header use output, only: title, header use photon_header - use plot_header use random_lcg, only: prn use surface_header use set_header, only: SetChar, SetInt diff --git a/src/output.F90 b/src/output.F90 index 4215fc509..485d957a6 100644 --- a/src/output.F90 +++ b/src/output.F90 @@ -14,7 +14,6 @@ module output use mgxs_interface use nuclide_header use particle_header, only: LocalCoord, Particle - use plot_header use sab_header, only: SAlphaBeta use settings use simulation_header From ade46934d198b61e2b7569f717b954ae797f8286 Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Tue, 23 Oct 2018 13:44:31 -0500 Subject: [PATCH 049/105] Fix CMake after rebase. --- CMakeLists.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f9c34eeb3..2800f6030 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -344,7 +344,6 @@ add_library(libopenmc SHARED src/photon_physics.F90 src/physics_common.F90 src/physics.F90 - src/physics_mg.F90 src/progress_header.F90 src/pugixml/pugixml_f.F90 src/random_lcg.F90 From 7930513bbd1b51e8d6c2481d01500b002d5e21ea Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Tue, 23 Oct 2018 14:51:02 -0500 Subject: [PATCH 050/105] Refactoring ObjectPlot constructor. --- include/openmc/plot.h | 13 +++++++ src/plot.cpp | 82 +++++++++++++++++++++++++++++++++++++------ 2 files changed, 84 insertions(+), 11 deletions(-) diff --git a/include/openmc/plot.h b/include/openmc/plot.h index 0f4b5166b..c71950fca 100644 --- a/include/openmc/plot.h +++ b/include/openmc/plot.h @@ -71,6 +71,19 @@ namespace openmc { std::vector colors; std::string path_plot; + private: + void set_id(pugi::xml_node plot_node); + void set_type(pugi::xml_node plot_node); + void set_output_path(pugi::xml_node plot_node); + void set_bg_color(pugi::xml_node plot_node); + void set_basis(pugi::xml_node plot_node); + void set_origin(pugi::xml_node plot_node); + void set_width(pugi::xml_node plot_node); + void set_universe(pugi::xml_node plot_node); + void set_default_colors(pugi::xml_node plot_node); + void set_user_colors(pugi::xml_node plot_node); + void set_meshlines(pugi::xml_node plot_node); + void set_mask(pugi::xml_node plot_node); }; //extern "C" int openmc_plot_geometry(); diff --git a/src/plot.cpp b/src/plot.cpp index 3c7d4cbb3..4e9d49597 100644 --- a/src/plot.cpp +++ b/src/plot.cpp @@ -152,10 +152,9 @@ void create_ppm(ObjectPlot* pl) { } - ObjectPlot::ObjectPlot(pugi::xml_node plot_node) : - index_meshlines_mesh(-1) { - - // Copy data into plots +void +ObjectPlot::set_id(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 { @@ -170,6 +169,10 @@ void create_ppm(ObjectPlot* pl) { fatal_error(err_msg.str()); } +} + +void +ObjectPlot::set_type(pugi::xml_node plot_node) { // Copy plot type // Default is slice std::string type_str = "slice"; @@ -188,8 +191,11 @@ void create_ppm(ObjectPlot* pl) { << "' in plot " << id; fatal_error(err_msg.str()); } - } + } +} +void +ObjectPlot::set_output_path(pugi::xml_node plot_node) { // Set output file path std::stringstream filename; filename << "plot_" << id; @@ -234,8 +240,11 @@ void create_ppm(ObjectPlot* pl) { fatal_error(err_msg.str()); } } +} - // Copy plot background color +void +ObjectPlot::set_bg_color(pugi::xml_node plot_node){ + // Copy plot background color std::vector bg_rgb; if (check_for_node(plot_node, "background")) { if (PLOT_TYPE::VOXEL == type) { @@ -263,7 +272,10 @@ void create_ppm(ObjectPlot* pl) { not_found.rgb[1] = 255; not_found.rgb[2] = 255; } +} +void +ObjectPlot::set_basis(pugi::xml_node plot_node) { // Copy plot basis if (PLOT_TYPE::SLICE == type) { std::string pl_basis = "xy"; @@ -284,7 +296,10 @@ void create_ppm(ObjectPlot* pl) { fatal_error(err_msg); } } +} +void +ObjectPlot::set_origin(pugi::xml_node plot_node) { // Copy plotting origin std::vector pl_origin; if (node_word_count(plot_node, "origin") == 3) { @@ -298,8 +313,11 @@ void create_ppm(ObjectPlot* pl) { << id; fatal_error(err_msg); } +} - // Copy plotting width +void +ObjectPlot::set_width(pugi::xml_node plot_node) { + // Copy plotting width std::vector pl_width; if (PLOT_TYPE::SLICE == type) { if (node_word_count(plot_node, "width") == 2) { @@ -325,7 +343,10 @@ void create_ppm(ObjectPlot* pl) { fatal_error(err_msg); } } +} +void +ObjectPlot::set_universe(pugi::xml_node plot_node) { // Copy plot universe level if (check_for_node(plot_node, "level")) { level = std::stoi(get_node_value(plot_node, "level")); @@ -337,7 +358,10 @@ void create_ppm(ObjectPlot* pl) { } else { level = PLOT_LEVEL_LOWEST; } +} +void +ObjectPlot::set_default_colors(pugi::xml_node plot_node) { // Copy plot color type and initialize all colors randomly std::string pl_color_by = "cell"; if (check_for_node(plot_node, "color_by")) { @@ -370,8 +394,11 @@ void create_ppm(ObjectPlot* pl) { << "' in plot " << id; fatal_error(err_msg); } +} - // Get the number of nodes and get a list of them +void +ObjectPlot::set_user_colors(pugi::xml_node plot_node) { + // Get the number of nodes and get a list of them std::vector color_nodes; color_nodes = get_child_nodes(plot_node, "color"); @@ -439,9 +466,11 @@ void create_ppm(ObjectPlot* pl) { } } // color node loop } +} - - // Deal with meshlines +void +ObjectPlot::set_meshlines(pugi::xml_node plot_node) { + // Deal with meshlines std::vector mesh_line_nodes; mesh_line_nodes = get_child_nodes(plot_node, "meshlines"); @@ -566,8 +595,11 @@ void create_ppm(ObjectPlot* pl) { fatal_error(err_msg); } } +} - // Deal with masks +void +ObjectPlot::set_mask(pugi::xml_node plot_node) { + // Deal with masks std::vector mask_nodes; mask_nodes = get_child_nodes(plot_node, "mask"); int n_masks = mask_nodes.size(); @@ -648,6 +680,34 @@ void create_ppm(ObjectPlot* pl) { fatal_error(err_msg); } } +} + +ObjectPlot::ObjectPlot(pugi::xml_node plot_node) + : index_meshlines_mesh(-1) { + + set_id(plot_node); + + set_type(plot_node); + + set_output_path(plot_node); + + set_bg_color(plot_node); + + set_basis(plot_node); + + set_origin(plot_node); + + set_width(plot_node); + + set_universe(plot_node); + + set_default_colors(plot_node); + + set_user_colors(plot_node); + + set_meshlines(plot_node); + + set_mask(plot_node); } // End ObjectPlot constructor From 765ec2c7bb7f6d74e0ee2f6c7d52e9e37f897495 Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Tue, 23 Oct 2018 14:58:44 -0500 Subject: [PATCH 051/105] Updating ObjectPlot node passing. --- include/openmc/plot.h | 25 +++++++++++---------- src/plot.cpp | 52 ++++++++++++++++++++++--------------------- 2 files changed, 40 insertions(+), 37 deletions(-) diff --git a/include/openmc/plot.h b/include/openmc/plot.h index c71950fca..a02db40d3 100644 --- a/include/openmc/plot.h +++ b/include/openmc/plot.h @@ -70,20 +70,21 @@ namespace openmc { ObjectColor not_found; std::vector colors; std::string path_plot; + pugi::xml_node plot_node; private: - void set_id(pugi::xml_node plot_node); - void set_type(pugi::xml_node plot_node); - void set_output_path(pugi::xml_node plot_node); - void set_bg_color(pugi::xml_node plot_node); - void set_basis(pugi::xml_node plot_node); - void set_origin(pugi::xml_node plot_node); - void set_width(pugi::xml_node plot_node); - void set_universe(pugi::xml_node plot_node); - void set_default_colors(pugi::xml_node plot_node); - void set_user_colors(pugi::xml_node plot_node); - void set_meshlines(pugi::xml_node plot_node); - void set_mask(pugi::xml_node plot_node); + void set_id(); + void set_type(); + void set_output_path(); + void set_bg_color(); + void set_basis(); + void set_origin(); + void set_width(); + void set_universe(); + void set_default_colors(); + void set_user_colors(); + void set_meshlines(); + void set_mask(); }; //extern "C" int openmc_plot_geometry(); diff --git a/src/plot.cpp b/src/plot.cpp index 4e9d49597..4bab60f24 100644 --- a/src/plot.cpp +++ b/src/plot.cpp @@ -153,7 +153,7 @@ void create_ppm(ObjectPlot* pl) { } void -ObjectPlot::set_id(pugi::xml_node plot_node) { +ObjectPlot::set_id() { // Copy data into plots if (check_for_node(plot_node, "id")) { id = std::stoi(get_node_value(plot_node, "id")); @@ -172,7 +172,7 @@ ObjectPlot::set_id(pugi::xml_node plot_node) { } void -ObjectPlot::set_type(pugi::xml_node plot_node) { +ObjectPlot::set_type() { // Copy plot type // Default is slice std::string type_str = "slice"; @@ -195,7 +195,7 @@ ObjectPlot::set_type(pugi::xml_node plot_node) { } void -ObjectPlot::set_output_path(pugi::xml_node plot_node) { +ObjectPlot::set_output_path() { // Set output file path std::stringstream filename; filename << "plot_" << id; @@ -243,7 +243,7 @@ ObjectPlot::set_output_path(pugi::xml_node plot_node) { } void -ObjectPlot::set_bg_color(pugi::xml_node plot_node){ +ObjectPlot::set_bg_color(){ // Copy plot background color std::vector bg_rgb; if (check_for_node(plot_node, "background")) { @@ -275,7 +275,7 @@ ObjectPlot::set_bg_color(pugi::xml_node plot_node){ } void -ObjectPlot::set_basis(pugi::xml_node plot_node) { +ObjectPlot::set_basis() { // Copy plot basis if (PLOT_TYPE::SLICE == type) { std::string pl_basis = "xy"; @@ -299,7 +299,7 @@ ObjectPlot::set_basis(pugi::xml_node plot_node) { } void -ObjectPlot::set_origin(pugi::xml_node plot_node) { +ObjectPlot::set_origin() { // Copy plotting origin std::vector pl_origin; if (node_word_count(plot_node, "origin") == 3) { @@ -316,7 +316,7 @@ ObjectPlot::set_origin(pugi::xml_node plot_node) { } void -ObjectPlot::set_width(pugi::xml_node plot_node) { +ObjectPlot::set_width() { // Copy plotting width std::vector pl_width; if (PLOT_TYPE::SLICE == type) { @@ -346,7 +346,7 @@ ObjectPlot::set_width(pugi::xml_node plot_node) { } void -ObjectPlot::set_universe(pugi::xml_node plot_node) { +ObjectPlot::set_universe() { // Copy plot universe level if (check_for_node(plot_node, "level")) { level = std::stoi(get_node_value(plot_node, "level")); @@ -361,7 +361,7 @@ ObjectPlot::set_universe(pugi::xml_node plot_node) { } void -ObjectPlot::set_default_colors(pugi::xml_node plot_node) { +ObjectPlot::set_default_colors() { // Copy plot color type and initialize all colors randomly std::string pl_color_by = "cell"; if (check_for_node(plot_node, "color_by")) { @@ -397,7 +397,7 @@ ObjectPlot::set_default_colors(pugi::xml_node plot_node) { } void -ObjectPlot::set_user_colors(pugi::xml_node plot_node) { +ObjectPlot::set_user_colors() { // Get the number of nodes and get a list of them std::vector color_nodes; color_nodes = get_child_nodes(plot_node, "color"); @@ -469,7 +469,7 @@ ObjectPlot::set_user_colors(pugi::xml_node plot_node) { } void -ObjectPlot::set_meshlines(pugi::xml_node plot_node) { +ObjectPlot::set_meshlines() { // Deal with meshlines std::vector mesh_line_nodes; mesh_line_nodes = get_child_nodes(plot_node, "meshlines"); @@ -598,7 +598,7 @@ ObjectPlot::set_meshlines(pugi::xml_node plot_node) { } void -ObjectPlot::set_mask(pugi::xml_node plot_node) { +ObjectPlot::set_mask() { // Deal with masks std::vector mask_nodes; mask_nodes = get_child_nodes(plot_node, "mask"); @@ -683,32 +683,34 @@ ObjectPlot::set_mask(pugi::xml_node plot_node) { } ObjectPlot::ObjectPlot(pugi::xml_node plot_node) - : index_meshlines_mesh(-1) { + : index_meshlines_mesh(-1), plot_node(plot_node) { - set_id(plot_node); + set_id(); - set_type(plot_node); + set_type(); - set_output_path(plot_node); + set_output_path(); - set_bg_color(plot_node); + set_bg_color(); - set_basis(plot_node); + set_basis(); - set_origin(plot_node); + set_origin(); - set_width(plot_node); + set_width(); - set_universe(plot_node); + set_universe(); - set_default_colors(plot_node); + set_default_colors(); - set_user_colors(plot_node); + set_user_colors(); - set_meshlines(plot_node); + set_meshlines(); - set_mask(plot_node); + set_mask(); + plot_node = pugi::xml_node(); // set to null node after construction + } // End ObjectPlot constructor //=============================================================================== From 8540838950355e0cc21b65fea19d5e55b6474d3f Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Fri, 26 Oct 2018 11:04:38 -0500 Subject: [PATCH 052/105] Updating style. Using macros. Adding to get_child_nodes function. --- include/openmc/constants.h | 3 +- include/openmc/output.h | 4 +- include/openmc/plot.h | 66 +++++------ include/openmc/string_functions.h | 2 +- include/openmc/xml_interface.h | 6 +- src/plot.cpp | 178 ++++++++++++++++-------------- src/string_functions.cpp | 8 +- src/xml_interface.cpp | 10 +- 8 files changed, 144 insertions(+), 133 deletions(-) diff --git a/include/openmc/constants.h b/include/openmc/constants.h index 60a2e0691..bfd4960f7 100644 --- a/include/openmc/constants.h +++ b/include/openmc/constants.h @@ -85,8 +85,7 @@ constexpr double INFTY {std::numeric_limits::max()}; constexpr double ONE {1.0}; constexpr double TWO {2.0}; constexpr double HALF {0.5}; - - + // Physical constants constexpr double MASS_NEUTRON {1.00866491588}; // mass of a neutron in amu constexpr double MASS_NEUTRON_EV {939.5654133e6}; // mass of a neutron in eV/c^2 diff --git a/include/openmc/output.h b/include/openmc/output.h index 4ba1303ea..8f76e43ae 100644 --- a/include/openmc/output.h +++ b/include/openmc/output.h @@ -22,9 +22,9 @@ void header(const char* msg, int level); //! Retrieve a time stamp with the format "yyyy-mm-dd hh:mm:ss" //! //============================================================================== - + std::string time_stamp(); - + //============================================================================== //! Display information regarding cell overlap checking. //============================================================================== diff --git a/include/openmc/plot.h b/include/openmc/plot.h index a02db40d3..004ca30d1 100644 --- a/include/openmc/plot.h +++ b/include/openmc/plot.h @@ -52,42 +52,42 @@ namespace openmc { // ObjectPlot holds plot information //=============================================================================== - struct ObjectPlot { +class ObjectPlot +{ - ObjectPlot(pugi::xml_node plot); +public: + ObjectPlot(pugi::xml_node plot); - int id; - int type; - int color_by; - Position origin; - Position width; - int basis; - int pixels[3]; - int meshlines_width; - int level; - int index_meshlines_mesh; - ObjectColor meshlines_color; - ObjectColor not_found; - std::vector colors; - std::string path_plot; - pugi::xml_node plot_node; + int id; + int type; + int color_by; + Position origin; + Position width; + int basis; + int pixels[3]; + int meshlines_width; + int level; + int index_meshlines_mesh; + ObjectColor meshlines_color; + ObjectColor not_found; + std::vector colors; + std::string path_plot; + pugi::xml_node plot_node; - private: - void set_id(); - void set_type(); - void set_output_path(); - void set_bg_color(); - void set_basis(); - void set_origin(); - void set_width(); - void set_universe(); - void set_default_colors(); - void set_user_colors(); - void set_meshlines(); - void set_mask(); - }; - - //extern "C" int openmc_plot_geometry(); + private: + void set_id(); + void set_type(); + void set_output_path(); + void set_bg_color(); + void set_basis(); + void set_origin(); + void set_width(); + void set_universe(); + void set_default_colors(); + void set_user_colors(); + void set_meshlines(); + void set_mask(); +}; extern "C" void read_plots(pugi::xml_node* plot_node); diff --git a/include/openmc/string_functions.h b/include/openmc/string_functions.h index acbbe4e1d..a653d1e77 100644 --- a/include/openmc/string_functions.h +++ b/include/openmc/string_functions.h @@ -15,6 +15,6 @@ char* strtrim(char* c_str); void to_lower(std::string& str); int word_count(std::string const& str); - + } // namespace openmc #endif // STRING_FUNCTIONS_H diff --git a/include/openmc/xml_interface.h b/include/openmc/xml_interface.h index e8248ca86..104e6ec27 100644 --- a/include/openmc/xml_interface.h +++ b/include/openmc/xml_interface.h @@ -50,12 +50,8 @@ xt::xarray get_node_xarray(pugi::xml_node node, const char* name, return xt::adapt(v, shape); } -//=============================================================================== -// GET_NODE_LIST is used to get a pointer to a list of sub-element nodes -//=============================================================================== - std::vector -get_child_nodes(pugi::xml_node node, const char* name); +get_child_nodes(pugi::xml_node node, const char* name = NULL); int node_word_count(pugi::xml_node node, const char* name); diff --git a/src/plot.cpp b/src/plot.cpp index 4bab60f24..0cbdd8d2b 100644 --- a/src/plot.cpp +++ b/src/plot.cpp @@ -17,13 +17,13 @@ namespace openmc { - int PLOT_LEVEL_LOWEST = -1; +int PLOT_LEVEL_LOWEST = -1; - std::map plot_dict; +std::map plot_dict; - int n_plots; +int n_plots; - std::vector plots; +std::vector plots; const int RED = 0; const int GREEN = 1; @@ -37,7 +37,8 @@ const int NULLRGB[3] = {0, 0, 0}; //=============================================================================== extern "C" -int openmc_plot_geometry() { +int openmc_plot_geometry() +{ int err; for(int i = 0; i < n_plots; i++) { @@ -57,13 +58,14 @@ int openmc_plot_geometry() { create_voxel(pl); continue; } - } return 0; } -void read_plots(pugi::xml_node* plots_node) { +void +read_plots(pugi::xml_node* plots_node) +{ std::vector plot_nodes; plot_nodes = get_child_nodes(*plots_node, "plot"); @@ -82,7 +84,8 @@ void read_plots(pugi::xml_node* plots_node) { // specification in the portable pixmap format (PPM) //=============================================================================== -void create_ppm(ObjectPlot* pl) { +void create_ppm(ObjectPlot* pl) +{ int width = pl->pixels[0]; int height = pl->pixels[1]; @@ -146,14 +149,16 @@ void create_ppm(ObjectPlot* pl) { } } + // draw mesh lines if present if (pl->index_meshlines_mesh >= 0) { draw_mesh_lines(pl, data); } + // write ppm data to file output_ppm(pl, data); - } void -ObjectPlot::set_id() { +ObjectPlot::set_id() +{ // Copy data into plots if (check_for_node(plot_node, "id")) { id = std::stoi(get_node_value(plot_node, "id")); @@ -168,34 +173,39 @@ ObjectPlot::set_id() { err_msg << id; fatal_error(err_msg.str()); } - } void -ObjectPlot::set_type() { +ObjectPlot::set_type() +{ // Copy plot type // Default is slice std::string type_str = "slice"; type = PLOT_TYPE::SLICE; + // check type specified on plot node if (check_for_node(plot_node, "type")) { type_str = get_node_value(plot_node, "type"); to_lower(type_str); + // set type using node value if (type_str == "slice") { type = PLOT_TYPE::SLICE; + return; } 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()); + return; } - } + // if we're here, something is wrong + std::stringstream err_msg; + err_msg << "Unsupported plot type '" << type_str + << "' in plot " << id; + fatal_error(err_msg.str()); + } } void -ObjectPlot::set_output_path() { +ObjectPlot::set_output_path() +{ // Set output file path std::stringstream filename; filename << "plot_" << id; @@ -243,7 +253,8 @@ ObjectPlot::set_output_path() { } void -ObjectPlot::set_bg_color(){ +ObjectPlot::set_bg_color() +{ // Copy plot background color std::vector bg_rgb; if (check_for_node(plot_node, "background")) { @@ -257,9 +268,9 @@ ObjectPlot::set_bg_color(){ } 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]; + not_found.rgb[RED] = bg_rgb[RED]; + not_found.rgb[GREEN] = bg_rgb[GREEN]; + not_found.rgb[BLUE] = bg_rgb[BLUE]; } else { std::stringstream err_msg; err_msg << "Bad background RGB in plot " @@ -268,14 +279,15 @@ ObjectPlot::set_bg_color(){ } } else { // default to a white background - not_found.rgb[0] = 255; - not_found.rgb[1] = 255; - not_found.rgb[2] = 255; + not_found.rgb[RED] = 255; + not_found.rgb[GREEN] = 255; + not_found.rgb[BLUE] = 255; } } void -ObjectPlot::set_basis() { +ObjectPlot::set_basis() +{ // Copy plot basis if (PLOT_TYPE::SLICE == type) { std::string pl_basis = "xy"; @@ -296,10 +308,11 @@ ObjectPlot::set_basis() { fatal_error(err_msg); } } -} +} void -ObjectPlot::set_origin() { +ObjectPlot::set_origin() +{ // Copy plotting origin std::vector pl_origin; if (node_word_count(plot_node, "origin") == 3) { @@ -316,8 +329,9 @@ ObjectPlot::set_origin() { } void -ObjectPlot::set_width() { - // Copy plotting width +ObjectPlot::set_width() +{ + // Copy plotting width std::vector pl_width; if (PLOT_TYPE::SLICE == type) { if (node_word_count(plot_node, "width") == 2) { @@ -346,7 +360,8 @@ ObjectPlot::set_width() { } void -ObjectPlot::set_universe() { +ObjectPlot::set_universe() +{ // Copy plot universe level if (check_for_node(plot_node, "level")) { level = std::stoi(get_node_value(plot_node, "level")); @@ -358,10 +373,11 @@ ObjectPlot::set_universe() { } else { level = PLOT_LEVEL_LOWEST; } -} +} void -ObjectPlot::set_default_colors() { +ObjectPlot::set_default_colors() +{ // Copy plot color type and initialize all colors randomly std::string pl_color_by = "cell"; if (check_for_node(plot_node, "color_by")) { @@ -370,23 +386,20 @@ ObjectPlot::set_default_colors() { } if ("cell" == pl_color_by) { color_by = PLOT_COLOR_BY::CELLS; - for(int i = 0; i < n_cells; i++) { colors.push_back(new ObjectColor()); - colors[i]->rgb[0] = int(prn()*255); - colors[i]->rgb[1] = int(prn()*255); - colors[i]->rgb[2] = int(prn()*255); + colors[i]->rgb[RED] = int(prn()*255); + colors[i]->rgb[GREEN] = int(prn()*255); + colors[i]->rgb[BLUE] = int(prn()*255); } } else if("material" == pl_color_by) { - color_by = PLOT_COLOR_BY::MATS; - for(int i = 0; i < materials.size(); i++) { colors.push_back(new ObjectColor()); - colors[i]->rgb[0] = int(prn()*255); - colors[i]->rgb[1] = int(prn()*255); - colors[i]->rgb[2] = int(prn()*255); + colors[i]->rgb[RED] = int(prn()*255); + colors[i]->rgb[GREEN] = int(prn()*255); + colors[i]->rgb[BLUE] = int(prn()*255); } } else { std::stringstream err_msg; @@ -397,8 +410,9 @@ ObjectPlot::set_default_colors() { } void -ObjectPlot::set_user_colors() { - // Get the number of nodes and get a list of them +ObjectPlot::set_user_colors() +{ + // Get the number of nodes and get a list of them std::vector color_nodes; color_nodes = get_child_nodes(plot_node, "color"); @@ -415,14 +429,12 @@ ObjectPlot::set_user_colors() { } for(auto cn : color_nodes) { - // Check and make sure 3 values are specified for RGB if (node_word_count(cn, "rgb") != 3) { std::stringstream err_msg; err_msg << "Bad RGB in plot " << id; fatal_error(err_msg); } - // Ensure that there is an id for this color specification int col_id; if (check_for_node(cn, "id")) { @@ -433,16 +445,15 @@ ObjectPlot::set_user_colors() { << id; fatal_error(err_msg); } - // Add RGB if (PLOT_COLOR_BY::CELLS == color_by) { std::vector cell_rgb; if (cell_map.find(col_id) != cell_map.end()) { col_id = cell_map[col_id]; cell_rgb = get_node_array(cn, "rgb"); - colors[col_id - 1]->rgb[0] = cell_rgb[0]; - colors[col_id - 1]->rgb[1] = cell_rgb[1]; - colors[col_id - 1]->rgb[2] = cell_rgb[2]; + colors[col_id - 1]->rgb[RED] = cell_rgb[RED]; + colors[col_id - 1]->rgb[GREEN] = cell_rgb[GREEN]; + colors[col_id - 1]->rgb[BLUE] = cell_rgb[BLUE]; } else { std::stringstream err_msg; err_msg << "Could not find cell " << col_id @@ -454,9 +465,9 @@ ObjectPlot::set_user_colors() { if (material_map.find(col_id) != material_map.end()) { col_id = material_map[col_id]; mat_rgb = get_node_array(cn, "rgb"); - colors[col_id - 1]->rgb[0] = mat_rgb[0]; - colors[col_id - 1]->rgb[1] = mat_rgb[1]; - colors[col_id - 1]->rgb[2] = mat_rgb[2]; + colors[col_id - 1]->rgb[RED] = mat_rgb[RED]; + colors[col_id - 1]->rgb[GREEN] = mat_rgb[GREEN]; + colors[col_id - 1]->rgb[BLUE] = mat_rgb[BLUE]; } else { std::stringstream err_msg; err_msg << "Could not find material " << col_id @@ -469,15 +480,15 @@ ObjectPlot::set_user_colors() { } void -ObjectPlot::set_meshlines() { - // Deal with meshlines +ObjectPlot::set_meshlines() +{ + // Deal with meshlines std::vector mesh_line_nodes; mesh_line_nodes = get_child_nodes(plot_node, "meshlines"); int n_meshlines = mesh_line_nodes.size(); if (n_meshlines != 0) { - if (PLOT_TYPE::VOXEL == type) { std::stringstream msg; msg << "Meshlines ignored in voxel plot " << id; @@ -598,14 +609,14 @@ ObjectPlot::set_meshlines() { } void -ObjectPlot::set_mask() { - // Deal with masks +ObjectPlot::set_mask() +{ + // Deal with masks std::vector mask_nodes; mask_nodes = get_child_nodes(plot_node, "mask"); int n_masks = mask_nodes.size(); if (n_masks > 0) { - if (PLOT_TYPE::VOXEL == type) { if (openmc_master) { std::stringstream wrn_msg; @@ -663,13 +674,13 @@ ObjectPlot::set_mask() { if (std::find(iarray.begin(), iarray.end(), j) != iarray.end()) { if (check_for_node(mask_node, "background")) { std::vector bg_rgb = get_node_array(mask_node, "background"); - colors[j]->rgb[0] = bg_rgb[0]; - colors[j]->rgb[1] = bg_rgb[1]; - colors[j]->rgb[2] = bg_rgb[2]; + colors[j]->rgb[RED] = bg_rgb[RED]; + colors[j]->rgb[GREEN] = bg_rgb[GREEN]; + colors[j]->rgb[BLUE] = bg_rgb[BLUE]; } else { - colors[j]->rgb[0] = 255; - colors[j]->rgb[1] = 255; - colors[j]->rgb[2] = 255; + colors[j]->rgb[RED] = 255; + colors[j]->rgb[GREEN] = 255; + colors[j]->rgb[BLUE] = 255; } } } @@ -681,12 +692,13 @@ ObjectPlot::set_mask() { } } } - -ObjectPlot::ObjectPlot(pugi::xml_node plot_node) - : index_meshlines_mesh(-1), plot_node(plot_node) { + +ObjectPlot::ObjectPlot(pugi::xml_node plot_node): +index_meshlines_mesh(-1), plot_node(plot_node) +{ set_id(); - + set_type(); set_output_path(); @@ -696,21 +708,21 @@ ObjectPlot::ObjectPlot(pugi::xml_node plot_node) set_basis(); set_origin(); - + set_width(); - set_universe(); + set_universe(); set_default_colors(); - + set_user_colors(); set_meshlines(); - + set_mask(); plot_node = pugi::xml_node(); // set to null node after construction - + } // End ObjectPlot constructor //=============================================================================== @@ -718,7 +730,8 @@ ObjectPlot::ObjectPlot(pugi::xml_node plot_node) // current particle's position //=============================================================================== -void position_rgb(Particle* p, ObjectPlot* pl, int rgb[3], int &id) { +void position_rgb(Particle* p, ObjectPlot* pl, int rgb[3], int &id) +{ bool found_cell; p->n_coord = 1; @@ -805,7 +818,7 @@ void output_ppm(ObjectPlot* pl, const ImageData &data) } } // Close file - // THIS IS HERE TO MATCH FORTRAN VERSION, NOT NECESSARY + // THIS IS HERE TO MATCH FORTRAN VERSION, NOT TECHNICALLY NECESSARY of << std::endl; of.close(); } @@ -909,8 +922,7 @@ void draw_mesh_lines(ObjectPlot *pl, ImageData &data) } // end if(in mesh) } } // end outer loops - -} +} // end draw_mesh_lines //=============================================================================== // CREATE_VOXEL outputs a binary file that can be input into silomesh for 3D @@ -924,7 +936,8 @@ void draw_mesh_lines(ObjectPlot *pl, ImageData &data) // id. For 1 million voxels this produces a file of approximately 15MB. //=============================================================================== -void create_voxel(ObjectPlot *pl) { +void create_voxel(ObjectPlot *pl) +{ // compute voxel widths in each direction double vox[3]; @@ -1013,10 +1026,9 @@ void create_voxel(ObjectPlot *pl) { } - void -voxel_init(hid_t file_id, const hsize_t* dims, hid_t* dspace, hid_t* dset, - hid_t* memspace) +voxel_init(hid_t file_id, const hsize_t* dims, + hid_t* dspace, hid_t* dset, hid_t* memspace) { // Create dataspace/dataset for voxel data *dspace = H5Screate_simple(3, dims, nullptr); diff --git a/src/string_functions.cpp b/src/string_functions.cpp index 6c077c8c0..2539586c3 100644 --- a/src/string_functions.cpp +++ b/src/string_functions.cpp @@ -28,15 +28,13 @@ void to_lower(std::string& str) for (int i = 0; i < str.size(); i++) str[i] = std::tolower(str[i]); } -int word_count(std::string const& str) { +int word_count(std::string const& str) +{ std::stringstream stream(str); std::string dum; int count = 0; while(stream >> dum) { count++; } return count; } - + } // namespace openmc - - - diff --git a/src/xml_interface.cpp b/src/xml_interface.cpp index 82c59a27b..fa50eb332 100644 --- a/src/xml_interface.cpp +++ b/src/xml_interface.cpp @@ -64,10 +64,16 @@ get_child_nodes(pugi::xml_node node, const char* name) pugi::xml_node current; std::vector node_list; - for (pugi::xml_node current : node.children(name)) { + // add all child nodes with name to vector and return + if (name) { + for (pugi::xml_node current : node.children(name)) { node_list.push_back(current); + } + } else { + for (pugi::xml_node current : node.children()) { + node_list.push_back(current); + } } - return node_list; } From 96c1afc8f7d5ea6d3d111fede2a2da289a0e9684 Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Fri, 26 Oct 2018 12:20:29 -0500 Subject: [PATCH 053/105] Fixes to indexing and masking. Also updating material id attribute to id_. --- src/plot.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/plot.cpp b/src/plot.cpp index 0cbdd8d2b..2e55a575b 100644 --- a/src/plot.cpp +++ b/src/plot.cpp @@ -451,9 +451,9 @@ ObjectPlot::set_user_colors() if (cell_map.find(col_id) != cell_map.end()) { col_id = cell_map[col_id]; cell_rgb = get_node_array(cn, "rgb"); - colors[col_id - 1]->rgb[RED] = cell_rgb[RED]; - colors[col_id - 1]->rgb[GREEN] = cell_rgb[GREEN]; - colors[col_id - 1]->rgb[BLUE] = cell_rgb[BLUE]; + colors[col_id]->rgb[RED] = cell_rgb[RED]; + colors[col_id]->rgb[GREEN] = cell_rgb[GREEN]; + colors[col_id]->rgb[BLUE] = cell_rgb[BLUE]; } else { std::stringstream err_msg; err_msg << "Could not find cell " << col_id @@ -465,9 +465,9 @@ ObjectPlot::set_user_colors() if (material_map.find(col_id) != material_map.end()) { col_id = material_map[col_id]; mat_rgb = get_node_array(cn, "rgb"); - colors[col_id - 1]->rgb[RED] = mat_rgb[RED]; - colors[col_id - 1]->rgb[GREEN] = mat_rgb[GREEN]; - colors[col_id - 1]->rgb[BLUE] = mat_rgb[BLUE]; + colors[col_id]->rgb[RED] = mat_rgb[RED]; + colors[col_id]->rgb[GREEN] = mat_rgb[GREEN]; + colors[col_id]->rgb[BLUE] = mat_rgb[BLUE]; } else { std::stringstream err_msg; err_msg << "Could not find material " << col_id @@ -671,7 +671,7 @@ ObjectPlot::set_mask() // Alter colors based on mask information // TODO: for(int j = 0; j < colors.size(); j++) { - if (std::find(iarray.begin(), iarray.end(), j) != iarray.end()) { + if (std::find(iarray.begin(), iarray.end(), j) == iarray.end()) { if (check_for_node(mask_node, "background")) { std::vector bg_rgb = get_node_array(mask_node, "background"); colors[j]->rgb[RED] = bg_rgb[RED]; @@ -771,7 +771,7 @@ void position_rgb(Particle* p, ObjectPlot* pl, int rgb[3], int &id) std::copy(pl->colors[p->material - 1]->rgb, pl->colors[p->material - 1]->rgb + 3, rgb); - id = materials[p->material - 1]->id; + id = materials[p->material - 1]->id_; } } else if (PLOT_COLOR_BY::CELLS == pl->color_by) { From 0baec6f9d581f3e049ec0a3420faeaa3bf6ba4f4 Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Fri, 26 Oct 2018 13:55:17 -0500 Subject: [PATCH 054/105] Making index_cmfd_mesh part of openmc::settings. --- include/openmc/settings.h | 3 ++- src/cmfd_execute.cpp | 5 +++-- src/plot.cpp | 16 ++++++++-------- src/settings.cpp | 3 ++- 4 files changed, 15 insertions(+), 12 deletions(-) diff --git a/include/openmc/settings.h b/include/openmc/settings.h index aa9f9c056..47ca0f078 100644 --- a/include/openmc/settings.h +++ b/include/openmc/settings.h @@ -61,7 +61,8 @@ extern std::string path_statepoint; //!< path to a statepoint file extern "C" int32_t index_entropy_mesh; //!< Index of entropy mesh in global mesh array extern "C" int32_t index_ufs_mesh; //!< Index of UFS mesh in global mesh array - +extern "C" int32_t index_cmfd_mesh; //!< Index of CMFD mesh in global mesh array + extern "C" int32_t n_batches; //!< number of (inactive+active) batches extern "C" int32_t n_inactive; //!< number of inactive batches extern "C" int32_t gen_per_batch; //!< number of generations per batch diff --git a/src/cmfd_execute.cpp b/src/cmfd_execute.cpp index aa9907a5b..415ddfaeb 100644 --- a/src/cmfd_execute.cpp +++ b/src/cmfd_execute.cpp @@ -9,10 +9,11 @@ #include "openmc/mesh.h" #include "openmc/message_passing.h" #include "openmc/simulation.h" +#include "openmc/settings.h" namespace openmc { -extern "C" int index_cmfd_mesh; + //extern "C" int index_cmfd_mesh; extern "C" void cmfd_populate_sourcecounts(int n_energy, const double* energies, @@ -24,7 +25,7 @@ cmfd_populate_sourcecounts(int n_energy, const double* energies, openmc_source_bank(&source_bank, &n); // Get source counts in each mesh bin / energy bin - auto& m = meshes.at(index_cmfd_mesh); + auto& m = meshes.at(settings::index_cmfd_mesh); xt::xarray counts = m->count_sites(simulation::work, source_bank, n_energy, energies, outside); // Copy data from the xarray into the source counts array diff --git a/src/plot.cpp b/src/plot.cpp index 2e55a575b..f271c47c3 100644 --- a/src/plot.cpp +++ b/src/plot.cpp @@ -560,14 +560,14 @@ ObjectPlot::set_meshlines() } else { index_meshlines_mesh = settings::index_ufs_mesh; } - // } else if ("cmfd" == meshtype) { - // if (!settings::cmfd_run) { - // std::stringstream err_msg; - // err_msg << "Need CMFD run to plot CMFD mesh for meshlines on plot " << id; - // fatal_error(err_msg); - // } else { - // index_meshlines_mesh = settings::index_cmfd_mesh; - // } + } else if ("cmfd" == meshtype) { + if (!settings::cmfd_run) { + std::stringstream err_msg; + err_msg << "Need CMFD run to plot CMFD mesh for meshlines on plot " << id; + fatal_error(err_msg); + } else { + index_meshlines_mesh = settings::index_cmfd_mesh; + } } else if ("entropy" == meshtype) { if (settings::index_entropy_mesh < 0) { std::stringstream err_msg; diff --git a/src/settings.cpp b/src/settings.cpp index ce0925978..2394597c7 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -72,7 +72,8 @@ std::string path_statepoint; int32_t index_entropy_mesh {-1}; int32_t index_ufs_mesh {-1}; - +int32_t index_cmfd_mesh {-1}; + int32_t n_batches; int32_t n_inactive {0}; int32_t gen_per_batch {1}; From 42495df5dba7f494f369b9b55d463438b58252d7 Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Fri, 26 Oct 2018 14:40:11 -0500 Subject: [PATCH 055/105] Adding docs. --- include/openmc/plot.h | 113 ++++++++++++++++++++++++++++++------------ 1 file changed, 82 insertions(+), 31 deletions(-) diff --git a/include/openmc/plot.h b/include/openmc/plot.h index 004ca30d1..e3cc5508f 100644 --- a/include/openmc/plot.h +++ b/include/openmc/plot.h @@ -12,18 +12,22 @@ namespace openmc { +//=============================================================================== +// Global variables +//=============================================================================== + + extern int PLOT_LEVEL_LOWEST; //!< lower bound on plot universe level + + extern std::map plot_dict; //!< map of plot ids to index + + extern int n_plots; //!< number of plots in openmc run + + extern std::vector plots; //!< Plot instance container + typedef std::vector< std::vector< std::vector > > ImageData; class ObjectPlot; - extern int PLOT_LEVEL_LOWEST; - - extern std::map plot_dict; - - extern int n_plots; - - extern std::vector plots; - enum PLOT_TYPE { SLICE = 1, VOXEL = 2 @@ -45,7 +49,7 @@ namespace openmc { //=============================================================================== struct ObjectColor { - int rgb[3]; + int rgb[3]; //!< RGB color values }; //=============================================================================== @@ -56,24 +60,10 @@ class ObjectPlot { public: + // Constructor ObjectPlot(pugi::xml_node plot); - int id; - int type; - int color_by; - Position origin; - Position width; - int basis; - int pixels[3]; - int meshlines_width; - int level; - int index_meshlines_mesh; - ObjectColor meshlines_color; - ObjectColor not_found; - std::vector colors; - std::string path_plot; - pugi::xml_node plot_node; - + // Methods private: void set_id(); void set_type(); @@ -87,27 +77,88 @@ public: void set_user_colors(); void set_meshlines(); void set_mask(); + + + // Members + int id; //!< Plot ID + int type; //!< Plot type (Slice/Voxel) + int color_by; //!< Plot coloring (cell/material) + Position origin; //!< Plot origin in geometry + Position width; //!< Plot width in geometry + int basis; //!< Plot basis (XY/XZ/YZ) + int pixels[3]; //!< Plot size in pixels + int meshlines_width; //!< Width of lines added to the plot + int level; //!< Plot universe level + int index_meshlines_mesh; //!< Index of the mesh to draw on the plot + ObjectColor meshlines_color; //!< Color of meshlines on the plot + ObjectColor not_found; //!< Plot background color + std::vector colors; //!< Plot colors + std::string path_plot; //!< Plot output filename + pugi::xml_node _plot_node; }; -extern "C" void read_plots(pugi::xml_node* plot_node); - -extern "C" void create_ppm(ObjectPlot* pl); - -extern "C" void create_voxel(ObjectPlot *pl); +//=============================================================================== +// Non-member functions +//=============================================================================== +//! Add mesh lines to image data of a plot object +//! \param[in] plot object +//! \param[out] image data associated with the plot object void draw_mesh_lines(ObjectPlot* pl, std::vector< std::vector< std::vector > > &data); - + +//! Write a ppm image to file using a plot object's image data +//! \param[in] plot object +//! \param[out] image data associated with the plot object void output_ppm(ObjectPlot* pl, const std::vector< std::vector< std::vector > > &data); +//! Get the rgb color for a given particle position in a plot +//! \param[in] particle with position for current pixel +//! \param[in] plot object +//! \param[out] rgb color +//! \param[out] cell or material id for particle position void position_rgb(Particle* p, ObjectPlot* pl, int rgb[3], int &id); + +//! Initialize a voxel file +//! \param[in] id of an open hdf5 file +//! \param[in] dimensions of the voxel file (dx, dy, dz) +//! \param[out] dataspace pointer to voxel data +//! \param[out] dataset pointer to voxesl data +//! \param[out] pointer to memory space of voxel data void voxel_init(hid_t file_id, const hsize_t* dims, hid_t* dspace, hid_t* dset, hid_t* memspace); + +//! Write a section of the voxel data to hdf5 +//! \param[in] voxel slice +//! \param[out] dataspace pointer to voxel data +//! \param[out] dataset pointer to voxesl data +//! \param[out] pointer to data to write void voxel_write_slice(int x, hid_t dspace, hid_t dset, hid_t memspace, void* buf); +//! Close voxel file entities +//! \param[in] data space to close +//! \param[in] dataset to close +//! \param[in] memory space to close void voxel_finalize(hid_t dspace, hid_t dset, hid_t memspace); +//=============================================================================== +// External functions +//=============================================================================== + +//! Read plots from plots.xml node +//! \param[in] plot node of plots.xml +extern "C" void read_plots(pugi::xml_node* plot_node); + +//! Create a ppm image for a plot object +//! \param[in] plot object +extern "C" void create_ppm(ObjectPlot* pl); + +//! Create an hdf5 voxel file for a plot object +//! \param[in] plot object +extern "C" void create_voxel(ObjectPlot *pl); + + } // namespace openmc #endif // OPENMC_PLOT_H From b4e29d9be248dfefef8306d289d433c134f66958 Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Fri, 26 Oct 2018 14:46:57 -0500 Subject: [PATCH 056/105] Moving forward declaration. Renaming internal variable for ObjectPlot. --- include/openmc/plot.h | 20 +++++++-------- src/plot.cpp | 58 +++++++++++++++++++++---------------------- 2 files changed, 39 insertions(+), 39 deletions(-) diff --git a/include/openmc/plot.h b/include/openmc/plot.h index e3cc5508f..97a88377b 100644 --- a/include/openmc/plot.h +++ b/include/openmc/plot.h @@ -22,11 +22,10 @@ namespace openmc { extern int n_plots; //!< number of plots in openmc run - extern std::vector plots; //!< Plot instance container - - typedef std::vector< std::vector< std::vector > > ImageData; - class ObjectPlot; + extern std::vector plots; //!< Plot instance container + + typedef std::vector< std::vector< std::vector > > ImageData; enum PLOT_TYPE { SLICE = 1, @@ -64,7 +63,7 @@ public: ObjectPlot(pugi::xml_node plot); // Methods - private: +private: void set_id(); void set_type(); void set_output_path(); @@ -80,6 +79,7 @@ public: // Members +public: int id; //!< Plot ID int type; //!< Plot type (Slice/Voxel) int color_by; //!< Plot coloring (cell/material) @@ -106,7 +106,7 @@ public: //! \param[out] image data associated with the plot object void draw_mesh_lines(ObjectPlot* pl, std::vector< std::vector< std::vector > > &data); - + //! Write a ppm image to file using a plot object's image data //! \param[in] plot object //! \param[out] image data associated with the plot object @@ -117,7 +117,7 @@ void output_ppm(ObjectPlot* pl, //! \param[in] particle with position for current pixel //! \param[in] plot object //! \param[out] rgb color -//! \param[out] cell or material id for particle position +//! \param[out] cell or material id for particle position void position_rgb(Particle* p, ObjectPlot* pl, int rgb[3], int &id); @@ -129,9 +129,9 @@ void position_rgb(Particle* p, ObjectPlot* pl, int rgb[3], int &id); //! \param[out] pointer to memory space of voxel data void voxel_init(hid_t file_id, const hsize_t* dims, hid_t* dspace, hid_t* dset, hid_t* memspace); - + //! Write a section of the voxel data to hdf5 -//! \param[in] voxel slice +//! \param[in] voxel slice //! \param[out] dataspace pointer to voxel data //! \param[out] dataset pointer to voxesl data //! \param[out] pointer to data to write @@ -159,6 +159,6 @@ extern "C" void create_ppm(ObjectPlot* pl); //! \param[in] plot object extern "C" void create_voxel(ObjectPlot *pl); - + } // namespace openmc #endif // OPENMC_PLOT_H diff --git a/src/plot.cpp b/src/plot.cpp index f271c47c3..d152ff2db 100644 --- a/src/plot.cpp +++ b/src/plot.cpp @@ -160,8 +160,8 @@ void ObjectPlot::set_id() { // Copy data into plots - if (check_for_node(plot_node, "id")) { - id = std::stoi(get_node_value(plot_node, "id")); + 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."); } @@ -183,8 +183,8 @@ ObjectPlot::set_type() std::string type_str = "slice"; type = PLOT_TYPE::SLICE; // check type specified on plot node - if (check_for_node(plot_node, "type")) { - type_str = get_node_value(plot_node, "type"); + if (check_for_node(_plot_node, "type")) { + type_str = get_node_value(_plot_node, "type"); to_lower(type_str); // set type using node value if (type_str == "slice") { @@ -210,8 +210,8 @@ ObjectPlot::set_output_path() std::stringstream filename; filename << "plot_" << id; - if (check_for_node(plot_node, "filename")) { - filename << get_node_value(plot_node, "filename"); + if (check_for_node(_plot_node, "filename")) { + filename << get_node_value(_plot_node, "filename"); } else { switch(type) { case PLOT_TYPE::SLICE: @@ -227,8 +227,8 @@ ObjectPlot::set_output_path() // 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"); + if (node_word_count(_plot_node, "pixels") == 2) { + pxls = get_node_array(_plot_node, "pixels"); pixels[0] = pxls[0]; pixels[1] = pxls[1]; } else { @@ -238,8 +238,8 @@ ObjectPlot::set_output_path() 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"); + 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]; @@ -257,7 +257,7 @@ ObjectPlot::set_bg_color() { // Copy plot background color std::vector bg_rgb; - if (check_for_node(plot_node, "background")) { + if (check_for_node(_plot_node, "background")) { if (PLOT_TYPE::VOXEL == type) { if (openmc_master) { std::stringstream err_msg; @@ -266,8 +266,8 @@ ObjectPlot::set_bg_color() warning(err_msg.str()); } } - if (node_word_count(plot_node, "background") == 3) { - bg_rgb = get_node_array(plot_node, "background"); + if (node_word_count(_plot_node, "background") == 3) { + bg_rgb = get_node_array(_plot_node, "background"); not_found.rgb[RED] = bg_rgb[RED]; not_found.rgb[GREEN] = bg_rgb[GREEN]; not_found.rgb[BLUE] = bg_rgb[BLUE]; @@ -291,8 +291,8 @@ ObjectPlot::set_basis() // 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"); + if (check_for_node(_plot_node, "basis")) { + pl_basis = get_node_value(_plot_node, "basis"); } to_lower(pl_basis); if ("xy" == pl_basis) { @@ -315,8 +315,8 @@ ObjectPlot::set_origin() { // Copy plotting origin std::vector pl_origin; - if (node_word_count(plot_node, "origin") == 3) { - pl_origin = get_node_array(plot_node, "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]; @@ -334,8 +334,8 @@ ObjectPlot::set_width() // 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"); + 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 { @@ -345,8 +345,8 @@ ObjectPlot::set_width() 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"); + 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]; @@ -363,8 +363,8 @@ void ObjectPlot::set_universe() { // Copy plot universe level - if (check_for_node(plot_node, "level")) { - level = std::stoi(get_node_value(plot_node, "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 ; @@ -380,8 +380,8 @@ ObjectPlot::set_default_colors() { // 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"); + 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) { @@ -414,7 +414,7 @@ ObjectPlot::set_user_colors() { // Get the number of nodes and get a list of them std::vector color_nodes; - color_nodes = get_child_nodes(plot_node, "color"); + color_nodes = get_child_nodes(_plot_node, "color"); // Copy user-specified colors if (0 != color_nodes.size()) { @@ -484,7 +484,7 @@ ObjectPlot::set_meshlines() { // Deal with meshlines std::vector mesh_line_nodes; - mesh_line_nodes = get_child_nodes(plot_node, "meshlines"); + mesh_line_nodes = get_child_nodes(_plot_node, "meshlines"); int n_meshlines = mesh_line_nodes.size(); @@ -613,7 +613,7 @@ ObjectPlot::set_mask() { // Deal with masks std::vector mask_nodes; - mask_nodes = get_child_nodes(plot_node, "mask"); + mask_nodes = get_child_nodes(_plot_node, "mask"); int n_masks = mask_nodes.size(); if (n_masks > 0) { @@ -694,7 +694,7 @@ ObjectPlot::set_mask() } ObjectPlot::ObjectPlot(pugi::xml_node plot_node): -index_meshlines_mesh(-1), plot_node(plot_node) +index_meshlines_mesh(-1), _plot_node(plot_node) { set_id(); From 9ebeb6590b09f0d6d088925514d5a980d12cb7ac Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Fri, 26 Oct 2018 14:53:40 -0500 Subject: [PATCH 057/105] Some more style fixes. --- include/openmc/plot.h | 44 +++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/include/openmc/plot.h b/include/openmc/plot.h index 97a88377b..572af78c1 100644 --- a/include/openmc/plot.h +++ b/include/openmc/plot.h @@ -16,40 +16,40 @@ namespace openmc { // Global variables //=============================================================================== - extern int PLOT_LEVEL_LOWEST; //!< lower bound on plot universe level +extern int PLOT_LEVEL_LOWEST; //!< lower bound on plot universe level - extern std::map plot_dict; //!< map of plot ids to index +extern std::map plot_dict; //!< map of plot ids to index - extern int n_plots; //!< number of plots in openmc run +extern int n_plots; //!< number of plots in openmc run - class ObjectPlot; - extern std::vector plots; //!< Plot instance container +class ObjectPlot; +extern std::vector plots; //!< Plot instance container - typedef std::vector< std::vector< std::vector > > ImageData; +typedef std::vector< std::vector< std::vector > > ImageData; - enum PLOT_TYPE { - SLICE = 1, - VOXEL = 2 - }; +enum PLOT_TYPE { + SLICE = 1, + VOXEL = 2 +}; - enum PLOT_BASIS { - XY = 1, - XZ = 2, - YZ = 3 - }; +enum PLOT_BASIS { + XY = 1, + XZ = 2, + YZ = 3 +}; - enum PLOT_COLOR_BY { - CELLS = 1, - MATS = 2 - }; +enum PLOT_COLOR_BY { + CELLS = 1, + MATS = 2 +}; //=============================================================================== // ObjectColor holds color information for plotted objects //=============================================================================== - struct ObjectColor { - int rgb[3]; //!< RGB color values - }; +struct ObjectColor { + int rgb[3]; //!< RGB color values +}; //=============================================================================== // ObjectPlot holds plot information From 50fb966a13d9362a4cf4cffc900a893c0b5c62cf Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Fri, 26 Oct 2018 15:22:23 -0500 Subject: [PATCH 058/105] Removing commented line. --- src/cmfd_execute.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/cmfd_execute.cpp b/src/cmfd_execute.cpp index 415ddfaeb..46371601b 100644 --- a/src/cmfd_execute.cpp +++ b/src/cmfd_execute.cpp @@ -13,7 +13,6 @@ namespace openmc { - //extern "C" int index_cmfd_mesh; extern "C" void cmfd_populate_sourcecounts(int n_energy, const double* energies, From 6d5cc5cd0dd32134e79cd5ec266cab9ddaaeda1a Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Sat, 27 Oct 2018 18:20:10 -0500 Subject: [PATCH 059/105] Addressing style and other comments from @shikar413 --- include/openmc/output.h | 8 ++- include/openmc/plot.h | 13 +++- src/output.cpp | 2 +- src/plot.cpp | 138 ++++++++++++++++----------------------- src/string_functions.cpp | 2 +- 5 files changed, 75 insertions(+), 88 deletions(-) diff --git a/include/openmc/output.h b/include/openmc/output.h index 8f76e43ae..6207e2eda 100644 --- a/include/openmc/output.h +++ b/include/openmc/output.h @@ -25,14 +25,18 @@ void header(const char* msg, int level); std::string time_stamp(); +//============================================================================== +//! Display plot information +//============================================================================== + +extern "C" void print_plot(); + //============================================================================== //! Display information regarding cell overlap checking. //============================================================================== void print_overlap_check(); -extern "C" void print_plot(); - extern "C" void title(); } // namespace openmc diff --git a/include/openmc/plot.h b/include/openmc/plot.h index 572af78c1..c2c065406 100644 --- a/include/openmc/plot.h +++ b/include/openmc/plot.h @@ -5,7 +5,7 @@ #include #include "hdf5.h" -#include "position.h" +#include "openmc/position.h" #include "openmc/constants.h" #include "openmc/particle.h" #include "openmc/xml_interface.h" @@ -16,16 +16,20 @@ namespace openmc { // Global variables //=============================================================================== +constexpr int RED = 0; +constexpr int GREEN = 1; +constexpr int BLUE = 2; + extern int PLOT_LEVEL_LOWEST; //!< lower bound on plot universe level -extern std::map plot_dict; //!< map of plot ids to index +extern std::map plot_map; //!< map of plot ids to index extern int n_plots; //!< number of plots in openmc run class ObjectPlot; extern std::vector plots; //!< Plot instance container -typedef std::vector< std::vector< std::vector > > ImageData; +typedef std::vector>> ImageData; enum PLOT_TYPE { SLICE = 1, @@ -62,6 +66,9 @@ public: // Constructor ObjectPlot(pugi::xml_node plot); + // Destructor + ~ObjectPlot(); + // Methods private: void set_id(); diff --git a/src/output.cpp b/src/output.cpp index 4eb33cb00..a1b127d69 100644 --- a/src/output.cpp +++ b/src/output.cpp @@ -116,7 +116,7 @@ void print_plot() { std::cout << "Pixels: " << pl->pixels[0] << " " << pl->pixels[1] << " " << std::endl; } else if (PLOT_TYPE::VOXEL == pl->type) { - std::cout << "Voxel: " << pl->pixels[0] << " " + std::cout << "Voxels: " << pl->pixels[0] << " " << pl->pixels[1] << " " << pl->pixels[2] << std::endl; } diff --git a/src/plot.cpp b/src/plot.cpp index d152ff2db..b5661e39d 100644 --- a/src/plot.cpp +++ b/src/plot.cpp @@ -17,18 +17,18 @@ namespace openmc { +//=============================================================================== +// Global variables +//=============================================================================== + int PLOT_LEVEL_LOWEST = -1; -std::map plot_dict; +std::map plot_map; int n_plots; std::vector plots; -const int RED = 0; -const int GREEN = 1; -const int BLUE = 2; - const int WHITE[3] = {255, 255, 255}; const int NULLRGB[3] = {0, 0, 0}; @@ -41,23 +41,21 @@ int openmc_plot_geometry() { int err; - for(int i = 0; i < n_plots; i++) { + for (int i = 0; i < n_plots; i++) { ObjectPlot* pl = plots[i]; std::stringstream ss; ss << "Processing plot " << pl->id << ": " << pl->path_plot << "..."; - write_message(ss.str(), 5); + write_message(ss.str(), 5); - if (PLOT_TYPE::SLICE == pl->type) { - // create 2D image - create_ppm(pl); - continue; - } else if (PLOT_TYPE::VOXEL == pl->type) { - // create voxel file for 3D viewing - create_voxel(pl); - continue; - } + if (PLOT_TYPE::SLICE == pl->type) { + // create 2D image + create_ppm(pl); + } else if (PLOT_TYPE::VOXEL == pl->type) { + // create voxel file for 3D viewing + create_voxel(pl); + } } return 0; } @@ -75,7 +73,7 @@ read_plots(pugi::xml_node* plots_node) for(int i = 0; i < plot_nodes.size(); i++) { ObjectPlot* pl = new ObjectPlot(plot_nodes[i]); plots.push_back(pl); - plot_dict[pl->id] = i; + plot_map[pl->id] = i; } } @@ -139,9 +137,9 @@ void create_ppm(ObjectPlot* pl) int rgb[3]; int id; for (int y = 0; y < height; y++) { - p->coord[0].xyz[out_i] = xyz[out_i] - out_pixel*(y); + p->coord[0].xyz[out_i] = xyz[out_i] - out_pixel * y; for (int x = 0; x < width; x++) { - p->coord[0].xyz[in_i] = xyz[in_i] + in_pixel*(x); + p->coord[0].xyz[in_i] = xyz[in_i] + in_pixel * x; position_rgb(p, pl, rgb, id); data[x][y][RED] = rgb[RED]; data[x][y][GREEN] = rgb[GREEN]; @@ -149,8 +147,10 @@ void create_ppm(ObjectPlot* pl) } } + delete p; + // draw mesh lines if present - if (pl->index_meshlines_mesh >= 0) { draw_mesh_lines(pl, data); } + if (pl->index_meshlines_mesh >= 0) {draw_mesh_lines(pl, data);} // write ppm data to file output_ppm(pl, data); @@ -159,7 +159,7 @@ void create_ppm(ObjectPlot* pl) void ObjectPlot::set_id() { - // Copy data into plots + // Copy data into plots if (check_for_node(_plot_node, "id")) { id = std::stoi(get_node_value(_plot_node, "id")); } else { @@ -167,10 +167,9 @@ ObjectPlot::set_id() } // Check to make sure 'id' hasn't been used - if (plot_dict.find(id) != plot_dict.end()) { + if (plot_map.find(id) != plot_map.end()) { std::stringstream err_msg; - err_msg << "Two or more plots use the same unique ID: "; - err_msg << id; + err_msg << "Two or more plots use the same unique ID: " << id; fatal_error(err_msg.str()); } } @@ -184,8 +183,7 @@ ObjectPlot::set_type() type = PLOT_TYPE::SLICE; // check type specified on plot node if (check_for_node(_plot_node, "type")) { - type_str = get_node_value(_plot_node, "type"); - to_lower(type_str); + type_str = get_node_value(_plot_node, "type", true); // set type using node value if (type_str == "slice") { type = PLOT_TYPE::SLICE; @@ -255,7 +253,7 @@ ObjectPlot::set_output_path() void ObjectPlot::set_bg_color() { - // Copy plot background color + // Copy plot background color std::vector bg_rgb; if (check_for_node(_plot_node, "background")) { if (PLOT_TYPE::VOXEL == type) { @@ -381,8 +379,7 @@ ObjectPlot::set_default_colors() // 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); + pl_color_by = get_node_value(_plot_node, "color_by", true); } if ("cell" == pl_color_by) { color_by = PLOT_COLOR_BY::CELLS; @@ -417,7 +414,7 @@ ObjectPlot::set_user_colors() color_nodes = get_child_nodes(_plot_node, "color"); // Copy user-specified colors - if (0 != color_nodes.size()) { + if (color_nodes.size() != 0) { if (PLOT_TYPE::VOXEL == type) { if (openmc_master) { @@ -495,29 +492,17 @@ ObjectPlot::set_meshlines() warning(msg); } - if (0 == n_meshlines) { - // Skip if no meshlines are specified - } else if (1 == n_meshlines) { + if (1 == n_meshlines) { // Get first meshline node pugi::xml_node meshlines_node = mesh_line_nodes[0]; - // Check mesh type - std::string meshline_type; - if (check_for_node(meshlines_node, "meshtype")) { - meshline_type = get_node_value(meshlines_node, "meshtype"); - } else { - std::stringstream err_msg; - err_msg << "Must specify a meshtype for meshlines specification in plot " << id; - fatal_error(err_msg); - } - // Check mesh type std::string meshtype; if (check_for_node(meshlines_node, "meshtype")) { meshtype = get_node_value(meshlines_node, "meshtype"); } else { std::stringstream err_msg; - err_msg << "Must specify a meshtype for meshlines specification in plot " << id ; + err_msg << "Must specify a meshtype for meshlines specification in plot " << id; fatal_error(err_msg); } @@ -580,21 +565,23 @@ ObjectPlot::set_meshlines() // Ensure that there is a mesh id if the type is tally int tally_mesh_id; if (check_for_node(meshlines_node, "id")) { - int tally_mesh_id = std::stoi(get_node_value(meshlines_node, "id")); - } else { - std::stringstream err_msg; - err_msg << "Must specify a mesh id for meshlines tally " - << "mesh specification in plot " << id; - fatal_error(err_msg); - } - int idx; - int err = openmc_get_mesh_index(tally_mesh_id, &idx); - if (0 != err) { + tally_mesh_id = std::stoi(get_node_value(meshlines_node, "id")); + } else { + std::stringstream err_msg; + err_msg << "Must specify a mesh id for meshlines tally " + << "mesh specification in plot " << id; + fatal_error(err_msg); + } + // find the tally index + int idx; + int err = openmc_get_mesh_index(tally_mesh_id, &idx); + if (err != 0) { std::stringstream err_msg; err_msg << "Could not find mesh " << tally_mesh_id << " specified in meshlines for plot " << id; fatal_error(err_msg); - } + } + index_meshlines_mesh = idx; } else { std::stringstream err_msg; err_msg << "Invalid type for meshlines on plot " << id ; @@ -669,7 +656,6 @@ ObjectPlot::set_mask() } // Alter colors based on mask information - // TODO: for(int j = 0; j < colors.size(); j++) { if (std::find(iarray.begin(), iarray.end(), j) == iarray.end()) { if (check_for_node(mask_node, "background")) { @@ -694,37 +680,31 @@ ObjectPlot::set_mask() } ObjectPlot::ObjectPlot(pugi::xml_node plot_node): -index_meshlines_mesh(-1), _plot_node(plot_node) +index_meshlines_mesh(-1) { - + _plot_node = plot_node; set_id(); - set_type(); - set_output_path(); - set_bg_color(); - set_basis(); - set_origin(); - set_width(); - set_universe(); - set_default_colors(); - set_user_colors(); - set_meshlines(); - set_mask(); - - plot_node = pugi::xml_node(); // set to null node after construction - + _plot_node = pugi::xml_node(); // set to null node after construction } // End ObjectPlot constructor +ObjectPlot::~ObjectPlot() { + // cleanup color pointers + for (auto c : colors) { + if (c) {delete c;} + } +} + //=============================================================================== // POSITION_RGB computes the red/green/blue values for a given plot with the // current particle's position @@ -732,21 +712,17 @@ index_meshlines_mesh(-1), _plot_node(plot_node) void position_rgb(Particle* p, ObjectPlot* pl, int rgb[3], int &id) { - bool found_cell; - p->n_coord = 1; - found_cell = find_cell(p, 0); + bool found_cell = find_cell(p, 0); int j = p->n_coord - 1; - if (settings::check_overlaps) { check_cell_overlap(p); } + if (settings::check_overlaps) {check_cell_overlap(p);} // Set coordinate level if specified if (pl->level >= 0) {j = pl->level + 1;} - Cell* c; - if (!found_cell) { // If no cell, revert to default color std::copy(pl->not_found.rgb, @@ -756,7 +732,7 @@ void position_rgb(Particle* p, ObjectPlot* pl, int rgb[3], int &id) } else { if (PLOT_COLOR_BY::MATS == pl->color_by) { // Assign color based on material - c = cells[p->coord[j].cell]; + Cell* c = cells[p->coord[j].cell]; if (c->type_ == FILL_UNIVERSE) { // If we stopped on a middle universe level, treat as if not found std::copy(pl->not_found.rgb, @@ -835,7 +811,7 @@ void draw_mesh_lines(ObjectPlot *pl, ImageData &data) rgb[BLUE] = pl->meshlines_color.rgb[BLUE]; int outer, inner; - switch(pl->basis){ + switch(pl->basis) { case PLOT_BASIS::XY : outer = 0; inner = 1; @@ -999,7 +975,7 @@ void create_voxel(ObjectPlot *pl) int rgb[3], id; for (int x = 0; x < pl->pixels[0]; x++) { - // progress bar here + // TODO: progress bar here for (int y = 0; y < pl->pixels[1]; y++) { for(int z = 0; z < pl->pixels[2]; z++) { // get voxel color diff --git a/src/string_functions.cpp b/src/string_functions.cpp index 2539586c3..27e14c9ba 100644 --- a/src/string_functions.cpp +++ b/src/string_functions.cpp @@ -33,7 +33,7 @@ int word_count(std::string const& str) std::stringstream stream(str); std::string dum; int count = 0; - while(stream >> dum) { count++; } + while (stream >> dum) {count++;} return count; } From 0f9b195ad818fe06a58875562a1c060625aed057 Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Sun, 28 Oct 2018 22:16:01 -0500 Subject: [PATCH 060/105] Setting width as doubles instead of ints. --- src/plot.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/plot.cpp b/src/plot.cpp index b5661e39d..d9da26652 100644 --- a/src/plot.cpp +++ b/src/plot.cpp @@ -330,10 +330,10 @@ void ObjectPlot::set_width() { // Copy plotting width - std::vector pl_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"); + pl_width = get_node_array(_plot_node, "width"); width[0] = pl_width[0]; width[1] = pl_width[1]; } else { @@ -344,7 +344,7 @@ ObjectPlot::set_width() } } else if (PLOT_TYPE::VOXEL == type) { if (node_word_count(_plot_node, "width") == 3) { - pl_width = get_node_array(_plot_node, "width"); + pl_width = get_node_array(_plot_node, "width"); width[0] = pl_width[0]; width[1] = pl_width[1]; width[2] = pl_width[2]; From 0d8dc172df412992e8f39b9c9be9307bfbc21b10 Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Mon, 29 Oct 2018 09:29:34 -0500 Subject: [PATCH 061/105] Making enums lowercase, converting to enum classes also. --- include/openmc/plot.h | 27 +++++++++--------- src/output.cpp | 22 +++++++-------- src/plot.cpp | 66 +++++++++++++++++++++---------------------- 3 files changed, 57 insertions(+), 58 deletions(-) diff --git a/include/openmc/plot.h b/include/openmc/plot.h index c2c065406..360cddc8d 100644 --- a/include/openmc/plot.h +++ b/include/openmc/plot.h @@ -31,20 +31,20 @@ extern std::vector plots; //!< Plot instance container typedef std::vector>> ImageData; -enum PLOT_TYPE { - SLICE = 1, - VOXEL = 2 +enum class plot_type { + slice = 1, + voxel = 2 }; -enum PLOT_BASIS { - XY = 1, - XZ = 2, - YZ = 3 +enum class plot_basis { + xy = 1, + xz = 2, + yz = 3 }; -enum PLOT_COLOR_BY { - CELLS = 1, - MATS = 2 +enum class plot_color_by { + cells = 1, + mats = 2 }; //=============================================================================== @@ -84,15 +84,14 @@ private: void set_meshlines(); void set_mask(); - // Members public: int id; //!< Plot ID - int type; //!< Plot type (Slice/Voxel) - int color_by; //!< Plot coloring (cell/material) + plot_type type; //!< Plot type (Slice/Voxel) + plot_color_by color_by; //!< Plot coloring (cell/material) Position origin; //!< Plot origin in geometry Position width; //!< Plot width in geometry - int basis; //!< Plot basis (XY/XZ/YZ) + plot_basis basis; //!< Plot basis (XY/XZ/YZ) int pixels[3]; //!< Plot size in pixels int meshlines_width; //!< Width of lines added to the plot int level; //!< Plot universe level diff --git a/src/output.cpp b/src/output.cpp index a1b127d69..396fffac0 100644 --- a/src/output.cpp +++ b/src/output.cpp @@ -71,9 +71,9 @@ void print_plot() { std::cout << "Universe depth: " << pl->level << std::endl; // Plot type - if (PLOT_TYPE::SLICE == pl->type) { + if (plot_type::slice == pl->type) { std::cout << "Plot Type: Slice" << std::endl; - } else if (PLOT_TYPE::VOXEL == pl->type) { + } else if (plot_type::voxel == pl->type) { std::cout << "Plot Type: Voxel" << std::endl; } @@ -82,12 +82,12 @@ void print_plot() { << pl->origin[1] << " " << pl->origin[2] << std::endl; - if (PLOT_TYPE::SLICE == pl->type) { + if (plot_type::slice == pl->type) { std::cout << std::setprecision(4) << "Width: " << pl->width[0] << " " << pl->width[1] << std::endl; - } else if (PLOT_TYPE::VOXEL == pl->type) { + } else if (plot_type::voxel == pl->type) { std::cout << std::setprecision(4) << "Width: " << pl->width[0] << " " @@ -95,27 +95,27 @@ void print_plot() { << pl->width[2] << std::endl; } - if (PLOT_COLOR_BY::CELLS == pl->color_by) { + if (plot_color_by::cells == pl->color_by) { std::cout << "Coloring: Cells" << std::endl; - } else if (PLOT_COLOR_BY::MATS == pl->color_by) { + } else if (plot_color_by::mats == pl->color_by) { std::cout << "Coloring: Materials" << std::endl; } - if (PLOT_TYPE::SLICE == pl->type) { + if (plot_type::slice == pl->type) { switch(pl->basis) { - case PLOT_BASIS::XY: + case plot_basis::xy: std::cout << "Basis: XY" << std::endl; break; - case PLOT_BASIS::XZ: + case plot_basis::xz: std::cout << "Basis: XZ" << std::endl; break; - case PLOT_BASIS::YZ: + case plot_basis::yz: std::cout << "Basis: YZ" << std::endl; break; } std::cout << "Pixels: " << pl->pixels[0] << " " << pl->pixels[1] << " " << std::endl; - } else if (PLOT_TYPE::VOXEL == pl->type) { + } else if (plot_type::voxel == pl->type) { std::cout << "Voxels: " << pl->pixels[0] << " " << pl->pixels[1] << " " << pl->pixels[2] << std::endl; diff --git a/src/plot.cpp b/src/plot.cpp index d9da26652..b58589471 100644 --- a/src/plot.cpp +++ b/src/plot.cpp @@ -49,10 +49,10 @@ int openmc_plot_geometry() << pl->path_plot << "..."; write_message(ss.str(), 5); - if (PLOT_TYPE::SLICE == pl->type) { + if (plot_type::slice == pl->type) { // create 2D image create_ppm(pl); - } else if (PLOT_TYPE::VOXEL == pl->type) { + } else if (plot_type::voxel == pl->type) { // create voxel file for 3D viewing create_voxel(pl); } @@ -103,21 +103,21 @@ void create_ppm(ObjectPlot* pl) int in_i, out_i; double xyz[3]; switch(pl->basis) { - case PLOT_BASIS::XY : + case plot_basis::xy : in_i = 0; out_i = 1; xyz[0] = pl->origin[0] - pl->width[0] / TWO; xyz[1] = pl->origin[1] + pl->width[1] / TWO; xyz[2] = pl->origin[2]; break; - case PLOT_BASIS::XZ : + case plot_basis::xz : in_i = 0; out_i = 2; xyz[0] = pl->origin[0] - pl->width[0] / TWO; xyz[1] = pl->origin[1]; xyz[2] = pl->origin[2] + pl->width[1] / TWO; break; - case PLOT_BASIS::YZ : + case plot_basis::yz : in_i = 1; out_i = 2; xyz[0] = pl->origin[0]; @@ -180,17 +180,17 @@ ObjectPlot::set_type() // Copy plot type // Default is slice std::string type_str = "slice"; - type = PLOT_TYPE::SLICE; + type = plot_type::slice; // check type specified on plot node if (check_for_node(_plot_node, "type")) { type_str = get_node_value(_plot_node, "type", true); // set type using node value if (type_str == "slice") { - type = PLOT_TYPE::SLICE; + type = plot_type::slice; return; } else if (type_str == "voxel") { - type = PLOT_TYPE::VOXEL; + type = plot_type::voxel; return; } // if we're here, something is wrong @@ -212,10 +212,10 @@ ObjectPlot::set_output_path() filename << get_node_value(_plot_node, "filename"); } else { switch(type) { - case PLOT_TYPE::SLICE: + case plot_type::slice: filename << ".ppm"; break; - case PLOT_TYPE::VOXEL: + case plot_type::voxel: filename << ".h5"; break; } @@ -224,7 +224,7 @@ ObjectPlot::set_output_path() // Copy plot pixel size std::vector pxls; - if (PLOT_TYPE::SLICE == type) { + if (plot_type::slice == type) { if (node_word_count(_plot_node, "pixels") == 2) { pxls = get_node_array(_plot_node, "pixels"); pixels[0] = pxls[0]; @@ -235,7 +235,7 @@ ObjectPlot::set_output_path() << id; fatal_error(err_msg.str()); } - } else if (PLOT_TYPE::VOXEL == type) { + } 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]; @@ -256,7 +256,7 @@ ObjectPlot::set_bg_color() // Copy plot background color std::vector bg_rgb; if (check_for_node(_plot_node, "background")) { - if (PLOT_TYPE::VOXEL == type) { + if (plot_type::voxel == type) { if (openmc_master) { std::stringstream err_msg; err_msg << "Background color ignored in voxel plot " @@ -287,18 +287,18 @@ void ObjectPlot::set_basis() { // Copy plot basis - if (PLOT_TYPE::SLICE == type) { + 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; + basis = plot_basis::xy; } else if ("xz" == pl_basis) { - basis = PLOT_BASIS::XZ; + basis = plot_basis::xz; } else if ("yz" == pl_basis) { - basis = PLOT_BASIS::YZ; + basis = plot_basis::yz; } else { std::stringstream err_msg; err_msg << "Unsupported plot basis '" << pl_basis @@ -331,7 +331,7 @@ ObjectPlot::set_width() { // Copy plotting width std::vector pl_width; - if (PLOT_TYPE::SLICE == type) { + 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]; @@ -342,7 +342,7 @@ ObjectPlot::set_width() << id; fatal_error(err_msg); } - } else if (PLOT_TYPE::VOXEL == type) { + } 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]; @@ -382,7 +382,7 @@ ObjectPlot::set_default_colors() pl_color_by = get_node_value(_plot_node, "color_by", true); } if ("cell" == pl_color_by) { - color_by = PLOT_COLOR_BY::CELLS; + color_by = plot_color_by::cells; for(int i = 0; i < n_cells; i++) { colors.push_back(new ObjectColor()); colors[i]->rgb[RED] = int(prn()*255); @@ -391,7 +391,7 @@ ObjectPlot::set_default_colors() } } else if("material" == pl_color_by) { - color_by = PLOT_COLOR_BY::MATS; + color_by = plot_color_by::mats; for(int i = 0; i < materials.size(); i++) { colors.push_back(new ObjectColor()); colors[i]->rgb[RED] = int(prn()*255); @@ -416,7 +416,7 @@ ObjectPlot::set_user_colors() // Copy user-specified colors if (color_nodes.size() != 0) { - if (PLOT_TYPE::VOXEL == type) { + if (plot_type::voxel == type) { if (openmc_master) { std::stringstream err_msg; err_msg << "Color specifications ignored in voxel plot " @@ -443,7 +443,7 @@ ObjectPlot::set_user_colors() fatal_error(err_msg); } // Add RGB - if (PLOT_COLOR_BY::CELLS == color_by) { + if (plot_color_by::cells == color_by) { std::vector cell_rgb; if (cell_map.find(col_id) != cell_map.end()) { col_id = cell_map[col_id]; @@ -457,7 +457,7 @@ ObjectPlot::set_user_colors() << " specified in plot " << id; fatal_error(err_msg); } - } else if (PLOT_COLOR_BY::MATS == color_by) { + } else if (plot_color_by::mats == color_by) { std::vector mat_rgb; if (material_map.find(col_id) != material_map.end()) { col_id = material_map[col_id]; @@ -486,7 +486,7 @@ ObjectPlot::set_meshlines() int n_meshlines = mesh_line_nodes.size(); if (n_meshlines != 0) { - if (PLOT_TYPE::VOXEL == type) { + if (plot_type::voxel == type) { std::stringstream msg; msg << "Meshlines ignored in voxel plot " << id; warning(msg); @@ -604,7 +604,7 @@ ObjectPlot::set_mask() int n_masks = mask_nodes.size(); if (n_masks > 0) { - if (PLOT_TYPE::VOXEL == type) { + if (plot_type::voxel == type) { if (openmc_master) { std::stringstream wrn_msg; wrn_msg << "Mask ignored in voxel plot " << id; @@ -632,7 +632,7 @@ ObjectPlot::set_mask() for (int j = 0; j < iarray.size(); j++) { col_id = iarray[j]; - if (PLOT_COLOR_BY::CELLS == color_by) { + if (plot_color_by::cells == color_by) { if (cell_map.find(col_id) != cell_map.end()) { iarray[j] = cell_map[col_id]; } @@ -642,7 +642,7 @@ ObjectPlot::set_mask() << " specified in the mask in plot " << id; fatal_error(err_msg); } - } else if (PLOT_COLOR_BY::MATS == color_by) { + } else if (plot_color_by::mats == color_by) { if (material_map.find(col_id) != material_map.end()) { iarray[j] = material_map[col_id]; } @@ -730,7 +730,7 @@ void position_rgb(Particle* p, ObjectPlot* pl, int rgb[3], int &id) rgb); id = -1; } else { - if (PLOT_COLOR_BY::MATS == pl->color_by) { + if (plot_color_by::mats == pl->color_by) { // Assign color based on material Cell* c = cells[p->coord[j].cell]; if (c->type_ == FILL_UNIVERSE) { @@ -750,7 +750,7 @@ void position_rgb(Particle* p, ObjectPlot* pl, int rgb[3], int &id) id = materials[p->material - 1]->id_; } - } else if (PLOT_COLOR_BY::CELLS == pl->color_by) { + } else if (plot_color_by::cells == pl->color_by) { // Assign color based on cell std::copy(pl->colors[p->coord[j].cell]->rgb, pl->colors[p->coord[j].cell]->rgb + 3, @@ -812,15 +812,15 @@ void draw_mesh_lines(ObjectPlot *pl, ImageData &data) int outer, inner; switch(pl->basis) { - case PLOT_BASIS::XY : + case plot_basis::xy : outer = 0; inner = 1; break; - case PLOT_BASIS::XZ : + case plot_basis::xz : outer = 0; inner = 2; break; - case PLOT_BASIS::YZ : + case plot_basis::yz : outer = 1; inner = 2; break; From 38a248b4a51bbe6471b0c5cffa01a9b3c914c82f Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Mon, 29 Oct 2018 09:33:24 -0500 Subject: [PATCH 062/105] Updating names of ObjectPlot and Object Color. --- include/openmc/plot.h | 32 +++++++++++++-------------- src/plot.cpp | 50 +++++++++++++++++++++---------------------- 2 files changed, 41 insertions(+), 41 deletions(-) diff --git a/include/openmc/plot.h b/include/openmc/plot.h index 360cddc8d..69d8c1cf8 100644 --- a/include/openmc/plot.h +++ b/include/openmc/plot.h @@ -26,8 +26,8 @@ extern std::map plot_map; //!< map of plot ids to index extern int n_plots; //!< number of plots in openmc run -class ObjectPlot; -extern std::vector plots; //!< Plot instance container +class Plot; +extern std::vector plots; //!< Plot instance container typedef std::vector>> ImageData; @@ -48,26 +48,26 @@ enum class plot_color_by { }; //=============================================================================== -// ObjectColor holds color information for plotted objects +// RGBColor holds color information for plotted objects //=============================================================================== -struct ObjectColor { +struct RGBColor { int rgb[3]; //!< RGB color values }; //=============================================================================== -// ObjectPlot holds plot information +// Plot class //=============================================================================== -class ObjectPlot +class Plot { public: // Constructor - ObjectPlot(pugi::xml_node plot); + Plot(pugi::xml_node plot); // Destructor - ~ObjectPlot(); + ~Plot(); // Methods private: @@ -96,9 +96,9 @@ public: int meshlines_width; //!< Width of lines added to the plot int level; //!< Plot universe level int index_meshlines_mesh; //!< Index of the mesh to draw on the plot - ObjectColor meshlines_color; //!< Color of meshlines on the plot - ObjectColor not_found; //!< Plot background color - std::vector colors; //!< Plot colors + RGBColor meshlines_color; //!< Color of meshlines on the plot + RGBColor not_found; //!< Plot background color + std::vector colors; //!< Plot colors std::string path_plot; //!< Plot output filename pugi::xml_node _plot_node; }; @@ -110,13 +110,13 @@ public: //! Add mesh lines to image data of a plot object //! \param[in] plot object //! \param[out] image data associated with the plot object -void draw_mesh_lines(ObjectPlot* pl, +void draw_mesh_lines(Plot* pl, std::vector< std::vector< std::vector > > &data); //! Write a ppm image to file using a plot object's image data //! \param[in] plot object //! \param[out] image data associated with the plot object -void output_ppm(ObjectPlot* pl, +void output_ppm(Plot* pl, const std::vector< std::vector< std::vector > > &data); //! Get the rgb color for a given particle position in a plot @@ -124,7 +124,7 @@ void output_ppm(ObjectPlot* pl, //! \param[in] plot object //! \param[out] rgb color //! \param[out] cell or material id for particle position -void position_rgb(Particle* p, ObjectPlot* pl, int rgb[3], int &id); +void position_rgb(Particle* p, Plot* pl, int rgb[3], int &id); //! Initialize a voxel file @@ -159,11 +159,11 @@ extern "C" void read_plots(pugi::xml_node* plot_node); //! Create a ppm image for a plot object //! \param[in] plot object -extern "C" void create_ppm(ObjectPlot* pl); +extern "C" void create_ppm(Plot* pl); //! Create an hdf5 voxel file for a plot object //! \param[in] plot object -extern "C" void create_voxel(ObjectPlot *pl); +extern "C" void create_voxel(Plot *pl); } // namespace openmc diff --git a/src/plot.cpp b/src/plot.cpp index b58589471..12aab9242 100644 --- a/src/plot.cpp +++ b/src/plot.cpp @@ -27,7 +27,7 @@ std::map plot_map; int n_plots; -std::vector plots; +std::vector plots; const int WHITE[3] = {255, 255, 255}; const int NULLRGB[3] = {0, 0, 0}; @@ -42,7 +42,7 @@ int openmc_plot_geometry() int err; for (int i = 0; i < n_plots; i++) { - ObjectPlot* pl = plots[i]; + Plot* pl = plots[i]; std::stringstream ss; ss << "Processing plot " << pl->id << ": " @@ -71,7 +71,7 @@ read_plots(pugi::xml_node* plots_node) n_plots = plot_nodes.size(); for(int i = 0; i < plot_nodes.size(); i++) { - ObjectPlot* pl = new ObjectPlot(plot_nodes[i]); + Plot* pl = new Plot(plot_nodes[i]); plots.push_back(pl); plot_map[pl->id] = i; } @@ -82,7 +82,7 @@ read_plots(pugi::xml_node* plots_node) // specification in the portable pixmap format (PPM) //=============================================================================== -void create_ppm(ObjectPlot* pl) +void create_ppm(Plot* pl) { int width = pl->pixels[0]; @@ -157,7 +157,7 @@ void create_ppm(ObjectPlot* pl) } void -ObjectPlot::set_id() +Plot::set_id() { // Copy data into plots if (check_for_node(_plot_node, "id")) { @@ -175,7 +175,7 @@ ObjectPlot::set_id() } void -ObjectPlot::set_type() +Plot::set_type() { // Copy plot type // Default is slice @@ -202,7 +202,7 @@ ObjectPlot::set_type() } void -ObjectPlot::set_output_path() +Plot::set_output_path() { // Set output file path std::stringstream filename; @@ -251,7 +251,7 @@ ObjectPlot::set_output_path() } void -ObjectPlot::set_bg_color() +Plot::set_bg_color() { // Copy plot background color std::vector bg_rgb; @@ -284,7 +284,7 @@ ObjectPlot::set_bg_color() } void -ObjectPlot::set_basis() +Plot::set_basis() { // Copy plot basis if (plot_type::slice == type) { @@ -309,7 +309,7 @@ ObjectPlot::set_basis() } void -ObjectPlot::set_origin() +Plot::set_origin() { // Copy plotting origin std::vector pl_origin; @@ -327,7 +327,7 @@ ObjectPlot::set_origin() } void -ObjectPlot::set_width() +Plot::set_width() { // Copy plotting width std::vector pl_width; @@ -358,7 +358,7 @@ ObjectPlot::set_width() } void -ObjectPlot::set_universe() +Plot::set_universe() { // Copy plot universe level if (check_for_node(_plot_node, "level")) { @@ -374,7 +374,7 @@ ObjectPlot::set_universe() } void -ObjectPlot::set_default_colors() +Plot::set_default_colors() { // Copy plot color type and initialize all colors randomly std::string pl_color_by = "cell"; @@ -384,7 +384,7 @@ ObjectPlot::set_default_colors() if ("cell" == pl_color_by) { color_by = plot_color_by::cells; for(int i = 0; i < n_cells; i++) { - colors.push_back(new ObjectColor()); + colors.push_back(new RGBColor()); colors[i]->rgb[RED] = int(prn()*255); colors[i]->rgb[GREEN] = int(prn()*255); colors[i]->rgb[BLUE] = int(prn()*255); @@ -393,7 +393,7 @@ ObjectPlot::set_default_colors() } else if("material" == pl_color_by) { color_by = plot_color_by::mats; for(int i = 0; i < materials.size(); i++) { - colors.push_back(new ObjectColor()); + colors.push_back(new RGBColor()); colors[i]->rgb[RED] = int(prn()*255); colors[i]->rgb[GREEN] = int(prn()*255); colors[i]->rgb[BLUE] = int(prn()*255); @@ -407,7 +407,7 @@ ObjectPlot::set_default_colors() } void -ObjectPlot::set_user_colors() +Plot::set_user_colors() { // Get the number of nodes and get a list of them std::vector color_nodes; @@ -477,7 +477,7 @@ ObjectPlot::set_user_colors() } void -ObjectPlot::set_meshlines() +Plot::set_meshlines() { // Deal with meshlines std::vector mesh_line_nodes; @@ -596,7 +596,7 @@ ObjectPlot::set_meshlines() } void -ObjectPlot::set_mask() +Plot::set_mask() { // Deal with masks std::vector mask_nodes; @@ -679,7 +679,7 @@ ObjectPlot::set_mask() } } -ObjectPlot::ObjectPlot(pugi::xml_node plot_node): +Plot::Plot(pugi::xml_node plot_node): index_meshlines_mesh(-1) { _plot_node = plot_node; @@ -696,9 +696,9 @@ index_meshlines_mesh(-1) set_meshlines(); set_mask(); _plot_node = pugi::xml_node(); // set to null node after construction -} // End ObjectPlot constructor +} // End Plot constructor -ObjectPlot::~ObjectPlot() { +Plot::~Plot() { // cleanup color pointers for (auto c : colors) { if (c) {delete c;} @@ -710,7 +710,7 @@ ObjectPlot::~ObjectPlot() { // current particle's position //=============================================================================== -void position_rgb(Particle* p, ObjectPlot* pl, int rgb[3], int &id) +void position_rgb(Particle* p, Plot* pl, int rgb[3], int &id) { p->n_coord = 1; @@ -768,7 +768,7 @@ void position_rgb(Particle* p, ObjectPlot* pl, int rgb[3], int &id) // OUTPUT_PPM writes out a previously generated image to a PPM file //=============================================================================== -void output_ppm(ObjectPlot* pl, const ImageData &data) +void output_ppm(Plot* pl, const ImageData &data) { // Open PPM file for writing std::string fname = pl->path_plot; @@ -803,7 +803,7 @@ void output_ppm(ObjectPlot* pl, const ImageData &data) // DRAW_MESH_LINES draws mesh line boundaries on an image //=============================================================================== -void draw_mesh_lines(ObjectPlot *pl, ImageData &data) +void draw_mesh_lines(Plot *pl, ImageData &data) { std::vector rgb; rgb.resize(3); rgb[RED] = pl->meshlines_color.rgb[RED]; @@ -912,7 +912,7 @@ void draw_mesh_lines(ObjectPlot *pl, ImageData &data) // id. For 1 million voxels this produces a file of approximately 15MB. //=============================================================================== -void create_voxel(ObjectPlot *pl) +void create_voxel(Plot *pl) { // compute voxel widths in each direction From 8018b56100ddee033af873a5f1231c18b77e7fc3 Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Mon, 29 Oct 2018 09:47:49 -0500 Subject: [PATCH 063/105] Updating structure of RGB color data. --- include/openmc/plot.h | 19 +++----- src/plot.cpp | 108 ++++++++++++++++++------------------------ 2 files changed, 54 insertions(+), 73 deletions(-) diff --git a/include/openmc/plot.h b/include/openmc/plot.h index 69d8c1cf8..0c5a24484 100644 --- a/include/openmc/plot.h +++ b/include/openmc/plot.h @@ -29,7 +29,7 @@ extern int n_plots; //!< number of plots in openmc run class Plot; extern std::vector plots; //!< Plot instance container -typedef std::vector>> ImageData; +typedef std::vector>> ImageData; enum class plot_type { slice = 1, @@ -51,10 +51,8 @@ enum class plot_color_by { // RGBColor holds color information for plotted objects //=============================================================================== -struct RGBColor { - int rgb[3]; //!< RGB color values -}; - +typedef std::array RGBColor; + //=============================================================================== // Plot class //=============================================================================== @@ -66,9 +64,6 @@ public: // Constructor Plot(pugi::xml_node plot); - // Destructor - ~Plot(); - // Methods private: void set_id(); @@ -98,7 +93,7 @@ public: int index_meshlines_mesh; //!< Index of the mesh to draw on the plot RGBColor meshlines_color; //!< Color of meshlines on the plot RGBColor not_found; //!< Plot background color - std::vector colors; //!< Plot colors + std::vector colors; //!< Plot colors std::string path_plot; //!< Plot output filename pugi::xml_node _plot_node; }; @@ -111,20 +106,20 @@ public: //! \param[in] plot object //! \param[out] image data associated with the plot object void draw_mesh_lines(Plot* pl, - std::vector< std::vector< std::vector > > &data); + ImageData &data); //! Write a ppm image to file using a plot object's image data //! \param[in] plot object //! \param[out] image data associated with the plot object void output_ppm(Plot* pl, - const std::vector< std::vector< std::vector > > &data); + const ImageData &data); //! Get the rgb color for a given particle position in a plot //! \param[in] particle with position for current pixel //! \param[in] plot object //! \param[out] rgb color //! \param[out] cell or material id for particle position -void position_rgb(Particle* p, Plot* pl, int rgb[3], int &id); +void position_rgb(Particle* p, Plot* pl, RGBColor &rgb, int &id); //! Initialize a voxel file diff --git a/src/plot.cpp b/src/plot.cpp index 12aab9242..89bd936d6 100644 --- a/src/plot.cpp +++ b/src/plot.cpp @@ -29,8 +29,8 @@ int n_plots; std::vector plots; -const int WHITE[3] = {255, 255, 255}; -const int NULLRGB[3] = {0, 0, 0}; +const RGBColor WHITE = {255, 255, 255}; +const RGBColor NULLRGB = {0, 0, 0}; //=============================================================================== // RUN_PLOT controls the logic for making one or many plots @@ -134,7 +134,7 @@ void create_ppm(Plot* pl) p->coord[0].universe = openmc_root_universe; // local variables - int rgb[3]; + RGBColor rgb; int id; for (int y = 0; y < height; y++) { p->coord[0].xyz[out_i] = xyz[out_i] - out_pixel * y; @@ -266,9 +266,9 @@ Plot::set_bg_color() } if (node_word_count(_plot_node, "background") == 3) { bg_rgb = get_node_array(_plot_node, "background"); - not_found.rgb[RED] = bg_rgb[RED]; - not_found.rgb[GREEN] = bg_rgb[GREEN]; - not_found.rgb[BLUE] = bg_rgb[BLUE]; + not_found[RED] = bg_rgb[RED]; + not_found[GREEN] = bg_rgb[GREEN]; + not_found[BLUE] = bg_rgb[BLUE]; } else { std::stringstream err_msg; err_msg << "Bad background RGB in plot " @@ -277,9 +277,9 @@ Plot::set_bg_color() } } else { // default to a white background - not_found.rgb[RED] = 255; - not_found.rgb[GREEN] = 255; - not_found.rgb[BLUE] = 255; + not_found[RED] = 255; + not_found[GREEN] = 255; + not_found[BLUE] = 255; } } @@ -383,20 +383,20 @@ Plot::set_default_colors() } if ("cell" == pl_color_by) { color_by = plot_color_by::cells; + colors.resize(n_cells); for(int i = 0; i < n_cells; i++) { - colors.push_back(new RGBColor()); - colors[i]->rgb[RED] = int(prn()*255); - colors[i]->rgb[GREEN] = int(prn()*255); - colors[i]->rgb[BLUE] = int(prn()*255); + colors[i][RED] = int(prn()*255); + colors[i][GREEN] = int(prn()*255); + colors[i][BLUE] = int(prn()*255); } } else if("material" == pl_color_by) { color_by = plot_color_by::mats; + colors.resize(n_materials); for(int i = 0; i < materials.size(); i++) { - colors.push_back(new RGBColor()); - colors[i]->rgb[RED] = int(prn()*255); - colors[i]->rgb[GREEN] = int(prn()*255); - colors[i]->rgb[BLUE] = int(prn()*255); + colors[i][RED] = int(prn()*255); + colors[i][GREEN] = int(prn()*255); + colors[i][BLUE] = int(prn()*255); } } else { std::stringstream err_msg; @@ -448,9 +448,9 @@ Plot::set_user_colors() if (cell_map.find(col_id) != cell_map.end()) { col_id = cell_map[col_id]; cell_rgb = get_node_array(cn, "rgb"); - colors[col_id]->rgb[RED] = cell_rgb[RED]; - colors[col_id]->rgb[GREEN] = cell_rgb[GREEN]; - colors[col_id]->rgb[BLUE] = cell_rgb[BLUE]; + colors[col_id][RED] = cell_rgb[RED]; + colors[col_id][GREEN] = cell_rgb[GREEN]; + colors[col_id][BLUE] = cell_rgb[BLUE]; } else { std::stringstream err_msg; err_msg << "Could not find cell " << col_id @@ -462,9 +462,9 @@ Plot::set_user_colors() if (material_map.find(col_id) != material_map.end()) { col_id = material_map[col_id]; mat_rgb = get_node_array(cn, "rgb"); - colors[col_id]->rgb[RED] = mat_rgb[RED]; - colors[col_id]->rgb[GREEN] = mat_rgb[GREEN]; - colors[col_id]->rgb[BLUE] = mat_rgb[BLUE]; + colors[col_id][RED] = mat_rgb[RED]; + colors[col_id][GREEN] = mat_rgb[GREEN]; + colors[col_id][BLUE] = mat_rgb[BLUE]; } else { std::stringstream err_msg; err_msg << "Could not find material " << col_id @@ -527,13 +527,13 @@ Plot::set_meshlines() fatal_error(err_msg); } ml_rgb = get_node_array(meshlines_node, "color"); - meshlines_color.rgb[0] = ml_rgb[0]; - meshlines_color.rgb[1] = ml_rgb[1]; - meshlines_color.rgb[2] = ml_rgb[2]; + meshlines_color[0] = ml_rgb[0]; + meshlines_color[1] = ml_rgb[1]; + meshlines_color[2] = ml_rgb[2]; } else { - meshlines_color.rgb[0] = 0; - meshlines_color.rgb[1] = 0; - meshlines_color.rgb[2] = 0; + meshlines_color[0] = 0; + meshlines_color[1] = 0; + meshlines_color[2] = 0; } // Set mesh based on type @@ -660,13 +660,13 @@ Plot::set_mask() if (std::find(iarray.begin(), iarray.end(), j) == iarray.end()) { if (check_for_node(mask_node, "background")) { std::vector bg_rgb = get_node_array(mask_node, "background"); - colors[j]->rgb[RED] = bg_rgb[RED]; - colors[j]->rgb[GREEN] = bg_rgb[GREEN]; - colors[j]->rgb[BLUE] = bg_rgb[BLUE]; + colors[j][RED] = bg_rgb[RED]; + colors[j][GREEN] = bg_rgb[GREEN]; + colors[j][BLUE] = bg_rgb[BLUE]; } else { - colors[j]->rgb[RED] = 255; - colors[j]->rgb[GREEN] = 255; - colors[j]->rgb[BLUE] = 255; + colors[j][RED] = 255; + colors[j][GREEN] = 255; + colors[j][BLUE] = 255; } } } @@ -698,19 +698,12 @@ index_meshlines_mesh(-1) _plot_node = pugi::xml_node(); // set to null node after construction } // End Plot constructor -Plot::~Plot() { - // cleanup color pointers - for (auto c : colors) { - if (c) {delete c;} - } -} - //=============================================================================== // POSITION_RGB computes the red/green/blue values for a given plot with the // current particle's position //=============================================================================== -void position_rgb(Particle* p, Plot* pl, int rgb[3], int &id) +void position_rgb(Particle* p, Plot* pl, RGBColor &rgb, int &id) { p->n_coord = 1; @@ -725,9 +718,7 @@ void position_rgb(Particle* p, Plot* pl, int rgb[3], int &id) if (!found_cell) { // If no cell, revert to default color - std::copy(pl->not_found.rgb, - pl->not_found.rgb + 3, - rgb); + rgb = pl->not_found; id = -1; } else { if (plot_color_by::mats == pl->color_by) { @@ -735,29 +726,23 @@ void position_rgb(Particle* p, Plot* pl, int rgb[3], int &id) Cell* c = cells[p->coord[j].cell]; if (c->type_ == FILL_UNIVERSE) { // If we stopped on a middle universe level, treat as if not found - std::copy(pl->not_found.rgb, - pl->not_found.rgb + 3, - rgb); + rgb = pl->not_found; id = -1; } else if (p->material == MATERIAL_VOID) { // By default, color void cells white - std::copy(WHITE, WHITE+3, rgb); + rgb = WHITE; id = -1; } else { - std::copy(pl->colors[p->material - 1]->rgb, - pl->colors[p->material - 1]->rgb + 3, - rgb); + rgb = pl->colors[p->material - 1]; id = materials[p->material - 1]->id_; } } else if (plot_color_by::cells == pl->color_by) { // Assign color based on cell - std::copy(pl->colors[p->coord[j].cell]->rgb, - pl->colors[p->coord[j].cell]->rgb + 3, - rgb); + rgb = pl->colors[p->coord[j].cell]; id = cells[p->coord[j].cell]->id_; } else { - std::copy(NULLRGB, NULLRGB+3, rgb); + rgb = NULLRGB; id = -1; } @@ -806,9 +791,9 @@ void output_ppm(Plot* pl, const ImageData &data) void draw_mesh_lines(Plot *pl, ImageData &data) { std::vector rgb; rgb.resize(3); - rgb[RED] = pl->meshlines_color.rgb[RED]; - rgb[GREEN] = pl->meshlines_color.rgb[GREEN]; - rgb[BLUE] = pl->meshlines_color.rgb[BLUE]; + rgb[RED] = pl->meshlines_color[RED]; + rgb[GREEN] = pl->meshlines_color[GREEN]; + rgb[BLUE] = pl->meshlines_color[BLUE]; int outer, inner; switch(pl->basis) { @@ -973,7 +958,8 @@ void create_voxel(Plot *pl) int data[pl->pixels[1]][pl->pixels[2]]; - int rgb[3], id; + RGBColor rgb; + int id; for (int x = 0; x < pl->pixels[0]; x++) { // TODO: progress bar here for (int y = 0; y < pl->pixels[1]; y++) { From d64d72d967c1b1e0c167fb1d43273c4a255403d8 Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Mon, 29 Oct 2018 09:53:31 -0500 Subject: [PATCH 064/105] Updating Color to RGBColor to simplify and optimize code. --- include/openmc/plot.h | 14 +++++++------- src/plot.cpp | 7 ++----- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/include/openmc/plot.h b/include/openmc/plot.h index 0c5a24484..25bb1f4d2 100644 --- a/include/openmc/plot.h +++ b/include/openmc/plot.h @@ -29,7 +29,13 @@ extern int n_plots; //!< number of plots in openmc run class Plot; extern std::vector plots; //!< Plot instance container -typedef std::vector>> ImageData; +//=============================================================================== +// RGBColor holds color information for plotted objects +//=============================================================================== + +typedef std::array RGBColor; + +typedef std::vector> ImageData; enum class plot_type { slice = 1, @@ -46,12 +52,6 @@ enum class plot_color_by { cells = 1, mats = 2 }; - -//=============================================================================== -// RGBColor holds color information for plotted objects -//=============================================================================== - -typedef std::array RGBColor; //=============================================================================== // Plot class diff --git a/src/plot.cpp b/src/plot.cpp index 89bd936d6..4cd8d1613 100644 --- a/src/plot.cpp +++ b/src/plot.cpp @@ -95,9 +95,6 @@ void create_ppm(Plot* pl) data.resize(width); for (auto & i : data) { i.resize(height); - for (auto & j : i) { - j.resize(3); - } } int in_i, out_i; @@ -772,7 +769,7 @@ void output_ppm(Plot* pl, const ImageData &data) // Write color for each pixel for (int y = 0; y < pl->pixels[1]; y++) { for (int x = 0; x < pl->pixels[0]; x++) { - std::vector rgb = data[x][y]; + RGBColor rgb = data[x][y]; of.write((char*)&rgb[RED], 1); of.write((char*)&rgb[GREEN], 1); of.write((char*)&rgb[BLUE], 1); @@ -790,7 +787,7 @@ void output_ppm(Plot* pl, const ImageData &data) void draw_mesh_lines(Plot *pl, ImageData &data) { - std::vector rgb; rgb.resize(3); + RGBColor rgb; rgb[RED] = pl->meshlines_color[RED]; rgb[GREEN] = pl->meshlines_color[GREEN]; rgb[BLUE] = pl->meshlines_color[BLUE]; From d3f49861f5bff4e33aff5ee306ff75b54e1c9565 Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Mon, 29 Oct 2018 10:01:52 -0500 Subject: [PATCH 065/105] Shortening block comments to line length of 80. --- src/plot.cpp | 43 ++++++++++++++++++++++--------------------- 1 file changed, 22 insertions(+), 21 deletions(-) diff --git a/src/plot.cpp b/src/plot.cpp index 4cd8d1613..bcade1330 100644 --- a/src/plot.cpp +++ b/src/plot.cpp @@ -17,9 +17,9 @@ namespace openmc { -//=============================================================================== +//============================================================================== // Global variables -//=============================================================================== +//============================================================================== int PLOT_LEVEL_LOWEST = -1; @@ -32,9 +32,9 @@ std::vector plots; const RGBColor WHITE = {255, 255, 255}; const RGBColor NULLRGB = {0, 0, 0}; -//=============================================================================== +//============================================================================== // RUN_PLOT controls the logic for making one or many plots -//=============================================================================== +//============================================================================== extern "C" int openmc_plot_geometry() @@ -77,10 +77,10 @@ read_plots(pugi::xml_node* plots_node) } } -//=============================================================================== +//============================================================================== // CREATE_PPM creates an image based on user input from a plots.xml // specification in the portable pixmap format (PPM) -//=============================================================================== +//============================================================================== void create_ppm(Plot* pl) { @@ -695,10 +695,10 @@ index_meshlines_mesh(-1) _plot_node = pugi::xml_node(); // set to null node after construction } // End Plot constructor -//=============================================================================== +//============================================================================== // POSITION_RGB computes the red/green/blue values for a given plot with the // current particle's position -//=============================================================================== +//============================================================================== void position_rgb(Particle* p, Plot* pl, RGBColor &rgb, int &id) { @@ -746,9 +746,9 @@ void position_rgb(Particle* p, Plot* pl, RGBColor &rgb, int &id) } // endif found_cell } -//=============================================================================== +//============================================================================== // OUTPUT_PPM writes out a previously generated image to a PPM file -//=============================================================================== +//============================================================================== void output_ppm(Plot* pl, const ImageData &data) { @@ -781,9 +781,9 @@ void output_ppm(Plot* pl, const ImageData &data) of.close(); } -//=============================================================================== +//============================================================================== // DRAW_MESH_LINES draws mesh line boundaries on an image -//=============================================================================== +//============================================================================== void draw_mesh_lines(Plot *pl, ImageData &data) { @@ -882,17 +882,18 @@ void draw_mesh_lines(Plot *pl, ImageData &data) } // end outer loops } // end draw_mesh_lines -//=============================================================================== +//============================================================================== // CREATE_VOXEL outputs a binary file that can be input into silomesh for 3D // geometry visualization. It works the same way as create_ppm by dragging a -// particle across the geometry for the specified number of voxels. The first -// 3 int(4)'s in the binary are the number of x, y, and z voxels. The next 3 -// real(8)'s are the widths of the voxels in the x, y, and z directions. The next -// 3 real(8)'s are the x, y, and z coordinates of the lower left point. Finally -// the binary is filled with entries of four int(4)'s each. Each 'row' in the -// binary contains four int(4)'s: 3 for x,y,z position and 1 for cell or material -// id. For 1 million voxels this produces a file of approximately 15MB. -//=============================================================================== +// particle across the geometry for the specified number of voxels. The first 3 +// int(4)'s in the binary are the number of x, y, and z voxels. The next 3 +// real(8)'s are the widths of the voxels in the x, y, and z directions. The +// next 3 real(8)'s are the x, y, and z coordinates of the lower left +// point. Finally the binary is filled with entries of four int(4)'s each. Each +// 'row' in the binary contains four int(4)'s: 3 for x,y,z position and 1 for +// cell or material id. For 1 million voxels this produces a file of +// approximately 15MB. +// ============================================================================= void create_voxel(Plot *pl) { From 1e2cff2da92a98bac0f632bdf2d7538302e8566c Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Mon, 29 Oct 2018 10:18:02 -0500 Subject: [PATCH 066/105] Changing from plot pointers to objects in global vector. --- include/openmc/plot.h | 12 ++-- src/output.cpp | 50 +++++++-------- src/plot.cpp | 144 +++++++++++++++++++++--------------------- 3 files changed, 102 insertions(+), 104 deletions(-) diff --git a/include/openmc/plot.h b/include/openmc/plot.h index 25bb1f4d2..bcd1f16f3 100644 --- a/include/openmc/plot.h +++ b/include/openmc/plot.h @@ -27,7 +27,7 @@ extern std::map plot_map; //!< map of plot ids to index extern int n_plots; //!< number of plots in openmc run class Plot; -extern std::vector plots; //!< Plot instance container +extern std::vector plots; //!< Plot instance container //=============================================================================== // RGBColor holds color information for plotted objects @@ -105,13 +105,13 @@ public: //! Add mesh lines to image data of a plot object //! \param[in] plot object //! \param[out] image data associated with the plot object -void draw_mesh_lines(Plot* pl, +void draw_mesh_lines(Plot pl, ImageData &data); //! Write a ppm image to file using a plot object's image data //! \param[in] plot object //! \param[out] image data associated with the plot object -void output_ppm(Plot* pl, +void output_ppm(Plot pl, const ImageData &data); //! Get the rgb color for a given particle position in a plot @@ -119,7 +119,7 @@ void output_ppm(Plot* pl, //! \param[in] plot object //! \param[out] rgb color //! \param[out] cell or material id for particle position -void position_rgb(Particle* p, Plot* pl, RGBColor &rgb, int &id); +void position_rgb(Particle* p, Plot pl, RGBColor &rgb, int &id); //! Initialize a voxel file @@ -154,11 +154,11 @@ extern "C" void read_plots(pugi::xml_node* plot_node); //! Create a ppm image for a plot object //! \param[in] plot object -extern "C" void create_ppm(Plot* pl); +extern "C" void create_ppm(Plot pl); //! Create an hdf5 voxel file for a plot object //! \param[in] plot object -extern "C" void create_voxel(Plot *pl); +extern "C" void create_voxel(Plot pl); } // namespace openmc diff --git a/src/output.cpp b/src/output.cpp index 396fffac0..e9c3f567f 100644 --- a/src/output.cpp +++ b/src/output.cpp @@ -64,45 +64,45 @@ void print_plot() { for (auto pl : plots) { // Plot id - std::cout << "Plot ID: " << pl->id << std::endl; + std::cout << "Plot ID: " << pl.id << std::endl; // Plot filename - std::cout << "Plot file: " << pl->path_plot << std::endl; + std::cout << "Plot file: " << pl.path_plot << std::endl; // Plot level - std::cout << "Universe depth: " << pl->level << std::endl; + std::cout << "Universe depth: " << pl.level << std::endl; // Plot type - if (plot_type::slice == pl->type) { + if (plot_type::slice == pl.type) { std::cout << "Plot Type: Slice" << std::endl; - } else if (plot_type::voxel == pl->type) { + } else if (plot_type::voxel == pl.type) { std::cout << "Plot Type: Voxel" << std::endl; } // Plot parameters - std::cout << "Origin: " << pl->origin[0] << " " - << pl->origin[1] << " " - << pl->origin[2] << std::endl; + std::cout << "Origin: " << pl.origin[0] << " " + << pl.origin[1] << " " + << pl.origin[2] << std::endl; - if (plot_type::slice == pl->type) { + if (plot_type::slice == pl.type) { std::cout << std::setprecision(4) << "Width: " - << pl->width[0] << " " - << pl->width[1] << std::endl; - } else if (plot_type::voxel == pl->type) { + << pl.width[0] << " " + << pl.width[1] << std::endl; + } else if (plot_type::voxel == pl.type) { std::cout << std::setprecision(4) << "Width: " - << pl->width[0] << " " - << pl->width[1] << " " - << pl->width[2] << std::endl; + << pl.width[0] << " " + << pl.width[1] << " " + << pl.width[2] << std::endl; } - if (plot_color_by::cells == pl->color_by) { + if (plot_color_by::cells == pl.color_by) { std::cout << "Coloring: Cells" << std::endl; - } else if (plot_color_by::mats == pl->color_by) { + } else if (plot_color_by::mats == pl.color_by) { std::cout << "Coloring: Materials" << std::endl; } - if (plot_type::slice == pl->type) { - switch(pl->basis) { + if (plot_type::slice == pl.type) { + switch(pl.basis) { case plot_basis::xy: std::cout << "Basis: XY" << std::endl; break; @@ -113,12 +113,12 @@ void print_plot() { std::cout << "Basis: YZ" << std::endl; break; } - std::cout << "Pixels: " << pl->pixels[0] << " " - << pl->pixels[1] << " " << std::endl; - } else if (plot_type::voxel == pl->type) { - std::cout << "Voxels: " << pl->pixels[0] << " " - << pl->pixels[1] << " " - << pl->pixels[2] << std::endl; + std::cout << "Pixels: " << pl.pixels[0] << " " + << pl.pixels[1] << " " << std::endl; + } else if (plot_type::voxel == pl.type) { + std::cout << "Voxels: " << pl.pixels[0] << " " + << pl.pixels[1] << " " + << pl.pixels[2] << std::endl; } std::cout << std::endl; diff --git a/src/plot.cpp b/src/plot.cpp index bcade1330..70aa2e29a 100644 --- a/src/plot.cpp +++ b/src/plot.cpp @@ -27,7 +27,7 @@ std::map plot_map; int n_plots; -std::vector plots; +std::vector plots; const RGBColor WHITE = {255, 255, 255}; const RGBColor NULLRGB = {0, 0, 0}; @@ -41,18 +41,16 @@ int openmc_plot_geometry() { int err; - for (int i = 0; i < n_plots; i++) { - Plot* pl = plots[i]; - + for (auto pl : plots) { std::stringstream ss; - ss << "Processing plot " << pl->id << ": " - << pl->path_plot << "..."; + ss << "Processing plot " << pl.id << ": " + << pl.path_plot << "..."; write_message(ss.str(), 5); - if (plot_type::slice == pl->type) { + if (plot_type::slice == pl.type) { // create 2D image create_ppm(pl); - } else if (plot_type::voxel == pl->type) { + } else if (plot_type::voxel == pl.type) { // create voxel file for 3D viewing create_voxel(pl); } @@ -71,9 +69,9 @@ read_plots(pugi::xml_node* plots_node) n_plots = plot_nodes.size(); for(int i = 0; i < plot_nodes.size(); i++) { - Plot* pl = new Plot(plot_nodes[i]); + Plot pl(plot_nodes[i]); plots.push_back(pl); - plot_map[pl->id] = i; + plot_map[pl.id] = i; } } @@ -82,14 +80,14 @@ read_plots(pugi::xml_node* plots_node) // specification in the portable pixmap format (PPM) //============================================================================== -void create_ppm(Plot* pl) +void create_ppm(Plot pl) { - int width = pl->pixels[0]; - int height = pl->pixels[1]; + int width = pl.pixels[0]; + int height = pl.pixels[1]; - double in_pixel = (pl->width[0])/double(width); - double out_pixel = (pl->width[1])/double(height); + double in_pixel = (pl.width[0])/double(width); + double out_pixel = (pl.width[1])/double(height); ImageData data; data.resize(width); @@ -99,27 +97,27 @@ void create_ppm(Plot* pl) int in_i, out_i; double xyz[3]; - switch(pl->basis) { + switch(pl.basis) { case plot_basis::xy : in_i = 0; out_i = 1; - xyz[0] = pl->origin[0] - pl->width[0] / TWO; - xyz[1] = pl->origin[1] + pl->width[1] / TWO; - xyz[2] = pl->origin[2]; + xyz[0] = pl.origin[0] - pl.width[0] / TWO; + xyz[1] = pl.origin[1] + pl.width[1] / TWO; + xyz[2] = pl.origin[2]; break; case plot_basis::xz : in_i = 0; out_i = 2; - xyz[0] = pl->origin[0] - pl->width[0] / TWO; - xyz[1] = pl->origin[1]; - xyz[2] = pl->origin[2] + pl->width[1] / TWO; + xyz[0] = pl.origin[0] - pl.width[0] / TWO; + xyz[1] = pl.origin[1]; + xyz[2] = pl.origin[2] + pl.width[1] / TWO; break; case plot_basis::yz : in_i = 1; out_i = 2; - xyz[0] = pl->origin[0]; - xyz[1] = pl->origin[1] - pl->width[0] / TWO; - xyz[2] = pl->origin[2] + pl->width[1] / TWO; + xyz[0] = pl.origin[0]; + xyz[1] = pl.origin[1] - pl.width[0] / TWO; + xyz[2] = pl.origin[2] + pl.width[1] / TWO; break; } @@ -147,7 +145,7 @@ void create_ppm(Plot* pl) delete p; // draw mesh lines if present - if (pl->index_meshlines_mesh >= 0) {draw_mesh_lines(pl, data);} + if (pl.index_meshlines_mesh >= 0) {draw_mesh_lines(pl, data);} // write ppm data to file output_ppm(pl, data); @@ -700,7 +698,7 @@ index_meshlines_mesh(-1) // current particle's position //============================================================================== -void position_rgb(Particle* p, Plot* pl, RGBColor &rgb, int &id) +void position_rgb(Particle* p, Plot pl, RGBColor &rgb, int &id) { p->n_coord = 1; @@ -711,32 +709,32 @@ void position_rgb(Particle* p, Plot* pl, RGBColor &rgb, int &id) if (settings::check_overlaps) {check_cell_overlap(p);} // Set coordinate level if specified - if (pl->level >= 0) {j = pl->level + 1;} + if (pl.level >= 0) {j = pl.level + 1;} if (!found_cell) { // If no cell, revert to default color - rgb = pl->not_found; + rgb = pl.not_found; id = -1; } else { - if (plot_color_by::mats == pl->color_by) { + if (plot_color_by::mats == pl.color_by) { // Assign color based on material Cell* c = cells[p->coord[j].cell]; if (c->type_ == FILL_UNIVERSE) { // If we stopped on a middle universe level, treat as if not found - rgb = pl->not_found; + rgb = pl.not_found; id = -1; } else if (p->material == MATERIAL_VOID) { // By default, color void cells white rgb = WHITE; id = -1; } else { - rgb = pl->colors[p->material - 1]; + rgb = pl.colors[p->material - 1]; id = materials[p->material - 1]->id_; } - } else if (plot_color_by::cells == pl->color_by) { + } else if (plot_color_by::cells == pl.color_by) { // Assign color based on cell - rgb = pl->colors[p->coord[j].cell]; + rgb = pl.colors[p->coord[j].cell]; id = cells[p->coord[j].cell]->id_; } else { rgb = NULLRGB; @@ -750,10 +748,10 @@ void position_rgb(Particle* p, Plot* pl, RGBColor &rgb, int &id) // OUTPUT_PPM writes out a previously generated image to a PPM file //============================================================================== -void output_ppm(Plot* pl, const ImageData &data) +void output_ppm(Plot pl, const ImageData &data) { // Open PPM file for writing - std::string fname = pl->path_plot; + std::string fname = pl.path_plot; fname = strtrim(fname); std::ofstream of; @@ -761,14 +759,14 @@ void output_ppm(Plot* pl, const ImageData &data) // Write header of << "P6" << std::endl; - of << pl->pixels[0] << " " << pl->pixels[1] << std::endl; + of << pl.pixels[0] << " " << pl.pixels[1] << std::endl; of << "255" << std::endl; of.close(); of.open(fname, std::ios::binary | std::ios::app); // Write color for each pixel - for (int y = 0; y < pl->pixels[1]; y++) { - for (int x = 0; x < pl->pixels[0]; x++) { + for (int y = 0; y < pl.pixels[1]; y++) { + for (int x = 0; x < pl.pixels[0]; x++) { RGBColor rgb = data[x][y]; of.write((char*)&rgb[RED], 1); of.write((char*)&rgb[GREEN], 1); @@ -785,15 +783,15 @@ void output_ppm(Plot* pl, const ImageData &data) // DRAW_MESH_LINES draws mesh line boundaries on an image //============================================================================== -void draw_mesh_lines(Plot *pl, ImageData &data) +void draw_mesh_lines(Plot pl, ImageData &data) { RGBColor rgb; - rgb[RED] = pl->meshlines_color[RED]; - rgb[GREEN] = pl->meshlines_color[GREEN]; - rgb[BLUE] = pl->meshlines_color[BLUE]; + rgb[RED] = pl.meshlines_color[RED]; + rgb[GREEN] = pl.meshlines_color[GREEN]; + rgb[BLUE] = pl.meshlines_color[BLUE]; int outer, inner; - switch(pl->basis) { + switch(pl.basis) { case plot_basis::xy : outer = 0; inner = 1; @@ -809,20 +807,20 @@ void draw_mesh_lines(Plot *pl, ImageData &data) } double xyz_ll_plot[3], xyz_ur_plot[3]; - std::copy((double*)&pl->origin, (double*)&pl->origin + 3, xyz_ll_plot); - std::copy((double*)&pl->origin, (double*)&pl->origin + 3, xyz_ur_plot); + std::copy((double*)&pl.origin, (double*)&pl.origin + 3, xyz_ll_plot); + std::copy((double*)&pl.origin, (double*)&pl.origin + 3, xyz_ur_plot); - xyz_ll_plot[outer] = pl->origin[outer] - pl->width[0] / TWO; - xyz_ll_plot[inner] = pl->origin[inner] - pl->width[1] / TWO; - xyz_ur_plot[outer] = pl->origin[outer] + pl->width[0] / TWO; - xyz_ur_plot[inner] = pl->origin[inner] + pl->width[1] / TWO; + xyz_ll_plot[outer] = pl.origin[outer] - pl.width[0] / TWO; + xyz_ll_plot[inner] = pl.origin[inner] - pl.width[1] / TWO; + xyz_ur_plot[outer] = pl.origin[outer] + pl.width[0] / TWO; + xyz_ur_plot[inner] = pl.origin[inner] + pl.width[1] / TWO; int width[3]; width[0] = xyz_ur_plot[0] - xyz_ll_plot[0]; width[1] = xyz_ur_plot[1] - xyz_ll_plot[1]; width[2] = xyz_ur_plot[2] - xyz_ll_plot[2]; - auto &m = meshes[pl->index_meshlines_mesh]; + auto &m = meshes[pl.index_meshlines_mesh]; int ijk_ll[3], ijk_ur[3]; bool in_mesh; @@ -849,18 +847,18 @@ void draw_mesh_lines(Plot *pl, ImageData &data) // map the xyz ranges to pixel ranges frac = (xyz_ll[outer] - xyz_ll_plot[outer]) / width[outer]; - outrange[0] = int(frac * double(pl->pixels[0])); + outrange[0] = int(frac * double(pl.pixels[0])); frac = (xyz_ur[outer] - xyz_ll_plot[outer]) / width[outer]; - outrange[1] = int(frac * double(pl->pixels[0])); + outrange[1] = int(frac * double(pl.pixels[0])); frac = (xyz_ur[inner] - xyz_ll_plot[inner]) / width[inner]; - inrange[0] = int((ONE - frac) * (double)pl->pixels[1]); + inrange[0] = int((ONE - frac) * (double)pl.pixels[1]); frac = (xyz_ll[inner] - xyz_ll_plot[inner]) / width[inner]; - inrange[1] = int((ONE - frac) * (double)pl->pixels[1]); + inrange[1] = int((ONE - frac) * (double)pl.pixels[1]); // draw lines for (int out_ = outrange[0]; out_ <= outrange[1]; out_++) { - for (int plus = 0; plus <= pl->meshlines_width; plus++) { + for (int plus = 0; plus <= pl.meshlines_width; plus++) { data[out_][inrange[0] + plus] = rgb; data[out_][inrange[1] + plus] = rgb; data[out_][inrange[0] - plus] = rgb; @@ -869,7 +867,7 @@ void draw_mesh_lines(Plot *pl, ImageData &data) } for (int in_ = inrange[0]; in_ <= inrange[1]; in_++) { - for (int plus = 0; plus <= pl->meshlines_width; plus++) { + for (int plus = 0; plus <= pl.meshlines_width; plus++) { data[outrange[0] + plus][in_] = rgb; data[outrange[1] + plus][in_] = rgb; data[outrange[0] - plus][in_] = rgb; @@ -895,20 +893,20 @@ void draw_mesh_lines(Plot *pl, ImageData &data) // approximately 15MB. // ============================================================================= -void create_voxel(Plot *pl) +void create_voxel(Plot pl) { // compute voxel widths in each direction double vox[3]; - vox[0] = pl->width[0]/(double)pl->pixels[0]; - vox[1] = pl->width[1]/(double)pl->pixels[1]; - vox[2] = pl->width[2]/(double)pl->pixels[2]; + vox[0] = pl.width[0]/(double)pl.pixels[0]; + vox[1] = pl.width[1]/(double)pl.pixels[1]; + vox[2] = pl.width[2]/(double)pl.pixels[2]; // initial particle position double ll[3]; - ll[0] = pl->origin[0] - pl->width[0] / TWO; - ll[1] = pl->origin[1] - pl->width[1] / TWO; - ll[2] = pl->origin[2] - pl->width[2] / TWO; + ll[0] = pl.origin[0] - pl.width[0] / TWO; + ll[1] = pl.origin[1] - pl.width[1] / TWO; + ll[2] = pl.origin[2] - pl.width[2] / TWO; // allocate and initialize particle double dir[3] = {HALF, HALF, HALF}; @@ -920,7 +918,7 @@ void create_voxel(Plot *pl) // Open binary plot file for writing std::ofstream of; - std::string fname = std::string(pl->path_plot); + std::string fname = std::string(pl.path_plot); fname = strtrim(fname); hid_t file_id = file_open(fname, 'w'); @@ -936,16 +934,16 @@ void create_voxel(Plot *pl) // Write current date and time write_attribute(file_id, "date_and_time", time_stamp().c_str()); hsize_t three = 3; - write_attr_int(file_id, 1, &three, "num_voxels", pl->pixels); + write_attr_int(file_id, 1, &three, "num_voxels", pl.pixels); write_attr_double(file_id, 1, &three, "voxel_width", vox); write_attr_double(file_id, 1, &three, "lower_left", ll); // Create dataset for voxel data -- note that the dimensions are reversed // since we want the order in the file to be z, y, x hsize_t dims[3]; - dims[0] = pl->pixels[0]; - dims[1] = pl->pixels[1]; - dims[2] = pl->pixels[2]; + dims[0] = pl.pixels[0]; + dims[1] = pl.pixels[1]; + dims[2] = pl.pixels[2]; hid_t dspace, dset, memspace; voxel_init(file_id, &(dims[0]), &dspace, &dset, &memspace); @@ -954,14 +952,14 @@ void create_voxel(Plot *pl) ll[1] = ll[1] + vox[1] / TWO; ll[2] = ll[2] + vox[2] / TWO; - int data[pl->pixels[1]][pl->pixels[2]]; + int data[pl.pixels[1]][pl.pixels[2]]; RGBColor rgb; int id; - for (int x = 0; x < pl->pixels[0]; x++) { + for (int x = 0; x < pl.pixels[0]; x++) { // TODO: progress bar here - for (int y = 0; y < pl->pixels[1]; y++) { - for(int z = 0; z < pl->pixels[2]; z++) { + for (int y = 0; y < pl.pixels[1]; y++) { + for(int z = 0; z < pl.pixels[2]; z++) { // get voxel color position_rgb(p, pl, rgb, id); // write to plot data From 1cebc3e9a21fa1cc0a105bd64c7fe3ff9386c4fa Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Mon, 29 Oct 2018 10:29:41 -0500 Subject: [PATCH 067/105] Updating some style and a few calls. --- src/plot.cpp | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/src/plot.cpp b/src/plot.cpp index 70aa2e29a..1472501d2 100644 --- a/src/plot.cpp +++ b/src/plot.cpp @@ -68,7 +68,7 @@ read_plots(pugi::xml_node* plots_node) n_plots = plot_nodes.size(); - for(int i = 0; i < plot_nodes.size(); i++) { + for (int i = 0; i < plot_nodes.size(); i++) { Plot pl(plot_nodes[i]); plots.push_back(pl); plot_map[pl.id] = i; @@ -174,11 +174,10 @@ Plot::set_type() { // Copy plot type // Default is slice - std::string type_str = "slice"; type = plot_type::slice; // check type specified on plot node if (check_for_node(_plot_node, "type")) { - type_str = get_node_value(_plot_node, "type", true); + std::string type_str = get_node_value(_plot_node, "type", true); // set type using node value if (type_str == "slice") { type = plot_type::slice; @@ -285,9 +284,8 @@ Plot::set_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"); + pl_basis = get_node_value(_plot_node, "basis", true); } - to_lower(pl_basis); if ("xy" == pl_basis) { basis = plot_basis::xy; } else if ("xz" == pl_basis) { @@ -379,7 +377,7 @@ Plot::set_default_colors() if ("cell" == pl_color_by) { color_by = plot_color_by::cells; colors.resize(n_cells); - for(int i = 0; i < n_cells; i++) { + for (int i = 0; i < n_cells; i++) { colors[i][RED] = int(prn()*255); colors[i][GREEN] = int(prn()*255); colors[i][BLUE] = int(prn()*255); @@ -388,7 +386,7 @@ Plot::set_default_colors() } else if("material" == pl_color_by) { color_by = plot_color_by::mats; colors.resize(n_materials); - for(int i = 0; i < materials.size(); i++) { + for (int i = 0; i < materials.size(); i++) { colors[i][RED] = int(prn()*255); colors[i][GREEN] = int(prn()*255); colors[i][BLUE] = int(prn()*255); @@ -420,7 +418,7 @@ Plot::set_user_colors() } } - for(auto cn : color_nodes) { + for (auto cn : color_nodes) { // Check and make sure 3 values are specified for RGB if (node_word_count(cn, "rgb") != 3) { std::stringstream err_msg; @@ -651,7 +649,7 @@ Plot::set_mask() } // Alter colors based on mask information - for(int j = 0; j < colors.size(); j++) { + for (int j = 0; j < colors.size(); j++) { if (std::find(iarray.begin(), iarray.end(), j) == iarray.end()) { if (check_for_node(mask_node, "background")) { std::vector bg_rgb = get_node_array(mask_node, "background"); @@ -959,7 +957,7 @@ void create_voxel(Plot pl) for (int x = 0; x < pl.pixels[0]; x++) { // TODO: progress bar here for (int y = 0; y < pl.pixels[1]; y++) { - for(int z = 0; z < pl.pixels[2]; z++) { + for (int z = 0; z < pl.pixels[2]; z++) { // get voxel color position_rgb(p, pl, rgb, id); // write to plot data From 7a35ac8b5eaf86f637f4f173d105663e3af91eac Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Mon, 29 Oct 2018 10:35:22 -0500 Subject: [PATCH 068/105] Removing _plot_node member of Plot. --- include/openmc/plot.h | 25 +++++----- src/plot.cpp | 106 +++++++++++++++++++++--------------------- 2 files changed, 64 insertions(+), 67 deletions(-) diff --git a/include/openmc/plot.h b/include/openmc/plot.h index bcd1f16f3..48d486e5d 100644 --- a/include/openmc/plot.h +++ b/include/openmc/plot.h @@ -66,18 +66,18 @@ public: // Methods private: - void set_id(); - void set_type(); - void set_output_path(); - void set_bg_color(); - void set_basis(); - void set_origin(); - void set_width(); - void set_universe(); - void set_default_colors(); - void set_user_colors(); - void set_meshlines(); - void set_mask(); + void set_id(pugi::xml_node plot_node); + void set_type(pugi::xml_node plot_node); + void set_output_path(pugi::xml_node plot_node); + void set_bg_color(pugi::xml_node plot_node); + void set_basis(pugi::xml_node plot_node); + void set_origin(pugi::xml_node plot_node); + void set_width(pugi::xml_node plot_node); + void set_universe(pugi::xml_node plot_node); + void set_default_colors(pugi::xml_node plot_node); + void set_user_colors(pugi::xml_node plot_node); + void set_meshlines(pugi::xml_node plot_node); + void set_mask(pugi::xml_node plot_node); // Members public: @@ -95,7 +95,6 @@ public: RGBColor not_found; //!< Plot background color std::vector colors; //!< Plot colors std::string path_plot; //!< Plot output filename - pugi::xml_node _plot_node; }; //=============================================================================== diff --git a/src/plot.cpp b/src/plot.cpp index 1472501d2..883824a95 100644 --- a/src/plot.cpp +++ b/src/plot.cpp @@ -152,11 +152,11 @@ void create_ppm(Plot pl) } void -Plot::set_id() +Plot::set_id(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")); + 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."); } @@ -170,14 +170,14 @@ Plot::set_id() } void -Plot::set_type() +Plot::set_type(pugi::xml_node plot_node) { // Copy plot type // Default is slice type = plot_type::slice; // check type specified on plot node - if (check_for_node(_plot_node, "type")) { - std::string type_str = get_node_value(_plot_node, "type", true); + if (check_for_node(plot_node, "type")) { + std::string type_str = get_node_value(plot_node, "type", true); // set type using node value if (type_str == "slice") { type = plot_type::slice; @@ -196,14 +196,14 @@ Plot::set_type() } void -Plot::set_output_path() +Plot::set_output_path(pugi::xml_node plot_node) { // Set output file path std::stringstream filename; filename << "plot_" << id; - if (check_for_node(_plot_node, "filename")) { - filename << get_node_value(_plot_node, "filename"); + if (check_for_node(plot_node, "filename")) { + filename << get_node_value(plot_node, "filename"); } else { switch(type) { case plot_type::slice: @@ -219,8 +219,8 @@ Plot::set_output_path() // 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"); + if (node_word_count(plot_node, "pixels") == 2) { + pxls = get_node_array(plot_node, "pixels"); pixels[0] = pxls[0]; pixels[1] = pxls[1]; } else { @@ -230,8 +230,8 @@ Plot::set_output_path() 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"); + 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]; @@ -245,11 +245,11 @@ Plot::set_output_path() } void -Plot::set_bg_color() +Plot::set_bg_color(pugi::xml_node plot_node) { // Copy plot background color std::vector bg_rgb; - if (check_for_node(_plot_node, "background")) { + if (check_for_node(plot_node, "background")) { if (plot_type::voxel == type) { if (openmc_master) { std::stringstream err_msg; @@ -258,8 +258,8 @@ Plot::set_bg_color() warning(err_msg.str()); } } - if (node_word_count(_plot_node, "background") == 3) { - bg_rgb = get_node_array(_plot_node, "background"); + if (node_word_count(plot_node, "background") == 3) { + bg_rgb = get_node_array(plot_node, "background"); not_found[RED] = bg_rgb[RED]; not_found[GREEN] = bg_rgb[GREEN]; not_found[BLUE] = bg_rgb[BLUE]; @@ -278,13 +278,13 @@ Plot::set_bg_color() } void -Plot::set_basis() +Plot::set_basis(pugi::xml_node plot_node) { // 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", true); + if (check_for_node(plot_node, "basis")) { + pl_basis = get_node_value(plot_node, "basis", true); } if ("xy" == pl_basis) { basis = plot_basis::xy; @@ -302,12 +302,12 @@ Plot::set_basis() } void -Plot::set_origin() +Plot::set_origin(pugi::xml_node plot_node) { // Copy plotting origin std::vector pl_origin; - if (node_word_count(_plot_node, "origin") == 3) { - pl_origin = get_node_array(_plot_node, "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]; @@ -320,13 +320,13 @@ Plot::set_origin() } void -Plot::set_width() +Plot::set_width(pugi::xml_node plot_node) { // 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"); + 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 { @@ -336,8 +336,8 @@ Plot::set_width() 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"); + 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]; @@ -351,11 +351,11 @@ Plot::set_width() } void -Plot::set_universe() +Plot::set_universe(pugi::xml_node plot_node) { // Copy plot universe level - if (check_for_node(_plot_node, "level")) { - level = std::stoi(get_node_value(_plot_node, "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 ; @@ -367,12 +367,12 @@ Plot::set_universe() } void -Plot::set_default_colors() +Plot::set_default_colors(pugi::xml_node plot_node) { // 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", true); + if (check_for_node(plot_node, "color_by")) { + pl_color_by = get_node_value(plot_node, "color_by", true); } if ("cell" == pl_color_by) { color_by = plot_color_by::cells; @@ -400,11 +400,11 @@ Plot::set_default_colors() } void -Plot::set_user_colors() +Plot::set_user_colors(pugi::xml_node plot_node) { // Get the number of nodes and get a list of them std::vector color_nodes; - color_nodes = get_child_nodes(_plot_node, "color"); + color_nodes = get_child_nodes(plot_node, "color"); // Copy user-specified colors if (color_nodes.size() != 0) { @@ -470,11 +470,11 @@ Plot::set_user_colors() } void -Plot::set_meshlines() +Plot::set_meshlines(pugi::xml_node plot_node) { // Deal with meshlines std::vector mesh_line_nodes; - mesh_line_nodes = get_child_nodes(_plot_node, "meshlines"); + mesh_line_nodes = get_child_nodes(plot_node, "meshlines"); int n_meshlines = mesh_line_nodes.size(); @@ -589,11 +589,11 @@ Plot::set_meshlines() } void -Plot::set_mask() +Plot::set_mask(pugi::xml_node plot_node) { // Deal with masks std::vector mask_nodes; - mask_nodes = get_child_nodes(_plot_node, "mask"); + mask_nodes = get_child_nodes(plot_node, "mask"); int n_masks = mask_nodes.size(); if (n_masks > 0) { @@ -675,20 +675,18 @@ Plot::set_mask() Plot::Plot(pugi::xml_node plot_node): index_meshlines_mesh(-1) { - _plot_node = plot_node; - set_id(); - set_type(); - set_output_path(); - set_bg_color(); - set_basis(); - set_origin(); - set_width(); - set_universe(); - set_default_colors(); - set_user_colors(); - set_meshlines(); - set_mask(); - _plot_node = pugi::xml_node(); // set to null node after construction + set_id(plot_node); + set_type(plot_node); + set_output_path(plot_node); + set_bg_color(plot_node); + set_basis(plot_node); + set_origin(plot_node); + set_width(plot_node); + set_universe(plot_node); + set_default_colors(plot_node); + set_user_colors(plot_node); + set_meshlines(plot_node); + set_mask(plot_node); } // End Plot constructor //============================================================================== From 29e493bcfbcb7a1daea46905344dc72156abf270 Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Mon, 29 Oct 2018 10:37:55 -0500 Subject: [PATCH 069/105] Moving some variables. --- src/plot.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/plot.cpp b/src/plot.cpp index 883824a95..afa2eade7 100644 --- a/src/plot.cpp +++ b/src/plot.cpp @@ -826,15 +826,13 @@ void draw_mesh_lines(Plot pl, ImageData &data) // Fortran/C++ index correction ijk_ur[0]++; ijk_ur[1]++; ijk_ur[2]++; - double frac; - int outrange[3], inrange[3]; double xyz_ll[3], xyz_ur[3]; // sweep through all meshbins on this plane and draw borders for (int i = ijk_ll[outer]; i <= ijk_ur[outer]; i++) { for (int j = ijk_ll[inner]; j <= ijk_ur[inner]; j++) { // check if we're in the mesh for this ijk if (i > 0 && i <= m->shape_[outer] && j >0 && j <= m->shape_[inner] ) { - + int outrange[3], inrange[3]; // get xyz's of lower left and upper right of this mesh cell xyz_ll[outer] = m->lower_left_[outer] + m->width_[outer] * (i - 1); xyz_ll[inner] = m->lower_left_[inner] + m->width_[inner] * (j - 1); @@ -842,7 +840,7 @@ void draw_mesh_lines(Plot pl, ImageData &data) xyz_ur[inner] = m->lower_left_[inner] + m->width_[inner] * j; // map the xyz ranges to pixel ranges - frac = (xyz_ll[outer] - xyz_ll_plot[outer]) / width[outer]; + double frac = (xyz_ll[outer] - xyz_ll_plot[outer]) / width[outer]; outrange[0] = int(frac * double(pl.pixels[0])); frac = (xyz_ur[outer] - xyz_ll_plot[outer]) / width[outer]; outrange[1] = int(frac * double(pl.pixels[0])); From 2aa3437cc08c64114c1797bd35b8d227eb1bfc36 Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Mon, 29 Oct 2018 15:06:27 -0500 Subject: [PATCH 070/105] More updates based on PR comments. --- include/openmc/plot.h | 6 +++--- include/openmc/xml_interface.h | 1 - src/plot.cpp | 20 +++++++++++--------- src/surface.cpp | 2 +- src/xml_interface.cpp | 1 + 5 files changed, 16 insertions(+), 14 deletions(-) diff --git a/include/openmc/plot.h b/include/openmc/plot.h index 48d486e5d..1beff9ca8 100644 --- a/include/openmc/plot.h +++ b/include/openmc/plot.h @@ -24,7 +24,7 @@ extern int PLOT_LEVEL_LOWEST; //!< lower bound on plot universe level extern std::map plot_map; //!< map of plot ids to index -extern int n_plots; //!< number of plots in openmc run +extern "C" int32_t n_plots; //!< number of plots in openmc run class Plot; extern std::vector plots; //!< Plot instance container @@ -153,11 +153,11 @@ extern "C" void read_plots(pugi::xml_node* plot_node); //! Create a ppm image for a plot object //! \param[in] plot object -extern "C" void create_ppm(Plot pl); +void create_ppm(Plot pl); //! Create an hdf5 voxel file for a plot object //! \param[in] plot object -extern "C" void create_voxel(Plot pl); +void create_voxel(Plot pl); } // namespace openmc diff --git a/include/openmc/xml_interface.h b/include/openmc/xml_interface.h index 104e6ec27..29de8839e 100644 --- a/include/openmc/xml_interface.h +++ b/include/openmc/xml_interface.h @@ -9,7 +9,6 @@ #include "pugixml.hpp" #include "xtensor/xarray.hpp" #include "xtensor/xadapt.hpp" -#include "openmc/string_functions.h" namespace openmc { diff --git a/src/plot.cpp b/src/plot.cpp index afa2eade7..ebc6c4f75 100644 --- a/src/plot.cpp +++ b/src/plot.cpp @@ -204,16 +204,17 @@ Plot::set_output_path(pugi::xml_node plot_node) if (check_for_node(plot_node, "filename")) { filename << get_node_value(plot_node, "filename"); - } else { - switch(type) { - case plot_type::slice: - filename << ".ppm"; - break; - case plot_type::voxel: - filename << ".h5"; - break; - } } + // add appropriate file extension to name + switch(type) { + case plot_type::slice: + filename << ".ppm"; + break; + case plot_type::voxel: + filename << ".h5"; + break; + } + path_plot = filename.str(); // Copy plot pixel size @@ -972,6 +973,7 @@ void create_voxel(Plot pl) // Write to HDF5 dataset voxel_write_slice(x, dspace, dset, memspace, &(data[0])); } + delete p; voxel_finalize(dspace, dset, memspace); file_close(file_id); diff --git a/src/surface.cpp b/src/surface.cpp index f535615e8..265a2f02c 100644 --- a/src/surface.cpp +++ b/src/surface.cpp @@ -8,7 +8,7 @@ #include "openmc/error.h" #include "openmc/hdf5_interface.h" #include "openmc/xml_interface.h" - +#include "openmc/string_functions.h" namespace openmc { diff --git a/src/xml_interface.cpp b/src/xml_interface.cpp index fa50eb332..93b65521c 100644 --- a/src/xml_interface.cpp +++ b/src/xml_interface.cpp @@ -3,6 +3,7 @@ #include // for transform #include +#include "openmc/string_functions.h" #include "openmc/error.h" From e09a78dabd9d327f2783bb522a8ef5978228bd2d Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Mon, 29 Oct 2018 15:28:26 -0500 Subject: [PATCH 071/105] Adding omp to pixel for loop. --- src/plot.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/plot.cpp b/src/plot.cpp index ebc6c4f75..50bfc4917 100644 --- a/src/plot.cpp +++ b/src/plot.cpp @@ -122,6 +122,8 @@ void create_ppm(Plot pl) } double dir[3] = {HALF, HALF, HALF}; +#pragma omp parallel +{ Particle *p = new Particle(); p->initialize(); std::copy(xyz, xyz+3, p->coord[0].xyz); @@ -141,8 +143,8 @@ void create_ppm(Plot pl) data[x][y][BLUE] = rgb[BLUE]; } } - - delete p; + delete p; +} // draw mesh lines if present if (pl.index_meshlines_mesh >= 0) {draw_mesh_lines(pl, data);} From 6014310f015f2c67166e8ecfb3fd377e6d1e43fa Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Mon, 29 Oct 2018 18:02:00 -0500 Subject: [PATCH 072/105] Implementation of progress bar. --- CMakeLists.txt | 1 + include/openmc/progress_bar.h | 22 ++++++++++++ src/plot.cpp | 4 +++ src/progress_bar.cpp | 52 +++++++++++++++++++++++++++ tests/regression_tests/plot/plots.xml | 2 +- 5 files changed, 80 insertions(+), 1 deletion(-) create mode 100644 include/openmc/progress_bar.h create mode 100644 src/progress_bar.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 2800f6030..fd0bbf457 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -413,6 +413,7 @@ add_library(libopenmc SHARED src/physics_mg.cpp src/plot.cpp src/position.cpp + src/progress_bar.cpp src/pugixml/pugixml_c.cpp src/random_lcg.cpp src/reaction.cpp diff --git a/include/openmc/progress_bar.h b/include/openmc/progress_bar.h new file mode 100644 index 000000000..18a3eea47 --- /dev/null +++ b/include/openmc/progress_bar.h @@ -0,0 +1,22 @@ +#ifndef OPENMC_PROGRESSBAR_H +#define OPENMC_PROGRESSBAR_H + +#include + +class ProgressBar { + +public: + // Constructor + ProgressBar(); + + void set_value(double val); + +private: + std::string bar; + char bar_old[72] = "???% | |"; + +}; + + +#endif // OPENMC_PROGRESSBAR_H + diff --git a/src/plot.cpp b/src/plot.cpp index 50bfc4917..eaa1de2b2 100644 --- a/src/plot.cpp +++ b/src/plot.cpp @@ -14,6 +14,7 @@ #include "openmc/hdf5_interface.h" #include "openmc/random_lcg.h" #include "openmc/output.h" +#include "openmc/progress_bar.h" namespace openmc { @@ -951,10 +952,13 @@ void create_voxel(Plot pl) int data[pl.pixels[1]][pl.pixels[2]]; + ProgressBar pb; + RGBColor rgb; int id; for (int x = 0; x < pl.pixels[0]; x++) { // TODO: progress bar here + pb.set_value(((double)x/(double)pl.pixels[0])*100); for (int y = 0; y < pl.pixels[1]; y++) { for (int z = 0; z < pl.pixels[2]; z++) { // get voxel color diff --git a/src/progress_bar.cpp b/src/progress_bar.cpp new file mode 100644 index 000000000..32fff626b --- /dev/null +++ b/src/progress_bar.cpp @@ -0,0 +1,52 @@ + +#include "openmc/progress_bar.h" + +#include +#include +#include + +#define BAR_WIDTH 72 + +ProgressBar::ProgressBar() { + // bar = "???% | |"; + + set_value(0.0); +} + +void +ProgressBar::set_value(double val) { + // set the bar percentage + if (val >= 100.0) { + bar.append("100"); + } else if (val <= 0.0) { + bar.append(" 0"); + } else { + std::stringstream ss; + ss << std::setfill(' ') << std::setw(3) << (int)val; + bar.append(ss.str()); + } + + bar.append("% |"); + + // remaining width of the bar + int remain = BAR_WIDTH - bar.size() - 1; + + // set the bar width + if (val >= 100.0) { + bar.append(remain, '='); + } else { + int width = (int)(65*val/100); + std::cout << "Setting width: " << width; + bar.append(width, '='); + bar.append(1, '>'); + bar.append(remain-width-1, ' '); + } + + bar.append("|"); + + // write the bar + std::cout << '\r' << bar << std::flush; + + // reset the bar value + bar = ""; //???% | |"; +} diff --git a/tests/regression_tests/plot/plots.xml b/tests/regression_tests/plot/plots.xml index ecfe69125..6651a5dfc 100644 --- a/tests/regression_tests/plot/plots.xml +++ b/tests/regression_tests/plot/plots.xml @@ -24,7 +24,7 @@ - 100 100 10 + 10000 100 10 0. 0. 0. 20 20 10 From ddbac3683bd8d5f584d4e8d20df82c1248229fd9 Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Mon, 29 Oct 2018 22:09:13 -0500 Subject: [PATCH 073/105] Removing unused code and print. --- src/progress_bar.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/progress_bar.cpp b/src/progress_bar.cpp index 32fff626b..7231b2098 100644 --- a/src/progress_bar.cpp +++ b/src/progress_bar.cpp @@ -8,8 +8,7 @@ #define BAR_WIDTH 72 ProgressBar::ProgressBar() { - // bar = "???% | |"; - + bar = ""; set_value(0.0); } @@ -36,7 +35,6 @@ ProgressBar::set_value(double val) { bar.append(remain, '='); } else { int width = (int)(65*val/100); - std::cout << "Setting width: " << width; bar.append(width, '='); bar.append(1, '>'); bar.append(remain-width-1, ' '); @@ -48,5 +46,5 @@ ProgressBar::set_value(double val) { std::cout << '\r' << bar << std::flush; // reset the bar value - bar = ""; //???% | |"; + bar = ""; } From 416ab13b14cfae108286121463baaec46aa85738 Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Mon, 29 Oct 2018 23:00:25 -0500 Subject: [PATCH 074/105] Adding check for redirect and non-terminal calls. --- src/progress_bar.cpp | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/src/progress_bar.cpp b/src/progress_bar.cpp index 7231b2098..6af9c698f 100644 --- a/src/progress_bar.cpp +++ b/src/progress_bar.cpp @@ -5,8 +5,26 @@ #include #include +#ifdef UNIX +#include +#endif + #define BAR_WIDTH 72 +#ifdef UNIX +int check_isatty(int fd) { + return isatty(fd); +} +#endif + +bool is_terminal() { +#ifdef UNIX + return check_isatty(STDOUT_FILENO) != 0; +#else + return false; +#endif +} + ProgressBar::ProgressBar() { bar = ""; set_value(0.0); @@ -14,6 +32,9 @@ ProgressBar::ProgressBar() { void ProgressBar::set_value(double val) { + + if (!is_terminal()) return; + // set the bar percentage if (val >= 100.0) { bar.append("100"); @@ -28,19 +49,19 @@ ProgressBar::set_value(double val) { bar.append("% |"); // remaining width of the bar - int remain = BAR_WIDTH - bar.size() - 1; + int remain = BAR_WIDTH - bar.size() - 2; // set the bar width if (val >= 100.0) { bar.append(remain, '='); } else { - int width = (int)(65*val/100); + int width = (int)((double)remain*val/100); bar.append(width, '='); bar.append(1, '>'); bar.append(remain-width-1, ' '); } - bar.append("|"); + bar.append("|+"); // write the bar std::cout << '\r' << bar << std::flush; From d5d655383f2c72700ee058193ededd5c77e61c56 Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Tue, 30 Oct 2018 09:05:28 -0500 Subject: [PATCH 075/105] Reverting plots file... --- tests/regression_tests/plot/plots.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/regression_tests/plot/plots.xml b/tests/regression_tests/plot/plots.xml index 6651a5dfc..ecfe69125 100644 --- a/tests/regression_tests/plot/plots.xml +++ b/tests/regression_tests/plot/plots.xml @@ -24,7 +24,7 @@ - 10000 100 10 + 100 100 10 0. 0. 0. 20 20 10 From c05a3e455bbb8f12445bfe18b9e1528b87011b98 Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Tue, 30 Oct 2018 10:47:18 -0500 Subject: [PATCH 076/105] Removing particle pointers. Updating omp block. --- include/openmc/plot.h | 3 +- src/plot.cpp | 72 +++++++++++++++++++++---------------------- 2 files changed, 37 insertions(+), 38 deletions(-) diff --git a/include/openmc/plot.h b/include/openmc/plot.h index 1beff9ca8..c66e74620 100644 --- a/include/openmc/plot.h +++ b/include/openmc/plot.h @@ -118,8 +118,7 @@ void output_ppm(Plot pl, //! \param[in] plot object //! \param[out] rgb color //! \param[out] cell or material id for particle position -void position_rgb(Particle* p, Plot pl, RGBColor &rgb, int &id); - +void position_rgb(Particle p, Plot pl, RGBColor &rgb, int &id); //! Initialize a voxel file //! \param[in] id of an open hdf5 file diff --git a/src/plot.cpp b/src/plot.cpp index eaa1de2b2..f9266b6f2 100644 --- a/src/plot.cpp +++ b/src/plot.cpp @@ -123,30 +123,30 @@ void create_ppm(Plot pl) } double dir[3] = {HALF, HALF, HALF}; + #pragma omp parallel { - Particle *p = new Particle(); - p->initialize(); - std::copy(xyz, xyz+3, p->coord[0].xyz); - std::copy(dir, dir+3, p->coord[0].uvw); - p->coord[0].universe = openmc_root_universe; + Particle p; + p.initialize(); + std::copy(xyz, xyz+3, p.coord[0].xyz); + std::copy(dir, dir+3, p.coord[0].uvw); + p.coord[0].universe = openmc_root_universe; - // local variables - RGBColor rgb; - int id; +#pragma omp for for (int y = 0; y < height; y++) { - p->coord[0].xyz[out_i] = xyz[out_i] - out_pixel * y; + p.coord[0].xyz[out_i] = xyz[out_i] - out_pixel * y; for (int x = 0; x < width; x++) { - p->coord[0].xyz[in_i] = xyz[in_i] + in_pixel * x; + // local variables + RGBColor rgb; + int id; + p.coord[0].xyz[in_i] = xyz[in_i] + in_pixel * x; position_rgb(p, pl, rgb, id); data[x][y][RED] = rgb[RED]; data[x][y][GREEN] = rgb[GREEN]; data[x][y][BLUE] = rgb[BLUE]; } } - delete p; } - // draw mesh lines if present if (pl.index_meshlines_mesh >= 0) {draw_mesh_lines(pl, data);} @@ -698,15 +698,16 @@ index_meshlines_mesh(-1) // current particle's position //============================================================================== -void position_rgb(Particle* p, Plot pl, RGBColor &rgb, int &id) + +void position_rgb(Particle p, Plot pl, RGBColor &rgb, int &id) { - p->n_coord = 1; + p.n_coord = 1; - bool found_cell = find_cell(p, 0); + bool found_cell = find_cell(&p, 0); - int j = p->n_coord - 1; + int j = p.n_coord - 1; - if (settings::check_overlaps) {check_cell_overlap(p);} + if (settings::check_overlaps) {check_cell_overlap(&p);} // Set coordinate level if specified if (pl.level >= 0) {j = pl.level + 1;} @@ -718,24 +719,24 @@ void position_rgb(Particle* p, Plot pl, RGBColor &rgb, int &id) } else { if (plot_color_by::mats == pl.color_by) { // Assign color based on material - Cell* c = cells[p->coord[j].cell]; + Cell* c = cells[p.coord[j].cell]; if (c->type_ == FILL_UNIVERSE) { // If we stopped on a middle universe level, treat as if not found rgb = pl.not_found; id = -1; - } else if (p->material == MATERIAL_VOID) { + } else if (p.material == MATERIAL_VOID) { // By default, color void cells white rgb = WHITE; id = -1; } else { - rgb = pl.colors[p->material - 1]; - id = materials[p->material - 1]->id_; + rgb = pl.colors[p.material - 1]; + id = materials[p.material - 1]->id_; } } else if (plot_color_by::cells == pl.color_by) { // Assign color based on cell - rgb = pl.colors[p->coord[j].cell]; - id = cells[p->coord[j].cell]->id_; + rgb = pl.colors[p.coord[j].cell]; + id = cells[p.coord[j].cell]->id_; } else { rgb = NULLRGB; id = -1; @@ -908,11 +909,11 @@ void create_voxel(Plot pl) // allocate and initialize particle double dir[3] = {HALF, HALF, HALF}; - Particle *p = new Particle(); - p->initialize(); - std::copy(ll, ll + 3, p->coord[0].xyz); - std::copy(dir, dir + 3, p->coord[0].uvw); - p->coord[0].universe = openmc_root_universe; + Particle p; + p.initialize(); + std::copy(ll, ll + 3, p.coord[0].xyz); + std::copy(dir, dir + 3, p.coord[0].uvw); + p.coord[0].universe = openmc_root_universe; // Open binary plot file for writing std::ofstream of; @@ -953,7 +954,7 @@ void create_voxel(Plot pl) int data[pl.pixels[1]][pl.pixels[2]]; ProgressBar pb; - + RGBColor rgb; int id; for (int x = 0; x < pl.pixels[0]; x++) { @@ -966,20 +967,19 @@ void create_voxel(Plot pl) // write to plot data data[y][z] = id; // advance particle in z direction - p->coord[0].xyz[2] = p->coord[0].xyz[2] + vox[2]; + p.coord[0].xyz[2] = p.coord[0].xyz[2] + vox[2]; } // advance particle in y direction - p->coord[0].xyz[1] = p->coord[0].xyz[1] + vox[1]; - p->coord[0].xyz[2] = ll[2]; + p.coord[0].xyz[1] = p.coord[0].xyz[1] + vox[1]; + p.coord[0].xyz[2] = ll[2]; } // advance particle in x direction - p->coord[0].xyz[0] = p->coord[0].xyz[0] + vox[0]; - p->coord[0].xyz[1] = ll[1]; - p->coord[0].xyz[2] = ll[2]; + p.coord[0].xyz[0] = p.coord[0].xyz[0] + vox[0]; + p.coord[0].xyz[1] = ll[1]; + p.coord[0].xyz[2] = ll[2]; // Write to HDF5 dataset voxel_write_slice(x, dspace, dset, memspace, &(data[0])); } - delete p; voxel_finalize(dspace, dset, memspace); file_close(file_id); From bc9668480df81b7062c553b5bfbfddd6af54b7eb Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Tue, 30 Oct 2018 10:51:38 -0500 Subject: [PATCH 077/105] Removing constants. --- include/openmc/constants.h | 3 --- src/plot.cpp | 40 +++++++++++++++++++------------------- 2 files changed, 20 insertions(+), 23 deletions(-) diff --git a/include/openmc/constants.h b/include/openmc/constants.h index bfd4960f7..d249e4cb5 100644 --- a/include/openmc/constants.h +++ b/include/openmc/constants.h @@ -82,9 +82,6 @@ constexpr double EXTSRC_REJECT_FRACTION {0.05}; constexpr double PI {3.1415926535898}; const double SQRT_PI {std::sqrt(PI)}; constexpr double INFTY {std::numeric_limits::max()}; -constexpr double ONE {1.0}; -constexpr double TWO {2.0}; -constexpr double HALF {0.5}; // Physical constants constexpr double MASS_NEUTRON {1.00866491588}; // mass of a neutron in amu diff --git a/src/plot.cpp b/src/plot.cpp index f9266b6f2..4be131098 100644 --- a/src/plot.cpp +++ b/src/plot.cpp @@ -102,27 +102,27 @@ void create_ppm(Plot pl) case plot_basis::xy : in_i = 0; out_i = 1; - xyz[0] = pl.origin[0] - pl.width[0] / TWO; - xyz[1] = pl.origin[1] + pl.width[1] / TWO; + xyz[0] = pl.origin[0] - pl.width[0] / 2.; + xyz[1] = pl.origin[1] + pl.width[1] / 2.; xyz[2] = pl.origin[2]; break; case plot_basis::xz : in_i = 0; out_i = 2; - xyz[0] = pl.origin[0] - pl.width[0] / TWO; + xyz[0] = pl.origin[0] - pl.width[0] / 2.; xyz[1] = pl.origin[1]; - xyz[2] = pl.origin[2] + pl.width[1] / TWO; + xyz[2] = pl.origin[2] + pl.width[1] / 2.; break; case plot_basis::yz : in_i = 1; out_i = 2; xyz[0] = pl.origin[0]; - xyz[1] = pl.origin[1] - pl.width[0] / TWO; - xyz[2] = pl.origin[2] + pl.width[1] / TWO; + xyz[1] = pl.origin[1] - pl.width[0] / 2.; + xyz[2] = pl.origin[2] + pl.width[1] / 2.; break; } - double dir[3] = {HALF, HALF, HALF}; + double dir[3] = {0.5, 0.5, 0.5}; #pragma omp parallel { @@ -811,10 +811,10 @@ void draw_mesh_lines(Plot pl, ImageData &data) std::copy((double*)&pl.origin, (double*)&pl.origin + 3, xyz_ll_plot); std::copy((double*)&pl.origin, (double*)&pl.origin + 3, xyz_ur_plot); - xyz_ll_plot[outer] = pl.origin[outer] - pl.width[0] / TWO; - xyz_ll_plot[inner] = pl.origin[inner] - pl.width[1] / TWO; - xyz_ur_plot[outer] = pl.origin[outer] + pl.width[0] / TWO; - xyz_ur_plot[inner] = pl.origin[inner] + pl.width[1] / TWO; + xyz_ll_plot[outer] = pl.origin[outer] - pl.width[0] / 2.; + xyz_ll_plot[inner] = pl.origin[inner] - pl.width[1] / 2.; + xyz_ur_plot[outer] = pl.origin[outer] + pl.width[0] / 2.; + xyz_ur_plot[inner] = pl.origin[inner] + pl.width[1] / 2.; int width[3]; width[0] = xyz_ur_plot[0] - xyz_ll_plot[0]; @@ -851,9 +851,9 @@ void draw_mesh_lines(Plot pl, ImageData &data) outrange[1] = int(frac * double(pl.pixels[0])); frac = (xyz_ur[inner] - xyz_ll_plot[inner]) / width[inner]; - inrange[0] = int((ONE - frac) * (double)pl.pixels[1]); + inrange[0] = int((1. - frac) * (double)pl.pixels[1]); frac = (xyz_ll[inner] - xyz_ll_plot[inner]) / width[inner]; - inrange[1] = int((ONE - frac) * (double)pl.pixels[1]); + inrange[1] = int((1. - frac) * (double)pl.pixels[1]); // draw lines for (int out_ = outrange[0]; out_ <= outrange[1]; out_++) { @@ -903,12 +903,12 @@ void create_voxel(Plot pl) // initial particle position double ll[3]; - ll[0] = pl.origin[0] - pl.width[0] / TWO; - ll[1] = pl.origin[1] - pl.width[1] / TWO; - ll[2] = pl.origin[2] - pl.width[2] / TWO; + ll[0] = pl.origin[0] - pl.width[0] / 2.; + ll[1] = pl.origin[1] - pl.width[1] / 2.; + ll[2] = pl.origin[2] - pl.width[2] / 2.; // allocate and initialize particle - double dir[3] = {HALF, HALF, HALF}; + double dir[3] = {0.5, 0.5, 0.5}; Particle p; p.initialize(); std::copy(ll, ll + 3, p.coord[0].xyz); @@ -947,9 +947,9 @@ void create_voxel(Plot pl) voxel_init(file_id, &(dims[0]), &dspace, &dset, &memspace); // move to center of voxels - ll[0] = ll[0] + vox[0] / TWO; - ll[1] = ll[1] + vox[1] / TWO; - ll[2] = ll[2] + vox[2] / TWO; + ll[0] = ll[0] + vox[0] / 2.; + ll[1] = ll[1] + vox[1] / 2.; + ll[2] = ll[2] + vox[2] / 2.; int data[pl.pixels[1]][pl.pixels[2]]; From 3935aed6bf78b3eb51291e196829c9de2d8db034 Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Tue, 30 Oct 2018 11:13:03 -0500 Subject: [PATCH 078/105] Moving ImageData to an xtensor structure. --- include/openmc/plot.h | 4 +++- src/plot.cpp | 33 +++++++++++++++------------------ 2 files changed, 18 insertions(+), 19 deletions(-) diff --git a/include/openmc/plot.h b/include/openmc/plot.h index c66e74620..3cd81d5b4 100644 --- a/include/openmc/plot.h +++ b/include/openmc/plot.h @@ -4,6 +4,8 @@ #include #include +#include "xtensor/xarray.hpp" + #include "hdf5.h" #include "openmc/position.h" #include "openmc/constants.h" @@ -35,7 +37,7 @@ extern std::vector plots; //!< Plot instance container typedef std::array RGBColor; -typedef std::vector> ImageData; +typedef xt::xtensor ImageData; enum class plot_type { slice = 1, diff --git a/src/plot.cpp b/src/plot.cpp index 4be131098..489542fac 100644 --- a/src/plot.cpp +++ b/src/plot.cpp @@ -84,17 +84,14 @@ read_plots(pugi::xml_node* plots_node) void create_ppm(Plot pl) { - int width = pl.pixels[0]; - int height = pl.pixels[1]; + size_t width = pl.pixels[0]; + size_t height = pl.pixels[1]; double in_pixel = (pl.width[0])/double(width); double out_pixel = (pl.width[1])/double(height); ImageData data; - data.resize(width); - for (auto & i : data) { - i.resize(height); - } + data.resize({width, height}); int in_i, out_i; double xyz[3]; @@ -141,9 +138,9 @@ void create_ppm(Plot pl) int id; p.coord[0].xyz[in_i] = xyz[in_i] + in_pixel * x; position_rgb(p, pl, rgb, id); - data[x][y][RED] = rgb[RED]; - data[x][y][GREEN] = rgb[GREEN]; - data[x][y][BLUE] = rgb[BLUE]; + data(x,y)[RED] = rgb[RED]; + data(x,y)[GREEN] = rgb[GREEN]; + data(x,y)[BLUE] = rgb[BLUE]; } } } @@ -768,7 +765,7 @@ void output_ppm(Plot pl, const ImageData &data) // Write color for each pixel for (int y = 0; y < pl.pixels[1]; y++) { for (int x = 0; x < pl.pixels[0]; x++) { - RGBColor rgb = data[x][y]; + RGBColor rgb = data(x,y); of.write((char*)&rgb[RED], 1); of.write((char*)&rgb[GREEN], 1); of.write((char*)&rgb[BLUE], 1); @@ -858,19 +855,19 @@ void draw_mesh_lines(Plot pl, ImageData &data) // draw lines for (int out_ = outrange[0]; out_ <= outrange[1]; out_++) { for (int plus = 0; plus <= pl.meshlines_width; plus++) { - data[out_][inrange[0] + plus] = rgb; - data[out_][inrange[1] + plus] = rgb; - data[out_][inrange[0] - plus] = rgb; - data[out_][inrange[1] - plus] = rgb; + data(out_, inrange[0] + plus) = rgb; + data(out_, inrange[1] + plus) = rgb; + data(out_, inrange[0] - plus) = rgb; + data(out_, inrange[1] - plus) = rgb; } } for (int in_ = inrange[0]; in_ <= inrange[1]; in_++) { for (int plus = 0; plus <= pl.meshlines_width; plus++) { - data[outrange[0] + plus][in_] = rgb; - data[outrange[1] + plus][in_] = rgb; - data[outrange[0] - plus][in_] = rgb; - data[outrange[1] - plus][in_] = rgb; + data(outrange[0] + plus, in_) = rgb; + data(outrange[1] + plus, in_) = rgb; + data(outrange[0] - plus, in_) = rgb; + data(outrange[1] - plus, in_) = rgb; } } From e793472b15b9e4aba108ba951e48a1b10fdace15 Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Tue, 30 Oct 2018 12:45:06 -0500 Subject: [PATCH 079/105] Adjusting value for progress bar in plots. --- src/plot.cpp | 2 +- src/progress_bar.cpp | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/plot.cpp b/src/plot.cpp index 489542fac..ab8db4e00 100644 --- a/src/plot.cpp +++ b/src/plot.cpp @@ -956,7 +956,7 @@ void create_voxel(Plot pl) int id; for (int x = 0; x < pl.pixels[0]; x++) { // TODO: progress bar here - pb.set_value(((double)x/(double)pl.pixels[0])*100); + pb.set_value(100.*(double)x/(double)(pl.pixels[0]-1)); for (int y = 0; y < pl.pixels[1]; y++) { for (int z = 0; z < pl.pixels[2]; z++) { // get voxel color diff --git a/src/progress_bar.cpp b/src/progress_bar.cpp index 6af9c698f..444dfa5ed 100644 --- a/src/progress_bar.cpp +++ b/src/progress_bar.cpp @@ -27,6 +27,7 @@ bool is_terminal() { ProgressBar::ProgressBar() { bar = ""; + // initialize bar set_value(0.0); } From a6830c9ca55864488cec6213c82c06bb3c3e4687 Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Tue, 30 Oct 2018 19:41:30 -0500 Subject: [PATCH 080/105] Further changes based on PR comments. --- include/openmc/output.h | 3 ++- include/openmc/plot.h | 4 ++-- src/plot.cpp | 2 +- src/progress_bar.cpp | 11 ++++++----- 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/include/openmc/output.h b/include/openmc/output.h index 6207e2eda..6d6d6ba0f 100644 --- a/include/openmc/output.h +++ b/include/openmc/output.h @@ -19,8 +19,9 @@ void header(const char* msg, int level); //============================================================================== -//! Retrieve a time stamp with the format "yyyy-mm-dd hh:mm:ss" +//! Retrieve a time stamp //! +//! \return current time stamp (format: "yyyy-mm-dd hh:mm:ss") //============================================================================== std::string time_stamp(); diff --git a/include/openmc/plot.h b/include/openmc/plot.h index 3cd81d5b4..8b5e6c19a 100644 --- a/include/openmc/plot.h +++ b/include/openmc/plot.h @@ -1,7 +1,7 @@ #ifndef OPENMC_PLOT_H #define OPENMC_PLOT_H -#include +#include #include #include "xtensor/xarray.hpp" @@ -24,7 +24,7 @@ constexpr int BLUE = 2; extern int PLOT_LEVEL_LOWEST; //!< lower bound on plot universe level -extern std::map plot_map; //!< map of plot ids to index +extern std::unordered_map plot_map; //!< map of plot ids to index extern "C" int32_t n_plots; //!< number of plots in openmc run diff --git a/src/plot.cpp b/src/plot.cpp index ab8db4e00..ae14ea9df 100644 --- a/src/plot.cpp +++ b/src/plot.cpp @@ -24,7 +24,7 @@ namespace openmc { int PLOT_LEVEL_LOWEST = -1; -std::map plot_map; +std::unordered_map plot_map; int n_plots; diff --git a/src/progress_bar.cpp b/src/progress_bar.cpp index 444dfa5ed..f412793c9 100644 --- a/src/progress_bar.cpp +++ b/src/progress_bar.cpp @@ -48,18 +48,19 @@ ProgressBar::set_value(double val) { } bar.append("% |"); - // remaining width of the bar - int remain = BAR_WIDTH - bar.size() - 2; + int remaining_width = BAR_WIDTH - bar.size() - 2; // set the bar width if (val >= 100.0) { - bar.append(remain, '='); + bar.append(remaining_width, '='); + } else if (val < 0.0) { + bar.append(remaining_width, ' '); } else { - int width = (int)((double)remain*val/100); + int width = (int)((double)remaining_width*val/100); bar.append(width, '='); bar.append(1, '>'); - bar.append(remain-width-1, ' '); + bar.append(remaining_width-width-1, ' '); } bar.append("|+"); From 1a7abf8147f2accf6bdd92f0fbdf42e7787d1dff Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Tue, 30 Oct 2018 19:58:34 -0500 Subject: [PATCH 081/105] Updating Plot class member names. --- include/openmc/plot.h | 28 ++-- src/output.cpp | 50 +++--- src/plot.cpp | 356 +++++++++++++++++++++--------------------- 3 files changed, 217 insertions(+), 217 deletions(-) diff --git a/include/openmc/plot.h b/include/openmc/plot.h index 8b5e6c19a..0ec07074b 100644 --- a/include/openmc/plot.h +++ b/include/openmc/plot.h @@ -83,20 +83,20 @@ private: // Members public: - int id; //!< Plot ID - plot_type type; //!< Plot type (Slice/Voxel) - plot_color_by color_by; //!< Plot coloring (cell/material) - Position origin; //!< Plot origin in geometry - Position width; //!< Plot width in geometry - plot_basis basis; //!< Plot basis (XY/XZ/YZ) - int pixels[3]; //!< Plot size in pixels - int meshlines_width; //!< Width of lines added to the plot - int level; //!< Plot universe level - int index_meshlines_mesh; //!< Index of the mesh to draw on the plot - RGBColor meshlines_color; //!< Color of meshlines on the plot - RGBColor not_found; //!< Plot background color - std::vector colors; //!< Plot colors - std::string path_plot; //!< Plot output filename + int id_; //!< Plot ID + plot_type type_; //!< Plot type (Slice/Voxel) + plot_color_by color_by_; //!< Plot coloring (cell/material) + Position origin_; //!< Plot origin in geometry + Position width_; //!< Plot width in geometry + plot_basis basis_; //!< Plot basis (XY/XZ/YZ) + int pixels_[3]; //!< Plot size in pixels + int meshlines_width_; //!< Width of lines added to the plot + int level_; //!< Plot universe level + int index_meshlines_mesh_; //!< Index of the mesh to draw on the plot + RGBColor meshlines_color_; //!< Color of meshlines on the plot + RGBColor not_found_; //!< Plot background color + std::vector colors_; //!< Plot colors + std::string path_plot_; //!< Plot output filename }; //=============================================================================== diff --git a/src/output.cpp b/src/output.cpp index e9c3f567f..10e5a0765 100644 --- a/src/output.cpp +++ b/src/output.cpp @@ -64,45 +64,45 @@ void print_plot() { for (auto pl : plots) { // Plot id - std::cout << "Plot ID: " << pl.id << std::endl; + std::cout << "Plot ID: " << pl.id_ << std::endl; // Plot filename - std::cout << "Plot file: " << pl.path_plot << std::endl; + std::cout << "Plot file: " << pl.path_plot_ << std::endl; // Plot level - std::cout << "Universe depth: " << pl.level << std::endl; + std::cout << "Universe depth: " << pl.level_ << std::endl; // Plot type - if (plot_type::slice == pl.type) { + if (plot_type::slice == pl.type_) { std::cout << "Plot Type: Slice" << std::endl; - } else if (plot_type::voxel == pl.type) { + } else if (plot_type::voxel == pl.type_) { std::cout << "Plot Type: Voxel" << std::endl; } // Plot parameters - std::cout << "Origin: " << pl.origin[0] << " " - << pl.origin[1] << " " - << pl.origin[2] << std::endl; + std::cout << "Origin: " << pl.origin_[0] << " " + << pl.origin_[1] << " " + << pl.origin_[2] << std::endl; - if (plot_type::slice == pl.type) { + if (plot_type::slice == pl.type_) { std::cout << std::setprecision(4) << "Width: " - << pl.width[0] << " " - << pl.width[1] << std::endl; - } else if (plot_type::voxel == pl.type) { + << pl.width_[0] << " " + << pl.width_[1] << std::endl; + } else if (plot_type::voxel == pl.type_) { std::cout << std::setprecision(4) << "Width: " - << pl.width[0] << " " - << pl.width[1] << " " - << pl.width[2] << std::endl; + << pl.width_[0] << " " + << pl.width_[1] << " " + << pl.width_[2] << std::endl; } - if (plot_color_by::cells == pl.color_by) { + if (plot_color_by::cells == pl.color_by_) { std::cout << "Coloring: Cells" << std::endl; - } else if (plot_color_by::mats == pl.color_by) { + } else if (plot_color_by::mats == pl.color_by_) { std::cout << "Coloring: Materials" << std::endl; } - if (plot_type::slice == pl.type) { - switch(pl.basis) { + if (plot_type::slice == pl.type_) { + switch(pl.basis_) { case plot_basis::xy: std::cout << "Basis: XY" << std::endl; break; @@ -113,12 +113,12 @@ void print_plot() { std::cout << "Basis: YZ" << std::endl; break; } - std::cout << "Pixels: " << pl.pixels[0] << " " - << pl.pixels[1] << " " << std::endl; - } else if (plot_type::voxel == pl.type) { - std::cout << "Voxels: " << pl.pixels[0] << " " - << pl.pixels[1] << " " - << pl.pixels[2] << std::endl; + std::cout << "Pixels: " << pl.pixels_[0] << " " + << pl.pixels_[1] << " " << std::endl; + } else if (plot_type::voxel == pl.type_) { + std::cout << "Voxels: " << pl.pixels_[0] << " " + << pl.pixels_[1] << " " + << pl.pixels_[2] << std::endl; } std::cout << std::endl; diff --git a/src/plot.cpp b/src/plot.cpp index ae14ea9df..17f67f1f9 100644 --- a/src/plot.cpp +++ b/src/plot.cpp @@ -44,14 +44,14 @@ int openmc_plot_geometry() for (auto pl : plots) { std::stringstream ss; - ss << "Processing plot " << pl.id << ": " - << pl.path_plot << "..."; + ss << "Processing plot " << pl.id_ << ": " + << pl.path_plot_ << "..."; write_message(ss.str(), 5); - if (plot_type::slice == pl.type) { + if (plot_type::slice == pl.type_) { // create 2D image create_ppm(pl); - } else if (plot_type::voxel == pl.type) { + } else if (plot_type::voxel == pl.type_) { // create voxel file for 3D viewing create_voxel(pl); } @@ -72,7 +72,7 @@ read_plots(pugi::xml_node* plots_node) for (int i = 0; i < plot_nodes.size(); i++) { Plot pl(plot_nodes[i]); plots.push_back(pl); - plot_map[pl.id] = i; + plot_map[pl.id_] = i; } } @@ -84,38 +84,38 @@ read_plots(pugi::xml_node* plots_node) void create_ppm(Plot pl) { - size_t width = pl.pixels[0]; - size_t height = pl.pixels[1]; + size_t width = pl.pixels_[0]; + size_t height = pl.pixels_[1]; - double in_pixel = (pl.width[0])/double(width); - double out_pixel = (pl.width[1])/double(height); + double in_pixel = (pl.width_[0])/double(width); + double out_pixel = (pl.width_[1])/double(height); ImageData data; data.resize({width, height}); int in_i, out_i; double xyz[3]; - switch(pl.basis) { + switch(pl.basis_) { case plot_basis::xy : in_i = 0; out_i = 1; - xyz[0] = pl.origin[0] - pl.width[0] / 2.; - xyz[1] = pl.origin[1] + pl.width[1] / 2.; - xyz[2] = pl.origin[2]; + xyz[0] = pl.origin_[0] - pl.width_[0] / 2.; + xyz[1] = pl.origin_[1] + pl.width_[1] / 2.; + xyz[2] = pl.origin_[2]; break; case plot_basis::xz : in_i = 0; out_i = 2; - xyz[0] = pl.origin[0] - pl.width[0] / 2.; - xyz[1] = pl.origin[1]; - xyz[2] = pl.origin[2] + pl.width[1] / 2.; + xyz[0] = pl.origin_[0] - pl.width_[0] / 2.; + xyz[1] = pl.origin_[1]; + xyz[2] = pl.origin_[2] + pl.width_[1] / 2.; break; case plot_basis::yz : in_i = 1; out_i = 2; - xyz[0] = pl.origin[0]; - xyz[1] = pl.origin[1] - pl.width[0] / 2.; - xyz[2] = pl.origin[2] + pl.width[1] / 2.; + xyz[0] = pl.origin_[0]; + xyz[1] = pl.origin_[1] - pl.width_[0] / 2.; + xyz[2] = pl.origin_[2] + pl.width_[1] / 2.; break; } @@ -145,7 +145,7 @@ void create_ppm(Plot pl) } } // draw mesh lines if present - if (pl.index_meshlines_mesh >= 0) {draw_mesh_lines(pl, data);} + if (pl.index_meshlines_mesh_ >= 0) {draw_mesh_lines(pl, data);} // write ppm data to file output_ppm(pl, data); @@ -156,15 +156,15 @@ Plot::set_id(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")); + 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_map.find(id) != plot_map.end()) { + if (plot_map.find(id_) != plot_map.end()) { std::stringstream err_msg; - err_msg << "Two or more plots use the same unique ID: " << id; + err_msg << "Two or more plots use the same unique ID: " << id_; fatal_error(err_msg.str()); } } @@ -174,23 +174,23 @@ Plot::set_type(pugi::xml_node plot_node) { // Copy plot type // Default is slice - type = plot_type::slice; + type_ = plot_type::slice; // check type specified on plot node if (check_for_node(plot_node, "type")) { std::string type_str = get_node_value(plot_node, "type", true); // set type using node value if (type_str == "slice") { - type = plot_type::slice; + type_ = plot_type::slice; return; } else if (type_str == "voxel") { - type = plot_type::voxel; + type_ = plot_type::voxel; return; } // if we're here, something is wrong std::stringstream err_msg; err_msg << "Unsupported plot type '" << type_str - << "' in plot " << id; + << "' in plot " << id_; fatal_error(err_msg.str()); } } @@ -200,13 +200,13 @@ Plot::set_output_path(pugi::xml_node plot_node) { // Set output file path std::stringstream filename; - filename << "plot_" << id; + filename << "plot_" << id_; if (check_for_node(plot_node, "filename")) { filename << get_node_value(plot_node, "filename"); } // add appropriate file extension to name - switch(type) { + switch(type_) { case plot_type::slice: filename << ".ppm"; break; @@ -215,31 +215,31 @@ Plot::set_output_path(pugi::xml_node plot_node) break; } - path_plot = filename.str(); + path_plot_ = filename.str(); // Copy plot pixel size std::vector pxls; - if (plot_type::slice == type) { + 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]; + pixels_[0] = pxls[0]; + pixels_[1] = pxls[1]; } else { std::stringstream err_msg; err_msg << " must be length 2 in slice plot " - << id; + << id_; fatal_error(err_msg.str()); } - } else if (plot_type::voxel == type) { + } 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]; + 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; + << id_; fatal_error(err_msg.str()); } } @@ -251,30 +251,30 @@ Plot::set_bg_color(pugi::xml_node plot_node) // Copy plot background color std::vector bg_rgb; if (check_for_node(plot_node, "background")) { - if (plot_type::voxel == type) { + if (plot_type::voxel == type_) { if (openmc_master) { std::stringstream err_msg; err_msg << "Background color ignored in voxel plot " - << id; + << id_; warning(err_msg.str()); } } if (node_word_count(plot_node, "background") == 3) { bg_rgb = get_node_array(plot_node, "background"); - not_found[RED] = bg_rgb[RED]; - not_found[GREEN] = bg_rgb[GREEN]; - not_found[BLUE] = bg_rgb[BLUE]; + not_found_[RED] = bg_rgb[RED]; + not_found_[GREEN] = bg_rgb[GREEN]; + not_found_[BLUE] = bg_rgb[BLUE]; } else { std::stringstream err_msg; err_msg << "Bad background RGB in plot " - << id; + << id_; fatal_error(err_msg); } } else { // default to a white background - not_found[RED] = 255; - not_found[GREEN] = 255; - not_found[BLUE] = 255; + not_found_[RED] = 255; + not_found_[GREEN] = 255; + not_found_[BLUE] = 255; } } @@ -282,21 +282,21 @@ void Plot::set_basis(pugi::xml_node plot_node) { // Copy plot basis - if (plot_type::slice == type) { + 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", true); } if ("xy" == pl_basis) { - basis = plot_basis::xy; + basis_ = plot_basis::xy; } else if ("xz" == pl_basis) { - basis = plot_basis::xz; + basis_ = plot_basis::xz; } else if ("yz" == pl_basis) { - basis = plot_basis::yz; + basis_ = plot_basis::yz; } else { std::stringstream err_msg; err_msg << "Unsupported plot basis '" << pl_basis - << "' in plot " << id; + << "' in plot " << id_; fatal_error(err_msg); } } @@ -309,13 +309,13 @@ Plot::set_origin(pugi::xml_node plot_node) 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]; + 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; + << id_; fatal_error(err_msg); } } @@ -325,27 +325,27 @@ Plot::set_width(pugi::xml_node plot_node) { // Copy plotting width std::vector pl_width; - if (plot_type::slice == type) { + 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]; + 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; + << id_; fatal_error(err_msg); } - } else if (plot_type::voxel == type) { + } 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]; + 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; + << id_; fatal_error(err_msg); } } @@ -356,14 +356,14 @@ Plot::set_universe(pugi::xml_node plot_node) { // Copy plot universe level if (check_for_node(plot_node, "level")) { - level = std::stoi(get_node_value(plot_node, "level")); - if (level < 0) { + level_ = std::stoi(get_node_value(plot_node, "level")); + if (level_ < 0) { std::stringstream err_msg; - err_msg << "Bad universe level in plot " << id ; + err_msg << "Bad universe level in plot " << id_; fatal_error(err_msg); } } else { - level = PLOT_LEVEL_LOWEST; + level_ = PLOT_LEVEL_LOWEST; } } @@ -376,26 +376,26 @@ Plot::set_default_colors(pugi::xml_node plot_node) pl_color_by = get_node_value(plot_node, "color_by", true); } if ("cell" == pl_color_by) { - color_by = plot_color_by::cells; - colors.resize(n_cells); + color_by_ = plot_color_by::cells; + colors_.resize(n_cells); for (int i = 0; i < n_cells; i++) { - colors[i][RED] = int(prn()*255); - colors[i][GREEN] = int(prn()*255); - colors[i][BLUE] = int(prn()*255); + colors_[i][RED] = int(prn()*255); + colors_[i][GREEN] = int(prn()*255); + colors_[i][BLUE] = int(prn()*255); } } else if("material" == pl_color_by) { - color_by = plot_color_by::mats; - colors.resize(n_materials); + color_by_ = plot_color_by::mats; + colors_.resize(n_materials); for (int i = 0; i < materials.size(); i++) { - colors[i][RED] = int(prn()*255); - colors[i][GREEN] = int(prn()*255); - colors[i][BLUE] = int(prn()*255); + colors_[i][RED] = int(prn()*255); + colors_[i][GREEN] = int(prn()*255); + colors_[i][BLUE] = int(prn()*255); } } else { std::stringstream err_msg; err_msg << "Unsupported plot color type '" << pl_color_by - << "' in plot " << id; + << "' in plot " << id_; fatal_error(err_msg); } } @@ -410,11 +410,11 @@ Plot::set_user_colors(pugi::xml_node plot_node) // Copy user-specified colors if (color_nodes.size() != 0) { - if (plot_type::voxel == type) { + if (plot_type::voxel == type_) { if (openmc_master) { std::stringstream err_msg; err_msg << "Color specifications ignored in voxel plot " - << id; + << id_; warning(err_msg); } } @@ -423,7 +423,7 @@ Plot::set_user_colors(pugi::xml_node plot_node) // Check and make sure 3 values are specified for RGB if (node_word_count(cn, "rgb") != 3) { std::stringstream err_msg; - err_msg << "Bad RGB in plot " << id; + err_msg << "Bad RGB in plot " << id_; fatal_error(err_msg); } // Ensure that there is an id for this color specification @@ -433,36 +433,36 @@ Plot::set_user_colors(pugi::xml_node plot_node) } else { std::stringstream err_msg; err_msg << "Must specify id for color specification in plot " - << id; + << id_; fatal_error(err_msg); } // Add RGB - if (plot_color_by::cells == color_by) { + if (plot_color_by::cells == color_by_) { std::vector cell_rgb; if (cell_map.find(col_id) != cell_map.end()) { col_id = cell_map[col_id]; cell_rgb = get_node_array(cn, "rgb"); - colors[col_id][RED] = cell_rgb[RED]; - colors[col_id][GREEN] = cell_rgb[GREEN]; - colors[col_id][BLUE] = cell_rgb[BLUE]; + colors_[col_id][RED] = cell_rgb[RED]; + colors_[col_id][GREEN] = cell_rgb[GREEN]; + colors_[col_id][BLUE] = cell_rgb[BLUE]; } else { std::stringstream err_msg; err_msg << "Could not find cell " << col_id - << " specified in plot " << id; + << " specified in plot " << id_; fatal_error(err_msg); } - } else if (plot_color_by::mats == color_by) { + } else if (plot_color_by::mats == color_by_) { std::vector mat_rgb; if (material_map.find(col_id) != material_map.end()) { col_id = material_map[col_id]; mat_rgb = get_node_array(cn, "rgb"); - colors[col_id][RED] = mat_rgb[RED]; - colors[col_id][GREEN] = mat_rgb[GREEN]; - colors[col_id][BLUE] = mat_rgb[BLUE]; + colors_[col_id][RED] = mat_rgb[RED]; + colors_[col_id][GREEN] = mat_rgb[GREEN]; + colors_[col_id][BLUE] = mat_rgb[BLUE]; } else { std::stringstream err_msg; err_msg << "Could not find material " << col_id - << " specified in plot " << id; + << " specified in plot " << id_; fatal_error(err_msg); } } @@ -480,9 +480,9 @@ Plot::set_meshlines(pugi::xml_node plot_node) int n_meshlines = mesh_line_nodes.size(); if (n_meshlines != 0) { - if (plot_type::voxel == type) { + if (plot_type::voxel == type_) { std::stringstream msg; - msg << "Meshlines ignored in voxel plot " << id; + msg << "Meshlines ignored in voxel plot " << id_; warning(msg); } @@ -496,7 +496,7 @@ Plot::set_meshlines(pugi::xml_node plot_node) meshtype = get_node_value(meshlines_node, "meshtype"); } else { std::stringstream err_msg; - err_msg << "Must specify a meshtype for meshlines specification in plot " << id; + err_msg << "Must specify a meshtype for meshlines specification in plot " << id_; fatal_error(err_msg); } @@ -504,10 +504,10 @@ Plot::set_meshlines(pugi::xml_node plot_node) std::string meshline_width; if (check_for_node(meshlines_node, "linewidth")) { meshline_width = get_node_value(meshlines_node, "linewidth"); - meshlines_width = std::stoi(meshline_width); + meshlines_width_ = std::stoi(meshline_width); } else { std::stringstream err_msg; - err_msg << "Must specify a linewidth for meshlines specification in plot " << id; + err_msg << "Must specify a linewidth for meshlines specification in plot " << id_; fatal_error(err_msg); } @@ -517,43 +517,43 @@ Plot::set_meshlines(pugi::xml_node plot_node) // Check and make sure 3 values are specified for RGB if (node_word_count(meshlines_node, "color") != 3) { std::stringstream err_msg; - err_msg << "Bad RGB for meshlines color in plot " << id; + err_msg << "Bad RGB for meshlines color in plot " << id_; fatal_error(err_msg); } ml_rgb = get_node_array(meshlines_node, "color"); - meshlines_color[0] = ml_rgb[0]; - meshlines_color[1] = ml_rgb[1]; - meshlines_color[2] = ml_rgb[2]; + meshlines_color_[0] = ml_rgb[0]; + meshlines_color_[1] = ml_rgb[1]; + meshlines_color_[2] = ml_rgb[2]; } else { - meshlines_color[0] = 0; - meshlines_color[1] = 0; - meshlines_color[2] = 0; + meshlines_color_[0] = 0; + meshlines_color_[1] = 0; + meshlines_color_[2] = 0; } // Set mesh based on type if ("ufs" == meshtype) { if (settings::index_ufs_mesh < 0) { std::stringstream err_msg; - err_msg << "No UFS mesh for meshlines on plot " << id; + err_msg << "No UFS mesh for meshlines on plot " << id_; fatal_error(err_msg); } else { - index_meshlines_mesh = settings::index_ufs_mesh; + index_meshlines_mesh_ = settings::index_ufs_mesh; } } else if ("cmfd" == meshtype) { if (!settings::cmfd_run) { std::stringstream err_msg; - err_msg << "Need CMFD run to plot CMFD mesh for meshlines on plot " << id; + err_msg << "Need CMFD run to plot CMFD mesh for meshlines on plot " << id_; fatal_error(err_msg); } else { - index_meshlines_mesh = settings::index_cmfd_mesh; + index_meshlines_mesh_ = settings::index_cmfd_mesh; } } else if ("entropy" == meshtype) { if (settings::index_entropy_mesh < 0) { std::stringstream err_msg; - err_msg <<"No entropy mesh for meshlines on plot " << id; + err_msg <<"No entropy mesh for meshlines on plot " << id_; fatal_error(err_msg); } else { - index_meshlines_mesh = settings::index_entropy_mesh; + index_meshlines_mesh_ = settings::index_entropy_mesh; } } else if ("tally" == meshtype) { // Ensure that there is a mesh id if the type is tally @@ -563,7 +563,7 @@ Plot::set_meshlines(pugi::xml_node plot_node) } else { std::stringstream err_msg; err_msg << "Must specify a mesh id for meshlines tally " - << "mesh specification in plot " << id; + << "mesh specification in plot " << id_; fatal_error(err_msg); } // find the tally index @@ -572,18 +572,18 @@ Plot::set_meshlines(pugi::xml_node plot_node) if (err != 0) { std::stringstream err_msg; err_msg << "Could not find mesh " << tally_mesh_id - << " specified in meshlines for plot " << id; + << " specified in meshlines for plot " << id_; fatal_error(err_msg); } - index_meshlines_mesh = idx; + index_meshlines_mesh_ = idx; } else { std::stringstream err_msg; - err_msg << "Invalid type for meshlines on plot " << id ; + err_msg << "Invalid type for meshlines on plot " << id_ ; fatal_error(err_msg); } } else { std::stringstream err_msg; - err_msg << "Mutliple meshlines specified in plot " << id; + err_msg << "Mutliple meshlines specified in plot " << id_; fatal_error(err_msg); } } @@ -598,10 +598,10 @@ Plot::set_mask(pugi::xml_node plot_node) int n_masks = mask_nodes.size(); if (n_masks > 0) { - if (plot_type::voxel == type) { + if (plot_type::voxel == type_) { if (openmc_master) { std::stringstream wrn_msg; - wrn_msg << "Mask ignored in voxel plot " << id; + wrn_msg << "Mask ignored in voxel plot " << id_; warning(wrn_msg); } } @@ -615,7 +615,7 @@ Plot::set_mask(pugi::xml_node plot_node) n_comp = node_word_count(mask_node, "components"); if (0 == n_comp) { std::stringstream err_msg; - err_msg << "Missing in mask of plot " << id; + err_msg << "Missing in mask of plot " << id_; fatal_error(err_msg); } std::vector iarray = get_node_array(mask_node, "components"); @@ -626,55 +626,55 @@ Plot::set_mask(pugi::xml_node plot_node) for (int j = 0; j < iarray.size(); j++) { col_id = iarray[j]; - if (plot_color_by::cells == color_by) { + if (plot_color_by::cells == color_by_) { if (cell_map.find(col_id) != cell_map.end()) { iarray[j] = cell_map[col_id]; } else { std::stringstream err_msg; err_msg << "Could not find cell " << col_id - << " specified in the mask in plot " << id; + << " specified in the mask in plot " << id_; fatal_error(err_msg); } - } else if (plot_color_by::mats == color_by) { + } else if (plot_color_by::mats == color_by_) { if (material_map.find(col_id) != material_map.end()) { iarray[j] = material_map[col_id]; } else { std::stringstream err_msg; err_msg << "Could not find material " << col_id - << " specified in the mask in plot " << id; + << " specified in the mask in plot " << id_; fatal_error(err_msg); } } } // Alter colors based on mask information - for (int j = 0; j < colors.size(); j++) { + for (int j = 0; j < colors_.size(); j++) { if (std::find(iarray.begin(), iarray.end(), j) == iarray.end()) { if (check_for_node(mask_node, "background")) { std::vector bg_rgb = get_node_array(mask_node, "background"); - colors[j][RED] = bg_rgb[RED]; - colors[j][GREEN] = bg_rgb[GREEN]; - colors[j][BLUE] = bg_rgb[BLUE]; + colors_[j][RED] = bg_rgb[RED]; + colors_[j][GREEN] = bg_rgb[GREEN]; + colors_[j][BLUE] = bg_rgb[BLUE]; } else { - colors[j][RED] = 255; - colors[j][GREEN] = 255; - colors[j][BLUE] = 255; + colors_[j][RED] = 255; + colors_[j][GREEN] = 255; + colors_[j][BLUE] = 255; } } } } else { std::stringstream err_msg; - err_msg << "Mutliple masks specified in plot " << id; + err_msg << "Mutliple masks specified in plot " << id_; fatal_error(err_msg); } } } Plot::Plot(pugi::xml_node plot_node): -index_meshlines_mesh(-1) +index_meshlines_mesh_(-1) { set_id(plot_node); set_type(plot_node); @@ -707,32 +707,32 @@ void position_rgb(Particle p, Plot pl, RGBColor &rgb, int &id) if (settings::check_overlaps) {check_cell_overlap(&p);} // Set coordinate level if specified - if (pl.level >= 0) {j = pl.level + 1;} + if (pl.level_ >= 0) {j = pl.level_ + 1;} if (!found_cell) { // If no cell, revert to default color - rgb = pl.not_found; + rgb = pl.not_found_; id = -1; } else { - if (plot_color_by::mats == pl.color_by) { + if (plot_color_by::mats == pl.color_by_) { // Assign color based on material Cell* c = cells[p.coord[j].cell]; if (c->type_ == FILL_UNIVERSE) { // If we stopped on a middle universe level, treat as if not found - rgb = pl.not_found; + rgb = pl.not_found_; id = -1; } else if (p.material == MATERIAL_VOID) { // By default, color void cells white rgb = WHITE; id = -1; } else { - rgb = pl.colors[p.material - 1]; + rgb = pl.colors_[p.material - 1]; id = materials[p.material - 1]->id_; } - } else if (plot_color_by::cells == pl.color_by) { + } else if (plot_color_by::cells == pl.color_by_) { // Assign color based on cell - rgb = pl.colors[p.coord[j].cell]; + rgb = pl.colors_[p.coord[j].cell]; id = cells[p.coord[j].cell]->id_; } else { rgb = NULLRGB; @@ -749,7 +749,7 @@ void position_rgb(Particle p, Plot pl, RGBColor &rgb, int &id) void output_ppm(Plot pl, const ImageData &data) { // Open PPM file for writing - std::string fname = pl.path_plot; + std::string fname = pl.path_plot_; fname = strtrim(fname); std::ofstream of; @@ -757,14 +757,14 @@ void output_ppm(Plot pl, const ImageData &data) // Write header of << "P6" << std::endl; - of << pl.pixels[0] << " " << pl.pixels[1] << std::endl; + of << pl.pixels_[0] << " " << pl.pixels_[1] << std::endl; of << "255" << std::endl; of.close(); of.open(fname, std::ios::binary | std::ios::app); // Write color for each pixel - for (int y = 0; y < pl.pixels[1]; y++) { - for (int x = 0; x < pl.pixels[0]; x++) { + for (int y = 0; y < pl.pixels_[1]; y++) { + for (int x = 0; x < pl.pixels_[0]; x++) { RGBColor rgb = data(x,y); of.write((char*)&rgb[RED], 1); of.write((char*)&rgb[GREEN], 1); @@ -784,12 +784,12 @@ void output_ppm(Plot pl, const ImageData &data) void draw_mesh_lines(Plot pl, ImageData &data) { RGBColor rgb; - rgb[RED] = pl.meshlines_color[RED]; - rgb[GREEN] = pl.meshlines_color[GREEN]; - rgb[BLUE] = pl.meshlines_color[BLUE]; + rgb[RED] = pl.meshlines_color_[RED]; + rgb[GREEN] = pl.meshlines_color_[GREEN]; + rgb[BLUE] = pl.meshlines_color_[BLUE]; int outer, inner; - switch(pl.basis) { + switch(pl.basis_) { case plot_basis::xy : outer = 0; inner = 1; @@ -805,20 +805,20 @@ void draw_mesh_lines(Plot pl, ImageData &data) } double xyz_ll_plot[3], xyz_ur_plot[3]; - std::copy((double*)&pl.origin, (double*)&pl.origin + 3, xyz_ll_plot); - std::copy((double*)&pl.origin, (double*)&pl.origin + 3, xyz_ur_plot); + std::copy((double*)&pl.origin_, (double*)&pl.origin_ + 3, xyz_ll_plot); + std::copy((double*)&pl.origin_, (double*)&pl.origin_ + 3, xyz_ur_plot); - xyz_ll_plot[outer] = pl.origin[outer] - pl.width[0] / 2.; - xyz_ll_plot[inner] = pl.origin[inner] - pl.width[1] / 2.; - xyz_ur_plot[outer] = pl.origin[outer] + pl.width[0] / 2.; - xyz_ur_plot[inner] = pl.origin[inner] + pl.width[1] / 2.; + xyz_ll_plot[outer] = pl.origin_[outer] - pl.width_[0] / 2.; + xyz_ll_plot[inner] = pl.origin_[inner] - pl.width_[1] / 2.; + xyz_ur_plot[outer] = pl.origin_[outer] + pl.width_[0] / 2.; + xyz_ur_plot[inner] = pl.origin_[inner] + pl.width_[1] / 2.; int width[3]; width[0] = xyz_ur_plot[0] - xyz_ll_plot[0]; width[1] = xyz_ur_plot[1] - xyz_ll_plot[1]; width[2] = xyz_ur_plot[2] - xyz_ll_plot[2]; - auto &m = meshes[pl.index_meshlines_mesh]; + auto &m = meshes[pl.index_meshlines_mesh_]; int ijk_ll[3], ijk_ur[3]; bool in_mesh; @@ -843,18 +843,18 @@ void draw_mesh_lines(Plot pl, ImageData &data) // map the xyz ranges to pixel ranges double frac = (xyz_ll[outer] - xyz_ll_plot[outer]) / width[outer]; - outrange[0] = int(frac * double(pl.pixels[0])); + outrange[0] = int(frac * double(pl.pixels_[0])); frac = (xyz_ur[outer] - xyz_ll_plot[outer]) / width[outer]; - outrange[1] = int(frac * double(pl.pixels[0])); + outrange[1] = int(frac * double(pl.pixels_[0])); frac = (xyz_ur[inner] - xyz_ll_plot[inner]) / width[inner]; - inrange[0] = int((1. - frac) * (double)pl.pixels[1]); + inrange[0] = int((1. - frac) * (double)pl.pixels_[1]); frac = (xyz_ll[inner] - xyz_ll_plot[inner]) / width[inner]; - inrange[1] = int((1. - frac) * (double)pl.pixels[1]); + inrange[1] = int((1. - frac) * (double)pl.pixels_[1]); // draw lines for (int out_ = outrange[0]; out_ <= outrange[1]; out_++) { - for (int plus = 0; plus <= pl.meshlines_width; plus++) { + for (int plus = 0; plus <= pl.meshlines_width_; plus++) { data(out_, inrange[0] + plus) = rgb; data(out_, inrange[1] + plus) = rgb; data(out_, inrange[0] - plus) = rgb; @@ -863,7 +863,7 @@ void draw_mesh_lines(Plot pl, ImageData &data) } for (int in_ = inrange[0]; in_ <= inrange[1]; in_++) { - for (int plus = 0; plus <= pl.meshlines_width; plus++) { + for (int plus = 0; plus <= pl.meshlines_width_; plus++) { data(outrange[0] + plus, in_) = rgb; data(outrange[1] + plus, in_) = rgb; data(outrange[0] - plus, in_) = rgb; @@ -894,15 +894,15 @@ void create_voxel(Plot pl) // compute voxel widths in each direction double vox[3]; - vox[0] = pl.width[0]/(double)pl.pixels[0]; - vox[1] = pl.width[1]/(double)pl.pixels[1]; - vox[2] = pl.width[2]/(double)pl.pixels[2]; + vox[0] = pl.width_[0]/(double)pl.pixels_[0]; + vox[1] = pl.width_[1]/(double)pl.pixels_[1]; + vox[2] = pl.width_[2]/(double)pl.pixels_[2]; // initial particle position double ll[3]; - ll[0] = pl.origin[0] - pl.width[0] / 2.; - ll[1] = pl.origin[1] - pl.width[1] / 2.; - ll[2] = pl.origin[2] - pl.width[2] / 2.; + ll[0] = pl.origin_[0] - pl.width_[0] / 2.; + ll[1] = pl.origin_[1] - pl.width_[1] / 2.; + ll[2] = pl.origin_[2] - pl.width_[2] / 2.; // allocate and initialize particle double dir[3] = {0.5, 0.5, 0.5}; @@ -914,7 +914,7 @@ void create_voxel(Plot pl) // Open binary plot file for writing std::ofstream of; - std::string fname = std::string(pl.path_plot); + std::string fname = std::string(pl.path_plot_); fname = strtrim(fname); hid_t file_id = file_open(fname, 'w'); @@ -930,16 +930,16 @@ void create_voxel(Plot pl) // Write current date and time write_attribute(file_id, "date_and_time", time_stamp().c_str()); hsize_t three = 3; - write_attr_int(file_id, 1, &three, "num_voxels", pl.pixels); + write_attr_int(file_id, 1, &three, "num_voxels", pl.pixels_); write_attr_double(file_id, 1, &three, "voxel_width", vox); write_attr_double(file_id, 1, &three, "lower_left", ll); // Create dataset for voxel data -- note that the dimensions are reversed // since we want the order in the file to be z, y, x hsize_t dims[3]; - dims[0] = pl.pixels[0]; - dims[1] = pl.pixels[1]; - dims[2] = pl.pixels[2]; + dims[0] = pl.pixels_[0]; + dims[1] = pl.pixels_[1]; + dims[2] = pl.pixels_[2]; hid_t dspace, dset, memspace; voxel_init(file_id, &(dims[0]), &dspace, &dset, &memspace); @@ -948,17 +948,17 @@ void create_voxel(Plot pl) ll[1] = ll[1] + vox[1] / 2.; ll[2] = ll[2] + vox[2] / 2.; - int data[pl.pixels[1]][pl.pixels[2]]; + int data[pl.pixels_[1]][pl.pixels_[2]]; ProgressBar pb; RGBColor rgb; int id; - for (int x = 0; x < pl.pixels[0]; x++) { + for (int x = 0; x < pl.pixels_[0]; x++) { // TODO: progress bar here - pb.set_value(100.*(double)x/(double)(pl.pixels[0]-1)); - for (int y = 0; y < pl.pixels[1]; y++) { - for (int z = 0; z < pl.pixels[2]; z++) { + pb.set_value(100.*(double)x/(double)(pl.pixels_[0]-1)); + for (int y = 0; y < pl.pixels_[1]; y++) { + for (int z = 0; z < pl.pixels_[2]; z++) { // get voxel color position_rgb(p, pl, rgb, id); // write to plot data From e5d8cdfc37befc62854fcec8783f9fd2ddab66d6 Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Tue, 30 Oct 2018 20:04:24 -0500 Subject: [PATCH 082/105] Updating enum names to camel case. --- include/openmc/plot.h | 12 ++++---- src/output.cpp | 22 +++++++-------- src/plot.cpp | 66 +++++++++++++++++++++---------------------- 3 files changed, 50 insertions(+), 50 deletions(-) diff --git a/include/openmc/plot.h b/include/openmc/plot.h index 0ec07074b..346dd0912 100644 --- a/include/openmc/plot.h +++ b/include/openmc/plot.h @@ -39,18 +39,18 @@ typedef std::array RGBColor; typedef xt::xtensor ImageData; -enum class plot_type { +enum class PlotType { slice = 1, voxel = 2 }; -enum class plot_basis { +enum class PlotBasis { xy = 1, xz = 2, yz = 3 }; -enum class plot_color_by { +enum class PlotColorBy { cells = 1, mats = 2 }; @@ -84,11 +84,11 @@ private: // Members public: int id_; //!< Plot ID - plot_type type_; //!< Plot type (Slice/Voxel) - plot_color_by color_by_; //!< Plot coloring (cell/material) + PlotType type_; //!< Plot type (Slice/Voxel) + PlotColorBy color_by_; //!< Plot coloring (cell/material) Position origin_; //!< Plot origin in geometry Position width_; //!< Plot width in geometry - plot_basis basis_; //!< Plot basis (XY/XZ/YZ) + PlotBasis basis_; //!< Plot basis (XY/XZ/YZ) int pixels_[3]; //!< Plot size in pixels int meshlines_width_; //!< Width of lines added to the plot int level_; //!< Plot universe level diff --git a/src/output.cpp b/src/output.cpp index 10e5a0765..0277ec701 100644 --- a/src/output.cpp +++ b/src/output.cpp @@ -71,9 +71,9 @@ void print_plot() { std::cout << "Universe depth: " << pl.level_ << std::endl; // Plot type - if (plot_type::slice == pl.type_) { + if (PlotType::slice == pl.type_) { std::cout << "Plot Type: Slice" << std::endl; - } else if (plot_type::voxel == pl.type_) { + } else if (PlotType::voxel == pl.type_) { std::cout << "Plot Type: Voxel" << std::endl; } @@ -82,12 +82,12 @@ void print_plot() { << pl.origin_[1] << " " << pl.origin_[2] << std::endl; - if (plot_type::slice == pl.type_) { + if (PlotType::slice == pl.type_) { std::cout << std::setprecision(4) << "Width: " << pl.width_[0] << " " << pl.width_[1] << std::endl; - } else if (plot_type::voxel == pl.type_) { + } else if (PlotType::voxel == pl.type_) { std::cout << std::setprecision(4) << "Width: " << pl.width_[0] << " " @@ -95,27 +95,27 @@ void print_plot() { << pl.width_[2] << std::endl; } - if (plot_color_by::cells == pl.color_by_) { + if (PlotColorBy::cells == pl.color_by_) { std::cout << "Coloring: Cells" << std::endl; - } else if (plot_color_by::mats == pl.color_by_) { + } else if (PlotColorBy::mats == pl.color_by_) { std::cout << "Coloring: Materials" << std::endl; } - if (plot_type::slice == pl.type_) { + if (PlotType::slice == pl.type_) { switch(pl.basis_) { - case plot_basis::xy: + case PlotBasis::xy: std::cout << "Basis: XY" << std::endl; break; - case plot_basis::xz: + case PlotBasis::xz: std::cout << "Basis: XZ" << std::endl; break; - case plot_basis::yz: + case PlotBasis::yz: std::cout << "Basis: YZ" << std::endl; break; } std::cout << "Pixels: " << pl.pixels_[0] << " " << pl.pixels_[1] << " " << std::endl; - } else if (plot_type::voxel == pl.type_) { + } else if (PlotType::voxel == pl.type_) { std::cout << "Voxels: " << pl.pixels_[0] << " " << pl.pixels_[1] << " " << pl.pixels_[2] << std::endl; diff --git a/src/plot.cpp b/src/plot.cpp index 17f67f1f9..69e7d9e32 100644 --- a/src/plot.cpp +++ b/src/plot.cpp @@ -48,10 +48,10 @@ int openmc_plot_geometry() << pl.path_plot_ << "..."; write_message(ss.str(), 5); - if (plot_type::slice == pl.type_) { + if (PlotType::slice == pl.type_) { // create 2D image create_ppm(pl); - } else if (plot_type::voxel == pl.type_) { + } else if (PlotType::voxel == pl.type_) { // create voxel file for 3D viewing create_voxel(pl); } @@ -96,21 +96,21 @@ void create_ppm(Plot pl) int in_i, out_i; double xyz[3]; switch(pl.basis_) { - case plot_basis::xy : + case PlotBasis::xy : in_i = 0; out_i = 1; xyz[0] = pl.origin_[0] - pl.width_[0] / 2.; xyz[1] = pl.origin_[1] + pl.width_[1] / 2.; xyz[2] = pl.origin_[2]; break; - case plot_basis::xz : + case PlotBasis::xz : in_i = 0; out_i = 2; xyz[0] = pl.origin_[0] - pl.width_[0] / 2.; xyz[1] = pl.origin_[1]; xyz[2] = pl.origin_[2] + pl.width_[1] / 2.; break; - case plot_basis::yz : + case PlotBasis::yz : in_i = 1; out_i = 2; xyz[0] = pl.origin_[0]; @@ -174,17 +174,17 @@ Plot::set_type(pugi::xml_node plot_node) { // Copy plot type // Default is slice - type_ = plot_type::slice; + type_ = PlotType::slice; // check type specified on plot node if (check_for_node(plot_node, "type")) { std::string type_str = get_node_value(plot_node, "type", true); // set type using node value if (type_str == "slice") { - type_ = plot_type::slice; + type_ = PlotType::slice; return; } else if (type_str == "voxel") { - type_ = plot_type::voxel; + type_ = PlotType::voxel; return; } // if we're here, something is wrong @@ -207,10 +207,10 @@ Plot::set_output_path(pugi::xml_node plot_node) } // add appropriate file extension to name switch(type_) { - case plot_type::slice: + case PlotType::slice: filename << ".ppm"; break; - case plot_type::voxel: + case PlotType::voxel: filename << ".h5"; break; } @@ -219,7 +219,7 @@ Plot::set_output_path(pugi::xml_node plot_node) // Copy plot pixel size std::vector pxls; - if (plot_type::slice == type_) { + if (PlotType::slice == type_) { if (node_word_count(plot_node, "pixels") == 2) { pxls = get_node_array(plot_node, "pixels"); pixels_[0] = pxls[0]; @@ -230,7 +230,7 @@ Plot::set_output_path(pugi::xml_node plot_node) << id_; fatal_error(err_msg.str()); } - } else if (plot_type::voxel == type_) { + } else if (PlotType::voxel == type_) { if (node_word_count(plot_node, "pixels") == 3) { pxls = get_node_array(plot_node, "pixels"); pixels_[0] = pxls[0]; @@ -251,7 +251,7 @@ Plot::set_bg_color(pugi::xml_node plot_node) // Copy plot background color std::vector bg_rgb; if (check_for_node(plot_node, "background")) { - if (plot_type::voxel == type_) { + if (PlotType::voxel == type_) { if (openmc_master) { std::stringstream err_msg; err_msg << "Background color ignored in voxel plot " @@ -282,17 +282,17 @@ void Plot::set_basis(pugi::xml_node plot_node) { // Copy plot basis - if (plot_type::slice == type_) { + if (PlotType::slice == type_) { std::string pl_basis = "xy"; if (check_for_node(plot_node, "basis")) { pl_basis = get_node_value(plot_node, "basis", true); } if ("xy" == pl_basis) { - basis_ = plot_basis::xy; + basis_ = PlotBasis::xy; } else if ("xz" == pl_basis) { - basis_ = plot_basis::xz; + basis_ = PlotBasis::xz; } else if ("yz" == pl_basis) { - basis_ = plot_basis::yz; + basis_ = PlotBasis::yz; } else { std::stringstream err_msg; err_msg << "Unsupported plot basis '" << pl_basis @@ -325,7 +325,7 @@ Plot::set_width(pugi::xml_node plot_node) { // Copy plotting width std::vector pl_width; - if (plot_type::slice == type_) { + if (PlotType::slice == type_) { if (node_word_count(plot_node, "width") == 2) { pl_width = get_node_array(plot_node, "width"); width_[0] = pl_width[0]; @@ -336,7 +336,7 @@ Plot::set_width(pugi::xml_node plot_node) << id_; fatal_error(err_msg); } - } else if (plot_type::voxel == type_) { + } else if (PlotType::voxel == type_) { if (node_word_count(plot_node, "width") == 3) { pl_width = get_node_array(plot_node, "width"); width_[0] = pl_width[0]; @@ -376,7 +376,7 @@ Plot::set_default_colors(pugi::xml_node plot_node) pl_color_by = get_node_value(plot_node, "color_by", true); } if ("cell" == pl_color_by) { - color_by_ = plot_color_by::cells; + color_by_ = PlotColorBy::cells; colors_.resize(n_cells); for (int i = 0; i < n_cells; i++) { colors_[i][RED] = int(prn()*255); @@ -385,7 +385,7 @@ Plot::set_default_colors(pugi::xml_node plot_node) } } else if("material" == pl_color_by) { - color_by_ = plot_color_by::mats; + color_by_ = PlotColorBy::mats; colors_.resize(n_materials); for (int i = 0; i < materials.size(); i++) { colors_[i][RED] = int(prn()*255); @@ -410,7 +410,7 @@ Plot::set_user_colors(pugi::xml_node plot_node) // Copy user-specified colors if (color_nodes.size() != 0) { - if (plot_type::voxel == type_) { + if (PlotType::voxel == type_) { if (openmc_master) { std::stringstream err_msg; err_msg << "Color specifications ignored in voxel plot " @@ -437,7 +437,7 @@ Plot::set_user_colors(pugi::xml_node plot_node) fatal_error(err_msg); } // Add RGB - if (plot_color_by::cells == color_by_) { + if (PlotColorBy::cells == color_by_) { std::vector cell_rgb; if (cell_map.find(col_id) != cell_map.end()) { col_id = cell_map[col_id]; @@ -451,7 +451,7 @@ Plot::set_user_colors(pugi::xml_node plot_node) << " specified in plot " << id_; fatal_error(err_msg); } - } else if (plot_color_by::mats == color_by_) { + } else if (PlotColorBy::mats == color_by_) { std::vector mat_rgb; if (material_map.find(col_id) != material_map.end()) { col_id = material_map[col_id]; @@ -480,7 +480,7 @@ Plot::set_meshlines(pugi::xml_node plot_node) int n_meshlines = mesh_line_nodes.size(); if (n_meshlines != 0) { - if (plot_type::voxel == type_) { + if (PlotType::voxel == type_) { std::stringstream msg; msg << "Meshlines ignored in voxel plot " << id_; warning(msg); @@ -598,7 +598,7 @@ Plot::set_mask(pugi::xml_node plot_node) int n_masks = mask_nodes.size(); if (n_masks > 0) { - if (plot_type::voxel == type_) { + if (PlotType::voxel == type_) { if (openmc_master) { std::stringstream wrn_msg; wrn_msg << "Mask ignored in voxel plot " << id_; @@ -626,7 +626,7 @@ Plot::set_mask(pugi::xml_node plot_node) for (int j = 0; j < iarray.size(); j++) { col_id = iarray[j]; - if (plot_color_by::cells == color_by_) { + if (PlotColorBy::cells == color_by_) { if (cell_map.find(col_id) != cell_map.end()) { iarray[j] = cell_map[col_id]; } @@ -636,7 +636,7 @@ Plot::set_mask(pugi::xml_node plot_node) << " specified in the mask in plot " << id_; fatal_error(err_msg); } - } else if (plot_color_by::mats == color_by_) { + } else if (PlotColorBy::mats == color_by_) { if (material_map.find(col_id) != material_map.end()) { iarray[j] = material_map[col_id]; } @@ -714,7 +714,7 @@ void position_rgb(Particle p, Plot pl, RGBColor &rgb, int &id) rgb = pl.not_found_; id = -1; } else { - if (plot_color_by::mats == pl.color_by_) { + if (PlotColorBy::mats == pl.color_by_) { // Assign color based on material Cell* c = cells[p.coord[j].cell]; if (c->type_ == FILL_UNIVERSE) { @@ -730,7 +730,7 @@ void position_rgb(Particle p, Plot pl, RGBColor &rgb, int &id) id = materials[p.material - 1]->id_; } - } else if (plot_color_by::cells == pl.color_by_) { + } else if (PlotColorBy::cells == pl.color_by_) { // Assign color based on cell rgb = pl.colors_[p.coord[j].cell]; id = cells[p.coord[j].cell]->id_; @@ -790,15 +790,15 @@ void draw_mesh_lines(Plot pl, ImageData &data) int outer, inner; switch(pl.basis_) { - case plot_basis::xy : + case PlotBasis::xy : outer = 0; inner = 1; break; - case plot_basis::xz : + case PlotBasis::xz : outer = 0; inner = 2; break; - case plot_basis::yz : + case PlotBasis::yz : outer = 1; inner = 2; break; From 3e36ed8e34db7939b798bb3498614728f6547c5c Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Tue, 30 Oct 2018 20:13:36 -0500 Subject: [PATCH 083/105] More PR comment resolution. --- include/openmc/plot.h | 7 +++---- src/output.cpp | 34 +++++++++++++++++----------------- src/plot.cpp | 8 ++++---- src/progress_bar.cpp | 9 +-------- 4 files changed, 25 insertions(+), 33 deletions(-) diff --git a/include/openmc/plot.h b/include/openmc/plot.h index 346dd0912..da9b33097 100644 --- a/include/openmc/plot.h +++ b/include/openmc/plot.h @@ -106,21 +106,20 @@ public: //! Add mesh lines to image data of a plot object //! \param[in] plot object //! \param[out] image data associated with the plot object -void draw_mesh_lines(Plot pl, - ImageData &data); +void draw_mesh_lines(Plot pl, ImageData &data); //! Write a ppm image to file using a plot object's image data //! \param[in] plot object //! \param[out] image data associated with the plot object void output_ppm(Plot pl, - const ImageData &data); + const ImageData& data); //! Get the rgb color for a given particle position in a plot //! \param[in] particle with position for current pixel //! \param[in] plot object //! \param[out] rgb color //! \param[out] cell or material id for particle position -void position_rgb(Particle p, Plot pl, RGBColor &rgb, int &id); +void position_rgb(Particle p, Plot pl, RGBColor& rgb, int& id); //! Initialize a voxel file //! \param[in] id of an open hdf5 file diff --git a/src/output.cpp b/src/output.cpp index 0277ec701..79800e21a 100644 --- a/src/output.cpp +++ b/src/output.cpp @@ -36,7 +36,7 @@ header(const char* msg, int level) { // Print header based on verbosity level. if (settings::verbosity >= level) { - std::cout << out.str() << std::endl << std::endl; + std::cout << out.str() << "\n\n"; } } @@ -64,64 +64,64 @@ void print_plot() { for (auto pl : plots) { // Plot id - std::cout << "Plot ID: " << pl.id_ << std::endl; + std::cout << "Plot ID: " << pl.id_ << "\n"; // Plot filename - std::cout << "Plot file: " << pl.path_plot_ << std::endl; + std::cout << "Plot file: " << pl.path_plot_ << "\n"; // Plot level - std::cout << "Universe depth: " << pl.level_ << std::endl; + std::cout << "Universe depth: " << pl.level_ << "\n"; // Plot type if (PlotType::slice == pl.type_) { - std::cout << "Plot Type: Slice" << std::endl; + std::cout << "Plot Type: Slice" << "\n"; } else if (PlotType::voxel == pl.type_) { - std::cout << "Plot Type: Voxel" << std::endl; + std::cout << "Plot Type: Voxel" << "\n"; } // Plot parameters std::cout << "Origin: " << pl.origin_[0] << " " << pl.origin_[1] << " " - << pl.origin_[2] << std::endl; + << pl.origin_[2] << "\n"; if (PlotType::slice == pl.type_) { std::cout << std::setprecision(4) << "Width: " << pl.width_[0] << " " - << pl.width_[1] << std::endl; + << pl.width_[1] << "\n"; } else if (PlotType::voxel == pl.type_) { std::cout << std::setprecision(4) << "Width: " << pl.width_[0] << " " << pl.width_[1] << " " - << pl.width_[2] << std::endl; + << pl.width_[2] << "\n"; } if (PlotColorBy::cells == pl.color_by_) { - std::cout << "Coloring: Cells" << std::endl; + std::cout << "Coloring: Cells" << "\n"; } else if (PlotColorBy::mats == pl.color_by_) { - std::cout << "Coloring: Materials" << std::endl; + std::cout << "Coloring: Materials" << "\n"; } if (PlotType::slice == pl.type_) { switch(pl.basis_) { case PlotBasis::xy: - std::cout << "Basis: XY" << std::endl; + std::cout << "Basis: XY" << "\n"; break; case PlotBasis::xz: - std::cout << "Basis: XZ" << std::endl; + std::cout << "Basis: XZ" << "\n"; break; case PlotBasis::yz: - std::cout << "Basis: YZ" << std::endl; + std::cout << "Basis: YZ" << "\n"; break; } std::cout << "Pixels: " << pl.pixels_[0] << " " - << pl.pixels_[1] << " " << std::endl; + << pl.pixels_[1] << " " << "\n"; } else if (PlotType::voxel == pl.type_) { std::cout << "Voxels: " << pl.pixels_[0] << " " << pl.pixels_[1] << " " - << pl.pixels_[2] << std::endl; + << pl.pixels_[2] << "\n"; } - std::cout << std::endl; + std::cout << "\n"; } } diff --git a/src/plot.cpp b/src/plot.cpp index 69e7d9e32..f27832486 100644 --- a/src/plot.cpp +++ b/src/plot.cpp @@ -756,9 +756,9 @@ void output_ppm(Plot pl, const ImageData &data) of.open(fname); // Write header - of << "P6" << std::endl; - of << pl.pixels_[0] << " " << pl.pixels_[1] << std::endl; - of << "255" << std::endl; + of << "P6" << "\n"; + of << pl.pixels_[0] << " " << pl.pixels_[1] << "\n"; + of << "255" << "\n"; of.close(); of.open(fname, std::ios::binary | std::ios::app); @@ -773,7 +773,7 @@ void output_ppm(Plot pl, const ImageData &data) } // Close file // THIS IS HERE TO MATCH FORTRAN VERSION, NOT TECHNICALLY NECESSARY - of << std::endl; + of << "\n"; of.close(); } diff --git a/src/progress_bar.cpp b/src/progress_bar.cpp index f412793c9..44a7e2496 100644 --- a/src/progress_bar.cpp +++ b/src/progress_bar.cpp @@ -11,22 +11,15 @@ #define BAR_WIDTH 72 -#ifdef UNIX -int check_isatty(int fd) { - return isatty(fd); -} -#endif - bool is_terminal() { #ifdef UNIX - return check_isatty(STDOUT_FILENO) != 0; + return isatty(STDOUT_FILENO) != 0; #else return false; #endif } ProgressBar::ProgressBar() { - bar = ""; // initialize bar set_value(0.0); } From 8c7b9969f94541447dd8332f2959e85dc597b343 Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Tue, 30 Oct 2018 21:29:35 -0500 Subject: [PATCH 084/105] Updating xml calls for reading plots.xml. --- include/openmc/xml_interface.h | 5 - src/plot.cpp | 191 ++++++++++++++------------------- src/xml_interface.cpp | 28 ----- 3 files changed, 81 insertions(+), 143 deletions(-) diff --git a/include/openmc/xml_interface.h b/include/openmc/xml_interface.h index 29de8839e..6ab8c148c 100644 --- a/include/openmc/xml_interface.h +++ b/include/openmc/xml_interface.h @@ -49,10 +49,5 @@ xt::xarray get_node_xarray(pugi::xml_node node, const char* name, return xt::adapt(v, shape); } -std::vector -get_child_nodes(pugi::xml_node node, const char* name = NULL); - -int node_word_count(pugi::xml_node node, const char* name); - } // namespace openmc #endif // OPENMC_XML_INTERFACE_H diff --git a/src/plot.cpp b/src/plot.cpp index f27832486..ec3934fdd 100644 --- a/src/plot.cpp +++ b/src/plot.cpp @@ -63,16 +63,11 @@ int openmc_plot_geometry() 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 (int i = 0; i < plot_nodes.size(); i++) { - Plot pl(plot_nodes[i]); + n_plots = 0; + for (auto node : plots_node->children("plot")) { + Plot pl(node); plots.push_back(pl); - plot_map[pl.id_] = i; + plot_map[pl.id_] = n_plots++; } } @@ -87,8 +82,8 @@ void create_ppm(Plot pl) size_t width = pl.pixels_[0]; size_t height = pl.pixels_[1]; - double in_pixel = (pl.width_[0])/double(width); - double out_pixel = (pl.width_[1])/double(height); + double in_pixel = (pl.width_[0])/static_cast(width); + double out_pixel = (pl.width_[1])/static_cast(height); ImageData data; data.resize({width, height}); @@ -218,10 +213,9 @@ Plot::set_output_path(pugi::xml_node plot_node) path_plot_ = filename.str(); // Copy plot pixel size - std::vector pxls; + std::vector pxls = get_node_array(plot_node, "pixels"); if (PlotType::slice == type_) { - if (node_word_count(plot_node, "pixels") == 2) { - pxls = get_node_array(plot_node, "pixels"); + if (pxls.size() == 2) { pixels_[0] = pxls[0]; pixels_[1] = pxls[1]; } else { @@ -231,8 +225,7 @@ Plot::set_output_path(pugi::xml_node plot_node) fatal_error(err_msg.str()); } } else if (PlotType::voxel == type_) { - if (node_word_count(plot_node, "pixels") == 3) { - pxls = get_node_array(plot_node, "pixels"); + if (pxls.size() == 3) { pixels_[0] = pxls[0]; pixels_[1] = pxls[1]; pixels_[2] = pxls[2]; @@ -249,8 +242,8 @@ void Plot::set_bg_color(pugi::xml_node plot_node) { // Copy plot background color - std::vector bg_rgb; if (check_for_node(plot_node, "background")) { + std::vector bg_rgb = get_node_array(plot_node, "background"); if (PlotType::voxel == type_) { if (openmc_master) { std::stringstream err_msg; @@ -259,8 +252,7 @@ Plot::set_bg_color(pugi::xml_node plot_node) warning(err_msg.str()); } } - if (node_word_count(plot_node, "background") == 3) { - bg_rgb = get_node_array(plot_node, "background"); + if (bg_rgb.size() == 3) { not_found_[RED] = bg_rgb[RED]; not_found_[GREEN] = bg_rgb[GREEN]; not_found_[BLUE] = bg_rgb[BLUE]; @@ -306,9 +298,8 @@ void Plot::set_origin(pugi::xml_node plot_node) { // Copy plotting origin - std::vector pl_origin; - if (node_word_count(plot_node, "origin") == 3) { - pl_origin = get_node_array(plot_node, "origin"); + std::vector pl_origin = get_node_array(plot_node, "origin"); + if (pl_origin.size() == 3) { origin_[0] = pl_origin[0]; origin_[1] = pl_origin[1]; origin_[2] = pl_origin[2]; @@ -324,10 +315,9 @@ void Plot::set_width(pugi::xml_node plot_node) { // Copy plotting width - std::vector pl_width; + std::vector pl_width = get_node_array(plot_node, "width"); if (PlotType::slice == type_) { - if (node_word_count(plot_node, "width") == 2) { - pl_width = get_node_array(plot_node, "width"); + if (pl_width.size() == 2) { width_[0] = pl_width[0]; width_[1] = pl_width[1]; } else { @@ -337,7 +327,7 @@ Plot::set_width(pugi::xml_node plot_node) fatal_error(err_msg); } } else if (PlotType::voxel == type_) { - if (node_word_count(plot_node, "width") == 3) { + if (pl_width.size() == 3) { pl_width = get_node_array(plot_node, "width"); width_[0] = pl_width[0]; width_[1] = pl_width[1]; @@ -403,92 +393,78 @@ Plot::set_default_colors(pugi::xml_node plot_node) void Plot::set_user_colors(pugi::xml_node plot_node) { - // 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 (color_nodes.size() != 0) { - - if (PlotType::voxel == type_) { - if (openmc_master) { - std::stringstream err_msg; - err_msg << "Color specifications ignored in voxel plot " - << id_; - warning(err_msg); - } + if (!plot_node.select_nodes("color").empty() && PlotType::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) { - // Check and make sure 3 values are specified for RGB - if (node_word_count(cn, "rgb") != 3) { - std::stringstream err_msg; - err_msg << "Bad RGB in plot " << id_; - fatal_error(err_msg); - } - // Ensure that there is an id for this color specification - int col_id; - if (check_for_node(cn, "id")) { - col_id = std::stoi(get_node_value(cn, "id")); + } + + for (auto cn : plot_node.children("color")) { + // Make sure 3 values are specified for RGB + std::vector user_rgb = get_node_array(cn, "rgb"); + if (user_rgb.size() != 3) { + std::stringstream err_msg; + err_msg << "Bad RGB in plot " << id_; + fatal_error(err_msg); + } + // Ensure that there is an id for this color specification + int col_id; + if (check_for_node(cn, "id")) { + col_id = std::stoi(get_node_value(cn, "id")); + } else { + std::stringstream err_msg; + err_msg << "Must specify id for color specification in plot " + << id_; + fatal_error(err_msg); + } + // Add RGB + if (PlotColorBy::cells == color_by_) { + if (cell_map.find(col_id) != cell_map.end()) { + col_id = cell_map[col_id]; + colors_[col_id][RED] = user_rgb[RED]; + colors_[col_id][GREEN] = user_rgb[GREEN]; + colors_[col_id][BLUE] = user_rgb[BLUE]; } else { std::stringstream err_msg; - err_msg << "Must specify id for color specification in plot " - << id_; + err_msg << "Could not find cell " << col_id + << " specified in plot " << id_; fatal_error(err_msg); } - // Add RGB - if (PlotColorBy::cells == color_by_) { - std::vector cell_rgb; - if (cell_map.find(col_id) != cell_map.end()) { - col_id = cell_map[col_id]; - cell_rgb = get_node_array(cn, "rgb"); - colors_[col_id][RED] = cell_rgb[RED]; - colors_[col_id][GREEN] = cell_rgb[GREEN]; - colors_[col_id][BLUE] = cell_rgb[BLUE]; - } else { - std::stringstream err_msg; - err_msg << "Could not find cell " << col_id - << " specified in plot " << id_; - fatal_error(err_msg); - } - } else if (PlotColorBy::mats == color_by_) { - std::vector mat_rgb; - if (material_map.find(col_id) != material_map.end()) { - col_id = material_map[col_id]; - mat_rgb = get_node_array(cn, "rgb"); - colors_[col_id][RED] = mat_rgb[RED]; - colors_[col_id][GREEN] = mat_rgb[GREEN]; - colors_[col_id][BLUE] = mat_rgb[BLUE]; - } else { - std::stringstream err_msg; - err_msg << "Could not find material " << col_id - << " specified in plot " << id_; - fatal_error(err_msg); - } + } else if (PlotColorBy::mats == color_by_) { + if (material_map.find(col_id) != material_map.end()) { + col_id = material_map[col_id]; + colors_[col_id][RED] = user_rgb[RED]; + colors_[col_id][GREEN] = user_rgb[GREEN]; + colors_[col_id][BLUE] = user_rgb[BLUE]; + } else { + std::stringstream err_msg; + err_msg << "Could not find material " << col_id + << " specified in plot " << id_; + fatal_error(err_msg); } - } // color node loop - } + } + } // color node loop } void Plot::set_meshlines(pugi::xml_node plot_node) { // Deal with meshlines - std::vector mesh_line_nodes; - mesh_line_nodes = get_child_nodes(plot_node, "meshlines"); + pugi::xpath_node_set mesh_line_nodes = plot_node.select_nodes("meshlines"); - int n_meshlines = mesh_line_nodes.size(); - - if (n_meshlines != 0) { + if (!mesh_line_nodes.empty()) { if (PlotType::voxel == type_) { std::stringstream msg; msg << "Meshlines ignored in voxel plot " << id_; warning(msg); } - if (1 == n_meshlines) { + if (mesh_line_nodes.size() == 1) { // Get first meshline node - pugi::xml_node meshlines_node = mesh_line_nodes[0]; + pugi::xml_node meshlines_node = mesh_line_nodes[0].node(); // Check mesh type std::string meshtype; @@ -512,15 +488,14 @@ Plot::set_meshlines(pugi::xml_node plot_node) } // Check for color - std::vector ml_rgb; if (check_for_node(meshlines_node, "color")) { // Check and make sure 3 values are specified for RGB - if (node_word_count(meshlines_node, "color") != 3) { + std::vector ml_rgb = get_node_array(meshlines_node, "color"); + if (ml_rgb.size() != 3) { std::stringstream err_msg; err_msg << "Bad RGB for meshlines color in plot " << id_; fatal_error(err_msg); } - ml_rgb = get_node_array(meshlines_node, "color"); meshlines_color_[0] = ml_rgb[0]; meshlines_color_[1] = ml_rgb[1]; meshlines_color_[2] = ml_rgb[2]; @@ -570,10 +545,10 @@ Plot::set_meshlines(pugi::xml_node plot_node) int idx; int err = openmc_get_mesh_index(tally_mesh_id, &idx); if (err != 0) { - std::stringstream err_msg; - err_msg << "Could not find mesh " << tally_mesh_id - << " specified in meshlines for plot " << id_; - fatal_error(err_msg); + std::stringstream err_msg; + err_msg << "Could not find mesh " << tally_mesh_id + << " specified in meshlines for plot " << id_; + fatal_error(err_msg); } index_meshlines_mesh_ = idx; } else { @@ -593,11 +568,9 @@ void Plot::set_mask(pugi::xml_node plot_node) { // Deal with masks - std::vector mask_nodes; - mask_nodes = get_child_nodes(plot_node, "mask"); - int n_masks = mask_nodes.size(); - - if (n_masks > 0) { + pugi::xpath_node_set mask_nodes = plot_node.select_nodes("mask"); + + if (!mask_nodes.empty()) { if (PlotType::voxel == type_) { if (openmc_master) { std::stringstream wrn_msg; @@ -606,19 +579,17 @@ Plot::set_mask(pugi::xml_node plot_node) } } - if (1 == n_masks) { + if (mask_nodes.size() == 1) { // Get pointer to mask - pugi::xml_node mask_node = mask_nodes[0]; + pugi::xml_node mask_node = mask_nodes[0].node(); // Determine how many components there are and allocate - int n_comp; - n_comp = node_word_count(mask_node, "components"); - if (0 == n_comp) { + std::vector iarray = get_node_array(mask_node, "components"); + if (iarray.size() == 0) { std::stringstream err_msg; err_msg << "Missing in mask of plot " << id_; fatal_error(err_msg); } - std::vector iarray = get_node_array(mask_node, "components"); // First we need to change the user-specified identifiers to indices // in the cell and material arrays diff --git a/src/xml_interface.cpp b/src/xml_interface.cpp index 93b65521c..60ae7ffca 100644 --- a/src/xml_interface.cpp +++ b/src/xml_interface.cpp @@ -3,7 +3,6 @@ #include // for transform #include -#include "openmc/string_functions.h" #include "openmc/error.h" @@ -57,31 +56,4 @@ get_node_value_bool(pugi::xml_node node, const char* name) return false; } - - -std::vector -get_child_nodes(pugi::xml_node node, const char* name) -{ - pugi::xml_node current; - std::vector node_list; - - // add all child nodes with name to vector and return - if (name) { - for (pugi::xml_node current : node.children(name)) { - node_list.push_back(current); - } - } else { - for (pugi::xml_node current : node.children()) { - node_list.push_back(current); - } - } - return node_list; -} - -int node_word_count(pugi::xml_node node, const char* name) -{ - std::string s = get_node_value(node, name); - return word_count(s); -} - } // namespace openmc From bbe18ef191f438b85fb8050c61587b85759daede Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Tue, 30 Oct 2018 21:50:55 -0500 Subject: [PATCH 085/105] Some cleanup of style and an assignement change. --- src/plot.cpp | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/src/plot.cpp b/src/plot.cpp index ec3934fdd..ca9dd979f 100644 --- a/src/plot.cpp +++ b/src/plot.cpp @@ -593,13 +593,10 @@ Plot::set_mask(pugi::xml_node plot_node) // First we need to change the user-specified identifiers to indices // in the cell and material arrays - int col_id; - for (int j = 0; j < iarray.size(); j++) { - col_id = iarray[j]; - + for (auto& col_id : iarray) { if (PlotColorBy::cells == color_by_) { if (cell_map.find(col_id) != cell_map.end()) { - iarray[j] = cell_map[col_id]; + col_id = cell_map[col_id]; } else { std::stringstream err_msg; @@ -609,7 +606,7 @@ Plot::set_mask(pugi::xml_node plot_node) } } else if (PlotColorBy::mats == color_by_) { if (material_map.find(col_id) != material_map.end()) { - iarray[j] = material_map[col_id]; + col_id = material_map[col_id]; } else { std::stringstream err_msg; @@ -667,7 +664,7 @@ index_meshlines_mesh_(-1) //============================================================================== -void position_rgb(Particle p, Plot pl, RGBColor &rgb, int &id) +void position_rgb(Particle p, Plot pl, RGBColor& rgb, int& id) { p.n_coord = 1; @@ -717,7 +714,7 @@ void position_rgb(Particle p, Plot pl, RGBColor &rgb, int &id) // OUTPUT_PPM writes out a previously generated image to a PPM file //============================================================================== -void output_ppm(Plot pl, const ImageData &data) +void output_ppm(Plot pl, const ImageData& data) { // Open PPM file for writing std::string fname = pl.path_plot_; @@ -737,9 +734,9 @@ void output_ppm(Plot pl, const ImageData &data) for (int y = 0; y < pl.pixels_[1]; y++) { for (int x = 0; x < pl.pixels_[0]; x++) { RGBColor rgb = data(x,y); - of.write((char*)&rgb[RED], 1); - of.write((char*)&rgb[GREEN], 1); - of.write((char*)&rgb[BLUE], 1); + of.write(reinterpret_cast(&rgb[RED]), 1); + of.write(reinterpret_cast(&rgb[GREEN]), 1); + of.write(reinterpret_cast(&rgb[BLUE]), 1); } } // Close file @@ -752,7 +749,7 @@ void output_ppm(Plot pl, const ImageData &data) // DRAW_MESH_LINES draws mesh line boundaries on an image //============================================================================== -void draw_mesh_lines(Plot pl, ImageData &data) +void draw_mesh_lines(Plot pl, ImageData& data) { RGBColor rgb; rgb[RED] = pl.meshlines_color_[RED]; @@ -776,9 +773,14 @@ void draw_mesh_lines(Plot pl, ImageData &data) } double xyz_ll_plot[3], xyz_ur_plot[3]; - std::copy((double*)&pl.origin_, (double*)&pl.origin_ + 3, xyz_ll_plot); - std::copy((double*)&pl.origin_, (double*)&pl.origin_ + 3, xyz_ur_plot); + xyz_ll_plot[0] = pl.origin_[0]; + xyz_ll_plot[1] = pl.origin_[1]; + xyz_ll_plot[2] = pl.origin_[2]; + xyz_ur_plot[0] = pl.origin_[0]; + xyz_ur_plot[1] = pl.origin_[1]; + xyz_ur_plot[2] = pl.origin_[2]; + xyz_ll_plot[outer] = pl.origin_[outer] - pl.width_[0] / 2.; xyz_ll_plot[inner] = pl.origin_[inner] - pl.width_[1] / 2.; xyz_ur_plot[outer] = pl.origin_[outer] + pl.width_[0] / 2.; @@ -789,7 +791,7 @@ void draw_mesh_lines(Plot pl, ImageData &data) width[1] = xyz_ur_plot[1] - xyz_ll_plot[1]; width[2] = xyz_ur_plot[2] - xyz_ll_plot[2]; - auto &m = meshes[pl.index_meshlines_mesh_]; + auto& m = meshes[pl.index_meshlines_mesh_]; int ijk_ll[3], ijk_ur[3]; bool in_mesh; From e7ff427b64b71011f2a1415e62ca4be0cf73edcf Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Tue, 30 Oct 2018 22:02:53 -0500 Subject: [PATCH 086/105] Updating types so write_attributes can be used uniformly. --- include/openmc/plot.h | 2 +- src/plot.cpp | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/include/openmc/plot.h b/include/openmc/plot.h index da9b33097..f0ed3016b 100644 --- a/include/openmc/plot.h +++ b/include/openmc/plot.h @@ -89,7 +89,7 @@ public: Position origin_; //!< Plot origin in geometry Position width_; //!< Plot width in geometry PlotBasis basis_; //!< Plot basis (XY/XZ/YZ) - int pixels_[3]; //!< Plot size in pixels + std::array pixels_; //!< Plot size in pixels int meshlines_width_; //!< Width of lines added to the plot int level_; //!< Plot universe level int index_meshlines_mesh_; //!< Index of the mesh to draw on the plot diff --git a/src/plot.cpp b/src/plot.cpp index ca9dd979f..e1cbdb2d1 100644 --- a/src/plot.cpp +++ b/src/plot.cpp @@ -866,13 +866,13 @@ void create_voxel(Plot pl) { // compute voxel widths in each direction - double vox[3]; + std::array vox; vox[0] = pl.width_[0]/(double)pl.pixels_[0]; vox[1] = pl.width_[1]/(double)pl.pixels_[1]; vox[2] = pl.width_[2]/(double)pl.pixels_[2]; // initial particle position - double ll[3]; + std::array ll; ll[0] = pl.origin_[0] - pl.width_[0] / 2.; ll[1] = pl.origin_[1] - pl.width_[1] / 2.; ll[2] = pl.origin_[2] - pl.width_[2] / 2.; @@ -881,8 +881,8 @@ void create_voxel(Plot pl) double dir[3] = {0.5, 0.5, 0.5}; Particle p; p.initialize(); - std::copy(ll, ll + 3, p.coord[0].xyz); - std::copy(dir, dir + 3, p.coord[0].uvw); + std::copy(ll.begin(), ll.begin()+ll.size(), p.coord[0].xyz); + std::copy(dir, dir+3, p.coord[0].uvw); p.coord[0].universe = openmc_root_universe; // Open binary plot file for writing @@ -903,9 +903,9 @@ void create_voxel(Plot pl) // Write current date and time write_attribute(file_id, "date_and_time", time_stamp().c_str()); hsize_t three = 3; - write_attr_int(file_id, 1, &three, "num_voxels", pl.pixels_); - write_attr_double(file_id, 1, &three, "voxel_width", vox); - write_attr_double(file_id, 1, &three, "lower_left", ll); + write_attribute(file_id, "num_voxels", pl.pixels_); + write_attribute(file_id, "voxel_width", vox); + write_attribute(file_id, "lower_left", ll); // Create dataset for voxel data -- note that the dimensions are reversed // since we want the order in the file to be z, y, x From 51578a7342e47f420037227c0e82c664ae3c2667 Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Tue, 30 Oct 2018 22:05:01 -0500 Subject: [PATCH 087/105] Style correction. --- include/openmc/plot.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/openmc/plot.h b/include/openmc/plot.h index f0ed3016b..a3e527456 100644 --- a/include/openmc/plot.h +++ b/include/openmc/plot.h @@ -106,7 +106,7 @@ public: //! Add mesh lines to image data of a plot object //! \param[in] plot object //! \param[out] image data associated with the plot object -void draw_mesh_lines(Plot pl, ImageData &data); +void draw_mesh_lines(Plot pl, ImageData& data); //! Write a ppm image to file using a plot object's image data //! \param[in] plot object From 66bdf04511e9ab999ea167fd3fa729f26c04bd93 Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Tue, 30 Oct 2018 22:30:45 -0500 Subject: [PATCH 088/105] Updating RGBColor to a char array. --- include/openmc/plot.h | 2 +- src/plot.cpp | 15 +++++++++++---- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/include/openmc/plot.h b/include/openmc/plot.h index a3e527456..8d9a11ff9 100644 --- a/include/openmc/plot.h +++ b/include/openmc/plot.h @@ -35,7 +35,7 @@ extern std::vector plots; //!< Plot instance container // RGBColor holds color information for plotted objects //=============================================================================== -typedef std::array RGBColor; +typedef std::array RGBColor; typedef xt::xtensor ImageData; diff --git a/src/plot.cpp b/src/plot.cpp index e1cbdb2d1..d6f54b90a 100644 --- a/src/plot.cpp +++ b/src/plot.cpp @@ -1,4 +1,5 @@ #include +#include #include "openmc/plot.h" #include "openmc/constants.h" @@ -22,6 +23,12 @@ namespace openmc { // Global variables //============================================================================== +const char* to_char(int i) { + std::stringstream s; + s << i; + return s.str().c_str(); + } + int PLOT_LEVEL_LOWEST = -1; std::unordered_map plot_map; @@ -30,7 +37,7 @@ int n_plots; std::vector plots; -const RGBColor WHITE = {255, 255, 255}; +const RGBColor WHITE = {static_cast(255), static_cast(255), static_cast(255)}; const RGBColor NULLRGB = {0, 0, 0}; //============================================================================== @@ -734,9 +741,9 @@ void output_ppm(Plot pl, const ImageData& data) for (int y = 0; y < pl.pixels_[1]; y++) { for (int x = 0; x < pl.pixels_[0]; x++) { RGBColor rgb = data(x,y); - of.write(reinterpret_cast(&rgb[RED]), 1); - of.write(reinterpret_cast(&rgb[GREEN]), 1); - of.write(reinterpret_cast(&rgb[BLUE]), 1); + of.write(&rgb[RED], 1); + of.write(&rgb[GREEN], 1); + of.write(&rgb[BLUE], 1); } } // Close file From cd3b05a3f65c13b9cf6c347ce1a8b9acaa5152fc Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Wed, 31 Oct 2018 09:05:44 -0500 Subject: [PATCH 089/105] Moving error message block into if-else. --- src/plot.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/plot.cpp b/src/plot.cpp index d6f54b90a..aa649c531 100644 --- a/src/plot.cpp +++ b/src/plot.cpp @@ -183,17 +183,16 @@ Plot::set_type(pugi::xml_node plot_node) // set type using node value if (type_str == "slice") { type_ = PlotType::slice; - return; } else if (type_str == "voxel") { type_ = PlotType::voxel; - return; - } + } else { // if we're here, something is wrong std::stringstream err_msg; err_msg << "Unsupported plot type '" << type_str << "' in plot " << id_; fatal_error(err_msg.str()); + } } } From 43488e02861c140fc9554dede7d9fda64cf6b298 Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Wed, 31 Oct 2018 15:14:14 -0500 Subject: [PATCH 090/105] Use unsigned char in RGBColor. --- include/openmc/plot.h | 2 +- src/plot.cpp | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/include/openmc/plot.h b/include/openmc/plot.h index 8d9a11ff9..a71b8926c 100644 --- a/include/openmc/plot.h +++ b/include/openmc/plot.h @@ -35,7 +35,7 @@ extern std::vector plots; //!< Plot instance container // RGBColor holds color information for plotted objects //=============================================================================== -typedef std::array RGBColor; +typedef std::array RGBColor; typedef xt::xtensor ImageData; diff --git a/src/plot.cpp b/src/plot.cpp index aa649c531..e08606787 100644 --- a/src/plot.cpp +++ b/src/plot.cpp @@ -37,7 +37,7 @@ int n_plots; std::vector plots; -const RGBColor WHITE = {static_cast(255), static_cast(255), static_cast(255)}; +const RGBColor WHITE {static_cast(255), static_cast(255), static_cast(255)}; const RGBColor NULLRGB = {0, 0, 0}; //============================================================================== @@ -740,9 +740,9 @@ void output_ppm(Plot pl, const ImageData& data) for (int y = 0; y < pl.pixels_[1]; y++) { for (int x = 0; x < pl.pixels_[0]; x++) { RGBColor rgb = data(x,y); - of.write(&rgb[RED], 1); - of.write(&rgb[GREEN], 1); - of.write(&rgb[BLUE], 1); + of.write(reinterpret_cast(&rgb[RED]), 1); + of.write(reinterpret_cast(&rgb[GREEN]), 1); + of.write(reinterpret_cast(&rgb[BLUE]), 1); } } // Close file From be10bc17810a7ece6d7276bcc22e6a5ff5452b63 Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Wed, 31 Oct 2018 15:26:32 -0500 Subject: [PATCH 091/105] Making RGBColor a struct. --- include/openmc/plot.h | 40 ++++++++++++++++++++++++++++++++++++++-- src/plot.cpp | 2 +- 2 files changed, 39 insertions(+), 3 deletions(-) diff --git a/include/openmc/plot.h b/include/openmc/plot.h index a71b8926c..512306068 100644 --- a/include/openmc/plot.h +++ b/include/openmc/plot.h @@ -35,8 +35,44 @@ extern std::vector plots; //!< Plot instance container // RGBColor holds color information for plotted objects //=============================================================================== -typedef std::array RGBColor; - +struct RGBColor { + //Constructors + RGBColor() : red(0), green(0), blue(0) { }; + RGBColor(const int v[3]) : red(v[RED]), green(v[GREEN]), blue(v[BLUE]) { }; + RGBColor(int r, int g, int b) : red(r), green(g), blue(b) { }; + + RGBColor(const std::vector &v) { + assert(v.size() == 3); + red = v[0]; + green = v[1]; + blue = v[2]; + } + + // Index operators + const unsigned char& operator[](int i) const { + switch (i) { + case 0: return red; + case 1: return blue; + case 2: return green; + default: + throw std::out_of_range{"Index in RGBColor must be between 0 and 2."}; + } + } + + unsigned char& operator[](int i) { + switch (i) { + case 0: return red; + case 1: return blue; + case 2: return green; + default: + throw std::out_of_range{"Index in RGBColor must be between 0 and 2."}; + } + } + + // Members + unsigned char red, green, blue; +}; + typedef xt::xtensor ImageData; enum class PlotType { diff --git a/src/plot.cpp b/src/plot.cpp index e08606787..6f80dbe4c 100644 --- a/src/plot.cpp +++ b/src/plot.cpp @@ -37,7 +37,7 @@ int n_plots; std::vector plots; -const RGBColor WHITE {static_cast(255), static_cast(255), static_cast(255)}; + const RGBColor WHITE(255,255,255);// {static_cast(255), static_cast(255), static_cast(255)}; const RGBColor NULLRGB = {0, 0, 0}; //============================================================================== From fd6ee5938df138b06fcbeb53d59d620948a30e87 Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Wed, 31 Oct 2018 15:42:08 -0500 Subject: [PATCH 092/105] Taking advantage of the RGBColor struct. --- include/openmc/plot.h | 12 +++++++---- src/plot.cpp | 50 ++++++++++++++++--------------------------- 2 files changed, 27 insertions(+), 35 deletions(-) diff --git a/include/openmc/plot.h b/include/openmc/plot.h index 512306068..e5f2ac456 100644 --- a/include/openmc/plot.h +++ b/include/openmc/plot.h @@ -52,8 +52,8 @@ struct RGBColor { const unsigned char& operator[](int i) const { switch (i) { case 0: return red; - case 1: return blue; - case 2: return green; + case 1: return green; + case 2: return blue; default: throw std::out_of_range{"Index in RGBColor must be between 0 and 2."}; } @@ -62,8 +62,8 @@ struct RGBColor { unsigned char& operator[](int i) { switch (i) { case 0: return red; - case 1: return blue; - case 2: return green; + case 1: return green; + case 2: return blue; default: throw std::out_of_range{"Index in RGBColor must be between 0 and 2."}; } @@ -195,6 +195,10 @@ void create_ppm(Plot pl); //! \param[in] plot object void create_voxel(Plot pl); +//! Create a randomly generated RGB color +//! \return RGBColor with random value +RGBColor rdm_color(); + } // namespace openmc #endif // OPENMC_PLOT_H diff --git a/src/plot.cpp b/src/plot.cpp index 6f80dbe4c..99858811c 100644 --- a/src/plot.cpp +++ b/src/plot.cpp @@ -37,7 +37,7 @@ int n_plots; std::vector plots; - const RGBColor WHITE(255,255,255);// {static_cast(255), static_cast(255), static_cast(255)}; +const RGBColor WHITE = {255, 255, 255}; const RGBColor NULLRGB = {0, 0, 0}; //============================================================================== @@ -140,9 +140,7 @@ void create_ppm(Plot pl) int id; p.coord[0].xyz[in_i] = xyz[in_i] + in_pixel * x; position_rgb(p, pl, rgb, id); - data(x,y)[RED] = rgb[RED]; - data(x,y)[GREEN] = rgb[GREEN]; - data(x,y)[BLUE] = rgb[BLUE]; + data(x,y) = rgb; } } } @@ -259,9 +257,7 @@ Plot::set_bg_color(pugi::xml_node plot_node) } } if (bg_rgb.size() == 3) { - not_found_[RED] = bg_rgb[RED]; - not_found_[GREEN] = bg_rgb[GREEN]; - not_found_[BLUE] = bg_rgb[BLUE]; + not_found_ = bg_rgb; } else { std::stringstream err_msg; err_msg << "Bad background RGB in plot " @@ -270,9 +266,7 @@ Plot::set_bg_color(pugi::xml_node plot_node) } } else { // default to a white background - not_found_[RED] = 255; - not_found_[GREEN] = 255; - not_found_[BLUE] = 255; + not_found_ = WHITE; } } @@ -375,18 +369,14 @@ Plot::set_default_colors(pugi::xml_node plot_node) color_by_ = PlotColorBy::cells; colors_.resize(n_cells); for (int i = 0; i < n_cells; i++) { - colors_[i][RED] = int(prn()*255); - colors_[i][GREEN] = int(prn()*255); - colors_[i][BLUE] = int(prn()*255); + colors_[i] = rdm_color(); } } else if("material" == pl_color_by) { color_by_ = PlotColorBy::mats; colors_.resize(n_materials); for (int i = 0; i < materials.size(); i++) { - colors_[i][RED] = int(prn()*255); - colors_[i][GREEN] = int(prn()*255); - colors_[i][BLUE] = int(prn()*255); + colors_[i] = rdm_color(); } } else { std::stringstream err_msg; @@ -430,9 +420,7 @@ Plot::set_user_colors(pugi::xml_node plot_node) if (PlotColorBy::cells == color_by_) { if (cell_map.find(col_id) != cell_map.end()) { col_id = cell_map[col_id]; - colors_[col_id][RED] = user_rgb[RED]; - colors_[col_id][GREEN] = user_rgb[GREEN]; - colors_[col_id][BLUE] = user_rgb[BLUE]; + colors_[col_id] = user_rgb; } else { std::stringstream err_msg; err_msg << "Could not find cell " << col_id @@ -442,9 +430,7 @@ Plot::set_user_colors(pugi::xml_node plot_node) } else if (PlotColorBy::mats == color_by_) { if (material_map.find(col_id) != material_map.end()) { col_id = material_map[col_id]; - colors_[col_id][RED] = user_rgb[RED]; - colors_[col_id][GREEN] = user_rgb[GREEN]; - colors_[col_id][BLUE] = user_rgb[BLUE]; + colors_[col_id] = user_rgb; } else { std::stringstream err_msg; err_msg << "Could not find material " << col_id @@ -628,13 +614,9 @@ Plot::set_mask(pugi::xml_node plot_node) if (std::find(iarray.begin(), iarray.end(), j) == iarray.end()) { if (check_for_node(mask_node, "background")) { std::vector bg_rgb = get_node_array(mask_node, "background"); - colors_[j][RED] = bg_rgb[RED]; - colors_[j][GREEN] = bg_rgb[GREEN]; - colors_[j][BLUE] = bg_rgb[BLUE]; + colors_[j] = bg_rgb; } else { - colors_[j][RED] = 255; - colors_[j][GREEN] = 255; - colors_[j][BLUE] = 255; + colors_[j] = WHITE; } } } @@ -758,9 +740,7 @@ void output_ppm(Plot pl, const ImageData& data) void draw_mesh_lines(Plot pl, ImageData& data) { RGBColor rgb; - rgb[RED] = pl.meshlines_color_[RED]; - rgb[GREEN] = pl.meshlines_color_[GREEN]; - rgb[BLUE] = pl.meshlines_color_[BLUE]; + rgb = pl.meshlines_color_; int outer, inner; switch(pl.basis_) { @@ -999,4 +979,12 @@ voxel_finalize(hid_t dspace, hid_t dset, hid_t memspace) H5Sclose(memspace); } +RGBColor rdm_color() { + RGBColor rgb; + rgb[RED] = int(prn()*255); + rgb[GREEN] = int(prn()*255); + rgb[BLUE] = int(prn()*255); + return rgb; +} + } // namespace openmc From 168066c01f73e3850f4b7d69c3a29e16a9a8e6ea Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Wed, 31 Oct 2018 15:43:16 -0500 Subject: [PATCH 093/105] Removing NULLRGB def. --- src/plot.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/plot.cpp b/src/plot.cpp index 99858811c..03a872d62 100644 --- a/src/plot.cpp +++ b/src/plot.cpp @@ -38,7 +38,6 @@ int n_plots; std::vector plots; const RGBColor WHITE = {255, 255, 255}; -const RGBColor NULLRGB = {0, 0, 0}; //============================================================================== // RUN_PLOT controls the logic for making one or many plots @@ -691,7 +690,7 @@ void position_rgb(Particle p, Plot pl, RGBColor& rgb, int& id) rgb = pl.colors_[p.coord[j].cell]; id = cells[p.coord[j].cell]->id_; } else { - rgb = NULLRGB; + rgb = RGBColor(); id = -1; } From 73a068026f02d4dbd108922874c30aba645ce302 Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Wed, 31 Oct 2018 15:49:59 -0500 Subject: [PATCH 094/105] Removing unreachable block. --- src/plot.cpp | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/plot.cpp b/src/plot.cpp index 03a872d62..903f3280b 100644 --- a/src/plot.cpp +++ b/src/plot.cpp @@ -684,16 +684,11 @@ void position_rgb(Particle p, Plot pl, RGBColor& rgb, int& id) rgb = pl.colors_[p.material - 1]; id = materials[p.material - 1]->id_; } - } else if (PlotColorBy::cells == pl.color_by_) { // Assign color based on cell rgb = pl.colors_[p.coord[j].cell]; id = cells[p.coord[j].cell]->id_; - } else { - rgb = RGBColor(); - id = -1; } - } // endif found_cell } From 8fab7f421786f3b6e26fc26f2158a14983f9e3f4 Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Wed, 31 Oct 2018 17:55:18 -0500 Subject: [PATCH 095/105] Moving RGBColor to uint8_t. --- include/openmc/plot.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/openmc/plot.h b/include/openmc/plot.h index e5f2ac456..f633394a6 100644 --- a/include/openmc/plot.h +++ b/include/openmc/plot.h @@ -70,7 +70,7 @@ struct RGBColor { } // Members - unsigned char red, green, blue; + uint8_t red, green, blue; }; typedef xt::xtensor ImageData; From 3c3c3fb28248a5b92c5490341724d9ec864688c3 Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Fri, 2 Nov 2018 22:07:51 -0500 Subject: [PATCH 096/105] Renaming rdm_color function. --- include/openmc/plot.h | 2 +- src/plot.cpp | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/include/openmc/plot.h b/include/openmc/plot.h index f633394a6..fb379ae46 100644 --- a/include/openmc/plot.h +++ b/include/openmc/plot.h @@ -197,7 +197,7 @@ void create_voxel(Plot pl); //! Create a randomly generated RGB color //! \return RGBColor with random value -RGBColor rdm_color(); +RGBColor random_color(); } // namespace openmc diff --git a/src/plot.cpp b/src/plot.cpp index 903f3280b..38c0eb194 100644 --- a/src/plot.cpp +++ b/src/plot.cpp @@ -368,14 +368,14 @@ Plot::set_default_colors(pugi::xml_node plot_node) color_by_ = PlotColorBy::cells; colors_.resize(n_cells); for (int i = 0; i < n_cells; i++) { - colors_[i] = rdm_color(); + colors_[i] = random_color(); } } else if("material" == pl_color_by) { color_by_ = PlotColorBy::mats; colors_.resize(n_materials); for (int i = 0; i < materials.size(); i++) { - colors_[i] = rdm_color(); + colors_[i] = random_color(); } } else { std::stringstream err_msg; @@ -973,7 +973,7 @@ voxel_finalize(hid_t dspace, hid_t dset, hid_t memspace) H5Sclose(memspace); } -RGBColor rdm_color() { +RGBColor random_color() { RGBColor rgb; rgb[RED] = int(prn()*255); rgb[GREEN] = int(prn()*255); From 9ed73c3c962dc855b66428beba1c69e9850c7858 Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Fri, 2 Nov 2018 22:10:00 -0500 Subject: [PATCH 097/105] Removing unused function. --- src/plot.cpp | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/plot.cpp b/src/plot.cpp index 38c0eb194..43202ffdf 100644 --- a/src/plot.cpp +++ b/src/plot.cpp @@ -22,12 +22,6 @@ namespace openmc { //============================================================================== // Global variables //============================================================================== - -const char* to_char(int i) { - std::stringstream s; - s << i; - return s.str().c_str(); - } int PLOT_LEVEL_LOWEST = -1; From 148c588a394ba06859ab29317781401b5b231200 Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Fri, 2 Nov 2018 22:18:26 -0500 Subject: [PATCH 098/105] Updating random_color generation. --- src/plot.cpp | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/plot.cpp b/src/plot.cpp index 43202ffdf..3a538f2dd 100644 --- a/src/plot.cpp +++ b/src/plot.cpp @@ -968,11 +968,7 @@ voxel_finalize(hid_t dspace, hid_t dset, hid_t memspace) } RGBColor random_color() { - RGBColor rgb; - rgb[RED] = int(prn()*255); - rgb[GREEN] = int(prn()*255); - rgb[BLUE] = int(prn()*255); - return rgb; + return {int(prn()*255), int(prn()*255), int(prn()*255)}; } } // namespace openmc From daffe0923dfbed78ee1d36f2589e33116c3b2ee7 Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Fri, 2 Nov 2018 22:33:09 -0500 Subject: [PATCH 099/105] Removing RGB index defs. Writing to ppm more cleanly. --- include/openmc/plot.h | 27 +-------------------------- src/plot.cpp | 21 +++++++++------------ 2 files changed, 10 insertions(+), 38 deletions(-) diff --git a/include/openmc/plot.h b/include/openmc/plot.h index fb379ae46..fa9ca171f 100644 --- a/include/openmc/plot.h +++ b/include/openmc/plot.h @@ -18,10 +18,6 @@ namespace openmc { // Global variables //=============================================================================== -constexpr int RED = 0; -constexpr int GREEN = 1; -constexpr int BLUE = 2; - extern int PLOT_LEVEL_LOWEST; //!< lower bound on plot universe level extern std::unordered_map plot_map; //!< map of plot ids to index @@ -38,7 +34,7 @@ extern std::vector plots; //!< Plot instance container struct RGBColor { //Constructors RGBColor() : red(0), green(0), blue(0) { }; - RGBColor(const int v[3]) : red(v[RED]), green(v[GREEN]), blue(v[BLUE]) { }; + RGBColor(const int v[3]) : red(v[0]), green(v[1]), blue(v[2]) { }; RGBColor(int r, int g, int b) : red(r), green(g), blue(b) { }; RGBColor(const std::vector &v) { @@ -48,27 +44,6 @@ struct RGBColor { blue = v[2]; } - // Index operators - const unsigned char& operator[](int i) const { - switch (i) { - case 0: return red; - case 1: return green; - case 2: return blue; - default: - throw std::out_of_range{"Index in RGBColor must be between 0 and 2."}; - } - } - - unsigned char& operator[](int i) { - switch (i) { - case 0: return red; - case 1: return green; - case 2: return blue; - default: - throw std::out_of_range{"Index in RGBColor must be between 0 and 2."}; - } - } - // Members uint8_t red, green, blue; }; diff --git a/src/plot.cpp b/src/plot.cpp index 3a538f2dd..f0f647679 100644 --- a/src/plot.cpp +++ b/src/plot.cpp @@ -481,13 +481,7 @@ Plot::set_meshlines(pugi::xml_node plot_node) err_msg << "Bad RGB for meshlines color in plot " << id_; fatal_error(err_msg); } - meshlines_color_[0] = ml_rgb[0]; - meshlines_color_[1] = ml_rgb[1]; - meshlines_color_[2] = ml_rgb[2]; - } else { - meshlines_color_[0] = 0; - meshlines_color_[1] = 0; - meshlines_color_[2] = 0; + meshlines_color_ = ml_rgb; } // Set mesh based on type @@ -710,11 +704,10 @@ void output_ppm(Plot pl, const ImageData& data) for (int y = 0; y < pl.pixels_[1]; y++) { for (int x = 0; x < pl.pixels_[0]; x++) { RGBColor rgb = data(x,y); - of.write(reinterpret_cast(&rgb[RED]), 1); - of.write(reinterpret_cast(&rgb[GREEN]), 1); - of.write(reinterpret_cast(&rgb[BLUE]), 1); + of << rgb.red << rgb.green << rgb.blue; } } + // Close file // THIS IS HERE TO MATCH FORTRAN VERSION, NOT TECHNICALLY NECESSARY of << "\n"; @@ -902,7 +895,6 @@ void create_voxel(Plot pl) RGBColor rgb; int id; for (int x = 0; x < pl.pixels_[0]; x++) { - // TODO: progress bar here pb.set_value(100.*(double)x/(double)(pl.pixels_[0]-1)); for (int y = 0; y < pl.pixels_[1]; y++) { for (int z = 0; z < pl.pixels_[2]; z++) { @@ -968,7 +960,12 @@ voxel_finalize(hid_t dspace, hid_t dset, hid_t memspace) } RGBColor random_color() { - return {int(prn()*255), int(prn()*255), int(prn()*255)}; + RGBColor rgb; + rgb.red = int(prn()*255); + rgb.green = int(prn()*255); + rgb.blue = int(prn()*255); + return rgb; + // return {int(prn()*255), int(prn()*255), int(prn()*255)}; } } // namespace openmc From f52664b29f297afee6c8e80c7ec1c4fbfe51f8f5 Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Fri, 2 Nov 2018 22:35:47 -0500 Subject: [PATCH 100/105] Fixing custom plot naming. --- src/plot.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/plot.cpp b/src/plot.cpp index f0f647679..6a28d2653 100644 --- a/src/plot.cpp +++ b/src/plot.cpp @@ -192,10 +192,11 @@ Plot::set_output_path(pugi::xml_node plot_node) { // Set output file path std::stringstream filename; - filename << "plot_" << id_; if (check_for_node(plot_node, "filename")) { filename << get_node_value(plot_node, "filename"); + } else { + filename << "plot_" << id_; } // add appropriate file extension to name switch(type_) { From 6de340e39a473729830ec846c44986787884bc34 Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Fri, 2 Nov 2018 22:39:22 -0500 Subject: [PATCH 101/105] Adding new line upon progress bar completion. --- src/progress_bar.cpp | 3 ++- tests/regression_tests/plot/plots.xml | 6 ++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/progress_bar.cpp b/src/progress_bar.cpp index 44a7e2496..8518c10fa 100644 --- a/src/progress_bar.cpp +++ b/src/progress_bar.cpp @@ -60,7 +60,8 @@ ProgressBar::set_value(double val) { // write the bar std::cout << '\r' << bar << std::flush; - + if (val >= 100.0) { std::cout << "\n"; } + // reset the bar value bar = ""; } diff --git a/tests/regression_tests/plot/plots.xml b/tests/regression_tests/plot/plots.xml index ecfe69125..84c3f46c6 100644 --- a/tests/regression_tests/plot/plots.xml +++ b/tests/regression_tests/plot/plots.xml @@ -29,4 +29,10 @@ 20 20 10 + + 100 100 10 + 0. 0. 0. + 20 20 10 + + From bcc26f96ab03be46e0e45dda28c5b370c0ff7222 Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Fri, 2 Nov 2018 23:06:19 -0500 Subject: [PATCH 102/105] Throwing error for incorrect vector size in RGBColor constructor. --- include/openmc/plot.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/include/openmc/plot.h b/include/openmc/plot.h index fa9ca171f..f3e482696 100644 --- a/include/openmc/plot.h +++ b/include/openmc/plot.h @@ -38,7 +38,9 @@ struct RGBColor { RGBColor(int r, int g, int b) : red(r), green(g), blue(b) { }; RGBColor(const std::vector &v) { - assert(v.size() == 3); + if (v.size() != 3) { + throw std::out_of_range("Incorrect vector size for RGBColor."); + } red = v[0]; green = v[1]; blue = v[2]; From 8485b39d7e6f6beacc923ba557687f9bed17c8e8 Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Fri, 2 Nov 2018 23:08:10 -0500 Subject: [PATCH 103/105] Checking out correct version of plots.xml in test. --- tests/regression_tests/plot/plots.xml | 6 ------ 1 file changed, 6 deletions(-) diff --git a/tests/regression_tests/plot/plots.xml b/tests/regression_tests/plot/plots.xml index 84c3f46c6..ecfe69125 100644 --- a/tests/regression_tests/plot/plots.xml +++ b/tests/regression_tests/plot/plots.xml @@ -29,10 +29,4 @@ 20 20 10 - - 100 100 10 - 0. 0. 0. - 20 20 10 - - From dc3a7e726f7123364265249cd7f1e5437d8f8b10 Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Fri, 2 Nov 2018 23:08:51 -0500 Subject: [PATCH 104/105] Trailing whitespace removal. --- include/openmc/plot.h | 8 ++++---- src/plot.cpp | 19 +++++++------------ src/progress_bar.cpp | 10 +++++----- 3 files changed, 16 insertions(+), 21 deletions(-) diff --git a/include/openmc/plot.h b/include/openmc/plot.h index f3e482696..64c092ce8 100644 --- a/include/openmc/plot.h +++ b/include/openmc/plot.h @@ -36,7 +36,7 @@ struct RGBColor { RGBColor() : red(0), green(0), blue(0) { }; RGBColor(const int v[3]) : red(v[0]), green(v[1]), blue(v[2]) { }; RGBColor(int r, int g, int b) : red(r), green(g), blue(b) { }; - + RGBColor(const std::vector &v) { if (v.size() != 3) { throw std::out_of_range("Incorrect vector size for RGBColor."); @@ -49,7 +49,7 @@ struct RGBColor { // Members uint8_t red, green, blue; }; - + typedef xt::xtensor ImageData; enum class PlotType { @@ -67,7 +67,7 @@ enum class PlotColorBy { cells = 1, mats = 2 }; - + //=============================================================================== // Plot class //=============================================================================== @@ -176,6 +176,6 @@ void create_voxel(Plot pl); //! \return RGBColor with random value RGBColor random_color(); - + } // namespace openmc #endif // OPENMC_PLOT_H diff --git a/src/plot.cpp b/src/plot.cpp index 6a28d2653..7b0cddb63 100644 --- a/src/plot.cpp +++ b/src/plot.cpp @@ -22,7 +22,7 @@ namespace openmc { //============================================================================== // Global variables //============================================================================== - + int PLOT_LEVEL_LOWEST = -1; std::unordered_map plot_map; @@ -241,7 +241,7 @@ Plot::set_bg_color(pugi::xml_node plot_node) { // Copy plot background color if (check_for_node(plot_node, "background")) { - std::vector bg_rgb = get_node_array(plot_node, "background"); + std::vector bg_rgb = get_node_array(plot_node, "background"); if (PlotType::voxel == type_) { if (openmc_master) { std::stringstream err_msg; @@ -391,7 +391,7 @@ Plot::set_user_colors(pugi::xml_node plot_node) warning(err_msg); } } - + for (auto cn : plot_node.children("color")) { // Make sure 3 values are specified for RGB std::vector user_rgb = get_node_array(cn, "rgb"); @@ -549,7 +549,7 @@ Plot::set_mask(pugi::xml_node plot_node) { // Deal with masks pugi::xpath_node_set mask_nodes = plot_node.select_nodes("mask"); - + if (!mask_nodes.empty()) { if (PlotType::voxel == type_) { if (openmc_master) { @@ -564,7 +564,7 @@ Plot::set_mask(pugi::xml_node plot_node) pugi::xml_node mask_node = mask_nodes[0].node(); // Determine how many components there are and allocate - std::vector iarray = get_node_array(mask_node, "components"); + std::vector iarray = get_node_array(mask_node, "components"); if (iarray.size() == 0) { std::stringstream err_msg; err_msg << "Missing in mask of plot " << id_; @@ -748,7 +748,7 @@ void draw_mesh_lines(Plot pl, ImageData& data) xyz_ur_plot[0] = pl.origin_[0]; xyz_ur_plot[1] = pl.origin_[1]; xyz_ur_plot[2] = pl.origin_[2]; - + xyz_ll_plot[outer] = pl.origin_[outer] - pl.width_[0] / 2.; xyz_ll_plot[inner] = pl.origin_[inner] - pl.width_[1] / 2.; xyz_ur_plot[outer] = pl.origin_[outer] + pl.width_[0] / 2.; @@ -961,12 +961,7 @@ voxel_finalize(hid_t dspace, hid_t dset, hid_t memspace) } RGBColor random_color() { - RGBColor rgb; - rgb.red = int(prn()*255); - rgb.green = int(prn()*255); - rgb.blue = int(prn()*255); - return rgb; - // return {int(prn()*255), int(prn()*255), int(prn()*255)}; + return {int(prn()*255), int(prn()*255), int(prn()*255)}; } } // namespace openmc diff --git a/src/progress_bar.cpp b/src/progress_bar.cpp index 8518c10fa..7917f9ffd 100644 --- a/src/progress_bar.cpp +++ b/src/progress_bar.cpp @@ -28,7 +28,7 @@ void ProgressBar::set_value(double val) { if (!is_terminal()) return; - + // set the bar percentage if (val >= 100.0) { bar.append("100"); @@ -43,12 +43,12 @@ ProgressBar::set_value(double val) { bar.append("% |"); // remaining width of the bar int remaining_width = BAR_WIDTH - bar.size() - 2; - + // set the bar width if (val >= 100.0) { bar.append(remaining_width, '='); } else if (val < 0.0) { - bar.append(remaining_width, ' '); + bar.append(remaining_width, ' '); } else { int width = (int)((double)remaining_width*val/100); bar.append(width, '='); @@ -57,11 +57,11 @@ ProgressBar::set_value(double val) { } bar.append("|+"); - + // write the bar std::cout << '\r' << bar << std::flush; if (val >= 100.0) { std::cout << "\n"; } - + // reset the bar value bar = ""; } From 0b492fe3fe8f83ee34dfb920fd582da451ea0fa4 Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Sat, 3 Nov 2018 14:04:05 -0500 Subject: [PATCH 105/105] Removing progress_header. --- CMakeLists.txt | 1 - src/progress_header.F90 | 102 ---------------------------------------- 2 files changed, 103 deletions(-) delete mode 100644 src/progress_header.F90 diff --git a/CMakeLists.txt b/CMakeLists.txt index fd0bbf457..3dd1b8b2a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -344,7 +344,6 @@ add_library(libopenmc SHARED src/photon_physics.F90 src/physics_common.F90 src/physics.F90 - src/progress_header.F90 src/pugixml/pugixml_f.F90 src/random_lcg.F90 src/reaction_header.F90 diff --git a/src/progress_header.F90 b/src/progress_header.F90 deleted file mode 100644 index 5f462e0fa..000000000 --- a/src/progress_header.F90 +++ /dev/null @@ -1,102 +0,0 @@ -module progress_header - - use, intrinsic :: ISO_FORTRAN_ENV, only: OUTPUT_UNIT - - implicit none - -#ifdef UNIX - interface - function check_isatty(fd) bind(C, name = 'isatty') - use, intrinsic :: ISO_C_BINDING, only: c_int - integer(c_int) :: check_isatty - integer(c_int), value :: fd - end function check_isatty - end interface -#endif - -!=============================================================================== -! PROGRESSBAR -!=============================================================================== - - type ProgressBar - private - character(len=72) :: bar="???% | " // & - " |" - contains - procedure :: set_value => bar_set_value - end type ProgressBar - -contains - -!=============================================================================== -! IS_TERMINAL checks if output is currently being output to a terminal. Relies -! on a POSIX implementation of isatty, and defaults to false if that is not -! available -!=============================================================================== - - function is_terminal() result(istty) - logical :: istty - - istty = .true. - -#ifdef UNIX - if (check_isatty(1) == 0) istty = .false. -#else - istty = .false. -#endif - - end function is_terminal - -!=============================================================================== -! BAR_SET_VALUE prints the progress bar without advancing. The value is -! specified as percent completion, from 0 to 100. If the value is ever set to -! 100 or above, the bar is set to 100 and a newline is written. -!=============================================================================== - - subroutine bar_set_value(self, val) - - class(ProgressBar), intent(inout) :: self - real(8), intent(in) :: val - - integer :: i - - if (.not. is_terminal()) return - - ! set the percentage - if (val >= 100.) then - write(self % bar(1:3), "(I3)") 100 - else if (val <= 0.) then - write(self % bar(1:3), "(I3)") 0 - else - write(self % bar(1:3), "(I3)") int(val) - end if - - ! set the bar width - if (val >= 100.) then - do i=1,65 - write(self % bar(i+6:i+6), '(A)') '=' - end do - else - do i=1,int(dble(65)*val/100.) - write(self % bar(i+6:i+6), '(A)') '=' - end do - end if - - write(OUTPUT_UNIT, '(A1,A1,A72)', ADVANCE='no') '+', char(13), self % bar - flush(OUTPUT_UNIT) - - if (val >= 100.) then - - ! make new line - write(OUTPUT_UNIT, "(A)") "" - flush(OUTPUT_UNIT) - - ! reset the bar in case we want to use this instance again - self % bar = "???% | " // & - " |" - - end if - - end subroutine bar_set_value - -end module progress_header