Skip to content

3D FEM#5009

Merged
rtimms merged 77 commits intopybamm-team:developfrom
Rishab87:gsoc
Jul 12, 2025
Merged

3D FEM#5009
rtimms merged 77 commits intopybamm-team:developfrom
Rishab87:gsoc

Conversation

@Rishab87
Copy link
Member

@Rishab87 Rishab87 commented May 9, 2025

Description

This PR will add a support for 3D FEM, 3D meshing along with a mesh generator with support for prismatic and cylindrical geometry

Fixes # (issue)

Type of change

Please add a line in the relevant section of CHANGELOG.md to document the change (include PR #)

Important checks:

Please confirm the following before marking the PR as ready for review:

  • No style issues: nox -s pre-commit
  • All tests pass: nox -s tests
  • The documentation builds: nox -s doctests
  • Code is commented for hard-to-understand areas
  • Tests added that prove fix is effective or that feature works

Copy link
Contributor

@rtimms rtimms left a comment

Choose a reason for hiding this comment

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

Looking good so far. Next steps are:

  1. Add an example of solving the 3D heat eqn in a jelly and prismatic domain, with different boundary conditions and a prescribed heat souce
  2. Add tests for the 3d finite volume methods (make sure things are discredited as expected, check simple problems are solved correctly). To help with this you can use the "method of manufactured solutions".

Once the mesh and method are tested for simple general equations we can start on the battery-specific parts of the project in a separate PR

@Rishab87 Rishab87 changed the title [GSOC 2025] Adding 3D Thermal Model with Two Way Coupling [GSOC 2025] 3D FVM May 27, 2025
@Rishab87
Copy link
Member Author

Rishab87 commented Jun 9, 2025

I am facing few issue with BCs, few tests are failing mostly due to shape mismatches, I saw @aabills was implementing 2D FVM, I was following his pattern. So it would be great if Alec can have a look at this PR specifically around ghost nodes and neumann values and shift. And overall too if you can review the PR to see if there is any potential issues present due to which tests are failing.

@aabills
Copy link
Contributor

aabills commented Jun 10, 2025

Hey Rishab, yeah Ghost nodes are a real pain. Let me wrap mine up this week and I'll get back to you ASAP

@Rishab87
Copy link
Member Author

thanks @aabills, in meantime I'll try to fix these errors myself.

z: {"min": pybamm.Scalar(0), "max": pybamm.Scalar(1)},
}
}
var_pts = {x: 5, y: 5, z: 5}
Copy link
Contributor

Choose a reason for hiding this comment

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

do we need var_pts here since the mesh generator decides on the number of nodes based on h?

it would be nice if you could grab the var_pts after the mesh is created so you know how many nodes you have in x/y/z

Copy link
Member Author

@Rishab87 Rishab87 Jun 27, 2025

Choose a reason for hiding this comment

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

Yeah we can grab that with .npts, we cant remove var_pts here since it is a compulsory argument in pybamm.Mesh

Copy link
Contributor

Choose a reason for hiding this comment

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

OK, I see. We may want to pass var_pts anyway since other domains may not be in 3D. Can you add a warning if the submesh type is 3D FEM saying that var_pts will be ignored and the mesh will be created to meet the h tolerance. And maybe recommend passing None for spatial variables on a 3D domain

tests/shared.py Outdated
z = pybamm.SpatialVariable("z", ["current collector"])
geometry = {
"current collector": {
x: {"min": pybamm.Scalar(0), "max": pybamm.Scalar(1)},
Copy link
Contributor

Choose a reason for hiding this comment

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

for testing I would make these have different lengths to avoid accidentally covering up errors where an axis gets swapped

Rishab87 and others added 2 commits June 27, 2025 16:58
Co-authored-by: Robert Timms <43040151+rtimms@users.noreply.github.com>
@Rishab87
Copy link
Member Author

@rtimms I've addressed all the reviews can you re-review it again?

@Rishab87 Rishab87 requested a review from rtimms June 27, 2025 12:45
Copy link
Contributor

@rtimms rtimms left a comment

Choose a reason for hiding this comment

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

@Rishab87 thanks this is looking great! just a few minor comments and then we can merge this and pick up some follow on tasks in a separate PR

z: {"min": pybamm.Scalar(0), "max": pybamm.Scalar(1)},
}
}
var_pts = {x: 5, y: 5, z: 5}
Copy link
Contributor

Choose a reason for hiding this comment

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

OK, I see. We may want to pass var_pts anyway since other domains may not be in 3D. Can you add a warning if the submesh type is 3D FEM saying that var_pts will be ignored and the mesh will be created to meet the h tolerance. And maybe recommend passing None for spatial variables on a 3D domain

@Rishab87
Copy link
Member Author

Rishab87 commented Jul 2, 2025

@rtimms I've addressed all reviews, can you please re-review it again?

@Rishab87 Rishab87 requested a review from rtimms July 2, 2025 13:10
@rtimms
Copy link
Contributor

rtimms commented Jul 4, 2025

@Rishab87 thanks for addressing all the comments, looks great! @aabills I'd appreciate a second pair of eyes on this before merging, since you've been working on higher-dimensional models too

@Rishab87
Copy link
Member Author

Rishab87 commented Jul 9, 2025

@aabills any updates on this?

Copy link
Contributor

@rtimms rtimms left a comment

Choose a reason for hiding this comment

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

looks great, thanks for all your work on this @Rishab87 !

@rtimms rtimms enabled auto-merge (squash) July 12, 2025 07:31
@rtimms rtimms merged commit 4a834dd into pybamm-team:develop Jul 12, 2025
22 checks passed
@agriyakhetarpal agriyakhetarpal changed the title [GSOC 2025] 3D FEM 3D FEM Jul 21, 2025
@agriyakhetarpal agriyakhetarpal added the GSoC 2025 Items being done as part of GSoC 2025 label Jul 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

GSoC 2025 Items being done as part of GSoC 2025

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants