code-saturne / code_saturne

code_saturne public mirror
https://www.code-saturne.org
GNU General Public License v2.0
223 stars 82 forks source link

Melissa writer works only if it outputs every time step. #13

Closed mathrack closed 6 years ago

mathrack commented 6 years ago

Dear users, developers,

Following this line of fvm_to_melissa, code_saturne works with Melissa only when data is communicated every time step. It should be possible to downsample the communication using the following modification:

-  c.writer->time_stamp = time_step;
+// Writer w has time_stamp in [0,N-1] but Melissa looks for time_stamp in [1,N]
+  c.writer->time_stamp = 1 + w->time_stamp; 

EDIT: it is actually slightly more complex to fix it, will update the post when I have a better solution

Best regards, Cedric

mathrack commented 6 years ago

Below is a workaround written for 5.0 which actually works.

diff --git a/src/fvm/fvm_to_melissa.c b/src/fvm/fvm_to_melissa.c
index 3be1313..35dfc35 100644
--- a/src/fvm/fvm_to_melissa.c
+++ b/src/fvm/fvm_to_melissa.c
@@ -153,7 +153,7 @@ _write_block_doubles_l(size_t             n_values,
   int n = (int)n_values;
   int coupling = 1;

-  if (is_init == 0 && c->writer->time_stamp > 0 && 0 == strcmp (c->name, "scalar1")) {
+  if (is_init == 0 && c->writer->time_stamp >= 0 && 0 == strcmp (c->name, "scalar1")) {
 #if defined(HAVE_MPI)
     melissa_init(c->name,
                  &n,
@@ -170,7 +170,8 @@ _write_block_doubles_l(size_t             n_values,
     is_init = 1;
   }

-  if (c->writer->time_stamp > 0 && 0 == strcmp (c->name, "scalar1")) {
+  if (c->writer->time_stamp >= 0 && 0 == strcmp (c->name, "scalar1")) {
+    c->writer->time_stamp += 1;
 #if defined(HAVE_MPI)
     melissa_send(&(c->writer->time_stamp),
                  c->name,
@@ -183,6 +184,7 @@ _write_block_doubles_l(size_t             n_values,
                         values,
                         &c->writer->simu_id);
 #endif
+    c->writer->time_stamp -= 1;
   }
 }

@@ -224,7 +226,7 @@ _field_output_g(void           *context,
   static int is_init = 0;
   int coupling = 1;

-  if (is_init == 0 && c->writer->time_stamp > 0 && 0 == strcmp (c->name, "scalar1")) {
+  if (is_init == 0 && c->writer->time_stamp >= 0 && 0 == strcmp (c->name, "scalar1")) {
     melissa_init(c->name,
                  &local_vect_size,
                  &c->writer->n_ranks,
@@ -235,12 +237,14 @@ _field_output_g(void           *context,
     is_init = 1;
   }

-  if (c->writer->time_stamp > 0 && 0 == strcmp (c->name, "scalar1")) {
+  if (c->writer->time_stamp >= 0 && 0 == strcmp (c->name, "scalar1")) {
+    c->writer->time_stamp += 1;
     melissa_send(&(c->writer->time_stamp),
                  c->name,
                  buffer,
                  &c->writer->rank,
                  &c->writer->simu_id);
+    c->writer->time_stamp -= 1;
   }
 }

@@ -678,7 +682,7 @@ fvm_to_melissa_export_field(void                  *this_writer_p,

   _melissa_context_t c;
   c.writer = w;
-  c.writer->time_stamp = time_step;
+//  c.writer->time_stamp = time_step;
   c.name = name;

   /* Per node variable */

EDIT: it would be much simpler to just remove line 681 and initialize time_stamp to 0 instead of -1