PeriDEM 0.2.0
PeriDEM -- Peridynamics-based high-fidelity model for granular media
Loading...
Searching...
No Matches
material::GaussianInfluenceFn Class Reference

A class to implement Gaussian influence function. More...

#include <influenceFn.h>

Inheritance diagram for material::GaussianInfluenceFn:
Collaboration diagram for material::GaussianInfluenceFn:

Public Member Functions

 GaussianInfluenceFn (const std::vector< double > &params, const size_t &dim)
 Constructor.
 
double getInfFn (const double &r) const override
 Returns the value of influence function.
 
double getMoment (const size_t &i) const override
 Returns the moment of influence function.
 
std::string printStr (int nt, int lvl) const override
 Returns the string containing printable information about the object.
 
void print (int nt, int lvl) const override
 Prints the information about the object.
 
void print () const override
 Prints the information about the object.
 
- Public Member Functions inherited from material::BaseInfluenceFn
 BaseInfluenceFn ()=default
 Constructor.
 

Private Attributes

double d_alpha
 Constants.
 
double d_beta
 Constants.
 

Detailed Description

A class to implement Gaussian influence function.

\( J(r) = \alpha \exp(-r^2/\beta) \)

Definition at line 227 of file influenceFn.h.

Constructor & Destructor Documentation

◆ GaussianInfluenceFn()

material::GaussianInfluenceFn::GaussianInfluenceFn ( const std::vector< double > &  params,
const size_t &  dim 
)

Constructor.

Parameters
paramsList of parameters
dimDimension

Definition at line 63 of file influenceFn.cpp.

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}
BaseInfluenceFn()=default
Constructor.

References d_alpha, and d_beta.

Member Function Documentation

◆ getInfFn()

double material::GaussianInfluenceFn::getInfFn ( const double &  r) const
overridevirtual

Returns the value of influence function.

Parameters
rReference (initial) bond length
Returns
value Influence function at r

Implements material::BaseInfluenceFn.

Definition at line 86 of file influenceFn.cpp.

86 {
87 return d_alpha * std::exp(-r * r / d_beta);
88}

◆ getMoment()

double material::GaussianInfluenceFn::getMoment ( const size_t &  i) const
overridevirtual

Returns the moment of influence function.

If \( J(r) \) is the influence function for \( r\in [0,1)\) then \( i^{th}\) moment is given by

\[ M_i = \int_0^1 J(r) r^i dr. \]

Parameters
iith moment
Returns
moment Moment

Implements material::BaseInfluenceFn.

Definition at line 90 of file influenceFn.cpp.

90 {
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}

Referenced by printStr().

Here is the caller graph for this function:

◆ print() [1/2]

void material::GaussianInfluenceFn::print ( ) const
inlineoverridevirtual

Prints the information about the object.

Reimplemented from material::BaseInfluenceFn.

Definition at line 289 of file influenceFn.h.

289{ print(0, 0); }
void print() const override
Prints the information about the object.

References print().

Referenced by print().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ print() [2/2]

void material::GaussianInfluenceFn::print ( int  nt,
int  lvl 
) const
inlineoverridevirtual

Prints the information about the object.

Parameters
ntNumber of tabs to append before printing
lvlInformation level (higher means more information)

Reimplemented from material::BaseInfluenceFn.

Definition at line 284 of file influenceFn.h.

284 {
285 std::cout << printStr(nt, lvl);
286 }
std::string printStr(int nt, int lvl) const override
Returns the string containing printable information about the object.

References printStr().

Here is the call graph for this function:

◆ printStr()

std::string material::GaussianInfluenceFn::printStr ( int  nt,
int  lvl 
) const
inlineoverridevirtual

Returns the string containing printable information about the object.

Parameters
ntNumber of tabs to append before printing
lvlInformation level (higher means more information)
Returns
string String containing printable information about the object

Reimplemented from material::BaseInfluenceFn.

Definition at line 263 of file influenceFn.h.

263 {
264
265 auto tabS = util::io::getTabS(nt);
266 std::ostringstream oss;
267 oss << tabS << "------- GaussianInfluenceFn --------" << std::endl << std::endl;
268 oss << tabS << "Gaussian function a0 * exp(-r*r / a1) with constants: a0 = "
269 << d_alpha << ", a1 = " << d_beta << std::endl;
270 oss << tabS << "First moment = " << getMoment(1)
271 << ", second moment = " << getMoment(2)
272 << ", third moment = " << getMoment(3) << std::endl;
273 oss << tabS << std::endl;
274
275 return oss.str();
276 }
double getMoment(const size_t &i) const override
Returns the moment of influence function.
std::string getTabS(int nt)
Returns tab spaces of given size.
Definition io.h:40

References d_alpha, d_beta, getMoment(), and util::io::getTabS().

Referenced by print().

Here is the call graph for this function:
Here is the caller graph for this function:

Field Documentation

◆ d_alpha

double material::GaussianInfluenceFn::d_alpha
private

Constants.

Definition at line 293 of file influenceFn.h.

Referenced by GaussianInfluenceFn(), and printStr().

◆ d_beta

double material::GaussianInfluenceFn::d_beta
private

Constants.

Definition at line 296 of file influenceFn.h.

Referenced by GaussianInfluenceFn(), and printStr().


The documentation for this class was generated from the following files: