41double L2Norm(GeometricField<scalar, fvPatchField, volMesh>& field)
44 a = Foam::sqrt(fvc::domainIntegrate(field * field).value());
49double L2Norm(GeometricField<vector, fvPatchField, volMesh>& field)
52 a = Foam::sqrt(fvc::domainIntegrate(field & field).value());
57double LinfNorm(GeometricField<scalar, fvPatchField, volMesh>& field)
60 a = Foam::max(Foam::sqrt(field.internalField() *
61 field.internalField())).value();
66double LinfNorm(GeometricField<vector, fvPatchField, volMesh>& field)
69 Info <<
"LinfNorm(GeometricField<vector, fvPatchField, volMesh>& field) is still to be implemented"
77template<
class Type,
template<
class>
class PatchField,
class GeoMesh>
78double errorFrobRel(GeometricField<Type, PatchField, GeoMesh>& field1,
79 GeometricField<Type, PatchField, GeoMesh>& field2, List<label>* labels)
82 autoPtr<GeometricField<Type, PatchField, GeoMesh >> errField;
83 autoPtr<GeometricField<Type, PatchField, GeoMesh >> field1_S;
84 autoPtr<GeometricField<Type, PatchField, GeoMesh >> field2_S;
85 autoPtr<fvMeshSubset> submesh;
89 submesh = autoPtr<fvMeshSubset>(
new fvMeshSubset(field1.mesh()));
91 submesh->setCellSubset(* labels);
93 submesh->setLargeCellSubset(* labels);
95 GeometricField<Type, PatchField, GeoMesh> field1tmp(submesh->interpolate(
97 GeometricField<Type, PatchField, GeoMesh> field2tmp(submesh->interpolate(
99 field1_S = autoPtr<GeometricField<Type, PatchField, GeoMesh >>
100 (
new GeometricField<Type, PatchField, GeoMesh>(field1tmp.clone()));
101 field2_S = autoPtr<GeometricField<Type, PatchField, GeoMesh >>
102 (
new GeometricField<Type, PatchField, GeoMesh>(field2tmp.clone()));
106 field1_S = autoPtr<GeometricField<Type, PatchField, GeoMesh >>
107 (
new GeometricField<Type, PatchField, GeoMesh>(field1));
108 field2_S = autoPtr<GeometricField<Type, PatchField, GeoMesh >>
109 (
new GeometricField<Type, PatchField, GeoMesh>(field2));
111 errField = autoPtr<GeometricField<Type, PatchField, GeoMesh >>
112 (
new GeometricField<Type, PatchField, GeoMesh>(field1_S() - field2_S()));
126template double errorFrobRel(GeometricField<scalar, fvPatchField, volMesh>&
128 GeometricField<scalar, fvPatchField, volMesh>& field2, List<label>* labels);
129template double errorFrobRel(GeometricField<vector, fvPatchField, volMesh>&
131 GeometricField<vector, fvPatchField, volMesh>& field2, List<label>* labels);
133template double errorFrobRel(GeometricField<scalar, fvsPatchField, surfaceMesh>
136 GeometricField<scalar, fvsPatchField, surfaceMesh>& field2,
137 List<label>* labels);
142 GeometricField<T, fvPatchField, volMesh>& field2, List<label>* labels)
145 autoPtr<GeometricField<T, fvPatchField, volMesh >> errField;
146 autoPtr<GeometricField<T, fvPatchField, volMesh >> field1_S;
147 autoPtr<GeometricField<T, fvPatchField, volMesh >> field2_S;
148 autoPtr<fvMeshSubset> submesh;
152 submesh = autoPtr<fvMeshSubset>(
new fvMeshSubset(field1.mesh()));
154 submesh->setCellSubset(* labels);
156 submesh->setLargeCellSubset(* labels);
158 GeometricField<T, fvPatchField, volMesh> field1tmp(submesh->interpolate(
160 GeometricField<T, fvPatchField, volMesh> field2tmp(submesh->interpolate(
162 field1_S = autoPtr<GeometricField<T, fvPatchField, volMesh >>
163 (
new GeometricField<T, fvPatchField, volMesh>(field1tmp.clone()));
164 field2_S = autoPtr<GeometricField<T, fvPatchField, volMesh >>
165 (
new GeometricField<T, fvPatchField, volMesh>(field2tmp.clone()));
169 field1_S = autoPtr<GeometricField<T, fvPatchField, volMesh >>
170 (
new GeometricField<T, fvPatchField, volMesh>(field1));
171 field2_S = autoPtr<GeometricField<T, fvPatchField, volMesh >>
172 (
new GeometricField<T, fvPatchField, volMesh>(field2));
174 errField = autoPtr<GeometricField<T, fvPatchField, volMesh >>
175 (
new GeometricField<T, fvPatchField, volMesh>(field1_S() - field2_S()));
189template double errorLinfRel(GeometricField<scalar, fvPatchField, volMesh>&
191 GeometricField<scalar, fvPatchField, volMesh>& field2, List<label>* labels);
192template double errorLinfRel(GeometricField<vector, fvPatchField, volMesh>&
194 GeometricField<vector, fvPatchField, volMesh>& field2, List<label>* labels);
197double errorL2Abs(GeometricField<vector, fvPatchField, volMesh>& field1,
198 GeometricField<vector, fvPatchField, volMesh>& field2, volScalarField& Volumes)
201 volScalarField diffFields2 = (((field1 - field2) & (field1 - field2)) *
203 double err = Foam::sqrt(gSum(diffFields2));
208double errorL2Abs(GeometricField<scalar, fvPatchField, volMesh>& field1,
209 GeometricField<scalar, fvPatchField, volMesh>& field2, volScalarField& Volumes)
212 volScalarField diffFields2 = (((field1 - field2) * (field1 - field2)) *
214 double err = Foam::sqrt(gSum(diffFields2));
219double errorL2Abs(GeometricField<T, fvPatchField, volMesh>& field1,
220 GeometricField<T, fvPatchField, volMesh>& field2, List<label>* labels)
222 autoPtr<GeometricField<T, fvPatchField, volMesh >> errField;
223 autoPtr<GeometricField<T, fvPatchField, volMesh >> field1_S;
224 autoPtr<GeometricField<T, fvPatchField, volMesh >> field2_S;
225 autoPtr<fvMeshSubset> submesh;
229 submesh = autoPtr<fvMeshSubset>(
new fvMeshSubset(field1.mesh()));
231 submesh->setCellSubset(* labels);
233 submesh->setLargeCellSubset(* labels);
235 GeometricField<T, fvPatchField, volMesh> field1tmp(submesh->interpolate(
237 GeometricField<T, fvPatchField, volMesh> field2tmp(submesh->interpolate(
239 field1_S = autoPtr<GeometricField<T, fvPatchField, volMesh >>
240 (
new GeometricField<T, fvPatchField, volMesh>(field1tmp.clone()));
241 field2_S = autoPtr<GeometricField<T, fvPatchField, volMesh >>
242 (
new GeometricField<T, fvPatchField, volMesh>(field2tmp.clone()));
246 field1_S = autoPtr<GeometricField<T, fvPatchField, volMesh >>
247 (
new GeometricField<T, fvPatchField, volMesh>(field1));
248 field2_S = autoPtr<GeometricField<T, fvPatchField, volMesh >>
249 (
new GeometricField<T, fvPatchField, volMesh>(field2));
251 errField = autoPtr<GeometricField<T, fvPatchField, volMesh >>
252 (
new GeometricField<T, fvPatchField, volMesh>(field1_S() - field2_S()));
253 double err =
L2Norm(errField());
257template double errorL2Abs(GeometricField<scalar, fvPatchField, volMesh>&
259 GeometricField<scalar, fvPatchField, volMesh>& field2, List<label>* labels);
260template double errorL2Abs(GeometricField<vector, fvPatchField, volMesh>&
262 GeometricField<vector, fvPatchField, volMesh>& field2, List<label>* labels);
265template<
class T,
template<
class>
class PatchField,
class GeoMesh>
266Eigen::MatrixXd
errorFrobRel(PtrList<GeometricField<T, PatchField, GeoMesh >> &
268 PtrList<GeometricField<T, PatchField, GeoMesh >>& fields2, List<label>* labels)
272 if (fields1.size() != fields2.size())
274 Info <<
"The two fields do not have the same size, code will abort" << endl;
278 err.resize(fields1.size(), 1);
280 for (label k = 0; k < fields1.size(); k++)
282 err(k, 0) =
errorFrobRel(fields1[k], fields2[k], labels);
283 Info <<
" Error is " << err[k] << endl;
290 PtrList<GeometricField<scalar, fvPatchField, volMesh >> & fields1,
291 PtrList<GeometricField<scalar, fvPatchField, volMesh >>& fields2,
292 List<label>* labels);
294 PtrList<GeometricField<vector, fvPatchField, volMesh >> & fields1,
295 PtrList<GeometricField<vector, fvPatchField, volMesh >>& fields2,
296 List<label>* labels);
298 PtrList<GeometricField<scalar, fvsPatchField, surfaceMesh >> & fields1,
299 PtrList<GeometricField<scalar, fvsPatchField, surfaceMesh >>& fields2,
300 List<label>* labels);
305 PtrList<GeometricField<T, fvPatchField, volMesh >> & fields1,
306 PtrList<GeometricField<T, fvPatchField, volMesh >>& fields2,
307 PtrList<volScalarField>& Volumes)
309 M_Assert(fields1.size() == fields2.size(),
310 "The two fields do not have the same size, code will abort");
311 M_Assert(fields1.size() == Volumes.size(),
312 "The volumes field and the two solution fields do not have the same size, code will abort");
314 err.resize(fields1.size(), 1);
316 for (label k = 0; k < fields1.size(); k++)
318 err(k, 0) =
errorL2Abs(fields1[k], fields2[k], Volumes[k]);
319 Info <<
" Error is " << err[k] << endl;
326 PtrList<GeometricField<scalar, fvPatchField, volMesh >> & fields1,
327 PtrList<GeometricField<scalar, fvPatchField, volMesh >>& fields2,
328 PtrList<volScalarField>& Volumes);
330 PtrList<GeometricField<vector, fvPatchField, volMesh >> & fields1,
331 PtrList<GeometricField<vector, fvPatchField, volMesh >>& fields2,
332 PtrList<volScalarField>& Volumes);
335Eigen::MatrixXd
errorL2Abs(PtrList<GeometricField<T, fvPatchField, volMesh >> &
337 PtrList<GeometricField<T, fvPatchField, volMesh >>& fields2,
342 if (fields1.size() != fields2.size())
344 Info <<
"The two fields do not have the same size, code will abort" << endl;
348 err.resize(fields1.size(), 1);
350 for (label k = 0; k < fields1.size(); k++)
352 err(k, 0) =
errorL2Abs(fields1[k], fields2[k], labels);
353 Info <<
" Error is " << err[k] << endl;
360 PtrList<GeometricField<scalar, fvPatchField, volMesh >> & fields1,
361 PtrList<GeometricField<scalar, fvPatchField, volMesh >>& fields2,
362 List<label>* labels);
364 PtrList<GeometricField<vector, fvPatchField, volMesh >> & fields1,
365 PtrList<GeometricField<vector, fvPatchField, volMesh >>& fields2,
366 List<label>* labels);
369double errorL2Rel(GeometricField<T, fvPatchField, volMesh>& field1,
370 GeometricField<T, fvPatchField, volMesh>& field2, List<label>* labels)
373 autoPtr<GeometricField<T, fvPatchField, volMesh >> errField;
374 autoPtr<GeometricField<T, fvPatchField, volMesh >> field1_S;
375 autoPtr<GeometricField<T, fvPatchField, volMesh >> field2_S;
376 autoPtr<fvMeshSubset> submesh;
380 submesh = autoPtr<fvMeshSubset>(
new fvMeshSubset(field1.mesh()));
382 submesh->setCellSubset(* labels);
384 submesh->setLargeCellSubset(* labels);
386 GeometricField<T, fvPatchField, volMesh> field1tmp(submesh->interpolate(
388 GeometricField<T, fvPatchField, volMesh> field2tmp(submesh->interpolate(
390 field1_S = autoPtr<GeometricField<T, fvPatchField, volMesh >>
391 (
new GeometricField<T, fvPatchField, volMesh>(field1tmp.clone()));
392 field2_S = autoPtr<GeometricField<T, fvPatchField, volMesh >>
393 (
new GeometricField<T, fvPatchField, volMesh>(field2tmp.clone()));
397 field1_S = autoPtr<GeometricField<T, fvPatchField, volMesh >>
398 (
new GeometricField<T, fvPatchField, volMesh>(field1));
399 field2_S = autoPtr<GeometricField<T, fvPatchField, volMesh >>
400 (
new GeometricField<T, fvPatchField, volMesh>(field2));
402 errField = autoPtr<GeometricField<T, fvPatchField, volMesh >>
403 (
new GeometricField<T, fvPatchField, volMesh>(field1_S() - field2_S()));
405 if (
L2Norm(field1) <= 1e-6)
417template double errorL2Rel(GeometricField<scalar, fvPatchField, volMesh>&
419 GeometricField<scalar, fvPatchField, volMesh>& field2, List<label>* labels);
420template double errorL2Rel(GeometricField<vector, fvPatchField, volMesh>&
422 GeometricField<vector, fvPatchField, volMesh>& field2, List<label>* labels);
425Eigen::MatrixXd
errorL2Rel(PtrList<GeometricField<T, fvPatchField, volMesh >> &
426 fields1, PtrList<GeometricField<T, fvPatchField, volMesh >>& fields2,
431 if (fields1.size() != fields2.size())
433 Info <<
"The two fields do not have the same size, code will abort" << endl;
437 err.resize(fields1.size(), 1);
439 for (label k = 0; k < fields1.size(); k++)
441 err(k, 0) =
errorL2Rel(fields1[k], fields2[k], labels);
442 Info <<
" Error is " << err[k] << endl;
449 PtrList<GeometricField<scalar, fvPatchField, volMesh >> & fields1,
450 PtrList<GeometricField<scalar, fvPatchField, volMesh >>& fields2,
451 List<label>* labels);
453 PtrList<GeometricField<vector, fvPatchField, volMesh >> & fields1,
454 PtrList<GeometricField<vector, fvPatchField, volMesh >>& fields2,
455 List<label>* labels);
458double H1Seminorm(GeometricField<scalar, fvPatchField, volMesh>& field)
461 a = Foam::sqrt(fvc::domainIntegrate(fvc::grad(field) & fvc::grad(
467double H1Seminorm(GeometricField<vector, fvPatchField, volMesh>& field)
470 a = Foam::sqrt(fvc::domainIntegrate(fvc::grad(field)
471 && fvc::grad(field)).value());
476template<
class Type,
template<
class>
class PatchField,
class GeoMesh>
477double frobNorm(GeometricField<Type, PatchField, GeoMesh>& field)
485template double frobNorm(GeometricField<scalar, fvPatchField, volMesh>& field);
486template double frobNorm(GeometricField<vector, fvPatchField, volMesh>& field);
493 label patchID =
mesh.boundaryMesh().findPatchID(patch);
494 const polyPatch& cPatch =
mesh.boundaryMesh()[patchID];
496 const labelUList& faceCells = cPatch.faceCells();
500 label faceOwner = faceCells[faceI] ;
501 scalar faceArea =
mesh.magSf().boundaryField()[patchID][faceI];
502 L2 += faceArea * field[faceOwner] * field[faceOwner];
505 return Foam::sqrt(L2);
509 List<scalar>& field2, word patch)
511 M_Assert(field1.size() == field2.size(),
512 "The two fields do not have the same size, code will abort");
515 label patchID =
mesh.boundaryMesh().findPatchID(patch);
516 const polyPatch& cPatch =
mesh.boundaryMesh()[patchID];
517 M_Assert(field1.size() == cPatch.size(),
518 "The filds must have the same size of the patch, code will abort");
521 scalar faceArea =
mesh.magSf().boundaryField()[patchID][faceI];
522 L2 += faceArea * field1[faceI] * field2[faceI];
533 label patchID =
mesh.boundaryMesh().findPatchID(patch);
534 const polyPatch& cPatch =
mesh.boundaryMesh()[patchID];
536 const labelUList& faceCells = cPatch.faceCells();
539 label faceOwner = faceCells[faceI] ;
543 Linf = std::abs(field[faceOwner]);
545 else if (std::abs(field[faceOwner]) > Linf)
547 Linf = std::abs(field[faceOwner]);
559 label patchID =
mesh.boundaryMesh().findPatchID(patch);
560 const polyPatch& cPatch =
mesh.boundaryMesh()[patchID];
562 const labelUList& faceCells = cPatch.faceCells();
566 label faceOwner = faceCells[faceI] ;
567 scalar faceArea =
mesh.magSf().boundaryField()[patchID][faceI];
568 integral += faceArea * field[faceOwner];
579 label patchID =
mesh.boundaryMesh().findPatchID(patch);
580 const polyPatch& cPatch =
mesh.boundaryMesh()[patchID];
582 const labelUList& faceCells = cPatch.faceCells();
583 int patchSize =
mesh.magSf().boundaryField()[patchID].size();
584 std::string message =
"The input list (size = " + std::to_string(field.size())
585 +
") must have the same size of the patch mesh (size = "
586 + std::to_string(patchSize) +
")";
587 M_Assert( patchSize == field.size(), message.c_str());
591 label faceOwner = faceCells[faceI] ;
592 scalar faceArea =
mesh.magSf().boundaryField()[patchID][faceI];
593 integral += faceArea * field[faceI];
forAll(example_CG.gList, solutionI)
#define M_Assert(Expr, Msg)
Header file of the ITHACAerror file.
static Eigen::VectorXd field2Eigen(GeometricField< tensor, PatchField, GeoMesh > &field)
Convert a vector OpenFOAM field into an Eigen Vector.
Namespace to implement some useful assign operation of OF fields.
double LinfNorm(GeometricField< scalar, fvPatchField, volMesh > &field)
double errorLinfRel(GeometricField< T, fvPatchField, volMesh > &field1, GeometricField< T, fvPatchField, volMesh > &field2, List< label > *labels)
Computes the relative error between two geometric Fields in Linf norm.
double LinfNormOnPatch(fvMesh &mesh, volScalarField &field, word patch)
Evaluate the Linf norm of a field on a boundary patch.
double H1Seminorm(GeometricField< scalar, fvPatchField, volMesh > &field)
double L2Norm(GeometricField< scalar, fvPatchField, volMesh > &field)
double integralOnPatch(fvMesh &mesh, volScalarField &field, word patch)
Evaluate the integral on a patch.
double L2normOnPatch(fvMesh &mesh, volScalarField &field, word patch)
Evaluate the L2 norm of a field on a boundary patch.
double errorL2Rel(GeometricField< T, fvPatchField, volMesh > &field1, GeometricField< T, fvPatchField, volMesh > &field2, List< label > *labels)
Computes the relative error between two geometric Fields in L2 norm.
double frobNorm(GeometricField< Type, PatchField, GeoMesh > &field)
Evaluate the Frobenius norm of a field.
double errorFrobRel(GeometricField< Type, PatchField, GeoMesh > &field1, GeometricField< Type, PatchField, GeoMesh > &field2, List< label > *labels)
Computes the relative error between two Fields in the Frobenius norm.
double L2productOnPatch(fvMesh &mesh, List< scalar > &field1, List< scalar > &field2, word patch)
Evaluate the L2 inner product between two scalarLists.
double errorL2Abs(GeometricField< vector, fvPatchField, volMesh > &field1, GeometricField< vector, fvPatchField, volMesh > &field2, volScalarField &Volumes)