PeriDEM 0.3.0
PeriDEM -- Peridynamics-based high-fidelity model for granular media
Loading...
Searching...
No Matches
particleFLoading.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 "particleFLoading.h"
12#include "particleLoadingUtil.h"
14#include "util/function.h"
15
16namespace {
17
18bool isInList(const size_t &i, const std::vector<size_t> &list) {
19 for (const auto &l : list)
20 if (l == i)
21 return true;
22
23 return false;
24}
25
26} // namespace
27
29 std::vector<inp::BCBaseDeck> &bc_data) {
30
31 d_bcData = bc_data;
32}
33
34void loading::ParticleFLoading::apply(const double &time,
36
37 for (size_t s = 0; s < d_bcData.size(); s++) {
38
39 // get alias for bc data
40 const auto &bc = d_bcData[s];
41
42 // check if we need to process this particle
43 if (!needToProcessParticle(particle->getId(), bc))
44 continue;
45
46 // get bounding box (quite possibly be generic)
47 auto reg_box = bc.d_regionGeomData.d_geom_p == nullptr ? std::pair<util::Point, util::Point>(util::Point(), util::Point()) : bc.d_regionGeomData.d_geom_p->box();
48
49 for (size_t i = 0; i < particle->getNumNodes(); i++) {
50
51 const auto x = particle->getXRefLocal(i);
52 double fmax = 1.0;
53
54 auto box = reg_box;
55 if (!bc.d_isRegionActive) {
56 // get box from particle
57 box = particle->d_geom_p->box();
58 }
59
60 if (needToComputeDof(x, particle->getId(), bc)) {
61
62 // apply spatial function
63 if (bc.d_spatialFnType == "hat_x") {
64 fmax = bc.d_spatialFnParams[0] *
65 util::hatFunction(x.d_x, box.first.d_x,
66 box.second.d_x);
67 } else if (bc.d_spatialFnType == "hat_y") {
68 fmax = bc.d_spatialFnParams[0] *
69 util::hatFunction(x.d_y, box.first.d_y,
70 box.second.d_y);
71 } else if (bc.d_spatialFnType == "sin_x") {
72 double a = M_PI * bc.d_spatialFnParams[0];
73 fmax = bc.d_spatialFnParams[0] * std::sin(a * x.d_x);
74 } else if (bc.d_spatialFnType == "sin_y") {
75 double a = M_PI * bc.d_spatialFnParams[0];
76 fmax = bc.d_spatialFnParams[0] * std::sin(a * x.d_y);
77 } else if (bc.d_spatialFnType == "linear_x") {
78 double a = bc.d_spatialFnParams[0];
79 fmax = bc.d_spatialFnParams[0] * a * x.d_x;
80 } else if (bc.d_spatialFnType == "linear_y") {
81 double a = bc.d_spatialFnParams[0];
82 fmax = bc.d_spatialFnParams[0] * a * x.d_y;
83 }
84
85 // apply time function
86 if (bc.d_timeFnType == "linear")
87 fmax *= time;
88 else if (bc.d_timeFnType == "linear_step")
89 fmax *= util::linearStepFunc(time, bc.d_timeFnParams[1],
90 bc.d_timeFnParams[2]);
91 else if (bc.d_timeFnType == "linear_slow_fast") {
92 if (util::isGreater(time, bc.d_timeFnParams[1]))
93 fmax *= bc.d_timeFnParams[3] * time;
94 else
95 fmax *= bc.d_timeFnParams[2] * time;
96 } else if (bc.d_timeFnType == "sin") {
97 double a = M_PI * bc.d_timeFnParams[1];
98 fmax *= std::sin(a * time);
99 }
100
101 // multiply by the slope
102 fmax *= bc.d_timeFnParams[0];
103
104 auto force_i = util::Point();
105 for (auto d : bc.d_direction) {
106 force_i[d-1] = fmax;
107 }
108
109 // add force
110 particle->addFLocal(i, force_i);
111 } // if compute force
112 }
113 } // loop over bc sets
114}
void apply(const double &time, particle::BaseParticle *particle)
Applies force boundary condition.
ParticleFLoading(std::vector< inp::BCBaseDeck > &bc_data)
Constructor.
std::vector< inp::BCBaseDeck > d_bcData
List of displacement bcs.
A class to store particle geometry, nodal discretization, and methods.
bool isInList(const size_t &i, const std::vector< size_t > &list)
bool needToProcessParticle(size_t id, const inp::BCBaseDeck &bc)
Function that checks if given particle with id = id needs to be processed within boundary condition d...
bool needToComputeDof(const util::Point &x, size_t id, const inp::BCBaseDeck &bc)
Function that checks if we need to do computation at a given point x within a particle with id = id.
Collection of methods and data related to particle object.
Definition modelData.h:36
bool isGreater(const double &a, const double &b)
Returns true if a > b.
Definition function.cpp:17
double hatFunction(const double &x, const double &x_min, const double &x_max)
Computes hat function at given point.
Definition function.cpp:27
double linearStepFunc(const double &x, const double &x1, const double &x2)
Compute linear step function.
Definition function.cpp:64
A structure to represent 3d vectors.
Definition point.h:30