source: anuga_core/source/anuga/fit_interpolate/general_fit_interpolate.py @ 4614

Last change on this file since 4614 was 4614, checked in by duncan, 17 years ago

Centralising max vertices per cell.

File size: 3.4 KB
Line 
1"""Least squares interpolation.
2
3   Implements a least-squares interpolation.
4
5   Ole Nielsen, Stephen Roberts, Duncan Gray, Christopher Zoppou
6   Geoscience Australia, 2004.
7
8DESIGN ISSUES
9* what variables should be global?
10- if there are no global vars functions can be moved around alot easier
11
12* The public interface
13__init__
14interpolate
15interpolate_block
16
17"""
18
19import time
20import os
21from warnings import warn
22
23from Numeric import zeros, array, Float, Int, dot, transpose, concatenate, \
24     ArrayType, allclose, take, NewAxis, arange
25
26from anuga.caching.caching import cache
27from anuga.abstract_2d_finite_volumes.neighbour_mesh import Mesh
28
29from anuga.utilities.sparse import Sparse, Sparse_CSR
30from anuga.utilities.cg_solve import conjugate_gradient, VectorShapeError
31from anuga.utilities.numerical_tools import ensure_numeric
32from anuga.utilities.polygon import in_and_outside_polygon
33from anuga.utilities.quad import build_quadtree
34
35from anuga.coordinate_transforms.geo_reference import Geo_reference
36from anuga.geospatial_data.geospatial_data import Geospatial_data, \
37     ensure_absolute
38
39# tests fail if 2 is used
40MAX_VERTICES_PER_CELL = 30
41
42class FitInterpolate:
43   
44    def __init__(self,
45                 vertex_coordinates,
46                 triangles,
47                 mesh_origin=None,
48                 verbose=False,
49                 max_vertices_per_cell=None):
50
51
52        """ Build interpolation matrix mapping from
53        function values at vertices to function values at data points
54
55        Inputs:
56
57          vertex_coordinates: List of coordinate pairs [xi, eta] of
58              points constituting a mesh (or an m x 2 Numeric array or
59              a geospatial object)
60              Points may appear multiple times
61              (e.g. if vertices have discontinuities)
62
63          triangles: List of 3-tuples (or a Numeric array) of
64              integers representing indices of all vertices in the mesh.
65
66          mesh_origin: A geo_reference object or 3-tuples consisting of
67              UTM zone, easting and northing.
68              If specified vertex coordinates are assumed to be
69              relative to their respective origins.
70
71          max_vertices_per_cell: Number of vertices in a quad tree cell
72          at which the cell is split into 4.
73
74          Note: Don't supply a vertex coords as a geospatial object and
75              a mesh origin, since geospatial has its own mesh origin.
76        """
77
78        if max_vertices_per_cell == None:
79            max_vertices_per_cell = MAX_VERTICES_PER_CELL
80       
81        #Convert input to Numeric arrays
82        triangles = ensure_numeric(triangles, Int)
83        vertex_coordinates = ensure_absolute(vertex_coordinates,
84                                             geo_reference = mesh_origin)
85
86        #Don't pass geo_reference to mesh.  It doesn't work. (Still??)
87       
88        if verbose: print 'FitInterpolate: Building mesh'       
89        self.mesh = Mesh(vertex_coordinates, triangles)
90        self.mesh.check_integrity()
91       
92        if verbose: print 'FitInterpolate: Building quad tree'
93        self.root = build_quadtree(self.mesh,
94                                   max_points_per_cell = max_vertices_per_cell)
95        #print "self.root",self.root.show()
96       
97       
98    def __repr__(self):
99        return 'Interpolation object based on: ' + repr(self.mesh)
Note: See TracBrowser for help on using the repository browser.