# Object is in wrong state

**URL:** <https://community.freefem.org/t/object-is-in-wrong-state/1145>\
**Category:** General Discussion\
**Created:** [August 9, 2021, 1:56pm UTC](https://community.freefem.org/t/object-is-in-wrong-state/1145 "2021-08-09T13:56:44Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mik](https://avatars.discourse-cdn.com/v4/letter/m/958977/32.png) [@Mik](https://community.freefem.org/u/Mik)\
**Post date:** [August 9, 2021, 1:56pm UTC](https://community.freefem.org/t/object-is-in-wrong-state/1145/1 "2021-08-09T13:56:44Z")

</div>

Dear members,

I have stumbled upon a Petsc error.  
Out of my full mesh, I am trying to solve the heat transfer problem on selected volume numbers defined as reg. Apart from these volume numbers, the rest are not solving for the heat transfer. So T=Tinitial for the unused volume numbers.

While adding the selected volume numbers in int3d(Th1, **reg** , qfV=qfV1), I am getting a Petsc error:  
Object is in wrong state

I think it is due to the fact that I am trying to solve in a selected volume numbers because if I remove this it works perfectly.

How to overcome this error?

I am attaching a test version of my problem in the attachment.  
Thanks in advance for your help and time.

[https://drive.google.com/drive/folders/1xARiZzE3yTov5bIwE2EXL3UpUVhQKWGn?usp=sharing](https://drive.google.com/drive/folders/1xARiZzE3yTov5bIwE2EXL3UpUVhQKWGn?usp=sharing)

---

<div class="post-metadata">

**Author:** ![prj](https://avatars.discourse-cdn.com/v4/letter/p/ecae2f/32.png) [@prj](https://community.freefem.org/u/prj)\
**Post date:** [August 9, 2021, 2:09pm UTC](https://community.freefem.org/t/object-is-in-wrong-state/1145/2 "2021-08-09T14:09:20Z")

</div>

Always look at the error message in full please…

```auto
[1]PETSC ERROR: Object is in wrong state
[1]PETSC ERROR: Matrix is missing diagonal entry 31

```

Furthermore, if you look at the trace, you’ll see something like:

```auto
[1]PETSC ERROR: #1 MatILUFactorSymbolic_SeqAIJ() at /ccc/work/cont003/rndm/rndm/petsc/src/mat/impls/aij/seq/aijfact.c:1697
[1]PETSC ERROR: #2 MatILUFactorSymbolic() at /ccc/work/cont003/rndm/rndm/petsc/src/mat/interface/matrix.c:6942
[1]PETSC ERROR: #3 PCSetUp_ILU() at /ccc/work/cont003/rndm/rndm/petsc/src/ksp/pc/impls/factor/ilu/ilu.c:144
[1]PETSC ERROR: #4 PCSetUp() at /ccc/work/cont003/rndm/rndm/petsc/src/ksp/pc/interface/precon.c:1016
[1]PETSC ERROR: #5 KSPSetUp() at /ccc/work/cont003/rndm/rndm/petsc/src/ksp/ksp/interface/itfunc.c:406
[1]PETSC ERROR: #6 PCSetUpOnBlocks_BJacobi_Singleblock() at /ccc/work/cont003/rndm/rndm/petsc/src/ksp/pc/impls/bjacobi/bjacobi.c:617
[1]PETSC ERROR: #7 PCSetUpOnBlocks() at /ccc/work/cont003/rndm/rndm/petsc/src/ksp/pc/interface/precon.c:1047
[1]PETSC ERROR: #8 KSPSetUpOnBlocks() at /ccc/work/cont003/rndm/rndm/petsc/src/ksp/ksp/interface/itfunc.c:214
[1]PETSC ERROR: #9 KSPSolve_Private() at /ccc/work/cont003/rndm/rndm/petsc/src/ksp/ksp/interface/itfunc.c:851
[1]PETSC ERROR: #10 KSPSolve() at /ccc/work/cont003/rndm/rndm/petsc/src/ksp/ksp/interface/itfunc.c:1084

```

You think you are using `-pc_type hypre`, but in reality your are not, since there is a typo in your sparams, `--pc_type` → `-pc_type`.  
Your problem is singular since you are only integrating on part of the domain. This is unlikely to work, even with `-pc_type hypre`.

---

<div class="post-metadata">

**Author:** ![Mik](https://avatars.discourse-cdn.com/v4/letter/m/958977/32.png) [@Mik](https://community.freefem.org/u/Mik)\
**Post date:** [August 10, 2021, 8:05am UTC](https://community.freefem.org/t/object-is-in-wrong-state/1145/3 "2021-08-10T08:05:47Z")

</div>

Thanks for the reply.

Is there any solution or suggestion for this problem?

---

<div class="post-metadata">

**Author:** ![prj](https://avatars.discourse-cdn.com/v4/letter/p/ecae2f/32.png) [@prj](https://community.freefem.org/u/prj)\
**Post date:** [August 10, 2021, 10:25am UTC](https://community.freefem.org/t/object-is-in-wrong-state/1145/4 "2021-08-10T10:25:10Z")

</div>

With PETSc, there is almost always a solution, which is almost always in one of the example from the distribution. Please see [FreeFem-sources/restriction-2d-PETSc.edp at develop · FreeFem/FreeFem-sources · GitHub](https://github.com/FreeFem/FreeFem-sources/blob/develop/examples/hpddm/restriction-2d-PETSc.edp). In your case, [line 19](https://github.com/FreeFem/FreeFem-sources/blob/develop/examples/hpddm/restriction-2d-PETSc.edp#L19) should read `Ph cond = region == reg;`, and then remove the `reg` inside the integrals.

---

<div class="post-metadata">

**Author:** ![Mik](https://avatars.discourse-cdn.com/v4/letter/m/958977/32.png) [@Mik](https://community.freefem.org/u/Mik)\
**Post date:** [August 13, 2021, 8:32am UTC](https://community.freefem.org/t/object-is-in-wrong-state/1145/5 "2021-08-13T08:32:23Z")

</div>

Are you suggesting by truncating the mesh?  
Then I already have one approach with FreeFEM which works beautifully with **trunc** command.

I am trying a new approach with the region-based integration, despite the presence of the complete mesh. It works good with **solve** but not when do it with **varf**.

---

<div class="post-metadata">

**Author:** ![prj](https://avatars.discourse-cdn.com/v4/letter/p/ecae2f/32.png) [@prj](https://community.freefem.org/u/prj)\
**Post date:** [August 13, 2021, 8:57am UTC](https://community.freefem.org/t/object-is-in-wrong-state/1145/6 "2021-08-13T08:57:19Z")

</div>

Why do you need a new approach? Is there a real need for the region-based integration? One way to bypass the problem may be to add a small regularization to make the problem definite, e.g., `int3d(Th, !reg)(eps * u * v)`, with a small `eps`.
