v0.16.3
Loading...
Searching...
No Matches
Namespaces | Macros
FieldCore.cpp File Reference

Core interface methods for managing fields. More...

#include <MoFEM.hpp>

Go to the source code of this file.

Namespaces

namespace  MoFEM
 implementation of Data Operators for Forces and Sources
 

Macros

#define FieldCoreFunctionBegin
 

Detailed Description

Core interface methods for managing fields.

Definition in file FieldCore.cpp.

Macro Definition Documentation

◆ FieldCoreFunctionBegin

#define FieldCoreFunctionBegin
Value:
MOFEM_LOG_CHANNEL("WORLD"); \
MOFEM_LOG_CHANNEL("SYNC"); \
MOFEM_LOG_FUNCTION(); \
MOFEM_LOG_TAG("WORLD", "FieldCore"); \
MOFEM_LOG_TAG("SYNC", "FieldCore");
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...

Definition at line 8 of file FieldCore.cpp.

15 {
16
17BitFieldId Core::get_field_id(const std::string &name) const {
18 auto &set = fIelds.get<FieldName_mi_tag>();
19 auto miit = set.find(name);
20 if (miit == set.end()) {
21 THROW_MESSAGE("field < " + name +
22 " > not in database (top tip: check spelling)");
23 }
24 return (*miit)->getId();
25}
26
27FieldBitNumber Core::get_field_bit_number(const std::string name) const {
28 auto &set = fIelds.get<FieldName_mi_tag>();
29 auto miit = set.find(name);
30 if (miit == set.end())
31 THROW_MESSAGE("field < " + name +
32 " > not in database (top tip: check spelling)");
33 return (*miit)->getBitNumber();
34}
35
36std::string Core::get_field_name(const BitFieldId id) const {
37 auto &set = fIelds.get<BitFieldId_mi_tag>();
38 auto miit = set.find(id);
39 if (miit == set.end())
40 THROW_MESSAGE("field not in database (top tip: check spelling)");
41 return (*miit)->getName();
42}
43
44EntityHandle Core::get_field_meshset(const BitFieldId id) const {
45 auto &set = fIelds.get<BitFieldId_mi_tag>();
46 auto miit = set.find(id);
47 if (miit == set.end())
48 THROW_MESSAGE("field not in database (top tip: check spelling)");
49 return (*miit)->meshSet;
50}
51
52EntityHandle Core::get_field_meshset(const std::string name) const {
53 return get_field_meshset(get_field_id(name));
54}
55
56bool Core::check_field(const std::string &name) const {
57 auto miit = fIelds.get<FieldName_mi_tag>().find(name);
58 if (miit == fIelds.get<FieldName_mi_tag>().end())
59 return false;
60 else
61 return true;
62}
63
64const Field *Core::get_field_structure(const std::string &name,
65 enum MoFEMTypes bh) const {
66 auto miit = fIelds.get<FieldName_mi_tag>().find(name);
67 if (miit == fIelds.get<FieldName_mi_tag>().end()) {
68 if (bh == MF_EXIST)
69 throw MoFEMException(
71 std::string("field < " + name +
72 " > not in database (top tip: check spelling)")
73 .c_str());
74 else
75 return nullptr;
76 }
77 return miit->get();
78}
79
80MoFEMErrorCode Core::get_field_entities_by_dimension(const std::string name,
81 int dim,
82 Range &ents) const {
83
85 EntityHandle meshset = get_field_meshset(name);
86 CHKERR get_moab().get_entities_by_dimension(meshset, dim, ents, true);
88}
89
90MoFEMErrorCode Core::get_field_entities_by_type(const std::string name,
91 EntityType type,
92 Range &ents) const {
94 EntityHandle meshset = get_field_meshset(name);
95 CHKERR get_moab().get_entities_by_type(meshset, type, ents, true);
97}
98
99MoFEMErrorCode Core::get_field_entities_by_handle(const std::string name,
100 Range &ents) const {
102 EntityHandle meshset = get_field_meshset(name);
103 CHKERR get_moab().get_entities_by_handle(meshset, ents, true);
105}
106
107MoFEMErrorCode Core::addField(const std::string &name, const FieldSpace space,
108 const FieldContinuity continuity,
110 const FieldCoefficientsNumber nb_of_coefficients,
111 const TagType tag_type, const enum MoFEMTypes bh,
112 int verb) {
113 MOFEM_LOG_CHANNEL("WORLD");
114 MOFEM_LOG_TAG("WORLD", "FieldCore");
115 MOFEM_LOG_CHANNEL("SYNC");
116 MOFEM_LOG_TAG("SYNC", "FieldCore");
119
120 // Add field mesh set to partion meshset. In case of no elements
121 // on processor part, when mesh file is read, finite element meshset is
122 // prevented from deletion by moab reader.
123 auto add_meshset_to_partition = [&](auto meshset) {
125 const void *tag_vals[] = {&rAnk};
126 ParallelComm *pcomm = ParallelComm::get_pcomm(
127 &get_moab(), get_basic_entity_data_ptr()->pcommID);
128 Tag part_tag = pcomm->part_tag();
129 Range tagged_sets;
130 CHKERR get_moab().get_entities_by_type_and_tag(0, MBENTITYSET, &part_tag,
131 tag_vals, 1, tagged_sets,
132 moab::Interface::UNION);
133 for (auto s : tagged_sets)
134 CHKERR get_moab().add_entities(s, &meshset, 1);
136 };
137
138 auto create_tags = [&](auto meshset, auto id) {
140 CHKERR get_moab().tag_set_data(th_FieldId, &meshset, 1, &id);
141 // space
142 CHKERR get_moab().tag_set_data(th_FieldSpace, &meshset, 1, &space);
143 // continuity
144 CHKERR get_moab().tag_set_data(th_FieldContinuity, &meshset, 1,
145 &continuity);
146 // base
147 CHKERR get_moab().tag_set_data(th_FieldBase, &meshset, 1, &base);
148
149 // name
150 void const *tag_data[] = {name.c_str()};
151 int tag_sizes[1];
152 tag_sizes[0] = name.size();
153 CHKERR get_moab().tag_set_by_ptr(th_FieldName, &meshset, 1, tag_data,
154 tag_sizes);
155 // rank
156 Tag th_rank;
157 int def_rank = 1;
158 const std::string tag_rank_name = "_Field_Rank_" + name;
159 CHKERR get_moab().tag_get_handle(tag_rank_name.c_str(), 1, MB_TYPE_INTEGER,
160 th_rank, MB_TAG_CREAT | MB_TAG_SPARSE,
161 &def_rank);
162 CHKERR get_moab().tag_set_data(th_rank, &meshset, 1, &nb_of_coefficients);
163
164 Version file_ver;
165 ierr = UnknownInterface::getFileVersion(moab, file_ver);
166 CHK_THROW_MESSAGE(ierr, "Not known file version");
167 if (file_ver.majorVersion >= 0 && file_ver.minorVersion >= 12 &&
168 file_ver.buildVersion >= 1) {
169
170 // Change tag names comparing to older versions
171
172 const std::string name_data_prefix("_App_Data_");
173 void const *tag_prefix_data[] = {name_data_prefix.c_str()};
174 int tag_prefix_sizes[1];
175 tag_prefix_sizes[0] = name_data_prefix.size();
176 CHKERR get_moab().tag_set_by_ptr(th_FieldName_DataNamePrefix, &meshset, 1,
177 tag_prefix_data, tag_prefix_sizes);
178 Tag th_app_order, th_field_data, th_field_data_vert;
179
180 // order
181 ApproximationOrder def_approx_order = -1;
182 const std::string tag_approx_order_name = "_App_Order_" + name;
183 CHKERR get_moab().tag_get_handle(
184 tag_approx_order_name.c_str(), 1, MB_TYPE_INTEGER, th_app_order,
185 MB_TAG_CREAT | MB_TAG_SPARSE, &def_approx_order);
186
187 // data
188 std::string tag_data_name = name_data_prefix + name;
189 const int def_len = 0;
190 CHKERR get_moab().tag_get_handle(
191 tag_data_name.c_str(), def_len, MB_TYPE_DOUBLE, th_field_data,
192 MB_TAG_CREAT | MB_TAG_VARLEN | MB_TAG_SPARSE, NULL);
193 std::string tag_data_name_verts = name_data_prefix + name + "_V";
194 VectorDouble def_vert_data(nb_of_coefficients);
195 def_vert_data.clear();
196 CHKERR get_moab().tag_get_handle(
197 tag_data_name_verts.c_str(), nb_of_coefficients, MB_TYPE_DOUBLE,
198 th_field_data_vert, MB_TAG_CREAT | tag_type, &*def_vert_data.begin());
199 } else {
200 // Deprecated names
201 const std::string name_data_prefix("_App_Data");
202 void const *tag_prefix_data[] = {name_data_prefix.c_str()};
203 int tag_prefix_sizes[1];
204 tag_prefix_sizes[0] = name_data_prefix.size();
205 CHKERR get_moab().tag_set_by_ptr(th_FieldName_DataNamePrefix, &meshset, 1,
206 tag_prefix_data, tag_prefix_sizes);
207 Tag th_app_order, th_field_data, th_field_data_vert;
208
209 // order
210 ApproximationOrder def_approx_order = -1;
211 const std::string tag_approx_order_name = "_App_Order_" + name;
212 CHKERR get_moab().tag_get_handle(
213 tag_approx_order_name.c_str(), 1, MB_TYPE_INTEGER, th_app_order,
214 MB_TAG_CREAT | MB_TAG_SPARSE, &def_approx_order);
215
216 // data
217 std::string tag_data_name = name_data_prefix + name;
218 const int def_len = 0;
219 CHKERR get_moab().tag_get_handle(
220 tag_data_name.c_str(), def_len, MB_TYPE_DOUBLE, th_field_data,
221 MB_TAG_CREAT | MB_TAG_VARLEN | MB_TAG_SPARSE, NULL);
222 std::string tag_data_name_verts = name_data_prefix + name + "V";
223 VectorDouble def_vert_data(nb_of_coefficients);
224 def_vert_data.clear();
225 CHKERR get_moab().tag_get_handle(
226 tag_data_name_verts.c_str(), nb_of_coefficients, MB_TYPE_DOUBLE,
227 th_field_data_vert, MB_TAG_CREAT | tag_type, &*def_vert_data.begin());
228 }
229
231 };
232
233 if (verb == -1)
234 verb = verbose;
235 *buildMoFEM = 0;
236 auto fit = fIelds.get<FieldName_mi_tag>().find(name);
237 if (fit != fIelds.get<FieldName_mi_tag>().end()) {
238 if (bh == MF_EXCL)
239 SETERRQ(PETSC_COMM_SELF, MOFEM_OPERATION_UNSUCCESSFUL,
240 "field is <%s> in database", name.c_str());
241
242 } else {
243
244 EntityHandle meshset;
245 CHKERR get_moab().create_meshset(MESHSET_SET, meshset);
246 CHKERR add_meshset_to_partition(meshset);
247
248 // id
249 int field_shift = 0;
250 for (;
251 fIelds.get<BitFieldId_mi_tag>().find(BitFieldId().set(field_shift)) !=
252 fIelds.get<BitFieldId_mi_tag>().end();
253 ++field_shift) {
254 if (field_shift == BITFEID_SIZE)
255 SETERRQ(PETSC_COMM_SELF, MOFEM_IMPOSSIBLE_CASE,
256 "Maximal number of fields exceeded");
257 }
258
259 auto id = BitFieldId().set(field_shift);
260 CHKERR create_tags(meshset, id);
261
262 auto p = fIelds.insert(boost::make_shared<Field>(moab, meshset));
263 if (verb > QUIET) {
264 MOFEM_LOG("WORLD", Sev::inform) << "Add field " << **p.first;
265 MOFEM_LOG("WORLD", Sev::noisy)
266 << "Field " << (*p.first)->getName() << " core value < "
267 << this->getValue() << " > field value ( "
268 << static_cast<int>((*p.first)->getBitNumber()) << " )";
269 }
270
271 if (!p.second)
272 SETERRQ(PETSC_COMM_SELF, MOFEM_NOT_FOUND,
273 "field not inserted %s (top tip, it could be already "
274 "there)",
275 Field(moab, meshset).getName().c_str());
276 }
277
278 MOFEM_LOG_CHANNEL("WORLD");
279 MOFEM_LOG_CHANNEL("SYNC");
281}
282
283MoFEMErrorCode Core::add_broken_field(
284 const std::string name, const FieldSpace space,
286 const FieldCoefficientsNumber nb_of_coefficients,
287
288 std::vector<
289
290 std::pair<EntityType,
291 std::function<MoFEMErrorCode(BaseFunction::DofsSideMap &)>
292
293 >>
294 list_dof_side_map,
295
296 const TagType tag_type, const enum MoFEMTypes bh, int verb) {
298 CHKERR this->addField(name, space, DISCONTINUOUS, base, nb_of_coefficients,
299 tag_type, bh, verb);
300
301 auto fit = fIelds.get<FieldName_mi_tag>().find(name);
302 if (fit == fIelds.get<FieldName_mi_tag>().end())
303 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
304 "field <%s> not in database", name.c_str());
305
306 for(auto &p : list_dof_side_map) {
307 auto &data_side_map = (*fit)->getDofSideMap()[p.first];
308 CHKERR p.second(data_side_map);
309 }
310
312}
313
314MoFEMErrorCode Core::add_field(const std::string name, const FieldSpace space,
316 const FieldCoefficientsNumber nb_of_coefficients,
317 const TagType tag_type, const enum MoFEMTypes bh,
318 int verb) {
319 return this->addField(name, space, CONTINUOUS, base, nb_of_coefficients,
320 tag_type, bh, verb);
321}
322
323MoFEMErrorCode Core::addEntsToFieldByDim(const Range &ents, const int dim,
324 const std::string &name, int verb) {
325
326 *buildMoFEM = 0;
327 EntityHandle idm = no_handle;
328 if (verb == -1)
329 verb = verbose;
330
331 MOFEM_LOG_CHANNEL("SYNC");
332 MOFEM_LOG_TAG("SYNC", "FieldCore");
334
336 idm = get_field_meshset(name);
337 FieldSpace space;
338 CHKERR get_moab().tag_get_data(th_FieldSpace, &idm, 1, &space);
339 FieldContinuity continuity;
340 CHKERR get_moab().tag_get_data(th_FieldContinuity, &idm, 1, &continuity);
341
342 switch (continuity) {
343 case CONTINUOUS:
344 case DISCONTINUOUS:
345 break;
346 default:
347 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
348 "sorry, unknown continuity added to entity");
349 }
350
351 std::vector<int> nb_ents_on_dim(3, 0);
352 switch (space) {
353 case L2:
354 CHKERR get_moab().add_entities(idm, ents);
355 break;
356 case H1:
357 CHKERR get_moab().add_entities(idm, ents);
358 if (continuity == DISCONTINUOUS)
359 break;
360 for (int dd = 0; dd != dim; ++dd) {
361 Range adj_ents;
362 CHKERR get_moab().get_adjacencies(ents, dd, false, adj_ents,
363 moab::Interface::UNION);
364 if (dd == 0) {
365 Range topo_nodes;
366 CHKERR get_moab().get_connectivity(ents, topo_nodes, true);
367 Range mid_nodes;
368 CHKERR get_moab().get_connectivity(ents, mid_nodes, false);
369 mid_nodes = subtract(mid_nodes, topo_nodes);
370 adj_ents = subtract(adj_ents, mid_nodes);
371 }
372 CHKERR get_moab().add_entities(idm, adj_ents);
373 nb_ents_on_dim[dd] = adj_ents.size();
374 }
375 break;
376 case HCURL:
377 CHKERR get_moab().add_entities(idm, ents);
378 if (continuity == DISCONTINUOUS)
379 break;
380 for (int dd = 1; dd != dim; ++dd) {
381 Range adj_ents;
382 CHKERR get_moab().get_adjacencies(ents, dd, false, adj_ents,
383 moab::Interface::UNION);
384 CHKERR get_moab().add_entities(idm, adj_ents);
385 nb_ents_on_dim[dd] = adj_ents.size();
386 }
387 break;
388 case HDIV:
389 CHKERR get_moab().add_entities(idm, ents);
390 if (continuity == DISCONTINUOUS)
391 break;
392 if (dim > 2) {
393 Range adj_ents;
394 CHKERR get_moab().get_adjacencies(ents, 2, false, adj_ents,
395 moab::Interface::UNION);
396 CHKERR get_moab().add_entities(idm, adj_ents);
397 nb_ents_on_dim[2] = adj_ents.size();
398 }
399 break;
400 default:
401 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
402 "sorry, unknown space added to entity");
403 }
404
405 if (verb >= VERBOSE) {
406 MOFEM_LOG("SYNC", Sev::noisy) << "add entities to field " << name;
407 MOFEM_LOG("SYNC", Sev::noisy) << "\tnb. add ents " << ents.size();
408 MOFEM_LOG("SYNC", Sev::noisy) << "\tnb. add faces " << nb_ents_on_dim[2];
409 MOFEM_LOG("SYNC", Sev::noisy) << "\tnb. add edges " << nb_ents_on_dim[1];
410 MOFEM_LOG("SYNC", Sev::noisy) << "\tnb. add nodes " << nb_ents_on_dim[0];
411 }
413}
414
415MoFEMErrorCode Core::add_ents_to_field_by_dim(const Range &ents, const int dim,
416 const std::string &name,
417 int verb) {
419 if (verb == -1)
420 verb = verbose;
421 Range ents_dim = ents.subset_by_dimension(dim);
422 CHKERR addEntsToFieldByDim(ents_dim, dim, name, verb);
423 // A quiet call may be made independently on one rank.
424 if (verb > QUIET)
425 MOFEM_LOG_SYNCHRONISE(mofemComm);
427}
428
429MoFEMErrorCode Core::add_ents_to_field_by_type(const Range &ents,
430 const EntityType type,
431 const std::string &name,
432 int verb) {
434 Range ents_type = ents.subset_by_type(type);
435 if (!ents_type.empty()) {
436 const int dim = get_moab().dimension_from_handle(ents_type[0]);
437 CHKERR addEntsToFieldByDim(ents_type, dim, name, verb);
438 }
439 MOFEM_LOG_SYNCHRONISE(mofemComm);
441}
442
443MoFEMErrorCode Core::add_ents_to_field_by_dim(const EntityHandle meshset,
444 const int dim,
445 const std::string &name,
446 const bool recursive, int verb) {
448 Range ents;
449 CHKERR get_moab().get_entities_by_dimension(meshset, dim, ents, recursive);
450 CHKERR addEntsToFieldByDim(ents, dim, name, verb);
451 MOFEM_LOG_SYNCHRONISE(mofemComm);
453}
454
455MoFEMErrorCode Core::add_ents_to_field_by_type(const EntityHandle meshset,
456 const EntityType type,
457 const std::string &name,
458 const bool recursive, int verb) {
460 Range ents;
461 CHKERR get_moab().get_entities_by_type(meshset, type, ents, recursive);
462 if (!ents.empty()) {
463 const int dim = get_moab().dimension_from_handle(ents[0]);
464 CHKERR addEntsToFieldByDim(ents, dim, name, verb);
465 }
466 MOFEM_LOG_SYNCHRONISE(mofemComm);
468}
469
470MoFEMErrorCode Core::create_vertices_and_add_to_field(const std::string name,
471 const double coords[],
472 int size, int verb) {
474
475 if (verb == DEFAULT_VERBOSITY)
476 verb = verbose;
477
478 Range verts;
479
480 auto create_vertices = [&]() {
482
483 vector<double *> arrays_coord;
484 EntityHandle startv = 0;
485 ReadUtilIface *iface;
486 CHKERR get_moab().query_interface(iface);
487 CHKERR iface->get_node_coords(3, size, 0, startv, arrays_coord);
488 verts.insert(startv, startv + size - 1);
489 for (int n = 0; n != size; ++n)
490 for (auto d : {0, 1, 2})
491 arrays_coord[d][n] = coords[3 * n + d];
492
494 };
495
496 auto add_verts_to_field = [&]() {
498 EntityHandle field_meshset = get_field_meshset(name);
499 CHKERR get_moab().add_entities(field_meshset, verts);
501 };
502
503 CHKERR create_vertices();
504 CHKERR add_verts_to_field();
505
507}
508
509MoFEMErrorCode Core::setFieldOrderImpl(boost::shared_ptr<Field> field_ptr,
510 const Range &ents,
511 const ApproximationOrder order,
512 int verb) {
514
515 if (verb == DEFAULT_VERBOSITY)
516 verb = verbose;
517 *buildMoFEM = 0;
518
519 const auto field_meshset = field_ptr->getMeshset();
520 const auto bit_number = field_ptr->getBitNumber();
521
522 // intersection with field meshset
523 Range ents_of_id_meshset;
524 CHKERR get_moab().get_entities_by_handle(field_meshset, ents_of_id_meshset,
525 false);
526 Range field_ents = intersect(ents, ents_of_id_meshset);
527 if (verb > QUIET) {
528 MOFEM_LOG_C("SYNC", Sev::noisy,
529 "change nb. of ents for order in the field <%s> %zu -> %zu",
530 field_ptr->getName().c_str(), ents.size(), field_ents.size());
531 }
532
533 // ent view by field id (in set all MoabEnts has the same FieldId)
534 auto eiit = entsFields.get<Unique_mi_tag>().lower_bound(
535 FieldEntity::getLoBitNumberUId(field_ptr->getBitNumber()));
537 if (eiit != entsFields.get<Unique_mi_tag>().end()) {
538 auto hi_eiit = entsFields.get<Unique_mi_tag>().upper_bound(
539 FieldEntity::getHiBitNumberUId(field_ptr->getBitNumber()));
540 std::copy(eiit, hi_eiit, std::back_inserter(ents_id_view));
541 }
542
543 if (verb > QUIET)
544 MOFEM_LOG_C("SYNC", Sev::noisy,
545 "current nb. of ents in the multi index field <%s> %zu",
546 field_ptr->getName().c_str(), ents_id_view.size());
547
548 // loop over ents
549 int nb_ents_set_order_up = 0;
550 int nb_ents_set_order_down = 0;
551 int nb_ents_set_order_new = 0;
552
553 FieldEntity_change_order modify_order_no_size_change(order, false);
554 FieldEntity_change_order modify_order_size_change(order, true);
555
556 for (auto pit = field_ents.const_pair_begin();
557 pit != field_ents.const_pair_end(); pit++) {
558 EntityHandle first = pit->first;
559 EntityHandle second = pit->second;
560
561 const auto type = static_cast<EntityType>(first >> MB_ID_WIDTH);
562
563 // Sanity check
564 switch (field_ptr->getSpace()) {
565 case H1:
566 break;
567 case HCURL:
568 if (type == MBVERTEX)
569 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
570 "Hcurl space on vertices makes no sense");
571
572 break;
573 case HDIV:
574 if (type == MBVERTEX)
575 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
576 "Hdiv space on vertices makes no sense");
577
578 if (type == MBEDGE)
579 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
580 "Hdiv space on edges makes no sense");
581
582 break;
583 default:
584 break;
585 }
586
587 // Entity is in database, change order only if needed
588 Range ents_in_database;
589 auto vit = ents_id_view.get<1>().lower_bound(first);
590 auto hi_vit = ents_id_view.get<1>().upper_bound(second);
591 if (order >= 0) {
592 for (; vit != hi_vit; ++vit) {
593 ents_in_database.insert(vit->get()->getEnt());
594 // entity is in database and order is changed or reset
595 const ApproximationOrder old_approximation_order =
596 (*vit)->getMaxOrder();
597
598 if (old_approximation_order != order) {
599
600 FieldEntity_multiIndex::iterator miit =
601 entsFields.get<Unique_mi_tag>().find((*vit)->getLocalUniqueId());
602
603 if ((*miit)->getMaxOrder() < order)
604 nb_ents_set_order_up++;
605 if ((*miit)->getMaxOrder() > order)
606 nb_ents_set_order_down++;
607
608 // set dofs inactive if order is reduced, and set new order to entity
609 // if order is increased (note that dofs are not build if order is
610 // increased)
611
612 bool can_change_size = true;
613 auto dit = dofsField.get<Unique_mi_tag>().lower_bound(
614 FieldEntity::getLoLocalEntityBitNumber(bit_number,
615 (*miit)->getEnt()));
616 if (dit != dofsField.get<Unique_mi_tag>().end()) {
617 auto hi_dit = dofsField.get<Unique_mi_tag>().upper_bound(
618 FieldEntity::getHiLocalEntityBitNumber(bit_number,
619 (*miit)->getEnt()));
620
621 if (dit != hi_dit)
622 can_change_size = false;
623 for (; dit != hi_dit; dit++) {
624 if ((*dit)->getDofOrder() > order) {
625 bool success = dofsField.modify(dofsField.project<0>(dit),
626 DofEntity_active_change(false));
627 if (!success)
628 SETERRQ(PETSC_COMM_SELF, MOFEM_OPERATION_UNSUCCESSFUL,
629 "modification unsuccessful");
630 }
631 }
632 }
633
634 bool success =
635 entsFields.modify(entsFields.project<0>(miit),
636 can_change_size ? modify_order_size_change
637 : modify_order_no_size_change);
638 if (!success)
639 SETERRQ(PETSC_COMM_SELF, MOFEM_OPERATION_UNSUCCESSFUL,
640 "modification unsuccessful");
641 }
642 }
643 }
644
645 Range new_ents = subtract(Range(first, second), ents_in_database);
646 for (Range::const_pair_iterator pit = new_ents.const_pair_begin();
647 pit != new_ents.const_pair_end(); ++pit) {
648 const auto first = pit->first;
649 const auto second = pit->second;
650 const auto ent_type = get_moab().type_from_handle(first);
651
652 if (!field_ptr->getFieldOrderTable()[ent_type])
653 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
654 "Number of degrees of freedom for entity %s for %s space on "
655 "base %s can "
656 "not be deduced",
657 moab::CN::EntityTypeName(ent_type),
658 field_ptr->getSpaceName().c_str(),
659 field_ptr->getApproxBaseName().c_str());
660
661 auto get_nb_dofs_on_order = [&](const int order) {
662 return order >= 0 ? (field_ptr->getFieldOrderTable()[ent_type])(order)
663 : 0;
664 };
665 const int nb_dofs_on_order = get_nb_dofs_on_order(order);
666 if (nb_dofs_on_order || order == -1) {
667
668 const int field_rank = field_ptr->getNbOfCoeffs();
669 const int nb_dofs = nb_dofs_on_order * field_rank;
670
671 // Entity is not in database and order is changed or reset
672 auto miit_ref_ent =
673 refinedEntities.get<Ent_mi_tag>().lower_bound(first);
674
675 auto create_tags_for_max_order = [&](const Range &ents) {
677 if (order >= 0) {
678 std::vector<ApproximationOrder> o_vec(ents.size(), order);
679 CHKERR get_moab().tag_set_data(field_ptr->th_AppOrder, ents,
680 &*o_vec.begin());
681 }
683 };
684
685 auto create_tags_for_data = [&](const Range &ents) {
687 if (order >= 0) {
688
689 if (nb_dofs > 0) {
690 if (ent_type == MBVERTEX) {
691 std::vector<FieldData> d_vec(nb_dofs * ents.size(), 0);
692 CHKERR get_moab().tag_set_data(field_ptr->th_FieldDataVerts,
693 ents, &*d_vec.begin());
694 } else {
695 std::vector<int> tag_size(ents.size(), nb_dofs);
696 std::vector<FieldData> d_vec(nb_dofs, 0);
697 std::vector<void const *> d_vec_ptr(ents.size(),
698 &*d_vec.begin());
699 CHKERR get_moab().tag_set_by_ptr(field_ptr->th_FieldData, ents,
700 &*d_vec_ptr.begin(),
701 &*tag_size.begin());
702 }
703 }
704 }
705
707 };
708
709 auto get_ents_in_ref_ent = [&](auto miit_ref_ent) {
710 auto hi = refinedEntities.get<Ent_mi_tag>().upper_bound(second);
711 Range in;
712 for (; miit_ref_ent != hi; ++miit_ref_ent)
713 in.insert(miit_ref_ent->get()->getEnt());
714 return in;
715 };
716
717 auto get_ents_max_order = [&](const Range &ents) {
718 boost::shared_ptr<std::vector<const void *>> vec(
719 new std::vector<const void *>());
720 vec->resize(ents.size());
721 CHKERR get_moab().tag_get_by_ptr(field_ptr->th_AppOrder, ents,
722 &*vec->begin());
723 return vec;
724 };
725
726 auto get_ents_field_data_vector_adaptor =
727 [&](const Range &ents,
728 boost::shared_ptr<std::vector<const void *>> &ents_max_orders) {
729 // create shared pointer and reserve memory
730 boost::shared_ptr<std::vector<double *>> vec(
731 new std::vector<double *>());
732 vec->reserve(ents.size());
733
734 if (order >= 0 && nb_dofs == 0) {
735 // set empty vector adaptor
736 for (int i = 0; i != ents.size(); ++i)
737 vec->emplace_back(nullptr);
738 } else {
739 moab::ErrorCode rval;
740 std::vector<int> tag_size(ents.size());
741 std::vector<const void *> d_vec_ptr(ents.size());
742
743 // get tags data
744 if (ent_type == MBVERTEX)
745 rval = get_moab().tag_get_by_ptr(field_ptr->th_FieldDataVerts,
746 ents, &*d_vec_ptr.begin(),
747 &*tag_size.begin());
748 else
749 rval = get_moab().tag_get_by_ptr(field_ptr->th_FieldData,
750 ents, &*d_vec_ptr.begin(),
751 &*tag_size.begin());
752
753 auto cast = [](auto p) {
754 return const_cast<FieldData *const>(
755 static_cast<const FieldData *>(p));
756 };
757
758 // some of entities has tag not set or zero dofs on entity
759 if (rval == MB_SUCCESS) {
760 // all is ok, all entities has tag set
761 auto tit = d_vec_ptr.begin();
762 auto oit = ents_max_orders->begin();
763 for (auto sit = tag_size.begin(); sit != tag_size.end();
764 ++sit, ++tit, ++oit)
765 vec->emplace_back(cast(*tit));
766
767 } else {
768 // set empty vector adaptor
769 for (int i = 0; i != ents.size(); ++i)
770 vec->emplace_back(nullptr);
771
772 // check order on all entities, and if for that order non zero
773 // dofs are expected get pointer to tag data and reset vector
774 // adaptor
775 auto oit = ents_max_orders->begin();
776 auto dit = vec->begin();
777 for (auto eit = ents.begin(); eit != ents.end();
778 ++eit, ++oit, ++dit) {
779
780 const int ent_order =
781 *static_cast<const ApproximationOrder *>(*oit);
782 const int ent_nb_dofs = get_nb_dofs_on_order(ent_order);
783
784 if (ent_nb_dofs) {
785 int tag_size;
786 const void *ret_val;
787 if (ent_type == MBVERTEX) {
788 rval = get_moab().tag_get_by_ptr(
789 field_ptr->th_FieldDataVerts, &*eit, 1, &ret_val,
790 &tag_size);
791 } else {
792 rval = get_moab().tag_get_by_ptr(
793 field_ptr->th_FieldData, &*eit, 1, &ret_val,
794 &tag_size);
795 if (rval != MB_SUCCESS) {
796
797 const int set_tag_size[] = {ent_nb_dofs * field_rank};
798 std::array<FieldData, MAX_DOFS_ON_ENTITY> set_d_vec;
799 std::fill(set_d_vec.begin(),
800 &set_d_vec[set_tag_size[0]], 0);
801 const void *set_d_vec_ptr[] = {set_d_vec.data()};
802 CHKERR get_moab().tag_set_by_ptr(
803 field_ptr->th_FieldData, &*eit, 1, set_d_vec_ptr,
804 set_tag_size);
805 rval = get_moab().tag_get_by_ptr(
806 field_ptr->th_FieldData, &*eit, 1, &ret_val,
807 &tag_size);
808
809 if (rval != MB_SUCCESS) {
811 LogManager::BitLineID |
812 LogManager::BitScope);
813 MOFEM_LOG("SELF", Sev::error)
814 << "Error is triggered in MOAB, field tag data "
815 "for same reason can not be for accessed.";
816 MOFEM_LOG("SELF", Sev::error)
817 << "Set order: " << order;
818 MOFEM_LOG("SELF", Sev::error)
819 << "Nb. dofs on entity for given order: "
820 << set_tag_size[0];
821 MOFEM_LOG("SELF", Sev::error)
822 << "Entity type: "
823 << moab::CN::EntityTypeName(ent_type);
824 MOFEM_LOG("SELF", Sev::error)
825 << "Field: " << *field_ptr;
826 CHKERR rval;
827 }
828 }
829 }
830 const_cast<FieldData *&>(*dit) = cast(ret_val);
831 }
832 }
833 }
834 }
835 return vec;
836 };
837
838 auto ents_in_ref_ent = get_ents_in_ref_ent(miit_ref_ent);
839
840 CHKERR create_tags_for_max_order(ents_in_ref_ent);
841 CHKERR create_tags_for_data(ents_in_ref_ent);
842 auto ents_max_order = get_ents_max_order(ents_in_ref_ent);
843 auto ent_field_data =
844 get_ents_field_data_vector_adaptor(ents_in_ref_ent, ents_max_order);
845
846 // reserve memory for field dofs
847 auto ents_array = boost::make_shared<std::vector<FieldEntity>>();
848 // Add sequence to field data structure. Note that entities are
849 // allocated once into vector. This vector is passed into sequence as a
850 // weak_ptr. Vector is destroyed at the point last entity inside that
851 // vector is destroyed.
852 ents_array->reserve(second - first + 1);
853 auto vit_max_order = ents_max_order->begin();
854 auto vit_field_data = ent_field_data->begin();
855 for (int i = 0; i != ents_in_ref_ent.size(); ++i) {
856
857 ents_array->emplace_back(
858 field_ptr, *miit_ref_ent,
859 boost::shared_ptr<double *const>(ent_field_data,
860 &*vit_field_data),
861 boost::shared_ptr<const int>(
862 ents_max_order, static_cast<const int *>(*vit_max_order)));
863 ++vit_max_order;
864 ++vit_field_data;
865 ++miit_ref_ent;
866 }
867 if (!ents_array->empty())
868 if ((*ents_array)[0].getFieldRawPtr() != field_ptr.get())
869 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
870 "Get field ent poiter and field pointer do not match for "
871 "field %s",
872 field_ptr->getName().c_str());
873 nb_ents_set_order_new += ents_array->size();
874
875 // Check if any of entities in the range has bit level but is not added
876 // to database. That generate data inconsistency and error.
877 if (ents_in_ref_ent.size() < (second - first + 1)) {
878 Range ents_not_in_database =
879 subtract(Range(first, second), ents_in_ref_ent);
880 std::vector<const void *> vec_bits(ents_not_in_database.size());
881 CHKERR get_moab().tag_get_by_ptr(
882 get_basic_entity_data_ptr()->th_RefBitLevel, ents_not_in_database,
883 &*vec_bits.begin());
884 auto cast = [](auto p) {
885 return static_cast<const BitRefLevel *>(p);
886 };
887 for (auto v : vec_bits)
888 if (cast(v)->any())
889 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
890 "Try to add entities which are not seeded or added to "
891 "database");
892 }
893
894 // Add entities to database
895 // Keep the successor of this ascending batch, including gap rebuilds.
896 const auto hint = ents_array->empty()
897 ? entsFields.end()
898 : entsFields.upper_bound(
899 ents_array->back().getLocalUniqueId());
900 for (auto &v : *ents_array)
901 entsFields.emplace_hint(hint, ents_array, &v);
902 }
903 }
904 }
905
906 if (verb > QUIET) {
907 MOFEM_LOG_C("SYNC", Sev::noisy,
908 "nb. of entities in field <%s> for which order was "
909 "increased %d (order %d)",
910 field_ptr->getName().c_str(), nb_ents_set_order_up, order);
911 MOFEM_LOG_C("SYNC", Sev::noisy,
912 "nb. of entities in field <%s> for which order was "
913 "reduced %d (order %d)",
914 field_ptr->getName().c_str(), nb_ents_set_order_down, order);
916 "SYNC", Sev::noisy,
917 "nb. of entities in field <%s> for which order set %d (order %d)",
918 field_ptr->getName().c_str(), nb_ents_set_order_new, order);
919 }
920
921 if (verb > QUIET) {
922 auto eiit = entsFields.get<Unique_mi_tag>().lower_bound(
923 FieldEntity::getLoBitNumberUId(field_ptr->getBitNumber()));
924 auto hi_eiit = entsFields.get<Unique_mi_tag>().upper_bound(
925 FieldEntity::getHiBitNumberUId(field_ptr->getBitNumber()));
926 MOFEM_LOG_C("SYNC", Sev::noisy,
927 "nb. of ents in the multi index field <%s> %d",
928 field_ptr->getName().c_str(), std::distance(eiit, hi_eiit));
929 }
930
931 if (verb > QUIET)
932 MOFEM_LOG_SEVERITY_SYNC(mofemComm, Sev::noisy);
933
935}
936
937MoFEMErrorCode Core::set_field_order(const Range &ents, const BitFieldId id,
938 const ApproximationOrder order, int verb) {
939 MOFEM_LOG_CHANNEL("WORLD");
940 MOFEM_LOG_TAG("WORLD", "FieldCore");
941 MOFEM_LOG_CHANNEL("SYNC");
942 MOFEM_LOG_TAG("SYNC", "FieldCore");
945
946 // check field & meshset
947 auto field_it = fIelds.get<BitFieldId_mi_tag>().find(id);
948 if (field_it == fIelds.get<BitFieldId_mi_tag>().end())
949 SETERRQ(PETSC_COMM_SELF, MOFEM_NOT_FOUND, "no field found");
950
951 MOFEM_LOG("WORLD", Sev::noisy)
952 << "Field " << (*field_it)->getName() << " core value < "
953 << this->getValue() << " > field value ( "
954 << static_cast<int>((*field_it)->getBitNumber()) << " )"
955 << " nb. of ents " << ents.size();
956
957 CHKERR this->setFieldOrderImpl(*field_it, ents, order, verb);
958
960}
961
962MoFEMErrorCode Core::set_field_order(const EntityHandle meshset,
963 const EntityType type, const BitFieldId id,
964 const ApproximationOrder order, int verb) {
966 if (verb == -1)
967 verb = verbose;
968 *buildMoFEM = 0;
969 Range ents;
970 CHKERR get_moab().get_entities_by_type(meshset, type, ents);
971 CHKERR this->set_field_order(ents, id, order, verb);
973}
974MoFEMErrorCode Core::set_field_order(const EntityHandle meshset,
975 const EntityType type,
976 const std::string &name,
977 const ApproximationOrder order, int verb) {
979 if (verb == -1)
980 verb = verbose;
981 *buildMoFEM = 0;
982 CHKERR this->set_field_order(meshset, type, get_field_id(name), order, verb);
984}
985MoFEMErrorCode Core::set_field_order(const Range &ents, const std::string &name,
986 const ApproximationOrder order, int verb) {
988 if (verb == -1)
989 verb = verbose;
990 *buildMoFEM = 0;
991 CHKERR this->set_field_order(ents, get_field_id(name), order, verb);
993}
994MoFEMErrorCode Core::set_field_order_by_entity_type_and_bit_ref(
995 const BitRefLevel &bit, const BitRefLevel &mask, const EntityType type,
996 const BitFieldId id, const ApproximationOrder order, int verb) {
998 if (verb == -1)
999 verb = verbose;
1000 *buildMoFEM = 0;
1001 Range ents;
1002 CHKERR BitRefManager(*this).getEntitiesByTypeAndRefLevel(bit, mask, type,
1003 ents, verb);
1004 CHKERR this->set_field_order(ents, id, order, verb);
1006}
1007
1008MoFEMErrorCode Core::set_field_order_by_entity_type_and_bit_ref(
1009 const BitRefLevel &bit, const BitRefLevel &mask, const EntityType type,
1010 const std::string &name, const ApproximationOrder order, int verb) {
1012 if (verb == -1)
1013 verb = verbose;
1014 *buildMoFEM = 0;
1015 Range ents;
1016 CHKERR BitRefManager(*this).getEntitiesByTypeAndRefLevel(bit, mask, type,
1017 ents, verb);
1018 CHKERR this->set_field_order(ents, get_field_id(name), order, verb);
1020}
1021
1023Core::buildFieldForNoFieldImpl(boost::shared_ptr<Field> field_ptr,
1024 std::map<EntityType, int> &dof_counter,
1025 int verb) {
1027
1028 const auto bit_number = field_ptr->getBitNumber();
1029
1030 // ents in the field meshset
1031 Range ents;
1032 CHKERR get_moab().get_entities_by_handle(field_ptr->getMeshset(), ents,
1033 false);
1034 if (verb > VERBOSE)
1035 MOFEM_LOG_C("SYNC", Sev::noisy, "Ents in field %s meshset %zu\n",
1036 field_ptr->getName().c_str(), ents.size());
1037
1038 // ent view by field id (in set all MoabEnts has the same FieldId)
1039 auto eiit = entsFields.get<Unique_mi_tag>().lower_bound(
1040 FieldEntity::getLoBitNumberUId(field_ptr->getBitNumber()));
1042 if (eiit != entsFields.get<Unique_mi_tag>().end()) {
1043 auto hi_eiit = entsFields.get<Unique_mi_tag>().upper_bound(
1044 FieldEntity::getHiBitNumberUId(field_ptr->getBitNumber()));
1045 std::copy(eiit, hi_eiit, std::back_inserter(ents_id_view));
1046 }
1047
1048 boost::shared_ptr<const int> zero_order(new const int(0));
1049
1050 for (auto ent : ents) {
1051 // search if field meshset is in database
1052 auto ref_ent_it = refinedEntities.get<Ent_mi_tag>().find(ent);
1053 if (ref_ent_it == refinedEntities.get<Ent_mi_tag>().end())
1054 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
1055 "Entity is not in MoFEM database, entities in field meshset need "
1056 "to be seeded (i.e. bit ref level add to them)");
1057
1058 auto add_dofs = [&](auto field_eit) {
1060 // create dofs on this entity (nb. of dofs is equal to rank)
1061 for (FieldCoefficientsNumber rank = 0; rank < field_ptr->getNbOfCoeffs();
1062 rank++) {
1063 // insert dof
1064 auto p = dofsField.insert(
1065 boost::make_shared<DofEntity>(field_eit, 0, rank, rank));
1066 if (p.second) {
1067 dof_counter[MBENTITYSET]++; // Count entities in the meshset
1068 } else
1069 SETERRQ(PETSC_COMM_SELF, MOFEM_OPERATION_UNSUCCESSFUL,
1070 "Dof expected to be created");
1071 }
1073 };
1074
1075 // create database entity
1076 auto field_ent_it = ents_id_view.get<1>().find(ent);
1077 if (field_ent_it == ents_id_view.get<1>().end()) {
1078
1079 auto p = entsFields.insert(
1080
1081 boost::make_shared<FieldEntity>(
1082 field_ptr, *ref_ent_it,
1083 FieldEntity::makeSharedFieldDataAdaptorPtr(field_ptr,
1084 *ref_ent_it),
1085 boost::shared_ptr<const int>(zero_order, zero_order.get()))
1086
1087 );
1088
1089 if ((*p.first)->getFieldRawPtr() != field_ptr.get())
1090 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
1091 "Get field ent poiter and field pointer do not match for "
1092 "field %s",
1093 field_ptr->getName().c_str());
1094
1095 if (!p.second)
1096 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
1097 "Entity should be created");
1098
1099 CHKERR add_dofs(*(p.first));
1100
1101 } else {
1102
1103 // If there are DOFs in that range is more pragmatic to remove them
1104 // rather than to find sub-ranges or make them inactive
1105 auto dit = dofsField.get<Unique_mi_tag>().lower_bound(
1106 FieldEntity::getLoLocalEntityBitNumber(bit_number, ent));
1107 auto hi_dit = dofsField.get<Unique_mi_tag>().upper_bound(
1108 FieldEntity::getHiLocalEntityBitNumber(bit_number, ent));
1109 dofsField.get<Unique_mi_tag>().erase(dit, hi_dit);
1110 CHKERR add_dofs(*field_ent_it);
1111 }
1112 }
1113
1114 if (verb > VERBOSE) {
1115 auto lo_dof = dofsField.get<Unique_mi_tag>().lower_bound(
1116 FieldEntity::getLoBitNumberUId(field_ptr->getBitNumber()));
1117 auto hi_dof = dofsField.get<Unique_mi_tag>().upper_bound(
1118 FieldEntity::getHiBitNumberUId(field_ptr->getBitNumber()));
1119 for (; lo_dof != hi_dof; lo_dof++)
1120 MOFEM_LOG("SYNC", Sev::noisy) << **lo_dof;
1121 MOFEM_LOG_SEVERITY_SYNC(mofemComm, Sev::noisy);
1122 }
1123
1125}
1126
1128Core::buildFieldForNoField(const BitFieldId id,
1129 std::map<EntityType, int> &dof_counter, int verb) {
1131
1132 if (verb == -1)
1133 verb = verbose;
1134
1135 // find fields
1136 auto field_it = fIelds.get<BitFieldId_mi_tag>().find(id);
1137 if (field_it == fIelds.get<BitFieldId_mi_tag>().end())
1138 SETERRQ(PETSC_COMM_SELF, MOFEM_NOT_FOUND, "Field not found");
1139
1140 if (verb > QUIET)
1141 MOFEM_LOG("WORLD", Sev::noisy)
1142 << "Field " << (*field_it)->getName() << " core value < "
1143 << this->getValue() << " > field value () "
1144 << (*field_it)->getBitNumber() << " )";
1145
1146 CHKERR this->buildFieldForNoFieldImpl(*field_it, dof_counter, verb);
1147
1149}
1150
1151MoFEMErrorCode Core::buildFieldForL2H1HcurlHdiv(
1152 const BitFieldId id, std::map<EntityType, int> &dof_counter,
1153 std::map<EntityType, int> &inactive_dof_counter, const Range *ents_ptr,
1154 int verb) {
1156 if (verb == -1)
1157 verb = verbose;
1158
1159 // Find field
1160 auto &set_id = fIelds.get<BitFieldId_mi_tag>();
1161 auto field_it = set_id.find(id);
1162 if (field_it == set_id.end()) {
1163 SETERRQ(PETSC_COMM_SELF, MOFEM_NOT_FOUND, "Field not found");
1164 }
1165 const int bit_number = field_it->get()->getBitNumber();
1166 const int rank = field_it->get()->getNbOfCoeffs();
1167
1168 // Ents in the field meshset
1169 Range ents_of_id_meshset;
1170 CHKERR get_moab().get_entities_by_handle((*field_it)->meshSet,
1171 ents_of_id_meshset, false);
1172 // Every entity visited below has its DOFs erased and recreated, so an
1173 // incremental build must restrict the range to the entities that changed.
1174 if (ents_ptr)
1175 ents_of_id_meshset = intersect(ents_of_id_meshset, *ents_ptr);
1176 if (verb > VERY_NOISY) {
1177 MOFEM_LOG_C("SYNC", Sev::noisy, "Ents in field %s meshset %zu",
1178 (*field_it)->getName().c_str(), ents_of_id_meshset.size());
1179 }
1180
1181 for (auto p_eit = ents_of_id_meshset.pair_begin();
1182 p_eit != ents_of_id_meshset.pair_end(); ++p_eit) {
1183
1184 const EntityHandle first = p_eit->first;
1185 const EntityHandle second = p_eit->second;
1186 const auto lo_uid =
1187 FieldEntity::getLoLocalEntityBitNumber(bit_number, first);
1188 const auto hi_uid =
1189 FieldEntity::getHiLocalEntityBitNumber(bit_number, second);
1190
1191 auto feit = entsFields.get<Unique_mi_tag>().lower_bound(lo_uid);
1192 if (feit == entsFields.get<Unique_mi_tag>().end())
1193 continue;
1194 auto hi_feit = entsFields.get<Unique_mi_tag>().upper_bound(hi_uid);
1195
1196 // If there are DOFs in that range is more pragmatic to remove them
1197 // rather than to find sub-ranges or make them inactive
1198 auto dit = dofsField.get<Unique_mi_tag>().lower_bound(lo_uid);
1199 auto hi_dit = dofsField.get<Unique_mi_tag>().upper_bound(hi_uid);
1200 dofsField.get<Unique_mi_tag>().erase(dit, hi_dit);
1201
1202 // Add vertices DOFs by bulk
1203 boost::shared_ptr<std::vector<DofEntity>> dofs_array =
1204 boost::make_shared<std::vector<DofEntity>>(std::vector<DofEntity>());
1205 // Add Sequence of DOFs to sequence container as weak_ptr
1206 int nb_dofs_on_ents = 0;
1207 for (auto tmp_feit = feit; tmp_feit != hi_feit; ++tmp_feit) {
1208 nb_dofs_on_ents += rank * tmp_feit->get()->getOrderNbDofs(
1209 tmp_feit->get()->getMaxOrder());
1210 }
1211
1212 // Reserve memory
1213 dofs_array->reserve(nb_dofs_on_ents);
1214
1215 // Create DOFs
1216 for (; feit != hi_feit; ++feit) {
1217 // Create dofs instances and shared pointers
1218 int DD = 0;
1219 // Loop orders (loop until max entity order is set)
1220 for (int oo = 0; oo <= feit->get()->getMaxOrder(); ++oo) {
1221 // Loop nb. dofs at order oo
1222 for (int dd = 0; dd < feit->get()->getOrderNbDofsDiff(oo); ++dd) {
1223 // Loop rank
1224 for (int rr = 0; rr < rank; ++rr, ++DD) {
1225 dofs_array->emplace_back(*feit, oo, rr, DD);
1226 ++dof_counter[feit->get()->getEntType()];
1227 }
1228 }
1229 }
1230 if (DD > feit->get()->getNbDofsOnEnt()) {
1231 std::ostringstream ss;
1232 ss << "rank " << rAnk << " ";
1233 ss << **feit << std::endl;
1234 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
1235 "Expected number of DOFs on entity not equal to number added "
1236 "to database (DD = %d != %d = "
1237 "feit->get()->getNbDofsOnEnt())\n"
1238 "%s",
1239 DD, feit->get()->getNbDofsOnEnt(), ss.str().c_str());
1240 }
1241 }
1242
1243 // Insert into Multi-Index container
1244 int dofs_field_size0 = dofsField.size();
1245 // The old interval was erased above; hi_dit is its surviving successor.
1246 const auto hint = hi_dit;
1247 for (auto &v : *dofs_array)
1248 dofsField.emplace_hint(hint, dofs_array, &v);
1249
1250 // Add Sequence of DOFs to sequence container as weak_ptr
1251 field_it->get()->getDofSequenceContainer().push_back(dofs_array);
1252
1253 // Check data consistency
1254 if (PetscUnlikely(static_cast<int>(dofs_array.use_count()) !=
1255 static_cast<int>(dofs_array->size() + 1))) {
1256 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
1257 "Wrong use count %ld != %zu", dofs_array.use_count(),
1258 dofs_array->size() + 1);
1259 }
1260 if (dofs_field_size0 + dofs_array->size() != dofsField.size()) {
1261 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
1262 "Wrong number of inserted DOFs %zu != %zu", dofs_array->size(),
1263 dofsField.size() - dofs_field_size0);
1264 }
1265 }
1267}
1268
1269MoFEMErrorCode Core::buildField(const boost::shared_ptr<Field> &field,
1270 const Range *ents_ptr, int verb) {
1272 if (verb == -1)
1273 verb = verbose;
1274 if (verb > QUIET)
1275 MOFEM_LOG("SYNC", Sev::verbose) << "Build field " << field->getName();
1276
1277 std::map<EntityType, int> dof_counter;
1278 std::map<EntityType, int> inactive_dof_counter;
1279
1280 // Need to rebuild order table since number of dofs on each order when
1281 // field was created.
1282 if (field->getApproxBase() == USER_BASE)
1283 CHKERR field->rebuildDofsOrderMap();
1284
1285 switch (field->getSpace()) {
1286 case NOFIELD:
1287 CHKERR this->buildFieldForNoField(field->getId(), dof_counter, verb);
1288 break;
1289 case L2:
1290 case H1:
1291 case HCURL:
1292 case HDIV:
1293 CHKERR this->buildFieldForL2H1HcurlHdiv(field->getId(), dof_counter,
1294 inactive_dof_counter, ents_ptr,
1295 verb);
1296 break;
1297 default:
1298 SETERRQ(PETSC_COMM_SELF, MOFEM_NOT_IMPLEMENTED, "not implemented");
1299 }
1300
1301 if (verb > QUIET) {
1302 int nb_added_dofs = 0;
1303 int nb_inactive_added_dofs = 0;
1304 for (auto const &it : dof_counter) {
1305 MOFEM_LOG("SYNC", Sev::verbose)
1306 << "Nb. of dofs (" << moab::CN::EntityTypeName(it.first) << ") "
1307 << it.second << " (inactive " << inactive_dof_counter[it.first]
1308 << ")";
1309 nb_added_dofs += it.second;
1310 nb_inactive_added_dofs += inactive_dof_counter[it.first];
1311 }
1312 MOFEM_LOG("SYNC", Sev::verbose)
1313 << "Nb. added dofs " << nb_added_dofs << " (number of inactive dofs "
1314 << nb_inactive_added_dofs << " )";
1315 }
1317}
1318
1319MoFEMErrorCode Core::build_field(const std::string field_name, int verb) {
1321 auto field_it = fIelds.get<FieldName_mi_tag>().find(field_name);
1322 if (field_it == fIelds.get<FieldName_mi_tag>().end())
1323 SETERRQ(PETSC_COMM_SELF, MOFEM_NOT_FOUND, "Field < %s > not found",
1324 field_name.c_str());
1325
1326 CHKERR this->buildField(*field_it, nullptr, verb);
1327 if (verb > QUIET)
1328 MOFEM_LOG_SYNCHRONISE(mofemComm);
1330}
1331
1332MoFEMErrorCode Core::build_field(const std::string field_name,
1333 const Range &ents, int verb) {
1335 auto field_it = fIelds.get<FieldName_mi_tag>().find(field_name);
1336 if (field_it == fIelds.get<FieldName_mi_tag>().end())
1337 SETERRQ(PETSC_COMM_SELF, MOFEM_NOT_FOUND, "Field < %s > not found",
1338 field_name.c_str());
1339
1340 CHKERR this->buildField(*field_it, &ents, verb);
1341 if (verb > QUIET)
1342 MOFEM_LOG_SYNCHRONISE(mofemComm);
1344}
1345
1346MoFEMErrorCode Core::build_fields(const Range &ents, int verb) {
1348 if (verb == -1)
1349 verb = verbose;
1350
1351 for (auto field : fIelds.get<BitFieldId_mi_tag>())
1352 CHKERR this->buildField(field, &ents, verb);
1353
1354 *buildMoFEM = 1 << 0;
1355 if (verb > QUIET) {
1356 MOFEM_LOG("SYNC", Sev::verbose) << "Number of dofs " << dofsField.size();
1357 MOFEM_LOG_SYNCHRONISE(mofemComm);
1358 }
1360}
1361
1362MoFEMErrorCode Core::build_fields(int verb) {
1364 if (verb == -1)
1365 verb = verbose;
1366
1367 for (auto field : fIelds.get<BitFieldId_mi_tag>())
1368 CHKERR this->buildField(field, nullptr, verb);
1369
1370 *buildMoFEM = 1 << 0;
1371 if (verb > QUIET) {
1372 MOFEM_LOG("SYNC", Sev::verbose) << "Number of dofs " << dofsField.size();
1373 MOFEM_LOG_SYNCHRONISE(mofemComm);
1374 }
1375
1377}
1378
1380Core::list_dofs_by_field_name(const std::string &field_name) const {
1382 auto dit = dofsField.get<Unique_mi_tag>().lower_bound(
1383 FieldEntity::getLoBitNumberUId(get_field_bit_number((field_name))));
1384 auto hi_dit = dofsField.get<Unique_mi_tag>().upper_bound(
1385 FieldEntity::getHiBitNumberUId(get_field_bit_number(field_name)));
1386 MOFEM_LOG("SYNC", Sev::inform) << "List DOFs:";
1387 for (; dit != hi_dit; dit++)
1388 MOFEM_LOG("SYNC", Sev::inform) << *dit;
1389
1390 MOFEM_LOG_SYNCHRONISE(mofemComm);
1392}
1393
1394MoFEMErrorCode Core::list_fields() const {
1396 MOFEM_LOG("SYNC", Sev::inform) << "List Fields:";
1397 for (auto &miit : fIelds.get<BitFieldId_mi_tag>())
1398 MOFEM_LOG("SYNC", Sev::inform) << *miit;
1399
1400 MOFEM_LOG_SYNCHRONISE(mofemComm);
1402}
1403
1404FieldEntityByUId::iterator
1405Core::get_ent_field_by_name_begin(const std::string &field_name) const {
1406 return entsFields.get<Unique_mi_tag>().lower_bound(
1407 FieldEntity::getLoBitNumberUId(get_field_bit_number(field_name)));
1408}
1409FieldEntityByUId::iterator
1410Core::get_ent_field_by_name_end(const std::string &field_name) const {
1411 return entsFields.get<Unique_mi_tag>().upper_bound(
1412 FieldEntity::getHiBitNumberUId(get_field_bit_number(field_name)));
1413}
1414DofEntityByUId::iterator
1415Core::get_dofs_by_name_begin(const std::string &field_name) const {
1416 return dofsField.get<Unique_mi_tag>().lower_bound(
1417 FieldEntity::getLoBitNumberUId(get_field_bit_number(field_name)));
1418}
1419DofEntityByUId::iterator
1420Core::get_dofs_by_name_end(const std::string &field_name) const {
1421 return dofsField.get<Unique_mi_tag>().upper_bound(
1422 FieldEntity::getHiBitNumberUId(get_field_bit_number(field_name)));
1423}
1424DofEntityByUId::iterator
1425Core::get_dofs_by_name_and_ent_begin(const std::string &field_name,
1426 const EntityHandle ent) const {
1427 return dofsField.get<Unique_mi_tag>().lower_bound(
1428 FieldEntity::getLoLocalEntityBitNumber(get_field_bit_number(field_name),
1429 ent));
1430}
1431DofEntityByUId::iterator
1432Core::get_dofs_by_name_and_ent_end(const std::string &field_name,
1433 const EntityHandle ent) const {
1434 return dofsField.get<Unique_mi_tag>().upper_bound(
1435 FieldEntity::getHiLocalEntityBitNumber(get_field_bit_number(field_name),
1436 ent));
1437}
1438DofEntityByUId::iterator
1439Core::get_dofs_by_name_and_type_begin(const std::string &field_name,
1440 const EntityType type) const {
1441 return dofsField.get<Unique_mi_tag>().lower_bound(
1442 FieldEntity::getLoLocalEntityBitNumber(get_field_bit_number(field_name),
1444}
1445DofEntityByUId::iterator
1446Core::get_dofs_by_name_and_type_end(const std::string &field_name,
1447 const EntityType type) const {
1448 return dofsField.get<Unique_mi_tag>().upper_bound(
1449 FieldEntity::getHiLocalEntityBitNumber(get_field_bit_number(field_name),
1451}
1453Core::check_number_of_ents_in_ents_field(const std::string &name) const {
1455 auto it = fIelds.get<FieldName_mi_tag>().find(name);
1456 if (it == fIelds.get<FieldName_mi_tag>().end()) {
1457 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
1458 "field not found < %s >", name.c_str());
1459 }
1460 EntityHandle meshset = (*it)->getMeshset();
1461 int num_entities;
1462 CHKERR get_moab().get_number_entities_by_handle(meshset, num_entities);
1463
1464 auto count_field_ents = [&]() {
1465 auto bit_number = (*it)->getBitNumber();
1466 auto low_eit = entsFields.get<Unique_mi_tag>().lower_bound(
1467 FieldEntity::getLoBitNumberUId(bit_number));
1468 auto hi_eit = entsFields.get<Unique_mi_tag>().upper_bound(
1469 FieldEntity::getHiBitNumberUId(bit_number));
1470 return std::distance(low_eit, hi_eit);
1471 };
1472
1473 if (count_field_ents() > (unsigned int)num_entities) {
1474 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
1475 "not equal number of entities in meshset and field multiindex "
1476 "< %s >",
1477 name.c_str());
1478 }
1480}
1481MoFEMErrorCode Core::check_number_of_ents_in_ents_field() const {
1483 for (auto &it : fIelds.get<FieldName_mi_tag>()) {
1484 if (it->getSpace() == NOFIELD)
1485 continue; // FIXME: should be treated properly, not test is just
1486 // skipped for this NOFIELD space
1487 EntityHandle meshset = it->getMeshset();
1488 int num_entities;
1489 CHKERR get_moab().get_number_entities_by_handle(meshset, num_entities);
1490
1491 auto count_field_ents = [&]() {
1492 auto bit_number = it->getBitNumber();
1493 auto low_eit = entsFields.get<Unique_mi_tag>().lower_bound(
1494 FieldEntity::getLoBitNumberUId(bit_number));
1495 auto hi_eit = entsFields.get<Unique_mi_tag>().upper_bound(
1496 FieldEntity::getHiBitNumberUId(bit_number));
1497 return std::distance(low_eit, hi_eit);
1498 };
1499
1500 if (count_field_ents() > (unsigned int)num_entities) {
1501 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
1502 "not equal number of entities in meshset and field "
1503 "multiindex < %s >",
1504 it->getName().c_str());
1505 }
1506 }
1508}
1509
1510} // namespace MoFEM
std::vector< int > size
WorkMesh base
ProjectedField & field
#define FieldCoreFunctionBegin
Definition FieldCore.cpp:8
std::string type
#define MOFEM_LOG_SEVERITY_SYNC(comm, severity)
Synchronise "SYNC" on curtain severity level.
#define MOFEM_LOG_SYNCHRONISE(comm)
Synchronise "SYNC" channel.
#define MOFEM_LOG_C(channel, severity, format,...)
It it
Definition Schur.cpp:2568
It end
Definition Schur.cpp:2568
std::string name
static PetscErrorCode ierr
@ QUIET
@ DEFAULT_VERBOSITY
@ VERBOSE
@ VERY_NOISY
MoFEMTypes
Those types control how functions respond on arguments, f.e. error handling.
@ MF_EXIST
@ MF_EXCL
FieldApproximationBase
approximation base
Definition definitions.h:58
@ USER_BASE
user implemented approximation base
Definition definitions.h:68
#define CHK_THROW_MESSAGE(err, msg)
Check and throw MoFEM exception.
#define MoFEMFunctionReturnHot(a)
Last executable line of each PETSc function used for error handling. Replaces return()
FieldSpace
approximation spaces
Definition definitions.h:82
@ L2
field with C-1 continuity
Definition definitions.h:88
@ NOFIELD
scalar or vector of scalars describe (no true field)
Definition definitions.h:84
@ H1
continuous field
Definition definitions.h:85
@ HCURL
field with continuous tangents
Definition definitions.h:86
@ HDIV
field with continuous normal traction
Definition definitions.h:87
#define MB_ID_WIDTH
FieldContinuity
Field continuity.
Definition definitions.h:99
@ CONTINUOUS
Regular field.
@ DISCONTINUOUS
Broken continuity (No effect on L2 space)
@ MOFEM_NOT_FOUND
Definition definitions.h:33
@ MOFEM_IMPOSSIBLE_CASE
Definition definitions.h:35
@ MOFEM_OPERATION_UNSUCCESSFUL
Definition definitions.h:34
@ MOFEM_DATA_INCONSISTENCY
Definition definitions.h:31
@ MOFEM_NOT_IMPLEMENTED
Definition definitions.h:32
#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 ...
#define BITFEID_SIZE
max number of finite elements
#define THROW_MESSAGE(msg)
Throw MoFEM exception.
constexpr int order
#define MOFEM_LOG(channel, severity)
Log.
#define MOFEM_LOG_TAG(channel, tag)
Tag channel.
#define MOFEM_LOG_CHANNEL(channel)
Set and reset channel.
#define MOFEM_LOG_ATTRIBUTES(channel, bit)
Add attributes to channel.
#define MOFEM_LOG_FUNCTION()
Set scope.
auto bit
set bit
FTensor::Index< 'i', SPACE_DIM > i
const double v
phase velocity of light in medium (cm/ns)
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)
Definition ddTensor0.hpp:33
PetscErrorCode MoFEMErrorCode
MoFEM/PETSc error code.
double FieldData
Field data type.
Definition Types.hpp:25
int ApproximationOrder
Approximation on the entity.
Definition Types.hpp:26
std::bitset< BITFIELDID_SIZE > BitFieldId
Field Id.
Definition Types.hpp:42
std::bitset< BITREFLEVEL_SIZE > BitRefLevel
Bit structure attached to each entity identifying to what mesh entity is attached.
Definition Types.hpp:40
UBlasVector< double > VectorDouble
Definition Types.hpp:68
char FieldBitNumber
Field bit number.
Definition Types.hpp:28
multi_index_container< boost::shared_ptr< FieldEntity >, indexed_by< sequenced<>, ordered_non_unique< tag< Ent_mi_tag >, const_mem_fun< FieldEntity::interface_type_RefEntity, EntityHandle, &FieldEntity::getEnt > > > > FieldEntity_multiIndex_ent_view
EntityHandle get_id_for_max_type()
EntityHandle get_id_for_min_type()
Field_multiIndex::index< FieldName_mi_tag >::type::iterator field_it
MoFEM::LogManager::SeverityLevel Sev
const EntityHandle no_handle
No entity handle is indicated by zero handle, i.e. root meshset.
Definition Common.hpp:12
constexpr auto field_name