mirror of
https://github.com/openmc-dev/openmc.git
synced 2026-07-29 06:35:48 -04:00
Allowing a scaling factor for MOAB meshes too.
This commit is contained in:
parent
9165a836fe
commit
a6140709cc
2 changed files with 56 additions and 19 deletions
|
|
@ -331,6 +331,15 @@ public:
|
|||
true}; //!< Write tallies onto the unstructured mesh at the end of a run
|
||||
std::string filename_; //!< Path to unstructured mesh file
|
||||
|
||||
protected:
|
||||
//! Set the length multiplier to apply to each point in the mesh
|
||||
void set_length_multiplier(const double length_multiplier);
|
||||
|
||||
// Data members
|
||||
double length_multiplier_ {
|
||||
1.0}; //!< Constant multiplication factor to apply to mesh coordinates
|
||||
bool specified_length_multiplier_ {false};
|
||||
|
||||
private:
|
||||
//! Setup method for the mesh. Builds data structures,
|
||||
//! sets up element mapping, creates bounding boxes, etc.
|
||||
|
|
@ -344,7 +353,7 @@ public:
|
|||
// Constructors
|
||||
MOABMesh() = default;
|
||||
MOABMesh(pugi::xml_node);
|
||||
MOABMesh(const std::string& filename);
|
||||
MOABMesh(const std::string& filename, double length_multiplier = 1.0);
|
||||
MOABMesh(std::shared_ptr<moab::Interface> external_mbi);
|
||||
|
||||
// Overridden Methods
|
||||
|
|
@ -533,9 +542,6 @@ private:
|
|||
//! Translate an element pointer to a bin index
|
||||
int get_bin_from_element(const libMesh::Elem* elem) const;
|
||||
|
||||
//! Set the length multiplier to apply to each point in the mesh
|
||||
void set_length_multiplier(const double length_multiplier);
|
||||
|
||||
// Data members
|
||||
unique_ptr<libMesh::Mesh> m_; //!< pointer to the libMesh mesh instance
|
||||
vector<unique_ptr<libMesh::PointLocatorBase>>
|
||||
|
|
@ -550,8 +556,6 @@ private:
|
|||
libMesh::BoundingBox bbox_; //!< bounding box of the mesh
|
||||
libMesh::dof_id_type
|
||||
first_element_id_; //!< id of the first element in the mesh
|
||||
double length_multiplier_ {1.0}; //!< Constant multiplication factor to apply to mesh coordinates
|
||||
bool specified_length_multiplier_ {false};
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
|||
59
src/mesh.cpp
59
src/mesh.cpp
|
|
@ -172,6 +172,12 @@ UnstructuredMesh::UnstructuredMesh(pugi::xml_node node) : Mesh(node)
|
|||
}
|
||||
}
|
||||
|
||||
// check if a length unit multiplier was specified
|
||||
if (check_for_node(node, "length_multiplier")) {
|
||||
length_multiplier_ = std::stod(get_node_value(node, "length_multiplier"));
|
||||
specified_length_multiplier_ = true;
|
||||
}
|
||||
|
||||
// get the filename of the unstructured mesh to load
|
||||
if (check_for_node(node, "filename")) {
|
||||
filename_ = get_node_value(node, "filename");
|
||||
|
|
@ -222,6 +228,12 @@ void UnstructuredMesh::to_hdf5(hid_t group) const
|
|||
close_group(mesh_group);
|
||||
}
|
||||
|
||||
void UnstructuredMesh::set_length_multiplier(double length_multiplier)
|
||||
{
|
||||
length_multiplier_ = length_multiplier;
|
||||
specified_length_multiplier_ = true;
|
||||
}
|
||||
|
||||
void StructuredMesh::get_indices(Position r, int* ijk, bool* in_mesh) const
|
||||
{
|
||||
*in_mesh = true;
|
||||
|
|
@ -1586,9 +1598,14 @@ MOABMesh::MOABMesh(pugi::xml_node node) : UnstructuredMesh(node)
|
|||
initialize();
|
||||
}
|
||||
|
||||
MOABMesh::MOABMesh(const std::string& filename)
|
||||
MOABMesh::MOABMesh(const std::string& filename, double length_multiplier)
|
||||
{
|
||||
filename_ = filename;
|
||||
|
||||
if (length_multiplier != 1.0) {
|
||||
set_length_multiplier(length_multiplier);
|
||||
}
|
||||
|
||||
initialize();
|
||||
}
|
||||
|
||||
|
|
@ -1635,6 +1652,34 @@ void MOABMesh::initialize()
|
|||
fatal_error("Failed to add tetrahedra to an entity set.");
|
||||
}
|
||||
|
||||
if (specified_length_multiplier_) {
|
||||
// get the connectivity of all tets
|
||||
moab::Range adj;
|
||||
rval = mbi_->get_adjacencies(ehs_, 0, true, adj, moab::Interface::UNION);
|
||||
if (rval != moab::MB_SUCCESS) {
|
||||
fatal_error("Failed to get adjacent vertices of tetrahedra.");
|
||||
}
|
||||
// scale all vertex coords by multiplier (done individually so not all
|
||||
// coordinates are in memory twice at once)
|
||||
for (auto vert : adj) {
|
||||
// retrieve coords
|
||||
std::array<double, 3> coord;
|
||||
rval = mbi_->get_coords(&vert, 1, coord.data());
|
||||
if (rval != moab::MB_SUCCESS) {
|
||||
fatal_error("Could not get coordinates of vertex.");
|
||||
}
|
||||
// scale coords
|
||||
for (auto& c : coord) {
|
||||
c *= length_multiplier_;
|
||||
}
|
||||
// set new coords
|
||||
rval = mbi_->set_coords(&vert, 1, coord.data());
|
||||
if (rval != moab::MB_SUCCESS) {
|
||||
fatal_error("Failed to set new vertex coordinates");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// build acceleration data structures
|
||||
compute_barycentric_data(ehs_);
|
||||
build_kdtree(ehs_);
|
||||
|
|
@ -2142,12 +2187,6 @@ void MOABMesh::write(const std::string& base_filename) const
|
|||
|
||||
LibMesh::LibMesh(pugi::xml_node node) : UnstructuredMesh(node)
|
||||
{
|
||||
// check if a length unit multiplier was specified
|
||||
if (check_for_node(node, "length_multiplier")) {
|
||||
length_multiplier_ = std::stod(get_node_value(node, "length_multiplier"));
|
||||
specified_length_multiplier_ = true;
|
||||
}
|
||||
|
||||
initialize();
|
||||
}
|
||||
|
||||
|
|
@ -2162,12 +2201,6 @@ LibMesh::LibMesh(const std::string& filename, double length_multiplier)
|
|||
initialize();
|
||||
}
|
||||
|
||||
void LibMesh::set_length_multiplier(double length_multiplier)
|
||||
{
|
||||
length_multiplier_ = length_multiplier;
|
||||
specified_length_multiplier_ = true;
|
||||
}
|
||||
|
||||
void LibMesh::initialize()
|
||||
{
|
||||
if (!settings::libmesh_comm) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue