libMesh
error_estimator.h
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2025 Benjamin S. Kirk, John W. Peterson, Roy H. Stogner
3 
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License, or (at your option) any later version.
8 
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
13 
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 
18 
19 
20 #ifndef LIBMESH_ERROR_ESTIMATOR_H
21 #define LIBMESH_ERROR_ESTIMATOR_H
22 
23 // Local Includes
24 #include "libmesh/libmesh_common.h"
25 #include "libmesh/system_norm.h"
26 
27 // C++ includes
28 #include <cstddef>
29 #include <map>
30 #include <string>
31 #include <vector>
32 #include <memory>
33 
34 namespace libMesh
35 {
36 
37 // Forward Declarations
38 class ErrorVector;
39 class EquationSystems;
40 class System;
41 template <typename T> class NumericVector;
42 
43 namespace Parallel {
44  class Communicator;
45 }
46 
47 enum ErrorEstimatorType : int;
48 
62 {
63 public:
64 
69  ErrorEstimator() = default;
70 
75  ErrorEstimator (const ErrorEstimator &) = default;
76  ErrorEstimator (ErrorEstimator &&) = default;
77  ErrorEstimator & operator= (const ErrorEstimator &) = default;
79  virtual ~ErrorEstimator() = default;
80 
81 
95  virtual void estimate_error (const System & system,
96  ErrorVector & error_per_cell,
97  const NumericVector<Number> * solution_vector = nullptr,
98  bool estimate_parent_error = false) = 0;
99 
111  virtual void estimate_errors (const EquationSystems & equation_systems,
112  ErrorVector & error_per_cell,
113  const std::map<const System *, SystemNorm> & error_norms,
114  const std::map<const System *, const NumericVector<Number> *> * solution_vectors = nullptr,
115  bool estimate_parent_error = false);
116 
121  typedef std::map<std::pair<const System *, unsigned int>, std::unique_ptr<ErrorVector>> ErrorMap;
122 
135  virtual void estimate_errors (const EquationSystems & equation_systems,
136  ErrorMap & errors_per_cell,
137  const std::map<const System *, const NumericVector<Number> *> * solution_vectors = nullptr,
138  bool estimate_parent_error = false);
139 
143  virtual ErrorEstimatorType type() const = 0;
144 
159 
160 protected:
161 
167  void reduce_error (std::vector<ErrorVectorReal> & error_per_cell,
168  const Parallel::Communicator & comm) const;
169 };
170 
171 
172 } // namespace libMesh
173 
174 #endif // LIBMESH_ERROR_ESTIMATOR_H
virtual void estimate_errors(const EquationSystems &equation_systems, ErrorVector &error_per_cell, const std::map< const System *, SystemNorm > &error_norms, const std::map< const System *, const NumericVector< Number > *> *solution_vectors=nullptr, bool estimate_parent_error=false)
This virtual function can be redefined in derived classes, but by default computes the sum of the err...
This is the EquationSystems class.
ErrorEstimator & operator=(const ErrorEstimator &)=default
SystemNorm error_norm
When estimating the error in a single system, the error_norm is used to control the scaling and norm ...
The ErrorVector is a specialization of the StatisticsVector for error data computed on a finite eleme...
Definition: error_vector.h:50
ErrorEstimatorType
Defines an enum for the different types of error estimators which are available.
virtual void estimate_error(const System &system, ErrorVector &error_per_cell, const NumericVector< Number > *solution_vector=nullptr, bool estimate_parent_error=false)=0
This pure virtual function must be redefined in derived classes to compute the error for each active ...
This class defines a norm/seminorm to be applied to a NumericVector which contains coefficients in a ...
Definition: system_norm.h:49
The libMesh namespace provides an interface to certain functionality in the library.
virtual ErrorEstimatorType type() const =0
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...
Manages consistently variables, degrees of freedom, and coefficient vectors.
Definition: system.h:96
This class holds functions that will estimate the error in a finite element solution on a given mesh...
void reduce_error(std::vector< ErrorVectorReal > &error_per_cell, const Parallel::Communicator &comm) const
This method takes the local error contributions in error_per_cell from each processor and combines th...
ErrorEstimator()=default
Constructor.
virtual ~ErrorEstimator()=default
void ErrorVector unsigned int
Definition: adjoints_ex3.C:360