24 #ifndef STAT_REDUCED_PROBLEM_H_
25 #define STAT_REDUCED_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>
51 #include <deal.II/base/data_out_base.h>
52 #include <deal.II/numerics/data_out.h>
53 #include <deal.II/numerics/matrix_tools.h>
54 #include <deal.II/numerics/vector_tools.h>
55 #include <deal.II/base/function.h>
56 #include <deal.II/lac/sparse_matrix.h>
57 #include <deal.II/lac/compressed_simple_sparsity_pattern.h>
58 #include <deal.II/lac/block_sparsity_pattern.h>
59 #include <deal.II/lac/sparse_direct.h>
79 template<
typename CONTROLNONLINEARSOLVER,
typename NONLINEARSOLVER,
80 typename CONTROLINTEGRATOR,
typename INTEGRATOR,
typename PROBLEM,
81 typename VECTOR,
int dopedim,
int dealdim>
97 template<
typename INTEGRATORDATACONT>
100 int base_priority = 0);
115 template<
typename STATEINTEGRATORDATACONT,
116 typename CONTROLINTEGRATORCONT>
119 STATEINTEGRATORDATACONT & s_idc,
int base_priority = 0);
218 template<
class DWRC,
class PDE>
221 DWRC& dwrc, PDE& pde);
259 GetU().PrintInfos(out);
275 WriteToFile(
const VECTOR &v, std::string name, std::string outfile,
276 std::string dof_type, std::string filetype);
385 CONTROLNONLINEARSOLVER&
395 return control_integrator_;
405 INTEGRATOR integrator_;
406 CONTROLINTEGRATOR control_integrator_;
407 NONLINEARSOLVER nonlinear_state_solver_;
408 NONLINEARSOLVER nonlinear_adjoint_solver_;
409 CONTROLNONLINEARSOLVER nonlinear_gradient_solver_;
411 bool build_state_matrix_, build_adjoint_matrix_, build_control_matrix_;
412 bool state_reinit_, adjoint_reinit_, gradient_reinit_;
415 StatReducedProblem<CONTROLNONLINEARSOLVER, NONLINEARSOLVER,
416 CONTROLINTEGRATOR, INTEGRATOR, PROBLEM, VECTOR, dopedim, dealdim>,
423 using namespace dealii;
426 template<
typename CONTROLNONLINEARSOLVER,
typename NONLINEARSOLVER,
427 typename CONTROLINTEGRATOR,
typename INTEGRATOR,
typename PROBLEM,
428 typename VECTOR,
int dopedim,
int dealdim>
431 CONTROLINTEGRATOR, INTEGRATOR, PROBLEM, VECTOR, dopedim, dealdim>::declare_params(
434 NONLINEARSOLVER::declare_params(param_reader);
438 template<
typename CONTROLNONLINEARSOLVER,
typename NONLINEARSOLVER,
439 typename CONTROLINTEGRATOR,
typename INTEGRATOR,
typename PROBLEM,
440 typename VECTOR,
int dopedim,
int dealdim>
441 template<
typename INTEGRATORDATACONT>
448 base_priority), u_(OP->GetSpaceTimeHandler(), state_behavior,
449 param_reader), z_(OP->GetSpaceTimeHandler(), state_behavior,
450 param_reader), du_(OP->GetSpaceTimeHandler(), state_behavior,
451 param_reader), dz_(OP->GetSpaceTimeHandler(), state_behavior,
452 param_reader), z_for_ee_(OP->GetSpaceTimeHandler(),
453 state_behavior, param_reader), integrator_(idc), control_integrator_(
454 idc), nonlinear_state_solver_(integrator_, param_reader), nonlinear_adjoint_solver_(
455 integrator_, param_reader), nonlinear_gradient_solver_(
456 control_integrator_, param_reader)
461 state_reinit_ =
true;
462 adjoint_reinit_ =
true;
463 gradient_reinit_ =
true;
469 template<
typename CONTROLNONLINEARSOLVER,
typename NONLINEARSOLVER,
470 typename CONTROLINTEGRATOR,
typename INTEGRATOR,
typename PROBLEM,
471 typename VECTOR,
int dopedim,
int dealdim>
472 template<
typename STATEINTEGRATORDATACONT,
typename CONTROLINTEGRATORCONT>
477 STATEINTEGRATORDATACONT & s_idc,
int base_priority)
479 base_priority), u_(OP->GetSpaceTimeHandler(), state_behavior,
480 param_reader), z_(OP->GetSpaceTimeHandler(), state_behavior,
481 param_reader), du_(OP->GetSpaceTimeHandler(), state_behavior,
482 param_reader), dz_(OP->GetSpaceTimeHandler(), state_behavior,
483 param_reader), z_for_ee_(OP->GetSpaceTimeHandler(),
484 state_behavior, param_reader), integrator_(s_idc), control_integrator_(
485 c_idc), nonlinear_state_solver_(integrator_, param_reader), nonlinear_adjoint_solver_(
486 integrator_, param_reader), nonlinear_gradient_solver_(
487 control_integrator_, param_reader)
492 state_reinit_ =
true;
493 adjoint_reinit_ =
true;
494 gradient_reinit_ =
true;
500 template<
typename CONTROLNONLINEARSOLVER,
typename NONLINEARSOLVER,
501 typename CONTROLINTEGRATOR,
typename INTEGRATOR,
typename PROBLEM,
502 typename VECTOR,
int dopedim,
int dealdim>
504 CONTROLINTEGRATOR, INTEGRATOR, PROBLEM, VECTOR, dopedim, dealdim>::~StatReducedProblem()
510 template<
typename CONTROLNONLINEARSOLVER,
typename NONLINEARSOLVER,
511 typename CONTROLINTEGRATOR,
typename INTEGRATOR,
typename PROBLEM,
512 typename VECTOR,
int dopedim,
int dealdim>
515 CONTROLINTEGRATOR, INTEGRATOR, PROBLEM, VECTOR, dopedim, dealdim>::GetNonlinearSolver(
518 if ((type ==
"state") || (type ==
"tangent"))
520 return nonlinear_state_solver_;
522 else if ((type ==
"adjoint") || (type ==
"adjoint_hessian")
523 || (type ==
"adjoint_for_ee"))
525 return nonlinear_adjoint_solver_;
529 throw DOpEException(
"No Solver for Problem type:`" + type +
"' found",
530 "StatReducedProblem::GetNonlinearSolver");
536 template<
typename CONTROLNONLINEARSOLVER,
typename NONLINEARSOLVER,
537 typename CONTROLINTEGRATOR,
typename INTEGRATOR,
typename PROBLEM,
538 typename VECTOR,
int dopedim,
int dealdim>
539 CONTROLNONLINEARSOLVER&
541 CONTROLINTEGRATOR, INTEGRATOR, PROBLEM, VECTOR, dopedim, dealdim>::GetControlNonlinearSolver()
543 if ((this->GetProblem()->GetType() ==
"gradient")
544 || (this->GetProblem()->GetType() ==
"hessian"))
546 return nonlinear_gradient_solver_;
551 "No Solver for Problem type:`" + this->GetProblem()->GetType()
552 +
"' found",
"StatReducedProblem::GetControlNonlinearSolver");
558 template<
typename CONTROLNONLINEARSOLVER,
typename NONLINEARSOLVER,
559 typename CONTROLINTEGRATOR,
typename INTEGRATOR,
typename PROBLEM,
560 typename VECTOR,
int dopedim,
int dealdim>
563 CONTROLINTEGRATOR, INTEGRATOR, PROBLEM, VECTOR, dopedim, dealdim>::ReInit()
570 state_reinit_ =
true;
571 adjoint_reinit_ =
true;
572 gradient_reinit_ =
true;
575 build_state_matrix_ =
true;
576 build_adjoint_matrix_ =
true;
582 GetZForEE().ReInit();
584 build_control_matrix_ =
true;
589 template<
typename CONTROLNONLINEARSOLVER,
typename NONLINEARSOLVER,
590 typename CONTROLINTEGRATOR,
typename INTEGRATOR,
typename PROBLEM,
591 typename VECTOR,
int dopedim,
int dealdim>
594 CONTROLINTEGRATOR, INTEGRATOR, PROBLEM, VECTOR, dopedim, dealdim>::ComputeReducedState(
597 this->InitializeFunctionalValues(
598 this->GetProblem()->GetNFunctionals() + 1);
600 this->GetOutputHandler()->Write(
"Computing State Solution:",
601 4 + this->GetBasePriority());
603 this->SetProblemType(
"state");
604 auto& problem = this->GetProblem()->GetStateProblem();
605 if (state_reinit_ ==
true)
607 GetNonlinearSolver(
"state").ReInit(problem);
608 state_reinit_ =
false;
611 this->GetProblem()->AddAuxiliaryToIntegrator(this->GetIntegrator());
612 if (dopedim == dealdim)
616 else if (dopedim == 0)
618 this->GetIntegrator().AddParamData(
"control",
624 "StatReducedProblem::ComputeReducedState");
627 build_state_matrix_ = this->GetNonlinearSolver(
"state").NonlinearSolve(
628 problem, (GetU().GetSpacialVector()),
true, build_state_matrix_);
630 if (dopedim == dealdim)
632 this->GetIntegrator().DeleteDomainData(
"control");
634 else if (dopedim == 0)
636 this->GetIntegrator().DeleteParamData(
"control");
642 "StatReducedProblem::ComputeReducedState");
644 this->GetProblem()->DeleteAuxiliaryFromIntegrator(this->GetIntegrator());
646 this->GetOutputHandler()->Write((GetU().GetSpacialVector()),
647 "State" + this->GetPostIndex(), problem.GetDoFType());
652 template<
typename CONTROLNONLINEARSOLVER,
typename NONLINEARSOLVER,
653 typename CONTROLINTEGRATOR,
typename INTEGRATOR,
typename PROBLEM,
654 typename VECTOR,
int dopedim,
int dealdim>
657 CONTROLINTEGRATOR, INTEGRATOR, PROBLEM, VECTOR, dopedim, dealdim>::ComputeReducedConstraints(
660 this->GetOutputHandler()->Write(
"Evaluating Constraints:",
661 4 + this->GetBasePriority());
663 this->SetProblemType(
"constraints");
669 if (dopedim == dealdim)
671 this->GetControlIntegrator().AddDomainData(
"control",
674 else if (dopedim == 0)
676 this->GetControlIntegrator().AddParamData(
"control",
682 "StatReducedProblem::ComputeReducedConstraints");
684 this->GetControlIntegrator().ComputeLocalControlConstraints(
686 if (dopedim == dealdim)
688 this->GetControlIntegrator().DeleteDomainData(
"control");
690 else if (dopedim == 0)
692 this->GetControlIntegrator().DeleteParamData(
"control");
698 "StatReducedProblem::ComputeReducedConstraints");
704 unsigned int nglobal = gc.size();
708 this->GetProblem()->AddAuxiliaryToIntegrator(this->GetIntegrator());
710 for (
unsigned int i = 0; i < nglobal; i++)
713 this->SetProblemType(
"global_constraints", i);
714 this->GetIntegrator().AddDomainData(
"state",
715 &(GetU().GetSpacialVector()));
716 if (dopedim == dealdim)
718 this->GetIntegrator().AddDomainData(
"control",
721 else if (dopedim == 0)
723 this->GetIntegrator().AddParamData(
"control",
729 "StatReducedProblem::ComputeReducedConstraints");
735 if (this->GetProblem()->GetConstraintType().find(
"domain")
736 != std::string::npos)
739 ret += this->GetIntegrator().ComputeDomainScalar(
740 *(this->GetProblem()));
742 if (this->GetProblem()->GetConstraintType().find(
"point")
743 != std::string::npos)
746 ret += this->GetIntegrator().ComputePointScalar(
747 *(this->GetProblem()));
749 if (this->GetProblem()->GetConstraintType().find(
"boundary")
750 != std::string::npos)
753 ret += this->GetIntegrator().ComputeBoundaryScalar(
754 *(this->GetProblem()));
756 if (this->GetProblem()->GetConstraintType().find(
"face")
757 != std::string::npos)
760 ret += this->GetIntegrator().ComputeFaceScalar(
761 *(this->GetProblem()));
767 "Unknown Constraint Type: "
768 + this->GetProblem()->GetConstraintType(),
769 "StatReducedProblem::ComputeReducedConstraints");
774 if (dopedim == dealdim)
776 this->GetIntegrator().DeleteDomainData(
"control");
778 else if (dopedim == 0)
780 this->GetIntegrator().DeleteParamData(
"control");
786 "StatReducedProblem::ComputeReducedConstraints");
788 this->GetIntegrator().DeleteDomainData(
"state");
791 this->GetProblem()->DeleteAuxiliaryFromIntegrator(
792 this->GetIntegrator());
797 if (g.
HasType(
"local_global_control") || g.
HasType(
"local_global_state"))
800 "There are global in space, local in time constraints given. In the stationary case they should be moved to global in space and time!",
801 "StatReducedProblem::ComputeReducedConstraints");
805 this->GetProblem()->PostProcessConstraints(g);
813 template<
typename CONTROLNONLINEARSOLVER,
typename NONLINEARSOLVER,
814 typename CONTROLINTEGRATOR,
typename INTEGRATOR,
typename PROBLEM,
815 typename VECTOR,
int dopedim,
int dealdim>
818 CONTROLINTEGRATOR, INTEGRATOR, PROBLEM, VECTOR, dopedim, dealdim>::GetControlBoxConstraints(
827 template<
typename CONTROLNONLINEARSOLVER,
typename NONLINEARSOLVER,
828 typename CONTROLINTEGRATOR,
typename INTEGRATOR,
typename PROBLEM,
829 typename VECTOR,
int dopedim,
int dealdim>
832 CONTROLINTEGRATOR, INTEGRATOR, PROBLEM, VECTOR, dopedim, dealdim>::ComputeReducedAdjoint(
835 this->GetOutputHandler()->Write(
"Computing Reduced Adjoint:",
836 4 + this->GetBasePriority());
838 this->SetProblemType(
"adjoint");
839 if (adjoint_reinit_ ==
true)
841 GetNonlinearSolver(
"adjoint").ReInit(*(this->GetProblem()));
842 adjoint_reinit_ =
false;
845 this->GetProblem()->AddAuxiliaryToIntegrator(this->GetIntegrator());
847 this->GetIntegrator().AddDomainData(
"state",
848 &(GetU().GetSpacialVector()));
850 if (dopedim == dealdim)
854 else if (dopedim == 0)
856 this->GetIntegrator().AddParamData(
"control",
862 "StatReducedProblem::ComputeReducedAdjoint");
865 build_adjoint_matrix_ =
866 this->GetNonlinearSolver(
"adjoint").NonlinearSolve(
867 *(this->GetProblem()), (GetZ().GetSpacialVector()),
true,
868 build_adjoint_matrix_);
870 if (dopedim == dealdim)
872 this->GetIntegrator().DeleteDomainData(
"control");
874 else if (dopedim == 0)
876 this->GetIntegrator().DeleteParamData(
"control");
882 "StatReducedProblem::ComputeReducedAdjoint");
884 this->GetIntegrator().DeleteDomainData(
"state");
886 this->GetProblem()->DeleteAuxiliaryFromIntegrator(this->GetIntegrator());
888 this->GetOutputHandler()->Write((GetZ().GetSpacialVector()),
889 "Adjoint" + this->GetPostIndex(), this->GetProblem()->GetDoFType());
894 template<
typename CONTROLNONLINEARSOLVER,
typename NONLINEARSOLVER,
895 typename CONTROLINTEGRATOR,
typename INTEGRATOR,
typename PROBLEM,
896 typename VECTOR,
int dopedim,
int dealdim>
899 CONTROLINTEGRATOR, INTEGRATOR, PROBLEM, VECTOR, dopedim, dealdim>::ComputeDualForErrorEstimation(
903 this->GetOutputHandler()->Write(
"Computing Dual for Error Estimation:",
904 4 + this->GetBasePriority());
908 this->SetProblemType(
"adjoint_for_ee");
913 "StatPDEProblem::ComputeDualForErrorEstimation");
917 auto& problem = *(this->GetProblem());
918 if (adjoint_reinit_ ==
true)
920 GetNonlinearSolver(
"adjoint_for_ee").ReInit(problem);
921 adjoint_reinit_ =
false;
924 this->GetProblem()->AddAuxiliaryToIntegrator(this->GetIntegrator());
926 this->GetIntegrator().AddDomainData(
"state",
927 &(GetU().GetSpacialVector()));
929 if (dopedim == dealdim)
933 else if (dopedim == 0)
935 this->GetIntegrator().AddParamData(
"control",
941 "StatReducedProblem::ComputeReducedAdjoint");
944 build_adjoint_matrix_ =
945 this->GetNonlinearSolver(
"adjoint_for_ee").NonlinearSolve(problem,
946 (GetZForEE().GetSpacialVector()),
true, build_adjoint_matrix_);
948 if (dopedim == dealdim)
950 this->GetIntegrator().DeleteDomainData(
"control");
952 else if (dopedim == 0)
954 this->GetIntegrator().DeleteParamData(
"control");
960 "StatReducedProblem::ComputeReducedAdjoint");
963 this->GetIntegrator().DeleteDomainData(
"state");
965 this->GetProblem()->DeleteAuxiliaryFromIntegrator(this->GetIntegrator());
967 this->GetOutputHandler()->Write((GetZForEE().GetSpacialVector()),
968 "Adjoint_for_ee" + this->GetPostIndex(), problem.GetDoFType());
974 template<
typename CONTROLNONLINEARSOLVER,
typename NONLINEARSOLVER,
975 typename CONTROLINTEGRATOR,
typename INTEGRATOR,
typename PROBLEM,
976 typename VECTOR,
int dopedim,
int dealdim>
979 CONTROLINTEGRATOR, INTEGRATOR, PROBLEM, VECTOR, dopedim, dealdim>::ComputeReducedGradient(
983 this->ComputeReducedAdjoint(q);
985 this->GetOutputHandler()->Write(
"Computing Reduced Gradient:",
986 4 + this->GetBasePriority());
990 if (this->GetProblem()->HasControlInDirichletData())
992 tmp.reinit(GetU().GetSpacialVector());
993 this->SetProblemType(
"adjoint");
994 this->GetProblem()->AddAuxiliaryToIntegrator(this->GetIntegrator());
996 if (dopedim == dealdim)
998 this->GetIntegrator().AddDomainData(
"control",
1001 else if (dopedim == 0)
1003 this->GetIntegrator().AddParamData(
"control",
1009 "StatReducedProblem::ComputeReducedGradient");
1012 this->GetIntegrator().AddDomainData(
"state",
1013 &(GetU().GetSpacialVector()));
1014 this->GetIntegrator().AddDomainData(
"last_newton_solution",
1015 &(GetZ().GetSpacialVector()));
1017 this->GetIntegrator().ComputeNonlinearResidual(*(this->GetProblem()),
1021 if (dopedim == dealdim)
1023 this->GetIntegrator().DeleteDomainData(
"control");
1025 else if (dopedim == 0)
1027 this->GetIntegrator().DeleteParamData(
"control");
1033 "StatReducedProblem::ComputeReducedGradient");
1036 this->GetIntegrator().DeleteDomainData(
"state");
1037 this->GetIntegrator().DeleteDomainData(
"last_newton_solution");
1038 this->GetProblem()->DeleteAuxiliaryFromIntegrator(
1039 this->GetIntegrator());
1042 this->SetProblemType(
"gradient");
1043 if (gradient_reinit_ ==
true)
1045 GetControlNonlinearSolver().ReInit(*(this->GetProblem()));
1046 gradient_reinit_ =
false;
1049 this->GetProblem()->AddAuxiliaryToIntegrator(
1050 this->GetControlIntegrator());
1052 if (dopedim == dealdim)
1054 this->GetControlIntegrator().AddDomainData(
"control",
1057 else if (dopedim == 0)
1059 this->GetControlIntegrator().AddParamData(
"control",
1065 "StatReducedProblem::ComputeReducedGradient");
1068 this->GetControlIntegrator().AddDomainData(
"state",
1069 &(GetU().GetSpacialVector()));
1070 this->GetControlIntegrator().AddDomainData(
"adjoint",
1071 &(GetZ().GetSpacialVector()));
1072 if (this->GetProblem()->HasControlInDirichletData())
1073 this->GetControlIntegrator().AddDomainData(
"adjoint_residual", &tmp);
1075 gradient_transposed = 0.;
1076 if (dopedim == dealdim)
1078 this->GetControlIntegrator().AddDomainData(
"last_newton_solution",
1080 this->GetControlIntegrator().ComputeNonlinearResidual(
1082 this->GetControlIntegrator().DeleteDomainData(
"last_newton_solution");
1084 else if (dopedim == 0)
1086 this->GetControlIntegrator().AddParamData(
"last_newton_solution",
1088 this->GetControlIntegrator().ComputeNonlinearResidual(
1091 this->GetControlIntegrator().DeleteParamData(
"last_newton_solution");
1097 gradient_transposed = gradient;
1101 build_control_matrix_ = this->GetControlNonlinearSolver().NonlinearSolve(
1103 build_control_matrix_);
1104 if (dopedim == dealdim)
1106 this->GetControlIntegrator().DeleteDomainData(
"control");
1108 else if (dopedim == 0)
1110 this->GetControlIntegrator().DeleteParamData(
"control");
1116 "StatReducedProblem::ComputeReducedGradient");
1118 this->GetControlIntegrator().DeleteDomainData(
"state");
1119 this->GetControlIntegrator().DeleteDomainData(
"adjoint");
1120 if (this->GetProblem()->HasControlInDirichletData())
1121 this->GetControlIntegrator().DeleteDomainData(
"adjoint_residual");
1123 this->GetProblem()->DeleteAuxiliaryFromIntegrator(
1124 this->GetControlIntegrator());
1126 this->GetOutputHandler()->Write(gradient,
1127 "Gradient" + this->GetPostIndex(), this->GetProblem()->GetDoFType());
1128 this->GetOutputHandler()->Write(gradient_transposed,
1129 "Gradient_Transposed" + this->GetPostIndex(),
1130 this->GetProblem()->GetDoFType());
1136 template<
typename CONTROLNONLINEARSOLVER,
typename NONLINEARSOLVER,
1137 typename CONTROLINTEGRATOR,
typename INTEGRATOR,
typename PROBLEM,
1138 typename VECTOR,
int dopedim,
int dealdim>
1141 CONTROLINTEGRATOR, INTEGRATOR, PROBLEM, VECTOR, dopedim, dealdim>::ComputeReducedCostFunctional(
1144 this->ComputeReducedState(q);
1149 this->GetOutputHandler()->Write(
"Computing Cost Functional:",
1150 4 + this->GetBasePriority());
1152 this->SetProblemType(
"cost_functional");
1154 this->GetProblem()->AddAuxiliaryToIntegrator(this->GetIntegrator());
1156 if (dopedim == dealdim)
1160 else if (dopedim == 0)
1162 this->GetIntegrator().AddParamData(
"control",
1168 "StatReducedProblem::ComputeReducedCostFunctional");
1170 this->GetIntegrator().AddDomainData(
"state",
1171 &(GetU().GetSpacialVector()));
1173 if (this->GetProblem()->GetFunctionalType().find(
"domain")
1174 != std::string::npos)
1177 ret += this->GetIntegrator().ComputeDomainScalar(*(this->GetProblem()));
1179 if (this->GetProblem()->GetFunctionalType().find(
"point")
1180 != std::string::npos)
1183 ret += this->GetIntegrator().ComputePointScalar(*(this->GetProblem()));
1185 if (this->GetProblem()->GetFunctionalType().find(
"boundary")
1186 != std::string::npos)
1189 ret += this->GetIntegrator().ComputeBoundaryScalar(
1190 *(this->GetProblem()));
1192 if (this->GetProblem()->GetFunctionalType().find(
"face")
1193 != std::string::npos)
1196 ret += this->GetIntegrator().ComputeFaceScalar(*(this->GetProblem()));
1202 "Unknown Functional Type: "
1203 + this->GetProblem()->GetFunctionalType(),
1204 "StatReducedProblem::ComputeReducedCostFunctional");
1207 if (dopedim == dealdim)
1209 this->GetIntegrator().DeleteDomainData(
"control");
1211 else if (dopedim == 0)
1213 this->GetIntegrator().DeleteParamData(
"control");
1219 "StatReducedProblem::ComputeReducedCostFunctional");
1221 this->GetIntegrator().DeleteDomainData(
"state");
1222 this->GetProblem()->DeleteAuxiliaryFromIntegrator(this->GetIntegrator());
1224 this->GetFunctionalValues()[0].push_back(ret);
1230 template<
typename CONTROLNONLINEARSOLVER,
typename NONLINEARSOLVER,
1231 typename CONTROLINTEGRATOR,
typename INTEGRATOR,
typename PROBLEM,
1232 typename VECTOR,
int dopedim,
int dealdim>
1235 CONTROLINTEGRATOR, INTEGRATOR, PROBLEM, VECTOR, dopedim, dealdim>::ComputeReducedFunctionals(
1238 this->GetOutputHandler()->Write(
"Computing Functionals:",
1239 4 + this->GetBasePriority());
1241 this->GetProblem()->AddAuxiliaryToIntegrator(this->GetIntegrator());
1243 if (dopedim == dealdim)
1247 else if (dopedim == 0)
1249 this->GetIntegrator().AddParamData(
"control",
1255 "StatReducedProblem::ComputeReducedFunctionals");
1257 this->GetIntegrator().AddDomainData(
"state",
1258 &(GetU().GetSpacialVector()));
1260 for (
unsigned int i = 0; i < this->GetProblem()->GetNFunctionals(); i++)
1265 this->SetProblemType(
"aux_functional", i);
1266 if (this->GetProblem()->GetFunctionalType().find(
"domain")
1267 != std::string::npos)
1270 ret += this->GetIntegrator().ComputeDomainScalar(
1271 *(this->GetProblem()));
1273 if (this->GetProblem()->GetFunctionalType().find(
"point")
1274 != std::string::npos)
1277 ret += this->GetIntegrator().ComputePointScalar(
1278 *(this->GetProblem()));
1280 if (this->GetProblem()->GetFunctionalType().find(
"boundary")
1281 != std::string::npos)
1284 ret += this->GetIntegrator().ComputeBoundaryScalar(
1285 *(this->GetProblem()));
1287 if (this->GetProblem()->GetFunctionalType().find(
"face")
1288 != std::string::npos)
1291 ret += this->GetIntegrator().ComputeFaceScalar(*(this->GetProblem()));
1297 "Unknown Functional Type: "
1298 + this->GetProblem()->GetFunctionalType(),
1299 "StatReducedProblem::ComputeReducedFunctionals");
1301 this->GetFunctionalValues()[i + 1].push_back(ret);
1302 std::stringstream out;
1303 this->GetOutputHandler()->InitOut(out);
1304 out << this->GetProblem()->GetFunctionalName() <<
": " << ret;
1305 this->GetOutputHandler()->Write(out, 2 + this->GetBasePriority());
1308 if (dopedim == dealdim)
1310 this->GetIntegrator().DeleteDomainData(
"control");
1312 else if (dopedim == 0)
1314 this->GetIntegrator().DeleteParamData(
"control");
1320 "StatReducedProblem::ComputeReducedFunctionals");
1322 this->GetIntegrator().DeleteDomainData(
"state");
1323 this->GetProblem()->DeleteAuxiliaryFromIntegrator(this->GetIntegrator());
1329 template<
typename CONTROLNONLINEARSOLVER,
typename NONLINEARSOLVER,
1330 typename CONTROLINTEGRATOR,
typename INTEGRATOR,
typename PROBLEM,
1331 typename VECTOR,
int dopedim,
int dealdim>
1332 template<
class DWRC,
class PDE>
1335 CONTROLINTEGRATOR, INTEGRATOR, PROBLEM, VECTOR, dopedim, dealdim>::ComputeRefinementIndicators(
1342 pde.ResidualModifier = boost::bind<void>(boost::mem_fn(&DWRC::ResidualModifier),boost::ref(dwrc),_1);
1343 pde.VectorResidualModifier = boost::bind<void>(boost::mem_fn(&DWRC::VectorResidualModifier),boost::ref(dwrc),_1);
1347 const unsigned int n_elements =
1348 this->GetProblem()->GetSpaceTimeHandler()->GetStateDoFHandler().get_tria().n_active_cells();
1352 if(this->GetProblem()->EEFunctionalIsCost() || !dwrc.NeedDual())
1354 this->GetOutputHandler()->Write(
"Computing Error Indicators:",
1355 4 + this->GetBasePriority());
1356 this->GetProblem()->AddAuxiliaryToIntegrator(this->GetIntegrator());
1359 this->GetIntegrator().AddDomainData(
"state",
1360 &(GetU().GetSpacialVector()));
1361 this->GetIntegrator().AddDomainData(
"adjoint_for_ee",
1362 &(GetZ().GetSpacialVector()));
1364 if (dopedim == dealdim)
1366 this->GetIntegrator().AddDomainData(
"control",
1369 else if (dopedim == 0)
1371 this->GetIntegrator().AddParamData(
"control",
1377 "StatReducedProblem::ComputeRefinementIndicators");
1380 this->SetProblemType(
"error_evaluation");
1383 dwrc.PrepareWeights(GetU(), GetZ());
1384 dwrc.PrepareWeights(q);
1387 this->GetIntegrator().ComputeRefinementIndicators(*this->GetProblem(),
1391 dwrc.ClearWeightData();
1394 if (dopedim == dealdim)
1396 this->GetIntegrator().DeleteDomainData(
"control");
1398 else if (dopedim == 0)
1400 this->GetIntegrator().DeleteParamData(
"control");
1406 "StatReducedProblem::ComputeRefinementIndicators");
1408 this->GetIntegrator().DeleteDomainData(
"state");
1409 this->GetIntegrator().DeleteDomainData(
"adjoint_for_ee");
1410 this->GetProblem()->DeleteAuxiliaryFromIntegrator(
1411 this->GetIntegrator());
1415 throw DOpEException(
"Estimating the error in other functionals than cost is not implemented",
1416 "StatReducedProblem::ComputeRefinementIndicators");
1420 std::stringstream out;
1421 this->GetOutputHandler()->InitOut(out);
1422 out <<
"Error estimate using "<<dwrc.GetName();
1424 out<<
" For the computation of "<<this->GetProblem()->GetFunctionalName();
1425 out<<
": "<< dwrc.GetError();
1426 this->GetOutputHandler()->Write(out, 2 + this->GetBasePriority());
1431 template<
typename CONTROLNONLINEARSOLVER,
typename NONLINEARSOLVER,
1432 typename CONTROLINTEGRATOR,
typename INTEGRATOR,
typename PROBLEM,
1433 typename VECTOR,
int dopedim,
int dealdim>
1436 CONTROLINTEGRATOR, INTEGRATOR, PROBLEM, VECTOR, dopedim, dealdim>::ComputeReducedHessianVector(
1441 this->GetOutputHandler()->Write(
"Computing ReducedHessianVector:",
1442 4 + this->GetBasePriority());
1443 this->GetOutputHandler()->Write(
"\tSolving Tangent:",
1444 5 + this->GetBasePriority());
1446 this->SetProblemType(
"tangent");
1448 this->GetProblem()->AddAuxiliaryToIntegrator(this->GetIntegrator());
1450 this->GetIntegrator().AddDomainData(
"state",
1451 &(GetU().GetSpacialVector()));
1452 this->GetControlIntegrator().AddDomainData(
"state",
1453 &(GetU().GetSpacialVector()));
1455 if (dopedim == dealdim)
1457 this->GetIntegrator().AddDomainData(
"dq",
1461 else if (dopedim == 0)
1463 this->GetIntegrator().AddParamData(
"dq",
1465 this->GetIntegrator().AddParamData(
"control",
1471 "StatReducedProblem::ComputeReducedHessianVector");
1475 build_state_matrix_ = this->GetNonlinearSolver(
"tangent").NonlinearSolve(
1476 *(this->GetProblem()), (GetDU().GetSpacialVector()),
true,
1477 build_state_matrix_);
1479 this->GetOutputHandler()->Write((GetDU().GetSpacialVector()),
1480 "Tangent" + this->GetPostIndex(), this->GetProblem()->GetDoFType());
1482 this->GetOutputHandler()->Write(
"\tSolving Adjoint Hessian:",
1483 5 + this->GetBasePriority());
1484 this->SetProblemType(
"adjoint_hessian");
1485 this->GetIntegrator().AddDomainData(
"adjoint",
1486 &(GetZ().GetSpacialVector()));
1487 this->GetIntegrator().AddDomainData(
"tangent",
1488 &(GetDU().GetSpacialVector()));
1489 this->GetControlIntegrator().AddDomainData(
"adjoint",
1490 &(GetZ().GetSpacialVector()));
1491 this->GetControlIntegrator().AddDomainData(
"tangent",
1492 &(GetDU().GetSpacialVector()));
1495 build_adjoint_matrix_ =
1496 this->GetNonlinearSolver(
"adjoint_hessian").NonlinearSolve(
1497 *(this->GetProblem()), (GetDZ().GetSpacialVector()),
true,
1498 build_adjoint_matrix_);
1500 this->GetOutputHandler()->Write((GetDZ().GetSpacialVector()),
1501 "Hessian" + this->GetPostIndex(), this->GetProblem()->GetDoFType());
1503 this->GetIntegrator().AddDomainData(
"adjoint_hessian",
1504 &(GetDZ().GetSpacialVector()));
1505 this->GetControlIntegrator().AddDomainData(
"adjoint_hessian",
1506 &(GetDZ().GetSpacialVector()));
1508 this->GetOutputHandler()->Write(
1509 "\tComputing Representation of the Hessian:",
1510 5 + this->GetBasePriority());
1514 if (this->GetProblem()->HasControlInDirichletData())
1516 tmp.reinit(GetU().GetSpacialVector());
1517 tmp_second.reinit(GetU().GetSpacialVector());
1518 this->SetProblemType(
"adjoint");
1519 this->GetIntegrator().AddDomainData(
"last_newton_solution",
1520 &(GetZ().GetSpacialVector()));
1522 this->GetIntegrator().ComputeNonlinearResidual(*(this->GetProblem()),
1526 this->GetIntegrator().DeleteDomainData(
"last_newton_solution");
1527 this->SetProblemType(
"adjoint_hessian");
1528 this->GetIntegrator().AddDomainData(
"last_newton_solution",
1529 &(GetDZ().GetSpacialVector()));
1531 this->GetIntegrator().ComputeNonlinearResidual(*(this->GetProblem()),
1535 this->GetIntegrator().DeleteDomainData(
"last_newton_solution");
1538 this->GetProblem()->DeleteAuxiliaryFromIntegrator(this->GetIntegrator());
1540 this->SetProblemType(
"hessian");
1541 this->GetProblem()->AddAuxiliaryToIntegrator(
1542 this->GetControlIntegrator());
1543 if (dopedim == dealdim)
1545 this->GetIntegrator().DeleteDomainData(
"dq");
1546 this->GetIntegrator().DeleteDomainData(
"control");
1547 this->GetControlIntegrator().AddDomainData(
"dq",
1549 this->GetControlIntegrator().AddDomainData(
"control",
1552 else if (dopedim == 0)
1554 this->GetIntegrator().DeleteParamData(
"dq");
1555 this->GetIntegrator().DeleteParamData(
"control");
1558 this->GetControlIntegrator().AddParamData(
"dq",
1560 this->GetControlIntegrator().AddParamData(
"control",
1566 "StatReducedProblem::ComputeReducedHessianVector");
1568 if (this->GetProblem()->HasControlInDirichletData())
1570 this->GetControlIntegrator().AddDomainData(
"adjoint_residual", &tmp);
1571 this->GetControlIntegrator().AddDomainData(
"hessian_residual",
1576 hessian_direction_transposed = 0.;
1577 if (dopedim == dealdim)
1579 this->GetControlIntegrator().AddDomainData(
"last_newton_solution",
1581 this->GetControlIntegrator().ComputeNonlinearResidual(
1584 this->GetControlIntegrator().DeleteDomainData(
"last_newton_solution");
1586 else if (dopedim == 0)
1588 this->GetControlIntegrator().AddParamData(
"last_newton_solution",
1590 this->GetControlIntegrator().ComputeNonlinearResidual(
1593 this->GetControlIntegrator().DeleteParamData(
"last_newton_solution");
1596 hessian_direction *= -1.;
1597 hessian_direction_transposed = hessian_direction;
1600 build_control_matrix_ =
1601 this->GetControlNonlinearSolver().NonlinearSolve(
1602 *(this->GetProblem()),
1604 build_control_matrix_);
1606 this->GetOutputHandler()->Write(hessian_direction,
1607 "HessianDirection" + this->GetPostIndex(),
1608 this->GetProblem()->GetDoFType());
1609 this->GetOutputHandler()->Write(hessian_direction_transposed,
1610 "HessianDirection_Transposed" + this->GetPostIndex(),
1611 this->GetProblem()->GetDoFType());
1614 if (dopedim == dealdim)
1616 this->GetControlIntegrator().DeleteDomainData(
"dq");
1617 this->GetControlIntegrator().DeleteDomainData(
"control");
1619 else if (dopedim == 0)
1621 this->GetControlIntegrator().DeleteParamData(
"dq");
1622 this->GetControlIntegrator().DeleteParamData(
"control");
1629 "StatReducedProblem::ComputeReducedHessianVector");
1631 this->GetIntegrator().DeleteDomainData(
"state");
1632 this->GetIntegrator().DeleteDomainData(
"adjoint");
1633 this->GetIntegrator().DeleteDomainData(
"tangent");
1634 this->GetIntegrator().DeleteDomainData(
"adjoint_hessian");
1635 this->GetControlIntegrator().DeleteDomainData(
"state");
1636 this->GetControlIntegrator().DeleteDomainData(
"adjoint");
1637 this->GetControlIntegrator().DeleteDomainData(
"tangent");
1638 this->GetControlIntegrator().DeleteDomainData(
"adjoint_hessian");
1639 if (this->GetProblem()->HasControlInDirichletData())
1641 this->GetControlIntegrator().DeleteDomainData(
"adjoint_residual");
1642 this->GetControlIntegrator().DeleteDomainData(
"hessian_residual");
1644 this->GetProblem()->DeleteAuxiliaryFromIntegrator(
1645 this->GetControlIntegrator());
1651 template<
typename CONTROLNONLINEARSOLVER,
typename NONLINEARSOLVER,
1652 typename CONTROLINTEGRATOR,
typename INTEGRATOR,
typename PROBLEM,
1653 typename VECTOR,
int dopedim,
int dealdim>
1656 CONTROLINTEGRATOR, INTEGRATOR, PROBLEM, VECTOR, dopedim, dealdim>::ComputeReducedGradientOfGlobalConstraints(
1663 std::stringstream out;
1664 out <<
"Computing Reduced Gradient of global constraint " << num <<
" :";
1665 this->GetOutputHandler()->Write(out, 4 + this->GetBasePriority());
1667 this->SetProblemType(
"global_constraint_gradient", num);
1669 if (dopedim == dealdim)
1671 this->GetControlIntegrator().AddDomainData(
"control",
1674 else if (dopedim == 0)
1676 this->GetControlIntegrator().AddParamData(
"control",
1682 "StatReducedProblem::ComputeReducedGradient");
1684 this->GetProblem()->AddAuxiliaryToIntegrator(
1685 this->GetControlIntegrator());
1686 this->GetControlIntegrator().AddDomainData(
"constraints_local",
1688 this->GetControlIntegrator().AddParamData(
"constraints_global",
1692 this->GetControlIntegrator().ComputeNonlinearRhs(*(this->GetProblem()),
1694 gradient_transposed = gradient;
1696 this->GetControlIntegrator().DeleteDomainData(
"constraints_local");
1697 this->GetControlIntegrator().DeleteParamData(
"constraints_global");
1698 this->GetProblem()->DeleteAuxiliaryFromIntegrator(
1699 this->GetControlIntegrator());
1700 if (dopedim == dealdim)
1702 this->GetControlIntegrator().DeleteDomainData(
"control");
1704 else if (dopedim == 0)
1706 this->GetControlIntegrator().DeleteParamData(
"control");
1712 "StatReducedProblem::ComputeReducedGradient");
1718 template<
typename CONTROLNONLINEARSOLVER,
typename NONLINEARSOLVER,
1719 typename CONTROLINTEGRATOR,
typename INTEGRATOR,
typename PROBLEM,
1720 typename VECTOR,
int dopedim,
int dealdim>
1723 CONTROLINTEGRATOR, INTEGRATOR, PROBLEM, VECTOR, dopedim, dealdim>::WriteToFile(
1724 const VECTOR &v, std::string name, std::string outfile,
1725 std::string dof_type, std::string filetype)
1727 if (dof_type ==
"state")
1730 this->GetProblem()->GetSpaceTimeHandler()->GetDataOut();
1731 data_out.attach_dof_handler(
1732 this->GetProblem()->GetSpaceTimeHandler()->GetStateDoFHandler());
1734 data_out.add_data_vector(v, name);
1735 data_out.build_patches();
1737 std::ofstream output(outfile.c_str());
1739 if (filetype ==
".vtk")
1741 data_out.write_vtk(output);
1743 else if (filetype ==
".gpl")
1745 data_out.write_gnuplot(output);
1750 "Don't know how to write filetype `" + filetype +
"'!",
1751 "StatReducedProblem::WriteToFile");
1755 else if (dof_type ==
"control")
1757 #if dope_dimension >0
1758 auto& data_out = this->GetProblem()->GetSpaceTimeHandler()->GetDataOut();
1759 data_out.attach_dof_handler (this->GetProblem()->GetSpaceTimeHandler()->GetControlDoFHandler());
1761 data_out.add_data_vector (v,name);
1762 data_out.build_patches ();
1764 std::ofstream output(outfile.c_str());
1766 if(filetype ==
".vtk")
1768 data_out.write_vtk (output);
1770 else if (filetype ==
".gpl")
1772 data_out.write_gnuplot(output);
1776 throw DOpEException(
"Don't know how to write filetype `" + filetype +
"'!",
1777 "StatReducedProblem::WriteToFile");
1781 if (filetype ==
".txt")
1783 std::ofstream output(outfile.c_str());
1786 for (
unsigned int i = 0; i < off.size(); i++)
1788 output << off(i) << std::endl;
1794 "Don't know how to write filetype `" + filetype +
"'!",
1795 "StatReducedProblem::WriteToFile");
1801 throw DOpEException(
"No such DoFHandler `" + dof_type +
"'!",
1802 "StatReducedProblem::WriteToFile");
1808 template<
typename CONTROLNONLINEARSOLVER,
typename NONLINEARSOLVER,
1809 typename CONTROLINTEGRATOR,
typename INTEGRATOR,
typename PROBLEM,
1810 typename VECTOR,
int dopedim,
int dealdim>
1813 CONTROLINTEGRATOR, INTEGRATOR, PROBLEM, VECTOR, dopedim, dealdim>::WriteToFile(
1815 std::string dof_type)
void ComputeRefinementIndicators(const ControlVector< VECTOR > &q, DWRC &dwrc, PDE &pde)
Definition: statreducedproblem.h:1335
CONTROLINTEGRATOR & GetControlIntegrator()
Definition: statreducedproblem.h:393
void UnLockCopy() const
Definition: controlvector.h:199
Definition: constraintvector.h:48
const dealii::Vector< double > & GetSpacialVectorCopy() const
Definition: controlvector.cc:276
NONLINEARSOLVER & GetNonlinearSolver(std::string type)
Definition: statreducedproblem.h:515
CONTROLNONLINEARSOLVER & GetControlNonlinearSolver()
Definition: statreducedproblem.h:541
void ComputeReducedFunctionals(const ControlVector< VECTOR > &q)
Definition: statreducedproblem.h:1235
void ReInit()
Definition: statreducedproblem.h:563
INTEGRATOR & GetIntegrator()
Definition: statreducedproblem.h:388
void ComputeDualForErrorEstimation(const ControlVector< VECTOR > &q, DOpEtypes::WeightComputation weight_comp)
Definition: statreducedproblem.h:899
StateVector< VECTOR > & GetU()
Definition: statreducedproblem.h:350
Definition: parameterreader.h:36
void WriteToFile(const VECTOR &v, std::string name, std::string outfile, std::string dof_type, std::string filetype)
Definition: statreducedproblem.h:1723
void ComputeReducedAdjoint(const ControlVector< VECTOR > &q)
Definition: statreducedproblem.h:832
const dealii::Vector< double > & GetGlobalConstraints() const
Definition: constraintvector.cc:174
Definition: statreducedproblem.h:82
StateVector< VECTOR > & GetZ()
Definition: statreducedproblem.h:355
StateVector< VECTOR > & GetZForEE()
Definition: statreducedproblem.h:378
Definition: controlvector.h:49
Definition: dopetypes.h:82
static void declare_params(ParameterReader ¶m_reader)
Definition: statreducedproblem.h:431
void GetControlBoxConstraints(ControlVector< VECTOR > &lb, ControlVector< VECTOR > &ub)
Definition: statreducedproblem.h:818
double ComputeReducedCostFunctional(const ControlVector< VECTOR > &q)
Definition: statreducedproblem.h:1141
const StateVector< VECTOR > & GetZForEE() const
Definition: statreducedproblem.h:373
StateVector< VECTOR > & GetDZ()
Definition: statreducedproblem.h:365
void ComputeReducedGradient(const ControlVector< VECTOR > &q, ControlVector< VECTOR > &gradient, ControlVector< VECTOR > &gradient_transposed)
Definition: statreducedproblem.h:979
Definition: statevector.h:50
VECTOR & GetSpacialVector()
******************************************************/
Definition: controlvector.cc:204
bool HasType(std::string name) const
******************************************************/
Definition: constraintvector.cc:119
VectorStorageType
Definition: dopetypes.h:120
WeightComputation
Definition: dopetypes.h:80
void ComputeReducedState(const ControlVector< VECTOR > &q)
Definition: statreducedproblem.h:594
Definition: reducedprobleminterface.h:335
StatReducedProblem(PROBLEM *OP, DOpEtypes::VectorStorageType state_behavior, ParameterReader ¶m_reader, INTEGRATORDATACONT &idc, int base_priority=0)
Definition: statreducedproblem.h:443
void ComputeReducedHessianVector(const ControlVector< VECTOR > &q, const ControlVector< VECTOR > &direction, ControlVector< VECTOR > &hessian_direction, ControlVector< VECTOR > &hessian_direction_transposed)
Definition: statreducedproblem.h:1436
bool ComputeReducedConstraints(const ControlVector< VECTOR > &q, ConstraintVector< VECTOR > &g)
Definition: statreducedproblem.h:657
void StateSizeInfo(std::stringstream &out)
Definition: statreducedproblem.h:257
VECTOR & GetSpacialVector(std::string name)
Definition: constraintvector.cc:130
Definition: dopeexception.h:35
void WriteToFile(const std::vector< double > &, std::string)
Definition: statreducedproblem.h:299
const StateVector< VECTOR > & GetU() const
Definition: statreducedproblem.h:345
virtual bool IsFeasible() const
Definition: constraintvector.cc:574
StateVector< VECTOR > & GetDU()
Definition: statreducedproblem.h:360
virtual void ReInit()
Definition: reducedprobleminterface.h:357
~StatReducedProblem()
Definition: statreducedproblem.h:504
void ComputeReducedGradientOfGlobalConstraints(unsigned int num, const ControlVector< VECTOR > &q, const ConstraintVector< VECTOR > &g, ControlVector< VECTOR > &gradient, ControlVector< VECTOR > &gradient_transposed)
Definition: statreducedproblem.h:1656