Writing and empty simulation function

A simulation function must contain two parts : These two parts should be developped in the .h and .cpp files. They should be compiled through a makefile.
Note:
An rough simulation function source code can be automatically generated through the OpenFLUID plugin for Eclipse, included in the SDK

Writing the signature

The function signature is a set of information given to the kernel. With this information, the kernel can evaluate the simulation function, have information on what it does, and dynamically associate it.
The informations included in the signature are :

The signature is declared and implemented in the .h file, and begin with the BEGIN_SIGNATURE_HOOK macro and ends with the END_SIGNATURE_HOOK macro. The minimal signature must include identification information. See part Complete the signature

Writing the derivative class from openfluid::base::PluggableFunction

TODO

Compiling the function

The OpenFLUID-engine simulation functions must be compiled using the gcc C++ compiler (g++) and must be linked to the OpenFLUID library (ofelib).
The ofelib-config tool gives the correct option to pass to the compiler: The best way to compile your simulation function is to use the makefile generated by the OpenFLUID plugin for the Eclipse IDE.

Complete example

Example of an empty function, with the .h file, the .cpp file, and the makefile

Header File (.h)

#ifndef __EXAMPLEFUNC_H__
#define __EXAMPLEFUNC_H__

#include "openfluid-base.h"
#include "openfluid-core.h"

// =====================================================================
// =====================================================================

DECLARE_PLUGIN_HOOKS;

// =====================================================================
// =====================================================================

class ExampleFunction : public openfluid::base::PluggableFunction
{
  private:

  public:
    ExampleFunction();

    ~ExampleFunction();

    bool initParams(openfluid::core::ParamsMap Params);

    bool prepareData();

    bool checkConsistency();

    bool initializeRun(const openfluid::base::SimulationInfo* SimInfo);

    bool runStep(const openfluid::base::SimulationStatus* SimStatus);

    bool finalizeRun(const openfluid::base::SimulationInfo* SimInfo);
};

#endif  // __EXAMPLEFUNC_H__

Implementation file (.cpp)

#include "ExampleFunc.h"

// =====================================================================
// =====================================================================

DEFINE_FUNCTION_HOOK(ExampleFunction);

// =====================================================================
// =====================================================================

BEGIN_SIGNATURE_HOOK
  DECLARE_SIGNATURE_ID(wxT("examplefunc"));
  DECLARE_SIGNATURE_NAME(wxT("Example Function"));
  DECLARE_SIGNATURE_DESCRIPTION(wxT(""));

  DECLARE_SIGNATURE_VERSION(wxT("1.0"));
  DECLARE_SIGNATURE_SDKVERSION;
  DECLARE_SIGNATURE_STATUS(openfluid::base::EXPERIMENTAL);

  DECLARE_SIGNATURE_DOMAIN(wxT(""));
  DECLARE_SIGNATURE_PROCESS(wxT(""));
  DECLARE_SIGNATURE_METHOD(wxT(""));
  DECLARE_SIGNATURE_AUTHORNAME(wxT(""));
  DECLARE_SIGNATURE_AUTHOREMAIL(wxT(""));
END_SIGNATURE_HOOK

// =====================================================================
// =====================================================================

ExampleFunction::ExampleFunction()
                : PluggableFunction()
{
  // here code for constructor
}

// =====================================================================
// =====================================================================

ExampleFunction::~ExampleFunction()
{
  // here code for destructor
}

// =====================================================================
// =====================================================================

bool ExampleFunction::initParams(openfluid::core::ParamsMap Params)
{
  // here code for function parameters initialization
  return true;
}

// =====================================================================
// =====================================================================

bool ExampleFunction::prepareData()
{
  // here code for data preparation befor consistency checking
  return true;
}

// =====================================================================
// =====================================================================

bool ExampleFunction::checkConsistency()
{
  // here code for function consistency checking
  return true;
}

// =====================================================================
// =====================================================================


bool ExampleFunction::initializeRun(const openfluid::base::SimulationInfo* SimInfo)
{
  // here code for initialization just before the simulation
  return true;
}

// =====================================================================
// =====================================================================

bool ExampleFunction::runStep(const openfluid::base::SimulationStatus* SimStatus)
{
  // here code for each time step
  return true;
}

// =====================================================================
// =====================================================================

bool ExampleFunction::finalizeRun(const openfluid::base::SimulationInfo* SimInfo)
{
  // here code for finalization just after the simulation
  return true;
}

Makefile

CPP = g++
WXLIBS = $(shell wx-config --libs base)
WXFLAGS = $(shell wx-config --cxxflags base)
OPENFLUIDLIBS = $(shell openfluid-config --libs)
OPENFLUIDFLAGS = $(shell openfluid-config --cflags)
BINFILE = examplefunc
SRCFILESROOT = ExampleFunc

INSTALLPATH = $(HOME)/.openfluid/engine/functions
OBJPATH = .
BINPATH = .

LDFLAGS =
PLUGEXT = sompi
ifeq ($(OSTYPE),msys)
  LDFLAGS=-Wl,--enable-runtime-pseudo-reloc
  PLUGEXT = dllmpi
endif

ifdef FORCEINSTALLPATH
  INSTALLPATH = $(FORCEINSTALLPATH)
endif

ifdef FORCEOBJPATH
  OBJPATH = $(FORCEOBJPATH)
endif

ifdef FORCEBINPATH
  BINPATH = $(FORCEBINPATH)
endif


all:
	$(CPP) -c $(SRCFILESROOT).cpp -o $(OBJPATH)/$(SRCFILESROOT).o -fPIC $(WXFLAGS) $(OPENFLUIDFLAGS)
	$(CPP) $(OBJPATH)/$(SRCFILESROOT).o $(WXLIBS) $(OPENFLUIDLIBS) -o $(BINPATH)/$(BINFILE).$(PLUGEXT) -shared $(LDFLAGS)

clean:
	rm -f $(BINPATH)/$(BINFILE).$(PLUGEXT)
	rm -f $(OBJPATH)/$(SRCFILESROOT).o

install: all
	 @mkdir -p $(INSTALLPATH)
	 @cp ./$(BINFILE).$(PLUGEXT) $(INSTALLPATH)

Generated using Doxygen 1.5.5
Creative Commons License Creative Commons By-NC-ND license