Using gradient_s subroutine on user defined fields

Questions and remarks about code_saturne usage
Forum rules
Please read the forum usage recommendations before posting.
Post Reply
mattfalc1997
Posts: 12
Joined: Wed Jun 20, 2018 3:27 pm

Using gradient_s subroutine on user defined fields

Post by mattfalc1997 »

I'm try to use the gradient_s subroutine to find the gradient of a user defined scalar, however I get an error 'Forbidden memory access intercepted' but I'm not sure which part of it is causing it. There are quite a few terms so I may have misinterpreted some of them. If there are other methodologies for finding the gradient of user defined variables that would also be welcome. I have used the modules: field, field_operator, mesh, numvar, cs_c_bindings.

Thanks in advance
Matt

Code: Select all

subroutine TKE_advection
double precision, dimension(:),pointer :: pvar
double precision, dimension(3,ncelet) :: TKE_grad
double precision, dimension(nfabor) :: coefap, coefbp

integer :: fid,imrgra,inc,recompute_cocg,nswrgp,imligp,iwarnp,i
double precision :: epsrgp, climgp, extrap
call field_get_val_s_by_name("TKE",pvar)

    fid=-1
    imrgra=0            !Gradient calculation mode: use iterative process
    inc=1               ! Do not increment
    recompute_cocg=0    ! Do not recompute COCG
    nswrgp=2            ! Number of sweeps for reconstruction
    imligp=-1           !No gradient limitation method
    iwarnp=0            ! No verbosity
    epsrgp=1.d-6        !Relative precision
    climgp=0.d0         !limiter coefficient for imligp: not required
    extrap=0.d0         !Gradient extrapolation coefficient: not required
    coefap=0.d0         !Boundary coefficient: No gradient
    coefbp=1.d0         !Boundary coefficent: dirichlet coefficent

    call gradient_s(fid,imrgra,inc,recompute_cocg,nswrgp,imligp,iwarnp,epsrgp,climgp,extrap,&
                        pvar,coefap,coefbp,TKE_grad)


end subroutine TKE_advection
mattfalc1997
Posts: 12
Joined: Wed Jun 20, 2018 3:27 pm

Re: Using gradient_s subroutine on user defined fields

Post by mattfalc1997 »

Just a further update, I corrected part of the subroutine and it seems to work for the first iteration, but the same error returns on iteration 2. I think this is because on the first iteration the variable (Turbulent Kinetic Energy) is 0, but as soon as the variable becomes non zero on iteration 2, it causes forbidden memory access, could it be caused by my choice of boundary coefficients (coefap, coefbp)?

Thanks again
Yvan Fournier
Posts: 4152
Joined: Mon Feb 20, 2012 3:25 pm

Re: Using gradient_s subroutine on user defined fields

Post by Yvan Fournier »

Hello,

To determine where the error is commng from, running a debug build would be the best option.
But chances are it is related to coefap/coefbp. Also, you directly define arrays which may be large (such as TKE_grad) with their dimension, rather than declaring them as allocatable and allocating them. Depending on how the compiler works (allocating it on the stack or on the heap), it might or might not work.

So running under a debugger (ideally under Valgrind) would help pinpoint the issue.

Best regards,

Yvan
Post Reply