-
Notifications
You must be signed in to change notification settings - Fork 24
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
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 ceeb5c2
Merge pull request #16 from jhdark/fenicsx
jhdark 751841c
dont add to another list, update bcs
jhdark d5cd7c0
renaming
jhdark b87518e
system test not needed
jhdark 86cd7e7
test time dependent attribute
jhdark 6874755
update doc strings
jhdark 334f190
post processing
jhdark 0146875
simpler method
jhdark 176f42d
import surface quantity and flux
jhdark 1d031a3
surface flux class
jhdark 1834054
use D global for exports
jhdark 67dabb9
use derived quantites dict
jhdark 1db757f
work in multispecies
jhdark 2022255
updated permeation test
jhdark 42a93b9
blank lines
jhdark 42e2e90
split methods
RemDelaporteMathurin 176274f
commented out import
RemDelaporteMathurin a5665c9
no need for D_global attribute
RemDelaporteMathurin f6e87c6
dict initialisation outside of loop
RemDelaporteMathurin 8482ea1
add D and D_expr to dicts + comments
RemDelaporteMathurin 42e00ab
cell_indices instead of entities
RemDelaporteMathurin 43a587a
refactored define_D_global
RemDelaporteMathurin 2709196
added TODO
RemDelaporteMathurin 876d5e7
docstrings + species instead of spe
RemDelaporteMathurin d7e9d0d
pop species from species_not_updated
RemDelaporteMathurin 7ca1912
Merge pull request #18 from RemDelaporteMathurin/surface_flux_export_…
jhdark 70e00fe
Merge branch 'surface_flux_export' of https://github.com/jhdark/FESTI…
jhdark 45ed02d
store data and t, move setters to parent
jhdark 068efdc
add setters
jhdark a341ecd
include surface quantity
jhdark 3461803
refactoring
jhdark a52d768
updated tests
jhdark 4d5f9f1
Merge branch 'update_time_dependent_bcs' into fenicsx
jhdark 5aa6b21
Merge branch 'surface_flux_export' into fenicsx
jhdark 100271d
Merge pull request #20 from jhdark/fenicsx
jhdark a550c54
dont use skip_post_processing
jhdark 2356e1a
added docs, only give n
jhdark 22e3bf4
updated docs
jhdark fbfaea8
refactoring
jhdark b5804e8
rename test file
jhdark 74dcd41
Merge branch 'RemDelaporteMathurin:fenicsx' into fenicsx
jhdark 5ffb629
Merge pull request #21 from jhdark/fenicsx
jhdark 6c41bf3
remove time dependent bcs
jhdark 20b3b47
Merge branch 'surface_flux_export' of https://github.com/jhdark/FESTI…
jhdark 1a8ac51
remove from doc
jhdark b7898a8
only export when needed, use surface quantity in tests
jhdark de7440c
test species in list
jhdark c610f43
new tests
jhdark 41e25e2
only create file after species matches
jhdark 62f653d
create file as method
jhdark 6233d38
not needed
jhdark f385a71
call create file
jhdark 1e5c3f5
not accepting ints for now
jhdark 5eef473
update global D in post processing
jhdark 2414d62
surface instead of surface subdomain
jhdark 9852021
updated doc strings
jhdark 8ddc161
use temperature_fenics
jhdark e1abfab
test defining D_global
jhdark 8248d78
test surface setter
jhdark b003bde
test global D with same species
jhdark 3878324
test post processing
jhdark bda7ad8
Apply suggestions from code review
jhdark 52da3d0
fixes
jhdark 96d47e0
new test and doc strings
jhdark cf41ff4
Apply suggestions from code review
jhdark e0d568a
changes from reveiw
jhdark 4b20b05
test new materials methods
jhdark b1106db
Merge branch 'surface_flux_export' of https://github.com/jhdark/FESTI…
jhdark ee155e9
export one first write
jhdark 849de04
update test
jhdark 3f81828
updated docs
jhdark File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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