diff --git a/cashocs/_optimization/line_search/line_search.py b/cashocs/_optimization/line_search/line_search.py index 689b4353..bcabbf2a 100644 --- a/cashocs/_optimization/line_search/line_search.py +++ b/cashocs/_optimization/line_search/line_search.py @@ -58,9 +58,14 @@ def __init__( self.cost_functional = optimization_problem.reduced_cost_functional if self.db.parameter_db.problem_type == "shape": - self.deformation_function = fenics.Function( - self.db.function_db.control_spaces[0] - ) + if "deformation_function" in self.db.parameter_db.temp_dict.keys(): + self.deformation_function = self.db.parameter_db.temp_dict[ + "deformation_function" + ] + else: + self.deformation_function = fenics.Function( + self.db.function_db.control_spaces[0] + ) self.global_deformation_vector = self.deformation_function.vector().vec() self.stepsize = self.config.getfloat("LineSearch", "initial_stepsize") diff --git a/cashocs/geometry/mesh_handler.py b/cashocs/geometry/mesh_handler.py index 4fba6283..5f1c5647 100644 --- a/cashocs/geometry/mesh_handler.py +++ b/cashocs/geometry/mesh_handler.py @@ -637,7 +637,7 @@ def remesh(self, solver: OptimizationAlgorithm) -> None: "gradient_norm_initial" ] = solver.gradient_norm_initial - self._update_mesh_transfer_matrix(new_xdmf_file) + self._update_mesh_transfer_matrix(new_xdmf_file, solver) self._reinitialize(solver) self._check_imported_mesh_quality(solver) @@ -675,11 +675,14 @@ def _check_imported_mesh_quality(self, solver: OptimizationAlgorithm) -> None: check_mesh_quality_tolerance(current_mesh_quality, mesh_quality_tol_upper) - def _update_mesh_transfer_matrix(self, xdmf_filename: str) -> None: + def _update_mesh_transfer_matrix( + self, xdmf_filename: str, solver: OptimizationAlgorithm + ) -> None: """Updates the transfer matrix for the global deformation after remeshing. Args: xdmf_filename: The filename for the new mesh (in XDMF format). + solver: The optimization algorithm. """ pre_log_level = ( @@ -700,3 +703,6 @@ def _update_mesh_transfer_matrix(self, xdmf_filename: str) -> None: self.db.parameter_db.temp_dict[ "old_transfer_matrix" ] = self.db.geometry_db.transfer_matrix.copy() + self.db.parameter_db.temp_dict[ + "deformation_function" + ] = solver.line_search.deformation_function.copy(True) diff --git a/docs/source/_static/version_switcher.json b/docs/source/_static/version_switcher.json index c0190cc7..d6e1a500 100755 --- a/docs/source/_static/version_switcher.json +++ b/docs/source/_static/version_switcher.json @@ -6,8 +6,8 @@ }, { "name": "2.0 (stable)", - "version": "2.0.2", - "url": "https://cashocs.readthedocs.io/en/v2.0.2/" + "version": "2.0.3", + "url": "https://cashocs.readthedocs.io/en/v2.0.3/" }, { "name": "1.8",