Skip to content
Open
Show file tree
Hide file tree
Changes from all 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>());
}

Field2D FieldFactory::create2D(const std::string& value, const Options* opt,
Expand Down
25 changes: 25 additions & 0 deletions src/field/fieldgenerators.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -352,4 +352,29 @@ private:
FieldGeneratorPtr test, gt0, lt0;
};

/// Function that evaluates to 1 when Y is periodic (i.e. in the core), 0 otherwise
/// Note: Assumes symmetricGlobalX
class FieldPeriodicY : public FieldGenerator {
public:
FieldPeriodicY() = default;
FieldGeneratorPtr clone(const std::list<FieldGeneratorPtr> UNUSED(args)) override {
return std::make_shared<FieldPeriodicY>();
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]

    return std::make_shared<FieldPeriodicY>();
                ^

}
BoutReal generate(const bout::generator::Context& ctx) override {
const Mesh* mesh = ctx.getMesh();
const BoutReal local_inner_boundary =
0.5 * (mesh->GlobalX(mesh->xstart - 1) + mesh->GlobalX(mesh->xstart));
const BoutReal local_outer_boundary =
0.5 * (mesh->GlobalX(mesh->xend + 1) + mesh->GlobalX(mesh->xend));
const int 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;
}
};

#endif // BOUT_FIELDGENERATORS_H
Loading