PeriDEM 0.3.0
PeriDEM -- Peridynamics-based high-fidelity model for granular media
Loading...
Searching...
No Matches
materialDeck.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_MATERIALDECK_H
12#define INP_MATERIALDECK_H
13
14#include "deckField.h"
15#include "util/io.h"
16#include "util/json.h"
17#include <cmath>
18#include <string>
19#include <vector>
20
21namespace inp {
22
24struct MatData {
25
32 double d_E;
33
35 double d_G;
36
38 double d_K;
39
41 double d_nu;
42
44 double d_lambda;
45
47 double d_mu;
48
57 double d_KIc;
58
60 double d_Gc;
61
68 : d_E(-1.), d_G(-1.), d_K(-1.), d_nu(-1.), d_lambda(-1.), d_mu(-1.),
69 d_KIc(-1.), d_Gc(-1.){};
70
76 MatData(const MatData &md)
77 : d_E(md.d_E), d_G(md.d_G), d_K(md.d_K), d_nu(md.d_nu),
78 d_lambda(md.d_lambda), d_mu(md.d_mu), d_KIc(md.d_KIc), d_Gc(md.d_Gc){};
79
92 static const std::vector<Field<MatData>> &fields() {
93 static const std::vector<Field<MatData>> f = {
94 field(&MatData::d_E, "E", -1., "Young's modulus"),
95 field(&MatData::d_G, "G", -1., "Shear modulus"),
96 field(&MatData::d_K, "K", -1., "Bulk modulus"),
97 field(&MatData::d_lambda, "Lambda", -1., "First Lame parameter"),
98 field(&MatData::d_mu, "Mu", -1., "Second Lame parameter"),
99 field(&MatData::d_nu, "Poisson_Ratio", -1., "Poisson ratio"),
100 field(&MatData::d_Gc, "Gc", -1., "Critical energy release rate"),
101 field(&MatData::d_KIc, "KIc", -1., "Critical stress intensity factor"),
102 };
103 return f;
104 }
105
106 void readFromJson(const json &j) {
107 if (j.empty())
108 return;
109 readFields(*this, j, fields());
110 }
111
119 std::string printStr(int nt = 0, int lvl = 0) const {
120
121 auto tabS = util::io::getTabS(nt);
122 std::ostringstream oss;
123 oss << tabS << "------- MatData --------" << std::endl << std::endl;
124 oss << tabS << "Young's modulus = " << d_E << std::endl;
125 oss << tabS << "Shear modulus = " << d_G << std::endl;
126 oss << tabS << "Bulk modulus = " << d_K << std::endl;
127 oss << tabS << "Poisson ratio = " << d_nu << std::endl;
128 oss << tabS << "Lame parameter Lambda = " << d_lambda << std::endl;
129 oss << tabS << "Lame parameter Mu = " << d_mu << std::endl;
130 oss << tabS << "Critical stress intensity factor = " << d_KIc << std::endl;
131 oss << tabS << "Critical energy release rate = " << d_Gc << std::endl;
132 oss << tabS << std::endl;
133
134 return oss.str();
135 }
136
143 void print(int nt = 0, int lvl = 0) const { std::cout << printStr(nt, lvl); }
144
156 double toNu(double lambda, double mu) { return lambda * 0.5 / (lambda + mu); }
157
164 double toNuEG(double E, double G) { return E * 0.5 / G - 1.; }
165
172 double toE(double K, double nu) { return K * (3. * (1. - 2. * nu)); }
173
180 double toK(double E, double nu) { return E / (3. * (1. - 2. * nu)); }
181
189 double toLambdaE(double E, double nu) {
190 return E * nu / ((1. + nu) * (1. - 2. * nu));
191 }
192
200 double toLambdaK(double K, double nu) { return 3. * K * nu / (1. + nu); }
201
208 double toGE(double E, double nu) { return E / (2. * (1. + nu)); }
209
216 double toGK(double K, double nu) {
217 return 3. * K * (1. - 2. * nu) / (2. * (1. + nu));
218 }
219
227 double toELambda(double lambda, double nu) {
228 return lambda * (1. + nu) * (1. - 2. * nu) / nu;
229 }
230
244 double toGc(double KIc, double nu, double E) { return KIc * KIc / E; }
245
259 double toKIc(double Gc, double nu, double E) { return std::sqrt(Gc * E); }
260
262};
263
271
277
279 std::string d_materialType;
280
283
286
289
291 std::vector<double> d_bondPotentialParams;
292
294 std::vector<double> d_statePotentialParams;
295
297 std::vector<double> d_influenceFnParams;
298
305
308
311
314
317
319 double d_density;
320
322 double d_horizon;
323
326
339
343 MaterialDeck(std::string materialType, bool isPlainStrain = false,
344 double horizon = -1., double horizonMeshRatio = -1., double density = 1.,
345 double K = 0., double G = 0., double Gc = 0., bool computeParamsFromElastic = true,
346 size_t influenceFnType = 0)
347 : d_materialType(materialType),
349 d_influenceFnType(influenceFnType), d_irreversibleBondBreak(true),
351 d_computeParamsFromElastic(computeParamsFromElastic), d_matData(inp::MatData()),
352 d_density(density), d_horizon(horizon), d_horizonMeshRatio(horizonMeshRatio) {
353
354 d_matData.d_K = K;
355 d_matData.d_G = G;
356 d_matData.d_Gc = Gc;
357 };
358
379
388 static const std::vector<Field<MaterialDeck>> &fields() {
389 static const std::vector<Field<MaterialDeck>> f = {
390 field(&MaterialDeck::d_materialType, "Type", std::string(),
391 "Peridynamic material model"),
392 field(&MaterialDeck::d_density, "Density", 1., "Mass density"),
394 "Compute_From_Classical", true,
395 "Derive the bond parameters from the elastic constants"),
396 field<MaterialDeck, bool>(&MaterialDeck::d_isPlaneStrain,
397 "Is_Plane_Strain", false,
398 "Plane strain rather than plane stress", {},
399 [](const bool &v) { return v; }),
400 field<MaterialDeck, double>(&MaterialDeck::d_horizon, "Horizon", -1.,
401 "Peridynamic horizon", {},
402 [](const double &v) { return v > 0.; }),
403 field<MaterialDeck, double>(&MaterialDeck::d_horizonMeshRatio,
404 "Horizon_Mesh_Ratio", -1.,
405 "Horizon as a multiple of the mesh size",
406 {},
407 [](const double &v) { return v > 0.; }),
408 field<MaterialDeck, std::vector<double>>(
409 &MaterialDeck::d_bondPotentialParams, "Bond_Potential_Params", {},
410 "Bond parameters given directly rather than derived", {},
411 [](const std::vector<double> &v) { return !v.empty(); }),
412 field<MaterialDeck, std::vector<double>>(
413 &MaterialDeck::d_statePotentialParams, "State_Potential_Params",
414 {}, "State parameters given directly rather than derived", {},
415 [](const std::vector<double> &v) { return !v.empty(); }),
416 };
417 return f;
418 }
419
424 static const std::vector<Field<MaterialDeck>> &influenceFields() {
425 static const std::vector<Field<MaterialDeck>> f = {
426 field(&MaterialDeck::d_influenceFnType, "Type", size_t(0),
427 "Influence function used in the bond force"),
428 field<MaterialDeck, std::vector<double>>(
429 &MaterialDeck::d_influenceFnParams, "Parameters", {},
430 "Parameters of the influence function", {},
431 [](const std::vector<double> &v) { return !v.empty(); }),
432 };
433 return f;
434 }
435
440 static const std::vector<OneOf> &groups() {
441 static const std::vector<OneOf> g = {
442 {"the horizon", {"Horizon", "Horizon_Mesh_Ratio"}},
443 };
444 return g;
445 }
446
463 static json getExampleJson(const json &given = json::object()) {
464 const std::vector<std::string> extra = {"E", "K", "G", "Gc",
465 "Influence_Function"};
466 json j = applyGiven(given, fields(), extra);
467 checkGroups(j, groups());
468 return j;
469 }
470
477 static json getExampleJson(const std::string &) = delete;
479 static json getExampleJson(const char *) = delete;
480
484 void readFromJson(const json &j) {
485 if (j.empty())
486 return;
487
488 // read mat data
490
491 readFields(*this, j, fields());
492
493 // Older decks spell this Is_Plain_Strain. The table reads the current
494 // spelling, so the older one is applied when it alone is present.
495 if (j.find("Is_Plane_Strain") == j.end() &&
496 j.find("Is_Plain_Strain") != j.end())
497 d_isPlaneStrain = j.at("Is_Plain_Strain").get<bool>();
498
499 checkGroups(j, groups());
500
501 if (j.find("Influence_Function") != j.end())
502 readFields(*this, j.at("Influence_Function"), influenceFields());
504 throw std::runtime_error(
505 "Compute_From_Classical is false but Bond_Potential_Params is missing.");
506 }
507
515 std::string printStr(int nt = 0, int lvl = 0) const {
516
517 auto tabS = util::io::getTabS(nt);
518 std::ostringstream oss;
519 oss << tabS << "------- MaterialDeck --------" << std::endl << std::endl;
520 oss << tabS << "Is plain strain = " << d_isPlaneStrain << std::endl;
521 oss << tabS << "Material type = " << d_materialType << std::endl;
522 oss << tabS << "Bond potential type = " << d_bondPotentialType << std::endl;
523 oss << tabS << "Bond potential params = ["
524 << util::io::printStr<double>(d_bondPotentialParams, 0) << "]"
525 << std::endl;
526 oss << tabS << "State potential type = " << d_statePotentialType
527 << std::endl;
528 oss << tabS << "State potential params = ["
529 << util::io::printStr<double>(d_statePotentialParams, 0) << "]"
530 << std::endl;
531 oss << tabS << "Influence function type = " << d_influenceFnType
532 << std::endl;
533 oss << tabS << "Influence function params = ["
534 << util::io::printStr<double>(d_influenceFnParams, 0) << "]"
535 << std::endl;
536 oss << tabS
537 << "Irreversible bond breaking enabled = " << d_irreversibleBondBreak
538 << std::endl;
539 oss << tabS << "State contribution from broken bond enabled = "
540 << d_stateContributionFromBrokenBond << std::endl;
541 oss << tabS << "Check Sc factor = " << d_checkScFactor << std::endl;
542 oss << tabS << "Compute parameters from elastic properties = "
543 << d_computeParamsFromElastic << std::endl;
544 oss << d_matData.printStr(nt + 1, lvl);
545 oss << tabS << "Density = " << d_density << std::endl;
546 oss << tabS << "Horizon = " << d_horizon << std::endl;
547 oss << tabS << "Horizon to mesh ratio = " << d_horizonMeshRatio
548 << std::endl;
549 oss << tabS << std::endl;
550
551 return oss.str();
552 }
553
560 void print(int nt = 0, int lvl = 0) const { std::cout << printStr(nt, lvl); }
561};
562
565} // namespace inp
566
567#endif // INP_MATERIALDECK_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
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
void checkGroups(const json &block, const std::vector< OneOf > &groups)
Checks that each group has exactly one of its keys.
Definition deckField.h:317
std::string getTabS(int nt)
Returns tab spaces of a given size.
Definition io.h:82
Structure for elastic properties and fracture properties.
double toGc(double KIc, double nu, double E)
Compute critical energy release rate Gc from critical stress-intensity factor KIc,...
double toLambdaE(double E, double nu)
Compute Lame first parameter lambda from Young's modulus E and Poisson's ratio nu.
void print(int nt=0, int lvl=0) const
Prints the information about the object.
double d_mu
Lame second parameter.
double toGK(double K, double nu)
Compute shear modulus from Bulk modulus K and Poisson's ratio nu.
double toKIc(double Gc, double nu, double E)
Compute critical stress-intensity factor KIc from critical energy release rate Gc,...
void readFromJson(const json &j)
double d_KIc
Critical stress intensity factor.
MatData(const MatData &md)
Copy constructor.
double toK(double E, double nu)
Compute Bulk modulus K from Young's modulus K and Poisson's ratio nu.
double d_K
Bulk modulus.
double d_lambda
Lame first parameter.
double toNu(double lambda, double mu)
Compute Poisson's ratio from Lame parameters.
double toGE(double E, double nu)
Compute shear modulus from Young's modulus E and Poisson's ratio nu.
double d_nu
Poisson's ratio.
double d_G
Shear modulus or Lame second parameter.
static const std::vector< Field< MatData > > & fields()
Reads from json object.
double toELambda(double lambda, double nu)
Compute Young's modulus E from Lame first parameter lambda and Poisson's ratio nu.
double toLambdaK(double K, double nu)
Compute Lame first parameter lambda from Bulk modulus K and Poisson's ratio nu.
double toNuEG(double E, double G)
Compute Poisson's ratio from Young's and Shear modulus.
double d_E
Young's elastic modulus.
MatData()
Constructor.
std::string printStr(int nt=0, int lvl=0) const
Returns the string containing printable information about the object.
double d_Gc
Critical energy release rate.
double toE(double K, double nu)
Compute Young's modulus E from Bulk modulus K and Poisson's ratio nu.
Structure to read and store material related data.
MaterialDeck(const json &j=json({}))
Constructor.
bool d_isPlaneStrain
Indicates if the 2-d simulation is of plane-strain type (thick material) or plane-stress type (thin m...
static json getExampleJson(const json &given=json::object())
Returns example JSON object for ModelDeck configuration.
double d_density
Density of material.
static const std::vector< OneOf > & groups()
Quantities this deck accepts in more than one form.
MaterialDeck(std::string materialType, bool isPlainStrain=false, double horizon=-1., double horizonMeshRatio=-1., double density=1., double K=0., double G=0., double Gc=0., bool computeParamsFromElastic=true, size_t influenceFnType=0)
Constructor.
size_t d_bondPotentialType
Type of pairwise (bond-based) potential.
double d_horizonMeshRatio
Horizon to mesh ratio.
size_t d_influenceFnType
Type of influence function.
std::vector< double > d_bondPotentialParams
List of parameters for pairwise potential.
void readFromJson(const json &j)
Reads from json object.
static json getExampleJson(const std::string &)=delete
Rejects a value given where a set of named values is expected.
std::string d_materialType
Material type.
double d_horizon
Horizon for peridynamic interaction.
bool d_stateContributionFromBrokenBond
Flag for contribution to hydrostatic force from the broken bond.
static const std::vector< Field< MaterialDeck > > & fields()
The fields of the block itself.
bool d_computeParamsFromElastic
Compute Peridynamic material properties from elastic properties.
inp::MatData d_matData
List of elastic and fracture properties.
std::vector< double > d_influenceFnParams
List of parameters for influence function.
size_t d_statePotentialType
Type of hydrostatic (state-based) potential.
std::vector< double > d_statePotentialParams
List of parameters for hydrostatic potential.
bool d_irreversibleBondBreak
Flag for irreversible breaking of bonds.
static json getExampleJson(const char *)=delete
Rejects a value given where a set of named values is expected.
double d_checkScFactor
Factor to check if bond is broken.
std::string printStr(int nt=0, int lvl=0) const
Returns the string containing printable information about the object.
void print(int nt=0, int lvl=0) const
Prints the information about the object.
static const std::vector< Field< MaterialDeck > > & influenceFields()
The fields of the Influence_Function sub-block.
MaterialDeck(const MaterialDeck &md)
Copy constructor.