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/)
-   -   Steady state timestep (https://www.cfd-online.com/Forums/fluent-udf/213782-steady-state-timestep.html)

CFDJonas January 8, 2019 13:26

Steady state timestep
 
Hello,

I want to calculate a custom ODE for every cell, so I created a user defined memory (UDM) for its result value. Then I thought I could use the DEFINE_ADJUST macro to change the UDM's value respectively.

For example following rate equation (just as an example):
dx/dt = -k * c(species1)

My approach was the following

Code:

DEFINE_ADJUST(adjust_macro, d)
{
   
        Thread *t;
        cell_t c;
        real dt = CURRENT_TIMESTEP;

        thread_loop_c(t, d)
        {
                begin_c_loop(c, t)
                        // get concentration
                        real conc = C_R(c, t) * C_YI(c, t, i_specie1) / mw_specie1;

                        // HERE APPLY THE RATE CHANGE TO THE VALUE
                        C_UDMI(c, t, MY_UDMI) += (-k * conc) * dt;
                end_c_loop(c, t)
        }
}

However the timestep is always 1 and I have the feeling this is somehow weird. I just want to have something like the timestep "dt" passed in DEFINE_CHEM_STEP without using the stiff chemistry solver.

Any help is appreciated, thank you!

AlexanderZ January 8, 2019 23:26

this code doesn't manipulate timestep, do you understand this?

timestep is involved in last equation and is equal to the value (timestep size), which you put in fluent GUI. And it is constant (else you are using adaptive timestep). It could be 1sec, 2, 111, any value you've put in GUI

IF you want to change timestep using UDF you should use DEFINE_DELTAT macro

best regards

CFDJonas January 9, 2019 03:36

Thank you for your answer!

Well I don't want to change the time step actually. I want to calculate the result of a rate equation/ode according to the current timestep.

Actually I want to synchroniously solve a rate equation/ode of a scalar (non specie concentration) to the chemical reaction. I have a volumetric reaction with a DEFINE_VR_RATE udf set up, thus I'm not using the stiff chemistry solver. But I want to have the same possibility of using the "dt" parameter of DEFINE_CHEM_STEP without changing said solver.

pakk January 9, 2019 09:26

Quote:

Originally Posted by CFDJonas (Post 721308)
[...] However the timestep is always 1 [...]

How did you come to that conclusion?

CFDJonas January 9, 2019 11:44

Quote:

Originally Posted by pakk (Post 721426)
How did you come to that conclusion?

Code:

Message("\n current timestep = %e \n", CURRENT_TIMESTEP);
Prints 1 on my screen the whole time during simulation.

CFDJonas January 11, 2019 08:43

First off, sorry for the double post.

But I try to ask the question more general: Is there any possibility to add a custom differential equation to the Fluent solver. Or somehow couple a new differential equation with the equations being solved by Fluent anyways. I think this shouldn't be that much of a challenge for a software that's main task is basically solving differential equations.

Hope anyone can help me, thanks.

AlexanderZ January 13, 2019 21:10

User-Defined Scalars may be the answer to your question
More information could be found in Ansys Fluent Customization manual

best regards

CFDJonas January 14, 2019 09:48

Quote:

Originally Posted by AlexanderZ (Post 721801)
User-Defined Scalars may be the answer to your question
More information could be found in Ansys Fluent Customization manual

best regards

Thank you very much. Indeed, user defined scalars are the thing I was looking for. However I have a new problem regarding them, as I am somehow confused about the units.

I want to add a additional ODE with respect to the scalar \phi with units of a concentration (kmol/m^3):
\frac{d\phi}{dt} = 2 k_1 c_1 - k_2 * \phi^2
The resulting unit of this source term then is kmol/m^3 s. So I wrote a DEFINE_SOURCE looking like the following:

Code:

DEFINE_SOURCE(source_phi, c, t, dS, eqn)
{
        real rho = C_R(c, t);
        real c_1= rho * C_YI(c, t, I_1) / M_i[I_1];
        real phi = C_UDSI(c, t, I_PHI);
       
        real source = 2 * k1 * c_1 - k2 * pow(phi, 2);
        dS[eqn] = -2 *k2 * phi;
       
        return source;
}

With initial condition in inlet set to constant value 0, mass flux rate set as uds convection term and inlet diffusion turned on I get a converging solution. However this solution is not in agreement with a simplified model solving the same differential equations. What bothers me most are the units in the transport equation. In my understanding the unit of the scalar should be irrelevant (thus I could declare the concentration of phi kmol/m^3 as MyUnit). That means my source term has the unit MyUnit/s. Looking in the Ansys manual the left side of the transport equation (especially the convection term) leads to unit 1/m * kg/m^3 * m/s * MyUnit resulting in kg/(m^3 s) * MyUnit. This raises the thought that I may have to multiply the source term with rho (density). But when I do this in my UDF above (source * rho) the solution does not converge anymore. Can anybody validate/explain my error during my explained thoughts? Thank you very much!!!


All times are GMT -4. The time now is 21:06.