CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > ANSYS > FLUENT > Fluent UDF and Scheme Programming

Using UDF cluster

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   April 9, 2018, 05:38
Default Using UDF cluster
  #1
New Member
 
André Domingues
Join Date: Apr 2018
Posts: 5
Rep Power: 8
André_UFC is on a distinguished road
Hello everybody

I'm using a UDF for a porous zone in fluent. The problem is that in local, my UDF works, but when i load it to the cluster it doesn't work.

I define my porous zone like a polygon. The stranger thing is when i use a square porous zone the UDF works in local and in the cluster.

Square porous zone:

Code:
#include "udf.h" 
#include "mem.h"

#define X1_MAX 0.048473779
#define X1_MIN 0.04737793
#define Y1_MAX 0.016324
#define Y1_MIN 0.0158501
#define C1 7000000.0
#define C2 8000000.0
 
DEFINE_SOURCE(axis1_source_adm_haut,c,t,dS,eqn) 
{
    #if !RP_HOST 
    
        real pos[ND_ND]; 
        real con, source, x, y; 
        
        C_CENTROID(pos,c,t); 
        x = pos[0]; 
        y = pos[1]; 
        
        if ((x > X1_MIN) && (x < X1_MAX) && (y > Y1_MIN) && (y < Y1_MAX)) 
        { 
                con = C1*0.5*C_R(c,t); 
                source = -con*fabs(C_U(c, t))*C_U(c, t); 
                dS[eqn] = -2.*con*fabs(C_U(c, t)); 
        }         
        else source=0;
        
        return source; 
        
    #endif 
}

DEFINE_SOURCE(radial1_source_adm_haut,c,t,dS,eqn) 
{ 
    #if !RP_HOST 
    
        real pos[ND_ND]; 
        real con, source, x, y; 
        
        C_CENTROID(pos,c,t); 
        x = pos[0]; 
        y = pos[1];
        
        if ((x > X1_MIN) && (x < X1_MAX) && (y > Y1_MIN) && (y < Y1_MAX)) 
        { 
            con = C2*0.5*C_R(c,t); 
            source = -con*fabs(C_V(c, t))*C_V(c, t); 
            dS[eqn] = -2.*con*fabs(C_V(c, t)); 
        } 
        else         source=0; 
        
        return source; 
        
    #endif 
}
Polygon porous zone:

Code:
#include "udf.h" 
#include "mem.h"

#define Xa 0.0475262209003453
#define Xb 0.048
#define Xc 0.0484737790996547
#define Xd 0.048
#define Ymax 0.0163238790996548
#define Ymin 0.0158501
#define Ca 700000000.0
#define Cb 800000000.0


DEFINE_SOURCE(axis1_source_adm_haut,c,t,dS,eqn) 
{
    #if !RP_HOST 
    
        real pos[ND_ND]; 
        real con, source, x, y; 
        real mda, mdb, ba, bb, da, db;

        mda = (Ymax-Ymin)/(Xa-Xd);
        mdb = (Ymax-Ymin)/(Xb-Xc);
        
        ba = Ymax-mda*Xa;
        bb = Ymax-mdb*Xb;
        
        da = mda*x+ba;
        db = mdb*x+bb;
        
        C_CENTROID(pos,c,t); 
        x = pos[0]; 
        y = pos[1]; 
                
        if ((y >= da) && (y <= db) && (y > Ymin) && (y < Ymax)) 
        { 
                con = Ca*0.5*C_R(c,t); 
                source = -con*fabs(C_U(c, t))*C_U(c, t); 
                dS[eqn] = -2.*con*fabs(C_U(c, t)); 
        }         
        else         source=0; 
        
        return source; 
        
    #endif 
}

DEFINE_SOURCE(radial1_source_adm_haut,c,t,dS,eqn) 
{ 
    #if !RP_HOST 
    
        real pos[ND_ND]; 
        real con, source, x, y; 
        real mda, mdb, ba, bb, da, db;

        mda = (Ymax-Ymin)/(Xa-Xd);
        mdb = (Ymax-Ymin)/(Xb-Xc);
        
        ba = Ymax-mda*Xa;
        bb = Ymax-mdb*Xb;
        
        da = mda*x+ba;
        db = mdb*x+bb;
        
        C_CENTROID(pos,c,t); 
        x = pos[0]; 
        y = pos[1];
        
        if ((y >= da) && (y <= db) && (y > Ymin) && (y < Ymax))   
        { 
            con = Cb*0.5*C_R(c,t); 
            source = -con*fabs(C_V(c, t))*C_V(c, t); 
            dS[eqn] = -2.*con*fabs(C_V(c, t)); 
        } 
        else         source=0; 
        
        return source; 
        
    #endif 
}
Someone have a idea why my code doesn't work in the cluster?

Thank's!
André_UFC is offline   Reply With Quote

Old   April 9, 2018, 11:47
Default
  #2
Senior Member
 
Join Date: Sep 2017
Posts: 246
Rep Power: 11
obscureed is on a distinguished road
Hi André_UFC,

My comments are not related to parallel, but they might be helpful:

(1) It would be safer to set "dS[eqn]=0.0;" in the "else" branch.
(2) In the polygon code, your calculations of da and db use x before x has been given its correct value. Maybe the question should be why it works locally?
(3) It would be good practice to define a function called test_inside or whatever, which you use in both UDFs. You could pass the cell as the arguments (cell_t c, Thread *t), but it might be easier to pass the array pos, and easier still to pass (real x, real y). Defining extra functions always feels like bureaucracy and extra effort, but it will pay for itself fairly quickly in a situation like this.
(4) I always feel more nervous seeing "if(x > X1_MIN)" than "if(x >= X1_MIN)", for example. It seems more likely that x==X1_MIN is just about acceptable. But this is probably a very minor detail.

Apart from this, I can't see any issues that are likely to cause trouble with parallel/serial or a different compiler (which is one sneaky cause of issues occasionally -- as usual, remember to read any warnings). I suspect that you don't get any benefit from "#include mem.h" or "#if !RP_HOST ... #endif", but I certainly hope that they don't break anything.

It's a relief that Ymin protects us from having to think about radial momentum sources at the axis.

Good luck!
Ed
obscureed is offline   Reply With Quote

Old   April 10, 2018, 03:00
Default
  #3
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 26
pakk will become famous soon enough
In addition to Obscureed's comments: you say that your code "doesn't work" on the cluster. This is rather vague, be more specific. What does "doesn't work" mean?

* does not compile
* gives segmentation fault
* gives different error
* crashes fluent
* gives wrong results
* something else
pakk is offline   Reply With Quote

Old   April 12, 2018, 05:36
Default
  #4
New Member
 
André Domingues
Join Date: Apr 2018
Posts: 5
Rep Power: 8
André_UFC is on a distinguished road
Thank you for your answers!

Hello Pakk, i don't have any error or warning in fluent command or cluster, when i compiled my UDF. That's why it was weird it works in local but not in the cluster.

So i did change the value of "dS[eqn]=0.0". And it worked! Now i can see the porous zone. Thank's a lot Obscureed
André_UFC is offline   Reply With Quote

Old   April 12, 2018, 06:15
Default
  #5
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 26
pakk will become famous soon enough
Nice that it works now, but for next time: you still did not explain what "doesn't work" means.

You say that there was no error or warning on the cluster, or on Fluent. Great, but what made you say that it "doesn't work"? Explain that next time!
pakk is offline   Reply With Quote

Old   April 12, 2018, 07:25
Default
  #6
New Member
 
André Domingues
Join Date: Apr 2018
Posts: 5
Rep Power: 8
André_UFC is on a distinguished road
It means the cluster server read the UDF but don't applied it. However, when i use the UDF in local, the porous zone it's visible. I used the same code, and the same files, to the both. And i don't know why, but when i change the "dS" (Array that contains the derivative of the source term with respect to the dependent variable of the transport equation) from dS[eqn] = -2.*con*fabs(C_U(c, t)) to dS[eqn] = 0.0 , the cluster applied the porous zone in my geometry.
André_UFC is offline   Reply With Quote

Old   April 12, 2018, 10:39
Default
  #7
Senior Member
 
Join Date: Sep 2017
Posts: 246
Rep Power: 11
obscureed is on a distinguished road
Hi there,

This is all rather mysterious. I would strongly advise you to find out what is going wrong (and right). Do not trust a UDF just because it looks approximately correct once.

I should have prioritised my suggestions better:
*** Point (2) is essential! *** The code as you posted should not work! -- in C, variables are not automatically initialised, and can contain any old junk (though some compilers might put in zero values -- which sometimes stops complete madness from breaking out, but also hides the problem).

Point (1) is just a preference, and it applies to the "else source=0;" branch of the if statement. In the main branch, your earlier version of dS[eqn] looks correct, based on your choices of source (which I question below), and the correct value of dS should be beneficial.

Earlier I did not look at your definition of source, because that was not the question. Now that I have looked, I strongly suspect it is not what you intend. If we assume temporarily that C_U and C_V are both positive, then you have one component (-con*C_U*C_U) and a perpendicular component (-con*C_V*C_V). So the magnitude of the overall 2D force is con*sqrt(C_U^4+C_V^4). As I say, this is probably not what you wanted. I will leave you to work through the details, but if you end up with something like (-con*C_U*sqrt(C_U*C_U+C_V*C_V)) and (-con*C_V*sqrt(C_U*C_U+C_V*C_V)) then I will find it easier to agree. The derivatives of these are more complicated, and I would be tempted to approximate them.

A thorough check would be to run a test, check the pressure drop (in parallel and in serial) against theory, and then rotate the mesh and look for the same answer. You could rotate by 45degrees, but that would not find some errors where wires were crossed -- a less neat angle would be a better test.

You're making progress, but you should not relax yet! Good luck,
Ed
obscureed is offline   Reply With Quote

Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help with unsteady calculation with source/sink UDF RobV FLUENT 1 November 13, 2016 05:44
problem loading UDF library in parallel cluster Veera Gutti FLUENT 8 July 26, 2016 07:24
Help with unsteady calculation with source/sink UDF RobV Fluent UDF and Scheme Programming 3 March 10, 2016 03:45
parse error while interpreting udf Kristin Fluent UDF and Scheme Programming 3 March 15, 2012 06:43
UDF, UDF, UDF, UDF Luc SEMINEL Main CFD Forum 0 November 25, 2002 04:01


All times are GMT -4. The time now is 21:49.