I did like you said but it seems that it just save the record in some steps i have provided more detailed code below
function new_EnergyState(ψPlusPrev_in,ψhPos_in, el)
ψPlus_in = ψhPos_in
if ψPlus_in >=ψPlusPrev_in
ψPlus_out =ψPlus_in
push!(el, ψPlus_out)
else
ψPlus_out=ψPlusPrev_in
push!(el, ψPlus_out)
end
true,ψPlus_out
end
function stepPhaseField(fem_params, uh_in,ΨPlusPrev_in)
A_PF(s,φ,uh_in,ΨPlusPrev_in) =Gc*ls*∇(φ)⋅∇(s) + (2*ΨPlusPrev_in*s*φ) + (Gc/ls)*s*φ
a_PF(s,φ) = ∫(A_PF(s,φ,uh_in,ΨPlusPrev_in))fem_params.dΩ
b_PF(φ) =∫((Gc/ls)*φ)fem_params.dΩ
op_PF = AffineFEOperator(a_PF,b_PF ,U_PF ,V0_PF)
sh_out = solve(op_PF)
# return sh_out
return get_free_dof_values(sh_out)
end
using Gridap.CellData
function stepDisp(fem_params,pth, uh_in,sh_in, vApp)
uApp1(x) = VectorValue(0.0,0.0)
uApp2(x) = VectorValue(0.0,0.0)
uApp3(x) = VectorValue(0.0,-vApp)
U_Disp = TrialFESpace(V0_Disp ,[uApp1 ,uApp2 ,uApp3])
A_Disp(u,v,pth,uh_in,sh_in) = ((p->Em(p))∘pth) * (ε(v) ⊙ (σfun∘(ε(u), ε(uh_in), sh_in)))
a_Disp(u,v) =∫(A_Disp(u,v,pth,uh_in,sh_in))fem_params.dΩ
b_Disp(v) = 0.0
op_Disp = AffineFEOperator(a_Disp ,b_Disp ,U_Disp ,fem_params.V0_Disp)
uh_out = solve(op_Disp)
# return uh_out
return get_free_dof_values(uh_out)
end
innerMax = 10
count = 0
vApp = 0
ψPlusPrev = CellState(0.0,dΩ)
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)
sl = zeros(sr,co)
ul = zeros(ur,co)
vl = zeros(co)
el=[]
push!(el, ψPlusPrev)
while vApp .< vAppMax
count = count .+ 1
if vApp >= vAppmid
delv = delvmid
end
vApp = vApp .+ delv
print("\n step", float(vApp))
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)fem_params.dΩ-∫( (Gc/ls)*sh)fem_params.dΩ))/abs(sum(∫( (Gc/ls)*sh)fem_params.dΩ))
sh_vec = stepPhaseField(fem_params,uh,ψhPlusPrev)
sh = FEFunction(fem_params.U_PF, sh_vec)
u_vec = stepDisp(fem_params,pth, uh, sh, vApp)
uAppp1(x) = VectorValue(0.0,0.0)
uAppp2(x) = VectorValue(0.0,0.0)
uAppp3(x) = VectorValue(0.0,-vApp)
U_Disp = TrialFESpace(V0_Disp ,[uAppp1 ,uAppp2 ,uAppp3])
uh = FEFunction(U_Disp, u_vec)
ψhPos_in = ψPos∘(ε(uh))
update_state!( new_EnergyState ,ψPlusPrev ,ψhPos_in)
if RelErr < 1e-8
sl[:,count] = sh_vec
ul[:,count] = u_vec
vl[count] = vApp
println("Energy", el)
break
end
end
end
writevtk(Ω,"resultstph",cellfields=["uh"=>uh, "sh"=>sh])
and the output is like below
step0.001EnergyAny[CellState()]
step0.002EnergyAny[CellState()]
step0.003EnergyAny[CellState()]
step0.004EnergyAny[CellState()]
step0.005EnergyAny[CellState()]
step0.006EnergyAny[CellState()]
step0.007EnergyAny[CellState()]
step0.008EnergyAny[CellState()]
step0.009000000000000001EnergyAny[CellState()]
step0.010000000000000002EnergyAny[CellState()]
step0.011000000000000003EnergyAny[CellState()]
step0.012000000000000004EnergyAny[CellState()]
step0.013000000000000005EnergyAny[CellState()]
step0.014000000000000005EnergyAny[CellState()]
step0.015000000000000006EnergyAny[CellState()]
step0.016000000000000007EnergyAny[CellState()]
step0.017000000000000008EnergyAny[CellState()]
step0.01800000000000001EnergyAny[CellState()]
step0.01900000000000001EnergyAny[CellState()]
step0.02000000000000001EnergyAny[CellState()]
step0.02100000000000001EnergyAny[CellState()]
step0.022000000000000013EnergyAny[CellState()]
step0.023000000000000013EnergyAny[CellState()]
step0.024000000000000014EnergyAny[CellState()]
step0.025000000000000015EnergyAny[CellState()]
step0.026000000000000016EnergyAny[CellState()]
step0.027000000000000017EnergyAny[CellState()]
step0.028000000000000018EnergyAny[CellState()]
step0.02900000000000002EnergyAny[CellState()]
step0.03000000000000002EnergyAny[CellState()]
step0.03010000000000002EnergyAny[CellState()]
step0.03020000000000002EnergyAny[CellState()]
step0.030300000000000018EnergyAny[CellState()]
step0.030400000000000017EnergyAny[CellState()]
step0.030500000000000017EnergyAny[CellState()]
step0.030600000000000016EnergyAny[CellState()]
step0.030700000000000015EnergyAny[CellState()]
step0.030800000000000015EnergyAny[CellState()]
step0.030900000000000014EnergyAny[CellState()]
step0.031000000000000014EnergyAny[CellState()]
step0.031100000000000013EnergyAny[CellState()]
step0.031200000000000012EnergyAny[CellState()]
step0.031300000000000015EnergyAny[CellState()]
step0.03140000000000002EnergyAny[CellState()]
step0.03150000000000002EnergyAny[CellState()]
step0.031600000000000024EnergyAny[CellState()]
step0.03170000000000003EnergyAny[CellState()]
step0.03180000000000003EnergyAny[CellState()]
step0.03190000000000003EnergyAny[CellState()]
step0.032000000000000035EnergyAny[CellState()]
step0.03210000000000004EnergyAny[CellState()]
step0.03220000000000004EnergyAny[CellState()]
step0.032300000000000044EnergyAny[CellState()]
step0.03240000000000005EnergyAny[CellState()]
step0.03250000000000005EnergyAny[CellState()]
step0.03260000000000005EnergyAny[CellState()]
step0.032700000000000055EnergyAny[CellState()]
step0.03280000000000006EnergyAny[CellState()]
step0.03290000000000006EnergyAny[CellState()]
step0.033000000000000064EnergyAny[CellState()]
step0.03310000000000007EnergyAny[CellState()]
step0.03320000000000007EnergyAny[CellState()]
step0.03330000000000007EnergyAny[CellState()]
step0.033400000000000075EnergyAny[CellState()]
step0.03350000000000008EnergyAny[CellState()]
step0.03360000000000008EnergyAny[CellState()]
step0.033700000000000084EnergyAny[CellState()]
step0.03380000000000009EnergyAny[CellState()]
step0.03390000000000009EnergyAny[CellState()]
step0.03400000000000009EnergyAny[CellState()]
step0.034100000000000096EnergyAny[CellState()]
step0.0342000000000001EnergyAny[CellState()]
step0.0343000000000001EnergyAny[CellState()]
step0.034400000000000104EnergyAny[CellState()]
step0.03450000000000011EnergyAny[CellState()]
step0.03460000000000011EnergyAny[CellState()]
step0.03470000000000011EnergyAny[CellState()]
step0.034800000000000116
step0.03490000000000012EnergyAny[CellState()]
step0.03500000000000012
step0.035100000000000124EnergyAny[CellState()]
step0.03520000000000013
step0.03530000000000013EnergyAny[CellState()]
step0.03540000000000013
step0.035500000000000136
step0.03560000000000014EnergyAny[CellState()]
step0.03570000000000014
step0.035800000000000144
step0.03590000000000015
step0.03600000000000015
step0.03610000000000015
step0.036200000000000156
step0.03630000000000016
step0.03640000000000016
step0.036500000000000164
step0.03660000000000017
step0.03670000000000017
step0.03680000000000017
step0.036900000000000176
step0.03700000000000018
step0.03710000000000018
step0.037200000000000184
step0.03730000000000019
step0.03740000000000019
step0.03750000000000019
step0.037600000000000196
step0.0377000000000002
step0.0378000000000002
step0.037900000000000204
step0.03800000000000021
step0.03810000000000021
step0.03820000000000021
step0.038300000000000216
step0.03840000000000022
step0.03850000000000022
step0.038600000000000224
step0.03870000000000023
step0.03880000000000023
step0.03890000000000023
step0.039000000000000236
step0.03910000000000024
step0.03920000000000024
Also it seems that in this way by using record inside the calculate sth it will save record in every iteration of for loop in inner counter. I need the final value of calculate sth in each vApp
thank you