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

Error in UDF for storing specie mass fraction gradients

Register Blogs Community New Posts Updated Threads Search

Like Tree2Likes
  • 1 Post By pakk
  • 1 Post By AlexanderZ

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   January 12, 2021, 07:29
Default Error in UDF for area weighted average of specie mass fraction gradients
  #1
New Member
 
Iota
Join Date: Jan 2021
Posts: 5
Rep Power: 5
iota is on a distinguished road
Hello every body and good morning. Hope you all are doing well in this horrible pandemic situation.

I am recently writing a udf to calculate at first and then store in UDM (later) the area weighted average specie mass fraction gradient at the fixed boundary.I can do it very easily manually in the surface integral menu of the post processing.However i want to use it in udf for some other operation.This at first seem quite easy task as a lot of information is present in manual. I come up with the following UDF:

DEFINE_EXECUTE_AT_END(execute_at_end)
{
Domain *domain;
Thread *t;
cell_t c;
real area[ND_ND];
real total_area = 0.0;
real total_area_ave_grad = 0.0;
real G_mean;
int ID = 4; /* outlet ID displayed in Fluent boundary conditions panel */
domain = Get_Domain(1);
t = Lookup_Thread(domain, ID);
begin_c_loop(c, t)
{
F_AREA(area, c, t);
total_area += NV_MAG(area);
total_area_ave_grad += NV_MAG(area)*sqrt(C_YI_G(c,t,0)[0]*C_YI_G(c,t,0)[0] + C_YI_G(c,t,0)[1]*C_YI_G(c,t,0)[1]); ;
end_c_loop(c, t)
}
G_mean = total_area_ave_grad/total_area;/* Weighted average of the mass fraction gradeint */
printf("Area averaged gradient: %g\n", G_mean);
fflush(stdout);
}

The code is complied and hooked without any problem but after running the following error appear as attached.

What i have already done so far: (Not useful at all)
1. Run on serial node.
2. Include mem.h header file.
3. Use solve/set/expert and gradient save option.
4. Run for few iterations then hook the udf.
5. Tested this code for temperature. Which mean problem is with C_YI_G(c,t,0).

Please help me by suggesting necessary solution to this problem as it is frustrating me now. Thank you so much for your kindness.

Kind regards.
Attached Images
File Type: jpg error.JPG (24.3 KB, 14 views)

Last edited by iota; January 12, 2021 at 08:53. Reason: Missing details
iota is offline   Reply With Quote

Old   January 12, 2021, 14:24
Default
  #2
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 26
pakk will become famous soon enough
The manual says about that variable: "C_YI_G can be used only in the density-based solver. To use this in the pressure-based solver, you will need to set the rpvar 'species/save-gradients? to #t".
iota likes this.
pakk is offline   Reply With Quote

Old   January 12, 2021, 16:28
Default
  #3
New Member
 
Iota
Join Date: Jan 2021
Posts: 5
Rep Power: 5
iota is on a distinguished road
Quote:
Originally Posted by pakk View Post
The manual says about that variable: "C_YI_G can be used only in the density-based solver. To use this in the pressure-based solver, you will need to set the rpvar 'species/save-gradients? to #t".
Thank you so much for your reply and nice suggestion. Yes, you are very correct and i am already following this step before hooking this UDF before running the simulation. That is the reason, i can get the mass fraction gradient in the derivative section of the surface integrals that i can calculate manually in post processing. However, this udf cannot still access those and give me this error. By the way i have also tried to use the Reconstructed gradient term as well.

Therefore, i do not know what is the real problem with memory access or may be i am missing something key one.

Thank you so much once again.

Kind regards,
iota is offline   Reply With Quote

Old   January 13, 2021, 01:02
Default
  #4
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34
AlexanderZ will become famous soon enoughAlexanderZ will become famous soon enough
Code:
F_AREA(area, c, t);
F_AREA can be used to return the real face area vector (or ‘face area normal’) of a given face f in aface thread t. See DEFINE_UDS_FLUX for an example UDF that utilizes F_AREA.


arguments are: F_AREA(A,f,t)
you are trying to put cell inside as an argument

so you need loop over faces not cells.
How you code should change i'm not sure. probably you should use gradient from adjusted to face cell using t0 c0 macros

btw it is possible to transfer information with data which you are able to get using TUI commands to UDF, ofc it has some limitations.
how are you going to use this integral further?
iota likes this.
__________________
best regards


******************************
press LIKE if this message was helpful
AlexanderZ is offline   Reply With Quote

Old   January 13, 2021, 07:20
Default
  #5
New Member
 
Iota
Join Date: Jan 2021
Posts: 5
Rep Power: 5
iota is on a distinguished road
Quote:
Originally Posted by AlexanderZ View Post
Code:
F_AREA(area, c, t);
F_AREA can be used to return the real face area vector (or ‘face area normal’) of a given face f in aface thread t. See DEFINE_UDS_FLUX for an example UDF that utilizes F_AREA.


arguments are: F_AREA(A,f,t)
you are trying to put cell inside as an argument

so you need loop over faces not cells.
How you code should change i'm not sure. probably you should use gradient from adjusted to face cell using t0 c0 macros

btw it is possible to transfer information with data which you are able to get using TUI commands to UDF, ofc it has some limitations.
how are you going to use this integral further?
Thank you so much Alexander for your kind suggestions. Infact your first hint about the error really works in a fraction of seconds and i modify my code accordingly and it really works. Thank you so much for such a nice complement.
Later on, I do realize the last part of your message which i did not consider previously. Actually i was planning to store this integral in a UDM and call it in other udf function. After your comment i revisit the udf manual and found that UDM exist for face, cell and node and not for any numerical output. I did not find much at present how to import data from TUI to another UDF. This put me in another problem.
I will be more thankful if you provide me another quick hint on this part. I will be very thankful for you in this regard.
I really appreciate your previous comment. It really helps. Thank you so much.

Kind regards,
iota 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
Inconsistencies in reading .dat file during run time in new injection model Scram_1 OpenFOAM 0 March 23, 2018 22:29
compile of new combination of property in thermophisicalpropery milad653279 OpenFOAM Running, Solving & CFD 4 April 6, 2017 04:35
Water subcooled boiling Attesz CFX 7 January 5, 2013 03:32
Simulation with UDF for species mass fraction and velocity profile virgy Fluent UDF and Scheme Programming 8 February 7, 2012 04:30
PB: Saving mass fraction of species on two points with an udf biget.a FLUENT 2 July 23, 2009 03:06


All times are GMT -4. The time now is 08:13.