261 "--enable-petsc, --enable-trilinos, or --enable-eigen");
264 #ifndef LIBMESH_ENABLE_AMR 265 libmesh_example_requires(
false,
"--enable-amr");
272 std::ifstream i(
"general.in");
273 libmesh_error_msg_if(!i,
'[' <<
init.comm().rank() <<
"] Can't find general.in; exiting early.");
277 GetPot infile(
"general.in");
280 infile.parse_command_line(argc, argv);
286 libmesh_example_requires(2 <= LIBMESH_DIM,
"2D support");
293 std::unique_ptr<MeshRefinement> mesh_refinement =
299 libMesh::out <<
"Reading in and building the mesh" << std::endl;
302 mesh.
read(param.domainfile.c_str());
310 initial_uniform_refinements.uniformly_refine(param.coarserefinements);
322 equation_systems.init ();
326 equation_systems.print_info();
331 unsigned int a_step = 0;
332 for (; a_step != param.max_adaptivesteps; ++a_step)
336 if (param.global_tolerance != 0.)
337 libmesh_assert_equal_to (param.nelem_target, 0);
341 libmesh_assert_greater (param.nelem_target, 0);
349 write_output(equation_systems, a_step,
"primal", param);
383 primal_solution.
swap(dual_solution_0);
384 write_output(equation_systems, a_step,
"adjoint_0", param);
387 primal_solution.
swap(dual_solution_0);
393 primal_solution.
swap(dual_solution_1);
394 write_output(equation_systems, a_step,
"adjoint_1", param);
397 primal_solution.
swap(dual_solution_1);
403 <<
" active elements and " 404 << equation_systems.n_active_dofs()
418 << std::setprecision(17)
423 << std::setprecision(17)
432 std::unique_ptr<AdjointRefinementEstimator> adjoint_refinement_error_estimator =
436 adjoint_refinement_error_estimator->estimate_error(system, QoI_elementwise_error);
440 libMesh::out <<
"The computed relative error in QoI 0 is " 441 << std::setprecision(17)
442 <<
std::abs(adjoint_refinement_error_estimator->get_global_QoI_error_estimate(0)) /
std::abs(QoI_0_exact)
445 libMesh::out <<
"The computed relative error in QoI 1 is " 446 << std::setprecision(17)
447 <<
std::abs(adjoint_refinement_error_estimator->get_global_QoI_error_estimate(1)) /
std::abs(QoI_1_exact)
452 libMesh::out <<
"The effectivity index for the computed error in QoI 0 is " 453 << std::setprecision(17)
454 <<
std::abs(adjoint_refinement_error_estimator->get_global_QoI_error_estimate(0)) /
std::abs(QoI_0_computed - QoI_0_exact)
457 libMesh::out <<
"The effectivity index for the computed error in QoI 1 is " 458 << std::setprecision(17)
459 <<
std::abs(adjoint_refinement_error_estimator->get_global_QoI_error_estimate(1)) /
std::abs(QoI_1_computed - QoI_1_exact)
465 if (!param.refine_uniformly)
466 for (std::size_t i=0; i<QoI_elementwise_error.size(); i++)
467 if (QoI_elementwise_error[i] != 0.)
468 QoI_elementwise_error[i] =
std::abs(QoI_elementwise_error[i]);
475 if (param.refine_uniformly)
477 mesh_refinement->uniformly_refine(1);
480 else if (param.global_tolerance >= 0. && param.nelem_target == 0.)
482 mesh_refinement->flag_elements_by_error_tolerance (QoI_elementwise_error);
484 mesh_refinement->refine_and_coarsen_elements();
491 libMesh::out <<
"We reached the target number of elements." << std::endl << std::endl;
495 mesh_refinement->flag_elements_by_nelem_target (QoI_elementwise_error);
497 mesh_refinement->refine_and_coarsen_elements();
501 equation_systems.reinit();
505 <<
" active elements and " 506 << equation_systems.n_active_dofs()
512 if (a_step == param.max_adaptivesteps)
517 write_output(equation_systems, a_step,
"primal", param);
536 primal_solution.
swap(dual_solution_0);
537 write_output(equation_systems, a_step,
"adjoint_0", param);
539 primal_solution.
swap(dual_solution_0);
543 primal_solution.
swap(dual_solution_1);
544 write_output(equation_systems, a_step,
"adjoint_1", param);
546 primal_solution.
swap(dual_solution_1);
552 <<
" active elements and " 553 << equation_systems.n_active_dofs()
567 << std::setprecision(17)
572 << std::setprecision(17)
583 std::unique_ptr<AdjointRefinementEstimator> adjoint_refinement_error_estimator =
587 adjoint_refinement_error_estimator->estimate_error(system, QoI_elementwise_error);
591 libMesh::out <<
"The computed relative error in QoI 0 is " 592 << std::setprecision(17)
593 <<
std::abs(adjoint_refinement_error_estimator->get_global_QoI_error_estimate(0)) /
std::abs(QoI_0_exact)
596 libMesh::out <<
"The computed relative error in QoI 1 is " 597 << std::setprecision(17)
598 <<
std::abs(adjoint_refinement_error_estimator->get_global_QoI_error_estimate(1)) /
std::abs(QoI_1_exact)
603 libMesh::out <<
"The effectivity index for the computed error in QoI 0 is " 604 << std::setprecision(17)
605 <<
std::abs(adjoint_refinement_error_estimator->get_global_QoI_error_estimate(0)) /
std::abs(QoI_0_computed - QoI_0_exact)
608 libMesh::out <<
"The effectivity index for the computed error in QoI 1 is " 609 << std::setprecision(17)
610 <<
std::abs(adjoint_refinement_error_estimator->get_global_QoI_error_estimate(1)) /
std::abs(QoI_1_computed - QoI_1_exact)
621 libmesh_assert_less(
std::abs(adjoint_refinement_error_estimator->get_global_QoI_error_estimate(0)) /
std::abs(QoI_0_computed - QoI_0_exact), 2.5);
622 libmesh_assert_greater(
std::abs(adjoint_refinement_error_estimator->get_global_QoI_error_estimate(0)) /
std::abs(QoI_0_computed - QoI_0_exact), .4);
623 libmesh_assert_less(
std::abs(adjoint_refinement_error_estimator->get_global_QoI_error_estimate(1)) /
std::abs(QoI_1_computed - QoI_1_exact), 2.5);
624 libmesh_assert_greater(
std::abs(adjoint_refinement_error_estimator->get_global_QoI_error_estimate(1)) /
std::abs(QoI_1_computed - QoI_1_exact), .4);
627 libmesh_assert_less(
std::abs(QoI_0_computed - QoI_0_exact), 2e-4);
628 libmesh_assert_less(
std::abs(QoI_1_computed - QoI_1_exact), 2e-4);
633 <<
"] Completing output." 636 #endif // #ifndef LIBMESH_ENABLE_AMR
This is the EquationSystems class.
virtual void read(const std::string &name, void *mesh_data=nullptr, bool skip_renumber_nodes_and_elements=false, bool skip_find_neighbors=false)=0
Interfaces for reading/writing a mesh to/from a file.
void set_weight(std::size_t, Real)
Set the weight for this index.
virtual dof_id_type n_active_elem() const =0
void set_adjoint_already_solved(bool setting)
Setter for the adjoint_already_solved boolean.
Data structure for specifying which Quantities of Interest should be calculated in an adjoint or a pa...
The ErrorVector is a specialization of the StatisticsVector for error data computed on a finite eleme...
Number & get_QoI_value(std::string type, unsigned int QoI_index)
void write_output(EquationSystems &es, unsigned int a_step, std::string solution_type, FEMParameters ¶m)
bool postprocess_sides
If postprocess_sides is true (it is false by default), the postprocessing loop will loop over all sid...
The LibMeshInit class, when constructed, initializes the dependent libraries (e.g.
std::unique_ptr< MeshRefinement > build_mesh_refinement(MeshBase &mesh, FEMParameters ¶m)
ADRealEigenVector< T, D, asd > abs(const ADRealEigenVector< T, D, asd > &)
SolverPackage default_solver_package()
Implements (adaptive) mesh refinement algorithms for a MeshBase.
void set_system_parameters(LaplaceSystem &system, FEMParameters ¶m)
void print_info(std::ostream &os=libMesh::out, const unsigned int verbosity=0, const bool global=true) const
Prints relevant information about the mesh.
std::unique_ptr< NumericVector< Number > > solution
Data structure to hold solution values.
void init(triangulateio &t)
Initializes the fields of t to nullptr/0 as necessary.
void read(GetPot &input, const std::vector< std::string > *other_variable_names=nullptr)
virtual LinearSolver< Number > * get_linear_solver() const override
virtual void reuse_preconditioner(bool)
Set the same_preconditioner flag, which indicates if we reuse the same preconditioner for subsequent ...
virtual void swap(NumericVector< T > &v)
Swaps the contents of this with v.
bool assemble_qoi_sides
If assemble_qoi_sides is true (it is false by default), the assembly loop for a quantity of interest ...
void add_indices(const std::vector< unsigned int > &indices)
Add this indices to the set to be calculated.
void all_second_order(const bool full_ordered=true)
Calls the range-based version of this function with a range consisting of all elements in the mesh...
NumericVector< Number > & get_adjoint_solution(unsigned int i=0)
virtual void solve() override
Invokes the solver associated with the system.
The Mesh class is a thin wrapper, around the ReplicatedMesh class by default.
processor_id_type processor_id() const
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...
virtual void postprocess()
Runs a postprocessing loop over all elements, and if postprocess_sides is true over all sides...
std::unique_ptr< AdjointRefinementEstimator > build_adjoint_refinement_error_estimator(QoISet &qois)