Re: include external field map in MAGFLD

From: Giuseppe Battistoni <Giuseppe.Battistoni_at_mi.infn.it>
Date: Wed, 29 Jul 2009 10:15:30 +0200 (CEST)

Sorry I have not an easy example to show, but I can guide you through the
logic that you have to implement.
There are 2 key points:
1) you must be able to OPEN and READ an external file
which gives a map of magnetic field (3 components) as a function of
x, y, z coordinates in a 3-D lattice, storing them in vectors defined by
you.
2) you must be able to code an algorithm capable to interpolate in
the map, using the above vector, and return the best estimate of the field
components at the run time coordinate X,Y,Z avaibale in the MAGFLD
routine.

Such codes line can be places in the following skeleton, where I imagined
that you will store tha map in 3 vectors BX(I,J,K), BY(I,J,K) and
BZ(I,J,K), where I,J and K are the indeces runnnig through the lattice
points contained in vectors XB(I), YB(J), ZB(K). The index I runs from 1
to NX, J runs from 1 to NY and K runs from 1 to NZ. The dimensions NX, NY
and NZ are given as parameters,

*===magfld=============================================================*
*
      SUBROUTINE MAGFLD ( X, Y, Z, BTX, BTY, BTZ, B, NREG, IDISC )

      INCLUDE '(DBLPRC)'
      INCLUDE '(DIMPAR)'
      INCLUDE '(IOUNIT)'
*
*----------------------------------------------------------------------*
* *
* Copyright (C) 1988-2005 by Alberto Fasso` & Alfredo Ferrari *
* All Rights Reserved. *
* *
* *
* Created in 1988 by Alberto Fasso`, CERN - TIS *
* *
* Last change on 11-dec-92 by Alfredo Ferrari *
* *
* Input variables: *
* x,y,z = current position *
* nreg = current region *
* Output variables: *
* btx,bty,btz = cosines of the magn. field vector *
* B = magnetic field intensity (Tesla) *
* idisc = set to 1 if the particle has to be discarded *
* *
*----------------------------------------------------------------------*
*
      PARAMETER (NX=....)
      PARAMETER (NY=....)
      PARAMETER (NZ=....)
      DIMENSION BX(NX,NY,NZ)
      DIMENSION BY(NX,NY,NZ)
      DIMENSION BZ(NX,NY,NZ)
      DIMENSION XB(NX), YB(NY), ZB(NZ)

      LOGICAL LFIRST
      DATA LFIRST /.TRUE./
      SAVE LFIRST

      IDISC = 0

      IF (LFIRST) THEN
         
* Here, at the first time in which MAGFLD is called
* open and read a file containing a map of the 3 magnetic field components
* BX(I,J,K), BY(I,J,K), BZ(I,J,K)
* in a lattice of points in 3 dimensions XB(I), YB(J), ZB(K). There are
* NX points in X with running index I
* NY points in Y with running index J
* NZ points in Z with running index K
         OPEN (....)
         READ (...) BTX(..), BTY(...), BTZ(...), ....
         ......
         ......
         LFIRST = .FALSE.
      ENDIF

* Optional check on the Region at run time, to avoid calculation in
* regions where magnetic field is expected to be null..
      IF(NREG .NE. ...) THEN
         WRITE (LUNOUT,*)
     & ' Magfld called in zone ',NREG,' where there should'
         WRITE (LUNOUT,*)
     & ' be no magnetic field. Something is wrong'
         IDISC = 1
         RETURN
      ELSE
* Each time the routine is called, activate an
* algorithm of your choice that, given the particle coordinates X, Y
* and Z, finds the closest XB(), YB() and ZB() coordinates and
* interpolates the local value of BX, BY and BZ...
* Then:
         B = SQRT(BX**2 + BY**2 + BZ**2)
         BTX = X / B
         BTY = Y / B
         BTZ = Z / B
         RETURN
      ENDIF
*=== End of subroutine magfld =========================================*
      END

Hope it helps...

        Giuseppe Battistoni

On Tue, 28 Jul 2009, Christian Richter wrote:

> Dear Fluka-Experts,
>
> As I am a Fluka-Beginner, I have the following question:
> Is there a sample code of the MAGFLD routine available that implements an
> external 3D magnetic field
> map in Fluka?
>
> Thank you a lot in advance.
>
> Best regards,
> Christian Richter
>
>
>
Received on Wed Jul 29 2009 - 10:49:36 CEST

This archive was generated by hypermail 2.2.0 : Wed Jul 29 2009 - 10:49:36 CEST