The minimal source code of an OpenFLUID simuilator is made of a C++ file and a build configuration for CMake tool. Using the CMake build tool, the simulator source code is built into a binary plugin for OpenFLUID and automatically installed in the dedicated location to be usable by the OpenFLUID platform.
See also the Organization of an OpenFLUID workspace appendix for sources codes location in workspaces.
Required tools for development environment
In order to build and develop a simulator, the following tools are required:
- GCC as the C++/C/Fortran compiler (version 7 or later for C++17 compatibility)
- CMake as the build configuration tool (version 3.10 or later). OpenFLUID provides a CMake module to ease the build of simulators.
Detailed instructions for installation of these tools are available on the OpenFLUID Community web site (http://community.openfluid-project.org).
Even if simulators can be developped using any text editor, the OpenFLUID-DevStudio is the recommended environment for simulators development.
Creation of a simulator using OpenFLUID-DevStudio
- Note
- As the OpenFLUID-DevStudio UI is multilingual, the items cited below such as menu names or labels can be in another language than english for you installation.
The OpenFLUID-DevStudio application is made of a main toolbar located on left, a file navigator on the left side and a file editor on the right side.
Screenshot of OpenFLUID-DevStudio workspace
To create a new simulator, go to menu File > New ware > Simulator... This opens the new simulator dialog. In this dialog, set the simulator ID and source files names then click OK. The Source code of a new simulator is created.
Screenshot of new simulator dialog
Configuration phase
Once created, the configuration phase must be performed at least once. Click on the Configure button of the main toolbar. This phase checks the dependencies (tools and libraries) required to build the simulator. It can be performed either in Release mode for performance optimization (mode by default, recommended) or in Debug mode to be used with an external debugger.
Build phase
The build phase must be performed each time the source code has been modified. Once the configure process is completed, click on the Build button to effectively build the simulator.
This phase builds thes simulator source code into a binary plugin for the OpenFLUID platform. It can be performed either in Build and install mode to make the simulator immediately available for simulations (mode by default, recommended) or in Build only mode for intermediate builds for example.
Complete source code example
The example below show a complete example of an empty simulator, including source code and build configuration using the OpenFLUID CMake module.
File ExampleSimulator.cpp containing the simulator source code
{
private:
public:
ExampleSimulator(): PluggableSimulator()
{
}
~ExampleSimulator()
{
}
{
}
{
}
{
}
{
}
{
}
{
}
};
#define DEFINE_SIMULATOR_CLASS(pluginclassname)
Definition: PluggableSimulator.hpp:73
Definition: SchedulingRequest.hpp:54
Abstract class for simulator plugin.
Definition: PluggableSimulator.hpp:105
virtual openfluid::base::SchedulingRequest runStep()=0
virtual openfluid::base::SchedulingRequest initializeRun()=0
openfluid::base::SchedulingRequest DefaultDeltaT() const
Definition: PluggableSimulator.hpp:366
virtual void prepareData()=0
virtual void checkConsistency()=0
virtual void finalizeRun()=0
virtual void initParams(const openfluid::ware::WareParams_t &Params)=0
std::map< WareParamKey_t, WareParamValue_t > WareParams_t
Definition: TypeDefs.hpp:146
File CMakeLists.txt containing the ware configuration
CMAKE_MINIMUM_REQUIRED(VERSION 3.10)
PROJECT("my.simulator.id")
FIND_PACKAGE(OpenFLUID REQUIRED)
ADD_SUBDIRECTORY(src)
ADD_SUBDIRECTORY(doc)
ADD_SUBDIRECTORY(tests)
File src/CMakeLists.txt defining the plugin build
# set this to add include directories
# ex: SET(WARE_INCLUDE_DIRS /path/to/include/A/ /path/to/include/B/)
#SET(WARE_INCLUDE_DIRS )
# set this to add libraries directories
# ex: SET(WARE_LIBRARY_DIRS /path/to/libA/ /path/to/libB/)
#SET(WARE_LIBRARY_DIRS )
# set this to add linked libraries
# ex: SET(WARE_LINK_LIBS libA libB)
#SET(WARE_LINK_LIBS )
# set this to add definitions
# ex: SET(WARE_DEFINITIONS "-DDebug")
#SET(WARE_DEFINITIONS )
# set this to list the extra files or directories to scan for strings to translate
#SET(I18N_FILES_EXTRASCANS )
OPENFLUID_ADD_WAREPLUGIN(
# list of C++ files
CPP_FILES WareMain.cpp
# list of Fortran files
#FORTRAN_FILES
# list of UI files (mainly for builderexts)
#UI_FILES
# list of RC files (mainly for builderexts)
#RC_FILES
# list of languages for translation
#I18N_LANGS
# list of supplementary OpenFLUID libraries (e.g. tools, ...)
#OPENFLUID_COMPONENTS
# custom target name, automatically generated if not provided
#TARGET
# custom installation path, standard path is used if not provided
#INSTALL_PATH
# parametrized signature and/or documentation (ON/OFF, OFF is default)
CONFIGURED_SIGNATURE OFF
# enable build of parameterization UI (ON/OFF, OFF is default)
WITH_PARAMSUI OFF
# list of C++ files for parametrization UI
#PARAMSUI_CPP_FILES
# list of UI files for parametrization UI
#PARAMSUI_UI_FILES
# list of RC files for parametrization UI
#PARAMSUI_RC_FILES
# list of supplementary OpenFLUID libraries (e.g. tools, ...) for parametrization UI
#PARAMSUI_OPENFLUID_COMPONENTS
# custom target name for parametrization UI, automatically generated by default
#PARAMSUI_TARGET
# custom installation path for parametrization UI, standard path is used by default
#PARAMSUI_INSTALL_PATH
)