(press launch binder to run the examples.ipynb)
PyModPDE is a Python software that generates the modified equation for a first order time dependent partial differential equation (PDE) of the form
Given a certain finite difference scheme for the PDE,
PyModPDE computes the amplification factor of the finite difference scheme and also returns the the modified equation in the form
where, in general, there are inifinitely more terms in the modified equation compared to the original PDE (P > M).
To use PyModPDE, one has to instantiate a first order time dependent differential equation object by calling its constructor that has the following signature
DifferentialEquation(dependentVarName,independentVarsNames,indices=[i, j, k], timeIndex=n)
Once the user constructs an object of type DifferentialEquation
, the next step is to start constructing the right-hand-side RHS for this equation. Two methods are available to achieve this: the first is to use the member function expr
which has the following signature
expr(order, directionName, time, stencil)
The second method is to use the dependent variable name
, the indices
, and the differential elements of the independent variable defined by the user, d<independentVarsNames>
. The signature of the member function <dependentVarName>
is as follow
<dependentVarName>(time, **kwargs)
time
here is the discrete time at which the expression of the dependent variable is evaluated ex: n+1, n, ...
. kwargs
are indicies of the spatial points at which this expression is evaluated, ex: x=i+1, y=j, ...
.
After the construction of the rhs expression using one the two previous methods or a combination of both the user can set the rhs for this differential equation by calling the member function set_rhs
that have the following signature
set_rhs(expression)
where expression
is a symbolic expression of the rhs constructed using the previously described methods.
Now the member function, generate_modified_equation(...)
, can be used to generate the modified equation up to certain number of terms that the user specify, and return the modified equation in latex form. The signature of generate_modified_equation
is as follow
generate_modified_equation(nterms)
where nterms
is a positive integer that indicates the total number of terms in the modified equation.
Below are some examples of using the PyModPDE software.
Starting with an example of using expr(...)
with the advection equation in one dimension using Forward Euler for time discretization and UPWIND for spatial discretization
from src.pymodpde import DifferentialEquation, i, n
# defining the advection velocity
a= symbols('a')
#constructing a time dependent differential equation
DE = DifferentialEquation(dependentVarName='u',independentVarsNames=['x'])
# method I of constructing the rhs:
advectionTerm1 = DE.expr(order=1, directionName='x', time=n, stencil=[-1, 0])
# setting the rhs of the differential equation
DE.set_rhs(- a * advectionTerm1 )
# displaying the amplification factor
DE.generate_amp_factor()
# computing and displaying the modified equation up to two terms
DE.generate_modified_equation(nterms=2)
Similarly, one can use the <dependentVarName>(...)
instead of expr(...)
to construct the discretization of the rhs
from src.pymodpde import DifferentialEquation, i, n
# defining the advection velocity
a= symbols('a')
#constructing a time dependent differential equation
DE = DifferentialEquation(dependentVarName='u',independentVarsNames=['x'])
# method II of constructing the rhs:
advectionTerm = (DE.u(time=n, x=i) - DE.u(time=n, x=i-1))/DE.dx
# setting the rhs of the differential equation
DE.set_rhs(- a * advectionTerm )
# displaying the amplification factor
DE.generate_amp_factor()
# computing and displaying the modified equation up to two terms
DE.generate_modified_equation(nterms=2)