PeriDEM 0.2.0
PeriDEM -- Peridynamics-based high-fidelity model for granular media
Loading...
Searching...
No Matches
baseParticle.cpp
Go to the documentation of this file.
1/*
2 * -------------------------------------------
3 * Copyright (c) 2021 - 2024 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#include "baseParticle.h"
12#include "util/methods.h"
13#include "fe/baseElem.h"
14#include "fe/quadElem.h"
15#include "fe/tetElem.h"
16#include "fe/triElem.h"
18#include "util/feElementDefs.h"
19#include "util/geom.h"
20#include <iostream>
21
22particle::BaseParticle::BaseParticle(std::string particle_type)
23: d_type(particle_type),
24 d_typeIndex(-1),
25 d_id(0),
26 d_typeId(0),
27 d_zoneId(0),
28 d_dim(0),
29 d_particleDescription(""),
30 d_isWall(false),
31 d_numNodes(0),
32 d_h(0.),
33 d_horizon(0.),
34 d_density(0.),
35 d_allDofsConstrained(false),
36 d_computeForce(true),
37 d_material_p(nullptr),
38 d_Rc(0.),
39 d_Kn(0.),
40 d_globStart(0),
41 d_globEnd(0),
42 d_globQuadStart(0),
43 d_globQuadEnd(0),
44 d_modelData_p(nullptr),
45 d_rp_p(nullptr),
46 d_geom_p(nullptr),
47 d_tform(particle::ParticleTransform()),
48 d_mesh_p(nullptr) {
49
50 if (particle_type == "particle") {
51 d_typeIndex = 0;
52 d_isWall = false;
53 }
54 else if (particle_type == "wall") {
55 d_typeIndex = 1;
56 d_isWall = true;
57 }
58}
59
60particle::BaseParticle::BaseParticle(std::string particle_type,
61 size_t id,
62 size_t particle_type_id,
63 size_t zone_id,
64 size_t dim,
65 std::string particle_description,
66 bool is_particle_a_wall,
67 bool are_all_dofs_constrained,
68 size_t num_nodes,
69 double h,
70 std::shared_ptr<model::ModelData> model_data,
71 std::shared_ptr<particle::RefParticle> ref_particle,
72 std::shared_ptr<util::geometry::GeomObject> geom,
74 std::shared_ptr<fe::Mesh> mesh,
75 inp::MaterialDeck &material_deck,
76 bool populate_data)
77 : d_type(particle_type),
78 d_typeIndex(-1),
79 d_id(id),
80 d_typeId(particle_type_id),
81 d_zoneId(zone_id),
82 d_dim(dim),
83 d_particleDescription(particle_description),
84 d_isWall(is_particle_a_wall),
85 d_numNodes(num_nodes),
86 d_h(h),
87 d_horizon(0),
88 d_density(0),
89 d_allDofsConstrained(are_all_dofs_constrained),
90 d_computeForce(true),
91 d_material_p(nullptr),
92 d_Rc(0.),
93 d_Kn(0.),
94 d_globStart(0),
95 d_globEnd(0),
96 d_globQuadStart(0),
97 d_globQuadEnd(0),
98 d_modelData_p(model_data),
99 d_rp_p(ref_particle),
100 d_geom_p(geom),
101 d_tform(transform),
102 d_mesh_p(mesh),
103 d_pRadius(geom->boundingRadius()) {
104
105 if (d_type == "particle")
106 d_typeIndex = 0;
107 else if (d_type == "wall")
108 d_typeIndex = 1;
109
111
112 // check
113 if (d_type == "particle" and d_isWall) {
114 std::cerr << "Error: Can not have d_type = 'particle' and d_isWall = true.\n";
116 }
117 if (d_type == "wall" and !d_isWall) {
118 std::cerr << "Error: Can not have d_type = 'wall' and d_isWall = false.\n";
120 }
121
122 if (populate_data) {
123
124 d_globStart = d_modelData_p->d_x.size();
125 d_globEnd = d_modelData_p->d_x.size() + d_rp_p->getNumNodes();
126
127 for (size_t i = 0; i < d_rp_p->getNumNodes(); i++) {
128
129 d_modelData_p->d_xRef.push_back(d_tform.apply(d_rp_p->getNode(i)));
130 d_modelData_p->d_x.push_back(d_tform.apply(d_rp_p->getNode(i)));
131 d_modelData_p->d_u.push_back(util::Point());
132 d_modelData_p->d_v.push_back(util::Point());
133 d_modelData_p->d_vMag.push_back(0.);
134 d_modelData_p->d_f.push_back(util::Point());
135 d_modelData_p->d_vol.push_back(
136 d_rp_p->getNodalVolume(i) *
137 std::pow(d_tform.d_scale, d_rp_p->getDimension()));
138 d_modelData_p->d_fix.push_back(uint8_t(0));
139 d_modelData_p->d_forceFixity.push_back(uint8_t(0));
140 d_modelData_p->d_thetaX.push_back(0.);
141 d_modelData_p->d_mX.push_back(0.);
142 d_modelData_p->d_ptId.push_back(id); // id of this particle
143 }
144 }
145
147 d_globEnd);
148
149 // initialize material class
151 // double horizon = d_geom_p->inscribedRadius();
152 double horizon = p_material_deck.d_horizon;
153 if (p_material_deck.d_horizonMeshRatio > 0.)
154 horizon = p_material_deck.d_horizonMeshRatio * d_h;
155
156 if (p_material_deck.d_materialType == "RNPBond")
157 d_material_p = std::make_unique<material::RnpMaterial>(
158 p_material_deck, d_rp_p->getDimension(), horizon);
159 else if (p_material_deck.d_materialType == "PMBBond")
160 d_material_p = std::make_unique<material::PmbMaterial>(
161 p_material_deck, d_rp_p->getDimension(), horizon);
162 else if (p_material_deck.d_materialType == "PDElasticBond")
163 d_material_p = std::make_unique<material::PdElastic>(
164 p_material_deck, d_rp_p->getDimension(), horizon);
165 else if (p_material_deck.d_materialType == "PDState")
166 d_material_p = std::make_unique<material::PdState>(
167 p_material_deck, d_rp_p->getDimension(), horizon);
168
169 d_horizon = horizon;
170 d_density = d_material_p->getDensity();
171
172 // d_material_p->print();
173
174 // set contact radius for internal contact
175 d_Rc = 0.95 * d_h;
176
177 // set contact coefficient for internal contact
178 d_Kn = (18. / (M_PI * std::pow(horizon, 5))) *
179 d_material_p->computeMaterialProperties(getDimension()).d_K;
180
181 if (!d_computeForce) {
182 std::cout << "Warning: Compute force is OFF in particle with id = "
183 << d_id << "\n";
184 }
186 std::cout << "Warning: All DoFs are OFF in particle with id = "
187 << d_id << "\n";
188 }
189}
190
191std::string particle::BaseParticle::printStr(int nt, int lvl) const {
192
193 auto tabS = util::io::getTabS(nt);
194 std::ostringstream oss;
195 oss << tabS << "------- BaseParticle --------" << std::endl
196 << std::endl;
197
198 oss << tabS << "d_type = " << d_type << std::endl;
199 oss << tabS << "d_particleDescription = " << d_particleDescription << std::endl;
200 oss << tabS << "d_typeIndex = " << d_typeIndex << std::endl;
201 oss << tabS << "d_isWall = " << d_isWall << std::endl;
202 oss << tabS << "d_id = " << d_id << std::endl;
203 oss << tabS << "d_typeId = " << d_typeId << std::endl;
204 oss << tabS << "d_zoneId = " << d_zoneId << std::endl;
205 oss << tabS << "d_dim = " << d_dim << std::endl;
206 oss << tabS << "d_numNodes = " << d_numNodes << std::endl;
207 oss << tabS << "d_pRadius = " << d_pRadius << std::endl;
208 oss << tabS << "d_h = " << d_h << std::endl;
209 oss << tabS << "d_allDofsConstrained = " << d_allDofsConstrained << std::endl;
210 oss << tabS << "d_computeForce = " << d_computeForce << std::endl;
211 oss << tabS << "d_horizon = " << d_horizon << std::endl;
212 oss << tabS << "d_density = " << d_density << std::endl;
213 oss << tabS << "d_Rc = " << d_Rc << std::endl;
214 oss << tabS << "d_Kn = " << d_Kn << std::endl;
215 oss << tabS << "d_globStart = " << d_globStart << std::endl;
216 oss << tabS << "d_globEnd = " << d_globEnd << std::endl;
217 oss << tabS << "d_globQuadStart = " << d_globQuadStart << std::endl;
218 oss << tabS << "d_globQuadEnd = " << d_globQuadEnd << std::endl;
219 oss << tabS << std::endl;
220 oss << tabS << std::endl;
221 oss << tabS << "Ref particle info = " << std::endl;
222 oss << d_rp_p->printStr(nt + 1, lvl);
223 oss << tabS << "Geometry info: " << std::endl;
224 oss << d_geom_p->printStr(nt + 1, lvl);
225
226 oss << tabS << std::endl;
227
228 return oss.str();
229}
particle::ParticleTransform d_tform
Transformation related data.
double d_Rc
Contact radius for contact between internal nodes of particle.
bool d_allDofsConstrained
Specify if all dofs are constrained so we do not update displacement, velocity, and force data.
bool d_computeForce
Specify if we compute force.
double d_horizon
horizon
double d_h
mesh size
size_t d_globStart
Id of first node of this object in global node list.
double d_density
density
std::shared_ptr< model::ModelData > d_modelData_p
Reference to model class.
bool d_isWall
Is this particle actually a wall?
size_t d_id
Id of this particle in all particles list.
BaseParticle(std::string particle_type="none")
Constructor.
size_t d_dim
Dimension of this particle.
size_t getDimension() const
Get id among the group of object in the same type as this.
std::string d_type
particle type, e.g., particle or wall
size_t d_globEnd
Id of last node of this object in global node list.
std::string printStr(int nt=0, int lvl=0) const
Returns the string containing printable information about the object.
std::unique_ptr< material::Material > d_material_p
Pointer to peridynamic material object.
double d_Kn
Normal contact coefficient for internal contact.
std::shared_ptr< particle::RefParticle > d_rp_p
Pointer to reference particle.
Collection of methods and data related to particle object.
std::string getTabS(int nt)
Returns tab spaces of given size.
Definition io.h:40
double computeMeshSize(const std::vector< util::Point > &nodes)
Computes minimum distance between any two nodes.
Definition geom.cpp:551
Structure to read and store material related data.
A struct that stores transformation parameters and provides method to transform the particle....
util::Point apply(const util::Point &v) const
Returns the transformed vector. We assume that the passed vector passes through origin.
double d_scale
Volumetric scaling factor.
A structure to represent 3d vectors.
Definition point.h:30