You are on page 1of 11

1

Computa*onalFluidDynamics:Lecture19 (MEEN6720/CHEN6355)

DepartmentofMechanicalEngineering UniversityofUtah Spring2012

Prof.RobStoll

Numericalcodeverica*on
PhysicalProcess (realworldobservables) Simula*on

Expe r (vali iments da) on)


ConceptualModel

ComputerizedCode

Verica)on:wewanttoanswertheques*on Doesournumericalcoderepresentourmodelproperly? orequivalently AmIsolvingmyequa*onscorrectly? Notethisisdierentthanvalida)onwhichaskstheques*on:AmIsolvingtheright equa*ons? Valida)oninvolvescomparisonwiththerealworldthroughexperimentaldataorwell establishedtheories.

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 !u !2 u +u = " 2 what do we have in this equation? !t !x !x


u(x,t)uisafunc*onofx, tandourequa*onmustbalance Whatifwepickasolu*onof:

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:

!u !u !2u + u " ! 2 = Q ( x, t ) !t !x !x Sourceterm(BCsetc.)

!u # = 2 x 3t % !t % !u % = 3x 2 t 2 % !x $ !u 5 4 % u = 3x t !x % % !2 u 2 " 2 = " 6 xt % !x &

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

Whataboutnoslip?Thisisthesameastheabovecasesbutbecauseofthe waythatnoslipisusuallyimplementedinnumericalcodesitismany*mes easiertosimplypickamanufacturedsolu*onthatmatchesthenoslip condi*on(ingeneralthisisntabadpolicy).

10

MethodofManufactureSolu*ons
Howdoweuseourexactsolu)on?
Solu*onfromnumericalcode Chosenmanufacturedsolu*on

Calculatedierences(errors)i.e., = f()-fexact

Foragivenscheme(e.g.,CDS)weknowthat = CP+H.O.T. sooursolu*onshouldscaleasP. ln()

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)

You might also like