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

Averaged C_FMEAN UDF

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   January 11, 2012, 14:04
Default Averaged C_FMEAN UDF
  #1
New Member
 
Jenny
Join Date: Jan 2012
Posts: 11
Rep Power: 14
Jenny_Wong is on a distinguished road
Hi Everyone,

I've written a UDF code to time-average the mean mixture fraction values computed in FLUENT after each iteration.

However, I received "SEMENTATION VIOLATION" error. I think it is becuase of C_FMEAN. When I use other macro, the averaging code works fine.


thread_loop_c(ct,d)
{
begin_c_loop(c,ct)
{
C_UDMI(c,ct,0) = C_FMEAN(c,ct)+C_UDMI(c,ct,0);
C_UDMI(c,ct,1) = C_UDMI(c,ct,0)/count ;
}
end_c_loop(c,ct)
}

If anyone knows the solution to this problem, please kindly advise me. I will really appreciate it. Thank you very much.
Jenny

Jenny_Wong is offline   Reply With Quote

Old   January 14, 2012, 21:48
Default
  #2
Senior Member
 
Real Name :)
Join Date: Jan 2010
Location: United States
Posts: 192
Rep Power: 16
ComputerGuy is on a distinguished road
Can you post the rest of the code? You could always test the code by replacing C_FMEAN with a constant (say, 0.0) to see if that's causing the error.

Do you have the premixed combustion model turned on?

ComputerGuy
ComputerGuy is offline   Reply With Quote

Old   January 16, 2012, 18:24
Default Averaged C_FMEAN UDF
  #3
New Member
 
Jenny
Join Date: Jan 2012
Posts: 11
Rep Power: 14
Jenny_Wong is on a distinguished road
Dear ComputerGuy,
Thank you for your reply.

The premixed combustion model wasn't turned on. I used the non-premixed model.

I tried replacing C_FMEAN with a constant as you suggested and the code worked perfectly.

Thanks again,
Jenny

Here's my code:
#include "udf.h"
int count = 0;
real start_avg = 0.001;
DEFINE_EXECUTE_AT_END(avg)
{
if(CURRENT_TIME > start_avg)
{
Domain *d;
Thread *ct;
cell_t c;
d=Get_Domain(1);
count = count+1;
thread_loop_c(ct,d)
{
begin_c_loop(c,ct)
{
C_UDMI(c,ct,0) = C_FMEAN+C_UDMI(c,ct,0);
C_UDMI(c,ct,1) = C_UDMI(c,ct,udm_offset)/count ;
}
end_c_loop(c,ct)
}
}
}
Jenny_Wong is offline   Reply With Quote

Old   January 17, 2012, 00:11
Default
  #4
Senior Member
 
Real Name :)
Join Date: Jan 2010
Location: United States
Posts: 192
Rep Power: 16
ComputerGuy is on a distinguished road
The code should be something similar to:

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

int count = 0;
real start_avg = 0.001;
DEFINE_EXECUTE_AT_END(avg)
{
if(CURRENT_TIME > start_avg)
    {
    Domain *d;
    Thread *ct;
    cell_t c;
    d=Get_Domain(1);
    count = count+1;
    thread_loop_c(ct,d)
        {
        begin_c_loop(c,ct)
            {
            C_UDMI(c,ct,0)  = C_FMEAN(c,ct)+C_UDMI(c,ct,0);                     
            C_UDMI(c,ct,1)  = C_UDMI(c,ct,udm_offset)/count ;
            }
              end_c_loop(c,ct)
        }
    }
}
Try those two changes. You were using C_FMEAN incorrectly and not passing c and t, and I think the first include statement should help. I also don't see any place where you're defining udm_offset. Make sure that if you're using variables, they're defined. I don't know if this is actually the code you're using, but I'm surprised it was able to compile.

Let me know

ComputerGuy
Quote:
Originally Posted by Jenny_Wong View Post
Dear ComputerGuy,
Thank you for your reply.

The premixed combustion model wasn't turned on. I used the non-premixed model.

I tried replacing C_FMEAN with a constant as you suggested and the code worked perfectly.

Thanks again,
Jenny

Here's my code:
#include "udf.h"
int count = 0;
real start_avg = 0.001;
DEFINE_EXECUTE_AT_END(avg)
{
if(CURRENT_TIME > start_avg)
{
Domain *d;
Thread *ct;
cell_t c;
d=Get_Domain(1);
count = count+1;
thread_loop_c(ct,d)
{
begin_c_loop(c,ct)
{
C_UDMI(c,ct,0) = C_FMEAN+C_UDMI(c,ct,0);
C_UDMI(c,ct,1) = C_UDMI(c,ct,udm_offset)/count ;
}
end_c_loop(c,ct)
}
}
}
ComputerGuy is offline   Reply With Quote

Old   January 17, 2012, 11:48
Default Averaged C_FMEAN UDF
  #5
New Member
 
Jenny
Join Date: Jan 2012
Posts: 11
Rep Power: 14
Jenny_Wong is on a distinguished road
Dear ComputerGuy,

I'm sorry I made a mistake. I did use C_FMEAN(c,ct) in the code and replace udm_offset with 0.

I have added include "sg_mem.h" as you recommended but still FLUENT gave the same SEGMENTATION VIOLATION error.

I saw in 1 forum, C_FMEAN was used like this
fmean = C_FMEAN(c,ct);
a = fmean + b;
So, I tried this in my code too but it didn't work either.

Now, I'm trying to just print the C_FMEAN values and see if it reads the values alone. Please kindly advise if you know what is wrong. Thank you again for your help.

Jenny
Jenny_Wong is offline   Reply With Quote

Old   January 17, 2012, 14:50
Default
  #6
Senior Member
 
Real Name :)
Join Date: Jan 2010
Location: United States
Posts: 192
Rep Power: 16
ComputerGuy is on a distinguished road
Try the code below...The user-defined memory is valid everywhere, but the C_FMEAN is likely to be only valid if the cell thread is a fluid thread.

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

int count = 0;
real start_avg = 0.001;
DEFINE_EXECUTE_AT_END(avg)
{
if(CURRENT_TIME > start_avg)
    {
    Domain *d;
    Thread *ct;
    cell_t c;
    d=Get_Domain(1);
    count = count+1;
    thread_loop_c(ct,d)
        {
        if (FLUID_THREAD_P(ct))
        {
        begin_c_loop(c,ct)
            {
            C_UDMI(c,ct,0)  = C_FMEAN(c,ct)+C_UDMI(c,ct,0);                     
            C_UDMI(c,ct,1)  = C_UDMI(c,ct,udm_offset)/count ;
            }
              end_c_loop(c,ct)
          }
        }
    }
}

ComputerGuy




Quote:
Originally Posted by Jenny_Wong View Post
Dear ComputerGuy,

I'm sorry I made a mistake. I did use C_FMEAN(c,ct) in the code and replace udm_offset with 0.

I have added include "sg_mem.h" as you recommended but still FLUENT gave the same SEGMENTATION VIOLATION error.

I saw in 1 forum, C_FMEAN was used like this
fmean = C_FMEAN(c,ct);
a = fmean + b;
So, I tried this in my code too but it didn't work either.

Now, I'm trying to just print the C_FMEAN values and see if it reads the values alone. Please kindly advise if you know what is wrong. Thank you again for your help.

Jenny
ComputerGuy is offline   Reply With Quote

Old   January 18, 2012, 07:45
Default Averaged C_FMEAN UDF
  #7
New Member
 
Jenny
Join Date: Jan 2012
Posts: 11
Rep Power: 14
Jenny_Wong is on a distinguished road
Dear ComputerGuy,
You are right. The code works very well now with no SEGMENTATION VIOLATION error. I have been struggling with this problem for 2 months and now I am very happy. Thank you very much,
Jenny
Jenny_Wong is offline   Reply With Quote

Old   January 18, 2012, 12:46
Default
  #8
Senior Member
 
Real Name :)
Join Date: Jan 2010
Location: United States
Posts: 192
Rep Power: 16
ComputerGuy is on a distinguished road
Outstanding. Glad to help!

Quote:
Originally Posted by Jenny_Wong View Post
Dear ComputerGuy,
You are right. The code works very well now with no SEGMENTATION VIOLATION error. I have been struggling with this problem for 2 months and now I am very happy. Thank you very much,
Jenny
ComputerGuy is offline   Reply With Quote

Old   January 14, 2015, 22:20
Default
  #9
New Member
 
Howard Zhang
Join Date: Oct 2014
Posts: 12
Rep Power: 12
hongfu2233 is on a distinguished road
could you tell me some usefulness about the head file "sg_mem.h", many thanks!
hongfu2233 is offline   Reply With Quote

Reply

Tags
c_fmean, fluent error, mean mixture fraction, segmentation violation, udf error


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
Dynamic Mesh UDF Qureshi FLUENT 7 March 23, 2017 08:37
UDF parallel error: chip-exec: function not found????? shankara.2 Fluent UDF and Scheme Programming 1 January 16, 2012 23:14
How to add a UDF to a compiled UDF library kim FLUENT 3 October 26, 2011 22:38
UDF...UDF...UDF...UDF Luc SEMINEL FLUENT 0 November 25, 2002 05:03
UDF, UDF, UDF, UDF Luc SEMINEL Main CFD Forum 0 November 25, 2002 05:01


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