Skip to content

Commit

Permalink
Merge pull request #339 from sblauth/dev/topology_visualization
Browse files Browse the repository at this point in the history
FEAT: Improve the visualization of the shape in topology optimization
  • Loading branch information
sblauth authored Oct 25, 2023
2 parents 09cb14d + 4a309b7 commit 178dc56
Show file tree
Hide file tree
Showing 14 changed files with 16 additions and 253 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,12 @@
from typing import Callable, List, Optional, TYPE_CHECKING, Union

import fenics
from matplotlib import colors
import numpy as np
import ufl

from cashocs import _exceptions
from cashocs import _optimization
from cashocs import _utils
from cashocs import io
from cashocs._optimization import line_search as ls
from cashocs._optimization.optimal_control import optimal_control_problem
Expand Down Expand Up @@ -308,8 +309,8 @@ def solve(

def plot_shape(self) -> None:
"""Visualize the current shape in a plot."""
shape = fenics.Function(self.dg0_space)
_utils.interpolate_levelset_function_to_cells(
self.levelset_function, 1.0, 0.0, shape
rgbvals = np.array([[0, 107, 164], [255, 128, 14]]) / 255.0
cmap = colors.LinearSegmentedColormap.from_list(
"tab10_colorblind", rgbvals, N=256
)
fenics.plot(shape)
fenics.plot(self.levelset_function, vmin=-1e-10, vmax=1e-10, cmap=cmap)
4 changes: 2 additions & 2 deletions demos/documented/topology_optimization/cantilever/config.ini
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ inner_newton_atol = 0.0

[Output]
verbose = True
save_results = True
save_txt = True
save_results = False
save_txt = False
save_state = False
save_adjoint = False
save_gradient = False
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

This file was deleted.

This file was deleted.

4 changes: 2 additions & 2 deletions demos/documented/topology_optimization/pipe_bend/config.ini
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ topological_derivative_is_identical = True

[Output]
verbose = True
save_results = True
save_txt = True
save_results = False
save_txt = False
save_state = False
save_adjoint = False
save_gradient = False
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ topological_derivative_is_identical = True

[Output]
verbose = True
save_results = True
save_txt = True
save_results = False
save_txt = False
save_state = False
save_adjoint = False
save_gradient = False
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 178dc56

Please sign in to comment.