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

Structure to read and store test-related input data. More...

#include <testDeck.h>

Collaboration diagram for inp::TestDeck:

Public Member Functions

 TestDeck (const json &j=json({}))
 Constructor.
 
 TestDeck (std::string testName, size_t particleIdCompressiveTest=0, size_t particleForceDirectionCompressiveTest=0)
 Constructor.
 
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.
 
void print (int nt=0, int lvl=0) const
 Prints the information about the object.
 

Static Public Member Functions

static const std::vector< Field< TestDeck > > & fields ()
 Returns example JSON object for ModelDeck configuration.
 
static bool isCompressive (const std::string &name)
 True when the name selects the compressive test.
 
static json getExampleJson (const json &given=json::object())
 Returns the block with the given fields set.
 
static json getExampleJson (const std::string &)=delete
 Returns the block with the given fields set.
 
static json getExampleJson (const char *)=delete
 Returns the block with the given fields set.
 

Data Fields

std::string d_testName
 Specify test name (if any)
 
size_t d_particleIdCompressiveTest
 if it is a compressive test, specify wall id and direction
 
size_t d_particleForceDirectionCompressiveTest
 if it is a compressive test, specify force direction on wall
 

Detailed Description

Structure to read and store test-related input data.

Definition at line 26 of file testDeck.h.

Constructor & Destructor Documentation

◆ TestDeck() [1/2]

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

Constructor.

Definition at line 40 of file testDeck.h.

40 {}))
42 readFromJson(j);
43 };
size_t d_particleForceDirectionCompressiveTest
if it is a compressive test, specify force direction on wall
Definition testDeck.h:34
void readFromJson(const json &j)
Reads from json object.
Definition testDeck.h:121
std::string d_testName
Specify test name (if any)
Definition testDeck.h:28
size_t d_particleIdCompressiveTest
if it is a compressive test, specify wall id and direction
Definition testDeck.h:31

◆ TestDeck() [2/2]

inp::TestDeck::TestDeck ( std::string  testName,
size_t  particleIdCompressiveTest = 0,
size_t  particleForceDirectionCompressiveTest = 0 
)
inline

Constructor.

Definition at line 48 of file testDeck.h.

50 : d_testName(testName),
51 d_particleIdCompressiveTest(particleIdCompressiveTest),
52 d_particleForceDirectionCompressiveTest(particleForceDirectionCompressiveTest) {};

Member Function Documentation

◆ fields()

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

Returns example JSON object for ModelDeck configuration.

Returns
JSON object with example configuration

Definition at line 58 of file testDeck.h.

58 {
59 static const std::vector<Field<TestDeck>> f = {
60 field(&TestDeck::d_testName, "Test_Name", std::string(),
61 "Post-processing applied after the run"),
62 };
63 return f;
64 }
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_testName, and inp::field().

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

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

◆ getExampleJson() [1/3]

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

Returns the block with the given fields set.

Kept so that existing callers continue to compile. Prefer the form that names each field.

Parameters
testNamePost-processing applied after the run
particleIdCompressiveTestWall the reaction is measured on
particleForceDirectionCompressiveTestDirection of that reaction
Returns
JSON object for this deck

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

A test name 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::TestDeck::getExampleJson ( const json &  given = json::object())
inlinestatic

Returns the block with the given fields set.

Without a test name the block is empty and no post-processing is done. The compressive test reads a sub-block that names the wall, so it is written here rather than declared as a field.

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

Definition at line 85 of file testDeck.h.

85 {
86 json j = applyGiven(given, fields(), {"Compressive_Test"});
87 const auto name = j.at("Test_Name").get<std::string>();
88 if (name.empty())
89 return json({});
90 if (isCompressive(name) && j.find("Compressive_Test") == j.end())
91 j["Compressive_Test"] =
92 json{{"Wall_Id", size_t(0)}, {"Wall_Force_Direction", size_t(0)}};
93 return j;
94 }
nlohmann::ordered_json json
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< TestDeck > > & fields()
Returns example JSON object for ModelDeck configuration.
Definition testDeck.h:58
static bool isCompressive(const std::string &name)
True when the name selects the compressive test.
Definition testDeck.h:71

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

Referenced by anonymous_namespace{testDeckRoundTrip.cpp}::testTestDeck().

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

◆ getExampleJson() [3/3]

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

Returns the block with the given fields set.

Kept so that existing callers continue to compile. Prefer the form that names each field.

Parameters
testNamePost-processing applied after the run
particleIdCompressiveTestWall the reaction is measured on
particleForceDirectionCompressiveTestDirection of that reaction
Returns
JSON object for this deck

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

A test name 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.

◆ isCompressive()

static bool inp::TestDeck::isCompressive ( const std::string &  name)
inlinestatic

True when the name selects the compressive test.

Parameters
nameTest name
Returns
bool True for either spelling

Definition at line 71 of file testDeck.h.

71 {
72 return name == "Compressive_Test" || name == "compressive_test";
73 }

Referenced by getExampleJson(), and readFromJson().

Here is the caller graph for this function:

◆ print()

void inp::TestDeck::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 161 of file testDeck.h.

161{ 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 testDeck.h:142

References printStr().

Here is the call graph for this function:

◆ printStr()

std::string inp::TestDeck::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 142 of file testDeck.h.

142 {
143 auto tabS = util::io::getTabS(nt);
144 std::ostringstream oss;
145 oss << tabS << "------- TestDeck --------" << std::endl << std::endl;
146 printFields(*this, oss, fields(), tabS);
147 oss << tabS << "Particle id for compressive test = " << d_particleIdCompressiveTest << std::endl;
148 oss << tabS << "Particle force direction for compressive test = " << d_particleForceDirectionCompressiveTest <<
149 std::endl;
150 oss << tabS << std::endl;
151
152 return oss.str();
153 }
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_particleForceDirectionCompressiveTest, d_particleIdCompressiveTest, fields(), util::io::getTabS(), and inp::printFields().

Referenced by print().

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

◆ readFromJson()

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

Reads from json object.

Definition at line 121 of file testDeck.h.

121 {
122 if (j.empty())
123 return;
124
125 readFields(*this, j, fields());
127 if (j.find("Compressive_Test") == j.end())
128 throw std::runtime_error("Compressive test requires Compressive_Test section");
129
130 d_particleIdCompressiveTest = j.at("Compressive_Test").value("Wall_Id", 0);
131 d_particleForceDirectionCompressiveTest = j.at("Compressive_Test").value("Wall_Force_Direction", 0);
132 }
133 }
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_particleForceDirectionCompressiveTest, d_particleIdCompressiveTest, d_testName, fields(), isCompressive(), and inp::readFields().

Referenced by anonymous_namespace{testDeckRoundTrip.cpp}::testTestDeck().

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

Field Documentation

◆ d_particleForceDirectionCompressiveTest

size_t inp::TestDeck::d_particleForceDirectionCompressiveTest

if it is a compressive test, specify force direction on wall

Definition at line 34 of file testDeck.h.

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

◆ d_particleIdCompressiveTest

size_t inp::TestDeck::d_particleIdCompressiveTest

if it is a compressive test, specify wall id and direction

Definition at line 31 of file testDeck.h.

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

◆ d_testName

std::string inp::TestDeck::d_testName

Specify test name (if any)

Definition at line 28 of file testDeck.h.

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


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