Internal API
Besides of the interface methods for VoronoiFVMDiffEq
, these are not exported and therefore should not be used outside of the package
Wrapping evaluators for physics callbacks
VoronoiFVM.hasdata
— Functionhasdata(physics)
Check if physics object has data
VoronoiFVM.AbstractEvaluator
— Typeabstract type AbstractEvaluator
Abstract type for evaluator.
VoronoiFVM.ResEvaluator
— Typestruct ResEvaluator{Tv<:Number, Func<:Function, G} <: VoronoiFVM.AbstractEvaluator
Evaluator for functions from physics. Allows to call different types of physic functions (flux, reaction, source) an provides a common interface to different function formats (with data, without data etc.)
fwrap::Function
: wrapper function in Format ready for Diffetential equationsy::Vector{Tv} where Tv<:Number
: pre-allocated resultgeom::Any
: Geometry object # geometry (node, edge...)nspec::Int64
: number of speciesisnontrivial::Bool
: Is the function not nofunc
VoronoiFVM.ResEvaluator
— Method ResEvaluator(physics,symb,uproto,geom,nspec)
Constructor for ResEvaluator
physics
Physics objectsymb
: symbol naming one of the functions in physics to be wrapped.uproto
: solution vector prototype,geom
: node, edge...nspec
: number of species
VoronoiFVM.evaluate!
— Methodevaluate!(e::VoronoiFVM.ResEvaluator)
Call function in evaluator, store result in predefined memory.
VoronoiFVM.evaluate!
— Methodevaluate!(e::VoronoiFVM.ResEvaluator, u)
Call function in evaluator, store result in predefined memory.
VoronoiFVM.res
— Methodres(
e::VoronoiFVM.ResEvaluator
) -> Vector{Tv} where Tv<:Number
Retrieve evaluation result
VoronoiFVM.ResJacEvaluator
— Typestruct ResJacEvaluator{Tv<:Number, Func<:Function, Cfg, Res, G} <: VoronoiFVM.AbstractEvaluator
Evaluator for functions from physics and their Jacobians. Allows to call different types of physic functions (flux, reaction, source) an provides a common interface to different function formats (with data, without data etc.)
fwrap::Function
: wrapper function in Format ready for Differential equationsconfig::Any
: ForwardDiff.JacobianConfigresult::Any
: DiffResults.JacobianResulty::Vector{Tv} where Tv<:Number
: pre-allocated resultgeom::Any
: Geometry object # geometry (node, edge...)nspec::Int64
: number of speciesisnontrivial::Bool
: Is the function not nofunc
VoronoiFVM.ResJacEvaluator
— MethodResJacEvaluator(physics, data, symb, uproto, geom, nspec)
Constructor for ResJEvaluator
physics
Physics objectsymb
: symbol naming one of the functions in physics to be wrapped.uproto
: solution vector prototype,geom
: node, edge...nspec
: number of species
VoronoiFVM.evaluate!
— Methodevaluate!(e::VoronoiFVM.ResJacEvaluator, u)
Call function in evaluator, store result and jacobian in predefined memory.
VoronoiFVM.res
— Methodres(e::VoronoiFVM.ResJacEvaluator) -> Any
Retrieve evaluation result
VoronoiFVM.jac
— Methodjac(e::VoronoiFVM.ResJacEvaluator) -> Any
Retrieve Jacobian
VoronoiFVM.isnontrivial
— Functionisnontrivial(e::VoronoiFVM.AbstractEvaluator) -> Any
Does calling the evaluator giva nontrivial (nonzero) result?
Manipulating systems
VoronoiFVM.update_grid_cellwise!
— Functionupdate_grid_cellwise!(system)
Update cellwise assembly data for new grid
VoronoiFVM.update_grid_edgewise!
— Functionupdate_grid_edgewise!(system)
Update edgewise assembly data for new grid
VoronoiFVM.sysmutatelock
— Constantconst sysmutatelock
Reentrant lock to safeguard mutating methods _complete!
and update_grid!
.
VoronoiFVM._complete!
— Function_complete!(system)
Update grid and compile species information for system. Uses a lock to ensure parallel access.
Global node and edge assembly loops
VoronoiFVM.AbstractAssemblyData
— Typeabstract type AbstractAssemblyData{Tv, Ti}
Assembly of residual and Jacobian comes in two flavors, cellwise and edgewise assembly loops, see VoronoiFVM.System(grid;kwargs...)
. The necessary data for assembly are held in structs which are subtypes of AbstractAssemblyData
.
VoronoiFVM.CellwiseAssemblyData
— Typestruct CellwiseAssemblyData{Tv, Ti} <: VoronoiFVM.AbstractAssemblyData{Tv, Ti}
Data for cellwise assembly.
nodefactors::Matrix
: Precomputed geometry factors for cell nodes. This is ancells x nnodes_per_cell
full matrix.
edgefactors::Matrix
: Precomputed geometry factors for cell edges This is ancells x nedge_per_cell
full matrix.
pcolor_partitions::Vector
partition_cells::Vector
VoronoiFVM.EdgewiseAssemblyData
— Typestruct EdgewiseAssemblyData{Tv, Ti} <: VoronoiFVM.AbstractAssemblyData{Tv, Ti}
nodefactors::SparseArrays.SparseMatrixCSC{Tv, Ti} where {Tv, Ti}
: Precomputed geometry factors for nodes. This is annodes x nregions
sparse matrix.
edgefactors::SparseArrays.SparseMatrixCSC{Tv, Ti} where {Tv, Ti}
: Precomputed geometry factors for edges This is anedges x nregions
sparse matrix.
pcolor_partitions::Vector
partition_nodes::Vector
partition_edges::Vector
VoronoiFVM.nodebatch
— Functionnodebatch(assemblydata)
Outer range for node assembly loop.
VoronoiFVM.noderange
— Functionnoderange(assemblydata, i)
Inner range for node assembly loop.
VoronoiFVM.edgebatch
— Functionnodebatch(assemblydata)
Outer range for edge assembly loop.
VoronoiFVM.edgerange
— Functionedgerange(assemblydata, i)
Inner range for edge assembly loop.
VoronoiFVM._fill!
— Function_fill!(node, asmdata, inode, icell)
Fill node with the help of assemblydata.
_fill!(node, asmdata, ibnode, ibface)
Fill boundary node with the help of assemblydata.
_fill!(edge, asmdata, iedge, icell)
Fill edge with the help of assemblydata.
_fill!(bedge, asmdata, ibedge, ibface)
Fill boundary edge with the help of assemblydata.
_fill!(node, asmdata, k, inode)
Fill node with the help of assemblydata.
_fill!(edge, asmdata, k, iedge)
Fill edge with the help of assemblydata.
Local node and edge assembly loops
Local assembly methods organize the assembly of data to those degrees of freedom (dofs) which are defined for a given node or edge. E.g. for an node residual for nspec
defined species, only those entries need to be assembled into the global residual vector which correspond to actually defined degrees of freedom.
Similarly for nspec x nspec
node Jacobian, an for the nparam x nspec
parameter derivatives.
These local assembly methods organize the correct loops and call back to the concrete assembly methods passed to them. These receive global degrees of freedom and the local species numbers to be handled. The callbacks can be used as well for other purposes than assembly
VoronoiFVM.assemble_res_jac
— Functionassemble_res_jac(node, system, asm_res, asm_jac, asm_param)
Assemble residual and jacobian for node functions. Parameters:
system
: System to be worked withnode
: nodeasm_jac(idof,jdof,ispec,jspec)
: e.g. assemble entryispec,jspec
of local jacobian into entryidof,jdof
of global matrixasm_param(idof,ispec,iparam)
shall assemble parameter derivatives
assemble_res_jac(bnode, system, asm_res, asm_jac, asm_param)
Assemble residual and jacobian for boundary node functions. See assemble_res_jac
for more explanations.
assemble_res_jac(edge, system, asm_res, asm_jac, asm_param)
Assemble residual and jacobian for edge (flux) functions. Parameters:
system
: System to be worked withedge
: edgeasm_res(idofK,idofL,ispec)
: e.g. assemble local ispec to global degrees of freedom in unknownsasm_jac(idofK,jdofK,idofL,jdofL,ispec,jspec)
: e.g. assemble entryispec,jspec
of local jacobian into entry four entries defined byidofK
andidofL
of global matrixasm_param(idofK,idofL,ispec,iparam)
shall assemble parameter derivatives
assemble_res_jac(bedge, system, asm_res, asm_jac, asm_param)
Assemble residual and jacobian for boundary edge (flux) functions. See assemble_res_jac
for more explanations.
VoronoiFVM.assemble_res
— Functionassemble_res(node, system, asm_res)
Assemble residual for node functions. See assemble_res_jac
for more explanations.
assemble_res(bnode, system, asm_res)
Assemble residual for boundary node functions. See assemble_res_jac
for more explanations.
assemble_res(edge, system, asm_res)
Assemble residual for edge (flux) functions. See assemble_res_jac
for more explanations.
assemble_res(bedge, system, asm_res)
Assemble residual for boundary edge (flux) functions. See assemble_res_jac
for more explanations.
Degree of Freedom management
We distinguish
- active degrees of freedom: these are the actual degrees of freedom
- degrees of freedom (dof) potential degrees of freedom - the may be active dofs or dummy ones With sparse arrays there are no dummy ones, with dense arrays dummy are maske in the node_dof field
- species: each degree of freedom has associated the species it represents and the node index where it is localized
VoronoiFVM.isnodespecies
— Functionisnodespecies(system, ispec, inode)
Check if species is defined in node.
VoronoiFVM.isregionspecies
— Functionisregionspecies(system, ispec, ireg)
Check if species is defined in region.
VoronoiFVM.firstnodedof
— Functionfirstnodedof(system, inode)
Get first degree of freedom associated with node.
VoronoiFVM.lastnodedof
— Functionlastnodedof(system, inode)
Get last degree of freedom associated with node.
VoronoiFVM.getspecies
— Functiongetspecies(system,idof)
Get species associated to degree of freedom
VoronoiFVM.getnodedof
— Functiongetnodedof(system,ispec,inode)
Get active or dummy degree of freedom associated with node and species
VoronoiFVM.increase_num_species!
— Function increase_num_species!(system,maxspec)
Increase number of species in system to maxspec by adding new rows to all relevant matrices.
VoronoiFVM.addzrows
— Functionaddzrows(matrix,maxrow)
Return matrix with number of rows increased to maxrow, and set the new elements to zero.
VoronoiFVM.dofs
— Functiondofs(a)
Vector of degrees of freedom in solution array.
dofs(a)
Vector of degrees of freedom in sparse solution array.
Geometry data
VoronoiFVM.AbstractGeometryItem
— Typeabstract type AbstractGeometryItem{Tc<:Number, Tp<:Number, Ti<:Integer}
Abstract type for geometry items (node,bnode,edge, bedge)
VoronoiFVM.AbstractNode
— Typeabstract type AbstractNode{Tc<:Number, Tp<:Number, Ti<:Integer} <: AbstractGeometryItem{Tc<:Number, Tp<:Number, Ti<:Integer}
Abstract type for nodes.
node[idim]
gives the the corresponding coordinate.
VoronoiFVM.AbstractNodeData
— Typeabstract type AbstractNodeData{Tv<:Number} <: AbstractArray{Tv<:Number, 1}
Abstract type for data on nodes. u[ispec]
accesses value of species at this node.
VoronoiFVM.AbstractEdge
— Typeabstract type AbstractEdge{Tv<:Number, Tp<:Number, Ti<:Integer} <: AbstractGeometryItem{Tv<:Number, Tp<:Number, Ti<:Integer}
Abstract type for edges
edge[idim,inode]
gives coordinate of node.
VoronoiFVM.AbstractEdgeData
— Typeabstract type AbstractEdgeData{Tv<:Number} <: AbstractArray{Tv<:Number, 2}
Abstract type for data on edges. u[ispec,inode]
accesses value of species at corresponding node.
VoronoiFVM.outflownode!
— Functionoutflownode!(edge)
Set edge.outflownode
entry.
VoronoiFVM.NodeUnknowns
— Typestruct NodeUnknowns{Tv, Tc, Tp, Ti} <: VoronoiFVM.AbstractNodeData{Tv}
Unknown data on node.
VoronoiFVM.NodeRHS
— Typestruct NodeRHS{Tv, Tc, Tp, Ti} <: VoronoiFVM.AbstractNodeData{Tv}
RHS data on node.
Global assembly & helpers
VoronoiFVM.factorizationstrategy
— Functionfactorizationstrategy(preconditioner, blockstratrgy, system)
Create a factorizations strategy from preconditioner and block information
VoronoiFVM.solve_step!
— Functionsolve_step!(
state,
solution,
oldsol,
control,
time,
tstep,
embedparam,
params
)
Solve time step problem. This is the core routine for implicit Euler and stationary solve.
VoronoiFVM.solve_transient!
— Function solve_transient(inival, system, times; kwargs...)
Solve transient or embedding problem.
VoronoiFVM.eval_and_assemble
— Functioneval_and_assemble(
system,
U,
UOld,
F,
matrix,
dudp,
time,
tstep,
λ,
data,
params;
edge_cutoff
)
Main assembly method.
Evaluate solution with result in right hand side F and assemble Jacobi matrix into system.matrix.
VoronoiFVM._eval_and_assemble_generic_operator
— FunctionEvaluate and assemble jacobian for generic operator part.
VoronoiFVM._addnz
— Function_addnz(matrix, i, j, v, fac)
_addnz(matrix, i, j, v, fac, part)
Add value v*fac
to matrix if v
is nonzero
VoronoiFVM._add
— Function_add(U::VoronoiFVM.DenseSolutionArray, idof, val) -> Any
Add residual value into global degree of freedom
(Internal method)
_add(U::VoronoiFVM.SparseSolutionArray, idof, val) -> Any
Add residual value into global degree of freedom
(internal)
Interface methods for VoronoiFVMDiffEq.jl
VoronoiFVM._eval_res_jac!
— Function_eval_res_jac!(state, u, t)
Evaluate functiaon and Jacobian at u if they have not been evaluated before at u. See https://github.com/SciML/DifferentialEquations.jl/issues/521 for discussion of another way to do this.
VoronoiFVM.eval_rhs!
— Functioneval_rhs!(du, u, state, t)
Interpret the discrete problem as an ODE/DAE problem. Provide the rhs function for SciMLBase.ODEFunction
.
VoronoiFVM.eval_jacobian!
— Functioneval_jacobian!(J, u, state, t)
Interpret the discrete problem as an ODE/DAE problem. Provide the jacobi matrix calculation function for SciMLBase.ODEFunction
VoronoiFVM.mass_matrix
— Functionmass_matrix(state)
Calculate the mass matrix for use with SciMLBase.ODEFunction
. Return a Diagonal matrix if it occurs to be diagonal, otherwise return a SparseMatrixCSC.
VoronoiFVM.prepare_diffeq!
— Functionprepare_diffeq!(state, jacval, tjac)
Prepare system for use with VoronoiFVMDiffEq.
jacval
: value at which to evaluate jacobian to obtatin prototypetjac
: time moment for jacobian
Returns a prototype for the jacobian.
Misc tools
VoronoiFVM.solutionarray
— Functionsolutionarray(a::Matrix)
solutionarray(a::SparseMatrixCSC)
VoronoiFVM.integrate
— Methodintegrate(, coordl, coordr, hnormal, velofunc; kwargs...)
This is an internal function to integrate velofunc
along the edge $\sigma=\overline{\mathtt{coordl}\,\mathtt{coordr}}$ between the $x_K$ and $x_L$ where $\mathtt{hnormal}=x_K-x_L$ using Simpson's Rule. To be precise, compute for a cartesian coordinate system: $\int_{\sigma} \mathbf{v} \cdot \mathbf{n} \,\mathrm{ds} \lvert x_K - x_L \rvert / \lvert\sigma\rvert$.
VoronoiFVM.integrate
— Methodintegrate(, coordl, coordr, hnormal, velofunc; kwargs...)
This is an internal function similar to integrate(::Type{<:Cartesian2D},...)
, but computes instead $\int_{\sigma} r \, \mathbf{v} \cdot \mathbf{n} \,\mathrm{ds} \lvert x_K - x_L \rvert / \left ( \lvert\sigma\rvert r(\mathrm{mid}(\sigma)) \right )$ where $r(\mathrm{mid}(\sigma))$ is the $r$-coordinate of the mid-point of $\sigma$.
VoronoiFVM.doolittle_ludecomp!
— Functiondoolittle_ludecomp!(LU)
Non-pivoting inplace LU factorization using Doolittle's method. Adapted from https://en.wikipedia.org/wiki/LUdecomposition#MATLABcode_example.
VoronoiFVM.doolittle_lusolve!
— Functiondoolittle_lusolve!(LU, b)
Non-pivoting inplace upper and lower triangular solve of matrix factorized with doolittle_ludecomp!
. Adapted from https://en.wikipedia.org/wiki/LUdecomposition#MATLABcode_example.
VoronoiFVM.bernoulli_horner
— Functionbernoulli_horner(x)
Calculation of Bernoulli function via Horner scheme based on Taylor coefficients around 0.
VoronoiFVM._print_error
— FunctionPrint error when catching exceptions