# PETSc SNES solver for mixed space and bounds;

**URL:** <https://fenicsproject.discourse.group/t/petsc-snes-solver-for-mixed-space-and-bounds/726>\
**Category:** variational formulation\
**Created:** [May 3, 2019, 11:40am UTC](https://fenicsproject.discourse.group/t/petsc-snes-solver-for-mixed-space-and-bounds/726 "2019-05-03T11:40:18Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![siddhartha\_harsha\_om](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/siddhartha_harsha_om/32/93_2.png) [@siddhartha\_harsha\_om](https://fenicsproject.discourse.group/u/siddhartha_harsha_om)\
**Post date:** [May 3, 2019, 11:40am UTC](https://fenicsproject.discourse.group/t/petsc-snes-solver-for-mixed-space-and-bounds/726/1 "2019-05-03T11:40:18Z")

</div>

Hi All,

I am trying to solve a NonLinear mixed problem using PETSc SNES solver. The mixed space is made up of 3 elements (`P2-P1-P1`) to solve for three unknowns say (`u, p, s`). I need upper and lower bounds only on the last solution (`0<= s <=1`). Extending from the snes [demo](https://github.com/FEniCS/dolfin/blob/master/demo/undocumented/contact-vi-snes/python/demo_contact-vi-snes.py), I need to create two functions carrying the upper and lower bounds for the solution of `s`. As a naive attempt I did the following.

```
#Creating function spaces
V_ele = VectorElement('P',mesh.ufl_cell(), 2)
Q_ele = FiniteElement('P',mesh.ufl_cell(), 1)
W = FunctionSpace(mesh,MixedElement(V_ele,Q_ele,Q_ele))

#Creating the box constraints to pass to the SNES solver
smin, smax = Function(W), Function(W)
smin_nodal_values = smin.sub(2).vector()
smin_array = smin_nodal_values.get_local()
smin_array.fill(Constant(0.0))
smin.sub(2).vector()[:] = smin_array

smax_nodal_values = smax.sub(2).vector()
smax_array = smax_nodal_values.get_local()
smax_array.fill(Constant(1.0))
smax.sub(2).vector()[:] = smax_array

```

And then I go ahead and pass these to the solver by

`NonlinearVariationalProbelm().set_bounds(smin, smax)`

Is there any better way to do this? At the moment I cannot verify with the solution of the problem, because there is a divergence maybe because of some other reason or because of this method. At least want to make sure I am doing this right. One thing I am not sure about is if I am passing any unintended bounds to the `u` and `p` spaces also by this method. Since they are not assigned any bounds they must be 0 ? Ideally they should not have any.

Thanks,  
Sid

---

<div class="post-metadata">

**Author:** ![xiaodong\_zhang](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/xiaodong_zhang/32/1135_2.png) [@xiaodong\_zhang](https://fenicsproject.discourse.group/u/xiaodong_zhang)\
**Post date:** [March 14, 2022, 4:53pm UTC](https://fenicsproject.discourse.group/t/petsc-snes-solver-for-mixed-space-and-bounds/726/2 "2022-03-14T16:53:56Z")

</div>

Hi, Sir. Did you solve the problem?
