Skip to content

Compile-time OpenFOAM reflections that can be consulted in run-time at no cost!

Notifications You must be signed in to change notification settings

FoamScience/openfoam-reflections

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

42 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Reflections for OpenFOAM code

This repository hosts my failed attempt at a perfect header-only reflections system for OpenFOAM code while we wait for this proposal to make it into the C++ standard. It'll be a while before that happens but since concepts are now in the language, it's not too far into the future.

Main objectives of this library:

  • Provide an automated mechanism to build dictionary skeletons for OpenFOAM classes (And JSON endpoints). A skeleton represents a "standard" OpenFOAM dictionary (or a simple JSON schema) with required keywords (and sub-dicts) to construct an object of the target type.
  • Provide an automated mechanism to generate UI widgets for OpenFOAM classes.

Use cases:

  • Cheaply generate UIs for OpenFOAM applications (Both in terms of developer effort, and performance overhead).
  • Natively generate skeletons (Both OpenFOAM dictionaries, and in JSON format) for use in Unit Testing and Ux generation.

Important

I discourage the use of reflections for any other purpose as they open a giant gate for all kinds of bugs. Think of all the bugs in Game Engines.

Reflections are done at compile-time with (near)zero runtime-cost through the refl-cpp library.

For a quick overview on how this effort started, the general goals and the current state; see

There is an interactiveUI application to illustrate basic usage of the reflection system by providing a JSON endpoint for few dummy OpenFOAM classes. Also, you need C++20 for this to work (not a hard requirement but I like concepts).

Getting started

Prerequisites

  • A recent version of OpenCFD OpenFOAM
  • C++20 compiler (For the dummy classes and the JSON endpoint generator)
  • Golang v1.22+ (For the sample TUI)

All of the requirements are contained in the associated Apptainer container.

Compiling the sample application

To compile the sample application:

git clone https://github.com/FoamScience/openfoam-reflections
cd openfoam-reflections
# Needs OpenFOAM to be sourced
./build.sh # Works on Ubuntu with go installed
./applications/endpoint/endpoint
# in another terminal, 
./TUI/tui

For the mechanism to work for your code, you have to follow specific methods:

  • A few macros need to be called for your base and child models (See interactiveUI/baseModel as an example)
  • Your ::New function needs to have a dictionary as first argument.
  • In general, your types need to satisfy concept constraints in uiConcepts.H (Or the other way around, your call)
  • If you wrap your class members in a uiElement<...>, descriptions, bounds and default values will be picked up by the UI generator. Although this is not fully implemented.

Apptainer containers

If you don't want to bloat your system but still would like to give this a try:

git clone https://github.com/FoamScience/openfoam-apptainer-packaging /tmp/of_tainers
git clone https://github.com/FoamScience/openfoam-reflections
cd openfoam-reflections
ansible-playbook /tmp/of_tainers/build.yaml --extra-vars="original_dir=$PWD" --extra-vars="@build/config.yaml"
# In one terminal (it's fine if there are some errors)
apptainer run containers/projects/reflections.sif "/opt/openfoam-reflections/endpoint/endpoint"
# In another terminal
apptainer run containers/projects/reflections.sif "/opt/openfoam-reflections/TUI/tui"

About

Compile-time OpenFOAM reflections that can be consulted in run-time at no cost!

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published