From 3c72f84632a40b849c69f78edeb80b08fcea9a25 Mon Sep 17 00:00:00 2001 From: Sebastian Blauth Date: Tue, 11 Jul 2023 09:29:58 +0200 Subject: [PATCH 1/2] Add the possibility to remesh after a certain amount of iters --- .../shape_variable_abstractions.py | 14 +++++++++++++- cashocs/io/config.py | 5 +++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/cashocs/_optimization/shape_optimization/shape_variable_abstractions.py b/cashocs/_optimization/shape_optimization/shape_variable_abstractions.py index ef9fbf38..7071104b 100644 --- a/cashocs/_optimization/shape_optimization/shape_variable_abstractions.py +++ b/cashocs/_optimization/shape_optimization/shape_variable_abstractions.py @@ -144,11 +144,23 @@ def requires_remeshing(self) -> bool: A boolean, which indicates whether remeshing is required. """ - return bool( + mesh_quality_criterion = bool( self.mesh_handler.current_mesh_quality < self.mesh_handler.mesh_quality_tol_upper ) + iteration = self.db.parameter_db.optimization_state["iteration"] + if self.db.config.getint("MeshQuality", "remesh_iter") > 0: + iteration_criterion = bool( + iteration > 0 + and iteration % self.db.config.getint("MeshQuality", "remesh_iter") == 0 + ) + else: + iteration_criterion = False + + requires_remeshing = mesh_quality_criterion or iteration_criterion + return requires_remeshing + def project_ncg_search_direction( self, search_direction: List[fenics.Function] ) -> None: diff --git a/cashocs/io/config.py b/cashocs/io/config.py index 2e39a168..2dd5928c 100644 --- a/cashocs/io/config.py +++ b/cashocs/io/config.py @@ -462,6 +462,10 @@ def __init__(self, config_file: Optional[str] = None) -> None: "type": "str", "possible_options": ["min", "avg", "minimum", "average"], }, + "remesh_iter": { + "type": "int", + "attributes": ["non_negative"], + }, }, "TopologyOptimization": { "angle_tol": { @@ -637,6 +641,7 @@ def __init__(self, config_file: Optional[str] = None) -> None: type = min volume_change = inf angle_change = inf +remesh_iter = 0 [TopologyOptimization] angle_tol = 1.0 From 0a65838c150142c4145a370b1dba09b550924b6c Mon Sep 17 00:00:00 2001 From: Sebastian Blauth Date: Tue, 11 Jul 2023 09:36:44 +0200 Subject: [PATCH 2/2] Document the remesh_iter configuration option --- CHANGELOG.rst | 4 ++++ .../user/demos/shape_optimization/doc_config.rst | 10 +++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 57e8bd24..206152c5 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -18,6 +18,10 @@ of the maintenance releases, please take a look at * :ini:`fail_if_not_converged` determines, whether the line search is cancelled once the state system cannot be solved or if a new iterate is tried instead. + * Section MeshQuality + + * :ini:`remesh_iter` is used to perform a remeshing after a certain amount of iterations. + 2.0.0 (May 16, 2023) diff --git a/docs/source/user/demos/shape_optimization/doc_config.rst b/docs/source/user/demos/shape_optimization/doc_config.rst index 0efbc71f..130d0474 100755 --- a/docs/source/user/demos/shape_optimization/doc_config.rst +++ b/docs/source/user/demos/shape_optimization/doc_config.rst @@ -963,7 +963,7 @@ Available options are (see :py:class:`MeshQuality ` for a detailed description). The default value is given by :ini:`measure = skewness`. -Finally, the parameter :ini:`type` determines, whether the minimum quality over all +The parameter :ini:`type` determines, whether the minimum quality over all elements (:ini:`type = min`) or the average quality over all elements (:ini:`type = avg`) shall be used. This is set via @@ -973,6 +973,14 @@ shall be used. This is set via and defaults to :ini:`type = min`. +Finally, we have the parameter :ini:`remesh_iter` in which the user can specify after how many iterations a remeshing should be performed. It is given by + +.. code-block:: ini + + remesh_iter = 0 + +where :ini:`remesh_iter = 0` means that no automatic remeshing is performed (this is the default), and :ini:`remesh_iter = n` means that remeshing is performed after each `n` iterations. Note that to use this parameter and avoid unexpected results, it might be beneficial to the the lower and upper mesh quality tolerances to a low value, so that the "quality based remeshing" does not interfere with the "iteration based remeshing", but both can be used in combination. + .. _config_shape_output: Section Output