24 #include <unordered_map> 25 #include <unordered_set> 50 #ifdef LIBMESH_ENABLE_AMR 75 number_h_refinements(1),
76 number_p_refinements(0),
77 _residual_evaluation_physics(nullptr),
120 for (
unsigned int j=0,
121 n_qois = system.
n_qois(); j != n_qois; j++)
139 if (swapping_physics)
146 coarse_residual = &(
dynamic_cast<ExplicitSystem &
>(system)).get_vector(
"RHS Vector");
147 coarse_residual->
close();
150 std::ostringstream liftfunc_name;
151 liftfunc_name <<
"adjoint_lift_function" << j;
160 (system.
get_vector(liftfunc_name.str()), static_cast<unsigned int>(j));
163 std::cout<<
"The flux QoI "<<
static_cast<unsigned int>(j)<<
" is: "<<coarse_residual->
dot(system.
get_vector(liftfunc_name.str()))<<std::endl<<std::endl;
166 if (swapping_physics)
173 std::map<std::string, std::unique_ptr<NumericVector<Number>>> coarse_vectors;
177 const std::string & var_name = pr.first;
179 coarse_vectors[var_name] = pr.second->
clone();
183 std::unique_ptr<NumericVector<Number>> coarse_solution = system.
solution->clone();
187 bool old_projection_setting;
194 std::unique_ptr<Partitioner> old_partitioner(
mesh.partitioner().release());
197 const bool old_renumbering_setting =
mesh.allow_renumbering();
198 mesh.allow_renumbering(
false);
201 if (solution_vector && solution_vector != system.
solution.get())
211 error_per_cell.clear();
212 error_per_cell.resize (
mesh.max_elem_id(), 0.);
220 const unsigned int sysnum = system.
number();
221 for (
const auto * node :
mesh.local_node_ptr_range())
222 for (
unsigned int v=0, nvars = node->n_vars(sysnum);
224 if (node->n_comp(sysnum, v))
226 local_dof_bearing_nodes++;
253 std::vector<std::unique_ptr<NumericVector<Number>>> coarse_adjoints;
254 for (
unsigned int j=0; j != system.
n_qois(); j++)
266 coarse_adjoints.emplace_back(std::move(coarse_adjoint));
269 coarse_adjoints.emplace_back(
nullptr);
279 if (swapping_physics)
288 if (swapping_physics)
293 projected_residual.
close();
307 for (
unsigned int j=0; j != system.
n_qois(); j++)
321 std::ostringstream liftfunc_name;
322 liftfunc_name <<
"adjoint_lift_function" << j;
353 for (
unsigned int j=0; j != system.
n_qois(); j++)
390 std::unordered_map<dof_id_type, unsigned int> shared_element_count;
397 std::unordered_set<dof_id_type> processed_node_ids;
401 for (
const auto & elem :
mesh.active_local_element_ptr_range())
402 for (
unsigned int n=0; n != elem->n_nodes(); ++n)
405 const Node & node = elem->node_ref(n);
411 if (processed_node_ids.find(node_id) == processed_node_ids.end())
414 std::set<const Elem *> fine_grid_neighbor_set;
417 elem->find_point_neighbors(node, fine_grid_neighbor_set);
420 std::vector<dof_id_type> coarse_grid_neighbors;
423 for (
const auto & fine_elem : fine_grid_neighbor_set)
426 const Elem * coarse_elem = fine_elem;
429 libmesh_assert (coarse_elem->
parent());
431 coarse_elem = coarse_elem->
parent();
440 for (; j != coarse_grid_neighbors.size(); j++)
441 if (coarse_grid_neighbors[j] == coarse_id)
446 if (j == coarse_grid_neighbors.size())
447 coarse_grid_neighbors.push_back(coarse_id);
452 shared_element_count[node_id] =
453 cast_int<unsigned int>(coarse_grid_neighbors.size());
456 processed_node_ids.insert(node_id);
464 std::vector<dof_id_type> dof_indices;
479 for (
unsigned int i=0; i != system.
n_qois(); i++)
490 for (
const auto & elem :
mesh.active_local_element_ptr_range())
493 const Elem * coarse = elem;
497 libmesh_assert (coarse->
parent());
499 coarse = coarse->
parent();
508 Number local_contribution = 0.;
511 for (
const auto & dof : dof_indices)
512 local_contribution += (*localized_projected_residual)(dof) * (*localized_adjoint_solution)(dof);
515 local_contribution *= error_weight;
549 libmesh_assert_equal_to (n_coarse_elem,
mesh.n_active_elem());
555 for (
const auto * node :
mesh.local_node_ptr_range())
556 for (
unsigned int v=0, nvars = node->n_vars(sysnum);
558 if (node->n_comp(sysnum, v))
560 final_local_dof_bearing_nodes++;
563 libmesh_assert_equal_to (local_dof_bearing_nodes,
564 final_local_dof_bearing_nodes);
571 *system.
solution = *coarse_solution;
577 const std::string & var_name = pr.first;
581 auto it = coarse_vectors.find(var_name);
582 if (it != coarse_vectors.end())
592 mesh.partitioner().reset(old_partitioner.release());
593 mesh.allow_renumbering(old_renumbering_setting);
604 #endif // #ifdef LIBMESH_ENABLE_AMR vectors_iterator vectors_end()
virtual ErrorEstimatorType type() const
void uniformly_p_refine(unsigned int n=1)
Manages multiples systems of equations.
const Elem * parent() const
A geometric point in (x,y,z) space associated with a DOF.
virtual void assembly(bool get_residual, bool get_jacobian, bool apply_heterogeneous_constraints=false, bool apply_no_constraints=false) override=0
virtual void get(const std::vector< numeric_index_type > &index, T *values) const
void dof_indices(const Elem *const elem, std::vector< dof_id_type > &di) const
Used to specify quantities of interest in a simulation.
unsigned int n_qois() const
const EquationSystems & get_equation_systems() const
The base class for all geometric element types.
void uniformly_p_coarsen(unsigned int n=1)
const Parallel::Communicator & comm() const
vectors_iterator vectors_begin()
virtual T dot(const NumericVector< T > &v) const =0
dof_id_type n_local_dofs() const
DIE A HORRIBLE DEATH HERE typedef float ErrorVectorReal
dof_id_type n_dofs() const
void enforce_adjoint_constraints_exactly(NumericVector< Number > &v, unsigned int q) const
Manages the degrees of freedom (DOFs) in a simulation.
bool has_index(std::size_t) const
unsigned int number() const
NumericVector< Number > & add_vector(const std::string &vec_name, const bool projections=true, const ParallelType type=PARALLEL)
Responsible for mesh refinement algorithms and data.
bool has_adjoint_dirichlet_boundaries(unsigned int q) const
Manages consistently variables, degrees of freedom, and coefficient vectors.
void uniformly_coarsen(unsigned int n=1)
const NumericVector< Number > & get_vector(const std::string &vec_name) const
std::unique_ptr< NumericVector< Number > > solution
void init(triangulateio &t)
SimpleRange< I > as_range(const std::pair< I, I > &p)
virtual std::pair< unsigned int, Real > adjoint_solve(const QoISet &qoi_indices=QoISet())
void reduce_error(std::vector< ErrorVectorReal > &error_per_cell, const Parallel::Communicator &comm) const
DifferentiablePhysics * _residual_evaluation_physics
bool is_adjoint_already_solved() const
static std::unique_ptr< NumericVector< T > > build(const Parallel::Communicator &comm, const SolverPackage solver_package=libMesh::default_solver_package())
Real weight(std::size_t) const
std::vector< Number > computed_global_QoI_errors
virtual void estimate_error(const System &system, ErrorVector &error_per_cell, const NumericVector< Number > *solution_vector=nullptr, bool estimate_parent_error=false)
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
virtual void swap(NumericVector< T > &v)
virtual std::unique_ptr< DifferentiableQoI > clone() override
bool & project_solution_on_reinit(void)
const MeshBase & get_mesh() const
NumericVector< Number > & get_adjoint_solution(unsigned int i=0)
std::unique_ptr< NumericVector< Number > > current_local_solution
AdjointRefinementEstimator()
const DofMap & get_dof_map() const
unsigned char number_h_refinements
const std::vector< dof_id_type > & get_send_list() const
Manages consistently variables, degrees of freedom, and coefficient vectors for explicit systems...
unsigned char number_p_refinements
void uniformly_refine(unsigned int n=1)
Manages consistently variables, degrees of freedom, coefficient vectors, and matrices for implicit sy...
virtual void localize(std::vector< T > &v_local) const =0