OOFEM 3.0
Loading...
Searching...
No Matches
meshqualityerrorestimator.C
Go to the documentation of this file.
1/*
2 *
3 * ##### ##### ###### ###### ### ###
4 * ## ## ## ## ## ## ## ### ##
5 * ## ## ## ## #### #### ## # ##
6 * ## ## ## ## ## ## ## ##
7 * ## ## ## ## ## ## ## ##
8 * ##### ##### ## ###### ## ##
9 *
10 *
11 * OOFEM : Object Oriented Finite Element Code
12 *
13 * Copyright (C) 1993 - 2025 Borek Patzak
14 *
15 *
16 *
17 * Czech Technical University, Faculty of Civil Engineering,
18 * Department of Structural Mechanics, 166 29 Prague, Czech Republic
19 *
20 * This library is free software; you can redistribute it and/or
21 * modify it under the terms of the GNU Lesser General Public
22 * License as published by the Free Software Foundation; either
23 * version 2.1 of the License, or (at your option) any later version.
24 *
25 * This program is distributed in the hope that it will be useful,
26 * but WITHOUT ANY WARRANTY; without even the implied warranty of
27 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
28 * Lesser General Public License for more details.
29 *
30 * You should have received a copy of the GNU Lesser General Public
31 * License along with this library; if not, write to the Free Software
32 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
33 */
34
36#include "element.h"
37#include "elementgeometrytype.h"
38#include "mathfem.h"
39#include "node.h"
40#include "integrationrule.h"
41#include "feinterpol.h"
42#include "gausspoint.h"
43
44namespace oofem {
45double MeshQualityErrorEstimator :: giveElementError(EE_ErrorType type, Element *elem, TimeStep *tStep)
46{
47 // A good plan would probably be to let the element determines its own quality if they implement some interface.
48 // otherwise use a sane default.
49 double error;
52 if ( fei && ir ) {
53 error = this->computeJacobianError(* fei, * ir, elem);
54 } else {
55 switch ( elem->giveGeometryType() ) {
56 case EGT_triangle_1:
57 error = this->computeTriangleRadiusError(elem);
58 break;
59 case EGT_triangle_2:
60 error = this->computeTriangleRadiusError(elem);
61 break;
62 default:
63 error = 0.0;
64 break;
65 }
66 }
67 return error;
68}
69
70double MeshQualityErrorEstimator :: computeTriangleRadiusError(Element *elem)
71{
72 // Outside/inside circle radius fraction based for quality measurement.
73 // Zero for a perfect triangle,
74 const auto &c1 = elem->giveNode(1)->giveCoordinates();
75 const auto &c2 = elem->giveNode(2)->giveCoordinates();
76 const auto &c3 = elem->giveNode(3)->giveCoordinates();
77 double a = distance(c1, c2);
78 double b = distance(c1, c3);
79 double c = distance(c2, c3);
80 return a * b * c / ( ( b + c - a ) * ( a + c - b ) * ( a + b - c ) ) - 1.0;
81 // Reciprocal error would be;
82 // (b+c-a)*(a+c-b)*(a+b-c)/(a*b*c - (b+c-a)*(a+c-b)*(a+b-c));
83 // Which is safe except for when all points coincide, i.e. a = b = c = 0
84}
85
86double MeshQualityErrorEstimator :: computeJacobianError(FEInterpolation &fei, IntegrationRule &ir, Element *elem)
87{
88 double min_rcond = 1.0, rcond;
89 FloatMatrix jac;
90
91 for ( auto &gp: ir ) {
92 fei.giveJacobianMatrixAt( jac, gp->giveNaturalCoordinates(), FEIElementGeometryWrapper(elem) );
93 rcond = jac.computeReciprocalCondition() * sgn( jac.giveDeterminant() ); // Signed rcond. as inverted mappings are particularly bad.
94 if ( rcond < min_rcond ) {
95 min_rcond = rcond;
96 }
97 }
98 return min_rcond < 1e-6 ? 1e6 : 1.0 / min_rcond; // Cap it to avoid overflow.
99}
100
101double MeshQualityErrorEstimator :: giveValue(EE_ValueType type, TimeStep *tStep)
102{
103 double error = 0.0;
104 for ( auto &elem : this->domain->giveElements() ) {
105 double temp = this->giveElementError(unknownET, elem.get(), tStep);
106 if ( temp > error ) {
107 error = temp;
108 }
109 }
110 return error;
111}
112
113int MeshQualityErrorEstimator :: estimateError(EE_ErrorMode mode, TimeStep *tStep)
114{
115 return true;
116}
117
118void MeshQualityErrorEstimator :: initializeFrom(InputRecord &ir)
119{
120 ErrorEstimator :: initializeFrom(ir);
121}
122} // end namespace oofem
const FloatArray & giveCoordinates() const
Definition dofmanager.h:390
Node * giveNode(int i) const
Definition element.h:629
virtual FEInterpolation * giveInterpolation() const
Definition element.h:648
virtual IntegrationRule * giveDefaultIntegrationRulePtr()
Definition element.h:886
virtual Element_Geometry_Type giveGeometryType() const =0
virtual void giveJacobianMatrixAt(FloatMatrix &jacobianMatrix, const FloatArray &lcoords, const FEICellGeometry &cellgeo) const
Definition feinterpol.h:284
Domain * domain
Link to domain object, useful for communicating with other FEM components.
Definition femcmpnn.h:79
double computeReciprocalCondition(char p='1') const
double giveDeterminant() const
static double computeJacobianError(FEInterpolation &fei, IntegrationRule &ir, Element *elem)
double giveElementError(EE_ErrorType type, Element *elem, TimeStep *tStep) override
static double computeTriangleRadiusError(Element *elem)
double rcond(const FloatMatrixF< N, N > &mat, int p=1)
double sgn(double i)
Returns the signum of given value (if value is < 0 returns -1, otherwise returns 1).
Definition mathfem.h:104
double distance(const FloatArray &x, const FloatArray &y)

This page is part of the OOFEM-3.0 documentation. Copyright Copyright (C) 1994-2025 Borek Patzak Bořek Patzák
Project e-mail: oofem@fsv.cvut.cz
Generated at for OOFEM by doxygen 1.15.0 written by Dimitri van Heesch, © 1997-2011