Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/field/field_factory.cxx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**************************************************************************
* Copyright 2010 B.D.Dudson, S.Farley, M.V.Umansky, X.Q.Xu
* Copyright 2010-2025 BOUT++ contributors
*
* Contact: Ben Dudson, bd512@york.ac.uk
* Contact: Ben Dudson, dudson2@llnl.gov
*
* This file is part of BOUT++.
*
Expand Down Expand Up @@ -176,6 +176,9 @@ FieldFactory::FieldFactory(Mesh* localmesh, Options* opt)

// Where switch function
addGenerator("where", std::make_shared<FieldWhere>(nullptr, nullptr, nullptr));

// Periodic in the Y direction?
addGenerator("periodicY", std::make_shared<FieldPeriodicY>(nullptr));
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: no header providing "std::make_shared" is directly included [misc-include-cleaner]

                                  ^

}

Field2D FieldFactory::create2D(const std::string& value, const Options* opt,
Expand Down
32 changes: 31 additions & 1 deletion src/field/fieldgenerators.hxx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*!
/*!A
* \file fieldgenerators.hxx
*
* These classes are used by FieldFactory
Expand Down Expand Up @@ -352,4 +352,34 @@ private:
FieldGeneratorPtr test, gt0, lt0;
};

/// Function that evaluates to 1 when Y is periodic (i.e. in the core), 0 otherwise
class FieldPeriodicY : public FieldGenerator {
public:
FieldPeriodicY(Mesh* mesh) : mesh(mesh) {
// Note: Assumes symmetricGlobalX
local_inner_boundary =
0.5 * (mesh->GlobalX(mesh->xstart - 1) + mesh->GlobalX(mesh->xstart));
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: 'local_inner_boundary' should be initialized in a member initializer of the constructor [cppcoreguidelines-prefer-member-initializer]

src/field/fieldgenerators.hxx:357:

-   FieldPeriodicY(Mesh* mesh) : mesh(mesh) {
+   FieldPeriodicY(Mesh* mesh) : mesh(mesh), local_inner_boundary(0.5 * (mesh->GlobalX(mesh->xstart - 1) + mesh->GlobalX(mesh->xstart))) {
Suggested change
0.5 * (mesh->GlobalX(mesh->xstart - 1) + mesh->GlobalX(mesh->xstart));

local_outer_boundary =
0.5 * (mesh->GlobalX(mesh->xend + 1) + mesh->GlobalX(mesh->xend));
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: 'local_outer_boundary' should be initialized in a member initializer of the constructor [cppcoreguidelines-prefer-member-initializer]

src/field/fieldgenerators.hxx:357:

-   FieldPeriodicY(Mesh* mesh) : mesh(mesh) {
+   FieldPeriodicY(Mesh* mesh) : mesh(mesh), local_outer_boundary(0.5 * (mesh->GlobalX(mesh->xend + 1) + mesh->GlobalX(mesh->xend))) {
Suggested change
0.5 * (mesh->GlobalX(mesh->xend + 1) + mesh->GlobalX(mesh->xend));

}
FieldGeneratorPtr clone(const std::list<FieldGeneratorPtr> UNUSED(args)) override {
return std::make_shared<FieldPeriodicY>(ctx.getMesh());
}
BoutReal generate(const bout::generator::Context& ctx) override {
int local_index = mesh->xstart
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 'local_index' of type 'int' can be declared 'const' [misc-const-correctness]

Suggested change
int local_index = mesh->xstart
int const local_index = mesh->xstart

+ int(((ctx.x() - local_inner_boundary)
/ (local_outer_boundary - local_inner_boundary))
* (mesh->xend - mesh->xstart + 1));
if (mesh->periodicY(local_index)) {
return 1.0;
}
return 0.0;
}

private:
Mesh* mesh;
BoutReal local_inner_boundary;
BoutReal local_outer_boundary;
};

#endif // BOUT_FIELDGENERATORS_H