Changeset 8158


Ignore:
Timestamp:
Mar 20, 2011, 11:32:14 AM (14 years ago)
Author:
steve
Message:

Using brent solver to solve for intermediate state in dam break calc

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/anuga_validation/validation_tests/dam_break_analytical.py

    r8157 r8158  
    2121#       MA 02110-1301, USA.
    2222
    23 
    2423   
    25 def wu(h2):
     24def wu(h2, h0=1.0, h1=10.0):
    2625    """ The intermediate state in dambreak problem
    2726    must satisfy wu(h2) = 0.0
     
    2928    Taken from formula (3.14) from Zoppou and Roberts SWW notes
    3029    """
    31    
     30
    3231    h21 = h2/h1
    3332    h01 = h0/h1
     
    3635
    3736
    38 h0 = 1.0
    39 h1 = 2.0
     37def h2(h0=1.0, h1=10.0):
    4038
    41 h21 = 1.0
    42 h01 = 0.5
     39    assert h1 >  0.0
     40    assert h0 <=  h1
     41    assert h0 >= 0.0
    4342
    44 print h21**3 - 9.0*(h21**2)*h01 + 16.0*(h21**(1.5))*h01 - h21*h01*(h01+8.0) + h01**3
    45 
    46 h21 = 0.5
    47 h01 = 0.5
    48 
    49 print  - 8.0*h21**3 + 16.0*h21**(2.5) -8*h21**2
     43    from scipy.optimize import brentq
     44    return brentq(wu, h0, h1, args=(h0,h1))
    5045
    5146
    52 n = 10
    53 import pylab as p
     47h1 = 1.0
    5448
    55 import numpy
    56 
    57 x = h0 + numpy.arange(0,n+1)/float(n)*(h1-h0)
    58 
    59 new_wu = numpy.vectorize(wu)
    60 y = new_wu(x)
    61 
    62 print x
    63 print y
     49for i in range(0,11):
     50    h0 = float(i)/10.0*h1
     51    print 'h2(%g,%g) = %g' % (h0, h1, h2(h0))
    6452
    6553
    66 print wu(h0), wu(h1)
    6754
    68 from scipy.optimize import brentq
    6955
    70 h2 = brentq(wu, h0,h1,disp=True)
    7156
    72 #print  h2, wu(h2)
    73    
Note: See TracChangeset for help on using the changeset viewer.