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

3D metrics #2025

Merged
merged 347 commits into from
Jul 7, 2021
Merged

3D metrics #2025

merged 347 commits into from
Jul 7, 2021

Conversation

dschwoerer
Copy link
Contributor

@dschwoerer dschwoerer commented Apr 29, 2020

Fixes #1668


(copied from comment below for better visibility)

I tried to look at all open comments, and I think this is the list of stuff that needs to be done (feel free to edit)

I've spotted a couple of places that could have useful unit tests, so I will have a stab at implementing those.

dschwoerer and others added 30 commits March 17, 2020 18:04
Allows to compile and run all tests by running:
make -j 4 build-check-all && make check-all
The shift-transform in staggered location requieres dz.
To calculate the staggered dz in y direction, the parallel transform is
requiered. Thus we special handel the case if dz is constant, and we can
do a trivial staggering, without a parallel transform.
For non-const dz, staggered dz needs to be given in an input file, so we
don't have to interpolate.

Also make isConst a free function, similar to min and max.
If we are deeper nested, omp_get_thread_num isn't unique anymore
* Add metric3D to cmake
* cmake with -DENABLE_METRIC_3D=ON to get 3D metrics
* Due to the out-of-source build we need to python dirs, one for noarch
files, and one for arched ones
otherwise python finds boututils in one pythonpath, and does not
look in other locations for the other file.
Some solver throw errors otherwise
Read the environment variable BOUT_SHOW_BACKTRACE.
If the variable is set, show the backtrace, otherwise just show the
message.
The allows to get the backtrace without having to attache gdb, or catch
the exception. The default behaviour is not changed.
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

clang-tidy made some suggestions

There were too many comments to post at once. Showing the first 25 out of 195. Check the log or trigger a new build to see more.

include/bout/coordinates.hxx Show resolved Hide resolved
include/bout/coordinates.hxx Show resolved Hide resolved
include/bout/coordinates.hxx Show resolved Hide resolved
include/bout/coordinates.hxx Show resolved Hide resolved
include/bout/coordinates.hxx Show resolved Hide resolved
include/bout/coordinates.hxx Show resolved Hide resolved
include/bout/coordinates.hxx Show resolved Hide resolved
include/bout/coordinates.hxx Show resolved Hide resolved
include/bout/coordinates.hxx Show resolved Hide resolved
include/bout/coordinates.hxx Show resolved Hide resolved
Previously no boundary was detection because the index cannot be out of
bounds in both directions
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

clang-tidy made some suggestions

There were too many comments to post at once. Showing the first 25 out of 170. Check the log or trigger a new build to see more.

include/bout/coordinates.hxx Show resolved Hide resolved
include/bout/coordinates.hxx Show resolved Hide resolved
include/bout/coordinates.hxx Show resolved Hide resolved
include/bout/coordinates.hxx Show resolved Hide resolved
include/bout/coordinates.hxx Show resolved Hide resolved
include/bout/paralleltransform.hxx Outdated Show resolved Hide resolved
include/bout/paralleltransform.hxx Outdated Show resolved Hide resolved
REGION region = RGN_NOBNDRY) { \
return func(f, outloc, toString(method), toString(region)); \
}
#define DERIV_FUNC_REGION_ENUM_TO_STRING(func, T, Tr) \
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: function-like macro DERIV_FUNC_REGION_ENUM_TO_STRING used; consider a constexpr template function [cppcoreguidelines-macro-usage]

#define DERIV_FUNC_REGION_ENUM_TO_STRING(func, T, Tr)                                  \
        ^

@@ -94,9 +94,9 @@ void Vector2D::toCovariant() {
const auto metric = localmesh->getCoordinates(location);

// Need to use temporary arrays to store result
Field2D gx{emptyFrom(x)}, gy{emptyFrom(y)}, gz{emptyFrom(z)};
Coordinates::FieldMetric gx{emptyFrom(x)}, gy{emptyFrom(y)}, gz{emptyFrom(z)};
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: multiple declarations in a single statement reduces readability [readability-isolate-declaration]

Coordinates::FieldMetric gx{emptyFrom(x)}, gy{emptyFrom(y)}, gz{emptyFrom(z)};
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

@@ -146,9 +146,9 @@ void Vector2D::toContravariant() {
const auto metric = localmesh->getCoordinates(location);

// Need to use temporary arrays to store result
Field2D gx{emptyFrom(x)}, gy{emptyFrom(y)}, gz{emptyFrom(z)};
Coordinates::FieldMetric gx{emptyFrom(x)}, gy{emptyFrom(y)}, gz{emptyFrom(z)};
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: multiple declarations in a single statement reduces readability [readability-isolate-declaration]

Coordinates::FieldMetric gx{emptyFrom(x)}, gy{emptyFrom(y)}, gz{emptyFrom(z)};
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

dschwoerer and others added 2 commits March 23, 2021 09:37
Returning non-const objects has no disadvantage for const correctness
and is easier to read.
* Previously, only the inner-most boundary point was set, which could cause problems with interpolation
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

clang-tidy made some suggestions

There were too many comments to post at once. Showing the first 25 out of 145. Check the log or trigger a new build to see more.

@@ -371,11 +371,11 @@ const Vector3D Vector2D::operator/(const Field3D &rhs) const {

////////////////// DOT PRODUCT ///////////////////

const Field2D Vector2D::operator*(const Vector2D &rhs) const {
const Coordinates::FieldMetric Vector2D::operator*(const Vector2D& rhs) const {
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: return type const Coordinates::FieldMetric (aka const Field2D) is const-qualified at the top level, which may reduce code readability without improving const correctness [readability-const-return-type]

const Coordinates::FieldMetric Vector2D::operator*(const Vector2D& rhs) const {
^~~~~~

@@ -474,7 +474,7 @@ const Vector3D operator*(const Field3D &lhs, const Vector2D &rhs) {
***************************************************************/

// Return the magnitude of a vector
const Field2D abs(const Vector2D &v, const std::string& region) {
const Coordinates::FieldMetric abs(const Vector2D& v, const std::string& region) {
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: return type const Coordinates::FieldMetric (aka const Field2D) is const-qualified at the top level, which may reduce code readability without improving const correctness [readability-const-return-type]

const Coordinates::FieldMetric abs(const Vector2D& v, const std::string& region) {
^~~~~~

BoutReal coef1=0.0, coef2=0.0, coef3=0.0, coef4=0.0,
coef5=0.0, coef6=0.0, kwave;

BoutReal coef1 = 0.0, coef2 = 0.0, coef3 = 0.0, coef4 = 0.0, coef5 = 0.0, coef6 = 0.0;
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: multiple declarations in a single statement reduces readability [readability-isolate-declaration]

BoutReal coef1 = 0.0, coef2 = 0.0, coef3 = 0.0, coef4 = 0.0, coef5 = 0.0, coef6 = 0.0;
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

src/mesh/boundary_standard.cxx Show resolved Hide resolved
src/mesh/boundary_standard.cxx Show resolved Hide resolved
src/mesh/boundary_standard.cxx Show resolved Hide resolved
src/mesh/boundary_standard.cxx Show resolved Hide resolved
src/mesh/boundary_standard.cxx Show resolved Hide resolved
@ZedThree
Copy link
Member

ZedThree commented Jul 1, 2021

Once #2357 has been merged, I think this is ready to go. We know there are issues with LaplaceXZ, but at least some of them exist in next (see #2207, #2359)

I do think we could do with more 3D-specific tests, but there is a decent amount of coverage already.

* next:
  Mark unused function arguments with MAYBE_UNUSED
  De-abbreviate exception message
  Use constants in setting default_dz for Coordinates unit test
  Fix expectation for default value
  Do not ignore default value
  Fix mpark_submodule if not called from local directory
  Add additional targets for submodules
  Some basic tests of Coordinates inputs
  Basic tests of Coordinates
  Enable FakeGridDataSource to provide values to Mesh
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

clang-tidy made some suggestions

There were too many comments to post at once. Showing the first 25 out of 125. Check the log or trigger a new build to see more.

@@ -284,14 +304,13 @@ private:
* Shift a 2D field in Z.
* Since 2D fields are constant in Z, this has no effect
*/
const Field2D shiftZ(const Field2D& f, const Field2D& UNUSED(zangle),
const std::string UNUSED(region) = "RGN_NOX") const {
Field2D shiftZ(const Field2D& f, const Field2D& UNUSED(zangle),
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: method shiftZ can be made static [readability-convert-member-functions-to-static]

Field2D shiftZ(const Field2D& f, const Field2D& UNUSED(zangle),
        ^
static

const Field2D shiftZ(const Field2D& f, const Field2D& UNUSED(zangle),
const std::string UNUSED(region) = "RGN_NOX") const {
Field2D shiftZ(const Field2D& f, const Field2D& UNUSED(zangle),
const std::string UNUSED(region) = "RGN_NOX") const {
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: the const qualified parameter UNUSED_region is copied for each invocation; consider making it a reference [performance-unnecessary-value-param]

const std::string UNUSED(region) = "RGN_NOX") const {
                                   ^
                                         &
/github/workspace/include/unused.hxx:29:20: note: expanded from macro 'UNUSED'
# define UNUSED(x) UNUSED_ ## x __attribute__((unused))
                   ^
note: expanded from here

const Field2D shiftZ(const Field2D& f, const Field2D& UNUSED(zangle),
REGION UNUSED(region)) const {
"const std::string& region = \"RGN_NOX\") instead")]] Field2D
shiftZ(const Field2D& f, const Field2D& UNUSED(zangle), REGION UNUSED(region)) const {
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: method shiftZ can be made static [readability-convert-member-functions-to-static]

shiftZ(const Field2D& f, const Field2D& UNUSED(zangle), REGION UNUSED(region)) const {
^                                                                              ~~~~~~

const YDirectionType y_direction_out,
const std::string& region = "RGN_NOX") const;
Field3D shiftZ(const Field3D& f, const Tensor<dcomplex>& phs,
const YDirectionType y_direction_out,
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: parameter y_direction_out is const-qualified in the function declaration; const-qualification of parameters only has an effect in function definitions [readability-avoid-const-params-in-decls]

const YDirectionType y_direction_out,
^~~~~~

const YDirectionType y_direction_out,
const std::string& region = "RGN_NOX") const;
FieldPerp shiftZ(const FieldPerp& f, const Tensor<dcomplex>& phs,
const YDirectionType y_direction_out,
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: parameter y_direction_out is const-qualified in the function declaration; const-qualification of parameters only has an effect in function definitions [readability-avoid-const-params-in-decls]

const YDirectionType y_direction_out,
^~~~~~

void BoundaryFree::apply_ddt(Field2D& UNUSED(f)) {
// Do nothing for free boundary
}
int jx, jy, jz, jzp, jzm;
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: multiple declarations in a single statement reduces readability [readability-isolate-declaration]

int jx, jy, jz, jzp, jzm;
^~~~~~~~~~~~~~~~~~~~~~~~~

void BoundaryFree::apply_ddt(Field2D& UNUSED(f)) {
// Do nothing for free boundary
}
int jx, jy, jz, jzp, jzm;
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: variable jx is not initialized [cppcoreguidelines-init-variables]

int jx, jy, jz, jzp, jzm;
    ^
       = 0

void BoundaryFree::apply_ddt(Field2D& UNUSED(f)) {
// Do nothing for free boundary
}
int jx, jy, jz, jzp, jzm;
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: variable jy is not initialized [cppcoreguidelines-init-variables]

int jx, jy, jz, jzp, jzm;
        ^
           = 0

void BoundaryFree::apply_ddt(Field2D& UNUSED(f)) {
// Do nothing for free boundary
}
int jx, jy, jz, jzp, jzm;
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: variable jz is not initialized [cppcoreguidelines-init-variables]

int jx, jy, jz, jzp, jzm;
            ^
               = 0

void BoundaryFree::apply_ddt(Field2D& UNUSED(f)) {
// Do nothing for free boundary
}
int jx, jy, jz, jzp, jzm;
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: variable jzp is not initialized [cppcoreguidelines-init-variables]

int jx, jy, jz, jzp, jzm;
                ^
                    = 0

@ZedThree
Copy link
Member

ZedThree commented Jul 1, 2021

@bshanahan @dschwoerer I'm happy to merge this when the tests pass, but between you please could you create one or two integrated 3D tests? Analytic answers would obviously be lovely, but a regression test would be fine! Maybe two waves in a rotating ellipsis?

@ZedThree ZedThree merged commit 4b75196 into next Jul 7, 2021
@bshanahan
Copy link
Contributor

🥳 🍾

@ZedThree ZedThree deleted the coord3d_merged2 branch November 30, 2021 14:05
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.

None yet

6 participants