2.2.2. How To Add a New Simulation Algorithm

group HowTo_NewSimulationAlgorithm

HowTo: Add a New Simulation Algorithm

The purpose of this page is to enumerate the steps in order to expand the flow algorithms used by SW2D.

The models of these algorithms are DIP and DDP, or swSource.

For an algorithm that uses only cell-based fields (e.g. source terms)

In the .h file (see swSource.h) In the .cpp file (see swSource.cpp)

For an algorithm that uses both cell- and interface-based fields (e.g. HypCL)

2.2.3. How To Add a New Model

group HowTo_NewModel

How to add a new Model

To add a new model, there is three steps:

1. you should create a new class inheriting from swModel and redefine 3 functions (with final keyword):

  • setParameters

  • solve

  • writeBoundaries

At the same time, write a test to check that your model is behaving as expected.

2. Then, in the init method of swPipeline, you have to define when should this new model be used

3. The next step is to edit the file parameters_definition.json in swCore and edit the parameter controling the model ( hyp at this time, but it may become phys/poromodel)

2.2.4. How To Add a New Parameter

group HowTo_NewParameter

How to add a new Parameter

To add a new parameter, there is three steps:

1. Edit the file parameters_definition.json in swCore or biological_parameters_definition.json in swTransport and add your new parameter there with it’s documentation, label, type, default_value and other needed field depending of it’s type. The best is to copy/paste from an existing parameter of the same type. The order of parameters doesn’t matter in these files. Here is an example of a parameter (with or without a comma at the end depending of it’s location):

$  "headloss_s1": {
$      "label": "Uniform coefficient in direction 1",
$      "doc": "Float equal or greater than 0",
$      "value": 0.01,
$      "min": 0.0,
$      "max": 100.0,
$      "decimals": 6,
$      "type": "dtk::d_real"
$  },

2. Then, for your parameter to appear on the GUI, edit simulator_menu or biological_simulator_menu in the app/sw2dModeler folder. In these files you can choose in which group your parameter will appear depending of where you put it. You can also choose of it will appear by choosing the widget. The block to put in These files should look like this (with or without a comma at the end depending of it’s location):

$ {
$    "parameter": {
$        "uid": "headloss_s1",
$        "widget": "dtkWidgetsParameterDoubleSpinBox",
$        "advanced": false
$    }
$  },

3. To finish, you can now use your parameter in the code if you have access to the swSettings instance of the simulation like this:

$ dtk::d_real(settings.value("headloss_s1")).value()