326 #ifndef LIBMESH_ENABLE_AMR   328   libmesh_example_requires(
false, 
"--enable-amr");
   331   libmesh_example_requires(2 <= LIBMESH_DIM, 
"2D support");
   334 #ifndef LIBMESH_ENABLE_DIRICHLET   335   libmesh_example_requires(
false, 
"--enable-dirichlet");
   339   LibMeshInit 
init (argc, argv);
   348     std::ifstream i(
"general.in");
   349     libmesh_error_msg_if(!i, 
'[' << 
init.comm().rank() << 
"] Can't find general.in; exiting early.");
   351   GetPot infile(
"general.in");
   354   infile.parse_command_line(argc, argv);
   362   Mesh 
mesh(
init.comm(), cast_int<unsigned char>(param.dimension));
   365   auto mesh_refinement = std::make_unique<MeshRefinement>(
mesh);
   368   EquationSystems equation_systems (
mesh);
   375   if (param.elementtype == 
"tri" ||
   376       param.elementtype == 
"unstructured")
   382                                        param.domain_xmin, param.domain_xmin + param.domain_edge_width,
   383                                        param.domain_ymin, param.domain_ymin + param.domain_edge_length,
   393   auto sigma_physics = std::make_unique<SigmaPhysics>();
   394   sigma_physics->init_data(system);
   399   equation_systems.init ();
   402   for (
unsigned int i=0; i != param.extrarefinements; ++i)
   404       mesh_refinement->uniformly_refine(1);
   405       equation_systems.reinit();
   408   libMesh::out << 
"Setting primal initial conditions" << std::endl;
   411                           equation_systems.parameters);
   432   equation_systems.print_info();
   435   Number QoI_1_accumulated = 0.0;
   440 #if defined(NDEBUG) && defined(LIBMESH_ENABLE_EXCEPTIONS)   446       for (
unsigned int t_step=param.initial_timestep;
   447            t_step != param.initial_timestep + param.n_timesteps; ++t_step)
   467           libMesh::out << 
"Advancing timestep" << std::endl << std::endl;
   471           write_output(equation_systems, t_step+1, 
"primal", param);
   476       (
dynamic_cast<HeatSystem &
>(system).QoI_time_instant)[0] = system.
time;
   485       QoI_1_accumulated = 0.0;
   487       for (
unsigned int t_step=param.initial_timestep;
   488            t_step != param.initial_timestep + param.n_timesteps; ++t_step)
   495       std::cout<< 
"The computed QoI 0 is " << std::setprecision(17) << system.
get_qoi_value(0) << std::endl;
   496       std::cout<< 
"The computed QoI 1 is " << std::setprecision(17) << QoI_1_accumulated << std::endl;
   501       libMesh::out << std::endl << 
"Solving the adjoint problems." << std::endl;
   508       const std::string & adjoint_solution_name0 = 
"adjoint_solution0";
   509       const std::string & adjoint_solution_name1 = 
"adjoint_solution1";
   510       const std::string & old_adjoint_solution_name0 = 
"_old_adjoint_solution0";
   511       const std::string & old_adjoint_solution_name1 = 
"_old_adjoint_solution1";
   528                             equation_systems.parameters,
   567                        << system.
time + (system.
time_solver->last_completed_timestep_size())/((param.timesolver_tolerance) ? 2.0 : 1.0)
   574                        << system.
time + (system.
time_solver->last_completed_timestep_size())/((param.timesolver_tolerance) ? 2.0 : 1.0)
   589       primal_solution.
swap(dual_solution_0);
   591       write_output(equation_systems, param.n_timesteps, 
"dual0", param);
   594       primal_solution.swap(dual_solution_0);
   600       primal_solution.
swap(dual_solution_1);
   602       write_output(equation_systems, param.n_timesteps, 
"dual1", param);
   605       primal_solution.swap(dual_solution_1);
   611       for (
unsigned int t_step=param.initial_timestep;
   612            t_step != param.initial_timestep + param.n_timesteps; ++t_step)
   630                          << system.
time - (system.
time_solver->last_completed_timestep_size())/((param.timesolver_tolerance) ? 2.0 : 1.0)
   667           libMesh::out << 
"Saving adjoint and retrieving primal solutions at time t=" << system.
time - system.
deltat << std::endl;
   684                        << system.
time + (system.
time_solver->last_completed_timestep_size())/((param.timesolver_tolerance) ? 2.0 : 1.0)
   691                        << system.
time + (system.
time_solver->last_completed_timestep_size())/((param.timesolver_tolerance) ? 2.0 : 1.0)
   704           primal_solution.
swap(dual_solution_0);
   706           write_output(equation_systems, param.n_timesteps - (t_step + 1), 
"dual0", param);
   709           primal_solution.swap(dual_solution_0);
   715           primal_solution.
swap(dual_solution_1);
   717           write_output(equation_systems, param.n_timesteps - (t_step + 1), 
"dual1", param);
   720           primal_solution.swap(dual_solution_1);
   736       qois.add_indices({0,1});
   737       qois.set_weight(0, 0.5);
   738       qois.set_weight(1, 0.5);
   741       auto adjoint_refinement_error_estimator =
   745       ErrorVector QoI_elementwise_error;
   746       std::vector<Number> QoI_spatially_integrated_error(system.
n_qois());
   749       ErrorVector accumulated_QoI_elementwise_error;
   750       std::vector<Number> accumulated_QoI_spatially_integrated_error(system.
n_qois());
   791       if(param.timesolver_tolerance)
   793         libmesh_error_msg_if(std::abs(Z0_old_norm - (4.3523242593920151e-06)) >= 2.e-10,
   794                              "Mismatch in expected Z0_old norm for the 1st half timestep!");
   795         libmesh_error_msg_if(std::abs(Z1_old_norm - (0.3118758855352407)) >= 2.e-5,
   796                              "Mismatch in expected Z1_old norm for the 1st half timestep!");
   800         libmesh_error_msg_if(std::abs(Z0_old_norm - (0.0030758523361801263)) >= 2.e-7,
   801                              "Mismatch in expected Z0_old norm for the 1st timestep!");
   802         libmesh_error_msg_if(std::abs(Z1_old_norm - (0.31162043809579365)) >= 2.e-5,
   803                              "Mismatch in expected Z1_old norm for the 1st timestep!");
   807                        << system.
time + (system.
time_solver->last_completed_timestep_size())/((param.timesolver_tolerance) ? 2.0 : 1.0)
   814                        << system.
time + (system.
time_solver->last_completed_timestep_size())/((param.timesolver_tolerance) ? 2.0 : 1.0)
   822       for (
unsigned int t_step=param.initial_timestep;
   823            t_step != param.initial_timestep + param.n_timesteps; ++t_step)
   825           system.
time_solver->integrate_adjoint_refinement_error_estimate(*adjoint_refinement_error_estimator, QoI_elementwise_error);
   860                        << system.
time + (system.
time_solver->last_completed_timestep_size())/((param.timesolver_tolerance) ? 2.0 : 1.0)
   867                        << system.
time + (system.
time_solver->last_completed_timestep_size())/((param.timesolver_tolerance) ? 2.0 : 1.0)
   874           for(
unsigned int i = 0; i < QoI_elementwise_error.size(); i++)
   875             accumulated_QoI_elementwise_error[i] += QoI_elementwise_error[i];
   881             if ((adjoint_refinement_error_estimator->qoi_set()).has_index(j))
   888       std::cout<<
"Time integrated error estimate for QoI 0: "<<std::setprecision(17)<<accumulated_QoI_spatially_integrated_error[0]<<std::endl;
   889       std::cout<<
"Time integrated error estimate for QoI 1: "<<std::setprecision(17)<<accumulated_QoI_spatially_integrated_error[1]<<std::endl;
   895       if(param.timesolver_tolerance)
   897         libmesh_error_msg_if(std::abs(system.
time - (1.7548735069535084)) >= 2.e-4,
   898                              "Mismatch in end time reached by adaptive timestepper!");
   900         libmesh_error_msg_if(std::abs(accumulated_QoI_spatially_integrated_error[0] - (-0.75139371165754232)) >= 2.e-4,
   901                              "Error Estimator identity not satisfied!");
   903         libmesh_error_msg_if(std::abs(accumulated_QoI_spatially_integrated_error[1] - (-0.70905030091469889)) >= 2.e-4,
   904                              "Error Estimator identity not satisfied!");
   908         libmesh_error_msg_if(std::abs(accumulated_QoI_spatially_integrated_error[0] - (-0.44809323880671958)) >= 2.e-4,
   909                              "Error Estimator identity not satisfied!");
   911         libmesh_error_msg_if(std::abs(accumulated_QoI_spatially_integrated_error[1] - (-0.23895256319278346)) >= 2.e-4,
   912                              "Error Estimator identity not satisfied!");
   915 #if defined(NDEBUG) && defined(LIBMESH_ENABLE_EXCEPTIONS)   919                    << 
"] Caught exception; exiting early." << std::endl;
   924                << 
"] Completing output."   930 #endif // LIBMESH_ENABLE_AMR 
Real time
For time-dependent problems, this is the time t at the beginning of the current timestep. 
ElemType
Defines an enum for geometric element types. 
Number adjoint_initial_value0(const Point &, const Parameters &, const std::string &, const std::string &)
void set_adjoint_already_solved(bool setting)
Setter for the adjoint_already_solved boolean. 
void write_output(EquationSystems &es, unsigned int t_step, std::string solution_type, FEMParameters ¶m)
Number get_qoi_value(unsigned int qoi_index) const
unsigned int n_qois() const
Number of currently active quantities of interest. 
std::unique_ptr< TimeSolver > time_solver
A pointer to the solver object we're going to use. 
void init_qois(unsigned int n_qois)
Accessors for qoi and qoi_error_estimates vectors. 
Gradient adjoint_initial_grad0(const Point &, const Parameters &, const std::string &, const std::string &)
void pop_physics()
Pop a physics object off of our stack. 
SolverPackage default_solver_package()
void project_solution(FunctionBase< Number > *f, FunctionBase< Gradient > *g=nullptr) const
Projects arbitrary functions onto the current solution. 
void libmesh_ignore(const Args &...)
Real deltat
For time-dependent problems, this is the amount delta t to advance the solution in time...
std::unique_ptr< NumericVector< Number > > solution
Data structure to hold solution values. 
Real calculate_norm(const NumericVector< Number > &v, unsigned int var, FEMNormType norm_type, std::set< unsigned int > *skip_dimensions=nullptr) const
void init(triangulateio &t)
Initializes the fields of t to nullptr/0 as necessary. 
void set_system_parameters(HeatSystem &system, FEMParameters ¶m)
void read(GetPot &input, const std::vector< std::string > *other_variable_names=nullptr)
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
void set_vector_preservation(const std::string &vec_name, bool preserve)
Allows one to set the boolean controlling whether the vector identified by vec_name should be "preser...
virtual void swap(NumericVector< T > &v)
Swaps the contents of this with v. 
IntRange< T > make_range(T beg, T end)
The 2-parameter make_range() helper function returns an IntRange<T> when both input parameters are of...
Gradient initial_grad(const Point &, const Parameters &, const std::string &, const std::string &)
NumericVector< Number > & get_adjoint_solution(unsigned int i=0)
std::unique_ptr< AdjointRefinementEstimator > build_adjoint_refinement_error_estimator(QoISet &qois, FEMPhysics *supplied_physics, FEMParameters &)
void project_vector(NumericVector< Number > &new_vector, FunctionBase< Number > *f, FunctionBase< Gradient > *g=nullptr, int is_adjoint=-1) const
Projects arbitrary functions onto a vector of degree of freedom values for the current system...
virtual void solve() override
Invokes the solver associated with the system. 
void push_physics(DifferentiablePhysics &new_physics)
Push a clone of a new physics object onto our stack, overriding the current physics until the new phy...
Number get_qoi_error_estimate_value(unsigned int qoi_index) const
template class LIBMESH_EXPORT NumericVector< Number >
Number initial_value(const Point &, const Parameters &, const std::string &, const std::string &)
virtual std::pair< unsigned int, Real > adjoint_solve(const QoISet &qoi_indices=QoISet()) override
This function sets the _is_adjoint boolean member of TimeSolver to true and then calls the adjoint_so...
const NumericVector< Number > & get_vector(std::string_view vec_name) const