CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   Fluent UDF and Scheme Programming (https://www.cfd-online.com/Forums/fluent-udf/)
-   -   Data access in define macros (https://www.cfd-online.com/Forums/fluent-udf/105111-data-access-define-macros.html)

Magneto July 23, 2012 11:24

Data access in define macros
 
Hi Everyone,

I am writing a DEFINE_SOURCE macro where I need to access data in other cells (not just the current cell's neighbors) in order to calculate the source term for the current cell. Does anyone know how to do this?

Thanks!

flotus1 July 23, 2012 13:49

If you have very few cells, you can add a loop over all the cells to the DEFINE_SOURCE macro and read the variables here.

Or you could define a user defined memory and store the desired variable here. In the DEFINE_SOURCE macro, you can then read the UDM for every cell.

I don't know if a cell value of a certain cell can be read directly.

Magneto July 23, 2012 13:54

Right, looping over the other cells is exactly what I want to do, but I don't know the syntax for that. Do you? Thanks for your reply!

Magneto July 23, 2012 15:16

Just to clarify, I know begin_c_loop...end_c_loop loops over the cells, but I don't know how to initialize the cell and thread that should be inputs to this loop.

flotus1 July 23, 2012 17:00

Until now, I haven't given any thought about that.

I just used begin_c_loop(c,t).
I guess the thread is the same on which the source is applied in this case.

Magneto July 23, 2012 17:17

Using the same thread pointer causes an error (with no useful information in the error dialog.) After digging through a lot of fluent documentation, I think the solution might be to nest a begin_c_loop...end_c_loop inside a thread_loop_c. I will try this and post whether it works for other people following this message thread. I'd love to hear from anyone who has done this before and has advice on how to implement it.

flotus1 July 25, 2012 04:20

I can only say that I dit it like this without geting an error message.
But if it really doesn't work, you can still use a UDM.

Magneto July 25, 2012 08:22

The cell loop nested within the thread loop works without errors, but it's clear that it is only counting about half the cells. I also tried specifically looping over the interior zone (got the zone ID from fluent's cell zone conditions GUI) with the same problem. The number of cells that get counted seems to be affected by whether I am processing the solution in serial or parallel. Very strange!

flotus1 July 25, 2012 08:27

But you do know that a UDF has to be modified in order to work properly in a parallel computation?

Magneto July 25, 2012 10:32

I was actually not aware of this, so thanks for the tip. I won't ask you to explain how to modify the UDF here since I imagine it's nontrivial (and probably something I can look up), but I'll take a look at the Fluent documentation and stick to serial until I figure it out.

Cheers!

flotus1 July 25, 2012 10:36

I am very glad that you didn't ask, because I actually don't know ;)

Magneto July 25, 2012 12:22

Just for future reference (and for anyone else reading this thread), here's what I've found out so far. In parallel mode, Fluent's central controller breaks the domain into discrete chunks of cells for each processor to solve, but the chunks have to share boundary cells because they need to pass information between the domains (mass flux, face pressure, etc.) In a UDF that has to loop over all the cells in the domain (like mine), you have to specifically tell the processors to loop over only the internal cells because otherwise the boundary cells get counted twice.

I may keep my UDF in serial because it looks like I would also have to implement a more complicated message passing system between the processors (which all work with different sets of threads) in order to simultaneously access the cell where I'm calculating the source term and the cell that's remotely causing the force (since the two cells may belong to different processors.)


All times are GMT -4. The time now is 14:23.