Addressing comments and suggestions of @paulromano

manually run clang-format on mesh.cpp and mesh.h
This commit is contained in:
Olaf Schumann 2022-01-12 19:43:48 +00:00
parent fbc2c68eb7
commit 3b3294662e
5 changed files with 361 additions and 287 deletions

View file

@ -345,10 +345,10 @@ attributes/sub-elements:
:r_grid:
The mesh divisions along the r-axis. (For cylindrical and spherical meshes only.)
:p_grid:
:phi_grid:
The mesh divisions along the phi-axis. (For cylindrical and spherical meshes only.)
:t_grid:
:theta_grid:
The mesh divisions along the theta-axis. (For spherical mesh only.)
:library:

View file

@ -141,13 +141,14 @@ public:
struct MeshDistance {
MeshDistance() = default;
MeshDistance(int _index, bool _max_surface, double _distance):
nextIndex{_index}, max_surface{_max_surface}, distance{_distance}
{ }
int nextIndex { -1 };
double distance { INFTY };
bool max_surface { true };
bool operator<(const MeshDistance& o) const {
MeshDistance(int _index, bool _max_surface, double _distance)
: next_index {_index}, max_surface {_max_surface}, distance {_distance}
{}
int next_index {-1};
double distance {INFTY};
bool max_surface {true};
bool operator<(const MeshDistance& o) const
{
return distance < o.distance;
}
};
@ -169,9 +170,10 @@ public:
//! \param[in] r0 Previous position of the particle
//! \param[in] r1 Current position of the particle
//! \param[in] u Particle direction
//! \param[in] tally Functor that eventually stores the tally data
template <class T> void raytrace_mesh(Position r0, Position r1, const Direction& u,
T tally) const;
//! \param[in] tally Functor that eventually stores the tally data
template<class T>
void raytrace_mesh(
Position r0, Position r1, const Direction& u, T tally) const;
//! Count number of bank sites in each mesh bin / energy bin
//
@ -206,19 +208,21 @@ public:
//! \param[in] i Direction index
virtual int get_index_in_direction(double r, int i) const = 0;
//! Get the closest distance from the coordinate r to the grid surface
//! Get the closest distance from the coordinate r to the grid surface
//! in i direction that bounds mesh cell ijk and that is larger than l
//! The coordinate r does not have to be inside the mesh cell ijk. In
//! The coordinate r does not have to be inside the mesh cell ijk. In
//! curved coordinates, multiple crossings of the same surface can happen,
//! these are selected by the parameter l
//! these are selected by the parameter l
//!
//! \param[in] ijk Array of mesh indices
//! \param[in] i direction index of grid surface
//! \param[in] r0 position, from where to calculate the distance
//! \param[in] u direction of flight. actual position is r0 + l * u
//! \param[in] l actual chord length
//! \return MeshDistance struct with closest distance, next cell index in i-direction and min/max surface indicator
virtual MeshDistance distance_to_grid_boundary(const MeshIndex& ijk, int i, const Position& r0, const Direction& u, double l) const = 0;
//! \return MeshDistance struct with closest distance, next cell index in
//! i-direction and min/max surface indicator
virtual MeshDistance distance_to_grid_boundary(const MeshIndex& ijk, int i,
const Position& r0, const Direction& u, double l) const = 0;
//! Get a label for the mesh bin
std::string bin_label(int bin) const override;
@ -232,7 +236,6 @@ public:
std::array<int, 3> shape_; //!< Number of mesh elements in each dimension
protected:
};
//==============================================================================
@ -252,7 +255,8 @@ public:
static const std::string mesh_type;
MeshDistance distance_to_grid_boundary(const MeshIndex& ijk, int i, const Position& r0, const Direction& u, double l) const override;
MeshDistance distance_to_grid_boundary(const MeshIndex& ijk, int i,
const Position& r0, const Direction& u, double l) const override;
std::pair<vector<double>, vector<double>> plot(
Position plot_ll, Position plot_ur) const override;
@ -297,8 +301,9 @@ public:
virtual std::string get_mesh_type() const override;
static const std::string mesh_type;
MeshDistance distance_to_grid_boundary(const MeshIndex& ijk, int i, const Position& r0, const Direction& u, double l) const override;
MeshDistance distance_to_grid_boundary(const MeshIndex& ijk, int i,
const Position& r0, const Direction& u, double l) const override;
std::pair<vector<double>, vector<double>> plot(
Position plot_ll, Position plot_ur) const override;
@ -318,7 +323,6 @@ public:
//! \param[in] i Direction index
double negative_grid_boundary(const MeshIndex& ijk, int i) const;
array<vector<double>, 3> grid_;
int set_grid();
@ -339,7 +343,8 @@ public:
static const std::string mesh_type;
MeshDistance distance_to_grid_boundary(const MeshIndex& ijk, int i, const Position& r0, const Direction& u, double l) const override;
MeshDistance distance_to_grid_boundary(const MeshIndex& ijk, int i,
const Position& r0, const Direction& u, double l) const override;
std::pair<vector<double>, vector<double>> plot(
Position plot_ll, Position plot_ur) const override;
@ -351,13 +356,17 @@ public:
int set_grid();
private:
double find_r_crossing(const Position& r, const Direction& u, double l, int shell) const;
double find_phi_crossing(const Position& r, const Direction& u, double l, int shell) const;
StructuredMesh::MeshDistance find_z_crossing(const Position& r, const Direction& u, double l, int shell) const;
double find_r_crossing(
const Position& r, const Direction& u, double l, int shell) const;
double find_phi_crossing(
const Position& r, const Direction& u, double l, int shell) const;
StructuredMesh::MeshDistance find_z_crossing(
const Position& r, const Direction& u, double l, int shell) const;
bool full_phi_ { false };
bool full_phi_ {false};
constexpr inline int sanitize_angular_index(int idx, bool full, int N) const {
constexpr inline int sanitize_angular_index(int idx, bool full, int N) const
{
if ((idx > 0) and (idx <= N)) {
return idx;
} else if (full) {
@ -367,13 +376,12 @@ private:
}
}
inline int sanitize_phi(int idx) const {
inline int sanitize_phi(int idx) const
{
return sanitize_angular_index(idx, full_phi_, shape_[1]);
}
};
class SphericalMesh : public StructuredMesh {
public:
// Constructors
@ -389,7 +397,8 @@ public:
static const std::string mesh_type;
MeshDistance distance_to_grid_boundary(const MeshIndex& ijk, int i, const Position& r0, const Direction& u, double l) const override;
MeshDistance distance_to_grid_boundary(const MeshIndex& ijk, int i,
const Position& r0, const Direction& u, double l) const override;
std::pair<vector<double>, vector<double>> plot(
Position plot_ll, Position plot_ur) const override;
@ -401,14 +410,18 @@ public:
int set_grid();
private:
double find_r_crossing(const Position& r, const Direction& u, double l, int shell) const;
double find_theta_crossing(const Position& r, const Direction& u, double l, int shell) const;
double find_phi_crossing(const Position& r, const Direction& u, double l, int shell) const;
double find_r_crossing(
const Position& r, const Direction& u, double l, int shell) const;
double find_theta_crossing(
const Position& r, const Direction& u, double l, int shell) const;
double find_phi_crossing(
const Position& r, const Direction& u, double l, int shell) const;
bool full_theta_ { false };
bool full_phi_ { false };
bool full_theta_ {false};
bool full_phi_ {false};
constexpr inline int sanitize_angular_index(int idx, bool full, int N) const {
constexpr inline int sanitize_angular_index(int idx, bool full, int N) const
{
if ((idx > 0) and (idx <= N)) {
return idx;
} else if (full) {
@ -418,13 +431,14 @@ private:
}
}
inline int sanitize_theta(int idx) const {
inline int sanitize_theta(int idx) const
{
return sanitize_angular_index(idx, full_theta_, shape_[1]);
}
inline int sanitize_phi(int idx) const {
inline int sanitize_phi(int idx) const
{
return sanitize_angular_index(idx, full_phi_, shape_[2]);
}
};
// Abstract class for unstructured meshes
@ -438,7 +452,7 @@ public:
static const std::string mesh_type;
virtual std::string get_mesh_type() const override;
// Overridden Methods
void surface_bins_crossed(Position r0, Position r1, const Direction& u,
vector<int>& bins) const override;

View file

@ -725,13 +725,13 @@ class CylindricalMesh(MeshBase):
if self._r_grid is not None:
string += fmt.format('\tR Min:', '=\t', self._r_grid[0])
string += fmt.format('\tR Max:', '=\t', self._r_grid[-1])
t_grid_str = str(self._phi_grid) if self._phi_grid is None else len(self._phi_grid)
string += fmt.format('\tN Phi pnts:', '=\t', t_grid_str)
phi_grid_str = str(self._phi_grid) if self._phi_grid is None else len(self._phi_grid)
string += fmt.format('\tN Phi pnts:', '=\t', phi_grid_str)
if self._phi_grid is not None:
string += fmt.format('\tPhi Min:', '=\t', self._phi_grid[0])
string += fmt.format('\tPhi Max:', '=\t', self._phi_grid[-1])
p_grid_str = str(self._z_grid) if self._z_grid is None else len(self._z_grid)
string += fmt.format('\tN Z pnts:', '=\t', p_grid_str)
z_grid_str = str(self._z_grid) if self._z_grid is None else len(self._z_grid)
string += fmt.format('\tN Z pnts:', '=\t', z_grid_str)
if self._z_grid is not None:
string += fmt.format('\tZ Min:', '=\t', self._z_grid[0])
string += fmt.format('\tZ Max:', '=\t', self._z_grid[-1])
@ -744,7 +744,7 @@ class CylindricalMesh(MeshBase):
# Read and assign mesh properties
mesh = cls(mesh_id)
mesh.r_grid = group['r_grid'][()]
mesh.phi_grid = 180 / np.pi * group['p_grid'][()]
mesh.phi_grid = 180 / np.pi * group['phi_grid'][()]
mesh.z_grid = group['z_grid'][()]
return mesh
@ -766,7 +766,7 @@ class CylindricalMesh(MeshBase):
subelement = ET.SubElement(element, "r_grid")
subelement.text = ' '.join(map(str, self.r_grid))
subelement = ET.SubElement(element, "p_grid")
subelement = ET.SubElement(element, "phi_grid")
subelement.text = ' '.join(map(str, self.phi_grid))
subelement = ET.SubElement(element, "z_grid")
@ -889,13 +889,13 @@ class SphericalMesh(MeshBase):
if self._r_grid:
string += fmt.format('\tR Min:', '=\t', self._r_grid[0])
string += fmt.format('\tR Max:', '=\t', self._r_grid[-1])
t_grid_str = str(self._theta_grid) if not self._theta_grid else len(self._theta_grid)
string += fmt.format('\tN Theta pnts:', '=\t', t_grid_str)
theta_grid_str = str(self._theta_grid) if not self._theta_grid else len(self._theta_grid)
string += fmt.format('\tN Theta pnts:', '=\t', theta_grid_str)
if self._theta_grid:
string += fmt.format('\tTheta Min:', '=\t', self._theta_grid[0])
string += fmt.format('\tTheta Max:', '=\t', self._theta_grid[-1])
p_grid_str = str(self._phi_grid) if not self._phi_grid else len(self._phi_grid)
string += fmt.format('\tN Phi pnts:', '=\t', p_grid_str)
phi_grid_str = str(self._phi_grid) if not self._phi_grid else len(self._phi_grid)
string += fmt.format('\tN Phi pnts:', '=\t', phi_grid_str)
if self._phi_grid:
string += fmt.format('\tPhi Min:', '=\t', self._phi_grid[0])
string += fmt.format('\tPhi Max:', '=\t', self._phi_grid[-1])
@ -908,8 +908,8 @@ class SphericalMesh(MeshBase):
# Read and assign mesh properties
mesh = cls(mesh_id)
mesh.r_grid = group['r_grid'][()]
mesh.theta_grid = 180 / np.pi * group['t_grid'][()]
mesh.phi_grid = 180 / np.pi * group['p_grid'][()]
mesh.theta_grid = 180 / np.pi * group['theta_grid'][()]
mesh.phi_grid = 180 / np.pi * group['phi_grid'][()]
return mesh
@ -930,10 +930,10 @@ class SphericalMesh(MeshBase):
subelement = ET.SubElement(element, "r_grid")
subelement.text = ' '.join(map(str, self.r_grid))
subelement = ET.SubElement(element, "t_grid")
subelement = ET.SubElement(element, "theta_grid")
subelement.text = ' '.join(map(str, self.theta_grid))
subelement = ET.SubElement(element, "p_grid")
subelement = ET.SubElement(element, "phi_grid")
subelement.text = ' '.join(map(str, self.phi_grid))
return element

File diff suppressed because it is too large Load diff

View file

@ -29,8 +29,8 @@ element tallies {
attribute type { ( "cylindrical" ) }) &
(element r_grid { list { xsd:double+ } } |
attribute r_grid { list { xsd:double+ } }) &
(element p_grid { list { xsd:double+ } } |
attribute p_grid { list { xsd:double+ } }) &
(element phi_grid { list { xsd:double+ } } |
attribute phi_grid { list { xsd:double+ } }) &
(element z_grid { list { xsd:double+ } } |
attribute z_grid { list { xsd:double+ } })
) | (
@ -38,10 +38,10 @@ element tallies {
attribute type { ( "spherical" ) }) &
(element r_grid { list { xsd:double+ } } |
attribute r_grid { list { xsd:double+ } }) &
(element t_grid { list { xsd:double+ } } |
attribute p_grid { list { xsd:double+ } }) &
(element p_grid { list { xsd:double+ } } |
attribute z_grid { list { xsd:double+ } })
(element theta_grid { list { xsd:double+ } } |
attribute theta_grid { list { xsd:double+ } }) &
(element phi_grid { list { xsd:double+ } } |
attribute phi_grid { list { xsd:double+ } })
)
)
}* &