Skip to content

Total volume quantity#703

Merged
RemDelaporteMathurin merged 15 commits into
festim-dev:fenicsxfrom
RemDelaporteMathurin:total_volume
Mar 7, 2024
Merged

Total volume quantity#703
RemDelaporteMathurin merged 15 commits into
festim-dev:fenicsxfrom
RemDelaporteMathurin:total_volume

Conversation

@RemDelaporteMathurin
Copy link
Copy Markdown
Collaborator

@RemDelaporteMathurin RemDelaporteMathurin commented Mar 5, 2024

Proposed changes

This PR adds the total volume quantity in exports

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)

@codecov
Copy link
Copy Markdown

codecov Bot commented Mar 5, 2024

Codecov Report

Attention: Patch coverage is 98.21429% with 1 lines in your changes are missing coverage. Please review.

Project coverage is 99.05%. Comparing base (36ff1fb) to head (0616381).

Files Patch % Lines
festim/hydrogen_transport_problem.py 80.00% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           fenicsx     #703      +/-   ##
===========================================
- Coverage    99.10%   99.05%   -0.05%     
===========================================
  Files           24       26       +2     
  Lines         1112     1168      +56     
===========================================
+ Hits          1102     1157      +55     
- Misses          10       11       +1     

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

@RemDelaporteMathurin RemDelaporteMathurin added enhancement New feature or request fenicsx Issue that is related to the fenicsx support labels Mar 5, 2024
@RemDelaporteMathurin RemDelaporteMathurin marked this pull request as ready for review March 5, 2024 14:55
Copy link
Copy Markdown
Collaborator

@jhdark jhdark left a comment

Choose a reason for hiding this comment

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

There are some small copy-paste errors, but there is a larger bug at hand with the export file writing, appending a previous file of the same name rather than overwriting it.

Comment thread test/test_total_volume.py Outdated
Comment thread festim/exports/volume_quantity.py Outdated
Comment thread festim/exports/volume_quantity.py Outdated
Comment thread festim/exports/volume_quantity.py Outdated
Comment on lines +56 to +70
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 = "Total volume {}: {}".format(self.volume.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])
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think we messed this up the previous time with surface quantity. In testing, I realised that when re-running scripts, instead of creating a new export file, it appends to a previous one if it exists. I'm not sure if we should fix this now or in another PR.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Let's fix it in another PR, it's as simple as changing mode="a" to mode="w"


# if filename given write export data to file
if export.filename is not None:
export.write(t=float(self.t))
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Could test this

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

So I think this is gonna be refactored when we start adding more derived quantities anyway, which is why I didn't bother testing it here

RemDelaporteMathurin and others added 2 commits March 6, 2024 13:25
Co-authored-by: James Dark <65899899+jhdark@users.noreply.github.com>
@RemDelaporteMathurin
Copy link
Copy Markdown
Collaborator Author

@jhdark I added the suggestions thanks for spotting those errors.
Since this is likely gonna be refactored in the near future, I didn't bother testing all the code duplication.

I also opened an issue to track the bug you found for appending to the files instead of overwriting.

@jhdark
Copy link
Copy Markdown
Collaborator

jhdark commented Mar 7, 2024

Just needs a rebase with the new hot fix and then should be good to go

@RemDelaporteMathurin RemDelaporteMathurin merged commit be788e4 into festim-dev:fenicsx Mar 7, 2024
@RemDelaporteMathurin RemDelaporteMathurin deleted the total_volume branch March 7, 2024 13:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request fenicsx Issue that is related to the fenicsx support

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants