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 "util/io.h"
16#include "util/json.h"
17
18namespace inp {
25 struct TestDeck {
27 std::string d_testName;
28
31
34
35
43
47 TestDeck(std::string testName, size_t particleIdCompressiveTest = 0,
48 size_t particleForceDirectionCompressiveTest = 0)
49 : d_testName(testName),
50 d_particleIdCompressiveTest(particleIdCompressiveTest),
51 d_particleForceDirectionCompressiveTest(particleForceDirectionCompressiveTest) {};
52
57 static json getExampleJson(std::string testName = "", size_t particleIdCompressiveTest = 0,
58 size_t particleForceDirectionCompressiveTest = 0) {
59
60 if (testName == "")
61 return json({});
62
63 auto j = json({"Test_Name", testName});
64
65 if (testName == "Compressive_Test") {
66 j["Compressive_Test"] = json{{"Wall_Id", particleIdCompressiveTest},
67 {"Wall_Force_Direction", particleForceDirectionCompressiveTest}};
68 }
69
70 return j;
71 }
72
76 void readFromJson(const json &j) {
77 if (j.empty())
78 return;
79
80 d_testName = j.value("Test_Name", "");
81 const bool compressive =
82 d_testName == "Compressive_Test" || d_testName == "compressive_test";
83 if (compressive) {
84 if (j.find("Compressive_Test") == j.end())
85 throw std::runtime_error("Compressive test requires Compressive_Test section");
86
87 d_particleIdCompressiveTest = j.at("Compressive_Test").value("Wall_Id", 0);
88 d_particleForceDirectionCompressiveTest = j.at("Compressive_Test").value("Wall_Force_Direction", 0);
89 }
90 }
91
99 std::string printStr(int nt = 0, int lvl = 0) const {
100 auto tabS = util::io::getTabS(nt);
101 std::ostringstream oss;
102 oss << tabS << "------- TestDeck --------" << std::endl << std::endl;
103 oss << tabS << "Test name = " << d_testName << std::endl;
104 oss << tabS << "Particle id for compressive test = " << d_particleIdCompressiveTest << std::endl;
105 oss << tabS << "Particle force direction for compressive test = " << d_particleForceDirectionCompressiveTest <<
106 std::endl;
107 oss << tabS << std::endl;
108
109 return oss.str();
110 }
111
118 void print(int nt = 0, int lvl = 0) const { std::cout << printStr(nt, lvl); }
119 };
120
122} // namespace inp
123
124#endif //INP_TESTDECK_H
nlohmann::ordered_json json
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
Structure to read and store test-related input data.
Definition testDeck.h:25
void print(int nt=0, int lvl=0) const
Prints the information about the object.
Definition testDeck.h:118
size_t d_particleForceDirectionCompressiveTest
if it is a compressive test, specify force direction on wall
Definition testDeck.h:33
TestDeck(std::string testName, size_t particleIdCompressiveTest=0, size_t particleForceDirectionCompressiveTest=0)
Constructor.
Definition testDeck.h:47
static json getExampleJson(std::string testName="", size_t particleIdCompressiveTest=0, size_t particleForceDirectionCompressiveTest=0)
Returns example JSON object for ModelDeck configuration.
Definition testDeck.h:57
void readFromJson(const json &j)
Reads from json object.
Definition testDeck.h:76
TestDeck(const json &j=json({}))
Constructor.
Definition testDeck.h:39
std::string printStr(int nt=0, int lvl=0) const
Returns the string containing printable information about the object.
Definition testDeck.h:99
std::string d_testName
Specify test name (if any)
Definition testDeck.h:27
size_t d_particleIdCompressiveTest
if it is a compressive test, specify wall id and direction
Definition testDeck.h:30