diff --git a/gel/gel.py b/gel/gel.py index e911376..8450f3c 100644 --- a/gel/gel.py +++ b/gel/gel.py @@ -237,6 +237,7 @@ def __init__(self, tola=1e-10, tolr=1e-9, traction=None, + u_init=None, formulation_kwargs=dict(), **kwargs ): @@ -267,10 +268,12 @@ def __init__(self, be in 1st order Lagrange space, will ignore DoFs outside of surface. "zero" will automatically contruct a 0 traction function + * `u_init`: str path to full-shape .xdmf file with initial + displacements * `formulation_kwargs`: dict of additional kwargs to the material model formulation (if applicable) implemented in `gel.mechanics` - * `kwargs`: dict of kwargs to the the geometry, for instance + * `kwargs`: dict of kwargs to the geometry, for instance the arguments to `gel.geometry.Geometry` """ # Validate, get geometry @@ -285,10 +288,14 @@ def __init__(self, """Corresponding object of type `gel.geometry.Geometry`""" # Initialize displacements, kinematic quantities - self.kinematics = Kinematics(self.geo) + self.kinematics = None """Object of type `gel.kinematics.Kinematics` with displacement information """ + if u_init is None: + self.kinematics = Kinematics(self.geo) + else: + self.kinematics = kinematics_from_file(self.geo, u_init) # Prepare modulus control variable self.ctl = create_mod_repr(self.geo, mod_repr_init) diff --git a/gel/helper.py b/gel/helper.py index 380d5e5..84b7d0a 100644 --- a/gel/helper.py +++ b/gel/helper.py @@ -49,6 +49,7 @@ def get_common_parser(*args, **kwargs): -p PRECONDITIONER --bci CELL_SURF_MESH --bco OUTER_SURF_MESH + --u-init U_INIT ``` """ if "formatter_class" not in kwargs: @@ -111,6 +112,13 @@ def get_common_parser(*args, **kwargs): default=None, help="filename of meshio-compatible mesh with outer nodes and u" ) + parser.add_argument( + "--u-init", + type=str, + metavar="U_INIT", + default=None, + help="filename of full-shape .xdmf file with initial displacements" + ) return parser diff --git a/gel/scripts/forward.py b/gel/scripts/forward.py index 3885c9b..5ec5bcd 100644 --- a/gel/scripts/forward.py +++ b/gel/scripts/forward.py @@ -39,6 +39,7 @@ "upper_bound", "Inner Mesh", "Outer Mesh", + "u_init", "time" ] """Names of columns in `table.csv`""" @@ -77,7 +78,8 @@ def run_experiments(args): args.b[0], args.b[1], args.bci, - args.bco + args.bco, + args.u_init ) logger.info(f"Beginning experiment with arguments {exp_info}.") @@ -109,7 +111,8 @@ def output_single_forward_result( lower_bound, upper_bound, bci, - bco + bco, + u_init ): r"""Runs a single forward model experiment, writes subdirectory and logs progress. @@ -137,6 +140,8 @@ def output_single_forward_result( `gel.geometry.Geometry` for details * `bco`: str path to .vtk file with outer BC info, see `gel.geometry.Geometry` for details + * `u_init`: str path to full-shape .xdmf file with initial + displacements Side-effects: writes many files in new subdirectory to `results_dir`, see intro to `gel.scripts.forward` @@ -163,7 +168,8 @@ def output_single_forward_result( lower_bound, upper_bound, bci, - bco + bco, + u_init ) # Setup logging @@ -183,6 +189,7 @@ def output_single_forward_result( logger.info(f"Using load steps: {load_steps}") logger.info(f"Override inner BC: {bci}") logger.info(f"Override outer BC: {bco}") + logger.info(f"Initial displacements: {u_init}") # Timer start timer = ExperimentTimer() @@ -208,6 +215,7 @@ def output_single_forward_result( tola=tola, tolr=tolr, traction=traction, + u_init=u_init, formulation_kwargs=formulation_kwargs, **addn_args ) diff --git a/gel/scripts/inverse.py b/gel/scripts/inverse.py index a2e62ed..515cb95 100644 --- a/gel/scripts/inverse.py +++ b/gel/scripts/inverse.py @@ -96,6 +96,7 @@ def _expand_obj_info(exp_info): "bci", "bco", "mu_ff", + "u_init", "outcome", "pure_obj", "reg", @@ -143,7 +144,8 @@ def main(args): args.opt_backend, args.bci, args.bco, - args.mu + args.mu, + args.u_init ) logger.info(f"Beginning experiment with arguments {exp_info}.") @@ -208,7 +210,8 @@ def gel_inverse( optimizer_backend="scipy", bci=None, bco=None, - mu=108.0 + mu=108.0, + u_init=None ): r"""Runs the inverse model, writes subdirectory and logs progress. @@ -248,6 +251,8 @@ def gel_inverse( * `bco`: str path to .vtk file with outer BC info, see `gel.geometry.Geometry` for details * `mu`: float far-field shear modulus from rheometry + * `u_init`: str path to full-shape .xdmf file with initial + displacements Side-effects: writes many files in new subdirectory to `results_dir`, see intro to `gel.scripts.inverse` @@ -318,6 +323,7 @@ def gel_inverse( logger.info(f"Override inner BC: {bci}") logger.info(f"Override outer BC: {bco}") logger.info(f"Far field modulus: {mu}") + logger.info(f"Initial displacements: {u_init}") objective_info.log_info(logger) # RESET TAPE @@ -351,6 +357,7 @@ def gel_inverse( data_directory=cell_data_dir, restrict_ctl_dofs_to_veh=restrict_ctl_dofs_to_veh, pc=preconditioner, + u_init=u_init, formulation_kwargs=formulation_kwargs, **addn_args )