PeriDEM 0.2.0
PeriDEM -- Peridynamics-based high-fidelity model for granular media
Loading...
Searching...
No Matches
influenceFn.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 "influenceFn.h"
12#include <cmath>
13
15 const std::vector<double> &params, const size_t &dim)
16 : BaseInfluenceFn(), d_a0(0.) {
17
18 d_a0 = params.empty() ? double(dim + 1) : params[0];
19}
20
21double material::ConstInfluenceFn::getInfFn(const double &r) const {
22 return d_a0;
23}
24
25double material::ConstInfluenceFn::getMoment(const size_t &i) const {
26 return d_a0 / double(i + 1);
27}
28
30 const std::vector<double> &params, const size_t &dim)
31 : BaseInfluenceFn(), d_a0(0.), d_a1(0.) {
32
33 if (params.empty()) {
34 // choose a0, a1 = -a0 such that \int_0^1 J(r) r^d dr = 1
35 // and J(r) = a0 (1 - r)
36 if (dim == 1) {
37 d_a0 = 6.;
38 d_a1 = -d_a0;
39 } else if (dim == 2) {
40 d_a0 = 12.;
41 d_a1 = -d_a0;
42 } else if (dim == 3) {
43 d_a0 = 20.;
44 d_a1 = -d_a0;
45 }
46 } else {
47 d_a0 = params[0];
48 if (params.size() < 2)
49 d_a1 = -d_a0;
50 else
51 d_a1 = params[1];
52 }
53}
54
55double material::LinearInfluenceFn::getInfFn(const double &r) const {
56 return d_a0 + d_a1 * r;
57}
58
59double material::LinearInfluenceFn::getMoment(const size_t &i) const {
60 return (d_a0 / double(i + 1)) + (d_a1 / double(i + 2));
61}
62
64 const std::vector<double> &params, const size_t &dim)
65 : BaseInfluenceFn(), d_alpha(0.), d_beta(0.) {
66
67 if (params.empty()) {
68 // beta = 0.2 (default value)
69 // choose alpha such that \int_0^1 J(r) r^d dr = 1
70 d_beta = 0.2;
71 if (dim == 1)
72 d_alpha = 2. / (d_beta * (1. - std::exp(-1. / d_beta)));
73 else if (dim == 2)
74 d_alpha = (4.0 / d_beta) * 1.0 /
75 (std::sqrt(M_PI * d_beta) * std::erf(1.0 / std::sqrt(d_beta)) -
76 2.0 * std::exp(-1.0 / d_beta));
77 else if (dim == 3)
78 d_alpha = (2.0 / d_beta) * 1.0 /
79 (d_beta - (d_beta + 1.) * std::exp(-1.0 / d_beta));
80 } else {
81 d_alpha = params[0];
82 d_beta = params[1];
83 }
84}
85
86double material::GaussianInfluenceFn::getInfFn(const double &r) const {
87 return d_alpha * std::exp(-r * r / d_beta);
88}
89
90double material::GaussianInfluenceFn::getMoment(const size_t &i) const {
91
92 double sq1 = std::sqrt(d_beta);
93 double sq2 = std::sqrt(M_PI);
94 // M_i = \int_0^1 alpha exp(-r^2/beta) r^i dr
95
96 if (i == 0) {
97 // M0 = 0.5 * \alpha (\beta)^(1/2) * (pi)^(1/2) * erf((1/beta)^(1/2))
98
99 return 0.5 * d_alpha * sq1 * sq2 * std::erf(1. / sq1);
100 } else if (i == 1) {
101 // M1 = 0.5 * \alpha \beta (1 - exp(-1/beta))
102
103 return 0.5 * d_alpha * d_beta * (1. - std::exp(-1. / d_beta));
104 } else if (i == 2) {
105 // M2 = 0.5 * \alpha (\beta)^(3/2) * [0.5 * (pi)^(1/2) erf((1/beta)^(1/2)
106 // ) - (1/beta)^(1/2) * exp(-1/beta) ]
107
108 return 0.5 * d_alpha * d_beta * sq1 *
109 (0.5 * sq2 * std::erf(1. / sq1) -
110 (1. / sq1) * std::exp(-1. / d_beta));
111 } else if (i == 3) {
112 // M3 = 0.5 * \alpha (\beta)^(2) * [1 - ((1/beta) + 1) * exp(-1/beta)]
113
114 return 0.5 * d_alpha * d_beta * d_beta *
115 (1. - (1. + 1. / d_beta) * std::exp(-1. / d_beta));
116 } else {
117 std::cerr << "Error: getMoment() accepts argument i from 0 to 3.\n";
118 exit(1);
119 }
120
121
122}
A base class for computing influence function.
Definition influenceFn.h:22
double getMoment(const size_t &i) const override
Returns the moment of influence function.
ConstInfluenceFn(const std::vector< double > &params, const size_t &dim)
Constructor.
double getInfFn(const double &r) const override
Returns the value of influence function.
double d_a0
Constant such that J(r) = Constant.
double getInfFn(const double &r) const override
Returns the value of influence function.
GaussianInfluenceFn(const std::vector< double > &params, const size_t &dim)
Constructor.
double getMoment(const size_t &i) const override
Returns the moment of influence function.
double d_a0
Constants such that J(r) = d_a0 + d_a1 * r.
double getInfFn(const double &r) const override
Returns the value of influence function.
double d_a1
Constants such that J(r) = d_a0 + d_a1 * r.
LinearInfluenceFn(const std::vector< double > &params, const size_t &dim)
Constructor.
double getMoment(const size_t &i) const override
Returns the moment of influence function.