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

Custom fenics mesh #677

Merged
merged 13 commits into from
Feb 26, 2024
Merged

Custom fenics mesh #677

merged 13 commits into from
Feb 26, 2024

Conversation

jhdark
Copy link
Collaborator

@jhdark jhdark commented Jan 11, 2024

Proposed changes

With this users will be able to give their own fenics mesh with custom mesh tags.

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...

@jhdark jhdark added enhancement New feature or request fenicsx Issue that is related to the fenicsx support labels Jan 11, 2024
Copy link

codecov bot commented Jan 11, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.09%. Comparing base (b7aca0d) to head (e6d94ea).

Additional details and impacted files
@@             Coverage Diff             @@
##           fenicsx     #677      +/-   ##
===========================================
+ Coverage    99.07%   99.09%   +0.02%     
===========================================
  Files           24       24              
  Lines         1076     1107      +31     
===========================================
+ Hits          1066     1097      +31     
  Misses          10       10              

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

@jhdark jhdark marked this pull request as ready for review January 19, 2024 17:22
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.

I don't understand the need for a new class here?
The mesh setter/getter could go in F.Mesh

The only thing that this class does is temporarily store the meshtags that are then passed to HTransportProblem.

We could save us the trouble of maintaining/documenting another class (although small) and instead allow users to simply set the mesh, facet_meshtags and volume_meshtags attributes of HTransportProblem

If users want to provide their own mesh and mesh_tags, could they not simply do the following :

import festim as F

# make a fenics mesh and meshtags
# ...

my_problem = F.HTransportProblem()

my_problem.mesh = F.Mesh(custom_mesh)
my_problem.facet_meshtags = custom_facet_meshtags
my_problem.volume_meshtags = cutsom_volume_meshtags

....

Comment on lines 62 to 63
self.surface_meshtags = surface_meshtags
self.volume_meshtags = volume_meshtags
Copy link
Collaborator

Choose a reason for hiding this comment

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

In HTransportProblem the meshtags are facet_meshtags and volume_meshtags, I would keep the same naming

Comment on lines 908 to 914
my_mesh = F.CustomFenicsMesh(
mesh=mesh_1D,
surface_meshtags=my_surface_meshtags,
volume_meshtags=my_volume_meshtags,
)

my_model = F.HydrogenTransportProblem(mesh=my_mesh)
Copy link
Collaborator

Choose a reason for hiding this comment

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

The usage could simply be:

Suggested change
my_mesh = F.CustomFenicsMesh(
mesh=mesh_1D,
surface_meshtags=my_surface_meshtags,
volume_meshtags=my_volume_meshtags,
)
my_model = F.HydrogenTransportProblem(mesh=my_mesh)
my_mesh = F.Mesh(mesh_1D)
my_model = F.HydrogenTransportProblem(mesh=my_mesh)
my_model.facet_meshtags = my_surface_meshtags
my_model.volume_meshtags = my_volume_meshtags

Copy link
Collaborator

Choose a reason for hiding this comment

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

We could even simplify things further by doing:

    my_mesh = mesh_1D
    my_model = F.HydrogenTransportProblem(mesh=my_mesh)
    
    my_model.facet_meshtags = my_surface_meshtags
    my_model.volume_meshtags = my_volume_meshtags

Then, in HTransportProblem make the setter of the mesh attribute:

def mesh(self, value):
    if isinstance(value, dolfinx.mesh.Mesh):
        self._mesh = F.Mesh(value)
    else:
        ....

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.

Just a couple of final small comments and we're good to go!

Co-authored-by: Rémi Delaporte-Mathurin <[email protected]>
@jhdark jhdark merged commit bb61acd into festim-dev:fenicsx Feb 26, 2024
7 checks passed
@jhdark jhdark deleted the custom_fenics_mesh branch February 26, 2024 13:49
@KulaginVladimir
Copy link
Collaborator

Is this PR linked to #647?

@RemDelaporteMathurin
Copy link
Collaborator

Is this PR linked to #647?

Yes!

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.

Users should be allowed to provide their own dolfinx mesh
3 participants