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): 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 19 Side-effects: writes `output_nodal` .xdmf and .h5 versions with 20 kinematic information: 21 * "u": $\mathbf{u}$ 22 * "J": $J$ 23 * "CC": $\mathbf{C}:\mathbf{C}$ 24 * "w2": $\mathbf{C}:\mathbf{C}-2\text{tr}\mathbf{C}+3$ 25 * "w3": $3\mathbf{C}:\mathbf{C}-\left(\text{tr}\mathbf{C}\right)^2$ 26 """ 27 geo = Geometry(cell_data) 28 kinematics = kinematics_from_file(geo, input_full_shape) 29 30 simulation_output_file = XDMFFile(output_nodal) 31 simulation_output_file.parameters["flush_output"] = True 32 simulation_output_file.parameters["functions_share_mesh"] = True 33 34 kinematics.u.rename("u","displacement") 35 36 DG_0 = FunctionSpace(geo.mesh, "DG", 0) 37 J = project(kinematics.Ju, DG_0) 38 J.rename("J","Jacobian") 39 40 C_norm_sq = inner(kinematics.C, kinematics.C) 41 C_ns_vec = project(C_norm_sq, DG_0) 42 C_ns_vec.rename("CC","CNormSquared") 43 44 w22 = C_norm_sq - (2*kinematics.Ic) + 3 45 w2 = sqrt(conditional(gt(w22,0),w22,0)) 46 w2_vec = project(w2, DG_0) 47 w2_vec.rename("w2","Weight2") 48 49 w33 = (3*C_norm_sq) - (kinematics.Ic*kinematics.Ic) 50 w3 = sqrt(conditional(gt(w33,0),w33,0)) 51 w3_vec = project(w3, DG_0) 52 w3_vec.rename("w3","Weight3") 53 54 # Writes out the variables 55 simulation_output_file.write(kinematics.u,0) 56 simulation_output_file.write(J,0) 57 simulation_output_file.write(C_ns_vec,0) 58 simulation_output_file.write(w2_vec,0) 59 simulation_output_file.write(w3_vec,0) 60 61 62def get_kinematics_mesh(): 63 """The function invoked by the command. Parses arguments and passes 64 to `main`. 65 """ 66 parser = argparse.ArgumentParser( 67 description="Convert a full-shape .xdmf file with displacements" 68 " to a nodal .xdmf file for both visualization and computing J" 69 ) 70 parser.add_argument( 71 "-c", 72 type=str, 73 metavar="CELL_DATA", 74 help="directory containing gel geometry" 75 ) 76 parser.add_argument( 77 "-i", 78 type=str, 79 metavar="INPUT_FULL_SHAPE", 80 help="full-shape 1st order Lagrange .xdmf with displacements 'u'" 81 ) 82 parser.add_argument( 83 "-o", 84 type=str, 85 metavar="OUTPUT_NODAL", 86 help="output .xdmf file with kinematic quantities like J" 87 ) 88 args = parser.parse_args() 89 90 main(args.c, args.i, args.o) 91 92 93if __name__=="__main__": 94 get_kinematics_mesh()
def
main(cell_data, input_full_shape, output_nodal):
10def main(cell_data, input_full_shape, output_nodal): 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 20 Side-effects: writes `output_nodal` .xdmf and .h5 versions with 21 kinematic information: 22 * "u": $\mathbf{u}$ 23 * "J": $J$ 24 * "CC": $\mathbf{C}:\mathbf{C}$ 25 * "w2": $\mathbf{C}:\mathbf{C}-2\text{tr}\mathbf{C}+3$ 26 * "w3": $3\mathbf{C}:\mathbf{C}-\left(\text{tr}\mathbf{C}\right)^2$ 27 """ 28 geo = Geometry(cell_data) 29 kinematics = kinematics_from_file(geo, input_full_shape) 30 31 simulation_output_file = XDMFFile(output_nodal) 32 simulation_output_file.parameters["flush_output"] = True 33 simulation_output_file.parameters["functions_share_mesh"] = True 34 35 kinematics.u.rename("u","displacement") 36 37 DG_0 = FunctionSpace(geo.mesh, "DG", 0) 38 J = project(kinematics.Ju, DG_0) 39 J.rename("J","Jacobian") 40 41 C_norm_sq = inner(kinematics.C, kinematics.C) 42 C_ns_vec = project(C_norm_sq, DG_0) 43 C_ns_vec.rename("CC","CNormSquared") 44 45 w22 = C_norm_sq - (2*kinematics.Ic) + 3 46 w2 = sqrt(conditional(gt(w22,0),w22,0)) 47 w2_vec = project(w2, DG_0) 48 w2_vec.rename("w2","Weight2") 49 50 w33 = (3*C_norm_sq) - (kinematics.Ic*kinematics.Ic) 51 w3 = sqrt(conditional(gt(w33,0),w33,0)) 52 w3_vec = project(w3, DG_0) 53 w3_vec.rename("w3","Weight3") 54 55 # Writes out the variables 56 simulation_output_file.write(kinematics.u,0) 57 simulation_output_file.write(J,0) 58 simulation_output_file.write(C_ns_vec,0) 59 simulation_output_file.write(w2_vec,0) 60 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.Geometry
input_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 created
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():
63def get_kinematics_mesh(): 64 """The function invoked by the command. Parses arguments and passes 65 to `main`. 66 """ 67 parser = argparse.ArgumentParser( 68 description="Convert a full-shape .xdmf file with displacements" 69 " to a nodal .xdmf file for both visualization and computing J" 70 ) 71 parser.add_argument( 72 "-c", 73 type=str, 74 metavar="CELL_DATA", 75 help="directory containing gel geometry" 76 ) 77 parser.add_argument( 78 "-i", 79 type=str, 80 metavar="INPUT_FULL_SHAPE", 81 help="full-shape 1st order Lagrange .xdmf with displacements 'u'" 82 ) 83 parser.add_argument( 84 "-o", 85 type=str, 86 metavar="OUTPUT_NODAL", 87 help="output .xdmf file with kinematic quantities like J" 88 ) 89 args = parser.parse_args() 90 91 main(args.c, args.i, args.o)
The function invoked by the command. Parses arguments and passes
to main
.