CFD Online Discussion Forums

CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   FLUENT (http://www.cfd-online.com/Forums/fluent/)
-   -   Looping over cells (http://www.cfd-online.com/Forums/fluent/29558-looping-over-cells.html)

Karl March 26, 2002 11:18

Looping over cells
 
I have written a simple udf that loops over all the cells in a single cell zone of my domain, and writes values of certain flow variables in these cells to a file. (The entire domain consists of two zones, one zone is sliding, the other zone for which cell looping is being done is stationary).

My udf works fine on NT serial solver. When I run on SGI parallel solver, only about 1/4th of the cells are being written. The mesh is partitioned into four partitions. It seems like only cells in a single partition are being looped over (I have no way to check for sure though, since there is no simple way to know which cells are in which partition - and I would like to avoid this kind of lengthy analysis anyway).

I know that in some cases for NT you are supposed to do something special for parallel solver, but I do not see anything special to be done in writing the udf for parallel solver.

I am wondering if anyone has encountered this problem with Fluent 6, and also if anyone has specific suggestions to resolve.

Thanks


Greg Perkins March 26, 2002 21:56

Re: Looping over cells
 
There's a couple of points to your problem.

First when writing files for a parallel program requires some additional thought. If all your parallel nodes write to the file at the same time, the results are not defined, unless you implement some sort of access control strategy to avoid clashes between the nodes when writing to the same file. This is a fairly well-known problem in parallel programming.

One way around this in Fluent is to restrict writing to the file to just one of the nodes. However, this creates a potential problem since this node can only access the cells on its partition and the common ones at the partition boundaries.

Another way is to get each node to write to a separate file and then once all nodes have completed this task, concatenate the node files into a single file.

This is relatively easy to do (I think). First define the filename based on the node number. Fluent uses nodes and 1 host. A node is defined and its partition number of process id is given by my_id.

#if RP_NODE /* --- I'm a ndoe process - id = my_id */ node_id = my_id; #endif

So you can create a filename using my_id in the name. Then run your udf with this mod.

Then write another udf or script to concatenate the files. If you use a udf for this, you'll have to get the total number of processes. I recommended running this udf only on the host process. The host is defined as:

#if !RP_NODE

/* --- I'm a host process ! */ #endif

I just had a look at para.h and there is a variable called compute_node_count which looks like it would contain the total number of compute nodes. You can also find looping macros which will enable you to loop over your files and then concatenate into a single one.

Hope it Helps Greg

Greg Perkins March 26, 2002 22:16

Re: Code Snippets for You
 
Here's some code snippets for how to do what I suggested:

/* --- node file writer */ DEFINE_ON_DEMAN(EXEC_Write_Node_File) { #if RP_NODE

char filename[100];

sscanf(filename,"cell_file_node-%d",my_id);

/* ---- write you cell data to this file as before */

#endif }

/* ---- concatenate files together */ DEFINE_ON_DEMAND(EXEC_Concate_Files) { #if !RP_NODE

int i;

/* --- open a main output file here */

/* --- loop over node files */

for(i=0; i<compute_node_count; i++)

{

/* --- read node file i and write to main output file */

/* --- close node file i */

}

/* --- close main file */

#endif }

Let me know if it works since I haven't tried this before and just made it up then!

Greg

Greg Perkins March 26, 2002 22:17

Re: Code Snippets for You - Opps
 
the loop over compute ndoes line should be:

for(i=0; i<compute_node_count; i++)

Greg

Greg Perkins March 26, 2002 22:18

Re: Code Snippets for You - OppsAgain
 
Something wrong with browser try:

for(i=0; i .LE. compute_node_number; i++)

and replace .LE. with less than equal to sign for C.

Greg


All times are GMT -4. The time now is 04:59.