PeriDEM 0.3.0
PeriDEM -- Peridynamics-based high-fidelity model for granular media
Loading...
Searching...
No Matches
inp::MeshDeck Struct Reference

Structure to read and store mesh related input data. More...

#include <meshDeck.h>

Collaboration diagram for inp::MeshDeck:

Public Member Functions

 MeshDeck (const json &j=json({}))
 Constructor.
 
 MeshDeck (std::string filename, double h_meshing=-1.)
 Constructor for programmatic use (optional meshing size for tests).
 
void readFromJson (const json &j)
 
std::string printStr (int nt=0, int lvl=0) const
 Returns the string containing printable information about the object.
 
void print (int nt=0, int lvl=0) const
 Prints the information about the object.
 

Static Public Member Functions

static json getExampleJson (const json &given=json::object())
 Returns example JSON object for ModelDeck configuration.
 
static json getExampleJson (const std::string &)=delete
 Rejects a value given where a set of named values is expected.
 
static json getExampleJson (const char *)=delete
 Rejects a value given where a set of named values is expected.
 
static const std::vector< Field< MeshDeck > > & fields ()
 Reads from json object.
 
static const std::vector< Field< MeshDeck > > & createMeshFields ()
 The fields of the CreateMesh sub-block.
 

Data Fields

std::string d_filename
 Filename to read mesh data.
 
double d_hMeshing
 Target spacing for in-built meshers only (Gmsh uniform / uniform rectangle grid).
 
bool d_createMesh
 Specify if we create mesh using in-built gmsh or in-built routine for uniform discretization of rectangle/cuboid.
 
std::string d_createMeshInfo
 Selector for in-built mesh creation (e.g. uniform rectangle, gmsh_builtin_mesh for built-in geometries meshed in-process with Gmsh).
 
bool d_writeMeshFile
 If true (default), Gmsh-based create-mesh paths write a .msh file; set false for in-memory only.
 
std::vector< std::vector< double > > d_voidRegions
 Axis-aligned boxes emptied from an in-built uniform grid (CreateMesh.Void_Regions: [xlo,ylo,zlo,xhi,yhi,zhi]).
 

Detailed Description

Structure to read and store mesh related input data.

Definition at line 28 of file meshDeck.h.

Constructor & Destructor Documentation

◆ MeshDeck() [1/2]

inp::MeshDeck::MeshDeck ( const json &  j = json({}))
inline

Constructor.

Definition at line 66 of file meshDeck.h.

66 {})) : d_hMeshing(0.), d_createMesh(false), d_writeMeshFile(true) {
67 readFromJson(j);
68 };
void readFromJson(const json &j)
Definition meshDeck.h:178
double d_hMeshing
Target spacing for in-built meshers only (Gmsh uniform / uniform rectangle grid).
Definition meshDeck.h:40
bool d_writeMeshFile
If true (default), Gmsh-based create-mesh paths write a .msh file; set false for in-memory only.
Definition meshDeck.h:55
bool d_createMesh
Specify if we create mesh using in-built gmsh or in-built routine for uniform discretization of recta...
Definition meshDeck.h:46

◆ MeshDeck() [2/2]

inp::MeshDeck::MeshDeck ( std::string  filename,
double  h_meshing = -1. 
)
inline

Constructor for programmatic use (optional meshing size for tests).

Definition at line 73 of file meshDeck.h.

74 : d_filename(std::move(filename)), d_hMeshing(h_meshing > 0. ? h_meshing : 0.),
75 d_createMesh(false), d_writeMeshFile(true) {}
std::string d_filename
Filename to read mesh data.
Definition meshDeck.h:31

Member Function Documentation

◆ createMeshFields()

static const std::vector< Field< MeshDeck > > & inp::MeshDeck::createMeshFields ( )
inlinestatic

The fields of the CreateMesh sub-block.

The sub-block has a table of its own. Its members are members of this deck, so the two tables write into the same object.

Returns
fields The field table

Definition at line 163 of file meshDeck.h.

163 {
164 static const std::vector<Field<MeshDeck>> f = {
165 field(&MeshDeck::d_createMesh, "Flag", false,
166 "Generate the mesh rather than read it"),
167 field(&MeshDeck::d_createMeshInfo, "Info", std::string("uniform"),
168 "Mesh generator used",
169 {{"uniform", "gmsh_builtin_mesh"}, {}, {}}),
170 field(&MeshDeck::d_hMeshing, "Mesh_Size", 0.,
171 "Element size the generator is asked for"),
172 field(&MeshDeck::d_writeMeshFile, "Write_Mesh_File", true,
173 "Write the generated mesh to File"),
174 };
175 return f;
176 }
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.
Definition deckField.h:144
std::string d_createMeshInfo
Selector for in-built mesh creation (e.g. uniform rectangle, gmsh_builtin_mesh for built-in geometrie...
Definition meshDeck.h:52

References d_createMesh, d_createMeshInfo, d_hMeshing, d_writeMeshFile, and inp::field().

Referenced by getExampleJson(), printStr(), and readFromJson().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ fields()

static const std::vector< Field< MeshDeck > > & inp::MeshDeck::fields ( )
inlinestatic

Reads from json object.

The fields of the block itself

Returns
fields The field table

Definition at line 147 of file meshDeck.h.

147 {
148 static const std::vector<Field<MeshDeck>> f = {
149 field(&MeshDeck::d_filename, "File", std::string(),
150 "Mesh file read, or written when one is generated"),
151 };
152 return f;
153 }

References d_filename, and inp::field().

Referenced by printStr(), and readFromJson().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getExampleJson() [1/3]

static json inp::MeshDeck::getExampleJson ( const char *  )
staticdelete

Rejects a value given where a set of named values is expected.

A file name passed on its own would convert to a JSON string and be read as a set with no keys, so such a call is rejected when compiling.

◆ getExampleJson() [2/3]

static json inp::MeshDeck::getExampleJson ( const json &  given = json::object())
inlinestatic

Returns example JSON object for ModelDeck configuration.

Returns
JSON object with example configuration

Definition at line 81 of file meshDeck.h.

81 {
82 const std::vector<std::string> names = {
83 "File", "Mesh_Size", "Create_Mesh",
84 "Info", "Write_Mesh_File", "Void_Regions"};
85 checkNames(given, names);
86
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>>());
94
95 auto j = json({});
96 if (!filename.empty())
97 j["File"] = filename;
98
99 // A mesh size with no filename requests generation. Create_Mesh lets a
100 // set both generate a mesh and name the file it is written to or read
101 // back from.
102 const bool create = given.value("Create_Mesh", false) ||
103 (filename.empty() && h_meshing > 0.);
104 if (create) {
105 if (!(h_meshing > 0.))
106 throw std::runtime_error(
107 "MeshDeck::getExampleJson: mesh creation needs a positive "
108 "Mesh_Size.");
109 auto cm = applyGiven(json{{"Flag", true},
110 {"Info", createMeshInfo},
111 {"Mesh_Size", h_meshing},
112 {"Write_Mesh_File", writeMeshFile}},
113 createMeshFields(), {"Void_Regions"});
114 for (const auto &r : voidRegions) {
115 if (r.size() != 6)
116 throw std::runtime_error(
117 "MeshDeck::getExampleJson: each Void_Regions entry needs 6 "
118 "values [xlo, ylo, zlo, xhi, yhi, zhi].");
119 }
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.");
126 }
127 return j;
128 }
nlohmann::ordered_json json
void checkNames(const json &given, const std::vector< std::string > &names)
Rejects a key that is not among those named.
Definition deckField.h:379
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.
Definition deckField.h:443
static const std::vector< Field< MeshDeck > > & createMeshFields()
The fields of the CreateMesh sub-block.
Definition meshDeck.h:163

References inp::applyGiven(), inp::checkNames(), and createMeshFields().

Referenced by inp::ParticleDeck::getParticleMeshExampleJson(), and anonymous_namespace{testDeckRoundTrip.cpp}::testMeshDeck().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getExampleJson() [3/3]

static json inp::MeshDeck::getExampleJson ( const std::string &  )
staticdelete

Rejects a value given where a set of named values is expected.

A file name passed on its own would convert to a JSON string and be read as a set with no keys, so such a call is rejected when compiling.

◆ print()

void inp::MeshDeck::print ( int  nt = 0,
int  lvl = 0 
) const
inline

Prints the information about the object.

Parameters
ntNumber of tabs to append before printing
lvlInformation level (higher means more information)

Definition at line 244 of file meshDeck.h.

244{ std::cout << printStr(nt, lvl); }
std::string printStr(int nt=0, int lvl=0) const
Returns the string containing printable information about the object.
Definition meshDeck.h:223

References printStr().

Here is the call graph for this function:

◆ printStr()

std::string inp::MeshDeck::printStr ( int  nt = 0,
int  lvl = 0 
) const
inline

Returns the string containing printable information about the object.

Parameters
ntNumber of tabs to append before printing
lvlInformation level (higher means more information)
Returns
string String containing printable information about the object

Definition at line 223 of file meshDeck.h.

223 {
224
225 auto tabS = util::io::getTabS(nt);
226 std::ostringstream oss;
227 oss << tabS << "------- MeshDeck --------" << std::endl << std::endl;
228 printFields(*this, oss, fields(), tabS);
229 printFields(*this, oss, createMeshFields(), tabS + " ");
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;
234
235 return oss.str();
236 }
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.
Definition deckField.h:251
std::string getTabS(int nt)
Returns tab spaces of a given size.
Definition io.h:82
std::vector< std::vector< double > > d_voidRegions
Axis-aligned boxes emptied from an in-built uniform grid (CreateMesh.Void_Regions: [xlo,...
Definition meshDeck.h:61
static const std::vector< Field< MeshDeck > > & fields()
Reads from json object.
Definition meshDeck.h:147

References createMeshFields(), d_voidRegions, fields(), util::io::getTabS(), and inp::printFields().

Referenced by print().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ readFromJson()

void inp::MeshDeck::readFromJson ( const json &  j)
inline

Definition at line 178 of file meshDeck.h.

178 {
179 if (j.empty())
180 return;
181
182 readFields(*this, j, fields());
183 // Defaults of the sub-block apply whether or not it is present.
184 readFields(*this, json::object(), createMeshFields());
185
186 if (j.find("CreateMesh") != j.end()) {
187 const auto &cm = j.at("CreateMesh");
188 readFields(*this, cm, createMeshFields());
189
190 // A mesh size written beside the block rather than inside it.
191 if (cm.find("Mesh_Size") == cm.end() && d_createMesh &&
192 j.find("Mesh_Size") != j.end())
193 d_hMeshing = j.at("Mesh_Size").get<double>();
194
195 d_voidRegions.clear();
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>>();
199 if (box.size() != 6)
200 throw std::runtime_error(
201 "CreateMesh.Void_Regions entries need 6 values [xlo,ylo,zlo,xhi,yhi,zhi].");
202 d_voidRegions.push_back(std::move(box));
203 }
204 }
205 }
206
207 if (d_createMesh && d_hMeshing <= 0.)
208 throw std::runtime_error(
209 "In-built mesh creation requires CreateMesh.Mesh_Size (or legacy top-level Mesh_Size).");
210
211 if (d_filename.empty() && !d_createMesh) {
212 throw std::runtime_error("Mesh filename can not be empty unless CreateMesh is enabled.");
213 }
214 }
void readFields(Deck &d, const json &j, const std::vector< Field< Deck > > &fs)
Reads every field of the table from the block.
Definition deckField.h:230

References createMeshFields(), d_createMesh, d_filename, d_hMeshing, d_voidRegions, fields(), and inp::readFields().

Referenced by anonymous_namespace{testDeckRoundTrip.cpp}::testMeshDeck().

Here is the call graph for this function:
Here is the caller graph for this function:

Field Documentation

◆ d_createMesh

bool inp::MeshDeck::d_createMesh

Specify if we create mesh using in-built gmsh or in-built routine for uniform discretization of rectangle/cuboid.

Definition at line 46 of file meshDeck.h.

Referenced by createMeshFields(), mesh_gen::createParticleMesh(), and readFromJson().

◆ d_createMeshInfo

std::string inp::MeshDeck::d_createMeshInfo

Selector for in-built mesh creation (e.g. uniform rectangle, gmsh_builtin_mesh for built-in geometries meshed in-process with Gmsh).

Definition at line 52 of file meshDeck.h.

Referenced by createMeshFields(), and mesh_gen::createParticleMesh().

◆ d_filename

◆ d_hMeshing

double inp::MeshDeck::d_hMeshing

Target spacing for in-built meshers only (Gmsh uniform / uniform rectangle grid).

Read from CreateMesh.Mesh_Size in JSON. It drives mesh generation only; the characteristic length stored on mesh::Mesh is always computed from the generated nodes (same as for meshes read from file).

Definition at line 40 of file meshDeck.h.

Referenced by anonymous_namespace{testMeshGen.cpp}::builtinMeshCheckForGeometry(), createMeshFields(), mesh_gen::createParticleMesh(), and readFromJson().

◆ d_voidRegions

std::vector<std::vector<double> > inp::MeshDeck::d_voidRegions

Axis-aligned boxes emptied from an in-built uniform grid (CreateMesh.Void_Regions: [xlo,ylo,zlo,xhi,yhi,zhi]).

Definition at line 61 of file meshDeck.h.

Referenced by mesh_gen::createParticleMesh(), printStr(), and readFromJson().

◆ d_writeMeshFile

bool inp::MeshDeck::d_writeMeshFile

If true (default), Gmsh-based create-mesh paths write a .msh file; set false for in-memory only.

Definition at line 55 of file meshDeck.h.

Referenced by createMeshFields(), mesh_gen::createParticleMesh(), and anonymous_namespace{particleMesh.cpp}::maybeWriteMeshFile().


The documentation for this struct was generated from the following file: