v0.13.1
Functions | Variables
convective_matrix.cpp File Reference
#include <BasicFiniteElements.hpp>

Go to the source code of this file.

Functions

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

Variables

static char help [] = "...\n\n"
 

Detailed Description

Atom test for convective mass element

Definition in file convective_matrix.cpp.

Function Documentation

◆ main()

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

Definition at line 29 of file convective_matrix.cpp.

29 {
30
31 MoFEM::Core::Initialize(&argc, &argv, (char *)0, help);
32
33 try {
34
35 moab::Core mb_instance;
36 moab::Interface &moab = mb_instance;
37 int rank;
38 MPI_Comm_rank(PETSC_COMM_WORLD, &rank);
39
40 PetscBool flg = PETSC_TRUE;
41 char mesh_file_name[255];
42 CHKERR PetscOptionsGetString(PETSC_NULL, PETSC_NULL, "-my_file",
43 mesh_file_name, 255, &flg);
44 if (flg != PETSC_TRUE) {
45 SETERRQ(PETSC_COMM_SELF, 1, "*** ERROR -my_file (MESH FILE NEEDED)");
46 }
47
48 const char *option;
49 option = ""; //"PARALLEL=BCAST;";//;DEBUG_IO";
50 CHKERR moab.load_file(mesh_file_name, 0, option);
51
52 MoFEM::Core core(moab);
53 MoFEM::Interface &m_field = core;
54
55 // ref meshset ref level 0
56 BitRefLevel bit_level0;
57 bit_level0.set(0);
58 EntityHandle meshset_level0;
59 CHKERR moab.create_meshset(MESHSET_SET, meshset_level0);
60 CHKERR m_field.getInterface<BitRefManager>()->setBitRefLevelByDim(
61 0, 3, bit_level0);
62 CHKERR m_field.getInterface<BitRefManager>()->getEntitiesByRefLevel(
63 bit_level0, BitRefLevel().set(), meshset_level0);
64
65 // Fields
66 CHKERR m_field.add_field("SPATIAL_POSITION", H1, AINSWORTH_LEGENDRE_BASE,
67 3);
68
69 // FE
70 CHKERR m_field.add_finite_element("ELASTIC");
71
72 // Define rows/cols and element data
74 "SPATIAL_POSITION");
76 "SPATIAL_POSITION");
78 "SPATIAL_POSITION");
79
80 // define problems
81 CHKERR m_field.add_problem("ELASTIC_MECHANICS");
82
83 // set finite elements for problems
84 CHKERR m_field.modify_problem_add_finite_element("ELASTIC_MECHANICS",
85 "ELASTIC");
86
87 // set refinement level for problem
88 CHKERR m_field.modify_problem_ref_level_add_bit("ELASTIC_MECHANICS",
89 bit_level0);
90
91 // add entitities (by tets) to the field
92 CHKERR m_field.add_ents_to_field_by_type(0, MBTET, "SPATIAL_POSITION");
93
94 // add finite elements entities
96 bit_level0, BitRefLevel().set(), "ELASTIC", MBTET);
97
98 // set app. order
99 PetscInt order;
100 CHKERR PetscOptionsGetInt(PETSC_NULL, PETSC_NULL, "-my_order", &order,
101 &flg);
102 if (flg != PETSC_TRUE) {
103 order = 1;
104 }
105 CHKERR m_field.set_field_order(0, MBTET, "SPATIAL_POSITION", order);
106 CHKERR m_field.set_field_order(0, MBTRI, "SPATIAL_POSITION", order);
107 CHKERR m_field.set_field_order(0, MBEDGE, "SPATIAL_POSITION", order);
108 CHKERR m_field.set_field_order(0, MBVERTEX, "SPATIAL_POSITION", 1);
109
110 CHKERR m_field.add_finite_element("NEUAMNN_FE");
111 CHKERR m_field.modify_finite_element_add_field_row("NEUAMNN_FE",
112 "SPATIAL_POSITION");
113 CHKERR m_field.modify_finite_element_add_field_col("NEUAMNN_FE",
114 "SPATIAL_POSITION");
115 CHKERR m_field.modify_finite_element_add_field_data("NEUAMNN_FE",
116 "SPATIAL_POSITION");
117 CHKERR m_field.modify_problem_add_finite_element("ELASTIC_MECHANICS",
118 "NEUAMNN_FE");
120 it)) {
121 Range tris;
122 CHKERR moab.get_entities_by_type(it->meshset, MBTRI, tris, true);
123 CHKERR m_field.add_ents_to_finite_element_by_type(tris, MBTRI,
124 "NEUAMNN_FE");
125 }
127 m_field, SIDESET | PRESSURESET, it)) {
128 Range tris;
129 CHKERR moab.get_entities_by_type(it->meshset, MBTRI, tris, true);
130 CHKERR m_field.add_ents_to_finite_element_by_type(tris, MBTRI,
131 "NEUAMNN_FE");
132 }
133
134 // Velocity
135 CHKERR m_field.add_field("SPATIAL_VELOCITY", H1, AINSWORTH_LEGENDRE_BASE,
136 3);
137 CHKERR m_field.add_ents_to_field_by_type(0, MBTET, "SPATIAL_VELOCITY");
138 int order_velocity = 1;
139 CHKERR m_field.set_field_order(0, MBTET, "SPATIAL_VELOCITY",
140 order_velocity);
141 CHKERR m_field.set_field_order(0, MBTRI, "SPATIAL_VELOCITY",
142 order_velocity);
143 CHKERR m_field.set_field_order(0, MBEDGE, "SPATIAL_VELOCITY",
144 order_velocity);
145 CHKERR m_field.set_field_order(0, MBVERTEX, "SPATIAL_VELOCITY", 1);
146
147 CHKERR m_field.add_field("DOT_SPATIAL_POSITION", H1,
149 CHKERR m_field.add_ents_to_field_by_type(0, MBTET, "DOT_SPATIAL_POSITION");
150 CHKERR m_field.set_field_order(0, MBTET, "DOT_SPATIAL_POSITION", order);
151 CHKERR m_field.set_field_order(0, MBTRI, "DOT_SPATIAL_POSITION", order);
152 CHKERR m_field.set_field_order(0, MBEDGE, "DOT_SPATIAL_POSITION", order);
153 CHKERR m_field.set_field_order(0, MBVERTEX, "DOT_SPATIAL_POSITION", 1);
154 CHKERR m_field.add_field("DOT_SPATIAL_VELOCITY", H1,
156 CHKERR m_field.add_ents_to_field_by_type(0, MBTET, "DOT_SPATIAL_VELOCITY");
157 CHKERR m_field.set_field_order(0, MBTET, "DOT_SPATIAL_VELOCITY",
158 order_velocity);
159 CHKERR m_field.set_field_order(0, MBTRI, "DOT_SPATIAL_VELOCITY",
160 order_velocity);
161 CHKERR m_field.set_field_order(0, MBEDGE, "DOT_SPATIAL_VELOCITY",
162 order_velocity);
163 CHKERR m_field.set_field_order(0, MBVERTEX, "DOT_SPATIAL_VELOCITY", 1);
164
165 ConvectiveMassElement inertia(m_field, 1);
166 CHKERR inertia.setBlocks();
167 CHKERR inertia.addConvectiveMassElement("MASS_ELEMENT", "SPATIAL_VELOCITY",
168 "SPATIAL_POSITION");
169 CHKERR inertia.addVelocityElement("VELOCITY_ELEMENT", "SPATIAL_VELOCITY",
170 "SPATIAL_POSITION");
171 CHKERR m_field.modify_problem_add_finite_element("ELASTIC_MECHANICS",
172 "MASS_ELEMENT");
173 CHKERR m_field.modify_problem_add_finite_element("ELASTIC_MECHANICS",
174 "VELOCITY_ELEMENT");
175
176 // build field
177 CHKERR m_field.build_fields();
178
179 double scale_positions = 2;
180 {
181 EntityHandle node = 0;
182 double coords[3];
183 for (_IT_GET_DOFS_FIELD_BY_NAME_FOR_LOOP_(m_field, "SPATIAL_POSITION",
184 dof_ptr)) {
185 if (dof_ptr->get()->getEntType() != MBVERTEX)
186 continue;
187 EntityHandle ent = dof_ptr->get()->getEnt();
188 int dof_rank = dof_ptr->get()->getDofCoeffIdx();
189 double &fval = dof_ptr->get()->getFieldData();
190 if (node != ent) {
191 CHKERR moab.get_coords(&ent, 1, coords);
192 node = ent;
193 }
194 fval = scale_positions * coords[dof_rank];
195 }
196 }
197
198 double scale_velocities = 4;
199 {
200 EntityHandle node = 0;
201 double coords[3];
202 for (_IT_GET_DOFS_FIELD_BY_NAME_FOR_LOOP_(m_field, "DOT_SPATIAL_POSITION",
203 dof_ptr)) {
204 if (dof_ptr->get()->getEntType() != MBVERTEX)
205 continue;
206 EntityHandle ent = dof_ptr->get()->getEnt();
207 int dof_rank = dof_ptr->get()->getDofCoeffIdx();
208 double &fval = dof_ptr->get()->getFieldData();
209 if (node != ent) {
210 CHKERR moab.get_coords(&ent, 1, coords);
211 node = ent;
212 }
213 fval = scale_velocities * coords[dof_rank];
214 }
215 }
216
217 // build finite elemnts
219
220 // build adjacencies
221 CHKERR m_field.build_adjacencies(bit_level0);
222
223 // build problem
224
225 ProblemsManager *prb_mng_ptr;
226 CHKERR m_field.getInterface(prb_mng_ptr);
227
228 CHKERR prb_mng_ptr->buildProblem("ELASTIC_MECHANICS", true);
229
230 // partition
231 CHKERR prb_mng_ptr->partitionProblem("ELASTIC_MECHANICS");
232 CHKERR prb_mng_ptr->partitionFiniteElements("ELASTIC_MECHANICS");
233 CHKERR prb_mng_ptr->partitionGhostDofs("ELASTIC_MECHANICS");
234
235 // create matrices
236 Vec F;
237 CHKERR m_field.getInterface<VecManager>()->vecCreateGhost(
238 "ELASTIC_MECHANICS", COL, &F);
239 Vec D;
240 CHKERR VecDuplicate(F, &D);
241 Mat Aij;
243 ->createMPIAIJWithArrays<PetscGlobalIdx_mi_tag>("ELASTIC_MECHANICS",
244 &Aij);
245
246 CHKERR inertia.setConvectiveMassOperators("SPATIAL_VELOCITY",
247 "SPATIAL_POSITION");
248 CHKERR inertia.setVelocityOperators("SPATIAL_VELOCITY", "SPATIAL_POSITION");
249
250 inertia.getLoopFeMassRhs().ts_F = F;
251 inertia.getLoopFeMassRhs().ts_a = 1;
252 inertia.getLoopFeMassLhs().ts_B = Aij;
253 inertia.getLoopFeMassLhs().ts_a = 1;
254
255 inertia.getLoopFeVelRhs().ts_F = F;
256 inertia.getLoopFeVelRhs().ts_a = 1;
257 inertia.getLoopFeVelLhs().ts_B = Aij;
258 inertia.getLoopFeVelLhs().ts_a = 1;
259
260 CHKERR m_field.loop_finite_elements("ELASTIC_MECHANICS", "MASS_ELEMENT",
261 inertia.getLoopFeMassRhs());
262 CHKERR m_field.loop_finite_elements("ELASTIC_MECHANICS", "VELOCITY_ELEMENT",
263 inertia.getLoopFeVelRhs());
264 CHKERR VecGhostUpdateBegin(F, ADD_VALUES, SCATTER_REVERSE);
265 CHKERR VecGhostUpdateEnd(F, ADD_VALUES, SCATTER_REVERSE);
266 CHKERR VecAssemblyBegin(F);
267 CHKERR VecAssemblyEnd(F);
268
269 CHKERR m_field.loop_finite_elements("ELASTIC_MECHANICS", "MASS_ELEMENT",
270 inertia.getLoopFeMassLhs());
271 CHKERR m_field.loop_finite_elements("ELASTIC_MECHANICS", "VELOCITY_ELEMENT",
272 inertia.getLoopFeVelLhs());
273 CHKERR MatAssemblyBegin(Aij, MAT_FINAL_ASSEMBLY);
274 CHKERR MatAssemblyEnd(Aij, MAT_FINAL_ASSEMBLY);
275
276 double sum = 0;
277 CHKERR VecSum(F, &sum);
278 CHKERR PetscPrintf(PETSC_COMM_WORLD, "sum = %9.8e\n", sum);
279 double fnorm;
280 CHKERR VecNorm(F, NORM_2, &fnorm);
281 CHKERR PetscPrintf(PETSC_COMM_WORLD, "fnorm = %9.8e\n", fnorm);
282
283 double mnorm;
284 CHKERR MatNorm(Aij, NORM_1, &mnorm);
285 CHKERR PetscPrintf(PETSC_COMM_WORLD, "mnorm = %9.8e\n", mnorm);
286
287 if (fabs(sum - 6.27285463e+00) > 1e-8) {
288 SETERRQ(PETSC_COMM_WORLD, MOFEM_ATOM_TEST_INVALID, "Failed to pass test");
289 }
290 if (fabs(fnorm - 1.28223353e+00) > 1e-6) {
291 SETERRQ(PETSC_COMM_WORLD, MOFEM_ATOM_TEST_INVALID, "Failed to pass test");
292 }
293 if (fabs(mnorm - 1.31250000e+00) > 1e-6) {
294 SETERRQ(PETSC_COMM_WORLD, MOFEM_ATOM_TEST_INVALID, "Failed to pass test");
295 }
296
297 CHKERR VecDestroy(&F);
298 CHKERR VecDestroy(&D);
299 CHKERR MatDestroy(&Aij);
300 }
302
304
305 return 0;
306}
static char help[]
@ COL
Definition: definitions.h:136
#define CATCH_ERRORS
Catch errors.
Definition: definitions.h:385
@ AINSWORTH_LEGENDRE_BASE
Ainsworth Cole (Legendre) approx. base .
Definition: definitions.h:73
@ H1
continuous field
Definition: definitions.h:98
@ PRESSURESET
Definition: definitions.h:165
@ FORCESET
Definition: definitions.h:164
@ NODESET
Definition: definitions.h:159
@ SIDESET
Definition: definitions.h:160
@ MOFEM_ATOM_TEST_INVALID
Definition: definitions.h:53
#define CHKERR
Inline error check.
Definition: definitions.h:548
#define _IT_GET_DOFS_FIELD_BY_NAME_FOR_LOOP_(MFIELD, NAME, IT)
Definition: Interface.hpp:1833
virtual MoFEMErrorCode modify_finite_element_add_field_row(const std::string &fe_name, const std::string &name_row)=0
set field row which finite element use
virtual MoFEMErrorCode add_finite_element(const std::string &fe_name, enum MoFEMTypes bh=MF_EXCL, int verb=DEFAULT_VERBOSITY)=0
add finite element
virtual MoFEMErrorCode add_ents_to_finite_element_by_bit_ref(const BitRefLevel &bit, const BitRefLevel &mask, const std::string &name, EntityType type, int verb=DEFAULT_VERBOSITY)=0
add TET entities from given refinement level to finite element database given by name
virtual MoFEMErrorCode build_finite_elements(int verb=DEFAULT_VERBOSITY)=0
Build finite elements.
virtual MoFEMErrorCode add_ents_to_finite_element_by_type(const EntityHandle entities, const EntityType type, const std::string &name, const bool recursive=true)=0
add entities to finite element
virtual MoFEMErrorCode modify_finite_element_add_field_data(const std::string &fe_name, const std::string &name_filed)=0
set finite element field data
virtual MoFEMErrorCode modify_finite_element_add_field_col(const std::string &fe_name, const std::string &name_row)=0
set field col which finite element use
virtual MoFEMErrorCode build_fields(int verb=DEFAULT_VERBOSITY)=0
virtual MoFEMErrorCode set_field_order(const EntityHandle meshset, const EntityType type, const std::string &name, const ApproximationOrder order, int verb=DEFAULT_VERBOSITY)=0
Set order approximation of the entities in the field.
virtual MoFEMErrorCode add_ents_to_field_by_type(const Range &ents, const EntityType type, const std::string &name, int verb=DEFAULT_VERBOSITY)=0
Add entities to field meshset.
virtual MoFEMErrorCode loop_finite_elements(const std::string &problem_name, const std::string &fe_name, FEMethod &method, boost::shared_ptr< NumeredEntFiniteElement_multiIndex > fe_ptr=nullptr, MoFEMTypes bh=MF_EXIST, CacheTupleWeakPtr cache_ptr=CacheTupleSharedPtr(), int verb=DEFAULT_VERBOSITY)=0
Make a loop over finite elements.
#define _IT_CUBITMESHSETS_BY_BCDATA_TYPE_FOR_LOOP_(MESHSET_MANAGER, CUBITBCTYPE, IT)
Iterator that loops over a specific Cubit MeshSet in a moFEM field.
MoFEMErrorCode partitionGhostDofs(const std::string name, int verb=VERBOSE)
determine ghost nodes
MoFEMErrorCode buildProblem(const std::string name, const bool square_matrix, int verb=VERBOSE)
build problem data structures
MoFEMErrorCode partitionProblem(const std::string name, int verb=VERBOSE)
partition problem dofs (collective)
MoFEMErrorCode partitionFiniteElements(const std::string name, bool part_from_moab=false, int low_proc=-1, int hi_proc=-1, int verb=VERBOSE)
partition finite elements
virtual MoFEMErrorCode modify_problem_add_finite_element(const std::string &name_problem, const std::string &fe_name)=0
add finite element to problem, this add entities assigned to finite element to a particular problem
virtual MoFEMErrorCode add_problem(const std::string &name, enum MoFEMTypes bh=MF_EXCL, int verb=DEFAULT_VERBOSITY)=0
Add problem.
virtual MoFEMErrorCode modify_problem_ref_level_add_bit(const std::string &name_problem, const BitRefLevel &bit)=0
add ref level to problem
char mesh_file_name[255]
const FTensor::Tensor2< T, Dim, Dim > Vec
std::bitset< BITREFLEVEL_SIZE > BitRefLevel
Bit structure attached to each entity identifying to what mesh entity is attached.
Definition: Types.hpp:51
PetscErrorCode PetscOptionsGetInt(PetscOptions *, const char pre[], const char name[], PetscInt *ivalue, PetscBool *set)
CoreTmp< 0 > Core
Definition: Core.hpp:1096
PetscErrorCode PetscOptionsGetString(PetscOptions *, const char pre[], const char name[], char str[], size_t size, PetscBool *set)
DeprecatedCoreInterface Interface
Definition: Interface.hpp:1965
const double D
diffusivity
structure grouping operators and data used for calculation of mass (convective) element \ nonlinear_e...
Managing BitRefLevels.
virtual MoFEMErrorCode build_adjacencies(const Range &ents, int verb=DEFAULT_VERBOSITY)=0
build adjacencies
virtual MoFEMErrorCode add_field(const std::string &name, const FieldSpace space, const FieldApproximationBase base, const FieldCoefficientsNumber nb_of_coefficients, const TagType tag_type=MB_TAG_SPARSE, const enum MoFEMTypes bh=MF_EXCL, int verb=DEFAULT_VERBOSITY)=0
Add field.
Core (interface) class.
Definition: Core.hpp:92
static MoFEMErrorCode Initialize(int *argc, char ***args, const char file[], const char help[])
Initializes the MoFEM database PETSc, MOAB and MPI.
Definition: Core.cpp:85
static MoFEMErrorCode Finalize()
Checks for options to be called at the conclusion of the program.
Definition: Core.cpp:125
Deprecated interface functions.
Matrix manager is used to build and partition problems.
Problem manager is used to build and partition problems.
MoFEMErrorCode getInterface(IFACE *&iface) const
Get interface refernce to pointer of interface.
Vector manager is used to create vectors \mofem_vectors.
Definition: VecManager.hpp:33

Variable Documentation

◆ help

char help[] = "...\n\n"
static

Definition at line 27 of file convective_matrix.cpp.