Pyclaw utility methods
Authors: | Kyle T. Mandli (2008-08-07) Initial version Randall J. LeVeque (2009-01-01) Added svn revision Kyle T. Mandli (2009-03-01) Added topo file utilities |
---|
Simple frame counter
Simple frame counter to keep track of current frame number. This can also be used to keep multiple runs frames seperated by having multiple counters at once.
Initializes to 0
Compiles and wraps fortran source into a callable module in python.
This function uses f2py to create an interface from python to the fortran sources in source_list. The source_list can either be a list of names of source files in which case compile_library will search for the file in local_path and then in library_path. If a path is given, the file will be checked to see if it exists, if not it will look for the file in the above resolution order. If any source file is not found, an IOException is raised.
The list interface_functions allows the user to specify which fortran functions are actually available to python. The interface functions are assumed to be in the file with their name, i.e. claw1 is located in ‘claw1.f95’ or ‘claw1.f’.
The interface from fortran may be different than the original function call in fortran so the user should make sure to check the automatically created doc string for the fortran module for proper use.
Source files will not be recompiled if they have not been changed.
One set of options of note is for enabling OpenMP, it requires the usual fortran flags but the OpenMP library also must be compiled in, this is done with the flag -lgomp. The call to compile_library would then be:
compile_library(src,module_name,f2py_flags=’-lgomp’,FFLAGS=’-fopenmp’)
For complete optimization use:
FFLAGS=’-O3 -fopenmp -funroll-loops -finline-functions -fdefault-real-8’
Input: |
|
---|
Constructs a function handle from the file at path.
This function will attempt to construct a function handle from the python file at path.
Input: |
|
---|---|
Output: |
|
Converts a fortran format double to a float
Converts a fortran format double to a python float.
number: is a string representation of the double. Number should be of the form “1.0d0”
Given a set of (x,z) locations, create a lambda function
Create a lambda function that when evaluated will give the topgraphy height at the point (x,y).
Example: |
---|
>>> f = create_topo_profile_func(loc)
>>> b = f(x,y)
Input: |
|
---|
Read data a single line from an input file
Reads one line from an input file and returns an array of values
inputfile: a file pointer to an open file object num_entries: number of entries that should be read, defaults to only 1 type: Type of the values to be read in, they all most be the same type
This function will return either a single value or an array of values depending on if num_entries > 1
Read in a topography file from path of type topo_type.
This utility function is for use with GeoClaw. Please to refer to GeoClaw’s documentation for more details.
Input: |
|
---|---|
Output: |
|
Write out a topo1 file to the file at path.
This utility function is for use with GeoClaw. Please to refer to GeoClaw’s documentation for more details.
Input: |
|
---|
Topo Type | Description |
---|---|
1 | Standard GIS format: 3 columns with longitude, latitude, and z in meters or x, y, z in one row |
2 | One z value per line with header |
3 | One row of z values per line with header |
Header format is
xxxx ncols
xxxx nrows
xxxx xllcorner
xxxx yllcorner
xxxx cellsize
xxxx NODATA_value
z values are positive for topography, negative for bathymetry.
Values are ordered from upper left corner, moving east across each row (y fixed, x increasing) and then south (y decreasing).
The region covered by this file should be refined to at least minlevel and at most maxlevel over the time interval specified.
If a point is covered by several regions, the largest values of minlevel and maxlevel from all such regions are used.
Refinement may also be forced or allowed by the minlevel and maxlevel parameters for the regions specified in setregions.data or setmovetopo.data.
At points that lie far from shore (where h is greater than depthdeep), refinement is only allowed to level maxleveldeep. These parameters are set in setgeo.data.
In setting topography in a computation, the finest topography available will be used for each grid cell. If a grid cells lies partially but not entirely in a topo file then a coarser topo file will be used for the remainder of the cell (with area-weighted averaging).
The order of topo files in the list above should not matter.