PeriDEM 0.3.0
PeriDEM -- Peridynamics-based high-fidelity model for granular media
Loading...
Searching...
No Matches
contactDeck.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_CONTACTDECK_H
12#define INP_CONTACTDECK_H
13
14#include "contactPairDeck.h"
15#include "deckField.h"
16#include "util/json.h"
17
18namespace inp {
19
28
32 std::vector<std::vector<ContactPairDeck>> d_data;
33
35 std::string d_dampingLaw;
36
38 std::string d_frictionLaw;
39
46
50 ContactDeck(const json &j = json({}))
51 : d_dampingLaw("com_and_node"), d_frictionLaw("coulomb_simple"),
52 d_correctVolume(true) {
53 readFromJson(j);
54 };
55
63 const ContactPairDeck &getContact(const size_t &i, const size_t &j) const {
64 //return d_data[i < j ? i : j][i < j ? j : i];
65 return d_data[i][j];
66 }
67
69 ContactPairDeck &getContact(const size_t &i, const size_t &j) {
70 //return d_data[i < j ? i : j][i < j ? j : i];
71 return d_data[i][j];
72 }
73
78 static const std::vector<Field<ContactDeck>> &fields() {
79 static const std::vector<Field<ContactDeck>> f = {
80 field(&ContactDeck::d_dampingLaw, "Damping_Law",
81 std::string("com_and_node"), "Where contact damping is applied",
82 {{"com_and_node", "com", "node", "off"}, {}, {}}),
83 field(&ContactDeck::d_frictionLaw, "Friction_Law",
84 std::string("coulomb_simple"), "Tangential contact law",
85 {{"coulomb_simple", "stick_slip"}, {}, {}}),
86 field(&ContactDeck::d_correctVolume, "Correct_Volume", true,
87 "Scale the neighbor volume by the overlap with the contact "
88 "sphere"),
89 };
90 return f;
91 }
92
103 static json getExampleJson(const json &given = json::object()) {
104 json j = applyGiven(given, fields(), {"Sets"});
105 const auto nSets = j.value("Sets", size_t(0));
106 if (nSets == 0)
107 return json({});
108
109 for (size_t i = 0; i < nSets; i++)
110 for (size_t k = i; k < nSets; k++)
111 j["Set_" + std::to_string(i + 1) + "_" + std::to_string(k + 1)] = {};
112
113 return j;
114 }
115
119 void readFromJson(const json &j) {
120 if (j.empty())
121 return;
122
123 readFields(*this, j, fields());
124
125 auto nSets = j.value("Sets", size_t(0));
126 d_data.resize(nSets);
127 for (size_t i=0; i<nSets; i++)
128 d_data[i].resize(nSets);
129
130 for (size_t i = 0; i < nSets; i++) {
131 for (size_t k = i; k < nSets; k++) {
132 std::string set_name = "Set_" + std::to_string(i+1) + "_" + std::to_string(k+1);
133 //std::cout << "\n\n\n processing " << set_name << "\n\n\n" << std::flush;
134
135 auto cd = inp::ContactPairDeck();
136
137 if (j.find(set_name) == j.end())
138 throw std::runtime_error("Set " + set_name + " not found in contact block.");
139
140 auto js = j.at(set_name);
141
142 // copy this set from previous set?
143 std::vector<int> copy_set = js.value("Copy_Data", std::vector<int>({-1, -1}));
144 //std::cout << "copy_data = " << copy_set[0] << ", " << copy_set[1] << "\n" << std::flush;
145
146 // check
147 if ((copy_set[0] != -1 and copy_set[1] == -1) or (copy_set[0] == -1 and copy_set[1] != -1) or (copy_set.size() != 2))
148 throw std::runtime_error("The pair of set ids for copying is invalid in contact block.");
149
150 if (copy_set[0] != -1) {
151 std::string copy_set_tag = "Set_" + std::to_string(copy_set[0]) + "_" + std::to_string(copy_set[1]);
152 auto js_copy = j.at(copy_set_tag);
153 cd.readFromJson(js_copy);
154 } else {
155 cd.readFromJson(js);
156 }
157
158 d_data[i][k] = cd;
159 if (i != k)
160 d_data[k][i] = cd;
161 }
162 }
163 }
164
172 std::string printStr(int nt = 0, int lvl = 0) const {
173
174 auto tabS = util::io::getTabS(nt);
175 std::ostringstream oss;
176 oss << tabS << "------- ContactDeck --------" << std::endl << std::endl;
177 printFields(*this, oss, fields(), tabS);
178 for (size_t i =0; i<d_data.size(); i++) {
179 for (size_t j = 0; j < d_data.size(); j++) {
180 oss << tabS << "ContactPairData id = (" << i << "," << j << ") info:"
181 << std::endl;
182 oss << getContact(i,j).printStr(nt+2, lvl);
183 }
184 }
185
186 oss << tabS << std::endl;
187
188 return oss.str();
189 }
190
197 void print(int nt = 0, int lvl = 0) const { std::cout << printStr(nt, lvl); }
198};
199
202} // namespace inp
203
204#endif // INP_CONTACTDECK_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 particle-particle contact related input data.
Definition contactDeck.h:27
ContactPairDeck & getContact(const size_t &i, const size_t &j)
Returns the contact data.
Definition contactDeck.h:69
void print(int nt=0, int lvl=0) const
Prints the information about the object.
std::string d_dampingLaw
Contact damping law name (default com_and_node).
Definition contactDeck.h:35
const ContactPairDeck & getContact(const size_t &i, const size_t &j) const
Returns the contact data.
Definition contactDeck.h:63
std::string d_frictionLaw
Friction law name (default coulomb_simple).
Definition contactDeck.h:38
static const std::vector< Field< ContactDeck > > & fields()
Returns example JSON object for ModelDeck configuration.
Definition contactDeck.h:78
void readFromJson(const json &j)
Reads from json object.
bool d_correctVolume
If true (default), DEM contact uses partial neighbor volume near the contact radius (correctedContact...
Definition contactDeck.h:45
ContactDeck(const json &j=json({}))
Constructor.
Definition contactDeck.h:50
std::string printStr(int nt=0, int lvl=0) const
Returns the string containing printable information about the object.
std::vector< std::vector< ContactPairDeck > > d_data
Store contact parameters for each pair of zone.
Definition contactDeck.h:32
static json getExampleJson(const json &given=json::object())
Returns the block with the given fields set.
Structure to read and store particle-particle contact related input data.
std::string printStr(int nt=0, int lvl=0) const
Returns the string containing printable information about the object.