PeriDEM 0.3.0
PeriDEM -- Peridynamics-based high-fidelity model for granular media
Loading...
Searching...
No Matches
particleDeck.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_PARTICLEDECK_H
12#define INP_PARTICLEDECK_H
13
14#include "meshDeck.h"
15#include "materialDeck.h"
16#include "contactDeck.h"
17#include "pNeighborDeck.h"
18#include "pGenDeck.h"
19#include "geom/geomIncludes.h"
20#include "util/json.h"
21#include <memory>
22
23namespace inp {
24
32
39 std::string d_particleSimType;
40
42 std::vector<geom::GeomData> d_pGeomVec;
43
45 std::vector<inp::MeshDeck> d_pMeshVec;
46
48 std::vector<inp::MaterialDeck> d_pMaterialVec;
49
52
55
58
62 ParticleDeck(const json &j = json({}), std::string particleSimType = "Multi_Particle") {
63 d_particleSimType = particleSimType;
64 readFromJson(j);
65 };
66
67 void readFromJson(const json &j) {
68
69 if (j.find("Particle") != j.end())
70 readParticleGeomFromJson(j.at("Particle"));
71
72 if (j.find("Mesh") != j.end())
73 readParticleMeshFromJson(j.at("Mesh"));
74
75 if (j.find("Material") != j.end())
76 readParticleMaterialFromJson(j.at("Material"));
77
78 if (j.find("Contact") != j.end())
79 readParticleContactFromJson(j.at("Contact"));
80
81 if (j.find("Neighbor") != j.end())
82 readParticleNeighborFromJson(j.at("Neighbor"));
83
84 if (j.find("Particle_Generation") != j.end())
85 readParticleGenFromJson(j.at("Particle_Generation"));
86
87 if (d_pGeomVec.size() != d_pMeshVec.size())
88 throw std::runtime_error("Number of particle geometry groups must be equal to number of particle mesh groups");
89 }
90
95 static json getParticleGeomExampleJson(std::vector<geom::GeomData> pGeomVec = std::vector<geom::GeomData>()) {
96
97 auto nSets = pGeomVec.size();
98
99 if (nSets == 0)
100 return json({});
101
102 auto j = json({{"Sets", nSets}});
103
104 for (size_t i = 0; i < nSets; i++) {
105 auto js = json({});
106 geom::writeGeometry(js, pGeomVec[i]);
107 std::string set_name = "Set_" + std::to_string(i+1);
108 j[set_name] = js;
109 }
110
111 return j;
112 }
113
118
119 if (j.empty())
120 return;
121
122 if (d_particleSimType == "Multi_Particle") {
123 auto nSets = j.value("Sets", size_t(0));
124
125 d_pGeomVec.resize(nSets);
126
127 for (size_t i = 0; i < nSets; i++) {
128 auto set_name = "Set_" + std::to_string(i + 1);
129 if (j.find(set_name) == j.end())
130 throw std::runtime_error("Set " + set_name + " not found in particle geometry");
131
132 auto js = j.at(set_name);
133
134 // read
136 // create
138 }
139 } else if (d_particleSimType == "Single_Particle") {
140 d_pGeomVec.resize(1);
141 auto js = j.find("Set_1") == j.end()? j : j.at("Set_1");
142 if (js.find("Type") != js.end()) {
145 }
146 }
147 }
148
153 static json getParticleMeshExampleJson(std::vector<std::string> filenameVec = std::vector<std::string>(),
154 std::vector<double> meshSizesVec = std::vector<double>()) {
155
156 auto nSets = filenameVec.size();
157
158 if (nSets == 0)
159 return json({});
160
161 auto j = json({{"Sets", nSets}});
162 for (size_t i = 0; i < nSets; i++) {
163 double h = meshSizesVec.size() > i ? meshSizesVec[i] : -1.;
165 json{{"File", filenameVec[i]}, {"Mesh_Size", h}});
166
167 std::string set_name = "Set_" + std::to_string(i+1);
168 j[set_name] = js;
169 }
170
171 return j;
172 }
173
175 if (j.empty())
176 return;
177
178 if (d_particleSimType == "Multi_Particle") {
179 auto nSets = j.value("Sets", size_t(0));
180 d_pMeshVec.resize(nSets);
181
182 for (size_t i = 0; i < nSets; i++) {
183 auto set_name = "Set_" + std::to_string(i + 1);
184
185 if (j.find(set_name) == j.end())
186 throw std::runtime_error("Set " + set_name + " not found in particle mesh");
187
188 auto js = j.at(set_name);
189
190 // copy this set from a previous set?
191 int copy_set = js.value("Copy_Data", int(-1));
192 if (copy_set != -1) {
193 std::string copy_set_tag = "Set_" + std::to_string(copy_set);
194 auto js_copy = j.at(copy_set_tag);
195 d_pMeshVec[i].readFromJson(js_copy);
196 } else
197 d_pMeshVec[i].readFromJson(js);
198 }
199 } else if (d_particleSimType == "Single_Particle") {
200 d_pMeshVec.resize(1);
201 auto js = j.find("Set_1") == j.end()? j : j.at("Set_1");
202 d_pMeshVec[0].readFromJson(js);
203 }
204 }
205
210 static json getParticleMaterialExampleJson(size_t nSets = 0) {
211
212 if (nSets == 0)
213 return json({});
214
215 auto j = json({{"Sets", nSets}});
216 for (size_t i = 0; i < nSets; i++) {
217 std::string set_name = "Set_" + std::to_string(i+1);
218 j[set_name] = {};
219 }
220
221 return j;
222 }
223
225 if (j.empty())
226 return;
227
228 if (d_particleSimType == "Multi_Particle") {
229 auto nSets = j.value("Sets", size_t(0));
230 d_pMaterialVec.resize(nSets);
231
232 for (size_t i = 0; i < nSets; i++) {
233 auto set_name = "Set_" + std::to_string(i + 1);
234 if (j.find(set_name) == j.end())
235 throw std::runtime_error("Set " + set_name + " not found in particle mesh");
236
237 auto js = j.at(set_name);
238
239 // copy this set from previous set?
240 int copy_set = js.value("Copy_Data", int(-1));
241 if (copy_set != -1) {
242 std::string copy_set_tag = "Set_" + std::to_string(copy_set);
243 auto js_copy = j.at(copy_set_tag);
244 d_pMaterialVec[i].readFromJson(js_copy);
245 } else {
246 d_pMaterialVec[i].readFromJson(js);
247 }
248 } // loop over sets
249 } else if (d_particleSimType == "Single_Particle") {
250 d_pMaterialVec.resize(1);
251 auto js = j.find("Set_1") == j.end()? j : j.at("Set_1");
252 d_pMaterialVec[0].readFromJson(js);
253 }
254 }
255
260 static json getParticleContactExampleJson(size_t nSets = 0) {
261 return inp::ContactDeck::getExampleJson(json{{"Sets", nSets}});
262 }
263
267
274 const json &given = json::object()) {
276 }
277
281
287 static json getParticleGenExampleJson(const json &given = json::object()) {
288 return inp::PGenDeck::getExampleJson(given);
289 }
290
293 }
294
302 std::string printStr(int nt = 0, int lvl = 0) const {
303
304 auto tabS = util::io::getTabS(nt);
305 std::ostringstream oss;
306 oss << tabS << "------- ParticleDeck --------" << std::endl << std::endl;
307
308 oss << tabS << "Number of particle geometry groups = " << d_pGeomVec.size() << std::endl;
309 oss << tabS << "Number of particle mesh groups = " << d_pMeshVec.size() << std::endl;
310 oss << tabS << "Number of particle material groups = " << d_pMaterialVec.size() << std::endl;
311
312 oss << tabS << "Particle geometry data:" << std::endl;
313 for (size_t i = 0; i < d_pGeomVec.size(); i++) {
314 oss << tabS << "Particle geometry data for group = " << i << std::endl;
315 oss << d_pGeomVec[i].printStr(nt + 1, lvl);
316 }
317
318
319 oss << tabS << "Particle mesh data:" << std::endl;
320 for (size_t i = 0; i < d_pMeshVec.size(); i++) {
321 oss << tabS << "Particle mesh data for group = " << i << std::endl;
322 oss << d_pMeshVec[i].printStr(nt + 1, lvl);
323 }
324
325 oss << tabS << "Particle material data:" << std::endl;
326 for (size_t i = 0; i < d_pMaterialVec.size(); i++) {
327 oss << tabS << "Particle material data for group = " << i << std::endl;
328 oss << d_pMaterialVec[i].printStr(nt + 1, lvl);
329 }
330
331 oss << tabS << "Contact data:" << std::endl;
332 oss << d_contactDeck.printStr(nt + 1, lvl);
333
334 oss << tabS << "Neighbor data:" << std::endl;
335 oss << d_pNeighDeck.printStr(nt+1, lvl);
336
337 oss << tabS << "Particle generation data:" << std::endl;
338 oss << d_pGenDeck.printStr(nt+1, lvl);
339
340 oss << tabS << std::endl;
341
342 return oss.str();
343 }
344
351 void print(int nt = 0, int lvl = 0) const { std::cout << printStr(nt, lvl); }
352};
353
356} // namespace inp
357
358#endif // INP_PARTICLEDECK_H
nlohmann::ordered_json json
void createGeomObject(const std::string &geom_type, const std::vector< double > &params, const std::vector< std::string > &vec_type, const std::vector< std::string > &vec_flag, std::shared_ptr< geom::GeomObject > &obj, bool perform_check)
void readGeometry(const json &j, geom::GeomData &geomData)
void writeGeometry(json &j, const geom::GeomData &geomData)
Collection of methods and database related to input.
Definition pairForce.h:20
std::string getTabS(int nt)
Returns tab spaces of a given size.
Definition io.h:82
Structure to read and store particle-particle contact related input data.
Definition contactDeck.h:27
void readFromJson(const json &j)
Reads from json object.
std::string printStr(int nt=0, int lvl=0) const
Returns the string containing printable information about the object.
static json getExampleJson(const json &given=json::object())
Returns the block with the given fields set.
static json getExampleJson(const json &given=json::object())
Returns example JSON object for ModelDeck configuration.
Definition meshDeck.h:81
Structure to read and store particle generation data, such as particle locations and group file.
Definition pGenDeck.h:28
static json getExampleJson(const json &given=json::object())
Returns the block with the given fields set.
Definition pGenDeck.h:82
void readFromJson(const json &j)
Reads from json object.
Definition pGenDeck.h:102
std::string printStr(int nt=0, int lvl=0) const
Returns the string containing printable information about the object.
Definition pGenDeck.h:135
User-input data for particle neighbor search.
std::string printStr(int nt=0, int lvl=0) const
Returns the string containing printable information about the object.
void readFromJson(const json &j)
Reads from json object.
static json getExampleJson(const json &given=json::object())
Returns the block with the given fields set.
Structure to read and store particle related input data.
void print(int nt=0, int lvl=0) const
Prints the information about the object.
static json getParticleContactExampleJson(size_t nSets=0)
Returns example JSON object for ModelDeck configuration.
inp::ContactDeck d_contactDeck
Particle contact data.
static json getParticleGeomExampleJson(std::vector< geom::GeomData > pGeomVec=std::vector< geom::GeomData >())
Returns example JSON object for ModelDeck configuration.
static json getParticleMeshExampleJson(std::vector< std::string > filenameVec=std::vector< std::string >(), std::vector< double > meshSizesVec=std::vector< double >())
Returns example JSON object for ModelDeck configuration.
std::vector< geom::GeomData > d_pGeomVec
Particle geometry data.
ParticleDeck(const json &j=json({}), std::string particleSimType="Multi_Particle")
Constructor.
std::string d_particleSimType
Specify if this is single or multi particle simulation Expected value is either 'Single_Particle' or ...
void readParticleGenFromJson(const json &j)
void readParticleMeshFromJson(const json &j)
inp::PGenDeck d_pGenDeck
Particle generation data.
std::vector< inp::MaterialDeck > d_pMaterialVec
Particle material data.
void readParticleGeomFromJson(const json &j)
Reads from json object.
std::string printStr(int nt=0, int lvl=0) const
Returns the string containing printable information about the object.
void readParticleNeighborFromJson(const json &j)
inp::PNeighborDeck d_pNeighDeck
Neighbor search data.
static json getParticleNeighborExampleJson(const json &given=json::object())
Returns the neighbor block with the given fields set.
static json getParticleMaterialExampleJson(size_t nSets=0)
Returns example JSON object for ModelDeck configuration.
void readParticleContactFromJson(const json &j)
static json getParticleGenExampleJson(const json &given=json::object())
Returns the particle generation block with the given fields set.
void readParticleMaterialFromJson(const json &j)
void readFromJson(const json &j)
std::vector< inp::MeshDeck > d_pMeshVec
Particle mesh data.