mechanoChemML.src.pde_layers

Module Contents

Classes

LayerFillRandomToBCs A customized Keras layer to add random noise to BCs with \(\epsilon~\sim\) N(0, stddev=0.005).
LayerFillZeros A customized Keras layer to generate zeros if value == -2.0
LayerFillRandomNumber A customized Keras layer to generate uniform random data (0, 1) if value == -2.0
LayerBulkResidual General bulk residual

Functions

GetElementResidualMask(data) Create a mask [batch, node_height, node_width, 1] for data [batch, node_height, node_width, m] where only the actual residual region is 1, the remaining part is zero.
ComputeBoundaryMaskNodalData(data_input, dof, opt=1) Create Dirichlet mask or Neumann mask based on the inputs, where only the boundary part is 0.0, margin and the body part is 1.0.
ComputeNeumannBoundaryResidualNodalData(data_input, dh, dof, padding=’SAME’) Compute the residual on the Neumann BCs. The implementation is based on Neumann BCs is scaled between (-1, 1), and Neumann condition should be always > 0 in the domain region. Raise value error if negative value is detected
ComputeNeumannBoundaryResidualNodalDataNew(data_input, dh, dof, padding=’SAME’) Compute the residual on the Neumann BCs. The implementation is based on Neumann BCs is scaled between (-1, 1), and Neumann condition should be always > 0 in the domain region. Raise value error if negative value is detected
Get1DGaussPointInfo(dh=1.0, GPs=2, dof=1)
param dh:element size
Get2DGaussPointInfo(dh=1.0, GPs=4, dof=1)
param dh:element size
GetNodalInfoFromElementInfo(data, residual_mask, dof, padding=’SAME’) reorganize data from a matrix form with 4 nodal values of elements to nodal values
mechanoChemML.src.pde_layers.GetElementResidualMask(data)[source]

Create a mask [batch, node_height, node_width, 1] for data [batch, node_height, node_width, m] where only the actual residual region is 1, the remaining part is zero.

Parameters:data (numpy array) – [batch, node_height, node_width, m] (scalar/vector)
Returns:mask [batch, elem_height, elem_width, 1] (same padding is used.)
Return type:numpy array
mechanoChemML.src.pde_layers.ComputeBoundaryMaskNodalData(data_input, dof, opt=1)[source]

Create Dirichlet mask or Neumann mask based on the inputs, where only the boundary part is 0.0, margin and the body part is 1.0.

Parameters:
  • data_input (numpy array) – size of [batch, node_height, node_width, dof*2]
  • dof (int) – dof per node
  • opt (int) – Dirichlet Mask (opt=1), Neumann mask (opt=2)
Returns:

boundary mask with size of [batch, node_height, node_width, dof]

Return type:

numpy array

Todo

make this function to work with (1S, 1V), 2S, 1V1S, 3S, 2V, etc.

mechanoChemML.src.pde_layers.ComputeNeumannBoundaryResidualNodalData(data_input, dh, dof, padding='SAME')[source]

Compute the residual on the Neumann BCs. The implementation is based on Neumann BCs is scaled between (-1, 1), and Neumann condition should be always > 0 in the domain region. Raise value error if negative value is detected

Parameters:
  • data_input (numpy array) – size of [batch, node_height, node_width, dof*2]
  • dof (int) – dof per node
  • dh (float) – element size
Returns:

nodal Neumann residual value with size of [batch, node_height, node_width, dof]

Return type:

numpy array

Todo

make this function to work with (1S, 1V), 2S, 1V1S, 3S, 2V, etc.

loop over each dof, instead of implementing different dof opt.

mechanoChemML.src.pde_layers.ComputeNeumannBoundaryResidualNodalDataNew(data_input, dh, dof, padding='SAME')[source]

Compute the residual on the Neumann BCs. The implementation is based on Neumann BCs is scaled between (-1, 1), and Neumann condition should be always > 0 in the domain region. Raise value error if negative value is detected

Parameters:
  • data_input (numpy array) – size of [batch, node_height, node_width, dof*3]
  • dof (int) – dof per node
  • dh (float) – element size
Returns:

nodal Neumann residual value with size of [batch, node_height, node_width, dof]

Return type:

numpy array

Todo

make this function to work with (1S, 1V), 2S, 1V1S, 3S, 2V, etc.

loop over each dof, instead of implementing different dof opt.

mechanoChemML.src.pde_layers.Get1DGaussPointInfo(dh=1.0, GPs=2, dof=1)[source]
Parameters:
  • dh (float) – element size
  • GPs (int) – total Gauss point number
  • dof (int) – dof per node
Returns:

  • shape function (numpy array) with size of [GPs, Nodes=2]
  • gradient shape function (numpy array) [None] Not implemented.
  • weight per gauss point (float scalar)

Todo

make this function to work with (1S, 1V), 2S, 1V1S, 3S, 2V, etc.

mechanoChemML.src.pde_layers.Get2DGaussPointInfo(dh=1.0, GPs=4, dof=1)[source]
Parameters:
  • dh (float) – element size
  • GPs (int) – total Gauss point number
  • dof (int) – dof per node
Returns:

  • shape function (numpy array) with size of [GPs, Nodes=4*dof]
  • gradient shape function (numpy array) [GPs, Nodes=4*dof, dim=2*dof] last dim: dof=1: [dc/dx, dc/dy] dof=2: [dx/dx, dx/dy, dy/dx, dy/dy]
  • weight per gauss point (float scalar)

Todo

make this function to work with (1S, 1V), 2S, 1V1S, 3S, 2V, etc.

mechanoChemML.src.pde_layers.GetNodalInfoFromElementInfo(data, residual_mask, dof, padding='SAME')[source]

reorganize data from a matrix form with 4 nodal values of elements to nodal values

Parameters:
  • data (numpy array/tensor) – [None, elem_height, elem_width, 4*dof] (4 nodal values for 1 dof)
  • residual_mask (numpy_array) – [None, elem_height, elem_width, 1]
  • dof (int) – dof per node
Returns:

output with size of [None, node_height, node_width, dof]

Return type:

numpy array

Todo

make this function to work with (1S, 1V), 2S, 1V1S, 3S, 2V, etc.

class mechanoChemML.src.pde_layers.LayerFillRandomToBCs(stddev=0.005, name='fill-random-num')[source]

Bases: tensorflow.keras.layers.Layer

A customized Keras layer to add random noise to BCs with \(\epsilon~\sim\) N(0, stddev=0.005).

Parameters:stddev (float) – default = 0.005
call(self, input)[source]
class mechanoChemML.src.pde_layers.LayerFillZeros(name='fill-zeros')[source]

Bases: tensorflow.keras.layers.Layer

A customized Keras layer to generate zeros if value == -2.0

call(self, input)[source]
class mechanoChemML.src.pde_layers.LayerFillRandomNumber(name='fill-random-num')[source]

Bases: tensorflow.keras.layers.Layer

A customized Keras layer to generate uniform random data (0, 1) if value == -2.0

call(self, input)[source]
class mechanoChemML.src.pde_layers.LayerBulkResidual(name='R_bulk_general')[source]

Bases: tensorflow.keras.layers.Layer

General bulk residual

initialize_arrays(self)[source]

Initialize the kernel array to transform nodal arrangement to element arrangement. Get the Gauss Point information.

GetElementInfo(self, input)[source]

Reorganize data from nodal value to a matrix form with 4*dof nodal values :param inputs: [batch, node_height, node_width, dof] :type inputs: tensor

Returns:data with size of [batch, elem_height, elem_width, dof*4]
Return type:tensor

Note

  • filter n1, n2, n3, n4: [filter_height, filter_width, in_channels, out_channels]
ComputeValuAtGPs(self, data)[source]

Reshape data[:, :, :, 4*dof] to [:, 4*dof] and compute the u(unknown) at each GPs.

Parameters:data (tensor) – size of [-1, 4*dof]
Returns:valu at each GPs with size of [-1, 1*dof]
Return type:tensor
ComputeGraduAtGPs(self, data)[source]

Reshape data[:, :, :, 4*dof] to [:, 4*dof] and compute the Grad of u(unknown) at each GPs.

Parameters:data (tensor) – size of [-1, 4*dof]
Returns:gradu at each GPs with size of [-1, 2*dof]
Return type:tensor
Get2ndOrderIdentityTensor(self, gradu1, domain_shape)[source]

Get the second order identity tensor in the format of I_4[-1, 4] and I_2x2[-1, :, :, 4GPs, 2, 2]

GetFe(self, gradu1, gradu2, gradu3, gradu4, I4, domain_shape, value1, value2, value3, value4)[source]

Compute Fe for large deformation

GetF(self, gradu1, gradu2, gradu3, gradu4, I4, domain_shape)[source]

Compute F for large deformation

GetEpsilon(self, gradu1, gradu2, gradu3, gradu4, domain_shape)[source]

Compute epsilon for small deformation

ComputeIntTranBxP(self, P1, P2, P3, P4, domain_shape)[source]

compute int ( B^T * P) dV

Parameters:P# (tensor) – with size of [:, 4]
ComputeIntTranNxU(self, valu1, valu2, valu3, valu4, domain_shape)[source]

compute int ( N^T * valu) dV

Parameters:valu# (tensor) – with size of [:, 1]
E_nu_to_lambda_mu(self, E, nu)[source]
mechanoChemML.src.pde_layers.dof = 1[source]