24 #ifndef STAT_PDE_PROBLEM_H_
25 #define STAT_PDE_PROBLEM_H_
33 #include <deal.II/lac/vector.h>
34 #include <deal.II/lac/block_sparsity_pattern.h>
35 #include <deal.II/lac/block_sparse_matrix.h>
48 #include <deal.II/base/data_out_base.h>
49 #include <deal.II/base/utilities.h>
50 #include <deal.II/numerics/data_out.h>
51 #include <deal.II/numerics/matrix_tools.h>
52 #include <deal.II/numerics/vector_tools.h>
53 #include <deal.II/base/function.h>
54 #include <deal.II/lac/sparse_matrix.h>
55 #include <deal.II/lac/compressed_simple_sparsity_pattern.h>
56 #include <deal.II/lac/block_sparsity_pattern.h>
57 #include <deal.II/lac/sparse_direct.h>
76 template<
typename NONLINEARSOLVER,
typename INTEGRATOR,
typename PROBLEM,
77 typename VECTOR,
int dealdim>
93 template<
typename INTEGRATORDATACONT>
96 int base_priority = 0);
110 template<
typename INTEGRATORDATACONT>
113 INTEGRATORDATACONT& idc2,
int base_priority = 0);
177 template<
class DWRC,
class PDE>
191 GetU().PrintInfos(out);
207 WriteToFile(
const VECTOR &v, std::string name, std::string outfile,
208 std::string dof_type, std::string filetype);
227 std::string outfile, std::string dof_type, std::string filetype);
316 return build_state_matrix_;
322 return build_adjoint_matrix_;
328 return state_reinit_;
334 return adjoint_reinit_;
341 return build_state_matrix_;
347 return build_adjoint_matrix_;
353 return state_reinit_;
359 return adjoint_reinit_;
392 StateVector<VECTOR> u_;
393 StateVector<VECTOR> z_for_ee_;
395 INTEGRATOR integrator_;
396 NONLINEARSOLVER nonlinear_state_solver_;
397 NONLINEARSOLVER nonlinear_adjoint_solver_;
399 bool build_state_matrix_;
400 bool build_adjoint_matrix_;
402 bool adjoint_reinit_;
406 friend class SolutionExtractor<
407 StatPDEProblem<NONLINEARSOLVER, INTEGRATOR, PROBLEM, VECTOR, dealdim>,
414 using namespace dealii;
417 template<
typename NONLINEARSOLVER,
typename INTEGRATOR,
typename PROBLEM,
418 typename VECTOR,
int dealdim>
423 NONLINEARSOLVER::declare_params(param_reader);
426 Patterns::Integer(0));
431 template<
typename NONLINEARSOLVER,
typename INTEGRATOR,
typename PROBLEM,
432 typename VECTOR,
int dealdim>
433 template<
typename INTEGRATORDATACONT>
439 OP->GetSpaceTimeHandler(), state_behavior, param_reader), z_for_ee_(
440 OP->GetSpaceTimeHandler(), state_behavior, param_reader), integrator_(
441 idc), nonlinear_state_solver_(integrator_, param_reader), nonlinear_adjoint_solver_(
442 integrator_, param_reader)
445 n_patches_ = param_reader.
get_integer(
"number of patches");
448 state_reinit_ =
true;
449 adjoint_reinit_ =
true;
453 template<
typename NONLINEARSOLVER,
typename INTEGRATOR,
typename PROBLEM,
454 typename VECTOR,
int dealdim>
455 template<
typename INTEGRATORDATACONT>
459 INTEGRATORDATACONT& idc2,
int base_priority)
461 OP->GetSpaceTimeHandler(), state_behavior, param_reader), z_for_ee_(
462 OP->GetSpaceTimeHandler(), state_behavior, param_reader), integrator_(
463 idc, idc2), nonlinear_state_solver_(integrator_, param_reader), nonlinear_adjoint_solver_(
464 integrator_, param_reader)
468 state_reinit_ =
true;
469 adjoint_reinit_ =
true;
475 template<
typename NONLINEARSOLVER,
typename INTEGRATOR,
typename PROBLEM,
476 typename VECTOR,
int dealdim>
483 template<
typename NONLINEARSOLVER,
typename INTEGRATOR,
typename PROBLEM,
484 typename VECTOR,
int dealdim>
491 return nonlinear_state_solver_;
493 else if (type ==
"adjoint_for_ee")
495 return nonlinear_adjoint_solver_;
499 throw DOpEException(
"No Solver for Problem type:`" + type +
"' found",
500 "StatReducedProblem::GetNonlinearSolver");
507 template<
typename NONLINEARSOLVER,
typename INTEGRATOR,
typename PROBLEM,
508 typename VECTOR,
int dealdim>
517 state_reinit_ =
true;
518 adjoint_reinit_ =
true;
521 build_state_matrix_ =
true;
522 build_adjoint_matrix_ =
true;
525 GetZForEE().ReInit();
530 template<
typename NONLINEARSOLVER,
typename INTEGRATOR,
typename PROBLEM,
531 typename VECTOR,
int dealdim>
535 this->InitializeFunctionalValues(this->GetProblem()->GetNFunctionals());
536 this->GetOutputHandler()->Write(
"Computing State Solution:",
537 4 + this->GetBasePriority());
539 this->SetProblemType(
"state");
540 auto& problem = this->GetProblem()->GetStateProblem();
541 if (state_reinit_ ==
true)
543 GetNonlinearSolver(
"state").ReInit(problem);
544 state_reinit_ =
false;
547 this->GetProblem()->AddAuxiliaryToIntegrator(this->GetIntegrator());
549 build_state_matrix_ = this->GetNonlinearSolver(
"state").NonlinearSolve(
550 problem, (GetU().GetSpacialVector()),
true, build_state_matrix_);
553 this->GetProblem()->DeleteAuxiliaryFromIntegrator(this->GetIntegrator());
555 this->GetOutputHandler()->Write((GetU().GetSpacialVector()),
556 "State" + this->GetPostIndex(), problem.GetDoFType());
562 template<
typename NONLINEARSOLVER,
typename INTEGRATOR,
typename PROBLEM,
563 typename VECTOR,
int dealdim>
568 this->GetOutputHandler()->Write(
"Computing Dual for Error Estimation:",
569 4 + this->GetBasePriority());
572 this->SetProblemType(
"adjoint_for_ee");
577 "StatPDEProblem::ComputeDualForErrorEstimation");
581 auto& problem = *(this->GetProblem());
582 if (adjoint_reinit_ ==
true)
584 GetNonlinearSolver(
"adjoint_for_ee").ReInit(problem);
585 adjoint_reinit_ =
false;
588 this->GetProblem()->AddAuxiliaryToIntegrator(this->GetIntegrator());
590 this->GetIntegrator().AddDomainData(
"state",
591 &(GetU().GetSpacialVector()));
594 build_adjoint_matrix_ =
595 this->GetNonlinearSolver(
"adjoint_for_ee").NonlinearSolve(problem,
596 (GetZForEE().GetSpacialVector()),
true, build_adjoint_matrix_);
598 this->GetIntegrator().DeleteDomainData(
"state");
601 this->GetProblem()->DeleteAuxiliaryFromIntegrator(this->GetIntegrator());
603 this->GetOutputHandler()->Write((GetZForEE().GetSpacialVector()),
604 "Adjoint_for_ee" + this->GetPostIndex(), problem.GetDoFType());
610 template<
typename NONLINEARSOLVER,
typename INTEGRATOR,
typename PROBLEM,
611 typename VECTOR,
int dealdim>
615 this->ComputeReducedState();
617 this->GetOutputHandler()->Write(
"Computing Functionals:",
618 4 + this->GetBasePriority());
620 this->GetProblem()->AddAuxiliaryToIntegrator(this->GetIntegrator());
622 this->GetIntegrator().AddDomainData(
"state",
623 &(GetU().GetSpacialVector()));
626 for (
unsigned int i = 0; i < this->GetProblem()->GetNFunctionals(); i++)
631 this->SetProblemType(
"aux_functional", i);
632 if (this->GetProblem()->GetFunctionalType().find(
"domain")
633 != std::string::npos)
636 ret += this->GetIntegrator().ComputeDomainScalar(
637 *(this->GetProblem()));
639 if (this->GetProblem()->GetFunctionalType().find(
"point")
640 != std::string::npos)
643 ret += this->GetIntegrator().ComputePointScalar(
644 *(this->GetProblem()));
646 if (this->GetProblem()->GetFunctionalType().find(
"boundary")
647 != std::string::npos)
650 ret += this->GetIntegrator().ComputeBoundaryScalar(
651 *(this->GetProblem()));
653 if (this->GetProblem()->GetFunctionalType().find(
"face")
654 != std::string::npos)
657 ret += this->GetIntegrator().ComputeFaceScalar(*(this->GetProblem()));
663 "Unknown Functional Type: "
664 + this->GetProblem()->GetFunctionalType(),
665 "StatPDEProblem::ComputeReducedFunctionals");
667 this->GetFunctionalValues()[i].push_back(ret);
668 std::stringstream out;
669 this->GetOutputHandler()->InitOut(out);
670 out << this->GetProblem()->GetFunctionalName() <<
": " << ret;
671 this->GetOutputHandler()->Write(out, 2 + this->GetBasePriority());
674 this->GetIntegrator().DeleteDomainData(
"state");
677 this->GetProblem()->DeleteAuxiliaryFromIntegrator(this->GetIntegrator());
682 template<
typename NONLINEARSOLVER,
typename INTEGRATOR,
typename PROBLEM,
683 typename VECTOR,
int dealdim>
688 this->InitializeFunctionalValues(this->GetProblem()->GetNFunctionals());
691 this->GetOutputHandler()->Write(
"Computing Functionals:",
692 4 + this->GetBasePriority());
694 this->GetProblem()->AddAuxiliaryToIntegrator(this->GetIntegrator());
696 this->GetIntegrator().AddDomainData(
"state",
697 &(GetU().GetSpacialVector()));
700 for (
unsigned int i = 0; i < this->GetProblem()->GetNFunctionals(); i++)
705 this->SetProblemType(
"aux_functional", i);
706 if (this->GetProblem()->GetFunctionalType().find(
"domain")
707 != std::string::npos)
710 ret += this->GetIntegrator().ComputeDomainScalar(
711 *(this->GetProblem()));
713 if (this->GetProblem()->GetFunctionalType().find(
"point")
714 != std::string::npos)
717 ret += this->GetIntegrator().ComputePointScalar(
718 *(this->GetProblem()));
720 if (this->GetProblem()->GetFunctionalType().find(
"boundary")
721 != std::string::npos)
724 ret += this->GetIntegrator().ComputeBoundaryScalar(
725 *(this->GetProblem()));
727 if (this->GetProblem()->GetFunctionalType().find(
"face")
728 != std::string::npos)
731 ret += this->GetIntegrator().ComputeFaceScalar(*(this->GetProblem()));
737 "Unknown Functional Type: "
738 + this->GetProblem()->GetFunctionalType(),
739 "StatPDEProblem::ComputeReducedFunctionals");
741 this->GetFunctionalValues()[i].push_back(ret);
742 std::stringstream out;
743 this->GetOutputHandler()->InitOut(out);
744 out << this->GetProblem()->GetFunctionalName() <<
": " << ret;
745 this->GetOutputHandler()->Write(out, 2 + this->GetBasePriority());
748 this->GetIntegrator().DeleteDomainData(
"state");
751 this->GetProblem()->DeleteAuxiliaryFromIntegrator(this->GetIntegrator());
756 template<
typename NONLINEARSOLVER,
typename INTEGRATOR,
typename PROBLEM,
757 typename VECTOR,
int dealdim>
758 template<
class DWRC,
class PDE>
761 DWRC& dwrc, PDE& pde)
764 pde.ResidualModifier = boost::bind<void>(
765 boost::mem_fn(&DWRC::ResidualModifier), boost::ref(dwrc), _1);
766 pde.VectorResidualModifier = boost::bind<void>(
767 boost::mem_fn(&DWRC::VectorResidualModifier), boost::ref(dwrc), _1);
770 const unsigned int n_elements =
771 this->GetProblem()->GetSpaceTimeHandler()->GetStateDoFHandler().get_tria().n_active_cells();
772 dwrc.ReInit(n_elements);
775 this->ComputeDualForErrorEstimation(dwrc.GetWeightComputation());
778 this->GetOutputHandler()->Write(
"Computing Error Indicators:",
779 4 + this->GetBasePriority());
781 this->GetProblem()->AddAuxiliaryToIntegrator(this->GetIntegrator());
784 this->GetIntegrator().AddDomainData(
"state",
785 &(GetU().GetSpacialVector()));
787 this->GetIntegrator().AddDomainData(
"adjoint_for_ee",
788 &(GetZForEE().GetSpacialVector()));
791 this->SetProblemType(
"error_evaluation");
794 dwrc.PrepareWeights(GetU(), GetZForEE());
797 this->GetIntegrator().ComputeRefinementIndicators(*this->GetProblem(),
803 const float error = dwrc.GetError();
806 dwrc.ClearWeightData();
807 this->GetIntegrator().DeleteDomainData(
"state");
809 this->GetIntegrator().DeleteDomainData(
"adjoint_for_ee");
811 this->GetProblem()->DeleteAuxiliaryFromIntegrator(
812 this->GetIntegrator());
814 std::stringstream out;
815 this->GetOutputHandler()->InitOut(out);
816 out <<
"Error estimate using " << dwrc.GetName();
818 out <<
" for the " << this->GetProblem()->GetFunctionalName();
819 out <<
": " << error;
820 this->GetOutputHandler()->Write(out, 2 + this->GetBasePriority());
821 this->GetOutputHandler()->WriteElementwise(dwrc.GetErrorIndicators(),
822 "Error_Indicators" + this->GetPostIndex(),
823 this->GetProblem()->GetDoFType());
829 template<
typename NONLINEARSOLVER,
typename INTEGRATOR,
typename PROBLEM,
830 typename VECTOR,
int dealdim>
833 const Vector<double> &v, std::string name, std::string outfile,
834 std::string dof_type, std::string filetype)
836 if (dof_type ==
"state")
839 this->GetProblem()->GetSpaceTimeHandler()->GetDataOut();
840 data_out.attach_dof_handler(
841 this->GetProblem()->GetSpaceTimeHandler()->GetStateDoFHandler());
843 data_out.add_data_vector(v, name);
844 data_out.build_patches(n_patches_);
846 std::ofstream output(outfile.c_str());
848 if (filetype ==
".vtk")
850 data_out.write_vtk(output);
855 "Don't know how to write filetype `" + filetype +
"'!",
856 "StatPDEProblem::WriteToFileElementwise");
862 throw DOpEException(
"No such DoFHandler `" + dof_type +
"'!",
863 "StatPDEProblem::WriteToFileElementwise");
869 template<
typename NONLINEARSOLVER,
typename INTEGRATOR,
typename PROBLEM,
870 typename VECTOR,
int dealdim>
873 const VECTOR &v, std::string name, std::string outfile,
874 std::string dof_type, std::string filetype)
876 if (dof_type ==
"state")
879 this->GetProblem()->GetSpaceTimeHandler()->GetDataOut();
880 data_out.attach_dof_handler(
881 this->GetProblem()->GetSpaceTimeHandler()->GetStateDoFHandler());
883 data_out.add_data_vector(v, name);
886 data_out.build_patches(
887 this->GetProblem()->GetSpaceTimeHandler()->GetMapping()[0]);
889 std::ofstream output(outfile.c_str());
891 if (filetype ==
".vtk")
893 data_out.write_vtk(output);
895 else if (filetype ==
".gpl")
897 data_out.write_gnuplot(output);
902 "Don't know how to write filetype `" + filetype +
"'!",
903 "StatPDEProblem::WriteToFile");
909 throw DOpEException(
"No such DoFHandler `" + dof_type +
"'!",
910 "StatPDEProblem::WriteToFile");
916 template<
typename NONLINEARSOLVER,
typename INTEGRATOR,
typename PROBLEM,
917 typename VECTOR,
int dealdim>
922 throw DOpEException(
"This Problem does not support ControlVectors",
"StatPDEProblem::WriteToFile");
StateVector< VECTOR > & GetU()
Definition: statpdeproblem.h:287
void StateSizeInfo(std::stringstream &out)
Definition: statpdeproblem.h:189
void WriteToFileElementwise(const Vector< double > &v, std::string name, std::string outfile, std::string dof_type, std::string filetype)
Definition: statpdeproblem.h:832
Definition: statpdeproblem.h:78
void ComputeReducedFunctionals()
Definition: statpdeproblem.h:613
void WriteToFile(const std::vector< double > &, std::string)
Definition: statpdeproblem.h:250
Definition: parameterreader.h:36
const bool & GetBuildAdjointMatrix() const
Definition: statpdeproblem.h:320
INTEGRATOR & GetIntegrator()
Definition: statpdeproblem.h:308
const StateVector< VECTOR > & GetZForEE() const
Definition: statpdeproblem.h:295
const bool & GetStateReinit() const
Definition: statpdeproblem.h:326
void declare_entry(const std::string &entry, const std::string &default_value, const Patterns::PatternBase &pattern=Patterns::Anything(), const std::string &documentation=std::string())
Definition: parameterreader.h:98
const bool & GetBuildStateMatrix() const
Definition: statpdeproblem.h:314
NONLINEARSOLVER & GetNonlinearSolver(std::string type)
Definition: statpdeproblem.h:486
Definition: controlvector.h:49
Definition: dopetypes.h:82
Definition: pdeprobleminterface.h:53
StateVector< VECTOR > & GetZForEE()
Definition: statpdeproblem.h:300
bool & GetBuildAdjointMatrix()
Definition: statpdeproblem.h:345
static void declare_params(ParameterReader ¶m_reader)
Definition: statpdeproblem.h:420
Definition: statevector.h:50
bool & GetStateReinit()
Definition: statpdeproblem.h:351
const StateVector< VECTOR > & GetU() const
Definition: statpdeproblem.h:282
bool & GetAdjointReinit()
Definition: statpdeproblem.h:357
void WriteToFile(const VECTOR &v, std::string name, std::string outfile, std::string dof_type, std::string filetype)
Definition: statpdeproblem.h:872
virtual ~StatPDEProblem()
Definition: statpdeproblem.h:477
void ComputeRefinementIndicators(DWRC &dwrc, PDE &pde)
Definition: statpdeproblem.h:760
int get_integer(const std::string &entry_name)
Definition: parameterreader.h:126
VectorStorageType
Definition: dopetypes.h:120
void ComputeDualForErrorEstimation(DOpEtypes::WeightComputation)
Definition: statpdeproblem.h:565
void SetSubsection(const std::string subsection)
Definition: parameterreader.h:93
void ReInit()
Definition: statpdeproblem.h:510
WeightComputation
Definition: dopetypes.h:80
const std::map< std::string, const VECTOR * > & GetUserDomainData() const
Definition: reducedprobleminterface.h:300
bool & GetBuildStateMatrix()
Definition: statpdeproblem.h:339
StatPDEProblem(PROBLEM *OP, DOpEtypes::VectorStorageType state_behavior, ParameterReader ¶m_reader, INTEGRATORDATACONT &idc, int base_priority=0)
Definition: statpdeproblem.h:434
const bool & GetAdjointReinit() const
Definition: statpdeproblem.h:332
void ComputeReducedState()
Definition: statpdeproblem.h:533
Definition: dopeexception.h:35