Iteration counter

Hi,
I want to track the load steps in my code using gridap but i got operation cell field out of this code and I cant get the values. Is this way right to implement this? Also I added this print lines to check the process but I couldnt get any print notifications out of it.

function new_EnergyStateit(ψPlusPrev_in, ψhPos_in, current_step,last_update)
    ψPlus_in = ψhPos_in
    if ψPlus_in >= ψPlusPrev_in
        last_update = current_step
        println("Updated at step $current_step, last_update set to $last_update")
    else
        println("No update at step $current_step, last_update remains $last_update")
    end
    return last_update
end

I used this function as below

    update_steps = [] 
    last_update = 1.0  # Tracks the last update step

    while vApp <= vAppMax
        count = count + 1
         ψhPos_in = (ψPos∘(ε(uh)))
            current_step= count
            last_update = new_EnergyStateit∘(ψPlusPrev, ψhPos_in, current_step,last_update)
            update_state!( new_EnergyState ,ψPlusPrev ,ψhPos_in)
        end
        push!(update_steps,last_update)

in this case the output for update_steps is

50-element Vector{Any}:
 new_EnergyStateit ∘ (CellState(), OperationCellField(), 1, 1.0)
 new_EnergyStateit ∘ (CellState(), OperationCellField(), 2, new_EnergyStateit ∘ (CellState(), OperationCellField(), 2, new_EnergyStateit ∘ (CellState(), OperationCellField(), 2, new_EnergyStateit ∘ (CellState(), OperationCellField(), 2, new_EnergyStateit ∘ (CellState(), OperationCellField(), 1, 1.0))))) 
.
.
.

Sorry your question is not very clear to me, can you rephrase and provide a complete runnable code (with all imports and definitions), along with a description of what it does not do correctly?

1 Like

Sorry about that. let me clarify. I have applied incremental loading so there is n load steps which i have it in the code as count. at each count there is an if condition whether the energy is higher than previous load step or not. if it is true I should save that count and if it is not i should save the latest value of count. for example if I have 50 load steps I should have an array including 50 load steps and in each element I should have the count number if it satisfied the if condition or the latest one if it is not satisfied. this value should be save for each element of domain. I couldnt simplify the code more than this to be runnable.
let me know if you have any questions.
thank you

While I also do not fully understand the question, I would assume the problem lies in

Here you are creating a ComposedFunction instead of calling new_EnergyStateit, so no print statements are reached. I assume you’d want to just use last_update = new_EnergyStateit(ψPlusPrev, ψhPos_in, current_step, last_update). The same is probably also true in ψhPos_in = (ψPos∘(ε(uh))).

1 Like