DOLFIN
DOLFIN C++ interface
ErrorControl.h
1// Copyright (C) 2010 Marie E. Rognes
2//
3// This file is part of DOLFIN.
4//
5// DOLFIN is free software: you can redistribute it and/or modify
6// it under the terms of the GNU Lesser General Public License as published by
7// the Free Software Foundation, either version 3 of the License, or
8// (at your option) any later version.
9//
10// DOLFIN is distributed in the hope that it will be useful,
11// but WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13// GNU Lesser General Public License for more details.
14//
15// You should have received a copy of the GNU Lesser General Public License
16// along with DOLFIN. If not, see <http://www.gnu.org/licenses/>.
17//
18// First added: 2010-08-19
19// Last changed: 2012-09-03
20
21#ifndef __ERROR_CONTROL_H
22#define __ERROR_CONTROL_H
23
24#include <vector>
25#include <memory>
26
27#include <dolfin/common/Hierarchical.h>
28#include <dolfin/common/Variable.h>
29#include <dolfin/fem/LinearVariationalSolver.h>
30#include "adapt.h"
31
32namespace dolfin
33{
34
35 class DirichletBC;
36 class Form;
37 class Function;
38 class FunctionSpace;
39 class SpecialFacetFunction;
40 class Vector;
41
42 template <typename T> class MeshFunction;
43
45
49
50 class ErrorControl : public Hierarchical<ErrorControl>, public Variable
51 {
52 public:
53
74 ErrorControl(std::shared_ptr<Form> a_star,
75 std::shared_ptr<Form> L_star,
76 std::shared_ptr<Form> residual,
77 std::shared_ptr<Form> a_R_T,
78 std::shared_ptr<Form> L_R_T,
79 std::shared_ptr<Form> a_R_dT,
80 std::shared_ptr<Form> L_R_dT,
81 std::shared_ptr<Form> eta_T,
82 bool is_linear);
83
86
89 {
90 Parameters p("error_control");
91
92 // Set parameters for dual solver
94 p_dual.rename("dual_variational_solver");
95 p.add(p_dual);
96
97 return p;
98 }
99
100
114 double estimate_error(const Function& u,
115 const std::vector<std::shared_ptr<const DirichletBC> > bcs);
116
125 const Function& u);
126
140 const Function& u);
141
150 void compute_cell_residual(Function& R_T, const Function& u);
151
164 const Function& u,
165 const Function& R_T);
166
176 void compute_dual(Function& z,
177 const std::vector<std::shared_ptr<const DirichletBC> > bcs);
178
186 void compute_extrapolation(const Function& z,
187 const std::vector<std::shared_ptr<const DirichletBC> > bcs);
188
189 friend std::shared_ptr<ErrorControl>
191 std::shared_ptr<const Mesh> adapted_mesh,
192 bool adapt_coefficients);
193
194 private:
195
196 void apply_bcs_to_extrapolation(const std::vector<std::shared_ptr<const DirichletBC> > bcs);
197
198 // Bilinear and linear form for dual problem
199 std::shared_ptr<Form> _a_star;
200 std::shared_ptr<Form> _L_star;
201
202 // Functional for evaluating residual (error estimate)
203 std::shared_ptr<Form> _residual;
204
205 // Bilinear and linear form for computing cell residual R_T
206 std::shared_ptr<Form> _a_R_T;
207 std::shared_ptr<Form> _L_R_T;
208
209 // Bilinear and linear form for computing facet residual R_dT
210 std::shared_ptr<Form> _a_R_dT;
211 std::shared_ptr<Form> _L_R_dT;
212
213 // Linear form for computing error indicators
214 std::shared_ptr<Form> _eta_T;
215
216 // Computed extrapolation
217 std::shared_ptr<Function> _Ez_h;
218
219 bool _is_linear;
220
221 // Function spaces for extrapolation, cell bubble and cell cone:
222 std::shared_ptr<const FunctionSpace> _extrapolation_space;
223 std::shared_ptr<const FunctionSpace> _bubble_space;
224 std::shared_ptr<const FunctionSpace> _cone_space;
225
226 // Functions for cell bubble, cell cone, computed cell residual,
227 // computed facet residual, and interpolated extrapolated(!) dual:
228 std::shared_ptr<Function> _cell_bubble;
229 std::shared_ptr<Function> _cell_cone;
230 std::shared_ptr<Function> _R_T;
231 std::shared_ptr<SpecialFacetFunction> _R_dT;
232 std::shared_ptr<Function> _Pi_E_z_h;
233 };
234}
235
236#endif
(Goal-oriented) Error Control class.
Definition: ErrorControl.h:51
double estimate_error(const Function &u, const std::vector< std::shared_ptr< const DirichletBC > > bcs)
Definition: ErrorControl.cpp:96
void compute_facet_residual(SpecialFacetFunction &R_dT, const Function &u, const Function &R_T)
Definition: ErrorControl.cpp:336
void compute_cell_residual(Function &R_T, const Function &u)
Definition: ErrorControl.cpp:260
static Parameters default_parameters()
Default parameter values.
Definition: ErrorControl.h:88
friend std::shared_ptr< ErrorControl > adapt(const ErrorControl &ec, std::shared_ptr< const Mesh > adapted_mesh, bool adapt_coefficients)
void compute_extrapolation(const Function &z, const std::vector< std::shared_ptr< const DirichletBC > > bcs)
Definition: ErrorControl.cpp:161
void residual_representation(Function &R_T, SpecialFacetFunction &R_dT, const Function &u)
Definition: ErrorControl.cpp:243
~ErrorControl()
Destructor.
Definition: ErrorControl.h:85
void compute_indicators(MeshFunction< double > &indicators, const Function &u)
Definition: ErrorControl.cpp:176
void compute_dual(Function &z, const std::vector< std::shared_ptr< const DirichletBC > > bcs)
Definition: ErrorControl.cpp:130
ErrorControl(std::shared_ptr< Form > a_star, std::shared_ptr< Form > L_star, std::shared_ptr< Form > residual, std::shared_ptr< Form > a_R_T, std::shared_ptr< Form > L_R_T, std::shared_ptr< Form > a_R_dT, std::shared_ptr< Form > L_R_dT, std::shared_ptr< Form > eta_T, bool is_linear)
Definition: ErrorControl.cpp:55
Definition: Function.h:66
Definition: Hierarchical.h:44
static Parameters default_parameters()
Default parameter values.
Definition: LinearVariationalSolver.h:49
Definition: MeshFunction.h:58
Definition: Parameters.h:95
void add(std::string key)
Definition: Parameters.h:128
void rename(std::string key)
Rename parameter set.
Definition: Parameters.cpp:55
Definition: SpecialFacetFunction.h:42
Common base class for DOLFIN variables.
Definition: Variable.h:36
Definition: adapt.h:30
double residual(const GenericLinearOperator &A, const GenericVector &x, const GenericVector &b)
Compute residual ||Ax - b||.
Definition: solve.cpp:163