cmt-dtu-energy / MagTense

MagTense - a micromagnetism and magnetostatic framework
http://www.MagTense.org
GNU General Public License v3.0
28 stars 12 forks source link

Compiling MagTense with gfortran #30

Closed lazersos closed 1 year ago

lazersos commented 1 year ago

Hello, I'm trying to compile MagTense with gfortran but I'm running into an issue in NumericalIntegrals.f90. I'm on the master branch.

make
cd source/NumericalIntegration/NumericalIntegration && /Applications/Xcode.app/Contents/Developer/usr/bin/make
/opt/local/bin/gfortran -c -O3 -fopenmp -fdefault-real-8 -ffixed-line-length-none -fPIC IntegrationDataTypes.f90
/opt/local/bin/gfortran -c -O3 -fopenmp -fdefault-real-8 -ffixed-line-length-none -fPIC quadpack.f90
/opt/local/bin/gfortran -c -O3 -fopenmp -fdefault-real-8 -ffixed-line-length-none -fPIC NumericalIntegrals.f90
NumericalIntegrals.f90:304:17:

  304 |         f_ptr => h
      |                 1
Error: Interface mismatch in procedure pointer assignment at (1): INTENT mismatch in argument 'dat'
make[1]: *** [NumericalIntegrals.o] Error 1
make: *** [all] Error 2

It seem like it could be related to this Compiler feature.

For context, we'd like to build the Fortran parts of this code and interface them to the particle following code in STELLOPT/BEAMS3D. This will allow us to include magnetic material in our simulations allowing us to model particle orbits in neutral beam boxes and the effect of ferretic inserts.

lazersos commented 1 year ago

It seems like adding INTENT(inout) to dat in the h function fixes this issue.


    function h(xx, dat)
        real :: h
        real,intent(in) :: xx
        real :: ss, res
        class(dataCollectionBase), INTENT(inout), target :: dat
        procedure (f_int_dat_vec), pointer :: f_ptr => null ()
        real :: tmp

        f_ptr => f_vec
        dat%x = xx

        call qags_y_vec( f_ptr, dat, dat%y1, dat%y2, dat%epsabs, dat%epsrel, ss, dat%abserr_y, dat%neval_y, dat%ier_y )    
        h = ss

        if ( mod( dat%progCallbackCnt, 100 ) .eq. 0 ) then
            !! Progress callback
            tmp = dat%progCallback( dat )
        endif

        dat%progCallbackCnt = dat%progCallbackCnt + 1

        return
    end function h
spollok commented 1 year ago

Hi @lazersos, We are excited that you are trying to use our code and to interface it to the particle following code. Thank you for opening the issue. And thank you even more for directly coming up with a solution to it 💯

We have implemented your solution directly into the master branch 👍 Additionally, we have reworked the Makefile in that folder and tested compilation successfully with gfortran and ifort.

Please feel free to open another issue if you run into any sort of problem. We are happy to fix them.