LearnMPM package

Submodules

LearnMPM.element module

class Bar1D

Bases: object

1D bar element with 2 nodes.

Attributes:

id: int

Element index.

nodes: list

List of nodes.

nnodes: int

Number of nodes in the element.

length: float

Element length.

particles: list

List of particles in the element.

compute_xi(x)

Computes the local xi (natural coordinates) of a given coordinate(x) The function transforms the physical coordinate to a natural coordinate. We call the is_point_in_element(x) function to check if the coordinate is in the cell.

Args:

x: coordinate of material point

Returns:

A tuple of a boolean to indicate if a coordinate is in the cell or not and the natural coordinate equivalent of the physical coordinate. We return a value of zero for the natural coordinate, if the coordinate is not in the cell.

is_point_in_element(x)

Checks if a given material point coordinates is withing the cell

Args:

x: coordinate of material point

Returns:

A boolean to indicate if a coordinate is in the cell or not

LearnMPM.interpolate module

Map quantities from particles to nodes using a interpolation function. This functions, have the general form:

\[\phi_i = \sum_p N_i(x_p) \phi_p\]

where,

\(\phi_i\) is a nodal quantity,

\(\phi_p\) is a particle quantity, and

\(N_i(x_p)\) is the terpolation function of the node i evaluated at particle position \(x_p\).

body_force_to_nodes(mesh, gravity)

Compute body force at the nodes. The external force \(f_{ext} = \sum_i N_i * m_p * g\).

Args:

mesh: mesh object with nodes, elements and particles

external_force_to_nodes(mesh)

Map external force of the particles to the nodes. The nodal external force \(f_{ext} = \sum_i N_i * {f_{ext}}_p\).

Args:

mesh: mesh object with nodes, elements and particles

internal_force_to_nodes(mesh)

Map internal force to nodes. The nodal stresses are mapped to the nodes as internal force. The nodal internal force \(f_{int} = -\sum_i dN_i \sigma_p m_p / P_p\).

Args:

mesh: mesh object with nodes, elements and particles

mass_momentum_to_nodes(mesh)

Map mass and momentum of particles in the elements to the associated nodes.

Args:

mesh: mesh object with nodes, elements and particles

LearnMPM.material module

class LinearElastic1D(E, density)

Bases: object

Linear Elastic material for 1D

Attributes:

E: float

Young’s modulus

density: float

Density of material point

__init__(E, density)

Initialize material properties

Args:

E: Young’s modulus

density: Density

update_stress(particle)

Update particle stress based on particle strain. \(d\sigma = E \cdot d\epsilon\) and the stress \(\sigma = \sigma + d \sigma\).

Args:

particle: Particle object

LearnMPM.mesh module

class Mesh1D(domain_size, nelements)

Bases: object

1D Mesh class with nodes, elements and particles.

Attributes:

nodes: List

List of nodes

elements: List

List of elements

particles: List

List of particles

boundary_nodes: List

Node ids of the boundary nodes

nelements: int

Number of elements in the mesh

dim: int

Dimension of Mesh (1D)

generate_particles_gauss(ppc, material)

Distributes particles at Gauss locations in the elements.

Parameters:
  • ppc (int) – number of particles per cell

  • material (material) – a material object

generate_particles_uniform(ppc, material)

Distributes particles uniformly across all elements in the mesh

Parameters:
  • ppc (int) – number of particles per cell

  • material (material) – a material object

LearnMPM.meta module

Metadata for LearnMPM.

LearnMPM.node module

class Node1D

Bases: object

1D MPM node

Attributes:
id: int

Index of node class.

x: float

Location of node.

mass: float

Mass at node.

velocity: float

Velocity at node.

momentum: float

Momentum at node.

f_int: float

Internal force.

f_ext: float

External force.

f_damp: float

Damping force at the node.

f_total: float

Total nodal force.

compute_damping_force(alpha)

Compute the nodal damping force based on the nodal unbalanced forces.

Arguments:

alpha: Damping coefficient.

reset_values()

Reset nodal values to zero at the end of time step.

LearnMPM.params module

class Params

Bases: object

Configuration object for handling MPM simulation

Attributes:

interpolation_typestring

interpolation function type ‘linear’

integration_schemestring

material point method integration scheme, can be ‘USL’, ‘USF’ or ‘MUSL’

nstepsfloat

Total number of simulation steps

dtfloat

time step

results_particleinteger

index of the particle to get the solution

results_fieldsstring

solution fields (position or velocity)

results: array

array to store the results wrt time

damping: float

alpha local damping factor proportional to the total nodal force

LearnMPM.particle module

class Particle1D(mass, x, xi, material)

Bases: object

1D material point object

Attributes:
id: int

particle id

mass: float

particle mass

x: float

particle position

xi: float

particle position in natural coordinates

material: material type

material

density: float

particle density

velocity: float

particle velocity

stress: float

particle stress

dstrain: float

particle strain increment

f_ext: float

external force in particle

volume: float

particle volume

element: element type

element containing the particle

shapefn: array

nodal interpolation functions

dn_dx: array

gradient of interpolation fn in physical coordinates

__init__(mass, x, xi, material)

Initialize particle class

Arguments:
mass: float

Mass of particle

x: float

Particle location in physical coordinates

xi: float

Particle location in natural coordinates

material: material type

compute_strain(dt)

Compute particle strain by mapping nodal velocity with gradient of interpolation fn.

Arguments:
dt: float

time step of simulation.

LearnMPM.shapefn module

class Linear1D

Bases: object

Define linear 1D shape function for element.

dn_dx(xi, coords)

Linear 1D gradient of shape function in physical coordinates.

Arguments:
xi: float

location in natural coordinates

coords: array

Nodal coordinates

Returns:

Gradient of 1D shape fn in physical coords at xi

gauss_pts(ngauss)

Gauss point coordinates of an element

Arguments:
ngauss: int

Number of gauss points

Returns:

Location of gauss points in the element

gradsf(xi)

Linear 1D gradient of shape function in natural coordinates.

Arguments:
xi: float

location in natural coordinates

Returns:

Gradient of shape function of 1D linear element.

sf(xi)

Linear 1D shape function in natural coordinates.

Arguments:
xi: float

location in natural coordinates

Returns:

shape function of 1D linear element in natural coords.

LearnMPM.solver module

compute_stress(mesh, params)

compute stress update: (1) compute nodal velocity, (2) particle strain increment, (3) update particle volume and density based on dstrain, and (4) compute particle stress.

Arguments:

mesh: Mesh object

params: MPM simulation set-up

explicit_solution(mesh, params)

LearnMPM.update module

fix_nodal_bc_force(mesh)

Set nodal force to zero on specific boundary nodes.

Arguments:
mesh: mesh

a mesh object

fix_nodal_bc_momentum(mesh)

Set momentum and velocity to zero on specific boundary nodes.

Arguments:
mesh: mesh

a mesh object

locate_particles(mesh)

Locate particle in the mesh and compute xi (natural coordinates) of the material points.

Arguments:
mesh: mesh

a mesh object

momentum_in_nodes(mesh, dt)

Compute momentum in nodes. \(mv += force * dt\)

Arguments:
mesh: mesh

a mesh object

dt: float

time step

nodal_acceleration_velocity(mesh, dt)

Compute nodal acceleration as \(a = f / m\) and v += a * dt

Arguments:
mesh: mesh

a mesh object

dt: float

time step

nodal_momentum(mesh)

Update nodal momentum \((mv)_i = \sum_p N_i(x_p) * m_p * v_p\).

Arguments:
mesh: mesh

a mesh object

dt: float

time step

nodal_total_force(mesh)

Compute total force as sum of internal, external and damping force.

Arguments:
mesh: mesh

a mesh object

nodal_velocity(mesh)

Compute nodal velocity as \(v = mv / m\).

Arguments:
mesh: mesh

a mesh object

particle_position(mesh, dt)

Compute particle position based on nodal momentum to particle. \(x_p += \sum_i N_i(x_p) * {mv}_i/m_i * dt\).

Arguments:
mesh: mesh

a mesh object

dt: float

time step

particle_position_velocity(mesh, dt)

Compute particle position and velocity based on nodal velocity. \(x_p += \sum_i N_i(x_p) * v_i\) and particle position \(x_p += v_p * dt\).

Arguments:
mesh: mesh

a mesh object

dt: float

time step

particle_strain_increment(mesh, dt)

Particle strain increment. Compute strain based on nodal velocity.

Arguments:
mesh: mesh

a mesh object

dt: float

time step

particle_stress(mesh)

Update particle stress based on dstrain.

Arguments:
mesh: mesh

a mesh object

particle_velocity(mesh, dt)

Compute particle velocity transfer nodal velocity to particle. \(v_p += \sum_i N_i(x_p) * {f_{total}}_i/m_i * dt\).

Arguments:
mesh: mesh

a mesh object

dt: float

time step

particle_volume_density(mesh)

Compute particle volume from \(V_p *= (1 + d\epsilon)\) and \(density = density / (1 + \epsilon)\)

Arguments:
mesh: mesh

a mesh object

reset_nodal_values(mesh)

Reset nodal values at the end of the iteration. Reset mesh.

Module contents

Import class definitions into the LearnMPM package namespace.