How to access time-window-size in a C++ based adapter?

Hello,

This question relates to the usage of preCICE C++ API in an adapter (the in-house implemented for XDEM). Please be patient with the thorough post, as this is not an official adapter I am giving as much info as possible.

Scenario:

I am doing some calculations on the XDEM side, which need to know the coupling time step value.
As these things are to be integrated over the coupling time step.
Hence, I am trying to access time-window-size in XDEM adapter.

My plan was to pass the precise coupling time step i.e time-window-size to the Coupling object I have.

Then proceed with Calculations and exchange of data.

General adapter outline

This is similar to the guidelines posted in the step-by-step guide.

// MAIN >>>
// Initialize XDEM

// initialize preCICE
const std::string solverName("XDEM");
precice::SolverInterface precice(solverName, configFileName, commRank, commSize);
const int precice_dimension = precice.getDimensions();

*** Modifications - new place I initialize preCICE***
// Get preCICE dt
double precice_dt = precice.initialize();
std::cout << "Debug: precice_coupling_dt: = " << precice_dt << std::endl;

// Save list of coupled objects = precice.initialize();

// Get XDEM Meshes (for coupling with CFD or FEM)
// Here we create & initialize the coupled object i.e coupled mesh, by passing various variables needed by the object 
***  here I want to pass the preCICE coupling dt ***

// initialize preCICE
//double precice_dt = precice.initialize(); //ususal place to initialize preCICE

//time loop
 while (!xdem.is_over())
 {
     // read and apply data
     // run XDEM
     // compute and write data

     // Advance preCICE time
    precice_dt = precice.advance( precice_dt );
}

// Finalize preCICE
  precice.finalize();
// Finalize XDEM
xdem.finalize();

Issue.

If I want to pass preCICE coupling time step (time-window-size) to my coupled object, I have to do precice.initialize(); before I do the // Get XDEM Meshes step.
I then run the adapter, get the expected output,

preCICE: This is preCICE version 2.3.0
preCICE: Revision info: v2.3.0
preCICE: Configuration: Debug
preCICE: Configuring preCICE with configuration "./precice-config.xml"
preCICE: I am participant "XDEM"
preCICE: Setting up master communication to coupling partner/s
preCICE: Masters are connected
preCICE: Setting up preliminary slaves communication to coupling partner/s
preCICE: Prepare partition for mesh Domain
preCICE: Receive global mesh Fluid-Mesh-PV
preCICE: Setting up slaves communication to coupling partner/s
preCICE: Slaves are connected
preCICE: iteration: 1, time-window: 1, time: 0 of 500, time-window-size: 0.2, max-timestep-length: 0.2, ongoing: yes, time-window-complete: no, 
Debug: precice_coupling_dt: = 0.2
Deformable Objects in XDEM:
Fluid Volumes in XDEM:
    -  Domain: Used in preCICE!
Inherited Momentum
Inherited HT
Inherited MT
[XDEM-Adapter] Created all the possible fields list
[XDEM-Adapter] Reading all the available fields for coupling

the error

preCICE:ERROR:  This participant attempted to modify the Mesh "Domain" while locked. Mesh modification is only allowed before calling initialize().

The weird thing is, this works if I run in debug mode in QT.
Does not work when I run normally in the terminal.
I think this is just a C++ thing that I am probably messing up.

But maybe there is an alternate solution to using precice.initialize() for getting time-window-size.

There is currently no such method to get the configured coupling time window size in the API: preCICE: precice::SolverInterface Class Reference

While it would be possible to add such a method, there always needs to be a good reason / a clear use case. What is special in XDEM than in other solvers that would require this?

As a workaround, why not select a default timestep size in XDEM and give it to preCICE?

I wouldn’t say anything special. :sweat_smile:
I am calculating Heat and mass sources. Which are to be accumulated (integrated) over the coupling time step, as that’s when I exchange the heat and mass source.
Anyways good to know that currently, it’s not possible. :slight_smile:
This solves my doubt. Thank you @Makis

Usually in direct coupling in XDEM, we have XDEM dt = OpenFOAM dt = Coupling dt.
As it’s just “one” solver. So no need to worry about wrong calculations.

As a workaround, why not select a default timestep size in XDEM and give it to preCICE?

Yes currently I am using time-window-size = XDEM dt.
But this was after can get a bit annoying as I use solver time steps which are much small than coupling time step. But it’s not that bad in terms of the time required for simulation.

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.

Related discussion: Add getter functions for time · Issue #682 · precice/precice · GitHub

1 Like