From 2f83993dda2f1f7b6a0a209e516ea217e6cfd4c6 Mon Sep 17 00:00:00 2001 From: David Ketcheson Date: Thu, 28 Jan 2016 14:57:17 +0300 Subject: [PATCH] Add test for dam_break problem that uses Python Roe solver. This tests https://github.com/clawpack/riemann/pull/109. --- examples/shallow_1d/dam_break.py | 9 +- examples/shallow_1d/dam_break_depth.txt | 500 ++++++++++++++++++++++++ examples/shallow_1d/test_dambreak.py | 38 ++ 3 files changed, 545 insertions(+), 2 deletions(-) create mode 100644 examples/shallow_1d/dam_break_depth.txt create mode 100644 examples/shallow_1d/test_dambreak.py diff --git a/examples/shallow_1d/dam_break.py b/examples/shallow_1d/dam_break.py index 9922a18ea..fb9d40e68 100755 --- a/examples/shallow_1d/dam_break.py +++ b/examples/shallow_1d/dam_break.py @@ -19,7 +19,8 @@ from clawpack import riemann from clawpack.riemann.shallow_roe_with_efix_1D_constants import depth, momentum, num_eqn -def setup(use_petsc=False,kernel_language='Fortran',outdir='./_output',solver_type='classic'): +def setup(use_petsc=False,kernel_language='Fortran',outdir='./_output', + solver_type='classic',disable_output=False): if use_petsc: import clawpack.petclaw as pyclaw @@ -27,7 +28,7 @@ def setup(use_petsc=False,kernel_language='Fortran',outdir='./_output',solver_ty from clawpack import pyclaw if kernel_language =='Python': - rs = riemann.shallow_1D_py.shallow_1D + rs = riemann.shallow_1D_py.shallow_roe_1D elif kernel_language =='Fortran': rs = riemann.shallow_roe_with_efix_1D @@ -51,6 +52,8 @@ def setup(use_petsc=False,kernel_language='Fortran',outdir='./_output',solver_ty # Gravitational constant state.problem_data['grav'] = 1.0 + if kernel_language =='Python': + state.problem_data['efix'] = True # Turn on entropy fix xc = state.grid.x.centers @@ -83,6 +86,8 @@ def setup(use_petsc=False,kernel_language='Fortran',outdir='./_output',solver_ty claw.solver = solver claw.outdir = outdir claw.setplot = setplot + if disable_output: + claw.output_format = None return claw diff --git a/examples/shallow_1d/dam_break_depth.txt b/examples/shallow_1d/dam_break_depth.txt new file mode 100644 index 000000000..0f368ad8c --- /dev/null +++ b/examples/shallow_1d/dam_break_depth.txt @@ -0,0 +1,500 @@ +3.000000000000000000e+00 +3.000000000000000000e+00 +3.000000000000000000e+00 +3.000000000000000000e+00 +3.000000000000000000e+00 +3.000000000000000000e+00 +3.000000000000000000e+00 +3.000000000000000000e+00 +3.000000000000000000e+00 +3.000000000000000000e+00 +3.000000000000000000e+00 +3.000000000000000000e+00 +3.000000000000000000e+00 +3.000000000000000000e+00 +3.000000000000000000e+00 +3.000000000000000000e+00 +3.000000000000000000e+00 +3.000000000000000000e+00 +3.000000000000000000e+00 +2.999999999999999556e+00 +2.999999999999999112e+00 +2.999999999999998668e+00 +2.999999999999998224e+00 +2.999999999999997780e+00 +2.999999999999997335e+00 +2.999999999999996891e+00 +2.999999999999996447e+00 +2.999999999999996003e+00 +2.999999999999995559e+00 +2.999999999999995115e+00 +2.999999999999994671e+00 +2.999999999999994227e+00 +2.999999999999993783e+00 +2.999999999999993339e+00 +2.999999999999992895e+00 +2.999999999999992450e+00 +2.999999999999992006e+00 +2.999999999999991562e+00 +2.999999999999991118e+00 +2.999999999999990674e+00 +2.999999999999990230e+00 +2.999999999999989786e+00 +2.999999999999989342e+00 +2.999999999999988898e+00 +2.999999999999988454e+00 +2.999999999999988010e+00 +2.999999999999987566e+00 +2.999999999999987121e+00 +2.999999999999986677e+00 +2.999999999999986233e+00 +2.999999999999985345e+00 +2.999999999999984013e+00 +2.999999999999973799e+00 +2.999999999999906297e+00 +2.999999999999525713e+00 +2.999999999997500666e+00 +2.999999999987228438e+00 +2.999999999937551731e+00 +2.999999999708487852e+00 +2.999999998701977866e+00 +2.999999994490965882e+00 +2.999999977732938028e+00 +2.999999914376564547e+00 +2.999999687164019324e+00 +2.999998915650839759e+00 +2.999996440920058127e+00 +2.999988963599564240e+00 +2.999967758348744962e+00 +2.999911566176372890e+00 +2.999773193702948149e+00 +2.999458610581341667e+00 +2.998803012561636283e+00 +2.997559036063035531e+00 +2.995420348904362040e+00 +2.992092475349013458e+00 +2.987386560203370678e+00 +2.981281462102505664e+00 +2.973915774161340675e+00 +2.965523098266498625e+00 +2.956356484743015045e+00 +2.946637375556893979e+00 +2.936536154512420449e+00 +2.926173957935661818e+00 +2.915633220687252614e+00 +2.904969103026086685e+00 +2.894218645560268310e+00 +2.883407165957455831e+00 +2.872552421856933158e+00 +2.861667230797036332e+00 +2.850761105727256606e+00 +2.839841285939655346e+00 +2.828913400851715831e+00 +2.817981909194108514e+00 +2.807050398141224257e+00 +2.796121792805827511e+00 +2.785198506654027018e+00 +2.774282551805204111e+00 +2.763375621387179404e+00 +2.752479152043161292e+00 +2.741594372095094378e+00 +2.730722339129930898e+00 +2.719863969632361655e+00 +2.709020062558567865e+00 +2.698191318216748957e+00 +2.687378353391605135e+00 +2.676581713448774824e+00 +2.665801882246182863e+00 +2.655039290832206245e+00 +2.644294325997111006e+00 +2.633567339145057584e+00 +2.622858653223754999e+00 +2.612168563841580582e+00 +2.601497336490073753e+00 +2.590845207240569881e+00 +2.580212388696136117e+00 +2.569599076140324456e+00 +2.559005450514699742e+00 +2.548431680181871606e+00 +2.537877923092691557e+00 +2.527344327252878387e+00 +2.516831030625754195e+00 +2.506338161932963438e+00 +2.495865841736861324e+00 +2.485414183378581665e+00 +2.474983293766440884e+00 +2.464573274074063569e+00 +2.454184220395391414e+00 +2.443816224366084811e+00 +2.433469373726660390e+00 +2.423143752811620200e+00 +2.412839442987229965e+00 +2.402556523077898021e+00 +2.392295069794732942e+00 +2.382055158145276241e+00 +2.371836861807437469e+00 +2.361640253491243069e+00 +2.351465405339123738e+00 +2.341312389386476234e+00 +2.331181278024377246e+00 +2.321072144334497711e+00 +2.310985062211726948e+00 +2.300920106384412911e+00 +2.290877352569514525e+00 +2.280856878002243349e+00 +2.270858762960181743e+00 +2.260883094073095734e+00 +2.250929967903188000e+00 +2.240999491055861714e+00 +2.231091775487675566e+00 +2.221206930009209213e+00 +2.211345062874100265e+00 +2.201506300732086530e+00 +2.191690776433268262e+00 +2.181898634211654642e+00 +2.172130035937955395e+00 +2.162385160350956959e+00 +2.152664204431183226e+00 +2.142967387390593892e+00 +2.133294951848852872e+00 +2.123647166496025918e+00 +2.114024332102460324e+00 +2.104426786039014008e+00 +2.094854908413459782e+00 +2.085309129257760130e+00 +2.075789937207404900e+00 +2.066297890032959828e+00 +2.056833627499076833e+00 +2.047397887187468069e+00 +2.037991524170592594e+00 +2.028615535760207145e+00 +2.019271093002544593e+00 +2.009959581231868242e+00 +2.000682652951875973e+00 +1.991442297978497811e+00 +1.982240937003036940e+00 +1.973081551571716385e+00 +1.963967864069789293e+00 +1.954904598887647893e+00 +1.945897870602743218e+00 +1.936955781082067229e+00 +1.928089365019375112e+00 +1.919314120546780078e+00 +1.910652495445550603e+00 +1.902137899894869921e+00 +1.893820843516064834e+00 +1.885777583032523408e+00 +1.878120321196374176e+00 +1.871005059118318714e+00 +1.864628536553640803e+00 +1.859202672974570314e+00 +1.854900745429218123e+00 +1.851789642415534898e+00 +1.849785879016442092e+00 +1.848670863905081507e+00 +1.848161126850121017e+00 +1.847990413974601731e+00 +1.847961403776367195e+00 +1.847985995504517698e+00 +1.848152659162276334e+00 +1.848421407737056654e+00 +1.848631936046682522e+00 +1.848744368190544662e+00 +1.848791868022739537e+00 +1.848807120825762373e+00 +1.848809732377544091e+00 +1.848808033511117888e+00 +1.848794396228332859e+00 +1.848770259233310176e+00 +1.848750435385469348e+00 +1.848740099578549456e+00 +1.848736141137073075e+00 +1.848734976948961384e+00 +1.848734665386236431e+00 +1.848734465985861108e+00 +1.848733738964701612e+00 +1.848729950273864331e+00 +1.848718190309582621e+00 +1.848697809841524320e+00 +1.848676173338512418e+00 +1.848660092583009451e+00 +1.848650716173848352e+00 +1.848646080397886138e+00 +1.848643939610365106e+00 +1.848642726153539417e+00 +1.848641294074984343e+00 +1.848636902547242000e+00 +1.848618575897817085e+00 +1.848561199252129361e+00 +1.848455165411467815e+00 +1.848348089394418414e+00 +1.848291139875028577e+00 +1.848278765549871139e+00 +1.848288399930753112e+00 +1.848381416536349908e+00 +1.848592005233613556e+00 +1.848802498723425947e+00 +1.848917577247448429e+00 +1.848952624699338854e+00 +1.848955623588344643e+00 +1.848928074085736561e+00 +1.848838049152976115e+00 +1.848733727500701196e+00 +1.848662738311284137e+00 +1.848624573756173284e+00 +1.848605604502676192e+00 +1.848595988494416309e+00 +1.848590030117412297e+00 +1.848583622947808536e+00 +1.848569542453239123e+00 +1.848528928747077638e+00 +1.848440375527008461e+00 +1.848328490197087337e+00 +1.848253890874888228e+00 +1.848231751660461164e+00 +1.848234529677000415e+00 +1.848305094025686213e+00 +1.848510360006063946e+00 +1.848748241973774631e+00 +1.848889676742812016e+00 +1.848935134474186226e+00 +1.848939649765498627e+00 +1.848909479504233788e+00 +1.848812623514766607e+00 +1.848709954253749732e+00 +1.848649823609100018e+00 +1.848623810301138315e+00 +1.848614244165152298e+00 +1.848610950372905570e+00 +1.848609526734996678e+00 +1.848607919305591540e+00 +1.848602445613365619e+00 +1.848578688877033471e+00 +1.848504913600915067e+00 +1.848373553912088685e+00 +1.848250024931894275e+00 +1.848192912791329467e+00 +1.848183952506912586e+00 +1.848215806365517633e+00 +1.848388203628294368e+00 +1.848669003966290303e+00 +1.848876511373932496e+00 +1.848956344191707180e+00 +1.848968834357552771e+00 +1.848946665683022461e+00 +1.848842598867144416e+00 +1.848712360661821430e+00 +1.848630034113095677e+00 +1.848593604940786062e+00 +1.848581028329159937e+00 +1.848578073731767857e+00 +1.848577945739909190e+00 +1.848579831341916613e+00 +1.848581507565771886e+00 +1.848581333741856403e+00 +1.848572395160547277e+00 +1.848520667950203311e+00 +1.848390646796860048e+00 +1.848244585278898677e+00 +1.848173755107417326e+00 +1.848163777214204995e+00 +1.848217559459067294e+00 +1.848451047859490215e+00 +1.848756668620942900e+00 +1.848931800099728795e+00 +1.848978320471926562e+00 +1.848976782159489129e+00 +1.848905693591372357e+00 +1.848769744038768703e+00 +1.848666959770843166e+00 +1.848614759705399679e+00 +1.848589992351213462e+00 +1.848577252680082772e+00 +1.848570332617326617e+00 +1.848566752507391664e+00 +1.848564836923709986e+00 +1.848562945596952334e+00 +1.848556919326090231e+00 +1.848525704682958626e+00 +1.848415105512402734e+00 +1.848224153444659068e+00 +1.848082027875918687e+00 +1.848045533883976965e+00 +1.848071495986051138e+00 +1.848307788847434630e+00 +1.848727308444387818e+00 +1.849010575177431281e+00 +1.849092987816477240e+00 +1.849092731603814377e+00 +1.848987526514262791e+00 +1.848793203971293320e+00 +1.848662668784191832e+00 +1.848609854650657969e+00 +1.848593274672668318e+00 +1.848588863468487054e+00 +1.848587753215147123e+00 +1.848587304325266967e+00 +1.848586708884374818e+00 +1.848584911904527228e+00 +1.848578705450702797e+00 +1.848555322500713416e+00 +1.848471212416082698e+00 +1.848277259492169922e+00 +1.848066132632561587e+00 +1.847978036919305733e+00 +1.847979142257460516e+00 +1.848168326489685320e+00 +1.848642305643545702e+00 +1.849023809258165674e+00 +1.849147171934744316e+00 +1.849152701023561329e+00 +1.849038412755558136e+00 +1.848812756890765074e+00 +1.848658364717445268e+00 +1.848593306625068378e+00 +1.848570976310896619e+00 +1.848564710242641462e+00 +1.848563623635267827e+00 +1.848564450082693655e+00 +1.848570456390365102e+00 +1.848579210631430492e+00 +1.848583451719246318e+00 +1.848583451254453669e+00 +1.848569286641933651e+00 +1.848466045738929697e+00 +1.848179761878911531e+00 +1.847899535133564308e+00 +1.847822021334155407e+00 +1.847908044994892807e+00 +1.848422084661455189e+00 +1.848996410129917889e+00 +1.849200626258799662e+00 +1.849210172000401053e+00 +1.849056839639506400e+00 +1.848821327834234030e+00 +1.848694398770129199e+00 +1.848642037515099368e+00 +1.848615761701990934e+00 +1.848596426823543526e+00 +1.848577439595843197e+00 +1.848561021421693207e+00 +1.848552960591940186e+00 +1.848551353332988700e+00 +1.848553234249125099e+00 +1.848558930082182972e+00 +1.848561742732789170e+00 +1.848560884356742262e+00 +1.848525111000090648e+00 +1.848260488848959993e+00 +1.847753052628876791e+00 +1.847559820164707878e+00 +1.847832706574010553e+00 +1.848865746532257104e+00 +1.849426205660122280e+00 +1.849449181059644509e+00 +1.849099837280031133e+00 +1.848756650908755850e+00 +1.848639809089107855e+00 +1.848598035479306789e+00 +1.848565574651633847e+00 +1.848550065981166446e+00 +1.848563097108502307e+00 +1.848571734579689929e+00 +1.848543154918167453e+00 +1.848562664166919278e+00 +1.848620375634701718e+00 +1.848513607266189629e+00 +1.848452268741717530e+00 +1.848675621776806777e+00 +1.848427061587315734e+00 +1.848487458939386041e+00 +1.851317189993118895e+00 +1.786978653980038745e+00 +1.238327375380458673e+00 +1.004297418880081949e+00 +1.000017198518015293e+00 +1.000000073716809545e+00 +1.000000000319281712e+00 +1.000000000001410871e+00 +1.000000000000006661e+00 +1.000000000000000000e+00 +1.000000000000000000e+00 +1.000000000000000000e+00 +1.000000000000000000e+00 +1.000000000000000000e+00 +1.000000000000000000e+00 +1.000000000000000000e+00 +1.000000000000000000e+00 +1.000000000000000000e+00 +1.000000000000000000e+00 +1.000000000000000000e+00 +1.000000000000000000e+00 +1.000000000000000000e+00 +1.000000000000000000e+00 +1.000000000000000000e+00 +1.000000000000000000e+00 +1.000000000000000000e+00 +1.000000000000000000e+00 +1.000000000000000000e+00 +1.000000000000000000e+00 +1.000000000000000000e+00 +1.000000000000000000e+00 +1.000000000000000000e+00 +1.000000000000000000e+00 +1.000000000000000000e+00 +1.000000000000000000e+00 +1.000000000000000000e+00 +1.000000000000000000e+00 +1.000000000000000000e+00 +1.000000000000000000e+00 +1.000000000000000000e+00 +1.000000000000000000e+00 +1.000000000000000000e+00 +1.000000000000000000e+00 +1.000000000000000000e+00 +1.000000000000000000e+00 +1.000000000000000000e+00 +1.000000000000000000e+00 +1.000000000000000000e+00 +1.000000000000000000e+00 +1.000000000000000000e+00 +1.000000000000000000e+00 +1.000000000000000000e+00 +1.000000000000000000e+00 +1.000000000000000000e+00 +1.000000000000000000e+00 +1.000000000000000000e+00 +1.000000000000000000e+00 +1.000000000000000000e+00 +1.000000000000000000e+00 +1.000000000000000000e+00 +1.000000000000000000e+00 +1.000000000000000000e+00 +1.000000000000000000e+00 +1.000000000000000000e+00 +1.000000000000000000e+00 +1.000000000000000000e+00 +1.000000000000000000e+00 +1.000000000000000000e+00 +1.000000000000000000e+00 +1.000000000000000000e+00 +1.000000000000000000e+00 +1.000000000000000000e+00 +1.000000000000000000e+00 +1.000000000000000000e+00 +1.000000000000000000e+00 +1.000000000000000000e+00 +1.000000000000000000e+00 +1.000000000000000000e+00 +1.000000000000000000e+00 +1.000000000000000000e+00 +1.000000000000000000e+00 +1.000000000000000000e+00 +1.000000000000000000e+00 +1.000000000000000000e+00 +1.000000000000000000e+00 +1.000000000000000000e+00 +1.000000000000000000e+00 +1.000000000000000000e+00 +1.000000000000000000e+00 +1.000000000000000000e+00 diff --git a/examples/shallow_1d/test_dambreak.py b/examples/shallow_1d/test_dambreak.py new file mode 100644 index 000000000..2820e634a --- /dev/null +++ b/examples/shallow_1d/test_dambreak.py @@ -0,0 +1,38 @@ +#!/usr/bin/env python +# encoding: utf-8 + +def test_1d_dambreak(): + """test_1d_dambreak + + Tests against expected classic solution of shallow water equations + for dam-break problem.""" + + import dam_break + + def verify_dambreak(controller): + import numpy as np + import os + + test_solution = controller.solution.state.get_q_global() + + if test_solution is not None: + thisdir = os.path.dirname(__file__) + expected_depth = np.loadtxt(os.path.join(thisdir,'dam_break_depth.txt')) + test_depth = test_solution[0,:] + discrepancy = np.linalg.norm(expected_depth - test_depth) + assert discrepancy < 1.e-12 + return + + from clawpack.pyclaw.util import gen_variants + classic_tests = gen_variants(dam_break.setup, verify_dambreak, + kernel_languages=["Python"], + solver_type='classic', + disable_output=True) + + from itertools import chain + for test in chain(classic_tests): + yield test + +if __name__=='__main__': + import nose + nose.main()