This page contains the tools Package documentation.
Bases: object
MPI Communicator wrapper
Encapsulates capabilities needed for Epetra. Some capabilities are not parallel.
Bases: fipy.tools.serialCommWrapper.SerialCommWrapper
Read a pickled object from a file. Returns the unpickled object. Wrapper for cPickle.load().
Parameters : |
|
---|
Pickle an object and write it to a file. Wrapper for cPickle.dump().
Parameters : |
|
---|
Test to check pickling and unpickling.
>>> from fipy.meshes.grid1D import Grid1D
>>> old = Grid1D(nx = 2)
>>> f, tempfile = write(old)
>>> new = read(tempfile, f)
>>> print old.getNumberOfCells() == new.getNumberOfCells()
True
This python script is ripped from http://www.nightmare.com/medusa/memory-leaks.html
It outputs the top 100 number of outstanding references for each object.
Bases: threading.Thread
This python script is ripped from http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/286222/index_txt
Bases: fipy.tools.commWrapper.CommWrapper
MPI Communicator wrapper
Encapsulates capabilities needed for both Epetra and mpi4py.
The functions provided in ths module replace the Numeric module. The functions work with Variables, arrays or numbers. For example, create a Variable.
>>> from fipy.variables.variable import Variable
>>> var = Variable(value=0)
Take the tangent of such a variable. The returned value is itself a Variable.
>>> v = tan(var)
>>> v
numerix.tan(Variable(value=array(0)))
>>> print float(v)
0.0
Take the tangent of a int.
>>> tan(0)
0.0
Take the tangent of an array.
>>> print tan(array((0,0,0)))
[ 0. 0. 0.]
Eventually, this module will be the only place in the code where Numeric (or numarray (or scipy_core)) is explicitly imported.
Parameters : |
|
---|---|
Returns : | is the -norm of . |
Parameters : |
|
---|---|
Returns : | is the -norm of . |
Parameters : |
|
---|---|
Returns : | is the -norm of . |
Tests whether or not first and second are equal, subect to the given relative and absolute tolerances, such that:
|first - second| < atol + rtol * |second|
This means essentially that both elements are small compared to atol or their difference divided by second‘s value is small compared to rtol.
Returns true if every element of first is equal to the corresponding element of second.
Inverse cosine of ,
>>> print tostring(arccos(0.0), precision=3)
1.571
>>> isnan(arccos(2.0))
True
>>> print tostring(arccos(array((0,0.5,1.0))), precision=3)
[ 1.571 1.047 0. ]
>>> from fipy.variables.variable import Variable
>>> arccos(Variable(value=(0,0.5,1.0)))
numerix.arccos(Variable(value=array([ 0. , 0.5, 1. ])))
Attention
the next should really return radians, but doesn’t
>>> print tostring(arccos(Variable(value=(0,0.5,1.0))), precision=3)
[ 1.571 1.047 0. ]
Inverse hyperbolic cosine of ,
>>> print arccosh(1.0)
0.0
>>> isnan(arccosh(0.0))
True
>>> print tostring(arccosh(array((1,2,3))), precision=3)
[ 0. 1.317 1.763]
>>> from fipy.variables.variable import Variable
>>> arccosh(Variable(value=(1,2,3)))
numerix.arccosh(Variable(value=array([1, 2, 3])))
>>> print tostring(arccosh(Variable(value=(1,2,3))), precision=3)
[ 0. 1.317 1.763]
Inverse sine of ,
>>> print tostring(arcsin(1.0), precision=3)
1.571
>>> isnan(arcsin(2.0))
True
>>> print tostring(arcsin(array((0,0.5,1.0))), precision=3)
[ 0. 0.524 1.571]
>>> from fipy.variables.variable import Variable
>>> arcsin(Variable(value=(0,0.5,1.0)))
numerix.arcsin(Variable(value=array([ 0. , 0.5, 1. ])))
Attention
the next should really return radians, but doesn’t
>>> print tostring(arcsin(Variable(value=(0,0.5,1.0))), precision=3)
[ 0. 0.524 1.571]
Inverse hyperbolic sine of ,
>>> print tostring(arcsinh(1.0), precision=3)
0.881
>>> print tostring(arcsinh(array((1,2,3))), precision=3)
[ 0.881 1.444 1.818]
>>> from fipy.variables.variable import Variable
>>> arcsinh(Variable(value=(1,2,3)))
numerix.arcsinh(Variable(value=array([1, 2, 3])))
>>> print tostring(arcsinh(Variable(value=(1,2,3))), precision=3)
[ 0.881 1.444 1.818]
Inverse tangent of ,
>>> print tostring(arctan(1.0), precision=3)
0.785
>>> print tostring(arctan(array((0,0.5,1.0))), precision=3)
[ 0. 0.464 0.785]
>>> from fipy.variables.variable import Variable
>>> arctan(Variable(value=(0,0.5,1.0)))
numerix.arctan(Variable(value=array([ 0. , 0.5, 1. ])))
Attention
the next should really return radians, but doesn’t
>>> print tostring(arctan(Variable(value=(0,0.5,1.0))), precision=3)
[ 0. 0.464 0.785]
Inverse tangent of a ratio ,
>>> print tostring(arctan2(3.0, 3.0), precision=3)
0.785
>>> print tostring(arctan2(array((0, 1, 2)), 2), precision=3)
[ 0. 0.464 0.785]
>>> from fipy.variables.variable import Variable
>>> arctan2(Variable(value=(0, 1, 2)), 2)
(numerix.arctan2(Variable(value=array([0, 1, 2])), 2))
Attention
the next should really return radians, but doesn’t
>>> print tostring(arctan2(Variable(value=(0, 1, 2)), 2), precision=3)
[ 0. 0.464 0.785]
Inverse hyperbolic tangent of ,
>>> print tostring(arctanh(0.5), precision=3)
0.549
>>> print tostring(arctanh(array((0,0.25,0.5))), precision=3)
[ 0. 0.255 0.549]
>>> from fipy.variables.variable import Variable
>>> arctanh(Variable(value=(0,0.25,0.5)))
numerix.arctanh(Variable(value=array([ 0. , 0.25, 0.5 ])))
>>> print tostring(arctanh(Variable(value=(0,0.25,0.5))), precision=3)
[ 0. 0.255 0.549]
The largest integer ,
>>> print ceil(2.3)
3.0
>>> print ceil(array((-1.5,2,2.5)))
[-1. 2. 3.]
>>> from fipy.variables.variable import Variable
>>> ceil(Variable(value=(-1.5,2,2.5), unit="m**2"))
numerix.ceil(Variable(value=PhysicalField(array([-1.5, 2. , 2.5]),'m**2')))
>>> print ceil(Variable(value=(-1.5,2,2.5), unit="m**2"))
[-1. 2. 3.] m**2
Complex conjugate of ,
>>> print conjugate(3 + 4j) == 3 - 4j
True
>>> print allclose(conjugate(array((3 + 4j, -2j, 10))), (3 - 4j, 2j, 10))
1
>>> from fipy.variables.variable import Variable
>>> var = conjugate(Variable(value=(3 + 4j, -2j, 10), unit="ohm"))
>>> print var.getUnit()
<PhysicalUnit ohm>
>>> print allclose(var.getNumericValue(), (3 - 4j, 2j, 10))
1
Cosine of ,
>>> print allclose(cos(2*pi/6), 0.5)
True
>>> print tostring(cos(array((0,2*pi/6,pi/2))), precision=3, suppress_small=1)
[ 1. 0.5 0. ]
>>> from fipy.variables.variable import Variable
>>> cos(Variable(value=(0,2*pi/6,pi/2), unit="rad"))
numerix.cos(Variable(value=PhysicalField(array([ 0. , 1.04719755, 1.57079633]),'rad')))
>>> print tostring(cos(Variable(value=(0,2*pi/6,pi/2), unit="rad")), suppress_small=1)
[ 1. 0.5 0. ]
Hyperbolic cosine of ,
>>> print cosh(0)
1.0
>>> print tostring(cosh(array((0,1,2))), precision=3)
[ 1. 1.543 3.762]
>>> from fipy.variables.variable import Variable
>>> cosh(Variable(value=(0,1,2)))
numerix.cosh(Variable(value=array([0, 1, 2])))
>>> print tostring(cosh(Variable(value=(0,1,2))), precision=3)
[ 1. 1.543 3.762]
return array of vector dot-products of v1 and v2 for arrays a1 and a2 of vectors v1 and v2
We can’t use numpy.dot() on an array of vectors
Test that Variables are returned as Variables.
>>> from fipy.meshes.grid2D import Grid2D
>>> mesh = Grid2D(nx=2, ny=1)
>>> from fipy.variables.cellVariable import CellVariable
>>> v1 = CellVariable(mesh=mesh, value=((0,1),(2,3)), rank=1)
>>> v2 = CellVariable(mesh=mesh, value=((0,1),(2,3)), rank=1)
>>> dot(v1, v2)._getVariableClass()
<class 'fipy.variables.cellVariable.CellVariable'>
>>> dot(v2, v1)._getVariableClass()
<class 'fipy.variables.cellVariable.CellVariable'>
>>> print rank(dot(v2, v1))
0
>>> print dot(v1, v2)
[ 4 10]
>>> dot(v1, v1)._getVariableClass()
<class 'fipy.variables.cellVariable.CellVariable'>
>>> print dot(v1, v1)
[ 4 10]
>>> v3 = array(((0,1),(2,3)))
>>> type(dot(v3, v3))
<type 'numpy.ndarray'>
>>> print dot(v3, v3)
[ 4 10]
Natural exponent of ,
The largest integer ,
>>> print floor(2.3)
2.0
>>> print floor(array((-1.5,2,2.5)))
[-2. 2. 2.]
>>> from fipy.variables.variable import Variable
>>> floor(Variable(value=(-1.5,2,2.5), unit="m**2"))
numerix.floor(Variable(value=PhysicalField(array([-1.5, 2. , 2.5]),'m**2')))
>>> print floor(Variable(value=(-1.5,2,2.5), unit="m**2"))
[-2. 2. 2.] m**2
Return the shape of arr
>>> getShape(1)
()
>>> getShape(1.)
()
>>> from fipy.variables.variable import Variable
>>> getShape(Variable(1))
()
>>> getShape(Variable(1.))
()
>>> getShape(Variable(1., unit="m"))
()
>>> getShape(Variable("1 m"))
()
indices(dimensions,typecode=None) returns an array representing a grid of indices with row-only, and column-only variation.
>>> NUMERIX.allclose(NUMERIX.array(indices((4, 6))), NUMERIX.indices((4,6)))
1
>>> NUMERIX.allclose(NUMERIX.array(indices((4, 6, 2))), NUMERIX.indices((4, 6, 2)))
1
>>> NUMERIX.allclose(NUMERIX.array(indices((1,))), NUMERIX.indices((1,)))
1
>>> NUMERIX.allclose(NUMERIX.array(indices((5,))), NUMERIX.indices((5,)))
1
Returns which elements of first and second are equal, subect to the given relative and absolute tolerances, such that:
|first - second| < atol + rtol * |second|
This means essentially that both elements are small compared to atol or their difference divided by second‘s value is small compared to rtol.
Natural logarithm of ,
>>> print tostring(log(10), precision=3)
2.303
>>> print tostring(log(array((0.1,1,10))), precision=3)
[-2.303 0. 2.303]
>>> from fipy.variables.variable import Variable
>>> log(Variable(value=(0.1,1,10)))
numerix.log(Variable(value=array([ 0.1, 1. , 10. ])))
>>> print tostring(log(Variable(value=(0.1,1,10))), precision=3)
[-2.303 0. 2.303]
Base-10 logarithm of ,
>>> print log10(10)
1.0
>>> print log10(array((0.1,1,10)))
[-1. 0. 1.]
>>> from fipy.variables.variable import Variable
>>> log10(Variable(value=(0.1,1,10)))
numerix.log10(Variable(value=array([ 0.1, 1. , 10. ])))
>>> print log10(Variable(value=(0.1,1,10)))
[-1. 0. 1.]
The opposite of take. The values of arr at the locations specified by ids are set to the corresponding value of values.
The following is to test improvments to puts with masked arrays. Places in the code were assuming incorrect put behavior.
>>> maskValue = 999999
>>> arr = zeros(3, 'l')
>>> ids = MA.masked_values((2, maskValue), maskValue)
>>> values = MA.masked_values((4, maskValue), maskValue)
>>> put(arr, ids, values) ## this should work
>>> print arr
[0 0 4]
>>> arr = MA.masked_values((maskValue, 5, 10), maskValue)
>>> ids = MA.masked_values((2, maskValue), maskValue)
>>> values = MA.masked_values((4, maskValue), maskValue)
>>> put(arr, ids, values)
>>> print arr ## works as expected
[-- 5 4]
>>> arr = MA.masked_values((maskValue, 5, 10), maskValue)
>>> ids = MA.masked_values((maskValue, 2), maskValue)
>>> values = MA.masked_values((4, maskValue), maskValue)
>>> put(arr, ids, values)
>>> print arr ## should be [-- 5 --] maybe??
[-- 5 999999]
Get the rank of sequence a (the number of dimensions, not a matrix rank) The rank of a scalar is zero.
Note
The rank of a MeshVariable is for any single element. E.g., A CellVariable containing scalars at each cell, and defined on a 9 element Grid1D, has rank 0. If it is defined on a 3x3 Grid2D, it is still rank 0.
Change the shape of arr to shape, as long as the product of all the lenghts of all the axes is constant (the total number of elements does not change).
Sine of ,
>>> print sin(pi/6)
0.5
>>> print sin(array((0,pi/6,pi/2)))
[ 0. 0.5 1. ]
>>> from fipy.variables.variable import Variable
>>> sin(Variable(value=(0,pi/6,pi/2), unit="rad"))
numerix.sin(Variable(value=PhysicalField(array([ 0. , 0.52359878, 1.57079633]),'rad')))
>>> print sin(Variable(value=(0,pi/6,pi/2), unit="rad"))
[ 0. 0.5 1. ]
Hyperbolic sine of ,
>>> print sinh(0)
0.0
>>> print tostring(sinh(array((0,1,2))), precision=3)
[ 0. 1.175 3.627]
>>> from fipy.variables.variable import Variable
>>> sinh(Variable(value=(0,1,2)))
numerix.sinh(Variable(value=array([0, 1, 2])))
>>> print tostring(sinh(Variable(value=(0,1,2))), precision=3)
[ 0. 1.175 3.627]
Square root of ,
>>> print tostring(sqrt(2), precision=3)
1.414
>>> print tostring(sqrt(array((1,2,3))), precision=3)
[ 1. 1.414 1.732]
>>> from fipy.variables.variable import Variable
>>> sqrt(Variable(value=(1, 2, 3), unit="m**2"))
numerix.sqrt(Variable(value=PhysicalField(array([1, 2, 3]),'m**2')))
>>> print tostring(sqrt(Variable(value=(1, 2, 3), unit="m**2")), precision=3)
[ 1. 1.414 1.732] m
Return array of square roots of vector dot-products for arrays a1 and a2 of vectors v1 and v2
Usually used with v1==v2 to return magnitude of v1.
The sum of all the elements of arr along the specified axis.
Selects the elements of a corresponding to indices.
Tangent of ,
>>> print tostring(tan(pi/3), precision=3)
1.732
>>> print tostring(tan(array((0,pi/3,2*pi/3))), precision=3)
[ 0. 1.732 -1.732]
>>> from fipy.variables.variable import Variable
>>> tan(Variable(value=(0,pi/3,2*pi/3), unit="rad"))
numerix.tan(Variable(value=PhysicalField(array([ 0. , 1.04719755, 2.0943951 ]),'rad')))
>>> print tostring(tan(Variable(value=(0,pi/3,2*pi/3), unit="rad")), precision=3)
[ 0. 1.732 -1.732]
Hyperbolic tangent of ,
>>> print tostring(tanh(1), precision=3)
0.762
>>> print tostring(tanh(array((0,1,2))), precision=3)
[ 0. 0.762 0.964]
>>> from fipy.variables.variable import Variable
>>> tanh(Variable(value=(0,1,2)))
numerix.tanh(Variable(value=array([0, 1, 2])))
>>> print tostring(tanh(Variable(value=(0,1,2))), precision=3)
[ 0. 0.762 0.964]
Returns a textual representation of a number or field of numbers. Each dimension is indicated by a pair of matching square brackets ([]), within which each subset of the field is output. The orientation of the dimensions is as follows: the last (rightmost) dimension is always horizontal, so that the frequent rank-1 fields use a minimum of screen real-estate. The next-to-last dimesnion is displayed vertically if present and any earlier dimension is displayed with additional bracket divisions.
Parameters : |
|
---|
This is a wrapper function for the python optparse module. Unfortunately optparse does not allow command line arguments to be ignored. See the documentation for optparse for more details. Returns the argument value.
Parameters : |
|
---|
Bases: fipy.tools.commWrapper.CommWrapper
Vector utility functions that are inexplicably absent from Numeric
removes elements with indices i = start + shift * n where n = 0, 1, 2, ...
>>> prune(numerix.arange(10), 3, 5)
array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
>>> prune(numerix.arange(10), 3, 2)
array([0, 1, 3, 4, 6, 7, 9])
>>> prune(numerix.arange(10), 3)
array([1, 2, 4, 5, 7, 8])
>>> prune(numerix.arange(4, 7), 3)
array([5, 6])
This is a temporary replacement for Numeric.put as it was not doing what we thought it was doing.
Bases: xml.dom.minidom.Document
Returns XML formatted information about current FiPy environment
append some additional information, possibly about a project under a separate svn repository