i-RIC / iriclib

1 stars 3 forks source link

encapsulate data #60

Open rmcd-mscb opened 4 years ago

rmcd-mscb commented 4 years ago

Would it be possible to make sure the iriclib data are encapsulated? When multiple models are run as in an coupled modeling situation, all output is written to the second initialized model. It maybe as simple as encapsulating the FID of the cgns file.

kskinoue0612 commented 4 years ago

Hello, thanks for your question.

I'm not sure, but I guess we have a solution for such cases. I guess now you use cg_iric_write_sol_real_f, to output result. Please use cg_iric_write_sol_real_mul_f instead, and give different FID values from each models. Each model has different FID values, that it gets when calling cg_open_f.

Thanks, Keisuke

rmcd-mscb commented 4 years ago

Hi Keisuke, Thanks for your suggestion. Using the *mul_f functions work with one exception. On the second declared object that is writing to cgns with iriclib, it writes a bunch of PolydataSolutionX groups with no data, where X is a number. Otherwise it writes the solution correctly. Would you have any insight? The model has not calls to write PolydataSolutions. I've attached the two cgn files in a zip file.

Thanks, Rich conflicting_instances_test_2.zip

kskinoue0612 commented 4 years ago

Hi Rich,

Thanks for your information. I've checked the files you've uploaded, and it seems that the files looks invalid, as you've mentioned.

conf_instances_test_1.cgn should have 10 PolydataSolutionX groups, and conf_instances_test_2.cgn should have 10 PolydataSolutionX groups.

But actually, conf_instances_test_1.cgn have no PolydataSolutionX group, and conf_instances_test_2.cgn have 50 PolydataSolutionX groups. Very strange.

I imagined maybe iriclib has a bug. I checked the code of CgnsFile::Impl::addSolutionNode(), defined at https://github.com/i-RIC/iriclib/blob/master/iriclib_cgnsfile_base.cpp#L704-L732, and it seems right. The code will generate the same number of PolydataSolutionX groups to FlowSolutionX groups etc.

As attached below, I've wrote a test program, and it creates the same number of PolydataSolutionX groups for each CGNS files.

test_program.zip

The content of test.c is as below. cg_iRIC_Write_Sol_Time_Mul() creates PolydataSolutionX groups etc.

#include "cgnslib.h"
#include <iriclib.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(int argc, char* argv) {
    int fin1, fin2, ier;
    int locked;
    int canceled;
    char* fname1 = "test1.cgn";
    char* fname2 = "test2.cgn";

    ier = cg_open(fname1, CG_MODE_MODIFY, &fin1);
    if (ier != 0){
        printf("*** Open error of CGNS file 1 ***\n");
        return 1;
    }
    ier = cg_open(fname2, CG_MODE_MODIFY, &fin2);
    if (ier != 0){
        printf("*** Open error of CGNS file 2 ***\n");
        return 1;
    }

    ier = cg_iRIC_Init(fin1);
    ier = cg_iRIC_Init(fin2);

    for (int i = 0; i < 10; ++i) {
        double time = i;
        ier = cg_iRIC_Write_Sol_Time_Mul(fin1, time);
        ier = cg_iRIC_Write_Sol_Time_Mul(fin2, time);
    }

    cg_close(fin1);
    cg_close(fin2);

    return 0;
}

You can test with the following operations. I hope you'll have the same CGNS files that I put into "output" folder in "test_program.zip".

  1. Build test.c.
  2. Copy cgnsdll.dll, iriclib.dll, hdf5.dll, szip.dll, zlib.dll to the folder where test.exe exists, from the folder where iRIC.exe exists.
  3. Copy test1.cgn, test2.cgn from "input" folder to the folder where test.exe exists.
  4. Run test.exe.

Can you create a simple program like this, to reproduce the issue you have?

Thanks, Keisuke