Line data Source code
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_ADJOINT_REFINEMENT_ESTIMATOR_H 21 : #define LIBMESH_ADJOINT_REFINEMENT_ESTIMATOR_H 22 : 23 : // Local Includes 24 : #include "libmesh/error_estimator.h" 25 : #include "libmesh/libmesh.h" 26 : #include "libmesh/qoi_set.h" 27 : 28 : // C++ includes 29 : #include <cstddef> 30 : #include <vector> 31 : 32 : #ifdef LIBMESH_ENABLE_AMR 33 : 34 : namespace libMesh 35 : { 36 : 37 : // Forward declarations 38 : class DifferentiablePhysics; 39 : 40 : /** 41 : * This class implements a "brute force" goal-oriented error 42 : * estimator which computes an estimate of error in a quantity of 43 : * interest based on the residual of the current coarse grid primal 44 : * solution as weighted against an adjoint solution on a uniformly 45 : * refined (in h and/or p, for an arbitrary number of levels) grid. 46 : * 47 : * \author Roy H. Stogner 48 : * \date 2009 49 : */ 50 : class AdjointRefinementEstimator : public ErrorEstimator 51 : { 52 : public: 53 : 54 : /** 55 : * Constructor. Sets the most common default parameter values. 56 : */ 57 : AdjointRefinementEstimator(); 58 : 59 : /** 60 : * Copy/move ctor, copy/move assignment operator, and destructor are 61 : * all explicitly defaulted for this class. 62 : */ 63 : AdjointRefinementEstimator (const AdjointRefinementEstimator &) = default; 64 : AdjointRefinementEstimator (AdjointRefinementEstimator &&) = default; 65 : AdjointRefinementEstimator & operator= (const AdjointRefinementEstimator &) = default; 66 : AdjointRefinementEstimator & operator= (AdjointRefinementEstimator &&) = default; 67 88 : virtual ~AdjointRefinementEstimator() = default; 68 : 69 : /** 70 : * Access to the QoISet (default: weight all QoIs equally) to use 71 : * when computing errors 72 : */ 73 63360 : QoISet & qoi_set() { return _qoi_set; } 74 : 75 : /** 76 : * Access to the QoISet (default: weight all QoIs equally) to use 77 : * when computing errors 78 : */ 79 : const QoISet & qoi_set() const { return _qoi_set; } 80 : 81 : /** 82 : * This function does uniform refinements and an adjoint 83 : * solve to get an adjoint solution on each cell, 84 : * then estimates the error by finding the weighted residual 85 : * of the coarse solution with the fine adjoint solution. 86 : * 87 : * system.solve() and system.assembly() must be called, and so 88 : * should have no side effects. 89 : * 90 : * Only the provided system is solved on the refined mesh; 91 : * we don't support adjoint solves on loosely coupled 92 : * collections of Systems. 93 : * 94 : * The estimated error is output in the vector 95 : * \p error_per_cell 96 : */ 97 : virtual void estimate_error (const System & system, 98 : ErrorVector & error_per_cell, 99 : const NumericVector<Number> * solution_vector = nullptr, 100 : bool estimate_parent_error = false) override; 101 : 102 : /** 103 : * This is an accessor function to access the computed global 104 : * QoI error estimates 105 : */ 106 928 : Number & get_global_QoI_error_estimate(unsigned int qoi_index) 107 : { 108 1856 : return computed_global_QoI_errors[qoi_index]; 109 : } 110 : 111 : virtual ErrorEstimatorType type() const override; 112 : 113 : /** 114 : * How many h refinements to perform to get the fine grid 115 : */ 116 : unsigned char number_h_refinements; 117 : 118 : /** 119 : * How many p refinements to perform to get the fine grid 120 : */ 121 : unsigned char number_p_refinements; 122 : 123 : /** 124 : * \returns A pointer to the DifferentiablePhysics object or \p nullptr if 125 : * no external Physics object is attached. 126 : */ 127 : DifferentiablePhysics * get_residual_evaluation_physics() 128 : { return this->_residual_evaluation_physics; } 129 : 130 : /** 131 : * Set the _residual_evaluation_physics member to argument 132 : */ 133 : void set_residual_evaluation_physics(DifferentiablePhysics* set_physics) 134 : { this->_residual_evaluation_physics = set_physics; } 135 : 136 : /** 137 : * \returns A pointer to the DifferentiablePhysics object or \p nullptr if 138 : * no external Physics object is attached. 139 : */ 140 : DifferentiablePhysics * get_adjoint_evaluation_physics() 141 : { return this->_adjoint_evaluation_physics; } 142 : 143 : /** 144 : * Set the _adjoint_evaluation_physics member to argument 145 : */ 146 : void set_adjoint_evaluation_physics(DifferentiablePhysics* set_physics) 147 : { this->_adjoint_evaluation_physics = set_physics; } 148 : 149 : protected: 150 : 151 : /** 152 : * Pointer to object to use for physics assembly evaluations. 153 : * Defaults to nullptr for backwards compatibility. 154 : */ 155 : DifferentiablePhysics * _residual_evaluation_physics; 156 : 157 : /** 158 : * Pointer to object to use for adjoint assembly. 159 : * Defaults to nullptr for backwards compatibility. 160 : */ 161 : DifferentiablePhysics * _adjoint_evaluation_physics; 162 : 163 : /* A vector to hold the computed global QoI error estimate */ 164 : std::vector<Number> computed_global_QoI_errors; 165 : 166 : /** 167 : * A QoISet to handle cases with multiple QoIs available 168 : */ 169 : QoISet _qoi_set; 170 : }; 171 : 172 : } // namespace libMesh 173 : 174 : #endif // #ifdef LIBMESH_ENABLE_AMR 175 : 176 : #endif // LIBMESH_ADJOINT_REFINEMENT_ESTIMATOR_H