73 MeshDeck(std::string filename,
double h_meshing = -1.)
82 const std::vector<std::string> names = {
83 "File",
"Mesh_Size",
"Create_Mesh",
84 "Info",
"Write_Mesh_File",
"Void_Regions"};
87 const auto filename = given.value(
"File", std::string());
88 const auto h_meshing = given.value(
"Mesh_Size", -1.);
89 const auto createMeshInfo =
90 given.value(
"Info", std::string(
"gmsh_builtin_mesh"));
91 const auto writeMeshFile = given.value(
"Write_Mesh_File",
true);
92 const auto voidRegions = given.value(
93 "Void_Regions", std::vector<std::vector<double>>());
96 if (!filename.empty())
102 const bool create = given.value(
"Create_Mesh",
false) ||
103 (filename.empty() && h_meshing > 0.);
105 if (!(h_meshing > 0.))
106 throw std::runtime_error(
107 "MeshDeck::getExampleJson: mesh creation needs a positive "
110 {
"Info", createMeshInfo},
111 {
"Mesh_Size", h_meshing},
112 {
"Write_Mesh_File", writeMeshFile}},
114 for (
const auto &r : voidRegions) {
116 throw std::runtime_error(
117 "MeshDeck::getExampleJson: each Void_Regions entry needs 6 "
118 "values [xlo, ylo, zlo, xhi, yhi, zhi].");
120 if (!voidRegions.empty())
121 cm[
"Void_Regions"] = voidRegions;
122 j[
"CreateMesh"] = cm;
123 }
else if (filename.empty()) {
124 throw std::runtime_error(
125 "MeshDeck::getExampleJson: a mesh set needs a File or a Mesh_Size.");
147 static const std::vector<Field<MeshDeck>> &
fields() {
148 static const std::vector<Field<MeshDeck>> f = {
150 "Mesh file read, or written when one is generated"),
164 static const std::vector<Field<MeshDeck>> f = {
166 "Generate the mesh rather than read it"),
168 "Mesh generator used",
169 {{
"uniform",
"gmsh_builtin_mesh"}, {}, {}}),
171 "Element size the generator is asked for"),
173 "Write the generated mesh to File"),
186 if (j.find(
"CreateMesh") != j.end()) {
187 const auto &cm = j.at(
"CreateMesh");
192 j.find(
"Mesh_Size") != j.end())
196 if (cm.find(
"Void_Regions") != cm.end()) {
197 for (
const auto &r : cm.at(
"Void_Regions")) {
198 auto box = r.get<std::vector<double>>();
200 throw std::runtime_error(
201 "CreateMesh.Void_Regions entries need 6 values [xlo,ylo,zlo,xhi,yhi,zhi].");
208 throw std::runtime_error(
209 "In-built mesh creation requires CreateMesh.Mesh_Size (or legacy top-level Mesh_Size).");
212 throw std::runtime_error(
"Mesh filename can not be empty unless CreateMesh is enabled.");
223 std::string
printStr(
int nt = 0,
int lvl = 0)
const {
226 std::ostringstream oss;
227 oss << tabS <<
"------- MeshDeck --------" << std::endl << std::endl;
230 oss << tabS <<
"Void_Regions count = " <<
d_voidRegions.size() << std::endl;
231 oss << tabS <<
"The geometry of a generated mesh is Particle.Set_i at the "
232 <<
"same index." << std::endl;
233 oss << tabS << std::endl;
244 void print(
int nt = 0,
int lvl = 0)
const { std::cout <<
printStr(nt, lvl); }
nlohmann::ordered_json json
Collection of methods and database related to input.
Field< Deck > field(T Deck::*m, std::string key, T def, std::string doc, Accepts< T > accepts={}, std::function< bool(const T &)> emitIf=[](const T &) { return true;})
Declares a field that maps one key to one member.
void readFields(Deck &d, const json &j, const std::vector< Field< Deck > > &fs)
Reads every field of the table from the block.
void checkNames(const json &given, const std::vector< std::string > &names)
Rejects a key that is not among those named.
void printFields(const Deck &d, std::ostringstream &oss, const std::vector< Field< Deck > > &fs, const std::string &tab="")
Appends every field of the table to a stream.
json applyGiven(const json &given, const std::vector< Field< Deck > > &fs, const std::vector< std::string > &extra={})
The default block with the given keys replaced.
std::string getTabS(int nt)
Returns tab spaces of a given size.
Structure to read and store mesh related input data.
void readFromJson(const json &j)
static json getExampleJson(const json &given=json::object())
Returns example JSON object for ModelDeck configuration.
MeshDeck(std::string filename, double h_meshing=-1.)
Constructor for programmatic use (optional meshing size for tests).
static json getExampleJson(const std::string &)=delete
Rejects a value given where a set of named values is expected.
double d_hMeshing
Target spacing for in-built meshers only (Gmsh uniform / uniform rectangle grid).
MeshDeck(const json &j=json({}))
Constructor.
bool d_writeMeshFile
If true (default), Gmsh-based create-mesh paths write a .msh file; set false for in-memory only.
static const std::vector< Field< MeshDeck > > & createMeshFields()
The fields of the CreateMesh sub-block.
bool d_createMesh
Specify if we create mesh using in-built gmsh or in-built routine for uniform discretization of recta...
void print(int nt=0, int lvl=0) const
Prints the information about the object.
std::vector< std::vector< double > > d_voidRegions
Axis-aligned boxes emptied from an in-built uniform grid (CreateMesh.Void_Regions: [xlo,...
static const std::vector< Field< MeshDeck > > & fields()
Reads from json object.
std::string d_createMeshInfo
Selector for in-built mesh creation (e.g. uniform rectangle, gmsh_builtin_mesh for built-in geometrie...
static json getExampleJson(const char *)=delete
Rejects a value given where a set of named values is expected.
std::string printStr(int nt=0, int lvl=0) const
Returns the string containing printable information about the object.
std::string d_filename
Filename to read mesh data.