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

How to get data of mass fraction in UDF

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   June 28, 2019, 01:43
Default How to get data of mass fraction in UDF
  #1
New Member
 
lili
Join Date: May 2019
Posts: 12
Rep Power: 7
lilistar-8216 is on a distinguished road
Hi, I'd like to get mass fraction data and store UDM at the end of tilmestep.
I tried calculation with UDF that can execute value at the end of tilmestep but it doesn't work and i get segmentation error.

My UDF is here,

#include "udf.h"
#include "sg_pdf.h"
#include "pdf_props.h"

DEFINE_EXECUTE_AT_END(mass_fraction)
{
Domain *d;
Thread *t;
cell_t c;
d = Get_Domain(1);
real mass;

thread_loop_c(t,d)
{
begin_c_loop(c, t)
{
mass = Pdf_Yi(c, t, 54); /*54 is an index of species i want to get value */
C_UDMI(c, t, 0) = mass;
Message("mf = %g\n", mass);
}
end_c_loop(c,t)
}
}

my calculation model has both solid zone and fluid zone. Addition to that, I use an Chemkin as a species model.

I also tried to change Pdf_Yi(cat,54) into C_YI(c,t,54) but it also didn't work.

Do you know if there are some problems in my UDF or not, how to use C_YI or Pdf_Yi macros, or the other ways to get mass fraction value at the end of tilmestep without these macros.

regards
lilistar-8216 is offline   Reply With Quote

Old   August 22, 2019, 04:23
Default
  #2
New Member
 
Sai Likitha Siddanathi
Join Date: Aug 2019
Posts: 1
Rep Power: 0
Likitha is on a distinguished road
In most of the cases while we use UDM we need to allocate the memory first.
It can be done it 2 ways :
1. by setting the parameters /solve/set/expert in the fluent TUI.
2. Or by allocating the variables using Alloc_Storage_Vars(domain, SV_*_RG, SV_*_G, SV_NULL) macro. In most of the cases the 2nd method is advisable while using UDF.

So try allocating memory and let me know if you still face the problem.
Likitha is offline   Reply With Quote

Old   August 25, 2019, 23:12
Default
  #3
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34
AlexanderZ will become famous soon enoughAlexanderZ will become famous soon enough
when did you get segmentation error,
if on initialization:
user-defined -> memory -> udm locations 1

best regards
AlexanderZ is offline   Reply With Quote

Old   February 25, 2020, 07:09
Default
  #4
Senior Member
 
mahdi rostami
Join Date: Jan 2020
Posts: 155
Rep Power: 6
mahdi-united is on a distinguished road
Quote:
Originally Posted by Likitha View Post
In most of the cases while we use UDM we need to allocate the memory first.
It can be done it 2 ways :
1. by setting the parameters /solve/set/expert in the fluent TUI.
2. Or by allocating the variables using Alloc_Storage_Vars(domain, SV_*_RG, SV_*_G, SV_NULL) macro. In most of the cases the 2nd method is advisable while using UDF.

So try allocating memory and let me know if you still face the problem.
hi

what is the argument should be put in * in SV_*_G for mass fraction?
mahdi-united is offline   Reply With Quote

Old   February 25, 2020, 08:59
Default Mass Fraction
  #5
Senior Member
 
vinerm's Avatar
 
Vinerm
Join Date: Jun 2009
Location: Nederland
Posts: 2,946
Blog Entries: 1
Rep Power: 36
vinerm will become famous soon enough
It is Y and since there are multiple components, an additional argument is required; so it written as

SV_Y_G, 0

for first component
__________________
Regards,
Vinerm

PM to be used if and only if you do not want something to be shared publicly. PM is considered to be of the least priority.
vinerm is offline   Reply With Quote

Old   February 25, 2020, 09:05
Default
  #6
Senior Member
 
mahdi rostami
Join Date: Jan 2020
Posts: 155
Rep Power: 6
mahdi-united is on a distinguished road
Quote:
Originally Posted by vinerm View Post
It is Y and since there are multiple components, an additional argument is required; so it written as

SV_Y_G, 0

for first component
thanks for responding
and what is your reference ?
i want to know more information about arguments of SV_*_G
mahdi-united is offline   Reply With Quote

Old   February 25, 2020, 09:11
Default Source
  #7
Senior Member
 
vinerm's Avatar
 
Vinerm
Join Date: Jun 2009
Location: Nederland
Posts: 2,946
Blog Entries: 1
Rep Power: 36
vinerm will become famous soon enough
Look at the source listing in your installation

./ansys_inc/vXXX/fluent/fluentXX.Y.Z/src
__________________
Regards,
Vinerm

PM to be used if and only if you do not want something to be shared publicly. PM is considered to be of the least priority.
vinerm is offline   Reply With Quote

Old   February 25, 2020, 09:21
Default
  #8
Senior Member
 
mahdi rostami
Join Date: Jan 2020
Posts: 155
Rep Power: 6
mahdi-united is on a distinguished road
Quote:
Originally Posted by vinerm View Post
Look at the source listing in your installation

./ansys_inc/vXXX/fluent/fluentXX.Y.Z/src
where??


i not found this address in my computer
mahdi-united is offline   Reply With Quote

Old   February 25, 2020, 09:31
Default OS
  #9
Senior Member
 
vinerm's Avatar
 
Vinerm
Join Date: Jun 2009
Location: Nederland
Posts: 2,946
Blog Entries: 1
Rep Power: 36
vinerm will become famous soon enough
Location varies from computer to computer. You have to find where Ansys products are installed in your computer. I have given the path further from there. If it is Windows, then most likely in Program Files. If it is Linux then it could be anywhere. Just type command

Code:
which fluent
in the terminal and it will show the location.
__________________
Regards,
Vinerm

PM to be used if and only if you do not want something to be shared publicly. PM is considered to be of the least priority.
vinerm is offline   Reply With Quote

Old   February 25, 2020, 09:39
Default
  #10
Senior Member
 
mahdi rostami
Join Date: Jan 2020
Posts: 155
Rep Power: 6
mahdi-united is on a distinguished road
Quote:
Originally Posted by vinerm View Post
Location varies from computer to computer. You have to find where Ansys products are installed in your computer. I have given the path further from there. If it is Windows, then most likely in Program Files. If it is Linux then it could be anywhere. Just type command

Code:
which fluent
in the terminal and it will show the location.
yes i found it
thank you so much
mahdi-united is offline   Reply With Quote

Old   February 25, 2020, 10:09
Default
  #11
Senior Member
 
mahdi rostami
Join Date: Jan 2020
Posts: 155
Rep Power: 6
mahdi-united is on a distinguished road
Quote:
Originally Posted by vinerm View Post
Location varies from computer to computer. You have to find where Ansys products are installed in your computer. I have given the path further from there. If it is Windows, then most likely in Program Files. If it is Linux then it could be anywhere. Just type command

Code:
which fluent
in the terminal and it will show the location.
dear friend



this is my code to storing volume fraction and mass fraction gradient in DEFINE_ADJUST
is it right??
thanks a lot


DEFINE_ADJUST(gradient, domain)
{
Thread *t;
Thread **pt;
cell_t c;
Domain *pDomain = DOMAIN_SUB_DOMAIN(domain,P_PHASE);
real voidx, voidy, voidz=0.0;
{
Alloc_Storage_Vars(pDomain,SV_VOF_RG,SV_VOF_G,SV_N ULL);
Scalar_Reconstruction(pDomain, SV_VOF,-1,SV_VOF_RG,NULL);
Scalar_Derivatives(pDomain,SV_VOF,-1,SV_VOF_G,SV_VOF_RG,Vof_Deriv_Accumulate);
}
{
Alloc_Storage_Vars(domain, SV_Y_RG,0, SV_Y_G,0, SV_NULL);
//Yi_derivatives(domain);
Free_Storage_Vars(domain, SV_Y_RG,0, SV_NULL);
}
mp_thread_loop_c (t,domain,pt)
if (FLUID_THREAD_P(t))
{
Thread *tp = pt[P_PHASE];
begin_c_loop (c,t)
{
// (C_VOF_G(c,tp)[0]*C_T_G(c,t)[0]+C_VOF_G(c,tp)[1]*C_T_G(c,t)[1]+C_VOF_G(c,tp)[2]*C_T_G(c,t)[2]);
C_UDMI(c,t,0) = C_YI_G(c,tp,0)[0];//(C_VOF_G(c,tp)[0]*C_YI_G(c,tp,0)[0] + C_VOF_G(c,tp)[1]*C_YI_G(c,tp,0)[1] + C_VOF_G(c,tp)[2]*C_YI_G(c,tp,0)[2]);
}
end_c_loop (c,t)
}
Free_Storage_Vars(pDomain,SV_VOF_RG,SV_VOF_G,SV_NU LL);
Free_Storage_Vars(domain, SV_Y_G,0, SV_NULL);
//Message("C_UDMI(cell,mix_air,0) = %g\n",C_UDMI(c,t,0));
}


i dont know is the YI_derivatives right or mistake
mahdi-united is offline   Reply With Quote

Old   February 25, 2020, 10:41
Default Code
  #12
Senior Member
 
vinerm's Avatar
 
Vinerm
Join Date: Jun 2009
Location: Nederland
Posts: 2,946
Blog Entries: 1
Rep Power: 36
vinerm will become famous soon enough
Allocation and reconstruction is available on domain. So, use

Alloc...(domain

instead of

Alloc...(pDomain

Do not use braces unnecessarily; will make code ambiguous. Use Free command only if Alloc has been used.
__________________
Regards,
Vinerm

PM to be used if and only if you do not want something to be shared publicly. PM is considered to be of the least priority.
vinerm is offline   Reply With Quote

Old   February 25, 2020, 10:45
Default
  #13
Senior Member
 
mahdi rostami
Join Date: Jan 2020
Posts: 155
Rep Power: 6
mahdi-united is on a distinguished road
Quote:
Originally Posted by vinerm View Post
Allocation and reconstruction is available on domain. So, use

Alloc...(domain

instead of

Alloc...(pDomain

Do not use braces unnecessarily; will make code ambiguous. Use Free command only if Alloc has been used.
thanks. i will solve it but

IS the Yi_derivatives right??
is there any problem in code?
mahdi-united is offline   Reply With Quote

Old   February 25, 2020, 10:52
Default Species Gradient
  #14
Senior Member
 
vinerm's Avatar
 
Vinerm
Join Date: Jun 2009
Location: Nederland
Posts: 2,946
Blog Entries: 1
Rep Power: 36
vinerm will become famous soon enough
Well, those ones appear to be alright to me. You can confirm by plotting their contours. To be able to do that, you have to issue the following command and then run at least 1 iteration

solve set expert

and then select yes to the question about Keeping Memory from being freed.
__________________
Regards,
Vinerm

PM to be used if and only if you do not want something to be shared publicly. PM is considered to be of the least priority.
vinerm is offline   Reply With Quote

Old   February 25, 2020, 10:57
Default Command
  #15
Senior Member
 
vinerm's Avatar
 
Vinerm
Join Date: Jun 2009
Location: Nederland
Posts: 2,946
Blog Entries: 1
Rep Power: 36
vinerm will become famous soon enough
Do you mean the literal Yi_derivatives command? There is no such command in Fluent.
__________________
Regards,
Vinerm

PM to be used if and only if you do not want something to be shared publicly. PM is considered to be of the least priority.
vinerm is offline   Reply With Quote

Old   February 25, 2020, 10:58
Default
  #16
Senior Member
 
mahdi rostami
Join Date: Jan 2020
Posts: 155
Rep Power: 6
mahdi-united is on a distinguished road
Quote:
Originally Posted by vinerm View Post
Well, those ones appear to be alright to me. You can confirm by plotting their contours. To be able to do that, you have to issue the following command and then run at least 1 iteration

solve set expert

and then select yes to the question about Keeping Memory from being freed.
all of this you say done

but code can't access to mass fraction gradient and will appear error in iteration1.
mahdi-united is offline   Reply With Quote

Old   February 25, 2020, 11:00
Default
  #17
Senior Member
 
mahdi rostami
Join Date: Jan 2020
Posts: 155
Rep Power: 6
mahdi-united is on a distinguished road
Quote:
Originally Posted by vinerm View Post
Do you mean the literal Yi_derivatives command? There is no such command in Fluent.
exactly my problem is Yi_derivatives

but in source files that you told me i not found anything about Yi_derivatives
mahdi-united is offline   Reply With Quote

Old   February 25, 2020, 11:00
Default Modified Code
  #18
Senior Member
 
vinerm's Avatar
 
Vinerm
Join Date: Jun 2009
Location: Nederland
Posts: 2,946
Blog Entries: 1
Rep Power: 36
vinerm will become famous soon enough
Post the modified code. Do note that Fluent does not accept // as argument. Change those to /* */.
__________________
Regards,
Vinerm

PM to be used if and only if you do not want something to be shared publicly. PM is considered to be of the least priority.
vinerm is offline   Reply With Quote

Old   February 29, 2020, 05:27
Default
  #19
Senior Member
 
mahdi rostami
Join Date: Jan 2020
Posts: 155
Rep Power: 6
mahdi-united is on a distinguished road
Quote:
Originally Posted by vinerm View Post
Post the modified code. Do note that Fluent does not accept // as argument. Change those to /* */.
hi dear friend
T_derivatives function in is not in sources files in ANSYS_INC
do you confident?
mahdi-united is offline   Reply With Quote

Old   February 29, 2020, 07:19
Default Function
  #20
Senior Member
 
vinerm's Avatar
 
Vinerm
Join Date: Jun 2009
Location: Nederland
Posts: 2,946
Blog Entries: 1
Rep Power: 36
vinerm will become famous soon enough
T_derivatives function is declared in pbns/sg.h, however, I do not think that it is relevant for you. You need to fetch gradients of mass fractions of species. That is accessible via C_YI_G or as stated earlier, using SV_Y_G, 0.

What error do you get if you use either C_YI_G or SV_Y_G? I would recommend the former since that is an easy wrapper for users.
__________________
Regards,
Vinerm

PM to be used if and only if you do not want something to be shared publicly. PM is considered to be of the least priority.
vinerm is offline   Reply With Quote

Reply

Tags
macros, segmentation error, udf


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
mass fraction of species Lilly FLUENT 5 March 13, 2022 18:52
CFD by anderson, chp 10.... supersonic flow over flat plate varunjain89 Main CFD Forum 18 May 11, 2018 08:31
Accessing the species mass fraction for particles data in UDF mac_09 FLUENT 17 August 9, 2017 21:15
Define mass flow profile with regards to species mass fraction danS Fluent UDF and Scheme Programming 0 June 20, 2017 07:21
Water subcooled boiling Attesz CFX 7 January 5, 2013 04:32


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