diff --git a/adapter/PreciceInterface.c b/adapter/PreciceInterface.c index d358e1c..f80c1ef 100644 --- a/adapter/PreciceInterface.c +++ b/adapter/PreciceInterface.c @@ -47,6 +47,9 @@ void Precice_Setup( char * configFilename, char * participantName, SimulationDat // Initialize coupling data Precice_InitializeData( sim ); + // find if coupling is implicit or explicit. Implicit coupling will return true at the very beginning and explicit will always return false + sim->coupling_implicit = Precice_IsWriteCheckpointRequired(); + } void Precice_InitializeData( SimulationData * sim ) @@ -111,6 +114,11 @@ bool Precice_IsWriteCheckpointRequired() return precicec_isActionRequired( "write-iteration-checkpoint" ); } +bool Precice_IsCouplingTimestepComplete() +{ + return precicec_isCouplingTimestepComplete(); +} + void Precice_FulfilledReadCheckpoint() { precicec_fulfilledAction( "read-iteration-checkpoint" ); diff --git a/adapter/PreciceInterface.h b/adapter/PreciceInterface.h index cf7ef69..71114d0 100644 --- a/adapter/PreciceInterface.h +++ b/adapter/PreciceInterface.h @@ -133,6 +133,7 @@ typedef struct SimulationData { double coupling_init_dtheta; double precice_dt; double solver_dt; + bool coupling_implicit; } SimulationData; @@ -186,6 +187,12 @@ bool Precice_IsReadCheckpointRequired(); */ bool Precice_IsWriteCheckpointRequired(); +/** + * @brief Returns true if coupling timestep is complete + * @return + */ +bool Precice_IsCouplingTimestepComplete(); + /** * @brief Tells preCICE that the checkpoint has been read */ diff --git a/nonlingeo_precice.c b/nonlingeo_precice.c index c20c542..4ac7dab 100644 --- a/nonlingeo_precice.c +++ b/nonlingeo_precice.c @@ -1089,6 +1089,8 @@ void nonlingeo_precice(double **cop, ITG *nk, ITG **konp, ITG **ipkonp, char **l /* Adapter: Create the interfaces and initialize the coupling */ printf("About to enter preCICE setup in Calculix with names %s and %s \n", preciceParticipantName, configFilename); Precice_Setup( configFilename, preciceParticipantName, &simulationData ); + // Initialize for the first step because Precice_IsCouplingTimestepComplete will return false until the end of the first step + if( !simulationData.coupling_implicit ) Precice_WriteIterationCheckpoint( &simulationData, vini ); /* Adapter: Give preCICE the control of the time stepping */ while( Precice_IsCouplingOngoing() ){ @@ -1114,11 +1116,14 @@ void nonlingeo_precice(double **cop, ITG *nk, ITG **konp, ITG **ipkonp, char **l memcpy(&vini[0],&vold[0],sizeof(double)*mt**nk); - if( Precice_IsWriteCheckpointRequired() ) + if( Precice_IsWriteCheckpointRequired() ) // implicit coupling { Precice_WriteIterationCheckpoint( &simulationData, vini ); Precice_FulfilledWriteCheckpoint(); } + if( Precice_IsCouplingTimestepComplete() && !simulationData.coupling_implicit ) // explicit coupling + Precice_WriteIterationCheckpoint( &simulationData, vini ); + for(k=0;k<*nboun;++k){xbounini[k]=xbounact[k];} if((*ithermal==1)||(*ithermal>=3)){