-
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
TXTExport
refactoring
#883
base: main
Are you sure you want to change the base?
TXTExport
refactoring
#883
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #883 +/- ##
==========================================
+ Coverage 99.56% 99.59% +0.03%
==========================================
Files 61 60 -1
Lines 2750 2727 -23
==========================================
- Hits 2738 2716 -22
+ Misses 12 11 -1 ☔ View full report in Codecov by Sentry. |
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.
Hi @KulaginVladimir thanks for taking care of this.
I'm wondering about adding more arguments to the write
method.
Could we instead store the information in attributes? For example, instead of calling filter_duplicates
at each write
we could call it once at the beginning of the simulation (if chemical pot is on) then store combined_indx
as an attribute (we would need more explicit variable names ofc).
Then, when we call write
we don't need to pass materials
and chemical_pot
.
If self.combined_indx
is None
then don't do anything to the data, otherwise filter the data with self.data = self.data[self.combined_indx, :]
or something like this.
What do you think?
festim/exports/txt_export.py
Outdated
else: | ||
V = f.FunctionSpace(self.function.function_space().mesh(), "CG", 1) | ||
|
||
solution = f.project(self.function, V) |
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.
Do we need to do this if chemical_pot
is False?
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.
Maybe no. Please check the logic in new attempt
festim/exports/txt_export.py
Outdated
|
||
return data[combined_indx, :] | ||
|
||
def write(self, current_time, final_time, materials, chemical_pot): |
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.
This function now does a lot more than just "write" (it filters the data and has some logic etc).
Plus it seems like a lot of what is done here could be done only once.
For instance, chemical_pot
will always be the same throughout the simulation, the materials will never change either!
Maybe we could put all this in a initialise step instead of doing this at each write?
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.
Maybe we could put all this in a initialise step instead of doing this at each write?
somewhere here?
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.
Yes
festim/exports/txt_export.py
Outdated
if final_time is None or self._first_time: | ||
if final_time is None: |
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.
Just for readability, it would be clearer to keep the steady
variable here but add
if final_time is None or self._first_time: | |
if final_time is None: | |
steady = final_time is None | |
if steady or self._first_time: | |
if steady: |
festim/generic_simulation.py
Outdated
self.materials, | ||
self.settings.chemical_pot, |
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.
I'm always careful when adding parameters like this because if we keep adding them then these functions because very hard to manage...
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.
@RemDelaporteMathurin
I refactored the filtering method according to your suggestions. However, there are several points I'd like to adress. Please, see my comments below.
festim/generic_simulation.py
Outdated
if isinstance(export, festim.TXTExport): | ||
# pre-process data depending on the chemical potential flag, trap element type, | ||
# and material borders | ||
project_to_DG = ( | ||
self.settings.chemical_pot | ||
or self.settings.traps_element_type == "DG" | ||
) | ||
export.initialise_TXTExport( | ||
self.mesh.mesh, | ||
project_to_DG, | ||
self.materials, | ||
) |
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.
- I removed the repeating loop
for export in self.exports
below. I don't think there is a needto iterate through it twice durinig initialisation. - I temporarly added new method
initialise_TXTExport
(formerfilter_duplicates
) that's called once. - Considering this task of FESTIM WS, I assume that we should project fields to
DG
ifsettings.traps_element_type = "DG"
. I added such a check with theproject_to_DG
variable, but it doesn't help and some information is lost due to filtering. For example, here is how the second figure from the task looks like:
since there are borders, the output data near the boundary looks like this:
Details
4.646464646464646964e-01,5.000000000000542899e-01
4.747474747474748069e-01,5.000000000000532907e-01
4.848484848484848619e-01,5.000000000000531797e-01
4.949494949494949725e-01,5.000000000000528466e-01
4.949494949494949725e-01,5.000000000000526246e-01
5.050505050505050830e-01,5.000000000000521805e-01
5.151515151515152491e-01,0.000000000000000000e+00
5.252525252525253041e-01,0.000000000000000000e+00
if there are no material.borders
, then (fig. 4 from the task):
and there are no duplicates in the output file.
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.
There's not much we can do about 3. I'm afraid. That is why I always recommend working with XDMF because there is no alteration of the data.
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.
However, what I showed is the result of filtering. We could filter data only for solute H or I don't know. If it's ok, then I'd maybe add a warning message
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.
This looks good to me! Just some more small comments about documentation, naming...
🚀
festim/exports/txt_export.py
Outdated
x = f.interpolate(f.Expression("x[0]", degree=1), self._V) | ||
x_column = np.transpose([x.vector()[:]]) | ||
|
||
# if chemical_pot is True or trap_element_type is DG, get indices of duplicates near interfaces |
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.
# if chemical_pot is True or trap_element_type is DG, get indices of duplicates near interfaces | |
# if project_to_DG is True, get indices of duplicates near interfaces |
In the scope of this method, there is no such thing as chemica_pot
or trap_element_type
festim/exports/txt_export.py
Outdated
# create a DG1 functionspace | ||
V_DG1 = f.FunctionSpace(self.function.function_space().mesh(), "DG", 1) | ||
if project_to_DG: | ||
self._V = f.FunctionSpace(mesh, "DG", 1) |
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.
I think we need to document this new attribute
festim/generic_simulation.py
Outdated
if isinstance(export, festim.TXTExport): | ||
# pre-process data depending on the chemical potential flag, trap element type, | ||
# and material borders | ||
project_to_DG = ( | ||
self.settings.chemical_pot | ||
or self.settings.traps_element_type == "DG" | ||
) | ||
export.initialise_TXTExport( | ||
self.mesh.mesh, | ||
project_to_DG, | ||
self.materials, | ||
) |
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.
There's not much we can do about 3. I'm afraid. That is why I always recommend working with XDMF because there is no alteration of the data.
festim/exports/txt_export.py
Outdated
return True | ||
return False | ||
|
||
def initialise_TXTExport(self, mesh, project_to_DG=False, materials=None): |
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.
I think we should call this method something else. Maybe just initialise
and then add docstrings to explain what it does
festim/exports/txt_export.py
Outdated
|
||
# if project_to_DG is True, get indices of duplicates near interfaces | ||
# and indices of the first elements from a pair of duplicates otherwise | ||
if project_to_DG: |
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.
I thought a bit about filtering, maybe we should allow users to control whether the data will be filtered or not?
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.
Control is good yeah, we could have a flag that defaults to true but can be deactivated if need be
Proposed changes
This PR removes deprecated class
TXTExports
and fixes issues #819 and #863.To-do list:
DG
is usedTypes of changes
What types of changes does your code introduce to FESTIM?
Checklist