Skip to content

Conversation

@ZedThree
Copy link
Member

@ZedThree ZedThree commented Dec 2, 2025

This adds the ability to read fields (2D and 3D) and doubles* from the grid file (mesh:file) and use them in expressions in the input file, for example to use coordinates directly from the grid generator:

[input:grid_variables]
rho = field2d
theta = field2d
scale = boutreal

[mesh]
B = (scale / rho) * cos(theta)

* ints can also be read, but the expression parser only handles doubles


This could also be used for something like region labels to the input file by having hypnotoad make a field which is 1.0 in that region and 0.0 elsewhere:

region_pfr = 1.0 if is_in_pfr else 0.0

and using like

[input:grid_variables]
region_pfr = field2d

[some_source]
function = region_pfr * cos(x) * whatever

We could probably also do this in BOUT++ directly, making fields for each boundary region.

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

return std::make_shared<FieldValuePtr>(ptr);
}

BOUT_ENUM_CLASS(GridVariableFunction, field3d, field2d, boutreal);
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: enum 'GridVariableFunction' uses a larger base type ('int', size: 4 bytes) than necessary for its value set, consider using 'std::uint8_t' (1 byte) as the base type to reduce its size [performance-enum-size]

BOUT_ENUM_CLASS(GridVariableFunction, field3d, field2d, boutreal);
                ^

return std::make_shared<FieldValuePtr>(ptr);
}

BOUT_ENUM_CLASS(GridVariableFunction, field3d, field2d, boutreal);
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 'GridVariableFunctionFromString' can be made static or moved into an anonymous namespace to enforce internal linkage [misc-use-internal-linkage]

BOUT_ENUM_CLASS(GridVariableFunction, field3d, field2d, boutreal);
^

expanded from here

return std::make_shared<FieldValuePtr>(ptr);
}

BOUT_ENUM_CLASS(GridVariableFunction, field3d, field2d, boutreal);
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 'UNUSED_similar_to' is unused [misc-unused-parameters]

BOUT_ENUM_CLASS(GridVariableFunction, field3d, field2d, boutreal);
^
Additional context

include/bout/bout_enum_class.hxx:98: expanded from macro 'BOUT_ENUM_CLASS'

  inline enumname Options::as<enumname>(const enumname&) const {               \
                                                       ^

class GridVariable : public FieldGenerator {
public:
GridVariable(T var, std::string name)
: variable(std::move(var)), name(std::move(name)) {}
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::move" is directly included [misc-include-cleaner]

src/field/fieldgenerators.hxx:18:

+ #include <utility>

}

FieldGeneratorPtr clone(const std::list<FieldGeneratorPtr> args) override {
if (args.size() != 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: the 'empty' method should be used to check for emptiness instead of 'size' [readability-container-size-empty]

Suggested change
if (args.size() != 0) {
if (!args.empty()) {
Additional context

/usr/include/c++/13/bits/stl_list.h:1142: method 'list'::empty() defined here

      empty() const _GLIBCXX_NOEXCEPT
      ^

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.

2 participants