bvp | |
SympyODE(*varargin, **kwargs) | Represent an ODE. |
IDict(*v, **kw) | |
Solution(*varargin, **kwargs) | Represents the solution to an ODE as returned by colnew. The default version simply ensures that copies are made of the abscissa because the colnew solution will mutate these. |
Transform | Abscissa tranformation objects should honour this interface. |
log_transform(r0, r1, rS) | Implements a logarithmic transform of z in [0, 1] to [r0, r1] |
ODE(*varargin, **kwargs) | Base class to simplify the interface to colnew. |
ODE_1_2(*varargin, **kwargs) | Simplified ODE interface for a single second order allowing for |
Inheritance diagram for mmf.math.ode.deq:
Interface to 1D colnew ode solver.
Here we provide a simplified interface to the colnew boundary value solver. This can solve differential equations for a set of functions of the form
where
is the set of derivatives . Thus, there are differential equations of orders , , , .
Note
Constants may be implemented using equations with in which case is a constant to be found. Likewise, if one of the constraints is that an integrated quantity has a fixed value (total particle number for example), then you can introduce through the first order equation and give the boundary conditions and . These two techniques are often used together to implement the constraint with a Lagrange multiplier that is entered as a constant parameter.
The m_star = m_1 + m_2 + ... m_n boundary conditions are specified by the conditions
at boundary points . (In these formula, the abscissa is implicit.) The solution will be tabulated on the range .
To simplify the interface, it is assumed that the user will give names to the n variables Y_n and define the functions f_(Y_n).
Debugging Tips:
Any system can be reduced to a system of first-order equations by introducing auxiliary variables for the higher orders. I.e. for one can introduce to express this as the system
Let us combine all variables into a single vector so that the system becomes (the first equation is trivial so )
Now express these in terms of new variables as functions . The resulting differentials satisfy
where is the Jacobian of the transformation. We may thus write
Dividing with , we obtain
Everything on the right-hand-side can be expressed in terms of the new variables.
Bases: mmf.objects.StateVars
Represent an ODE.
SympyODE(vars=Required,
eqs=Required,
bcs=Required,
params={})
Specify the original ODE here in terms of the original variables either as a string or using :pkg:`sympy`. The :pkg:`sympy` package will be used to define the various functions required to satisfy the BVP interface.
Examples
>>> class Example1(SympyODE):
... _state_vars = [
... ('vars', ['x', 'u', 'v']),
... ('eqs',
... ['-u(x).diff(x)/x + ((nu/x)**2 -1)*u(x) - u(x).diff(x,x)',
... 'x**(nu+1)*u(x) - v(x).diff(x)']),
... ('bcs',
... [(1, 1e-5, 'u(x) - besselj(nu,x)'),
... (10, 0, 'u(x) - besselj(nu,x)'),
... (5, 1e-5, 'v(x) - x**(nu+1)*besselj(nu+1,x)')]),
... ('nu', 3.4123)]
... process_vars()
>>> e = Example1()
>>> s = e.solve(maximum_mesh_size=300)
Attributes
State Variables: | |
|
List of sympy vars [x, Y_1, Y_2, ..., Y_n], the first of which is the abscissa, and the rest correspond to the variables Y_i. |
|
List of equations defining the system. Each equation should be zero – i.e. the lhs of – and linear in the highest derivative. |
|
List of tuples [(x, g)] where xs = [x_1, x_2, ...] is the set of abscissa for the boundary conditions, and gs = [g_1(x,Z), g_2(x,Z), ...] is the list of equations. Note: the boundary points xs must evaluate to numbers (they cannot contain parameters), the equations gs should explicitly contain the abscissa (to allow later for transformations), but the equations gs are not permitted to have the highest derivative. The xs need not be sorted. |
|
Dictionary of parameter values. The equations can be expressed in terms of additional constants. One can specify values here, or define them directly as state variables. (This dictionary allows you to avoid possible name-clashes.) These values will be preferred if a parameter appears both here and as a state var. |
Methods
all_items() | Return a list [(name, obj)] of (name, object) pairs containing all items available. |
archive(name) | Return a string representation that can be executed to restore the object. |
archive_1([env]) | Return (rep, args, imports). |
initialize(**kwargs) | Calls __init__() passing all assigned attributes. |
items([archive]) | Return a list [(name, obj)] of (name, object) pairs where the |
resume() | Resume calls to __init__() from __setattr__(), |
suspend() | Suspend calls to __init__() from |
This is the initialization routine. It is called after the attributes specified in _state_vars have been assigned.
The user version should perform any after-assignment initializations that need to be performed.
Note
Since all of the initial arguments are listed in kwargs, this can be used as a list of attributes that have “changed” allowing the initialization to be streamlined. The default __setattr__() method will call __init__() with the changed attribute to allow for recalculation.
This recomputing only works for attributes that are assigned, i.e. iff __setattr__() is called. If an attribute is mutated, then __getattr__() is called and there is no (efficient) way to determine if it was mutated.
Computed values with True Computed.save will be passed in through kwargs when objects are restored from an archive. These parameters in general need not be recomputed, but this opens the possibility for an inconsistent state upon construction if a user inadvertently provides these parameters. Note that the parameters still cannot be set directly.
See __init__() Semantics for details.
Methods
all_items() | Return a list [(name, obj)] of (name, object) pairs containing all items available. |
archive(name) | Return a string representation that can be executed to restore the object. |
archive_1([env]) | Return (rep, args, imports). |
initialize(**kwargs) | Calls __init__() passing all assigned attributes. |
items([archive]) | Return a list [(name, obj)] of (name, object) pairs where the |
resume() | Resume calls to __init__() from __setattr__(), |
suspend() | Suspend calls to __init__() from |
This is the initialization routine. It is called after the attributes specified in _state_vars have been assigned.
The user version should perform any after-assignment initializations that need to be performed.
Note
Since all of the initial arguments are listed in kwargs, this can be used as a list of attributes that have “changed” allowing the initialization to be streamlined. The default __setattr__() method will call __init__() with the changed attribute to allow for recalculation.
This recomputing only works for attributes that are assigned, i.e. iff __setattr__() is called. If an attribute is mutated, then __getattr__() is called and there is no (efficient) way to determine if it was mutated.
Computed values with True Computed.save will be passed in through kwargs when objects are restored from an archive. These parameters in general need not be recomputed, but this opens the possibility for an inconsistent state upon construction if a user inadvertently provides these parameters. Note that the parameters still cannot be set directly.
See __init__() Semantics for details.
Bases: dict
Methods
clear | D.clear() -> None. Remove all items from D. |
copy | D.copy() -> a shallow copy of D |
fromkeys(...) | v defaults to None. |
get | D.get(k[,d]) -> D[k] if k in D, else d. d defaults to None. |
has_key | D.has_key(k) -> True if D has a key k, else False |
items | D.items() -> list of D’s (key, value) pairs, as 2-tuples |
iteritems | D.iteritems() -> an iterator over the (key, value) items of D |
iterkeys | D.iterkeys() -> an iterator over the keys of D |
itervalues | D.itervalues() -> an iterator over the values of D |
keys | D.keys() -> list of D’s keys |
notify_update() | |
pop | D.pop(k[,d]) -> v, remove specified key and return the corresponding value. |
popitem | D.popitem() -> (k, v), remove and return some (key, value) pair as a |
setdefault | D.setdefault(k[,d]) -> D.get(k,d), also set D[k]=d if k not in D |
update | D.update([E, ]**F) -> None. Update D from dict/iterable E and F. |
values | D.values() -> list of D’s values |
viewitems | D.viewitems() -> a set-like object providing a view on D’s items |
viewkeys | D.viewkeys() -> a set-like object providing a view on D’s keys |
viewvalues | D.viewvalues() -> an object providing a view on D’s values |
Bases: mmf.objects.StateVars, scikits.bvp1lg.colnew.Solution
Represents the solution to an ODE as returned by colnew. The default version simply ensures that copies are made of the abscissa because the colnew solution will mutate these.
Solution(ispace=Required,
fspace=Required,
ode=Required)
Attributes
Bases: object
Abscissa tranformation objects should honour this interface.
Methods
rdot(x) | Return the derivative dr/dx evaluated at x. |
rdot_r(r) | Return the derivative dr/dx evaluated at r. |
x(r) | Return x(r), the inverse transformation. |
x.__init__(...) initializes x; see help(type(x)) for signature
Bases: mmf.math.ode.deq.Transform
Implements a logarithmic transform of z in [0, 1] to [r0, r1] with typical scale rS at r0.
Methods
rdot(x) | |
rdot_r(r) | |
x(r) |
Transformation from [0, 1] to [r0, r1] with scale rS at r0.
Methods
rdot(x) | |
rdot_r(r) | |
x(r) |
Bases: mmf.objects.StateVars
Base class to simplify the interface to colnew.
ODE(Solution=<class 'mmf.math.ode.deq.Solution'>,
left=None,
right=None,
maximum_mesh_size=1000,
problem_regularity=0,
verbosity=0,
coarsen_initial_guess_mesh=True,
plot=False,
plot_pause=0,
_debug=False)
Attributes
Bases: mmf.math.ode.deq.ODE
Simplified ODE interface for a single second order allowing for transformations.
Original Equation: y’‘(x) = f(x, y, y’)
Transformation: x = s(a) y = t(b)
Transformed system: Q’(a) = f(s(a), t(b), Q)/s’(a) b’(a) = s’(a)/t’(b)*Q(a)
This class requires you to define your Example: A’‘(x) = 2*(A(x) + x*A’(x)) A(-1) = 1 A(2) = exp(3)
Solution: A(x) = exp(x**2-1)
Attributes
collocation_points | |
extra_fixed_points |
Methods
all_items() | Return a list [(name, obj)] of (name, object) pairs containing all items available. |
archive(name) | Return a string representation that can be executed to restore the object. |
archive_1([env]) | Return (rep, args, imports). |
boundary_conditions(j, mu, **kwargs) | This function must return the j‘th boundary condition(s), which should be zero if and only if the boundary condition(s) at x = self.boundary_point[j] is satsified. |
boundary_points | Default value for required attributes. |
check_sol(sol) | This function should check the solution sol, possibly |
initialize(**kwargs) | Calls __init__() passing all assigned attributes. |
items([archive]) | Return a list [(name, obj)] of (name, object) pairs where the |
plotter(idict, **kwargs) | Default plotter. |
resume() | Resume calls to __init__() from __setattr__(), |
solve([sol]) | Return solution. |
suspend() | Suspend calls to __init__() from |
vars | Default value for required attributes. |
This is the initialization routine. It is called after the attributes specified in _state_vars have been assigned.
The user version should perform any after-assignment initializations that need to be performed.
Note
Since all of the initial arguments are listed in kwargs, this can be used as a list of attributes that have “changed” allowing the initialization to be streamlined. The default __setattr__() method will call __init__() with the changed attribute to allow for recalculation.
This recomputing only works for attributes that are assigned, i.e. iff __setattr__() is called. If an attribute is mutated, then __getattr__() is called and there is no (efficient) way to determine if it was mutated.
Computed values with True Computed.save will be passed in through kwargs when objects are restored from an archive. These parameters in general need not be recomputed, but this opens the possibility for an inconsistent state upon construction if a user inadvertently provides these parameters. Note that the parameters still cannot be set directly.
See __init__() Semantics for details.
Attributes
collocation_points | |
extra_fixed_points |
Methods
all_items() | Return a list [(name, obj)] of (name, object) pairs containing all items available. |
archive(name) | Return a string representation that can be executed to restore the object. |
archive_1([env]) | Return (rep, args, imports). |
boundary_conditions(j, mu, **kwargs) | This function must return the j‘th boundary condition(s), which should be zero if and only if the boundary condition(s) at x = self.boundary_point[j] is satsified. |
boundary_points | Default value for required attributes. |
check_sol(sol) | This function should check the solution sol, possibly |
initialize(**kwargs) | Calls __init__() passing all assigned attributes. |
items([archive]) | Return a list [(name, obj)] of (name, object) pairs where the |
plotter(idict, **kwargs) | Default plotter. |
resume() | Resume calls to __init__() from __setattr__(), |
solve([sol]) | Return solution. |
suspend() | Suspend calls to __init__() from |
vars | Default value for required attributes. |
This is the initialization routine. It is called after the attributes specified in _state_vars have been assigned.
The user version should perform any after-assignment initializations that need to be performed.
Note
Since all of the initial arguments are listed in kwargs, this can be used as a list of attributes that have “changed” allowing the initialization to be streamlined. The default __setattr__() method will call __init__() with the changed attribute to allow for recalculation.
This recomputing only works for attributes that are assigned, i.e. iff __setattr__() is called. If an attribute is mutated, then __getattr__() is called and there is no (efficient) way to determine if it was mutated.
Computed values with True Computed.save will be passed in through kwargs when objects are restored from an archive. These parameters in general need not be recomputed, but this opens the possibility for an inconsistent state upon construction if a user inadvertently provides these parameters. Note that the parameters still cannot be set directly.
See __init__() Semantics for details.