From 0e035eaf4e702898143111fa4d9c58a155a37b38 Mon Sep 17 00:00:00 2001 From: nkr <42086312+nkr0@users.noreply.github.com> Date: Wed, 27 Nov 2019 18:02:35 +0100 Subject: [PATCH 1/3] save state after every iteration in explicit coupling --- adapter/PreciceInterface.c | 3 +++ adapter/PreciceInterface.h | 1 + nonlingeo_precice.c | 4 ++-- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/adapter/PreciceInterface.c b/adapter/PreciceInterface.c index d358e1c..c01f1a9 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_explicit = !Precice_IsWriteCheckpointRequired(); + } void Precice_InitializeData( SimulationData * sim ) diff --git a/adapter/PreciceInterface.h b/adapter/PreciceInterface.h index cf7ef69..e3f210e 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_explicit; } SimulationData; diff --git a/nonlingeo_precice.c b/nonlingeo_precice.c index c20c542..e8f165b 100644 --- a/nonlingeo_precice.c +++ b/nonlingeo_precice.c @@ -1114,10 +1114,10 @@ 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() || simulationData.coupling_explicit) { Precice_WriteIterationCheckpoint( &simulationData, vini ); - Precice_FulfilledWriteCheckpoint(); + if( Precice_IsWriteCheckpointRequired() ) Precice_FulfilledWriteCheckpoint(); } for(k=0;k<*nboun;++k){xbounini[k]=xbounact[k];} From 5c16d6e200854be50c0cc5ffaacd89018d755531 Mon Sep 17 00:00:00 2001 From: nkr Date: Fri, 29 Nov 2019 10:59:34 +0100 Subject: [PATCH 2/3] implict boolean --- adapter/PreciceInterface.c | 2 +- adapter/PreciceInterface.h | 2 +- nonlingeo_precice.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/adapter/PreciceInterface.c b/adapter/PreciceInterface.c index c01f1a9..32afd5c 100644 --- a/adapter/PreciceInterface.c +++ b/adapter/PreciceInterface.c @@ -48,7 +48,7 @@ void Precice_Setup( char * configFilename, char * participantName, SimulationDat 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_explicit = !Precice_IsWriteCheckpointRequired(); + sim->coupling_implicit = Precice_IsWriteCheckpointRequired(); } diff --git a/adapter/PreciceInterface.h b/adapter/PreciceInterface.h index e3f210e..62f06b1 100644 --- a/adapter/PreciceInterface.h +++ b/adapter/PreciceInterface.h @@ -133,7 +133,7 @@ typedef struct SimulationData { double coupling_init_dtheta; double precice_dt; double solver_dt; - bool coupling_explicit; + bool coupling_implicit; } SimulationData; diff --git a/nonlingeo_precice.c b/nonlingeo_precice.c index e8f165b..ded5361 100644 --- a/nonlingeo_precice.c +++ b/nonlingeo_precice.c @@ -1114,7 +1114,7 @@ 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() || simulationData.coupling_explicit) + if( Precice_IsWriteCheckpointRequired() == simulationData.coupling_implicit) { Precice_WriteIterationCheckpoint( &simulationData, vini ); if( Precice_IsWriteCheckpointRequired() ) Precice_FulfilledWriteCheckpoint(); From d1a4f5aa20eb39e9021b2bebdd0c7a5be485991c Mon Sep 17 00:00:00 2001 From: nkr Date: Fri, 29 Nov 2019 15:54:19 +0100 Subject: [PATCH 3/3] save every coupling iteration, not sub-cycle --- adapter/PreciceInterface.c | 5 +++++ adapter/PreciceInterface.h | 6 ++++++ nonlingeo_precice.c | 9 +++++++-- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/adapter/PreciceInterface.c b/adapter/PreciceInterface.c index 32afd5c..f80c1ef 100644 --- a/adapter/PreciceInterface.c +++ b/adapter/PreciceInterface.c @@ -114,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 62f06b1..71114d0 100644 --- a/adapter/PreciceInterface.h +++ b/adapter/PreciceInterface.h @@ -187,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 ded5361..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() == simulationData.coupling_implicit) + if( Precice_IsWriteCheckpointRequired() ) // implicit coupling { Precice_WriteIterationCheckpoint( &simulationData, vini ); - if( Precice_IsWriteCheckpointRequired() ) Precice_FulfilledWriteCheckpoint(); + 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)){