Skip to main content
. Author manuscript; available in PMC: 2021 Jun 24.
Published in final edited form as: Int J Numer Method Biomed Eng. 2021 Feb 10;37(4):e3438. doi: 10.1002/cnm.3438

Listing 1:

The Python code snippet for the NN material model

def E2S(E_PD, E_XD, E_phi, sigma, W0, b0, W1, b1, W2, b2):
  ″″″Compute the stress components using the NN material model.
  Wi and bi (i = 0,1,2) are the weights and biases of the NN model.″″″
  # An elementwise softplus function
  def softplus (x, beta = 1., threshold = 20.):
    def _elem_softplus (x, beta=beta, threshold=threshold):
      return 1./beta*ln(exp(beta*x) + 1)
    y = elem_op (_elem_softplus, x)
    return y
  # The NN model prediction
  inputs = as_vector ([E_PD, E_XD, E_phi, sigma])
  y1 = softplus (dot(W0, inputs) + b0)
  y2 = softplus (dot(W1, y1) + b1)
  outputs = dot (W2, y2) + b2
  # Impose zero shear stresses for zero shear strains
  multiplier = as_vector ([1., 1., E[2]])
  S = elem_mult (multiplier, outputs)
  return S