OOFEM  2.4
OOFEM.org - Object Oriented Finite Element Solver
matforceevaluator.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 "matforceevaluator.h"
36 #include "xfem/tipinfo.h"
37 #include "domain.h"
38 #include "spatiallocalizer.h"
40 #include "dofmanager.h"
41 #include "integrationrule.h"
42 #include "feinterpol.h"
43 #include "gausspoint.h"
45 
46 #include <fstream>
47 #include <set>
48 
49 namespace oofem {
50 
52 {
53 }
54 
56 {
57 }
58 
59 void MaterialForceEvaluator::computeMaterialForce(FloatArray &oMatForce, Domain &iDomain, const TipInfo &iTipInfo, TimeStep *tStep, const double &iRadius)
60 {
61  oMatForce.resize(2);
62  oMatForce.clear();
63 
64 
65  // Fetch elements within a specified volume around the crack tip
66  SpatialLocalizer *localizer = iDomain.giveSpatialLocalizer();
67  IntArray elList;
68  localizer->giveAllElementsWithNodesWithinBox(elList, iTipInfo.mGlobalCoord, iRadius);
69 
70  if ( elList.isEmpty() ) {
71  FloatArray lcoords, closest;
72  Element *closestEl = localizer->giveElementClosestToPoint(lcoords, closest, iTipInfo.mGlobalCoord);
73 
74  if ( closestEl != NULL ) {
75  if ( closest.distance(iTipInfo.mGlobalCoord) < 1.0e-9 ) {
76  int elInd = closestEl->giveGlobalNumber();
77  int elPlaceInArray = iDomain.giveElementPlaceInArray(elInd);
78  elList.insertSortedOnce( elPlaceInArray );
79  }
80  } else {
81  printf("Could not find closest element.\n");
82  }
83  }
84 
85  // Compute phi in nodes
86  std::unordered_map<int, double> weightInNodes;
87 
88  for ( int elIndex : elList ) {
89 // int elPlaceInArray = iDomain.giveElementPlaceInArray(elIndex);
90  Element *el = iDomain.giveElement(elIndex);
91 
92  const IntArray &elNodes = el->giveDofManArray();
93  for ( int nodeInd : elNodes ) {
94  DofManager *dMan = iDomain.giveDofManager(nodeInd);
95 
96  weightInNodes[nodeInd] = computeWeightFunctionInPoint( *(dMan->giveCoordinates()), iTipInfo.mGlobalCoord, iRadius);
97  }
98 
99  }
100 
101  // Loop over elements and Gauss points
102  for( int elIndex : elList ) {
103 // int elPlaceInArray = iDomain.giveElementPlaceInArray(elIndex);
104  NLStructuralElement *el = dynamic_cast<NLStructuralElement*>( iDomain.giveElement(elIndex) );
105 
106  if ( el == NULL ) {
107  OOFEM_ERROR("Could not cast to NLStructuralElement.")
108  }
109 
110 // const IntArray &elNodes = el->giveDofManArray();
111 
112  for ( auto &gp : *(el->giveDefaultIntegrationRulePtr()) ) {
113 
114  FloatArray gradWeight;
115  const FloatArray &pos = gp->giveGlobalCoordinates();
116 
117 #if 0
118  // Compute grad(phi)
119  FloatMatrix dNdx;
120  FEInterpolation *interp = el->giveInterpolation();
121  const FEIElementGeometryWrapper geomWrapper(el);
122  interp->evaldNdx(dNdx, gp->giveNaturalCoordinates(), geomWrapper);
123 
124  FloatArray weightInElNodes;
125 
126  weightInElNodes.resize( elNodes.giveSize() );
127  for(int i = 0; i < weightInElNodes.giveSize(); i++) {
128  weightInElNodes[i] = weightInNodes[elNodes[i]];
129  }
130 
131  gradWeight.beTProductOf(dNdx, weightInElNodes);
132 #else
133  FloatArray q;
134 // q.beDifferenceOf(pos, iTipInfo.mGlobalCoord);
135 // printf("q: "); q.printYourself();
136  q = {pos[0]-iTipInfo.mGlobalCoord[0],pos[1]-iTipInfo.mGlobalCoord[1]};
137 
138  gradWeight.beScaled(-1.0/(iRadius*q.computeNorm()),q);
139 #endif
140 
141  // Compute Eshelby stress
142  StructuralCrossSection *cs = dynamic_cast<StructuralCrossSection*>( gp->giveCrossSection() );
143  if (cs != NULL) {
144 
145  FloatArray Fv;
146  el->computeDeformationGradientVector(Fv, gp, tStep);
147 
148  FloatArray eshelbyStressV;
149  cs->giveEshelbyStresses(eshelbyStressV, gp, Fv, tStep);
150 
151  FloatArray fullEshelbyStressV;
152  StructuralMaterial :: giveFullVectorForm( fullEshelbyStressV, eshelbyStressV, _PlaneStrain );
153 
154  FloatMatrix eshelbyStress3D;
155  eshelbyStress3D.beMatrixForm(fullEshelbyStressV);
156 
157  FloatMatrix eshelbyStress2D;
158  eshelbyStress2D.beSubMatrixOf(eshelbyStress3D, 1, 2, 1, 2);
159 
160 // printf("eshelbyStress2D: "); eshelbyStress2D.printYourself();
161 
162  if( computeWeightFunctionInPoint( pos, iTipInfo.mGlobalCoord, iRadius) > 0.0 ) {
163  // Add contribution
164  FloatArray contrib(2);
165  contrib.beProductOf(eshelbyStress2D, gradWeight);
166  contrib.times( -el->computeVolumeAround(gp) );
167 
168 // if( contrib.computeNorm() > 1.0e10 ) {
169 // printf("Fv: "); Fv.printYourself();
170 // }
171 
172  oMatForce.add(contrib);
173  }
174  }
175  }
176 
177  }
178 
179 // printf("oMatForce: "); oMatForce.printYourself();
180 
181 }
182 
183 double MaterialForceEvaluator::computeWeightFunctionInPoint(const FloatArray &iCoord, const FloatArray &iTipCoord, const double &iRadius) const
184 {
185  double weight = 0.0;
186 
187  double r = iTipCoord.distance(iCoord);
188 
189 // if(r <= iRadius) {
190  weight = 1.0 - r/iRadius;
191 // }
192 
193 // printf("r: %e weight: %e\n", r, weight);
194 
195  return weight;
196 }
197 
198 } /* namespace oofem */
The base class for all spatial localizers.
Class and object Domain.
Definition: domain.h:115
virtual IntegrationRule * giveDefaultIntegrationRulePtr()
Access method for default integration rule.
Definition: element.h:822
Abstract base class for "structural" finite elements with geometrical nonlinearities.
bool isEmpty() const
Checks if receiver is empty (i.e., zero sized).
Definition: intarray.h:208
void beSubMatrixOf(const FloatMatrix &src, int topRow, int bottomRow, int topCol, int bottomCol)
Assigns to the receiver the sub-matrix of another matrix.
Definition: floatmatrix.C:962
int giveGlobalNumber() const
Definition: element.h:1059
TipInfo gathers useful information about a crack tip, like its position and tangent direction...
Definition: tipinfo.h:24
void clear()
Clears receiver (zero size).
Definition: floatarray.h:206
bool insertSortedOnce(int value, int allocChunk=0)
Inserts given value into a receiver, which is assumed to be sorted.
Definition: intarray.C:360
virtual void giveAllElementsWithNodesWithinBox(elementContainerType &elemSet, const FloatArray &coords, const double radius)
Returns container (set) of all domain elements having node within given box.
virtual FloatArray * giveCoordinates()
Definition: dofmanager.h:382
Abstract base class for all finite elements.
Definition: element.h:145
Base class for dof managers.
Definition: dofmanager.h:113
Class implementing an array of integers.
Definition: intarray.h:61
virtual FEInterpolation * giveInterpolation() const
Definition: element.h:629
void beMatrixForm(const FloatArray &aArray)
Definition: floatmatrix.C:1657
double distance(const FloatArray &x) const
Computes the distance between position represented by receiver and position given as parameter...
Definition: floatarray.C:489
Class representing a general abstraction for finite element interpolation class.
Definition: feinterpol.h:132
void beScaled(double s, const FloatArray &b)
Sets receiver to be .
Definition: floatarray.C:146
virtual double computeVolumeAround(GaussPoint *gp)
Returns volume related to given integration point.
Definition: element.h:518
const IntArray & giveDofManArray() const
Definition: element.h:592
static void giveFullVectorForm(FloatArray &answer, const FloatArray &strainVector, MaterialMode matMode)
Converts the reduced symmetric Voigt vector (2nd order tensor) to full form.
double computeWeightFunctionInPoint(const FloatArray &iCoord, const FloatArray &iTipCoord, const double &iRadius) const
Element * giveElement(int n)
Service for accessing particular domain fe element.
Definition: domain.C:160
#define OOFEM_ERROR(...)
Definition: error.h:61
SpatialLocalizer * giveSpatialLocalizer()
Returns receiver&#39;s associated spatial localizer.
Definition: domain.C:1184
Wrapper around element definition to provide FEICellGeometry interface.
Definition: feinterpol.h:95
void beProductOf(const FloatMatrix &aMatrix, const FloatArray &anArray)
Receiver becomes the result of the product of aMatrix and anArray.
Definition: floatarray.C:676
void beTProductOf(const FloatMatrix &aMatrix, const FloatArray &anArray)
Receiver becomes the result of the product of aMatrix^T and anArray.
Definition: floatarray.C:708
Class representing vector of real numbers.
Definition: floatarray.h:82
virtual void computeDeformationGradientVector(FloatArray &answer, GaussPoint *gp, TimeStep *tStep)
Computes the deformation gradient in Voigt form at integration point ip and at time step tStep...
Implementation of matrix containing floating point numbers.
Definition: floatmatrix.h:94
void computeMaterialForce(FloatArray &oMatForce, Domain &iDomain, const TipInfo &iTipInfo, TimeStep *tStep, const double &iRadius)
double computeNorm() const
Computes the norm (or length) of the vector.
Definition: floatarray.C:840
virtual Element * giveElementClosestToPoint(FloatArray &lcoords, FloatArray &closest, const FloatArray &coords, int region=0)=0
Returns the element closest to a given point.
void times(double s)
Multiplies receiver with scalar.
Definition: floatarray.C:818
int giveElementPlaceInArray(int iGlobalElNum) const
Returns the array index of the element with global number iGlobalElNum, so that it can be fetched by ...
Definition: domain.C:183
virtual void giveEshelbyStresses(FloatArray &answer, GaussPoint *gp, const FloatArray &reducedvF, TimeStep *tStep)
Computes the Eshelby stress vector.
int giveSize() const
Returns the size of receiver.
Definition: floatarray.h:218
Abstract base class for all structural cross section models.
FloatArray mGlobalCoord
Definition: tipinfo.h:30
the oofem namespace is to define a context or scope in which all oofem names are defined.
DofManager * giveDofManager(int n)
Service for accessing particular domain dof manager.
Definition: domain.C:314
Class representing solution step.
Definition: timestep.h:80
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...
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:29 for OOFEM by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2011