Source code for model_package.Tardigrade_MOOSE.build_plastic_Tardigrade_input_deck_platens

#!python
import argparse
import os
import pathlib
import sys
import yaml

import pandas

import build_plastic_Tardigrade_input_deck
import MOOSE_input_deck_tools as moose_tools

[docs] def build_input(output_file, mesh_file, calibration_map, disp, duration, specimen_top_surface, specimen_bottom_surface, top_platen_contact, bottom_platen_contact, top_platen_fixture, bottom_platen_fixture, contact_type='frictionless'): '''Write Tardigrade-MOOSE input file for a plastic simulation with platens :param str output_file: The name of Tardigrade-MOOSE file to write :param str mesh_file: The name of the mesh file :param str calibration_map: CSV file containing calibration data :param str BCs: The type of boundary conditions, either "slip" or "clamp" :param float disp: The compressive displacement to be applied :param float duration: The duration of the simulation :param str specimen_top_surface: Specify the name of the specimen top contact surface :param str specimen_bottom_surface: Specify the name of the specimen bottom contact surface :param str top_platen_contact: Specify the name of the top platen contact surface :param str bottom_platen_contact: Specify the name of the bottom platen contact surface :param str top_platen_fixture: Specify the name of the top platen fixture surface :param str bottom_platen_fixture: Specify the name of the bottom platen fixture surface :param str contact_type: The option for specifying contact, either "frictionless" or "friction" :returns: ``output_file`` ''' assert os.path.exists(mesh_file), f"Mesh file not found: {mesh_file}" # load calibration map parameter_df = pandas.read_csv(calibration_map) parameter_df = parameter_df.sort_values(by='element') # Write input file with open(output_file, 'w') as f: f.write('###############################################################################\n') f.write('[Mesh]\n') f.write(' type = FileMesh\n') f.write(f' file = "{mesh_file}"\n') f.write(' patch_update_strategy = iteration\n') f.write('[]\n') f.write('\n') f.write('[GlobalParams]\n') f.write(' displacements = "disp_x disp_y disp_z"\n') f.write('[]\n') # Variables f.write('# Variables\n') moose_tools.write_variables(f) f.write('[]\n') f.write('\n') # Kernels f.write('# Kernels\n') moose_tools.write_kernels(f) f.write('[]\n') f.write('\n') # Aux variables f.write('# Aux variables\n') f.write('[AuxVariables]\n') moose_tools.write_default_auxvariables(f) f.write('## plastic Aux variables\n') moose_tools.write_plastic_auxvariables(f) f.write(' [./inc_slip_top_x]\n') f.write(' [../]\n') f.write(' [./inc_slip_top_y]\n') f.write(' [../]\n') f.write(' [./inc_slip_top_z]\n') f.write(' [../]\n') f.write(' [./accum_slip_top_x]\n') f.write(' [../]\n') f.write(' [./accum_slip_top_y]\n') f.write(' [../]\n') f.write(' [./accum_slip_top_z]\n') f.write(' [../]\n') f.write(' [./tang_force_top_x]\n') f.write(' [../]\n') f.write(' [./tang_force_top_y]\n') f.write(' [../]\n') f.write(' [./tang_force_top_z]\n') f.write(' [../]\n') f.write(' [./inc_slip_bottom_x]\n') f.write(' [../]\n') f.write(' [./inc_slip_bottom_y]\n') f.write(' [../]\n') f.write(' [./inc_slip_bottom_z]\n') f.write(' [../]\n') f.write(' [./accum_slip_bottom_x]\n') f.write(' [../]\n') f.write(' [./accum_slip_bottom_y]\n') f.write(' [../]\n') f.write(' [./accum_slip_bottom_z]\n') f.write(' [../]\n') f.write(' [./tang_force_bottom_x]\n') f.write(' [../]\n') f.write(' [./tang_force_bottom_y]\n') f.write(' [../]\n') f.write(' [./tang_force_bottom_z]\n') f.write(' [../]\n') f.write('[]\n') f.write('\n') # Aux kernels f.write('# Aux kernels\n') moose_tools.write_default_auxkernels(f) moose_tools.write_plastic_auxkernels(f) f.write('# Contact Kernels\n') f.write('[AuxKernels]\n') f.write(' [./inc_slip_top_x]\n') f.write(' type = PenetrationAux\n') f.write(' variable = inc_slip_top_x\n') f.write(' quantity = incremental_slip_x\n') #f.write(f' paired_boundary = "{top_platen_contact}"\n') f.write(f' boundary = "{top_platen_contact}"\n') f.write(f' paired_boundary = "{specimen_top_surface}"\n') f.write(' [../]\n') f.write(' [./inc_slip_top_y]\n') f.write(' type = PenetrationAux\n') f.write(' variable = inc_slip_top_y\n') f.write(' quantity = incremental_slip_y\n') f.write(f' boundary = "{top_platen_contact}"\n') f.write(f' paired_boundary = "{specimen_top_surface}"\n') f.write(' [../]\n') f.write(' [./inc_slip_top_z]\n') f.write(' type = PenetrationAux\n') f.write(' variable = inc_slip_top_z\n') f.write(' quantity = incremental_slip_z\n') f.write(f' boundary = "{top_platen_contact}"\n') f.write(f' paired_boundary = "{specimen_top_surface}"\n') f.write(' [../]\n') f.write(' [./inc_slip_bottom_x]\n') f.write(' type = PenetrationAux\n') f.write(' variable = inc_slip_bottom_x\n') f.write(' quantity = incremental_slip_x\n') f.write(f' paired_boundary = "{specimen_bottom_surface}"\n') f.write(f' boundary = "{bottom_platen_contact}"\n') f.write(' [../]\n') f.write(' [./inc_slip_bottom_y]\n') f.write(' type = PenetrationAux\n') f.write(' variable = inc_slip_bottom_y\n') f.write(' quantity = incremental_slip_y\n') f.write(f' paired_boundary = "{specimen_bottom_surface}"\n') f.write(f' boundary = "{bottom_platen_contact}"\n') f.write(' [../]\n') f.write(' [./inc_slip_bottom_z]\n') f.write(' type = PenetrationAux\n') f.write(' variable = inc_slip_bottom_z\n') f.write(' quantity = incremental_slip_z\n') f.write(f' paired_boundary = "{specimen_bottom_surface}"\n') f.write(f' boundary = "{bottom_platen_contact}"\n') f.write(' [../]\n') f.write(' [./tangential_force_top_x]\n') f.write(' type = PenetrationAux\n') f.write(' variable = tang_force_top_x\n') f.write(' execute_on = timestep_end\n') f.write(' quantity = tangential_force_x\n') f.write(f' boundary = "{top_platen_contact}"\n') f.write(f' paired_boundary = "{specimen_top_surface}"\n') f.write(' [../]\n') f.write(' [./tangential_force_top_y]\n') f.write(' type = PenetrationAux\n') f.write(' variable = tang_force_top_y\n') f.write(' execute_on = timestep_end\n') f.write(' quantity = tangential_force_y\n') f.write(f' boundary = "{top_platen_contact}"\n') f.write(f' paired_boundary = "{specimen_top_surface}"\n') f.write(' [../]\n') f.write(' [./tangential_force_top_z]\n') f.write(' type = PenetrationAux\n') f.write(' variable = tang_force_top_z\n') f.write(' execute_on = timestep_end\n') f.write(' quantity = tangential_force_z\n') f.write(f' boundary = "{top_platen_contact}"\n') f.write(f' paired_boundary = "{specimen_top_surface}"\n') f.write(' [../]\n') f.write(' [./tangential_force_bottom_x]\n') f.write(' type = PenetrationAux\n') f.write(' variable = tang_force_bottom_x\n') f.write(' execute_on = timestep_end\n') f.write(' quantity = tangential_force_x\n') f.write(f' paired_boundary = "{specimen_bottom_surface}"\n') f.write(f' boundary = "{bottom_platen_contact}"\n') f.write(' [../]\n') f.write(' [./tangential_force_bottom_y]\n') f.write(' type = PenetrationAux\n') f.write(' variable = tang_force_bottom_y\n') f.write(' execute_on = timestep_end\n') f.write(' quantity = tangential_force_y\n') f.write(f' paired_boundary = "{specimen_bottom_surface}"\n') f.write(f' boundary = "{bottom_platen_contact}"\n') f.write(' [../]\n') f.write(' [./tangential_force_bottom_z]\n') f.write(' type = PenetrationAux\n') f.write(' variable = tang_force_bottom_z\n') f.write(' execute_on = timestep_end\n') f.write(' quantity = tangential_force_z\n') f.write(f' paired_boundary = "{specimen_bottom_surface}"\n') f.write(f' boundary = "{bottom_platen_contact}"\n') f.write(' [../]\n') f.write(' [./accum_slip_top_x]\n') f.write(' type = AccumulateAux\n') f.write(' variable = accum_slip_top_x\n') f.write(' accumulate_from_variable = inc_slip_top_x\n') f.write(' execute_on = timestep_end\n') f.write(' [../]\n') f.write(' [./accum_slip_top_y]\n') f.write(' type = AccumulateAux\n') f.write(' variable = accum_slip_top_y\n') f.write(' accumulate_from_variable = inc_slip_top_y\n') f.write(' execute_on = timestep_end\n') f.write(' [../]\n') f.write(' [./accum_slip_top_z]\n') f.write(' type = AccumulateAux\n') f.write(' variable = accum_slip_top_z\n') f.write(' accumulate_from_variable = inc_slip_top_z\n') f.write(' execute_on = timestep_end\n') f.write(' [../]\n') f.write(' [./accum_slip_bottom_x]\n') f.write(' type = AccumulateAux\n') f.write(' variable = accum_slip_bottom_x\n') f.write(' accumulate_from_variable = inc_slip_bottom_x\n') f.write(' execute_on = timestep_end\n') f.write(' [../]\n') f.write(' [./accum_slip_bottom_y]\n') f.write(' type = AccumulateAux\n') f.write(' variable = accum_slip_bottom_y\n') f.write(' accumulate_from_variable = inc_slip_bottom_y\n') f.write(' execute_on = timestep_end\n') f.write(' [../]\n') f.write(' [./accum_slip_bottom_z]\n') f.write(' type = AccumulateAux\n') f.write(' variable = accum_slip_bottom_z\n') f.write(' accumulate_from_variable = inc_slip_bottom_z\n') f.write(' execute_on = timestep_end\n') f.write(' [../]\n') f.write('[]\n') f.write('\n') # Reaction Force sample_force = 'force_z' f.write('# Do some cool math to get the reaction force\n') f.write('[Postprocessors]\n') f.write(' [bot_react_z]\n') f.write(' type = NodalSum\n') f.write(f' variable = {sample_force}\n') f.write(f' boundary = "{specimen_bottom_surface}"\n') f.write(' []\n') f.write('[]\n') f.write('\n') # BCs f.write('[BCs]\n') f.write(' active = "bottom_x bottom_y bottom_z top_x top_y top_z"\n') f.write(' [./bottom_x]\n') f.write(' type = DirichletBC\n') f.write(' variable = disp_x\n') f.write(f' boundary = "{bottom_platen_contact}"\n') f.write(' preset = true\n') f.write(' value = 0\n') f.write(' [../]\n') f.write(' [./bottom_y]\n') f.write(' type = DirichletBC\n') f.write(' variable = disp_y\n') f.write(f' boundary = "{bottom_platen_contact}"\n') f.write(' preset = true\n') f.write(' value = 0\n') f.write(' [../]\n') f.write(' [./bottom_z]\n') f.write(' type = DirichletBC\n') f.write(' variable = disp_z\n') f.write(f' boundary = "{bottom_platen_contact}"\n') f.write(' preset = true\n') f.write(' value = 0\n') f.write(' [../]\n') f.write(' [./top_x]\n') f.write(' type = DirichletBC\n') f.write(' variable = disp_x\n') f.write(f' boundary = "{top_platen_contact}"\n') f.write(' preset = true\n') f.write(' value = 0\n') f.write(' [../]\n') f.write(' [./top_y]\n') f.write(' type = DirichletBC\n') f.write(' variable = disp_y\n') f.write(f' boundary = "{top_platen_contact}"\n') f.write(' preset = true\n') f.write(' value = 0\n') f.write(' [../]\n') f.write(' [./top_z]\n') f.write(' type = FunctionDirichletBC\n') f.write(' variable = disp_z\n') f.write(f' boundary = "{top_platen_contact}"\n') f.write(' preset = true\n') f.write(' function = top_bc\n') f.write(' [../]\n') f.write('[]\n') f.write('\n') # Loading function f.write('\n') f.write('[Functions]\n') f.write(' [./top_bc]\n') f.write(' type = ParsedFunction\n') f.write(f' expression = -{disp}*t\n') f.write(' [../]\n') f.write('[]\n') f.write('\n') # Contact if contact_type == 'frictionless': f.write('[Contact]\n') f.write(' [./top_center_cont]\n') f.write(f' primary = "{top_platen_contact}"\n') f.write(f' secondary = "{specimen_top_surface}"\n') f.write(' penalty = 1e3\n') f.write(' normalize_penalty = true\n') f.write(' tangential_tolerance = 1.e-3\n') f.write(' [../]\n') f.write(' [./bottom_center_cont]\n') f.write(f' primary = "{bottom_platen_contact}"\n') f.write(f' secondary = "{specimen_bottom_surface}"\n') f.write(' penalty = 1e3\n') f.write(' normalize_penalty = true\n') f.write(' tangential_tolerance = 1.e-3\n') f.write(' [../]\n') f.write('[]\n') elif contact_type == 'friction': f.write('[Contact]\n') f.write(' [./top_center_cont]\n') f.write(f' secondary = "{top_platen_contact}"\n') f.write(f' primary = "{specimen_top_surface}"\n') f.write(' model = coulomb\n') f.write(' formulation = tangential_penalty\n') f.write(' friction_coefficient = "0.2"\n') f.write(' penalty = 1e9\n') f.write(' normalize_penalty = true\n') f.write(' tangential_tolerance = 1.e-3\n') f.write(' normal_smoothing_distance = 0.001\n') f.write(' [../]\n') f.write(' [./bottom_center_cont]\n') f.write(f' secondary = "{bottom_platen_contact}"\n') f.write(f' primary = "{specimen_bottom_surface}"\n') f.write(' model = coulomb\n') f.write(' formulation = tangential_penalty\n') f.write(' friction_coefficient = "0.2"\n') f.write(' penalty = 1e9\n') f.write(' normalize_penalty = true\n') f.write(' tangential_tolerance = 1.e-3\n') f.write(' normal_smoothing_distance = 0.001\n') f.write(' [../]\n') f.write('[]\n') f.write('\n') f.write('[Dampers]\n') f.write(' [./contact_slip_top]\n') f.write(' type = ContactSlipDamper\n') f.write(f' secondary = "{top_platen_contact}"\n') f.write(f' primary = "{specimen_top_surface}"\n') f.write(' min_damping_factor = 1.e-2\n') f.write(' [../]\n') f.write(' [./contact_slip_bottom]\n') f.write(' type = ContactSlipDamper\n') f.write(f' secondary = "{bottom_platen_contact}"\n') f.write(f' primary = "{specimen_bottom_surface}"\n') f.write(' min_damping_factor = 1.e-2\n') f.write(' [../]\n') f.write('[]\n') f.write('\n') else: print('Specify a valid contact_type!') # Materials f.write('# Materials\n') f.write('[Materials]\n') # Load in parameter data for each filter domain / element if len(list(parameter_df.index)) > 1: for index in parameter_df.index: # Unpack parameters mat_line_1, mat_line_2, mat_line_3, mat_line_blank, mat_line_10, mat_line_11, mat_line_12, mat_line_13, mat_line_14, element = build_plastic_Tardigrade_input_deck.unpack_plastic_parameter_csv(parameter_df, index) # Write in material info f.write(f' [./linear_elastic_{element}]\n') f.write(' type = MicromorphicMaterial\n') f.write(f' material_fparameters = "{mat_line_1}\n') f.write(f' {mat_line_2}\n') f.write(f' {mat_line_3}\n') f.write(f' {mat_line_blank}\n') f.write(f' {mat_line_blank}\n') f.write(f' {mat_line_blank}\n') f.write(f' {mat_line_blank}\n') f.write(f' {mat_line_blank}\n') f.write(f' {mat_line_blank}\n') f.write(f' {mat_line_10}\n') f.write(f' {mat_line_11}\n') f.write(f' {mat_line_12}\n') f.write(f' {mat_line_13}\n') f.write(f' {mat_line_14}"\n') f.write(' number_SDVS = 55\n') f.write(f' model_name = "LinearElasticityDruckerPragerPlasticity"\n') f.write('\n') f.write(' #Coupled variables\n') f.write(' u1 = "disp_x"\n') f.write(' u2 = "disp_y"\n') f.write(' u3 = "disp_z"\n') f.write(' phi_11 = "phi_xx"\n') f.write(' phi_22 = "phi_yy"\n') f.write(' phi_33 = "phi_zz"\n') f.write(' phi_23 = "phi_yz"\n') f.write(' phi_13 = "phi_xz"\n') f.write(' phi_12 = "phi_xy"\n') f.write(' phi_32 = "phi_zy"\n') f.write(' phi_31 = "phi_zx"\n') f.write(' phi_21 = "phi_yx"\n') f.write(f' block = "element_{element}"\n') f.write(' [../]\n') else: # Unpack parameters mat_line_1, mat_line_2, mat_line_3, mat_line_blank, mat_line_10, mat_line_11, mat_line_12, mat_line_13, mat_line_14, element = build_plastic_Tardigrade_input_deck.unpack_plastic_parameter_csv(parameter_df, 0) # Write in material info f.write(f' [./linear_elastic]\n') f.write(' type = MicromorphicMaterial\n') f.write(f' material_fparameters = "{mat_line_1}\n') f.write(f' {mat_line_2}\n') f.write(f' {mat_line_3}\n') f.write(f' {mat_line_blank}\n') f.write(f' {mat_line_blank}\n') f.write(f' {mat_line_blank}\n') f.write(f' {mat_line_blank}\n') f.write(f' {mat_line_blank}\n') f.write(f' {mat_line_blank}\n') f.write(f' {mat_line_10}\n') f.write(f' {mat_line_11}\n') f.write(f' {mat_line_12}\n') f.write(f' {mat_line_13}\n') f.write(f' {mat_line_14}"\n') f.write(' number_SDVS = 55\n') f.write(f' model_name = "LinearElasticityDruckerPragerPlasticity"\n') f.write('\n') f.write(' #Coupled variables\n') f.write(' u1 = "disp_x"\n') f.write(' u2 = "disp_y"\n') f.write(' u3 = "disp_z"\n') f.write(' phi_11 = "phi_xx"\n') f.write(' phi_22 = "phi_yy"\n') f.write(' phi_33 = "phi_zz"\n') f.write(' phi_23 = "phi_yz"\n') f.write(' phi_13 = "phi_xz"\n') f.write(' phi_12 = "phi_xy"\n') f.write(' phi_32 = "phi_zy"\n') f.write(' phi_31 = "phi_zx"\n') f.write(' phi_21 = "phi_yx"\n') f.write(' block = "specimen"\n') f.write(' [../]\n') # Platens platen_material = 'micromorphic' if platen_material == 'micromorphic': f.write(' [./platen]\n') f.write(' type = MicromorphicMaterial\n') f.write(' material_fparameters = "2 121200. 80770.\n') f.write(' 5 0. 0. 0. 0. 0.\n') f.write(' 11 0. 0. 0. 0. 0. 0. 0.001 0. 0. 0. 0.\n') f.write(' 2 0. 0."\n') f.write(' model_name = "LinearElasticity"\n') f.write('\n') f.write(' #Coupled variables\n') f.write(' u1 = "disp_x"\n') f.write(' u2 = "disp_y"\n') f.write(' u3 = "disp_z"\n') f.write(' phi_11 = "phi_xx"\n') f.write(' phi_22 = "phi_yy"\n') f.write(' phi_33 = "phi_zz"\n') f.write(' phi_23 = "phi_yz"\n') f.write(' phi_13 = "phi_xz"\n') f.write(' phi_12 = "phi_xy"\n') f.write(' phi_32 = "phi_zy"\n') f.write(' phi_31 = "phi_zx"\n') f.write(' phi_21 = "phi_yx"\n') f.write(' block = "top_platen bottom_platen"\n') f.write(' [../]\n') f.write('[]\n') f.write('\n') # Preconditioner moose_tools.write_preconditioner_block(f) elif platen_material == 'basic': f.write(' [./tensor]\n') f.write(' type = ComputeIsotropicElasticityTensor\n') f.write(' block = "top_platen bottom_platen"\n') f.write(' youngs_modulus = 210000.\n') f.write(' poissons_ratio = 0.3\n') f.write(' [../]\n') f.write(' [./stress]\n') f.write(' type = ComputeLinearElasticStress\n') f.write(' block = "top_platen bottom_platen"\n') f.write(' [../]\n') f.write('\n') # Execution and Timestepping dt = duration / 20 f.write('[Executioner]\n') f.write(' type = Transient\n') #f.write(' solve_type = NEWTON\n') f.write(' solve_type = PJFNK\n') #f.write(' petsc_options_iname = "-pc_type -pc_factor_mat_solver_package"\n') #f.write(' petsc_options_value = "lu superlu_dist "\n') f.write(' petsc_options_iname = "-pc_type -pc_factor_mat_solver_package -pc_factor_shift_type"\n') f.write(' petsc_options_value = "lu superlu_dist NONZERO"\n') f.write(' line_search = none\n') f.write(' automatic_scaling = true\n') f.write(' compute_scaling_once = true\n') f.write(' nl_rel_tol = 1e-5\n') f.write(' nl_abs_tol = 1e-5\n') f.write(' l_tol = 1e-3\n') f.write(' l_max_its = 250\n') f.write(' nl_max_its = 150\n') f.write(' start_time = 0.0\n') f.write(f' end_time = {duration}\n') f.write(' dtmin = 1e-10\n') f.write(' dtmax= 0.05\n') f.write(' [TimeStepper]\n') f.write(' type = IterationAdaptiveDT\n') #f.write(' optimal_iterations = 4\n') #f.write(' iteration_window = 3\n') #f.write(' linear_iteration_ratio = 1000\n') f.write(' growth_factor=1.5\n') #f.write(' cutback_factor=0.5\n') f.write(f' dt = {dt}\n') f.write(' []\n') f.write('[]\n') # Outputs moose_tools.write_outputs_block(f) f.write('\n') return 0
def get_parser(): script_name = pathlib.Path(__file__) prog = f"python {script_name.name} " cli_description = "Write Tardigrade-MOOSE input file for a plastic simulation with platens" parser = argparse.ArgumentParser(description=cli_description, prog=prog) parser.add_argument('-o', '--output-file', type=str, required=True, help="Specify the name of Tardigrade-MOOSE file to write") parser.add_argument('--mesh', type=str, required=True, help='Specify the mesh file') parser.add_argument('--calibration-map', type=str, required=True, help='CSV file containing calibration data') parser.add_argument('--disp', type=float, required=True, help='Specify the compressive displacement to be applied') parser.add_argument('--duration', type=float, required=True, help='Specify the duration of the simulation') parser.add_argument('--specimen-top-surface', type=str, required=True, help='Specify the name of the specimen top contact surface') parser.add_argument('--specimen-bottom-surface', type=str, required=True, help='Specify the name of the specimen bottom contact surface') parser.add_argument('--top-platen-contact', type=str, required=True, help='Specify the name of the top platen contact surface') parser.add_argument('--bottom-platen-contact', type=str, required=True, help='Specify the name of the bottom platen contact surface') parser.add_argument('--top-platen-fixture', type=str, required=True, help='Specify the name of the top platen fixture surface') parser.add_argument('--bottom-platen-fixture', type=str, required=True, help='Specify the name of the bottom platen fixture surface') parser.add_argument('--contact-type', type=str, required=False, default='frictionless', help='The option for specifying contact, either "frictionless" or "friction"') return parser if __name__ == '__main__': parser = get_parser() args, unknown = parser.parse_known_args() sys.exit(build_input(output_file=args.output_file, mesh_file=args.mesh, calibration_map=args.calibration_map, disp=args.disp, duration=args.duration, specimen_top_surface=args.specimen_top_surface, specimen_bottom_surface=args.specimen_bottom_surface, top_platen_contact=args.top_platen_contact, bottom_platen_contact=args.bottom_platen_contact, top_platen_fixture=args.top_platen_fixture, bottom_platen_fixture=args.bottom_platen_fixture, contact_type=args.contact_type, ))