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

Different values for identical UDS and UDM

Register Blogs Members List Search Today's Posts Mark Forums Read

Reply
 
LinkBack Thread Tools Display Modes
Old   August 7, 2015, 14:19
Post Different values for identical UDS and UDM
  #1
Member
 
Farzin
Join Date: Jul 2014
Posts: 41
Rep Power: 4
FarzinD is on a distinguished road
Hello everyone,
I wrote a UDF that calculates a quantity for a User Defined Scalar, then in another c_loop values of UDS are stored in a User Defined Memory.
After calculations, contours of the UDM and UDS differ from each other significantly.
It seems that UDM contour is the correct one. But why they are different?

Thanks for any suggestion,
Farzin
FarzinD is offline   Reply With Quote

Old   August 11, 2015, 05:32
Default
  #2
Senior Member
 
Bruno Machado
Join Date: May 2014
Posts: 262
Rep Power: 5
Bruno Machado is on a distinguished road
Could you post the part of the code you are talking about?
Them we can see if there is any mistake and help you.
Bruno Machado is offline   Reply With Quote

Old   August 11, 2015, 07:59
Default
  #3
Member
 
Farzin
Join Date: Jul 2014
Posts: 41
Rep Power: 4
FarzinD is on a distinguished road
Quote:
Originally Posted by Bruno Machado View Post
Could you post the part of the code you are talking about?
Them we can see if there is any mistake and help you.
One thing I'm suspicious of is that I didn't allocate face values of UDM and the contours are face values indeed.
Here's the related part of the UDF:
Code:
DEFINE_ADJUST(adjust_vorticity_calc,domain)
{
    int n;
    Thread *t,t0,t1;
    cell_t c,c0,c1;
    face_t f;

    //Calculating Vorticity for Cell Centers
    thread_loop_c(t,domain)
    {
        begin_c_loop(c,t)
        {
            C_UDSI(c,t,Vorticity_I) = VORI(c,t);
            C_UDSI(c,t,Vorticity_J) = VORJ(c,t);
            C_UDSI(c,t,Vorticity_K) = VORK(c,t);
        }
        end_c_loop(c,t);
    }

    //Calculating Vorticity Derivatives
    for (n=Vorticity_I; n<Vorticity_I+3; n++)
    {
        uds_derivatives(domain,n);
    }


    thread_loop_c(t,domain)
    {
        begin_c_loop(c,t)
        {
            C_UDMI(c,t,Vorticity_I) = C_UDSI(c,t,Vorticity_I);
            C_UDMI(c,t,Vorticity_J) = C_UDSI(c,t,Vorticity_J);
            C_UDMI(c,t,Vorticity_K) = C_UDSI(c,t,Vorticity_K);
            ND_D(C_UDSI(c,t,G_Vorticity_Ix),C_UDSI(c,t,G_Vorticity_Iy),C_UDSI(c,t,G_Vorticity_Iz),=,\
                C_UDSI_G(c,t,Vorticity_I)[0],C_UDSI_G(c,t,Vorticity_I)[1],C_UDSI_G(c,t,Vorticity_I)[2]);
            ND_D(C_UDSI(c,t,G_Vorticity_Jx),C_UDSI(c,t,G_Vorticity_Jy),C_UDSI(c,t,G_Vorticity_Jz),=,\
                C_UDSI_G(c,t,Vorticity_J)[0],C_UDSI_G(c,t,Vorticity_J)[1],C_UDSI_G(c,t,Vorticity_J)[2]);
            ND_D(C_UDSI(c,t,G_Vorticity_Kx),C_UDSI(c,t,G_Vorticity_Ky),C_UDSI(c,t,G_Vorticity_Kz),=,\
                C_UDSI_G(c,t,Vorticity_K)[0],C_UDSI_G(c,t,Vorticity_K)[1],C_UDSI_G(c,t,Vorticity_K)[2]);
        }
        end_c_loop(c,t);
    }
}



void uds_derivatives(Domain *domain, int n)
{
    MD_Alloc_Storage_Vars(domain, SV_UDSI_RG(n), SV_UDSI_G(n), SV_NULL);
    Scalar_Reconstruction(domain, SV_UDS_I(n), -1, SV_UDSI_RG(n), NULL);
    Scalar_Derivatives(domain, SV_UDS_I(n), -1, SV_UDSI_G(n), SV_UDSI_RG(n), NULL);
    return;
}
FarzinD is offline   Reply With Quote

Old   August 11, 2015, 08:52
Default
  #4
Senior Member
 
Bruno Machado
Join Date: May 2014
Posts: 262
Rep Power: 5
Bruno Machado is on a distinguished road
Are you plotting in the Fluent software or in the CFD-Post?
If fluent, plot the results of the CELL and try to compare both. Should be same. If you are plotting the NODE values, it can be different since it is a average.
Bruno Machado is offline   Reply With Quote

Old   August 11, 2015, 09:21
Default
  #5
Member
 
Farzin
Join Date: Jul 2014
Posts: 41
Rep Power: 4
FarzinD is on a distinguished road
I'm plotting computed cell values in FLUENT, not node values.
This order of difference cannot be made by averaging;
UDS-UDM.jpg
FarzinD is offline   Reply With Quote

Old   August 11, 2015, 09:39
Default
  #6
Senior Member
 
Bruno Machado
Join Date: May 2014
Posts: 262
Rep Power: 5
Bruno Machado is on a distinguished road
Make a test, plot the values of the UDS and UDM in the GUI.

Add this in your code, after saying UDS=UDM and run one iteration.

if((c%2000) == 0)
Message("UDM Vor_I %f UDS Vor_I%f\n UDM Vor_J %f UDS Vor_J%f\n UDM Vor_K %f UDS Vor_K%f\n" C_UDMI(c,t,Vorticity_I), C_UDSI(c,t,Vorticity_I), C_UDMI(c,t,Vorticity_J), C_UDSI(c,t,Vorticity_J), C_UDMI(c,t,Vorticity_K), C_UDSI(c,t,Vorticity_K));
Bruno Machado is offline   Reply With Quote

Old   August 11, 2015, 09:55
Default
  #7
Senior Member
 
Bruno Machado
Join Date: May 2014
Posts: 262
Rep Power: 5
Bruno Machado is on a distinguished road
What I would also suggest is to add this part in an EXECUTE_AT_THE_END macro instead of putting it in the ADJUST macro

thread_loop_c(t,domain)
{
begin_c_loop(c,t)
{
C_UDMI(c,t,Vorticity_I) = C_UDSI(c,t,Vorticity_I);
C_UDMI(c,t,Vorticity_J) = C_UDSI(c,t,Vorticity_J);
C_UDMI(c,t,Vorticity_K) = C_UDSI(c,t,Vorticity_K);
ND_D(C_UDSI(c,t,G_Vorticity_Ix),C_UDSI(c,t,G_Vorti city_Iy),C_UDSI(c,t,G_Vorticity_Iz),=,\
C_UDSI_G(c,t,Vorticity_I)[0],C_UDSI_G(c,t,Vorticity_I)[1],C_UDSI_G(c,t,Vorticity_I)[2]);
ND_D(C_UDSI(c,t,G_Vorticity_Jx),C_UDSI(c,t,G_Vorti city_Jy),C_UDSI(c,t,G_Vorticity_Jz),=,\
C_UDSI_G(c,t,Vorticity_J)[0],C_UDSI_G(c,t,Vorticity_J)[1],C_UDSI_G(c,t,Vorticity_J)[2]);
ND_D(C_UDSI(c,t,G_Vorticity_Kx),C_UDSI(c,t,G_Vorti city_Ky),C_UDSI(c,t,G_Vorticity_Kz),=,\
C_UDSI_G(c,t,Vorticity_K)[0],C_UDSI_G(c,t,Vorticity_K)[1],C_UDSI_G(c,t,Vorticity_K)[2]);
}
end_c_loop(c,t);
}
Bruno Machado is offline   Reply With Quote

Old   August 11, 2015, 10:34
Default
  #8
Member
 
Farzin
Join Date: Jul 2014
Posts: 41
Rep Power: 4
FarzinD is on a distinguished road
Thank you Bruno, for your time and effort.
Printed values of the UDMs and UDSs are all equal.
Plus, plot of vorticity values calculated by FLUENT is very similar to UDM (which should be the same as UDS values). So the problem should be due to the way they're plotted.
My concern was vorticity (UDS) and its gradient which are used in another UDF, are not correct.
FarzinD is offline   Reply With Quote

Old   August 11, 2015, 10:50
Default
  #9
Senior Member
 
Bruno Machado
Join Date: May 2014
Posts: 262
Rep Power: 5
Bruno Machado is on a distinguished road
Glad I could help you.

Just to make sure the value you are getting is the correct one and the difference is in the plotting, you could compute the other UDF using the value of the UDM and from the UDS. You should get the same value.
Bruno Machado is offline   Reply With Quote

Old   August 11, 2015, 11:04
Default
  #10
Member
 
Farzin
Join Date: Jul 2014
Posts: 41
Rep Power: 4
FarzinD is on a distinguished road
I just replaced the whole ADJUST function by AT_THE_END, and now the vorticity UDS and UDM plots are both exactly the same as the one calculated by FLUENT.
Still don't know why but this solved the problem.
Thank you Bruno for the suggestion.
FarzinD is offline   Reply With Quote

Old   August 11, 2015, 11:33
Default
  #11
Senior Member
 
Bruno Machado
Join Date: May 2014
Posts: 262
Rep Power: 5
Bruno Machado is on a distinguished road
I think it is because fluent solve all the equations you imputed before solving the governing equations, so your current value of some variables actually were the value of previous iteration. But glad you solve the problem.
Bruno Machado is offline   Reply With Quote

Old   January 26, 2016, 12:07
Default
  #12
Senior Member
 
Przemek
Join Date: Jun 2011
Posts: 133
Rep Power: 7
gaza is on a distinguished road
Hi Bruno,
I have such a code:
Code:
/********************************************************************
 
 *********************************************************************/
 #include "udf.h"
DEFINE_EXECUTE_AT_END(myFunc)
{
 Domain *d;
 Thread *t;
 /* Integrate dissipation. */
 real sum_diss=0.;
 cell_t c;
 d = Get_Domain(1); /* mixture domain if multiphase */
 thread_loop_c(t,d)
 {
 if (FLUID_THREAD_P(t))
 {
 begin_c_loop(c,t)
 C_UDMI(c,t,0) = C_T(c,t);
 end_c_loop(c,t)
 }
 }

 }
I wanto to write temperature to my UDM. However after the calculations in the post
Static temperature and User memory 0 differ (exactly only in one location = at boundary). Can you tell what I am doing wrong?
__________________
best regards
pblasiak
gaza is offline   Reply With Quote

Old   January 26, 2016, 13:17
Default
  #13
Member
 
Farzin
Join Date: Jul 2014
Posts: 41
Rep Power: 4
FarzinD is on a distinguished road
Quote:
Originally Posted by gaza View Post
Hi Bruno,
I have such a code:
Code:
/********************************************************************
 
 *********************************************************************/
 #include "udf.h"
DEFINE_EXECUTE_AT_END(myFunc)
{
 Domain *d;
 Thread *t;
 /* Integrate dissipation. */
 real sum_diss=0.;
 cell_t c;
 d = Get_Domain(1); /* mixture domain if multiphase */
 thread_loop_c(t,d)
 {
 if (FLUID_THREAD_P(t))
 {
 begin_c_loop(c,t)
 C_UDMI(c,t,0) = C_T(c,t);
 end_c_loop(c,t)
 }
 }

 }
I wanto to write temperature to my UDM. However after the calculations in the post
Static temperature and User memory 0 differ (exactly only in one location = at boundary). Can you tell what I am doing wrong?

It's because you didn't assign UDM value for the boundary and you're trying to get it.
Actually, the value you get is an interpolated value calculated by fluent.
If you want to set values of a boundary to the UDM, you should also add face UDM.
Try this one:

Code:
#include "udf.h"
DEFINE_EXECUTE_AT_END(myFunc)
{
 Domain *d;
 /* Integrate dissipation. */
 real sum_diss=0.;
 cell_t c;
 Thread *t;
 d = Get_Domain(1); /* mixture domain if multiphase */
 thread_loop_c(t,d)
 {
 if (FLUID_THREAD_P(t))
 {
 begin_c_loop(c,t)
 C_UDMI(c,t,0) = C_T(c,t);
 end_c_loop(c,t)
 }
 }
 thread_loop_f(t,d)
 {
 if (FLUID_THREAD_P(t))
 {
 begin_f_loop(f,t)
 F_UDMI(f,t,0) = F_T(f,t);
 end_f_loop(f,t);
 }
 }
}
FarzinD is offline   Reply With Quote

Old   January 26, 2016, 13:32
Default
  #14
Senior Member
 
Przemek
Join Date: Jun 2011
Posts: 133
Rep Power: 7
gaza is on a distinguished road
Hi Bruno,
Thank you for your fast replay.
I used your code with adding (face_t f) and t = LookupThread(d,11)
but it gives me "received a fatal signal (Segmentation fault)".

Code:
#include "udf.h"
DEFINE_EXECUTE_AT_END(myFunc)
{
 Domain *d;
 /* Integrate dissipation. */
    real sum_diss=0.;
    cell_t c;
    face_t f;
    Thread *t;

    d = Get_Domain(1); /* mixture domain if multiphase */
    thread_loop_c(t,d)
    {
        if (FLUID_THREAD_P(t))
        {
            begin_c_loop(c,t)
                C_UDMI(c,t,0) = C_T(c,t);
            end_c_loop(c,t)
        }
    }

    t = Lookup_Thread(d,11);
    thread_loop_f(t,d)
    {
        if (FLUID_THREAD_P(t))
        {
            begin_f_loop(f,t)
                F_UDMI(f,tf,0) = F_T(f,t);
            end_f_loop(f,t);
        }
    }
}


11 is the ID of the boundary where I want to set value. Do you know why error occur?
__________________
best regards
pblasiak
gaza is offline   Reply With Quote

Old   January 26, 2016, 14:12
Default
  #15
Senior Member
 
Przemek
Join Date: Jun 2011
Posts: 133
Rep Power: 7
gaza is on a distinguished road
I changed the code like that but it does not solve the problem

Code:
#include "udf.h"
DEFINE_EXECUTE_AT_END(myFunc)
{
 Domain *d;
 /* Integrate dissipation. */
    real sum_diss=0.;
    cell_t c;
    face_t f;
    Thread *t;
    const int ID = 11;

    d = Get_Domain(1); /* mixture domain if multiphase */
    thread_loop_c(t,d)
    {
        if (FLUID_THREAD_P(t))
        {
            begin_c_loop(c,t)
                C_UDMI(c,t,0) = C_T(c,t);
            end_c_loop(c,t)
        }
    }
    


    t = Lookup_Thread(d,ID);
    thread_loop_f(t,d)
    {
        //if (FLUID_THREAD_P(t))
        if (NNULLP(THREAD_STORAGE(t,SV_UDM_I)))
        {
            begin_f_loop(f,t)
                F_UDMI(f,t,0) = F_T(f,t);
            end_f_loop(f,t);
        }
        else
        {
          Message("Skipping FACE thread no. %d..\n", THREAD_ID(t));
        }
    }
}

Can anybody help?
__________________
best regards
pblasiak
gaza is offline   Reply With Quote

Old   January 26, 2016, 14:15
Default
  #16
Member
 
Farzin
Join Date: Jul 2014
Posts: 41
Rep Power: 4
FarzinD is on a distinguished road
Hi, I'm Farzin!
I do not get why you added the thread pointer to the boundary; Because the loop in below line provides the thread pointer to all face threads, including that particular boundary.
Remove the line you added and try. If you want to keep it, you should remove the face thread loop.
FarzinD is offline   Reply With Quote

Old   January 26, 2016, 14:25
Default
  #17
Senior Member
 
Przemek
Join Date: Jun 2011
Posts: 133
Rep Power: 7
gaza is on a distinguished road
Ok I deleted it but I got received a fatal signal (Segmentation fault).
Do you know what is wrong?
__________________
best regards
pblasiak
gaza is offline   Reply With Quote

Old   January 26, 2016, 14:34
Default
  #18
Member
 
Farzin
Join Date: Jul 2014
Posts: 41
Rep Power: 4
FarzinD is on a distinguished road
Quote:
Originally Posted by gaza View Post
Hi Bruno,
Thank you for your fast replay.
I used your code with adding (face_t f) and t = LookupThread(d,11)
but it gives me "received a fatal signal (Segmentation fault)".

Code:
#include "udf.h"
DEFINE_EXECUTE_AT_END(myFunc)
{
 Domain *d;
 /* Integrate dissipation. */
    real sum_diss=0.;
    cell_t c;
    face_t f;
    Thread *t;

    d = Get_Domain(1); /* mixture domain if multiphase */
    thread_loop_c(t,d)
    {
        if (FLUID_THREAD_P(t))
        {
            begin_c_loop(c,t)
                C_UDMI(c,t,0) = C_T(c,t);
            end_c_loop(c,t)
        }
    }

    t = Lookup_Thread(d,11);
    thread_loop_f(t,d)
    {
        if (FLUID_THREAD_P(t))
        {
            begin_f_loop(f,t)
                F_UDMI(f,tf,0) = F_T(f,t);
            end_f_loop(f,t);
        }
    }
}


11 is the ID of the boundary where I want to set value. Do you know why error occur?
Correct this one, if you're using it: F_UDMI(f,tf,0) = F_T(f,t); >> F_UDMI(f,t,0) = F_T(f,t);

It shouldn't have any problem.
FarzinD is offline   Reply With Quote

Old   January 26, 2016, 14:49
Default
  #19
Senior Member
 
Bruno Machado
Join Date: May 2014
Posts: 262
Rep Power: 5
Bruno Machado is on a distinguished road
I believe the values are different because the macro C_T gives the total temperature, so it might be different from the static temperature.

Have a look at this thread
http://www.cfd-online.com/Forums/flu...mperature.html
Bruno Machado is offline   Reply With Quote

Old   January 26, 2016, 16:53
Default
  #20
Senior Member
 
Przemek
Join Date: Jun 2011
Posts: 133
Rep Power: 7
gaza is on a distinguished road
Hi Bruno and Farzin,
@Farzin:
I compiled this code:
Code:
#include "udf.h"
DEFINE_EXECUTE_AT_END(myFunc)
{
 Domain *d;
 /* Integrate dissipation. */
    real sum_diss=0.;
    cell_t c;
    face_t f;
    Thread *t;
    const int ID = 11;

    d = Get_Domain(1); /* mixture domain if multiphase */
    thread_loop_c(t,d)
    {
        if (FLUID_THREAD_P(t))
        {
            begin_c_loop(c,t)
                C_UDMI(c,t,0) = C_T(c,t);
            end_c_loop(c,t)
        }
    }
    


    //t = Lookup_Thread(d,ID);
    thread_loop_f(t,d)
    {
        //if (FLUID_THREAD_P(t))
        //if (NNULLP(THREAD_STORAGE(t,SV_UDM_I)))
        
            begin_f_loop(f,t)
                F_UDMI(f,t,0) = F_T(f,t);
            end_f_loop(f,t);
        
        
    }
}
and it gave the: received a fatal signal (Segmentation fault).

@Bruno:
I do not agree with you because I compared data for Static temperature and C_T that was assigned to UDM. Each value was the same but boundary value.
So I agree with Farzin that I have to set face value also with F_T, however I do not know how???

Here mvee wrote that he solved this problem but he unfortunately didn't provide the code:

http://www.cfd-online.com/Forums/flu...g-udm-uds.html
__________________
best regards
pblasiak
gaza is offline   Reply With Quote

Reply

Tags
udf, udm, uds

Thread Tools
Display Modes

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 On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Adjusting UDM to UDS mvee Fluent UDF and Scheme Programming 14 January 27, 2016 07:39
Segmentation violation louiza FLUENT 15 January 9, 2014 13:57
UDS Unsteady with UDM shashank312 FLUENT 3 May 15, 2013 15:35
UDS stored to UDM do not show the same values swati_mohanty FLUENT 0 December 3, 2010 04:46
usage of UDS & UDM Tong FLUENT 2 February 15, 2006 11:32


All times are GMT -4. The time now is 18:54.