API documentaion

Contents

API documentaion#

simcardems.cli module#

simcardems.cli.main(config: Config | None)[source]#

simcardems.config module#

class simcardems.config.Config(outdir: pathlib.Path | str = 'results', outfilename: str = 'results.h5', geometry_path: pathlib.Path | str = '', geometry_schema_path: pathlib.Path | str | NoneType = None, T: float = 1000, dt: float = 0.05, bnd_rigid: bool = False, load_state: bool = False, cell_init_file: pathlib.Path | str = '', show_progress_bar: bool = True, save_freq: int = 1, pre_stretch: dolfin.function.constant.Constant | float | NoneType = None, traction: dolfin.function.constant.Constant | float = None, spring: dolfin.function.constant.Constant | float = None, fix_right_plane: bool = False, loglevel: int = 20, num_refinements: int = 1, set_material: str = '', debug_mode: bool = False, drug_factors_file: pathlib.Path | str = '', popu_factors_file: pathlib.Path | str = '', disease_state: str = 'healthy', dt_mech: float = 1.0, mech_threshold: float = 0.05, mechanics_solve_strategy: Literal['fixed', 'adaptive'] = 'adaptive', ep_ode_scheme: str = 'GRL1', ep_preconditioner: str = 'sor', ep_theta: float = 0.5, linear_mechanics_solver: str = 'mumps', mechanics_use_continuation: bool = False, mechanics_use_custom_newton_solver: bool = False, PCL: float = 1000, coupling_type: Literal['fully_coupled_ORdmm_Land', 'fully_coupled_Tor_Land', 'explicit_ORdmm_Land', 'pureEP_ORdmm_Land'] = 'fully_coupled_ORdmm_Land')[source]#

Bases: object

PCL: float = 1000#
T: float = 1000#
as_dict()[source]#
bnd_rigid: bool = False#
cell_init_file: Path | str = ''#
coupling_type: Literal['fully_coupled_ORdmm_Land', 'fully_coupled_Tor_Land', 'explicit_ORdmm_Land', 'pureEP_ORdmm_Land'] = 'fully_coupled_ORdmm_Land'#
debug_mode: bool = False#
disease_state: str = 'healthy'#
drug_factors_file: Path | str = ''#
dt: float = 0.05#
dt_mech: float = 1.0#
ep_ode_scheme: str = 'GRL1'#
ep_preconditioner: str = 'sor'#
ep_theta: float = 0.5#
fix_right_plane: bool = False#
geometry_path: Path | str = ''#
geometry_schema_path: Path | str | None = None#
linear_mechanics_solver: str = 'mumps'#
load_state: bool = False#
loglevel: int = 20#
mech_threshold: float = 0.05#
mechanics_solve_strategy: Literal['fixed', 'adaptive'] = 'adaptive'#
mechanics_use_continuation: bool = False#
mechanics_use_custom_newton_solver: bool = False#
num_refinements: int = 1#
outdir: Path | str = 'results'#
outfilename: str = 'results.h5'#
popu_factors_file: Path | str = ''#
pre_stretch: Constant | float | None = None#
save_freq: int = 1#
set_material: str = ''#
show_progress_bar: bool = True#
spring: Constant | float = None#
traction: Constant | float = None#
simcardems.config.default_parameters()[source]#

simcardems.datacollector module#

class simcardems.datacollector.Assigners(*, vs: SplittingSolver | None = None, mech_state: MechanicsProblem | None = None)[source]#

Bases: object

Helper class to assign subfunctions from EP and Mechanics state

assign() None[source]#
assign_ep() None[source]#
assign_mechanics() None[source]#
assign_pre() None[source]#
assign_pre_ep() None[source]#
assign_pre_mechanics() None[source]#
compute_pre_norm()[source]#
register_subfunction(name: str, group: Literal['ep', 'mechanics'], subspace_index: int, is_pre: bool = False) None[source]#
class simcardems.datacollector.DataCollector(outdir, geo: BaseGeometry, outfilename: str = 'results.h5', reset_state=True)[source]#

Bases: object

property function_names: Dict[str, List[str]]#
property names: Dict[str, List[str]]#
register(group: str, name: str, f: Function, reduction: str = 'full') None[source]#
property results_file#
save_residual(residual, index)[source]#
store(t: float) None[source]#
property valid_reductions: List[str]#
class simcardems.datacollector.DataGroups(value)[source]#

Bases: Enum

An enumeration.

ep = 'ep'#
mechanics = 'mechanics'#
class simcardems.datacollector.DataLoader(h5name: Path | str, empty_ok: bool = False)[source]#

Bases: object

cleanup()[source]#
property ep_mesh#
extract_value(group: DataGroups, name: str, t: str | float, reduction: str = 'average')[source]#
property function_names: Dict[str, List[str]]#
get(group: DataGroups, name: str, t: str | float) Function[source]#

Retrieve the function from the file

Parameters:
  • group (DataGroups) – The group where the function is stored, either ‘ep’ or ‘mechanics’

  • name (str) – Name of the function

  • t (Union[str, float]) – Time stamp you want to use. See DataLoader.time_stamps

Returns:

The function

Return type:

dolfin.Function

Raises:
  • KeyError – If group does not exist in the file

  • KeyError – If name does not exist in group

  • KeyError – If ‘t’ provided is not among the time stamps

property mech_mesh#
property residual: List[ndarray]#
property size: int#
exception simcardems.datacollector.InvalidReductionError[source]#

Bases: RuntimeError

simcardems.datacollector.assign_item_is_None(f: Function | None, assigner: FunctionAssigner | None, index: int | None) bool[source]#
simcardems.datacollector.close_h5file(h5file)[source]#
simcardems.datacollector.close_h5pyfile(h5pyfile)[source]#
simcardems.datacollector.extract_number_from_h5py(dataset: Dataset | None) int | None[source]#

simcardems.ep_model module#

simcardems.ep_model.default_conductivities()[source]#
simcardems.ep_model.define_conductivity_tensor(microstructure: Microstructure, chi: float = 140.0, C_m: float = 0.01)[source]#
simcardems.ep_model.file_exist(filename: str | None, suffix: str) bool[source]#
simcardems.ep_model.handle_cell_inits(CellModel: Type[CardiacCellModel], cell_inits: Dict[str, float] | None = None, cell_init_file: str = '') Dict[str, float][source]#
simcardems.ep_model.handle_cell_params(CellModel: Type[BaseCellModel], cell_params: Dict[str, float] | None = None, disease_state: str = 'healthy', drug_factors_file: str = '', popu_factors_file: str = '')[source]#
simcardems.ep_model.load_json(filename: str)[source]#
simcardems.ep_model.setup_cell_model(cls, coupling: BaseEMCoupling, cell_params=None, cell_inits=None, cell_init_file=None, drug_factors_file=None, popu_factors_file=None, disease_state='healthy')[source]#
simcardems.ep_model.setup_model(cellmodel: CardiacCellModel, mesh: Mesh, microstructure: Microstructure, stimulus_domain: StimulusDomain, PCL: int = 1000, chi: float = 140.0, C_m: float = 0.01, duration: float = 2.0, A: float = 50000.0) CardiacModel[source]#

Set-up cardiac model based on benchmark parameters

Parameters:
  • cellmodel (cbcbeat.CardiacCellModel) – _description_

  • mesh (dolfin.Mesh) – _description_

  • microstructure (pulse.Microstructure) – _description_

  • PCL (int, optional) – _description_, by default 1000

  • chi (float, optional) – Surface to volume ratio in mm^{-1}, by default 140.0

  • C_m (float, optional) – Membrane capacitance in mu F / mm^2, by default 0.01

  • duration (float, optional) – Stimulation duration in milliseconds, by default 2.0

  • A (float, optional) – FIXME: Some value in mu A/cm^3, by default 50_000.0

Returns:

The EP model

Return type:

cbcbeat.CardiacModel

simcardems.ep_model.setup_solver(dt, cellmodel: cbcbeat.CardiacCellModel, coupling: BaseEMCoupling, scheme='GRL1', theta=0.5, preconditioner='sor', PCL=1000) cbcbeat.SplittingSolver[source]#
simcardems.ep_model.setup_splitting_solver_parameters(dt, theta=0.5, preconditioner='sor', scheme='GRL1')[source]#

simcardems.geometry module#

class simcardems.geometry.BaseGeometry(parameters: Dict[str, Any] | None = None, stimulus_domain: StimulusDomain | Callable[[Mesh], StimulusDomain] | None = None, mechanics_mesh: Mesh | None = None, ep_mesh: Mesh | None = None, microstructure: Microstructure | None = None, microstructure_ep: Microstructure | None = None, ffun: MeshFunction | None = None, ffun_ep: MeshFunction | None = None, markers: Dict[str, Tuple[int, int]] | None = None, outdir: Path | str | None = None)[source]#

Bases: ABC

Abstract geometry base class

comm() Comm[source]#
abstract static default_markers() Dict[str, Tuple[int, int]][source]#
abstract static default_parameters() Dict[str, Any][source]#
static default_schema() Dict[str, H5Path][source]#
static default_stimulus_domain(mesh: Mesh) StimulusDomain[source]#
property ds#

Return the surface measure of exterior facets using self.mesh as domain and self.ffun as subdomain_data

dump(fname: Path | str, schema_path: Path | str | None = None, unlink: bool = True)[source]#
property dx#

Return the volume measure using self.mesh

property ep_mesh: Mesh#
property f0: Function#
property f0_ep: Function#
property facet_normal: FacetNormal#
property ffun: MeshFunction#
property ffun_ep: MeshFunction#
classmethod from_files(mesh_path: Path | str, ffun_path: Path | str | None = None, marker_path: Path | str | None = None, parameter_path: Path | str | None = None, microstructure_path: Path | str | None = None, **kwargs)[source]#
classmethod from_geometry(geo: Geometry, **kwargs)[source]#
property marker_functions#
property mechanics_mesh: Mesh#
property mesh: Mesh#
property microstructure: Microstructure#
property microstructure_ep: Microstructure#
property n0: Function#
property n0_ep: Function#
property num_refinements: int#
property outdir: Path | None#
property s0: Function#
property s0_ep: Function#
validate()[source]#
class simcardems.geometry.StimulusDomain(domain, marker)[source]#

Bases: NamedTuple

domain: MeshFunction#

Alias for field number 0

marker: int#

Alias for field number 1

simcardems.geometry.load_geometry(mesh_path: Path | str, schema_path: Path | str | None = None, stimulus_domain: StimulusDomain | Callable[[Mesh], StimulusDomain] | None = None) BaseGeometry[source]#
simcardems.geometry.refine_mesh(mesh: Mesh, num_refinements: int, redistribute: bool = False) Mesh[source]#
class simcardems.slabgeometry.SlabGeometry(parameters: Dict[str, Any] | None = None, stimulus_domain: StimulusDomain | Callable[[Mesh], StimulusDomain] | None = None, mechanics_mesh: Mesh | None = None, ep_mesh: Mesh | None = None, microstructure: Microstructure | None = None, microstructure_ep: Microstructure | None = None, ffun: MeshFunction | None = None, ffun_ep: MeshFunction | None = None, markers: Dict[str, Tuple[int, int]] | None = None, outdir: Path | str | None = None)[source]#

Bases: BaseGeometry

static default_markers() Dict[str, Tuple[int, int]][source]#
static default_parameters()[source]#
validate()[source]#
simcardems.slabgeometry.create_boxmesh(lx, ly, lz, dx=0.5, refinements=0)[source]#
simcardems.slabgeometry.create_slab_facet_function(mesh: Mesh, lx: float, ly: float, lz: float, markers: Dict[str, Tuple[int, int]] | None = None) MeshFunction[source]#
simcardems.slabgeometry.create_slab_microstructure(fiber_space, mesh)[source]#
class simcardems.lvgeometry.LeftVentricularGeometry(parameters: Dict[str, Any] | None = None, stimulus_domain: StimulusDomain | Callable[[Mesh], StimulusDomain] | None = None, mechanics_mesh: Mesh | None = None, ep_mesh: Mesh | None = None, microstructure: Microstructure | None = None, microstructure_ep: Microstructure | None = None, ffun: MeshFunction | None = None, ffun_ep: MeshFunction | None = None, markers: Dict[str, Tuple[int, int]] | None = None, outdir: Path | str | None = None)[source]#

Bases: BaseGeometry

static default_markers() Dict[str, Tuple[int, int]][source]#
static default_parameters()[source]#
validate()[source]#

simcardems.mechanics_model module#

class simcardems.mechanics_model.ContinuationBasedMechanicsProblem(*args, **kwargs)[source]#

Bases: MechanicsProblem

solve()[source]#

Solve the variational problem

\[\delta W = 0\]
solve_for_control(control, tol=1e-05)[source]#

Solve with a continuation step for better initial guess for the Newton solver

class simcardems.mechanics_model.MechanicsProblem(*args, **kwargs)[source]#

Bases: ContinuationBasedMechanicsProblem

solve()[source]#

Solve the variational problem

\[\delta W = 0\]
property u_subspace_index: int#
class simcardems.mechanics_model.RigidMotionProblem(*args, **kwargs)[source]#

Bases: MechanicsProblem

rigid_motion_term(u, r)[source]#
property u_subspace_index: int#
simcardems.mechanics_model.create_problem(material: Material, geo: BaseGeometry, bnd_rigid: bool = False, pre_stretch: Constant | float | None = None, traction: Constant | float | None = None, spring: Constant | float | None = None, fix_right_plane: bool = False, linear_solver='mumps', use_custom_newton_solver: bool = False, debug_mode=False) MechanicsProblem[source]#
simcardems.mechanics_model.resolve_boundary_conditions(geo: BaseGeometry, pre_stretch: Constant | float | None = None, traction: Constant | float | None = None, spring: Constant | float | None = None, fix_right_plane: bool = False) BoundaryConditions[source]#
simcardems.mechanics_model.setup_solver(coupling: em_model.BaseEMCoupling, ActiveModel, bnd_rigid: bool = False, pre_stretch: Optional[Union[dolfin.Constant, float]] = None, traction: Union[dolfin.Constant, float] = None, spring: Union[dolfin.Constant, float] = None, fix_right_plane: bool = False, debug_mode: bool = False, set_material: str = '', linear_solver='mumps', use_custom_newton_solver: bool = False, state_prev=None)[source]#

Setup mechanics model with dirichlet boundary conditions or rigid motion.

simcardems.newton_solver module#

class simcardems.newton_solver.MechanicsNewtonSolver(problem: NonlinearProblem, state: Function, update_cb=None, parameters=None)[source]#

Bases: NewtonSolver

check_overloads_called()[source]#
converged(self: dolfin.cpp.nls.NewtonSolver, arg0: dolfin.cpp.la.GenericVector, arg1: dolfin::NonlinearProblem, arg2: int) bool[source]#
static default_solver_parameters()[source]#
register_datacollector(datacollector)[source]#
save_residuals() None[source]#
solve(self: dolfin.cpp.nls.NewtonSolver, arg0: dolfin::NonlinearProblem, arg1: dolfin.cpp.la.GenericVector) Tuple[int, bool][source]#
solver_setup(self: dolfin.cpp.nls.NewtonSolver, arg0: dolfin.cpp.la.GenericMatrix, arg1: dolfin.cpp.la.GenericMatrix, arg2: dolfin::NonlinearProblem, arg3: int) None[source]#
class simcardems.newton_solver.MechanicsNewtonSolver_ODE(problem: NonlinearProblem, state: Function, update_cb=None, parameters=None)[source]#

Bases: MechanicsNewtonSolver

update_solution(self: dolfin.cpp.nls.NewtonSolver, arg0: dolfin.cpp.la.GenericVector, arg1: dolfin.cpp.la.GenericVector, arg2: float, arg3: dolfin::NonlinearProblem, arg4: int) None[source]#

simcardems.postprocess module#

simcardems.postprocess.activation_map(voltage: Iterable[Function], time_stamps: Iterable[float], V: FunctionSpace, threshold: float = 0.0, t0: float = 0.0) Function[source]#
simcardems.postprocess.ecg(voltage: Iterable[Function], sigma_b: float, point1: tuple[float, float, float], point2: tuple[float, float, float], mesh: Mesh | None = None) list[float][source]#
simcardems.postprocess.ecg_recovery(*, v: Function, sigma_b: Constant | float, mesh: Mesh, dx: Measure | None = None, point: ndarray | None = None, r: Function | None = None) float[source]#
simcardems.postprocess.extract_biomarkers(*, V: ndarray, time: ndarray, Ca: ndarray, Ta: ndarray | None = None, lmbda: ndarray | None = None, inv_lmbda: ndarray | None = None, u: ndarray | None = None) Dict[str, float][source]#
simcardems.postprocess.extract_last_beat(y, time, pacing, return_interval=False)[source]#
simcardems.postprocess.extract_sub_results(results_file: Path | str, output_file: Path | str, t_start: float = 0.0, t_end: float | None = None, names: Dict[str, List[str]] | None = None) DataCollector[source]#

Extract sub results from another results file. This can be useful if you have stored a lot of data in one file and you want to create a smaller file containing only a subset of the data (e.g only the last beat)

Parameters:
  • results_file (utils.PathLike) – The input result file

  • output_file (utils.PathLike) – Path to file where you want to store the sub results

  • t_start (float, optional) – Time point indicating when the sub results should start, by default 0.0

  • t_end (float | None, optional) – Time point indicating when the sub results should end, by default None in which case it will choose the last time point

  • names (Optional[Dict[str, List[str]]], optional) – A dictionary of names for each group indicating which functions to extract for the sub results. If not provided (default) then all functions will be extracted.

Returns:

A data collector containing the sub results

Return type:

datacollector.DataCollector

Raises:
  • FileNotFoundError – If the input file does not exist

  • KeyError – If some of the names provided does not exists in the input file

simcardems.postprocess.extract_traces(loader: DataLoader, reduction: str = 'average', names: List[Tuple[str, str]] | None = None) Dict[str, ndarray | Dict[str, ndarray]][source]#
simcardems.postprocess.find_decaytime(y, x, a)[source]#
simcardems.postprocess.find_duration(y, t, repolarisation)[source]#
simcardems.postprocess.find_ttp(y, x)[source]#
simcardems.postprocess.get_biomarkers(results, outdir, num_models)[source]#
simcardems.postprocess.json_serial(obj)[source]#
simcardems.postprocess.make_xdmffiles(results_file, names=None)[source]#
simcardems.postprocess.numpyfy(d)[source]#
simcardems.postprocess.plot_peaks(fname, data, threshold)[source]#
simcardems.postprocess.plot_population(results, outdir, num_models, reset_time=True)[source]#
simcardems.postprocess.plot_state_traces(results_file: Path | str, reduction: str = 'average', flag_peaks: bool = True)[source]#
simcardems.postprocess.save_popu_json(population_folder, num_models)[source]#
simcardems.postprocess.stats(y)[source]#

simcardems.save_load_functions module#

simcardems.save_load_functions.check_file_exists(h5_filename, raise_on_false=True)[source]#
simcardems.save_load_functions.decode(x)[source]#
simcardems.save_load_functions.dict_to_h5(data, h5name, h5group, use_attrs: bool = True, comm=None)[source]#
simcardems.save_load_functions.group_in_file(h5_filename, h5group)[source]#
simcardems.save_load_functions.h5_to_dict(h5group, use_attrs: bool = True)[source]#
simcardems.save_load_functions.h5pyfile(h5name, filemode='r', force_serial: bool = False, comm=None)[source]#
simcardems.save_load_functions.load_initial_conditions_from_h5(path: str | Path, CellModel: Type[CardiacCellModel])[source]#
simcardems.save_load_functions.load_state(path: str | Path, drug_factors_file: str | Path = '', popu_factors_file: str | Path = '', disease_state='healthy', PCL: float = 1000)[source]#
simcardems.save_load_functions.mech_heart_to_bnd_cond(mech_heart: MechanicsProblem)[source]#
simcardems.save_load_functions.save_state(path, config: Config, geo: BaseGeometry, state_params: Dict[str, float] | None = None)[source]#
simcardems.save_load_functions.serialize_dict(d)[source]#
simcardems.save_load_functions.vs_functions_to_dict(vs, state_names)[source]#

simcardems.runner module#

class simcardems.runner.Runner(config: Config | None = None, empty: bool = False)[source]#

Bases: object

classmethod from_models(coupling: BaseEMCoupling, config: Config | None = None, reset: bool = True)[source]#
property outdir: Path#
save_state()[source]#
solve(T: float = 1000, save_freq: int = 1, show_progress_bar: bool = True, st_progress: ~typing.Any | None = None, default_save_condition: ~typing.Callable[[int, float, float], bool] = <function Runner.<lambda>>)[source]#
property state_path: Path#
store()[source]#
property t: float#
property t0: float#
simcardems.runner.create_progressbar(time_stepper: TimeStepper | None = None, show_progress_bar: bool = True)[source]#

simcardems.utils module#

class simcardems.utils.MPIFilt(name='')[source]#

Bases: Filter

filter(record)[source]#

Determine if the specified record is to be logged.

Returns True if the record should be logged, or False otherwise. If deemed appropriate, the record may be modified in-place.

class simcardems.utils.Projector(V: FunctionSpace, solver_type: str = 'lu', preconditioner_type: str = 'default')[source]#

Bases: object

project(u: Function, f: Expr) None[source]#

Project f into u.

Parameters:
  • u (dolfin.Function) – The function to project into

  • f (ufl.core.expr.Expr) – The ufl expression to project

simcardems.utils.compute_norm(x, x_prev)[source]#
simcardems.utils.enum2str(x, EnumCls)[source]#
simcardems.utils.float_to_constant(x: Constant | float) Constant[source]#

Convert float to a dolfin constant. If value is already a constant, do nothing.

Parameters:

x (Union[dolfin.Constant, float]) – The value to be converted

Returns:

The same value, wrapped in a constant

Return type:

dolfin.Constant

simcardems.utils.getLogger(name)[source]#
simcardems.utils.local_project(v, V, u=None)[source]#
simcardems.utils.print_mesh_info(mesh, total_dofs)[source]#
simcardems.utils.remove_file(path, comm=None)[source]#
simcardems.utils.setup_assigner(vs, index)[source]#
simcardems.utils.sub_function(vs, index)[source]#

simcardems.value_extractor module#

class simcardems.value_extractor.Boundary(mesh)[source]#

Bases: ABC

abstract static nodes() Sequence[str][source]#
class simcardems.value_extractor.LVBoundary(mesh)[source]#

Bases: Boundary

static nodes()[source]#
class simcardems.value_extractor.SlabBoundary(mesh)[source]#

Bases: Boundary

property boundaries#
property center#
static nodes()[source]#
property xmax#
property xmin#
property ymax#
property ymin#
property zmax#
property zmin#
class simcardems.value_extractor.SlabBoundaryNodes(value)[source]#

Bases: Enum

An enumeration.

center = 'center'#
xmax = 'xmax'#
xmin = 'xmin'#
ymax = 'ymax'#
ymin = 'ymin'#
zmax = 'zmax'#
zmin = 'zmin'#
class simcardems.value_extractor.ValueExtractor(geo: BaseGeometry)[source]#

Bases: object

average(func: Function) float[source]#
eval(func: Function, value: str, dofs: ndarray | None = None)[source]#
eval_at_node(func: Function, point: ndarray, dofs: ndarray | None = None)[source]#
simcardems.value_extractor.center_func(fmin, fmax)[source]#

simcardems.version module#

Models#

simcardems.models.em_model module#

class simcardems.models.em_model.BaseEMCoupling(geometry: BaseGeometry, t: float = 0.0, **kwargs)[source]#

Bases: object

property assigners: datacollector.Assigners#
cell_params()[source]#
coupling_to_ep() None[source]#
coupling_to_mechanics() None[source]#
property coupling_type#

CustomType

property dt_mechanics: float#
ep_to_coupling() None[source]#
static from_state(path: str | Path, drug_factors_file: str | Path = '', popu_factors_file: str | Path = '', disease_state='healthy', PCL: float = 1000)[source]#
mechanics_to_coupling() None[source]#
print_ep_info()[source]#
print_mechanics_info()[source]#
register_datacollector(collector: datacollector.DataCollector) None[source]#
register_ep_model(solver: SplittingSolver) None[source]#
register_mech_model(solver: MechanicsProblem) None[source]#
register_time_stepper(time_stepper: TimeStepper) None[source]#
save_state(path: str | Path, config: Config | None = None) None[source]#
setup_assigners() None[source]#
solve_ep(interval: Tuple[float, float]) None[source]#
solve_mechanics() None[source]#
property state_params#
update_prev_ep() None[source]#
update_prev_mechanics() None[source]#
simcardems.models.em_model.setup_EM_model(cls_EMCoupling, cls_CellModel, cls_ActiveModel, geometry: BaseGeometry, config: Config | None = None, cell_params: Dict[str, float] | None = None, cell_inits: Function | None = None, mech_state_init: Function | None = None, state_params: Dict[str, float] | None = None) BaseEMCoupling[source]#
simcardems.models.em_model.setup_EM_model_from_config(config: Config, geometry: BaseGeometry | None = None, state_params: Dict[str, float] | None = None) BaseEMCoupling[source]#

simcardems.models.fully_coupled_ORdmm_Land#

simcardems.models.fully_coupled_ORdmm_Land.ActiveModel#

alias of LandModel

simcardems.models.fully_coupled_ORdmm_Land.CellModel#

alias of ORdmmLandFull

class simcardems.models.fully_coupled_ORdmm_Land.EMCoupling(geometry: BaseGeometry, **state_params)[source]#

Bases: BaseEMCoupling

property assigners: datacollector.Assigners#
cell_params()[source]#
coupling_to_ep()[source]#
coupling_to_mechanics()[source]#
property coupling_type#

CustomType

property dt_mechanics: float#
property ep_mesh#
ep_to_coupling()[source]#
classmethod from_state(path: str | Path, drug_factors_file: str | Path = '', popu_factors_file: str | Path = '', disease_state='healthy', PCL: float = 1000) BaseEMCoupling[source]#
interpolate(f_mech: Function, f_ep: Function) Function[source]#

Interpolates function from mechanics to ep mesh

property mech_mesh#
property mech_state: Function#
mechanics_to_coupling()[source]#
print_ep_info()[source]#
print_mechanics_info()[source]#
register_datacollector(collector: datacollector.DataCollector) None[source]#
register_ep_model(solver)[source]#
register_mech_model(solver: mechanics_model.MechanicsProblem)[source]#
register_time_stepper(time_stepper: TimeStepper) None[source]#
save_state(path: str | Path, config: Config | None = None) None[source]#
setup_assigners() None[source]#
solve_ep(interval: Tuple[float, float]) None[source]#
solve_mechanics() None[source]#
update_prev_ep()[source]#
update_prev_mechanics()[source]#
property vs: Function#

simcardems.models.explicit_ORdmm_Land#

class simcardems.models.explicit_ORdmm_Land.ActiveModel(coupling: EMCoupling, **kwargs)[source]#

Bases: ActiveModel

simcardems.models.explicit_ORdmm_Land.CellModel#

alias of ORdmmLandExplicit

class simcardems.models.explicit_ORdmm_Land.EMCoupling(geometry: BaseGeometry, lmbda: Function | None = None, **state_params)[source]#

Bases: BaseEMCoupling

property assigners: datacollector.Assigners#
cell_params()[source]#
coupling_to_ep()[source]#
coupling_to_mechanics()[source]#
property coupling_type#

CustomType

property dLambda_ep#
property ep_mesh#
ep_to_coupling()[source]#
classmethod from_state(path: str | Path, drug_factors_file: str | Path = '', popu_factors_file: str | Path = '', disease_state='healthy', PCL: float = 1000) BaseEMCoupling[source]#
interpolate(f_mech: Function, f_ep: Function) Function[source]#

Interpolates function from mechanics to ep mesh

property lmbda_mech#
property lmbda_mech_func#
property mech_mesh#
property mech_state#
mechanics_to_coupling()[source]#
print_ep_info()[source]#
print_mechanics_info()[source]#
register_datacollector(collector: datacollector.DataCollector) None[source]#
register_ep_model(solver: SplittingSolver)[source]#
register_mech_model(solver: mechanics_model.MechanicsProblem)[source]#
save_state(path: str | Path, config: Config | None = None) None[source]#
setup_assigners() None[source]#
solve_ep(interval: Tuple[float, float]) None[source]#
solve_mechanics() None[source]#
update_prev_ep()[source]#
update_prev_mechanics()[source]#
property vs: Function#

simcardems.models.pureEP_ORdmm_Land#

simcardems.models.pureEP_ORdmm_Land.CellModel#

alias of ORdmmLandPureEp

class simcardems.models.pureEP_ORdmm_Land.EMCoupling(geometry: BaseGeometry, t: float = 0.0, **kwargs)[source]#

Bases: BaseEMCoupling

property assigners: Assigners#
cell_params()[source]#
property coupling_type#

CustomType

property ep_mesh#
classmethod from_state(path: str | Path, drug_factors_file: str | Path = '', popu_factors_file: str | Path = '', disease_state='healthy', PCL: float = 1000) BaseEMCoupling[source]#
print_ep_info()[source]#
register_ep_model(solver: SplittingSolver)[source]#
save_state(path: str | Path, config: Config | None = None) None[source]#
setup_assigners() None[source]#
solve_ep(interval: Tuple[float, float]) None[source]#
update_prev_ep()[source]#
property vs: Function#

Module contents#

class simcardems.Config(outdir: pathlib.Path | str = 'results', outfilename: str = 'results.h5', geometry_path: pathlib.Path | str = '', geometry_schema_path: pathlib.Path | str | NoneType = None, T: float = 1000, dt: float = 0.05, bnd_rigid: bool = False, load_state: bool = False, cell_init_file: pathlib.Path | str = '', show_progress_bar: bool = True, save_freq: int = 1, pre_stretch: dolfin.function.constant.Constant | float | NoneType = None, traction: dolfin.function.constant.Constant | float = None, spring: dolfin.function.constant.Constant | float = None, fix_right_plane: bool = False, loglevel: int = 20, num_refinements: int = 1, set_material: str = '', debug_mode: bool = False, drug_factors_file: pathlib.Path | str = '', popu_factors_file: pathlib.Path | str = '', disease_state: str = 'healthy', dt_mech: float = 1.0, mech_threshold: float = 0.05, mechanics_solve_strategy: Literal['fixed', 'adaptive'] = 'adaptive', ep_ode_scheme: str = 'GRL1', ep_preconditioner: str = 'sor', ep_theta: float = 0.5, linear_mechanics_solver: str = 'mumps', mechanics_use_continuation: bool = False, mechanics_use_custom_newton_solver: bool = False, PCL: float = 1000, coupling_type: Literal['fully_coupled_ORdmm_Land', 'fully_coupled_Tor_Land', 'explicit_ORdmm_Land', 'pureEP_ORdmm_Land'] = 'fully_coupled_ORdmm_Land')[source]#

Bases: object

PCL: float = 1000#
T: float = 1000#
as_dict()[source]#
bnd_rigid: bool = False#
cell_init_file: Path | str = ''#
coupling_type: Literal['fully_coupled_ORdmm_Land', 'fully_coupled_Tor_Land', 'explicit_ORdmm_Land', 'pureEP_ORdmm_Land'] = 'fully_coupled_ORdmm_Land'#
debug_mode: bool = False#
disease_state: str = 'healthy'#
drug_factors_file: Path | str = ''#
dt: float = 0.05#
dt_mech: float = 1.0#
ep_ode_scheme: str = 'GRL1'#
ep_preconditioner: str = 'sor'#
ep_theta: float = 0.5#
fix_right_plane: bool = False#
geometry_path: Path | str = ''#
geometry_schema_path: Path | str | None = None#
linear_mechanics_solver: str = 'mumps'#
load_state: bool = False#
loglevel: int = 20#
mech_threshold: float = 0.05#
mechanics_solve_strategy: Literal['fixed', 'adaptive'] = 'adaptive'#
mechanics_use_continuation: bool = False#
mechanics_use_custom_newton_solver: bool = False#
num_refinements: int = 1#
outdir: Path | str = 'results'#
outfilename: str = 'results.h5'#
popu_factors_file: Path | str = ''#
pre_stretch: Constant | float | None = None#
save_freq: int = 1#
set_material: str = ''#
show_progress_bar: bool = True#
spring: Constant | float = None#
traction: Constant | float = None#
class simcardems.DataCollector(outdir, geo: BaseGeometry, outfilename: str = 'results.h5', reset_state=True)[source]#

Bases: object

property function_names: Dict[str, List[str]]#
property names: Dict[str, List[str]]#
register(group: str, name: str, f: Function, reduction: str = 'full') None[source]#
property results_file#
save_residual(residual, index)[source]#
store(t: float) None[source]#
property valid_reductions: List[str]#
class simcardems.DataLoader(h5name: Path | str, empty_ok: bool = False)[source]#

Bases: object

cleanup()[source]#
property ep_mesh#
extract_value(group: DataGroups, name: str, t: str | float, reduction: str = 'average')[source]#
property function_names: Dict[str, List[str]]#
get(group: DataGroups, name: str, t: str | float) Function[source]#

Retrieve the function from the file

Parameters:
  • group (DataGroups) – The group where the function is stored, either ‘ep’ or ‘mechanics’

  • name (str) – Name of the function

  • t (Union[str, float]) – Time stamp you want to use. See DataLoader.time_stamps

Returns:

The function

Return type:

dolfin.Function

Raises:
  • KeyError – If group does not exist in the file

  • KeyError – If name does not exist in group

  • KeyError – If ‘t’ provided is not among the time stamps

property mech_mesh#
property residual: List[ndarray]#
property size: int#
class simcardems.MechanicsNewtonSolver(problem: NonlinearProblem, state: Function, update_cb=None, parameters=None)[source]#

Bases: NewtonSolver

check_overloads_called()[source]#
converged(self: dolfin.cpp.nls.NewtonSolver, arg0: dolfin.cpp.la.GenericVector, arg1: dolfin::NonlinearProblem, arg2: int) bool[source]#
static default_solver_parameters()[source]#
register_datacollector(datacollector)[source]#
save_residuals() None[source]#
solve(self: dolfin.cpp.nls.NewtonSolver, arg0: dolfin::NonlinearProblem, arg1: dolfin.cpp.la.GenericVector) Tuple[int, bool][source]#
solver_setup(self: dolfin.cpp.nls.NewtonSolver, arg0: dolfin.cpp.la.GenericMatrix, arg1: dolfin.cpp.la.GenericMatrix, arg2: dolfin::NonlinearProblem, arg3: int) None[source]#
class simcardems.MechanicsNewtonSolver_ODE(problem: NonlinearProblem, state: Function, update_cb=None, parameters=None)[source]#

Bases: MechanicsNewtonSolver

update_solution(self: dolfin.cpp.nls.NewtonSolver, arg0: dolfin.cpp.la.GenericVector, arg1: dolfin.cpp.la.GenericVector, arg2: float, arg3: dolfin::NonlinearProblem, arg4: int) None[source]#
class simcardems.MechanicsProblem(*args, **kwargs)[source]#

Bases: ContinuationBasedMechanicsProblem

solve()[source]#

Solve the variational problem

\[\delta W = 0\]
property u_subspace_index: int#
class simcardems.RigidMotionProblem(*args, **kwargs)[source]#

Bases: MechanicsProblem

rigid_motion_term(u, r)[source]#
property u_subspace_index: int#
class simcardems.Runner(config: Config | None = None, empty: bool = False)[source]#

Bases: object

classmethod from_models(coupling: BaseEMCoupling, config: Config | None = None, reset: bool = True)[source]#
property outdir: Path#
save_state()[source]#
solve(T: float = 1000, save_freq: int = 1, show_progress_bar: bool = True, st_progress: ~typing.Any | None = None, default_save_condition: ~typing.Callable[[int, float, float], bool] = <function Runner.<lambda>>)[source]#
property state_path: Path#
store()[source]#
property t: float#
property t0: float#
class simcardems.TimeStepper(*, t0: float, T: float, dt: float, use_ns: bool = True, st_progress: Any | None = None)[source]#

Bases: object

property T: float#
property dt: float#
static ms2ns(t: float) float[source]#

Convert from milliseconds to nanoseconds

Parameters:

t (float) – Time in milliseconds

Returns:

Time in nanoseconds

Return type:

float

static ns2ms(t: float) float[source]#

Convert nanoseconds to milliseconds

Parameters:

t (float) – The time in nanoseconds

Returns:

Time in milliseconds

Return type:

float

reset()[source]#
property total_steps: int#
simcardems.default_parameters()[source]#