gel.scripts.full_shape_to_nodal
Implementation of get_kinematics_mesh command for $J$ postpro.
1r"""Implementation of `get_kinematics_mesh` command for $J$ postpro. 2""" 3import argparse 4import os 5os.environ["SUPPRESS_ADJOINT"] = "1" 6from gel import * 7 8 9def main(cell_data, input_full_shape, output_nodal, bci=None, bco=None): 10 r"""Writes .xdmf with element-wise kinematics information. 11 12 * `cell_data`: str path to directory with files needed by 13 `gel.geometry.Geometry` 14 * `input_full_shape`: str path to full-shape .xdmf file with 15 displacements "u" 16 * `output_nodal`: str path to .xdmf file (ending in that extension) 17 that will be created 18 * `bci`: str or None. Override path to the inner cell-surface BC .vtk; 19 when None, `gel.geometry.Geometry` defaults to `cell_data/bci.vtk` 20 * `bco`: str or None. Override path to the outer boundary BC .vtk 21 22 Side-effects: writes `output_nodal` .xdmf and .h5 versions with 23 kinematic information: 24 * "u": $\mathbf{u}$ 25 * "J": $J$ 26 * "CC": $\mathbf{C}:\mathbf{C}$ 27 * "w2": $\mathbf{C}:\mathbf{C}-2\text{tr}\mathbf{C}+3$ 28 * "w3": $3\mathbf{C}:\mathbf{C}-\left(\text{tr}\mathbf{C}\right)^2$ 29 """ 30 geo = Geometry(cell_data, bci_data=bci, bco_data=bco) 31 kinematics = kinematics_from_file(geo, input_full_shape) 32 33 simulation_output_file = XDMFFile(output_nodal) 34 simulation_output_file.parameters["flush_output"] = True 35 simulation_output_file.parameters["functions_share_mesh"] = True 36 37 kinematics.u.rename("u","displacement") 38 39 DG_0 = FunctionSpace(geo.mesh, "DG", 0) 40 J = project(kinematics.Ju, DG_0) 41 J.rename("J","Jacobian") 42 43 C_norm_sq = inner(kinematics.C, kinematics.C) 44 C_ns_vec = project(C_norm_sq, DG_0) 45 C_ns_vec.rename("CC","CNormSquared") 46 47 w22 = C_norm_sq - (2*kinematics.Ic) + 3 48 w2 = sqrt(conditional(gt(w22,0),w22,0)) 49 w2_vec = project(w2, DG_0) 50 w2_vec.rename("w2","Weight2") 51 52 w33 = (3*C_norm_sq) - (kinematics.Ic*kinematics.Ic) 53 w3 = sqrt(conditional(gt(w33,0),w33,0)) 54 w3_vec = project(w3, DG_0) 55 w3_vec.rename("w3","Weight3") 56 57 # Writes out the variables 58 simulation_output_file.write(kinematics.u,0) 59 simulation_output_file.write(J,0) 60 simulation_output_file.write(C_ns_vec,0) 61 simulation_output_file.write(w2_vec,0) 62 simulation_output_file.write(w3_vec,0) 63 64 65def get_kinematics_mesh(): 66 """The function invoked by the command. Parses arguments and passes 67 to `main`. 68 """ 69 parser = argparse.ArgumentParser( 70 description="Convert a full-shape .xdmf file with displacements" 71 " to a nodal .xdmf file for both visualization and computing J" 72 ) 73 parser.add_argument( 74 "-c", 75 type=str, 76 metavar="CELL_DATA", 77 help="directory containing gel geometry" 78 ) 79 parser.add_argument( 80 "-i", 81 type=str, 82 metavar="INPUT_FULL_SHAPE", 83 help="full-shape 1st order Lagrange .xdmf with displacements 'u'" 84 ) 85 parser.add_argument( 86 "-o", 87 type=str, 88 metavar="OUTPUT_NODAL", 89 help="output .xdmf file with kinematic quantities like J" 90 ) 91 parser.add_argument( 92 "--bci", 93 type=str, 94 metavar="CELL_SURF_MESH", 95 default=None, 96 help="override path to inner cell-surface BC .vtk (default: -c dir's " 97 "bci.vtk)" 98 ) 99 parser.add_argument( 100 "--bco", 101 type=str, 102 metavar="OUTER_SURF_MESH", 103 default=None, 104 help="override path to outer boundary BC .vtk (default: -c dir's " 105 "bco.vtk)" 106 ) 107 args = parser.parse_args() 108 109 main(args.c, args.i, args.o, args.bci, args.bco) 110 111 112if __name__=="__main__": 113 get_kinematics_mesh()
def
main(cell_data, input_full_shape, output_nodal, bci=None, bco=None):
10def main(cell_data, input_full_shape, output_nodal, bci=None, bco=None): 11 r"""Writes .xdmf with element-wise kinematics information. 12 13 * `cell_data`: str path to directory with files needed by 14 `gel.geometry.Geometry` 15 * `input_full_shape`: str path to full-shape .xdmf file with 16 displacements "u" 17 * `output_nodal`: str path to .xdmf file (ending in that extension) 18 that will be created 19 * `bci`: str or None. Override path to the inner cell-surface BC .vtk; 20 when None, `gel.geometry.Geometry` defaults to `cell_data/bci.vtk` 21 * `bco`: str or None. Override path to the outer boundary BC .vtk 22 23 Side-effects: writes `output_nodal` .xdmf and .h5 versions with 24 kinematic information: 25 * "u": $\mathbf{u}$ 26 * "J": $J$ 27 * "CC": $\mathbf{C}:\mathbf{C}$ 28 * "w2": $\mathbf{C}:\mathbf{C}-2\text{tr}\mathbf{C}+3$ 29 * "w3": $3\mathbf{C}:\mathbf{C}-\left(\text{tr}\mathbf{C}\right)^2$ 30 """ 31 geo = Geometry(cell_data, bci_data=bci, bco_data=bco) 32 kinematics = kinematics_from_file(geo, input_full_shape) 33 34 simulation_output_file = XDMFFile(output_nodal) 35 simulation_output_file.parameters["flush_output"] = True 36 simulation_output_file.parameters["functions_share_mesh"] = True 37 38 kinematics.u.rename("u","displacement") 39 40 DG_0 = FunctionSpace(geo.mesh, "DG", 0) 41 J = project(kinematics.Ju, DG_0) 42 J.rename("J","Jacobian") 43 44 C_norm_sq = inner(kinematics.C, kinematics.C) 45 C_ns_vec = project(C_norm_sq, DG_0) 46 C_ns_vec.rename("CC","CNormSquared") 47 48 w22 = C_norm_sq - (2*kinematics.Ic) + 3 49 w2 = sqrt(conditional(gt(w22,0),w22,0)) 50 w2_vec = project(w2, DG_0) 51 w2_vec.rename("w2","Weight2") 52 53 w33 = (3*C_norm_sq) - (kinematics.Ic*kinematics.Ic) 54 w3 = sqrt(conditional(gt(w33,0),w33,0)) 55 w3_vec = project(w3, DG_0) 56 w3_vec.rename("w3","Weight3") 57 58 # Writes out the variables 59 simulation_output_file.write(kinematics.u,0) 60 simulation_output_file.write(J,0) 61 simulation_output_file.write(C_ns_vec,0) 62 simulation_output_file.write(w2_vec,0) 63 simulation_output_file.write(w3_vec,0)
Writes .xdmf with element-wise kinematics information.
cell_data: str path to directory with files needed bygel.geometry.Geometryinput_full_shape: str path to full-shape .xdmf file with displacements "u"output_nodal: str path to .xdmf file (ending in that extension) that will be createdbci: str or None. Override path to the inner cell-surface BC .vtk; when None,gel.geometry.Geometrydefaults tocell_data/bci.vtkbco: str or None. Override path to the outer boundary BC .vtk
Side-effects: writes output_nodal .xdmf and .h5 versions with
kinematic information:
- "u": $\mathbf{u}$
- "J": $J$
- "CC": $\mathbf{C}:\mathbf{C}$
- "w2": $\mathbf{C}:\mathbf{C}-2\text{tr}\mathbf{C}+3$
- "w3": $3\mathbf{C}:\mathbf{C}-\left(\text{tr}\mathbf{C}\right)^2$
def
get_kinematics_mesh():
66def get_kinematics_mesh(): 67 """The function invoked by the command. Parses arguments and passes 68 to `main`. 69 """ 70 parser = argparse.ArgumentParser( 71 description="Convert a full-shape .xdmf file with displacements" 72 " to a nodal .xdmf file for both visualization and computing J" 73 ) 74 parser.add_argument( 75 "-c", 76 type=str, 77 metavar="CELL_DATA", 78 help="directory containing gel geometry" 79 ) 80 parser.add_argument( 81 "-i", 82 type=str, 83 metavar="INPUT_FULL_SHAPE", 84 help="full-shape 1st order Lagrange .xdmf with displacements 'u'" 85 ) 86 parser.add_argument( 87 "-o", 88 type=str, 89 metavar="OUTPUT_NODAL", 90 help="output .xdmf file with kinematic quantities like J" 91 ) 92 parser.add_argument( 93 "--bci", 94 type=str, 95 metavar="CELL_SURF_MESH", 96 default=None, 97 help="override path to inner cell-surface BC .vtk (default: -c dir's " 98 "bci.vtk)" 99 ) 100 parser.add_argument( 101 "--bco", 102 type=str, 103 metavar="OUTER_SURF_MESH", 104 default=None, 105 help="override path to outer boundary BC .vtk (default: -c dir's " 106 "bco.vtk)" 107 ) 108 args = parser.parse_args() 109 110 main(args.c, args.i, args.o, args.bci, args.bco)
The function invoked by the command. Parses arguments and passes
to main.