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

Steady state timestep

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   January 8, 2019, 14:26
Default Steady state timestep
  #1
New Member
 
Join Date: May 2018
Posts: 29
Rep Power: 8
CFDJonas is on a distinguished road
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!
CFDJonas is offline   Reply With Quote

Old   January 9, 2019, 00:26
Default
  #2
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34
AlexanderZ will become famous soon enoughAlexanderZ will become famous soon enough
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
AlexanderZ is offline   Reply With Quote

Old   January 9, 2019, 04:36
Default
  #3
New Member
 
Join Date: May 2018
Posts: 29
Rep Power: 8
CFDJonas is on a distinguished road
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.
CFDJonas is offline   Reply With Quote

Old   January 9, 2019, 10:26
Default
  #4
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27
pakk will become famous soon enough
Quote:
Originally Posted by CFDJonas View Post
[...] However the timestep is always 1 [...]
How did you come to that conclusion?
pakk is offline   Reply With Quote

Old   January 9, 2019, 12:44
Default
  #5
New Member
 
Join Date: May 2018
Posts: 29
Rep Power: 8
CFDJonas is on a distinguished road
Quote:
Originally Posted by pakk View Post
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 is offline   Reply With Quote

Old   January 11, 2019, 09:43
Default
  #6
New Member
 
Join Date: May 2018
Posts: 29
Rep Power: 8
CFDJonas is on a distinguished road
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.
CFDJonas is offline   Reply With Quote

Old   January 13, 2019, 22:10
Default
  #7
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34
AlexanderZ will become famous soon enoughAlexanderZ will become famous soon enough
User-Defined Scalars may be the answer to your question
More information could be found in Ansys Fluent Customization manual

best regards
AlexanderZ is offline   Reply With Quote

Old   January 14, 2019, 10:48
Default
  #8
New Member
 
Join Date: May 2018
Posts: 29
Rep Power: 8
CFDJonas is on a distinguished road
Quote:
Originally Posted by AlexanderZ View Post
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!!!
CFDJonas 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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Effect of initial condition for steady state vs Transient prasa ANSYS 0 August 22, 2018 05:45
Domain Reference Pressure and mass flow inlet boundary AdidaKK CFX 75 August 20, 2018 06:37
Calculation of the Governing Equations Mihail CFX 7 September 7, 2014 07:27
Constant velocity of the material Sas CFX 15 July 13, 2010 09:56
About the difference between steady and unsteady problems Lisa Main CFD Forum 11 July 5, 2000 15:37


All times are GMT -4. The time now is 15:54.