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/)
-   -   UDFs for Energy Source & Water Vapour Concentration Source (https://www.cfd-online.com/Forums/fluent-udf/225957-udfs-energy-source-water-vapour-concentration-source.html)

Morice April 13, 2020 07:10

UDFs for Energy Source & Water Vapour Concentration Source
 
Hi Guys,

I am attempting to model the effect of crops in a heated closed greenhouse. The crops have been modelled as a porous medium domain with a sink for both energy and water vapour concentration. The source/sink term for the energy and water vapour concentration are given by equations and I have written UDFs to model these variables. Kindly take a look and advice, thank you very much and much appreciated.

/*Energy Sink Term for the Crop-Zone*/

#include "udf.h"
#define rho 1.225
#define Ca 1006.25
#define Lad 3
#define L 0.405
#define v crop_zone velocity /*air velocity within the crop zone*/
#define Tcrop crop_zone temperature /*temperature of the crop zone*/
#define Tair fluid temperature /*temperature inside the greenhouse*/

DEFINE_SOURCE (crop_zone_energy_source, c, t, dS, eqn)
{
real source;
ra = 305 * ((L/v) exp0.5);
source = -2 * rho * Lad * Ca * ((Tcrop - Tair)/ ra);
dS[eqn] = 0.0;
return source;
}

/*Water Vapour Sink Term for the Crop-Zone*/
#include "udf.h"
#define rho 1.225
#define lambda 2.45*10e6
#define Le 0.86
#define Lad 3
#define rs 290
#define Wcrop crop_zone water vapour source /*water vapour within the crop zone*/
#define Wair fluid water vapour source /*water vapour within the greenhouse*/

DEFINE_SOURCE (crop_zone_water vapour_source, c, t, dS, eqn)
{
real source;
source = -rho * lambda * ((Le) exp1/3) * Lad ((Wcrop -Wair) / (ra + rs));
dS[eqn] = 0.0;
return source;
}

vinerm April 14, 2020 04:12

Source Terms
 
Syntactically, the UDF will work with proper values assigned to the parameters. However, dS[eqn] should not be set to 0 if the parameters in the source equation are not constant. In dS[eqn], S is source and eqn is the field variable to which the source is being applied. So, for energy equation, T is eqn. Consequently, if energy source is a function of T, then dS[eqn] should be first derivative of source term with T and not 0. If that is the not the case, then the UDF is alright and will work.

Morice April 17, 2020 03:47

I apologize for the late response. I was not able to quickly respond due to the network disruptions because of the pandemic. Thank you very much for the response. That is the case and dS should not be set to 0.
I set it as follows for the cropzone energy sink term:

dS[eqn] = - ((2 * rho * Lad * Ca ) / r)

What do you think?

vinerm April 17, 2020 06:00

Derivative
 
If T_{crop} and T_{air} are constants, then dS[eqn] has to be 0. However, if those are not constant, then those have to be written in terms of field temperature T and then the gradient should be computed. The gradient you have computed is correct only if T_{crop} is equal to T and T_{air} is constant.

Morice April 17, 2020 10:01

It is a heated closed greenhouse and as such Tcrop and Tair are not constants. As heat is added to the greenhouse air, Tair will continue rise. The crops continously absorb heat from the air and as such Tcrop will also continue to rise up to a point. Its seems my computation was wrong. How do you suggest the gradient should be computed to reflect that Tcrop and Tair are not constants, and they are written in terms of field temperature T?

vinerm April 17, 2020 10:42

Air Temperature
 
Since you solving for the air domain, T_{air} = T. As far as T_{crop} is concerned, this does not belong to the temperature of the zone to which you are applying source term. Hence, this would be constant as far as source is concerned. So, the derivative will be

dS[eqn] = \frac{2\rho\times Lad\times ca}{ra}

However, T_{crop} will be equal to T if you do not consider non-equilibrium heat transfer model for the porous zone. And then, your source term will be 0, which it should be.

Morice April 17, 2020 11:34

I see your point now. Thank you very much for your help. Much appreciated.

Morice May 2, 2020 21:31

Transient Simulation
 
Quote:

Originally Posted by vinerm (Post 766139)
Since you solving for the air domain, T_{air} = T. As far as T_{crop} is concerned, this does not belong to the temperature of the zone to which you are applying source term. Hence, this would be constant as far as source is concerned. So, the derivative will be

dS[eqn] = \frac{2\rho\times Lad\times ca}{ra}

However, T_{crop} will be equal to T if you do not consider non-equilibrium heat transfer model for the porous zone. And then, your source term will be 0, which it should be.

Hey Vinerm

The UDFs we discussed were okay for steady-state simulation.

Is there any modification that is required if they are to be applied in transient simulation?

Temperatures, for instance, vary during the day.

Thank you very much for your assistance, much appreciated

vinerm May 3, 2020 15:34

Transient
 
As far as Fluent is concerned, there is no change required. However, user has to ensure that the formulation is logical. You can use same UDF for transient, except then Fluent will consider the value supplied by the UDF in terms of per unit time. So, it will further multiply the term returned by UDF with the time-step and apply that as source.

Morice May 4, 2020 03:23

Quote:

Originally Posted by vinerm (Post 768498)
As far as Fluent is concerned, there is no change required. However, user has to ensure that the formulation is logical. You can use same UDF for transient, except then Fluent will consider the value supplied by the UDF in terms of per unit time. So, it will further multiply the term returned by UDF with the time-step and apply that as source.

I understand.

Thanks, Much appreciated

Morice May 25, 2020 08:14

Compiling Errors
 
Code:

..\..\src\Ta.cpp(11): error C2086: 'real S0avg': redefinition
..\..\src\Ta.cpp(9): note: see declaration of 'S0avg'
..\..\src\Ta.cpp(11): error C2086: 'real volume': redefinition
..\..\src\Ta.cpp(10): note: see declaration of 'volume'
..\..\src\Ta.cpp(11): error C2086: 'real vol_tot': redefinition
..\..\src\Ta.cpp(10): note: see declaration of 'vol_tot'
..\..\src\Ta.cpp(12): error C2059: syntax error: 'empty declaration'
..\..\src\Ta.cpp(18): error C2065: 'thread': undeclared identifier
..\..\src\Ta.cpp(18): error C2789: 'cell_loop_last': an object of const-qualified type must be initialized
..\..\src\Ta.cpp(18): note: see declaration of 'cell_loop_last'
..\..\src\Ta.cpp(18): error C2065: 'cell': undeclared identifier
..\..\src\Ta.cpp(20): error C2065: 'thread': undeclared identifier
..\..\src\Ta.cpp(20): error C2065: 'cell': undeclared identifier
..\..\src\Ta.cpp(21): error C2065: 'thread': undeclared identifier
..\..\src\Ta.cpp(21): error C2065: 'cell': undeclared identifier
..\..\src\Ta.cpp(22): error C2065: 'S0': undeclared identifier
..\..\src\Ta.cpp(22): error C2065: 'thread': undeclared identifier
..\..\src\Ta.cpp(22): error C2065: 'cell': undeclared identifier
..\..\src\Ta.cpp(25): error C2065: 'S0': undeclared identifier
..\..\src\Ta.cpp(27): error C2065: 'thread': undeclared identifier
..\..\src\Ta.cpp(27): error C2065: 'cell': undeclared identifier
..\..\src\Ta.cpp(29): error C2065: 'thread': undeclared identifier
..\..\src\Ta.cpp(29): error C2065: 'cell': undeclared identifier
..\..\src\Ta.cpp(30): error C2064: term does not evaluate to a function taking 1 arguments
..\..\src\Ta.cpp(30): error C2064: term does not evaluate to a function taking 1 arguments
..\..\src\Ta.cpp(32): error C2065: 'thread': undeclared identifier
..\..\src\Ta.cpp(32): error C2065: 'cell': undeclared identifier
..\..\src\Ta.cpp(33): error C2065: 'thread': undeclared identifier
..\..\src\Ta.cpp(33): error C2065: 'cell': undeclared identifier
..\..\src\Ta.cpp(59): error C3872: '0xac': this character is not allowed in an identifier
..\..\src\Ta.cpp(59): error C3688: invalid literal suffix '�?�'; literal operator or literal operator template 'operator ""�?�' not found
..\..\src\Ta.cpp(62): error C3872: '0xac': this character is not allowed in an identifier
..\..\src\Ta.cpp(62): error C3688: invalid literal suffix '�?�'; literal operator or literal operator template 'operator ""�?�' not found

Hey Vinerm,

I hope you are well.

I finished writing the UDF but ran into some errors during compiling.

I fixed all the issues apart from calculations of average temp. and average species mass fractions.

I am also attempting to store the value of sensible heat for post-processing but I get an error. It seems I am not able to use the word "source" twice for storage.

A little background:

1. The porous crop zone is in thermal equilibrium with the air flowing through it so I thought I would use the volume-weighted average temp. value of the fluid domain of the entire greenhouse as Temp-air in sensible heat and transpiration calculations

2. Did the same with water vapor, Species-0.

3. All the equations used are above the associated code.

Is there a code I could write to initialize the UDMIs?

Thank you, much appreciated.

vinerm May 25, 2020 10:37

Errors
 
There are multiple syntactical errors in the code. Go through each line that is reported in the compilation, such as, 9, 10, 11, 12, 18, etc. Each of these line has errors. E.g., there are no variables defined by the names of cell and thread, however, those are being used as the arguments for the loop. There are some variables being redefined, such as, S0avg, volume, vol_tot. Go through each line and try to remove those errors.

Morice May 25, 2020 21:37

Compiling Errors
 
Good Morning,

Thank you for your fast response, much appreciated.

Will do.

Thanks


All times are GMT -4. The time now is 11:51.