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

Structure to read and store particle generation data, such as particle locations and group file. More...

#include <pGenDeck.h>

Collaboration diagram for inp::PGenDeck:

Public Member Functions

 PGenDeck (const json &j=json({}))
 Constructor.
 
 PGenDeck (std::string genMethod, json pGenJson=json({}), bool genWithRandomRotation=true)
 Constructor.
 
void readFromJson (const json &j)
 Reads from json object.
 
json writeToJson () const
 Returns this deck as a 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< PGenDeck > > & fields ()
 Returns example JSON object for ModelDeck configuration.
 
static json getExampleJson (const json &given=json::object())
 Returns the block with the given fields set.
 
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_genMethod
 Particle generation method.
 
json d_pGenJson
 Json object loaded from the input json file or jason file for particle generation.
 
bool d_genWithRandomRotation
 Random rotation of particles if orientation is not provided.
 

Detailed Description

Structure to read and store particle generation data, such as particle locations and group file.

Definition at line 28 of file pGenDeck.h.

Constructor & Destructor Documentation

◆ PGenDeck() [1/2]

inp::PGenDeck::PGenDeck ( const json &  j = json({}))
inline

Constructor.

Definition at line 49 of file pGenDeck.h.

49 {}))
50 : d_genMethod("Use_Particle_Geometry"),
52 readFromJson(j);
53 };
json d_pGenJson
Json object loaded from the input json file or jason file for particle generation.
Definition pGenDeck.h:41
void readFromJson(const json &j)
Reads from json object.
Definition pGenDeck.h:102
bool d_genWithRandomRotation
Random rotation of particles if orientation is not provided.
Definition pGenDeck.h:44
std::string d_genMethod
Particle generation method.
Definition pGenDeck.h:38

◆ PGenDeck() [2/2]

inp::PGenDeck::PGenDeck ( std::string  genMethod,
json  pGenJson = json({}),
bool  genWithRandomRotation = true 
)
inline

Constructor.

Definition at line 58 of file pGenDeck.h.

58 {}), bool genWithRandomRotation = true)
59 : d_genMethod(genMethod),
60 d_pGenJson(pGenJson), d_genWithRandomRotation(genWithRandomRotation) {};

Member Function Documentation

◆ fields()

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

Returns example JSON object for ModelDeck configuration.

Returns
JSON object with example configuration

Definition at line 66 of file pGenDeck.h.

66 {
67 static const std::vector<Field<PGenDeck>> f = {
68 field(&PGenDeck::d_genMethod, "Method", std::string("From_File"),
69 "Where the particle positions come from",
70 {{"From_File", "Use_Particle_Geometry"}, {}, {}}),
71 field(&PGenDeck::d_genWithRandomRotation, "Random_Rotation", true,
72 "Give each particle a random orientation when none is given"),
73 };
74 return f;
75 }
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_genMethod, d_genWithRandomRotation, and inp::field().

Referenced by getExampleJson(), printStr(), readFromJson(), and writeToJson().

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

◆ getExampleJson() [1/3]

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

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

A string converts to a JSON string, which would otherwise bind to the overload above and be read as a block with no keys. Deleting these makes that a compile error rather than a failure when the deck is built.

◆ getExampleJson() [2/3]

static json inp::PGenDeck::getExampleJson ( const json &  given = json::object())
inlinestatic

Returns the block with the given fields set.

Parameters
givenField names and values to set, checked against the table
Returns
JSON object for this deck

Definition at line 82 of file pGenDeck.h.

82 {
83 return applyGiven(given, fields(), {"Data"});
84 }
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
static const std::vector< Field< PGenDeck > > & fields()
Returns example JSON object for ModelDeck configuration.
Definition pGenDeck.h:66

References inp::applyGiven(), and fields().

Referenced by anonymous_namespace{main.cpp}::buildBhatInputJson(), anonymous_namespace{main.cpp}::buildImpactInputJson(), 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(), anonymous_namespace{main.cpp}::buildInputJson(), getInputJson(), inp::ParticleDeck::getParticleGenExampleJson(), and anonymous_namespace{testDeckRoundTrip.cpp}::testNeighborAndGenDecks().

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

◆ getExampleJson() [3/3]

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

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

A string converts to a JSON string, which would otherwise bind to the overload above and be read as a block with no keys. Deleting these makes that a compile error rather than a failure when the deck is built.

◆ print()

void inp::PGenDeck::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 162 of file pGenDeck.h.

162{ 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 pGenDeck.h:135

References printStr().

Here is the call graph for this function:

◆ printStr()

std::string inp::PGenDeck::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 135 of file pGenDeck.h.

135 {
136
137 auto tabS = util::io::getTabS(nt);
138 std::ostringstream oss;
139 oss << tabS << "------- PGenDeck --------" << std::endl << std::endl;
140 printFields(*this, oss, fields(), tabS);
141 size_t nParticles = d_pGenJson.value("N", 0);
142 oss << tabS << "Number of particles in json object = " << nParticles << std::endl;
143 oss << tabS << "Data for first five particles: " << std::endl;
144 if (nParticles > 0) {
145 nParticles = nParticles > 5 ? 5 : nParticles;
146 for (size_t i=0; i< nParticles; i++) {
147 oss << tabS << "Particle number = " << i << std::endl;
148 oss << tabS << d_pGenJson.at(std::to_string(i)) << std::endl;
149 }
150 }
151 oss << tabS << std::endl;
152
153 return oss.str();
154 }
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
std::string getTabS(int nt)
Returns tab spaces of a given size.
Definition io.h:82

References d_pGenJson, fields(), util::io::getTabS(), and inp::printFields().

Referenced by print(), and inp::ParticleDeck::printStr().

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

◆ readFromJson()

void inp::PGenDeck::readFromJson ( const json &  j)
inline

Reads from json object.

Parameters
jJSON object

Definition at line 102 of file pGenDeck.h.

102 {
103 if (j.empty())
104 return;
105 readFields(*this, j, fields());
106
107 // The positions themselves are a block of their own, not a field.
108 if (d_genMethod == "From_File") {
109 if (j.find("Data") == j.end())
110 throw std::runtime_error("Need information inside key Data.");
111
112 d_pGenJson = j.at("Data");
113 }
114 }
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

References d_genMethod, d_pGenJson, fields(), and inp::readFields().

Referenced by inp::ParticleDeck::readParticleGenFromJson().

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

◆ writeToJson()

json inp::PGenDeck::writeToJson ( ) const
inline

Returns this deck as a JSON object.

Returns
JSON object for this deck

Definition at line 120 of file pGenDeck.h.

120 {
121 json j = json::object();
122 writeFields(*this, j, fields());
123 if (d_genMethod == "From_File")
124 j["Data"] = d_pGenJson;
125 return j;
126 }
nlohmann::ordered_json json
void writeFields(const Deck &d, json &j, const std::vector< Field< Deck > > &fs)
Writes every field of the table into the block.
Definition deckField.h:237

References d_genMethod, d_pGenJson, fields(), and inp::writeFields().

Here is the call graph for this function:

Field Documentation

◆ d_genMethod

std::string inp::PGenDeck::d_genMethod

Particle generation method.

"From_File" means particle location, radius and other details will be loaded from the input json file. Use key 'Particle_Generation' to provide the data.

"Use_Particle_Geometry" means particle geometry will be used to generate particles.

Definition at line 38 of file pGenDeck.h.

Referenced by fields(), readFromJson(), and writeToJson().

◆ d_genWithRandomRotation

bool inp::PGenDeck::d_genWithRandomRotation

Random rotation of particles if orientation is not provided.

Definition at line 44 of file pGenDeck.h.

Referenced by fields().

◆ d_pGenJson

json inp::PGenDeck::d_pGenJson

Json object loaded from the input json file or jason file for particle generation.

Definition at line 41 of file pGenDeck.h.

Referenced by printStr(), readFromJson(), and writeToJson().


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