v0.15.5
Loading...
Searching...
No Matches
EntitiesFieldData.cpp
Go to the documentation of this file.
1/** \file EntitiesFieldData.cpp
2\brief Implementation for Data Structures in Forces and Sources
3
4*/
5
6
7
8namespace MoFEM {
9
10EntitiesFieldData::EntData::EntData(const bool allocate_base_matrices)
11 : sEnse(0), oRder(0), bAse(NOBASE), entDataBitRefLevel(),
12 N(baseFunctionsAndBaseDerivatives[ZeroDerivative]),
13 diffN(baseFunctionsAndBaseDerivatives[FirstDerivative]) {
14 if (allocate_base_matrices) {
15
16 for (auto d = 0; d != LastDerivative; ++d) {
17 for (int b = 0; b != LASTBASE; ++b) {
19 }
20 }
21 } else {
22
23 // set null to all base function pointers
24 for (auto d = 0; d != LastDerivative; ++d) {
25 std::fill(baseFunctionsAndBaseDerivatives[d].begin(),
26 baseFunctionsAndBaseDerivatives[d].end(), nullptr);
27 }
28 }
29}
30
31int EntitiesFieldData::EntData::getSense() const { return sEnse; }
32
33boost::shared_ptr<MatrixDouble> &
35 const BaseDerivatives derivative) {
36 return baseFunctionsAndBaseDerivatives[derivative][base];
37}
38
39boost::shared_ptr<MatrixDouble> &
43
44boost::shared_ptr<MatrixDouble> &EntitiesFieldData::EntData::getDiffNSharedPtr(
45 const FieldApproximationBase base) {
46 return diffN[base];
47}
48
49static void constructor_data(EntitiesFieldData *data, const EntityType type) {
50
52
53 auto set_default = [&]() {
54 std::array<size_t, MBMAXTYPE> count;
55 std::fill(count.begin(), count.end(), 0);
56 const int dim_type = moab::CN::Dimension(type);
57 data->dataOnEntities[MBVERTEX].resize(1);
58 if (type != MBVERTEX) {
59 for (auto dd = dim_type; dd > 0; --dd) {
60 int nb_ents = moab::CN::NumSubEntities(type, dd);
61 for (int ii = 0; ii != nb_ents; ++ii) {
62 auto sub_ent_type = moab::CN::SubEntityType(type, dd, ii);
63 count[sub_ent_type] = nb_ents;
64 }
65 for (auto tt = moab::CN::TypeDimensionMap[dd].first;
66 tt <= moab::CN::TypeDimensionMap[dd].second; ++tt) {
67 data->dataOnEntities[tt].resize(count[tt]);
68 }
69 }
70 }
71 };
72
73 switch (type) {
74 case MBENTITYSET:
75 break;
76
77 default:
78 set_default();
79 }
80}
81
83 constructor_data(this, type);
84}
85
91
92static void
94 const boost::shared_ptr<EntitiesFieldData> &data_ptr) {
95
97 using DerivedEntData = DerivedEntitiesFieldData::DerivedEntData;
98
99 for (int tt = MBVERTEX; tt != MBMAXTYPE; ++tt) {
100 auto &ent_data = data_ptr->dataOnEntities[tt];
101 auto &derived_ent_data = derived_data->dataOnEntities[tt];
102 for (auto c = derived_ent_data.size(); c < ent_data.size(); ++c) {
103 boost::shared_ptr<EntData> ent_data_ptr(data_ptr, &ent_data[c]);
104 derived_ent_data.push_back(new DerivedEntData(ent_data_ptr));
105 }
106 derived_ent_data.resize(ent_data.size());
107 }
108}
109
111 const boost::shared_ptr<EntitiesFieldData> &data_ptr)
112 : EntitiesFieldData(), dataPtr(data_ptr) {
114}
115
121
124 sPace = NOSPACE;
125 bAse = NOBASE;
126 fieldEntities.resize(0, false);
127 iNdices.resize(0, false);
128 localIndices.resize(0, false);
129 dOfs.resize(0, false);
130 fieldData.resize(0, false);
132}
133
136 for (EntityType t = MBVERTEX; t != MBMAXTYPE; t++)
137 for (auto &e : dataOnEntities[t])
138 CHKERR e.resetFieldDependentData();
140}
141
144 const FieldApproximationBase base) {
146 auto make_swap = [](boost::shared_ptr<MatrixDouble> &ptr,
147 boost::shared_ptr<MatrixDouble> &ptrBB,
148 boost::shared_ptr<MatrixDouble> &swap_ptr) {
149 if (swap_ptr) {
150 ptr = swap_ptr;
151 swap_ptr.reset();
152 } else {
153 swap_ptr = ptr;
154 ptr = ptrBB;
155 }
156 };
157 make_swap(getNSharedPtr(base), getBBNSharedPtr(field_name), swapBaseNPtr);
158 make_swap(getDiffNSharedPtr(base), getBBDiffNSharedPtr(field_name),
159 swapBaseDiffNPtr);
161}
162
164 const FieldApproximationBase base) {
166 // Note: Do not swap bases on entities sets
167 for (int tt = MBVERTEX; tt != MBENTITYSET; ++tt) {
168 auto &ent_data = dataOnEntities[tt];
169 for (auto &side_data : ent_data)
170 CHKERR side_data.baseSwap(field_name, base);
171 }
173}
174
176 const std::string &field_name, const FieldApproximationBase base) {
178 auto make_swap = [](boost::shared_ptr<MatrixDouble> &ptr,
179 boost::shared_ptr<MatrixDouble> &ptrBB,
180 boost::shared_ptr<MatrixDouble> &swap_ptr) {
181 if (swap_ptr) {
182 ptr = swap_ptr;
183 swap_ptr.reset();
184 } else {
185 swap_ptr = ptr;
186 ptr = ptrBB;
187 }
188 };
189 make_swap(getDerivedNSharedPtr(base), getBBNSharedPtr(field_name),
190 swapBaseNPtr);
191 make_swap(getDerivedDiffNSharedPtr(base), getBBDiffNSharedPtr(field_name),
192 swapBaseDiffNPtr);
194}
195
197 const boost::shared_ptr<EntitiesFieldData::EntData> &ent_data_ptr)
198 : EntitiesFieldData::EntData(false), entDataPtr(ent_data_ptr) {}
199
201 return entDataPtr->getSense();
202}
203
204boost::shared_ptr<MatrixDouble> &
206 const FieldApproximationBase base, const BaseDerivatives derivative) {
207 if (baseFunctionsAndBaseDerivatives[derivative][base])
208 return baseFunctionsAndBaseDerivatives[derivative][base];
209 else
210 return entDataPtr->getNSharedPtr(base, derivative);
211}
212
213boost::shared_ptr<MatrixDouble> &
215 const FieldApproximationBase base) {
216 if (N[base])
217 return N[base];
218 else
219 return entDataPtr->getNSharedPtr(base);
220}
221
222boost::shared_ptr<MatrixDouble> &
224 const FieldApproximationBase base) {
225 if (diffN[base])
226 return diffN[base];
227 else
228 return entDataPtr->getDiffNSharedPtr(base);
229}
230const boost::shared_ptr<MatrixDouble> &
232 const FieldApproximationBase base) const {
233 if (N[base])
234 return N[base];
235 else
236 return entDataPtr->getNSharedPtr(base);
237}
238const boost::shared_ptr<MatrixDouble> &
240 const FieldApproximationBase base) const {
241 if (diffN[base])
242 return diffN[base];
243 else
244 return entDataPtr->getDiffNSharedPtr(base);
245}
246
247std::ostream &operator<<(std::ostream &os,
249 os << "sEnse: " << e.getSense() << std::endl
250 << "oRder: " << e.getOrder() << std::endl
251 << "global indices: " << e.getIndices() << std::endl
252 << "local indices: " << e.getLocalIndices() << std::endl;
253 // FIXME: precision should not be set here
254 os << "fieldData: " << std::fixed << std::setprecision(2) << e.getFieldData()
255 << std::endl;
256 MatrixDouble base = const_cast<EntitiesFieldData::EntData &>(e).getN();
257 MatrixDouble diff_base =
258 const_cast<EntitiesFieldData::EntData &>(e).getDiffN();
259 const double eps = 1e-6;
260 for (unsigned int ii = 0; ii != base.size1(); ii++) {
261 for (unsigned int jj = 0; jj != base.size2(); jj++) {
262 if (fabs(base(ii, jj)) < eps)
263 base(ii, jj) = 0;
264 }
265 }
266 for (unsigned int ii = 0; ii != diff_base.size1(); ii++) {
267 for (unsigned int jj = 0; jj != diff_base.size2(); jj++) {
268 if (fabs(diff_base(ii, jj)) < eps)
269 diff_base(ii, jj) = 0;
270 }
271 }
272 os << "N: " << std::fixed << base << std::endl
273 << "diffN: " << std::fixed << diff_base;
274 return os;
275}
276
277std::ostream &operator<<(std::ostream &os, const EntitiesFieldData &e) {
278 for (EntityType t = MBVERTEX; t != MBMAXTYPE; ++t) {
279 for (unsigned int nn = 0; nn < e.dataOnEntities[t].size(); nn++) {
280 os << "dataOnEntities[" << moab::CN::EntityTypeName(t) << "][" << nn
281 << "]" << std::endl
282 << e.dataOnEntities[t][nn] << std::endl;
283 }
284 }
285 return os;
286}
287
288/** \name Specializations for H1/L2 */
289
290/**@{*/
291
292template <>
294EntitiesFieldData::EntData::getFTensor1FieldData<3>() {
295#ifndef NDEBUG
296 for (auto &d : dOfs) {
297 if (d) {
298 if (d->getNbOfCoeffs() != 3) {
299 std::stringstream s;
300 s << "Wrong number of coefficients is " << d->getNbOfCoeffs();
301 s << " but you ask for tensor rank 1 dimension 3";
303 }
304 break;
305 }
306 }
307#endif
308 double *ptr = &*fieldData.data().begin();
310 &ptr[2]);
311}
312
313template <>
315EntitiesFieldData::EntData::getFTensor1FieldData<2>() {
316#ifndef NDEBUG
317 for (auto &d : dOfs) {
318 if (d) {
319 if (d->getNbOfCoeffs() != 2) {
320 std::stringstream s;
321 s << "Wrong number of coefficients is " << d->getNbOfCoeffs();
322 s << " but you ask for tensor rank 1 dimension 2";
324 }
325 break;
326 }
327 }
328#endif
329 double *ptr = &*fieldData.data().begin();
330 return FTensor::Tensor1<FTensor::PackPtr<double *, 2>, 2>(ptr, &ptr[1]);
331}
332
333template <>
335EntitiesFieldData::EntData::getFTensor1FieldData<1>() {
336#ifndef NDEBUG
337 for (auto &d : dOfs) {
338 if (d) {
339 if (d->getNbOfCoeffs() != 1) {
340 std::stringstream s;
341 s << "Wrong number of coefficients is " << d->getNbOfCoeffs();
342 s << " but you ask for tensor rank 1 dimension 1";
344 }
345 break;
346 }
347 }
348#endif
349 double *ptr = &*fieldData.data().begin();
351}
352
353template <>
355EntitiesFieldData::EntData::getFTensor2FieldData<1, 1>() {
356#ifndef NDEBUG
357 for (auto &d : dOfs) {
358 if (d) {
359 if (d->getNbOfCoeffs() != 1) {
360 std::stringstream s;
361 s << "Wrong number of coefficients is " << d->getNbOfCoeffs();
362 s << " but you ask for tensor rank 2 dimensions 1 by 1 so 1 "
363 "coefficients "
364 "is expected";
366 }
367 break;
368 }
369 }
370#endif
371 double *ptr = &*fieldData.data().begin();
373}
374
375template <>
377EntitiesFieldData::EntData::getFTensor2FieldData<1, 2>() {
378#ifndef NDEBUG
379 for (auto &d : dOfs) {
380 if (d) {
381 if (d->getNbOfCoeffs() != 2) {
382 std::stringstream s;
383 s << "Wrong number of coefficients is " << d->getNbOfCoeffs();
384 s << " but you ask for tensor rank 2 dimensions 1 by 2 so 2 "
385 "coefficients "
386 "is expected";
388 }
389 break;
390 }
391 }
392#endif
393 double *ptr = &*fieldData.data().begin();
394 return FTensor::Tensor2<FTensor::PackPtr<double *, 2>, 1, 2>(ptr, &ptr[1]);
395}
396
397template <>
399EntitiesFieldData::EntData::getFTensor2FieldData<1, 3>() {
400#ifndef NDEBUG
401 for (auto &d : dOfs) {
402 if (d) {
403 if (d->getNbOfCoeffs() != 3) {
404 std::stringstream s;
405 s << "Wrong number of coefficients is " << d->getNbOfCoeffs();
406 s << " but you ask for tensor rank 2 dimensions 1 by 3 so 3 "
407 "coefficients "
408 "is expected";
410 }
411 break;
412 }
413 }
414#endif
415 double *ptr = &*fieldData.data().begin();
416 return FTensor::Tensor2<FTensor::PackPtr<double *, 3>, 1, 3>(ptr, &ptr[1],
417 &ptr[2]);
418}
419
420template <>
422EntitiesFieldData::EntData::getFTensor2FieldData<2, 2>() {
423#ifndef NDEBUG
424 for(auto &d : dOfs) {
425 if(d) {
426 if(d->getNbOfCoeffs() != 4) {
427 std::stringstream s;
428 s << "Wrong number of coefficients is " << d->getNbOfCoeffs();
429 s << " but you ask for tensor rank 2 dimensions 2 by 2 so 4 coefficients "
430 "is expected";
432 }
433 break;
434 }
435 }
436#endif
437 double *ptr = &*fieldData.data().begin();
439 ptr, &ptr[1], &ptr[2], &ptr[3]);
440}
441
442template <>
444EntitiesFieldData::EntData::getFTensor2FieldData<3, 3>() {
445#ifndef NDEBUG
446 for (auto &d : dOfs) {
447 if (d) {
448 if (d->getNbOfCoeffs() != 9) {
449 std::stringstream s;
450 s << "Wrong number of coefficients is " << d->getNbOfCoeffs();
451 s << " but you ask for tensor rank 2 dimensions 3 by 3 so 9 "
452 "coefficients "
453 "is expected";
455 }
456 break;
457 }
458 }
459#endif
460 double *ptr = &*fieldData.data().begin();
462 ptr, &ptr[1], &ptr[2], &ptr[3], &ptr[4], &ptr[5], &ptr[6], &ptr[7],
463 &ptr[8]);
464}
465
466template <>
468EntitiesFieldData::EntData::getFTensor2SymmetricFieldData<3>() {
469#ifndef NDEBUG
470 for (auto &d : dOfs) {
471 if (d) {
472 if (d->getNbOfCoeffs() != 6) {
473 std::stringstream s;
474 s << "Wrong number of coefficients is " << d->getNbOfCoeffs();
475 s << " but you ask for symmetric tensor rank 2 dimensions 3 by 3 so 6 "
476 "coefficients "
477 "is expected";
479 }
480 break;
481 }
482 }
483#endif
484 double *ptr = &*fieldData.data().begin();
486 ptr, &ptr[1], &ptr[2], &ptr[3], &ptr[4], &ptr[5]);
487}
488
489template <>
491EntitiesFieldData::EntData::getFTensor2SymmetricFieldData<2>() {
492#ifndef NDEBUG
493 for (auto &d : dOfs) {
494 if (d) {
495 if (d->getNbOfCoeffs() != 3) {
496 std::stringstream s;
497 s << "Wrong number of coefficients is " << d->getNbOfCoeffs();
498 s << " but you ask for symmetric tensor rank 2 dimensions 2 by 2 so 3 "
499 "coefficients "
500 "is expected";
502 }
503 break;
504 }
505 }
506#endif
507 double *ptr = &*fieldData.data().begin();
509 ptr, &ptr[1], &ptr[2]);
510}
511
514#ifndef NDEBUG
515 for (auto &d : dOfs) {
516 if (d) {
517 if (d->getNbOfCoeffs() != 1) {
518 std::stringstream s;
519 s << "Wrong number of coefficients is " << d->getNbOfCoeffs();
520 s << " but expected scalar field, tensor of rank 0";
522 }
523 break;
524 }
525 }
526#endif
528 &*fieldData.data().begin());
529}
530
531template <int Tensor_Dim>
534 const FieldApproximationBase base) {
535 std::stringstream s;
536 s << "Template for tensor dimension " << Tensor_Dim << " not implemented";
537 THROW_MESSAGE(s.str());
539}
540
541template <int Tensor_Dim>
544 return getFTensor1DiffN<Tensor_Dim>(bAse);
545}
546
547/**
548 * \brief Get spatial derivative of base function tensor for dimension 3d
549 */
550template <>
552EntitiesFieldData::EntData::getFTensor1DiffN<3>(
553 const FieldApproximationBase base) {
554 double *ptr = &*getDiffN(base).data().begin();
556 &ptr[2]);
557}
558
559/**
560 * \brief Get spatial derivative of base function tensor for dimension 3d
561 */
562template <>
564EntitiesFieldData::EntData::getFTensor1DiffN<3>() {
565 return getFTensor1DiffN<3>(bAse);
566}
567
568/**
569 * \brief Get spatial derivative of base function tensor for dimension 2d
570 */
571template <>
573EntitiesFieldData::EntData::getFTensor1DiffN<2>(
574 const FieldApproximationBase base) {
575 double *ptr = &*getDiffN(base).data().begin();
576 return FTensor::Tensor1<FTensor::PackPtr<double *, 2>, 2>(ptr, &ptr[1]);
577}
578
579/**
580 * \brief Get spatial derivative of base function tensor for dimension 2d
581 */
582template <>
584EntitiesFieldData::EntData::getFTensor1DiffN<2>() {
585 return getFTensor1DiffN<2>(bAse);
586}
587
588template <int Tensor_Dim>
591 const int gg, const int bb) {
592 std::stringstream s;
593 s << "Template for tensor dimension " << Tensor_Dim << " not implemented";
594 THROW_MESSAGE(s.str());
596}
597
598/**
599 * \brief Get spatial derivative of base function tensor for dimension 3d
600 */
601template <>
603EntitiesFieldData::EntData::getFTensor1DiffN<3>(
604 const FieldApproximationBase base, const int gg, const int bb) {
605 double *ptr = &getDiffN(base)(gg, 3 * bb);
607 &ptr[2]);
608}
609
610/**
611 * \brief Get spatial derivative of base function tensor for dimension 3d
612 */
613template <>
615EntitiesFieldData::EntData::getFTensor1DiffN<3>(const int gg, const int bb) {
616 return getFTensor1DiffN<3>(bAse, gg, bb);
617}
618
619/**
620 * \brief Get spatial derivative of base function tensor for dimension 2d
621 */
622template <>
624EntitiesFieldData::EntData::getFTensor1DiffN<2>(
625 const FieldApproximationBase base, const int gg, const int bb) {
626 double *ptr = &getDiffN(base)(gg, 2 * bb);
627 return FTensor::Tensor1<FTensor::PackPtr<double *, 2>, 2>(ptr, &ptr[1]);
628}
629
630/**
631 * \brief Get spatial derivative of base function tensor for dimension 2d
632 */
633template <>
635EntitiesFieldData::EntData::getFTensor1DiffN<2>(const int gg, const int bb) {
636 return getFTensor1DiffN<2>(bAse, gg, bb);
637}
638
639/**@}*/
640
641/** \name Specializations for HDiv/HCrul */
642
643/**@{*/
644
645template <int Tensor_Dim>
648 std::stringstream s;
649 s << "Template for tensor dimension " << Tensor_Dim << " not implemented";
650 THROW_MESSAGE(s.str());
652}
653
654template <int Tensor_Dim>
657 const int gg, const int bb) {
658 std::stringstream s;
659 s << "Template for tensor dimension " << Tensor_Dim << " not implemented";
660 THROW_MESSAGE(s.str());
662}
663
664template <int Tensor_Dim0, int Tensor_Dim1>
666 Tensor_Dim0, Tensor_Dim1>
668 std::stringstream s;
669 s << "Template for tensor dimension " << Tensor_Dim0 << "x" << Tensor_Dim1
670 << " not implemented";
671 THROW_MESSAGE(s.str());
673}
674
675template <int Tensor_Dim0, int Tensor_Dim1>
677 Tensor_Dim0, Tensor_Dim1>
679 const int gg, const int bb) {
680 std::stringstream s;
681 s << "Template for tensor dimension " << Tensor_Dim0 << "x" << Tensor_Dim1
682 << " not implemented";
683 THROW_MESSAGE(s.str());
685}
686
687template <>
689EntitiesFieldData::EntData::getFTensor1N<3>(FieldApproximationBase base) {
690 double *t_n_ptr = &*getN(base).data().begin();
691 return FTensor::Tensor1<FTensor::PackPtr<double *, 3>, 3>(t_n_ptr, // HVEC0
692 &t_n_ptr[HVEC1],
693 &t_n_ptr[HVEC2]);
694}
695
696template <>
698EntitiesFieldData::EntData::getFTensor1N<3>(FieldApproximationBase base,
699 const int gg, const int bb) {
700 double *t_n_ptr = &getN(base)(gg, 3 * bb);
701 return FTensor::Tensor1<FTensor::PackPtr<double *, 3>, 3>(t_n_ptr, // HVEC0
702 &t_n_ptr[HVEC1],
703 &t_n_ptr[HVEC2]);
704}
705
706template <>
708EntitiesFieldData::EntData::getFTensor2DiffN<3, 3>(
710 double *t_diff_n_ptr = &*getDiffN(base).data().begin();
712 t_diff_n_ptr, &t_diff_n_ptr[HVEC0_1], &t_diff_n_ptr[HVEC0_2],
713 &t_diff_n_ptr[HVEC1_0], &t_diff_n_ptr[HVEC1_1], &t_diff_n_ptr[HVEC1_2],
714 &t_diff_n_ptr[HVEC2_0], &t_diff_n_ptr[HVEC2_1], &t_diff_n_ptr[HVEC2_2]);
715}
716
717template <>
719EntitiesFieldData::EntData::getFTensor2DiffN<3, 3>(FieldApproximationBase base,
720 const int gg, const int bb) {
721 double *t_diff_n_ptr = &getDiffN(base)(gg, 9 * bb);
723 t_diff_n_ptr, &t_diff_n_ptr[HVEC0_1], &t_diff_n_ptr[HVEC0_2],
724 &t_diff_n_ptr[HVEC1_0], &t_diff_n_ptr[HVEC1_1], &t_diff_n_ptr[HVEC1_2],
725 &t_diff_n_ptr[HVEC2_0], &t_diff_n_ptr[HVEC2_1], &t_diff_n_ptr[HVEC2_2]);
726}
727
728template <>
730EntitiesFieldData::EntData::getFTensor2DiffN<3, 2>(
732 double *t_diff_n_ptr = &*getDiffN(base).data().begin();
734 t_diff_n_ptr, &t_diff_n_ptr[HVEC0_1], &t_diff_n_ptr[HVEC1_0],
735 &t_diff_n_ptr[HVEC1_1], &t_diff_n_ptr[HVEC2_0], &t_diff_n_ptr[HVEC2_1]);
736}
737
738template <>
740EntitiesFieldData::EntData::getFTensor2DiffN<3, 2>(FieldApproximationBase base,
741 const int gg, const int bb) {
742 double *t_diff_n_ptr = &getDiffN(base)(gg, 6 * bb);
744 t_diff_n_ptr, &t_diff_n_ptr[HVEC0_1], &t_diff_n_ptr[HVEC1_0],
745 &t_diff_n_ptr[HVEC1_1], &t_diff_n_ptr[HVEC2_0], &t_diff_n_ptr[HVEC2_1]);
746}
747
748template <>
751 double *ptr = &(getN(base, BaseDerivatives::SecondDerivative))(0, 0);
753
754 &ptr[2 * HVEC0_0 + 0], &ptr[2 * HVEC0_0 + 1], &ptr[2 * HVEC0_1 + 0],
755 &ptr[2 * HVEC0_1 + 1],
756
757 &ptr[2 * HVEC1_0 + 0], &ptr[2 * HVEC1_0 + 1], &ptr[2 * HVEC1_1 + 0],
758 &ptr[2 * HVEC1_1 + 1],
759
760 &ptr[2 * HVEC2_0 + 0], &ptr[2 * HVEC2_0 + 1], &ptr[2 * HVEC2_1 + 0],
761 &ptr[2 * HVEC2_1 + 1]
762
763 };
764}
765
766template <>
768EntitiesFieldData::EntData::getFTensor2DiffN2<2>(FieldApproximationBase base) {
769 double *ptr = &(getN(base, BaseDerivatives::SecondDerivative))(0, 0);
771 ptr, &ptr[1], &ptr[2], &ptr[3]);
772}
773
774template <>
776EntitiesFieldData::EntData::getFTensor2DiffN2<2>(FieldApproximationBase base,
777 const int gg, const int bb) {
778 double *ptr = &getN(base, BaseDerivatives::SecondDerivative)(gg, 4 * bb);
780 ptr, &ptr[1], &ptr[2], &ptr[3]);
781}
782
783template <>
785EntitiesFieldData::EntData::getFTensor2DiffN2<2>() {
786 return getFTensor2DiffN2<2>(bAse);
787}
788
789template <>
791EntitiesFieldData::EntData::getFTensor2DiffN2<2>(const int gg, const int bb) {
792 return getFTensor2DiffN2<2>(bAse, gg, bb);
793}
794
795template <>
797EntitiesFieldData::EntData::getFTensor2DiffN2<3>(FieldApproximationBase base) {
798 double *ptr = &(getN(base, BaseDerivatives::SecondDerivative))(0, 0);
800 ptr, &ptr[1], &ptr[2], &ptr[3], &ptr[4], &ptr[5], &ptr[6], &ptr[7],
801 &ptr[8]);
802}
803
804template <>
806EntitiesFieldData::EntData::getFTensor2DiffN2<3>(FieldApproximationBase base,
807 const int gg, const int bb) {
808 double *ptr = &getN(base, BaseDerivatives::SecondDerivative)(gg, 9 * bb);
810 ptr, &ptr[1], &ptr[2], &ptr[3], &ptr[4], &ptr[5], &ptr[6], &ptr[7],
811 &ptr[8]);
812}
813
814template <>
816EntitiesFieldData::EntData::getFTensor2DiffN2<3>() {
817 return getFTensor2DiffN2<3>(bAse);
818}
819
820template <>
822EntitiesFieldData::EntData::getFTensor2DiffN2<3>(const int gg, const int bb) {
823 return getFTensor2DiffN2<3>(bAse, gg, bb);
824}
825
826template <int Tensor_Dim0, int Tensor_Dim1>
828 Tensor_Dim0, Tensor_Dim1>
830 std::stringstream s;
831 s << "Template for tensor dimension " << Tensor_Dim0 << ", " << Tensor_Dim1
832 << " not implemented";
833 THROW_MESSAGE(s.str());
835 Tensor_Dim0, Tensor_Dim1>();
836}
837
838template <>
840EntitiesFieldData::EntData::getFTensor2N<3, 3>(FieldApproximationBase base) {
841 double *t_n_ptr = &*(getN(base).data().begin());
843
844 &t_n_ptr[HVEC0], &t_n_ptr[HVEC1], &t_n_ptr[HVEC2],
845
846 &t_n_ptr[3 + HVEC0], &t_n_ptr[3 + HVEC1], &t_n_ptr[3 + HVEC2],
847
848 &t_n_ptr[6 + HVEC0], &t_n_ptr[6 + HVEC1], &t_n_ptr[6 + HVEC2]
849
850 );
851}
852
853template <int Tensor_Dim0, int Tensor_Dim1>
855 Tensor_Dim0, Tensor_Dim1>
857 const int gg, const int bb) {
858 std::stringstream s;
859 s << "Template for tensor dimension " << Tensor_Dim0 << ", " << Tensor_Dim1
860 << " not implemented";
861 THROW_MESSAGE(s.str());
863 Tensor_Dim0, Tensor_Dim1>();
864}
865
866template <>
868EntitiesFieldData::EntData::getFTensor2N<3, 3>(FieldApproximationBase base,
869 const int gg, const int bb) {
870 double *t_n_ptr = &getN(base)(gg, 9 * bb);
872
873 &t_n_ptr[HVEC0], &t_n_ptr[HVEC1], &t_n_ptr[HVEC2],
874
875 &t_n_ptr[3 + HVEC0], &t_n_ptr[3 + HVEC1], &t_n_ptr[3 + HVEC2],
876
877 &t_n_ptr[6 + HVEC0], &t_n_ptr[6 + HVEC1], &t_n_ptr[6 + HVEC2]
878
879 );
880}
881
882template <int Tensor_Dim0, int Tensor_Dim1, int Tensor_Dim2>
885 Tensor_Dim0, Tensor_Dim1, Tensor_Dim2>
887 std::stringstream s;
888 s << "Template for tensor dimension " << Tensor_Dim0 << "x" << Tensor_Dim1
889 << "x" << Tensor_Dim2 << " not implemented";
890 THROW_MESSAGE(s.str());
892}
893
894template <int Tensor_Dim0, int Tensor_Dim1, int Tensor_Dim2>
896 Tensor_Dim0, Tensor_Dim1, Tensor_Dim2>
898 const int gg, const int bb) {
899 std::stringstream s;
900 s << "Template for tensor dimension " << Tensor_Dim0 << "x" << Tensor_Dim1
901 << " not implemented";
902 THROW_MESSAGE(s.str());
904}
905
906template <>
909 double *ptr = &*getDiffN(base).data().begin();
910 return getFTensor3FromPtr<3, 3, 3>(ptr);
911};
912
913template <>
916 const int gg, const int bb) {
917 double *ptr = &getDiffN(base)(gg, 27 * bb);
918 return getFTensor3FromPtr<3, 3, 3>(ptr);
919};
920
921/**@}*/
922
923/** \name Bernstein-Bezier base only functions */
924
925/**@{*/
926
927boost::shared_ptr<MatrixInt> &
929 const std::string &field_name) {
930 return bbAlphaIndices[field_name];
931}
932
933boost::shared_ptr<MatrixDouble> &
935 return bbN[field_name];
936}
937
938/**
939 * Get shared pointer to BB base base functions
940 */
941const boost::shared_ptr<MatrixDouble> &
943 const std::string &field_name) const {
944 return bbN.at(field_name);
945}
946
947/**
948 * Get shared pointer to BB derivatives of base base functions
949 */
950boost::shared_ptr<MatrixDouble> &
952 return bbDiffN[field_name];
953}
954
955/**
956 * Get shared pointer to derivatives of BB base base functions
957 */
958const boost::shared_ptr<MatrixDouble> &
960 const std::string &field_name) const {
961 return bbDiffN.at(field_name);
962}
963
964std::map<std::string, boost::shared_ptr<MatrixInt>> &
966 return bbAlphaIndices;
967}
968
969std::map<std::string, boost::shared_ptr<MatrixDouble>> &
973
974std::map<std::string, boost::shared_ptr<MatrixDouble>> &
976 return bbDiffN;
977}
978
979boost::shared_ptr<MatrixInt> &
981 return bbAlphaIndicesByOrder[o];
982}
983
984boost::shared_ptr<MatrixDouble> &
986 return bbNByOrder[o];
987}
988
989boost::shared_ptr<MatrixDouble> &
991 return bbDiffNByOrder[o];
992}
993
994std::array<boost::shared_ptr<MatrixInt>,
997 return bbAlphaIndicesByOrder;
998}
999
1000std::array<boost::shared_ptr<MatrixDouble>,
1003 return bbNByOrder;
1004}
1005
1006std::array<boost::shared_ptr<MatrixDouble>,
1009 return bbDiffNByOrder;
1010}
1011
1012boost::shared_ptr<MatrixInt> &
1014 const std::string &field_name) {
1015 return entDataPtr->getBBAlphaIndicesSharedPtr(field_name);
1016}
1017
1018boost::shared_ptr<MatrixDouble> &
1020 const std::string &field_name) {
1021 return entDataPtr->getBBNSharedPtr(field_name);
1022}
1023
1024const boost::shared_ptr<MatrixDouble> &
1026 const std::string &field_name) const {
1027 return entDataPtr->getBBNSharedPtr(field_name);
1028}
1029
1030/**
1031 * Get shared pointer to BB derivatives of base base functions
1032 */
1033boost::shared_ptr<MatrixDouble> &
1035 const std::string &field_name) {
1036 return entDataPtr->getBBDiffNSharedPtr(field_name);
1037}
1038
1039/**
1040 * Get shared pointer to derivatives of BB base base functions
1041 */
1042const boost::shared_ptr<MatrixDouble> &
1044 const std::string &field_name) const {
1045 return entDataPtr->getBBDiffNSharedPtr(field_name);
1046}
1047
1048/**@}*/
1049
1051 return entDataBitRefLevel;
1052}
1053
1054std::vector<BitRefLevel> &
1056 return entDataPtr->getEntDataBitRefLevel();
1057}
1058
1059
1060
1061
1062} // namespace MoFEM
static const double eps
T data[Tensor_Dim]
T data[Tensor_Dim0][Tensor_Dim1]
FieldApproximationBase
approximation base
Definition definitions.h:58
@ LASTBASE
Definition definitions.h:69
@ NOBASE
Definition definitions.h:59
#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()
@ NOSPACE
Definition definitions.h:83
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
@ HVEC0
@ HVEC1
@ HVEC2
@ MOFEM_DATA_INCONSISTENCY
Definition definitions.h:31
#define MoFEMFunctionReturn(a)
Last executable line of each PETSc function used for error handling. Replaces return()
@ HVEC1_1
@ HVEC0_1
@ HVEC1_0
@ HVEC2_1
@ HVEC1_2
@ HVEC2_2
@ HVEC2_0
@ HVEC0_2
@ HVEC0_0
#define CHKERR
Inline error check.
#define MoFEMFunctionBeginHot
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
#define THROW_MESSAGE(msg)
Throw MoFEM exception.
const double c
speed of light (cm/ns)
PetscErrorCode MoFEMErrorCode
MoFEM/PETSc error code.
UBlasMatrix< double > MatrixDouble
Definition Types.hpp:77
implementation of Data Operators for Forces and Sources
Definition Common.hpp:10
static void constructor_derived_data(DerivedEntitiesFieldData *derived_data, const boost::shared_ptr< EntitiesFieldData > &data_ptr)
static void constructor_data(EntitiesFieldData *data, const EntityType type)
FTensor::Tensor3< FTensor::PackPtr< double *, 27 >, 3, 3, 3 > getFTensor3FromPtr< 3, 3, 3 >(double *ptr)
constexpr double t
plate stiffness
Definition plate.cpp:58
constexpr auto field_name
const int N
Definition speed_test.cpp:3
Derived data on single entity (This is passed as argument to DataOperator::doWork)
boost::shared_ptr< MatrixDouble > & getBBNSharedPtr(const std::string &field_name)
MoFEMErrorCode baseSwap(const std::string &field_name, const FieldApproximationBase base)
Used by Bernstein base to keep temporary pointer.
std::vector< BitRefLevel > & getEntDataBitRefLevel()
Get entity bit reference level.
int getSense() const
Get entity sense for conforming approximation fields.
boost::shared_ptr< MatrixInt > & getBBAlphaIndicesSharedPtr(const std::string &field_name)
boost::shared_ptr< MatrixDouble > & getBBDiffNSharedPtr(const std::string &field_name)
boost::shared_ptr< MatrixDouble > & getDiffNSharedPtr(const FieldApproximationBase base)
Get shared pointer to derivatives of base functions.
DerivedEntData(const boost::shared_ptr< EntitiesFieldData::EntData > &ent_data_ptr)
boost::shared_ptr< MatrixDouble > & getNSharedPtr(const FieldApproximationBase base, const BaseDerivatives derivative)
Get shared pointer to base functions with derivatives.
this class derives data from other data structure
MoFEMErrorCode setElementType(const EntityType type)
Set element type for derived data.
const boost::shared_ptr< EntitiesFieldData > dataPtr
DerivedEntitiesFieldData(const boost::shared_ptr< EntitiesFieldData > &data_ptr)
Construct DerivedEntitiesFieldData from existing EntitiesFieldData.
Data on single entity (This is passed as argument to DataOperator::doWork)
virtual std::array< boost::shared_ptr< MatrixDouble >, MaxBernsteinBezierOrder > & getBBDiffNByOrderArray()
virtual std::array< boost::shared_ptr< MatrixDouble >, MaxBernsteinBezierOrder > & getBBNByOrderArray()
auto getFTensor2N()
Get base functions for Hdiv space.
VectorDouble fieldData
Field data on entity.
ApproximationOrder getOrder() const
Get approximation order.
VectorInt localIndices
Local indices on entity.
virtual std::array< boost::shared_ptr< MatrixInt >, MaxBernsteinBezierOrder > & getBBAlphaIndicesByOrderArray()
virtual std::map< std::string, boost::shared_ptr< MatrixInt > > & getBBAlphaIndicesMap()
FTensor::Tensor1< FTensor::PackPtr< double *, Tensor_Dim >, Tensor_Dim > getFTensor1DiffN()
Get derivatives of base functions.
static constexpr size_t MaxBernsteinBezierOrder
VectorInt iNdices
Global indices on entity.
virtual boost::shared_ptr< MatrixDouble > & getNSharedPtr(const FieldApproximationBase base, const BaseDerivatives derivative)
Get shared pointer to base functions with derivatives.
virtual boost::shared_ptr< MatrixInt > & getBBAlphaIndicesSharedPtr(const std::string &field_name)
const VectorDouble & getFieldData() const
Get DOF values on entity.
virtual boost::shared_ptr< MatrixDouble > & getBBDiffNByOrderSharedPtr(const size_t o)
get BB base derivative by order
virtual std::map< std::string, boost::shared_ptr< MatrixDouble > > & getBBNMap()
get hash map of base function for BB base, key is a field name
virtual MoFEMErrorCode baseSwap(const std::string &field_name, const FieldApproximationBase base)
Swap bases functions.
const VectorInt & getLocalIndices() const
Get local indices of degrees of freedom on entity.
FTensor::Tensor3< FTensor::PackPtr< double *, Tensor_Dim0 *Tensor_Dim1 *Tensor_Dim2 >, Tensor_Dim0, Tensor_Dim1, Tensor_Dim2 > getFTensor3DiffN()
Get derivatives of base functions for tonsorial Hdiv space.
virtual std::map< std::string, boost::shared_ptr< MatrixDouble > > & getBBDiffNMap()
get hash map of derivatives base function for BB base, key is a field name
virtual std::vector< BitRefLevel > & getEntDataBitRefLevel()
Get entity bit reference level.
virtual int getSense() const
Get entity sense for conforming approximation fields.
VectorFieldEntities fieldEntities
Field entities.
FTensor::Tensor0< FTensor::PackPtr< double *, 1 > > getFTensor0FieldData()
Return scalar files as a FTensor of rank 0.
virtual boost::shared_ptr< MatrixInt > & getBBAlphaIndicesByOrderSharedPtr(const size_t o)
get ALpha indices for BB base by order
FTensor::Tensor3< FTensor::PackPtr< double *, Tensor_Dim0 *Tensor_Dim1 *Tensor_Dim2 >, Tensor_Dim0, Tensor_Dim1, Tensor_Dim2 > getFTensor3Diff2N()
Get second derivatives of base functions for Hvec space.
auto getFTensor1N()
Get base functions for Hdiv space.
virtual boost::shared_ptr< MatrixDouble > & getBBNSharedPtr(const std::string &field_name)
std::array< std::array< boost::shared_ptr< MatrixDouble >, LASTBASE >, LastDerivative > baseFunctionsAndBaseDerivatives
FTensor::Tensor2< FTensor::PackPtr< double *, Tensor_Dim0 *Tensor_Dim1 >, Tensor_Dim0, Tensor_Dim1 > getFTensor2DiffN()
Get derivatives of base functions for Hdiv space.
virtual boost::shared_ptr< MatrixDouble > & getDiffNSharedPtr(const FieldApproximationBase base)
Get shared pointer to derivatives of base functions.
virtual boost::shared_ptr< MatrixDouble > & getBBNByOrderSharedPtr(const size_t o)
get BB base by order
const VectorInt & getIndices() const
Get global indices of degrees of freedom on entity.
EntData(const bool allocate_base_matrices=true)
Construct EntData object.
FieldApproximationBase bAse
Field approximation base.
virtual boost::shared_ptr< MatrixDouble > & getBBDiffNSharedPtr(const std::string &field_name)
data structure for finite element entity
friend std::ostream & operator<<(std::ostream &os, const EntitiesFieldData &e)
MoFEMErrorCode resetFieldDependentData()
Reset data associated with particular field name.
std::bitset< LASTBASE > bAse
bases on element
std::array< boost::ptr_vector< EntData >, MBMAXTYPE > dataOnEntities
virtual MoFEMErrorCode baseSwap(const std::string &field_name, const FieldApproximationBase base)
Swap approximation base.
virtual MoFEMErrorCode setElementType(const EntityType type)
Set element type and initialize data structures.