20 #include "libmesh/adjoint_residual_error_estimator.h" 21 #include "libmesh/error_vector.h" 22 #include "libmesh/patch_recovery_error_estimator.h" 23 #include "libmesh/libmesh_logging.h" 24 #include "libmesh/numeric_vector.h" 25 #include "libmesh/system.h" 26 #include "libmesh/system_norm.h" 27 #include "libmesh/qoi_set.h" 28 #include "libmesh/enum_error_estimator_type.h" 29 #include "libmesh/int_range.h" 64 bool estimate_parent_error)
66 LOG_SCOPE(
"estimate_error()",
"AdjointResidualErrorEstimator");
73 error_per_cell.resize (
mesh.max_elem_id());
74 std::fill (error_per_cell.begin(), error_per_cell.end(), 0.);
80 std::map<const System *, const NumericVector<Number> *>solutionvecs;
81 solutionvecs[&_system] = _system.
solution.get();
100 if (!error_norm_is_identity)
101 for (
unsigned int v = 0; v <
n_vars; v++)
103 primal_errors_per_cell[std::make_pair(&_system, v)] = std::make_unique<ErrorVector>();
104 dual_errors_per_cell[std::make_pair(&_system, v)] = std::make_unique<ErrorVector>();
105 total_dual_errors_per_cell[std::make_pair(&_system, v)] = std::make_unique<ErrorVector>();
112 if (!error_norm_is_identity)
122 (_system, primal_error_per_cell, solution_vector, estimate_parent_error);
126 for (
unsigned int i = 0, n_qois = _system.
n_qois(); i != n_qois; ++i)
134 std::map<const System *, const NumericVector<Number> *>adjointsolutionvecs;
138 if (!error_norm_is_identity)
142 estimate_parent_error);
151 std::size_t error_size;
154 if (!error_norm_is_identity)
156 error_size = dual_errors_per_cell[std::make_pair(&_system, 0)]->size();
160 error_size = dual_error_per_cell.size();
164 if (!error_norm_is_identity)
167 for (
unsigned int v = 0; v <
n_vars; v++)
169 libmesh_assert(!total_dual_errors_per_cell[std::make_pair(&_system, v)]->size() ||
170 total_dual_errors_per_cell[std::make_pair(&_system, v)]->size() == error_size) ;
171 total_dual_errors_per_cell[std::make_pair(&_system, v)]->resize(error_size);
177 total_dual_error_per_cell.size() == error_size);
178 total_dual_error_per_cell.resize(error_size);
181 for (std::size_t e = 0; e != error_size; ++e)
184 if (!error_norm_is_identity)
187 for (
unsigned int v = 0; v <
n_vars; v++)
190 (*total_dual_errors_per_cell[std::make_pair(&_system, v)])[e] +=
191 static_cast<ErrorVectorReal>
193 (*dual_errors_per_cell[std::make_pair(&_system, v)])[e]);
198 total_dual_error_per_cell[e] +=
208 if (!error_norm_is_identity)
211 for (
unsigned int v = 0; v <
n_vars; v++)
213 std::ostringstream primal_out;
214 std::ostringstream dual_out;
218 primal_out << std::setw(1)
219 << std::setprecision(0)
224 dual_out << std::setw(1)
225 << std::setprecision(0)
230 primal_errors_per_cell[std::make_pair(&_system, v)]->plot_error(primal_out.str(), _system.
get_mesh());
231 total_dual_errors_per_cell[std::make_pair(&_system, v)]->plot_error(dual_out.str(), _system.
get_mesh());
239 std::ostringstream primal_out;
240 std::ostringstream dual_out;
257 if (!error_norm_is_identity)
260 std::vector<Real> cell_primal_error;
261 std::vector<Real> cell_dual_error;
263 for (
unsigned int v = 0; v <
n_vars; v++)
265 cell_primal_error.push_back((*primal_errors_per_cell[std::make_pair(&_system, v)])[i]);
266 cell_dual_error.push_back((*total_dual_errors_per_cell[std::make_pair(&_system, v)])[i]);
275 error_per_cell[i] = primal_error_per_cell[i]*total_dual_error_per_cell[i];
SystemNorm error_norm
When estimating the error in a single system, the error_norm is used to control the scaling and norm ...
Data structure for specifying which Quantities of Interest should be calculated in an adjoint or a pa...
unsigned int n_qois() const
Number of currently active quantities of interest.
The ErrorVector is a specialization of the StatisticsVector for error data computed on a finite eleme...
ErrorEstimatorType
Defines an enum for the different types of error estimators which are available.
const EquationSystems & get_equation_systems() const
QoISet _qoi_set
A QoISet to handle cases with multiple QoIs available.
The libMesh namespace provides an interface to certain functionality in the library.
std::map< std::pair< const System *, unsigned int >, std::unique_ptr< ErrorVector > > ErrorMap
When calculating many error vectors at once, we need a data structure to hold them all...
const MeshBase & get_mesh() const
DIE A HORRIBLE DEATH HERE typedef float ErrorVectorReal
This is the MeshBase class.
AdjointResidualErrorEstimator()
Constructor.
bool has_index(std::size_t) const
Return whether or not this index is in the set to be calculated.
std::string error_plot_suffix
To aid in investigating error estimator behavior, set this string to a suffix with which to plot (pre...
Manages consistently variables, degrees of freedom, and coefficient vectors.
std::unique_ptr< NumericVector< Number > > solution
Data structure to hold solution values.
This class holds functions that will estimate the error in a finite element solution on a given mesh...
virtual std::pair< unsigned int, Real > adjoint_solve(const QoISet &qoi_indices=QoISet())
Solves the adjoint system, for the specified qoi indices, or for every qoi if qoi_indices is nullptr...
void plot_error(const std::string &filename, const MeshBase &mesh) const
Plots a data file, of a type determined by looking at the file extension in filename, of the error values on the active elements of mesh.
std::unique_ptr< ErrorEstimator > _dual_error_estimator
An error estimator for the adjoint problem.
bool is_adjoint_already_solved() const
Accessor for the adjoint_already_solved boolean.
Real weight(std::size_t) const
Get the weight for this index (default 1.0)
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
This class implements the Patch Recovery error indicator.
Real calculate_norm(const std::vector< Real > &v)
std::unique_ptr< ErrorEstimator > _primal_error_estimator
An error estimator for the forward problem.
NumericVector< Number > & get_adjoint_solution(unsigned int i=0)
unsigned int n_vars() const
virtual void estimate_error(const System &system, ErrorVector &error_per_cell, const NumericVector< Number > *solution_vector=nullptr, bool estimate_parent_error=false) override
Compute the adjoint-weighted error on each element and place it in the error_per_cell vector...
virtual ErrorEstimatorType type() const override
auto index_range(const T &sizable)
Helper function that returns an IntRange<std::size_t> representing all the indices of the passed-in v...