Addressing more of @promano's comments.

This commit is contained in:
Patrick Shriwise 2019-03-14 11:02:19 -05:00
parent e7b3175da1
commit 14e4665301
3 changed files with 53 additions and 57 deletions

View file

@ -70,7 +70,7 @@ extern "C" {
int openmc_next_batch(int* status);
int openmc_nuclide_name(int index, const char** name);
int openmc_plot_geometry();
int openmc_id_map(const void* slice, int32_t *data_out);
int openmc_id_map(const void* slice, int32_t* data_out);
int openmc_reset();
int openmc_run();
void openmc_set_seed(int64_t new_seed);

View file

@ -26,8 +26,6 @@ class _Position(Structure):
def __repr__(self):
return "({}, {}, {})".format(self.x, self.y, self.z)
def __str__(self):
return self.__repr__()
class _PlotBase(Structure):
"""A structure defining a 2-D geometry slice with underlying c-types
@ -74,16 +72,15 @@ class _PlotBase(Structure):
@property
def origin(self):
out = [self.origin_.x, self.origin_.y, self.origin_.z]
return [float(val) for val in out]
return self.origin_
@property
def width(self):
return float(self.width_.x)
return self.width_.x
@property
def height(self):
return float(self.width_.y)
return self.width_.y
@property
def basis(self):
@ -94,7 +91,7 @@ class _PlotBase(Structure):
elif self.basis_ == 3:
return 'yz'
raise ValueError("Plot basis {} is invalid".format(basis_))
raise ValueError("Plot basis {} is invalid".format(self.basis_))
@property
def h_res(self):
@ -171,10 +168,7 @@ class _PlotBase(Structure):
"HRes: {}".format(self.h_res),
"VRes: {}".format(self.v_res),
"Level: {}".format(self.level)]
return '\n'.join(output)
def __str__(self):
return self.__repr__()
return '\n'.join(out_str)
_dll.openmc_id_map.argtypes = [POINTER(_PlotBase), POINTER(c_int32)]
@ -189,7 +183,7 @@ def id_map(plot):
Parameters
----------
plot : An openmc.capi.plot._PlotBase
plot : openmc.capi.plot._PlotBase
Object describing the slice of the model to be generated
Returns

View file

@ -1,5 +1,6 @@
#include "openmc/plot.h"
#include <algorithm>
#include <fstream>
#include <sstream>
@ -133,26 +134,27 @@ void create_ppm(Plot pl)
Direction u {0.5, 0.5, 0.5};
#pragma omp parallel
{
Particle p;
p.r() = r;
p.u() = u;
p.coord_[0].universe = model::root_universe;
#pragma omp parallel
{
Particle p;
p.r() = r;
p.u() = u;
p.coord_[0].universe = model::root_universe;
#pragma omp for
for (int y = 0; y < height; y++) {
p.r()[out_i] = r[out_i] - out_pixel * y;
for (int x = 0; x < width; x++) {
// local variables
RGBColor rgb;
int id;
p.r()[in_i] = r[in_i] + in_pixel * x;
position_rgb(p, pl, rgb, id);
data(x,y) = rgb;
#pragma omp for
for (int y = 0; y < height; y++) {
p.r()[out_i] = r[out_i] - out_pixel * y;
for (int x = 0; x < width; x++) {
// local variables
RGBColor rgb;
int id;
p.r()[in_i] = r[in_i] + in_pixel * x;
position_rgb(p, pl, rgb, id);
data(x,y) = rgb;
}
}
}
}
// draw mesh lines if present
if (pl.index_meshlines_mesh_ >= 0) {draw_mesh_lines(pl, data);}
@ -995,35 +997,35 @@ extern "C" int openmc_id_map(const void* plot, int32_t* data_out) {
// arbitrary direction
Direction dir = {0.5, 0.5, 0.5};
#pragma omp parallel
{
Particle p;
p.r() = xyz;
p.u() = dir;
p.coord_[0].universe = model::root_universe;
int level = plt->level_;
int j{};
#pragma omp parallel
{
Particle p;
p.r() = xyz;
p.u() = dir;
p.coord_[0].universe = model::root_universe;
int level = plt->level_;
int j{};
#pragma omp for
for (int y = 0; y < height; y++) {
p.r()[out_i] = xyz[out_i] - out_pixel * y;
for (int x = 0; x < width; x++) {
p.r()[in_i] = xyz[in_i] + in_pixel * x;
p.n_coord_ = 1;
// local variables
bool found_cell = find_cell(&p, 0);
j = p.n_coord_ - 1;
if (level >=0) {j = level + 1;}
if (found_cell) {
Cell* c = model::cells[p.coord_[j].cell].get();
data(y,x,0) = c->id_;
if (c->type_ != FILL_UNIVERSE && p.material_ != MATERIAL_VOID) {
data(y,x,1) = model::materials[p.material_]->id_;
#pragma omp for
for (int y = 0; y < height; y++) {
p.r()[out_i] = xyz[out_i] - out_pixel * y;
for (int x = 0; x < width; x++) {
p.r()[in_i] = xyz[in_i] + in_pixel * x;
p.n_coord_ = 1;
// local variables
bool found_cell = find_cell(&p, 0);
j = p.n_coord_ - 1;
if (level >=0) {j = level + 1;}
if (found_cell) {
Cell* c = model::cells[p.coord_[j].cell].get();
data(y,x,0) = c->id_;
if (c->type_ != FILL_UNIVERSE && p.material_ != MATERIAL_VOID) {
data(y,x,1) = model::materials[p.material_]->id_;
}
}
}
} // inner for
} // outer for
} // omp parallel
} // inner for
} // outer for
} // omp parallel
// write id data to array
std::copy(data.begin(), data.end(), data_out);