PeriDEM 0.3.0
PeriDEM -- Peridynamics-based high-fidelity model for granular media
Loading...
Searching...
No Matches
testDeck.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_TESTDECK_H
12#define INP_TESTDECK_H
13
14#include <string>
15#include "deckField.h"
16#include "util/io.h"
17#include "util/json.h"
18
19namespace inp {
26 struct TestDeck {
28 std::string d_testName;
29
32
35
36
44
48 TestDeck(std::string testName, size_t particleIdCompressiveTest = 0,
49 size_t particleForceDirectionCompressiveTest = 0)
50 : d_testName(testName),
51 d_particleIdCompressiveTest(particleIdCompressiveTest),
52 d_particleForceDirectionCompressiveTest(particleForceDirectionCompressiveTest) {};
53
58 static const std::vector<Field<TestDeck>> &fields() {
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 }
65
71 static bool isCompressive(const std::string &name) {
72 return name == "Compressive_Test" || name == "compressive_test";
73 }
74
85 static json getExampleJson(const json &given = json::object()) {
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 }
95
114 static json getExampleJson(const std::string &) = delete;
116 static json getExampleJson(const char *) = delete;
117
121 void readFromJson(const json &j) {
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 }
134
142 std::string printStr(int nt = 0, int lvl = 0) const {
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 }
154
161 void print(int nt = 0, int lvl = 0) const { std::cout << printStr(nt, lvl); }
162 };
163
165} // namespace inp
166
167#endif //INP_TESTDECK_H
nlohmann::ordered_json json
Collection of methods and database related to input.
Definition pairForce.h:20
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
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
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
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
std::string getTabS(int nt)
Returns tab spaces of a given size.
Definition io.h:82
Structure to read and store test-related input data.
Definition testDeck.h:26
void print(int nt=0, int lvl=0) const
Prints the information about the object.
Definition testDeck.h:161
size_t d_particleForceDirectionCompressiveTest
if it is a compressive test, specify force direction on wall
Definition testDeck.h:34
TestDeck(std::string testName, size_t particleIdCompressiveTest=0, size_t particleForceDirectionCompressiveTest=0)
Constructor.
Definition testDeck.h:48
static json getExampleJson(const char *)=delete
Returns the block with the given fields set.
static json getExampleJson(const std::string &)=delete
Returns the block with the given fields set.
void readFromJson(const json &j)
Reads from json object.
Definition testDeck.h:121
TestDeck(const json &j=json({}))
Constructor.
Definition testDeck.h:40
static const std::vector< Field< TestDeck > > & fields()
Returns example JSON object for ModelDeck configuration.
Definition testDeck.h:58
std::string printStr(int nt=0, int lvl=0) const
Returns the string containing printable information about the object.
Definition testDeck.h:142
static json getExampleJson(const json &given=json::object())
Returns the block with the given fields set.
Definition testDeck.h:85
static bool isCompressive(const std::string &name)
True when the name selects the compressive test.
Definition testDeck.h:71
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