11#ifndef INP_CONTACTDECK_H
12#define INP_CONTACTDECK_H
32 std::vector<std::vector<ContactPairDeck>>
d_data;
78 static const std::vector<Field<ContactDeck>> &
fields() {
79 static const std::vector<Field<ContactDeck>> f = {
81 std::string(
"com_and_node"),
"Where contact damping is applied",
82 {{
"com_and_node",
"com",
"node",
"off"}, {}, {}}),
84 std::string(
"coulomb_simple"),
"Tangential contact law",
85 {{
"coulomb_simple",
"stick_slip"}, {}, {}}),
87 "Scale the neighbor volume by the overlap with the contact "
105 const auto nSets = j.value(
"Sets",
size_t(0));
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)] = {};
125 auto nSets = j.value(
"Sets",
size_t(0));
127 for (
size_t i=0; i<nSets; i++)
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);
137 if (j.find(set_name) == j.end())
138 throw std::runtime_error(
"Set " + set_name +
" not found in contact block.");
140 auto js = j.at(set_name);
143 std::vector<int> copy_set = js.value(
"Copy_Data", std::vector<int>({-1, -1}));
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.");
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);
172 std::string
printStr(
int nt = 0,
int lvl = 0)
const {
175 std::ostringstream oss;
176 oss << tabS <<
"------- ContactDeck --------" << std::endl << std::endl;
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:"
186 oss << tabS << std::endl;
197 void print(
int nt = 0,
int lvl = 0)
const { std::cout <<
printStr(nt, lvl); }
nlohmann::ordered_json json
Collection of methods and database related to input.
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.
void readFields(Deck &d, const json &j, const std::vector< Field< Deck > > &fs)
Reads every field of the table from the block.
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.
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.
std::string getTabS(int nt)
Returns tab spaces of a given size.