v0.13.2
Loading...
Searching...
No Matches
find_local_coordinates.cpp
Go to the documentation of this file.
1/** \file find_local_coordinates
2 * \example find_local_coordinates
3 *
4 * \brief testing finding local coordinates on tetrahedron
5 *
6 * \ingroup mesh_cut
7 */
8
9
10
11#include <MoFEM.hpp>
12
13using namespace MoFEM;
14
15static char help[] = "testing mesh cut test\n\n";
16
17int main(int argc, char *argv[]) {
18
19 MoFEM::Core::Initialize(&argc, &argv, (char *)0, help);
20
21 try {
22
23 auto test_tet = [&]() {
25 MatrixDouble elem_coords(4, 3);
26
27 elem_coords(0, 0) = -1;
28 elem_coords(0, 1) = -1;
29 elem_coords(0, 2) = -1;
30 elem_coords(1, 0) = 2;
31 elem_coords(1, 1) = 0;
32 elem_coords(1, 2) = 0;
33 elem_coords(2, 0) = 0;
34 elem_coords(2, 1) = 1;
35 elem_coords(2, 2) = 0;
36 elem_coords(3, 0) = 0;
37 elem_coords(3, 1) = 0;
38 elem_coords(3, 2) = 1;
39
40 MatrixDouble init_local_coords(5, 3);
41 init_local_coords(0, 0) = 0;
42 init_local_coords(0, 1) = 0;
43 init_local_coords(0, 2) = 0;
44 init_local_coords(1, 0) = 0.5;
45 init_local_coords(1, 1) = 0;
46 init_local_coords(1, 2) = 0;
47 init_local_coords(2, 0) = 0;
48 init_local_coords(2, 1) = 0.5;
49 init_local_coords(2, 2) = 0;
50 init_local_coords(3, 0) = 0;
51 init_local_coords(3, 1) = 0;
52 init_local_coords(3, 2) = 0.5;
53 init_local_coords(4, 0) = 1. / 3.;
54 init_local_coords(4, 1) = 1. / 3.;
55 init_local_coords(4, 2) = 1. / 3.;
56
57 MatrixDouble shape(init_local_coords.size1(), 4);
58 CHKERR Tools::shapeFunMBTET<3>(&shape(0, 0), &init_local_coords(0, 0),
59 &init_local_coords(0, 1),
60 &init_local_coords(0, 2), 5);
61
62 MatrixDouble global_coords = prod(shape, elem_coords);
63
64 MatrixDouble local_coords(init_local_coords.size1(), 3);
66 &elem_coords(0, 0), &global_coords(0, 0), init_local_coords.size1(),
67 &local_coords(0, 0));
68
69 MatrixDouble residual = local_coords - init_local_coords;
70 MOFEM_LOG("SELF", Sev::inform) << residual;
71 for (auto v : residual.data())
72 if (std::abs(v) > 1e-12)
73 SETERRQ1(PETSC_COMM_SELF, MOFEM_ATOM_TEST_INVALID,
74 "Should be zer, but is v = %3.4e", v);
75
77 };
78
79 auto test_tri = [&]() {
81 MatrixDouble elem_coords(3, 3);
82
83 elem_coords(0, 0) = -1;
84 elem_coords(0, 1) = -1;
85 elem_coords(0, 2) = -1;
86 elem_coords(1, 0) = 2;
87 elem_coords(1, 1) = 0;
88 elem_coords(1, 2) = 0;
89 elem_coords(2, 0) = 0;
90 elem_coords(2, 1) = 1;
91 elem_coords(2, 2) = 0;
92
93 MatrixDouble init_local_coords(4, 2);
94 init_local_coords(0, 0) = 0;
95 init_local_coords(0, 1) = 0;
96 init_local_coords(1, 0) = 1;
97 init_local_coords(1, 1) = 0;
98 init_local_coords(2, 0) = 0;
99 init_local_coords(2, 1) = 1;
100 init_local_coords(3, 0) = 1. / 3.;
101 init_local_coords(3, 1) = 1. / 3.;
102
103 MatrixDouble shape(init_local_coords.size1(), 3);
104 CHKERR Tools::shapeFunMBTRI<2>(&shape(0, 0), &init_local_coords(0, 0),
105 &init_local_coords(0, 1),
106 init_local_coords.size1());
107 MOFEM_LOG("SELF", Sev::verbose) << "tri shape " << shape;
108
109 MatrixDouble global_coords = prod(shape, elem_coords);
110 MOFEM_LOG("SELF", Sev::verbose) << "tri global_coords " << global_coords;
111
112 MatrixDouble local_coords(init_local_coords.size1(), 2);
114 &elem_coords(0, 0), &global_coords(0, 0), init_local_coords.size1(),
115 &local_coords(0, 0));
116
117 MatrixDouble residual = local_coords - init_local_coords;
118 MOFEM_LOG("SELF", Sev::inform) << residual;
119 for (auto v : residual.data())
120 if (std::abs(v) > 1e-12)
121 SETERRQ1(PETSC_COMM_SELF, MOFEM_ATOM_TEST_INVALID,
122 "Should be zer, but is v = %3.4e", v);
123
125 };
126
127 auto test_edge = [&]() {
129 MatrixDouble elem_coords(2, 3);
130
131 elem_coords(0, 0) = -1;
132 elem_coords(0, 1) = -1;
133 elem_coords(0, 2) = -1;
134 elem_coords(1, 0) = 2;
135 elem_coords(1, 1) = 0;
136 elem_coords(1, 2) = 0;
137
138 VectorDouble init_local_coords(6);
139 init_local_coords[0] = 0;
140 init_local_coords[1] = 1;
141 init_local_coords[2] = 0.5;
142 init_local_coords[4] = 0.25;
143 init_local_coords[5] = 0.75;
144
145 MatrixDouble shape(init_local_coords.size(), 2);
146 CHKERR Tools::shapeFunMBEDGE<1>(&shape(0, 0), &init_local_coords[0],
147 init_local_coords.size());
148 MOFEM_LOG("SELF", Sev::verbose) << "edge shape " << shape;
149
150 MatrixDouble global_coords = prod(shape, elem_coords);
151 MOFEM_LOG("SELF", Sev::verbose) << "edge global_coords " << global_coords;
152
153 VectorDouble local_coords(init_local_coords.size());
155 &elem_coords(0, 0), &global_coords(0, 0), init_local_coords.size(),
156 &local_coords[0]);
157
158 VectorDouble residual = local_coords - init_local_coords;
159 MOFEM_LOG("SELF", Sev::inform) << residual;
160 for (auto v : residual.data())
161 if (std::abs(v) > 1e-12)
162 SETERRQ1(PETSC_COMM_SELF, MOFEM_ATOM_TEST_INVALID,
163 "Should be zer, but is v = %3.4e", v);
164
166 };
167
168 CHKERR test_tet();
169 CHKERR test_tri();
170 CHKERR test_edge();
171 }
173
175
176 return 0;
177}
int main()
Definition: adol-c_atom.cpp:46
#define CATCH_ERRORS
Catch errors.
Definition: definitions.h:372
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
Definition: definitions.h:346
@ MOFEM_ATOM_TEST_INVALID
Definition: definitions.h:40
#define MoFEMFunctionReturn(a)
Last executable line of each PETSc function used for error handling. Replaces return()
Definition: definitions.h:416
#define CHKERR
Inline error check.
Definition: definitions.h:535
static char help[]
#define MOFEM_LOG(channel, severity)
Log.
Definition: LogManager.hpp:308
const double v
phase velocity of light in medium (cm/ns)
implementation of Data Operators for Forces and Sources
Definition: Common.hpp:10
static MoFEMErrorCode Initialize(int *argc, char ***args, const char file[], const char help[])
Initializes the MoFEM database PETSc, MOAB and MPI.
Definition: Core.cpp:72
static MoFEMErrorCode Finalize()
Checks for options to be called at the conclusion of the program.
Definition: Core.cpp:112
static MoFEMErrorCode getLocalCoordinatesOnReferenceFourNodeTet(const double *elem_coords, const double *glob_coords, const int nb_nodes, double *local_coords)
Get the Local Coordinates On Reference Four Node Tet object.
Definition: Tools.cpp:90
static MoFEMErrorCode getLocalCoordinatesOnReferenceTriNodeTri(const double *elem_coords, const double *glob_coords, const int nb_nodes, double *local_coords)
Get the Local Coordinates On Reference Four Node Tet object.
Definition: Tools.cpp:142
static MoFEMErrorCode getLocalCoordinatesOnReferenceEdgeNodeEdge(const double *elem_coords, const double *glob_coords, const int nb_nodes, double *local_coords)
Get the Local Coordinates On Reference Four Node Tet object.
Definition: Tools.cpp:200