Page 1 of 1

Storing an variable from UDF at each iteration step

Posted: 16 Apr 2024, 18:09
by szlyc0706
Hi Elmer users,

I am writing a UDF which has input 'xVec' and output 'newXVec', and newXVec is calculated based on current and previous value of xVec in the iteration. So ideally I need somewhere to store an array, and at each node when my UDF is called the array size +1, so the history of newXVec is recoreded.
From post https://www.elmerfem.org/forum/viewtopic.php?t=1383, it is suggesting that I need to store iterative value of newXVec into Variable_t % Values. But I couldn't find any example.
Anyone has any idea about what method I need to use for storing my variable into Variable_t % Values and where I need my store it into?

I appreciate for your help,
Eric

Re: Storing an variable from UDF at each iteration step

Posted: 16 Apr 2024, 18:55
by szlyc0706
I've made some progress!
writing in is using

Code: Select all

call ListAddConsReal(Model%Simulation,'Name',newXVec)
it is working because I can get values out by

Code: Select all

ListGetConstReal( Model % Simulation, 'Name', found)
I am able to write into model%simulation. Is this the right method to be used and the 'Model%Simulation' is the right place to write in? How can I get historical value of it? because this time %PrevValues still returning error.

Re: Storing an variable from UDF at each iteration step

Posted: 03 May 2024, 16:59
by raback
Hi Eric,

What is the size of your variable?

Are you sure that your case is an UDF rather than a Solver. If you have transient history then the Solver provides some services to advance a variable forward when doing timestepping. So what would the UDF do? The answer depends on your goal.

-Peter