PeriDEM 0.3.0
PeriDEM -- Peridynamics-based high-fidelity model for granular media
Loading...
Searching...
No Matches
pGenDeck.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_PGENDECK_H
12#define INP_PGENDECK_H
13
14#include "util/io.h"
15#include "util/json.h"
16#include "geom/geomIncludes.h"
17#include <string>
18
19namespace inp {
20
27 struct PGenDeck {
28
37 std::string d_genMethod;
38
41
44
48 PGenDeck(const json &j = json({}))
49 : d_genMethod("Use_Particle_Geometry"),
51 readFromJson(j);
52 };
53
57 PGenDeck(std::string genMethod, json pGenJson = json({}), bool genWithRandomRotation = true)
58 : d_genMethod(genMethod),
59 d_pGenJson(pGenJson), d_genWithRandomRotation(genWithRandomRotation) {};
60
65 static json getExampleJson(std::string genMethod = "From_File") {
66
67 auto j = json({{"Method", "From_File"}, {"Random_Rotation", true}});
68 return j;
69 }
70
74 void readFromJson(const json &j) {
75 if (j.empty())
76 return;
77
78 d_genMethod = j.value("Method", std::string("Use_Particle_Geometry"));
79 d_genWithRandomRotation = j.value("Random_Rotation", true);
80
81 if (d_genMethod == "From_File") {
82 if (j.find("Data") == j.end())
83 throw std::runtime_error("Need information inside key Data.");
84
85 d_pGenJson = j.at("Data");
86 }
87 }
88
96 std::string printStr(int nt = 0, int lvl = 0) const {
97
98 auto tabS = util::io::getTabS(nt);
99 std::ostringstream oss;
100 oss << tabS << "------- PGenDeck --------" << std::endl << std::endl;
101 oss << tabS << "Method = " << d_genMethod << std::endl;
102 oss << tabS << "Random rotation of particles = " << d_genWithRandomRotation << std::endl;
103 size_t nParticles = d_pGenJson.value("N", 0);
104 oss << tabS << "Number of particles in json object = " << nParticles << std::endl;
105 oss << tabS << "Data for first five particles: " << std::endl;
106 if (nParticles > 0) {
107 nParticles = nParticles > 5 ? 5 : nParticles;
108 for (size_t i=0; i< nParticles; i++) {
109 oss << tabS << "Particle number = " << i << std::endl;
110 oss << tabS << d_pGenJson.at(std::to_string(i)) << std::endl;
111 }
112 }
113 oss << tabS << std::endl;
114
115 return oss.str();
116 }
117
124 void print(int nt = 0, int lvl = 0) const { std::cout << printStr(nt, lvl); }
125 };
126
129} // namespace inp
130
131#endif // INP_PGENDECK_H
nlohmann::ordered_json json
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:39
Structure to read and store particle generation data, such as particle locations and group file.
Definition pGenDeck.h:27
PGenDeck(std::string genMethod, json pGenJson=json({}), bool genWithRandomRotation=true)
Constructor.
Definition pGenDeck.h:57
static json getExampleJson(std::string genMethod="From_File")
Returns example JSON object for ModelDeck configuration.
Definition pGenDeck.h:65
json d_pGenJson
Json object loaded from the input json file or jason file for particle generation.
Definition pGenDeck.h:40
void print(int nt=0, int lvl=0) const
Prints the information about the object.
Definition pGenDeck.h:124
void readFromJson(const json &j)
Reads from json object.
Definition pGenDeck.h:74
std::string printStr(int nt=0, int lvl=0) const
Returns the string containing printable information about the object.
Definition pGenDeck.h:96
bool d_genWithRandomRotation
Random rotation of particles if orientation is not provided.
Definition pGenDeck.h:43
PGenDeck(const json &j=json({}))
Constructor.
Definition pGenDeck.h:48
std::string d_genMethod
Particle generation method.
Definition pGenDeck.h:37