36 namespace fs = std::filesystem;
37 fs::path n = fs::absolute(dir).lexically_normal();
38 std::string s = n.string();
39 if (!s.empty() && s.back() !=
'/' && s.back() !=
'\\')
40 s += fs::path::preferred_separator;
45 const std::filesystem::path &mesh_cir,
46 const std::filesystem::path &mesh_wall,
double R,
47 double mesh_size,
double horizon,
double Rc_factor,
48 double Kn,
double final_time,
size_t num_steps,
49 bool policy_combo =
false) {
52 "central_difference",
true, 2,
54 model[
"Wall_Contact"] =
"analytical_plane";
56 model[
"Self_Contact"] =
"reference_gap";
57 model[
"Bond_Break"] =
"absolute_stretch";
62 std::vector<std::string>({
"Displacement",
"Force",
"Particle_ID"}),
63 std::max<size_t>(1, num_steps / 5), 1,
false,
"zlib",
false, num_steps,
"",
67 bc[
"Displacement_BC"][
"Set_1"] =
json{
68 {
"Particle_List", std::vector<size_t>{1}},
69 {
"Direction", std::vector<size_t>{1, 2}},
70 {
"Time_Function", {{
"Type",
"constant"}, {
"Parameters", std::vector<double>{0.}}}},
71 {
"Spatial_Function", {{
"Type",
"constant"}}},
72 {
"Zero_Displacement",
true}};
74 const double wall_half = 3.0 * R;
75 const double wall_thick = mesh_size;
81 floor.
d_geomParams = {-wall_half, -wall_thick, 0., wall_half, 0., 0.};
85 auto mesh_set = [&](
const std::filesystem::path &f) {
86 return json{{
"File", f.string()},
89 {
"Info",
"gmsh_builtin_mesh"},
90 {
"Mesh_Size", mesh_size},
91 {
"Write_Mesh_File",
true}}}};
94 {
"Set_1", mesh_set(mesh_cir)},
95 {
"Set_2", mesh_set(mesh_wall)}};
97 const double rho = 1200.0;
98 const double K = 2.16e7;
99 const double G = 1.296e7;
100 const double Gc = 50.0;
110 Rc_factor,
true,
false,
false, Kn, 1.0, 0.0, 1.0,
113 contact_base[
"Kn"] = Kn;
114 contact_base[
"Kn_Factor"] = 1.0;
116 contact[
"Set_1_1"] = contact_base;
117 contact[
"Set_1_2"] = contact_base;
118 contact[
"Set_2_2"] = contact_base;
119 contact[
"Damping_Law"] = policy_combo ?
"node" :
"off";
120 contact[
"Friction_Law"] = policy_combo ?
"stick_slip" :
"coulomb_simple";
123 const double cy = R + 0.25 * mesh_size;
125 pgen[
"Random_Rotation"] =
false;
126 pgen[
"Data"][
"N"] = 2;
127 pgen[
"Data"][
"0"] =
json{{
"x", 0.},
135 pgen[
"Data"][
"1"] =
json{{
"x", 0.},
136 {
"y", -0.5 * wall_thick},
145 return json{{
"Model", model},
147 {
"Displacement_BC", bc[
"Displacement_BC"]},
154 {
"Particle_Generation", pgen}};
158 size_t n_contact_nodes = 0;
159 double min_gap = 1.e300;
160 double max_force_err = 0.;
161 double max_force_ref = 0.;
168 throw std::runtime_error(
"analytical wall: contact path not set up");
171 const double Kn =
contact.d_Kn;
172 const double Rc =
contact.d_contactR;
174 for (
auto &f : dem.
d_f)
179 for (
size_t i = 0; i < dem.
d_x.size(); ++i) {
195 const double err = (dem.
d_f[i] - f_ref).length();
205 double ming = 1.e300;
207 for (
size_t i = 0; i < dem.
d_x.size(); ++i) {
216 return n ? ming : 0.;
221int main(
int argc,
char *argv[]) {
225 unsigned n_threads = 2;
227 n_threads =
static_cast<unsigned>(std::stoi(input.
getCmdOption(
"-nThreads")));
230 namespace fs = std::filesystem;
231 fs::path base = fs::current_path() /
"wall_analytical_run";
234 const fs::path out_dir = base /
"out";
235 const fs::path inp_dir = base /
"inp";
236 fs::create_directories(out_dir);
237 fs::create_directories(inp_dir);
239 const double R = 0.001;
240 const double mesh_size = R / 5.0;
241 const double horizon = 3.0 * mesh_size;
242 const double Rc_factor = 0.95;
243 const double Kn = 1.0e11;
244 const double final_time = 5.0e-4;
245 const size_t num_steps = 5000;
249 buildInputJson(directoryPathWithTrailingSep(out_dir), inp_dir /
"mesh_cir.msh",
250 inp_dir /
"mesh_wall.msh", R, mesh_size, horizon, Rc_factor, Kn,
251 final_time, num_steps, policy_combo);
253 std::ofstream os(inp_dir /
"input.json");
254 os << input_json.dump(2);
257 auto deck = std::make_shared<inp::Input>(input_json);
262 throw std::runtime_error(
"analytical wall: Wall_Contact not analytical_plane");
265 throw std::runtime_error(
"alternate deck: Self_Contact is not reference_gap");
267 throw std::runtime_error(
"alternate deck: Bond_Break is not absolute_stretch");
269 throw std::runtime_error(
"alternate deck: Friction_Law is not stick_slip");
271 throw std::runtime_error(
"alternate deck: Damping_Law is not node");
274 throw std::runtime_error(
"alternate deck: node damping not active on contact");
278 !dem.
d_contact_p->d_wallContact->skipsMeshedGrainWall())
279 throw std::runtime_error(
"analytical wall: must skip meshed grain-wall");
281 const double Rc = dem.
d_particleDeck_p->d_contactDeck.getContact(0, 1).d_contactR;
287 const double push = 0.5 * Rc;
288 for (
size_t i = 0; i < dem.
d_x.size(); ++i) {
291 dem.
d_u[i].d_y -= push;
297 "analytical wall formula: n_contact={}, min_gap={}, Rc={}, max|f_ref|={}, max|f-f_ref|={}\n",
298 frozen.n_contact_nodes, frozen.min_gap, Rc, frozen.max_force_ref,
299 frozen.max_force_err));
300 if (frozen.n_contact_nodes == 0)
301 throw std::runtime_error(
"analytical wall: no grain nodes in contact");
302 if (!(frozen.max_force_ref > 0.))
303 throw std::runtime_error(
"analytical wall: expected nonzero force");
304 if (!(frozen.max_force_err <= 1.e-6 * (1. + frozen.max_force_ref)))
305 throw std::runtime_error(std::format(
306 "analytical wall: force density mismatch vs Kn*(gap-Rc)*voli*(-n): err={}",
307 frozen.max_force_err));
308 if (!(frozen.min_gap > -Rc))
309 throw std::runtime_error(std::format(
310 "analytical wall: deep penetration past Rc in contact config: min_gap={}, Rc={}",
311 frozen.min_gap, Rc));
317 util::io::print(std::format(
"analytical wall after computeForces: min_gap={}, Rc={}\n", ming, Rc));
319 throw std::runtime_error(
320 "analytical wall: expected grain-wall contact (min_gap < Rc)");
322 throw std::runtime_error(std::format(
323 "analytical wall: deep penetration past Rc: min_gap={}, Rc={}", ming, Rc));
std::unique_ptr< contact::Contact > d_contact_p
std::vector< util::Point > d_x
Current positions of the nodes.
std::vector< util::Point > d_xRef
reference positions of the nodes
std::vector< util::Point > d_u
Displacement of the nodes.
std::vector< util::Point > d_f
Total force on the nodes.
std::shared_ptr< inp::ModelDeck > d_modelDeck_p
Pointer to deck holding problem related data.
std::vector< size_t > d_ptId
Global node to particle id (walls are assigned id after last particle id)
std::shared_ptr< inp::ParticleDeck > d_particleDeck_p
Pointer to deck holding particle related data.
std::vector< double > d_vol
Nodal volumes.
std::vector< util::Point > d_v
Velocity of the nodes.
Defines abstract geometrical domain.
virtual bool wallContactQuery(const util::Point &x, WallContactHit &hit) const
Closest-point / signed-gap query for analytical wall contact. Default: unsupported (returns false,...
Infinite plane: free space is the half-space in the normal direction.
nlohmann::ordered_json json
std::string directoryPathWithTrailingSep(const std::filesystem::path &dir)
Probe checkWallSpringOnly(PeriDEMModel &dem, geom::GeomObject &wall_geom)
double minGrainWallGap(PeriDEMModel &dem, geom::GeomObject &wall_geom)
json buildInputJson(const std::string &output_path, const std::filesystem::path &mesh_cir, const std::filesystem::path &mesh_wall, double R, double mesh_size, double horizon, double Rc_factor, double Kn, double final_time, size_t num_steps, bool policy_combo=false)
Collection of methods and data related to finite element and mesh.
Collection of methods and data related to particle object.
void print(const T &msg, int nt=print_default_tab, int printMpiRank=print_default_mpi_rank)
Prints formatted information.
void initNThreads(unsigned int nThreads=std::thread::hardware_concurrency())
Initializes MpiStatus struct.
void initMpi(int argc=0, char *argv[]=nullptr)
Initializes MPI and also creates MpiStatus struct.
Input data for geometrical objects.
std::vector< double > d_geomParams
Zone parameters.
std::string d_geomName
Zone type.
static json getExampleJson(size_t nForceSets=0, size_t nDispSets=0, size_t nICSets=0, bool gravityActive=false, util::Point gravity=util::Point())
Returns example JSON object for ModelDeck configuration.
static json getExampleJson(std::string materialType="PDState", 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, double E=-1.)
Returns example JSON object for ModelDeck configuration.
static json getExampleJson(size_t dim=2, double tFinal=1.0, size_t Nt=10, std::string spatialDiscretization="finite_difference", std::string timeDiscretization="central_difference", bool populateElementNodeConnectivity=true, size_t quadOrder=2, std::string particleSimType="Multi_Particle", int seed=0)
Returns example JSON object for ModelDeck configuration.
static json getExampleJson(std::string outFormat="vtu", std::string path="./", std::vector< std::string > outTags={"Displacement"}, size_t outputInterval=1, size_t debug=2, bool performFEOut=true, std::string compressType="zlib", bool performOut=true, size_t dtTestOut=1, std::string tagPPFile="", bool pvdCollection=false)
Returns example JSON object for ModelDeck configuration.
static json getExampleJson(std::string genMethod="From_File")
Returns example JSON object for ModelDeck configuration.
static json getExampleJson(std::string updateCriteria="simple_all", double sFactor=1., size_t neighUpdateInterval=1, double nearBdNodesTol=0.5)
Returns example JSON object for ModelDeck configuration.
static json getParticleContactExampleJson(size_t nSets=0)
Returns example JSON object for ModelDeck configuration.
static json getParticleGeomExampleJson(std::vector< geom::GeomData > pGeomVec=std::vector< geom::GeomData >())
Returns example JSON object for ModelDeck configuration.
static json getParticleMaterialExampleJson(size_t nSets=0)
Returns example JSON object for ModelDeck configuration.
A structure to represent 3d vectors.
double length() const
Computes the Euclidean length of the vector.