finite element
- 格式:pdf
- 大小:505.68 KB
- 文档页数:25
EFFICIENTIMPLEMENTATIONOFADAPTIVEP1-FEMINMATLAB
S.FUNKEN,D.PRAETORIUS,ANDP.WISSGOTT
Abstract.WeprovideaMatlabpackagep1afemforanadaptiveP1-finiteelementmethod(AFEM).Thisincludesfunctionsfortheassemblyofthedata,differenterrorestimators,andanindicator-basedadaptivemesh-refiningalgorithm.Throughout,thefocusisonanefficientrealizationbyuseofMatlabbuilt-infunctionsandvectorization.Numericalexperimentsunderlinetheefficiencyofthecodewhichisobservedtobeofalmostlinearcomplexitywithrespecttotheruntime.AlthoughthescopeofthispaperisonAFEM,thegeneralideascanbeunderstoodasaguidelineforwritingefficientMatlabcode.
1.Introduction
Inrecentyears,Matlabhasbecomeadefactostandardforthedevelopmentandprototyping
ofvariouskindsofalgorithmsfornumericalsimulations.Inparticular,ithasproventobean
excellenttoolforacademiceducation,e.g.,inthefieldofpartialdifferentialequations,cf.[20,21].
In[1],aMatlabcodefortheP1-GalerkinFEMisproposedwhichwasdesignedforshortness
andclarity.Whereasthegivencodeseemstobeoflinearcomplexitywithrespecttothenumber
ofelements,themeasurementofthecomputationaltimeprovesquadraticdependenceinstead.
SincethisismainlyduetotheinternaldatastructureofMatlab,weshowhowtomodifythe
existingMatlabcodesothatthetheoreticallypredictedcomplexitycanevenbemeasuredin
computations.
Moreoverandinadditionto[1],weprovideacompleteandeasy-to-modifypackagecalled
p1afemforadaptiveP1-FEMcomputations,includingthreedifferentaposteriorierrorestima-
torsaswellasanadaptivemesh-refinementbasedonared-green-bluestrategy(RGB)ornewest
vertexbisection(NVB).Forthelatter,weadditionallyprovideanefficientimplementationof
thecoarseningstrategyfromChenandZhang[10,15].Allpartsofp1afemareimplemented
inaway,weexpecttobeoptimalinMatlabasacompromisebetweenclarity,shortness,and
useofMatlabbuilt-infunctions.Inparticular,weusefullvectorizationinthesensethat
for-loopsareeliminatedbyuseofMatlabvectoroperations.
ThecompleteMatlabcodeofp1afemcanbedownloadfromtheweb[18],andthetechnical
report[17]providesadetaileddocumentationoftheunderlyingideas.
Theremainingcontentofthispaperisorganizedasfollows:Section2introducesthemodel
problemandtheGalerkinscheme.InSection3,wefirstrecallthedatastructuresof[1]as
wellastheirMatlabimplementation.Wediscussthereasonswhythiscodeleadstoquadratic
complexityinpractice.Evensimplemodificationsyieldanimprovedcodewhichbehavesalmost
linearly.Weshowhowtheoccurringfor-loopscanbeeliminatedbyuseofMatlab’svector
arithmeticswhichleadstoafurtherimprovementoftheruntime.Section4givesashort
overviewonthefunctionalityprovidedbyp1afem,andselectedfunctionsarefurtherdiscussedin
theremainderofthepaper:Section5isfocusedonlocalmesh-refinementandmesh-coarsening
basedonNVB.Section6providesarealizationofastandardadaptivemesh-refiningalgorithm
steeredbytheresidual-basederrorestimatorduetoBabuˇskaandMiller[4].Section7
concludesthepaperwithsomenumericalexperimentsand,inparticular,comparisonswith
otherMatlabFEMpackageslikeAFEM[13,14]oriFEM[11,12].2.ModelExampleandP1-GalerkinFEM
2.1.ContinuousProblem.Asmodelproblem,weconsidertheLaplaceequationwithmixed
Dirichlet-Neumannboundaryconditions.Givenf∈L2(Ω),uD∈H1/2(ΓD),andg∈L2(ΓN),
weaimtocomputeanapproximationofthesolutionu∈H1(Ω)of
−∆u=finΩ,
u=uDonΓD,
∂nu=gonΓN.(2.1)
Here,ΩisaboundedLipschitzdomaininR2whosepolygonalboundaryΓ:=∂Ωissplitinto
aclosedDirichletboundaryΓDwithpositivelengthandaNeumannboundaryΓN:=Γ\ΓD.
OnΓN,weprescribethenormalderivative∂nuofu,i.e.theflux.Fortheoreticalreasons,we
identifyuD∈H1/2(ΓD)withsomearbitraryextensionuD∈H1(Ω).With
u0=u−uD∈H1D(Ω):={v∈H1(Ω):v=0onΓD},(2.2)
theweakformreads:Findu0∈H1D(Ω)suchthat
Ω∇u0·∇vdx=
Ωfvdx+
ΓNgvds−
Ω∇uD·∇vdxforallv∈H1D(Ω).(2.3)
Functionalanalysisprovidestheuniqueexistenceofu0intheHilbertspaceH1D(Ω),whence
theuniqueexistenceofaweaksolutionu:=u0+uD∈H1(Ω)of(2.1).Notethatudoesonly
dependonuD|ΓDsothatonemayconsidertheeasiestpossibleextensionuDoftheDirichlet
traceuD|ΓDfromΓDtoΩ.
2.2.P1-GalerkinFEM.LetTbearegulartriangulationofΩintotriangles,i.e.•TisafinitesetofcompacttrianglesT=conv{z1,z2,z3}withpositivearea|T|>0,•theunionofalltrianglesinTcoverstheclosure
−1
−0.500.51−1−0.8−0.6−0.4−0.200.20.40.60.81
1123
2253
3543
4413
5457
65107
71097
8947
9568
106118
1111108
121058112
225
356
4611
11110
2109
394
441wherethenodesaregivenincounterclockwiseorder,i.e.,theparametrizationoftheboundary
∂Tℓismathematicallypositive.
TheDirichletboundaryΓDissplitintoKaffineboundarypieces,whichareedgesoftriangles
T∈T.ItisrepresentedbyaK×2integerarraydirichlet.Theℓ-thedgeEℓ=conv{zi,zj}
ontheDirichletboundaryisstoredintheform
dirichlet(ℓ,:)=[ij].
Itisassumedthatzj−zigivesthemathematicallypositiveorientationofΓ,i.e.
nℓ=1
1function[x,energy]=solveLaplace(coordinates,elements,dirichlet,neumann,f,g,uD)
2nC=size(coordinates,1);