-
Notifications
You must be signed in to change notification settings - Fork 108
Add cell volume and areas #3326
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
Changes from 15 commits
3f521d0
3065f88
1c0e385
5c28542
078322d
7547d9e
01d776b
13fdb8a
db66e35
cca09ac
a0d4954
aae5b5d
63ab8b4
6b66188
4c0c495
fd12c54
1b83ae8
f9cf8d2
7ad4d05
6751afd
042cf65
cc172bc
1258b6f
46536c6
48a4a68
afc091b
90c3d49
1334f5b
99a212e
68b1dc8
22ab659
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -3,16 +3,16 @@ | |||||||||||||||
| * | ||||||||||||||||
| * ChangeLog | ||||||||||||||||
| * ========= | ||||||||||||||||
| * | ||||||||||||||||
| * | ||||||||||||||||
| * 2014-11-10 Ben Dudson <bd512@york.ac.uk> | ||||||||||||||||
| * * Created by separating metric from Mesh | ||||||||||||||||
| * | ||||||||||||||||
| * | ||||||||||||||||
| * | ||||||||||||||||
| ************************************************************************** | ||||||||||||||||
| * Copyright 2014-2025 BOUT++ contributors | ||||||||||||||||
| * | ||||||||||||||||
| * Contact: Ben Dudson, dudson2@llnl.gov | ||||||||||||||||
| * | ||||||||||||||||
| * | ||||||||||||||||
| * This file is part of BOUT++. | ||||||||||||||||
| * | ||||||||||||||||
| * BOUT++ is free software: you can redistribute it and/or modify | ||||||||||||||||
|
|
@@ -38,6 +38,7 @@ | |||||||||||||||
| #include <bout/field2d.hxx> | ||||||||||||||||
| #include <bout/field3d.hxx> | ||||||||||||||||
| #include <bout/paralleltransform.hxx> | ||||||||||||||||
| #include <optional> | ||||||||||||||||
|
|
||||||||||||||||
| class Mesh; | ||||||||||||||||
|
|
||||||||||||||||
|
|
@@ -102,6 +103,149 @@ public: | |||||||||||||||
| /// Covariant metric tensor | ||||||||||||||||
| FieldMetric g_11, g_22, g_33, g_12, g_13, g_23; | ||||||||||||||||
|
|
||||||||||||||||
| /// get g_22 at the cell faces; | ||||||||||||||||
| const FieldMetric& g_22_ylow() const; | ||||||||||||||||
| const FieldMetric& g_22_yhigh() const; | ||||||||||||||||
| FieldMetric& g_22_ylow(); | ||||||||||||||||
| FieldMetric& g_22_yhigh(); | ||||||||||||||||
| /// get Jxz at the cell faces or cell centre | ||||||||||||||||
| const FieldMetric& Jxz_ylow() const { | ||||||||||||||||
| if (!_jxz_ylow.has_value()) { | ||||||||||||||||
| _compute_Jxz_cell_faces(); | ||||||||||||||||
| } | ||||||||||||||||
| return *_jxz_ylow; | ||||||||||||||||
|
dschwoerer marked this conversation as resolved.
Outdated
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this
Suggested change
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unfortunately
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What if the struct _compute_result {
FieldMetric low;
FieldMetric high;
};then this could be: return _jxz_low.value_or(_compute_Jxz_cell_faces().low);
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I thought that would work, but that would cause the compute function to be always be called. But this should work: The advantage of the initial version is, that it fails if the compute functions do not set the value. With this version that will always return a valid FieldMetric, but it might be recomputed every time. Imho, I find this worse then having a segfault in my code ...
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added an
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, yes, we need C++23's Yeah, the |
||||||||||||||||
| } | ||||||||||||||||
| const FieldMetric& Jxz_yhigh() const { | ||||||||||||||||
| if (!_jxz_yhigh.has_value()) { | ||||||||||||||||
| _compute_Jxz_cell_faces(); | ||||||||||||||||
| } | ||||||||||||||||
| return *_jxz_yhigh; | ||||||||||||||||
|
dschwoerer marked this conversation as resolved.
Outdated
|
||||||||||||||||
| } | ||||||||||||||||
| const FieldMetric& Jxz() const { | ||||||||||||||||
| if (!_jxz_centre.has_value()) { | ||||||||||||||||
| _compute_Jxz_cell_faces(); | ||||||||||||||||
| } | ||||||||||||||||
| return *_jxz_centre; | ||||||||||||||||
|
dschwoerer marked this conversation as resolved.
Outdated
|
||||||||||||||||
| } | ||||||||||||||||
| FieldMetric& Jxz_ylow() { | ||||||||||||||||
| if (!_jxz_ylow.has_value()) { | ||||||||||||||||
| _compute_Jxz_cell_faces(); | ||||||||||||||||
| } | ||||||||||||||||
| return *_jxz_ylow; | ||||||||||||||||
|
dschwoerer marked this conversation as resolved.
Outdated
|
||||||||||||||||
| } | ||||||||||||||||
| FieldMetric& Jxz_yhigh() { | ||||||||||||||||
| if (!_jxz_yhigh.has_value()) { | ||||||||||||||||
| _compute_Jxz_cell_faces(); | ||||||||||||||||
| } | ||||||||||||||||
| return *_jxz_yhigh; | ||||||||||||||||
|
dschwoerer marked this conversation as resolved.
Outdated
|
||||||||||||||||
| } | ||||||||||||||||
| FieldMetric& Jxz() { | ||||||||||||||||
| if (!_jxz_centre.has_value()) { | ||||||||||||||||
| _compute_Jxz_cell_faces(); | ||||||||||||||||
| } | ||||||||||||||||
| return *_jxz_centre; | ||||||||||||||||
|
dschwoerer marked this conversation as resolved.
Outdated
|
||||||||||||||||
| } | ||||||||||||||||
| // Cell Areas | ||||||||||||||||
| const FieldMetric& cell_area_xlow() const { | ||||||||||||||||
| if (!_cell_area_xlow.has_value()) { | ||||||||||||||||
| _compute_cell_area_x(); | ||||||||||||||||
| } | ||||||||||||||||
| return *_cell_area_xlow; | ||||||||||||||||
|
dschwoerer marked this conversation as resolved.
|
||||||||||||||||
| } | ||||||||||||||||
| const FieldMetric& cell_area_xhigh() const { | ||||||||||||||||
| if (!_cell_area_xhigh.has_value()) { | ||||||||||||||||
| _compute_cell_area_x(); | ||||||||||||||||
| } | ||||||||||||||||
| return *_cell_area_xhigh; | ||||||||||||||||
|
dschwoerer marked this conversation as resolved.
|
||||||||||||||||
| } | ||||||||||||||||
| const FieldMetric& cell_area_ylow() const { | ||||||||||||||||
| if (!_cell_area_ylow.has_value()) { | ||||||||||||||||
| _compute_cell_area_y(); | ||||||||||||||||
| } | ||||||||||||||||
| return *_cell_area_ylow; | ||||||||||||||||
|
dschwoerer marked this conversation as resolved.
|
||||||||||||||||
| } | ||||||||||||||||
| const FieldMetric& cell_area_yhigh() const { | ||||||||||||||||
| if (!_cell_area_yhigh.has_value()) { | ||||||||||||||||
| _compute_cell_area_y(); | ||||||||||||||||
| } | ||||||||||||||||
| return *_cell_area_yhigh; | ||||||||||||||||
|
dschwoerer marked this conversation as resolved.
|
||||||||||||||||
| } | ||||||||||||||||
| const FieldMetric& cell_area_zlow() const { | ||||||||||||||||
| if (!_cell_area_zlow.has_value()) { | ||||||||||||||||
| _compute_cell_area_z(); | ||||||||||||||||
| } | ||||||||||||||||
| return *_cell_area_zlow; | ||||||||||||||||
|
dschwoerer marked this conversation as resolved.
|
||||||||||||||||
| } | ||||||||||||||||
| const FieldMetric& cell_area_zhigh() const { | ||||||||||||||||
| if (!_cell_area_zhigh.has_value()) { | ||||||||||||||||
| _compute_cell_area_z(); | ||||||||||||||||
| } | ||||||||||||||||
| return *_cell_area_zhigh; | ||||||||||||||||
|
dschwoerer marked this conversation as resolved.
|
||||||||||||||||
| } | ||||||||||||||||
| FieldMetric& cell_area_xlow() { | ||||||||||||||||
| if (!_cell_area_xlow.has_value()) { | ||||||||||||||||
| _compute_cell_area_x(); | ||||||||||||||||
| } | ||||||||||||||||
| return *_cell_area_xlow; | ||||||||||||||||
|
dschwoerer marked this conversation as resolved.
|
||||||||||||||||
| } | ||||||||||||||||
| FieldMetric& cell_area_xhigh() { | ||||||||||||||||
| if (!_cell_area_xhigh.has_value()) { | ||||||||||||||||
| _compute_cell_area_x(); | ||||||||||||||||
| } | ||||||||||||||||
| return *_cell_area_xhigh; | ||||||||||||||||
|
dschwoerer marked this conversation as resolved.
|
||||||||||||||||
| } | ||||||||||||||||
| FieldMetric& cell_area_ylow() { | ||||||||||||||||
| if (!_cell_area_ylow.has_value()) { | ||||||||||||||||
| _compute_cell_area_y(); | ||||||||||||||||
| } | ||||||||||||||||
| return *_cell_area_ylow; | ||||||||||||||||
|
dschwoerer marked this conversation as resolved.
|
||||||||||||||||
| } | ||||||||||||||||
| FieldMetric& cell_area_yhigh() { | ||||||||||||||||
| if (!_cell_area_yhigh.has_value()) { | ||||||||||||||||
| _compute_cell_area_y(); | ||||||||||||||||
| } | ||||||||||||||||
| return *_cell_area_yhigh; | ||||||||||||||||
|
dschwoerer marked this conversation as resolved.
|
||||||||||||||||
| } | ||||||||||||||||
| FieldMetric& cell_area_zlow() { | ||||||||||||||||
| if (!_cell_area_zlow.has_value()) { | ||||||||||||||||
| _compute_cell_area_z(); | ||||||||||||||||
| } | ||||||||||||||||
| return *_cell_area_zlow; | ||||||||||||||||
|
dschwoerer marked this conversation as resolved.
|
||||||||||||||||
| } | ||||||||||||||||
| FieldMetric& cell_area_zhigh() { | ||||||||||||||||
| if (!_cell_area_zhigh.has_value()) { | ||||||||||||||||
| _compute_cell_area_z(); | ||||||||||||||||
| } | ||||||||||||||||
| return *_cell_area_zhigh; | ||||||||||||||||
|
dschwoerer marked this conversation as resolved.
|
||||||||||||||||
| } | ||||||||||||||||
| // Cell Volume | ||||||||||||||||
| const FieldMetric& cell_volume() const { | ||||||||||||||||
| if (!_cell_volume.has_value()) { | ||||||||||||||||
| _compute_cell_volume(); | ||||||||||||||||
| } | ||||||||||||||||
| return *_cell_volume; | ||||||||||||||||
|
dschwoerer marked this conversation as resolved.
|
||||||||||||||||
| } | ||||||||||||||||
| FieldMetric& cell_volume() { | ||||||||||||||||
| if (!_cell_volume.has_value()) { | ||||||||||||||||
| _compute_cell_volume(); | ||||||||||||||||
| } | ||||||||||||||||
| return *_cell_volume; | ||||||||||||||||
|
dschwoerer marked this conversation as resolved.
|
||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| private: | ||||||||||||||||
| mutable std::optional<FieldMetric> _g_22_ylow, _g_22_yhigh; | ||||||||||||||||
|
dschwoerer marked this conversation as resolved.
|
||||||||||||||||
| mutable std::optional<FieldMetric> _jxz_ylow, _jxz_yhigh, _jxz_centre; | ||||||||||||||||
| mutable std::optional<FieldMetric> _cell_area_xlow, _cell_area_xhigh; | ||||||||||||||||
| mutable std::optional<FieldMetric> _cell_area_ylow, _cell_area_yhigh; | ||||||||||||||||
| mutable std::optional<FieldMetric> _cell_area_zlow, _cell_area_zhigh; | ||||||||||||||||
| mutable std::optional<FieldMetric> _cell_volume; | ||||||||||||||||
| void _compute_Jxz_cell_faces() const; | ||||||||||||||||
| void _compute_cell_area_x() const; | ||||||||||||||||
| void _compute_cell_area_y() const; | ||||||||||||||||
| void _compute_cell_area_z() const; | ||||||||||||||||
| void _compute_cell_volume() const; | ||||||||||||||||
|
|
||||||||||||||||
| public: | ||||||||||||||||
| /// Christoffel symbol of the second kind (connection coefficients) | ||||||||||||||||
| FieldMetric G1_11, G1_22, G1_33, G1_12, G1_13, G1_23; | ||||||||||||||||
| FieldMetric G2_11, G2_22, G2_33, G2_12, G2_13, G2_23; | ||||||||||||||||
|
|
@@ -256,10 +400,10 @@ private: | |||||||||||||||
| class TokamakCoordinates : public Coordinates { | ||||||||||||||||
| public: | ||||||||||||||||
| TokamakCoordinates(Mesh *mesh) : Coordinates(mesh) { | ||||||||||||||||
|
|
||||||||||||||||
| } | ||||||||||||||||
| private: | ||||||||||||||||
|
|
||||||||||||||||
| }; | ||||||||||||||||
| */ | ||||||||||||||||
|
|
||||||||||||||||
|
|
||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably don't need these overloads?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We probably want to add the cell length, both in the cell centre, as well as at the faces, i.e. the distance between the cell centres.
That would replace
g_22then, right now they are still needed.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I meant the non-
constones!Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need them for normalization. But I am starting to be worried, that that might be a bad idea.
Right now:
gives the correct thing for FCI, but wrong for FA.
or
works for both
and
works only for FA.
So we probably want to remove write access to the fields, and let BOUT++ handle all of the normalisation. I think that is part of github.com//pull/2873 or #3046 - but that is 900 commits behind next and with its 500 comits has probably more merge conflicts that what I can deal with right now :-(
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#3046 is into #2873 by the way.
We (@tomc271 and myself) can take care of bringing those PRs up-to-date -- can you review them? Starting with #3046
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was waiting for the wrappers that make
coords->dy[i]working again, so not all the code needs to be changed. I thought you still wanted to do that?