PeriDEM 0.3.0
PeriDEM -- Peridynamics-based high-fidelity model for granular media
Loading...
Searching...
No Matches
modelDeck.h
Go to the documentation of this file.
1/*
2 * -------------------------------------------
3 * Copyright (c) 2021 - 2026 Prashant K. Jha
4 * -------------------------------------------
5 * PeriDEM https://github.com/prashjha/PeriDEM
6 *
7 * Distributed under the Boost Software License, Version 1.0. (See accompanying
8 * file LICENSE)
9 */
10
11#ifndef INP_MODELDECK_H
12#define INP_MODELDECK_H
13
14#include <string>
15#include <stdexcept>
16#include "deckField.h"
17#include "util/io.h"
18#include "util/json.h"
19
20namespace inp {
27 struct ModelDeck {
35 std::string d_simType;
36
39
50
60
63
66
73 std::string d_particleSimType;
74
84 std::string d_mpiStrategy;
85
89 std::string d_bondBreak;
90
95 std::vector<std::pair<size_t, double>> d_rigidParticles;
96
100 std::string d_selfContact;
101
105 std::string d_wallContact;
106
108 size_t d_dim;
109
111 double d_tFinal;
112
114 double d_dt;
115
117 size_t d_Nt;
118
121
125 ModelDeck(const json &j = json({}))
127 d_tFinal(0.), d_dt(0.), d_Nt(0),
128 d_particleSimType(""), d_mpiStrategy("auto"),
129 d_bondBreak("tension"), d_selfContact("broken_bond_kn"),
130 d_wallContact("meshed"), d_seed(0), d_quadOrder(1) {
131
132 readFromJson(j);
133 };
134
135 ModelDeck(size_t dim, double tFinal = 1.0, size_t Nt = 10,
136 std::string spatialDiscretization = "finite_difference",
137 std::string timeDiscretization = "central_difference",
138 bool populateElementNodeConnectivity = true,
139 size_t quadOrder = 2,
140 std::string particleSimType = "Multi_Particle",
141 int seed = 0)
142 : d_dim(dim), d_isRestartActive(false),
143 d_spatialDiscretization(spatialDiscretization),
144 d_timeDiscretization(timeDiscretization),
145 d_populateElementNodeConnectivity(populateElementNodeConnectivity),
146 d_tFinal(tFinal), d_dt(0.), d_Nt(Nt),
147 d_particleSimType(particleSimType), d_mpiStrategy("auto"),
148 d_bondBreak("tension"), d_selfContact("broken_bond_kn"),
149 d_wallContact("meshed"), d_seed(seed), d_quadOrder(quadOrder) {
150
151 if (d_timeDiscretization == "central_difference" or d_timeDiscretization == "velocity_verlet")
152 d_simType = "explicit";
153
154 if (std::abs(d_tFinal) < 1.0E-10 or d_Nt <= 0) {
155 throw std::runtime_error(
157 << "Error: Check Final_Time and Time_Steps data.\n");
158 }
159
160 d_dt = d_tFinal / d_Nt;
161 };
162
177 static const std::vector<Field<ModelDeck>> &fields() {
178 static const std::vector<Field<ModelDeck>> f = {
179 field(&ModelDeck::d_dim, "Dimension", size_t(2),
180 "Spatial dimension", {{size_t(1), size_t(2), size_t(3)}, {}, {}}),
181 field(&ModelDeck::d_tFinal, "Final_Time", 1.0,
182 "End of the integration window"),
183 field(&ModelDeck::d_Nt, "Time_Steps", size_t(10),
184 "Number of time steps", {{}, size_t(1), {}}),
186 "Populate_ElementNodeConnectivity", true,
187 "Build the element to node map, which strain output needs"),
188 field(&ModelDeck::d_quadOrder, "Quad_Approximation_Order", size_t(2),
189 "Order of the quadrature rule"),
190 field(&ModelDeck::d_particleSimType, "Particle_Sim_Type",
191 std::string("Multi_Particle"), "One body or many",
192 {{"Multi_Particle", "Single_Particle"}, {}, {}}),
193 field(&ModelDeck::d_mpiStrategy, "MPI_Strategy", std::string("auto"),
194 "What is distributed across ranks",
195 {{"auto", "none", "particle", "dof"}, {}, {}}),
196 field(&ModelDeck::d_bondBreak, "Bond_Break", std::string("tension"),
197 "Criterion for breaking a bond",
198 {{"tension", "absolute_stretch"}, {}, {}}),
199 field(&ModelDeck::d_selfContact, "Self_Contact",
200 std::string("broken_bond_kn"),
201 "Contact across broken bonds inside one body",
202 {{"broken_bond_kn", "reference_gap", "none"}, {}, {}}),
203 field(&ModelDeck::d_wallContact, "Wall_Contact",
204 std::string("meshed"), "How a wall is represented for contact",
205 {{"meshed", "analytical_plane"}, {}, {}}),
206 field(&ModelDeck::d_seed, "Seed", 0,
207 "Seed of the random number generator"),
208 };
209 return f;
210 }
211
217 static json getExampleJson(const json &given = json::object()) {
218 json j = applyGiven(given, fields(),
219 {"Discretization_Type", "Rigid_Particles"});
220 if (j.find("Discretization_Type") == j.end())
221 j["Discretization_Type"] = json{{"Spatial", "finite_difference"},
222 {"Time", "central_difference"}};
223 return j;
224 }
225
229 void readFromJson(const json &j) {
230 if (j.empty())
231 return;
232
233 readFields(*this, j, fields());
234
235 d_spatialDiscretization = j.at("Discretization_Type").at("Spatial");
236 d_timeDiscretization = j.at("Discretization_Type").at("Time");
237 if (d_timeDiscretization == "central_difference" or
238 d_timeDiscretization == "velocity_verlet")
239 d_simType = "explicit";
240
241 d_rigidParticles.clear();
242 if (j.find("Rigid_Particles") != j.end()) {
243 for (const auto &r : j.at("Rigid_Particles")) {
244 const double mass = r.value("Mass", -1.);
245 if (!(mass > 0.)) {
246 throw std::runtime_error(
248 << "Error: Model.Rigid_Particles entries need Mass > 0.\n");
249 }
250 d_rigidParticles.emplace_back(r.at("Id").get<size_t>(), mass);
251 }
252 }
253
254 if (std::abs(d_tFinal) < 1.0E-10 or d_Nt <= 0) {
255 throw std::runtime_error(
257 << "Error: Check Final_Time and Time_Steps data.\n");
258 }
259
260 d_dt = d_tFinal / d_Nt;
261 }
262
270 std::string printStr(int nt = 0, int lvl = 0) const {
271 auto tabS = util::io::getTabS(nt);
272 std::ostringstream oss;
273 oss << tabS << "------- ModelDeck --------" << std::endl << std::endl;
274 printFields(*this, oss, fields(), tabS);
275 oss << tabS << "Discretization_Type.Spatial = " << d_spatialDiscretization
276 << std::endl;
277 oss << tabS << "Discretization_Type.Time = " << d_timeDiscretization
278 << std::endl;
279 oss << tabS << "Simulation type = " << d_simType << std::endl;
280 oss << tabS << "Time step size = " << d_dt << std::endl;
281 oss << tabS << "Restart active = " << d_isRestartActive << std::endl;
282 oss << tabS << std::endl;
283
284 return oss.str();
285 }
286
293 void print(int nt = 0, int lvl = 0) const { std::cout << printStr(nt, lvl); }
294 };
295
297} // namespace inp
298
299#endif // INP_MODELDECK_H
Collects a message with stream syntax for use in an exception.
Definition io.h:52
nlohmann::ordered_json json
Collection of methods and database related to input.
Definition pairForce.h:20
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
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
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
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
std::string getTabS(int nt)
Returns tab spaces of a given size.
Definition io.h:82
Structure to read and store model related input data.
Definition modelDeck.h:27
bool d_populateElementNodeConnectivity
Flag to indicate if we should populate element-node connectivity data in meshes.
Definition modelDeck.h:62
std::string d_mpiStrategy
MPI domain-decomposition strategy (independent of Particle_Sim_Type).
Definition modelDeck.h:84
void readFromJson(const json &j)
Reads from json object.
Definition modelDeck.h:229
size_t d_quadOrder
Order of quadrature approximation for strain and stress computation (default is 1)
Definition modelDeck.h:65
ModelDeck(size_t dim, 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)
Definition modelDeck.h:135
size_t d_Nt
Number of time steps.
Definition modelDeck.h:117
static const std::vector< Field< ModelDeck > > & fields()
Returns example JSON object for ModelDeck configuration.
Definition modelDeck.h:177
size_t d_dim
Dimension.
Definition modelDeck.h:108
std::string d_selfContact
Intra-body self-contact law name (default broken_bond_kn).
Definition modelDeck.h:100
double d_tFinal
Final simulation time.
Definition modelDeck.h:111
std::string d_particleSimType
Specify if this is single or multi particle simulation Expected value is either 'Single_Particle' or ...
Definition modelDeck.h:73
ModelDeck(const json &j=json({}))
Constructor.
Definition modelDeck.h:125
std::string d_bondBreak
Bond failure criterion: tension (default) or absolute_stretch.
Definition modelDeck.h:89
std::string d_simType
Simulation type.
Definition modelDeck.h:35
std::vector< std::pair< size_t, double > > d_rigidParticles
Rigid translating particles: {"Id": <id>, "Mass": <mass>}. Nodal force densities are set to density *...
Definition modelDeck.h:95
int d_seed
Seed for random calculations (if any)
Definition modelDeck.h:120
std::string d_spatialDiscretization
Tag for spatial discretization.
Definition modelDeck.h:49
double d_dt
Size of time steps.
Definition modelDeck.h:114
std::string d_wallContact
Wall contact representation: meshed (default) or analytical_plane.
Definition modelDeck.h:105
bool d_isRestartActive
Flag indicating if this restart problem.
Definition modelDeck.h:38
std::string printStr(int nt=0, int lvl=0) const
Returns the string containing printable information about the object.
Definition modelDeck.h:270
void print(int nt=0, int lvl=0) const
Prints the information about the object.
Definition modelDeck.h:293
std::string d_timeDiscretization
Tag for time discretization.
Definition modelDeck.h:59
static json getExampleJson(const json &given=json::object())
Returns the block with the given fields set.
Definition modelDeck.h:217