Changeset 8881


Ignore:
Timestamp:
Jun 5, 2013, 4:08:23 PM (11 years ago)
Author:
steve
Message:

Made the computation of topography faster using numpy procedures
in numerical_varying_width.py

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/anuga_core/source/anuga_validation_tests/Analytical_exact/lake_at_rest_varying_width/numerical_varying_width.py

    r8878 r8881  
    1212from anuga import Domain as Domain
    1313from math import cos
    14 from numpy import zeros, ones, array, interp, polyval
     14from numpy import zeros, ones, array, interp, polyval, ones_like, zeros_like
     15from numpy import where, logical_and
    1516from time import localtime, strftime, gmtime
    1617from scipy.interpolate import interp1d
     
    7172            45.,40.,40.,30.,40.,40.,5.,40.,35.,25.,40.,40.])/2.
    7273
    73 print "Start here"
     74
     75depth = interp1d(XX, ZZ)
     76width = interp1d(XX, WW)
     77
    7478def bed_elevation(x,y):
    75     z = 25.*ones(len(x), float)
    76     for i in range(len(XX)-1):
    77         for j in range(len(x)):
    78             if XX[i] <= x[j] <= XX[i+1]:
    79                 v1 = [XX[i+1]-XX[i], WW[i+1]-WW[i]]
    80                 v2 = [XX[i+1]-x[j], WW[i+1]-abs(y[j])]
    81                 xp = v1[0]*v2[1] - v1[1]*v2[0]
    82                 #if 0.0 <= abs(y[j]) <= interp1d([XX[i],XX[i+1]], [WW[i],WW[i+1]])(y[j]):
    83                 if xp >= 0:
    84                     z[j] = interp1d([XX[i],XX[i+1]], [ZZ[i],ZZ[i+1]])(x[j])
     79
     80    z = 25.0*ones_like(x)
     81
     82    wid = width(x)
     83    dep = depth(x)
     84
     85    z = where( logical_and(y < wid, y>-wid), dep, z)
     86
    8587    return z
     88
    8689domain.set_quantity('elevation', bed_elevation)
    87 print "Start now"
     90
    8891
    8992#-----------------------------------------------------------------------------
Note: See TracChangeset for help on using the changeset viewer.