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

107 mixed space adj project #108

Merged
merged 6 commits into from
Feb 21, 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
5 changes: 3 additions & 2 deletions goalie/adjoint.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Drivers for solving adjoint problems on sequences of meshes.
"""

import firedrake
from firedrake.petsc import PETSc
from firedrake.adjoint import pyadjoint
Expand Down Expand Up @@ -382,8 +383,8 @@ def wrapped_solver(subinterval, ic, **kwargs):
)
elif j * stride + 1 == num_solve_blocks:
if i + 1 < num_subintervals:
sols.adjoint_next[i][j].project(
sols.adjoint_next[i + 1][0]
project(
sols.adjoint_next[i + 1][0], sols.adjoint_next[i][j]
)
else:
raise IndexError(
Expand Down
7 changes: 6 additions & 1 deletion goalie/go_mesh_seq.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Drivers for goal-oriented error estimation on sequences of meshes.
"""

from .adjoint import AdjointMeshSeq
from .error_estimation import get_dwr_indicator
from .log import pyrint
Expand Down Expand Up @@ -61,7 +62,9 @@ def get_enriched_mesh_seq(
get_qoi=self._get_qoi,
get_bcs=self._get_bcs,
qoi_type=self.qoi_type,
parameters=self.params,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. Partially addresses #97.

)
mesh_seq_e.update_function_spaces()

# Apply p-refinement
if enrichment_method == "p":
Expand Down Expand Up @@ -312,7 +315,9 @@ def fixed_point_iteration(
break

# Adapt meshes and log element counts
continue_unconditionally = adaptor(self, self.solutions, self.indicators, **adaptor_kwargs)
continue_unconditionally = adaptor(
self, self.solutions, self.indicators, **adaptor_kwargs
)
if self.params.drop_out_converged:
self.check_convergence[:] = np.logical_not(
np.logical_or(continue_unconditionally, self.converged)
Expand Down
17 changes: 14 additions & 3 deletions goalie/mesh_seq.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Sequences of meshes corresponding to a :class:`~.TimePartition`.
"""

import firedrake
from firedrake.adjoint import pyadjoint
from firedrake.adjoint_utils.solving import get_solve_blocks
Expand Down Expand Up @@ -235,8 +236,10 @@ def _function_spaces_consistent(self) -> bool:
)
return consistent

@property
def function_spaces(self) -> list:
def update_function_spaces(self) -> list:
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jwallwork23 - I think your edits here make more sense than my interpretation of your suggestions and it is a better descriptive name of the method you had already implemented.

"""
Update the function space dictionary associated with the :class:`MeshSeq`.
"""
if self._fs is None or not self._function_spaces_consistent:
self._fs = [self.get_function_spaces(mesh) for mesh in self.meshes]
self._fs = AttrDict(
Expand All @@ -250,6 +253,10 @@ def function_spaces(self) -> list:
), "Meshes and function spaces are inconsistent"
return self._fs

@property
def function_spaces(self):
return self.update_function_spaces()

@property
def initial_condition(self) -> AttrDict:
ic = OrderedDict(self.get_initial_condition())
Expand Down Expand Up @@ -653,7 +660,11 @@ def check_element_count_convergence(self):

@PETSc.Log.EventDecorator()
def fixed_point_iteration(
self, adaptor: Callable, solver_kwargs: dict = {}, adaptor_kwargs: dict = {}, **kwargs
self,
adaptor: Callable,
solver_kwargs: dict = {},
adaptor_kwargs: dict = {},
**kwargs,
):
r"""
Apply goal-oriented mesh adaptation using a fixed point iteration loop.
Expand Down
Loading