Skip to content

GoalAdaptiveVariationalSolver#4893

Draft
pbrubeck wants to merge 56 commits intomainfrom
pbrubeck/goal-adaptive-solver
Draft

GoalAdaptiveVariationalSolver#4893
pbrubeck wants to merge 56 commits intomainfrom
pbrubeck/goal-adaptive-solver

Conversation

@pbrubeck
Copy link
Copy Markdown
Contributor

Description

@pbrubeck pbrubeck force-pushed the pbrubeck/goal-adaptive-solver branch from daf58a1 to b28fbf5 Compare February 26, 2026 13:52
Comment on lines +546 to +551
if write_solution == "all":
should_write = True
elif write_solution == "first_and_last":
if it == 0 or it == self.options.max_iterations:
should_write = True
elif write_solution == "by_iteration":
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

These are too many cases, and it is not obvious for a user. The user could decide if they want to do this by writing their own adaptivity loop and calling solver.step(). Should we just remove this function?

Comment on lines +657 to +664
# Only required for my examples:
def getlabels(mesh, codim):
ngmesh = mesh.netgen_mesh
names = ngmesh.GetRegionNames(codim=codim)
names_to_labels = {}
for l in names:
names_to_labels[l] = tuple(i+1 for i, name in enumerate(names) if name == l)
return names_to_labels
Copy link
Copy Markdown
Contributor Author

@pbrubeck pbrubeck Mar 27, 2026

Choose a reason for hiding this comment

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

This should probably become a class method, something like:

mesh.region_names_to_subdomain_ids(codim)

Comment on lines +619 to +654
@singledispatch
def refine(expr, self, coefficient_mapping=None):
return coarsen(expr, self, coefficient_mapping=coefficient_mapping) # fallback to original


@refine.register(ufl.Mesh)
@refine.register(ufl.MeshSequence)
def refine_mesh(mesh, self, coefficient_mapping=None):
hierarchy, level = utils.get_level(mesh)
if hierarchy is None:
raise CoarseningError("No mesh hierarchy available")
return hierarchy[level + 1]


@refine.register(Cofunction)
@refine.register(Function)
def refine_function(expr, self, coefficient_mapping=None):
if coefficient_mapping is None:
coefficient_mapping = {}
new = coefficient_mapping.get(expr)
if new is None:
Vf = expr.function_space()
Vc = self(Vf, self)
name = expr.name()
if name is not None:
level_increment = -1 if self == coarsen else 1
try:
name, prev_level = name.split("_level_")
except ValueError:
prev_level = 0
level = int(prev_level) + level_increment
name = f"{name}_level_{level}"
new = Function(Vc, name=name)
new.interpolate(expr)
coefficient_mapping[expr] = new
return new
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This should live in mg/ufl_utils.py

@pbrubeck pbrubeck force-pushed the pbrubeck/goal-adaptive-solver branch 2 times, most recently from 4341140 to 34be255 Compare April 7, 2026 11:12
@pbrubeck pbrubeck force-pushed the pbrubeck/goal-adaptive-solver branch from 34be255 to 774aedf Compare April 7, 2026 11:15
@pbrubeck pbrubeck force-pushed the pbrubeck/goal-adaptive-solver branch from f59bd8e to b920833 Compare April 7, 2026 16:54
@pbrubeck pbrubeck force-pushed the pbrubeck/goal-adaptive-solver branch from 645af70 to 37ab7d9 Compare April 7, 2026 17:36
@pbrubeck pbrubeck force-pushed the pbrubeck/goal-adaptive-solver branch from b3dcbb2 to befe0ff Compare April 7, 2026 21:08
@pbrubeck pbrubeck force-pushed the pbrubeck/goal-adaptive-solver branch from befe0ff to b241c80 Compare April 7, 2026 22:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants