josie package¶
Subpackages¶
- josie.bn package
- josie.boundary package
- josie.euler package
- josie.fluid package
- josie.general package
- josie.heat package
- josie.io package
- josie.mesh package
- josie.ns package
- josie.plot package
- josie.scheme package
- josie.twofluid package
Submodules¶
josie.bc module¶
- class josie.bc.BoundaryCondition(bc)¶
Bases:
object
A
BoundaryCondition
is a collection ofScalarBC
, one per eachfields
of theProblem
.- bc¶
A
State
instance whose elements per each field are not float butScalarBC
instead>>> from josie.state import StateTemplate >>> MyState = StateTemplate("u", "v") >>> mybc = BoundaryCondition(MyState(Dirichlet(0), Neumann(1)))
- __call__(cells, boundary, t)¶
- Parameters
mesh – A
Mesh
object that contains informations on cells data and time instantboundary (Boundary) – A
Boundary
object representing the mesh boundary on which theBoundaryCondition
must be appliedt (float) – The time instant to be used to update time dependent
ScalarBC
- class josie.bc.Dirichlet(value: ImposedValue, constant: bool = False)¶
Bases:
josie.bc.ScalarBC
A
ScalarBC
that fixes a value of a field on the boundary.Assuming we want to impose the value on the (left, as an example) boundary, we can assume that the value on the boundary is approximated by:
That means we can impose the
ScalarBC
assigning the value ofto the ghost cell.
- Parameters
value –
The value of the field to be imposed on the boundary. It can have different types:
A
float
. Then it’s the scalar constant value for the
individual field for which we want to apply the BC for. In this case the object returned is of type
_ConstantDirichlet
in order to optimize since we know it’s constantA
BCCallable
. It is called on the cells of the boundary in
order to provide a non-constant boundary condition
A
, each element isState
of size
one of the two previous options. Used as a shortcut to impose the same
ScalarBC
for all the fieldsconstant –
Set this flag to
True
to explicitly force the creation of a constant boundary condition. A constant BC is optimized to reduce the number of calls.Dirichlet
normally is capable to understand automatically if you are providing a constant imposed value: if you provide a constant scalarfloat
orint
(or aState
containing a scalar value for each field). If you provide aBCCallable
then it cannot automatically infer it your callable is actually only a function of space (i.e. it does not change at every time step) or not. If you want to optimize the call, you need to explicitly setconstant
toTrue
.
- set_value¶
A
SetValueCallable
that can be used to provide a specific value theScalarBC
needs to impose. E.g. * In the case ofDirichlet
, theset_value
gives the value of the fields to impose on the boundary.In the case of
Neumann
it provides a callable that returns
the value of the gradient to impose on the boundary
- Type
BCCallable
- __call__(cells, ghost_cells, field, t)¶
- Parameters
cells (CellSet) – A
CellSet
containing the state of the mesh cellsghosts_cells – A
CellSet
containing the ghost cells associated to theBoundary
theBoundaryCondition
is applied tofield (int) – The field to which the
ScalarBC
is applied tot (float) – The time instant to which this
ScalarBC
must be evaluated (useful for time-dependent BCs)
- Returns
- Return type
The value of the field on the ghost cell
- set_value: BCCallable¶
- class josie.bc.Neumann(value: ImposedValue, constant: bool = False)¶
Bases:
josie.bc.Dirichlet
A
ScalarBC
that fixes a value of the gradient of a field on the boundary.Assuming we want to impose the value of the gradient of the state on the (left, as an example) boundary, we can assume that the value of the gradient on the boundary is approximated by:
That means we can impose the
ScalarBC
assigning the value ofto the ghost cell (assuming a )
- Parameters
value –
The value of the field to be imposed on the boundary. It can have different types:
A
float
. Then it’s the scalar constant value for the
individual field for which we want to apply the BC for
A
Callable[[CellSet, t], np.ndarray]
. It is called on the
cells of the boundary in order to provide a non-constant boundary condition
A
, each element isState
of size
one of the two previous options. Used as a shortcut to impose the same
ScalarBC
for all the fields
- __call__(cells, ghost_cells, field, t)¶
- Parameters
cells (CellSet) – A
CellSet
containing the state of the mesh cellsghosts_cells – A
CellSet
containing the ghost cells associated to theBoundary
theBoundaryCondition
is applied tofield (int) – The field to which the
ScalarBC
is applied tot (float) – The time instant to which this
ScalarBC
must be evaluated (useful for time-dependent BCs)
- Returns
- Return type
The value of the field on the ghost cell
- set_value: BCCallable¶
- class josie.bc.NeumannDirichlet(neumann_value: ImposedValue, dirichlet_value: ImposedValue, partition_fun: Callable[[np.ndarray], np.ndarray])¶
Bases:
josie.bc.ScalarBC
A
ScalarBC
that applies aDirichlet
on a part of the domain and aNeumann
on the rest of it.- Parameters
neumann_value – The value of the gradient to use for the
Neumann
partition of the boundarydirichlet_value – The value of the
State
to use for theDirichlet
partition of the boundarypartition_fun (Callable[[josie.bc.NeumannDirichlet, numpy.ndarray], numpy.ndarray]) – A callable that takes as input the coordinates of the boundary cells and returns the indices of the cells for which the
Dirichlet
boundary condition has to be applied
- __call__(cells, ghost_cells, field, t)¶
- Parameters
cells (CellSet) – A
CellSet
containing the state of the mesh cellsghosts_cells – A
CellSet
containing the ghost cells associated to theBoundary
theBoundaryCondition
is applied tofield (int) – The field to which the
ScalarBC
is applied tot (float) – The time instant to which this
ScalarBC
must be evaluated (useful for time-dependent BCs)
- Returns
- Return type
The value of the field on the ghost cell
- dirichlet: josie.bc.Dirichlet¶
- init(cells)¶
This method is used to initialize the datastructures used to store the ghost values and avoid multiple allocations.
It’s useful for constant
ScalarBC
to avoid to recompute the same value at each time step: you just store it ones hereBy default it does nothing
- neumann: josie.bc.Neumann¶
- partition_fun: Callable[[josie.bc.NeumannDirichlet, numpy.ndarray], numpy.ndarray]¶
- class josie.bc.Periodic(side)¶
Bases:
josie.bc.BoundaryCondition
A
BoundaryCondition
that connects one side of the domain to the other. In general is more straighforward to use the :func`make_periodic` function on a couple ofBoundaryCurve
that needs to be linked periodicallyThat means the neighbour cells of the cells on one domain are the cells on the other side of the domain. In other words, as an example, given a cell on the left boundary, identified by the indices , i.e. , its west neighbour cell needs to be , being the number of cells along the -direction (i.e. for increasing index )
- Parameters
side (
PeriodicSide
) – The side on which the Periodic BC is configured- Raises
ValueError – If side is not recognized
- __call__(cells, boundary, t)¶
- Parameters
mesh – A
Mesh
object that contains informations on cells data and time instantboundary (Boundary) – A
Boundary
object representing the mesh boundary on which theBoundaryCondition
must be appliedt (float) – The time instant to be used to update time dependent
ScalarBC
- class josie.bc.PeriodicSide(value=<no_arg>, names=None, module=None, type=None, start=1, boundary=None)¶
Bases:
josie.data.NoAliasEnum
A Enum encapsulating the 4 indexing possibilities of a
Periodic
ScalarBC
- BOTTOM = (slice(None, None, None), -1)¶
- LEFT = (-1, slice(None, None, None))¶
- RIGHT = (0, slice(None, None, None))¶
- TOP = (slice(None, None, None), 0)¶
- class josie.bc.ScalarBC¶
Bases:
abc.ABC
A
ScalarBC
is implemented as a callable that sets the equivalent cell value for the ghost cells for the specific field- abstract __call__(cells, ghost_cells, field, t)¶
- Parameters
cells (CellSet) – A
CellSet
containing the state of the mesh cellsghosts_cells – A
CellSet
containing the ghost cells associated to theBoundary
theBoundaryCondition
is applied tofield (int) – The field to which the
ScalarBC
is applied tot (float) – The time instant to which this
ScalarBC
must be evaluated (useful for time-dependent BCs)
- Returns
- Return type
The value of the field on the ghost cell
- class josie.bc.SetValueCallable(value)¶
Bases:
object
Used to convert the bare float value to a callable returning constant value for all the cells. Used for
Dirichlet
and children classes- __call__(cells, t)¶
Call self as a function.
- Return type
np.ndarray
- josie.bc.make_periodic(first, second, direction)¶
This handy function takes as arguments two opposed BoundaryCurve and configures them correctly to provide periodic behaviour.
- Parameters
first (
BoundaryCurve
) – The firstBoundaryCurve
to linksecond (
BoundaryCurve
) – The secondBoundaryCurve
to linkdirection (
Direction
) – The direction on which the twoBoundaryCurve
are periodically connected
- Return type
Tuple
[BoundaryCurve
,BoundaryCurve
]- Returns
first – The first
BoundaryCurve
whose bc attribute is correctly configuredsecond – The second
BoundaryCurve
whose bc attribute is correctly configured
josie.data module¶
- class josie.data.NoAliasEnum(value=<no_arg>, names=None, module=None, type=None, start=1, boundary=None)¶
Bases:
aenum.Enum
Allow pickling of NoAlias IntEnum
- class josie.data.NoAliasIntEnum(value=<no_arg>, names=None, module=None, type=None, start=1, boundary=None)¶
Bases:
josie.data.NoAliasEnum
,aenum.IntEnum
An enumeration.
- class josie.data.StateElement(time, data)¶
Bases:
object
An handy class to store the state of a simulation
- data: Dict[str, numpy.ndarray]¶
- time: float¶
- josie.data.unpickle_noaliasenum(cls, name)¶
josie.dimension module¶
josie.fields module¶
- class josie.fields.Field(name: str, value: int)¶
Bases:
int
A class that acts as a
int
used inFieldsMeta
to store field name and its value- name: str¶
- value: int¶
- class josie.fields.Fields(clsname: Optional[str] = None, fields: Optional[dict] = None, *args, **kwargs)¶
Bases:
object
- class josie.fields.FieldsMeta(name, bases, clsdict)¶
Bases:
type
This metaclass reproduces in a simpler form the behaviour of
Enum
. It tracks all the defined attributes of a class, it precomputes the number of fields and replaces the fields that have no int value with the corresponding int- names()¶
Returns a list of field names
- Return type
List
[str
]
josie.geometry module¶
josie.math module¶
General purpose math primitives
- class josie.math.Direction(value)¶
Bases:
enum.IntEnum
An
Enum
encapsulating the coordinates indices- X = 0¶
- Y = 1¶
- Z = 2¶
- class josie.math.R3¶
Bases:
object
An
Enum
encapsulating the unit vectors for a cartesia R2 space- X = array([1., 0.])¶
- Y = array([0., 1.])¶
- josie.math.map01to(x, a, b)¶
Maps in
josie.nbconvert module¶
- class josie.nbconvert.BinderBadgePreprocessor(**kwargs)¶
Bases:
nbconvert.preprocessors.base.Preprocessor
This preprocessor adds a BinderBadge on top of the notebook
- BINDER_URL = 'https://mybinder.org'¶
- preprocess(nb, resources)¶
Preprocessing to apply on each notebook.
Must return modified nb, resources.
If you wish to apply your preprocessing to each cell, you might want to override preprocess_cell method instead.
- Parameters
nb (NotebookNode) – Notebook being converted
resources (dictionary) – Additional resources used in the conversion process. Allows preprocessors to pass variables into the Jinja engine.
- class josie.nbconvert.CleanOutputPreprocessor(**kwargs)¶
Bases:
nbconvert.preprocessors.tagremove.TagRemovePreprocessor
A pre-processor that removes cells tagged with
remove_output
- remove_all_outputs_tags = {'remove_output'}¶
- remove_cell_tags = {'skip_conversion'}¶
- class josie.nbconvert.MathFixPreprocessor(**kwargs)¶
Bases:
nbconvert.preprocessors.base.Preprocessor
This preprocessor fix the markdown for the math formulas using the :mod`recommonmark` notation
- preprocess_cell(cell, resources, index)¶
Override if you want to apply some preprocessing to each cell. Must return modified cell and resource dictionary.
- Parameters
cell (NotebookNode cell) – Notebook cell being processed
resources (dictionary) – Additional resources used in the conversion process. Allows preprocessors to pass variables into the Jinja engine.
index (int) – Index of the cell being processed
- regexs = [RegexReplace(regex='\\\\begin\\{[a-zA-Z]+\\}([\\s\\S]*?)\\\\end\\{[a-zA-Z]+\\}', replace='```math\\n \\1 \\n```'), RegexReplace(regex='\\$\\$\\n([ \\S]+)\\n\\$\\$', replace='```math\\n \\1 \\n```'), RegexReplace(regex='\\$(.*)\\$', replace='`$ \\1 $`')]¶
- class josie.nbconvert.MdBinderExporter(**kwargs)¶
Bases:
nbconvert.exporters.templateexporter.TemplateExporter
A
nbconvert
exporter that exports Notebooks as markdown files with a Binder badge on top ready to be used in Sphinx documentation- BINDER_URL = 'https://mybinder.org'¶
- file_extension = '.md'¶
- preprocessors = [<class 'josie.nbconvert.MplInlinePreprocessor'>, <class 'nbconvert.preprocessors.execute.ExecutePreprocessor'>, <class 'josie.nbconvert.SkipPreprocessor'>, <class 'josie.nbconvert.CleanOutputPreprocessor'>, <class 'josie.nbconvert.MathFixPreprocessor'>, <class 'josie.nbconvert.BinderBadgePreprocessor'>]¶
- template_file = 'markdown/index.md.j2'¶
- class josie.nbconvert.MplInlinePreprocessor(**kwargs)¶
Bases:
josie.nbconvert.MathFixPreprocessor
This preprocessors replaces the magic command for matplolib to
inline
.- regexs = [RegexReplace(regex='(%matplotlib) .*', replace='\\1 inline')]¶
- class josie.nbconvert.RegexReplace(regex, replace)¶
Bases:
object
A
dataclass
used to store regex patterns and their replacements- regex: str¶
- replace: str¶
- class josie.nbconvert.SkipPreprocessor(**kwargs)¶
Bases:
nbconvert.preprocessors.base.Preprocessor
A Preprocessor that removes cell tagged as “skip”
- check_cell_conditions(cell, resources, index)¶
- preprocess(nb, resources)¶
Preprocessing to apply on each notebook.
Must return modified nb, resources.
If you wish to apply your preprocessing to each cell, you might want to override preprocess_cell method instead.
- Parameters
nb (NotebookNode) – Notebook being converted
resources (dictionary) – Additional resources used in the conversion process. Allows preprocessors to pass variables into the Jinja engine.
josie.ode module¶
Handy objects to speed up the setup of a simulation for a problem governed by an Ordinary Differential Equation (ODE) (i.e. time-varying only)
- class josie.ode.OdeProblem(f)¶
Bases:
josie.problem.Problem
- s(cells, t)¶
This returns the values of the source terms
A general problem can be written in a compact way:
This method needs to return
- Parameters
cells (
Union
[MeshCellSet
,CellSet
]) – AMeshCellSet
that contains the cell datat (
float
) – Time instant
- Returns
An array of dimension containing the computed source terms
- Return type
s
- class josie.ode.OdeSolver(Q0, dt, Scheme, f, *args, **kwargs)¶
Bases:
josie.solver.Solver
A convenience solver that takes care of all the required setups of objects to speed up the configuration of an ODE problem
- Parameters
Q – A
State
describing the state variable. For example for an oscilator the state is where is the position and is the velocity of a point connected to the oscillatorScheme (
Type
[TimeScheme
]) – ATimeScheme
to be used to integrate the problemf (
Callable
[[State
,float
],State
]) – The RHS of the ODE problemQ0 (
State
) – The initial state value
- solve(final_time, WriterClass=<class 'josie.io.write.writer.MemoryWriter'>)¶
This method solves the ODE system using a
- Parameters
final_time (
float
) – The final time for the time integrationwriter – The
Writer
to use to perform the integration. By defaultMemoryWriter
is used.
- t: float¶
josie.problem module¶
- class josie.problem.Problem(**kwargs)¶
Bases:
object
A class representing a physical problem to be solved (governed by a PDE).
A general problem can be written in a compact way:
A concrete instance of this class potentially provides the terms
- B(cells)¶
This returns the tensor that pre-multiplies the non-conservative term of the problem.
A general problem can be written in a compact way:
This method needs to return
- Parameters
state_array – The
State
array containing the values of all the fields- Returns
An array of dimension containing the computed pre-multiplier tensor
- Return type
B
- F(cells)¶
The convective flux operator
- Parameters
cells (
Union
[CellSet
,MeshCellSet
]) – AMeshCellSet
that contains the cell data- Returns
An array of dimension containing the computed convective flux for the given problem
- Return type
F
- K(cells)¶
This returns the tensor that pre-multiplies the gradient in the diffusive term of the problem.
A general problem can be written in a compact way:
This method needs to return
- Parameters
cells (
Union
[CellSet
,MeshCellSet
]) – AMeshCellSet
that contains the cell data- Returns
An array of dimension containing the computed pre-multiplier tensor
- Return type
D
- s(cells, t)¶
This returns the values of the source terms
A general problem can be written in a compact way:
This method needs to return
- Parameters
cells (
Union
[CellSet
,MeshCellSet
]) – AMeshCellSet
that contains the cell datat (
float
) – Time instant
- Returns
An array of dimension containing the computed source terms
- Return type
s
josie.solver module¶
- class josie.solver.Solver(mesh, Q, scheme)¶
Bases:
object
This class is used to solve a problem governed by PDEs.
- Parameters
- animate(t)¶
Animate the simulation. Call
animate()
for each time instant you want to provide in the animation.- Parameters
t – The time instant to animate
- init(init_fun)¶
This method initialize the internal values of the cells of the
Mesh
and the values of the ghost cells that apply theBoundaryCondition
for each boundary of the domain- Parameters
init_fun (
Callable
[[MeshCellSet
],NoReturn
]) – The function to use to initialize the value in the domain
- plot()¶
Plot the current state of the simulation in a GUI.
- show(fields)¶
Display on screen the given fields
- Parameters
fields (
Union
[List
[str
],str
]) – The fields you want to plot
- step(dt)¶
This method advances one step in time using the
Scheme.step()
method of the given numerical scheme.- Parameters
dt (
float
) – Time increment of the step
- t: float¶
josie.state module¶
- class josie.state.State(*args, **kwargs)¶
Bases:
numpy.ndarray
State
is a subclass ofnumpy.ndarray
. It behaves like a normalnumpy.ndarray
except it has additional init methods to ease the usageA
State
can be initialized using aStateTemplate
,>>> Q = StateTemplate("rho", "rhoU", "rhoV") >>> state = np.array([0, 1, 2]).view(Q) >>> assert state[state.fields.rho] == 0 >>> assert state[state.fields.rhoU] == 1 >>> assert state[state.fields.rhoV] == 2
or directly providing key-value arguments
>>> state = State(rho=0, rhoU=1, rhoV=2) >>> assert state[state.fields.rho] == 0 >>> assert state[state.fields.rhoU] == 1 >>> assert state[state.fields.rhoV] == 2
A
State
can also store non-numeric elements. CheckBoundaryCondition
for an actual situation in which callables are stored instead of numeric elements.A
State can be manipulated as a normal :class:`numpy.ndarray
:>>> e1 = State([1, 0, 0]) >>> e2 = State([0, 1, 0]) >>> e3 = State([0, 0, 1]) >>> assert np.array_equal(np.cross(e1, e2), e3)
A
State
can be multidimensional. The last dimension must be the number of states defined in theStateTemplate
call. In this case you can get all the values of the state for a specific variable:>>> state = np.random.random((10, 10, 3)).view(Q) >>> assert np.array_equal(state[..., state.fields.rho], state[..., 0]) >>> assert np.array_equal(state[..., state.fields.rhoU],state[..., 1])
- fields: Type[<class ‘josie.fields.Fields’>]¶
- classmethod from_mesh(mesh)¶
Initialize an empty class:State object of the right dimensiosn for the given class:Mesh
- Return type
- josie.state.StateTemplate(*fields)¶
A factory for a
State
.It allows you to create at will a
State
class for which you can access its variables (e.g. the velocity ) using the attributefields
, that is anIntEnum
(and not only by index).- Parameters
fields (
str
) – A list of (scalar) fields composing the state
A scalar
State
as for the advection equation>>> Q = StateTemplate("u")
Than you can concretize the state with a value
>>> zero = Q(0)
You can also create higher dimensional states, for examples the state of the 2D Euler compressible equations
>>> Q = StateTemplate("rho", "rhoU", "rhoV", "E") >>> zero = Q(0, 0, 0, 0) >>> assert zero[Q.fields.rho] == 0
- Return type
Type
[State
]
- class josie.state.SubsetState(*args, **kwargs)¶
Bases:
josie.state.State
This class stores a subset of :class`State`, filtered by field name. It also stores a mapping of the indices in
State.fields
corresponding to theSubsetState.fields
inself._subset_fields_map
- josie.state.unpickle_state(d, array)¶
josie.transport module¶
- class josie.transport.Transport¶
Bases:
abc.ABC
A class providing the transport coefficients