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

User-input data for particle neighbor search. More...

#include <bcBaseDeck.h>

Collaboration diagram for inp::BCBaseDeck:

Public Member Functions

 BCBaseDeck (const json &j=json({}), std::string type="Force_BC")
 Constructor.
 
 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.
 
void readFromJson (const json &j, std::string type)
 Reads from json object.
 
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 const std::vector< Field< BCBaseDeck > > & fields ()
 The fields of the block itself.
 
static const std::vector< Field< BCBaseDeck > > & timeFunctionFields ()
 The fields of the Time_Function sub-block.
 
static const std::vector< Field< BCBaseDeck > > & spatialFunctionFields ()
 The fields of the Spatial_Function sub-block.
 
static json getExampleJson (const json &given=json::object(), const geom::GeomData *region=nullptr)
 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.
 

Data Fields

std::string d_type
 Method for applying force. E.g., Force_BC, Displacement_BC, IC.
 
std::string d_selectionType
 Method for applying force e.g.
 
bool d_isRegionActive
 Flag that indicates if region-based application of boundary condition is active. So cases of 'region', 'region_with_include_list', 'region_with_exclude_list', and 'region_with_include_list_with_exclude_list' will have region-based application of boundary condition.
 
geom::GeomData d_regionGeomData
 Region geometry (if any)
 
std::vector< size_t > d_pList
 List of particles (if any)
 
std::vector< size_t > d_pNotList
 List of particles to not include (if any)
 
std::string d_timeFnType
 Name of the formula with respect to time.
 
std::string d_spatialFnType
 Name of the formula of with respect to spatial coordinate.
 
std::vector< size_t > d_direction
 List of dofs on which this bc will be applied.
 
std::vector< double > d_timeFnParams
 List of parameters for function wrt time.
 
std::vector< double > d_spatialFnParams
 List of parameters for function wrt spatial coordinate.
 
bool d_isDisplacementZero
 Specify if this bc corresponds to zero displacement condition.
 
std::string d_icType
 Type.
 
util::Point d_icVec
 Initial velocity vector.
 

Detailed Description

User-input data for particle neighbor search.

Definition at line 26 of file bcBaseDeck.h.

Constructor & Destructor Documentation

◆ BCBaseDeck() [1/2]

inp::BCBaseDeck::BCBaseDeck ( const json &  j = json({}),
std::string  type = "Force_BC" 
)
inline

Constructor.

Definition at line 110 of file bcBaseDeck.h.

110 {}), std::string type = "Force_BC") :
111 d_type(type), d_isRegionActive(false), d_isDisplacementZero(false) {
112 readFromJson(j, type);
113 };
void readFromJson(const json &j, std::string type)
Reads from json object.
Definition bcBaseDeck.h:294
bool d_isDisplacementZero
Specify if this bc corresponds to zero displacement condition.
Definition bcBaseDeck.h:99
bool d_isRegionActive
Flag that indicates if region-based application of boundary condition is active. So cases of 'region'...
Definition bcBaseDeck.h:46
std::string d_type
Method for applying force. E.g., Force_BC, Displacement_BC, IC.
Definition bcBaseDeck.h:28

◆ BCBaseDeck() [2/2]

inp::BCBaseDeck::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 
)
inline

Constructor.

Definition at line 118 of file bcBaseDeck.h.

128 : d_isRegionActive(isRegionActive), d_regionGeomData(regionGeomData),
129 d_pList(pList), d_pNotList(pNotList), d_timeFnType(timeFnType), d_timeFnParams(timeFnParams),
130 d_spatialFnType(spatialFnType), d_spatialFnParams(spatialFnParams),
131 d_direction(direction), d_isDisplacementZero(isDisplacementZero) {
132
133 // fix selection type
134 if (d_isRegionActive) {
135 d_selectionType = "region";
136 d_isRegionActive = true;
137 if (d_pList.size() > 0)
138 d_selectionType += "_with_include_list";
139
140 if (d_pNotList.size() > 0)
141 d_selectionType += "_with_exclude_list";
142 } else {
143 if (d_pList.size() > 0)
144 d_selectionType = "particle";
145 }
146
147 if (d_isRegionActive) {
148 // create a geometry object based on the data
150 }
151 };
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)
std::vector< size_t > d_pList
List of particles (if any)
Definition bcBaseDeck.h:52
std::vector< size_t > d_pNotList
List of particles to not include (if any)
Definition bcBaseDeck.h:55
geom::GeomData d_regionGeomData
Region geometry (if any)
Definition bcBaseDeck.h:49
std::vector< double > d_timeFnParams
List of parameters for function wrt time.
Definition bcBaseDeck.h:93
std::vector< double > d_spatialFnParams
List of parameters for function wrt spatial coordinate.
Definition bcBaseDeck.h:96
std::vector< size_t > d_direction
List of dofs on which this bc will be applied.
Definition bcBaseDeck.h:90
std::string d_selectionType
Method for applying force e.g.
Definition bcBaseDeck.h:39
std::string d_timeFnType
Name of the formula with respect to time.
Definition bcBaseDeck.h:68
std::string d_spatialFnType
Name of the formula of with respect to spatial coordinate.
Definition bcBaseDeck.h:81

References geom::createGeomObject(), d_isRegionActive, d_pList, d_pNotList, d_regionGeomData, and d_selectionType.

Here is the call graph for this function:

Member Function Documentation

◆ fields()

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

The fields of the block itself.

A list that is empty and a displacement that is not held are left out of the block, which is how the decks in the repository are written.

Returns
fields The field table

Definition at line 162 of file bcBaseDeck.h.

162 {
163 static const std::vector<Field<BCBaseDeck>> f = {
164 field<BCBaseDeck, std::vector<size_t>>(
165 &BCBaseDeck::d_pList, "Particle_List", {},
166 "Particles the condition applies to", {},
167 [](const std::vector<size_t> &v) { return !v.empty(); }),
168 field<BCBaseDeck, std::vector<size_t>>(
169 &BCBaseDeck::d_pNotList, "Particle_Exclude_List", {},
170 "Particles the condition does not apply to", {},
171 [](const std::vector<size_t> &v) { return !v.empty(); }),
172 field<BCBaseDeck, std::vector<size_t>>(
173 &BCBaseDeck::d_direction, "Direction", {},
174 "Components the condition acts on, counted from one", {},
175 [](const std::vector<size_t> &v) { return !v.empty(); }),
176 field<BCBaseDeck, bool>(
177 &BCBaseDeck::d_isDisplacementZero, "Zero_Displacement", false,
178 "Hold the displacement at zero", {},
179 [](const bool &v) { return v; }),
180 };
181 return f;
182 }
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

References d_direction, d_isDisplacementZero, d_pList, d_pNotList, and inp::field().

Referenced by getExampleJson(), and readFromJson().

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

◆ getExampleJson() [1/3]

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

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

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

◆ getExampleJson() [2/3]

static json inp::BCBaseDeck::getExampleJson ( const json &  given = json::object(),
const geom::GeomData *  region = nullptr 
)
inlinestatic

Returns example JSON object for ModelDeck configuration.

Returns
JSON object with example configuration

Returns the block with the given fields set

Type selects what the block may carry rather than appearing in it: a set of initial conditions takes IC_Type and IC_Vector, any other takes Direction and Zero_Displacement. A region is given as a geometry rather than as a key, so it is a parameter of its own; leaving it out means the set applies everywhere.

Parameters
givenField names and values to set, checked against the table
regionGeometry the set is restricted to, or nothing
Returns
JSON object for this deck

Definition at line 233 of file bcBaseDeck.h.

234 {
235 const std::vector<std::string> extra = {
236 "Type", "Time_Function", "Spatial_Function", "IC_Type", "IC_Vector"};
237 checkKeys(given, fields(), extra);
238
239 const auto type = given.value("Type", std::string("Force_BC"));
240
241 auto j = json({});
242
243 if (region != nullptr) {
244 auto j_geom = json({});
245 geom::writeGeometry(j_geom, *region);
246 // Must be an object: readFromJson does j.at("Region").at("Geometry").
247 j["Region"] = json{{"Geometry", j_geom}};
248 }
249
250 json fieldsGiven =
251 json{{"Particle_List",
252 given.value("Particle_List", std::vector<size_t>())},
253 {"Particle_Exclude_List",
254 given.value("Particle_Exclude_List", std::vector<size_t>())}};
255 if (type != "IC") {
256 fieldsGiven["Direction"] =
257 given.value("Direction", std::vector<size_t>());
258 fieldsGiven["Zero_Displacement"] =
259 given.value("Zero_Displacement", false);
260 }
261 j.update(applyGiven(fieldsGiven, fields()));
262
263 if (given.find("Time_Function") != given.end())
264 j["Time_Function"] =
265 applyGiven(given.at("Time_Function"), timeFunctionFields());
266
267 if (given.find("Spatial_Function") != given.end())
268 j["Spatial_Function"] =
269 applyGiven(given.at("Spatial_Function"), spatialFunctionFields());
270
271 if (type == "IC") {
272 const auto icType = given.value("IC_Type", std::string());
273 if (icType == "Constant_Velocity")
274 j[icType]["Velocity_Vector"] =
275 given.value("IC_Vector", std::vector<double>());
276 }
277
278 return j;
279 }
nlohmann::ordered_json json
void writeGeometry(json &j, const geom::GeomData &geomData)
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
void checkKeys(const json &given, const std::vector< Field< Deck > > &fs, const std::vector< std::string > &extra={})
Rejects a key that no field declares.
Definition deckField.h:421
static const std::vector< Field< BCBaseDeck > > & spatialFunctionFields()
The fields of the Spatial_Function sub-block.
Definition bcBaseDeck.h:204
static const std::vector< Field< BCBaseDeck > > & timeFunctionFields()
The fields of the Time_Function sub-block.
Definition bcBaseDeck.h:188
static const std::vector< Field< BCBaseDeck > > & fields()
The fields of the block itself.
Definition bcBaseDeck.h:162

References inp::applyGiven(), inp::checkKeys(), fields(), spatialFunctionFields(), timeFunctionFields(), and geom::writeGeometry().

Referenced by anonymous_namespace{main.cpp}::buildInputJson(), anonymous_namespace{main.cpp}::buildInputJson(), anonymous_namespace{main.cpp}::buildInputJson(), anonymous_namespace{main.cpp}::buildInputJson(), anonymous_namespace{main.cpp}::buildInputJson(), anonymous_namespace{main.cpp}::buildInputJson(), getInputJson(), and anonymous_namespace{testDeckRoundTrip.cpp}::testBCBaseDeck().

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

◆ getExampleJson() [3/3]

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

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

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

◆ print()

void inp::BCBaseDeck::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 384 of file bcBaseDeck.h.

384{ 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 bcBaseDeck.h:347

References printStr().

Here is the call graph for this function:

◆ printStr()

std::string inp::BCBaseDeck::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 347 of file bcBaseDeck.h.

347 {
348
349 auto tabS = util::io::getTabS(nt);
350 std::ostringstream oss;
351 oss << tabS << "------- BCBaseDeck --------" << std::endl << std::endl;
352 oss << tabS << "Selection type = " << d_selectionType << std::endl;
353 oss << tabS << "Is region active = " << d_isRegionActive << std::endl;
354 if (d_regionGeomData.d_geom_p != nullptr) {
355 oss << tabS << "Region geometry info: " << std::endl;
356 oss << d_regionGeomData.printStr(nt + 1, lvl);
357 }
358 if (!d_pList.empty())
359 oss << tabS << "Particle list = ["
360 << util::io::printStr<size_t>(d_pList, 0) << "]" << std::endl;
361 if (!d_pNotList.empty())
362 oss << tabS << "Particle excluded list = ["
363 << util::io::printStr<size_t>(d_pNotList, 0) << "]" << std::endl;
364 oss << tabS << "Time function type = " << d_timeFnType << std::endl;
365 oss << tabS << "Time function parameters = ["
366 << util::io::printStr<double>(d_timeFnParams, 0) << "]" << std::endl;
367 oss << tabS << "Spatial function type = " << d_spatialFnType << std::endl;
368 oss << tabS << "Spatial function parameters = ["
369 << util::io::printStr<double>(d_spatialFnParams, 0) << "]" << std::endl;
370 oss << tabS << "Direction = [" << util::io::printStr<size_t>(d_direction, 0)
371 << "]" << std::endl;
372 oss << tabS << "Is displacement zero = " << d_isDisplacementZero << std::endl;
373 oss << tabS << std::endl;
374
375 return oss.str();
376 }
std::string getTabS(int nt)
Returns tab spaces of a given size.
Definition io.h:82
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.

References d_direction, geom::GeomData::d_geom_p, d_isDisplacementZero, d_isRegionActive, d_pList, d_pNotList, d_regionGeomData, d_selectionType, d_spatialFnParams, d_spatialFnType, d_timeFnParams, d_timeFnType, util::io::getTabS(), and geom::GeomData::printStr().

Referenced by print().

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

◆ readFromJson()

void inp::BCBaseDeck::readFromJson ( const json &  j,
std::string  type 
)
inline

Reads from json object.

Definition at line 294 of file bcBaseDeck.h.

294 {
295 if (j.empty())
296 return;
297
298 // fix selection type
299 if (j.find("Region") != j.end()) {
300 d_selectionType = "region";
301 d_isRegionActive = true;
302 if (j.find("Particle_List") != j.end())
303 d_selectionType += "_with_include_list";
304
305 if (j.find("Particle_Exclude_List") != j.end())
306 d_selectionType += "_with_exclude_list";
307 } else {
308 d_isRegionActive = false;
309 if (j.find("Particle_List") != j.end())
310 d_selectionType = "particle";
311 }
312
313 if (d_isRegionActive) {
314 geom::readGeometry(j.at("Region").at("Geometry"), d_regionGeomData);
315 // create a geometry object based on the data
317 }
318
319 readFields(*this, j, fields());
320
321 if (j.find("Time_Function") != j.end())
322 readFields(*this, j.at("Time_Function"), timeFunctionFields());
323
324 if (j.find("Spatial_Function") != j.end())
325 readFields(*this, j.at("Spatial_Function"), spatialFunctionFields());
326
327 if (type != "IC" && j.find("Direction") == j.end())
328 throw std::runtime_error(
329 "Direction must be specified for boundary condition");
330
331 // if it is initial condition
332 if (type == "IC") {
333 if (j.find("Constant_Velocity") != j.end()) {
334 d_icType = "Constant_Velocity";
335 d_icVec = util::Point(j.at("Constant_Velocity").value("Velocity_Vector", std::vector<double>({0., 0., 0.})));
336 }
337 }
338 }
void readGeometry(const json &j, geom::GeomData &geomData)
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
std::string d_icType
Type.
Definition bcBaseDeck.h:102
util::Point d_icVec
Initial velocity vector.
Definition bcBaseDeck.h:105
A structure to represent 3d vectors.
Definition point.h:30

References geom::createGeomObject(), d_icType, d_icVec, d_isRegionActive, d_regionGeomData, d_selectionType, fields(), inp::readFields(), geom::readGeometry(), spatialFunctionFields(), and timeFunctionFields().

Referenced by inp::BCDeck::readFromJson(), and anonymous_namespace{testDeckRoundTrip.cpp}::testBCBaseDeck().

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

◆ spatialFunctionFields()

static const std::vector< Field< BCBaseDeck > > & inp::BCBaseDeck::spatialFunctionFields ( )
inlinestatic

The fields of the Spatial_Function sub-block.

Returns
fields The field table

Definition at line 204 of file bcBaseDeck.h.

204 {
205 static const std::vector<Field<BCBaseDeck>> f = {
206 field(&BCBaseDeck::d_spatialFnType, "Type", std::string(),
207 "Spatial dependence of the condition"),
208 field<BCBaseDeck, std::vector<double>>(
209 &BCBaseDeck::d_spatialFnParams, "Parameters", {},
210 "Parameters of the spatial dependence", {},
211 [](const std::vector<double> &v) { return !v.empty(); }),
212 };
213 return f;
214 }

References d_spatialFnParams, d_spatialFnType, and inp::field().

Referenced by getExampleJson(), and readFromJson().

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

◆ timeFunctionFields()

static const std::vector< Field< BCBaseDeck > > & inp::BCBaseDeck::timeFunctionFields ( )
inlinestatic

The fields of the Time_Function sub-block.

Returns
fields The field table

Definition at line 188 of file bcBaseDeck.h.

188 {
189 static const std::vector<Field<BCBaseDeck>> f = {
190 field(&BCBaseDeck::d_timeFnType, "Type", std::string(),
191 "Time dependence of the condition"),
192 field<BCBaseDeck, std::vector<double>>(
193 &BCBaseDeck::d_timeFnParams, "Parameters", {},
194 "Parameters of the time dependence", {},
195 [](const std::vector<double> &v) { return !v.empty(); }),
196 };
197 return f;
198 }

References d_timeFnParams, d_timeFnType, and inp::field().

Referenced by getExampleJson(), and readFromJson().

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

Field Documentation

◆ d_direction

std::vector<size_t> inp::BCBaseDeck::d_direction

List of dofs on which this bc will be applied.

E.g. if bc is only applied on x-component, d_direction will be 1. If bc is applied on x- and y-component, d_direction will be vector with elements 1 and 2.

Definition at line 90 of file bcBaseDeck.h.

Referenced by fields(), printStr(), and anonymous_namespace{testDeckRoundTrip.cpp}::testBCBaseDeck().

◆ d_icType

std::string inp::BCBaseDeck::d_icType

◆ d_icVec

util::Point inp::BCBaseDeck::d_icVec

Initial velocity vector.

Definition at line 105 of file bcBaseDeck.h.

Referenced by readFromJson(), and anonymous_namespace{testDeckRoundTrip.cpp}::testBCBaseDeck().

◆ d_isDisplacementZero

bool inp::BCBaseDeck::d_isDisplacementZero

Specify if this bc corresponds to zero displacement condition.

Definition at line 99 of file bcBaseDeck.h.

Referenced by fields(), printStr(), and anonymous_namespace{testDeckRoundTrip.cpp}::testBCBaseDeck().

◆ d_isRegionActive

bool inp::BCBaseDeck::d_isRegionActive

Flag that indicates if region-based application of boundary condition is active. So cases of 'region', 'region_with_include_list', 'region_with_exclude_list', and 'region_with_include_list_with_exclude_list' will have region-based application of boundary condition.

Definition at line 46 of file bcBaseDeck.h.

Referenced by BCBaseDeck(), loading::needToComputeDof(), printStr(), readFromJson(), and anonymous_namespace{testDeckRoundTrip.cpp}::testBCBaseDeck().

◆ d_pList

std::vector<size_t> inp::BCBaseDeck::d_pList

◆ d_pNotList

std::vector<size_t> inp::BCBaseDeck::d_pNotList

◆ d_regionGeomData

geom::GeomData inp::BCBaseDeck::d_regionGeomData

◆ d_selectionType

std::string inp::BCBaseDeck::d_selectionType

Method for applying force e.g.

  • particle: provides global id of particle to which force should be applied
  • wall: provides global id of wall to which force should be applied
  • region: provides area within which all nodes of any particle will get this force

Definition at line 39 of file bcBaseDeck.h.

Referenced by BCBaseDeck(), loading::needToComputeDof(), loading::needToProcessParticle(), printStr(), and readFromJson().

◆ d_spatialFnParams

std::vector<double> inp::BCBaseDeck::d_spatialFnParams

List of parameters for function wrt spatial coordinate.

Definition at line 96 of file bcBaseDeck.h.

Referenced by printStr(), and spatialFunctionFields().

◆ d_spatialFnType

std::string inp::BCBaseDeck::d_spatialFnType

Name of the formula of with respect to spatial coordinate.

List of allowed values are:

  • "" (none)
  • constant
  • hat_x
  • hat_y
  • sin
  • rotation

Definition at line 81 of file bcBaseDeck.h.

Referenced by printStr(), spatialFunctionFields(), and anonymous_namespace{testDeckRoundTrip.cpp}::testBCBaseDeck().

◆ d_timeFnParams

std::vector<double> inp::BCBaseDeck::d_timeFnParams

List of parameters for function wrt time.

Definition at line 93 of file bcBaseDeck.h.

Referenced by printStr(), anonymous_namespace{testDeckRoundTrip.cpp}::testBCBaseDeck(), and timeFunctionFields().

◆ d_timeFnType

std::string inp::BCBaseDeck::d_timeFnType

Name of the formula with respect to time.

List of allowed values are:

  • "" (none)
  • constant
  • linear
  • linear_step
  • linear_slow_fast
  • rotation

Definition at line 68 of file bcBaseDeck.h.

Referenced by printStr(), anonymous_namespace{testDeckRoundTrip.cpp}::testBCBaseDeck(), and timeFunctionFields().

◆ d_type

std::string inp::BCBaseDeck::d_type

Method for applying force. E.g., Force_BC, Displacement_BC, IC.

Definition at line 28 of file bcBaseDeck.h.


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