forked from zuowangda/Fast-Fluid-Dynamics
/
cosimulation.c
76 lines (58 loc) · 2.25 KB
/
cosimulation.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#ifdef _MSC_VER
#include <windows.h>
#endif
#include <stdio.h>
#include "data_structure.h"
#include "cosimulation_interface.h"
#include "utility.h"
/******************************************************************************
Read the data send from the other program
******************************************************************************/
int read_cosimulation_data(PARA_DATA *para, REAL **var)
{
int j, k;
int imax = para->geom->imax, jmax = para->geom->jmax;
int kmax = para->geom->kmax;
int IMAX = imax+2, IJMAX = (imax+2)*(jmax+2);
otherSharedData data;
REAL feak[1];
if(read_from_shared_memory(&data))
exit(1);
else
ffd_log("cosimulation.c: read data from shared memory.", FFD_NORMAL);
feak[0] = data.arr[0];
/*--------------------------------------------------------------------------
| The following code is to be modified by the users
--------------------------------------------------------------------------*/
for(j=0; j<=jmax+1; j++)
for(k=0; k<=kmax+1; k++)
var[TEMPBC][IX(imax+1,j,k)]= feak[0];
printf("\ntime=%f, status=%d\n", data.t, data.status);
printf("arr[0]=%f, arr[1]=%f, arr[2]=%f\n", data.arr[0], data.arr[1], data.arr[2]);
//printf("message=%s\n",data.message);
return 0;
} // End of read_cosimulation_data()
/******************************************************************************
Write data that will be read by other program
******************************************************************************/
int write_cosimulation_data(PARA_DATA *para, REAL **var)
{
int i;
int imax = para->geom->imax, jmax = para->geom->jmax;
int kmax = para->geom->kmax;
int IMAX = imax+2, IJMAX = (imax+2)*(jmax+2);
ffdSharedData data;
/*--------------------------------------------------------------------------
| The following code is to be modified by the users
--------------------------------------------------------------------------*/
for(i=0; i<3; i++)
data.number[i] = var[VX][IX(1,1,1)] + i;
data.status = 1;
data.t = para->mytime->t;
strcpy(data.message, "This is FFD data\0");
if(write_to_shared_memory(&data))
exit(1);
else
ffd_log("cosimulation.c: write data to shared memory.", FFD_NORMAL);
return 0;
} // End of write_cosimulation_data()