DNDSR 0.1.0.dev1+gcd065ad
Distributed Numeric Data Structure for CFV
Loading...
Searching...
No Matches
ConfigParam.hpp File Reference

pybind11-style configuration registration with macro-based field declaration and namespace-scoped tag kwargs. More...

#include "ConfigRegistry.hpp"
#include <type_traits>
#include <utility>
Include dependency graph for ConfigParam.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  DNDS::ConfigTypeTagOf< T, Enable >
 
struct  DNDS::ConfigTypeTagOf< bool >
 
struct  DNDS::ConfigTypeTagOf< std::string >
 
struct  DNDS::ConfigTypeTagOf< T, std::enable_if_t< std::is_integral_v< T > &&!std::is_same_v< T, bool > > >
 
struct  DNDS::ConfigTypeTagOf< T, std::enable_if_t< std::is_floating_point_v< T > > >
 
struct  DNDS::ConfigTypeTagOf< std::vector< T > >
 
struct  DNDS::ConfigTypeTagOf< std::array< T, N > >
 
struct  DNDS::ConfigTypeTagOf< nlohmann::ordered_json >
 
struct  DNDS::ConfigTypeTagOf< T, std::enable_if_t< std::is_enum_v< T > > >
 C++ enum types serialize as JSON strings via nlohmann, so map to Enum. More...
 
struct  DNDS::detail::is_eigen_type< T, typename >
 
struct  DNDS::detail::is_eigen_type< T, std::void_t< typename T::Scalar, decltype(static_cast< int >(T::RowsAtCompileTime)), decltype(static_cast< int >(T::ColsAtCompileTime))> >
 
struct  DNDS::ConfigTypeTagOf< T, std::enable_if_t< detail::is_eigen_type< T >::value > >
 
struct  DNDS::Config::RangeTag
 Numeric range constraint. Enforced at parse time in readFromJson and emitted in schema. More...
 
struct  DNDS::Config::InfoTag
 Auxiliary info tag (emitted as "x-<key>" in schema). More...
 
struct  DNDS::Config::EnumValuesTag
 Explicit enum allowed-values tag. More...
 
class  DNDS::ConfigSectionBuilder< T >
 Builder object passed to the user's registration function. More...
 

Namespaces

namespace  DNDS
 the host side operators are provided as implemented
 
namespace  DNDS::detail
 
namespace  DNDS::Config
 Namespace for config field tag kwargs.
 

Macros

#define DNDS_FIELD(name_, desc_, ...)    config.field(&T::name_, #name_, desc_, ##__VA_ARGS__)
 Register a field inside a DNDS_DECLARE_CONFIG body.
 
#define DNDS_DECLARE_CONFIG(Type_)
 Open a config section registration body.
 

Functions

std::string DNDS::schemaTypeString (ConfigTypeTag tag)
 
RangeTag DNDS::Config::range (double min)
 Create a minimum-only range constraint.
 
RangeTag DNDS::Config::range (double min, double max)
 Create a min+max range constraint.
 
InfoTag DNDS::Config::info (std::string key, std::string value)
 Create an auxiliary info tag.
 
EnumValuesTag DNDS::Config::enum_values (std::vector< std::string > vals)
 Create an enum allowed-values tag.
 
void DNDS::detail::applyTag (FieldMeta &meta, const Config::RangeTag &tag)
 
void DNDS::detail::applyTag (FieldMeta &meta, const Config::InfoTag &tag)
 
void DNDS::detail::applyTag (FieldMeta &meta, const Config::EnumValuesTag &tag)
 
void DNDS::detail::applyTags (FieldMeta &)
 
template<typename Tag , typename... Rest>
void DNDS::detail::applyTags (FieldMeta &meta, Tag &&tag, Rest &&...rest)
 
template<typename T , typename V >
std::function< nlohmann::ordered_json()> DNDS::detail::makeSchemaEntry (V T::*member, const char *desc, const FieldMeta &meta)
 Build the schemaEntry closure from a fully-tagged FieldMeta.
 
template<typename T , typename V >
std::function< void(const nlohmann::ordered_json &, const char *)> DNDS::detail::makeRangeChecker (const FieldMeta &meta)
 Build a runtime range-check closure.
 

Detailed Description

pybind11-style configuration registration with macro-based field declaration and namespace-scoped tag kwargs.

Overview

Config sections are plain structs. Metadata is registered in a static method opened by the DNDS_DECLARE_CONFIG(Type) macro. Inside that body the user calls DNDS_FIELD(member, "description", tags...) which is a macro that auto-stringifies the member name — no name duplication.

Example

struct ImplicitCFLControl
{
real CFL = 10;
int nForceLocalStartStep = INT_MAX;
bool useLocalDt = true;
real RANSRelax = 1;
DNDS_DECLARE_CONFIG(ImplicitCFLControl)
{
DNDS_FIELD(CFL, "CFL for implicit local dt");
DNDS_FIELD(nForceLocalStartStep, "Step to force local dt",
DNDS_FIELD(useLocalDt, "Use local (vs uniform) dTau");
DNDS_FIELD(RANSRelax, "RANS under-relaxation factor",
DNDS::Config::range(0.0, 1.0));
config.check([](const T &s) -> DNDS::CheckResult {
if (s.RANSRelax <= 0)
return {false, "RANSRelax must be positive"};
return {true, ""};
});
}
};
#define DNDS_FIELD(name_, desc_,...)
Register a field inside a DNDS_DECLARE_CONFIG body.
#define DNDS_DECLARE_CONFIG(Type_)
Open a config section registration body.
RangeTag range(double min)
Create a minimum-only range constraint.
Result of a single validation check.

Adding a New Parameter

  1. Declare the member with default (plain C++).
  2. Add DNDS_FIELD(member, "description") in the DNDS_DECLARE_CONFIG body.

Tag kwargs (namespace-scoped)

Tags are passed as extra arguments to DNDS_FIELD:

Tag Purpose Example
DNDS::Config::range(min) Min constraint (schema + runtime check) DNDS::Config::range(0)
DNDS::Config::range(min,max) Min+max constraint DNDS::Config::range(0.0, 1.0)
DNDS::Config::info(k,v) Aux info ("x-<key>" in schema) DNDS::Config::info("unit","Pa")
DNDS::Config::enum_values(v) Allowed string values for enum fields DNDS::Config::enum_values({"Roe","HLLC"})

Runtime Range Validation

When a field has a range() tag, readFromJson() checks the parsed value against the min/max bounds and throws std::runtime_error with a clear message on violation. This catches bad config values at load time.

Section-Level Checks

config.check([](const T &s) -> DNDS::CheckResult { ... });
config.check_ctx([](const T &s, const DNDS::ConfigContext &ctx) -> DNDS::CheckResult { ... });
Runtime context supplied to context-aware validation checks.

Nested Sections and Special Fields

Use explicit config.* calls (not the DNDS_FIELD macro) for these:

config.field_section(&T::frameRotation, "frameConstRotation", "Rotating frame");
config.field_array_of<BoxInit>(&T::boxInits, "boxInitializers", "Box inits");
config.field_map_of<CoarseCtrl>(&T::coarseList, "coarseGridList", "Per-level");
config.field_json(&T::extra, "odeSettingsExtra", "Opaque ODE settings");
config.field_alias(&T::rsType, "riemannSolverType", "Riemann solver type");

Trivial Copyability

The struct has no base class, no virtual methods, no instance-level data introduced by the macro. DNDS_DECLARE_CONFIG only generates static methods and friend functions.

Definition in file ConfigParam.hpp.

Macro Definition Documentation

◆ DNDS_DECLARE_CONFIG

#define DNDS_DECLARE_CONFIG (   Type_)

Open a config section registration body.

Expands to:

  • using T = Type (so DNDS_FIELD can reference &T::member).
  • Lazy _dnds_ensure_registered() with one-time init guard.
  • Friend to_json / from_json calling ensureRegistered first.
  • schema(), validate(), validateWithContext(), validateKeys().
  • Opens static void _dnds_do_register(ConfigSectionBuilder<T>& config) — the user provides the { ... } body after the macro.
struct MySection
{
real a = 1.0;
int b = 42;
{
DNDS_FIELD(a, "The a parameter", DNDS::Config::range(0));
DNDS_FIELD(b, "The b parameter");
}
};
tVec b(NCells)

Definition at line 662 of file ConfigParam.hpp.

◆ DNDS_FIELD

#define DNDS_FIELD (   name_,
  desc_,
  ... 
)     config.field(&T::name_, #name_, desc_, ##__VA_ARGS__)

Register a field inside a DNDS_DECLARE_CONFIG body.

Auto-stringifies the member name so you never write it twice. The JSON key equals the C++ member name.

Parameters
name_Member name (unquoted).
desc_Description string literal.
...Zero or more DNDS::Config tag objects.
DNDS_FIELD(CFL, "CFL for implicit dt", DNDS::Config::range(0));

Definition at line 633 of file ConfigParam.hpp.