elastodynamicsx.solvers.timedomain

Module contents

The timedomain module contains tools for solving time-dependent problems. Note that building the problem is the role of the pde.timescheme module.

class elastodynamicsx.solvers.timedomain.TimeStepper(comm: Comm, tscheme: TimeScheme, **kwargs)[source]

Bases: object

Base class for solving time-dependent problems.

petsc_options_explicit_scheme = {'ksp_type': 'preonly', 'pc_type': 'lu'}
petsc_options_implicit_scheme_linear = {'ksp_type': 'preonly', 'pc_type': 'lu'}
build(**kwargs)[source]

Convenience static method that instanciates the required time-stepping scheme

Parameters:

args – (passed to the required scheme)

Keyword Arguments:
  • scheme – (required) Available options are ‘leapfrog’, ‘midpoint’ ‘linear-acceleration-method’, ‘newmark’, ‘hht-alpha’, ‘generalized-alpha’

  • **kwargs – (passed to the required scheme)

static Courant_number(domain: Mesh, c_max, dt)[source]

The Courant number: \(C = c_{max} \, \mathrm{d}t / h\), with \(h\) the cell diameter

Related to the Courant-Friedrichs-Lewy (CFL) condition.

Parameters:
  • domain – the mesh

  • c_max – ufl-compatible, the maximum velocity

  • dt – ufl-compatible, the time step

See:

https://en.wikipedia.org/wiki/Courant%E2%80%93Friedrichs%E2%80%93Lewy_condition

property timescheme
property t
property dt
set_initial_condition(u0, v0, t0=0) None[source]

Apply initial conditions

Parameters:
  • u0 – u at t0

  • v0 – du/dt at t0

  • t0 – start time (default: 0)

u0 and v0 can be:
  • Python callable -> will be evaluated at nodes

    -> e.g. u0 = lambda x: np.zeros((dim, x.shape[1]), dtype=PETSc.ScalarType)

  • scalar (int, float, complex, PETSc.ScalarType)

    -> e.g. u0 = 0

  • array (list, tuple, np.ndarray) or fem.function.Constant

    -> e.g. u0 = [0,0,0]

  • fem.function.Function

    -> e.g. u0 = fem.Function(V)

solve(num_steps, **kwargs)[source]
class elastodynamicsx.solvers.timedomain.NonlinearTimeStepper(comm: Comm, tscheme: TimeScheme, **kwargs)[source]

Bases: TimeStepper

Base class for solving nonlinear problems using implicit time schemes. Not implemented yet.

class elastodynamicsx.solvers.timedomain.LinearTimeStepper(comm: Comm, tscheme: TimeScheme, A: Mat, b: Vec, **kwargs)[source]

Bases: TimeStepper

Base class for solving linear problems. Note that nonlinear problems formulated with an explicit scheme come down to linear problems; they are handled by this class.

property A: Mat | Vec
property b: Vec
property explicit: bool
property solver: KSP | DiagonalSolver
class elastodynamicsx.solvers.timedomain.OneStepTimeStepper(comm: Comm, tscheme: TimeScheme, A: Mat, b: Vec, **kwargs)[source]

Bases: LinearTimeStepper

Base class for solving time-dependent problems with one-step algorithms (e.g. Newmark-beta methods).

solve(num_steps, **kwargs)[source]

Run the loop on time steps

Parameters:

num_steps – number of time steps to integrate

Keyword Arguments:
  • callfirsts – (default=[]) list of functions to be called at the beginning of each iteration (before solving). For instance: update a source term. Each callfirst if of the form: cf = lambda t: do_something where t is the time at which to evaluate the sources

  • callbacks – (detault=[]) similar to callfirsts, but the callbacks are called at the end of each iteration (after solving). For instance: store/save, plot, print, … Each callback is of the form cb = lambda i, out: -> do_something() where i is the iteration index and out is the PETSc.Vec vector just solved for

  • live_plotter – a plotter object that can refresh through a live_plotter.live_plotter_update_function(i, out) function

  • verbose – (default=0) Verbosity level. >9 means an info msg before each step

elastodynamicsx.solvers.timestepper.timestepper

class elastodynamicsx.solvers.timedomain.timesteppers.DiagonalSolver(A: Vec)[source]

Bases: object

A solver with a diagonal left hand side

Parameters:

A – A PETSc vector that represents a diagonal matrix

solve(b: Vec, out: Vec) None[source]

Solve (in-place) the linear system \(\mathbf{A} * \mathbf{out} = \mathbf{b}\)

class elastodynamicsx.solvers.timedomain.timesteppers.TimeStepper(comm: Comm, tscheme: TimeScheme, **kwargs)[source]

Bases: object

Base class for solving time-dependent problems.

petsc_options_explicit_scheme = {'ksp_type': 'preonly', 'pc_type': 'lu'}
petsc_options_implicit_scheme_linear = {'ksp_type': 'preonly', 'pc_type': 'lu'}
build(**kwargs)[source]

Convenience static method that instanciates the required time-stepping scheme

Parameters:

args – (passed to the required scheme)

Keyword Arguments:
  • scheme – (required) Available options are ‘leapfrog’, ‘midpoint’ ‘linear-acceleration-method’, ‘newmark’, ‘hht-alpha’, ‘generalized-alpha’

  • **kwargs – (passed to the required scheme)

static Courant_number(domain: Mesh, c_max, dt)[source]

The Courant number: \(C = c_{max} \, \mathrm{d}t / h\), with \(h\) the cell diameter

Related to the Courant-Friedrichs-Lewy (CFL) condition.

Parameters:
  • domain – the mesh

  • c_max – ufl-compatible, the maximum velocity

  • dt – ufl-compatible, the time step

See:

https://en.wikipedia.org/wiki/Courant%E2%80%93Friedrichs%E2%80%93Lewy_condition

property timescheme
property t
property dt
set_initial_condition(u0, v0, t0=0) None[source]

Apply initial conditions

Parameters:
  • u0 – u at t0

  • v0 – du/dt at t0

  • t0 – start time (default: 0)

u0 and v0 can be:
  • Python callable -> will be evaluated at nodes

    -> e.g. u0 = lambda x: np.zeros((dim, x.shape[1]), dtype=PETSc.ScalarType)

  • scalar (int, float, complex, PETSc.ScalarType)

    -> e.g. u0 = 0

  • array (list, tuple, np.ndarray) or fem.function.Constant

    -> e.g. u0 = [0,0,0]

  • fem.function.Function

    -> e.g. u0 = fem.Function(V)

solve(num_steps, **kwargs)[source]
class elastodynamicsx.solvers.timedomain.timesteppers.NonlinearTimeStepper(comm: Comm, tscheme: TimeScheme, **kwargs)[source]

Bases: TimeStepper

Base class for solving nonlinear problems using implicit time schemes. Not implemented yet.

class elastodynamicsx.solvers.timedomain.timesteppers.LinearTimeStepper(comm: Comm, tscheme: TimeScheme, A: Mat, b: Vec, **kwargs)[source]

Bases: TimeStepper

Base class for solving linear problems. Note that nonlinear problems formulated with an explicit scheme come down to linear problems; they are handled by this class.

property A: Mat | Vec
property b: Vec
property explicit: bool
property solver: KSP | DiagonalSolver
class elastodynamicsx.solvers.timedomain.timesteppers.OneStepTimeStepper(comm: Comm, tscheme: TimeScheme, A: Mat, b: Vec, **kwargs)[source]

Bases: LinearTimeStepper

Base class for solving time-dependent problems with one-step algorithms (e.g. Newmark-beta methods).

solve(num_steps, **kwargs)[source]

Run the loop on time steps

Parameters:

num_steps – number of time steps to integrate

Keyword Arguments:
  • callfirsts – (default=[]) list of functions to be called at the beginning of each iteration (before solving). For instance: update a source term. Each callfirst if of the form: cf = lambda t: do_something where t is the time at which to evaluate the sources

  • callbacks – (detault=[]) similar to callfirsts, but the callbacks are called at the end of each iteration (after solving). For instance: store/save, plot, print, … Each callback is of the form cb = lambda i, out: -> do_something() where i is the iteration index and out is the PETSc.Vec vector just solved for

  • live_plotter – a plotter object that can refresh through a live_plotter.live_plotter_update_function(i, out) function

  • verbose – (default=0) Verbosity level. >9 means an info msg before each step