Changeset 541


Ignore:
Timestamp:
Nov 15, 2004, 1:51:59 PM (20 years ago)
Author:
ole
Message:

Got oblique analytical solution to work

Location:
inundation/ga/storm_surge
Files:
1 deleted
2 edited

Legend:

Unmodified
Added
Removed
  • inundation/ga/storm_surge/analytical solutions/oblique_test_chris.py

    r536 r541  
    1212# Module imports
    1313#
     14
     15#Were these used?
     16#import visualise2_chris as visualise
     17#import Image, ImageGrab
     18
     19import sys
     20from os import sep
     21sys.path.append('..'+sep+'pyvolution')
     22
     23
     24from shallow_water import Domain, Constant_height
    1425from shallow_water import Transmissive_boundary, Reflective_boundary,\
    1526     Dirichlet_boundary
    16 from domain import oblique_domain, rectangular_domain
    1727
    18 from shallow_water import Friction, Constant_height
    19 import visualise2_chris as visualise
    20 import Image, ImageGrab
     28from math import sqrt, cos, sin, pi
     29from mesh_factory import oblique
     30
    2131
    2232######################
     
    2838lenx = 40.
    2939
    30 domain = oblique_domain(m, n, lenx, leny )
     40points, elements, boundary = oblique(m, n, lenx, leny)
     41domain = Domain(points, elements, boundary)
    3142
    3243# Order of solver
     
    5162    return 0*x
    5263
    53 domain.set_field_values(x_slope, Friction(0))
     64domain.set_quantity('elevation', x_slope)
     65domain.set_quantity('friction', 0.0)
    5466
    5567######################
    5668# Boundary conditions
    5769#
    58 R = Reflective_boundary()
    59 T = Transmissive_boundary()
     70R = Reflective_boundary(domain)
     71T = Transmissive_boundary(domain)
    6072D = Dirichlet_boundary([1.0, 8.57, 0.0])
    6173
     
    6577#Initial condition
    6678h = 0.5
    67 domain.set_conserved_quantities(Constant_height(x_slope, h), None, None)
     79domain.set_quantity('level', Constant_height(x_slope, h) )
     80
    6881
    6982######################
    70 # Visualisation using Visual Python, comment out if not required
    71 #visualise.create_surface(domain)
    72  
    73 ######################
    7483#Evolution
    75 #raw_input('Press key to start simulation')
    7684import time
    7785t0 = time.time()
    78 for t in domain.evolve(max_timestep = 0.1, yieldstep = 0.5, finaltime = 50):
     86for t in domain.evolve(yieldstep = 0.5, finaltime = 50):
    7987    domain.write_time()
    80 
    81 # Remove the following if Visual Python not required   
    82 #    visualise.update(domain, index=0, smooth=True)
    8388   
    8489print 'That took %.2f seconds' %(time.time()-t0)
    8590
    86 print "saving file?"
    87 im = ImageGrab.grab()
    88 im.save("ccube.eps")
     91#print "saving file?"
     92#im = ImageGrab.grab()
     93#im.save("ccube.eps")
    8994
    9095
  • inundation/ga/storm_surge/pyvolution/mesh_factory.py

    r540 r541  
    6363
    6464
    65 # def oblique_mesh(m, n, lenx = 1.0, leny = 1.0, theta = 8.95, origin = (0.0, 0.0),
    66 #                   point_class=Point, element_class=Triangle, mesh_class=Mesh):
    67 #     """Setup a oblique grid of triangles
    68 #     with m segments in the x-direction and n segments in the y-direction
    69 
    70 #     Triangle refers to the actual class or subclass to be instantiated:
    71 #     e.g. if Volume is a subclass of Triangle,
    72 #     this function can be invoked with the keywords
    73 #       oblique_mesh(...,Triangle=Volume, Mesh=Domain)
    74 #     """
    75 
    76 #     from Numeric import array
    77 #     from visual import rate
    78 #     import math
    79 
    80 #     from config import epsilon
    81 
    82 #     E = m*n*2        #Number of triangular elements
    83 #     P = (m+1)*(n+1)  #Number of initial vertices
    84 
    85 #     initialise_consecutive_datastructure(P+E, E,
    86 #                                          point_class,
    87 #                                          element_class,
    88 #                                          mesh_class)
    89 
    90 #     deltax = lenx/float(m)
    91 #     deltay = leny/float(n)
    92 #     a = 0.75*lenx*math.tan(theta/180.*math.pi)
    93 #     x1 = lenx
    94 #     y1 = 0
    95 #     x2 = lenx
    96 #     y2 = leny
    97 #     x3 = 0.25*lenx
    98 #     y3 = leny
    99 #     x4 = x3
    100 #     y4 = 0
    101 #     a2 = a/(x1-x4)
    102 #     a1 = -a2*x4
    103 #     a4 = ((a1 + a2*x3)/y3-(a1 + a2*x2)/y2)/(x2-x3)
    104 #     a3 = 1. - (a1 + a2*x3)/y3 - a4*x3
    105 
    106 #     # Dictionary of vertex objects
    107 #     vertices = {}
    108 
    109 #     for i in range(m+1):
    110 #         x = deltax*i
    111 #         for j in range(n+1):     
    112 #             y = deltay*j
    113 #             if x > 0.25*lenx:
    114 #                 y = a1 + a2*x + a3*y + a4*x*y
     65def oblique(m, n, lenx = 1.0, leny = 1.0, theta = 8.95, origin = (0.0, 0.0)):
     66    """Setup a oblique grid of triangles
     67    with m segments in the x-direction and n segments in the y-direction
     68
     69    """
     70
     71    from Numeric import array
     72    import math
     73
     74    from config import epsilon
     75
     76
     77    deltax = lenx/float(m)
     78    deltay = leny/float(n)
     79    a = 0.75*lenx*math.tan(theta/180.*math.pi)
     80    x1 = lenx
     81    y1 = 0
     82    x2 = lenx
     83    y2 = leny
     84    x3 = 0.25*lenx
     85    y3 = leny
     86    x4 = x3
     87    y4 = 0
     88    a2 = a/(x1-x4)
     89    a1 = -a2*x4
     90    a4 = ((a1 + a2*x3)/y3-(a1 + a2*x2)/y2)/(x2-x3)
     91    a3 = 1. - (a1 + a2*x3)/y3 - a4*x3
     92
     93    # Dictionary of vertex objects
     94    vertices = {}
     95    points = []
     96
     97    for i in range(m+1):
     98        x = deltax*i
     99        for j in range(n+1):     
     100            y = deltay*j
     101            if x > 0.25*lenx:
     102                y = a1 + a2*x + a3*y + a4*x*y
    115103               
    116 #             vertices[i,j] = Point(x + origin[0],y + origin[1])
    117 
    118 #     # Construct 2 elements per element       
    119 #     elements = []
    120 #     for i in range(m):
    121 #         for j in range(n):
    122 #             v1 = vertices[i,j+1]
    123 #             v2 = vertices[i,j]           
    124 #             v3 = vertices[i+1,j+1]           
    125 #             v4 = vertices[i+1,j]
    126  
    127 #             elements.append(element_class(v4,v3,v2)) #Lower               
    128 #             elements.append(element_class(v1,v2,v3)) #Upper   
    129 
    130 #     M = mesh_class(elements)
    131 
    132 #     #Set a default tagging
    133 
     104            vertices[i,j] = len(points)
     105            points.append([x + origin[0], y + origin[1]])
     106
     107    # Construct 2 triangles per element       
     108    elements = []
     109    boundary = {}
     110    for i in range(m):
     111        for j in range(n):
     112            v1 = vertices[i,j+1]
     113            v2 = vertices[i,j]           
     114            v3 = vertices[i+1,j+1]           
     115            v4 = vertices[i+1,j]
     116           
     117            #Update boundary dictionary and create elements
     118            if i == m-1:
     119                boundary[(len(elements), 2)] = 'right'
     120            if j == 0:
     121                boundary[(len(elements), 1)] = 'bottom'               
     122            elements.append([v4,v3,v2]) #Lower
     123
     124            if i == 0:
     125                boundary[(len(elements), 2)] = 'left'
     126            if j == n-1:
     127                boundary[(len(elements), 1)] = 'top'
     128             
     129            elements.append([v1,v2,v3]) #Upper
     130
     131    return points, elements, boundary       
     132
     133#OLD FORMULA FOR SETTING BOUNDARY TAGS - OBSOLETE NOW             
    134134#     for id, face in M.boundary:
    135135
     
    159159#             print face, id, id%m, m, n
    160160#             raise 'Unknown boundary'         
    161     
     161#   
    162162#     return M
     163
     164
    163165
    164166def from_polyfile(name):
Note: See TracChangeset for help on using the changeset viewer.