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