CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Running, Solving & CFD (https://www.cfd-online.com/Forums/openfoam-solving/)

 xiao September 3, 2008 22:30

Hi all, I have a question

Hi all,

I have a question encountered during code coupling (coupling OF with an external code). Any suggestions would be appreciated!

During coupling, OF needs to give a "vector array" to the external code (say, the velocity at N points). Suppose this velocity array is declared as:

vector vp[4];
The values are:
vp[0] = (v0x, v0y, v0z);
vp[1] = (v1x, v1y, v1z);
...
vp[N-1] = (vnx, vny, vnz);

However, the external code does not have a "vector" data structure. Instead, it assume the velocity to be 1D array of size (3*N), N being the number of point. In this case, "vp" need to be as follows in order to be passed to this external code:

double vp[3*N];

vp ={v0x, v0y, v0z, v1x, v1y, v1z, ... }

Now, every time during the "communication" of the the two code, I setup a temperary array "vtmp", copy the velocity components from the vector array to a regular 1D array "vtmp", and then pass "vtmp" to the external code. When the array size N is big and the communication is frequent, this waste a lot of time.

Could any one give me a better suggestion? Particularly, is there any structure we can assume about the storage of the components of "vector" data structure? say, are the components contiguous in the memory? e.g. in the example above, is "v0x" and "v0y" next to each other in the memory? or even further, are "v0z" and "v1x" next to each other?