Professional Documents
Culture Documents
Computa*onalFluidDynamics:Lecture19 (MEEN6720/CHEN6355)
Prof.RobStoll
Numericalcodeverica*on
PhysicalProcess (realworldobservables) Simula*on
ComputerizedCode
Verica*on
Intheend,verica*onistheprocessofndingcodemistakes.Herewewillusethe deni*onfromRoache,1998(seeSalariandKnupp,2000postedinthehandouts) Paraphrasing:Inaveriedcode,thecodedenespreciselywhat equa*onsandboundarycondi*onsaresolvedandconvincingly demonstratesthattheyarecorrectlysolvedbyshowingthattheorderof accuracyiscorrectandthatas0thecodeproducestheexactsolu*onof theequa*ons. Notethatbythisdeni*on,wearenotconcernedwithverica*onofcalcula*ons, i.e.thattheaccuracyofthecodeforaspecicproblemisofapar*cularlevelbut insteadthatthecodeforagivensetofBCshastheproperorderofaccuracyand needonlybedoneonceforapar*cularcode(andrepeatedwheneverchangestothe codestructurearemade).
Verica*on
Intheendwearereallytalkingaboutndingcodemistakes: Twobasictypes: Sta*cmistakes:compile*meerrors,languageconsistency(oinetes*ng) Dynamicmistakes:whilerunningthecode,usuallymanifeststhroughorderof accuracyandconsistencyerrors Wehaveafewbasicapproacheswecanusetododynamictes*ng 1. Trendtes)ng:Runthecodewithavarietyofinputparametersandthenchecktrends usingexpertjudgment. Example:heatconduc*onproblemwheresteadystate*medecreasesasthe specicheatdecreases. 2. Symmetrytests:Checkthecodesolu*onforknownsymmetries.Doesntrequire exactsolu*ontobeknown. Example:NavierStokesequa*onsforhomogeneousperiodiccondi*onsare symmetricwithrespectto: Transla*onstheequa*onsareinvariantto*meorspaceshihs. Rota*onsandreec*onsaboutaxedaxisinspaceor*me. Galileantransla*onsinvarianttoxedvelocitytransla*ons.
Verica*on
3. Comparisontests:Useanestablishedcodeandcomparethenewcodeforadened testcaseacodeisconsideredacceptableifitreproducesresultswithina maximumacceptabledierence.Problem:ndingacode!Makingsuretheresults aregeneral,knowingifthecorrectcodeisreallycorrect! 4. MethodofExactSolu)ons(MES):ndanexactmathema*calsolu*ontotheproblem ofinterest,comparecoderesultstothissolu*onforavarietyofdierents(e.g. homework1).Thismethodiscompletelycapableofcodeverica*onbuthas drawbacks:1)exactsolu*onsmaybecomplexanddiculttocomparewith(example inniteseriessolu*onsfor2Dheatconduc*onprobleminhomework2).2)exact solu*onsmaynotexist(example3DNSequa*ons)!3)exactsolu*onswhichare availablemaynotbegeneral. 5. MethodofManufacturedSolu)ons(MMS):Toovercomedicul*esofMES,wewill makeupourownsolu*onsthentestforconsistencyandorderofaccuracy. DierencebetweenMMSandMESforageneralproblem:Du=g
MethodofManufactureSolu*ons
6. MethodofManufacturedSolu)ons(MMS):Toovercomedicul*esofMES,wewill makeupourownsolu*onsthentestforconsistencyandorderofaccuracy. DierencebetweenMMSandMESforageneralproblem:Du=g InMESwepickgndu InMMSwepickundg
dieren*al operator solu*on Sourceterm(BCsetc.)
i.e.inMMSwepickoursolu*on1st(possiblyevenbeforeweknowour equa*ons!)
MMSExample:1DBurgersEqua*on
u ( x, t ) = A + sin ( x + Bt )
willthissa*sfyourPDE?
MethodofManufactureSolu*ons
Insteadwewillgetasolu*ontoamodiedversionofourequa*on Q(x,t)dependsonourmanufacturedsolu*on Ifwepickadierentsolu*on(sayu(x,t)=x2e-t),wegetadierentsourceterm Letslookataspecicexample:picku(x,t)=x3t2 For1DBurgersequa*on(termbyterm)weget:
Subs*tu*ngtheseintoourPDEand solvingforQ
Q ( x, t ) = 2 x 3t + 3x 5t 4 ! " 6 xt 2
MethodofManufactureSolu*ons
Whatdowedowiththisinourdiscre*zedversionoftheequa*on? Example:ExplicitEuler,centraldierenceinspace
n +1 i
Foranimplicitscheme(Ax=b)weaddQ to b. Generalguidelinesforpickingmanufacturedsolu)ons: 1. Thesolu*onshouldbesmoothanddieren*abletothedesiredlevel(e.g., polynomials,exponen*als,trigonometricfunc*ons) 2. Solu*onsshouldbegeneralenoughtoexercisethedesiredterms. 3. Thesolu*onshouldbevalidduringtheen*re*meofdesiredsimula*on(i.e., rangeoftsandoveren*redomain) 4. Dieren*ableoperatorsshouldmakesense.ForexampleinBurgersequa*onif ! !u !u ! isnotaconstant()ourcombina*onof andshouldbedieren*able. !x !x !x Notethatwecanalsoconstructfunc*onalconstantstotestthose(e.g.,or,thermal conduc*vity,etc.)theseshouldfollowsimilarrules,theyshouldmakesenseandbe dieren*able. Itisimportanttonotethatnoneoftheseguidelinesrequirephysicalrealism!
$ n uin+1 " uin"1 ' uin+1 " 2uin + uin"1 = u + !t & ui "# + Q) 2 2 ( !x ) ( !x ) % (
n i
MMSSourceterm
MethodofManufactureSolu*ons
Whataboutboundarycondi)ons? Shortanswerevaluatethesolu*onattheboundaries 3basictypes: Dirichlet:constantvaluecondi*onsevaluateoursolu*onatpoints wherethisBCisneeded Forexample: u ( x, t ) =
2 x 3t 2 at x = Lx ! u ( Lx , t ) = L3 xt
Neumanncondi*ons:gradientbasedBCs
!u = constant " we evaluate our constant from our solution !x and enforce it at the boundaries
10
MethodofManufactureSolu*ons
Howdoweuseourexactsolu)on?
Solu*onfromnumericalcode Chosenmanufacturedsolu*on
Calculatedierences(errors)i.e., = f()-fexact
Errorbetweenexactand manufacturedatoneresolu*on
P=>slope
ln() Thiswasusedinhomework#1andisdiscussedinmoredetailinlecture5.
11
MethodofManufactureSolu*ons
Moreonfunc)onselec)on Wecanturntermson/owithoursolu*onchoice. e.g.,choosingalinearsolu*onwillturnoourdiusionterms. Whataboutturningotheconvec*onterm?Twoways,onendasolu*on thatturnsitowithoutremovingthediusionterm(hardtodoeverywhere simultaneously).Onepossibilityistoincrease
AlloftheseideascanchangeQautodieren*a*onisidealifpossible. WhatcanwendwithMMS? Bugs Orderofaccuracyerrors,typographicalerrors,algorithmicimplementa*onerrors SalariandKnupp(2000)SandiaNa*onalLabreportgiveablindstudy. Foundallerrors(21casesoneplacebo)eec*ngorderofaccuracy Somebugscouldntbedetected(onesnoteec*ngorderofaccuracy) MMSdoesntworkfor: Stochas*cmethods Fluxorslopelimiterschemes(variableorderofaccuracyschemes) Preprocessingorpostprocessingerrors Timesteppingerrors(orderofaccuracyisntwelldened)