Allowing a scaling factor for MOAB meshes too.

This commit is contained in:
Patrick Shriwise 2021-09-11 08:02:19 -05:00
parent 9165a836fe
commit a6140709cc
2 changed files with 56 additions and 19 deletions

View file

@ -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

View file

@ -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) {