Changeset 2526


Ignore:
Timestamp:
Mar 12, 2006, 9:25:40 PM (18 years ago)
Author:
ole
Message:

Moved more general numerical functionality into utilities/numerical_tools.py

Location:
inundation
Files:
14 edited

Legend:

Unmodified
Added
Removed
  • inundation/pyvolution/data_manager.py

    r2521 r2526  
    30863086    from data_manager import get_dataobject
    30873087    from os import sep, path
    3088     from util import mean
     3088    from utilities.numerical_tools import mean
    30893089
    30903090    if verbose == True:print 'Creating domain from', filename
  • inundation/pyvolution/least_squares.py

    r2516 r2526  
    11341134        from math import pi, cos, sin, sqrt
    11351135        from Numeric import zeros, Float
    1136         from util import mean       
     1136        from utilities.numerical_tools import mean       
    11371137
    11381138        if self.spatial is True:
  • inundation/pyvolution/mesh.py

    r2502 r2526  
    495495        from config import epsilon
    496496        from math import pi
    497         from util import anglediff
     497        from utilities.numerical_tools import anglediff
    498498
    499499        N = self.number_of_elements
  • inundation/pyvolution/quantity.py

    r2516 r2526  
    11891189
    11901190    from Numeric import zeros, Float
    1191     from util import gradient
     1191    from utilitites.numerical_tools import gradient
    11921192
    11931193    centroid_coordinates = quantity.domain.centroid_coordinates
  • inundation/pyvolution/test_data_manager.py

    r2520 r2526  
    55import copy
    66from Numeric import zeros, array, allclose, Float
    7 from util import mean
     7from utilities.numerical_tools import mean
    88import tempfile
    99import os
  • inundation/pyvolution/test_least_squares.py

    r2502 r2526  
    10851085        #Check basic interpolation of one quantity using averaging
    10861086        #(no interpolation points or spatial info)
    1087         from util import mean       
     1087        from utilities.numerical_tools import mean       
    10881088        I = Interpolation_function(time, [mean(Q[0,:]),
    10891089                                          mean(Q[1,:]),
  • inundation/pyvolution/test_quantity.py

    r2347 r2526  
    10651065        from shallow_water import Domain, Transmissive_boundary
    10661066        from Numeric import zeros, Float
    1067         from util import mean
     1067        from utilities.numerical_tools import mean
    10681068
    10691069        #Create basic mesh
     
    11551155        from shallow_water import Domain, Transmissive_boundary
    11561156        from Numeric import zeros, Float
    1157         from util import mean
     1157        from utilities.numerical_tools import mean
    11581158
    11591159
  • inundation/pyvolution/test_shallow_water.py

    r2516 r2526  
    16851685        domain = Domain(points, vertices, boundary)
    16861686        domain.smooth = False
    1687         domain.default_order=2
     1687        domain.default_order = 2
    16881688        domain.beta_h = 0.2
     1689        domain.set_quantities_to_be_stored(['stage'])
    16891690
    16901691        #IC
  • inundation/pyvolution/test_util.py

    r2509 r2526  
    3838    #                    'distance is wrong!')
    3939
    40     def test_angle(self):
    41         from util import angle
    42 
    43         assert allclose(angle([1.0, 1.0])/pi*180, 45.0)
    44 
    45 
    46     def test_anglediff(self):
    47         from util import anglediff
    48 
    49         assert allclose(anglediff([0.0, 1.], [1.0, 1.0])/pi*180, 45.0)
    50 
    51 
    5240
    5341    def test_file_function_time1(self):
     
    131119        domain1 = Domain(points, vertices, boundary)
    132120
    133         from util import mean
     121        from utilities.numerical_tools import mean
    134122        domain1.reduction = mean
    135123        domain1.smooth = True #NOTE: Mimic sww output where each vertex has
     
    331319       
    332320
    333         from util import mean
     321        from utilities.numerical_tools import mean     
    334322        domain1.reduction = mean
    335323        domain1.smooth = True #NOTE: Mimic sww output where each vertex has
  • inundation/pyvolution/util.py

    r2516 r2526  
    88import utilities.polygon
    99from warnings import warn
    10 
    11 
    12 def angle(v):
    13     """Compute angle between e1 (the unit vector in the x-direction)
    14     and the specified vector
    15     """
    16 
    17     from math import acos, pi, sqrt
    18     from Numeric import sum, array
    19 
    20     l = sqrt( sum (array(v)**2))
    21     v1 = v[0]/l
    22     v2 = v[1]/l
    23 
    24 
    25     theta = acos(v1)
    26    
    27     #try:
    28     #   theta = acos(v1)
    29     #except ValueError, e:
    30     #    print 'WARNING (util.py): Angle acos(%s) failed: %s' %(str(v1), e)
    31     #
    32     #    #FIXME, hack to avoid acos(1.0) Value error
    33     #    # why is it happening?
    34     #    # is it catching something we should avoid?
    35     #    #FIXME (Ole): When did this happen? We need a unit test to
    36     #    #reveal this condition or otherwise remove the hack
    37     #   
    38     #    s = 1e-6
    39     #    if (v1+s >  1.0) and (v1-s < 1.0) :
    40     #        theta = 0.0
    41     #    elif (v1+s >  -1.0) and (v1-s < -1.0):
    42     #        theta = 3.1415926535897931
    43     #    print 'WARNING (util.py): angle v1 is %f, setting acos to %f '\
    44     #          %(v1, theta)
    45 
    46     if v2 < 0:
    47         #Quadrant 3 or 4
    48         theta = 2*pi-theta
    49 
    50     return theta
    51 
    52 
    53 def anglediff(v0, v1):
    54     """Compute difference between angle of vector x0, y0 and x1, y1.
    55     This is used for determining the ordering of vertices,
    56     e.g. for checking if they are counter clockwise.
    57 
    58     Always return a positive value
    59     """
    60 
    61     from math import pi
    62 
    63     a0 = angle(v0)
    64     a1 = angle(v1)
    65 
    66     #Ensure that difference will be positive
    67     if a0 < a1:
    68         a0 += 2*pi
    69 
    70     return a0-a1
    71 
    72 
    73 def mean(x):
    74     from Numeric import sum
    75     return sum(x)/len(x)
    76 
    7710
    7811
     
    465398
    466399
     400def angle(v):
     401    """Temporary Interface to new location"""
     402
     403    import utilities.numerical_tools as NT     
     404   
     405    msg = 'angle has moved from util.py.  '
     406    msg += 'Please use "from utilities.numerical_tools import angle"'
     407    warn(msg, DeprecationWarning)
     408
     409    return NT.angle(v)
     410   
     411def anglediff(v0, v1):
     412    """Temporary Interface to new location"""
     413
     414    import utilities.numerical_tools as NT
     415   
     416    msg = 'anglediff has moved from util.py.  '
     417    msg += 'Please use "from utilities.numerical_tools import anglediff"'
     418    warn(msg, DeprecationWarning)
     419
     420    return NT.anglediff(v0, v1)   
     421
     422   
     423def mean(x):
     424    """Temporary Interface to new location"""
     425
     426    import utilities.numerical_tools as NT   
     427   
     428    msg = 'mean has moved from util.py.  '
     429    msg += 'Please use "from utilities.numerical_tools import mean"'
     430    warn(msg, DeprecationWarning)
     431
     432    return NT.mean(x)   
     433
    467434def point_on_line(*args, **kwargs):
    468435    """Temporary Interface to new location"""
  • inundation/test_all.py

    r2390 r2526  
    2323exclude_dirs = ['pypar_dist', #Special requirements
    2424                'props', 'wcprops', 'prop-base', 'text-base', '.svn', #Svn
    25                 'tmp']#,
    26                 #'pmesh']         #Name conflict on my home machine (Ole)       
     25                'tmp',
     26                'pmesh']         #Name conflict on my home machine (Ole)       
    2727
    2828
  • inundation/triangle/triang.c

    r2142 r2526  
    5353
    5454#include "Python.h"
     55
    5556
    5657
  • inundation/utilities/numerical_tools.py

    r2516 r2526  
    55
    66import Numeric
     7
     8
     9
     10def angle(v):
     11    """Compute angle between e1 (the unit vector in the x-direction)
     12    and the specified vector
     13    """
     14
     15    from math import acos, pi, sqrt
     16    from Numeric import sum, array
     17
     18    l = sqrt( sum (array(v)**2))
     19    v1 = v[0]/l
     20    v2 = v[1]/l
     21
     22
     23    theta = acos(v1)
     24   
     25    #try:
     26    #   theta = acos(v1)
     27    #except ValueError, e:
     28    #    print 'WARNING (util.py): Angle acos(%s) failed: %s' %(str(v1), e)
     29    #
     30    #    #FIXME, hack to avoid acos(1.0) Value error
     31    #    # why is it happening?
     32    #    # is it catching something we should avoid?
     33    #    #FIXME (Ole): When did this happen? We need a unit test to
     34    #    #reveal this condition or otherwise remove the hack
     35    #   
     36    #    s = 1e-6
     37    #    if (v1+s >  1.0) and (v1-s < 1.0) :
     38    #        theta = 0.0
     39    #    elif (v1+s >  -1.0) and (v1-s < -1.0):
     40    #        theta = 3.1415926535897931
     41    #    print 'WARNING (util.py): angle v1 is %f, setting acos to %f '\
     42    #          %(v1, theta)
     43
     44    if v2 < 0:
     45        #Quadrant 3 or 4
     46        theta = 2*pi-theta
     47
     48    return theta
     49
     50
     51def anglediff(v0, v1):
     52    """Compute difference between angle of vector x0, y0 and x1, y1.
     53    This is used for determining the ordering of vertices,
     54    e.g. for checking if they are counter clockwise.
     55
     56    Always return a positive value
     57    """
     58
     59    from math import pi
     60
     61    a0 = angle(v0)
     62    a1 = angle(v1)
     63
     64    #Ensure that difference will be positive
     65    if a0 < a1:
     66        a0 += 2*pi
     67
     68    return a0-a1
     69
    770
    871def mean(x):
  • inundation/utilities/test_numerical_tools.py

    r2516 r2526  
    1818    def tearDown(self):
    1919        pass
     20
     21
     22    def test_angle(self):
     23        assert allclose(angle([1.0, 1.0])/pi*180, 45.0)
     24
     25
     26    def test_anglediff(self):
     27        assert allclose(anglediff([0.0, 1.], [1.0, 1.0])/pi*180, 45.0)
    2028
    2129
Note: See TracChangeset for help on using the changeset viewer.