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

Total Volume for Cylindrical and Spherical meshes #882

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

rekomodo
Copy link
Contributor

@rekomodo rekomodo commented Sep 1, 2024

Proposed changes

Implements TotalVolume derived quantities for both Cylindrical and Spherical meshes as per #723 .

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)

Further comments

If this is a relatively large or complex change, kick off the discussion by explaining why you chose the solution you did and what alternatives you considered, etc...

Copy link

codecov bot commented Sep 1, 2024

Codecov Report

Attention: Patch coverage is 96.00000% with 2 lines in your changes missing coverage. Please review.

Project coverage is 99.49%. Comparing base (abe3942) to head (9dfb219).

Files with missing lines Patch % Lines
festim/exports/derived_quantities/total_volume.py 95.91% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #882      +/-   ##
==========================================
- Coverage   99.56%   99.49%   -0.07%     
==========================================
  Files          61       61              
  Lines        2750     2799      +49     
==========================================
+ Hits         2738     2785      +47     
- Misses         12       14       +2     

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

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 @rekomodo thanks for this contribution it will be much needed!

I made a few comments. The expression for spherical is wrong and needs fixing

class TotalVolumeCylindrical(TotalVolume):
"""
Computes the total value of a field in a given volume
int(f r dx)
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
int(f r dx)
int(f r dr)

Copy link
Collaborator

Choose a reason for hiding this comment

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

For these new classes you will need to override the export_unit property.

The units of TotalVolumeCylindrical and TotalVolumeSpherical are always H (since it's a 3D equivalent).

For TotalVolume this property is defined here:

@property
def export_unit(self):
# obtain domain dimension
try:
dim = self.function.function_space().mesh().topology().dim()
except AttributeError:
dim = self.dx._domain._topological_dimension
# TODO we could simply do that all the time
# return unit depending on field and dimension of domain
if self.field == "T":
return f"K m{dim}".replace("1", "")
else:
return f"H m{dim-3}".replace(" m0", "")


@property
def allowed_meshes(self):
return ["spherical"]
Copy link
Collaborator

Choose a reason for hiding this comment

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

This line isn't tested. Could we add a simple test that checks that the only allowed mesh is spherical?

class TotalVolumeSpherical(TotalVolume):
"""
Computes the total value of a field in a given volume
int(f r dx)
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
int(f r dx)
int(f r**2 dx)

Btw, this should include the angular coverages too! Same comment for the Cylindrical version

Comment on lines +183 to +185
(phi_1 - phi_0)
* (theta_1 - theta_0)
* f.assemble(self.function * self.r**2 * self.dx(self.volume))
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is not correct. There should be a cos somewhere (see this).

Consider the expression of the volume element in spherical coordinates (link):
image

az0, az1 = azimuth_range
th0, th1 = polar_range

expected_value = f.assemble((az1 - az0) * (th1 - th0) * c * r**2 * dx(volume))
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is not the expected value, see my comment above

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.

2 participants