14#ifndef dealii_mesh_worker_assembler_h
15#define dealii_mesh_worker_assembler_h
108 template <
typename VectorType>
132 template <
class DOFINFO>
134 initialize_info(DOFINFO &info,
bool face)
const;
140 template <
class DOFINFO>
142 assemble(
const DOFINFO &info);
147 template <
class DOFINFO>
149 assemble(
const DOFINFO &info1,
const DOFINFO &info2);
156 assemble(VectorType &global,
158 const std::vector<types::global_dof_index> &dof);
207 template <
typename MatrixType,
typename number =
double>
239 template <
class DOFINFO>
241 initialize_info(DOFINFO &info,
bool face)
const;
247 template <
class DOFINFO>
249 assemble(
const DOFINFO &info);
254 template <
class DOFINFO>
256 assemble(
const DOFINFO &info1,
const DOFINFO &info2);
265 const unsigned int block_row,
266 const unsigned int block_col,
267 const std::vector<types::global_dof_index> &dof1,
268 const std::vector<types::global_dof_index> &dof2);
322 template <
typename MatrixType,
typename number =
double>
373 template <
class DOFINFO>
375 initialize_info(DOFINFO &info,
bool face)
const;
381 template <
class DOFINFO>
383 assemble(
const DOFINFO &info);
388 template <
class DOFINFO>
390 assemble(
const DOFINFO &info1,
const DOFINFO &info2);
397 assemble(MatrixType &global,
399 const unsigned int block_row,
400 const unsigned int block_col,
401 const std::vector<types::global_dof_index> &dof1,
402 const std::vector<types::global_dof_index> &dof2,
403 const unsigned int level1,
404 const unsigned int level2,
411 assemble_fluxes(MatrixType &global,
413 const unsigned int block_row,
414 const unsigned int block_col,
415 const std::vector<types::global_dof_index> &dof1,
416 const std::vector<types::global_dof_index> &dof2,
417 const unsigned int level1,
418 const unsigned int level2);
424 assemble_up(MatrixType &global,
426 const unsigned int block_row,
427 const unsigned int block_col,
428 const std::vector<types::global_dof_index> &dof1,
429 const std::vector<types::global_dof_index> &dof2,
430 const unsigned int level1,
431 const unsigned int level2);
437 assemble_down(MatrixType &global,
439 const unsigned int block_row,
440 const unsigned int block_col,
441 const std::vector<types::global_dof_index> &dof1,
442 const std::vector<types::global_dof_index> &dof2,
443 const unsigned int level1,
444 const unsigned int level2);
450 assemble_in(MatrixType &global,
452 const unsigned int block_row,
453 const unsigned int block_col,
454 const std::vector<types::global_dof_index> &dof1,
455 const std::vector<types::global_dof_index> &dof2,
456 const unsigned int level1,
457 const unsigned int level2);
463 assemble_out(MatrixType &global,
465 const unsigned int block_row,
466 const unsigned int block_col,
467 const std::vector<types::global_dof_index> &dof1,
468 const std::vector<types::global_dof_index> &dof2,
469 const unsigned int level1,
470 const unsigned int level2);
526 template <
typename VectorType>
536 template <
typename VectorType>
545 template <
typename VectorType>
546 template <
class DOFINFO>
552 info.initialize_vectors(residuals.size());
555 template <
typename VectorType>
560 const std::vector<types::global_dof_index> &dof)
562 if (constraints == 0)
564 for (
unsigned int b = 0; b < local.
n_blocks(); ++b)
565 for (
unsigned int j = 0; j < local.
block(b).
size(); ++j)
575 const unsigned int jcell =
576 this->block_info->local().local_to_global(b, j);
577 global(dof[jcell]) += local.
block(b)(j);
581 constraints->distribute_local_to_global(local, dof, global);
585 template <
typename VectorType>
586 template <
class DOFINFO>
590 for (
unsigned int i = 0; i < residuals.size(); ++i)
591 assemble(*(residuals.entry<VectorType>(i)),
597 template <
typename VectorType>
598 template <
class DOFINFO>
601 const DOFINFO &info1,
602 const DOFINFO &info2)
604 for (
unsigned int i = 0; i < residuals.size(); ++i)
606 assemble(*(residuals.entry<VectorType>(i)),
609 assemble(*(residuals.entry<VectorType>(i)),
618 template <
typename MatrixType,
typename number>
621 : threshold(threshold)
625 template <
typename MatrixType,
typename number>
637 template <
typename MatrixType,
typename number>
647 template <
typename MatrixType,
typename number>
648 template <
class DOFINFO>
654 info.initialize_matrices(*matrices, face);
659 template <
typename MatrixType,
typename number>
664 const unsigned int block_row,
665 const unsigned int block_col,
666 const std::vector<types::global_dof_index> &dof1,
667 const std::vector<types::global_dof_index> &dof2)
669 if (constraints ==
nullptr)
671 for (
unsigned int j = 0; j < local.n_rows(); ++j)
672 for (
unsigned int k = 0; k < local.n_cols(); ++k)
673 if (std::fabs(local(j, k)) >= threshold)
683 const unsigned int jcell =
684 this->block_info->local().local_to_global(block_row, j);
685 const unsigned int kcell =
686 this->block_info->local().local_to_global(block_col, k);
688 global.
add(dof1[jcell], dof2[kcell], local(j, k));
694 std::vector<types::global_dof_index> sliced_row_indices(
696 for (
unsigned int i = 0; i < sliced_row_indices.size(); ++i)
697 sliced_row_indices[i] = dof1[bi.
block_start(block_row) + i];
699 std::vector<types::global_dof_index> sliced_col_indices(
701 for (
unsigned int i = 0; i < sliced_col_indices.size(); ++i)
702 sliced_col_indices[i] = dof2[bi.
block_start(block_col) + i];
704 constraints->distribute_local_to_global(local,
712 template <
typename MatrixType,
typename number>
713 template <
class DOFINFO>
718 for (
unsigned int i = 0; i < matrices->size(); ++i)
725 assemble(matrices->block(i),
726 info.matrix(i,
false).matrix,
735 template <
typename MatrixType,
typename number>
736 template <
class DOFINFO>
739 const DOFINFO &info1,
740 const DOFINFO &info2)
742 for (
unsigned int i = 0; i < matrices->size(); ++i)
749 assemble(matrices->block(i),
750 info1.matrix(i,
false).matrix,
755 assemble(matrices->block(i),
756 info1.matrix(i,
true).matrix,
761 assemble(matrices->block(i),
762 info2.matrix(i,
false).matrix,
767 assemble(matrices->block(i),
768 info2.matrix(i,
true).matrix,
779 template <
typename MatrixType,
typename number>
782 : threshold(threshold)
786 template <
typename MatrixType,
typename number>
793 AssertDimension(block_info->local().size(), block_info->global().size());
798 template <
typename MatrixType,
typename number>
803 mg_constrained_dofs = &mg_c;
807 template <
typename MatrixType,
typename number>
808 template <
class DOFINFO>
814 info.initialize_matrices(*matrices, face);
819 template <
typename MatrixType,
typename number>
830 template <
typename MatrixType,
typename number>
840 template <
typename MatrixType,
typename number>
845 const unsigned int block_row,
846 const unsigned int block_col,
847 const std::vector<types::global_dof_index> &dof1,
848 const std::vector<types::global_dof_index> &dof2,
849 const unsigned int level1,
850 const unsigned int level2,
853 for (
unsigned int j = 0; j < local.n_rows(); ++j)
854 for (
unsigned int k = 0; k < local.n_cols(); ++k)
855 if (std::fabs(local(j, k)) >= threshold)
865 const unsigned int jcell =
866 this->block_info->local().local_to_global(block_row, j);
867 const unsigned int kcell =
868 this->block_info->local().local_to_global(block_col, k);
878 const unsigned int jglobal = this->block_info->level(level1)
879 .global_to_local(dof1[jcell])
881 const unsigned int kglobal = this->block_info->level(level2)
882 .global_to_local(dof2[kcell])
885 if (mg_constrained_dofs == 0)
888 global.
add(kglobal, jglobal, local(j, k));
890 global.add(jglobal, kglobal, local(j, k));
894 if (!mg_constrained_dofs->at_refinement_edge(level1,
896 !mg_constrained_dofs->at_refinement_edge(level2, kglobal))
898 if (mg_constrained_dofs->set_boundary_values())
900 if ((!mg_constrained_dofs->is_boundary_index(
902 !mg_constrained_dofs->is_boundary_index(
904 (mg_constrained_dofs->is_boundary_index(
906 mg_constrained_dofs->is_boundary_index(
911 global.add(kglobal, jglobal, local(j, k));
913 global.add(jglobal, kglobal, local(j, k));
919 global.add(kglobal, jglobal, local(j, k));
921 global.add(jglobal, kglobal, local(j, k));
929 template <
typename MatrixType,
typename number>
934 const unsigned int block_row,
935 const unsigned int block_col,
936 const std::vector<types::global_dof_index> &dof1,
937 const std::vector<types::global_dof_index> &dof2,
938 const unsigned int level1,
939 const unsigned int level2)
941 for (
unsigned int j = 0; j < local.n_rows(); ++j)
942 for (
unsigned int k = 0; k < local.n_cols(); ++k)
943 if (std::fabs(local(j, k)) >= threshold)
953 const unsigned int jcell =
954 this->block_info->local().local_to_global(block_row, j);
955 const unsigned int kcell =
956 this->block_info->local().local_to_global(block_col, k);
966 const unsigned int jglobal = this->block_info->level(level1)
967 .global_to_local(dof1[jcell])
969 const unsigned int kglobal = this->block_info->level(level2)
970 .global_to_local(dof2[kcell])
973 if (mg_constrained_dofs == 0)
974 global.add(jglobal, kglobal, local(j, k));
977 if (!mg_constrained_dofs->non_refinement_edge_index(
979 !mg_constrained_dofs->non_refinement_edge_index(level2,
982 if (!mg_constrained_dofs->at_refinement_edge(level1,
984 !mg_constrained_dofs->at_refinement_edge(level2,
986 global.add(jglobal, kglobal, local(j, k));
992 template <
typename MatrixType,
typename number>
997 const unsigned int block_row,
998 const unsigned int block_col,
999 const std::vector<types::global_dof_index> &dof1,
1000 const std::vector<types::global_dof_index> &dof2,
1001 const unsigned int level1,
1002 const unsigned int level2)
1004 for (
unsigned int j = 0; j < local.n_rows(); ++j)
1005 for (
unsigned int k = 0; k < local.n_cols(); ++k)
1006 if (std::fabs(local(j, k)) >= threshold)
1016 const unsigned int jcell =
1017 this->block_info->local().local_to_global(block_row, j);
1018 const unsigned int kcell =
1019 this->block_info->local().local_to_global(block_col, k);
1029 const unsigned int jglobal = this->block_info->level(level1)
1030 .global_to_local(dof1[jcell])
1032 const unsigned int kglobal = this->block_info->level(level2)
1033 .global_to_local(dof2[kcell])
1036 if (mg_constrained_dofs == 0)
1037 global.add(jglobal, kglobal, local(j, k));
1040 if (!mg_constrained_dofs->non_refinement_edge_index(
1042 !mg_constrained_dofs->non_refinement_edge_index(level2,
1045 if (!mg_constrained_dofs->at_refinement_edge(level1,
1047 !mg_constrained_dofs->at_refinement_edge(level2,
1049 global.add(jglobal, kglobal, local(j, k));
1055 template <
typename MatrixType,
typename number>
1060 const unsigned int block_row,
1061 const unsigned int block_col,
1062 const std::vector<types::global_dof_index> &dof1,
1063 const std::vector<types::global_dof_index> &dof2,
1064 const unsigned int level1,
1065 const unsigned int level2)
1067 for (
unsigned int j = 0; j < local.n_rows(); ++j)
1068 for (
unsigned int k = 0; k < local.n_cols(); ++k)
1069 if (std::fabs(local(k, j)) >= threshold)
1079 const unsigned int jcell =
1080 this->block_info->local().local_to_global(block_row, j);
1081 const unsigned int kcell =
1082 this->block_info->local().local_to_global(block_col, k);
1092 const unsigned int jglobal = this->block_info->level(level1)
1093 .global_to_local(dof1[jcell])
1095 const unsigned int kglobal = this->block_info->level(level2)
1096 .global_to_local(dof2[kcell])
1099 if (mg_constrained_dofs == 0)
1100 global.add(jglobal, kglobal, local(k, j));
1103 if (!mg_constrained_dofs->non_refinement_edge_index(
1105 !mg_constrained_dofs->non_refinement_edge_index(level2,
1108 if (!mg_constrained_dofs->at_refinement_edge(level1,
1110 !mg_constrained_dofs->at_refinement_edge(level2,
1112 global.add(jglobal, kglobal, local(k, j));
1118 template <
typename MatrixType,
typename number>
1123 const unsigned int block_row,
1124 const unsigned int block_col,
1125 const std::vector<types::global_dof_index> &dof1,
1126 const std::vector<types::global_dof_index> &dof2,
1127 const unsigned int level1,
1128 const unsigned int level2)
1133 for (
unsigned int j = 0; j < local.n_rows(); ++j)
1134 for (
unsigned int k = 0; k < local.n_cols(); ++k)
1135 if (std::fabs(local(j, k)) >= threshold)
1145 const unsigned int jcell =
1146 this->block_info->local().local_to_global(block_row, j);
1147 const unsigned int kcell =
1148 this->block_info->local().local_to_global(block_col, k);
1158 const unsigned int jglobal = this->block_info->level(level1)
1159 .global_to_local(dof1[jcell])
1161 const unsigned int kglobal = this->block_info->level(level2)
1162 .global_to_local(dof2[kcell])
1165 if (mg_constrained_dofs == 0)
1166 global.add(jglobal, kglobal, local(j, k));
1169 if (mg_constrained_dofs->at_refinement_edge(level1,
1171 !mg_constrained_dofs->at_refinement_edge(level2, kglobal))
1173 if (mg_constrained_dofs->set_boundary_values())
1175 if ((!mg_constrained_dofs->is_boundary_index(
1177 !mg_constrained_dofs->is_boundary_index(
1178 level2, kglobal)) ||
1179 (mg_constrained_dofs->is_boundary_index(
1181 mg_constrained_dofs->is_boundary_index(
1183 jglobal == kglobal))
1184 global.add(jglobal, kglobal, local(j, k));
1187 global.add(jglobal, kglobal, local(j, k));
1193 template <
typename MatrixType,
typename number>
1198 const unsigned int block_row,
1199 const unsigned int block_col,
1200 const std::vector<types::global_dof_index> &dof1,
1201 const std::vector<types::global_dof_index> &dof2,
1202 const unsigned int level1,
1203 const unsigned int level2)
1208 for (
unsigned int j = 0; j < local.n_rows(); ++j)
1209 for (
unsigned int k = 0; k < local.n_cols(); ++k)
1210 if (std::fabs(local(k, j)) >= threshold)
1220 const unsigned int jcell =
1221 this->block_info->local().local_to_global(block_row, j);
1222 const unsigned int kcell =
1223 this->block_info->local().local_to_global(block_col, k);
1233 const unsigned int jglobal = this->block_info->level(level1)
1234 .global_to_local(dof1[jcell])
1236 const unsigned int kglobal = this->block_info->level(level2)
1237 .global_to_local(dof2[kcell])
1240 if (mg_constrained_dofs == 0)
1241 global.add(jglobal, kglobal, local(k, j));
1244 if (mg_constrained_dofs->at_refinement_edge(level1,
1246 !mg_constrained_dofs->at_refinement_edge(level2, kglobal))
1248 if (mg_constrained_dofs->set_boundary_values())
1250 if ((!mg_constrained_dofs->is_boundary_index(
1252 !mg_constrained_dofs->is_boundary_index(
1253 level2, kglobal)) ||
1254 (mg_constrained_dofs->is_boundary_index(
1256 mg_constrained_dofs->is_boundary_index(
1258 jglobal == kglobal))
1259 global.add(jglobal, kglobal, local(k, j));
1262 global.add(jglobal, kglobal, local(k, j));
1269 template <
typename MatrixType,
typename number>
1270 template <
class DOFINFO>
1273 const DOFINFO &info)
1275 const unsigned int level = info.cell->level();
1277 for (
unsigned int i = 0; i < matrices->size(); ++i)
1281 const unsigned int row = matrices->block(i)[
level].row;
1282 const unsigned int col = matrices->block(i)[
level].column;
1284 assemble(matrices->block(i)[
level].matrix,
1285 info.matrix(i,
false).matrix,
1292 if (mg_constrained_dofs != 0)
1294 if (interface_in != 0)
1295 assemble_in(interface_in->block(i)[
level],
1296 info.matrix(i,
false).matrix,
1303 if (interface_out != 0)
1304 assemble_in(interface_out->block(i)[
level],
1305 info.matrix(i,
false).matrix,
1313 assemble_in(matrices->block_in(i)[
level],
1314 info.matrix(i,
false).matrix,
1321 assemble_out(matrices->block_out(i)[
level],
1322 info.matrix(i,
false).matrix,
1334 template <
typename MatrixType,
typename number>
1335 template <
class DOFINFO>
1338 const DOFINFO &info1,
1339 const DOFINFO &info2)
1341 const unsigned int level1 = info1.cell->level();
1342 const unsigned int level2 = info2.cell->level();
1344 for (
unsigned int i = 0; i < matrices->size(); ++i)
1350 const unsigned int row = o[level1].row;
1351 const unsigned int col = o[level1].column;
1353 if (level1 == level2)
1355 if (mg_constrained_dofs == 0)
1357 assemble(o[level1].matrix,
1358 info1.matrix(i,
false).matrix,
1365 assemble(o[level1].matrix,
1366 info1.matrix(i,
true).matrix,
1373 assemble(o[level1].matrix,
1374 info2.matrix(i,
false).matrix,
1381 assemble(o[level1].matrix,
1382 info2.matrix(i,
true).matrix,
1392 assemble_fluxes(o[level1].matrix,
1393 info1.matrix(i,
false).matrix,
1400 assemble_fluxes(o[level1].matrix,
1401 info1.matrix(i,
true).matrix,
1408 assemble_fluxes(o[level1].matrix,
1409 info2.matrix(i,
false).matrix,
1416 assemble_fluxes(o[level1].matrix,
1417 info2.matrix(i,
true).matrix,
1429 if (flux_up->size() != 0)
1434 assemble_fluxes(o[level1].matrix,
1435 info1.matrix(i,
false).matrix,
1442 assemble_up(flux_up->block(i)[level1].matrix,
1443 info1.matrix(i,
true).matrix,
1450 assemble_down(flux_down->block(i)[level1].matrix,
1451 info2.matrix(i,
true).matrix,
size_type block_size(const unsigned int i) const
size_type block_start(const unsigned int i) const
A small class collecting the different BlockIndices involved in global, multilevel and local computat...
unsigned int n_blocks() const
BlockType & block(const unsigned int i)
void add(size_type row, size_type column, const std::string &name)
void add(const size_type i, const size_type j, const typename MatrixType::value_type value)
void assemble_down(MatrixType &global, const FullMatrix< number > &local, const unsigned int block_row, const unsigned int block_col, const std::vector< types::global_dof_index > &dof1, const std::vector< types::global_dof_index > &dof2, const unsigned int level1, const unsigned int level2)
void initialize_info(DOFINFO &info, bool face) const
MatrixPtrVectorPtr matrices
void assemble_in(MatrixType &global, const FullMatrix< number > &local, const unsigned int block_row, const unsigned int block_col, const std::vector< types::global_dof_index > &dof1, const std::vector< types::global_dof_index > &dof2, const unsigned int level1, const unsigned int level2)
void assemble(const DOFINFO &info)
ObserverPointer< const BlockInfo, MGMatrixLocalBlocksToGlobalBlocks< MatrixType, number > > block_info
MatrixPtrVectorPtr interface_out
void initialize(const BlockInfo *block_info, MatrixPtrVector &matrices)
void assemble_up(MatrixType &global, const FullMatrix< number > &local, const unsigned int block_row, const unsigned int block_col, const std::vector< types::global_dof_index > &dof1, const std::vector< types::global_dof_index > &dof2, const unsigned int level1, const unsigned int level2)
void assemble_out(MatrixType &global, const FullMatrix< number > &local, const unsigned int block_row, const unsigned int block_col, const std::vector< types::global_dof_index > &dof1, const std::vector< types::global_dof_index > &dof2, const unsigned int level1, const unsigned int level2)
ObserverPointer< const MGConstrainedDoFs, MGMatrixLocalBlocksToGlobalBlocks< MatrixType, number > > mg_constrained_dofs
MatrixPtrVectorPtr interface_in
void initialize_interfaces(MatrixPtrVector &interface_in, MatrixPtrVector &interface_out)
void assemble_fluxes(MatrixType &global, const FullMatrix< number > &local, const unsigned int block_row, const unsigned int block_col, const std::vector< types::global_dof_index > &dof1, const std::vector< types::global_dof_index > &dof2, const unsigned int level1, const unsigned int level2)
MatrixPtrVectorPtr flux_down
void initialize_edge_flux(MatrixPtrVector &up, MatrixPtrVector &down)
MatrixPtrVectorPtr flux_up
MGMatrixLocalBlocksToGlobalBlocks(double threshold=1.e-12)
void initialize_info(DOFINFO &info, bool face) const
ObserverPointer< const BlockInfo, MatrixLocalBlocksToGlobalBlocks< MatrixType, number > > block_info
ObserverPointer< const AffineConstraints< typename MatrixType::value_type >, MatrixLocalBlocksToGlobalBlocks< MatrixType, number > > constraints
void initialize(const BlockInfo *block_info, MatrixBlockVector< MatrixType > &matrices)
ObserverPointer< MatrixBlockVector< MatrixType >, MatrixLocalBlocksToGlobalBlocks< MatrixType, number > > matrices
MatrixLocalBlocksToGlobalBlocks(double threshold=1.e-12)
void assemble(const DOFINFO &info)
void initialize_info(DOFINFO &info, bool face) const
void initialize(const BlockInfo *block_info, AnyData &residuals)
void assemble(const DOFINFO &info)
ObserverPointer< const BlockInfo, ResidualLocalBlocksToGlobalBlocks< VectorType > > block_info
ObserverPointer< const AffineConstraints< typename VectorType::value_type >, ResidualLocalBlocksToGlobalBlocks< VectorType > > constraints
#define DEAL_II_DEPRECATED
#define DEAL_II_NAMESPACE_OPEN
#define DEAL_II_NAMESPACE_CLOSE
static ::ExceptionBase & ExcNotImplemented()
#define Assert(cond, exc)
#define AssertDimension(dim1, dim2)