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

Surface Quantities: Surface Flux #629

Merged
merged 72 commits into from
Nov 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
72 commits
Select commit Hold shift + click to select a range
56948fb
time dependent bcs updated
jhdark Oct 25, 2023
ceeb5c2
Merge pull request #16 from jhdark/fenicsx
jhdark Oct 26, 2023
751841c
dont add to another list, update bcs
jhdark Oct 26, 2023
d5cd7c0
renaming
jhdark Oct 26, 2023
b87518e
system test not needed
jhdark Oct 26, 2023
86cd7e7
test time dependent attribute
jhdark Oct 26, 2023
6874755
update doc strings
jhdark Oct 26, 2023
334f190
post processing
jhdark Oct 28, 2023
0146875
simpler method
jhdark Oct 31, 2023
176f42d
import surface quantity and flux
jhdark Oct 31, 2023
1d031a3
surface flux class
jhdark Nov 1, 2023
1834054
use D global for exports
jhdark Nov 1, 2023
67dabb9
use derived quantites dict
jhdark Nov 1, 2023
1db757f
work in multispecies
jhdark Nov 1, 2023
2022255
updated permeation test
jhdark Nov 1, 2023
42a93b9
blank lines
jhdark Nov 1, 2023
42e2e90
split methods
RemDelaporteMathurin Nov 1, 2023
176274f
commented out import
RemDelaporteMathurin Nov 1, 2023
a5665c9
no need for D_global attribute
RemDelaporteMathurin Nov 1, 2023
f6e87c6
dict initialisation outside of loop
RemDelaporteMathurin Nov 1, 2023
8482ea1
add D and D_expr to dicts + comments
RemDelaporteMathurin Nov 1, 2023
42e00ab
cell_indices instead of entities
RemDelaporteMathurin Nov 1, 2023
43a587a
refactored define_D_global
RemDelaporteMathurin Nov 1, 2023
2709196
added TODO
RemDelaporteMathurin Nov 1, 2023
876d5e7
docstrings + species instead of spe
RemDelaporteMathurin Nov 1, 2023
d7e9d0d
pop species from species_not_updated
RemDelaporteMathurin Nov 1, 2023
7ca1912
Merge pull request #18 from RemDelaporteMathurin/surface_flux_export_…
jhdark Nov 1, 2023
70e00fe
Merge branch 'surface_flux_export' of https://github.com/jhdark/FESTI…
jhdark Nov 1, 2023
45ed02d
store data and t, move setters to parent
jhdark Nov 1, 2023
068efdc
add setters
jhdark Nov 1, 2023
a341ecd
include surface quantity
jhdark Nov 1, 2023
3461803
refactoring
jhdark Nov 1, 2023
a52d768
updated tests
jhdark Nov 1, 2023
4d5f9f1
Merge branch 'update_time_dependent_bcs' into fenicsx
jhdark Nov 2, 2023
5aa6b21
Merge branch 'surface_flux_export' into fenicsx
jhdark Nov 2, 2023
100271d
Merge pull request #20 from jhdark/fenicsx
jhdark Nov 2, 2023
a550c54
dont use skip_post_processing
jhdark Nov 2, 2023
2356e1a
added docs, only give n
jhdark Nov 2, 2023
22e3bf4
updated docs
jhdark Nov 2, 2023
fbfaea8
refactoring
jhdark Nov 2, 2023
b5804e8
rename test file
jhdark Nov 2, 2023
74dcd41
Merge branch 'RemDelaporteMathurin:fenicsx' into fenicsx
jhdark Nov 2, 2023
5ffb629
Merge pull request #21 from jhdark/fenicsx
jhdark Nov 2, 2023
6c41bf3
remove time dependent bcs
jhdark Nov 2, 2023
20b3b47
Merge branch 'surface_flux_export' of https://github.com/jhdark/FESTI…
jhdark Nov 2, 2023
1a8ac51
remove from doc
jhdark Nov 2, 2023
b7898a8
only export when needed, use surface quantity in tests
jhdark Nov 2, 2023
de7440c
test species in list
jhdark Nov 2, 2023
c610f43
new tests
jhdark Nov 2, 2023
41e25e2
only create file after species matches
jhdark Nov 2, 2023
62f653d
create file as method
jhdark Nov 2, 2023
6233d38
not needed
jhdark Nov 2, 2023
f385a71
call create file
jhdark Nov 2, 2023
1e5c3f5
not accepting ints for now
jhdark Nov 2, 2023
5eef473
update global D in post processing
jhdark Nov 2, 2023
2414d62
surface instead of surface subdomain
jhdark Nov 2, 2023
9852021
updated doc strings
jhdark Nov 2, 2023
8ddc161
use temperature_fenics
jhdark Nov 2, 2023
e1abfab
test defining D_global
jhdark Nov 2, 2023
8248d78
test surface setter
jhdark Nov 2, 2023
b003bde
test global D with same species
jhdark Nov 2, 2023
3878324
test post processing
jhdark Nov 4, 2023
bda7ad8
Apply suggestions from code review
jhdark Nov 4, 2023
52da3d0
fixes
jhdark Nov 4, 2023
96d47e0
new test and doc strings
jhdark Nov 5, 2023
cf41ff4
Apply suggestions from code review
jhdark Nov 5, 2023
e0d568a
changes from reveiw
jhdark Nov 5, 2023
4b20b05
test new materials methods
jhdark Nov 5, 2023
b1106db
Merge branch 'surface_flux_export' of https://github.com/jhdark/FESTI…
jhdark Nov 5, 2023
ee155e9
export one first write
jhdark Nov 6, 2023
849de04
update test
jhdark Nov 6, 2023
3f81828
updated docs
jhdark Nov 6, 2023
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
2 changes: 2 additions & 0 deletions festim/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@

from .stepsize import Stepsize

from .exports.surface_quantity import SurfaceQuantity
from .exports.surface_flux import SurfaceFlux
from .exports.vtx import VTXExport
from .exports.xdmf import XDMFExport

Expand Down
42 changes: 42 additions & 0 deletions festim/exports/surface_flux.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
from dolfinx import fem
import festim as F
import ufl


class SurfaceFlux(F.SurfaceQuantity):
"""Exports surface flux at a given subdomain

Args:
field (festim.Species): species for which the surface flux is computed
surface (festim.SurfaceSubdomain1D): surface subdomain
filename (str, optional): name of the file to which the surface flux is exported

Attributes:
field (festim.Species): species for which the surface flux is computed
Copy link
Collaborator

Choose a reason for hiding this comment

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

Note to ourselves: one day we will want to compute HeatFluxes

surface (festim.SurfaceSubdomain1D): surface subdomain
filename (str): name of the file to which the surface flux is exported
"""

def __init__(
self,
field: F.Species,
surface: F.SurfaceSubdomain1D,
filename: str = None,
) -> None:
super().__init__(field, surface, filename)

def compute(self, n, ds):
jhdark marked this conversation as resolved.
Show resolved Hide resolved
"""Computes the value of the surface flux at the surface

Args:
n (ufl.geometry.FacetNormal): normal vector to the surface
ds (ufl.Measure): surface measure of the model
"""
self.value = fem.assemble_scalar(
fem.form(
-self.D
* ufl.dot(ufl.grad(self.field.solution), n)
* ds(self.surface.id)
)
)
self.data.append(self.value)
82 changes: 82 additions & 0 deletions festim/exports/surface_quantity.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import festim as F
import csv
import os


class SurfaceQuantity:
"""Export SurfaceQuantity

Args:
field (festim.Species): species for which the surface flux is computed
surface (festim.SurfaceSubdomain1D): surface subdomain
filename (str, optional): name of the file to which the surface flux is exported

Attributes:
field (festim.Species): species for which the surface flux is computed
surface (festim.SurfaceSubdomain1D): surface subdomain
filename (str): name of the file to which the surface flux is exported
jhdark marked this conversation as resolved.
Show resolved Hide resolved
t (list): list of time values
data (list): list of values of the surface quantity
"""

def __init__(self, field, surface, filename: str = None) -> None:
self.field = field
self.surface = surface
self.filename = filename

self.t = []
self.data = []
jhdark marked this conversation as resolved.
Show resolved Hide resolved

@property
def filename(self):
return self._filename

@filename.setter
def filename(self, value):
if value is None:
self._filename = None
elif not isinstance(value, str):
raise TypeError("filename must be of type str")
elif not value.endswith(".csv") and not value.endswith(".txt"):
raise ValueError("filename must end with .csv or .txt")
self._filename = value

@property
def surface(self):
return self._surface

@surface.setter
def surface(self, value):
if not isinstance(value, (int, F.SurfaceSubdomain1D)) or isinstance(
value, bool
):
raise TypeError("surface should be an int or F.SurfaceSubdomain1D")
self._surface = value

@property
def field(self):
return self._field

@field.setter
def field(self, value):
# check that field is festim.Species
if not isinstance(value, (F.Species, str)):
raise TypeError("field must be of type festim.Species")

self._field = value

def write(self, t):
"""If the filename doesnt exist yet, create it and write the header,
then append the time and value to the file"""

if not os.path.isfile(self.filename):
title = "Flux surface {}: {}".format(self.surface.id, self.field.name)

if self.filename is not None:
with open(self.filename, mode="w", newline="") as file:
writer = csv.writer(file)
writer.writerow(["t(s)", f"{title}"])

with open(self.filename, mode="a", newline="") as file:
writer = csv.writer(file)
writer.writerow([t, self.value])
Loading
Loading