OOFEM  2.4
OOFEM.org - Object Oriented Finite Element Solver
ncprincipalstress.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 "ncprincipalstress.h"
36 #include "error.h"
37 #include "xfem/enrichmentitem.h"
38 #include "domain.h"
39 #include "element.h"
40 #include "gausspoint.h"
41 
42 #include "Materials/structuralms.h"
44 
46 #include "xfem/xfemmanager.h"
52 #include "dynamicdatareader.h"
53 #include "dynamicinputrecord.h"
54 #include "geometry.h"
55 #include "classfactory.h"
56 #include "spatiallocalizer.h"
57 #include "crosssection.h"
58 
59 #include <memory>
60 
61 namespace oofem {
63 
65 NucleationCriterion(ipDomain),
66 mStressThreshold(0.0),
67 mInitialCrackLength(0.0),
68 mMatForceRadius(0.0),
69 mIncrementLength(0.0),
70 mCrackPropThreshold(0.0),
71 mCutOneEl(false),
72 mCrossSectionInd(2)
73 {
74 
75 }
76 
78 
79 }
80 
81 std::vector<std::unique_ptr<EnrichmentItem>> NCPrincipalStress::nucleateEnrichmentItems() {
82 
83 
86 
87  std::vector<std::unique_ptr<EnrichmentItem>> eiList;
88 
89  // Center coordinates of newly inserted cracks
90  std::vector<FloatArray> center_coord_inserted_cracks;
91 
92  // Loop over all elements and all bulk GP.
93  for(auto &el : mpDomain->giveElements() ) {
94 
95  int numIR = el->giveNumberOfIntegrationRules();
96 
97  int csNum = el->giveCrossSection()->giveNumber();
98 
99  if(csNum == mCrossSectionInd || true) {
100 
101  for(int irInd = 0; irInd < numIR; irInd++) {
102  IntegrationRule *ir = el->giveIntegrationRule(irInd);
103 
104 
105 
106  int numGP = ir->giveNumberOfIntegrationPoints();
107 
108  for(int gpInd = 0; gpInd < numGP; gpInd++) {
109  GaussPoint *gp = ir->getIntegrationPoint(gpInd);
110 
111  // int csNum = gp->giveCrossSection()->giveNumber();
112  // printf("csNum: %d\n", csNum);
113 
114 
116 
117  if(ms != NULL) {
118 
119  const FloatArray &stress = ms->giveTempStressVector();
120 
121  FloatArray principalVals;
122  FloatMatrix principalDirs;
123  StructuralMaterial::computePrincipalValDir(principalVals, principalDirs, stress, principal_stress);
124 
125  if(principalVals[0] > mStressThreshold) {
126 
127 
128 
129  // printf("\nFound GP with stress above threshold.\n");
130  // printf("principalVals: "); principalVals.printYourself();
131 
132  FloatArray crackNormal;
133  crackNormal.beColumnOf(principalDirs, 1);
134  // printf("crackNormal: "); crackNormal.printYourself();
135 
136  FloatArray crackTangent = {-crackNormal(1), crackNormal(0)};
137  crackTangent.normalize();
138  // printf("crackTangent: "); crackTangent.printYourself();
139 
140 
141 
142  // Create geometry
143  FloatArray pc = {gp->giveGlobalCoordinates()(0), gp->giveGlobalCoordinates()(1)};
144  // printf("Global coord: "); pc.printYourself();
145 
146 
147  FloatArray ps = pc;
148  ps.add(-0.5*mInitialCrackLength, crackTangent);
149 
150  FloatArray pe = pc;
151  pe.add(0.5*mInitialCrackLength, crackTangent);
152 
153  if(mCutOneEl) {
154  // If desired, ensure that the crack cuts exactly one element.
155  Line line(ps, pe);
156  std::vector<FloatArray> intersecPoints;
157  // line.computeIntersectionPoints(el.get(), intersecPoints);
158 
159  for ( int i = 1; i <= el->giveNumberOfDofManagers(); i++ ) {
160 // int n1 = i;
161 // int n2 = 0;
162 // if ( i < el->giveNumberOfDofManagers() ) {
163 // n2 = i + 1;
164 // } else {
165 // n2 = 1;
166 // }
167 
168  // const FloatArray &p1 = *(el->giveDofManager(n1)->giveCoordinates());
169  // const FloatArray &p2 = *(el->giveDofManager(n2)->giveCoordinates());
170 
171 
172  }
173 
174  // printf("intersecPoints.size(): %lu\n", intersecPoints.size());
175 
176  if(intersecPoints.size() == 2) {
177  ps = std::move(intersecPoints[0]);
178  pe = std::move(intersecPoints[1]);
179  }
180  else {
181  OOFEM_ERROR("intersecPoints.size() != 2")
182  }
183  }
184 
185  FloatArray points = {ps(0), ps(1), pc(0), pc(1), pe(0), pe(1)};
186 
187  // double diffX = 0.5*(ps(0) + pe(0)) - pc(0);
188  // printf("diffX: %e\n", diffX);
189 
190  // double diffY = 0.5*(ps(1) + pe(1)) - pc(1);
191  // printf("diffY: %e\n", diffY);
192 
193 
194  // TODO: Check if nucleation is allowed, by checking for already existing cracks close to the GP.
195  // Idea: Nucleation is not allowed if we are within an enriched element. In this way, branching is not
196  // completely prohibited, but we avoid initiating multiple similar cracks.
197  bool insertionAllowed = true;
198 
199  Element *el_s = octree->giveElementContainingPoint(ps);
200  if(el_s) {
201  if( xMan->isElementEnriched(el_s) ) {
202  insertionAllowed = false;
203  }
204  }
205 
206  Element *el_c = octree->giveElementContainingPoint(pc);
207  if(el_c) {
208  if( xMan->isElementEnriched(el_c) ) {
209  insertionAllowed = false;
210  }
211  }
212 
213  Element *el_e = octree->giveElementContainingPoint(pe);
214  if(el_e) {
215  if( xMan->isElementEnriched(el_e) ) {
216  insertionAllowed = false;
217  }
218  }
219 
220  for(const auto &x: center_coord_inserted_cracks) {
221  if( x.distance(pc) < 2.0*mInitialCrackLength) {
222  insertionAllowed = false;
223  break;
224  printf("Preventing insertion.\n");
225  }
226  }
227 
228  if(insertionAllowed) {
229  int n = xMan->giveNumberOfEnrichmentItems() + 1;
230  std::unique_ptr<Crack> crack(new Crack(n, xMan, mpDomain));
231 
232 
233  // Geometry
234  std::unique_ptr<BasicGeometry> geom = std::unique_ptr<BasicGeometry>(new PolygonLine());
235  geom->insertVertexBack(ps);
236  geom->insertVertexBack(pc);
237  geom->insertVertexBack(pe);
238  crack->setGeometry(std::move(geom));
239 
240  // Enrichment function
242  crack->setEnrichmentFunction(ef);
243 
244  // Enrichment fronts
245 // EnrichmentFront *efStart = new EnrFrontLinearBranchFuncOneEl();
247  crack->setEnrichmentFrontStart(efStart);
248 
249 // EnrichmentFront *efEnd = new EnrFrontLinearBranchFuncOneEl();
251  crack->setEnrichmentFrontEnd(efEnd);
252 
253 
254 
255 
257  // Propagation law
258 
259  // Options
260  // double radius = 0.5*mInitialCrackLength, angleInc = 10.0, incrementLength = 0.5*mInitialCrackLength, hoopStressThreshold = 0.0;
261  // bool useRadialBasisFunc = true;
262 
263  // PLHoopStressCirc *pl = new PLHoopStressCirc();
264  // pl->setRadius(radius);
265  // pl->setAngleInc(angleInc);
266  // pl->setIncrementLength(incrementLength);
267  // pl->setHoopStressThreshold(hoopStressThreshold);
268  // pl->setUseRadialBasisFunc(useRadialBasisFunc);
269 
270  // PLDoNothing *pl = new PLDoNothing();
271 
272  PLMaterialForce *pl = new PLMaterialForce();
275 // pl->setIncrementLength(0.25);
276 // pl->setCrackPropThreshold(0.25);
278 
279  crack->setPropagationLaw(pl);
280 
281  crack->updateDofIdPool();
282 
283  center_coord_inserted_cracks.push_back(pc);
284  eiList.push_back( std::unique_ptr<EnrichmentItem>(std::move(crack)) );
285 
286 // printf("Nucleating a crack in NCPrincipalStress::nucleateEnrichmentItems.\n");
287 // printf("el->giveGlobalNumber(): %d\n", el->giveGlobalNumber() );
288 
289  // We only introduce one crack per element in a single time step.
290  break;
291  }
292  }
293  }
294 
295  }
296  }
297  } // If correct csNum
298  }
299 
300 
301  return std::move( eiList );
302 }
303 
304 
306 
307  IRResultType result; // Required by IR_GIVE_FIELD macro
308 
310 // printf("mStressThreshold: %e\n", mStressThreshold);
311 
313 // printf("mInitialCrackLength: %e\n", mInitialCrackLength);
314 
316 // printf("mMatForceRadius: %e\n", mMatForceRadius);
317 
319 // printf("mIncrementLength: %e\n", mIncrementLength);
320 
322 // printf("mCrackPropThreshold: %e\n", mCrackPropThreshold);
323 
324 
326 }
327 
329 {
331 
332  ir->setRecordKeywordField( this->giveInputRecordName(), 1 );
333 
339 
341 
342  // Enrichment function
343  DynamicInputRecord *efRec = new DynamicInputRecord();
346 }
347 
348 } /* namespace oofem */
The base class for all spatial localizers.
#define _IFT_NCPrincipalStress_IncrementLength
void setField(int item, InputFieldType id)
#define _IFT_NCPrincipalStress_MatForceRadius
Class and object Domain.
Definition: domain.h:115
For computing principal stresses.
Class representing the implementation of a dynamic data reader for in-code use.
void setIncrementLength(const double &iIncrementLength)
This class implements a structural material status information.
Definition: structuralms.h:65
Abstract base class for all finite elements.
Definition: element.h:145
static void computePrincipalValDir(FloatArray &answer, FloatMatrix &dir, const FloatArray &s, stressStrainPrincMode mode)
Computes principal values and directions of stress or strain vector.
XfemManager * giveXfemManager()
Definition: domain.C:375
Abstract class representing global shape function Base class declares abstract interface common to al...
Abstract base class representing integration rule.
virtual IRResultType initializeFrom(InputRecord *ir)
void beColumnOf(const FloatMatrix &mat, int col)
Reciever will be set to a given column in a matrix.
Definition: floatarray.C:1114
int giveNumberOfEnrichmentItems() const
Definition: xfemmanager.h:185
Crack.
Definition: crack.h:54
#define _IFT_NCPrincipalStress_StressThreshold
#define OOFEM_ERROR(...)
Definition: error.h:61
virtual void appendInputRecords(DynamicDataReader &oDR)
REGISTER_NucleationCriterion(NCPrincipalStrain)
#define _IFT_NCPrincipalStress_CrackPropThreshold
Class EnrichmentFront: describes the edge or tip of an XFEM enrichment.
virtual const char * giveInputRecordName() const
SpatialLocalizer * giveSpatialLocalizer()
Returns receiver&#39;s associated spatial localizer.
Definition: domain.C:1184
virtual void giveInputRecord(DynamicInputRecord &input)
Setups the input record string of receiver.
virtual IRResultType initializeFrom(InputRecord *ir)
#define _IFT_NCPrincipalStress_InitialCrackLength
virtual Element * giveElementContainingPoint(const FloatArray &coords, const IntArray *regionList=NULL)=0
Returns the element, containing given point and belonging to one of the region in region list...
const FloatArray & giveGlobalCoordinates()
Definition: gausspoint.h:160
Class representing vector of real numbers.
Definition: floatarray.h:82
void setCrackPropThreshold(const double &iCrackPropThreshold)
Implementation of matrix containing floating point numbers.
Definition: floatmatrix.h:94
This class manages the xfem part.
Definition: xfemmanager.h:109
IRResultType
Type defining the return values of InputRecord reading operations.
Definition: irresulttype.h:47
GaussPoint * getIntegrationPoint(int n)
Access particular integration point of receiver.
IntegrationPointStatus * giveMaterialStatus()
Returns reference to associated material status (NULL if not defined).
Definition: gausspoint.h:205
Class representing the general Input Record.
Definition: inputrecord.h:101
bool isElementEnriched(const Element *elem)
Definition: xfemmanager.C:104
Class representing Heaviside EnrichmentFunction.
int giveNumberOfIntegrationPoints() const
Returns number of integration points of receiver.
Class representing the a dynamic Input Record.
int mCrossSectionInd
Index of the cross section that the nucleation criterion applies to.
void setRecordKeywordField(std::string keyword, int number)
std::vector< std::unique_ptr< Element > > & giveElements()
Definition: domain.h:279
bool mCutOneEl
If the initiated crack should cut exactly one element.
const FloatArray & giveTempStressVector() const
Returns the const pointer to receiver&#39;s temporary stress vector.
Definition: structuralms.h:117
the oofem namespace is to define a context or scope in which all oofem names are defined.
#define IR_GIVE_FIELD(__ir, __value, __id)
Macro facilitating the use of input record reading methods.
Definition: inputrecord.h:69
EnrichmentFunction * mpEnrichmentFunc
double normalize()
Normalizes receiver.
Definition: floatarray.C:828
virtual std::vector< std::unique_ptr< EnrichmentItem > > nucleateEnrichmentItems()
void setRadius(const double &iRadius)
Class representing integration point in finite element program.
Definition: gausspoint.h:93
void insertInputRecord(InputRecordType type, InputRecord *record)
Main purpose of this class it the possibility to add new input records in code.
void add(const FloatArray &src)
Adds array src to receiver.
Definition: floatarray.C:156
Propagation law that propagates the crack in the direction of the material force. ...

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:30 for OOFEM by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2011