[2638] | 1 | """Example of shallow water wave equation. |
---|
| 2 | |
---|
| 3 | Island surrounded by water. |
---|
| 4 | This example investigates onshore 'creep' |
---|
| 5 | |
---|
| 6 | """ |
---|
| 7 | |
---|
| 8 | |
---|
| 9 | #------------------------------------------------------------------------------ |
---|
| 10 | # Import necessary modules |
---|
| 11 | #------------------------------------------------------------------------------ |
---|
| 12 | |
---|
| 13 | # Standard modules |
---|
| 14 | from math import exp |
---|
| 15 | |
---|
| 16 | # Application specific imports |
---|
| 17 | from pyvolution.mesh_factory import rectangular |
---|
| 18 | from pyvolution.shallow_water import Domain, Reflective_boundary, Dirichlet_boundary |
---|
| 19 | from pmesh.mesh_interface import create_mesh_from_regions |
---|
| 20 | from utilities.polygon import Polygon_function, read_polygon |
---|
| 21 | |
---|
| 22 | from pyvolution.quantity import Quantity |
---|
| 23 | from Numeric import allclose |
---|
| 24 | |
---|
| 25 | #------------------------------------------------------------------------------ |
---|
| 26 | # Setup computational domain |
---|
| 27 | #------------------------------------------------------------------------------ |
---|
| 28 | |
---|
| 29 | #Create basic mesh |
---|
| 30 | create_mesh_from_regions( [[0,0], [100,0], [100,100], [0,100]], |
---|
| 31 | boundary_tags = {'bottom': [0], |
---|
| 32 | 'right': [1], |
---|
| 33 | 'top': [2], |
---|
| 34 | 'left': [3]}, |
---|
[2648] | 35 | maximum_triangle_area = 5, |
---|
[2649] | 36 | filename = 'island.msh' , |
---|
| 37 | interior_regions=[ ([[50,25], [70,25], [70,75], [50,75]], 3)] |
---|
[2638] | 38 | ) |
---|
| 39 | |
---|
| 40 | |
---|
| 41 | |
---|
| 42 | #Create shallow water domain |
---|
| 43 | domain = Domain(mesh_filename = 'island.msh') |
---|
| 44 | domain.smooth = False |
---|
| 45 | domain.set_name('island') |
---|
| 46 | domain.set_default_order(2) |
---|
| 47 | |
---|
| 48 | |
---|
| 49 | #I tried to introduce this parameter top control the h-limiter, |
---|
| 50 | #but it doesn't remove the 'lapping water' |
---|
| 51 | #NEW (ON): I think it has been fixed (or at least reduced significantly) now |
---|
| 52 | # |
---|
| 53 | # beta_h == 1.0 means that the largest gradients (on h) are allowed |
---|
| 54 | # beta_h == 0.0 means that constant (1st order) gradients are introduced |
---|
| 55 | # on h. This is equivalent to the constant depth used previously. |
---|
| 56 | domain.beta_h = 0.9 |
---|
| 57 | |
---|
| 58 | |
---|
| 59 | #------------------------------------------------------------------------------ |
---|
| 60 | # Setup initial conditions |
---|
| 61 | #------------------------------------------------------------------------------ |
---|
| 62 | |
---|
| 63 | def island(x, y): |
---|
| 64 | z = 0*x |
---|
| 65 | for i in range(len(x)): |
---|
| 66 | z[i] = 8*exp( -((x[i]-50)**2 + (y[i]-50)**2)/100 ) |
---|
| 67 | |
---|
| 68 | #z[i] += 0.5*exp( -((x[i]-10)**2 + (y[i]-10)**2)/50 ) |
---|
| 69 | |
---|
| 70 | return z |
---|
| 71 | |
---|
| 72 | def slump(x, y): |
---|
| 73 | z = 0*x |
---|
| 74 | for i in range(len(x)): |
---|
| 75 | z[i] -= 0.7*exp( -((x[i]-10)**2 + (y[i]-10)**2)/200 ) |
---|
| 76 | |
---|
| 77 | return z |
---|
| 78 | |
---|
[2648] | 79 | #domain.set_quantity('friction', 0.1) #Honky dory |
---|
[2731] | 80 | domain.set_quantity('friction', 100) #Creep |
---|
[2638] | 81 | domain.set_quantity('elevation', island) |
---|
| 82 | domain.set_quantity('stage', 1) |
---|
[2648] | 83 | domain.max_timestep = 0.01 |
---|
[2638] | 84 | |
---|
| 85 | |
---|
| 86 | #------------------------------------------------------------------------------ |
---|
| 87 | # Setup boundary conditions (all reflective) |
---|
| 88 | #------------------------------------------------------------------------------ |
---|
| 89 | |
---|
| 90 | Br = Reflective_boundary(domain) |
---|
| 91 | Bd = Dirichlet_boundary([1, 0, 0]) |
---|
| 92 | |
---|
| 93 | domain.set_boundary({'left': Bd, 'right': Bd, 'top': Bd, 'bottom': Bd}) |
---|
| 94 | domain.check_integrity() |
---|
| 95 | |
---|
| 96 | |
---|
| 97 | #------------------------------------------------------------------------------ |
---|
| 98 | # Evolve system through time |
---|
| 99 | #------------------------------------------------------------------------------ |
---|
| 100 | |
---|
| 101 | import time |
---|
| 102 | for t in domain.evolve(yieldstep = 1, finaltime = 100): |
---|
| 103 | domain.write_time() |
---|
| 104 | #if allclose(t, 100): |
---|
| 105 | # Q = domain.get_quantity('stage') |
---|
| 106 | # Q_s = Quantity(domain) |
---|
| 107 | # Q_s.set_values(slump) |
---|
| 108 | # domain.set_quantity('stage', Q + Q_s) |
---|
| 109 | #print ' Volume: ', domain.get_quantity('stage').get_integral() |
---|
| 110 | |
---|
| 111 | print 'Done' |
---|