Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FEAT: Improve the visualization of the shape in topology optimization #339

Merged
merged 2 commits into from
Oct 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading