OOFEM  2.4
OOFEM.org - Object Oriented Finite Element Solver
AbaqusUserElement.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 "AbaqusUserElement.h"
36 #include "gausspoint.h"
37 #include "classfactory.h"
38 #include "dynamicinputrecord.h"
39 #include "dofmanager.h"
40 #include "node.h"
41 
42 #ifdef _WIN32 //_MSC_VER and __MINGW32__ included
43  #include <Windows.h>
44 #else
45  #include <dlfcn.h>
46 #endif
47 
48 #include <cstring>
49 
50 namespace oofem {
51 REGISTER_Element(AbaqusUserElement);
52 
53 
55  NLStructuralElement(n, d), uelobj(NULL), hasTangentFlag(false), uel(NULL)
56 {}
57 
59 {
60 #ifdef _WIN32
61  if ( this->uelobj ) {
62  FreeLibrary( ( HMODULE ) this->uelobj );
63  }
64 #else
65  if ( this->uelobj ) {
66  dlclose(this->uelobj);
67  }
68 #endif
69 }
70 
71 
73 {
74  IRResultType result; // Required by IR_GIVE_FIELD macro
75 
77  if ( result != IRRT_OK ) {
78  return result;
79  }
80 
82 
83  // necessary to prevent an array dimension error in Init
85 
88  if ( this->numSvars < 0 ) {
89  OOFEM_ERROR("'numsvars' field has an invalid value");
90  }
93  if ( this->jtype < 0 ) {
94  OOFEM_ERROR("'type' has an invalid value");
95  }
97 
98 #if 0
99  uelname = "uel";
101 #endif
102 
103 #ifdef _WIN32
104  this->uelobj = ( void * ) LoadLibrary( filename.c_str() );
105  if ( !this->uelobj ) {
106  OOFEM_ERROR( "couldn't load \"%s\",\ndlerror: %s", filename.c_str() );
107  }
108 
109  * ( FARPROC * ) ( & this->uel ) = GetProcAddress( ( HMODULE ) this->uelobj, "uel_" ); //works for MinGW 32bit
110  if ( !this->uel ) {
111  // char *dlresult = GetLastError();
112  DWORD dlresult = GetLastError(); //works for MinGW 32bit
113  OOFEM_ERROR("couldn't load symbol uel,\nerror: %s\n", dlresult);
114  }
115 #else
116  this->uelobj = dlopen(filename.c_str(), RTLD_NOW);
117  if ( !this->uelobj ) {
118  OOFEM_ERROR( "couldn't load \"%s\",\ndlerror: %s", filename.c_str(), dlerror() );
119  }
120 
121  * ( void ** ) ( & this->uel ) = dlsym(this->uelobj, "uel_");
122  char *dlresult = dlerror();
123  if ( dlresult ) {
124  OOFEM_ERROR("couldn't load symbol uel,\ndlerror: %s\n", dlresult);
125  }
126 #endif
127 
128  return IRRT_OK;
129 }
130 
131 
133 {
135 
136  this->ndofel = this->numberOfDofMans * this->nCoords;
137  this->mlvarx = this->ndofel;
138  this->nrhs = 2;
139  this->rhs.resize(this->ndofel, this->nrhs);
140  this->amatrx.resize(this->ndofel, this->ndofel);
141  this->svars.resize(this->numSvars);
142  this->lFlags.resize(5);
143  this->predef.resize( this->npredef * this->numberOfDofMans * 2 );
144  this->energy.resize(8);
145  this->U.resize(this->ndofel);
146  this->V.resize(this->ndofel);
147  this->A.resize(this->ndofel);
148  this->DU.resize(this->ndofel, this->nrhs);
149 
150  if ( !this->coords.isNotEmpty() ) {
151  this->coords.resize(this->numberOfDofMans, this->mcrd);
152  for ( int j = 1; j <= numberOfDofMans; j++ ) {
153  Node *dm = this->giveNode(j);
154  for ( int i = 1; i <= mcrd; i++ ) {
155  this->coords.at(i, j) = dm->giveCoordinate(i);
156  }
157  }
158  }
159 }
160 
161 
163 {
165 
172 }
173 
175 {
176  return NULL;
177 }
178 
180 {
181  answer = this->dofs;
182 }
183 
185 {
186  if ( !hasTangent() ) {
187  // use uel to calculate the tangent
188  FloatArray forces;
189  giveInternalForcesVector(forces, tStep, U, DU, 0);
190  }
191  // give tangent
192  answer = giveTempTangent();
193  // add stuff to behave differently if mUseNumericalTangent is set?
194 }
195 
197 {
199  svars = tempSvars;
200  amatrx = tempAmatrx;
201  rhs = tempRHS;
202  hasTangentFlag = false;
203 }
204 
206 {
207  FloatArray tmp;
208  this->giveInternalForcesVector(tmp, tStep, 0);
209 }
210 
211 void AbaqusUserElement :: giveInternalForcesVector(FloatArray &answer, TimeStep *tStep, int useUpdatedGpRecord)
212 {
213  // init U vector
214  this->computeVectorOf(VM_Total, tStep, U);
215  FloatArray tempIntVect;
216  // init DU vector
217  computeVectorOf(VM_Incremental, tStep, tempIntVect);
218  this->giveDomain()->giveClassName();
219  DU.zero();
220  DU.setColumn(tempIntVect, 1);
221  //this->computeVectorOf(VM_Total, tStep, DU);
222  this->giveInternalForcesVector(answer, tStep, U, DU, useUpdatedGpRecord);
223 }
224 
226  FloatArray &U, FloatMatrix &DU, int useUpdatedGpRecord)
227 {
228  if ( useUpdatedGpRecord ) {
229  this->rhs.copyColumn(answer, 1);
230  } else {
231  this->lFlags.at(1) = 1; // 1 based access
232  this->lFlags.at(3) = 1; // 1 based access
233  this->lFlags.at(4) = 0; // 1 based access
234 
235  int nprops = props.giveSize();
236  int njprops = jprops.giveSize();
237 
238  FloatMatrix loc_rhs(this->ndofel, this->nrhs);
239  FloatMatrix loc_amatrx(this->ndofel, this->ndofel);
240  FloatArray loc_svars = this->giveStateVector();
241 
242  //this->getSvars();
243  double period = 0., pnewdt = 0.;
244  double dtime = tStep->giveTimeIncrement();
245  double time[] = {tStep->giveTargetTime() - dtime, tStep->giveTargetTime()};
246  this->uel(
247  loc_rhs.givePointer(),
248  loc_amatrx.givePointer(),
249  loc_svars.givePointer(),
251  & ndofel,
252  & nrhs,
253  & numSvars,
254  props.givePointer(),
255  & nprops,
257  & mcrd,
258  & this->numberOfDofMans,
259  U.givePointer(),
260  DU.givePointer(),
261  V.givePointer(),
262  A.givePointer(),
263  & jtype,
264  time,
265  & dtime,
266  & kstep,
267  & kinc,
268  & ( this->number ),
269  params,
270  & ndLoad,
271  jdltype,
274  & npredef,
276  & mlvarx,
278  & mdLoad,
279  & pnewdt,
281  & njprops,
282  & period);
283  //FloatArray vout;
284  //vout.resize(12);
285  //for (int i = 1; i <= 3; i++)
286  //{
287  // vout.at(i) = rhs.at(i, 1);
288  // vout.at(i+6) = rhs.at(i+3, 1);
289  //}
290  //answer = vout;
291  //this->rhs.copyColumn(answer, 1);
292  //answer.negated();
293  loc_rhs.negated(); //really needed???
294  loc_rhs.copyColumn(answer, 1);
295  letTempRhsBe(loc_rhs);
296  letTempTangentBe(loc_amatrx);
297  letTempSvarsBe(loc_svars);
298  }
299 }
300 
301 
302 void
303 AbaqusUserElement :: computeConsistentMassMatrix(FloatMatrix &answer, TimeStep *tStep, double &mass, const double *ipDensity)
304 {
305  answer.resize(ndofel, ndofel);
306  answer.zero();
307 }
308 } // namespace oofem
void(* uel)(double *rhs, double *amatrx, double *svars, double energy[8], int *ndofel, int *nrhs, int *nsvars, double *props, int *nprops, double *coords, int *mcrd, int *nnode, double *u, double *du, double *v, double *a, int *jtype, double time[2], double *dtime, int *kstep, int *kinc, int *jelem, double params[3], int *ndload, int *jdltyp, double *adlmag, double *predef, int *npredef, int *lflags, int *mvarx, double *ddlmag, int *mdload, double *pnewdt, int *jprops, int *njprop, double *period)
Pointer to the dynamically loaded uel-function (translated to C)
void setField(int item, InputFieldType id)
virtual void postInitialize()
Performs post initialization steps.
Definition: element.C:752
IntArray dofManArray
Array containing dofmanager numbers.
Definition: element.h:151
int number
Component number.
Definition: femcmpnn.h:80
virtual const FloatMatrix & giveTempTangent()
virtual void giveInternalForcesVector(FloatArray &answer, TimeStep *tStep, int useUpdatedGpRecord=0)
Evaluates nodal representation of real internal forces.
Class and object Domain.
Definition: domain.h:115
void computeVectorOf(ValueModeType u, TimeStep *tStep, FloatArray &answer)
Returns local vector of unknowns.
Definition: element.C:86
Abstract base class for "structural" finite elements with geometrical nonlinearities.
std::string filename
File containing the uel function.
virtual void postInitialize()
Performs post initialization steps.
FloatArray props
Element properties.
virtual void updateInternalState(TimeStep *tStep)
Updates element state after equilibrium in time step has been reached.
virtual FloatArray & letTempSvarsBe(FloatArray &src)
#define _IFT_AbaqusUserElement_dofs
const char * giveClassName() const
Returns class name of the receiver.
Definition: domain.h:688
double giveTargetTime()
Returns target time.
Definition: timestep.h:146
void negated()
Changes sign of receiver values.
Definition: floatmatrix.C:1605
const int * givePointer() const
Breaks encapsulation.
Definition: intarray.h:336
virtual IRResultType initializeFrom(InputRecord *ir)
Initializes receiver according to object description stored in input record.
const double * givePointer() const
Exposes the internal values of the matrix.
Definition: floatmatrix.h:558
virtual void giveInputRecord(DynamicInputRecord &input)
Setups the input record string of receiver.
virtual double giveCoordinate(int i)
Definition: node.C:82
int numSvars
Number of status variables.
Class implementing an array of integers.
Definition: intarray.h:61
int & at(int i)
Coefficient access function.
Definition: intarray.h:103
MatResponseMode
Describes the character of characteristic material matrix.
AbaqusUserElement(int n, Domain *d)
Constructor.
#define _IFT_AbaqusUserElement_name
virtual Interface * giveInterface(InterfaceType it)
Interface requesting service.
double giveTimeIncrement()
Returns solution step associated time increment.
Definition: timestep.h:150
bool isNotEmpty() const
Tests for empty matrix.
Definition: floatmatrix.h:162
#define _IFT_AbaqusUserElement_properties
virtual void giveDofManDofIDMask(int inode, IntArray &answer) const
Returns dofmanager dof mask for node.
void * uelobj
Dynamically loaded uel.
#define _IFT_AbaqusUserElement_userElement
FloatMatrix amatrx
Element amatrx.
#define OOFEM_ERROR(...)
Definition: error.h:61
REGISTER_Element(LSpace)
FloatArray U
Inputs to element routines. Velocity and Acceleration currently ignored.
virtual void letTempTangentBe(FloatMatrix &src)
virtual void computeConsistentMassMatrix(FloatMatrix &answer, TimeStep *tStep, double &mass, const double *ipDensity=NULL)
Computes consistent mass matrix of receiver using numerical integration over element volume...
int nCoords
Coord transf.
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
#define _IFT_AbaqusUserElement_numsvars
virtual ~AbaqusUserElement()
Destructor.
virtual void updateYourself(TimeStep *tStep)
Updates element state after equilibrium in time step has been reached.
bool hasTangentFlag
Keeps track of whether the tangent has been obtained already.
Class representing vector of real numbers.
Definition: floatarray.h:82
virtual void computeStiffnessMatrix(FloatMatrix &answer, MatResponseMode rMode, TimeStep *tStep)
Computes the stiffness matrix of receiver.
Implementation of matrix containing floating point numbers.
Definition: floatmatrix.h:94
#define _IFT_AbaqusUserElement_type
IRResultType
Type defining the return values of InputRecord reading operations.
Definition: irresulttype.h:47
virtual void updateYourself(TimeStep *tStep)
Updates element state after equilibrium in time step has been reached.
void resize(int rows, int cols)
Checks size of receiver towards requested bounds.
Definition: floatmatrix.C:1358
Class representing the general Input Record.
Definition: inputrecord.h:101
Class Interface.
Definition: interface.h:82
void copyColumn(FloatArray &dest, int c) const
Fetches the values from the specified column.
Definition: floatmatrix.C:662
void setColumn(const FloatArray &src, int c)
Sets the values of the matrix in specified column.
Definition: floatmatrix.C:648
Class representing the a dynamic Input Record.
FloatArray svars
Status variables.
const double * givePointer() const
Gives the pointer to the raw data, breaking encapsulation.
Definition: floatarray.h:469
void zero()
Zeroes all coefficient of receiver.
Definition: floatmatrix.C:1326
Domain * giveDomain() const
Definition: femcmpnn.h:100
InterfaceType
Enumerative type, used to identify interface type.
Definition: interfacetype.h:43
#define IR_GIVE_OPTIONAL_FIELD(__ir, __value, __id)
Macro facilitating the use of input record reading methods.
Definition: inputrecord.h:78
virtual FloatMatrix & letTempRhsBe(FloatMatrix &src)
int giveSize() const
Definition: intarray.h:203
int giveSize() const
Returns the size of receiver.
Definition: floatarray.h:218
the oofem namespace is to define a context or scope in which all oofem names are defined.
virtual const FloatArray & giveStateVector() const
Class implementing node in finite element mesh.
Definition: node.h:87
#define IR_GIVE_FIELD(__ir, __value, __id)
Macro facilitating the use of input record reading methods.
Definition: inputrecord.h:69
Node * giveNode(int i) const
Returns reference to the i-th node of element.
Definition: element.h:610
virtual void giveInputRecord(DynamicInputRecord &input)
Setups the input record string of receiver.
virtual IRResultType initializeFrom(InputRecord *ir)
Initializes receiver according to object description stored in input record.
#define _IFT_AbaqusUserElement_numcoords
Class representing solution step.
Definition: timestep.h:80
int numberOfDofMans
Number of dofmanagers.
Definition: element.h:149
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:27 for OOFEM by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2011