CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > ANSYS > CFX

derivative in CEL expressions

Register Blogs Community New Posts Updated Threads Search

Like Tree20Likes

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   November 14, 2016, 15:13
Default
  #61
New Member
 
Farough
Join Date: Jul 2015
Posts: 5
Rep Power: 10
Farough is on a distinguished road
[QUOTE=singer1812;285581]

Hi Emund,

I am reading through all these comments you have in this post and other posts. Found them pretty useful and i am wondering if you can help me with my problem:

I am trying to get the temperature gradient (dT/dt) in my simulation using the previous temperate. First i define my variable (PreviousTemperature) as follow:

LIBRARY:
&replace ADDITIONAL VARIABLE: PreviousTemperature
Option = Definition
Tensor Type = SCALAR
Units = [K]
Update Loop = TRANS_LOOP
Variable Type = Specific
END
END

then after, i define my dT/dt as follows:
(Temperature - PreviousTemperature)/dt
dt is my timesteps. I am not sure what i am doing wring but my dT/dt goes to negative which doesn't make scene at all. Is that because of the way i define PreviousTemperature??

Highly appreciate your help.
Farough is offline   Reply With Quote

Old   November 15, 2016, 07:43
Default
  #62
Senior Member
 
Join Date: Jun 2009
Posts: 1,804
Rep Power: 32
Opaque will become famous soon enough
For transient runs, you should be able to access the time derivative by using

Temperature.Time Derivative

No need for a workaround,

Hope it helps,
Farough likes this.
Opaque is offline   Reply With Quote

Old   November 22, 2016, 10:17
Default
  #63
New Member
 
Farough
Join Date: Jul 2015
Posts: 5
Rep Power: 10
Farough is on a distinguished road
Thanks Opaque. I will try it and will see what happens. Does it even work for the first time step?
Farough is offline   Reply With Quote

Old   December 2, 2016, 11:29
Default
  #64
New Member
 
Farough
Join Date: Jul 2015
Posts: 5
Rep Power: 10
Farough is on a distinguished road
Hi Opaque,

Your solution on time derivative of a variable like Temperature worked perfectly. Thanks for your help.... Now i am wondering if you/anybody else know how to take the Time Derivative of a CEL function????
Farough is offline   Reply With Quote

Old   December 2, 2016, 14:26
Default
  #65
Senior Member
 
Join Date: Jun 2009
Posts: 1,804
Rep Power: 32
Opaque will become famous soon enough
Create an algebraic additional variable

Insert AdditionalVariable ->MyAVCELFunc

Activate Additional Variable in Domain panel
Select Option = Algebraic Expression
Additional Variable Value = MyCELFunc( .., .. , ...)

Done..

If you need the Time Derivative, just reference it where needed as MyAVCELFunc.Time Derivative.
Farough likes this.
Opaque is offline   Reply With Quote

Old   December 2, 2016, 14:55
Default
  #66
New Member
 
Farough
Join Date: Jul 2015
Posts: 5
Rep Power: 10
Farough is on a distinguished road
Awesome. Great help... Thanks for your quick reply Opaque.
Farough is offline   Reply With Quote

Old   December 27, 2022, 10:13
Default
  #67
New Member
 
Join Date: Dec 2022
Posts: 29
Rep Power: 3
jaxk is on a distinguished road
Hey, I am testing this 'Update Loop = TRANS_LOOP' method by trying to make a plot of oldVel = oldVel + 1 [m/s], which should start at oldVel = 0 and increase with 1 m/s at each iteration.

I am using Fluid Flow (CFX) in Workbench.

I have added an AV called oldVel, added 'Update Loop = TRANS_LOOP', and have given it the value 0 [m/s].
If I run the solver with one iteration and open the .res file in CFX-PST I can see the oldVel value of 0 m/s has been saved.

(see OutFile1)

Then I open CFX-PRE and change ‘Add. Var. Value’ from 0 to ‘oldVel + 1 [m/s]’ in the Default Domain.
And in Solver Control I change the Max. Iterations from 1 to 100.
In CFX-SM I then select the .res file for the Initial Value 1 Settings.

When I run I get the error:

Error in subroutine GET_VARVX :
OLD : Failure to get data area USER_AV1_FL1
GETVAR originally called by subroutine SU_DVAR_ZONE

(see OutFile2)

Does anyone know what is going on? I am new to CFX, so some help is very much appreciated.
Attached Files
File Type: txt OutFile1.txt (30.7 KB, 4 views)
File Type: txt OutFile2.txt (25.7 KB, 0 views)
jaxk is offline   Reply With Quote

Old   December 27, 2022, 10:58
Default
  #68
Senior Member
 
Join Date: Jun 2009
Posts: 1,804
Rep Power: 32
Opaque will become famous soon enough
Quote:
Originally Posted by jaxk View Post
Hey, I am testing this 'Update Loop = TRANS_LOOP' method by trying to make a plot of oldVel = oldVel + 1 [m/s], which should start at oldVel = 0 and increase with 1 m/s at each iteration.

I am using Fluid Flow (CFX) in Workbench.

I have added an AV called oldVel, added 'Update Loop = TRANS_LOOP', and have given it the value 0 [m/s].
If I run the solver with one iteration and open the .res file in CFX-PST I can see the oldVel value of 0 m/s has been saved.

(see OutFile1)

Then I open CFX-PRE and change ‘Add. Var. Value’ from 0 to ‘oldVel + 1 [m/s]’ in the Default Domain.
And in Solver Control I change the Max. Iterations from 1 to 100.
In CFX-SM I then select the .res file for the Initial Value 1 Settings.

When I run I get the error:

Error in subroutine GET_VARVX :
OLD : Failure to get data area USER_AV1_FL1
GETVAR originally called by subroutine SU_DVAR_ZONE

(see OutFile2)

Does anyone know what is going on? I am new to CFX, so some help is very much appreciated.

Since you are new to Ansys CFX, it is best to explain what you are trying to achieve before getting into unsupported features. Perhaps there are better ways to achieve your goals w/o workarounds.
__________________
Note: I do not answer CFD questions by PM. CFD questions should be posted on the forum.
Opaque is offline   Reply With Quote

Old   December 28, 2022, 17:35
Default
  #69
New Member
 
Join Date: Dec 2022
Posts: 29
Rep Power: 3
jaxk is on a distinguished road
If only there was an 'initial value' box next to expression AV's

In an expression I have I need to refer to the expression value of the previous iteration.
Current value = previous value + slope*timestep

(I've sent you a PM with more details. Let me know if you think I should add those details here)
jaxk is offline   Reply With Quote

Old   December 28, 2022, 21:59
Default
  #70
Senior Member
 
Join Date: Jun 2009
Posts: 1,804
Rep Power: 32
Opaque will become famous soon enough
You are describing where you are having problems, not what you are trying to achieve.

From the variable names used, it seems you are integrating in time explicitly using the first-order approximation. So you are trying to compute

Value (t+dt) = Integral from t->t+dt of (whatever expression).dt

Since there is no more context, it is impossible to know if you want to do this for a field variable, i.e. for each location within a domain or just a single value. The former is not a built-in functionality, the latter is easy to achieve using a monitored expression plus its statistics.

Create a monitor point, say MyTimeIntExpr
Select Option = Expression
Set Expression Value = expression to be integrated

Set Monitor Statistics
Select Time Integral
Set range of the time integral

If you need the current Value at a given t to be used in another expression, you can create another monitored expression

Create a monitor point, say MyProbeTimeIntExpr
Select Option = Expression
Set Expression Value = probe(Expression Value.Time Integral)@MyTimeIntExpr

No need for workaround if the goal is a single valued result.
__________________
Note: I do not answer CFD questions by PM. CFD questions should be posted on the forum.
Opaque is offline   Reply With Quote

Old   December 29, 2022, 07:24
Default
  #71
New Member
 
Join Date: Dec 2022
Posts: 29
Rep Power: 3
jaxk is on a distinguished road
Thank you for your answer. I think your suggestions are for use of the expression in Post. I need them in Pre. I’m sorry I should have been more clear.

I am performing a Transient simulation of a Rigid Body which is submerged in water. The water flows in x-direction, and the Rigid Body is free to move in x-direction only. After some time, the Rigid Body has a certain velocity of VV [m/s]. At that moment I want to apply a Force in x-direction on the Rigid Body, which decelerates the Rigid Body.

I have already build that with an if statement: External Force 1 = if(rbstate(Linear Velocity X)@Rigid Body 1 >= VV, ForceValue, 0 [N]). This works well so far.

The change I want to make now, is to apply a gradual force on the Rigid Body once the velocity of VV has been reached instead of a sudden increase from 0 to ForceValue.

Therefor I need to store the previous value of the force applied on the RB in x-direction (so a single value), such that I can increase it by slope*timestep at the next iteration.
jaxk is offline   Reply With Quote

Old   December 30, 2022, 11:47
Default
  #72
Senior Member
 
Join Date: Jun 2009
Posts: 1,804
Rep Power: 32
Opaque will become famous soon enough
Quote:
Originally Posted by jaxk View Post
Thank you for your answer. I think your suggestions are for use of the expression in Post. I need them in Pre. I’m sorry I should have been more clear.

I am performing a Transient simulation of a Rigid Body which is submerged in water. The water flows in x-direction, and the Rigid Body is free to move in x-direction only. After some time, the Rigid Body has a certain velocity of VV [m/s]. At that moment I want to apply a Force in x-direction on the Rigid Body, which decelerates the Rigid Body.

I have already build that with an if statement: External Force 1 = if(rbstate(Linear Velocity X)@Rigid Body 1 >= VV, ForceValue, 0 [N]). This works well so far.

The change I want to make now, is to apply a gradual force on the Rigid Body once the velocity of VV has been reached instead of a sudden increase from 0 to ForceValue.

Therefor I need to store the previous value of the force applied on the RB in x-direction (so a single value), such that I can increase it by slope*timestep at the next iteration.
My advice to you is to read the documentation, and at least verify what I described can be done in CFX-Pre. CFD-Post does not have an "Output Control" section.
__________________
Note: I do not answer CFD questions by PM. CFD questions should be posted on the forum.
Opaque is offline   Reply With Quote

Old   January 3, 2023, 08:04
Default
  #73
New Member
 
Join Date: Dec 2022
Posts: 29
Rep Power: 3
jaxk is on a distinguished road
Hello Opaque, thanks again for your answer. I believe I read the relevant topics within the documentation guides (but it could be I do not know exactly what to look for), and looked for threads and tutorials which try to achieve something similar. The closest I got to a source which refers to a value from a previous timestep is this thread.

I understood you suggested me to create these monitor points and set monitor statistics within CFX-Pre. It is because I read that transient statistics data are not available for CEL expressions in Pre, that I assumed you believed I needed the expression values in Post. I have however tried if your suggestions can get me any closer to my goal, but without success.

Quote:
Originally Posted by singer1812 View Post
Actuallly you can get the derivative from last time step to current time step via use of additional variables settings. If you create an additional variable of the velocity, and add the term using ccl in the ADDITIONAL VARIABLE term:

Update Loop = TRANS_LOOP

This will cause that variable to take the old value of the velocity. You can use it to create your derivative.
Quote:
Originally Posted by singer1812 View Post
Yes this can. But you need to initialize the variable with a separate artifical run.

For example if you use additional variable Q=Q+1, this will work fine except for the first iteration if Q hasn't been intialized, because CFX will complain that Q doesnt exist for the right hand side of the equation.

CFX doesn't let you initialize an algebraic AV (at least at V12.1, havent checked into V13). The workaround is to run a sinlge iteration with the AV set to zero. This result will be saved to the res file. On the next run you set up your AV with the summing expression and use the res file from the first run to initialize it
I do not need a derivative of any value, all I need is to store the value of an expression from a previous iteration to be used in a later iteration. First I run a single iteration to set the AV to zero. But at the next iteration I always get the same error:

Error in subroutine GET_VARVX :
OLD : Failure to get data area USER_AV1_FL1
GETVAR originally called by subroutine SU_DVAR_ZONE

I wrote my initial post because I can’t find info about the above error. If you have any suggestions or alternatives based on the additional info I provided on December 29, I am really happy to hear it.
jaxk is offline   Reply With Quote

Old   January 3, 2023, 16:27
Default
  #74
Super Moderator
 
Glenn Horrocks
Join Date: Mar 2009
Location: Sydney, Australia
Posts: 17,703
Rep Power: 143
ghorrocks is just really niceghorrocks is just really niceghorrocks is just really niceghorrocks is just really nice
There is no information on the CFX error messages. You have to guess what it means. This is a bit silly, and a list of error codes and descriptions would be really helpful - but it does not exist.

Many of the applications discussed on this thread would appear to be better done using User Fortran rather than the TRANS_LOOP approach. Using unsupported features is often going to lead to inexplicable outcomes. At least with User Fortran you can control things. It does have a steep learning curve however.
__________________
Note: I do not answer CFD questions by PM. CFD questions should be posted on the forum.
ghorrocks is offline   Reply With Quote

Old   January 24, 2023, 13:40
Default
  #75
New Member
 
Join Date: Dec 2022
Posts: 29
Rep Power: 3
jaxk is on a distinguished road
I didn't find a solution for my problem using TRANS_LOOP or Fortran.
In the end I managed to add a gradual force on the Rigid Body by adding a damper force to the RB:
x-component of External Force: -1*dampingcoefficient*rbstate(Linear Velocity X)@Rigid Body 1

Perhaps that helps someone in the future
jaxk is offline   Reply With Quote

Old   March 22, 2023, 05:41
Default CEL User Functions
  #76
New Member
 
David Dudli
Join Date: Oct 2020
Location: Switzerland
Posts: 7
Rep Power: 5
schnafkid is on a distinguished road
I managed to directly access the time derivative and the gradients by just typing

Code:
<Variable Name>.Time Derivative
  <Variable Name>.Gradient X
...
into any fields that allow for Algebraic Expressions. I found this practice documented in the 'Ansys CFD Post Standalone Reference Guide', under 15.2. If you have an Ansys Account, here's the link to this section. There are also some PDFs with this guide distributed on rather dubious sources on the Internet.

Last edited by schnafkid; March 22, 2023 at 05:42. Reason: Spelling Errory
schnafkid is offline   Reply With Quote

Old   October 23, 2023, 22:23
Default
  #77
New Member
 
zh
Join Date: Oct 2023
Posts: 13
Rep Power: 2
zh&c is on a distinguished road
Do you know how the traffic at the last time step in the ansys cfx is represented by additional variables?

I am doing windkessel boundary conditions, encountered difficulties, I hope you can help me, I will be very grateful!
zh&c is offline   Reply With Quote

Old   October 23, 2023, 22:30
Default
  #78
New Member
 
zh
Join Date: Oct 2023
Posts: 13
Rep Power: 2
zh&c is on a distinguished road
Do you know how the traffic at the last time step in the ansys cfx is represented by additional variables?

I am doing windkessel boundary conditions, encountered difficulties, I hope you can help me, I will be very grateful!
zh&c is offline   Reply With Quote

Old   October 23, 2023, 22:57
Default
  #79
Super Moderator
 
Glenn Horrocks
Join Date: Mar 2009
Location: Sydney, Australia
Posts: 17,703
Rep Power: 143
ghorrocks is just really niceghorrocks is just really niceghorrocks is just really niceghorrocks is just really nice
I do not understand your question. Can you write your question again?

Is this question related to the rest of this thread? If it is a new question please start a new thread.
__________________
Note: I do not answer CFD questions by PM. CFD questions should be posted on the forum.
ghorrocks is offline   Reply With Quote

Old   October 23, 2023, 23:03
Default
  #80
New Member
 
zh
Join Date: Oct 2023
Posts: 13
Rep Power: 2
zh&c is on a distinguished road
I am doing the windkessel model with ansys cfx and need the derivative of the flow rate to the time, so, I want to know how to get the flow rate at the last time step.
zh&c 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
Cel expressions RAMAN6089 CFX 13 November 30, 2009 23:17
junction box routine and CEL function bornspur CFX 2 February 3, 2009 02:24
Cel expressions for trasient problem Jervds CFX 0 March 4, 2008 10:03
Cel expressions Time dependent Juan Maria Campos CFX 8 December 27, 2007 18:16
CEL Expressions Nick CFX 3 September 25, 2007 14:54


All times are GMT -4. The time now is 07:08.