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 2,
"Multi_Particle", 0);
100 if (
mesh.getNodes().empty()) {
101 util::io::log(std::format(
"Error: mesh check: {} produced zero nodes.\n", geomName));
105 const auto box =
geom->box();
106 const double tol = 4.0 * meshSize;
107 for (
const auto &p :
mesh.getNodes()) {
108 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 ||
109 p.d_x > box.second.d_x + tol || p.d_y > box.second.d_y + tol || p.d_z > box.second.d_z + tol) {
111 "Error: mesh check {}: node ({},{},{}) outside geometry box (tol {}).\n", geomName, p.d_x,
117 util::io::log(std::format(
" mesh check [ {} ] passed.\n", geomName));
119 }
catch (
const std::exception &e) {
120 util::io::log(std::format(
"Error: mesh check {}: {}\n", geomName, e.what()));
128 util::io::log(
"Starting mesh generator tests (loop over geom::getAcceptableGeometries)...\n");
130 bool allTestsPassed =
true;
134 allTestsPassed =
false;
137 const double s = 0.001;
138 util::io::log(
"Builtin Gmsh mesh checks (exampleGeomParams + bounding box)...\n");
141 if (name ==
"complex")
144 util::io::log(std::format(
"Mesh check failed for geometry: {}\n", name));
145 allTestsPassed =
false;
149 if (allTestsPassed) {
Defines annulus rectangle.
size_t d_dim
Dimension objects live in.
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(size_t dim=2, double tFinal=1.0, size_t Nt=10, std::string spatialDiscretization="finite_difference", std::string timeDiscretization="central_difference", bool populateElementNodeConnectivity=true, size_t quadOrder=2, std::string particleSimType="Multi_Particle", int seed=0)
Returns example JSON object for ModelDeck configuration.
A structure to represent 3d vectors.