# Update state! for a cellstate

**URL:** <https://discourse.julialang.org/t/update-state-for-a-cellstate/101681>\
**Category:** New to Julia\
**Tags:** question, gridap\
**Created:** [July 16, 2023, 9:53pm UTC](https://discourse.julialang.org/t/update-state-for-a-cellstate/101681 "2023-07-16T21:53:55Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![mary](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mary/32/53139_2.png) [@mary](https://discourse.julialang.org/u/mary)\
**Post date:** [July 16, 2023, 9:53pm UTC](https://discourse.julialang.org/t/update-state-for-a-cellstate/101681/1 "2023-07-16T21:53:55Z")

</div>

Hi, I am trying to panelize a cell state and then use it in a update state function in gridap but it gives me error. I appreciate your suggestions.

```julia
innerMax = 10
p0 = ones(fem_params.np)
pf_vec = Filter(p0;r, fem_params)
pfh = FEFunction(fem_params.Pf, pf_vec)
pth = (pf -> Threshold(pf; β, η)) ∘ pfh
sPrev = CellState(1.0,dΩ)
sh = project(sPrev ,model,dΩ,order)
ψPlusPrev = ((p->Em(p))∘pth) * CellState(0.0,dΩ)
for inner = 1: innerMax
        ψhPlusPrev = project(ψPlusPrev ,model ,dΩ,order)
        RelErr = abs(sum(∫( Gc*ls*∇(sh)⋅∇(sh) + 2*ψhPlusPrev*sh*sh + (Gc/ls)*sh*sh)*dΩ-∫( (Gc/ls)*sh)*dΩ))/abs(sum(∫( (Gc/ls)*sh)*dΩ))
        sh_vec = stepPhaseField(fem_params,uh,ψhPlusPrev)
        sh = FEFunction(fem_params.U_PF, sh_vec)
        u_vec = stepDisp(fem_params,pth, uh, sh)
        uh = FEFunction(fem_params.U0_Disp, u_vec)
        ψhPos_in = ((p->Em(p))∘pth) * (ψPos∘(ε(uh)))
        update_state!( new_EnergyState ,ψPlusPrev ,ψhPos_in)
        if RelErr < 1e-8
            break
        end
end

writevtk(Ω,"resultstph",cellfields=["uh"=>uh, "sh"=>sh])

```

the error is

```julia
AssertionError: 

At least one CellState object has to be given to the update_state! function

Stacktrace:
 [1] update_state!(::Function, ::Gridap.CellData.OperationCellField{ReferenceDomain}, ::Vararg{Gridap.CellData.OperationCellField{ReferenceDomain}})
   @ Gridap.CellData C:\Users\marya\.julia\packages\Gridap\971dU\src\CellData\CellStates.jl:81
 [2] top-level scope
   @ In[26]:19

```

It seems that multiplication of ((p-\>Em(p))∘pth) with a cell state cause the problem but i dont know how to solve it.  
thanks

---

<div class="post-metadata">

**Author:** ![algunion](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/algunion/32/51630_2.png) [@algunion](https://discourse.julialang.org/u/algunion)\
**Post date:** [July 18, 2023, 9:13pm UTC](https://discourse.julialang.org/t/update-state-for-a-cellstate/101681/2 "2023-07-18T21:13:24Z")

</div>

If you provide a minimal working example, you can make it easier for others to help.

I suggest also including the `using` and `import` statements so we just take the MWE, run it, and reproduce the issue.
