26namespace fs = std::filesystem;
33size_t meshDimForBuiltin(
const std::string &deckName,
const std::shared_ptr<geom::GeomObject> &obj) {
34 if (obj->d_name ==
"annulus_object")
43 util::io::log(
"Testing circle mesh file output (gmsh_builtin_mesh)...\n");
45 const std::vector<double> center = {0.0, 0.0, 0.0};
46 const double radius = 0.001;
47 const double meshSize = radius / 5.0;
49 const fs::path outputDir =
"test_output/mesh_gen";
50 fs::create_directories(outputDir);
54 std::make_shared<geom::Circle>(radius,
util::Point(center[0], center[1], center[2]));
56 true,
true,
nullptr,
nullptr,
nullptr);
58 const bool mshOk = fs::exists(outputDir /
"circle.msh");
59 const bool vtkOk = fs::exists(outputDir /
"circle.vtk");
60 if (!mshOk || !vtkOk) {
61 util::io::log(
"Error: Expected circle.msh and circle.vtk under test_output/mesh_gen.\n");
71 }
catch (
const std::exception &e) {
72 util::io::log(std::format(
"Error in mesh generation: {}\n", e.what()));
84 const double meshSize = s / 5.0;
88 meshDeck.
d_filename = std::string(
"mesh_") + geomName +
".msh";
91 const auto modelJson =
93 json{{
"Dimension", dim},
94 {
"Final_Time", 0.001},
96 {
"Discretization_Type",
json{{
"Spatial",
"finite_difference"}, {
"Time",
"central_difference"}}},
97 {
"Populate_ElementNodeConnectivity",
true},
98 {
"Quad_Approximation_Order", 2},
99 {
"Particle_Sim_Type",
"Multi_Particle"},
107 if (
mesh.getNodes().empty()) {
108 util::io::log(std::format(
"Error: mesh check: {} produced zero nodes.\n", geomName));
112 const auto box =
geom->box();
113 const double tol = 4.0 * meshSize;
114 for (
const auto &p :
mesh.getNodes()) {
115 if (p.d_x < box.first.d_x - tol || p.d_y < box.first.d_y - tol || p.d_z < box.first.d_z - tol ||
116 p.d_x > box.second.d_x + tol || p.d_y > box.second.d_y + tol || p.d_z > box.second.d_z + tol) {
118 "Error: mesh check {}: node ({},{},{}) outside geometry box (tol {}).\n", geomName, p.d_x,
124 util::io::log(std::format(
" mesh check [ {} ] passed.\n", geomName));
126 }
catch (
const std::exception &e) {
127 util::io::log(std::format(
"Error: mesh check {}: {}\n", geomName, e.what()));
135 util::io::log(
"Starting mesh generator tests (loop over geom::getAcceptableGeometries)...\n");
137 bool allTestsPassed =
true;
141 allTestsPassed =
false;
144 const double s = 0.001;
145 util::io::log(
"Builtin Gmsh mesh checks (exampleGeomParams + bounding box)...\n");
148 if (name ==
"complex")
151 util::io::log(std::format(
"Mesh check failed for geometry: {}\n", name));
152 allTestsPassed =
false;
156 if (allTestsPassed) {
Defines annulus rectangle.
size_t d_dim
Dimension objects live in.
nlohmann::ordered_json json
bool testCircleMeshWritesFiles()
Circle: write .msh and .vtk via the built-in Gmsh path (file I/O check).
bool builtinMeshCheckForGeometry(const std::string &geomName, double s)
For one acceptable geometry name: exampleGeomParams → mesh in memory → non-empty nodes,...
size_t meshDimForBuiltin(const std::string &deckName, const std::shared_ptr< geom::GeomObject > &obj)
Model dimension for mesh deck (annulus deck names map to annulus_object with d_dim set).
std::shared_ptr< GeomObject > makeExampleGeomObject(const std::string &geom_type, const util::Point &c, double s)
One-liner: createGeomObject(exampleGeomParams(...)). Prefer this over per-class static factories so a...
const std::vector< std::string > & getAcceptableGeometries()
Returns list of acceptable geometries for PeriDEM simulation.
size_t getGeomTypeToDim(std::string type)
Returns list of acceptable geometries for PeriDEM simulation.
void generateBuiltinParticleMeshGmsh(const std::shared_ptr< geom::GeomObject > &geomObj, double h, const std::string &filenameStem, bool vtk_out, bool write_mesh_file, mesh::Mesh *out_mesh, const inp::MeshDeck *meshDeck, const inp::ModelDeck *modelDeck)
In-process Gmsh mesh from geom::GeomObject (after createGeomObject on deck / Particle data).
Collection of methods and data related to finite element and mesh.
void log(std::ostringstream &oss, bool screen_out=false, int printMpiRank=print_default_mpi_rank)
Global method to log the message.
Structure to read and store mesh related input data.
double d_hMeshing
Target spacing for in-built meshers only (Gmsh uniform / uniform rectangle grid).
std::string d_filename
Filename to read mesh data.
Structure to read and store model related input data.
static json getExampleJson(const json &given=json::object())
Returns the block with the given fields set.
A structure to represent 3d vectors.