v0.14.0
Functions | Variables
find_local_coordinates.cpp File Reference
#include <MoFEM.hpp>

Go to the source code of this file.

Functions

int main (int argc, char *argv[])
 

Variables

static char help [] = "testing mesh cut test\n\n"
 

Function Documentation

◆ main()

int main ( int  argc,
char *  argv[] 
)

Definition at line 17 of file find_local_coordinates.cpp.

17  {
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);
65  CHKERR Tools::getLocalCoordinatesOnReferenceFourNodeTet(
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);
113  CHKERR Tools::getLocalCoordinatesOnReferenceThreeNodeTri(
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());
154  CHKERR Tools::getLocalCoordinatesOnReferenceEdgeNodeEdge(
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  }
172  CATCH_ERRORS;
173 
175 
176  return 0;
177 }

Variable Documentation

◆ help

char help[] = "testing mesh cut test\n\n"
static

Definition at line 15 of file find_local_coordinates.cpp.

MoFEM::Types::MatrixDouble
UBlasMatrix< double > MatrixDouble
Definition: Types.hpp:77
help
static char help[]
Definition: find_local_coordinates.cpp:15
MoFEM::CoreTmp< 0 >::Finalize
static MoFEMErrorCode Finalize()
Checks for options to be called at the conclusion of the program.
Definition: Core.cpp:112
CHKERR
#define CHKERR
Inline error check.
Definition: definitions.h:535
v
const double v
phase velocity of light in medium (cm/ns)
Definition: initial_diffusion.cpp:40
MoFEM::CoreTmp< 0 >::Initialize
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
MOFEM_LOG
#define MOFEM_LOG(channel, severity)
Log.
Definition: LogManager.hpp:308
CATCH_ERRORS
#define CATCH_ERRORS
Catch errors.
Definition: definitions.h:372
MoFEM::Types::VectorDouble
UBlasVector< double > VectorDouble
Definition: Types.hpp:68
MOFEM_ATOM_TEST_INVALID
@ MOFEM_ATOM_TEST_INVALID
Definition: definitions.h:40
MoFEMFunctionReturn
#define MoFEMFunctionReturn(a)
Last executable line of each PETSc function used for error handling. Replaces return()
Definition: definitions.h:416
MoFEMFunctionBegin
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
Definition: definitions.h:346