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

TXTExport refactoring #883

Merged

Conversation

KulaginVladimir
Copy link
Collaborator

@KulaginVladimir KulaginVladimir commented Sep 9, 2024

Proposed changes

This PR removes deprecated class TXTExports and fixes issues #819 and #863.

To-do list:

  • Add possibility to write data at the last export time
  • Define function space depending on the chemical potential conservation flag
  • Add filter method to remove duplicates if DG is used
  • Tests

Types of changes

What types of changes does your code introduce to FESTIM?

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Code refactoring
  • Documentation Update (if none of the other choices apply)
  • New tests

Checklist

  • Black formatted
  • Unit tests pass locally with my changes
  • I have added tests that prove my fix is effective or that my feature works
  • I have added necessary documentation (if appropriate)

Copy link

codecov bot commented Sep 9, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.27%. Comparing base (12628bd) to head (468611d).
Report is 66 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #883      +/-   ##
==========================================
- Coverage   99.56%   99.27%   -0.30%     
==========================================
  Files          61       60       -1     
  Lines        2750     2753       +3     
==========================================
- Hits         2738     2733       -5     
- Misses         12       20       +8     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@KulaginVladimir KulaginVladimir marked this pull request as ready for review October 2, 2024 20:43
Copy link
Collaborator

@RemDelaporteMathurin RemDelaporteMathurin left a 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 Show resolved Hide resolved
festim/exports/txt_export.py Outdated Show resolved Hide resolved
festim/exports/txt_export.py Outdated Show resolved Hide resolved
festim/generic_simulation.py Outdated Show resolved Hide resolved
Copy link
Collaborator Author

@KulaginVladimir KulaginVladimir left a 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 Show resolved Hide resolved
festim/exports/txt_export.py Outdated Show resolved Hide resolved
Copy link
Collaborator

@RemDelaporteMathurin RemDelaporteMathurin left a 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...

🚀

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
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
# 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 Show resolved Hide resolved
festim/exports/txt_export.py Outdated Show resolved Hide resolved
festim/exports/txt_export.py Outdated Show resolved Hide resolved
festim/generic_simulation.py Outdated Show resolved Hide resolved
festim/exports/txt_export.py Outdated Show resolved Hide resolved
Copy link
Collaborator

@RemDelaporteMathurin RemDelaporteMathurin left a comment

Choose a reason for hiding this comment

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

Hi @KulaginVladimir very sorry for being so late on this... This looks good! A couple of very minor comments, feel free to merge!

Comment on lines 120 to 123
else:
if np.isclose(current_time, self.times[-1], atol=0):
# write at final time if exports at specific times
return True
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
else:
if np.isclose(current_time, self.times[-1], atol=0):
# write at final time if exports at specific times
return True
elif np.isclose(current_time, self.times[-1], atol=0):
# write at final time if exports at specific times
return True

The array is then used to obtain indices of sorted elements for the data export.

.. note::
If DG1 is used and filter flag is True, the duplicated vertices in the array are filtered except those near interfaces,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
If DG1 is used and filter flag is True, the duplicated vertices in the array are filtered except those near interfaces,
If DG1 is used and ``filter`` flag is True, the duplicated vertices in the array are filtered except those near interfaces,

Comment on lines 152 to 153
print(my_export._unique_indices)
assert len(my_export.data) == export_len
Copy link
Collaborator

Choose a reason for hiding this comment

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

Instead of a print you can do the following:

Suggested change
print(my_export._unique_indices)
assert len(my_export.data) == export_len
assert len(my_export.data) == export_len, f"Wrong export length. Unique indices: {my_export._unique_indices}"

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Didn't know about such a functionality, but I forgot to delete this print-statement

@KulaginVladimir KulaginVladimir merged commit 35096f1 into festim-dev:main Dec 21, 2024
5 of 6 checks passed
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.

TXT export: store data in memory and write only at last timestep TXTExport produces duplicates
2 participants