Skip to content

Commit

Permalink
Merge branch 'main' into hotfix/2.1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
sblauth authored Mar 7, 2024
2 parents 735d625 + a1af5dd commit 03c915c
Show file tree
Hide file tree
Showing 10 changed files with 53 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ repos:
- id: pyroma

- repo: https://github.com/psf/black
rev: 24.1.1
rev: 24.2.0
hooks:
- id: black

Expand Down
4 changes: 2 additions & 2 deletions .zenodo.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"description": "<p>cashocs is a computational, adjoint-based shape optimization and optimal control software.</p>",
"license": "GPL-3.0+",
"title": "cashocs v2.1.1",
"version": "v2.1.1",
"title": "cashocs v2.2.0-dev",
"version": "v2.2.0-dev",
"upload_type": "software",
"creators": [
{
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ of the maintenance releases, please take a look at
`<https://github.com/sblauth/cashocs/releases>`_.


2.2.0 (in development)
----------------------

* Increase the precision of the Gmsh output from cashocs


2.1.0 (February 6, 2024)
------------------------

Expand Down
3 changes: 2 additions & 1 deletion cashocs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@
from cashocs.nonlinear_solvers import newton_solve
from cashocs.nonlinear_solvers import picard_iteration

__version__ = "2.1.1"

__version__ = "2.2.0-dev"

__citation__ = """
@Article{Blauth2021cashocs,
Expand Down
1 change: 1 addition & 0 deletions cashocs/_optimization/line_search/armijo_line_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,5 +199,6 @@ def _compute_objective_at_new_iterate(self, current_function_value: float) -> fl
raise error
else:
objective_step = 2.0 * abs(current_function_value)
self.state_problem.revert_to_checkpoint()

return objective_step
24 changes: 24 additions & 0 deletions cashocs/_pde_problems/state_problem.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ def __init__(

self.bcs_list: List[List[fenics.DirichletBC]] = self.state_form_handler.bcs_list
self.states = self.db.function_db.states
self.states_checkpoint = [fun.copy(True) for fun in self.states]

self.picard_rtol = self.config.getfloat("StateSystem", "picard_rtol")
self.picard_atol = self.config.getfloat("StateSystem", "picard_atol")
Expand Down Expand Up @@ -127,6 +128,7 @@ def solve(self) -> List[fenics.Function]:
"""
if not self.has_solution:
self.db.callback.call_pre()
self._generate_checkpoint()
if (
not self.config.getboolean("StateSystem", "picard_iteration")
or self.db.parameter_db.state_dim == 1
Expand Down Expand Up @@ -198,3 +200,25 @@ def solve(self) -> List[fenics.Function]:
self._update_cost_functionals()

return self.states

def _generate_checkpoint(self) -> None:
"""Generates a checkpoint of the state variables."""
for i in range(len(self.states)):
self.states_checkpoint[i].vector().vec().aypx(
0.0, self.states[i].vector().vec()
)
self.states_checkpoint[i].vector().apply("")

def revert_to_checkpoint(self) -> None:
"""Reverts the state variables to a checkpointed value.
This is useful when the solution of the state problem fails and another attempt
is made to solve it. Then, the perturbed solution of Newton's method should not
be the initial guess.
"""
for i in range(len(self.states)):
self.states[i].vector().vec().aypx(
0.0, self.states_checkpoint[i].vector().vec()
)
self.states[i].vector().apply("")
12 changes: 10 additions & 2 deletions cashocs/io/managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -585,8 +585,16 @@ def _write_xdmf_step(
mesh = function.function_space().mesh()
comm = mesh.mpi_comm()

if function.function_space().ufl_element().family() == "Real":
space = fenics.FunctionSpace(mesh, "CG", 1)
if function.function_space().ufl_element().family() in [
"Real",
"NodalEnrichedElement",
]:
if len(function.ufl_shape) > 0:
space = fenics.VectorFunctionSpace(
mesh, "CG", 1, dim=function.ufl_shape[0]
)
else:
space = fenics.FunctionSpace(mesh, "CG", 1)
function = fenics.interpolate(function, space)

function.rename(function_name, function_name)
Expand Down
10 changes: 5 additions & 5 deletions cashocs/io/mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -355,14 +355,14 @@ def create_point_representation(
mod_line = ""
if dim == 2:
mod_line = (
f"{points[idcs[subwrite_counter]][0]:.16f} "
f"{points[idcs[subwrite_counter]][1]:.16f} 0\n"
f"{points[idcs[subwrite_counter]][0]:.16e} "
f"{points[idcs[subwrite_counter]][1]:.16e} 0\n"
)
elif dim == 3:
mod_line = (
f"{points[idcs[subwrite_counter]][0]:.16f} "
f"{points[idcs[subwrite_counter]][1]:.16f} "
f"{points[idcs[subwrite_counter]][2]:.16f}\n"
f"{points[idcs[subwrite_counter]][0]:.16e} "
f"{points[idcs[subwrite_counter]][1]:.16e} "
f"{points[idcs[subwrite_counter]][2]:.16e}\n"
)

return mod_line
Expand Down
2 changes: 1 addition & 1 deletion docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
author = "Sebastian Blauth"

# The full version, including alpha/beta/rc tags
release = "2.1.1"
release = "2.2.0-dev"


# -- General configuration ---------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "cashocs"
version = "2.1.1"
version = "2.2.0-dev"
description = "Computational Adjoint-Based Shape Optimization and Optimal Control Software"
readme = "README.rst"
requires-python = ">=3.8"
Expand Down

0 comments on commit 03c915c

Please sign in to comment.