22 {
23
25
26 try {
27
28 moab::Core mb_instance;
29 moab::Interface &moab = mb_instance;
30 int rank;
31 MPI_Comm_rank(PETSC_COMM_WORLD, &rank);
32
33 PetscBool flg = PETSC_TRUE;
35#if PETSC_VERSION_GE(3, 6, 4)
37 255, &flg);
38
39#else
42
43#endif
44 if (flg != PETSC_TRUE) {
45 SETERRQ(PETSC_COMM_SELF, 1, "*** ERROR -my_file (MESH FILE NEEDED)");
46 }
47 const char *option;
48 option = "";
50
51
52 enum bases { AINSWORTH, DEMKOWICZ, LASBASETOP };
53
54 const char *list_bases[] = {"ainsworth", "demkowicz"};
55
56 PetscInt choice_base_value = AINSWORTH;
58 LASBASETOP, &choice_base_value, &flg);
59
60 if (flg != PETSC_TRUE) {
62 }
63
65 if (choice_base_value == AINSWORTH) {
67 } else if (choice_base_value == DEMKOWICZ) {
69 }
70
71
74
75
77 bit_level0.set(0);
79 CHKERR moab.create_meshset(MESHSET_SET, meshset_level0);
80
82 0, 3, bit_level0);
83
84
86 3);
87
89
90
95
96
101 "MESH_NODE_POSITIONS");
102
107 "MESH_NODE_POSITIONS");
108
113 "MESH_NODE_POSITIONS");
114
119 "MESH_NODE_POSITIONS");
120
121
123
124
129
130
132
133
135
137
138
141
145
146 Skinner skin(&moab);
148 CHKERR skin.find_skin(0, tets,
false, skin_faces);
149
151 "SKIN_FE");
152
156
157 faces = subtract(faces, skin_faces);
159
161 CHKERR moab.get_adjacencies(faces, 1,
false, edges, moab::Interface::UNION);
162
164
166 CHKERR moab.get_adjacencies(skin_faces, 1,
false, skin_edges,
167 moab::Interface::UNION);
168
170
171
176
182
183
184
185
187
188
190
191
193
194
198
199
202
203
204
205
208
209
211
215 CHKERR VecSetRandom(
v, PETSC_NULL);
216
218 "TEST_PROBLEM",
ROW,
v, INSERT_VALUES, SCATTER_REVERSE);
219
221
222 typedef tee_device<std::ostream, std::ofstream>
TeeDevice;
224 std::ofstream ofs("forces_and_sources_hdiv_continuity_check.txt");
227
228 struct OpTetFluxes
229 : public VolumeElementForcesAndSourcesCore::UserDataOperator {
230
232 Tag tH;
233
237 mField(m_field), tH(
th) {}
238
242
245
246 if (type == MBTRI) {
247
248 boost::shared_ptr<const NumeredEntFiniteElement> mofem_fe =
249 getNumeredEntFiniteElementPtr();
252 .find(boost::make_tuple(type, side))
253 ->get()
254 ->ent;
255 int sense = side_table.get<1>()
256 .find(boost::make_tuple(type, side))
257 ->get()
258 ->sense;
259
260
261
263 int nb_dofs = data.
getN().size2() / 3;
264 for (
int dd = 0;
dd < nb_dofs;
dd++) {
265 for (int ddd = 0; ddd < 3; ddd++) {
268 }
269 }
270
271 double *t_ptr;
273 (const void **)&t_ptr);
274
275 for (
int dd = 0;
dd < 3;
dd++) {
276 t_ptr[
dd] += sense *
t[
dd];
277 }
278 }
279
280 if (type == MBEDGE) {
281
282 boost::shared_ptr<const NumeredEntFiniteElement> mofem_fe =
283 getNumeredEntFiniteElementPtr();
286 .find(boost::make_tuple(type, side))
287 ->get()
288 ->ent;
290 CHKERR mField.
get_moab().get_adjacencies(&edge, 1, 3,
false, adj_tets,
291 moab::Interface::UNION);
292 const int nb_adj_tets = adj_tets.size();
293
295 int nb_dofs = data.
getN().size2() / 3;
296 for (
int dd = 0;
dd < nb_dofs;
dd++) {
297 for (int ddd = 0; ddd < 3; ddd++) {
300 }
301 }
302
303 double *t_ptr;
305 (const void **)&t_ptr);
306
307 for (
int dd = 0;
dd < 3;
dd++) {
308 t_ptr[
dd] +=
t[
dd] / nb_adj_tets;
309 }
310 }
311
313 }
314 };
315
317
321
324
326
327 try {
328
329 N_tri.resize(1, 3);
331
332 gaussPts.resize(4, 4 + 6);
333 int ff = 0;
334 for (; ff < 4; ff++) {
336 for (;
dd < 3;
dd++) {
338 cblas_ddot(3, &N_tri(0, 0), 1, &
face_coords[ff][dd], 3);
339 }
341 }
342
343 int ee = 0;
344 for (; ee < 6; ee++) {
346 for (;
dd < 3;
dd++) {
349 }
351 }
352
353
354
355 } catch (std::exception &ex) {
356 std::ostringstream ss;
357 ss << "throw in method: " << ex.what() << " at line " << __LINE__
358 << " in file " << __FILE__;
360 }
361
363 }
364 };
365
366 struct OpFacesSkinFluxes
367 : public FaceElementForcesAndSourcesCore::UserDataOperator {
368
370 Tag tH1, tH2;
372
377 mField(m_field), tH1(th1), tH2(th2), mySplit(my_split) {}
378
382
383 if (type != MBTRI)
385
386 EntityHandle face = getNumeredEntFiniteElementPtr()->getEnt();
387
388 double *t_ptr;
390 (const void **)&t_ptr);
391
392 double *tn_ptr;
394 (const void **)&tn_ptr);
395
396 *tn_ptr = getTangent1AtGaussPts()(0, 0) * t_ptr[0] +
397 getTangent1AtGaussPts()(0, 1) * t_ptr[1] +
398 getTangent1AtGaussPts()(0, 2) * t_ptr[2] +
399 getTangent2AtGaussPts()(0, 0) * t_ptr[0] +
400 getTangent2AtGaussPts()(0, 1) * t_ptr[1] +
401 getTangent2AtGaussPts()(0, 2) * t_ptr[2];
402
403 int nb_dofs = data.
getN().size2() / 3;
405 for (;
dd < nb_dofs;
dd++) {
407 *tn_ptr +=
408 -getTangent1AtGaussPts()(0, 0) * data.
getN()(0, 3 *
dd + 0) *
409 val -
410 getTangent1AtGaussPts()(0, 1) * data.
getN()(0, 3 *
dd + 1) * val -
411 getTangent1AtGaussPts()(0, 2) * data.
getN()(0, 3 *
dd + 2) * val -
412 getTangent2AtGaussPts()(0, 0) * data.
getN()(0, 3 *
dd + 0) * val -
413 getTangent2AtGaussPts()(0, 1) * data.
getN()(0, 3 *
dd + 1) * val -
414 getTangent2AtGaussPts()(0, 2) * data.
getN()(0, 3 *
dd + 2) * val;
415 }
416
417 const double eps = 1e-8;
418 if (fabs(*tn_ptr) >
eps) {
420 "HCurl continuity failed %6.4e", *tn_ptr);
421 }
422
423 mySplit.precision(5);
424 mySplit << face << " " << fabs(*tn_ptr) << std::endl;
425
427 }
428 };
429
431 : public FaceElementForcesAndSourcesCore::UserDataOperator {
432
434 Tag tH1, tH2;
436
441 mField(m_field), tH1(_th1), tH2(_th2), mySplit(my_split) {}
442
446
447 if (type != MBTRI)
449
450 EntityHandle face = getNumeredEntFiniteElementPtr()->getEnt();
451
452 double *t_ptr;
454 (const void **)&t_ptr);
455
456 double *tn_ptr;
458 (const void **)&tn_ptr);
459
460 *tn_ptr = getTangent1AtGaussPts()(0, 0) * t_ptr[0] +
461 getTangent1AtGaussPts()(0, 1) * t_ptr[1] +
462 getTangent1AtGaussPts()(0, 2) * t_ptr[2] +
463 getTangent2AtGaussPts()(0, 0) * t_ptr[0] +
464 getTangent2AtGaussPts()(0, 1) * t_ptr[1] +
465 getTangent2AtGaussPts()(0, 2) * t_ptr[2];
466
467 const double eps = 1e-8;
468 if (fabs(*tn_ptr) >
eps) {
470 "HCurl continuity failed %6.4e", *tn_ptr);
471 }
472
473 mySplit.precision(5);
474
475 mySplit << face << " " << fabs(*tn_ptr) << std::endl;
476
478 }
479 };
480
482
486
489
490 gaussPts.resize(3, 1);
494
496 }
497 };
498
499 struct OpEdgesFluxes
500 : public EdgeElementForcesAndSourcesCore::UserDataOperator {
501
503 Tag tH1, tH2;
505
510 mField(m_field), tH1(_th1), tH2(_th2), mySplit(my_split) {}
511
515
516 if (type != MBEDGE)
518
519 EntityHandle edge = getNumeredEntFiniteElementPtr()->getEnt();
520
521 double *t_ptr;
523 (const void **)&t_ptr);
524
525 double *tn_ptr;
527 (const void **)&tn_ptr);
528
529 *tn_ptr = getTangentAtGaussPts()(0, 0) * t_ptr[0] +
530 getTangentAtGaussPts()(0, 1) * t_ptr[1] +
531 getTangentAtGaussPts()(0, 2) * t_ptr[2];
532
533 double tn = 0;
534 unsigned int nb_dofs = data.
getN().size2() / 3;
537 "Number of dofs on edge and number of base functions not "
538 "equla %d != %d",
540 }
541
542 for (
unsigned int dd = 0;
dd != nb_dofs; ++
dd) {
544 tn += getTangentAtGaussPts()(0, 0) * data.
getN()(0, 3 *
dd + 0) *
545 val +
546 getTangentAtGaussPts()(0, 1) * data.
getN()(0, 3 *
dd + 1) *
547 val +
548 getTangentAtGaussPts()(0, 2) * data.
getN()(0, 3 *
dd + 2) *
549 val;
550 }
551
552
553 *tn_ptr -= tn;
554
555
556
557
558
559 const double eps = 1e-8;
560 if (fabs(*tn_ptr) >
eps) {
562 "HCurl continuity failed %6.4e", *tn_ptr);
563 }
564
565 mySplit.precision(5);
566
567 mySplit << edge << " " << fabs(*tn_ptr) << std::endl;
568
570 }
571 };
572
574
578
581
582 gaussPts.resize(2, 1);
585
587 }
588 };
589
590 MyTetFE tet_fe(m_field);
591 MyTriFE tri_fe(m_field);
592 MyTriFE skin_fe(m_field);
593 MyEdgeFE edge_fe(m_field);
594
595 Tag th1;
596 double def_val[] = {0, 0, 0};
597 CHKERR moab.tag_get_handle(
"T", 3, MB_TYPE_DOUBLE, th1,
598 MB_TAG_CREAT | MB_TAG_SPARSE, &def_val);
599
600 auto material_grad_mat = boost::make_shared<MatrixDouble>();
601 auto material_det_vec = boost::make_shared<VectorDouble>();
602 auto material_inv_grad_mat = boost::make_shared<MatrixDouble>();
603
605 "MESH_NODE_POSITIONS", material_grad_mat));
607 material_grad_mat, material_det_vec, material_inv_grad_mat));
608 tet_fe.getOpPtrVector().push_back(
new OpSetHOWeights(material_det_vec));
609 tet_fe.getOpPtrVector().push_back(
611 tet_fe.getOpPtrVector().push_back(
613 tet_fe.getOpPtrVector().push_back(new OpTetFluxes(m_field, th1));
614
615 Tag th2;
616 CHKERR moab.tag_get_handle(
"TN", 1, MB_TYPE_DOUBLE, th2,
617 MB_TAG_CREAT | MB_TAG_SPARSE, &def_val);
618
619 tri_fe.getOpPtrVector().push_back(
621 tri_fe.getOpPtrVector().push_back(
623
624 tri_fe.getOpPtrVector().push_back(
626 tri_fe.getOpPtrVector().push_back(
628
629 skin_fe.getOpPtrVector().push_back(
631 skin_fe.getOpPtrVector().push_back(
633 skin_fe.getOpPtrVector().push_back(
634 new OpFacesSkinFluxes(m_field, th1, th2, my_split));
635
636 edge_fe.getOpPtrVector().push_back(
638 edge_fe.getOpPtrVector().push_back(
640 edge_fe.getOpPtrVector().push_back(
641 new OpEdgesFluxes(m_field, th1, th2, my_split));
642
643 for (Range::iterator fit = faces.begin(); fit != faces.end(); fit++) {
644 CHKERR moab.tag_set_data(th1, &*fit, 1, &def_val);
645 CHKERR moab.tag_set_data(th2, &*fit, 1, &def_val);
646 }
647
649 my_split << "internal\n";
651 my_split << "skin\n";
653 my_split << "edges\n";
655
657 CHKERR moab.create_meshset(MESHSET_SET, meshset);
660 CHKERR moab.write_file(
"out.vtk",
"VTK",
"", &meshset, 1);
661 }
663
665}
ForcesAndSourcesCore::UserDataOperator UserDataOperator
#define CATCH_ERRORS
Catch errors.
FieldApproximationBase
approximation base
@ AINSWORTH_LEGENDRE_BASE
Ainsworth Cole (Legendre) approx. base .
#define MoFEMFunctionReturnHot(a)
Last executable line of each PETSc function used for error handling. Replaces return()
@ HCURL
field with continuous tangents
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
@ MOFEM_STD_EXCEPTION_THROW
@ MOFEM_ATOM_TEST_INVALID
@ MOFEM_DATA_INCONSISTENCY
#define MoFEMFunctionReturn(a)
Last executable line of each PETSc function used for error handling. Replaces return()
#define CHKERR
Inline error check.
#define MoFEMFunctionBeginHot
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
static const double face_coords[4][9]
static const double edge_coords[6][6]
multi_index_container< boost::shared_ptr< SideNumber >, indexed_by< ordered_unique< member< SideNumber, EntityHandle, &SideNumber::ent > >, ordered_non_unique< composite_key< SideNumber, const_mem_fun< SideNumber, EntityType, &SideNumber::getEntType >, member< SideNumber, signed char, &SideNumber::side_number > > > > > SideNumber_multiIndex
SideNumber_multiIndex for SideNumber.
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 build_finite_elements(int verb=DEFAULT_VERBOSITY)=0
Build finite elements.
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 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_row(const std::string &fe_name, const std::string name_row)=0
set field row 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_dofs(const Problem *problem_ptr, const std::string &field_name, RowColData rc, DofMethod &method, int lower_rank, int upper_rank, int verb=DEFAULT_VERBOSITY)=0
Make a loop over dofs.
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.
MoFEMErrorCode partitionGhostDofs(const std::string name, int verb=VERBOSE)
determine ghost nodes
MoFEMErrorCode partitionSimpleProblem(const std::string name, int verb=VERBOSE)
partition problem dofs
MoFEMErrorCode buildProblem(const std::string name, const bool square_matrix, int verb=VERBOSE)
build problem data structures
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 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
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
const double v
phase velocity of light in medium (cm/ns)
const FTensor::Tensor2< T, Dim, Dim > Vec
const Tensor2_symmetric_Expr< const ddTensor0< T, Dim, i, j >, typename promote< T, double >::V, Dim, i, j > dd(const Tensor0< T * > &a, const Index< i, Dim > index1, const Index< j, Dim > index2, const Tensor1< int, Dim > &d_ijk, const Tensor1< double, Dim > &d_xyz)
PetscErrorCode MoFEMErrorCode
MoFEM/PETSc error code.
std::bitset< BITREFLEVEL_SIZE > BitRefLevel
Bit structure attached to each entity identifying to what mesh entity is attached.
PetscErrorCode PetscOptionsGetEList(PetscOptions *, const char pre[], const char name[], const char *const *list, PetscInt next, PetscInt *value, PetscBool *set)
PetscErrorCode PetscOptionsGetString(PetscOptions *, const char pre[], const char name[], char str[], size_t size, PetscBool *set)
constexpr double t
plate stiffness
virtual moab::Interface & get_moab()=0
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.
static MoFEMErrorCode Initialize(int *argc, char ***args, const char file[], const char help[])
Initializes the MoFEM database PETSc, MOAB and MPI.
static MoFEMErrorCode Finalize()
Checks for options to be called at the conclusion of the program.
Deprecated interface functions.
Data on single entity (This is passed as argument to DataOperator::doWork)
MatrixDouble & getN(const FieldApproximationBase base)
get base functions this return matrix (nb. of rows is equal to nb. of Gauss pts, nb....
const VectorDouble & getFieldData() const
get dofs values
const MatrixAdaptor getVectorN(const FieldApproximationBase base, const int gg)
get Hdiv of base functions at Gauss pts
virtual MoFEMErrorCode setGaussPts(int order_row, int order_col, int order_data)
set user specific integration rule
virtual int getRule(int order_row, int order_col, int order_data)
another variant of getRule
MatrixDouble gaussPts
Matrix of integration points.
Calculate HO coordinates at gauss points.
Get field gradients at integration pts for scalar filed rank 0, i.e. vector field.
Calculate normals at Gauss points of triangle element.
Calculate tangent vector on edge form HO geometry approximation.
transform local reference derivatives of shape function to global derivatives if higher order geometr...
Set inverse jacobian to base functions.
Problem manager is used to build and partition problems.
Projection of edge entities with one mid-node on hierarchical basis.
MoFEMErrorCode getInterface(IFACE *&iface) const
Get interface refernce to pointer of interface.
Vector manager is used to create vectors \mofem_vectors.
Volume finite element base.
MoFEMErrorCode doWork(int side, EntityType type, EntitiesFieldData::EntData &data)