14#ifndef dealii_mesh_worker_simple_h
15#define dealii_mesh_worker_simple_h
55 template <
typename VectorType>
82 template <
class DOFINFO>
84 initialize_info(DOFINFO &info,
bool face)
const;
92 template <
class DOFINFO>
94 assemble(
const DOFINFO &info);
99 template <
class DOFINFO>
101 assemble(
const DOFINFO &info1,
const DOFINFO &info2);
148 template <
typename MatrixType>
162 initialize(MatrixType &m);
168 initialize(std::vector<MatrixType> &m);
188 template <
class DOFINFO>
190 initialize_info(DOFINFO &info,
bool face)
const;
196 template <
class DOFINFO>
198 assemble(
const DOFINFO &info);
204 template <
class DOFINFO>
206 assemble(
const DOFINFO &info1,
const DOFINFO &info2);
212 std::vector<ObserverPointer<MatrixType, MatrixSimple<MatrixType>>>
matrix;
228 const unsigned int index,
229 const std::vector<types::global_dof_index> &i1,
230 const std::vector<types::global_dof_index> &i2);
250 template <
typename MatrixType>
294 template <
class DOFINFO>
296 initialize_info(DOFINFO &info,
bool face)
const;
301 template <
class DOFINFO>
303 assemble(
const DOFINFO &info);
309 template <
class DOFINFO>
311 assemble(
const DOFINFO &info1,
const DOFINFO &info2);
318 assemble(MatrixType &G,
320 const std::vector<types::global_dof_index> &i1,
321 const std::vector<types::global_dof_index> &i2);
327 assemble(MatrixType &G,
329 const std::vector<types::global_dof_index> &i1,
330 const std::vector<types::global_dof_index> &i2,
331 const unsigned int level);
338 assemble_up(MatrixType &G,
340 const std::vector<types::global_dof_index> &i1,
341 const std::vector<types::global_dof_index> &i2,
348 assemble_down(MatrixType &G,
350 const std::vector<types::global_dof_index> &i1,
351 const std::vector<types::global_dof_index> &i2,
359 assemble_in(MatrixType &G,
361 const std::vector<types::global_dof_index> &i1,
362 const std::vector<types::global_dof_index> &i2,
370 assemble_out(MatrixType &G,
372 const std::vector<types::global_dof_index> &i1,
373 const std::vector<types::global_dof_index> &i2,
433 template <
typename MatrixType,
typename VectorType>
447 initialize(MatrixType &m, VectorType &rhs);
467 template <
class DOFINFO>
469 initialize_info(DOFINFO &info,
bool face)
const;
474 template <
class DOFINFO>
476 assemble(
const DOFINFO &info);
482 template <
class DOFINFO>
484 assemble(
const DOFINFO &info1,
const DOFINFO &info2);
494 const unsigned int index,
495 const std::vector<types::global_dof_index> &indices);
500 const unsigned int index,
501 const std::vector<types::global_dof_index> &i1,
502 const std::vector<types::global_dof_index> &i2);
508 template <
typename VectorType>
517 template <
typename VectorType>
527 template <
typename VectorType>
528 template <
class DOFINFO>
532 info.initialize_vectors(residuals.size());
537 template <
typename VectorType>
538 template <
class DOFINFO>
542 for (
unsigned int k = 0; k < residuals.size(); ++k)
544 VectorType *v = residuals.entry<VectorType *>(k);
545 for (
unsigned int i = 0; i != info.vector(k).n_blocks(); ++i)
547 const std::vector<types::global_dof_index> &ldi =
548 info.vector(k).n_blocks() == 1 ? info.indices :
549 info.indices_by_block[i];
551 if (constraints !=
nullptr)
552 constraints->distribute_local_to_global(info.vector(k).block(i),
556 v->add(ldi, info.vector(k).block(i));
561 template <
typename VectorType>
562 template <
class DOFINFO>
565 const DOFINFO &info2)
574 template <
typename MatrixType>
576 : threshold(threshold)
580 template <
typename MatrixType>
589 template <
typename MatrixType>
593 matrix.resize(m.size());
594 for (
unsigned int i = 0; i < m.size(); ++i)
599 template <
typename MatrixType>
608 template <
typename MatrixType>
609 template <
class DOFINFO>
615 const unsigned int n = info.indices_by_block.size();
618 info.initialize_matrices(matrix.size(), face);
621 info.initialize_matrices(matrix.size() * n * n, face);
623 for (
unsigned int m = 0; m < matrix.size(); ++m)
624 for (
unsigned int i = 0; i < n; ++i)
625 for (
unsigned int j = 0; j < n; ++j, ++k)
627 info.matrix(k,
false).row = i;
628 info.matrix(k,
false).column = j;
631 info.matrix(k,
true).row = i;
632 info.matrix(k,
true).column = j;
640 template <
typename MatrixType>
644 const unsigned int index,
645 const std::vector<types::global_dof_index> &i1,
646 const std::vector<types::global_dof_index> &i2)
651 if (constraints ==
nullptr)
653 for (
unsigned int j = 0; j < i1.size(); ++j)
654 for (
unsigned int k = 0; k < i2.size(); ++k)
655 if (std::fabs(M(j, k)) >= threshold)
656 matrix[index]->add(i1[j], i2[k], M(j, k));
659 constraints->distribute_local_to_global(M, i1, i2, *matrix[index]);
663 template <
typename MatrixType>
664 template <
class DOFINFO>
669 const unsigned int n = info.indices_by_block.size();
672 for (
unsigned int m = 0; m < matrix.size(); ++m)
673 assemble(info.matrix(m,
false).matrix, m, info.indices, info.indices);
676 for (
unsigned int m = 0; m < matrix.size(); ++m)
677 for (
unsigned int k = 0; k < n * n; ++k)
680 info.matrix(k + m * n * n,
false).matrix,
682 info.indices_by_block[info.matrix(k + m * n * n,
false).row],
683 info.indices_by_block[info.matrix(k + m * n * n,
false)
690 template <
typename MatrixType>
691 template <
class DOFINFO>
694 const DOFINFO &info2)
699 info2.indices_by_block.size());
701 const unsigned int n = info1.indices_by_block.size();
705 for (
unsigned int m = 0; m < matrix.size(); ++m)
707 assemble(info1.matrix(m,
false).matrix,
711 assemble(info1.matrix(m,
true).matrix,
715 assemble(info2.matrix(m,
false).matrix,
719 assemble(info2.matrix(m,
true).matrix,
727 for (
unsigned int m = 0; m < matrix.size(); ++m)
728 for (
unsigned int k = 0; k < n * n; ++k)
730 const unsigned int row = info1.matrix(k + m * n * n,
false).row;
731 const unsigned int column =
732 info1.matrix(k + m * n * n,
false).column;
734 assemble(info1.matrix(k + m * n * n,
false).matrix,
736 info1.indices_by_block[row],
737 info1.indices_by_block[column]);
738 assemble(info1.matrix(k + m * n * n,
true).matrix,
740 info1.indices_by_block[row],
741 info2.indices_by_block[column]);
742 assemble(info2.matrix(k + m * n * n,
false).matrix,
744 info2.indices_by_block[row],
745 info2.indices_by_block[column]);
746 assemble(info2.matrix(k + m * n * n,
true).matrix,
748 info2.indices_by_block[row],
749 info1.indices_by_block[column]);
757 template <
typename MatrixType>
759 : threshold(threshold)
763 template <
typename MatrixType>
770 template <
typename MatrixType>
774 mg_constrained_dofs = &c;
778 template <
typename MatrixType>
789 template <
typename MatrixType>
796 interface_out = &out;
800 template <
typename MatrixType>
801 template <
class DOFINFO>
805 const unsigned int n = info.indices_by_block.size();
808 info.initialize_matrices(1, face);
811 info.initialize_matrices(n * n, face);
813 for (
unsigned int i = 0; i < n; ++i)
814 for (
unsigned int j = 0; j < n; ++j, ++k)
816 info.matrix(k,
false).row = i;
817 info.matrix(k,
false).column = j;
820 info.matrix(k,
true).row = i;
821 info.matrix(k,
true).column = j;
828 template <
typename MatrixType>
833 const std::vector<types::global_dof_index> &i1,
834 const std::vector<types::global_dof_index> &i2)
841 for (
unsigned int j = 0; j < i1.size(); ++j)
842 for (
unsigned int k = 0; k < i2.size(); ++k)
843 if (std::fabs(M(j, k)) >= threshold)
844 G.add(i1[j], i2[k], M(j, k));
848 template <
typename MatrixType>
853 const std::vector<types::global_dof_index> &i1,
854 const std::vector<types::global_dof_index> &i2,
855 const unsigned int level)
860 if (mg_constrained_dofs ==
nullptr)
862 for (
unsigned int j = 0; j < i1.size(); ++j)
863 for (
unsigned int k = 0; k < i2.size(); ++k)
864 if (std::fabs(M(j, k)) >= threshold)
865 G.add(i1[j], i2[k], M(j, k));
869 for (
unsigned int j = 0; j < i1.size(); ++j)
870 for (
unsigned int k = 0; k < i2.size(); ++k)
874 if (std::fabs(M(j, k)) < threshold)
884 if (mg_constrained_dofs->at_refinement_edge(
level, i1[j]) ||
885 mg_constrained_dofs->at_refinement_edge(
level, i2[k]))
890 if ((mg_constrained_dofs->is_boundary_index(
level, i1[j]) ||
891 mg_constrained_dofs->is_boundary_index(
level, i2[k])) &&
895 G.add(i1[j], i2[k], M(j, k));
901 template <
typename MatrixType>
906 const std::vector<types::global_dof_index> &i1,
907 const std::vector<types::global_dof_index> &i2,
908 const unsigned int level)
913 if (mg_constrained_dofs ==
nullptr)
915 for (
unsigned int j = 0; j < i1.size(); ++j)
916 for (
unsigned int k = 0; k < i2.size(); ++k)
917 if (std::fabs(M(k, j)) >= threshold)
918 G.add(i1[j], i2[k], M(k, j));
922 for (
unsigned int j = 0; j < i1.size(); ++j)
923 for (
unsigned int k = 0; k < i2.size(); ++k)
924 if (std::fabs(M(k, j)) >= threshold)
925 if (!mg_constrained_dofs->at_refinement_edge(
level, i2[k]))
926 G.add(i1[j], i2[k], M(k, j));
930 template <
typename MatrixType>
935 const std::vector<types::global_dof_index> &i1,
936 const std::vector<types::global_dof_index> &i2,
937 const unsigned int level)
942 if (mg_constrained_dofs ==
nullptr)
944 for (
unsigned int j = 0; j < i1.size(); ++j)
945 for (
unsigned int k = 0; k < i2.size(); ++k)
946 if (std::fabs(M(j, k)) >= threshold)
947 G.add(i1[j], i2[k], M(j, k));
951 for (
unsigned int j = 0; j < i1.size(); ++j)
952 for (
unsigned int k = 0; k < i2.size(); ++k)
953 if (std::fabs(M(j, k)) >= threshold)
954 if (!mg_constrained_dofs->at_refinement_edge(
level, i2[k]))
955 G.add(i1[j], i2[k], M(j, k));
959 template <
typename MatrixType>
964 const std::vector<types::global_dof_index> &i1,
965 const std::vector<types::global_dof_index> &i2,
966 const unsigned int level)
972 for (
unsigned int j = 0; j < i1.size(); ++j)
973 for (
unsigned int k = 0; k < i2.size(); ++k)
974 if (std::fabs(M(j, k)) >= threshold)
986 if (mg_constrained_dofs->at_refinement_edge(
level, i1[j]) &&
987 !mg_constrained_dofs->at_refinement_edge(
level, i2[k]))
989 if ((!mg_constrained_dofs->is_boundary_index(
level, i1[j]) &&
990 !mg_constrained_dofs->is_boundary_index(
level, i2[k])) ||
991 (mg_constrained_dofs->is_boundary_index(
level, i1[j]) &&
992 mg_constrained_dofs->is_boundary_index(
level, i2[k]) &&
994 G.add(i1[j], i2[k], M(j, k));
999 template <
typename MatrixType>
1004 const std::vector<types::global_dof_index> &i1,
1005 const std::vector<types::global_dof_index> &i2,
1006 const unsigned int level)
1012 for (
unsigned int j = 0; j < i1.size(); ++j)
1013 for (
unsigned int k = 0; k < i2.size(); ++k)
1014 if (std::fabs(M(k, j)) >= threshold)
1015 if (mg_constrained_dofs->at_refinement_edge(
level, i1[j]) &&
1016 !mg_constrained_dofs->at_refinement_edge(
level, i2[k]))
1018 if ((!mg_constrained_dofs->is_boundary_index(
level, i1[j]) &&
1019 !mg_constrained_dofs->is_boundary_index(
level, i2[k])) ||
1020 (mg_constrained_dofs->is_boundary_index(
level, i1[j]) &&
1021 mg_constrained_dofs->is_boundary_index(
level, i2[k]) &&
1023 G.add(i1[j], i2[k], M(k, j));
1028 template <
typename MatrixType>
1029 template <
class DOFINFO>
1034 const unsigned int level = info.cell->level();
1036 if (info.indices_by_block.empty())
1038 assemble((*matrix)[
level],
1039 info.matrix(0,
false).matrix,
1043 if (mg_constrained_dofs !=
nullptr)
1045 assemble_in((*interface_in)[
level],
1046 info.matrix(0,
false).matrix,
1050 assemble_out((*interface_out)[
level],
1051 info.matrix(0,
false).matrix,
1058 for (
unsigned int k = 0; k < info.n_matrices(); ++k)
1060 const unsigned int row = info.matrix(k,
false).row;
1061 const unsigned int column = info.matrix(k,
false).column;
1063 assemble((*matrix)[
level],
1064 info.matrix(k,
false).matrix,
1065 info.indices_by_block[row],
1066 info.indices_by_block[column],
1069 if (mg_constrained_dofs !=
nullptr)
1071 assemble_in((*interface_in)[
level],
1072 info.matrix(k,
false).matrix,
1073 info.indices_by_block[row],
1074 info.indices_by_block[column],
1076 assemble_out((*interface_out)[
level],
1077 info.matrix(k,
false).matrix,
1078 info.indices_by_block[column],
1079 info.indices_by_block[row],
1086 template <
typename MatrixType>
1087 template <
class DOFINFO>
1090 const DOFINFO &info2)
1094 const unsigned int level1 = info1.cell->level();
1095 const unsigned int level2 = info2.cell->level();
1097 if (info1.indices_by_block.empty())
1099 if (level1 == level2)
1101 assemble((*matrix)[level1],
1102 info1.matrix(0,
false).matrix,
1106 assemble((*matrix)[level1],
1107 info1.matrix(0,
true).matrix,
1111 assemble((*matrix)[level1],
1112 info2.matrix(0,
false).matrix,
1116 assemble((*matrix)[level1],
1117 info2.matrix(0,
true).matrix,
1128 assemble((*matrix)[level1],
1129 info1.matrix(0,
false).matrix,
1135 assemble_up((*flux_up)[level1],
1136 info1.matrix(0,
true).matrix,
1140 assemble_down((*flux_down)[level1],
1141 info2.matrix(0,
true).matrix,
1149 for (
unsigned int k = 0; k < info1.n_matrices(); ++k)
1151 const unsigned int row = info1.matrix(k,
false).row;
1152 const unsigned int column = info1.matrix(k,
false).column;
1154 if (level1 == level2)
1156 assemble((*matrix)[level1],
1157 info1.matrix(k,
false).matrix,
1158 info1.indices_by_block[row],
1159 info1.indices_by_block[column],
1161 assemble((*matrix)[level1],
1162 info1.matrix(k,
true).matrix,
1163 info1.indices_by_block[row],
1164 info2.indices_by_block[column],
1166 assemble((*matrix)[level1],
1167 info2.matrix(k,
false).matrix,
1168 info2.indices_by_block[row],
1169 info2.indices_by_block[column],
1171 assemble((*matrix)[level1],
1172 info2.matrix(k,
true).matrix,
1173 info2.indices_by_block[row],
1174 info1.indices_by_block[column],
1183 assemble((*matrix)[level1],
1184 info1.matrix(k,
false).matrix,
1185 info1.indices_by_block[row],
1186 info1.indices_by_block[column],
1190 assemble_up((*flux_up)[level1],
1191 info1.matrix(k,
true).matrix,
1192 info2.indices_by_block[column],
1193 info1.indices_by_block[row],
1195 assemble_down((*flux_down)[level1],
1196 info2.matrix(k,
true).matrix,
1197 info2.indices_by_block[row],
1198 info1.indices_by_block[column],
1207 template <
typename MatrixType,
typename VectorType>
1213 template <
typename MatrixType,
typename VectorType>
1219 VectorType *p = &rhs;
1220 data.add(p,
"right hand side");
1226 template <
typename MatrixType,
typename VectorType>
1235 template <
typename MatrixType,
typename VectorType>
1236 template <
class DOFINFO>
1245 template <
typename MatrixType,
typename VectorType>
1250 const unsigned int index,
1251 const std::vector<types::global_dof_index> &indices)
1257 VectorType *v = residuals.
entry<VectorType *>(index);
1261 for (
unsigned int i = 0; i < indices.size(); ++i)
1262 (*v)(indices[i]) += vector(i);
1264 for (
unsigned int j = 0; j < indices.size(); ++j)
1265 for (
unsigned int k = 0; k < indices.size(); ++k)
1283 template <
typename MatrixType,
typename VectorType>
1288 const unsigned int index,
1289 const std::vector<types::global_dof_index> &i1,
1290 const std::vector<types::global_dof_index> &i2)
1296 VectorType *v = residuals.
entry<VectorType *>(index);
1300 for (
unsigned int j = 0; j < i1.size(); ++j)
1301 for (
unsigned int k = 0; k < i2.size(); ++k)
1310 vector, i1, i2, *v, M,
false);
1317 template <
typename MatrixType,
typename VectorType>
1318 template <
class DOFINFO>
1325 const unsigned int n = info.indices_by_block.size();
1329 for (
unsigned int m = 0; m < MatrixSimple<MatrixType>::matrix.size();
1331 assemble(info.matrix(m,
false).matrix,
1332 info.vector(m).block(0),
1338 for (
unsigned int m = 0; m < MatrixSimple<MatrixType>::matrix.size();
1340 for (
unsigned int k = 0; k < n * n; ++k)
1342 const unsigned int row = info.matrix(k + m * n * n,
false).row;
1343 const unsigned int column =
1344 info.matrix(k + m * n * n,
false).column;
1347 assemble(info.matrix(k + m * n * n,
false).matrix,
1348 info.vector(m).block(row),
1350 info.indices_by_block[row]);
1352 assemble(info.matrix(k + m * n * n,
false).matrix,
1353 info.vector(m).block(row),
1355 info.indices_by_block[row],
1356 info.indices_by_block[column]);
1362 template <
typename MatrixType,
typename VectorType>
1363 template <
class DOFINFO>
1366 const DOFINFO &info2)
1371 info2.indices_by_block.size());
1373 const unsigned int n = info1.indices_by_block.size();
1377 for (
unsigned int m = 0; m < MatrixSimple<MatrixType>::matrix.size();
1380 assemble(info1.matrix(m,
false).matrix,
1381 info1.vector(m).block(0),
1384 assemble(info1.matrix(m,
true).matrix,
1385 info1.vector(m).block(0),
1389 assemble(info2.matrix(m,
false).matrix,
1390 info2.vector(m).block(0),
1393 assemble(info2.matrix(m,
true).matrix,
1394 info2.vector(m).block(0),
1402 for (
unsigned int m = 0; m < MatrixSimple<MatrixType>::matrix.size();
1404 for (
unsigned int k = 0; k < n * n; ++k)
1406 const unsigned int row = info1.matrix(k + m * n * n,
false).row;
1407 const unsigned int column =
1408 info1.matrix(k + m * n * n,
false).column;
1412 assemble(info1.matrix(k + m * n * n,
false).matrix,
1413 info1.vector(m).block(row),
1415 info1.indices_by_block[row]);
1416 assemble(info2.matrix(k + m * n * n,
false).matrix,
1417 info2.vector(m).block(row),
1419 info2.indices_by_block[row]);
1423 assemble(info1.matrix(k + m * n * n,
false).matrix,
1424 info1.vector(m).block(row),
1426 info1.indices_by_block[row],
1427 info1.indices_by_block[column]);
1428 assemble(info2.matrix(k + m * n * n,
false).matrix,
1429 info2.vector(m).block(row),
1431 info2.indices_by_block[row],
1432 info2.indices_by_block[column]);
1434 assemble(info1.matrix(k + m * n * n,
true).matrix,
1435 info1.vector(m).block(row),
1437 info1.indices_by_block[row],
1438 info2.indices_by_block[column]);
1439 assemble(info2.matrix(k + m * n * n,
true).matrix,
1440 info2.vector(m).block(row),
1442 info2.indices_by_block[row],
1443 info1.indices_by_block[column]);
type entry(const std::string &name)
Access to stored data object by name.
void assemble_out(MatrixType &G, const FullMatrix< double > &M, const std::vector< types::global_dof_index > &i1, const std::vector< types::global_dof_index > &i2, const unsigned int level=numbers::invalid_unsigned_int)
ObserverPointer< MGLevelObject< MatrixType >, MGMatrixSimple< MatrixType > > flux_up
void initialize_fluxes(MGLevelObject< MatrixType > &flux_up, MGLevelObject< MatrixType > &flux_down)
void initialize_interfaces(MGLevelObject< MatrixType > &interface_in, MGLevelObject< MatrixType > &interface_out)
ObserverPointer< MGLevelObject< MatrixType >, MGMatrixSimple< MatrixType > > interface_in
ObserverPointer< MGLevelObject< MatrixType >, MGMatrixSimple< MatrixType > > flux_down
void assemble(const DOFINFO &info)
void initialize_info(DOFINFO &info, bool face) const
ObserverPointer< MGLevelObject< MatrixType >, MGMatrixSimple< MatrixType > > matrix
void assemble_in(MatrixType &G, const FullMatrix< double > &M, const std::vector< types::global_dof_index > &i1, const std::vector< types::global_dof_index > &i2, const unsigned int level=numbers::invalid_unsigned_int)
MGMatrixSimple(double threshold=1.e-12)
ObserverPointer< MGLevelObject< MatrixType >, MGMatrixSimple< MatrixType > > interface_out
void initialize(MGLevelObject< MatrixType > &m)
void assemble_down(MatrixType &G, const FullMatrix< double > &M, const std::vector< types::global_dof_index > &i1, const std::vector< types::global_dof_index > &i2, const unsigned int level=numbers::invalid_unsigned_int)
void assemble_up(MatrixType &G, const FullMatrix< double > &M, const std::vector< types::global_dof_index > &i1, const std::vector< types::global_dof_index > &i2, const unsigned int level=numbers::invalid_unsigned_int)
ObserverPointer< const MGConstrainedDoFs, MGMatrixSimple< MatrixType > > mg_constrained_dofs
std::vector< ObserverPointer< MatrixType, MatrixSimple< MatrixType > > > matrix
void initialize(MatrixType &m)
MatrixSimple(double threshold=1.e-12)
void initialize_info(DOFINFO &info, bool face) const
ObserverPointer< const AffineConstraints< typename MatrixType::value_type >, MatrixSimple< MatrixType > > constraints
void assemble(const DOFINFO &info)
void assemble(const DOFINFO &info)
void initialize_info(DOFINFO &info, bool face) const
ObserverPointer< const AffineConstraints< typename VectorType::value_type >, ResidualSimple< VectorType > > constraints
void initialize(AnyData &results)
SystemSimple(double threshold=1.e-12)
void assemble(const DOFINFO &info)
void initialize(MatrixType &m, VectorType &rhs)
void initialize_info(DOFINFO &info, bool face) const
#define DEAL_II_DEPRECATED
#define DEAL_II_NAMESPACE_OPEN
#define DEAL_II_NAMESPACE_CLOSE
#define Assert(cond, exc)
#define AssertDimension(dim1, dim2)
static ::ExceptionBase & ExcInternalError()
static ::ExceptionBase & ExcNotInitialized()
static ::ExceptionBase & ExcMessage(std::string arg1)
std::vector< index_type > data
constexpr unsigned int invalid_unsigned_int