PeriDEM 0.3.0
PeriDEM -- Peridynamics-based high-fidelity model for granular media
Loading...
Searching...
No Matches
contactPairDeck.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_CONTACTPAIRDECK_H
12#define INP_CONTACTPAIRDECK_H
13
14
15#include "util/io.h"
16#include "util/json.h"
17
18namespace inp {
27
29 double d_contactR;
30
33
35
36 double d_vMax;
37 double d_deltaMax;
38 double d_Kn;
39 double d_KnFactor;
41
43
44 double d_eps;
45 double d_betan;
49
51
52 double d_mu;
54 double d_K;
56
60 ContactPairDeck(const json &j = json({}))
61 : d_contactR(0.), d_computeContactR(true), d_vMax(0.), d_deltaMax(0.),
62 d_Kn(0.), d_eps(1.), d_betan(0.), d_mu(0.), d_dampingOn(true),
63 d_frictionOn(true), d_KnFactor(1.), d_betanFactor(1.), d_K(0.) {
64 readFromJson(j);
65 };
66
70 ContactPairDeck(double contactR, bool computeContactR = true,
71 bool dampingOn = true, bool frictionOn = true,
72 double Kn = 0., double eps = 1., double mu = 0.,
73 double KnFactor = 1., double betanFactor = 1.,
74 double deltaMax = 1., double vMax = 0.)
75 : d_contactR(contactR), d_computeContactR(computeContactR), d_vMax(vMax), d_deltaMax(deltaMax),
76 d_Kn(Kn), d_eps(eps), d_betan(0.), d_mu(mu), d_dampingOn(dampingOn),
77 d_frictionOn(frictionOn), d_KnFactor(KnFactor), d_betanFactor(betanFactor), d_K(0.) {
78 };
79
93
98 static json getExampleJson(double contactR = 0., bool computeContactR = true,
99 bool dampingOn = true, bool frictionOn = true,
100 double Kn = 0., double eps = 1., double mu = 0.,
101 double KnFactor = 1., double betanFactor = 1.,
102 double deltaMax = 1., double vMax = 0., double K = 0.) {
103
104 auto j = json({});
105
106 if (computeContactR) {
107 if (contactR < 1E-10) {
108 throw std::runtime_error("Conctar radius factor can not be zero.");
109 }
110 j["Contact_Radius_Factor"] = contactR;
111 } else {
112 j["Contact_Radius"] = contactR;
113 }
114
115 if (Kn < 1.E-10) {
116 if (vMax < 1.E-10) throw std::runtime_error("Need V_Max parameter for contact force.");
117 else j["V_Max"] = vMax;
118
119 if (deltaMax < 1.E-10) deltaMax = 1.;
120 j["Delta_Max"] = deltaMax;
121 } else {
122 j["Kn"] = Kn;
123 }
124
125 if (dampingOn and betanFactor < 1.E-10) dampingOn = false;
126 if (!dampingOn) betanFactor = 0.;
127
128 if (frictionOn and mu < 1.E-10) {
129 throw std::runtime_error("Friction coefficient can not be zero.");
130 }
131
132 if (K > 1.E-10)
133 j["K"] = K;
134
135 j["Damping_On"] = dampingOn;
136 j["Epsilon"] = eps;
137
138 j["Friction_On"] = frictionOn;
139 j["Friction_Coeff"] = mu;
140
141 j["Kn_Factor"] = KnFactor;
142 j["Beta_n_Factor"] = betanFactor;
143
144 return j;
145 }
146
150 void readFromJson(const json &j) {
151
152 if (j.empty())
153 return;
154
155 if (j.find("Contact_Radius_Factor") != j.end()) {
156 d_computeContactR = true;
157 d_contactR = j.at("Contact_Radius_Factor");
158 } else {
159 if (j.find("Contact_Radius") == j.end())
160 throw std::runtime_error("Need Contact_Radius or Contact_Radius_Factor.");
161
162 d_computeContactR = false;
163 d_contactR = j.at("Contact_Radius");
164 }
165
166 if (j.find("Kn") != j.end()) {
167 d_Kn = j.at("Kn");
168 d_deltaMax = 1.;
169 d_vMax = std::sqrt(d_Kn);
170 } else {
171 if (j.find("V_Max") == j.end()) throw std::runtime_error("V_Max is needed for contact.");
172
173 d_vMax = j.at("V_Max");
174 d_deltaMax = j.value("Delta_Max", 1.);
175 }
176 d_KnFactor = j.value("Kn_Factor", 1.);
177
178 d_dampingOn = j.value("Damping_On", true);
179 d_eps = j.value("Epsilon", 1.);
180 d_betanFactor = j.value("Beta_n_Factor", 1.);
181 if (d_betanFactor < 1.E-8)
182 d_dampingOn = false;
183
184 if (!d_dampingOn)
185 d_betanFactor = 0.;
186
187 d_frictionOn = j.value("Friction_On", true);
188 d_mu = j.value("Friction_Coeff", 0.);
189 d_K = j.value("K", 0.);
190
191 if (d_frictionOn and d_mu < 1.E-10) {
192 throw std::runtime_error("Friction coefficient can not be zero.");
193 }
194 if (d_frictionOn and d_K < 1.E-10) {
195 throw std::runtime_error("Bulk modulus can not be zero.");
196 }
197 }
198
199
207 std::string printStr(int nt = 0, int lvl = 0) const {
208 auto tabS = util::io::getTabS(nt);
209 std::ostringstream oss;
210 oss << tabS << "------- ContactPairDeck --------" << std::endl << std::endl;
211 oss << tabS << "Contact radius = " << d_contactR << std::endl;
212 oss << tabS << "v_max = " << d_vMax << ", Delta_max = " << d_deltaMax
213 << ", Kn = " << d_Kn << std::endl;
214 oss << tabS << "epsilon = " << d_eps << ", Beta_n = " << d_betan << std::endl;
215 oss << tabS << "Friction coefficient = " << d_mu << std::endl;
216 oss << tabS << "Damping status = " << d_dampingOn << std::endl;
217 oss << tabS << "Kn factor = " << d_KnFactor
218 << ", Beta n factor = " << d_betanFactor << std::endl;
219 oss << tabS << "Bulk modulus = " << d_K << std::endl;
220 oss << tabS << std::endl;
221 return oss.str();
222 }
223
230 void print(int nt = 0, int lvl = 0) const { std::cout << printStr(nt, lvl); }
231 };
232
234} // namespace inp
235
236#endif // INP_CONTACTPAIRDECK_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 particle-particle contact related input data.
double d_contactR
contact radius
ContactPairDeck(double contactR, bool computeContactR=true, bool dampingOn=true, bool frictionOn=true, double Kn=0., double eps=1., double mu=0., double KnFactor=1., double betanFactor=1., double deltaMax=1., double vMax=0.)
Constructor.
void readFromJson(const json &j)
Reads from json object.
bool d_frictionOn
parameters for frictional force
double d_eps
parameters for normal damping force
bool d_computeContactR
Flag that indicates whether contact radius is to be computed.
ContactPairDeck(const ContactPairDeck &cd)
Copy constructor.
void print(int nt=0, int lvl=0) const
Prints the information about the object.
double d_betan
parameters for normal damping force
double d_betanFactor
parameters for normal damping force
static json getExampleJson(double contactR=0., bool computeContactR=true, bool dampingOn=true, bool frictionOn=true, double Kn=0., double eps=1., double mu=0., double KnFactor=1., double betanFactor=1., double deltaMax=1., double vMax=0., double K=0.)
Returns example JSON object for ModelDeck configuration.
double d_vMax
parameters for normal force
double d_KnFactor
parameters for normal force
double d_Kn
parameters for normal force
std::string printStr(int nt=0, int lvl=0) const
Returns the string containing printable information about the object.
double d_mu
parameters for frictional force
double d_K
parameters for frictional force
double d_deltaMax
parameters for normal force
bool d_dampingOn
parameters for normal damping force
ContactPairDeck(const json &j=json({}))
Constructor.