PeriDEM 0.3.0
PeriDEM -- Peridynamics-based high-fidelity model for granular media
Loading...
Searching...
No Matches
bcBaseDeck.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_BCBASEDECK_H
12#define INP_BCBASEDECK_H
13
14#include "geom/geomIncludes.h"
15#include "util/json.h"
16
17namespace inp {
18
25 struct BCBaseDeck {
27 std::string d_type;
28
38 std::string d_selectionType;
39
46
49
51 std::vector<size_t> d_pList;
52
54 std::vector<size_t> d_pNotList;
55
67 std::string d_timeFnType;
68
80 std::string d_spatialFnType;
81
89 std::vector<size_t> d_direction;
90
92 std::vector<double> d_timeFnParams;
93
95 std::vector<double> d_spatialFnParams;
96
99
101 std::string d_icType;
102
105
109 BCBaseDeck(const json &j = json({}), std::string type = "Force_BC") :
110 d_type(type), d_isRegionActive(false), d_isDisplacementZero(false) {
111 readFromJson(j, type);
112 };
113
117 BCBaseDeck(bool isRegionActive,
118 geom::GeomData regionGeomData = geom::GeomData(),
119 std::vector<size_t> pList = std::vector<size_t>(),
120 std::vector<size_t> pNotList = std::vector<size_t>(),
121 std::string timeFnType = "",
122 std::vector<double> timeFnParams = std::vector<double>(),
123 std::string spatialFnType = "",
124 std::vector<double> spatialFnParams = std::vector<double>(),
125 std::vector<size_t> direction = std::vector<size_t>(),
126 bool isDisplacementZero = false)
127 : d_isRegionActive(isRegionActive), d_regionGeomData(regionGeomData),
128 d_pList(pList), d_pNotList(pNotList), d_timeFnType(timeFnType), d_timeFnParams(timeFnParams),
129 d_spatialFnType(spatialFnType), d_spatialFnParams(spatialFnParams),
130 d_direction(direction), d_isDisplacementZero(isDisplacementZero) {
131
132 // fix selection type
133 if (d_isRegionActive) {
134 d_selectionType = "region";
135 d_isRegionActive = true;
136 if (d_pList.size() > 0)
137 d_selectionType += "_with_include_list";
138
139 if (d_pNotList.size() > 0)
140 d_selectionType += "_with_exclude_list";
141 } else {
142 if (d_pList.size() > 0)
143 d_selectionType = "particle";
144 }
145
146 if (d_isRegionActive) {
147 // create a geometry object based on the data
149 }
150 };
151
152
157 static json getExampleJson(std::string type = "Foce_BC",
158 bool isRegionActive = false,
159 geom::GeomData regionGeomData = geom::GeomData(),
160 std::vector<size_t> pList = std::vector<size_t>(),
161 std::vector<size_t> pNotList = std::vector<size_t>(),
162 std::string timeFnType = "",
163 std::vector<double> timeFnParams = std::vector<double>(),
164 std::string spatialFnType = "",
165 std::vector<double> spatialFnParams = std::vector<double>(),
166 std::vector<size_t> direction = std::vector<size_t>(),
167 bool isDisplacementZero = false,
168 std::string icType = "",
169 std::vector<double> icVec = std::vector<double>()) {
170
171 auto j = json({});
172
173 if (isRegionActive) {
174 // get json object for geometry
175 auto j_geom = json({});
176 geom::writeGeometry(j_geom, regionGeomData);
177 j["Region"] = {"Geometry", j_geom};
178 }
179
180 if (pList.size() > 0) j["Particle_List"] = pList;
181
182 if (pNotList.size() > 0) j["Particle_Exclude_List"] = pNotList;
183
184 if (timeFnType != "") {
185 j["Time_Function"] = {"Type", timeFnType};
186 if (timeFnParams.size() > 0)
187 j["Time_Function"] = {"Parameters", timeFnParams};
188 }
189
190 if (spatialFnType != "") {
191 j["Spatial_Function"] = {"Type", spatialFnType};
192 if (spatialFnParams.size() > 0)
193 j["Spatial_Function"] = {"Parameters", spatialFnParams};
194 }
195
196 if (type != "IC") {
197 if (direction.size() > 0)
198 j["Direction"] = direction;
199
200 if (isDisplacementZero) {
201 j["Zero_Displacement"] = true;
202 }
203 }
204
205 if (type == "IC") {
206 if (icType == "Constant_Velocity") {
207 j[icType]["Velocity_Vector"] = icVec;
208 }
209 }
210
211 return j;
212 }
213
217 void readFromJson(const json &j, std::string type) {
218 if (j.empty())
219 return;
220
221 // fix selection type
222 if (j.find("Region") != j.end()) {
223 d_selectionType = "region";
224 d_isRegionActive = true;
225 if (j.find("Particle_List") != j.end())
226 d_selectionType += "_with_include_list";
227
228 if (j.find("Particle_Exclude_List") != j.end())
229 d_selectionType += "_with_exclude_list";
230 } else {
231 d_isRegionActive = false;
232 if (j.find("Particle_List") != j.end())
233 d_selectionType = "particle";
234 }
235
236 if (d_isRegionActive) {
237 geom::readGeometry(j.at("Region").at("Geometry"), d_regionGeomData);
238 // create a geometry object based on the data
240 }
241
242 if (j.find("Particle_List") != j.end()) d_pList = j.value("Particle_List", std::vector<size_t>());
243
244 if (j.find("Particle_Exclude_List") != j.end())
245 d_pNotList = j.value("Particle_Exclude_List", std::vector<size_t>());
246
247 if (j.find("Time_Function") != j.end()) {
248 d_timeFnType = j.at("Time_Function").value("Type", "");
249 if (j.at("Time_Function").find("Parameters") != j.at("Time_Function").end())
250 d_timeFnParams = j.at("Time_Function").value("Parameters", std::vector<double>());
251 }
252
253 if (j.find("Spatial_Function") != j.end()) {
254 d_spatialFnType = j.at("Spatial_Function").value("Type", "");
255 if (j.at("Spatial_Function").find("Parameters") != j.at("Spatial_Function").end())
256 d_spatialFnParams = j.at("Spatial_Function").value("Parameters", std::vector<double>());
257 }
258
259 if (type != "IC") {
260 if (j.find("Direction") == j.end()) {
261 throw std::runtime_error("Direction must be specified for boundary condition");
262 return;
263 }
264
265 d_direction = j.value("Direction", std::vector<size_t>());
266
267 if (j.find("Zero_Displacement") != j.end())
268 d_isDisplacementZero = j.at("Zero_Displacement");
269 }
270
271 // if it is initial condition
272 if (type == "IC") {
273 if (j.find("Constant_Velocity") != j.end()) {
274 d_icType = "Constant_Velocity";
275 d_icVec = util::Point(j.at("Constant_Velocity").value("Velocity_Vector", std::vector<double>({0., 0., 0.})));
276 }
277 }
278 }
279
287 std::string printStr(int nt = 0, int lvl = 0) const {
288
289 auto tabS = util::io::getTabS(nt);
290 std::ostringstream oss;
291 oss << tabS << "------- BCBaseDeck --------" << std::endl << std::endl;
292 oss << tabS << "Selection type = " << d_selectionType << std::endl;
293 oss << tabS << "Is region active = " << d_isRegionActive << std::endl;
294 if (d_regionGeomData.d_geom_p != nullptr) {
295 oss << tabS << "Region geometry info: " << std::endl;
296 oss << d_regionGeomData.printStr(nt + 1, lvl);
297 }
298 if (!d_pList.empty())
299 oss << tabS << "Particle list = ["
300 << util::io::printStr<size_t>(d_pList, 0) << "]" << std::endl;
301 if (!d_pNotList.empty())
302 oss << tabS << "Particle excluded list = ["
303 << util::io::printStr<size_t>(d_pNotList, 0) << "]" << std::endl;
304 oss << tabS << "Time function type = " << d_timeFnType << std::endl;
305 oss << tabS << "Time function parameters = ["
306 << util::io::printStr<double>(d_timeFnParams, 0) << "]" << std::endl;
307 oss << tabS << "Spatial function type = " << d_spatialFnType << std::endl;
308 oss << tabS << "Spatial function parameters = ["
309 << util::io::printStr<double>(d_spatialFnParams, 0) << "]" << std::endl;
310 oss << tabS << "Direction = [" << util::io::printStr<size_t>(d_direction, 0)
311 << "]" << std::endl;
312 oss << tabS << "Is displacement zero = " << d_isDisplacementZero << std::endl;
313 oss << tabS << std::endl;
314
315 return oss.str();
316 }
317
324 void print(int nt = 0, int lvl = 0) const { std::cout << printStr(nt, lvl); }
325 };
326
329} // namespace inp
330
331#endif // INP_BCBASEDECK_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:39
Input data for geometrical objects.
std::shared_ptr< geom::GeomObject > d_geom_p
Zone geometry.
std::string printStr(int nt=0, int lvl=0) const
Returns the string containing printable information about the object.
User-input data for particle neighbor search.
Definition bcBaseDeck.h:25
BCBaseDeck(bool isRegionActive, geom::GeomData regionGeomData=geom::GeomData(), std::vector< size_t > pList=std::vector< size_t >(), std::vector< size_t > pNotList=std::vector< size_t >(), std::string timeFnType="", std::vector< double > timeFnParams=std::vector< double >(), std::string spatialFnType="", std::vector< double > spatialFnParams=std::vector< double >(), std::vector< size_t > direction=std::vector< size_t >(), bool isDisplacementZero=false)
Constructor.
Definition bcBaseDeck.h:117
std::vector< size_t > d_pList
List of particles (if any)
Definition bcBaseDeck.h:51
std::string printStr(int nt=0, int lvl=0) const
Returns the string containing printable information about the object.
Definition bcBaseDeck.h:287
std::vector< size_t > d_pNotList
List of particles to not include (if any)
Definition bcBaseDeck.h:54
geom::GeomData d_regionGeomData
Region geometry (if any)
Definition bcBaseDeck.h:48
void readFromJson(const json &j, std::string type)
Reads from json object.
Definition bcBaseDeck.h:217
std::vector< double > d_timeFnParams
List of parameters for function wrt time.
Definition bcBaseDeck.h:92
std::vector< double > d_spatialFnParams
List of parameters for function wrt spatial coordinate.
Definition bcBaseDeck.h:95
std::vector< size_t > d_direction
List of dofs on which this bc will be applied.
Definition bcBaseDeck.h:89
std::string d_icType
Type.
Definition bcBaseDeck.h:101
void print(int nt=0, int lvl=0) const
Prints the information about the object.
Definition bcBaseDeck.h:324
bool d_isDisplacementZero
Specify if this bc corresponds to zero displacement condition.
Definition bcBaseDeck.h:98
static json getExampleJson(std::string type="Foce_BC", bool isRegionActive=false, geom::GeomData regionGeomData=geom::GeomData(), std::vector< size_t > pList=std::vector< size_t >(), std::vector< size_t > pNotList=std::vector< size_t >(), std::string timeFnType="", std::vector< double > timeFnParams=std::vector< double >(), std::string spatialFnType="", std::vector< double > spatialFnParams=std::vector< double >(), std::vector< size_t > direction=std::vector< size_t >(), bool isDisplacementZero=false, std::string icType="", std::vector< double > icVec=std::vector< double >())
Returns example JSON object for ModelDeck configuration.
Definition bcBaseDeck.h:157
BCBaseDeck(const json &j=json({}), std::string type="Force_BC")
Constructor.
Definition bcBaseDeck.h:109
bool d_isRegionActive
Flag that indicates if region-based application of boundary condition is active. So cases of 'region'...
Definition bcBaseDeck.h:45
std::string d_type
Method for applying force. E.g., Force_BC, Displacement_BC, IC.
Definition bcBaseDeck.h:27
std::string d_selectionType
Method for applying force e.g.
Definition bcBaseDeck.h:38
util::Point d_icVec
Initial velocity vector.
Definition bcBaseDeck.h:104
std::string d_timeFnType
Name of the formula with respect to time.
Definition bcBaseDeck.h:67
std::string d_spatialFnType
Name of the formula of with respect to spatial coordinate.
Definition bcBaseDeck.h:80
A structure to represent 3d vectors.
Definition point.h:30