CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   Fluent UDF and Scheme Programming (https://www.cfd-online.com/Forums/fluent-udf/)
-   -   A UDF to calculate energy per a cell and then returns new CO2 content in a cell. (https://www.cfd-online.com/Forums/fluent-udf/235125-udf-calculate-energy-per-cell-then-returns-new-co2-content-cell.html)

Yasser April 4, 2021 09:25

Look in the manual at Define_Mass_transfer and see the arguments ...

visitor April 4, 2021 10:21

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.

Yasser April 4, 2021 10:36

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

visitor April 4, 2021 11:11

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, ....

Yasser April 4, 2021 12:18

Quote:

Originally Posted by visitor (Post 800644)
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

visitor April 4, 2021 12:26

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.

pakk April 4, 2021 12:44

Then use Google, look for "Define_Mass_transfer fluent".

Old manuals are online (don't know about the legal status), examples are still relevant.

visitor April 4, 2021 12:53

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.

pakk April 4, 2021 13:16

Mass of CO2 is density x volume. Does that help?

pakk April 4, 2021 13:21

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?

visitor April 4, 2021 13:35

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.

pakk April 4, 2021 16:15

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.

AlexanderZ April 4, 2021 20:36

besides the logic of your code, compile what you have, read log and fix syntax

visitor April 5, 2021 01:35

energy per mass of CO2 in a cell.
 
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 April 9, 2021 11:29

calculating energy in breaking up co2.
 
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)
}
}

pakk April 9, 2021 11:56

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.

visitor April 9, 2021 12:18

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)
}
}

pakk April 9, 2021 12:25

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...

visitor April 9, 2021 14:00

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)
}
}

pakk April 9, 2021 14:24

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?


All times are GMT -4. The time now is 16:59.