Skip to content

Knook/multicomponent #4322

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

Open
wants to merge 35 commits into
base: release
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
d0bab8a
initial commit multicomponent flow demo
KarsKnook May 14, 2025
95f8d38
more writing
KarsKnook May 14, 2025
737c860
text, code, figures
KarsKnook May 15, 2025
3ca07ea
restructure and writing
KarsKnook May 20, 2025
c8aa070
reference
KarsKnook May 20, 2025
5145f3c
bibliography
KarsKnook May 20, 2025
c8e58a9
Small suggestions (#4335)
pefarrell May 21, 2025
11062d8
typos
KarsKnook May 21, 2025
405b685
Merge branch 'release' into knook/multicomponent
KarsKnook May 21, 2025
68a72b7
swap order
KarsKnook May 21, 2025
9dfc296
resolving suggestions
KarsKnook May 26, 2025
345d94b
Merge remote-tracking branch 'origin/release' into knook/multicomponent
connorjward Jun 4, 2025
4a4e1f7
Fix underlines
connorjward Jun 4, 2025
4042260
smaller problem for CI
KarsKnook Jun 5, 2025
133f07a
fixes
KarsKnook Jun 9, 2025
cd61bf3
naming fields outside continuation loop
KarsKnook Jun 9, 2025
fe14543
clarifying equationBC
KarsKnook Jun 10, 2025
a6f0e1b
better FixAtPointBC
KarsKnook Jun 11, 2025
08026f5
typo
KarsKnook Jun 11, 2025
37738c5
Update demos/multicomponent/multicomponent.py.rst
ABaierReinio Jun 22, 2025
46ee4c1
Update demos/multicomponent/multicomponent.py.rst
ABaierReinio Jun 22, 2025
b53d79f
Update demos/multicomponent/multicomponent.py.rst
ABaierReinio Jun 22, 2025
b168413
Update demos/multicomponent/multicomponent.py.rst
ABaierReinio Jun 22, 2025
65a4bcc
Update demos/multicomponent/multicomponent.py.rst
ABaierReinio Jun 22, 2025
b9928c6
Update demos/boussinesq/boussinesq.py.rst
ABaierReinio Jun 22, 2025
0414465
Update demos/multicomponent/multicomponent.py.rst
ABaierReinio Jun 22, 2025
f7cfe89
Update demos/multicomponent/multicomponent.py.rst
ABaierReinio Jun 22, 2025
45422ac
Update demos/multicomponent/multicomponent.py.rst
ABaierReinio Jun 22, 2025
e73f614
Update demos/multicomponent/multicomponent.py.rst
ABaierReinio Jun 22, 2025
6a1a3b2
Update demos/multicomponent/multicomponent.py.rst
ABaierReinio Jun 22, 2025
c6362f2
Merge branch 'release' into knook/multicomponent
ABaierReinio Jun 22, 2025
38a6ef9
Fix description of BCs
ABaierReinio Jun 22, 2025
24c356d
Use mathrsfs when building doc PDF
ABaierReinio Jun 29, 2025
7278e91
Store boundary ids as tuples so they can be used as dictionary keys
ABaierReinio Jun 29, 2025
7364530
Include runnable python script
ABaierReinio Jun 29, 2025
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
73 changes: 38 additions & 35 deletions demos/boussinesq/boussinesq.py.rst
Original file line number Diff line number Diff line change
Expand Up @@ -160,43 +160,46 @@ cannot always be sure that the linear solver at hand is correctly utilising the
To directly eliminate the nullspace we introduce a class :code:`FixAtPointBC` which
implements a boundary condition that fixes a field at a single point. ::

import firedrake.utils as firedrake_utils

class FixAtPointBC(firedrake.DirichletBC):
r'''A special BC object for pinning a function at a point.

:arg V: the :class:`.FunctionSpace` on which the boundary condition should be applied.
:arg g: the boundary condition value.
:arg bc_point: the point at which to pin the function.
The location of the finite element DOF nearest to bc_point is actually used.
'''
def __init__(self, V, g, bc_point):
super(FixAtPointBC, self).__init__(V, g, bc_point)
if isinstance(bc_point, tuple):
bc_point = as_vector(bc_point)
self.bc_point = bc_point

@firedrake_utils.cached_property
def nodes(self):
V = self.function_space()
x = firedrake.SpatialCoordinate(V.mesh())
xdist = x - self.bc_point

test = firedrake.TestFunction(V)
trial = firedrake.TrialFunction(V)
xphi = firedrake.assemble(ufl.inner(xdist * test, xdist * trial) * ufl.dx, diagonal=True)
phi = firedrake.assemble(ufl.inner(test, trial) * ufl.dx, diagonal=True)
with xphi.dat.vec as xu, phi.dat.vec as u:
xu.pointwiseDivide(xu, u)
min_index, min_value = xu.min() # Find the index of the DOF closest to bc_point

nodes = V.dof_dset.lgmap.applyInverse([min_index])
nodes = nodes[nodes >= 0]
return nodes

import functools

class FixAtPointBC(DirichletBC):
r'''A special BC object for pinning a function at a point.

:arg V: the :class:`.FunctionSpace` on which the boundary condition should be applied.
:arg g: the boundary condition value.
:arg bc_point: the point at which to pin the function.
The location of the finite element DOF nearest to bc_point is actually used.
'''
def __init__(self, V, g, bc_point):
super().__init__(V, g, bc_point)

@functools.cached_property
def nodes(self):
V = self.function_space()
if V.mesh().ufl_coordinate_element().degree() != 1:
# Ensure a P1 mesh
coordinates = V.mesh().coordinates
P1 = coordinates.function_space().reconstruct(degree=1)
P1_mesh = Mesh(Function(P1).interpolate(coordinates))
V = V.reconstruct(mesh=P1_mesh)

point = [tuple(self.sub_domain)]
vom = VertexOnlyMesh(V.mesh(), point)
P0 = FunctionSpace(vom, "DG", 0)
Fvom = Cofunction(P0.dual()).assign(1)

# Take the basis function with the largest abs value at bc_point
v = TestFunction(V)
F = assemble(Interpolate(inner(v, v), Fvom))
with F.dat.vec as Fvec:
max_index, _ = Fvec.max()
nodes = V.dof_dset.lgmap.applyInverse([max_index])
nodes = nodes[nodes >= 0]
return nodes

We use this to fix the pressure and auxiliary temperature at the origin::

aux_bcs = [FixAtPointBC(Z.sub(1), 0, as_vector([0, 0])),
aux_bcs = [FixAtPointBC(Z.sub(1), 0, (0, 0)),
FixAtPointBC(Z.sub(2), 0, as_vector([0, 0]))]

:code:`FixAtPointBC` takes three arguments: the function space to fix, the value with which it
Expand Down
27 changes: 27 additions & 0 deletions demos/demo_references.bib
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@ @Book{2006:SV
year = 2006
}

@book{Perry:2007,
title = {Perry’s Chemical Engineers’ Handbook},
edition = {8th},
author = {Green, Don W. and Perry, Robert H.},
year = 2007,
publisher = {McGraw Hill Professional}
}

@InBook{2015:lmscup,
author = {O. Bokhove and A. Kalogirou},
title = {Lectures on the Theory of Water Waves},
Expand Down Expand Up @@ -309,6 +317,25 @@ @article{Ricker:1953
doi={https://doi.org/10.1190/1.1437843}
}

@article{Krishna:1997,
title={The {M}axwell--{S}tefan approach to mass transfer},
author={Krishna, Rajamani and Wesselingh, Johannes A},
journal={Chemical Engineering Science},
volume={52},
number={6},
pages={861--911},
year={1997},
publisher={Elsevier},
doi={10.1016/S0009-2509(96)00458-7}
}

@article{BaierReinio:2025,
title={High-order finite element methods for three-dimensional multicomponent convection-diffusion},
author={Baier-Reinio, Aaron and Farrell, Patrick E},
journal={arXiv preprint arXiv:2408.17390},
year={2025}
}

@article{Brubeck2022,
author = {Brubeck, Pablo D. and Farrell, Patrick E.},
doi = {10.1137/21M1444187},
Expand Down
Binary file added demos/multicomponent/benzene_0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added demos/multicomponent/benzene_4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added demos/multicomponent/microfluidic_container.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading