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

How to get multiple outputs from CFX user routine

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   March 26, 2017, 11:28
Default How to get multiple outputs from CFX user routine
  #1
New Member
 
Tony
Join Date: Mar 2016
Posts: 24
Rep Power: 10
doublestrong is on a distinguished road
I use open temperature and pressure for outlet boudary condition of my case. The values of temperature and pressure should be given by user routine. I wrote user fortran to predict the two values. However, it seems that only one value can be returned to user routine.

My solution is to assemble the values of pressure and temperature into one value. For instance, if the pressure is 123,456 [Pa] and the temperature is 789[K], then I make my subroutine return 123456.789. This number can be splitted to two numbers using int(123456.789) and 1000*(123456.789 - int(123456.789)) in CFX expressions.

However, the problem is that the default type of return value in user routine is REAL. This type makes 123456.789 be returned as 123456.8, therefore the temperature cannot be accurate anymore. Is there a way to make the default type of return value to be double precision? Or can anyone provide me with other solutions?

Thanks!
doublestrong is offline   Reply With Quote

Old   March 26, 2017, 21:46
Default
  #2
Super Moderator
 
Glenn Horrocks
Join Date: Mar 2009
Location: Sydney, Australia
Posts: 17,854
Rep Power: 144
ghorrocks is just really niceghorrocks is just really niceghorrocks is just really niceghorrocks is just really nice
That looks like a horrible way to pass variables into CFX. Why can't you split it into two fortran routines and get one to pass the pressure variable and one to pass the temperature variable?
ghorrocks is offline   Reply With Quote

Old   March 26, 2017, 22:41
Default
  #3
New Member
 
Tony
Join Date: Mar 2016
Posts: 24
Rep Power: 10
doublestrong is on a distinguished road
Dear Glenn,

Thank you! The problem can be solved if I split it into two fortran routines. But I prefer to use just one fortran routine if two values can be returned in one fortran routine in any way. My fortran routine is a one-dimensional simulation. There are hundreds of iterations in the fortran routine every physical time step. And the temperature and pressure actually can be figured out in one run together. If I split it into two fortran routines, I soppuse the routines are almost the same but return different variables. I am worried about the extra computation time caused by another fortran routine. I will think about using two routines if there is no other way to solve the problem. Thanks again.
doublestrong is offline   Reply With Quote

Old   March 27, 2017, 08:09
Default
  #4
Super Moderator
 
Glenn Horrocks
Join Date: Mar 2009
Location: Sydney, Australia
Posts: 17,854
Rep Power: 144
ghorrocks is just really niceghorrocks is just really niceghorrocks is just really niceghorrocks is just really nice
By far the easiest way is just to calculate it twice. I would check the computational time of this option before discarding it. Anything else will be significantly more difficult to implement.
ghorrocks is offline   Reply With Quote

Old   April 11, 2017, 08:59
Default
  #5
New Member
 
Dmitry
Join Date: Feb 2013
Posts: 29
Rep Power: 13
techtuner is on a distinguished road
Doublestrong, you can pass your results as array of dimensionless values. Later, in CEL just choose appropriate index of your required value.

Sent from my M040 using CFD Online Forum mobile app
techtuner is offline   Reply With Quote

Old   April 11, 2017, 11:06
Default Solution
  #6
New Member
 
Join Date: Mar 2015
Posts: 5
Rep Power: 11
LorenzoSaintDubois is on a distinguished road
Funky little problem for the afternoon...
Every effort to shave off some computational time is noble, in my opinion.
Solution shown below. Do try to test this thoroughly though.
Best of luck!
LSD

program test
implicit none
doubleprecision:: T=789.12,P=123456.1,F,s=1000000,tn,pn
character*(100):: ct,cp,cf


! Encode T and P into doubleprecision F.
ct=''
write(ct,*)nint(T)
write(*,*)ct
ct=adjustl(trim(ct))

cp=''
write(cp,*)nint(P)
write(*,*)cp
cp=adjustl(trim(cp))

cf=''
cf=adjustl(trim(ct))//adjustl(trim(cp))
write(*,*)cf

read(cf,*)F
write(*,*)F

! Retrieve tn and pn from F.
tn=int(F/s)
write(*,*)tn
pn=F-tn*s
write(*,*)pn

end program test
LorenzoSaintDubois is offline   Reply With Quote

Old   April 11, 2017, 12:07
Default
  #7
Senior Member
 
Join Date: Jun 2009
Posts: 1,873
Rep Power: 33
Opaque will become famous soon enough
I am still puzzled by this question.

What is the point of returning multiple output for CFX UserFortran CEL function when the left hand side of the expression only takes one input.

The usage of CEL expressions is as follows

Parameter of Interest = MyCELFunction (P, T, ...)

How can the software split the multiple outputs w/o indication which output goes into which parameter ? Sure, we could add an index to indicate which single output to return, say

Parameter1 = MyCELFunction (1, P, T, ...)
Parameter2 = MyCELFunction (2, P, T, ...)

That will definitely work; however, the software still has to call the same function twice (if that is the number of possible outputs), and the time saving logic can only be embedded into the function.

It seems focus has been lost from solving the engineering problem at hand, which led to a CFD model, and time is being spent on an optimization of a low level (though time consuming) detail of the big picture.

Advice, create a local data area in the ANSYS CFX memory, or equivalent, store the time consuming results and reuse the data whenever it has already been computed. Alternatively, find a much faster algorithm to recompute the data.

My 2 cents,
Opaque is offline   Reply With Quote

Old   April 11, 2017, 12:25
Default
  #8
New Member
 
Join Date: Mar 2015
Posts: 5
Rep Power: 11
LorenzoSaintDubois is on a distinguished road
The way I see it, the user has a single computationaly expensive Fortran function that however delivers both needed variable values for the BC definition. So the trick is to call this expensive function once and somehow give CFX the values of both the temperature and the pressure using this one function call. So, I guess, you define a CFX user-variable (say, F) that is calculated using the Fortran function and holds the information of both T and P. Then using a couple of expressions you extract T and P from the values of F and set these expressions to the BC definition. So the solver calls the Fortran function once to populate F and then uses the available values on the grid for calculating T and P.

Your suggestion of using the CFX MMS is the most elegant way to go, but definitely not trivial and I'm not sure whether the documentation is sufficient for figuring out how to do this. I'd have to call support if I'd go that way.

LSD
LorenzoSaintDubois is offline   Reply With Quote

Reply

Tags
cfx, double precision, multiple outputs, user routine


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
How to compile CFX user routine in Linux mabna CFX 14 May 3, 2016 09:06
CFX Routine User Hicha04m CFX 0 August 5, 2015 05:46
Transient User Defined Function in CFX Niru CFX 0 November 12, 2013 18:07
CFD Short Course & CFX User Day Chris Reeves CFX 0 September 11, 2000 09:53
CFX User Subroutine Archive David Creech Main CFD Forum 0 March 17, 1999 13:41


All times are GMT -4. The time now is 17:34.