PeriDEM 0.2.0
PeriDEM -- Peridynamics-based high-fidelity model for granular media
Loading...
Searching...
No Matches
refParticle.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 "refParticle.h"
13#include "fe/baseElem.h"
14#include "util/geom.h"
15#include <iostream>
16
17// Reference particle class
19 std::shared_ptr<model::ModelData> model_data,
20 std::shared_ptr<util::geometry::GeomObject> geom,
21 std::shared_ptr<fe::Mesh> mesh)
22 : d_id(id),
23 d_modelData_p(model_data),
24 d_geom_p(geom),
25 d_mesh_p(mesh),
26 d_centerNode(0),
27 d_pRadius(geom->boundingRadius()) {
28
29 if (d_pRadius < 1.0E-10) {
30 std::cerr << "Error: Reference particle radius is too small.\n";
31 exit(1);
32 }
33
34 // find the node which is closest to the particle center
35 // also add node near boundary to list
36 auto center = d_geom_p->center();
37 auto dx = util::Point();
38 double dist = d_geom_p->boundingRadius();
39 for (size_t i = 0; i < mesh->getNumNodes(); i++) {
40 dx = center - mesh->getNode(i);
41 if (util::isLess(dx.length(), dist)) {
42 dist = dx.length();
43 d_centerNode = i;
44 }
45 }
46}
47
48std::string particle::RefParticle::printStr(int nt, int lvl) const {
49
50 auto tabS = util::io::getTabS(nt);
51 std::ostringstream oss;
52 oss << tabS << "------- Reference particle --------" << std::endl
53 << std::endl;
54
55 oss << tabS << "Mesh pointer = " << d_mesh_p.get() << std::endl;
56 oss << tabS << "Mesh info: " << std::endl;
57 oss << d_mesh_p->printStr(nt + 1, lvl);
58 oss << tabS << "Center node = " << d_centerNode << std::endl;
59 oss << tabS << "Center node location = " << getNode(d_centerNode).printStr()
60 << std::endl;
61 oss << tabS << "Geometry info: " << std::endl;
62 oss << d_geom_p->printStr(nt + 1, lvl);
63 oss << tabS << "Radius = " << d_pRadius << std::endl;
64 oss << tabS << "Num interior flag data = " << d_intFlags.size() << std::endl;
65
66 oss << tabS << std::endl;
67
68 return oss.str();
69}
RefParticle(size_t id, std::shared_ptr< model::ModelData > model_data, std::shared_ptr< util::geometry::GeomObject > geom, std::shared_ptr< fe::Mesh > mesh)
Constructor.
std::string printStr(int nt=0, int lvl=0) const
Returns the string containing printable information about the object.
size_t d_centerNode
Id of mesh node closest to the particle center.
double d_pRadius
Particle radius.
std::shared_ptr< util::geometry::GeomObject > d_geom_p
Geometrical object defining this particle.
std::string getTabS(int nt)
Returns tab spaces of given size.
Definition io.h:40
bool isLess(const double &a, const double &b)
Returns true if a < b.
Definition function.cpp:20
A structure to represent 3d vectors.
Definition point.h:30