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:
objectA
BoundaryConditionis a collection ofScalarBC, one per eachfieldsof theProblem.- bc¶
A
Stateinstance whose elements per each field are not float butScalarBCinstead>>> from josie.state import StateTemplate >>> MyState = StateTemplate("u", "v") >>> mybc = BoundaryCondition(MyState(Dirichlet(0), Neumann(1)))
- __call__(cells, boundary, t)¶
- Parameters
mesh – A
Meshobject that contains informations on cells data and time instantboundary (Boundary) – A
Boundaryobject representing the mesh boundary on which theBoundaryConditionmust 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.ScalarBCA
ScalarBCthat 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
ScalarBCassigning 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
_ConstantDirichletin 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 isStateof size
one of the two previous options. Used as a shortcut to impose the same
ScalarBCfor all the fieldsconstant –
Set this flag to
Trueto explicitly force the creation of a constant boundary condition. A constant BC is optimized to reduce the number of calls.Dirichletnormally is capable to understand automatically if you are providing a constant imposed value: if you provide a constant scalarfloatorint(or aStatecontaining a scalar value for each field). If you provide aBCCallablethen 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 setconstanttoTrue.
- set_value¶
A
SetValueCallablethat can be used to provide a specific value theScalarBCneeds to impose. E.g. * In the case ofDirichlet, theset_valuegives the value of the fields to impose on the boundary.In the case of
Neumannit 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
CellSetcontaining the state of the mesh cellsghosts_cells – A
CellSetcontaining the ghost cells associated to theBoundarytheBoundaryConditionis applied tofield (int) – The field to which the
ScalarBCis applied tot (float) – The time instant to which this
ScalarBCmust 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.DirichletA
ScalarBCthat 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
ScalarBCassigning 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 isStateof size
one of the two previous options. Used as a shortcut to impose the same
ScalarBCfor all the fields
- __call__(cells, ghost_cells, field, t)¶
- Parameters
cells (CellSet) – A
CellSetcontaining the state of the mesh cellsghosts_cells – A
CellSetcontaining the ghost cells associated to theBoundarytheBoundaryConditionis applied tofield (int) – The field to which the
ScalarBCis applied tot (float) – The time instant to which this
ScalarBCmust 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.ScalarBCA
ScalarBCthat applies aDirichleton a part of the domain and aNeumannon the rest of it.- Parameters
neumann_value – The value of the gradient to use for the
Neumannpartition of the boundarydirichlet_value – The value of the
Stateto use for theDirichletpartition 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
Dirichletboundary condition has to be applied
- __call__(cells, ghost_cells, field, t)¶
- Parameters
cells (CellSet) – A
CellSetcontaining the state of the mesh cellsghosts_cells – A
CellSetcontaining the ghost cells associated to theBoundarytheBoundaryConditionis applied tofield (int) – The field to which the
ScalarBCis applied tot (float) – The time instant to which this
ScalarBCmust 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
ScalarBCto 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.BoundaryConditionA
BoundaryConditionthat connects one side of the domain to the other. In general is more straighforward to use the :func`make_periodic` function on a couple ofBoundaryCurvethat 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
Meshobject that contains informations on cells data and time instantboundary (Boundary) – A
Boundaryobject representing the mesh boundary on which theBoundaryConditionmust 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.NoAliasEnumA Enum encapsulating the 4 indexing possibilities of a
PeriodicScalarBC- 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.ABCA
ScalarBCis 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
CellSetcontaining the state of the mesh cellsghosts_cells – A
CellSetcontaining the ghost cells associated to theBoundarytheBoundaryConditionis applied tofield (int) – The field to which the
ScalarBCis applied tot (float) – The time instant to which this
ScalarBCmust 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:
objectUsed to convert the bare float value to a callable returning constant value for all the cells. Used for
Dirichletand 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 firstBoundaryCurveto linksecond (
BoundaryCurve) – The secondBoundaryCurveto linkdirection (
Direction) – The direction on which the twoBoundaryCurveare periodically connected
- Return type
Tuple[BoundaryCurve,BoundaryCurve]- Returns
first – The first
BoundaryCurvewhose bc attribute is correctly configuredsecond – The second
BoundaryCurvewhose 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.EnumAllow 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.IntEnumAn enumeration.
- class josie.data.StateElement(time, data)¶
Bases:
objectAn 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:
intA class that acts as a
intused inFieldsMetato 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:
typeThis 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.IntEnumAn
Enumencapsulating the coordinates indices- X = 0¶
- Y = 1¶
- Z = 2¶
- class josie.math.R3¶
Bases:
objectAn
Enumencapsulating 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.PreprocessorThis 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.TagRemovePreprocessorA 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.PreprocessorThis 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.TemplateExporterA
nbconvertexporter 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.MathFixPreprocessorThis preprocessors replaces the magic command for matplolib to
inline.- regexs = [RegexReplace(regex='(%matplotlib) .*', replace='\\1 inline')]¶
- class josie.nbconvert.RegexReplace(regex, replace)¶
Bases:
objectA
dataclassused to store regex patterns and their replacements- regex: str¶
- replace: str¶
- class josie.nbconvert.SkipPreprocessor(**kwargs)¶
Bases:
nbconvert.preprocessors.base.PreprocessorA 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]) – AMeshCellSetthat 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.SolverA convenience solver that takes care of all the required setups of objects to speed up the configuration of an ODE problem
- Parameters
Q – A
Statedescribing the state variable. For example for an oscilator the state iswhere
is the position and
is the velocity of a point connected to the oscillator
Scheme (
Type[TimeScheme]) – ATimeSchemeto 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
Writerto use to perform the integration. By defaultMemoryWriteris used.
- t: float¶
josie.problem module¶
- class josie.problem.Problem(**kwargs)¶
Bases:
objectA 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
Statearray 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]) – AMeshCellSetthat 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]) – AMeshCellSetthat 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]) – AMeshCellSetthat 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:
objectThis 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
Meshand the values of the ghost cells that apply theBoundaryConditionfor 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.ndarrayStateis a subclass ofnumpy.ndarray. It behaves like a normalnumpy.ndarrayexcept it has additional init methods to ease the usageA
Statecan 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
Statecan also store non-numeric elements. CheckBoundaryConditionfor 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
Statecan be multidimensional. The last dimension must be the number of states defined in theStateTemplatecall. 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
Stateclass for which you can access its variables (e.g. the velocity) using the attribute
fields, that is anIntEnum(and not only by index).- Parameters
fields (
str) – A list of (scalar) fields composing the state
A scalar
Stateas 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.StateThis class stores a subset of :class`State`, filtered by field name. It also stores a mapping of the indices in
State.fieldscorresponding to theSubsetState.fieldsinself._subset_fields_map
- josie.state.unpickle_state(d, array)¶
josie.transport module¶
- class josie.transport.Transport¶
Bases:
abc.ABCA class providing the transport coefficients