# Equality constrain to NLopt

Hi, I am doing topology optimization. I have seen some tutorials. I want to add volume constrain to my model as below:

``````v/v0=f
``````

which v is material volume and v0 is domain volume and f is volume fraction.
could you please tell me how can i add this to my code

``````using NLopt

function gf_p_optimize(p_init; r, β, η, TOL = 1e-6, MAX_ITER = 700, fem_params)
##################### Optimize #################
opt = Opt(:LD_CCSAQ, fem_params.np)
opt.lower_bounds = 0
opt.upper_bounds = 1
opt.ftol_rel = TOL
opt.maxeval = MAX_ITER

(g_opt, p_opt, ret) = optimize(opt, p_init)
@show numevals = opt.numevals # the number of function evaluations
return g_opt, p_opt

end
``````

thank you

CCSAQ doesn’t support equality constraints — the CCSA algorithm requires the feasible set to have a non-empty interior in general.

Normally if you are doing structural optimization you can replace volume constraints with an inequality constraint V ≤ f V_0, since the optimization naturally “wants” the structure to use as much material as possible (i.e. the constraint will be active at the optimum, so you will end up with V = f V_0).

so it should be work by adding

``````    inequality_constraint!(opt, sum(p0) - 0.4*fem_params.np<0)
``````

what if i dont implement constrain in my model?