OOFEM 3.0
Loading...
Searching...
No Matches
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 - 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
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
49namespace oofem {
50
54
58
59void 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 != nullptr ) {
75 if ( distance(closest, 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 == nullptr ) {
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 = Vec2(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 != nullptr) {
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
183double MaterialForceEvaluator::computeWeightFunctionInPoint(const FloatArray &iCoord, const FloatArray &iTipCoord, const double &iRadius) const
184{
185 double weight = 0.0;
186 double r = distance(iTipCoord, iCoord);
187// if(r <= iRadius) {
188 weight = 1.0 - r/iRadius;
189// }
190// printf("r: %e weight: %e\n", r, weight);
191 return weight;
192}
193
194} /* namespace oofem */
const FloatArray & giveCoordinates() const
Definition dofmanager.h:390
SpatialLocalizer * giveSpatialLocalizer()
Definition domain.C:1255
int giveElementPlaceInArray(int iGlobalElNum) const
Definition domain.C:188
DofManager * giveDofManager(int n)
Definition domain.C:317
Element * giveElement(int n)
Definition domain.C:165
int giveGlobalNumber() const
Definition element.h:1129
virtual FEInterpolation * giveInterpolation() const
Definition element.h:648
const IntArray & giveDofManArray() const
Definition element.h:611
virtual IntegrationRule * giveDefaultIntegrationRulePtr()
Definition element.h:886
virtual double computeVolumeAround(GaussPoint *gp)
Definition element.h:530
virtual double evaldNdx(FloatMatrix &answer, const FloatArray &lcoords, const FEICellGeometry &cellgeo) const =0
double computeNorm() const
Definition floatarray.C:861
void resize(Index s)
Definition floatarray.C:94
Index giveSize() const
Returns the size of receiver.
Definition floatarray.h:261
void beProductOf(const FloatMatrix &aMatrix, const FloatArray &anArray)
Definition floatarray.C:689
void beScaled(double s, const FloatArray &b)
Definition floatarray.C:208
void beTProductOf(const FloatMatrix &aMatrix, const FloatArray &anArray)
Definition floatarray.C:721
void add(const FloatArray &src)
Definition floatarray.C:218
void times(double s)
Definition floatarray.C:834
void beSubMatrixOf(const FloatMatrix &src, Index topRow, Index bottomRow, Index topCol, Index bottomCol)
void beMatrixForm(const FloatArray &aArray)
bool insertSortedOnce(int value, int allocChunk=0)
Definition intarray.C:309
bool isEmpty() const
Definition intarray.h:217
double computeWeightFunctionInPoint(const FloatArray &iCoord, const FloatArray &iTipCoord, const double &iRadius) const
void computeMaterialForce(FloatArray &oMatForce, Domain &iDomain, const TipInfo &iTipInfo, TimeStep *tStep, const double &iRadius)
virtual void computeDeformationGradientVector(FloatArray &answer, GaussPoint *gp, TimeStep *tStep)
virtual void giveAllElementsWithNodesWithinBox(elementContainerType &elemSet, const FloatArray &coords, const double radius)
virtual Element * giveElementClosestToPoint(FloatArray &lcoords, FloatArray &closest, const FloatArray &coords, int region=0)=0
virtual void giveEshelbyStresses(FloatArray &answer, GaussPoint *gp, const FloatArray &reducedvF, TimeStep *tStep)
FloatArray mGlobalCoord
Definition tipinfo.h:30
#define OOFEM_ERROR(...)
Definition error.h:79
static FloatArray Vec2(const double &a, const double &b)
Definition floatarray.h:606
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