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

Make the inner optimal control problem silent in topology optimization #515

Merged
merged 2 commits into from
Nov 11, 2024
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 @@ -262,6 +262,7 @@ def __init__(
self, self.box_constraints, self.db
)
)
self._silent = False

if bool(desired_weights is not None):
self._scale_cost_functional()
Expand Down Expand Up @@ -405,15 +406,17 @@ def solve(
+ \texttt{rtol} || \nabla J(u_0) ||

"""
log.begin("Solving the optimal control problem.", level=log.INFO)
if not self._silent:
log.begin("Solving the optimal control problem.", level=log.INFO)
super().solve(algorithm=algorithm, rtol=rtol, atol=atol, max_iter=max_iter)

self._setup_control_bcs()

self.solver = self._setup_solver()
self.solver.run()
self.solver.post_processing()
log.end()
if not self._silent:
log.end()

def compute_gradient(self) -> List[fenics.Function]:
"""Solves the Riesz problem to determine the gradient.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@ def post_processing(self) -> None:
elif self.converged_reason == -2:
self.iteration -= 1
self.post_process()
log.end()
self._exit("Armijo rule failed.")

# Mesh Quality is too low
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ def __init__(
self._cashocs_problem.config.set("OptimizationRoutine", "rtol", "0.0")
self._cashocs_problem.config.set("OptimizationRoutine", "atol", "0.0")

self._cashocs_problem._silent = True
self._cashocs_problem.output_manager._silent = True

self.successful = False
self.loop_restart = False

Expand Down
17 changes: 11 additions & 6 deletions cashocs/io/output.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ def __init__(self, db: database.Database) -> None:
self.result_dir = self.config.get("Output", "result_dir")
self.result_dir = self.result_dir.rstrip("/")

self._silent = False

self.time_suffix = self.config.getboolean("Output", "time_suffix")
if self.time_suffix:
dt_current_time = dt.now()
Expand Down Expand Up @@ -93,15 +95,18 @@ def __init__(self, db: database.Database) -> None:

def output(self) -> None:
"""Writes the desired output to files and console."""
for manager in self.managers:
manager.output()
if not self._silent:
for manager in self.managers:
manager.output()

def output_summary(self) -> None:
"""Writes the summary to files and console."""
for manager in self.managers:
manager.output_summary()
if not self._silent:
for manager in self.managers:
manager.output_summary()

def post_process(self) -> None:
"""Performs a postprocessing of the output."""
for manager in self.managers:
manager.post_process()
if not self._silent:
for manager in self.managers:
manager.post_process()
Loading