OOFEM  2.4
OOFEM.org - Object Oriented Finite Element Solver
feinterpol2d.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 - 2013 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 
35 #include "feinterpol2d.h"
36 #include "floatarray.h"
37 #include "gaussintegrationrule.h"
38 
39 namespace oofem {
41 {
42  this->computeLocalEdgeMapping(answer, boundary);
43 }
44 
45 void FEInterpolation2d :: boundaryEdgeEvalN(FloatArray &answer, int boundary, const FloatArray &lcoords, const FEICellGeometry &cellgeo)
46 {
47  this->edgeEvalN(answer, boundary, lcoords, cellgeo);
48 }
49 
51 {
52  return this->edgeGiveTransformationJacobian(boundary, lcoords, cellgeo);
53 }
54 
55 void FEInterpolation2d :: boundaryEdgeLocal2Global(FloatArray &answer, int boundary, const FloatArray &lcoords, const FEICellGeometry &cellgeo)
56 {
57  this->edgeLocal2global(answer, boundary, lcoords, cellgeo);
58 }
59 
60 double FEInterpolation2d :: giveArea(const FEICellGeometry &cellgeo) const
61 {
62  OOFEM_ERROR("Not implemented in subclass.");
63  return 0;
64 }
65 
66 #define POINT_TOL 1.e-3
67 
68 int FEInterpolation2d :: global2local(FloatArray &answer, const FloatArray &gcoords, const FEICellGeometry &cellgeo)
69 {
70  FloatArray res, delta, guess, lcoords_guess;
71  FloatMatrix jac;
72  double convergence_limit, error = 0.0;
73 
74  // find a suitable convergence limit
75  convergence_limit = 1e-6 * this->giveCharacteristicLength(cellgeo);
76 
77  // setup initial guess
78  lcoords_guess.resize( 2 );
79  lcoords_guess.zero();
80 
81  // apply Newton-Raphson to solve the problem
82  for ( int nite = 0; nite < 10; nite++ ) {
83  // compute the residual
84  this->local2global(guess, lcoords_guess, cellgeo);
85  res = {gcoords(0) - guess(0), gcoords(1) - guess(1)};
86 
87  // check for convergence
88  error = res.computeNorm();
89  if ( error < convergence_limit ) {
90  break;
91  }
92 
93  // compute the corrections
94  this->giveJacobianMatrixAt(jac, lcoords_guess, cellgeo);
95  jac.solveForRhs(res, delta);
96 
97  // update guess
98  lcoords_guess.add(delta);
99  }
100  if ( error > convergence_limit ) { // Imperfect, could give false negatives.
101  OOFEM_WARNING("Failed convergence");
102  answer = {1. / 3., 1. / 3.};
103  return false;
104  }
105 
106  answer = { lcoords_guess(0), lcoords_guess(1) };
107 
108  return inside(answer);
109 }
110 
111 void
112 FEInterpolation2d :: giveJacobianMatrixAt(FloatMatrix &jacobianMatrix, const FloatArray &lcoords, const FEICellGeometry &cellgeo)
113 // Returns the jacobian matrix J (x,y)/(ksi,eta) of the receiver.
114 {
115  double x, y;
116  FloatMatrix dn;
117 
118  jacobianMatrix.resize(2, 2);
119  jacobianMatrix.zero();
120 
121  this->evaldNdxi(dn, lcoords, cellgeo );
122 
123  for ( int i = 1; i <= dn.giveNumberOfRows(); i++ ) {
124  x = cellgeo.giveVertexCoordinates(i)->at(xind);
125  y = cellgeo.giveVertexCoordinates(i)->at(yind);
126 
127  jacobianMatrix.at(1, 1) += dn.at(i, 1) * x;
128  jacobianMatrix.at(2, 1) += dn.at(i, 1) * y;
129  jacobianMatrix.at(1, 2) += dn.at(i, 2) * x;
130  jacobianMatrix.at(2, 2) += dn.at(i, 2) * y;
131  }
132 }
133 
134 bool FEInterpolation2d ::inside(const FloatArray &lcoords) const
135 {
136  OOFEM_ERROR("Not implemented.")
137 }
138 
140 {
141  this->computeLocalEdgeMapping(answer, boundary);
142 }
143 
144 void FEInterpolation2d :: boundaryEvalN(FloatArray &answer, int boundary, const FloatArray &lcoords, const FEICellGeometry &cellgeo)
145 {
146  this->edgeEvalN(answer, boundary, lcoords, cellgeo);
147 }
148 
149 double FEInterpolation2d :: boundaryEvalNormal(FloatArray &answer, int boundary, const FloatArray &lcoords, const FEICellGeometry &cellgeo)
150 {
151  return this->edgeEvalNormal(answer, boundary, lcoords, cellgeo);
152 }
153 
154 double FEInterpolation2d :: boundaryGiveTransformationJacobian(int boundary, const FloatArray &lcoords, const FEICellGeometry &cellgeo)
155 {
156  return this->edgeGiveTransformationJacobian(boundary, lcoords, cellgeo);
157 }
158 
159 void FEInterpolation2d :: boundaryLocal2Global(FloatArray &answer, int boundary, const FloatArray &lcoords, const FEICellGeometry &cellgeo)
160 {
161  return this->edgeLocal2global(answer, boundary, lcoords, cellgeo);
162 }
163 
164 void FEInterpolation2d :: computeEdgeMapping(IntArray &edgeNodes, IntArray &elemNodes, int iedge)
165 {
166  IntArray ln;
167  this->computeLocalEdgeMapping(ln, iedge);
168  int size = ln.giveSize();
169  edgeNodes.resize(size);
170  for ( int i = 1; i <= size; i++ ) {
171  edgeNodes.at(i) = elemNodes.at( ln.at(i) );
172  }
173 }
174 
175 double FEInterpolation2d :: edgeGiveTransformationJacobian(int iedge, const FloatArray &lcoords, const FEICellGeometry &cellgeo)
176 {
177  FloatArray normal;
178  return this->edgeEvalNormal(normal, iedge, lcoords, cellgeo);
179 }
180 
181 void FEInterpolation2d::boundarySurfaceEvalN(FloatArray &answer, int isurf, const FloatArray &lcoords, const FEICellGeometry &cellgeo)
182 {
183  this->evalN(answer, lcoords, cellgeo);
184 }
185 
187  const FloatArray &lcoords, const FEICellGeometry &cellgeo)
188 {
189  this->evaldNdx(answer, lcoords, cellgeo);
190 }
191 
192 double FEInterpolation2d::boundarySurfaceEvalNormal(FloatArray &answer, int isurf, const FloatArray &lcoords,
193  const FEICellGeometry &cellgeo)
194 {
195  answer = {0,0,1};
196  return this->giveTransformationJacobian(lcoords, cellgeo);
197 }
198 
200  const FloatArray &lcoords, const FEICellGeometry &cellgeo)
201 {
202  this->local2global(answer, lcoords, cellgeo);
203 }
204 
206  const FEICellGeometry &cellgeo)
207 {
208  return this->giveTransformationJacobian(lcoords, cellgeo);
209 }
210 
212 {
213  int nnode = this->giveNumberOfNodes();
214  answer.resize(nnode);
215  for (int i =1; i<=nnode; i++) {
216  answer.at(i)=i;
217  }
218 }
219 
220 
221 } // end namespace oofem
virtual double boundarySurfaceEvalNormal(FloatArray &answer, int isurf, const FloatArray &lcoords, const FEICellGeometry &cellgeo)
Evaluates the normal out of the surface at given point.
Definition: feinterpol2d.C:192
virtual void edgeLocal2global(FloatArray &answer, int iedge, const FloatArray &lcoords, const FEICellGeometry &cellgeo)=0
Evaluates edge global coordinates from given local ones.
virtual void evaldNdxi(FloatMatrix &answer, const FloatArray &lcoords, const FEICellGeometry &cellgeo)
Evaluates the matrix of derivatives of interpolation functions (shape functions) at given point...
Definition: feinterpol.h:193
virtual void evalN(FloatArray &answer, const FloatArray &lcoords, const FEICellGeometry &cellgeo)=0
Evaluates the array of interpolation functions (shape functions) at given point.
virtual double giveTransformationJacobian(const FloatArray &lcoords, const FEICellGeometry &cellgeo)
Evaluates the determinant of the transformation.
Definition: feinterpol.C:43
bool solveForRhs(const FloatArray &b, FloatArray &answer, bool transpose=false)
Solves the system of linear equations .
Definition: floatmatrix.C:1112
virtual void boundarySurfaceEvalN(FloatArray &answer, int isurf, const FloatArray &lcoords, const FEICellGeometry &cellgeo)
Evaluates the array of edge interpolation functions (shape functions) at given point.
Definition: feinterpol2d.C:181
virtual void boundaryGiveNodes(IntArray &answer, int boundary)
Gives the boundary nodes for requested boundary number.
Definition: feinterpol2d.C:139
double & at(int i)
Coefficient access function.
Definition: floatarray.h:131
virtual const FloatArray * giveVertexCoordinates(int i) const =0
Class representing a general abstraction for cell geometry.
Definition: feinterpol.h:62
virtual double giveCharacteristicLength(const FEICellGeometry &cellgeo) const
Returns a characteristic length of the geometry, typically a diagonal or edge length.
Definition: feinterpol2d.h:67
virtual void boundaryEdgeLocal2Global(FloatArray &answer, int boundary, const FloatArray &lcoords, const FEICellGeometry &cellgeo)
Maps the local boundary coordinates to global.
Definition: feinterpol2d.C:55
virtual void boundarySurfaceGiveNodes(IntArray &answer, int boundary)
Gives the boundary nodes for requested boundary number.
Definition: feinterpol2d.C:211
virtual double edgeGiveTransformationJacobian(int iedge, const FloatArray &lcoords, const FEICellGeometry &cellgeo)
Evaluates the edge Jacobian of transformation between local and global coordinates.
Definition: feinterpol2d.C:175
virtual double boundarySurfaceGiveTransformationJacobian(int isurf, const FloatArray &lcoords, const FEICellGeometry &cellgeo)
Evaluates the edge jacobian of transformation between local and global coordinates.
Definition: feinterpol2d.C:205
Class implementing an array of integers.
Definition: intarray.h:61
int & at(int i)
Coefficient access function.
Definition: intarray.h:103
virtual int giveNumberOfNodes() const
Returns the number of geometric nodes of the receiver.
Definition: feinterpol.h:486
virtual void computeLocalEdgeMapping(IntArray &edgeNodes, int iedge)=0
virtual double boundaryEvalNormal(FloatArray &answer, int boundary, const FloatArray &lcoords, const FEICellGeometry &cellgeo)
Evaluates the normal on the requested boundary.
Definition: feinterpol2d.C:149
virtual void giveJacobianMatrixAt(FloatMatrix &jacobianMatrix, const FloatArray &lcoords, const FEICellGeometry &cellgeo)
Gives the jacobian matrix at the local coordinates.
Definition: feinterpol2d.C:112
void computeEdgeMapping(IntArray &edgeNodes, IntArray &elemNodes, int iedge)
Definition: feinterpol2d.C:164
virtual double giveArea(const FEICellGeometry &cellgeo) const
Computes the exact area.
Definition: feinterpol2d.C:60
virtual double edgeEvalNormal(FloatArray &answer, int iedge, const FloatArray &lcoords, const FEICellGeometry &cellgeo)=0
Evaluates the normal on the given edge.
virtual void boundaryEvalN(FloatArray &answer, int boundary, const FloatArray &lcoords, const FEICellGeometry &cellgeo)
Evaluates the basis functions on the requested boundary.
Definition: feinterpol2d.C:144
#define OOFEM_ERROR(...)
Definition: error.h:61
virtual void boundaryEdgeEvalN(FloatArray &answer, int boundary, const FloatArray &lcoords, const FEICellGeometry &cellgeo)
Evaluates the basis functions on the requested boundary.
Definition: feinterpol2d.C:45
virtual double boundaryGiveTransformationJacobian(int boundary, const FloatArray &lcoords, const FEICellGeometry &cellgeo)
Evaluates the determinant of the transformation Jacobian on the requested boundary.
Definition: feinterpol2d.C:154
double at(int i, int j) const
Coefficient access function.
Definition: floatmatrix.h:176
void resize(int n)
Checks size of receiver towards requested bounds.
Definition: intarray.C:124
virtual void edgeEvalN(FloatArray &answer, int iedge, const FloatArray &lcoords, const FEICellGeometry &cellgeo)=0
Evaluates the array of edge interpolation functions (shape functions) at given point.
Class representing vector of real numbers.
Definition: floatarray.h:82
Implementation of matrix containing floating point numbers.
Definition: floatmatrix.h:94
double computeNorm() const
Computes the norm (or length) of the vector.
Definition: floatarray.C:840
void resize(int rows, int cols)
Checks size of receiver towards requested bounds.
Definition: floatmatrix.C:1358
void zero()
Zeroes all coefficients of receiver.
Definition: floatarray.C:658
virtual void boundarySurfaceLocal2global(FloatArray &answer, int isurf, const FloatArray &lcoords, const FEICellGeometry &cellgeo)
Evaluates edge global coordinates from given local ones.
Definition: feinterpol2d.C:199
virtual bool inside(const FloatArray &lcoords) const
Definition: feinterpol2d.C:134
void zero()
Zeroes all coefficient of receiver.
Definition: floatmatrix.C:1326
virtual double boundaryEdgeGiveTransformationJacobian(int boundary, const FloatArray &lcoords, const FEICellGeometry &cellgeo)
Evaluates the determinant of the transformation Jacobian on the requested boundary.
Definition: feinterpol2d.C:50
virtual void boundaryEdgeGiveNodes(IntArray &answer, int boundary)
Gives the boundary nodes for requested boundary number.
Definition: feinterpol2d.C:40
virtual void boundarySurfaceEvaldNdx(FloatMatrix &answer, int isurf, const FloatArray &lcoords, const FEICellGeometry &cellgeo)
Evaluates the matrix of derivatives of edge interpolation functions (shape functions) at given point...
Definition: feinterpol2d.C:186
int giveSize() const
Definition: intarray.h:203
the oofem namespace is to define a context or scope in which all oofem names are defined.
virtual void boundaryLocal2Global(FloatArray &answer, int boundary, const FloatArray &lcoords, const FEICellGeometry &cellgeo)
Maps the local boundary coordinates to global.
Definition: feinterpol2d.C:159
int giveNumberOfRows() const
Returns number of rows of receiver.
Definition: floatmatrix.h:156
#define OOFEM_WARNING(...)
Definition: error.h:62
virtual int global2local(FloatArray &answer, const FloatArray &gcoords, const FEICellGeometry &cellgeo)
Default implementation using Newton&#39;s method to find the local coordinates.
Definition: feinterpol2d.C:68
void add(const FloatArray &src)
Adds array src to receiver.
Definition: floatarray.C:156
virtual double evaldNdx(FloatMatrix &answer, const FloatArray &lcoords, const FEICellGeometry &cellgeo)=0
Evaluates the matrix of derivatives of interpolation functions (shape functions) at given point...
virtual void local2global(FloatArray &answer, const FloatArray &lcoords, const FEICellGeometry &cellgeo)=0
Evaluates global coordinates from given local ones.
void resize(int s)
Resizes receiver towards requested size.
Definition: floatarray.C:631

This page is part of the OOFEM documentation. Copyright (c) 2011 Borek Patzak
Project e-mail: info@oofem.org
Generated at Tue Jan 2 2018 20:07:28 for OOFEM by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2011