From e6eda4cbc78593d4cfc9e8001cdbc7f062a8d1c5 Mon Sep 17 00:00:00 2001 From: Sebastian Blauth Date: Fri, 8 Nov 2024 16:24:03 +0100 Subject: [PATCH 1/3] USe the ghost offset correctly for interpolating the levelset function to cells --- cashocs/_utils/interpolations.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/cashocs/_utils/interpolations.py b/cashocs/_utils/interpolations.py index 1a5ea9bc..65e245af 100644 --- a/cashocs/_utils/interpolations.py +++ b/cashocs/_utils/interpolations.py @@ -132,10 +132,11 @@ std::vector cells = mesh->cells(); int meshdim = mesh->geometry().dim(); + auto ghost_offset = mesh->topology().ghost_offset(meshdim); if (meshdim == 2){ int index = 0; - for (int i=0; i Date: Mon, 11 Nov 2024 14:39:49 +0100 Subject: [PATCH 2/3] Fix some small mpi related bugs --- cashocs/_utils/interpolations.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/cashocs/_utils/interpolations.py b/cashocs/_utils/interpolations.py index 65e245af..9f79de0e 100644 --- a/cashocs/_utils/interpolations.py +++ b/cashocs/_utils/interpolations.py @@ -247,7 +247,8 @@ def interpolate_by_volume( ) arr = fenics.assemble(form_td * test * dx) vol = fenics.assemble(test * dx) - node_function.vector()[:] = arr[:] / vol[:] + node_function.vector().set_local(arr[:] / vol[:]) + node_function.vector().apply("") def interpolate_by_angle( @@ -440,3 +441,4 @@ def interpolate_by_angle( values /= weights d2v = fenics.dof_to_vertex_map(cg1_space) node_function.vector()[:] = values[d2v] + node_function.vector().apply("") From 902f37aed489f4beb66c34f9fb30a4edb2392170 Mon Sep 17 00:00:00 2001 From: Sebastian Blauth Date: Mon, 11 Nov 2024 14:47:40 +0100 Subject: [PATCH 3/3] Raise exception for angle weighted interpolation in parallel --- .../topology_optimization_algorithm.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/cashocs/_optimization/topology_optimization/topology_optimization_algorithm.py b/cashocs/_optimization/topology_optimization/topology_optimization_algorithm.py index 68798a33..b48b8026 100755 --- a/cashocs/_optimization/topology_optimization/topology_optimization_algorithm.py +++ b/cashocs/_optimization/topology_optimization/topology_optimization_algorithm.py @@ -90,6 +90,16 @@ def __init__( self._cashocs_problem.db.parameter_db.problem_type = "topology" self.mesh = optimization_problem.mesh + + mpi_comm = self.mesh.mpi_comm() + if self.interpolation_scheme == "angle" and mpi_comm.Get_size() > 1: + raise _exceptions.InputError( + "TopologyOptimizationProblem", + "TopologyOptimization.interpolation_scheme", + "The angle weighted interpolation option is not supported in parallel. " + "Please use interpolation_scheme = volume in your config file.", + ) + self.cg1_space = fenics.FunctionSpace(self.mesh, "CG", 1) self.dg0_space = optimization_problem.dg0_space self.topological_derivative_vertex: fenics.Function = fenics.Function(