PeriDEM 0.3.0
PeriDEM -- Peridynamics-based high-fidelity model for granular media
Loading...
Searching...
No Matches
restartDeck.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_RESTARTDECK_H
12#define INP_RESTARTDECK_H
13
14#include <string>
15#include "deckField.h"
16#include "util/json.h"
17
18namespace inp {
19
26 struct RestartDeck {
27
29 std::string d_file;
30
32 size_t d_step;
33
37
41 RestartDeck(std::string file, size_t step = 0, bool changeRefFreeDofs = false)
42 : d_file(file), d_step(step), d_changeRefFreeDofs(changeRefFreeDofs) {};
43
47 RestartDeck(const json &j = json({}))
48 : d_file(""), d_step(0), d_changeRefFreeDofs(false) {
49 readFromJson(j);
50 };
51
52
57 static const std::vector<Field<RestartDeck>> &fields() {
58 static const std::vector<Field<RestartDeck>> f = {
59 field(&RestartDeck::d_file, "File", std::string(),
60 "File the state is read from"),
61 field(&RestartDeck::d_step, "Step", size_t(0),
62 "Step the state was written at"),
64 "Change_Reference_Free_Dofs", false,
65 "Move only the bodies that have a free degree of freedom"),
66 };
67 return f;
68 }
69
79 static json getExampleJson(const json &given = json::object()) {
80 json j = applyGiven(given, fields());
81 if (j.at("File").get<std::string>().empty())
82 return json({});
83 return j;
84 }
85
93 static json getExampleJson(const std::string &) = delete;
95 static json getExampleJson(const char *) = delete;
96
101 void readFromJson(const json &j) {
102 if (j.empty())
103 return;
104 readFields(*this, j, fields());
105 }
106
112 json j = json::object();
113 writeFields(*this, j, fields());
114 return j;
115 }
116
124 std::string printStr(int nt = 0, int lvl = 0) const {
125 auto tabS = util::io::getTabS(nt);
126 std::ostringstream oss;
127 oss << tabS << "------- RestartDeck --------" << std::endl << std::endl;
128 printFields(*this, oss, fields(), tabS);
129 oss << tabS << std::endl;
130
131 return oss.str();
132 }
133
140 void print(int nt = 0, int lvl = 0) const { std::cout << printStr(nt, lvl); }
141 };
142
145} // namespace inp
146
147#endif // INP_RESTARTDECK_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 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
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 restart related data input.
Definition restartDeck.h:26
static json getExampleJson(const char *)=delete
Rejects a value given where a set of named values is expected.
json writeToJson() const
Returns this deck as a JSON object.
std::string d_file
restart filename
Definition restartDeck.h:29
static json getExampleJson(const std::string &)=delete
Rejects a value given where a set of named values is expected.
std::string printStr(int nt=0, int lvl=0) const
Returns the string containing printable information about the object.
static const std::vector< Field< RestartDeck > > & fields()
Returns example JSON object for ModelDeck configuration.
Definition restartDeck.h:57
RestartDeck(std::string file, size_t step=0, bool changeRefFreeDofs=false)
Constructor.
Definition restartDeck.h:41
void readFromJson(const json &j)
Reads from json object.
static json getExampleJson(const json &given=json::object())
Returns the block with the given fields set.
Definition restartDeck.h:79
void print(int nt=0, int lvl=0) const
Prints the information about the object.
size_t d_step
Restart time step.
Definition restartDeck.h:32
bool d_changeRefFreeDofs
Change only those particles/walls which have any one of its nodes dof free.
Definition restartDeck.h:36
RestartDeck(const json &j=json({}))
Constructor.
Definition restartDeck.h:47