dctkit.physics namespace

Submodules

dctkit.physics.elastica module

class dctkit.physics.elastica.Elastica(num_elements: float, L: float)[source]

Bases: object

Euler’s Elastica class.

Parameters:
  • num_elements – number of elements of primal mesh.

  • L – length of the rod.

energy(theta: ndarray[tuple[Any, ...], dtype[_ScalarT]], B: float, theta_0: float, F: float) Array[source]

Computes the total potential energy.

Parameters:
  • theta – current configuration angles.

  • B – bending stiffness.

  • theta_0 – prescribed value of the angle at the left end (cantilever).

  • F – vertical component of the applied force at the right end.

Returns:

value of the energy.

get_elastica_mesh()[source]

Constructs the normalized simplicial complex in the interval [0,1].

obj_stiffness(theta: ndarray[tuple[Any, ...], dtype[_ScalarT]], B: float, theta_true: ndarray[tuple[Any, ...], dtype[_ScalarT]]) Array[source]
Objective function for the bending stiffness identification problem

(inverse problem).

Parameters:
  • theta – candidate solution (except left angle).

  • B – candidate bending stiffness.

  • theta_true – true solution.

Returns:

error between the candidate and the true solutions.

dctkit.physics.elasticity module

class dctkit.physics.elasticity.LinearElasticity(S: SimplicialComplex, mu_: float, lambda_: float)[source]

Bases: object

Linear elasticity class.

Parameters:
  • S – reference configuration simplicial complex.

  • mu – Lamé modulus.

  • lambda – Lamé modulus.

elasticity_energy(node_coords: CochainP0, f: CochainP0) float[source]

Compute the elasticity energy of isotropic linear elastic materials in 2D with no body force using DEC framework.

Parameters:
  • node_coords – primal vector valued 0-cochain of node coordinates of the current configuration.

  • f – primal vector-valued 2-cochain of sources.

Returns:

the energy.

force_balance_residual_dual(node_coords: CochainP0, f: CochainD2, boundary_tractions: Dict[str, Tuple[Array, Array]]) CochainD2[source]
Compute the residual of the discrete balance equation in the case

of isotropic linear elastic materials in 2D using DEC framework.

Parameters:
  • node_coords – primal vector valued 0-cochain of node coordinates of the current configuration.

  • f – dual vector-valued 2-cochain of sources.

  • boundary_tractions – a dictionary of tuples. Each key represent the type of coordinate to manipulate (x,y, or both), while each tuple consists of two jax arrays, in which the first encordes the indices where we want to impose the boundary tractions, while the last encodes the boundary traction values themselves.

Returns:

the residual vector-valued cochain.

force_balance_residual_primal(node_coords: CochainP0, f: CochainP2, boundary_tractions: Dict[str, Tuple[Array, Array]]) CochainP2[source]
Compute the residual of the discrete balance equation in the case

of isotropic linear elastic materials in 2D using DEC framework.

Parameters:
  • node_coords – primal vector valued 0-cochain of node coordinates of the current configuration.

  • f – primal vector-valued 2-cochain of sources.

  • boundary_tractions – a dictionary of tuples. Each key represent the type of coordinate to manipulate (x,y, or both), while each tuple consists of two jax arrays, in which the first encordes the indices where we want to impose the boundary tractions, while the last encodes the boundary traction values themselves.

Returns:

the residual vector-valued cochain.

get_GreenLagrange_strain(node_coords: ndarray[tuple[Any, ...], dtype[_ScalarT]] | Array) ndarray[tuple[Any, ...], dtype[_ScalarT]] | Array[source]

Compute the discrete GL strain tensor given the current node coordinates.

Parameters:

node_coords – current node coordinates.

Returns:

the discrete GL strain tensor.

get_dual_balance(node_coords: CochainP0, boundary_tractions: Dict[str, Tuple[Array, Array]]) CochainD2[source]
Compute the balance of the discrete balance equation in the case

of isotropic linear elastic materials in 2D using DEC framework.

Parameters:
  • node_coords – primal vector valued 0-cochain of node coordinates of the current configuration.

  • f – dual vector-valued 2-cochain of sources.

  • boundary_tractions – a dictionary of tuples. Each key represent the type of coordinate to manipulate (x,y, or both), while each tuple consists of two jax arrays, in which the first encordes the indices where we want to impose the boundary tractions, while the last encodes the boundary traction values themselves.

Returns:

the balance vector-valued cochain.

get_infinitesimal_strain(node_coords: ndarray[tuple[Any, ...], dtype[_ScalarT]] | Array) ndarray[tuple[Any, ...], dtype[_ScalarT]] | Array[source]

Compute the discrete strain tensor given the current node coordinates.

Parameters:

node_coords – current node coordinates.

Returns:

the discrete infinitesimal strain tensor.

get_penalty_displacement_bc(node_coords: ndarray[tuple[Any, ...], dtype[_ScalarT]] | Array, boundary_values: Dict[str, Tuple[Array, Array]], gamma: float) float[source]

Set displacement boundary conditions as a quadratic penalty term.

Parameters:
  • node_coords – node coordinates of the current configuration.

  • boundary_values – a dictionary of tuples. Each key represent the type of coordinate to manipulate (x,y, or both), while each tuple consists of two np.arrays in which the first encodes the indices of boundary values, while the last encodes the boundary values themselves.

  • gamma – penalty factor.

Returns:

the penalty term.

get_stress(strain: ndarray[tuple[Any, ...], dtype[_ScalarT]] | Array) Array[source]

Compute the discrete stress tensor from strains using the consistutive equation for isotropic linear elastic materials.

Parameters:

strain – discrete strain tensor.

Returns:

the discrete stress tensor.

obj_linear_elasticity_dual(unknown_node_coords: ndarray[tuple[Any, ...], dtype[_ScalarT]] | Array, f: ndarray[tuple[Any, ...], dtype[_ScalarT]] | Array, boundary_values: Dict[str, Tuple[Array, Array]], boundary_tractions: Dict[str, Tuple[Array, Array]], curr_node_coords: ndarray[tuple[Any, ...], dtype[_ScalarT]] | Array, unknown_node_idx: ndarray[tuple[Any, ...], dtype[_ScalarT]] | Array) float[source]

Objective function of the optimization problem associated to linear elasticity balance equation with Dirichlet boundary conditions on a portion of the boundary.

Parameters:
  • unknown_node_coords – 1-dimensional array obtained after flattening the matrix with unknown node coordinates.

  • f – matrix of external sources (constant term of the system).

  • boundary_values – a dictionary of tuples. Each key represent the type of coordinate to manipulate (x,y, or both), while each tuple consists of two np.arrays in which the first encodes the indices of boundary values, while the last encodes the boundary values themselves.

  • boundary_tractions – a dictionary of tuples. Each key represent the type of coordinate to manipulate (x,y, or both), while each tuple consists of two jax arrays, in which the first encordes the indices where we want to impose the boundary tractions, while the last encodes the boundary traction values themselves. It is None when we perform the force balance on dual cells.

  • curr_node_coords – nan matrix of size equal to self.S.node_coords.size. It is filled with displacement boundary conditions and unknown current node coordinates.

  • unknown_node_idx – indexes (in the flattened array) of the node coordinates non-corresponding to boundary conditions.

Returns:

the value of the objective function at node_coords.

obj_linear_elasticity_energy(node_coords: ndarray[tuple[Any, ...], dtype[_ScalarT]] | Array, f: ndarray[tuple[Any, ...], dtype[_ScalarT]] | Array, gamma: float, boundary_values: Dict[str, Tuple[Array, Array]]) float[source]

Objective function of the optimization problem associated to linear elasticity (energy formulation) with Dirichlet boundary conditions on a portion of the boundary.

Parameters:
  • node_coords – 1-dimensional array obtained after flattening the matrix with node coordinates arranged row-wise.

  • f – matrix of external sources (constant term of the system).

  • gamma – penalty factor.

  • boundary_values – a dictionary of tuples. Each key represent the type of coordinate to manipulate (x,y, or both), while each tuple consists of two np.arrays in which the first encodes the indices of boundary values, while the last encodes the boundary values themselves.

Returns:

the value of the objective function at node_coords.

obj_linear_elasticity_primal(node_coords: ndarray[tuple[Any, ...], dtype[_ScalarT]] | Array, f: ndarray[tuple[Any, ...], dtype[_ScalarT]] | Array, gamma: float, boundary_values: Dict[str, Tuple[Array, Array]], boundary_tractions: Dict[str, Tuple[Array, Array]]) float[source]

Objective function of the optimization problem associated to linear elasticity balance equation with Dirichlet boundary conditions on a portion of the boundary.

Parameters:
  • node_coords – 1-dimensional array obtained after flattening the matrix with node coordinates arranged row-wise.

  • f – matrix of external sources (constant term of the system).

  • gamma – penalty factor.

  • boundary_values – a dictionary of tuples. Each key represent the type of coordinate to manipulate (x,y, or both), while each tuple consists of two np.arrays in which the first encodes the indices of boundary values, while the last encodes the boundary values themselves.

  • boundary_tractions – a dictionary of tuples. Each key represent the type of coordinate to manipulate (x,y, or both), while each tuple consists of two jax arrays, in which the first encordes the indices where we want to impose the boundary tractions, while the last encodes the boundary traction values themselves. It is None when we perform the force balance on dual cells.

Returns:

the value of the objective function at node_coords.

set_boundary_tractions(forces: CochainP1, boundary_tractions: Dict[str, Tuple[Array, Array]]) CochainP1[source]

Set the boundary tractions on primal edges.

Parameters:
  • forces – vector-valued primal 1-cochain containing forces acting on primal edges.

  • boundary_tractions – a dictionary of tuples. Each key represent the type of coordinate to manipulate (x,y, or both), while each tuple consists of two jax arrays, in which the first encordes the indices where we want to impose the boundary tractions, while the last encodes the boundary traction values themselves.

Returns:

the updated force 1-cochain.

set_displacement_bc(curr_node_coords: ndarray[tuple[Any, ...], dtype[_ScalarT]] | Array, boundary_values: Dict[str, Tuple[Array, Array]]) Array[source]

Set linear displacement boundary conditions.

Parameters:
  • curr_node_coords – nan matrix of size equal to self.S.node_coords.size.

  • boundary_values – a dictionary of tuples. Each key represent the type of coordinate to manipulate (x,y, or both), while each tuple consists of two np.arrays in which the first encodes the indices of boundary values, while the last encodes the boundary values themselves.

Returns:

updated curr_node_coords.

dctkit.physics.poisson module

dctkit.physics.poisson.energy_poisson(x: ndarray[tuple[Any, ...], dtype[_ScalarT]], f: ndarray[tuple[Any, ...], dtype[_ScalarT]], S, k: float, boundary_values: Tuple[ndarray[tuple[Any, ...], dtype[_ScalarT]], ndarray[tuple[Any, ...], dtype[_ScalarT]]], gamma: float) float[source]

Implementation of the discrete Dirichlet energy.

Parameters:
  • x – array of the nodal values of the state variable (0-cochain)

  • f – array of the coefficients of the primal 0-cochain source term

  • S – a simplicial complex representing the mesh where the energy is defined

  • k – the diffusitivity coefficient

  • boundary_values – tuple of two arrays where the first encodes the positions of boundary values, and the second encodes the boundary values

  • gamma – penalty factor for the Dirichlet boundary conditions

Returns:

value of the energy.

dctkit.physics.poisson.grad_energy_poisson(x, f, S, k, boundary_values, gamma)[source]

Gradient of the Dirichlet energy.

Parameters:
  • x – vector in which we want to evaluate the gradient.

  • f – array of the coefficients of the primal 0-cochain source term

  • S – a simplicial complex in which we define the cochain to apply Poisson.

  • k – the diffusitivity coefficient.

  • boundary_values – tuple of two np.arrays in which the first encodes the positions of boundary values, while the last encodes the boundary values themselves.

  • gamma – penalty factor.

Returns:

the value of the gradient of the objective function at x.

dctkit.physics.poisson.grad_obj_poisson(x: ndarray[tuple[Any, ...], dtype[_ScalarT]], f: ndarray[tuple[Any, ...], dtype[_ScalarT]], S: SimplicialComplex, k: float, boundary_values: Tuple[ndarray[tuple[Any, ...], dtype[_ScalarT]], ndarray[tuple[Any, ...], dtype[_ScalarT]]], gamma: float, mask: ndarray[tuple[Any, ...], dtype[_ScalarT]]) Array | ndarray[tuple[Any, ...], dtype[_ScalarT]][source]

Gradient of the objective function of the Poisson optimization problem.

Parameters:
  • x – vector in which we want to evaluate the gradient.

  • f – vector of external sources (constant term of the system).

  • S – a simplicial complex in which we define the cochain to apply Poisson.

  • k – the diffusitivity coefficient.

  • boundary_values (tuple) – tuple of two np.arrays in which the first encodes the positions of boundary values, while the last encodes the boundary values themselves.

  • gamma – penalty factor.

Returns:

the value of the gradient of the objective function at x.

dctkit.physics.poisson.obj_poisson(x: ndarray[tuple[Any, ...], dtype[_ScalarT]], f: ndarray[tuple[Any, ...], dtype[_ScalarT]], S: SimplicialComplex, k: float, boundary_values: Tuple[ndarray[tuple[Any, ...], dtype[_ScalarT]], ndarray[tuple[Any, ...], dtype[_ScalarT]]], gamma: float, mask) float[source]

Objective function of the optimization problem associated to Poisson equation with Dirichlet boundary conditions.

Parameters:
  • x – vector in which we want to evaluate the objective function.

  • f – vector of external sources (constant term of the system).

  • S – a simplicial complex in which we define the cochain to apply Poisson.

  • k – the diffusitivity coefficient.

  • boundary_values – tuple of two np.arrays in which the first encodes the positions of boundary values, while the last encodes the boundary values themselves.

  • gamma – penalty factor.

Returns:

the value of the objective function at x.

dctkit.physics.poisson.poisson_residual(u: CochainP0, f: CochainD2, k: float) Cochain[source]

Compute the residual of the discrete Poisson equation in 2D using DEC framework.

-dh + f = 0, h = -k*star*du => Au + f = 0, A=d star d: matrix associated to the conformal Laplacian

Parameters:
  • u – a primal 0-cochain

  • f – dual 2-cochain of sources

  • k – the diffusitivity coefficient

Returns:

residual cochain