Potential¶
-
class
siegpy.potential.
Potential
(grid, values)[source]¶ Bases:
siegpy.functions.Function
Class defining a generic 1D potential.
Examples
A Potential is a function:
>>> pot = Potential([-1, 0, 1], [-3, 2, 0]) >>> pot.grid array([-1, 0, 1]) >>> pot.values array([-3, 2, 0])
The main difference is that only Potential instances can be added to a potential:
>>> pot += Function([1, 2, 3], [0, -1, 0]) Traceback (most recent call last): TypeError: Cannot add a <class 'siegpy.functions.Function'> to a Potential
Parameters: - grid (list or set or numpy array) – Discretization grid.
- values (list or set or numpy array) – Values of the function evaluated on the grid points.
Raises: ValueError
– If the grid is not made of reals or if thegrid
andvalues
arrays have incoherent lengths.Example
Note that both
grid
andvalues
are converted to numpyarrays:
>>> f = Function([-1, 0, 1], [1, 2, 3])
>>> f.grid
array([-1, 0, 1])
>>> f.values
array([1, 2, 3])
-
__add__
(other)[source]¶ Add two potentials.
Parameters: other (Potential) – Another potential. Returns: Sum of both potentials. Return type: Potential Raises: TypeError
– Ifother
is not aPotential
instance.Examples
Two potentials can be added:
>>> pot1 = Potential([1, 2, 3], [1, 1, 1]) >>> pot2 = Potential([1, 2, 3], [0, -1, 0]) >>> pot = pot1 + pot2 >>> pot.grid array([1, 2, 3]) >>> pot.values array([1, 0, 1])
The previous potentials are unchanged:
>>> pot1.values array([1, 1, 1]) >>> pot2.values array([ 0, -1, 0])