Conversation
Information like perpendicular J, Bxyz and g_22 are only known to the grid generator, but are needed for more correct parallel derivatives
_[A-Z].* is preserved for compilers, thus use _[a-z].*
At this time the parallel transform is not yet set, so isFci() return false.
| if (!_jxz_ylow.has_value()) { | ||
| _compute_Jxz_cell_faces(); | ||
| } | ||
| return *_jxz_ylow; |
There was a problem hiding this comment.
warning: unchecked access to optional value [bugprone-unchecked-optional-access]
return *_jxz_ylow;
^| if (!_jxz_yhigh.has_value()) { | ||
| _compute_Jxz_cell_faces(); | ||
| } | ||
| return *_jxz_yhigh; |
There was a problem hiding this comment.
warning: unchecked access to optional value [bugprone-unchecked-optional-access]
return *_jxz_yhigh;
^| if (!_jxz_centre.has_value()) { | ||
| _compute_Jxz_cell_faces(); | ||
| } | ||
| return *_jxz_centre; |
There was a problem hiding this comment.
warning: unchecked access to optional value [bugprone-unchecked-optional-access]
return *_jxz_centre;
^| if (!_jxz_ylow.has_value()) { | ||
| _compute_Jxz_cell_faces(); | ||
| } | ||
| return *_jxz_ylow; |
There was a problem hiding this comment.
warning: unchecked access to optional value [bugprone-unchecked-optional-access]
return *_jxz_ylow;
^| if (!_jxz_yhigh.has_value()) { | ||
| _compute_Jxz_cell_faces(); | ||
| } | ||
| return *_jxz_yhigh; |
There was a problem hiding this comment.
warning: unchecked access to optional value [bugprone-unchecked-optional-access]
return *_jxz_yhigh;
^| } | ||
|
|
||
| private: | ||
| mutable std::optional<FieldMetric> _g_22_ylow, _g_22_yhigh; |
There was a problem hiding this comment.
warning: no header providing "std::optional" is directly included [misc-include-cleaner]
include/bout/coordinates.hxx:40:
+ #include <optional>| const Coordinates::FieldMetric& Coordinates::invSg() const { | ||
| if (invSgCache == nullptr) { | ||
| auto ptr = std::make_unique<FieldMetric>(); | ||
| auto ptr = std::make_unique<Coordinates::FieldMetric>(); |
There was a problem hiding this comment.
warning: no header providing "std::make_unique" is directly included [misc-include-cleaner]
auto ptr = std::make_unique<Coordinates::FieldMetric>();
^| if (_g_22_ylow.has_value()) { | ||
| return *_g_22_ylow; | ||
| } | ||
| _g_22_ylow.emplace(emptyFrom(g_22)); |
There was a problem hiding this comment.
warning: no header providing "emptyFrom" is directly included [misc-include-cleaner]
_g_22_ylow.emplace(emptyFrom(g_22));
^
src/mesh/coordinates.cxx
Outdated
| } | ||
| _g_22_ylow.emplace(emptyFrom(g_22)); | ||
| //_g_22_ylow->setLocation(CELL_YLOW); | ||
| auto mesh = Bxy.getMesh(); |
There was a problem hiding this comment.
warning: 'auto mesh' can be declared as 'auto *mesh' [readability-qualified-auto]
| auto mesh = Bxy.getMesh(); | |
| auto *mesh = Bxy.getMesh(); |
|
@dschwoerer excellent work, this has been on my wishlist for a very long time. The amount of places we calculate the areas and volumes is considerable, and so is the number of potential mistakes this generates. I have some questions on what is actually being calculated here. I see there are areas for each side of X, Y and Z. What about parallel areas? What is Jxz? Is that just J? |
ZedThree
left a comment
There was a problem hiding this comment.
Looks great, thanks @dschwoerer! A couple of suggestions:
| const FieldMetric& Jxz_ylow() const { | ||
| if (!_jxz_ylow.has_value()) { | ||
| _compute_Jxz_cell_faces(); | ||
| } | ||
| return *_jxz_ylow; |
There was a problem hiding this comment.
I think this clang-tidy check is unfortunately not clever enough. If _compute_Jxz_cell_faces() returns the computed value, this can actually just be
| const FieldMetric& Jxz_ylow() const { | |
| if (!_jxz_ylow.has_value()) { | |
| _compute_Jxz_cell_faces(); | |
| } | |
| return *_jxz_ylow; | |
| const FieldMetric& Jxz_ylow() const { | |
| return _jxz_low.value_or(_compute_Jxz_cell_faces()); |
There was a problem hiding this comment.
Unfortunately _compute_Jxz_cell_faces() computes 3 different quantities.
We could split up the functions to do that, but that would add even more boiler plate code.
| FieldMetric& g_22_ylow(); | ||
| FieldMetric& g_22_yhigh(); |
There was a problem hiding this comment.
Probably don't need these overloads?
There was a problem hiding this comment.
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_22 then, right now they are still needed.
What do you mean by "parallel" areas? Parallel to what? Or for the parallel slices?
No, that is the 2D jacobian in the x-z plane. Probably not needed anymore, we should use the areas directly. |
| // metrics. | ||
| auto* mesh = Bxy.getMesh(); | ||
| ASSERT0(mesh->xstart > 0); | ||
| BOUT_FOR(i, _jxz_centre->getRegion("RGN_NOX")) { |
There was a problem hiding this comment.
warning: unchecked access to optional value [bugprone-unchecked-optional-access]
BOUT_FOR(i, _jxz_centre->getRegion("RGN_NOX")) {
^|
|
||
| void Coordinates::_compute_cell_area_y() const { | ||
| Jxz(); | ||
| if (_jxz_centre->isFci()) { |
There was a problem hiding this comment.
warning: unchecked access to optional value [bugprone-unchecked-optional-access]
if (_jxz_centre->isFci()) {
^| ASSERT2(isUniform(dx, false, "RGN_ALL")); | ||
| ASSERT3(isUniform(dz, true, "RGN_ALL")); | ||
| ASSERT2(isUniform(dz, false, "RGN_ALL")); | ||
| _cell_area_ylow.emplace(*_jxz_ylow * dx * dz); |
There was a problem hiding this comment.
warning: unchecked access to optional value [bugprone-unchecked-optional-access]
_cell_area_ylow.emplace(*_jxz_ylow * dx * dz);
^| ASSERT3(isUniform(dz, true, "RGN_ALL")); | ||
| ASSERT2(isUniform(dz, false, "RGN_ALL")); | ||
| _cell_area_ylow.emplace(*_jxz_ylow * dx * dz); | ||
| _cell_area_yhigh.emplace(*_jxz_yhigh * dx * dz); |
There was a problem hiding this comment.
warning: unchecked access to optional value [bugprone-unchecked-optional-access]
_cell_area_yhigh.emplace(*_jxz_yhigh * dx * dz);
^| // metrics. | ||
| auto* mesh = Bxy.getMesh(); | ||
| ASSERT0(mesh->ystart > 0); | ||
| BOUT_FOR(i, _jxz_centre->getRegion("RGN_NOY")) { |
There was a problem hiding this comment.
warning: unchecked access to optional value [bugprone-unchecked-optional-access]
BOUT_FOR(i, _jxz_centre->getRegion("RGN_NOY")) {
^| // We cannot setLocation, as that would trigger the computation of staggered | ||
| // metrics. | ||
| //ASSERT0(mesh->zstart > 0); | ||
| BOUT_FOR(i, _jxz_centre->getRegion("RGN_NOZ")) { |
There was a problem hiding this comment.
warning: unchecked access to optional value [bugprone-unchecked-optional-access]
BOUT_FOR(i, _jxz_centre->getRegion("RGN_NOZ")) {
^
They should make code more readable, and also potentially faster, as now cell_areas at the cell faces can be requested from the coordinates.
This should make the hermes-3 FA operator much more readable, and at the same time also FCI compatible, as the cell areas can be done correctly once for FCI, and then used transparently in user codes. @mikekryjak
Todo:
use in FA operators(needs FA operators from hermes-3)