63 bool estimate_parent_error)
65 LOG_SCOPE(
"estimate_error()",
"AdjointResidualErrorEstimator");
72 error_per_cell.resize (
mesh.max_elem_id());
73 std::fill (error_per_cell.begin(), error_per_cell.end(), 0.);
79 std::map<const System *, const NumericVector<Number> *>solutionvecs;
80 solutionvecs[&_system] = _system.
solution.get();
99 if (!error_norm_is_identity)
100 for (
unsigned int v = 0; v <
n_vars; v++)
102 primal_errors_per_cell[std::make_pair(&_system, v)] =
new ErrorVector;
103 dual_errors_per_cell[std::make_pair(&_system, v)] =
new ErrorVector;
104 total_dual_errors_per_cell[std::make_pair(&_system, v)] =
new ErrorVector;
111 if (!error_norm_is_identity)
121 (_system, primal_error_per_cell, solution_vector, estimate_parent_error);
125 for (
unsigned int i = 0, n_qois = _system.
n_qois(); i != n_qois; ++i)
133 std::map<const System *, const NumericVector<Number> *>adjointsolutionvecs;
137 if (!error_norm_is_identity)
141 estimate_parent_error);
150 std::size_t error_size;
153 if (!error_norm_is_identity)
155 error_size = dual_errors_per_cell[std::make_pair(&_system, 0)]->size();
159 error_size = dual_error_per_cell.size();
163 if (!error_norm_is_identity)
166 for (
unsigned int v = 0; v <
n_vars; v++)
168 libmesh_assert(!total_dual_errors_per_cell[std::make_pair(&_system, v)]->size() ||
169 total_dual_errors_per_cell[std::make_pair(&_system, v)]->size() == error_size) ;
170 total_dual_errors_per_cell[std::make_pair(&_system, v)]->resize(error_size);
175 libmesh_assert(!total_dual_error_per_cell.size() ||
176 total_dual_error_per_cell.size() == error_size);
177 total_dual_error_per_cell.resize(error_size);
180 for (std::size_t e = 0; e != error_size; ++e)
183 if (!error_norm_is_identity)
186 for (
unsigned int v = 0; v <
n_vars; v++)
189 (*total_dual_errors_per_cell[std::make_pair(&_system, v)])[e] +=
190 static_cast<ErrorVectorReal>
192 (*dual_errors_per_cell[std::make_pair(&_system, v)])[e]);
197 total_dual_error_per_cell[e] +=
207 if (!error_norm_is_identity)
210 for (
unsigned int v = 0; v <
n_vars; v++)
212 std::ostringstream primal_out;
213 std::ostringstream dual_out;
217 primal_out << std::setw(1)
218 << std::setprecision(0)
223 dual_out << std::setw(1)
224 << std::setprecision(0)
229 (*primal_errors_per_cell[std::make_pair(&_system, v)]).plot_error(primal_out.str(), _system.
get_mesh());
230 (*total_dual_errors_per_cell[std::make_pair(&_system, v)]).plot_error(dual_out.str(), _system.
get_mesh());
238 std::ostringstream primal_out;
239 std::ostringstream dual_out;
256 if (!error_norm_is_identity)
259 std::vector<Real> cell_primal_error;
260 std::vector<Real> cell_dual_error;
262 for (
unsigned int v = 0; v <
n_vars; v++)
264 cell_primal_error.push_back((*primal_errors_per_cell[std::make_pair(&_system, v)])[i]);
265 cell_dual_error.push_back((*total_dual_errors_per_cell[std::make_pair(&_system, v)])[i]);
274 error_per_cell[i] = primal_error_per_cell[i]*total_dual_error_per_cell[i];
279 if (!error_norm_is_identity)
280 for (
unsigned int v = 0; v <
n_vars; v++)
282 delete primal_errors_per_cell[std::make_pair(&_system, v)];
283 delete dual_errors_per_cell[std::make_pair(&_system, v)];
284 delete total_dual_errors_per_cell[std::make_pair(&_system, v)];
Used to specify quantities of interest in a simulation.
unsigned int n_qois() const
const EquationSystems & get_equation_systems() const
IntRange< std::size_t > index_range(const std::vector< T > &vec)
const unsigned int n_vars
const MeshBase & get_mesh() const
DIE A HORRIBLE DEATH HERE typedef float ErrorVectorReal
AdjointResidualErrorEstimator()
bool has_index(std::size_t) const
std::string error_plot_suffix
Manages consistently variables, degrees of freedom, and coefficient vectors.
std::unique_ptr< NumericVector< Number > > solution
virtual std::pair< unsigned int, Real > adjoint_solve(const QoISet &qoi_indices=QoISet())
std::map< std::pair< const System *, unsigned int >, ErrorVector * > ErrorMap
void plot_error(const std::string &filename, const MeshBase &mesh) const
std::unique_ptr< ErrorEstimator > _dual_error_estimator
bool is_adjoint_already_solved() const
Real weight(std::size_t) const
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
Real calculate_norm(const std::vector< Real > &v)
std::unique_ptr< ErrorEstimator > _primal_error_estimator
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
virtual ErrorEstimatorType type() const override