24 #ifndef IntegratorMixed_H_
25 #define IntegratorMixed_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/base/function.h>
33 #include <deal.II/dofs/dof_tools.h>
34 #include <deal.II/fe/mapping_q1.h>
41 #if DEAL_II_VERSION_GTE(7,3,0)
42 #include <deal.II/base/types.h>
64 template<
typename INTEGRATORDATACONT,
typename VECTOR,
typename SCALAR,
int dimlow,
75 template<
typename PROBLEM>
77 template<
typename PROBLEM,
typename MATRIX>
79 template<
typename PROBLEM>
83 template<
typename PROBLEM>
85 template<
typename PROBLEM>
87 template<
typename PROBLEM>
89 template<
typename PROBLEM>
91 template<
typename PROBLEM>
93 template<
typename PROBLEM>
96 template<
typename PROBLEM>
98 template<
typename PROBLEM>
100 template<
typename PROBLEM>
102 template<
typename PROBLEM,
typename MATRIX>
105 inline void AddDomainData(std::string name,
const VECTOR* new_data);
108 inline void AddParamData(std::string name,
const dealii::Vector<SCALAR>* new_data);
114 inline const std::map<std::string, const VECTOR*>&
GetDomainData()
const;
115 inline const std::map<std::string, const dealii::Vector<SCALAR>*>&
GetParamData()
const;
120 INTEGRATORDATACONT & idc_;
122 std::map<std::string, const VECTOR*> domain_data_;
123 std::map<std::string, const dealii::Vector<SCALAR>*> param_data_;
128 template<
typename INTEGRATORDATACONT,
typename VECTOR,
typename SCALAR,
129 int dimlow,
int dimhigh>
138 template<
typename INTEGRATORDATACONT,
typename VECTOR,
typename SCALAR,
int dimlow,
147 template<
typename INTEGRATORDATACONT,
typename VECTOR,
typename SCALAR,
int dimlow,
156 template<
typename INTEGRATORDATACONT,
typename VECTOR,
typename SCALAR,
int dimlow,
158 template<
typename PROBLEM>
161 bool apply_boundary_values)
166 const unsigned int dofs =
167 pde.GetBaseProblem().GetSpaceTimeHandler()->GetControlNDoFs();
169 dealii::Vector<SCALAR> local_vector(dofs);
170 const auto& dof_handler =
171 pde.GetBaseProblem().GetSpaceTimeHandler()->GetDoFHandler();
172 auto element = pde.GetBaseProblem().GetSpaceTimeHandler()->GetDoFHandlerBeginActive();
173 auto endc = pde.GetBaseProblem().GetSpaceTimeHandler()->GetDoFHandlerEnd();
176 idc_.InitializeEDC(pde.GetUpdateFlags(),
177 *(pde.GetBaseProblem().GetSpaceTimeHandler()), element,
178 this->GetParamData(), this->GetDomainData());
179 auto& edc = idc_.GetElementDataContainer();
181 bool need_faces = pde.HasFaces();
182 bool need_interfaces = pde.HasInterfaces();
183 std::vector<unsigned int> boundary_equation_colors = pde.GetBoundaryEquationColors();
184 bool need_boundary_integrals = (boundary_equation_colors.size() > 0);
185 idc_.InitializeFDC(pde.GetFaceUpdateFlags(),
186 *(pde.GetBaseProblem().GetSpaceTimeHandler()),
188 this->GetParamData(),
189 this->GetDomainData());
190 auto & fdc = idc_.GetFaceDataContainer();
192 for (; element[0] != endc[0]; element[0]++)
194 for (
unsigned int dh = 1; dh < dof_handler.size(); dh++)
196 if (element[dh] == endc[dh])
198 throw DOpEException(
"Elementnumbers in DoFHandlers are not matching!",
199 "IntegratorMixedDimensions::ComputeNonlinearResidual");
206 pde.ElementRhs(edc,local_vector, -1.);
208 if(need_boundary_integrals)
210 for (
unsigned int face=0; face < dealii::GeometryInfo<dimhigh>::faces_per_cell; ++face)
212 #if DEAL_II_VERSION_GTE(8,3,0)
213 if (element[0]->face(face)->at_boundary()
215 (find(boundary_equation_colors.begin(),boundary_equation_colors.end(),element[0]->face(face)->boundary_id()) != boundary_equation_colors.end()))
217 if (element[0]->face(face)->at_boundary()
219 (find(boundary_equation_colors.begin(),boundary_equation_colors.end(),element[0]->face(face)->boundary_indicator()) != boundary_equation_colors.end()))
223 pde.BoundaryRhs(fdc,local_vector,-1.);
229 for (
unsigned int face=0; face < dealii::GeometryInfo<dimhigh>::faces_per_cell; ++face)
231 if (element[0]->neighbor_index(face) != -1)
234 pde.FaceRhs(fdc,local_vector,-1.);
241 "IntegratorMixedDimensions::ComputeNonlinearResidual");
244 for (
unsigned int i = 0; i < dofs; ++i)
246 residual(i) += local_vector(i);
249 for (
unsigned int dh = 1; dh < dof_handler.size(); dh++)
256 pde.ElementEquation(edc, local_vector, 1., 1.);
258 for (
unsigned int i = 0; i < dofs; ++i)
260 residual(i) += local_vector(i);
263 if (pde.HasControlInDirichletData())
265 ApplyTransposedInitialBoundaryValues(pde,residual, -1.);
269 AddPresetRightHandSide(-1.,local_vector);
270 for (
unsigned int i = 0; i < dofs; ++i)
272 residual(i) += local_vector(i);
275 if (apply_boundary_values)
277 ApplyNewtonBoundaryValues(pde,residual);
283 template<
typename INTEGRATORDATACONT,
typename VECTOR,
typename SCALAR,
int dimlow,
285 template<
typename PROBLEM>
288 bool apply_boundary_values)
293 const unsigned int dofs =
294 pde.GetBaseProblem().GetSpaceTimeHandler()->GetControlNDoFs();
296 dealii::Vector<SCALAR> local_vector(dofs);
297 const auto& dof_handler =
298 pde.GetBaseProblem().GetSpaceTimeHandler()->GetDoFHandler();
299 auto element = pde.GetBaseProblem().GetSpaceTimeHandler()->GetDoFHandlerBeginActive();
300 auto endc = pde.GetBaseProblem().GetSpaceTimeHandler()->GetDoFHandlerEnd();
303 idc_.InitializeEDC(pde.GetUpdateFlags(),
304 *(pde.GetBaseProblem().GetSpaceTimeHandler()), element,
305 this->GetParamData(), this->GetDomainData());
306 auto& edc = idc_.GetElementDataContainer();
308 bool need_faces = pde.HasFaces();
309 bool need_interfaces = pde.HasInterfaces();
310 std::vector<unsigned int> boundary_equation_colors = pde.GetBoundaryEquationColors();
311 bool need_boundary_integrals = (boundary_equation_colors.size() > 0);
312 idc_.InitializeFDC(pde.GetFaceUpdateFlags(),
313 *(pde.GetBaseProblem().GetSpaceTimeHandler()),
315 this->GetParamData(),
316 this->GetDomainData());
317 auto & fdc = idc_.GetFaceDataContainer();
319 for (; element[0] != endc[0]; element[0]++)
321 for (
unsigned int dh = 1; dh < dof_handler.size(); dh++)
323 if (element[dh] == endc[dh])
325 throw DOpEException(
"Elementnumbers in DoFHandlers are not matching!",
326 "IntegratorMixedDimensions::ComputeNonlinearResidual");
333 pde.ElementRhs(edc,local_vector, 1.);
335 if(need_boundary_integrals)
337 for (
unsigned int face=0; face < dealii::GeometryInfo<dimhigh>::faces_per_cell; ++face)
339 #if DEAL_II_VERSION_GTE(8,3,0)
340 if (element[0]->face(face)->at_boundary()
342 (find(boundary_equation_colors.begin(),boundary_equation_colors.end(),element[0]->face(face)->boundary_id()) != boundary_equation_colors.end()))
344 if (element[0]->face(face)->at_boundary()
346 (find(boundary_equation_colors.begin(),boundary_equation_colors.end(),element[0]->face(face)->boundary_indicator()) != boundary_equation_colors.end()))
350 pde.BoundaryRhs(fdc,local_vector,1.);
356 for (
unsigned int face=0; face < dealii::GeometryInfo<dimhigh>::faces_per_cell; ++face)
358 if (element[0]->neighbor_index(face) != -1)
361 pde.FaceRhs(fdc,local_vector,1.);
368 "IntegratorMixedDimensions::ComputeNonlinearRhs");
371 for (
unsigned int i = 0; i < dofs; ++i)
373 residual(i) += local_vector(i);
376 for (
unsigned int dh = 1; dh < dof_handler.size(); dh++)
382 if (pde.HasControlInDirichletData())
384 ApplyTransposedInitialBoundaryValues(pde,residual, -1.);
388 AddPresetRightHandSide(-1.,local_vector);
389 for (
unsigned int i = 0; i < dofs; ++i)
391 residual(i) += local_vector(i);
394 if (apply_boundary_values)
396 ApplyNewtonBoundaryValues(pde,residual);
403 template<
typename INTEGRATORDATACONT,
typename VECTOR,
typename SCALAR,
int dimlow,
405 template<
typename PROBLEM,
typename MATRIX>
408 throw DOpEException(
"You should not use this function, try VoidLinearSolver instead.",
409 "IntegratorMixedDimensions::ComputeMatrix");
414 template<
typename INTEGRATORDATACONT,
typename VECTOR,
typename SCALAR,
int dimlow,
416 template<
typename PROBLEM>
420 pde.ComputeLocalControlConstraints(constraints,this->GetParamData(),this->GetDomainData());
424 template<
typename INTEGRATORDATACONT,
typename VECTOR,
typename SCALAR,
425 int dimlow,
int dimhigh>
426 template<
typename PROBLEM>
429 dimhigh>::ComputeDomainScalar(PROBLEM& pde)
433 const unsigned int n_q_points = this->GetQuadratureFormula()->size();
435 const auto& dof_handler =
436 pde.GetBaseProblem().GetSpaceTimeHandler()->GetDoFHandler();
437 auto element = pde.GetBaseProblem().GetSpaceTimeHandler()->GetDoFHandlerBeginActive();
438 auto endc = pde.GetBaseProblem().GetSpaceTimeHandler()->GetDoFHandlerEnd();
440 idc_.InitializeEDC(pde.GetUpdateFlags(),
441 *(pde.GetBaseProblem().GetSpaceTimeHandler()), element,
442 this->GetParamData(), this->GetDomainData());
443 auto& edc = idc_.GetElementDataContainer();
445 for (; element[0] != endc[0]; element[0]++)
447 for (
unsigned int dh = 1; dh < dof_handler.size(); dh++)
449 if (element[dh] == endc[dh])
451 throw DOpEException(
"Elementnumbers in DoFHandlers are not matching!",
452 "IntegratorMixedDimensions::ComputeDomainScalar");
456 ret += pde.ElementFunctional(edc);
458 for (
unsigned int dh = 1; dh < dof_handler.size(); dh++)
468 template<
typename INTEGRATORDATACONT,
typename VECTOR,
typename SCALAR,
int dimlow,
470 template<
typename PROBLEM>
473 if (pde.GetFEValuesNeededToBeInitialized())
475 this->InitializeFEValues();
481 ret += pde.PointFunctional(this->GetParamData(), this->GetDomainData());
488 template<
typename INTEGRATORDATACONT,
typename VECTOR,
typename SCALAR,
int dimlow,
490 template<
typename PROBLEM>
498 const std::vector<const DOpEWrapper::DoFHandler<dimhigh, dealii::DoFHandler >*>& dof_handler =
499 pde.GetBaseProblem().GetSpaceTimeHandler()->GetDoFHandler();
500 std::vector<typename DOpEWrapper::DoFHandler<dimhigh, dealii::DoFHandler >::active_element_iterator>
501 element(dof_handler.size());
502 std::vector<typename DOpEWrapper::DoFHandler<dimhigh, dealii::DoFHandler>::active_element_iterator>
503 endc(dof_handler.size());
505 for (
unsigned int dh = 0; dh < dof_handler.size(); dh++)
507 element[dh] = dof_handler[dh]->begin_active();
508 endc[dh] = dof_handler[dh]->end();
513 pde.GetFaceUpdateFlags(),
514 *(pde.GetBaseProblem().GetSpaceTimeHandler()), element,
515 this->GetParamData(), this->GetDomainData());
517 std::vector<unsigned int> boundary_functional_colors =
518 pde.GetBoundaryFunctionalColors();
519 bool need_boundary_integrals = (boundary_functional_colors.size() > 0);
520 if (!need_boundary_integrals)
523 "IntegratorMixedDimensions::ComputeBoundaryScalar");
526 for (; element[0] != endc[0]; element[0]++)
528 for (
unsigned int dh = 1; dh < dof_handler.size(); dh++)
530 if (element[dh] == endc[dh])
532 throw DOpEException(
"Elementnumbers in DoFHandlers are not matching!",
533 "IntegratorMixedDimensions::ComputeBoundaryScalar");
537 if(need_boundary_integrals)
539 for (
unsigned int face=0; face < dealii::GeometryInfo<dimhigh>::faces_per_cell; ++face)
541 #if DEAL_II_VERSION_GTE(8,3,0)
542 if (element[0]->face(face)->at_boundary()
544 (find(boundary_functional_colors.begin(),boundary_functional_colors.end(),
545 element[0]->face(face)->boundary_id()) != boundary_functional_colors.end()))
547 if (element[0]->face(face)->at_boundary()
549 (find(boundary_functional_colors.begin(),boundary_functional_colors.end(),
550 element[0]->face(face)->boundary_indicator()) != boundary_functional_colors.end()))
555 ret += pde.BoundaryFunctional(fdc);
559 for (
unsigned int dh = 1; dh < dof_handler.size(); dh++)
569 template<
typename INTEGRATORDATACONT,
typename VECTOR,
typename SCALAR,
int dimlow,
571 template<
typename PROBLEM>
578 const std::vector<const DOpEWrapper::DoFHandler<dimhigh, dealii::DoFHandler >*>& dof_handler =
579 pde.GetBaseProblem().GetSpaceTimeHandler()->GetDoFHandler();
580 std::vector<typename DOpEWrapper::DoFHandler<dimhigh, dealii::DoFHandler>::active_element_iterator>
581 element(dof_handler.size());
582 std::vector<typename DOpEWrapper::DoFHandler<dimhigh, dealii::DoFHandler>::active_element_iterator>
583 endc(dof_handler.size());
585 for (
unsigned int dh = 0; dh < dof_handler.size(); dh++)
587 element[dh] = dof_handler[dh]->begin_active();
588 endc[dh] = dof_handler[dh]->end();
592 pde.GetFaceUpdateFlags(),
593 *(pde.GetBaseProblem().GetSpaceTimeHandler()), element,
594 this->GetParamData(), this->GetDomainData());
596 bool need_faces = pde.HasFaces();
599 throw DOpEException(
"No faces required!",
"IntegratorMixedDimensions::ComputeFaceScalar");
602 for (; element[0] != endc[0]; element[0]++)
604 for (
unsigned int dh = 1; dh < dof_handler.size(); dh++)
606 if (element[dh] == endc[dh])
608 throw DOpEException(
"Elementnumbers in DoFHandlers are not matching!",
609 "IntegratorMixedDimensions::ComputeFaceScalar");
615 for (
unsigned int face=0; face < dealii::GeometryInfo<dimhigh>::faces_per_cell; ++face)
618 ret +=pde.FaceFunctional(fdc);
621 for (
unsigned int dh = 1; dh < dof_handler.size(); dh++)
632 template<
typename INTEGRATORDATACONT,
typename VECTOR,
typename SCALAR,
int dimlow,
634 template<
typename PROBLEM>
638 ret = pde.AlgebraicFunctional(this->GetParamData(), this->GetDomainData());
642 template<
typename INTEGRATORDATACONT,
typename VECTOR,
typename SCALAR,
int dimlow,
644 template<
typename PROBLEM>
651 template<
typename INTEGRATORDATACONT,
typename VECTOR,
typename SCALAR,
int dimlow,
653 template<
typename PROBLEM>
661 pde.GetBaseProblem().GetSpaceTimeHandler()->GetControlNDoFs();
662 dealii::Vector<SCALAR> local_vector(dofs);
664 std::vector<unsigned int> dirichlet_colors = pde.GetTransposedDirichletColors();
665 std::vector<bool> selected_components;
666 if (dirichlet_colors.size() > 0)
668 selected_components.resize(
669 pde.GetBaseProblem().GetSpaceTimeHandler()->GetDoFHandler()[0]->n_dofs());
670 const std::vector<Point<dimhigh> >& support_points =
671 pde.GetBaseProblem().GetSpaceTimeHandler()->GetMapDoFToSupportPoints();
673 for (
unsigned int i = 0; i < dirichlet_colors.size(); i++)
675 unsigned int color = dirichlet_colors[i];
676 std::vector<bool> comp_mask = pde.GetTransposedDirichletCompMask(color);
677 std::vector<bool> current_comp(comp_mask.size(),
false);
678 #if DEAL_II_VERSION_GTE(7,3,0)
679 std::set<types::boundary_id> boundary_indicators;
681 std::set<unsigned char> boundary_indicators;
683 boundary_indicators.insert(color);
684 for (
unsigned int j = 0; j < comp_mask.size(); j++)
687 current_comp[j - 1] =
false;
690 current_comp[j] =
true;
692 DoFTools::extract_boundary_dofs(pde.GetBaseProblem().GetSpaceTimeHandler()->GetDoFHandler()[0]->GetDEALDoFHandler(),
693 current_comp, selected_components, boundary_indicators);
696 pde.GetTransposedDirichletValues(color,
697 this->GetParamData(),
698 this->GetDomainData());
699 for (
unsigned int k = 0; k < selected_components.size(); k++)
701 if (selected_components[k])
704 DD.
value(support_points[k], j, k, local_vector);
705 for (
unsigned int l = 0; l < dofs; ++l)
707 u(l) += scale * local_vector(l);
719 template<
typename INTEGRATORDATACONT,
typename VECTOR,
typename SCALAR,
int dimlow,
721 template<
typename PROBLEM>
729 template<
typename INTEGRATORDATACONT,
typename VECTOR,
typename SCALAR,
int dimlow,
731 template<
typename PROBLEM,
typename MATRIX>
742 template<
typename INTEGRATORDATACONT,
typename VECTOR,
typename SCALAR,
int dimlow,
746 const VECTOR* new_data)
748 if (domain_data_.find(name) != domain_data_.end())
750 throw DOpEException(
"Adding multiple Data with name " + name +
" is prohibited!",
751 "IntegratorMixedDimensions::AddDomainData");
753 domain_data_.insert(std::pair<std::string, const VECTOR*>(name, new_data));
758 template<
typename INTEGRATORDATACONT,
typename VECTOR,
typename SCALAR,
int dimlow,
763 typename std::map<std::string, const VECTOR *>::iterator it = domain_data_.find(name);
764 if (it == domain_data_.end())
766 throw DOpEException(
"Deleting Data " + name +
" is impossible! Data not found",
767 "IntegratorMixedDimensions::DeleteDomainData");
769 domain_data_.erase(it);
774 template<
typename INTEGRATORDATACONT,
typename VECTOR,
typename SCALAR,
int dimlow,
777 SCALAR, dimlow, dimhigh>::GetDomainData()
const
784 template<
typename INTEGRATORDATACONT,
typename VECTOR,
typename SCALAR,
int dimlow,
788 const dealii::Vector<
791 if (param_data_.find(name) != param_data_.end())
793 throw DOpEException(
"Adding multiple Data with name " + name +
" is prohibited!",
794 "IntegratorMixedDimensions::AddParamData");
796 param_data_.insert(std::pair<std::string,
const dealii::Vector<SCALAR>*>(name, new_data));
801 template<
typename INTEGRATORDATACONT,
typename VECTOR,
typename SCALAR,
int dimlow,
806 typename std::map<std::string, const dealii::Vector<SCALAR>*>::iterator it =
807 param_data_.find(name);
808 if (it == param_data_.end())
810 throw DOpEException(
"Deleting Data " + name +
" is impossible! Data not found",
811 "IntegratorMixedDimensions::DeleteParamData");
813 param_data_.erase(it);
818 template<
typename INTEGRATORDATACONT,
typename VECTOR,
typename SCALAR,
int dimlow,
821 INTEGRATORDATACONT, VECTOR, SCALAR, dimlow, dimhigh>::GetParamData()
const
827 template<
typename INTEGRATORDATACONT,
typename VECTOR,
typename SCALAR,
828 int dimlow,
int dimhigh>
829 const INTEGRATORDATACONT&
837 template<
typename INTEGRATORDATACONT,
typename VECTOR,
typename SCALAR,
838 int dimlow,
int dimhigh>
841 dealii::Vector<SCALAR> &residual)
const
843 typename std::map<std::string, const dealii::Vector<SCALAR>*>::const_iterator it =
844 param_data_.find(
"fixed_rhs");
845 if (it != param_data_.end())
847 assert(residual.size() == it->second->size());
848 residual.add(s,*(it->second));
void ComputeMatrix(PROBLEM &pde, MATRIX &matrix)
Definition: integratormixeddims.h:406
const std::map< std::string, const VECTOR * > & GetDomainData() const
Definition: integratormixeddims.h:777
IntegratorMixedDimensions(INTEGRATORDATACONT &idc)
Definition: integratormixeddims.h:131
const INTEGRATORDATACONT & GetIntegratorDataContainer() const
Definition: integratormixeddims.h:830
~IntegratorMixedDimensions()
Definition: integratormixeddims.h:140
const std::map< std::string, const dealii::Vector< SCALAR > * > & GetParamData() const
Definition: integratormixeddims.h:821
void ApplyNewtonBoundaryValues(PROBLEM &pde, VECTOR &u)
Definition: integratormixeddims.h:722
void ComputeNonlinearRhs(PROBLEM &pde, VECTOR &residual, bool apply_boundary_values=true)
Definition: integratormixeddims.h:286
virtual void value(const dealii::Point< dealdim > &p, const unsigned int component, const unsigned int dof_number, dealii::Vector< double > &local_vector) const =0
void ReInit()
Definition: integratormixeddims.h:149
void DeleteDomainData(std::string name)
Definition: integratormixeddims.h:760
void ComputeLocalControlConstraints(PROBLEM &pde, VECTOR &constraints)
Definition: integratormixeddims.h:417
Definition: facedatacontainer.h:50
SCALAR ComputeAlgebraicScalar(PROBLEM &pde)
Definition: integratormixeddims.h:635
void AddPresetRightHandSide(double s, dealii::Vector< SCALAR > &residual) const
Definition: integratormixeddims.h:840
SCALAR ComputeDomainScalar(PROBLEM &pde)
Definition: integratormixeddims.h:429
void DeleteParamData(std::string name)
Definition: integratormixeddims.h:803
void ApplyInitialBoundaryValues(PROBLEM &pde, VECTOR &u)
Definition: integratormixeddims.h:645
Definition: integratormixeddims.h:66
void ApplyTransposedInitialBoundaryValues(PROBLEM &pde, VECTOR &u, SCALAR scale)
Definition: integratormixeddims.h:655
void ComputeNonlinearResidual(PROBLEM &pde, VECTOR &residual, bool apply_boundary_values=true)
Definition: integratormixeddims.h:159
SCALAR ComputeFaceScalar(PROBLEM &pde)
Definition: integratormixeddims.h:572
Definition: transposeddirichletdatainterface.h:37
void AddDomainData(std::string name, const VECTOR *new_data)
Definition: integratormixeddims.h:744
Definition: dopeexception.h:35
SCALAR ComputeBoundaryScalar(PROBLEM &pde)
Definition: integratormixeddims.h:491
SCALAR ComputePointScalar(PROBLEM &pde)
Definition: integratormixeddims.h:471
void AddParamData(std::string name, const dealii::Vector< SCALAR > *new_data)
Definition: integratormixeddims.h:786