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

A UDF to calculate energy per a cell and then returns new CO2 content in a cell.

Register Blogs Community New Posts Updated Threads Search

Like Tree2Likes

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   April 4, 2021, 10:25
Default
  #21
Member
 
Yasser Selima
Join Date: Mar 2009
Location: Canada
Posts: 51
Rep Power: 19
Yasser is on a distinguished road
Look in the manual at Define_Mass_transfer and see the arguments ...
Yasser is offline   Reply With Quote

Old   April 4, 2021, 11:21
Default
  #22
Senior Member
 
AH
Join Date: Apr 2014
Posts: 287
Rep Power: 0
visitor is on a distinguished road
Dear Yasser, thanks for your reply. But with everything shutdown, I don't have much resources. The fluent manual i have shows limited information. The other alternative i have seen in Mode-Specific DEFINE Macros
is;

Function:.
species mass or UDS
DEFINE Macro:.
DEFINE_DIFFUSIVITY
Panel Activated In:
Materials

Basically i am looking for away to read massof CO2 gas in cell. This is why i hav chosen dzdt>species [CO2]. If there is away in reading this mass, please let me know. Thanks.
visitor is offline   Reply With Quote

Old   April 4, 2021, 11:36
Default
  #23
Member
 
Yasser Selima
Join Date: Mar 2009
Location: Canada
Posts: 51
Rep Power: 19
Yasser is on a distinguished road
I am not sure which manual you are using ... but you will find general macros like define_adjust .. and you will find data access macros which include cell macros. There you you will find the macros required to access mass fraction and properties. And you you will find looping macros, which will enable you to loop over cells when required ... also you will find User defined memory macros, which will enable you store data for each cell ... You need to have a look at all of the above and start writing you UDF and we can help if you have compilation error or if you are not getting the desired result
Yasser is offline   Reply With Quote

Old   April 4, 2021, 12:11
Default
  #24
Senior Member
 
AH
Join Date: Apr 2014
Posts: 287
Rep Power: 0
visitor is on a distinguished road
Dear Yasser

University is closed, because of lockdown. I just have limited documentation. If i have access to university resources, then this could have been solved by now.

I have found this C_YI(c,t,i). Which returns species mass fraction. But i just want CO2 mass, i don't think this helps. Also what is i for CO2, O2, C, ....
visitor is offline   Reply With Quote

Old   April 4, 2021, 13:18
Default
  #25
Member
 
Yasser Selima
Join Date: Mar 2009
Location: Canada
Posts: 51
Rep Power: 19
Yasser is on a distinguished road
Quote:
Originally Posted by visitor View Post
Dear Yasser

University is closed, because of lockdown. I just have limited documentation. If i have access to university resources, then this could have been solved by now.

I have found this C_YI(c,t,i). Which returns species mass fraction. But i just want CO2 mass, i don't think this helps. Also what is i for CO2, O2, C, ....
From fluent, click the help button and this will open your browser and pass the login requirement ... press the Ansys logo at the top and then navigate through the products until you reach fluent ... now you can download a pdf of all documentations
Yasser is offline   Reply With Quote

Old   April 4, 2021, 13:26
Default
  #26
Senior Member
 
AH
Join Date: Apr 2014
Posts: 287
Rep Power: 0
visitor is on a distinguished road
Dear Yasser, yes I know this. But can't, download ANSYS academic, limited internet. Could only do this at the university. Everything else is shutdown. A part from a few essential shops. Thanks.
visitor is offline   Reply With Quote

Old   April 4, 2021, 13:44
Default
  #27
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27
pakk will become famous soon enough
Then use Google, look for "Define_Mass_transfer fluent".

Old manuals are online (don't know about the legal status), examples are still relevant.
__________________
"The UDF library you are trying to load (libudf) is not compiled for parallel use on the current platform" is NOT the error after compiling. It is the error after loading. To see compiler errors, look at your screen after you click "build".
pakk is offline   Reply With Quote

Old   April 4, 2021, 13:53
Default
  #28
Senior Member
 
AH
Join Date: Apr 2014
Posts: 287
Rep Power: 0
visitor is on a distinguished road
Dear pakk, i have printed a few documents before shut down. Still it's not helpful to me. There isn't a tutorial which is similar to what I am looking for. The only way is to try to get some help, or wait till uni is open again. Plenty of experts around in this field in various dept's.
visitor is offline   Reply With Quote

Old   April 4, 2021, 14:16
Default
  #29
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27
pakk will become famous soon enough
Mass of CO2 is density x volume. Does that help?
__________________
"The UDF library you are trying to load (libudf) is not compiled for parallel use on the current platform" is NOT the error after compiling. It is the error after loading. To see compiler errors, look at your screen after you click "build".
pakk is offline   Reply With Quote

Old   April 4, 2021, 14:21
Default
  #30
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27
pakk will become famous soon enough
And you keep writing "dzdt>energy" as if that means something... It means 'dzdt is bigger than energy', but I can't guess what that means. Did you see this somewhere? Are you sure you copied this correctly?
__________________
"The UDF library you are trying to load (libudf) is not compiled for parallel use on the current platform" is NOT the error after compiling. It is the error after loading. To see compiler errors, look at your screen after you click "build".
pakk is offline   Reply With Quote

Old   April 4, 2021, 14:35
Default
  #31
Senior Member
 
AH
Join Date: Apr 2014
Posts: 287
Rep Power: 0
visitor is on a distinguished road
Dear pakk, may be I did not explain enough. There is also air and humidity (H2O) in the domain. I just need to read per a cell; energy in joules, temperature in K, and only mass of CO2.

If i get density*volume. Then it will have to be reading density of CO2 (in cell) and volume of cell.
visitor is offline   Reply With Quote

Old   April 4, 2021, 17:15
Default
  #32
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27
pakk will become famous soon enough
Yes, you want to use CO2 density, I saw that, but I also saw that you knew how to get the mass fraction, so you easily get CO2 density from the total density.

And you want to use energy per cell. I believe that your equation talks about energy per cell, but you should be able to rewrite your equation to energy per volume. Your cell volume should be irrelevant for your constitutive equation. (Physical behavior of the gas does not depend on your mesh.) This will make your implementation easier.
__________________
"The UDF library you are trying to load (libudf) is not compiled for parallel use on the current platform" is NOT the error after compiling. It is the error after loading. To see compiler errors, look at your screen after you click "build".
pakk is offline   Reply With Quote

Old   April 4, 2021, 21:36
Default
  #33
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34
AlexanderZ will become famous soon enoughAlexanderZ will become famous soon enough
besides the logic of your code, compile what you have, read log and fix syntax
__________________
best regards


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

Old   April 5, 2021, 02:35
Default energy per mass of CO2 in a cell.
  #34
Senior Member
 
AH
Join Date: Apr 2014
Posts: 287
Rep Power: 0
visitor is on a distinguished road
Dear Pakk thanks. I have now entered lines to calculate; (cell volume) * (cell density). Then multiply by CO2 mass fraction.

#include "udf.h"
/*Adjusting CO2 based on; temperature, CO2 mass in cell, and energy in a cell*/
DEFINE_MASS_TRANSFER(cell_update_CO2, domain)
{
Real C_H(c,thread); /*Gas phase enthalpy J/s. Reading must be per a cell*/
/*Below. Multiply cell volume by cell density. Then multiply by CO2 mass fraction.*/
total_mass_per_cell=(C_VOLUME(c,t)) * (C R(c,t))
CO2_mass_per_cell=(total_mass_per_cell) * (C YI(c,t,i))
/*where i is number for CO2*/


/* define temperature in cell and get its value */
real temp = C_T(cell, thread);
face_t f;
Thread *thread = Lookup_Thread(domain, ID);
begin_f_loop(f, thread)
{
energy_IN_cell_per_CO2_mass_in_cell =(C_H(c,thread))/(CO2_mass_per_cell);
/*The following lines finds the average of the above two readings.*/
if (temp ≥ 500 && < 1000)
if (energy_IN_cell_per_CO2_mass_in_cell ≥((100e3/0.044) && <(150e3/0.044));
C=1;
return C;
endif;
}
{
if (energy_IN_cell_per_CO2_mass_in_cell ≥((100e3/0.044) && <(150e3/0.044));
O2=1;
return O2;
endif;
}
{
if (energy_IN_cell_per_CO2_mass_in_cell ≥((100e3/0.044) && <(150e3/0.044));
return (((energy_IN_cell_per_CO2_mass_in_cell)-(150e-3/0.044))*(CO2_mass_per_cell));
return ((energy_IN_cell_per_CO2_mass_in_cell)*(CO2_mass_p er_cell));
}
end_f_loop(f,thread)
}
visitor is offline   Reply With Quote

Old   April 9, 2021, 12:29
Default calculating energy in breaking up co2.
  #35
Senior Member
 
AH
Join Date: Apr 2014
Posts: 287
Rep Power: 0
visitor is on a distinguished road
Revised this code should obtain temperature, energy per mass of CO2 in cell, then act with an 'if' condition.

Then subtracts an amount of heat energy in the cell, while CO2 breaks, and returns the left over energy to the cell.

Then wait for about 1 millisecond.

Note: Please ignore numbers for energy, it is just an example.

Then return the new values of C and O2, broken up from CO2. This by multiplying molar mass ratios (e.g. carbon to carbon dioxide is (12/44)), by the original CO2 mass available in the cell.


Changed to using C_H(c,thread) . This will get energy per a cell
#include "udf.h"
/*Adjusting CO2 based on; temperature, CO2 mass in cell, and energy in a cell*/
DEFINE_MASS_TRANSFER(cell_update_CO2, domain)
{
Real C_H(c,thread); /*Gas phase enthalpy J/s. Reading must be per a cell*/
/* define temperature in cell and get its value */
real temp = C_T(cell, thread);
face_t f;
Thread *thread = Lookup_Thread(domain, ID);
begin_f_loop(f, thread)
{
/*The i below is the index for CO2 gas in fluent.*/
energy_IN_cell_per_CO2_mass_in_cell =(C_H(c,thread))/((C_VOLUME(c,t))*(C R(c,t)))*(C YI(c,t,i)));
/*The following lines finds the average of the above two readings.*/
{
if (temp ≥ 500 && < 1000)
if (energy_IN_cell_per_CO2_mass_in_cell ≥((100e3/0.044) && <(150e3/0.044));
return (((energy_IN_cell_per_CO2_mass_in_cell)-(150e-3/0.018))*((C_VOLUME(c,thread))*(C R(c,thread)))*(C YI(c,thread,i)));
/*Below returns a mass of zero CO2 gas back in the cell. Assigning the original mass to zero*/
return =((C_VOLUME(c,thread))*(C R(c,thread)))*(C YI(c,thread,i))=0;
endif;
}
Delay(1);
/*Below returns the value for C. Multiply the original mass of CO2 by the ratio of C to CO2 molar mass (12/44).*/
Return (12/44)*((C_VOLUME(c, thread))*(C R(c, thread)))*(C YI(c, thread,i));
/*Below returns the value for C. Multiply the original mass of CO2 by the ratio of C to CO2 molar mass (32/44).*/
Return (32/44)*((C_VOLUME(c, thread))*(C R(c, thread)))*(C YI(c, thread,i));
end_f_loop(f,thread)
}
}
visitor is offline   Reply With Quote

Old   April 9, 2021, 12:56
Default
  #36
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27
pakk will become famous soon enough
Code:
if (temp ≥ 500 && < 1000)
This is not allowed. Write it out fully :
Code:
if ((temp >= 500) && (temp <= 1000))
I don't understand the delay, most people don't like slow simulations, but I understand you want to keep your reason a secret.
__________________
"The UDF library you are trying to load (libudf) is not compiled for parallel use on the current platform" is NOT the error after compiling. It is the error after loading. To see compiler errors, look at your screen after you click "build".
pakk is offline   Reply With Quote

Old   April 9, 2021, 13:18
Default
  #37
Senior Member
 
AH
Join Date: Apr 2014
Posts: 287
Rep Power: 0
visitor is on a distinguished road
I have made revisions.
Changed to DEFINE_MASS_TRANSFER.
Changed to using C_H(c,thread) . This will get energy per a cell
#include "udf.h"
/*Adjusting CO2 based on; temperature, CO2 mass in cell, and energy in a cell*/
DEFINE_MASS_TRANSFER(cell_update_CO2, domain)
{
Real C_H(c,thread); /*Gas phase enthalpy J/s. Reading must be per a cell*/
/* define temperature in cell and get its value */
real temp = C_T(cell, thread);
face_t f;
Thread *thread = Lookup_Thread(domain, ID);
begin_f_loop(f, thread)
{
/*The i below is the index for CO2 gas in fluent.*/
energy_IN_cell_per_CO2_mass_in_cell =(C_H(c,thread))/((C_VOLUME(c,t))*(C R(c,t)))*(C YI(c,t,i)));
/*The following lines finds the average of the above two readings.*/
{
if (temp ≥ 500 && < 1000)
if (energy_IN_cell_per_CO2_mass_in_cell ≥((100e3/0.044) && <(150e3/0.044));
return (((energy_IN_cell_per_CO2_mass_in_cell)-(150e-3/0.018))*((C_VOLUME(c,thread))*(C R(c,thread)))*(C YI(c,thread,i)));
/*Below returns a mass of zero CO2 gas back in the cell. Assigning the original mass to zero*/
return =((C_VOLUME(c,thread))*(C R(c,thread)))*(C YI(c,thread,i))=0;
endif;
}
Delay(1);
/*Below returns the value for C. Multiply the original mass of CO2 by the ratio of C to CO2 molar mass (12/44).*/
Return (12/44)*((C_VOLUME(c, thread))*(C R(c, thread)))*(C YI(c, thread,i));
/*Below returns the value for C. Multiply the original mass of CO2 by the ratio of C to CO2 molar mass (32/44).*/
Return (32/44)*((C_VOLUME(c, thread))*(C R(c, thread)))*(C YI(c, thread,i));
end_f_loop(f,thread)
}
}
visitor is offline   Reply With Quote

Old   April 9, 2021, 13:25
Default
  #38
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27
pakk will become famous soon enough
You are using return multiple times. What do you expect this to do?

Fluent will ignore everything after it gets to a return, so your current code has useless code, but it's hard to correct because I don't know what you want the code to do...
__________________
"The UDF library you are trying to load (libudf) is not compiled for parallel use on the current platform" is NOT the error after compiling. It is the error after loading. To see compiler errors, look at your screen after you click "build".
pakk is offline   Reply With Quote

Old   April 9, 2021, 15:00
Default
  #39
Senior Member
 
AH
Join Date: Apr 2014
Posts: 287
Rep Power: 0
visitor is on a distinguished road
I have made revisions.
Changed to DEFINE_MASS_TRANSFER.
Changed to using C_H(c,thread) . This will get energy per a cell

NOT sure about how to return the quantities below as C & O2. Please see end of this code with remarks.


#include "udf.h"
/*Adjusting CO2 based on; temperature, CO2 mass in cell, and energy in a cell*/
DEFINE_MASS_TRANSFER(cell_update_CO2, domain)
{
Real C_H(c,thread); /*Gas phase enthalpy J/s. Reading must be per a cell*/
/* define temperature in cell and get its value */
real temp = C_T(cell, thread);
face_t f;
Thread *thread = Lookup_Thread(domain, ID);
begin_f_loop(f, thread)
{
/*The i below is the index for CO2 gas in fluent.*/
energy_IN_cell_per_CO2_mass_in_cell =(C_H(c,thread))/((C_VOLUME(c,t))*(C R(c,t)))*(C YI(c,t,i)));
/*The following lines finds the average of the above two readings.*/
{
if (temp ≥ 500 && < 1000)
{
if (energy_IN_cell_per_CO2_mass_in_cell ≥((100e3/0.044) && <(150e3/0.044));
return (((energy_IN_cell_per_CO2_mass_in_cell)-(150e-3/0.018))*((C_VOLUME(c,thread))*(C R(c,thread)))*(C YI(c,thread,i)));
Endif;
}
/*Below returns a mass of zero CO2 gas back in the cell. Assigning the original mass to zero*/
return =((C_VOLUME(c,thread))*(C R(c,thread)))*(C YI(c,thread,i))=0;

/*Delay for one second.*/
For(float CURRENT_TIME, (CURRENT_TIME+0.001), 0.001)
{
If((CURRENT_TIME+0.001) - CURRENT_TIME= 0.001)
Return ***;
}

/*Below returns the value for C. Multiply the original mass of CO2 by the ratio of C to CO2 molar mass (12/44).*/
/*NOT sure about how to return the quantity below as C.*/
Return (12/44)*((C_VOLUME(c, thread))*(C R(c, thread)))*(C YI(c, thread,i));
/*Below returns the value for O2 Multiply the original mass of CO2 by the ratio of O2 to CO2 molar mass (32/44).*/
/*NOT sure about how to return the quantity below as O2.*/
Return (32/44)*((C_VOLUME(c, thread))*(C R(c, thread)))*(C YI(c, thread,i));
end_f_loop(f,thread)
}
}

Last edited by visitor; April 9, 2021 at 16:55.
visitor is offline   Reply With Quote

Old   April 9, 2021, 15:24
Default
  #40
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27
pakk will become famous soon enough
Wait a minute... Is your intention that the CO2 breakup takes one millisecond? Are you trying to simulate a chemical reaction that take one millisecond to finish?
Yasser likes this.
__________________
"The UDF library you are trying to load (libudf) is not compiled for parallel use on the current platform" is NOT the error after compiling. It is the error after loading. To see compiler errors, look at your screen after you click "build".
pakk 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



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