PeriDEM 0.3.0
PeriDEM -- Peridynamics-based high-fidelity model for granular media
Loading...
Searching...
No Matches
outputDeck.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_OUTPUTDECK_H
12#define INP_OUTPUTDECK_H
13
14#include "deckField.h"
15#include "util/io.h"
16#include "util/json.h"
17#include "util/vecMethods.h"
18#include <stdexcept>
19#include <string>
20#include <vector>
21
22namespace inp {
29 struct OutputDeck {
34 std::string d_outFormat;
35
40 std::string d_path;
41
43 std::vector<std::string> d_outTags;
44
46 size_t d_dtOut;
47
49 size_t d_dtOutOld;
50
58 size_t d_debug;
59
67
69 std::string d_compressType;
70
81 std::string d_outCriteria;
82
88
90 std::vector<double> d_outCriteriaParams;
91
94
97
99 std::string d_tagPPFile;
100
106
110 OutputDeck(const json& j = json({}))
111 : d_outFormat("vtu"), d_path("./"), d_dtOut(0), d_dtOutOld(0), d_debug(0),
113 d_dtTestOut(0), d_tagPPFile(""), d_pvdCollection(false) {
114
115 readFromJson(j);
116 };
117
118
122 OutputDeck(std::string outFormat,
123 std::string path = "./",
124 std::vector<std::string> outTags = {"Displacement"},
125 size_t outputInterval = 1,
126 size_t debug = 2,
127 bool performFEOut = true,
128 std::string compressType = "zlib",
129 bool performOut = true,
130 size_t dtTestOut = 1,
131 std::string tagPPFile = "",
132 bool pvdCollection = false)
133 : d_outFormat(outFormat), d_path(path),
134 d_dtOut(outputInterval), d_dtOutOld(outputInterval), d_dtOutCriteria(outputInterval),
135 d_debug(debug),
136 d_performFEOut(performFEOut), d_compressType(compressType),
137 d_performOut(performOut), d_dtTestOut(dtTestOut), d_tagPPFile(tagPPFile),
138 d_pvdCollection(pvdCollection), d_outTags(outTags){};
139
151 static json getExampleJson(const std::string &) = delete;
153 static json getExampleJson(const char *) = delete;
154
164 static const std::vector<Field<OutputDeck>> &fields() {
165 static const std::vector<Field<OutputDeck>> f = {
166 field(&OutputDeck::d_path, "Path", std::string("./"),
167 "Directory the output is written to"),
168 field(&OutputDeck::d_performOut, "Perform_Out", true,
169 "Write output at all"),
170 field(&OutputDeck::d_outTags, "Tags", std::vector<std::string>(),
171 "Fields written at each output step"),
172 field(&OutputDeck::d_dtOut, "Output_Interval", size_t(1),
173 "Steps between outputs", {{}, size_t(1), {}}),
174 field(&OutputDeck::d_debug, "Debug", size_t(2),
175 "How much is written to the log"),
176 field(&OutputDeck::d_performFEOut, "Perform_FE_Out", true,
177 "Write the finite element mesh as well as the nodes"),
178 field(&OutputDeck::d_compressType, "Compress_Type",
179 std::string("zlib"), "Compression used in the output files"),
180 field(&OutputDeck::d_outFormat, "File_Format", std::string("vtu"),
181 "Output file format"),
182 field(&OutputDeck::d_dtTestOut, "Test_Output_Interval", size_t(1),
183 "Steps between post-processing outputs"),
184 field(&OutputDeck::d_tagPPFile, "Tag_PP", std::string(),
185 "Suffix of the post-processing file"),
186 // Absent unless a collection is asked for, which is how the decks
187 // in the repository were written.
188 field<OutputDeck, bool>(&OutputDeck::d_pvdCollection,
189 "PVD_Collection", false,
190 "Write a PVD file indexing the time steps",
191 {}, [](const bool &v) { return v; }),
192 };
193 return f;
194 }
195
201 static json getExampleJson(const json &given = json::object()) {
202 return applyGiven(given, fields(), {"Output_Criteria"});
203 }
204
208 void readFromJson(const json &j) {
209 if (j.empty())
210 return ;
211
212 readFields(*this, j, fields());
213
214 // An empty path names the working directory.
215 if (d_path.empty())
216 d_path = "./";
217
218 // Both follow the output interval until the criteria block changes one.
221
222 if (j.contains("Output_Criteria")) {
223 d_outCriteria = j.at("Output_Criteria").value("Type", std::string(""));
224 d_dtOutCriteria = j.at("Output_Criteria").value("New_Interval", size_t(1));
225 d_outCriteriaParams = j.at("Output_Criteria").value("Parameters", std::vector<double>());
226 if (d_dtOutCriteria < 1)
227 throw std::runtime_error(
228 "Output_Criteria.New_Interval must be >= 1 (use 1 to write every step).");
229 }
230 }
231
239 std::string printStr(int nt = 0, int lvl = 0) const {
240 auto tabS = util::io::getTabS(nt);
241 std::ostringstream oss;
242 oss << tabS << "------- OutputDeck --------" << std::endl << std::endl;
243 printFields(*this, oss, fields(), tabS);
244 oss << tabS << "Output_Interval before the criteria = " << d_dtOutOld
245 << std::endl;
246 oss << tabS << "Output_Criteria.Type = " << d_outCriteria << std::endl;
247 oss << tabS << "Output_Criteria.New_Interval = " << d_dtOutCriteria
248 << std::endl;
249 oss << tabS << "Output_Criteria.Parameters = "
250 << util::io::printStr<double>(d_outCriteriaParams, 0) << std::endl;
251 oss << tabS << std::endl;
252
253 return oss.str();
254 }
255
262 void print(int nt = 0, int lvl = 0) const { std::cout << printStr(nt, lvl); }
263 };
264
266} // namespace inp
267
268#endif // INP_OUTPUTDECK_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 input data for performing simulation output.
Definition outputDeck.h:29
size_t d_dtTestOut
Size of time steps (or frequency) for output operation.
Definition outputDeck.h:96
std::vector< std::string > d_outTags
List of tags of data to be dumped.
Definition outputDeck.h:43
static json getExampleJson(const char *)=delete
Returns example JSON object for ModelDeck configuration.
void print(int nt=0, int lvl=0) const
Prints the information about the object.
Definition outputDeck.h:262
std::string d_compressType
Compressor type for .vtu files.
Definition outputDeck.h:69
size_t d_dtOutCriteria
Specify output frequency if output criteria is met.
Definition outputDeck.h:87
void readFromJson(const json &j)
Reads from json object.
Definition outputDeck.h:208
std::string printStr(int nt=0, int lvl=0) const
Returns the string containing printable information about the object.
Definition outputDeck.h:239
std::string d_outCriteria
Specify output criteria to change output frequency.
Definition outputDeck.h:81
size_t d_dtOut
Size of time steps (or frequency) for output operation.
Definition outputDeck.h:46
bool d_performFEOut
Flag specifying if element-node connectivity should not be dumped.
Definition outputDeck.h:66
static const std::vector< Field< OutputDeck > > & fields()
The fields of this deck, declared once.
Definition outputDeck.h:164
std::string d_outFormat
Output format. Allowed values are vtu, msh, legacy_vtk.
Definition outputDeck.h:34
std::string d_path
Output Path where the files will be written.
Definition outputDeck.h:40
std::string d_tagPPFile
Tag for postprocessing file.
Definition outputDeck.h:99
size_t d_debug
Level below which a message is logged.
Definition outputDeck.h:58
bool d_performOut
Perform vtu output.
Definition outputDeck.h:93
size_t d_dtOutOld
Size of time steps (or frequency) for output operation.
Definition outputDeck.h:49
std::vector< double > d_outCriteriaParams
List of parameters required in checking output criteria.
Definition outputDeck.h:90
OutputDeck(std::string outFormat, std::string path="./", std::vector< std::string > outTags={"Displacement"}, size_t outputInterval=1, size_t debug=2, bool performFEOut=true, std::string compressType="zlib", bool performOut=true, size_t dtTestOut=1, std::string tagPPFile="", bool pvdCollection=false)
Constructor.
Definition outputDeck.h:122
static json getExampleJson(const std::string &)=delete
Returns example JSON object for ModelDeck configuration.
OutputDeck(const json &j=json({}))
Constructor.
Definition outputDeck.h:110
bool d_pvdCollection
If true, write a ParaView .pvd collection alongside VTU files so one file can be opened to animate al...
Definition outputDeck.h:105
static json getExampleJson(const json &given=json::object())
Returns the block with the given fields set.
Definition outputDeck.h:201