9 void ConvergenceStudy::Reset()
22 DGFaceErrors.SetSize(0);
23 DGFaceRates.SetSize(0);
30 bool norm_set =
false;
33 int order_quad = std::max(2, 2*order+1);
35 for (
int i=0; i < Geometry::NumGeom; ++i)
40 ParGridFunction *pgf =
dynamic_cast<ParGridFunction *
>(gf);
43 ParMesh *pmesh = pgf->ParFESpace()->GetParMesh();
70 void ConvergenceStudy::AddL2Error(GridFunction *gf,
71 Coefficient *scalar_u, VectorCoefficient *vector_u)
75 ParGridFunction *pgf =
dynamic_cast<ParGridFunction *
>(gf);
78 MPI_Comm comm = pgf->ParFESpace()->GetComm();
80 MPI_Comm_rank(comm, &rank);
82 if (rank==0) { print_flag = 1; }
83 tdofs = pgf->ParFESpace()->GlobalTrueVSize();
86 if (!tdofs) { tdofs = gf->FESpace()->GetTrueVSize(); }
91 L2Err = gf->ComputeL2Error(*scalar_u);
92 CoeffNorm = GetNorm(gf,scalar_u,
nullptr);
96 L2Err = gf->ComputeL2Error(*vector_u);
97 CoeffNorm = GetNorm(gf,
nullptr,vector_u);
101 MFEM_ABORT(
"Exact Solution Coefficient pointer is NULL");
103 L2Errors.Append(L2Err);
106 double val = (counter) ? log(L2Errors[counter-1]/L2Err)/log(2.0) : 0.0;
111 void ConvergenceStudy::AddGf(GridFunction *gf, Coefficient *scalar_u,
112 VectorCoefficient *grad,
113 Coefficient *ell_coeff,
double Nu)
115 cont_type = gf->FESpace()->FEColl()->GetContType();
119 "This constructor is intended for H1 or L2 Elements")
121 AddL2Error(gf,scalar_u,
nullptr);
125 double GradErr = gf->ComputeGradError(grad);
126 DErrors.Append(GradErr);
127 double err = sqrt(L2Errors[counter-1]*L2Errors[counter-1]+GradErr*GradErr);
128 EnErrors.Append(err);
131 double val = (dcounter) ? log(DErrors[dcounter-1]/GradErr)/log(2.0) : 0.0;
132 double eval = (dcounter) ? log(EnErrors[dcounter-1]/err)/log(2.0) : 0.0;
134 EnRates.Append(eval);
135 CoeffDNorm = GetNorm(gf,
nullptr,grad);
137 MFEM_VERIFY(counter == dcounter,
138 "Number of added solutions and derivatives do not match")
143 double DGErr = gf->ComputeDGFaceJumpError(scalar_u,ell_coeff,Nu);
144 DGFaceErrors.Append(DGErr);
147 double val=(fcounter) ? log(DGFaceErrors[fcounter-1]/DGErr)/log(2.0):0.;
148 DGFaceRates.Append(val);
150 MFEM_VERIFY(fcounter == counter,
"Number of added solutions mismatch");
154 void ConvergenceStudy::AddGf(GridFunction *gf, VectorCoefficient *vector_u,
155 VectorCoefficient *curl, Coefficient *div)
157 cont_type = gf->FESpace()->FEColl()->GetContType();
159 AddL2Error(gf,
nullptr,vector_u);
161 bool derivative =
false;
164 DErr = gf->ComputeCurlError(curl);
165 CoeffDNorm = GetNorm(gf,
nullptr,curl);
170 DErr = gf->ComputeDivError(div);
172 CoeffDNorm = GetNorm(gf,div,
nullptr);
177 double err = sqrt(L2Errors[counter-1]*L2Errors[counter-1] + DErr*DErr);
178 DErrors.Append(DErr);
179 EnErrors.Append(err);
182 double val = (dcounter) ? log(DErrors[dcounter-1]/DErr)/log(2.0) : 0.0;
183 double eval = (dcounter) ? log(EnErrors[dcounter-1]/err)/log(2.0) : 0.0;
185 EnRates.Append(eval);
187 MFEM_VERIFY(counter == dcounter,
188 "Number of added solutions and derivatives do not match")
192 void ConvergenceStudy::Print(
bool relative, std::ostream &
out)
196 std::string title = (relative) ?
"Relative " :
"Absolute ";
198 out <<
" -------------------------------------------" <<
"\n";
199 out << std::setw(21) << title <<
"L2 Error " <<
"\n";
200 out <<
" -------------------------------------------"
202 out << std::right<< std::setw(11)<<
"DOFs "<< std::setw(13) <<
"Error ";
203 out << std::setw(15) <<
"Rate " <<
"\n";
204 out <<
" -------------------------------------------"
206 out << std::setprecision(4);
207 double d = (relative) ? CoeffNorm : 1.0;
208 for (
int i =0; i<counter; i++)
210 out << std::right << std::setw(10)<< ndofs[i] << std::setw(16)
211 << std::scientific << L2Errors[i]/d << std::setw(13)
212 << std::fixed << L2Rates[i] <<
"\n";
215 if (dcounter == counter)
220 case 0: dname =
"Grad";
break;
221 case 1: dname =
"Curl";
break;
222 case 2: dname =
"Div";
break;
223 case 3: dname =
"DG Grad";
break;
226 out <<
" -------------------------------------------" <<
"\n";
227 out << std::setw(21) << title << dname <<
" Error " <<
"\n";
228 out <<
" -------------------------------------------" <<
"\n";
229 out << std::right<<std::setw(11)<<
"DOFs "<< std::setw(13) <<
"Error";
230 out << std::setw(15) <<
"Rate " <<
"\n";
231 out <<
" -------------------------------------------"
233 out << std::setprecision(4);
234 d = (relative) ? CoeffDNorm : 1.0;
235 for (
int i =0; i<dcounter; i++)
237 out << std::right << std::setw(10)<< ndofs[i] << std::setw(16)
238 << std::scientific << DErrors[i]/d << std::setw(13)
239 << std::fixed << DRates[i] <<
"\n";
244 case 0: dname =
"H1";
break;
245 case 1: dname =
"H(Curl)";
break;
246 case 2: dname =
"H(Div)";
break;
247 case 3: dname =
"DG H1";
break;
254 sqrt(CoeffNorm*CoeffNorm + CoeffDNorm*CoeffDNorm):1.0;
256 out <<
" -------------------------------------------" <<
"\n";
257 out << std::setw(21) << title << dname <<
" Error " <<
"\n";
258 out <<
" -------------------------------------------" <<
"\n";
259 out << std::right<< std::setw(11)<<
"DOFs "<< std::setw(13);
261 out << std::setw(15) <<
"Rate " <<
"\n";
262 out <<
" -------------------------------------------"
264 out << std::setprecision(4);
265 for (
int i =0; i<dcounter; i++)
267 out << std::right << std::setw(10)<< ndofs[i] << std::setw(16)
268 << std::scientific << EnErrors[i]/d << std::setw(13)
269 << std::fixed << EnRates[i] <<
"\n";
273 if (cont_type == 3 && fcounter)
275 out <<
" -------------------------------------------" <<
"\n";
276 out <<
" DG Face Jump Error " <<
"\n";
277 out <<
" -------------------------------------------"
279 out << std::right<< std::setw(11)<<
"DOFs "<< std::setw(13);
281 out << std::setw(15) <<
"Rate " <<
"\n";
282 out <<
" -------------------------------------------"
284 out << std::setprecision(4);
285 for (
int i =0; i<fcounter; i++)
287 out << std::right << std::setw(10)<< ndofs[i] << std::setw(16)
288 << std::scientific << DGFaceErrors[i] << std::setw(13)
289 << std::fixed << DGFaceRates[i] <<
"\n";
Field is discontinuous across element interfaces.
Class for an integration rule - an Array of IntegrationPoint.
Class for grid function - Vector with associated FE space.
const IntegrationRule & Get(int GeomType, int Order)
Returns an integration rule for given GeomType and Order.
Base class for vector Coefficients that optionally depend on time and space.
double ComputeLpNorm(double p, Coefficient &coeff, Mesh &mesh, const IntegrationRule *irs[])
Compute the Lp norm of a function f. .
Mesh * GetMesh() const
Returns the mesh.
FiniteElementSpace * FESpace()
OutStream err(std::cerr)
Global stream used by the library for standard error output. Initially it uses the same std::streambu...
Base class Coefficients that optionally depend on space and time. These are used by the BilinearFormI...
int GetOrder(int i) const
Returns the order of the i'th finite element.
Field is continuous across element interfaces.
double ComputeGlobalLpNorm(double p, Coefficient &coeff, ParMesh &pmesh, const IntegrationRule *irs[])
Compute the global Lp norm of a function f. .
OutStream out(std::cout)
Global stream used by the library for standard output. Initially it uses the same std::streambuf as s...
IntegrationRules IntRules(0, Quadrature1D::GaussLegendre)
A global object with all integration rules (defined in intrules.cpp)