Sie sind auf Seite 1von 16

On-demand numerical code generation

and
finite element analysis
AceGen
Multi-language, Multi-
environment Numerical Code
Generation
AceFEM
The Mathematica Finite
Element Environment

AceShare
Finite Element File
Sharing
1 J. KORELC, UNIVERSITY OF LJUBLJANA
AceGen
Multi-language, Multi-
environment Numerical Code
Generation

Key features:
• simultaneous derivation of expressions, global optimization of
expressions and generation of program structure
• automatic selection of the appropriate intermediate variables
• forward and backward mode of automatic differentiation technique
• multi-language code generation (Fortran/Fortran90, C, Mathematica©
language, Matlab© language),
• the generated codes are higly efficient and portable
• symbolic derivation of the characteristic quantities needed in numerical
procedures (e.g. gradients, tangent operators, sensitivity vectors, etc.)
• automatic interface to general environments (MathLink connection to
Mathematica, Matlab©) and specialized FEM environments
(AceFEM©, FEAP©, ELFEN©, ABAQUS©,...)
2 J. KORELC, UNIVERSITY OF LJUBLJANA
AceGen - highlights

AceGen
- interface code
- symbolic input
- initialization
- problem formulation
- numerical integration
- user subroutines
-…

numerical user subroutines

C Mathematica FORTRAN MATLAB

ELFEN FEAP
MathLink AceFEM
MATLAB
CDriver MDriver ABAQUS

….
Numerical environments
3 J. KORELC, UNIVERSITY OF LJUBLJANA
AceGen - highlights
Simultaneous optimizations of expressions:

{ v} = ⎧⎨
12 EI v1 L 2 v 2 L ⎫ vector of
Original matrix − − ⎬
(input for code generator): ⎩ L
3
2 3 ⎭ auxiliary
variables
⎡ 12 EI 6 EI 12 EI 6 EI ⎤ internal
⎢ L3 − 2 − 2 ⎥
L L3 L data base
⎢ 6 EI 4 EI 6 EI 2 EI ⎥
⎢− 2 ⎥
[ K0 ] = ⎢⎢ 12 EI
L L
6 EI
L2
12 EI
L ⎥
6 EI ⎥
user AceGen
⎢ L3 L2 L3 L2 ⎥
⎢ 6 EI 2 EI 6 EI 4 EI ⎥ Mathematic
⎢− 2 ⎥ a
⎣ L L L2 L ⎦
⎡ v1 v2 − v1 v2 ⎤
⎢ v3 ⎥
⎢ v2 v3 − v2 ⎥
[ K S ] = ⎢− v1 − v2 v1
2 ⎥
− v2 ⎥

• heuristic procedures ⎢v v3
− v2 v3 ⎥
⎢⎣ 2 2 ⎥⎦
• random signatures of Result is simplified matrix, expressed with the
expressions new auxiliary variables

4 J. KORELC, UNIVERSITY OF LJUBLJANA


AceGen - highlights
Simultaneous generation of control structures:
H∗Initialization∗L
SMSInitialize @"test", "Language" −> • "If" construct
"C++", "Mode" → "Optimal"D;
SMSIf@x <= 0D;
H∗Definition of a new subroutine∗L
f • x2; $V[i,1]
SMSModule@"Test",
Real@x$$, f$$, dfdx$$ DD; SMSElse@D;
H∗Numeric−symbolic interface∗L
f § Sin@xD; $V[i,2]
x ¢ SMSReal@x$$D; SMSEndIf@fD;
H∗Derivation of the problem∗L fictive variable
α ¢ Cos@xD;
$V[i,3]
SMSIf@SMSAbs@αD > 10−10D;
f • Sin@2 α2D ê α;
SMSElse@D;
f § SMSFreeze@Limit@
Sin@2 α2D ê α, α → 0D, "Dependency", • "Do" construct
88α, Limit@D@Sin@2 α2D ê α, αD êê
Evaluate, α → 0D<<D;
SMSEndIf@True, fD;
H∗ Automatic differentiation∗L
f • 1;
dfdx £ SMSD@f, xD; SMSDo@i, 1, n, 1, fD;
H∗Symbolic−numeric interafce∗L f § f + xi;
SMSExport@dfdx, dfdx$$D;
SMSEndDo@fD;
H∗Code generation∗L
SMSWrite@D;
5 J. KORELC, UNIVERSITY OF LJUBLJANA
AceGen - highlights
Automatic differentiation technique (AD):

– differentiation of the whole program

• Reverse mode / Forward mode

• Enhancements with respect to the standard AD technique:


– AD procedure can be initiated at any time and at any point of
derivation of the formulas and as many times as required

– AD as code-to-code translator is replaced by the method that


consistently extends current code rather than produce a new one

– the results of all previous uses of AD are accounted for when AD is


used several times inside the same subroutine

– exceptions handling mechanisms

6 J. KORELC, UNIVERSITY OF LJUBLJANA


AceGen - highlights
Multi-language code generation with AceGen:
2. Symbolic description in AceGen
1. Mathematical description SMSInitialize@"test", Language −> "C++ "D
SMSModule@"Test", 8u1$$@3D, x$$, L$$, g$$@3D<D;

u = N i ui 8x, L< £ 8SMSReal@x$$D, SMSReal@L$$D<;


ui £ Array@SMSReal@u$$@#DD&, 3D;
x x x x
N = { ,1 − , (1 − )} Ni £ 9
x x x
,1− ,
x
I1 − M=;
L L L L L L L L
f = u2
u £ Ni .ui;
f £ u2 ;
g £ SMSD@f, uiD;

SMSExport@g, g$$D;
SMSWrite@D;

3. Automatically generated code "Mathematica" "Matlab"


"Fortran" "C++"
void Test(double v[501], Test[]:=Module[{},
SUBROUTINE Test(v,u1,x,L,g) double u1[3],double *x,
REAL*8 v(500),u1(3),x,L,g(3) $VV[6]=x$$/L$$;
double *L,double g[3])
v(6)=x/L $VV[7]=1 - $VV[6];
{
v(7)=1d0 - v(6) v[6]=*x/*L; $VV[8]=$VV[6]*$VV[7];
v(8)=v(6)*v(7) v[7]=1e0 - v[6]; $VV[12]=2*(u$$[1]*$VV[6] +
v(12)=2d0*(u(1)*v(6) + v[8]=v[6]*v[7]; u$$[2]*$VV[7]+u$$[3]*$VV[8]);
- u(2)*v(7) + u(3)*v(8)) v[12]=2e0*(u[0]*v[6] + g$$[1]=$VV[6]*$VV[12];
g(1)=v(12)*v(6) u[1]*v[7]+ u[2]*v[8]);
g(2)=v(12)*v(7) g$$[2]=$VV[7]*$VV[12];
g[0]=v[12]*v[6];
g(3)=v(12)*v(8) g$$[3]=$VV[8]*$VV[12];
g[1]=v[12]*v[7];
END g[2]=v[12]*v[8]; ]
};
7 J. KORELC, UNIVERSITY OF LJUBLJANA
Multi-environment code generation
AceFEM FEAP
<< AceGen`;
SMSInitialize@"test", "Environment" −> "AceFEM"D;
<< AceGen`;
SMSInitialize@"test", "Environment" −> "FEAP"D;
SMSTemplate@"SMSTopology" → "Q1", "SMSDOFGlobal" → 5, SMSTemplate@"SMSTopology" → "Q1", "SMSDOFGlobal" → 5,
"SMSGroupDataNames" → 8"Constant 1", "Constant 2"<D; "SMSGroupDataNames" → 8"Constant 1", "Constant 2"<D;
SMSStandardModule@"Tangent and residual"D; SMSStandardModule@"Tangent and residual"D;
SMSExport@SMSReal@nd$$@1, "X", 1DD, p$$@1DD; SMSExport@SMSReal@nd$$@1, "X", 1DD, p$$@1DD;
SMSWrite@D; SMSWrite@D;
Method : SKR 1 formulae, 9 sub−expressions RKt10
@0D File created :
Method : 1 formulae, 8 sub−expressions
@0D File created :
test.c Size : 3530 test.f Size : 4915

subroutine elmt10(d,ul,xl,ix,tl,s,p,ndfe,ndme,nste,isw)
#include "sms.h"
implicit none
void SKR(double v[5001],ElementSpec *es,ElementData *ed,NodeS
include 'sms.h'
FILE *SMTFile;
integer ix(nen),ndme,ndfe,nste,isw,INTEGRATIONCODE
double precision xl(ndme,nen),d(*),ul(ndfe,nen,*)
DLLEXPORT int SMTSetElSpec(ElementSpec *es,int *idata,int ic,in
double precision s(nste,nste),p(nste),tl(nen),sxd(24)
{ int intc,nd,i;
static int pn[6]={1, 2, 3, 4, 0, 0};
Suplementary
static int dof[4]={5, 5, 5, 5}; routines double precision sall(33,33),pall(33),du(24),dh(9)
double precision ul0(ndfe,nen),sg(24),sg0(24)
static int nsto[4]={0, 0, 0, 0};
character*50 SELEM,datades(2),postdes(0)
static int ndat[4];
logical DEBUG
…..

/******************* S U B R O U T I N E *****************/ parameter (INTEGRATIONCODE=7,DEBUG=.false.,


void SSE(double v[5001],ElementSpec *es,ElementData *ed,Node # SELEM="Hypersolid")
,NodeData **nd,double *rdata,int *idata,double *p)
{ integer i,j,jj,ll,ii,k,kk,i1,i2,i3,hlen,icode
int i44,i45,i46,b51,b52,b55,b58; user double precision w,v(5409),gpost(64,0),npost(8,0)
integer ipordl(30)
v[35]=-nd[0]->X[0]+nd[1]->X[0]; subroutines data (ipordl(i),i=1,30)/1,4,3,2,1,2,6,5,1,2,1,5,8,4,1,
v[37]=-nd[0]->X[1]+nd[1]->X[1];
v[31]=es->Data[0]; & 4,8,7,3,4,3,7,6,2,3,7,8,5,6,7/
v[32]=es->Data[1]; 1235 format(i3,">",3g17.9)
v[33]=es->Data[2]; ……
v[34]=sqrt(Power(v[35],2)+Power(v[37],2));
8 J. KORELC, UNIVERSITY OF LJUBLJANA
AceFEM
The Mathematica Finite
Element Environment

Key features:
• hybrid symbolic-numeric FEM environment
• AceFEM combines use of Mathematica’s features with external
handling of intensive computations by compiled modules
• customized FEM-based applications in Mathematica.
• AceFEM combines use of Mathematica’s features with external
handling of intensive computations by compiled modules
• support for web-based FEM throught webMathematica
• parallel optimisation throught gridMathematica
• build-in structured mesh generation and interface to GID© general
preprocessor
• fast sparse solvers, exact sensitivity analysis, etc.

9 J. KORELC, UNIVERSITY OF LJUBLJANA


AceShare
Finite Element File
Sharing

Key features:
• enables browsing and downloading the FE user subroutines from
standard and third-party on-line libraries
• provides mechanism for the formation of the third-party libraries to be
posted on the internet
• includes symbolic templates for direct and exact sensitivity analysis of
steady state, transient, coupled and coupled transient problems
• available libraries include AceGen templates and user subroutine source
codes for solid, structural, thermal and contact FE for all supported
environments (FEAP©, ELFEN©, AceFEM©, AceFEM-MDriver,
ABAQUS©, …)
• AceShare is ideal medium for the dissemination and verification of
new numerical methods

10 J. KORELC, UNIVERSITY OF LJUBLJANA


AceFEM FEM environment

AceFEM
Mathematica C language
General procedures CDriver
- input data processing
MathLink- data base
- mesh generation - evaluation of element quantities
- solution strategies - assembly of element contributions
- command language - various linear solvers
- graphic post-processing

dynamic link

MDriver element 1 element 2


- Mathematica language .dll file .dll file
- data base in MMA
- evaluation of element quantities element ...
- assembly of element contributions .dll file
- MMA linear algebra

element 1 AceShare
element 2 .m file
.m file - FEM file sharing system
element ... - download .dll or .m files
.m file

11 J. KORELC, UNIVERSITY OF LJUBLJANA


AceFEM - highlights: Multi - field problems
• induction heating
• T. Šuštar , C3M - Ljubljana, Slovenia

Magnetic Thermal Mechanical

12 J. KORELC, UNIVERSITY OF LJUBLJANA


AceFEM - highlights: Multi-scale problems
S. Stupkiewicz, IPPT, Warsaw, Poland
MICRO - 3D surface roughness

MACRO - elastic properties of contact surface

MACRO - lubricant flow in contact surface MACRO - thermal properties of contact surface
13 J. KORELC, UNIVERSITY OF LJUBLJANA
AceFEM - highlights: structural analysis
• Sensitivity analysis of single-storey steel building
• four node shell elements and large displacement truss elements

18

16 Analitic (elastic)
14
Finite differeces (elastic)
12
Analitic (plastic)
A

Sensitivity
10
Finite differeces (plastic)

β 8

0
0 10 20 30 40 50
Roof angle (deg)

14 J. KORELC, UNIVERSITY OF LJUBLJANA


AceFEM - highlights: Simulation of technological process
J. Lengiewicz, IPPT, Warsaw, Poland
Two phase forging

15 J. KORELC, UNIVERSITY OF LJUBLJANA


Ways to use the system
• AceGen as multi-language code generator
– translates MMA input into efficient C, Fortran, Matab code
– no calls to external subroutines
– AD
• AceGen as generator of finite elements for specific environments
– templates provided for some commercial and research environments
– finite element environments have large user groups (ABAQUS
several 1000) and companies that make specialized elements
– finite elements for specific purpose can be expensive

• AceFEM (independent finite element environment)

• AceGen + AceFEM
– complete Finite Element System
– commercial linear solver (Intel MKL), meshing, …
16 J. KORELC, UNIVERSITY OF LJUBLJANA

Das könnte Ihnen auch gefallen