24 #ifndef IntegratorMultiMesh_H_
25 #define IntegratorMultiMesh_H_
27 #include <deal.II/lac/vector.h>
28 #include <deal.II/lac/block_sparsity_pattern.h>
29 #include <deal.II/lac/block_sparse_matrix.h>
30 #include <deal.II/numerics/matrix_tools.h>
31 #include <deal.II/numerics/vector_tools.h>
32 #include <deal.II/grid/grid_tools.h>
33 #include <deal.II/base/function.h>
59 template<
typename INTEGRATORDATACONT,
typename VECTOR,
typename SCALAR,
71 template<
typename PROBLEM>
74 bool apply_boundary_values =
true);
75 template<
typename PROBLEM>
78 bool apply_boundary_values =
true);
79 template<
typename PROBLEM>
82 bool apply_boundary_values =
true);
83 template<
typename PROBLEM,
typename MATRIX>
87 template<
typename PROBLEM>
89 template<
typename PROBLEM>
92 template<
typename PROBLEM>
95 template<
typename PROBLEM>
98 template<
typename PROBLEM>
101 template<
typename PROBLEM>
104 template<
typename PROBLEM>
108 template<
typename PROBLEM>
111 template<
typename PROBLEM>
114 template<
typename PROBLEM,
typename MATRIX>
125 AddParamData(std::string name,
const dealii::Vector<SCALAR>* new_data);
130 inline const std::map<std::string, const dealii::Vector<SCALAR>*>&
133 inline INTEGRATORDATACONT&
135 inline const std::map<std::string, const VECTOR*>&
140 template<
template<
int,
int>
class DH>
142 InterpolateBoundaryValues(
144 const unsigned int color,
const dealii::Function<dim>&
function,
145 std::map<unsigned int, SCALAR>& boundary_values,
146 const std::vector<bool>& comp_mask)
const;
152 template<
typename PROBLEM,
template<
int,
int>
class DH>
153 inline void ComputeNonlinearResidual_Recursive(
156 typename std::vector<
typename DH<dim, dim>::cell_iterator>& element_iter,
157 typename std::vector<
typename dealii::Triangulation<dim>::cell_iterator>& tria_element_iter,
158 const FullMatrix<SCALAR>& prolong_matrix,
unsigned int coarse_index,
unsigned int fine_index,
166 template<
typename PROBLEM,
template<
int,
int>
class DH>
167 inline void ComputeNonlinearRhs_Recursive(
170 typename std::vector<
typename DH<dim, dim>::cell_iterator>& element_iter,
171 typename std::vector<
typename dealii::Triangulation<dim>::cell_iterator>& tria_element_iter,
172 const FullMatrix<SCALAR>& prolong_matrix,
unsigned int coarse_index,
unsigned int fine_index,
180 template<
typename PROBLEM,
typename MATRIX,
template<
int,
int>
class DH>
181 inline void ComputeMatrix_Recursive(
184 typename std::vector<
typename DH<dim, dim>::cell_iterator>& element_iter,
185 typename std::vector<
typename dealii::Triangulation<dim>::cell_iterator>& tria_element_iter,
186 const FullMatrix<SCALAR>& prolong_matrix,
unsigned int coarse_index,
unsigned int fine_index,
194 template<
typename PROBLEM,
template<
int,
int>
class DH>
195 inline SCALAR ComputeDomainScalar_Recursive(
197 typename std::vector<
typename DH<dim, dim>::cell_iterator>& element_iter,
198 typename std::vector<
typename dealii::Triangulation<dim>::cell_iterator>& tria_element_iter,
199 const FullMatrix<SCALAR>& prolong_matrix,
unsigned int coarse_index,
unsigned int fine_index,
206 template<
typename PROBLEM,
template<
int,
int>
class DH>
207 inline SCALAR ComputeBoundaryScalar_Recursive(
209 typename std::vector<
typename DH<dim, dim>::cell_iterator>& element_iter,
210 typename std::vector<
typename dealii::Triangulation<dim>::cell_iterator>& tria_element_iter,
211 const FullMatrix<SCALAR>& prolong_matrix,
unsigned int coarse_index,
unsigned int fine_index,
214 INTEGRATORDATACONT & idc_;
216 std::map<std::string, const VECTOR*> domain_data_;
217 std::map<std::string, const dealii::Vector<SCALAR>*> param_data_;
222 template<
typename INTEGRATORDATACONT,
typename VECTOR,
typename SCALAR,
225 INTEGRATORDATACONT& idc) :
232 template<
typename INTEGRATORDATACONT,
typename VECTOR,
typename SCALAR,
241 template<
typename INTEGRATORDATACONT,
typename VECTOR,
typename SCALAR,
251 template<
typename INTEGRATORDATACONT,
typename VECTOR,
typename SCALAR,
253 template<
typename PROBLEM>
256 PROBLEM& pde, VECTOR &residual,
bool apply_boundary_values)
260 const auto& dof_handler =
261 pde.GetBaseProblem().GetSpaceTimeHandler()->GetDoFHandler();
263 assert(dof_handler.size() == 2);
265 const auto tria_element_list = GridTools::get_finest_common_cells (dof_handler[0]->GetDEALDoFHandler().get_tria(),
266 dof_handler[1]->GetDEALDoFHandler().get_tria());
267 const auto element_list = GridTools::get_finest_common_cells (dof_handler[0]->GetDEALDoFHandler(),
268 dof_handler[1]->GetDEALDoFHandler());
270 auto element_iter = element_list.begin();
271 auto tria_element_iter = tria_element_list.begin();
273 std::vector<decltype(tria_element_iter->first)> tria_element(2);
274 tria_element[0] = tria_element_iter->first;
275 tria_element[1] = tria_element_iter->second;
277 std::vector<decltype(element_iter->first)> element(2);
278 element[0] = element_iter->first;
279 element[1] = element_iter->second;
280 int coarse_index = 0;
284 idc_.InitializeMMEDC(pde.GetUpdateFlags(),
285 *(pde.GetBaseProblem().GetSpaceTimeHandler()), element, tria_element,
286 this->GetParamData(), this->GetDomainData());
287 auto& edc = idc_.GetMultimeshElementDataContainer();
289 bool need_interfaces = pde.HasInterfaces();
290 idc_.InitializeMMFDC(pde.GetFaceUpdateFlags(),
291 *(pde.GetBaseProblem().GetSpaceTimeHandler()),
294 this->GetParamData(),
295 this->GetDomainData(),
297 auto& fdc = idc_.GetMultimeshFaceDataContainer();
299 for(; element_iter != element_list.end(); element_iter++)
301 element[0] = element_iter->first;
302 element[1] = element_iter->second;
303 tria_element[0] = tria_element_iter->first;
304 tria_element[1] = tria_element_iter->second;
305 FullMatrix<SCALAR> prolong_matrix;
307 if(element[0]->has_children())
309 prolong_matrix = IdentityMatrix(element[1]->get_fe().dofs_per_cell);
315 if(element[1]->has_children())
317 prolong_matrix = IdentityMatrix(element[0]->get_fe().dofs_per_cell);
323 assert(element.size() ==2);
324 coarse_index = fine_index = 2;
327 ComputeNonlinearResidual_Recursive(pde,residual,element,tria_element,prolong_matrix,coarse_index,fine_index,edc,fdc);
331 AddPresetRightHandSide(-1.,residual);
333 if (apply_boundary_values)
335 ApplyNewtonBoundaryValues(pde, residual);
341 template<
typename INTEGRATORDATACONT,
typename VECTOR,
typename SCALAR,
343 template<
typename PROBLEM>
346 PROBLEM& pde, VECTOR &residual,
bool apply_boundary_values)
349 throw DOpEException(
"This function needs to be implemented!",
"IntegratorMultiMesh::ComputeNonlinearLhs");
355 template<
typename INTEGRATORDATACONT,
typename VECTOR,
typename SCALAR,
357 template<
typename PROBLEM>
360 PROBLEM& pde, VECTOR &residual,
bool apply_boundary_values)
364 const auto& dof_handler =
365 pde.GetBaseProblem().GetSpaceTimeHandler()->GetDoFHandler();
367 assert(dof_handler.size() == 2);
369 const auto tria_element_list = GridTools::get_finest_common_cells (dof_handler[0]->GetDEALDoFHandler().get_tria(),
370 dof_handler[1]->GetDEALDoFHandler().get_tria());
371 const auto element_list = GridTools::get_finest_common_cells (dof_handler[0]->GetDEALDoFHandler(),
372 dof_handler[1]->GetDEALDoFHandler());
374 auto element_iter = element_list.begin();
375 auto tria_element_iter = tria_element_list.begin();
377 std::vector<decltype(tria_element_iter->first)> tria_element(2);
378 tria_element[0] = tria_element_iter->first;
379 tria_element[1] = tria_element_iter->second;
381 std::vector<decltype(element_iter->first)> element(2);
382 element[0] = element_iter->first;
383 element[1] = element_iter->second;
384 int coarse_index = 0;
388 idc_.InitializeMMEDC(pde.GetUpdateFlags(),
389 *(pde.GetBaseProblem().GetSpaceTimeHandler()), element, tria_element,
390 this->GetParamData(), this->GetDomainData());
391 auto& edc = idc_.GetMultimeshElementDataContainer();
393 bool need_interfaces = pde.HasInterfaces();
394 idc_.InitializeMMFDC(pde.GetFaceUpdateFlags(),
395 *(pde.GetBaseProblem().GetSpaceTimeHandler()),
398 this->GetParamData(),
399 this->GetDomainData(),
401 auto& fdc = idc_.GetMultimeshFaceDataContainer();
403 for(; element_iter != element_list.end(); element_iter++)
405 element[0] = element_iter->first;
406 element[1] = element_iter->second;
407 tria_element[0] = tria_element_iter->first;
408 tria_element[1] = tria_element_iter->second;
409 FullMatrix<SCALAR> prolong_matrix;
411 if(element[0]->has_children())
413 prolong_matrix = IdentityMatrix(element[1]->get_fe().dofs_per_cell);
419 if(element[1]->has_children())
421 prolong_matrix = IdentityMatrix(element[0]->get_fe().dofs_per_cell);
427 assert(element.size() ==2);
428 coarse_index = fine_index = 2;
431 ComputeNonlinearRhs_Recursive(pde,residual,element,tria_element,prolong_matrix,coarse_index,fine_index,edc,fdc);
435 AddPresetRightHandSide(1.,residual);
437 if (apply_boundary_values)
439 ApplyNewtonBoundaryValues(pde, residual);
445 template<
typename INTEGRATORDATACONT,
typename VECTOR,
typename SCALAR,
447 template<
typename PROBLEM,
typename MATRIX>
450 PROBLEM& pde, MATRIX &matrix)
454 const auto& dof_handler =
455 pde.GetBaseProblem().GetSpaceTimeHandler()->GetDoFHandler();
457 assert(dof_handler.size() == 2);
459 const auto tria_element_list = GridTools::get_finest_common_cells (dof_handler[0]->GetDEALDoFHandler().get_tria(),
460 dof_handler[1]->GetDEALDoFHandler().get_tria());
461 const auto element_list = GridTools::get_finest_common_cells (dof_handler[0]->GetDEALDoFHandler(),
462 dof_handler[1]->GetDEALDoFHandler());
464 auto element_iter = element_list.begin();
465 auto tria_element_iter = tria_element_list.begin();
467 std::vector<decltype(tria_element_iter->first)> tria_element(2);
468 tria_element[0] = tria_element_iter->first;
469 tria_element[1] = tria_element_iter->second;
471 std::vector<decltype(element_iter->first)> element(2);
472 element[0] = element_iter->first;
473 element[1] = element_iter->second;
474 int coarse_index = 0;
478 idc_.InitializeMMEDC(pde.GetUpdateFlags(),
479 *(pde.GetBaseProblem().GetSpaceTimeHandler()), element, tria_element,
480 this->GetParamData(), this->GetDomainData());
481 auto& edc = idc_.GetMultimeshElementDataContainer();
483 bool need_interfaces = pde.HasInterfaces();
484 idc_.InitializeMMFDC(pde.GetFaceUpdateFlags(),
485 *(pde.GetBaseProblem().GetSpaceTimeHandler()),
488 this->GetParamData(),
489 this->GetDomainData(),
491 auto & fdc = idc_.GetMultimeshFaceDataContainer();
493 for(; element_iter != element_list.end(); element_iter++)
495 element[0] = element_iter->first;
496 element[1] = element_iter->second;
497 tria_element[0] = tria_element_iter->first;
498 tria_element[1] = tria_element_iter->second;
499 FullMatrix<SCALAR> prolong_matrix;
501 if(element[0]->has_children())
503 prolong_matrix = IdentityMatrix(element[1]->get_fe().dofs_per_cell);
509 if(element[1]->has_children())
511 prolong_matrix = IdentityMatrix(element[0]->get_fe().dofs_per_cell);
517 assert(element.size() ==2);
518 coarse_index = fine_index = 2;
521 ComputeMatrix_Recursive(pde,matrix,element,tria_element,prolong_matrix,coarse_index,fine_index,edc,fdc);
526 template<
typename INTEGRATORDATACONT,
typename VECTOR,
typename SCALAR,
528 template<
typename PROBLEM>
535 const auto& dof_handler =
536 pde.GetBaseProblem().GetSpaceTimeHandler()->GetDoFHandler();
538 assert(dof_handler.size() == 2);
540 const auto tria_element_list = GridTools::get_finest_common_cells (dof_handler[0]->GetDEALDoFHandler().get_tria(),
541 dof_handler[1]->GetDEALDoFHandler().get_tria());
542 const auto element_list = GridTools::get_finest_common_cells (dof_handler[0]->GetDEALDoFHandler(),
543 dof_handler[1]->GetDEALDoFHandler());
545 auto element_iter = element_list.begin();
546 auto tria_element_iter = tria_element_list.begin();
548 std::vector<decltype(tria_element_iter->first)> tria_element(2);
549 tria_element[0] = tria_element_iter->first;
550 tria_element[1] = tria_element_iter->second;
552 std::vector<decltype(element_iter->first)> element(2);
553 element[0] = element_iter->first;
554 element[1] = element_iter->second;
555 int coarse_index = 0;
560 throw DOpEException(
"This function should not be called when faces are needed!",
561 "IntegratorMultiMesh::ComputeDomainScalar");
565 idc_.InitializeMMEDC(pde.GetUpdateFlags(),
566 *(pde.GetBaseProblem().GetSpaceTimeHandler()), element, tria_element,
567 this->GetParamData(), this->GetDomainData());
568 auto& edc = idc_.GetMultimeshElementDataContainer();
570 for(; element_iter != element_list.end(); element_iter++)
572 element[0] = element_iter->first;
573 element[1] = element_iter->second;
574 tria_element[0] = tria_element_iter->first;
575 tria_element[1] = tria_element_iter->second;
576 FullMatrix<SCALAR> prolong_matrix;
578 if(element[0]->has_children())
580 prolong_matrix = IdentityMatrix(element[1]->get_fe().dofs_per_cell);
586 if(element[1]->has_children())
588 prolong_matrix = IdentityMatrix(element[0]->get_fe().dofs_per_cell);
594 assert(element.size() ==2);
595 coarse_index = fine_index = 2;
598 ret += ComputeDomainScalar_Recursive(pde,element,tria_element,prolong_matrix,coarse_index,fine_index,edc);
607 template<
typename INTEGRATORDATACONT,
typename VECTOR,
typename SCALAR,
609 template<
typename PROBLEM>
617 ret += pde.PointFunctional(this->GetParamData(),
618 this->GetDomainData());
625 template<
typename INTEGRATORDATACONT,
typename VECTOR,
typename SCALAR,
627 template<
typename PROBLEM>
635 const auto& dof_handler =
636 pde.GetBaseProblem().GetSpaceTimeHandler()->GetDoFHandler();
638 const auto tria_element_list = GridTools::get_finest_common_cells (dof_handler[0]->GetDEALDoFHandler().get_tria(),
639 dof_handler[1]->GetDEALDoFHandler().get_tria());
640 const auto element_list = GridTools::get_finest_common_cells (dof_handler[0]->GetDEALDoFHandler(),
641 dof_handler[1]->GetDEALDoFHandler());
643 auto element_iter = element_list.begin();
644 auto tria_element_iter = tria_element_list.begin();
646 std::vector<decltype(tria_element_iter->first)> tria_element(2);
647 tria_element[0] = tria_element_iter->first;
648 tria_element[1] = tria_element_iter->second;
650 std::vector<decltype(element_iter->first)> element(2);
651 element[0] = element_iter->first;
652 element[1] = element_iter->second;
653 int coarse_index = 0;
657 idc_.InitializeMMFDC(pde.GetFaceUpdateFlags(),
658 *(pde.GetBaseProblem().GetSpaceTimeHandler()),
659 element, tria_element,
660 this->GetParamData(),
661 this->GetDomainData());
662 auto & fdc = idc_.GetMultimeshFaceDataContainer();
664 std::vector<unsigned int> boundary_functional_colors = pde.GetBoundaryFunctionalColors();
665 bool need_boundary_integrals = (boundary_functional_colors.size() > 0);
666 if(!need_boundary_integrals)
668 throw DOpEException(
"No boundary colors given!",
"IntegratorMultiMesh::ComputeBoundaryScalar");
671 for(; element_iter != element_list.end(); element_iter++)
673 element[0] = element_iter->first;
674 element[1] = element_iter->second;
675 tria_element[0] = tria_element_iter->first;
676 tria_element[1] = tria_element_iter->second;
677 FullMatrix<SCALAR> prolong_matrix;
679 if(element[0]->has_children())
681 prolong_matrix = IdentityMatrix(element[1]->get_fe().dofs_per_cell);
687 if(element[1]->has_children())
689 prolong_matrix = IdentityMatrix(element[0]->get_fe().dofs_per_cell);
695 assert(element.size() ==2);
696 coarse_index = fine_index = 2;
699 ret += ComputeBoundaryScalar_Recursive(pde,element,tria_element,prolong_matrix,coarse_index,fine_index,fdc);
707 template<
typename INTEGRATORDATACONT,
typename VECTOR,
typename SCALAR,
709 template<
typename PROBLEM>
715 throw DOpEException(
"This function needs to be implemented!",
"IntegratorMultiMesh::ComputeFaceScalar");
773 template<
typename INTEGRATORDATACONT,
typename VECTOR,
typename SCALAR,
775 template<
typename PROBLEM>
783 ret = pde.AlgebraicFunctional(this->GetParamData(),
784 this->GetDomainData());
791 template <
typename INTEGRATORDATACONT,
typename VECTOR,
typename SCALAR,
int dim>
792 template<
typename PROBLEM>
797 pde.AlgebraicResidual(residual,this->GetParamData(),this->GetDomainData());
799 AddPresetRightHandSide(-1.,residual);
804 template <
typename INTEGRATORDATACONT,
typename VECTOR,
typename SCALAR,
int dim>
805 template<
typename PROBLEM>
810 pde.ComputeLocalControlConstraints(constraints,this->GetParamData(),this->GetDomainData());
815 template<
typename INTEGRATORDATACONT,
typename VECTOR,
typename SCALAR,
817 template<
typename PROBLEM>
820 PROBLEM& pde, VECTOR &u)
827 std::vector<unsigned int> dirichlet_colors = pde.GetDirichletColors();
828 for (
unsigned int i = 0; i < dirichlet_colors.size(); i++)
830 unsigned int color = dirichlet_colors[i];
831 std::vector<bool> comp_mask = pde.GetDirichletCompMask(color);
832 std::map<unsigned int, SCALAR> boundary_values;
834 InterpolateBoundaryValues(pde.GetBaseProblem().GetSpaceTimeHandler()->GetDoFHandler()[0], color, pde.GetDirichletValues(color, this->GetParamData(),
835 this->GetDomainData()), boundary_values, comp_mask );
837 for (
typename std::map<unsigned int, SCALAR>::const_iterator p =
838 boundary_values.begin(); p != boundary_values.end(); p++)
840 u(p->first) = p->second;
847 template<
typename INTEGRATORDATACONT,
typename VECTOR,
typename SCALAR,
849 template<
typename PROBLEM>
852 PROBLEM& pde, VECTOR &u)
857 pde.GetDoFConstraints().condense(u);
858 std::vector<unsigned int> dirichlet_colors = pde.GetDirichletColors();
859 for (
unsigned int i = 0; i < dirichlet_colors.size(); i++)
861 unsigned int color = dirichlet_colors[i];
862 std::vector<bool> comp_mask = pde.GetDirichletCompMask(color);
863 std::map<unsigned int, SCALAR> boundary_values;
866 InterpolateBoundaryValues(
867 pde.GetBaseProblem().GetSpaceTimeHandler()->GetDoFHandler()[0],
868 color, dealii::ZeroFunction<dim>(comp_mask.size()),
869 boundary_values, comp_mask);
871 for (
typename std::map<unsigned int, SCALAR>::const_iterator p =
872 boundary_values.begin(); p != boundary_values.end(); p++)
874 u(p->first) = p->second;
880 template<
typename INTEGRATORDATACONT,
typename VECTOR,
typename SCALAR,
882 template<
typename PROBLEM,
typename MATRIX>
885 PROBLEM& pde, MATRIX& matrix, VECTOR &rhs, VECTOR &sol)
889 pde.GetDoFConstraints().condense(rhs);
890 pde.GetDoFConstraints().condense(matrix);
891 std::vector<unsigned int> dirichlet_colors = pde.GetDirichletColors();
892 for (
unsigned int i = 0; i < dirichlet_colors.size(); i++)
894 unsigned int color = dirichlet_colors[i];
895 std::vector<bool> comp_mask = pde.GetDirichletCompMask(color);
896 std::map<unsigned int, SCALAR> boundary_values;
898 InterpolateBoundaryValues(
899 pde.GetBaseProblem().GetSpaceTimeHandler()->GetDoFHandler()[0],
900 color, dealii::ZeroFunction<dim>(comp_mask.size()),
901 boundary_values, comp_mask);
903 dealii::MatrixTools::apply_boundary_values(boundary_values, matrix,
910 template<
typename INTEGRATORDATACONT,
typename VECTOR,
typename SCALAR,
914 std::string name,
const VECTOR* new_data)
916 if (domain_data_.find(name) != domain_data_.end())
919 "Adding multiple Data with name " + name +
" is prohibited!",
920 "IntegratorMultiMesh::AddDomainData");
922 domain_data_.insert(std::pair<std::string, const VECTOR*>(name, new_data));
927 template<
typename INTEGRATORDATACONT,
typename VECTOR,
typename SCALAR,
933 typename std::map<std::string, const VECTOR *>::iterator it =
934 domain_data_.find(name);
935 if (it == domain_data_.end())
938 "Deleting Data " + name +
" is impossible! Data not found",
939 "IntegratorMultiMesh::DeleteDomainData");
941 domain_data_.erase(it);
945 template<
typename INTEGRATORDATACONT,
typename VECTOR,
typename SCALAR,
949 VECTOR &residual)
const
951 typename std::map<std::string, const VECTOR *>::const_iterator it =
952 domain_data_.find(
"fixed_rhs");
953 if (it != domain_data_.end())
955 assert(residual.size() == it->second->size());
956 residual.add(s,*(it->second));
962 template<
typename INTEGRATORDATACONT,
typename VECTOR,
typename SCALAR,
964 const std::map<std::string, const VECTOR*>&
972 template<
typename INTEGRATORDATACONT,
typename VECTOR,
typename SCALAR,
976 std::string name,
const dealii::Vector<SCALAR>* new_data)
978 if (param_data_.find(name) != param_data_.end())
981 "Adding multiple Data with name " + name +
" is prohibited!",
982 "IntegratorMultiMesh::AddParamData");
985 std::pair<std::string,
const dealii::Vector<SCALAR>*>(name, new_data));
990 template<
typename INTEGRATORDATACONT,
typename VECTOR,
typename SCALAR,
996 typename std::map<std::string, const dealii::Vector<SCALAR>*>::iterator
997 it = param_data_.find(name);
998 if (it == param_data_.end())
1001 "Deleting Data " + name +
" is impossible! Data not found",
1002 "IntegratorMultiMesh::DeleteParamData");
1004 param_data_.erase(it);
1009 template<
typename INTEGRATORDATACONT,
typename VECTOR,
typename SCALAR,
1011 const std::map<std::string, const dealii::Vector<SCALAR>*>&
1019 template<
typename INTEGRATORDATACONT,
typename VECTOR,
typename SCALAR,
1030 template<
typename INTEGRATORDATACONT,
typename VECTOR,
typename SCALAR,
1032 template<
template<
int,
int>
class DH>
1036 const unsigned int color,
const dealii::Function<dim>&
function,
1037 std::map<unsigned int, SCALAR>& boundary_values,
1038 const std::vector<bool>& comp_mask)
const
1040 dealii::VectorTools::interpolate_boundary_values(
1042 boundary_values, comp_mask);
1047 template<
typename INTEGRATORDATACONT,
typename VECTOR,
typename SCALAR,
int dim>
1048 template<
typename PROBLEM,
template<
int,
int>
class DH>
1049 void IntegratorMultiMesh<INTEGRATORDATACONT, VECTOR, SCALAR, dim>::ComputeNonlinearResidual_Recursive(
1052 typename std::vector<
typename DH<dim, dim>::cell_iterator> &element,
1053 typename std::vector<
typename dealii::Triangulation<dim>::cell_iterator> &tria_element,
1054 const FullMatrix<SCALAR>& prolong_matrix,
unsigned int coarse_index,
unsigned int fine_index,
1055 Multimesh_ElementDataContainer<DH, VECTOR, dim>& edc,Multimesh_FaceDataContainer<DH, VECTOR, dim>& fdc)
1057 if(!element[0]->has_children() && ! element[1]->has_children())
1059 unsigned int dofs_per_element;
1060 dealii::Vector<SCALAR> local_vector;
1061 std::vector<unsigned int> local_dof_indices;
1063 bool need_faces = pde.HasFaces();
1064 std::vector<unsigned int> boundary_equation_colors = pde.GetBoundaryEquationColors();
1065 bool need_boundary_integrals = (boundary_equation_colors.size() > 0);
1066 bool need_interfaces = pde.HasInterfaces();
1068 edc.
ReInit(coarse_index,fine_index,prolong_matrix);
1070 dofs_per_element = element[0]->get_fe().dofs_per_cell;
1072 local_vector.reinit(dofs_per_element);
1075 local_dof_indices.resize(0);
1076 local_dof_indices.resize(dofs_per_element, 0);
1080 pde.ElementEquation(edc, local_vector, 1., 1.);
1081 pde.ElementRhs(edc, local_vector, -1.);
1084 if(need_faces || need_interfaces)
1086 throw DOpEException(
" Faces on multiple meshes not implemented yet!",
1087 "IntegratorMultiMesh::ComputeNonlinearResidual_Recursive");
1089 unsigned int b_index = fine_index%2;
1092 if(need_boundary_integrals && element[b_index]->at_boundary())
1094 for (
unsigned int face=0; face < dealii::GeometryInfo<dim>::faces_per_cell; ++face)
1096 #if DEAL_II_VERSION_GTE(8,3,0)
1097 if (element[b_index]->face(face)->at_boundary()
1099 (find(boundary_equation_colors.begin(),boundary_equation_colors.end(),
1100 element[b_index]->face(face)->boundary_id()) != boundary_equation_colors.end()))
1102 if (element[b_index]->face(face)->at_boundary()
1104 (find(boundary_equation_colors.begin(),boundary_equation_colors.end(),
1105 element[b_index]->face(face)->boundary_indicator()) != boundary_equation_colors.end()))
1108 fdc.ReInit(coarse_index,fine_index,prolong_matrix,face);
1109 pde.BoundaryEquation(fdc,local_vector, 1., 1.);
1110 pde.BoundaryRhs(fdc,local_vector,-1.);
1140 if(coarse_index == 0)
1142 dealii::Vector<SCALAR> tmp(dofs_per_element);
1143 prolong_matrix.Tvmult(tmp,local_vector);
1146 element[0]->get_dof_indices(local_dof_indices);
1147 for (
unsigned int i = 0; i < dofs_per_element; ++i)
1149 residual(local_dof_indices[i]) += tmp(i);
1155 element[0]->get_dof_indices(local_dof_indices);
1156 for (
unsigned int i = 0; i < dofs_per_element; ++i)
1158 residual(local_dof_indices[i]) += local_vector(i);
1165 assert(fine_index != coarse_index);
1166 assert(element[fine_index]->has_children());
1167 assert(!element[coarse_index]->has_children());
1168 assert(tria_element[fine_index]->has_children());
1169 assert(!tria_element[coarse_index]->has_children());
1171 unsigned int local_n_dofs = element[coarse_index]->get_fe().dofs_per_cell;
1173 typename DH<dim, dim>::cell_iterator dofh_fine = element[fine_index];
1174 typename dealii::Triangulation<dim>::cell_iterator tria_fine = tria_element[fine_index];
1176 for (
unsigned int child=0; child<GeometryInfo<dim>::max_children_per_cell;++child)
1178 FullMatrix<SCALAR> new_matrix(local_n_dofs);
1179 element[coarse_index]->get_fe().get_prolongation_matrix(child).mmult (new_matrix,
1181 element[fine_index] = dofh_fine->child(child);
1182 tria_element[fine_index] = tria_fine->child(child);
1184 ComputeNonlinearResidual_Recursive(pde,residual,element,tria_element,new_matrix, coarse_index, fine_index, edc, fdc);
1190 template<
typename INTEGRATORDATACONT,
typename VECTOR,
typename SCALAR,
int dim>
1191 template<
typename PROBLEM,
template<
int,
int>
class DH>
1192 void IntegratorMultiMesh<INTEGRATORDATACONT, VECTOR, SCALAR, dim>::ComputeNonlinearRhs_Recursive(
1195 typename std::vector<
typename DH<dim, dim>::cell_iterator> &element,
1196 typename std::vector<
typename dealii::Triangulation<dim>::cell_iterator> &tria_element,
1197 const FullMatrix<SCALAR>& prolong_matrix,
unsigned int coarse_index,
unsigned int fine_index,
1198 Multimesh_ElementDataContainer<DH, VECTOR, dim>& edc,Multimesh_FaceDataContainer<DH, VECTOR, dim>& fdc)
1200 if(!element[0]->has_children() && ! element[1]->has_children())
1202 unsigned int dofs_per_element;
1203 dealii::Vector<SCALAR> local_vector;
1204 std::vector<unsigned int> local_dof_indices;
1206 bool need_faces = pde.HasFaces();
1207 std::vector<unsigned int> boundary_equation_colors = pde.GetBoundaryEquationColors();
1208 bool need_boundary_integrals = (boundary_equation_colors.size() > 0);
1209 bool need_interfaces = pde.HasInterfaces();
1211 edc.ReInit(coarse_index,fine_index,prolong_matrix);
1213 dofs_per_element = element[0]->get_fe().dofs_per_cell;
1215 local_vector.reinit(dofs_per_element);
1218 local_dof_indices.resize(0);
1219 local_dof_indices.resize(dofs_per_element, 0);
1223 pde.ElementRhs(edc, local_vector, 1.);
1228 throw DOpEException(
" Faces on multiple meshes not implemented yet!",
1229 "IntegratorMultiMesh::ComputeNonlinearRhs_Recursive");
1231 if(need_interfaces )
1233 throw DOpEException(
" Faces on multiple meshes not implemented yet!",
1234 "IntegratorMultiMesh::ComputeNonlinearRhs_Recursive");
1236 unsigned int b_index = fine_index%2;
1239 if(need_boundary_integrals && element[b_index]->at_boundary())
1241 for (
unsigned int face=0; face < dealii::GeometryInfo<dim>::faces_per_cell; ++face)
1243 #if DEAL_II_VERSION_GTE(8,3,0)
1244 if (element[b_index]->face(face)->at_boundary()
1246 (find(boundary_equation_colors.begin(),boundary_equation_colors.end(),
1247 element[b_index]->face(face)->boundary_id()) != boundary_equation_colors.end()))
1249 if (element[b_index]->face(face)->at_boundary()
1251 (find(boundary_equation_colors.begin(),boundary_equation_colors.end(),
1252 element[b_index]->face(face)->boundary_indicator()) != boundary_equation_colors.end()))
1255 fdc.ReInit(coarse_index,fine_index,prolong_matrix,face);
1256 pde.BoundaryRhs(fdc,local_vector,1.);
1271 if(coarse_index == 0)
1273 dealii::Vector<SCALAR> tmp(dofs_per_element);
1274 prolong_matrix.Tvmult(tmp,local_vector);
1277 element[0]->get_dof_indices(local_dof_indices);
1278 for (
unsigned int i = 0; i < dofs_per_element; ++i)
1280 residual(local_dof_indices[i]) += tmp(i);
1286 element[0]->get_dof_indices(local_dof_indices);
1287 for (
unsigned int i = 0; i < dofs_per_element; ++i)
1289 residual(local_dof_indices[i]) += local_vector(i);
1296 assert(fine_index != coarse_index);
1297 assert(element[fine_index]->has_children());
1298 assert(!element[coarse_index]->has_children());
1299 assert(tria_element[fine_index]->has_children());
1300 assert(!tria_element[coarse_index]->has_children());
1302 unsigned int local_n_dofs = element[coarse_index]->get_fe().dofs_per_cell;
1304 typename DH<dim, dim>::cell_iterator dofh_fine = element[fine_index];
1305 typename dealii::Triangulation<dim>::cell_iterator tria_fine = tria_element[fine_index];
1307 for (
unsigned int child=0; child<GeometryInfo<dim>::max_children_per_cell;++child)
1309 FullMatrix<SCALAR> new_matrix(local_n_dofs);
1310 element[coarse_index]->get_fe().get_prolongation_matrix(child).mmult (new_matrix,
1312 element[fine_index] = dofh_fine->child(child);
1313 tria_element[fine_index] = tria_fine->child(child);
1315 ComputeNonlinearRhs_Recursive(pde,residual,element,tria_element,new_matrix, coarse_index, fine_index, edc, fdc);
1322 template<
typename INTEGRATORDATACONT,
typename VECTOR,
typename SCALAR,
1324 template<
typename PROBLEM,
typename MATRIX,
template<
int,
int>
class DH>
1326 IntegratorMultiMesh<INTEGRATORDATACONT, VECTOR, SCALAR, dim>::ComputeMatrix_Recursive(
1327 PROBLEM& pde, MATRIX &matrix,
typename std::vector<
typename DH<dim, dim>::cell_iterator>& element,
1328 typename std::vector<
typename dealii::Triangulation<dim>::cell_iterator>& tria_element,
1329 const FullMatrix<SCALAR>& prolong_matrix,
unsigned int coarse_index,
unsigned int fine_index,
1330 Multimesh_ElementDataContainer<DH, VECTOR, dim>& edc,
1331 Multimesh_FaceDataContainer<DH, VECTOR, dim>& fdc)
1334 if(!element[0]->has_children() && ! element[1]->has_children())
1336 unsigned int dofs_per_element;
1337 std::vector<unsigned int> local_dof_indices;
1339 bool need_faces = pde.HasFaces();
1340 bool need_interfaces = pde.HasInterfaces();
1341 std::vector<unsigned int> boundary_equation_colors = pde.GetBoundaryEquationColors();
1342 bool need_boundary_integrals = (boundary_equation_colors.size() > 0);
1344 edc.ReInit(coarse_index,fine_index,prolong_matrix);
1345 dofs_per_element = element[0]->get_fe().dofs_per_cell;
1347 dealii::FullMatrix<SCALAR> local_matrix(dofs_per_element,
1351 local_dof_indices.resize(0);
1352 local_dof_indices.resize(dofs_per_element, 0);
1353 pde.ElementMatrix(edc, local_matrix);
1356 if(need_faces || need_interfaces)
1358 throw DOpEException(
" Faces on multiple meshes not implemented yet!",
1359 "IntegratorMultiMesh::ComputeMatrix_Recursive");
1361 unsigned int b_index = fine_index%2;
1363 if(need_boundary_integrals && element[b_index]->at_boundary())
1366 for (
unsigned int face=0; face < dealii::GeometryInfo<dim>::faces_per_cell; ++face)
1368 #if DEAL_II_VERSION_GTE(8,3,0)
1369 if (element[b_index]->face(face)->at_boundary()
1371 (find(boundary_equation_colors.begin(),boundary_equation_colors.end(),
1372 element[b_index]->face(face)->boundary_id()) != boundary_equation_colors.end()))
1374 if (element[b_index]->face(face)->at_boundary()
1376 (find(boundary_equation_colors.begin(),boundary_equation_colors.end(),
1377 element[b_index]->face(face)->boundary_indicator()) != boundary_equation_colors.end()))
1380 fdc.ReInit(coarse_index,fine_index,prolong_matrix,face);
1381 pde.BoundaryMatrix(fdc, local_matrix);
1429 if(coarse_index == 0)
1431 dealii::FullMatrix<SCALAR> tmp(dofs_per_element);
1433 prolong_matrix.Tmmult(tmp,local_matrix);
1435 tmp.mmult(local_matrix,prolong_matrix);
1438 element[0]->get_dof_indices(local_dof_indices);
1439 for (
unsigned int i = 0; i < dofs_per_element; ++i)
1441 for (
unsigned int j = 0; j < dofs_per_element; ++j)
1443 matrix.add(local_dof_indices[i], local_dof_indices[j],
1444 local_matrix(i, j));
1451 element[0]->get_dof_indices(local_dof_indices);
1452 for (
unsigned int i = 0; i < dofs_per_element; ++i)
1454 for (
unsigned int j = 0; j < dofs_per_element; ++j)
1456 matrix.add(local_dof_indices[i], local_dof_indices[j],
1457 local_matrix(i, j));
1465 assert(fine_index != coarse_index);
1466 assert(element[fine_index]->has_children());
1467 assert(!element[coarse_index]->has_children());
1468 assert(tria_element[fine_index]->has_children());
1469 assert(!tria_element[coarse_index]->has_children());
1471 unsigned int local_n_dofs = element[coarse_index]->get_fe().dofs_per_cell;
1473 typename DH<dim, dim>::cell_iterator dofh_fine = element[fine_index];
1474 typename dealii::Triangulation<dim>::cell_iterator tria_fine = tria_element[fine_index];
1476 for (
unsigned int child=0; child<GeometryInfo<dim>::max_children_per_cell;++child)
1478 FullMatrix<SCALAR> new_matrix(local_n_dofs);
1479 element[coarse_index]->get_fe().get_prolongation_matrix(child).mmult (new_matrix,
1481 element[fine_index] = dofh_fine->child(child);
1482 tria_element[fine_index] = tria_fine->child(child);
1484 ComputeMatrix_Recursive(pde,matrix,element,tria_element,new_matrix, coarse_index, fine_index, edc, fdc);
1491 template<
typename INTEGRATORDATACONT,
typename VECTOR,
typename SCALAR,
int dim>
1492 template<
typename PROBLEM,
template<
int,
int>
class DH>
1493 SCALAR IntegratorMultiMesh<INTEGRATORDATACONT, VECTOR, SCALAR, dim>::ComputeDomainScalar_Recursive(
1495 typename std::vector<
typename DH<dim, dim>::cell_iterator> &element,
1496 typename std::vector<
typename dealii::Triangulation<dim>::cell_iterator> &tria_element,
1497 const FullMatrix<SCALAR>& prolong_matrix,
unsigned int coarse_index,
unsigned int fine_index,
1498 Multimesh_ElementDataContainer<DH, VECTOR, dim>& edc)
1500 if(!element[0]->has_children() && ! element[1]->has_children())
1503 edc.ReInit(coarse_index,fine_index,prolong_matrix);
1504 ret += pde.ElementFunctional(edc);
1509 assert(fine_index != coarse_index);
1510 assert(element[fine_index]->has_children());
1511 assert(!element[coarse_index]->has_children());
1512 assert(tria_element[fine_index]->has_children());
1513 assert(!tria_element[coarse_index]->has_children());
1515 unsigned int local_n_dofs = element[coarse_index]->get_fe().dofs_per_cell;
1517 typename DH<dim, dim>::cell_iterator dofh_fine = element[fine_index];
1518 typename dealii::Triangulation<dim>::cell_iterator tria_fine = tria_element[fine_index];
1520 for (
unsigned int child=0; child<GeometryInfo<dim>::max_children_per_cell;++child)
1522 FullMatrix<SCALAR> new_matrix(local_n_dofs);
1523 element[coarse_index]->get_fe().get_prolongation_matrix(child).mmult (new_matrix,
1525 element[fine_index] = dofh_fine->child(child);
1526 tria_element[fine_index] = tria_fine->child(child);
1528 ret += ComputeDomainScalar_Recursive(pde,element,tria_element,new_matrix, coarse_index, fine_index, edc);
1535 template<
typename INTEGRATORDATACONT,
typename VECTOR,
typename SCALAR,
int dim>
1536 template<
typename PROBLEM,
template<
int,
int>
class DH>
1537 SCALAR IntegratorMultiMesh<INTEGRATORDATACONT, VECTOR, SCALAR, dim>::ComputeBoundaryScalar_Recursive(
1539 typename std::vector<
typename DH<dim, dim>::cell_iterator> &element,
1540 typename std::vector<
typename dealii::Triangulation<dim>::cell_iterator> &tria_element,
1541 const FullMatrix<SCALAR>& prolong_matrix,
unsigned int coarse_index,
unsigned int fine_index,
1542 Multimesh_FaceDataContainer<DH, VECTOR, dim>& fdc)
1544 if(!element[0]->has_children() && ! element[1]->has_children())
1547 std::vector<unsigned int> boundary_functional_colors = pde.GetBoundaryFunctionalColors();
1548 unsigned int b_index = fine_index%2;
1550 for (
unsigned int face=0; face < dealii::GeometryInfo<dim>::faces_per_cell; ++face)
1552 #if DEAL_II_VERSION_GTE(8,3,0)
1553 if (element[b_index]->face(face)->at_boundary()
1555 (find(boundary_functional_colors.begin(),boundary_functional_colors.end(),
1556 element[b_index]->face(face)->boundary_id()) != boundary_functional_colors.end()))
1558 if (element[b_index]->face(face)->at_boundary()
1560 (find(boundary_functional_colors.begin(),boundary_functional_colors.end(),
1561 element[b_index]->face(face)->boundary_indicator()) != boundary_functional_colors.end()))
1564 fdc.ReInit(coarse_index,fine_index,prolong_matrix,face);
1565 ret += pde.BoundaryFunctional(fdc);
1572 assert(fine_index != coarse_index);
1573 assert(element[fine_index]->has_children());
1574 assert(!element[coarse_index]->has_children());
1575 assert(tria_element[fine_index]->has_children());
1576 assert(!tria_element[coarse_index]->has_children());
1578 unsigned int local_n_dofs = element[coarse_index]->get_fe().dofs_per_cell;
1580 typename DH<dim, dim>::cell_iterator dofh_fine = element[fine_index];
1581 typename dealii::Triangulation<dim>::cell_iterator tria_fine = tria_element[fine_index];
1583 for (
unsigned int child=0; child<GeometryInfo<dim>::max_children_per_cell;++child)
1585 FullMatrix<SCALAR> new_matrix(local_n_dofs);
1586 element[coarse_index]->get_fe().get_prolongation_matrix(child).mmult (new_matrix,
1588 element[fine_index] = dofh_fine->child(child);
1589 tria_element[fine_index] = tria_fine->child(child);
1591 ret += ComputeBoundaryScalar_Recursive(pde,element,tria_element,new_matrix, coarse_index, fine_index, fdc);
const std::map< std::string, const VECTOR * > & GetDomainData() const
Definition: integrator_multimesh.h:965
void ComputeLocalControlConstraints(PROBLEM &pde, VECTOR &constraints)
Definition: integrator_multimesh.h:807
SCALAR ComputeBoundaryScalar(PROBLEM &pde)
Definition: integrator_multimesh.h:629
Definition: integrator_multimesh.h:61
SCALAR ComputeFaceScalar(PROBLEM &pde)
Definition: integrator_multimesh.h:711
SCALAR ComputeDomainScalar(PROBLEM &pde)
Definition: integrator_multimesh.h:530
void ComputeNonlinearLhs(PROBLEM &pde, VECTOR &residual, bool apply_boundary_values=true)
Definition: integrator_multimesh.h:345
Definition: multimesh_elementdatacontainer.h:57
void ComputeNonlinearRhs(PROBLEM &pde, VECTOR &residual, bool apply_boundary_values=true)
Definition: integrator_multimesh.h:359
void ComputeNonlinearResidual(PROBLEM &pde, VECTOR &residual, bool apply_boundary_values=true)
Definition: integrator_multimesh.h:255
SCALAR ComputeAlgebraicScalar(PROBLEM &pde)
Definition: integrator_multimesh.h:777
void AddParamData(std::string name, const dealii::Vector< SCALAR > *new_data)
Definition: integrator_multimesh.h:975
const DOFHANDLER< dim, dim > & GetDEALDoFHandler() const
Definition: dofhandler_wrapper.h:69
SCALAR ComputePointScalar(PROBLEM &pde)
Definition: integrator_multimesh.h:611
void ApplyNewtonBoundaryValues(PROBLEM &pde, VECTOR &u)
Definition: integrator_multimesh.h:851
void ComputeMatrix(PROBLEM &pde, MATRIX &matrix)
Definition: integrator_multimesh.h:449
~IntegratorMultiMesh()
Definition: integrator_multimesh.h:234
void DeleteParamData(std::string name)
Definition: integrator_multimesh.h:993
void ReInit()
Definition: integrator_multimesh.h:244
void DeleteDomainData(std::string name)
Definition: integrator_multimesh.h:930
void ApplyInitialBoundaryValues(PROBLEM &pde, VECTOR &u)
Definition: integrator_multimesh.h:819
IntegratorMultiMesh(INTEGRATORDATACONT &idc)
Definition: integrator_multimesh.h:224
void AddDomainData(std::string name, const VECTOR *new_data)
Definition: integrator_multimesh.h:913
void ComputeNonlinearAlgebraicResidual(PROBLEM &pde, VECTOR &residual)
Definition: integrator_multimesh.h:794
Definition: multimesh_facedatacontainer.h:53
void AddPresetRightHandSide(double s, VECTOR &residual) const
Definition: integrator_multimesh.h:948
INTEGRATORDATACONT & GetIntegratorDataContainer() const
Definition: integrator_multimesh.h:1022
Definition: dopeexception.h:35
const std::map< std::string, const dealii::Vector< SCALAR > * > & GetParamData() const
Definition: integrator_multimesh.h:1012