source: inundation/parallel/run_sw_lost_mass_simpler.py @ 2920

Last change on this file since 2920 was 1636, checked in by ole, 19 years ago

Fixed 'lost mass' conservation problem and added unit test, that reveals it.


File size: 2.0 KB
Line 
1#!/usr/bin/env/python
2#########################################################
3#
4# Shows problem of conservation of mass. Due to material being
5# removed if too shallow. Can lead to problems if timestep
6# set very small.
7#
8#
9#
10#  Authors: Linda Stals, Steve Roberts, Matthew Hardy, Ole Nielsen
11#  July 2005
12#
13#
14#########################################################
15
16
17##############################################
18# Change min_depth and see how larger values aggravate the problem
19yieldstep = 0.1
20finaltime = 10.0
21#min_depth = 1.0e-4
22min_depth = 1.0e-2
23
24
25import sys
26from os import sep; sys.path.append('..'+sep+'pyvolution')
27from mesh_factory import rectangular
28from shallow_water import Domain, Reflective_boundary
29
30
31
32#Create shallow water domain
33points, vertices, boundary = rectangular(50, 50, len1=500, len2=500)
34domain = Domain(points, vertices, boundary)
35domain.smooth = False
36domain.visualise = True
37domain.default_order = 1
38domain.minimum_allowed_height = min_depth
39print 'Extent', domain.get_extent()
40
41# Set initial condition
42class Set_IC:
43    """Set an initial condition with a constant value, for x0<x<x1
44    """
45
46    def __init__(self, x0=0.25, x1=0.5, h=1.0):
47        self.x0 = x0
48        self.x1 = x1
49        self.= h
50
51    def __call__(self, x, y):
52        return self.h*((x>self.x0)&(x<self.x1))
53
54
55domain.set_quantity('stage', Set_IC(200.0,300.0,5.0))
56
57try:
58    domain.initialise_visualiser()
59except:
60    print 'No visualiser'
61else:   
62    domain.visualiser.scale_z['stage'] = 0.2
63    domain.visualiser.scale_z['elevation'] = 0.05
64   
65
66#Boundaries
67R = Reflective_boundary(domain)
68domain.set_boundary( {'left': R, 'right': R, 'top':R, 'bottom': R} )
69
70
71# Evolution
72print 'Minimal allowed water height = ', domain.minimum_allowed_height
73for t in domain.evolve(yieldstep = yieldstep, finaltime = finaltime):
74    print 'Integral stage = ', domain.quantities['stage'].get_integral(),' Time = ',domain.time
75
76
Note: See TracBrowser for help on using the repository browser.