24 #ifndef STAT_REDUCED_PROBLEM_H_
25 #define STAT_REDUCED_PROBLEM_H_
33 #include <lac/vector.h>
35 #include <lac/block_sparsity_pattern.h>
36 #include <lac/block_sparse_matrix.h>
52 #include <base/data_out_base.h>
53 #include <numerics/data_out.h>
54 #include <numerics/matrix_tools.h>
55 #include <numerics/vector_tools.h>
56 #include <base/function.h>
57 #include <lac/sparse_matrix.h>
58 #include <lac/compressed_simple_sparsity_pattern.h>
59 #include <lac/block_sparsity_pattern.h>
60 #include <lac/sparse_direct.h>
80 template<
typename CONTROLNONLINEARSOLVER,
typename NONLINEARSOLVER,
81 typename CONTROLINTEGRATOR,
typename INTEGRATOR,
typename PROBLEM,
82 typename VECTOR,
int dopedim,
int dealdim>
98 template<
typename INTEGRATORDATACONT>
101 int base_priority = 0);
116 template<
typename STATEINTEGRATORDATACONT,
117 typename CONTROLINTEGRATORCONT>
120 STATEINTEGRATORDATACONT & s_idc,
int base_priority = 0);
219 template<
class DWRC,
class PDE>
222 DWRC& dwrc, PDE& pde);
260 GetU().PrintInfos(out);
276 WriteToFile(
const VECTOR &v, std::string name, std::string outfile,
277 std::string dof_type, std::string filetype);
386 CONTROLNONLINEARSOLVER&
396 return control_integrator_;
406 INTEGRATOR integrator_;
407 CONTROLINTEGRATOR control_integrator_;
408 NONLINEARSOLVER nonlinear_state_solver_;
409 NONLINEARSOLVER nonlinear_adjoint_solver_;
410 CONTROLNONLINEARSOLVER nonlinear_gradient_solver_;
412 bool build_state_matrix_, build_adjoint_matrix_, build_control_matrix_;
413 bool state_reinit_, adjoint_reinit_, gradient_reinit_;
416 StatReducedProblem<CONTROLNONLINEARSOLVER, NONLINEARSOLVER,
417 CONTROLINTEGRATOR, INTEGRATOR, PROBLEM, VECTOR, dopedim, dealdim>,
424 using namespace dealii;
427 template<
typename CONTROLNONLINEARSOLVER,
typename NONLINEARSOLVER,
428 typename CONTROLINTEGRATOR,
typename INTEGRATOR,
typename PROBLEM,
429 typename VECTOR,
int dopedim,
int dealdim>
432 CONTROLINTEGRATOR, INTEGRATOR, PROBLEM, VECTOR, dopedim, dealdim>::declare_params(
435 NONLINEARSOLVER::declare_params(param_reader);
439 template<
typename CONTROLNONLINEARSOLVER,
typename NONLINEARSOLVER,
440 typename CONTROLINTEGRATOR,
typename INTEGRATOR,
typename PROBLEM,
441 typename VECTOR,
int dopedim,
int dealdim>
442 template<
typename INTEGRATORDATACONT>
449 base_priority), u_(OP->GetSpaceTimeHandler(), state_behavior,
450 param_reader), z_(OP->GetSpaceTimeHandler(), state_behavior,
451 param_reader), du_(OP->GetSpaceTimeHandler(), state_behavior,
452 param_reader), dz_(OP->GetSpaceTimeHandler(), state_behavior,
453 param_reader), z_for_ee_(OP->GetSpaceTimeHandler(),
454 state_behavior, param_reader), integrator_(idc), control_integrator_(
455 idc), nonlinear_state_solver_(integrator_, param_reader), nonlinear_adjoint_solver_(
456 integrator_, param_reader), nonlinear_gradient_solver_(
457 control_integrator_, param_reader)
462 state_reinit_ =
true;
463 adjoint_reinit_ =
true;
464 gradient_reinit_ =
true;
470 template<
typename CONTROLNONLINEARSOLVER,
typename NONLINEARSOLVER,
471 typename CONTROLINTEGRATOR,
typename INTEGRATOR,
typename PROBLEM,
472 typename VECTOR,
int dopedim,
int dealdim>
473 template<
typename STATEINTEGRATORDATACONT,
typename CONTROLINTEGRATORCONT>
478 STATEINTEGRATORDATACONT & s_idc,
int base_priority)
480 base_priority), u_(OP->GetSpaceTimeHandler(), state_behavior,
481 param_reader), z_(OP->GetSpaceTimeHandler(), state_behavior,
482 param_reader), du_(OP->GetSpaceTimeHandler(), state_behavior,
483 param_reader), dz_(OP->GetSpaceTimeHandler(), state_behavior,
484 param_reader), z_for_ee_(OP->GetSpaceTimeHandler(),
485 state_behavior, param_reader), integrator_(s_idc), control_integrator_(
486 c_idc), nonlinear_state_solver_(integrator_, param_reader), nonlinear_adjoint_solver_(
487 integrator_, param_reader), nonlinear_gradient_solver_(
488 control_integrator_, param_reader)
493 state_reinit_ =
true;
494 adjoint_reinit_ =
true;
495 gradient_reinit_ =
true;
501 template<
typename CONTROLNONLINEARSOLVER,
typename NONLINEARSOLVER,
502 typename CONTROLINTEGRATOR,
typename INTEGRATOR,
typename PROBLEM,
503 typename VECTOR,
int dopedim,
int dealdim>
505 CONTROLINTEGRATOR, INTEGRATOR, PROBLEM, VECTOR, dopedim, dealdim>::~StatReducedProblem()
511 template<
typename CONTROLNONLINEARSOLVER,
typename NONLINEARSOLVER,
512 typename CONTROLINTEGRATOR,
typename INTEGRATOR,
typename PROBLEM,
513 typename VECTOR,
int dopedim,
int dealdim>
516 CONTROLINTEGRATOR, INTEGRATOR, PROBLEM, VECTOR, dopedim, dealdim>::GetNonlinearSolver(
519 if ((type ==
"state") || (type ==
"tangent"))
521 return nonlinear_state_solver_;
523 else if ((type ==
"adjoint") || (type ==
"adjoint_hessian")
524 || (type ==
"adjoint_for_ee"))
526 return nonlinear_adjoint_solver_;
530 throw DOpEException(
"No Solver for Problem type:`" + type +
"' found",
531 "StatReducedProblem::GetNonlinearSolver");
537 template<
typename CONTROLNONLINEARSOLVER,
typename NONLINEARSOLVER,
538 typename CONTROLINTEGRATOR,
typename INTEGRATOR,
typename PROBLEM,
539 typename VECTOR,
int dopedim,
int dealdim>
540 CONTROLNONLINEARSOLVER&
542 CONTROLINTEGRATOR, INTEGRATOR, PROBLEM, VECTOR, dopedim, dealdim>::GetControlNonlinearSolver()
544 if ((this->GetProblem()->GetType() ==
"gradient")
545 || (this->GetProblem()->GetType() ==
"hessian"))
547 return nonlinear_gradient_solver_;
552 "No Solver for Problem type:`" + this->GetProblem()->GetType()
553 +
"' found",
"StatReducedProblem::GetControlNonlinearSolver");
559 template<
typename CONTROLNONLINEARSOLVER,
typename NONLINEARSOLVER,
560 typename CONTROLINTEGRATOR,
typename INTEGRATOR,
typename PROBLEM,
561 typename VECTOR,
int dopedim,
int dealdim>
564 CONTROLINTEGRATOR, INTEGRATOR, PROBLEM, VECTOR, dopedim, dealdim>::ReInit()
571 state_reinit_ =
true;
572 adjoint_reinit_ =
true;
573 gradient_reinit_ =
true;
576 build_state_matrix_ =
true;
577 build_adjoint_matrix_ =
true;
583 GetZForEE().ReInit();
585 build_control_matrix_ =
true;
590 template<
typename CONTROLNONLINEARSOLVER,
typename NONLINEARSOLVER,
591 typename CONTROLINTEGRATOR,
typename INTEGRATOR,
typename PROBLEM,
592 typename VECTOR,
int dopedim,
int dealdim>
595 CONTROLINTEGRATOR, INTEGRATOR, PROBLEM, VECTOR, dopedim, dealdim>::ComputeReducedState(
598 this->InitializeFunctionalValues(
599 this->GetProblem()->GetNFunctionals() + 1);
601 this->GetOutputHandler()->Write(
"Computing State Solution:",
602 4 + this->GetBasePriority());
604 this->SetProblemType(
"state");
605 auto& problem = this->GetProblem()->GetStateProblem();
606 if (state_reinit_ ==
true)
608 GetNonlinearSolver(
"state").ReInit(problem);
609 state_reinit_ =
false;
612 this->GetProblem()->AddAuxiliaryToIntegrator(this->GetIntegrator());
613 if (dopedim == dealdim)
617 else if (dopedim == 0)
619 this->GetIntegrator().AddParamData(
"control",
625 "StatReducedProblem::ComputeReducedState");
628 build_state_matrix_ = this->GetNonlinearSolver(
"state").NonlinearSolve(
629 problem, (GetU().GetSpacialVector()),
true, build_state_matrix_);
631 if (dopedim == dealdim)
633 this->GetIntegrator().DeleteDomainData(
"control");
635 else if (dopedim == 0)
637 this->GetIntegrator().DeleteParamData(
"control");
643 "StatReducedProblem::ComputeReducedState");
645 this->GetProblem()->DeleteAuxiliaryFromIntegrator(this->GetIntegrator());
647 this->GetOutputHandler()->Write((GetU().GetSpacialVector()),
648 "State" + this->GetPostIndex(), problem.GetDoFType());
653 template<
typename CONTROLNONLINEARSOLVER,
typename NONLINEARSOLVER,
654 typename CONTROLINTEGRATOR,
typename INTEGRATOR,
typename PROBLEM,
655 typename VECTOR,
int dopedim,
int dealdim>
658 CONTROLINTEGRATOR, INTEGRATOR, PROBLEM, VECTOR, dopedim, dealdim>::ComputeReducedConstraints(
661 this->GetOutputHandler()->Write(
"Evaluating Constraints:",
662 4 + this->GetBasePriority());
664 this->SetProblemType(
"constraints");
670 if (dopedim == dealdim)
672 this->GetControlIntegrator().AddDomainData(
"control",
675 else if (dopedim == 0)
677 this->GetControlIntegrator().AddParamData(
"control",
683 "StatReducedProblem::ComputeReducedConstraints");
685 this->GetControlIntegrator().ComputeLocalControlConstraints(
687 if (dopedim == dealdim)
689 this->GetControlIntegrator().DeleteDomainData(
"control");
691 else if (dopedim == 0)
693 this->GetControlIntegrator().DeleteParamData(
"control");
699 "StatReducedProblem::ComputeReducedConstraints");
705 unsigned int nglobal = gc.size();
709 this->GetProblem()->AddAuxiliaryToIntegrator(this->GetIntegrator());
711 for (
unsigned int i = 0; i < nglobal; i++)
714 this->SetProblemType(
"global_constraints", i);
715 this->GetIntegrator().AddDomainData(
"state",
716 &(GetU().GetSpacialVector()));
717 if (dopedim == dealdim)
719 this->GetIntegrator().AddDomainData(
"control",
722 else if (dopedim == 0)
724 this->GetIntegrator().AddParamData(
"control",
730 "StatReducedProblem::ComputeReducedConstraints");
736 if (this->GetProblem()->GetConstraintType().find(
"domain")
737 != std::string::npos)
740 ret += this->GetIntegrator().ComputeDomainScalar(
741 *(this->GetProblem()));
743 if (this->GetProblem()->GetConstraintType().find(
"point")
744 != std::string::npos)
747 ret += this->GetIntegrator().ComputePointScalar(
748 *(this->GetProblem()));
750 if (this->GetProblem()->GetConstraintType().find(
"boundary")
751 != std::string::npos)
754 ret += this->GetIntegrator().ComputeBoundaryScalar(
755 *(this->GetProblem()));
757 if (this->GetProblem()->GetConstraintType().find(
"face")
758 != std::string::npos)
761 ret += this->GetIntegrator().ComputeFaceScalar(
762 *(this->GetProblem()));
768 "Unknown Constraint Type: "
769 + this->GetProblem()->GetConstraintType(),
770 "StatReducedProblem::ComputeReducedConstraints");
775 if (dopedim == dealdim)
777 this->GetIntegrator().DeleteDomainData(
"control");
779 else if (dopedim == 0)
781 this->GetIntegrator().DeleteParamData(
"control");
787 "StatReducedProblem::ComputeReducedConstraints");
789 this->GetIntegrator().DeleteDomainData(
"state");
792 this->GetProblem()->DeleteAuxiliaryFromIntegrator(
793 this->GetIntegrator());
798 if (g.
HasType(
"local_global_control") || g.
HasType(
"local_global_state"))
801 "There are global in space, local in time constraints given. In the stationary case they should be moved to global in space and time!",
802 "StatReducedProblem::ComputeReducedConstraints");
806 this->GetProblem()->PostProcessConstraints(g);
814 template<
typename CONTROLNONLINEARSOLVER,
typename NONLINEARSOLVER,
815 typename CONTROLINTEGRATOR,
typename INTEGRATOR,
typename PROBLEM,
816 typename VECTOR,
int dopedim,
int dealdim>
819 CONTROLINTEGRATOR, INTEGRATOR, PROBLEM, VECTOR, dopedim, dealdim>::GetControlBoxConstraints(
828 template<
typename CONTROLNONLINEARSOLVER,
typename NONLINEARSOLVER,
829 typename CONTROLINTEGRATOR,
typename INTEGRATOR,
typename PROBLEM,
830 typename VECTOR,
int dopedim,
int dealdim>
833 CONTROLINTEGRATOR, INTEGRATOR, PROBLEM, VECTOR, dopedim, dealdim>::ComputeReducedAdjoint(
836 this->GetOutputHandler()->Write(
"Computing Reduced Adjoint:",
837 4 + this->GetBasePriority());
839 this->SetProblemType(
"adjoint");
840 if (adjoint_reinit_ ==
true)
842 GetNonlinearSolver(
"adjoint").ReInit(*(this->GetProblem()));
843 adjoint_reinit_ =
false;
846 this->GetProblem()->AddAuxiliaryToIntegrator(this->GetIntegrator());
848 this->GetIntegrator().AddDomainData(
"state",
849 &(GetU().GetSpacialVector()));
851 if (dopedim == dealdim)
855 else if (dopedim == 0)
857 this->GetIntegrator().AddParamData(
"control",
863 "StatReducedProblem::ComputeReducedAdjoint");
866 build_adjoint_matrix_ =
867 this->GetNonlinearSolver(
"adjoint").NonlinearSolve(
868 *(this->GetProblem()), (GetZ().GetSpacialVector()),
true,
869 build_adjoint_matrix_);
871 if (dopedim == dealdim)
873 this->GetIntegrator().DeleteDomainData(
"control");
875 else if (dopedim == 0)
877 this->GetIntegrator().DeleteParamData(
"control");
883 "StatReducedProblem::ComputeReducedAdjoint");
885 this->GetIntegrator().DeleteDomainData(
"state");
887 this->GetProblem()->DeleteAuxiliaryFromIntegrator(this->GetIntegrator());
889 this->GetOutputHandler()->Write((GetZ().GetSpacialVector()),
890 "Adjoint" + this->GetPostIndex(), this->GetProblem()->GetDoFType());
895 template<
typename CONTROLNONLINEARSOLVER,
typename NONLINEARSOLVER,
896 typename CONTROLINTEGRATOR,
typename INTEGRATOR,
typename PROBLEM,
897 typename VECTOR,
int dopedim,
int dealdim>
900 CONTROLINTEGRATOR, INTEGRATOR, PROBLEM, VECTOR, dopedim, dealdim>::ComputeDualForErrorEstimation(
904 this->GetOutputHandler()->Write(
"Computing Dual for Error Estimation:",
905 4 + this->GetBasePriority());
909 this->SetProblemType(
"adjoint_for_ee");
914 "StatPDEProblem::ComputeDualForErrorEstimation");
918 auto& problem = *(this->GetProblem());
919 if (adjoint_reinit_ ==
true)
921 GetNonlinearSolver(
"adjoint_for_ee").ReInit(problem);
922 adjoint_reinit_ =
false;
925 this->GetProblem()->AddAuxiliaryToIntegrator(this->GetIntegrator());
927 this->GetIntegrator().AddDomainData(
"state",
928 &(GetU().GetSpacialVector()));
930 if (dopedim == dealdim)
934 else if (dopedim == 0)
936 this->GetIntegrator().AddParamData(
"control",
942 "StatReducedProblem::ComputeReducedAdjoint");
945 build_adjoint_matrix_ =
946 this->GetNonlinearSolver(
"adjoint_for_ee").NonlinearSolve(problem,
947 (GetZForEE().GetSpacialVector()),
true, build_adjoint_matrix_);
949 if (dopedim == dealdim)
951 this->GetIntegrator().DeleteDomainData(
"control");
953 else if (dopedim == 0)
955 this->GetIntegrator().DeleteParamData(
"control");
961 "StatReducedProblem::ComputeReducedAdjoint");
964 this->GetIntegrator().DeleteDomainData(
"state");
966 this->GetProblem()->DeleteAuxiliaryFromIntegrator(this->GetIntegrator());
968 this->GetOutputHandler()->Write((GetZForEE().GetSpacialVector()),
969 "Adjoint_for_ee" + this->GetPostIndex(), problem.GetDoFType());
975 template<
typename CONTROLNONLINEARSOLVER,
typename NONLINEARSOLVER,
976 typename CONTROLINTEGRATOR,
typename INTEGRATOR,
typename PROBLEM,
977 typename VECTOR,
int dopedim,
int dealdim>
980 CONTROLINTEGRATOR, INTEGRATOR, PROBLEM, VECTOR, dopedim, dealdim>::ComputeReducedGradient(
984 this->ComputeReducedAdjoint(q);
986 this->GetOutputHandler()->Write(
"Computing Reduced Gradient:",
987 4 + this->GetBasePriority());
991 if (this->GetProblem()->HasControlInDirichletData())
993 tmp.reinit(GetU().GetSpacialVector());
994 this->SetProblemType(
"adjoint");
995 this->GetProblem()->AddAuxiliaryToIntegrator(this->GetIntegrator());
997 if (dopedim == dealdim)
999 this->GetIntegrator().AddDomainData(
"control",
1002 else if (dopedim == 0)
1004 this->GetIntegrator().AddParamData(
"control",
1010 "StatReducedProblem::ComputeReducedGradient");
1013 this->GetIntegrator().AddDomainData(
"state",
1014 &(GetU().GetSpacialVector()));
1015 this->GetIntegrator().AddDomainData(
"last_newton_solution",
1016 &(GetZ().GetSpacialVector()));
1018 this->GetIntegrator().ComputeNonlinearResidual(*(this->GetProblem()),
1022 if (dopedim == dealdim)
1024 this->GetIntegrator().DeleteDomainData(
"control");
1026 else if (dopedim == 0)
1028 this->GetIntegrator().DeleteParamData(
"control");
1034 "StatReducedProblem::ComputeReducedGradient");
1037 this->GetIntegrator().DeleteDomainData(
"state");
1038 this->GetIntegrator().DeleteDomainData(
"last_newton_solution");
1039 this->GetProblem()->DeleteAuxiliaryFromIntegrator(
1040 this->GetIntegrator());
1043 this->SetProblemType(
"gradient");
1044 if (gradient_reinit_ ==
true)
1046 GetControlNonlinearSolver().ReInit(*(this->GetProblem()));
1047 gradient_reinit_ =
false;
1050 this->GetProblem()->AddAuxiliaryToIntegrator(
1051 this->GetControlIntegrator());
1053 if (dopedim == dealdim)
1055 this->GetControlIntegrator().AddDomainData(
"control",
1058 else if (dopedim == 0)
1060 this->GetControlIntegrator().AddParamData(
"control",
1066 "StatReducedProblem::ComputeReducedGradient");
1069 this->GetControlIntegrator().AddDomainData(
"state",
1070 &(GetU().GetSpacialVector()));
1071 this->GetControlIntegrator().AddDomainData(
"adjoint",
1072 &(GetZ().GetSpacialVector()));
1073 if (this->GetProblem()->HasControlInDirichletData())
1074 this->GetControlIntegrator().AddDomainData(
"adjoint_residual", &tmp);
1076 gradient_transposed = 0.;
1077 if (dopedim == dealdim)
1079 this->GetControlIntegrator().AddDomainData(
"last_newton_solution",
1081 this->GetControlIntegrator().ComputeNonlinearResidual(
1083 this->GetControlIntegrator().DeleteDomainData(
"last_newton_solution");
1085 else if (dopedim == 0)
1087 this->GetControlIntegrator().AddParamData(
"last_newton_solution",
1089 this->GetControlIntegrator().ComputeNonlinearResidual(
1092 this->GetControlIntegrator().DeleteParamData(
"last_newton_solution");
1098 gradient_transposed = gradient;
1102 build_control_matrix_ = this->GetControlNonlinearSolver().NonlinearSolve(
1104 build_control_matrix_);
1105 if (dopedim == dealdim)
1107 this->GetControlIntegrator().DeleteDomainData(
"control");
1109 else if (dopedim == 0)
1111 this->GetControlIntegrator().DeleteParamData(
"control");
1117 "StatReducedProblem::ComputeReducedGradient");
1119 this->GetControlIntegrator().DeleteDomainData(
"state");
1120 this->GetControlIntegrator().DeleteDomainData(
"adjoint");
1121 if (this->GetProblem()->HasControlInDirichletData())
1122 this->GetControlIntegrator().DeleteDomainData(
"adjoint_residual");
1124 this->GetProblem()->DeleteAuxiliaryFromIntegrator(
1125 this->GetControlIntegrator());
1127 this->GetOutputHandler()->Write(gradient,
1128 "Gradient" + this->GetPostIndex(), this->GetProblem()->GetDoFType());
1129 this->GetOutputHandler()->Write(gradient_transposed,
1130 "Gradient_Transposed" + this->GetPostIndex(),
1131 this->GetProblem()->GetDoFType());
1137 template<
typename CONTROLNONLINEARSOLVER,
typename NONLINEARSOLVER,
1138 typename CONTROLINTEGRATOR,
typename INTEGRATOR,
typename PROBLEM,
1139 typename VECTOR,
int dopedim,
int dealdim>
1142 CONTROLINTEGRATOR, INTEGRATOR, PROBLEM, VECTOR, dopedim, dealdim>::ComputeReducedCostFunctional(
1145 this->ComputeReducedState(q);
1150 this->GetOutputHandler()->Write(
"Computing Cost Functional:",
1151 4 + this->GetBasePriority());
1153 this->SetProblemType(
"cost_functional");
1155 this->GetProblem()->AddAuxiliaryToIntegrator(this->GetIntegrator());
1157 if (dopedim == dealdim)
1161 else if (dopedim == 0)
1163 this->GetIntegrator().AddParamData(
"control",
1169 "StatReducedProblem::ComputeReducedCostFunctional");
1171 this->GetIntegrator().AddDomainData(
"state",
1172 &(GetU().GetSpacialVector()));
1174 if (this->GetProblem()->GetFunctionalType().find(
"domain")
1175 != std::string::npos)
1178 ret += this->GetIntegrator().ComputeDomainScalar(*(this->GetProblem()));
1180 if (this->GetProblem()->GetFunctionalType().find(
"point")
1181 != std::string::npos)
1184 ret += this->GetIntegrator().ComputePointScalar(*(this->GetProblem()));
1186 if (this->GetProblem()->GetFunctionalType().find(
"boundary")
1187 != std::string::npos)
1190 ret += this->GetIntegrator().ComputeBoundaryScalar(
1191 *(this->GetProblem()));
1193 if (this->GetProblem()->GetFunctionalType().find(
"face")
1194 != std::string::npos)
1197 ret += this->GetIntegrator().ComputeFaceScalar(*(this->GetProblem()));
1203 "Unknown Functional Type: "
1204 + this->GetProblem()->GetFunctionalType(),
1205 "StatReducedProblem::ComputeReducedCostFunctional");
1208 if (dopedim == dealdim)
1210 this->GetIntegrator().DeleteDomainData(
"control");
1212 else if (dopedim == 0)
1214 this->GetIntegrator().DeleteParamData(
"control");
1220 "StatReducedProblem::ComputeReducedCostFunctional");
1222 this->GetIntegrator().DeleteDomainData(
"state");
1223 this->GetProblem()->DeleteAuxiliaryFromIntegrator(this->GetIntegrator());
1225 this->GetFunctionalValues()[0].push_back(ret);
1231 template<
typename CONTROLNONLINEARSOLVER,
typename NONLINEARSOLVER,
1232 typename CONTROLINTEGRATOR,
typename INTEGRATOR,
typename PROBLEM,
1233 typename VECTOR,
int dopedim,
int dealdim>
1236 CONTROLINTEGRATOR, INTEGRATOR, PROBLEM, VECTOR, dopedim, dealdim>::ComputeReducedFunctionals(
1239 this->GetOutputHandler()->Write(
"Computing Functionals:",
1240 4 + this->GetBasePriority());
1242 this->GetProblem()->AddAuxiliaryToIntegrator(this->GetIntegrator());
1244 if (dopedim == dealdim)
1248 else if (dopedim == 0)
1250 this->GetIntegrator().AddParamData(
"control",
1256 "StatReducedProblem::ComputeReducedFunctionals");
1258 this->GetIntegrator().AddDomainData(
"state",
1259 &(GetU().GetSpacialVector()));
1261 for (
unsigned int i = 0; i < this->GetProblem()->GetNFunctionals(); i++)
1266 this->SetProblemType(
"aux_functional", i);
1267 if (this->GetProblem()->GetFunctionalType().find(
"domain")
1268 != std::string::npos)
1271 ret += this->GetIntegrator().ComputeDomainScalar(
1272 *(this->GetProblem()));
1274 if (this->GetProblem()->GetFunctionalType().find(
"point")
1275 != std::string::npos)
1278 ret += this->GetIntegrator().ComputePointScalar(
1279 *(this->GetProblem()));
1281 if (this->GetProblem()->GetFunctionalType().find(
"boundary")
1282 != std::string::npos)
1285 ret += this->GetIntegrator().ComputeBoundaryScalar(
1286 *(this->GetProblem()));
1288 if (this->GetProblem()->GetFunctionalType().find(
"face")
1289 != std::string::npos)
1292 ret += this->GetIntegrator().ComputeFaceScalar(*(this->GetProblem()));
1298 "Unknown Functional Type: "
1299 + this->GetProblem()->GetFunctionalType(),
1300 "StatReducedProblem::ComputeReducedFunctionals");
1302 this->GetFunctionalValues()[i + 1].push_back(ret);
1303 std::stringstream out;
1304 this->GetOutputHandler()->InitOut(out);
1305 out << this->GetProblem()->GetFunctionalName() <<
": " << ret;
1306 this->GetOutputHandler()->Write(out, 2 + this->GetBasePriority());
1309 if (dopedim == dealdim)
1311 this->GetIntegrator().DeleteDomainData(
"control");
1313 else if (dopedim == 0)
1315 this->GetIntegrator().DeleteParamData(
"control");
1321 "StatReducedProblem::ComputeReducedFunctionals");
1323 this->GetIntegrator().DeleteDomainData(
"state");
1324 this->GetProblem()->DeleteAuxiliaryFromIntegrator(this->GetIntegrator());
1330 template<
typename CONTROLNONLINEARSOLVER,
typename NONLINEARSOLVER,
1331 typename CONTROLINTEGRATOR,
typename INTEGRATOR,
typename PROBLEM,
1332 typename VECTOR,
int dopedim,
int dealdim>
1333 template<
class DWRC,
class PDE>
1336 CONTROLINTEGRATOR, INTEGRATOR, PROBLEM, VECTOR, dopedim, dealdim>::ComputeRefinementIndicators(
1343 pde.ResidualModifier = boost::bind<void>(boost::mem_fn(&DWRC::ResidualModifier),boost::ref(dwrc),_1);
1344 pde.VectorResidualModifier = boost::bind<void>(boost::mem_fn(&DWRC::VectorResidualModifier),boost::ref(dwrc),_1);
1348 const unsigned int n_elements =
1349 this->GetProblem()->GetSpaceTimeHandler()->GetStateDoFHandler().get_tria().n_active_cells();
1353 if(this->GetProblem()->EEFunctionalIsCost() || !dwrc.NeedDual())
1355 this->GetOutputHandler()->Write(
"Computing Error Indicators:",
1356 4 + this->GetBasePriority());
1357 this->GetProblem()->AddAuxiliaryToIntegrator(this->GetIntegrator());
1360 this->GetIntegrator().AddDomainData(
"state",
1361 &(GetU().GetSpacialVector()));
1362 this->GetIntegrator().AddDomainData(
"adjoint_for_ee",
1363 &(GetZ().GetSpacialVector()));
1365 if (dopedim == dealdim)
1367 this->GetIntegrator().AddDomainData(
"control",
1370 else if (dopedim == 0)
1372 this->GetIntegrator().AddParamData(
"control",
1378 "StatReducedProblem::ComputeRefinementIndicators");
1381 this->SetProblemType(
"error_evaluation");
1384 dwrc.PrepareWeights(GetU(), GetZ());
1385 dwrc.PrepareWeights(q);
1388 this->GetIntegrator().ComputeRefinementIndicators(*this->GetProblem(),
1392 dwrc.ClearWeightData();
1395 if (dopedim == dealdim)
1397 this->GetIntegrator().DeleteDomainData(
"control");
1399 else if (dopedim == 0)
1401 this->GetIntegrator().DeleteParamData(
"control");
1407 "StatReducedProblem::ComputeRefinementIndicators");
1409 this->GetIntegrator().DeleteDomainData(
"state");
1410 this->GetIntegrator().DeleteDomainData(
"adjoint_for_ee");
1411 this->GetProblem()->DeleteAuxiliaryFromIntegrator(
1412 this->GetIntegrator());
1416 throw DOpEException(
"Estimating the error in other functionals than cost is not implemented",
1417 "StatReducedProblem::ComputeRefinementIndicators");
1421 std::stringstream out;
1422 this->GetOutputHandler()->InitOut(out);
1423 out <<
"Error estimate using "<<dwrc.GetName();
1425 out<<
" For the computation of "<<this->GetProblem()->GetFunctionalName();
1426 out<<
": "<< dwrc.GetError();
1427 this->GetOutputHandler()->Write(out, 2 + this->GetBasePriority());
1432 template<
typename CONTROLNONLINEARSOLVER,
typename NONLINEARSOLVER,
1433 typename CONTROLINTEGRATOR,
typename INTEGRATOR,
typename PROBLEM,
1434 typename VECTOR,
int dopedim,
int dealdim>
1437 CONTROLINTEGRATOR, INTEGRATOR, PROBLEM, VECTOR, dopedim, dealdim>::ComputeReducedHessianVector(
1442 this->GetOutputHandler()->Write(
"Computing ReducedHessianVector:",
1443 4 + this->GetBasePriority());
1444 this->GetOutputHandler()->Write(
"\tSolving Tangent:",
1445 5 + this->GetBasePriority());
1447 this->SetProblemType(
"tangent");
1449 this->GetProblem()->AddAuxiliaryToIntegrator(this->GetIntegrator());
1451 this->GetIntegrator().AddDomainData(
"state",
1452 &(GetU().GetSpacialVector()));
1453 this->GetControlIntegrator().AddDomainData(
"state",
1454 &(GetU().GetSpacialVector()));
1456 if (dopedim == dealdim)
1458 this->GetIntegrator().AddDomainData(
"dq",
1462 else if (dopedim == 0)
1464 this->GetIntegrator().AddParamData(
"dq",
1466 this->GetIntegrator().AddParamData(
"control",
1472 "StatReducedProblem::ComputeReducedHessianVector");
1476 build_state_matrix_ = this->GetNonlinearSolver(
"tangent").NonlinearSolve(
1477 *(this->GetProblem()), (GetDU().GetSpacialVector()),
true,
1478 build_state_matrix_);
1480 this->GetOutputHandler()->Write((GetDU().GetSpacialVector()),
1481 "Tangent" + this->GetPostIndex(), this->GetProblem()->GetDoFType());
1483 this->GetOutputHandler()->Write(
"\tSolving Adjoint Hessian:",
1484 5 + this->GetBasePriority());
1485 this->SetProblemType(
"adjoint_hessian");
1486 this->GetIntegrator().AddDomainData(
"adjoint",
1487 &(GetZ().GetSpacialVector()));
1488 this->GetIntegrator().AddDomainData(
"tangent",
1489 &(GetDU().GetSpacialVector()));
1490 this->GetControlIntegrator().AddDomainData(
"adjoint",
1491 &(GetZ().GetSpacialVector()));
1492 this->GetControlIntegrator().AddDomainData(
"tangent",
1493 &(GetDU().GetSpacialVector()));
1496 build_adjoint_matrix_ =
1497 this->GetNonlinearSolver(
"adjoint_hessian").NonlinearSolve(
1498 *(this->GetProblem()), (GetDZ().GetSpacialVector()),
true,
1499 build_adjoint_matrix_);
1501 this->GetOutputHandler()->Write((GetDZ().GetSpacialVector()),
1502 "Hessian" + this->GetPostIndex(), this->GetProblem()->GetDoFType());
1504 this->GetIntegrator().AddDomainData(
"adjoint_hessian",
1505 &(GetDZ().GetSpacialVector()));
1506 this->GetControlIntegrator().AddDomainData(
"adjoint_hessian",
1507 &(GetDZ().GetSpacialVector()));
1509 this->GetOutputHandler()->Write(
1510 "\tComputing Representation of the Hessian:",
1511 5 + this->GetBasePriority());
1515 if (this->GetProblem()->HasControlInDirichletData())
1517 tmp.reinit(GetU().GetSpacialVector());
1518 tmp_second.reinit(GetU().GetSpacialVector());
1519 this->SetProblemType(
"adjoint");
1520 this->GetIntegrator().AddDomainData(
"last_newton_solution",
1521 &(GetZ().GetSpacialVector()));
1523 this->GetIntegrator().ComputeNonlinearResidual(*(this->GetProblem()),
1527 this->GetIntegrator().DeleteDomainData(
"last_newton_solution");
1528 this->SetProblemType(
"adjoint_hessian");
1529 this->GetIntegrator().AddDomainData(
"last_newton_solution",
1530 &(GetDZ().GetSpacialVector()));
1532 this->GetIntegrator().ComputeNonlinearResidual(*(this->GetProblem()),
1536 this->GetIntegrator().DeleteDomainData(
"last_newton_solution");
1539 this->GetProblem()->DeleteAuxiliaryFromIntegrator(this->GetIntegrator());
1541 this->SetProblemType(
"hessian");
1542 this->GetProblem()->AddAuxiliaryToIntegrator(
1543 this->GetControlIntegrator());
1544 if (dopedim == dealdim)
1546 this->GetIntegrator().DeleteDomainData(
"dq");
1547 this->GetIntegrator().DeleteDomainData(
"control");
1548 this->GetControlIntegrator().AddDomainData(
"dq",
1550 this->GetControlIntegrator().AddDomainData(
"control",
1553 else if (dopedim == 0)
1555 this->GetIntegrator().DeleteParamData(
"dq");
1556 this->GetIntegrator().DeleteParamData(
"control");
1559 this->GetControlIntegrator().AddParamData(
"dq",
1561 this->GetControlIntegrator().AddParamData(
"control",
1567 "StatReducedProblem::ComputeReducedHessianVector");
1569 if (this->GetProblem()->HasControlInDirichletData())
1571 this->GetControlIntegrator().AddDomainData(
"adjoint_residual", &tmp);
1572 this->GetControlIntegrator().AddDomainData(
"hessian_residual",
1577 hessian_direction_transposed = 0.;
1578 if (dopedim == dealdim)
1580 this->GetControlIntegrator().AddDomainData(
"last_newton_solution",
1582 this->GetControlIntegrator().ComputeNonlinearResidual(
1585 this->GetControlIntegrator().DeleteDomainData(
"last_newton_solution");
1587 else if (dopedim == 0)
1589 this->GetControlIntegrator().AddParamData(
"last_newton_solution",
1591 this->GetControlIntegrator().ComputeNonlinearResidual(
1594 this->GetControlIntegrator().DeleteParamData(
"last_newton_solution");
1597 hessian_direction *= -1.;
1598 hessian_direction_transposed = hessian_direction;
1601 build_control_matrix_ =
1602 this->GetControlNonlinearSolver().NonlinearSolve(
1603 *(this->GetProblem()),
1605 build_control_matrix_);
1607 this->GetOutputHandler()->Write(hessian_direction,
1608 "HessianDirection" + this->GetPostIndex(),
1609 this->GetProblem()->GetDoFType());
1610 this->GetOutputHandler()->Write(hessian_direction_transposed,
1611 "HessianDirection_Transposed" + this->GetPostIndex(),
1612 this->GetProblem()->GetDoFType());
1615 if (dopedim == dealdim)
1617 this->GetControlIntegrator().DeleteDomainData(
"dq");
1618 this->GetControlIntegrator().DeleteDomainData(
"control");
1620 else if (dopedim == 0)
1622 this->GetControlIntegrator().DeleteParamData(
"dq");
1623 this->GetControlIntegrator().DeleteParamData(
"control");
1630 "StatReducedProblem::ComputeReducedHessianVector");
1632 this->GetIntegrator().DeleteDomainData(
"state");
1633 this->GetIntegrator().DeleteDomainData(
"adjoint");
1634 this->GetIntegrator().DeleteDomainData(
"tangent");
1635 this->GetIntegrator().DeleteDomainData(
"adjoint_hessian");
1636 this->GetControlIntegrator().DeleteDomainData(
"state");
1637 this->GetControlIntegrator().DeleteDomainData(
"adjoint");
1638 this->GetControlIntegrator().DeleteDomainData(
"tangent");
1639 this->GetControlIntegrator().DeleteDomainData(
"adjoint_hessian");
1640 if (this->GetProblem()->HasControlInDirichletData())
1642 this->GetControlIntegrator().DeleteDomainData(
"adjoint_residual");
1643 this->GetControlIntegrator().DeleteDomainData(
"hessian_residual");
1645 this->GetProblem()->DeleteAuxiliaryFromIntegrator(
1646 this->GetControlIntegrator());
1652 template<
typename CONTROLNONLINEARSOLVER,
typename NONLINEARSOLVER,
1653 typename CONTROLINTEGRATOR,
typename INTEGRATOR,
typename PROBLEM,
1654 typename VECTOR,
int dopedim,
int dealdim>
1657 CONTROLINTEGRATOR, INTEGRATOR, PROBLEM, VECTOR, dopedim, dealdim>::ComputeReducedGradientOfGlobalConstraints(
1664 std::stringstream out;
1665 out <<
"Computing Reduced Gradient of global constraint " << num <<
" :";
1666 this->GetOutputHandler()->Write(out, 4 + this->GetBasePriority());
1668 this->SetProblemType(
"global_constraint_gradient", num);
1670 if (dopedim == dealdim)
1672 this->GetControlIntegrator().AddDomainData(
"control",
1675 else if (dopedim == 0)
1677 this->GetControlIntegrator().AddParamData(
"control",
1683 "StatReducedProblem::ComputeReducedGradient");
1685 this->GetProblem()->AddAuxiliaryToIntegrator(
1686 this->GetControlIntegrator());
1687 this->GetControlIntegrator().AddDomainData(
"constraints_local",
1689 this->GetControlIntegrator().AddParamData(
"constraints_global",
1693 this->GetControlIntegrator().ComputeNonlinearRhs(*(this->GetProblem()),
1695 gradient_transposed = gradient;
1697 this->GetControlIntegrator().DeleteDomainData(
"constraints_local");
1698 this->GetControlIntegrator().DeleteParamData(
"constraints_global");
1699 this->GetProblem()->DeleteAuxiliaryFromIntegrator(
1700 this->GetControlIntegrator());
1701 if (dopedim == dealdim)
1703 this->GetControlIntegrator().DeleteDomainData(
"control");
1705 else if (dopedim == 0)
1707 this->GetControlIntegrator().DeleteParamData(
"control");
1713 "StatReducedProblem::ComputeReducedGradient");
1719 template<
typename CONTROLNONLINEARSOLVER,
typename NONLINEARSOLVER,
1720 typename CONTROLINTEGRATOR,
typename INTEGRATOR,
typename PROBLEM,
1721 typename VECTOR,
int dopedim,
int dealdim>
1724 CONTROLINTEGRATOR, INTEGRATOR, PROBLEM, VECTOR, dopedim, dealdim>::WriteToFile(
1725 const VECTOR &v, std::string name, std::string outfile,
1726 std::string dof_type, std::string filetype)
1728 if (dof_type ==
"state")
1731 this->GetProblem()->GetSpaceTimeHandler()->GetDataOut();
1732 data_out.attach_dof_handler(
1733 this->GetProblem()->GetSpaceTimeHandler()->GetStateDoFHandler());
1735 data_out.add_data_vector(v, name);
1736 data_out.build_patches();
1738 std::ofstream output(outfile.c_str());
1740 if (filetype ==
".vtk")
1742 data_out.write_vtk(output);
1744 else if (filetype ==
".gpl")
1746 data_out.write_gnuplot(output);
1751 "Don't know how to write filetype `" + filetype +
"'!",
1752 "StatReducedProblem::WriteToFile");
1756 else if (dof_type ==
"control")
1758 #if dope_dimension >0
1759 auto& data_out = this->GetProblem()->GetSpaceTimeHandler()->GetDataOut();
1760 data_out.attach_dof_handler (this->GetProblem()->GetSpaceTimeHandler()->GetControlDoFHandler());
1762 data_out.add_data_vector (v,name);
1763 data_out.build_patches ();
1765 std::ofstream output(outfile.c_str());
1767 if(filetype ==
".vtk")
1769 data_out.write_vtk (output);
1771 else if (filetype ==
".gpl")
1773 data_out.write_gnuplot(output);
1777 throw DOpEException(
"Don't know how to write filetype `" + filetype +
"'!",
1778 "StatReducedProblem::WriteToFile");
1782 if (filetype ==
".txt")
1784 std::ofstream output(outfile.c_str());
1787 for (
unsigned int i = 0; i < off.size(); i++)
1789 output << off(i) << std::endl;
1795 "Don't know how to write filetype `" + filetype +
"'!",
1796 "StatReducedProblem::WriteToFile");
1802 throw DOpEException(
"No such DoFHandler `" + dof_type +
"'!",
1803 "StatReducedProblem::WriteToFile");
1809 template<
typename CONTROLNONLINEARSOLVER,
typename NONLINEARSOLVER,
1810 typename CONTROLINTEGRATOR,
typename INTEGRATOR,
typename PROBLEM,
1811 typename VECTOR,
int dopedim,
int dealdim>
1814 CONTROLINTEGRATOR, INTEGRATOR, PROBLEM, VECTOR, dopedim, dealdim>::WriteToFile(
1816 std::string dof_type)
void ComputeRefinementIndicators(const ControlVector< VECTOR > &q, DWRC &dwrc, PDE &pde)
Definition: statreducedproblem.h:1336
CONTROLINTEGRATOR & GetControlIntegrator()
Definition: statreducedproblem.h:394
void UnLockCopy() const
Definition: controlvector.h:199
Definition: constraintvector.h:48
const dealii::Vector< double > & GetSpacialVectorCopy() const
Definition: controlvector.cc:277
NONLINEARSOLVER & GetNonlinearSolver(std::string type)
Definition: statreducedproblem.h:516
CONTROLNONLINEARSOLVER & GetControlNonlinearSolver()
Definition: statreducedproblem.h:542
void ComputeReducedFunctionals(const ControlVector< VECTOR > &q)
Definition: statreducedproblem.h:1236
void ReInit()
Definition: statreducedproblem.h:564
INTEGRATOR & GetIntegrator()
Definition: statreducedproblem.h:389
void ComputeDualForErrorEstimation(const ControlVector< VECTOR > &q, DOpEtypes::WeightComputation weight_comp)
Definition: statreducedproblem.h:900
StateVector< VECTOR > & GetU()
Definition: statreducedproblem.h:351
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:1724
void ComputeReducedAdjoint(const ControlVector< VECTOR > &q)
Definition: statreducedproblem.h:833
const dealii::Vector< double > & GetGlobalConstraints() const
Definition: constraintvector.cc:174
Definition: statreducedproblem.h:83
StateVector< VECTOR > & GetZ()
Definition: statreducedproblem.h:356
StateVector< VECTOR > & GetZForEE()
Definition: statreducedproblem.h:379
Definition: controlvector.h:49
Definition: dopetypes.h:82
static void declare_params(ParameterReader ¶m_reader)
Definition: statreducedproblem.h:432
void GetControlBoxConstraints(ControlVector< VECTOR > &lb, ControlVector< VECTOR > &ub)
Definition: statreducedproblem.h:819
double ComputeReducedCostFunctional(const ControlVector< VECTOR > &q)
Definition: statreducedproblem.h:1142
const StateVector< VECTOR > & GetZForEE() const
Definition: statreducedproblem.h:374
StateVector< VECTOR > & GetDZ()
Definition: statreducedproblem.h:366
void ComputeReducedGradient(const ControlVector< VECTOR > &q, ControlVector< VECTOR > &gradient, ControlVector< VECTOR > &gradient_transposed)
Definition: statreducedproblem.h:980
Definition: statevector.h:50
VECTOR & GetSpacialVector()
Definition: controlvector.cc:205
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:595
Definition: reducedprobleminterface.h:336
StatReducedProblem(PROBLEM *OP, DOpEtypes::VectorStorageType state_behavior, ParameterReader ¶m_reader, INTEGRATORDATACONT &idc, int base_priority=0)
Definition: statreducedproblem.h:444
void ComputeReducedHessianVector(const ControlVector< VECTOR > &q, const ControlVector< VECTOR > &direction, ControlVector< VECTOR > &hessian_direction, ControlVector< VECTOR > &hessian_direction_transposed)
Definition: statreducedproblem.h:1437
bool ComputeReducedConstraints(const ControlVector< VECTOR > &q, ConstraintVector< VECTOR > &g)
Definition: statreducedproblem.h:658
void StateSizeInfo(std::stringstream &out)
Definition: statreducedproblem.h:258
VECTOR & GetSpacialVector(std::string name)
Definition: constraintvector.cc:130
Definition: dopeexception.h:35
void WriteToFile(const std::vector< double > &, std::string)
Definition: statreducedproblem.h:300
const StateVector< VECTOR > & GetU() const
Definition: statreducedproblem.h:346
virtual bool IsFeasible() const
Definition: constraintvector.cc:574
StateVector< VECTOR > & GetDU()
Definition: statreducedproblem.h:361
virtual void ReInit()
Definition: reducedprobleminterface.h:358
~StatReducedProblem()
Definition: statreducedproblem.h:505
void ComputeReducedGradientOfGlobalConstraints(unsigned int num, const ControlVector< VECTOR > &q, const ConstraintVector< VECTOR > &g, ControlVector< VECTOR > &gradient, ControlVector< VECTOR > &gradient_transposed)
Definition: statreducedproblem.h:1657