10 #ifndef __ENTITIES_FIELD_DATA_HPP__
11 #define __ENTITIES_FIELD_DATA_HPP__
13 using namespace boost::numeric;
19 FEDofEntity *, std::allocator<FEDofEntity *>
23 using VectorDofs = ublas::vector<FEDofEntity *, DofsAllocator>;
44 std::bitset<LASTBASE>
bAse;
48 std::array<std::bitset<LASTSPACE>, MBMAXTYPE>
50 std::array<std::bitset<LASTBASE>, MBMAXTYPE>
52 std::array<std::bitset<LASTBASE>,
LASTSPACE>
54 std::array<std::bitset<LASTBASE>,
LASTSPACE>
56 std::array<boost::ptr_vector<EntData>, MBMAXTYPE>
115 const boost::shared_ptr<EntitiesFieldData> &data_ptr);
119 const boost::shared_ptr<EntitiesFieldData>
dataPtr;
143 EntData(
const bool allocate_base_matrices =
true);
154 virtual int getSense()
const;
160 inline const VectorInt &getIndices()
const;
166 inline const VectorInt &getLocalIndices()
const;
171 inline int &getSense();
192 inline const VectorDofs &getFieldDofs()
const;
204 virtual std::vector<BitRefLevel> &getEntDataBitRefLevel();
217 template <
int Tensor_Dim>
219 getFTensor1FieldData();
233 template <
int Tensor_Dim0,
int Tensor_Dim1>
235 Tensor_Dim0, Tensor_Dim1>
236 getFTensor2FieldData();
250 template <
int Tensor_Dim>
254 getFTensor2SymmetricFieldData();
286 virtual boost::shared_ptr<MatrixDouble> &
293 virtual boost::shared_ptr<MatrixDouble> &
299 virtual boost::shared_ptr<MatrixDouble> &
426 const int gg,
const int nb_base_functions);
439 inline const VectorAdaptor getN(
const int gg,
const int nb_base_functions);
455 const int nb_base_functions);
469 const int nb_base_functions);
494 template <
int DIM>
inline const MatrixAdaptor getVectorN(
const int gg);
503 template <
int DIM0,
int DIM1>
513 template <
int DIM0,
int DIM1>
523 template <
int DIM0,
int DIM1>
525 const int dof,
const int gg);
533 template <
int DIM0,
int DIM1>
534 inline const MatrixAdaptor getVectorDiffN(
const int dof,
const int gg);
593 getFTensor0N(
const int gg,
const int bb);
612 template <
int Tensor_Dim>
632 template <
int Tensor_Dim>
654 template <
int Tensor_Dim>
677 template <
int Tensor_Dim>
679 getFTensor1DiffN(
const int gg,
const int bb);
706 template <
int Tensor_Dim>
730 template <
int Tensor_Dim>
auto getFTensor1N();
734 template <
int Tensor_Dim0,
int Tensor_Dim1>
736 Tensor_Dim0, Tensor_Dim1>
742 template <
int Tensor_Dim0,
int Tensor_Dim1>
744 Tensor_Dim0, Tensor_Dim1>
749 template <
int Tensor_Dim0,
int Tensor_Dim1>
751 Tensor_Dim0, Tensor_Dim1>
753 return getFTensor2DiffN<Tensor_Dim0, Tensor_Dim1>(bAse);
759 template <
int Tensor_Dim0,
int Tensor_Dim1>
761 Tensor_Dim0, Tensor_Dim1>
763 return getFTensor2DiffN<Tensor_Dim0, Tensor_Dim1>(bAse, gg, bb);
768 template <
int Tensor_Dim0,
int Tensor_Dim1,
int Tensor_Dim2>
771 Tensor_Dim0, Tensor_Dim1, Tensor_Dim2>
776 template <
int Tensor_Dim0,
int Tensor_Dim1,
int Tensor_Dim2>
779 Tensor_Dim0, Tensor_Dim1, Tensor_Dim2>
781 return getFTensor3Diff2N<Tensor_Dim0, Tensor_Dim1, Tensor_Dim2>(bAse);
798 template <
int Tensor_Dim>
816 template <
int Tensor_Dim>
817 inline auto getFTensor1N(
const int gg,
const int bb);
845 template <
int Tensor_Dim0,
int Tensor_Dim1>
847 Tensor_Dim0, Tensor_Dim1>
872 template <
int Tensor_Dim0,
int Tensor_Dim1>
auto getFTensor2N();
900 template <
int Tensor_Dim0,
int Tensor_Dim1>
902 Tensor_Dim0, Tensor_Dim1>
926 template <
int Tensor_Dim0,
int Tensor_Dim1>
927 auto getFTensor2N(
const int gg,
const int bb);
935 friend std::ostream &
operator<<(std::ostream &os,
964 virtual boost::shared_ptr<MatrixInt> &
965 getBBAlphaIndicesSharedPtr(
const std::string &
field_name);
970 virtual boost::shared_ptr<MatrixDouble> &
971 getBBNSharedPtr(
const std::string &
field_name);
976 virtual const boost::shared_ptr<MatrixDouble> &
977 getBBNSharedPtr(
const std::string &
field_name)
const;
982 virtual boost::shared_ptr<MatrixDouble> &
983 getBBDiffNSharedPtr(
const std::string &
field_name);
988 virtual const boost::shared_ptr<MatrixDouble> &
989 getBBDiffNSharedPtr(
const std::string &
field_name)
const;
991 virtual std::map<std::string, boost::shared_ptr<MatrixInt>> &
992 getBBAlphaIndicesMap();
999 virtual std::map<std::string, boost::shared_ptr<MatrixDouble>> &getBBNMap();
1007 virtual std::map<std::string, boost::shared_ptr<MatrixDouble>> &
1016 virtual boost::shared_ptr<MatrixInt> &
1017 getBBAlphaIndicesByOrderSharedPtr(
const size_t o);
1025 virtual boost::shared_ptr<MatrixDouble> &
1026 getBBNByOrderSharedPtr(
const size_t o);
1034 virtual boost::shared_ptr<MatrixDouble> &
1035 getBBDiffNByOrderSharedPtr(
const size_t o);
1039 virtual std::array<boost::shared_ptr<MatrixInt>, MaxBernsteinBezierOrder> &
1040 getBBAlphaIndicesByOrderArray();
1042 virtual std::array<boost::shared_ptr<MatrixDouble>, MaxBernsteinBezierOrder> &
1043 getBBNByOrderArray();
1045 virtual std::array<boost::shared_ptr<MatrixDouble>, MaxBernsteinBezierOrder> &
1046 getBBDiffNByOrderArray();
1081 std::vector<EntityType>
1084 std::array<std::array<boost::shared_ptr<MatrixDouble>,
LASTBASE>,
1089 std::array<boost::shared_ptr<MatrixDouble>,
LASTBASE>
1094 std::map<std::string, boost::shared_ptr<MatrixDouble>>
bbN;
1095 std::map<std::string, boost::shared_ptr<MatrixDouble>>
bbDiffN;
1096 std::map<std::string, boost::shared_ptr<MatrixInt>>
1099 std::array<boost::shared_ptr<MatrixDouble>, MaxBernsteinBezierOrder>
1101 std::array<boost::shared_ptr<MatrixDouble>, MaxBernsteinBezierOrder>
1103 std::array<boost::shared_ptr<MatrixInt>, MaxBernsteinBezierOrder>
1140 const boost::shared_ptr<EntitiesFieldData::EntData> &ent_data_ptr);
1142 int getSense()
const;
1145 std::vector<BitRefLevel> &getEntDataBitRefLevel();
1147 boost::shared_ptr<MatrixDouble> &
1151 boost::shared_ptr<MatrixDouble> &
1154 boost::shared_ptr<MatrixDouble> &
1157 const boost::shared_ptr<MatrixDouble> &
1160 const boost::shared_ptr<MatrixDouble> &
1163 inline boost::shared_ptr<MatrixDouble> &
1166 inline boost::shared_ptr<MatrixDouble> &
1169 boost::shared_ptr<MatrixInt> &
1170 getBBAlphaIndicesSharedPtr(
const std::string &
field_name);
1175 boost::shared_ptr<MatrixDouble> &
1176 getBBNSharedPtr(
const std::string &
field_name);
1181 const boost::shared_ptr<MatrixDouble> &
1182 getBBNSharedPtr(
const std::string &
field_name)
const;
1187 boost::shared_ptr<MatrixDouble> &
1188 getBBDiffNSharedPtr(
const std::string &
field_name);
1193 const boost::shared_ptr<MatrixDouble> &
1194 getBBDiffNSharedPtr(
const std::string &
field_name)
const;
1214 const VectorInt &EntitiesFieldData::EntData::getIndices()
const {
1219 EntitiesFieldData::EntData::getIndicesUpToOrder(
int order) {
1220 unsigned int size = 0;
1221 if (
auto dof = dOfs[0]) {
1222 size = dof->getOrderNbDofs(
order) * dof->getNbOfCoeffs();
1223 size = size < iNdices.size() ? size : iNdices.size();
1225 int *data = &*iNdices.data().begin();
1226 return VectorIntAdaptor(size, ublas::shallow_array_adaptor<int>(size, data));
1229 const VectorInt &EntitiesFieldData::EntData::getLocalIndices()
const {
1230 return localIndices;
1234 EntitiesFieldData::EntData::getLocalIndicesUpToOrder(
int order) {
1235 unsigned int size = 0;
1236 if (
auto dof = dOfs[0]) {
1237 size = dof->getOrderNbDofs(
order) * dof->getNbOfCoeffs();
1238 size = size < localIndices.size() ? size : localIndices.size();
1240 int *data = &*localIndices.data().begin();
1241 return VectorIntAdaptor(size, ublas::shallow_array_adaptor<int>(size, data));
1244 int &EntitiesFieldData::EntData::getSense() {
return sEnse; }
1248 VectorInt &EntitiesFieldData::EntData::getIndices() {
return iNdices; }
1250 VectorInt &EntitiesFieldData::EntData::getLocalIndices() {
1251 return localIndices;
1259 EntitiesFieldData::EntData::getFieldDataUpToOrder(
int order) {
1260 unsigned int size = 0;
1261 if (
auto dof = dOfs[0]) {
1262 size = dof->getOrderNbDofs(
order) * dof->getNbOfCoeffs();
1263 size = size < fieldData.size() ? size : fieldData.size();
1265 double *data = &*fieldData.data().begin();
1269 const VectorDofs &EntitiesFieldData::EntData::getFieldDofs()
const {
1273 VectorDofs &EntitiesFieldData::EntData::getFieldDofs() {
return dOfs; }
1275 VectorDouble &EntitiesFieldData::EntData::getFieldData() {
return fieldData; }
1278 return fieldEntities;
1282 EntitiesFieldData::EntData::getFieldEntities()
const {
1283 return fieldEntities;
1286 template <
int Tensor_Dim>
1288 EntitiesFieldData::EntData::getFTensor1FieldData() {
1289 std::stringstream s;
1290 s <<
"Not implemented for this dimension dim = " << Tensor_Dim;
1294 template <
int Tensor_Dim0,
int Tensor_Dim1>
1296 Tensor_Dim0, Tensor_Dim1>
1297 EntitiesFieldData::EntData::getFTensor2FieldData() {
1298 std::stringstream s;
1299 s <<
"Not implemented for this dimension dim0 = " << Tensor_Dim0;
1300 s <<
" and dim1 " << Tensor_Dim1;
1304 template <
int Tensor_Dim>
1306 FTensor::PackPtr<
double *, (Tensor_Dim * (Tensor_Dim + 1)) / 2>, Tensor_Dim>
1307 EntitiesFieldData::EntData::getFTensor2SymmetricFieldData() {
1308 std::stringstream s;
1309 s <<
"Not implemented for this dimension dim = " << Tensor_Dim;
1315 FieldSpace &EntitiesFieldData::EntData::getSpace() {
return sPace; }
1319 return *(getNSharedPtr(base));
1330 return *(getDiffNSharedPtr(base));
1337 if (!getNSharedPtr(base, derivative)) {
1339 "Ptr to base %s functions derivative %d is null",
1344 return *(getNSharedPtr(base, derivative));
1348 EntitiesFieldData::EntData::getDiffN(
const std::string &
field_name) {
1352 MatrixDouble &EntitiesFieldData::EntData::getDiffN() {
return getDiffN(bAse); }
1356 return getN(bAse, derivative);
1362 int size = getN(base).size2();
1363 double *data = &getN(base)(gg, 0);
1364 return VectorAdaptor(size, ublas::shallow_array_adaptor<double>(size, data));
1368 return getN(bAse, gg);
1377 if (getN(base).size1() == getDiffN(base).size1()) {
1378 int size = getN(base).size2();
1379 int dim = getDiffN(base).size2() / size;
1380 double *data = &getDiffN(base)(gg, 0);
1382 getN(base).size2(), dim,
1383 ublas::shallow_array_adaptor<double>(getDiffN(base).size2(), data));
1388 getN(base).size1(), getN(base).size2(),
1389 ublas::shallow_array_adaptor<double>(getDiffN(base).data().size(),
1390 &getDiffN(base).data()[0]));
1395 return getDiffN(bAse, gg);
1400 const int gg,
const int nb_base_functions) {
1401 (void)getN()(gg, nb_base_functions -
1403 double *data = &getN(base)(gg, 0);
1404 return VectorAdaptor(nb_base_functions, ublas::shallow_array_adaptor<double>(
1405 nb_base_functions, data));
1409 EntitiesFieldData::EntData::getN(
const int gg,
const int nb_base_functions) {
1410 return getN(bAse, gg, nb_base_functions);
1416 const int nb_base_functions) {
1420 if (getN(base).size1() == getDiffN(base).size1()) {
1421 (void)getN(base)(gg,
1424 int dim = getDiffN(base).size2() / getN(base).size2();
1425 double *data = &getDiffN(base)(gg, 0);
1427 nb_base_functions, dim,
1428 ublas::shallow_array_adaptor<double>(dim * nb_base_functions, data));
1433 getN(base).size1(), getN(base).size2(),
1434 ublas::shallow_array_adaptor<double>(getDiffN(base).data().size(),
1435 &getDiffN(base).data()[0]));
1440 EntitiesFieldData::EntData::getDiffN(
const int gg,
1441 const int nb_base_functions) {
1442 return getDiffN(bAse, gg, nb_base_functions);
1449 if (PetscUnlikely(getN(base).size2() % DIM)) {
1453 const int nb_base_functions = getN(base).size2() / DIM;
1454 double *data = &getN(base)(gg, 0);
1456 nb_base_functions, DIM,
1457 ublas::shallow_array_adaptor<double>(DIM * nb_base_functions, data));
1462 return getVectorN<DIM>(bAse, gg);
1465 template <
int DIM0,
int DIM1>
1469 if (PetscUnlikely(getDiffN(base).size2() % (DIM0 *
DIM1))) {
1473 const int nb_base_functions = getN(base).size2() / (DIM0 *
DIM1);
1474 double *data = &getN(base)(gg, 0);
1476 ublas::shallow_array_adaptor<double>(
1477 DIM0 *
DIM1 * nb_base_functions, data));
1480 template <
int DIM0,
int DIM1>
1482 return getVectorDiffN<DIM0, DIM1>(bAse, gg);
1485 template <
int DIM0,
int DIM1>
1488 const int dof,
const int gg) {
1490 &EntitiesFieldData::EntData::getDiffN(base)(gg, DIM0 *
DIM1 * dof);
1492 ublas::shallow_array_adaptor<double>(DIM0 *
DIM1, data));
1495 template <
int DIM0,
int DIM1>
1498 return getVectorDiffN<DIM0, DIM1>(bAse, dof, gg);
1503 double *ptr = &*getN(base).data().begin();
1508 EntitiesFieldData::EntData::getFTensor0N() {
1509 return getFTensor0N(bAse);
1514 const int gg,
const int bb) {
1515 double *ptr = &getN(base)(gg, bb);
1520 EntitiesFieldData::EntData::getFTensor0N(
const int gg,
const int bb) {
1521 return getFTensor0N(bAse, gg, bb);
1524 template <
int Tensor_Dim>
auto EntitiesFieldData::EntData::getFTensor1N() {
1525 return getFTensor1N<Tensor_Dim>(bAse);
1528 template <
int Tensor_Dim>
1529 auto EntitiesFieldData::EntData::getFTensor1N(
const int gg,
const int bb) {
1530 return getFTensor1N<Tensor_Dim>(bAse, gg, bb);
1533 template <
int Tensor_Dim0,
int Tensor_Dim1>
1534 auto EntitiesFieldData::EntData::getFTensor2N() {
1535 return getFTensor2N<Tensor_Dim0, Tensor_Dim1>(bAse);
1538 template <
int Tensor_Dim0,
int Tensor_Dim1>
1539 auto EntitiesFieldData::EntData::getFTensor2N(
const int gg,
const int bb) {
1540 return getFTensor2N<Tensor_Dim0, Tensor_Dim1>(bAse, gg, bb);
1547 VectorInt &EntitiesFieldData::EntData::getBBNodeOrder() {
return bbNodeOrder; }
1549 MatrixInt &EntitiesFieldData::EntData::getBBAlphaIndices() {
1550 return *getBBAlphaIndicesSharedPtr(bbFieldName);
1559 boost::shared_ptr<MatrixDouble> &
1560 DerivedEntitiesFieldData::DerivedEntData::getDerivedNSharedPtr(
1565 boost::shared_ptr<MatrixDouble> &
1566 DerivedEntitiesFieldData::DerivedEntData::getDerivedDiffNSharedPtr(
1588 template <
typename T = EntityStorage>
1591 const double *ptr, InsertMode iora) {
1592 static_assert(!std::is_same<T, T>::value,
1593 "VecSetValues value for this data storage is not implemented");
1600 const double *ptr, InsertMode iora) {
1620 template <
typename T = EntityStorage>
1624 return VecSetValues<T>(V, data, &*vec.data().begin(), iora);
1643 template <
typename T = EntityStorage>
1647 const double *ptr, InsertMode iora) {
1648 static_assert(!std::is_same<T, T>::value,
1649 "MatSetValues value for this data storage is not implemented");
1669 template <
typename T = EntityStorage>
1674 return MatSetValues<T>(
M, row_data, col_data, &*mat.data().begin(), iora);
1681 const double *ptr, InsertMode iora) {
1698 const int gg,
const int bb);
1712 EntitiesFieldData::EntData::getFTensor1DiffN<3>(
1716 EntitiesFieldData::EntData::getFTensor1DiffN<3>();
1720 EntitiesFieldData::EntData::getFTensor1DiffN<2>(
1724 EntitiesFieldData::EntData::getFTensor1DiffN<2>();
1732 const int gg,
const int bb);
1746 EntitiesFieldData::EntData::getFTensor1FieldData<3>();
1750 EntitiesFieldData::EntData::getFTensor1FieldData<2>();
1754 EntitiesFieldData::EntData::getFTensor1FieldData<1>();
1758 EntitiesFieldData::EntData::getFTensor2FieldData<1, 1>();
1762 EntitiesFieldData::EntData::getFTensor2FieldData<1, 2>();
1766 EntitiesFieldData::EntData::getFTensor2FieldData<1, 3>();
1770 EntitiesFieldData::EntData::getFTensor2FieldData<2, 2>();
1774 EntitiesFieldData::EntData::getFTensor2FieldData<3, 3>();
1778 EntitiesFieldData::EntData::getFTensor2SymmetricFieldData<3>();
1782 EntitiesFieldData::EntData::getFTensor2SymmetricFieldData<2>();
1798 #endif //__ENTITIES_FIELD_DATA_HPP__