PrincetonUniversity / SPEC

The Stepped-Pressure Equilibrium Code, an advanced MRxMHD equilibrium solver.
https://princetonuniversity.github.io/SPEC/
GNU General Public License v3.0
25 stars 6 forks source link

Segmentation fault when using Lfindzero=0? #126

Closed abaillod closed 3 years ago

abaillod commented 3 years ago

Hello,

I get a segmentation fault when running toroidal cases with Lfindzero=0. See for example the attached file (I added the .txt extension so that Github accepts it...)

G3V02L3Fi.001.sp.txt

the segmentation fault occurs in dfp200.f90 - it seems that dRodR and dZodZ are not allocated. This part is related to the derivatives of the axis w.r.t the boundary. I don't understand why SPEC enters this part of the code when Lfindzero=0 - is a flag wrongly set somewhere? Lcomputederivatives or something similar? In general, do we want SPEC to compute the force gradient if Lfindzero=0?

I don't know since when this bug is part of the code, maybe I introduced it with the current constraint merge... An easy fix is to ensure that no derivatives are evaluated when Lfindzero=0, but I am not sure this is what is wanted!

jonathanschilling commented 3 years ago

@abaillod Looks strange... What branch are you using when this error occurs and is it up-to-date with the repository (so that I can try to reproduce it here)?

abaillod commented 3 years ago

@jonathanschilling master branch, latest commit (up-to-date with repository, I just did git pull origin master)

abaillod commented 3 years ago

In dfp200.f90, lines 1455-1672 are related to the computation of the force gradient. I think it should be in a if( LComputeDerivatives ) condition... Otherwise derivatives of B^2 w.r.t to the geometry are always evaluated.

Now, if Lfindzero.eq.0 and Lcheck.eq.5 .or. LHevalues .or. LHevectors .or. LHmatrix .or. Lperturbed.eq.1 then hesian is called and the derivatives are required. However dRodR and dZodZ are only allocated if Lfindzero.eq.0...

Anyway, I think the logic is broken, I will propose a fix in a minute or so.

jonathanschilling commented 3 years ago

@abaillod All the checks (except uploading an unchanged py_spec to pypi) have passed and I merged into master. Can you please verify that it works to that we can close this issue?

abaillod commented 3 years ago

Everything seems to work on my side. I close the issue.