DUNE-ACFEM (2.5.1)

stationaryadaptivealgorithm.hh
1#ifndef __DUNE_ACFEM_ALGORITHMS_STATIONARY_ADAPTIVE_ALGORITHM_HH__
2#define __DUNE_ACFEM_ALGORITHMS_STATIONARY_ADAPTIVE_ALGORITHM_HH__
3
4#include <dune/fem/solver/timeprovider.hh>
5#include "../algorithms/femschemeinterface.hh"
6
7namespace Dune {
8
9 namespace ACFem {
10
37 static inline
38 std::pair<double, double>
39 adaptiveAlgorithm(AdaptiveFemScheme& scheme, const std::string& prefix_ = "")
40 {
41 std::string prefix = prefix_ == std::string("") ? prefix_ : prefix_ + ".";
42
43 const bool verbose = Dune::Fem::Parameter::getValue<int>("fem.verboserank", -1) != -1;
44
45 // initialize discrete solution
46 scheme.initialize();
47
48 // solve once
49 scheme.solve();
50
51 // write initial solve
52 scheme.output();
53
54 // calculate error
55 double error = -1., oldError;
56 double estimate = 1., oldEstimate;
57 size_t size = 0, oldSize;
58
59 // get tolerance for adaptive algorithm
60 const double tolerance = Dune::Fem::Parameter::getValue<double>(prefix+"adaptation.tolerance", 0.1);
61
62 // get error estimate
63 estimate = scheme.estimate();
64
65 // TODO: maybe trigger computation of errors by a dedicated
66 // flag parameter (also second error computation below)
67 if (verbose) {
68 error = scheme.error();
69 size_t size = scheme.size(); // attention: communication, NOT inside verbose()!!!
70 if (Fem::Parameter::verbose()) {
71 std::cout << "Error: " << error << std::endl;
72 std::cout << "#DoFs: " << size << std::endl;
73 }
74 }
75
76 // until estimator is below tolerance for *THE LOOP*
77 while (estimate > tolerance) {
78 // mark element for adaptation
79 scheme.mark(tolerance);
80
81 // adapt grid
82 scheme.adapt();
83
84 // solve again
85 scheme.solve();
86
87 // data I/O
88 scheme.output();
89
90 // save old estimate
91 oldEstimate = estimate;
92
93 // calculate new error
94 estimate = scheme.estimate();
95
96 // TODO: maybe trigger computation of errors by a dedicated
97 // flag parameter (also second error computation below)
98 if (verbose) {
99 oldError = error;
100 error = scheme.error();
101 oldSize = size;
102 size = scheme.size(); // attention: communication, NOT inside Parameter::verbose()!!!
103 if (Fem::Parameter::verbose()) {
104 std::cout << "Estimate/Error: " << estimate << ", " << error << std::endl;
105 std::cout << "#DoFs: " << size << std::endl;
106 if (oldEstimate > 0) {
107 double estimatorRatio = oldEstimate/estimate;
108 double errorRatio = oldError/error;
109 double sizeRatio = (double)size/(double)oldSize;
110
111 std::cout << "Efficiency: "
112 << std::log(estimatorRatio)/std::log(sizeRatio)
113 << ", "
114 << std::log(errorRatio)/std::log(sizeRatio)
115 << std::endl;
116 }
117 }
118 }
119 }
120
121 if (!verbose) {
122 error = scheme.error();
123 }
124
125 return std::pair<double,double>(estimate, error);
126 }
127
129
130 } // ACFem
131
132} // Dune
133
134#endif // __DUNE_ACFEM_ALGORITHMS_STATIONARY_ADAPTIVE_ALGORITHM_HH__
Abstract space adaptative FEM scheme.
Definition: femschemeinterface.hh:60
virtual bool mark(const double tolerance)=0
mark elements for adaptation
virtual void adapt()=0
do the adaptation for a given marking
virtual double estimate()=0
calculate error estimator
virtual size_t size() const =0
return some measure about the number of DOFs in use
virtual double error() const =0
calculate L2/H1 error
virtual int output()=0
data I/O, return -1 if no data has been written otherwise the sequence number of the file
virtual void solve(bool forceMatrixAssembling=true)=0
Solve the system.
virtual void initialize()=0
initialize the solution
static std::pair< double, double > adaptiveAlgorithm(AdaptiveFemScheme &scheme, const std::string &prefix_="")
Stationary adaptive algorithm like adapt_method_stat() from poor old ALBERTA.
Definition: stationaryadaptivealgorithm.hh:39
static UnaryGridFunctionExpression< LogOperation, Function > log(const Fem::Function< typename Function::FunctionSpaceType, Function > &f_)
Component-wise logarithm, log(f)(x) = [log(f(x)_0),...,log(f(x)_N].
Definition: gridfunctionexpression.hh:2844
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden & Uni Heidelberg  |  generated with Hugo v0.111.3 (Mar 12, 23:28, 2025)