PeriDEM 0.3.0
PeriDEM -- Peridynamics-based high-fidelity model for granular media
Loading...
Searching...
No Matches
anonymous_namespace{testFeLib.cpp} Namespace Reference

Functions

util::SymMatrix3 strainFromB (const fe::B &B, const std::vector< util::Point > &u)
 
void readNodes (const std::string &filename, std::vector< util::Point > &nodes)
 
size_t readElements (const std::string &filename, const size_t &elem_type, std::vector< size_t > &elements)
 
bool checkRefIntegration (const size_t &n, const size_t &i, const size_t &j, const std::vector< fe::QuadData > &qds, double &I_exact)
 
bool checkRefIntegration (const size_t &n, const size_t &i, const size_t &j, const size_t &k, const std::vector< fe::QuadData > &qds, double &I_exact)
 

Variables

int debug_id = -1
 
const double tol = 1.0E-12
 

Function Documentation

◆ checkRefIntegration() [1/2]

bool anonymous_namespace{testFeLib.cpp}::checkRefIntegration ( const size_t &  n,
const size_t &  i,
const size_t &  j,
const size_t &  k,
const std::vector< fe::QuadData > &  qds,
double &  I_exact 
)

Definition at line 131 of file testFeLib.cpp.

134 {
135
136 double I_approx = 0.;
137 for (auto qd: qds)
138 I_approx += qd.d_w * std::pow(qd.d_p.d_x, i) * std::pow(qd.d_p.d_y, j) *
139 std::pow(qd.d_p.d_z, k);
140
141 if (std::abs(I_exact - I_approx) > tol) {
142 std::cout << "Error in order = " << n << ". Exact integration = " << I_exact
143 << " and approximate integration = " << I_approx
144 << " of polynomial of order (i = " << i << " + j = " << j
145 << " + k = " << k << ") = " << i + j + k
146 << " over reference element "
147 << "is not matching using quadrature points.\n";
148
149 std::cout << "Print " << i << " " << j << " " << k
150 << " debug id = " << debug_id << "\n";
151 for (auto qd: qds)
152 std::cout << qd.printStr() << "\n";
153
154 return false;
155 }
156
157 return true;
158 }

References debug_id, and tol.

◆ checkRefIntegration() [2/2]

bool anonymous_namespace{testFeLib.cpp}::checkRefIntegration ( const size_t &  n,
const size_t &  i,
const size_t &  j,
const std::vector< fe::QuadData > &  qds,
double &  I_exact 
)

Definition at line 109 of file testFeLib.cpp.

112 {
113
114 double I_approx = 0.;
115 for (auto qd: qds)
116 I_approx += qd.d_w * std::pow(qd.d_p.d_x, i) * std::pow(qd.d_p.d_y, j);
117
118 if (std::abs(I_exact - I_approx) > tol) {
119 std::cout << "Error in order = " << n << ". Exact integration = " << I_exact
120 << " and approximate integration = " << I_approx
121 << " of polynomial of order (i = " << i << " + j = " << j
122 << ") = " << i + j << " over reference element "
123 << "is not matching using quadrature points.\n";
124
125 return false;
126 }
127
128 return true;
129 }

References tol.

Referenced by test::testQuadElem(), test::testTetElem(), and test::testTriElem().

Here is the caller graph for this function:

◆ readElements()

size_t anonymous_namespace{testFeLib.cpp}::readElements ( const std::string &  filename,
const size_t &  elem_type,
std::vector< size_t > &  elements 
)

Definition at line 70 of file testFeLib.cpp.

71 {
72
73 if (elem_type == util::vtk_type_triangle) {
74 io::CSVReader<3> in(filename);
75 std::vector<size_t> ids(3, 0);
76 while (in.read_row(ids[0], ids[1], ids[2])) {
77 for (auto id: ids)
78 elements.emplace_back(id);
79 }
80
81 size_t num_vertex = util::vtk_map_element_to_num_nodes[elem_type];
82 return elements.size() / num_vertex;
83 } else if (elem_type == util::vtk_type_quad) {
84 io::CSVReader<4> in(filename);
85 std::vector<size_t> ids(4, 0);
86 while (in.read_row(ids[0], ids[1], ids[2], ids[3])) {
87 for (auto id: ids)
88 elements.emplace_back(id);
89 }
90
91 size_t num_vertex = util::vtk_map_element_to_num_nodes[elem_type];
92 return elements.size() / num_vertex;
93 } else if (elem_type == util::vtk_type_tetra) {
94 io::CSVReader<4> in(filename);
95 std::vector<size_t> ids(4, 0);
96 while (in.read_row(ids[0], ids[1], ids[2], ids[3])) {
97 for (auto id: ids)
98 elements.emplace_back(id);
99 }
100
101 size_t num_vertex = util::vtk_map_element_to_num_nodes[elem_type];
102 return elements.size() / num_vertex;
103 } else {
104 std::cerr << "Error: readElements() only supports vtk_type_triangle, vtk_type_quad, and vtk_type_tetra elem_type in testing.\n";
105 exit(1);
106 }
107 }
static int vtk_map_element_to_num_nodes[16]
Map from element type to number of nodes (for vtk)
static const int vtk_type_triangle
Integer flag for triangle element.
static const int vtk_type_quad
Integer flag for quad element.
static const int vtk_type_tetra
Integer flag for tetrahedron element.

References util::vtk_map_element_to_num_nodes, util::vtk_type_quad, util::vtk_type_tetra, and util::vtk_type_triangle.

Referenced by test::testQuadElem(), test::testTetElem(), and test::testTriElem().

Here is the caller graph for this function:

◆ readNodes()

void anonymous_namespace{testFeLib.cpp}::readNodes ( const std::string &  filename,
std::vector< util::Point > &  nodes 
)

Definition at line 60 of file testFeLib.cpp.

61 {
62
63 // csv reader
64 io::CSVReader<3> in(filename);
65 double x, y, z;
66 while (in.read_row(x, y, z))
67 nodes.emplace_back(x, y, z);
68 }

Referenced by test::testQuadElem(), test::testTetElem(), and test::testTriElem().

Here is the caller graph for this function:

◆ strainFromB()

util::SymMatrix3 anonymous_namespace{testFeLib.cpp}::strainFromB ( const fe::B &  B,
const std::vector< util::Point > &  u 
)

Definition at line 31 of file testFeLib.cpp.

32 {
33 std::vector<double> uflat(B.nDof());
34 const int dim = B.dim();
35 for (size_t a = 0; a < u.size(); a++) {
36 uflat[dim * static_cast<int>(a)] = u[a][0];
37 if (dim > 1)
38 uflat[dim * static_cast<int>(a) + 1] = u[a][1];
39 if (dim > 2)
40 uflat[dim * static_cast<int>(a) + 2] = u[a][2];
41 }
42 std::vector<double> e(B.nStrain(), 0.);
43 for (int i = 0; i < B.nStrain(); i++)
44 for (int j = 0; j < B.nDof(); j++)
45 e[i] += B(i, j) * uflat[j];
47 s(0, 0) = e[0];
48 if (dim > 1) {
49 s(1, 1) = e[1];
50 s(0, 1) = (dim == 2) ? e[2] : e[5];
51 }
52 if (dim > 2) {
53 s(2, 2) = e[2];
54 s(1, 2) = e[3];
55 s(0, 2) = e[4];
56 }
57 return s;
58 }
int dim() const
Definition bMatrix.h:31
int nDof() const
Definition bMatrix.h:30
int nStrain() const
Definition bMatrix.h:29
A structure to represent 3d matrices.
Definition matrix.h:258

References fe::B::dim(), fe::B::nDof(), and fe::B::nStrain().

Referenced by test::testPatchQuad(), test::testPatchTet(), test::testPatchTri(), and test::testPatchTriDistorted().

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

Variable Documentation

◆ debug_id

int anonymous_namespace{testFeLib.cpp}::debug_id = -1

Definition at line 28 of file testFeLib.cpp.

Referenced by checkRefIntegration(), and test::testTetElem().

◆ tol

const double anonymous_namespace{testFeLib.cpp}::tol = 1.0E-12