# Calculating an entity every 1000th step/cycle

Greetings!
I have created a simple script codepart1 (attached) which is working well with no errors. As shown in Fig below, the problem consists of a top platen, rock sample, and bottom platen. Top platen is being applied a downward velocity of 0.01m/s and bottom platen is fixed.
In codepart2, I want to calculate a particular entity like stress or strain every 1000th cycle/step. To simplify, in the example shown below, I want to update the value of abc after every 1000th step. Here is the codepart2

``````fish define P
k = cycle ; variable k is assigned the current cycle value
abc = 0 ; initialize abc
loop while k/1000 = (1,5) ; currently I have around 5000 steps hence k/1000 will vary from 1 to 5
abc = k
end_loop
end
history @k
history @abc
@P
block cycle time 0.0005
``````

The output I am expecting is abc = 1000, 2000, 3000, 4000, 5000. However, when I check the histories of k and abc, it is blank. I am not getting where is the error. I am not sure if I am using the correct commands like if I need to use loop for or something else. Kindly help. Thank you.
UCS7code.txt (2.3 KB)

Hi @venkateshmd,

that is quite a mess and I’m not even sure where to start.
In order for your function to be evaluate every XX steps you have to actually make a history for that function, so history @P in your case.

If your are fine with a general history interval of 1000 (also for displacements etc.) you can then simply set history interval 1000 and your function will be executed every 1000 steps and also update your observation values (stress etc.).

Also, you don’t need a loop in your function (or only if you want to control your whole run with it and always cycle 1000 steps and calculate values for a given number of iterations). Since you seem new to FISH I would heavily suggest the former method: One simple evaluation function that is evaluated at the intervals specified by history interval.

history interval 1000 does the job. However, it causes all history variables to be calculated once every 1000 steps. I was thinking about running my fish function and its related variables only. Other variables like stress-yy or strain-xx can be calculated every single time step.

You could introduce a counting number for this purpose, like:

counting_n = 0
whilestepping
counting_n = counting_n + 1
if counting_n = 1000 then
; do what you want to do every 1000 steps
counting_n = 0 ;initiate the counting number
endif

these are the fish codes for older version 6.0, not sure if they still work in 7.0

1 Like

Thank you. I will implement this and see if it works. Will post back here.