# RE: lattice and magnetic field

From: Santana, Mario <msantana_at_SLAC.Stanford.EDU>
Date: Wed, 4 Aug 2010 12:10:32 -0700

I am not sure if, like its inverse function (GEOL2N), GEON2L has 4
parameters instead of the 3 that it used to have, if so, that could well be the
reason for the crashes.
In any case, I don't understand the value of all the code that you write
and which I copy further down. Why don't you just obtain the corresponding
lattice name and use that in the IF THEN structure that defines the field? e.g.

CALL GEOL2N(MLATTC,LATNAM,IRTLAT,Ierr)lat
IF ((LATNAM.EQ."B3TaEL ").AND.(...)) THEN
B=3D 0.103775493E+1
BTX=3D 0.00000000000000E+0
BTY=3D-0.10000000000000E+1
BTZ=3D 0.00000000000000E+0
ELSEIF ((LATNAM.EQ."B3TbEL ").AND.(...)) THEN
B=3D 0.103775493E+1
BTX=3D 0.00000000000000E+0
BTY=3D-0.10000000000000E+1
BTZ=3D 0.00000000000000E+0
...
ENDIF

Of if it was easier to use numbers (like for example, if you had
alternating quads and you want to use the MOD function to tell if they are odd or
even numbers to determine the sign of the field), why can't you just use MLATTC?
Maybe I am completely missing something, but I have the impression that the
example above will solve your problem.

Mario

---------------------------------------------------------------------------=

```--
This was the routine that you attached:
SUBROUTINE MAGFLD (X,Y,Z,BTX,BTY,BTZ,B,NREG,IDISC)
INCLUDE '(DBLPRC)'
INCLUDE '(DIMPAR)'
INCLUDE '(IOUNIT)'
INCLUDE '(LTCLCM)'
LOGICAL ISFIRST
INTEGER NAMEP(350 )
INTEGER NAMEL(350 )
DATA ISFIRST /.TRUE./
SAVE ISFIRST,NAMEP,NAMEL
IDISC=3D0
IF (ISFIRST) THEN
CALL GEON2L("B3TaEL  ",NAMEL(  1 ),IERR)
CALL GEON2L("B3TbEL  ",NAMEL(  2 ),IERR)
CALL GEON2L("B1EL    ",NAMEL(  3 ),IERR)
CALL GEON2L("B11EL   ",NAMEL(  4 ),IERR)
CALL GEON2L("Q2EL    ",NAMEL(  5 ),IERR)
CALL GEON2L("Q1EL    ",NAMEL(  6 ),IERR)
CALL GEON2L("Q3EL    ",NAMEL(  9 ),IERR)
CALL GEON2L("B2aEL   ",NAMEL( 10 ),IERR)
CALL GEON2L("B2bEL   ",NAMEL( 11 ),IERR)
CALL GEON2L("B2cEL   ",NAMEL( 12 ),IERR)
CALL GEON2L("B3aEL   ",NAMEL( 14 ),IERR)
CALL GEON2L("B3bEL   ",NAMEL( 15 ),IERR)
CALL GEON2L("B3cEL   ",NAMEL( 16 ),IERR)
CALL GEON2L("Q4EL    ",NAMEL( 17 ),IERR)
CALL GEON2L("Q5EL    ",NAMEL( 18 ),IERR)
CALL GEON2L("Q6aEL   ",NAMEL( 20 ),IERR)
CALL GEON2L("Q7aEL   ",NAMEL( 21 ),IERR)
CALL GEON2L("Q8aEL   ",NAMEL( 22 ),IERR)
CALL GEON2L("Q8bEL   ",NAMEL( 26 ),IERR)
CALL GEON2L("Q7bEL   ",NAMEL( 27 ),IERR)
CALL GEON2L("Q6bEL   ",NAMEL( 28 ),IERR)
CALL GEON2L("Q9aEL   ",NAMEL( 29 ),IERR)
CALL GEON2L("Q10aEL  ",NAMEL( 30 ),IERR)
CALL GEON2L("B4aEL   ",NAMEL( 31 ),IERR)
CALL GEON2L("B4bEL   ",NAMEL( 32 ),IERR)
CALL GEON2L("B4cEL   ",NAMEL( 33 ),IERR)
CALL GEON2L("B5aEL   ",NAMEL( 34 ),IERR)
CALL GEON2L("B5bEL   ",NAMEL( 35 ),IERR)
CALL GEON2L("B5cEL   ",NAMEL( 36 ),IERR)
CALL GEON2L("Q10bEL  ",NAMEL( 37 ),IERR)
CALL GEON2L("Q9bEL   ",NAMEL( 38 ),IERR)
CALL GEON2L("Q11EL   ",NAMEL( 40 ),IERR)
CALL GEON2L("B6EL    ",NAMEL( 41 ),IERR)
CALL GEON2L("Q13EL   ",NAMEL( 43 ),IERR)
CALL GEON2L("Q14EL   ",NAMEL( 44 ),IERR)
CALL GEON2L("Q15EL   ",NAMEL( 45 ),IERR)
CALL GEON2L("Q16EL   ",NAMEL( 46 ),IERR)
CALL GEON2L("Q17EL   ",NAMEL( 47 ),IERR)
CALL GEON2L("Q18EL   ",NAMEL( 48 ),IERR)
CALL GEON2R("MTNH0VA ",NAMEP( 1),IERR)
CALL GEON2R("MSNH0VA ",NAMEP( 2),IERR)
CALL GEON2R("MBNH0VA ",NAMEP( 3),IERR)
CALL GEON2R("MBNV0VA ",NAMEP( 4),IERR)
CALL GEON2R("QNLQ0VA ",NAMEP( 5),IERR)
CALL GEON2R("QWLQ0VA ",NAMEP( 6),IERR)
CALL GEON2R("QSLQ0VA ",NAMEP( 7),IERR)
ISFIRST =3D .FALSE.
END IF
IF((MLATTC.EQ.NAMEL( 1)).AND.(NREG.EQ.NAMEP( 1))) THEN
B=3D 0.103775493E+1
BTX=3D 0.00000000000000E+0
BTY=3D-0.10000000000000E+1
BTZ=3D 0.00000000000000E+0
ENDIF
IF((MLATTC.EQ.NAMEL( 2)).AND.(NREG.EQ.NAMEP( 1))) THEN
B=3D 0.103775493E+1
BTX=3D 0.00000000000000E+0
BTY=3D-0.10000000000000E+1
BTZ=3D 0.00000000000000E+0
ENDIF
IF((MLATTC.EQ.NAMEL( 3)).AND.(NREG.EQ.NAMEP( 2))) THEN
B=3D 0.583737146E+0
BTX=3D 0.00000000000000E+0
BTY=3D-0.10000000000000E+1
BTZ=3D 0.00000000000000E+0
ENDIF
IF((MLATTC.EQ.NAMEL( 4)).AND.(NREG.EQ.NAMEP( 2))) THEN
B=3D 0.000000000E+0
BTX=3D 0.00000000000000E+0
BTY=3D-0.10000000000000E+1
BTZ=3D 0.00000000000000E+0
ENDIF
IF((MLATTC.EQ.NAMEL( 5)).AND.(NREG.EQ.NAMEP( 5))) THEN
B=3D 0.000000000E+0
BTX=3D 0.10000000000000E+1
BTY=3D 0.00000000000000E+0
BTZ=3D 0.00000000000000E+0
ENDIF
IF((MLATTC.EQ.NAMEL( 6)).AND.(NREG.EQ.NAMEP( 7))) THEN
B=3D 0.000000000E+0
BTX=3D 0.10000000000000E+1
BTY=3D 0.00000000000000E+0
BTZ=3D 0.00000000000000E+0
ENDIF
IF((MLATTC.EQ.NAMEL( 9)).AND.(NREG.EQ.NAMEP( 5))) THEN
B=3D 0.000000000E+0
BTX=3D 0.10000000000000E+1
BTY=3D 0.00000000000000E+0
BTZ=3D 0.00000000000000E+0
ENDIF
IF((MLATTC.EQ.NAMEL(10)).AND.(NREG.EQ.NAMEP( 4))) THEN
B=3D 0.912097630E+0
BTX=3D 0.10000000000000E+1
BTY=3D 0.00000000000000E+0
BTZ=3D 0.00000000000000E+0
ENDIF
IF((MLATTC.EQ.NAMEL(11)).AND.(NREG.EQ.NAMEP( 4))) THEN
B=3D 0.912097630E+0
BTX=3D 0.10000000000000E+1
BTY=3D 0.00000000000000E+0
BTZ=3D 0.00000000000000E+0
ENDIF
IF((MLATTC.EQ.NAMEL(12)).AND.(NREG.EQ.NAMEP( 4))) THEN
B=3D 0.912097630E+0
BTX=3D 0.10000000000000E+1
BTY=3D 0.00000000000000E+0
BTZ=3D 0.00000000000000E+0
ENDIF
IF((MLATTC.EQ.NAMEL(14)).AND.(NREG.EQ.NAMEP( 4))) THEN
B=3D 0.912097630E+0
BTX=3D 0.10000000000000E+1
BTY=3D 0.00000000000000E+0
BTZ=3D 0.00000000000000E+0
ENDIF
IF((MLATTC.EQ.NAMEL(15)).AND.(NREG.EQ.NAMEP( 4))) THEN
B=3D 0.912097630E+0
BTX=3D 0.10000000000000E+1
BTY=3D 0.00000000000000E+0
BTZ=3D 0.00000000000000E+0
ENDIF
IF((MLATTC.EQ.NAMEL(16)).AND.(NREG.EQ.NAMEP( 4))) THEN
B=3D 0.912097630E+0
BTX=3D 0.10000000000000E+1
BTY=3D 0.00000000000000E+0
BTZ=3D 0.00000000000000E+0
ENDIF
IF((MLATTC.EQ.NAMEL(17)).AND.(NREG.EQ.NAMEP( 5))) THEN
B=3D 0.000000000E+0
BTX=3D 0.10000000000000E+1
BTY=3D 0.00000000000000E+0
BTZ=3D 0.00000000000000E+0
ENDIF
IF((MLATTC.EQ.NAMEL(18)).AND.(NREG.EQ.NAMEP( 5))) THEN
B=3D 0.000000000E+0
BTX=3D 0.10000000000000E+1
BTY=3D 0.00000000000000E+0
BTZ=3D 0.00000000000000E+0
ENDIF
C      IF((MLATTC.EQ.NAMEL(20)).AND.(NREG.EQ.NAMEP( 6))) THEN
C        B=3D 0.000000000E+0
C        BTX=3D 0.10000000000000E+1
C        BTY=3D 0.00000000000000E+0
C        BTZ=3D 0.00000000000000E+0
C       ENDIF
C      IF((MLATTC.EQ.NAMEL(21)).AND.(NREG.EQ.NAMEP( 5))) THEN
C        B=3D 0.000000000E+0
C        BTX=3D 0.10000000000000E+1
C        BTY=3D 0.00000000000000E+0
C        BTZ=3D 0.00000000000000E+0
C       ENDIF
C      IF((MLATTC.EQ.NAMEL(22)).AND.(NREG.EQ.NAMEP( 5))) THEN
C        B=3D 0.000000000E+0
C        BTX=3D 0.10000000000000E+1
C        BTY=3D 0.00000000000000E+0
C        BTZ=3D 0.00000000000000E+0
C       ENDIF
C      IF((MLATTC.EQ.NAMEL(26)).AND.(NREG.EQ.NAMEP( 5))) THEN
C        B=3D 0.000000000E+0
C        BTX=3D 0.10000000000000E+1
C        BTY=3D 0.00000000000000E+0
C        BTZ=3D 0.00000000000000E+0
C       ENDIF
C      IF((MLATTC.EQ.NAMEL(27)).AND.(NREG.EQ.NAMEP( 5))) THEN
C        B=3D 0.000000000E+0
C        BTX=3D 0.10000000000000E+1
C        BTY=3D 0.00000000000000E+0
C        BTZ=3D 0.00000000000000E+0
C       ENDIF
C      IF((MLATTC.EQ.NAMEL(28)).AND.(NREG.EQ.NAMEP( 6))) THEN
C        B=3D 0.000000000E+0
C        BTX=3D 0.10000000000000E+1
C        BTY=3D 0.00000000000000E+0
C        BTZ=3D 0.00000000000000E+0
C       ENDIF
C      IF((MLATTC.EQ.NAMEL(29)).AND.(NREG.EQ.NAMEP( 5))) THEN
C        B=3D 0.000000000E+0
C        BTX=3D 0.10000000000000E+1
C        BTY=3D 0.00000000000000E+0
C        BTZ=3D 0.00000000000000E+0
C       ENDIF
C      IF((MLATTC.EQ.NAMEL(30)).AND.(NREG.EQ.NAMEP( 5))) THEN
C        B=3D 0.000000000E+0
C        BTX=3D 0.10000000000000E+1
C        BTY=3D 0.00000000000000E+0
C        BTZ=3D 0.00000000000000E+0
C       ENDIF
C     IF((MLATTC.EQ.NAMEL(31)).AND.(NREG.EQ.NAMEP( 4))) THEN
C        B=3D 0.912097630E+0
C        BTX=3D-0.10000000000000E+1
C        BTY=3D 0.00000000000000E+0
C       BTZ=3D 0.00000000000000E+0
C       ENDIF
C      IF((MLATTC.EQ.NAMEL(32)).AND.(NREG.EQ.NAMEP( 4))) THEN
C       B=3D 0.912097630E+0
C        BTX=3D-0.10000000000000E+1
C        BTY=3D 0.00000000000000E+0
C        BTZ=3D 0.00000000000000E+0
C       ENDIF
C      IF((MLATTC.EQ.NAMEL(33)).AND.(NREG.EQ.NAMEP( 4))) THEN
C        B=3D 0.912097630E+0
C        BTX=3D-0.10000000000000E+1
C        BTY=3D 0.00000000000000E+0
C        BTZ=3D 0.00000000000000E+0
C       ENDIF
C      IF((MLATTC.EQ.NAMEL(34)).AND.(NREG.EQ.NAMEP( 4))) THEN
C        B=3D 0.912097630E+0
C        BTX=3D-0.10000000000000E+1
C        BTY=3D 0.00000000000000E+0
C        BTZ=3D 0.00000000000000E+0
C       ENDIF
C      IF((MLATTC.EQ.NAMEL(35)).AND.(NREG.EQ.NAMEP( 4))) THEN
C        B=3D 0.912097630E+0
C        BTX=3D-0.10000000000000E+1
C        BTY=3D 0.00000000000000E+0
C        BTZ=3D 0.00000000000000E+0
C       ENDIF
C      IF((MLATTC.EQ.NAMEL(36)).AND.(NREG.EQ.NAMEP( 4))) THEN
C         B=3D 0.912097630E+0
C         BTX=3D-0.10000000000000E+1
C         BTY=3D 0.00000000000000E+0
C         BTZ=3D 0.00000000000000E+0
C        ENDIF
C       IF((MLATTC.EQ.NAMEL(37)).AND.(NREG.EQ.NAMEP( 5))) THEN
C         B=3D 0.000000000E+0
C         BTX=3D 0.10000000000000E+1
C         BTY=3D 0.00000000000000E+0
C         BTZ=3D 0.00000000000000E+0
C        ENDIF
C       IF((MLATTC.EQ.NAMEL(38)).AND.(NREG.EQ.NAMEP( 5))) THEN
C         B=3D 0.000000000E+0
C         BTX=3D 0.10000000000000E+1
C         BTY=3D 0.00000000000000E+0
C         BTZ=3D 0.00000000000000E+0
C        ENDIF
C       IF((MLATTC.EQ.NAMEL(40)).AND.(NREG.EQ.NAMEP( 5))) THEN
C         B=3D 0.000000000E+0
C         BTX=3D 0.10000000000000E+1
C         BTY=3D 0.00000000000000E+0
C         BTZ=3D 0.00000000000000E+0
C        ENDIF
C       IF((MLATTC.EQ.NAMEL(41)).AND.(NREG.EQ.NAMEP( 3))) THEN
C         B=3D 0.800553800E+0
C         BTX=3D 0.00000000000000E+0
C         BTY=3D-0.10000000000000E+1
C         BTZ=3D 0.00000000000000E+0
C        ENDIF
C       IF((MLATTC.EQ.NAMEL(43)).AND.(NREG.EQ.NAMEP( 5))) THEN
C         B=3D 0.000000000E+0
C         BTX=3D 0.10000000000000E+1
C         BTY=3D 0.00000000000000E+0
C         BTZ=3D 0.00000000000000E+0
C        ENDIF
C       IF((MLATTC.EQ.NAMEL(44)).AND.(NREG.EQ.NAMEP( 6))) THEN
C         B=3D 0.000000000E+0
C         BTX=3D 0.10000000000000E+1
C         BTY=3D 0.00000000000000E+0
C         BTZ=3D 0.00000000000000E+0
C        ENDIF
C       IF((MLATTC.EQ.NAMEL(45)).AND.(NREG.EQ.NAMEP( 6))) THEN
C         B=3D 0.000000000E+0
C         BTX=3D 0.10000000000000E+1
C         BTY=3D 0.00000000000000E+0
C         BTZ=3D 0.00000000000000E+0
C        ENDIF
C       IF((MLATTC.EQ.NAMEL(46)).AND.(NREG.EQ.NAMEP( 5))) THEN
C         B=3D 0.000000000E+0
C         BTX=3D 0.10000000000000E+1
C         BTY=3D 0.00000000000000E+0
C         BTZ=3D 0.00000000000000E+0
C        ENDIF
C       IF((MLATTC.EQ.NAMEL(47)).AND.(NREG.EQ.NAMEP( 5))) THEN
C         B=3D 0.000000000E+0
C         BTX=3D 0.10000000000000E+1
C         BTY=3D 0.00000000000000E+0
C         BTZ=3D 0.00000000000000E+0
C        ENDIF
C       IF((MLATTC.EQ.NAMEL(48)).AND.(NREG.EQ.NAMEP( 5))) THEN
C         B=3D 0.000000000E+0
C         BTX=3D 0.10000000000000E+1
C         BTY=3D 0.00000000000000E+0
C         BTZ=3D 0.00000000000000E+0
C        ENDIF
RETURN
END
-----Original Message-----
From: Chrysostomos Valderanis [mailto:Chrysostomos.Valderanis_at_cern.ch]
Sent: Saturday, July 24, 2010 7:28 AM
To: Santana, Mario; fluka-discuss_at_fluka.org
Subject: RE: lattice and magnetic field
Hi again,
I implemented your suggestion. To be fair, I implemented the way I understood it.
But now fluka crashes. It crashes somewhere in the initialization phase.
I tried my input file without magnetic field and it works. I also tried
to comment out different sections of the magfld routine but it makes no
difference. Fluka crashes to the same point. I scan the out file for signs
of problems but I couldn't find any. It crashes to the point where it tries
to give a summary of the lattice regions.
Any hint abount what is going on is very welcomed.
Thank you,
Makis
________________________________
From: owner-fluka-discuss_at_mi.infn.it on behalf of Santana, Mario
Sent: Fri 23/07/2010 19:20
To: Chrysostomos Valderanis; fluka-discuss_at_fluka.org
Subject: RE: lattice and magnetic field
Hi Makis,
What you are asking to do is possible and it is actually quite common.
You need the following instruction in your magfld.f routine
CALL GEOL2N(MLATTC,LATNAM,IRTLAT,Ierr)
And then a code that looks like in the example below:
[...]
IF      (LATNAM.eq."QU01L  ".or.LATNAM.eq."QU03L  ".or.
\$           LATNAM.eq."QU05L  ".or.LATNAM.eq."QU07L  ".or.
\$           LATNAM.eq."QU09L  ".or.LATNAM.eq."QU11L  ".or.
\$           LATNAM.eq."QU13L  ".or.LATNAM.eq."QU15L  ".or.
\$           LATNAM.eq."QU17L  ".or.LATNAM.eq."QU19L  ".or.
\$           LATNAM.eq."QU21L  ".or.LATNAM.eq."QU23L  ".or.
\$           LATNAM.eq."QU25L  ".or.LATNAM.eq."QU27L  ".or.
\$           LATNAM.eq."QU29L  ".or.LATNAM.eq."QU31L  ".or.
\$           LATNAM.eq."QU33L  ") THEN
ck =3D3D  3.85D-01 * 7.8/7.32  ! effective length=3D3D7.8 cm
ELSE IF (LATNAM.eq."QU02L  ".or.LATNAM.eq."QU04L  ".or.
\$           LATNAM.eq."QU06L  ".or.LATNAM.eq."QU08L  ".or.
\$           LATNAM.eq."QU10L  ".or.LATNAM.eq."QU12L  ".or.
\$           LATNAM.eq."QU14L  ".or.LATNAM.eq."QU16L  ".or.
\$           LATNAM.eq."QU18L  ".or.LATNAM.eq."QU20L  ".or.
\$           LATNAM.eq."QU22L  ".or.LATNAM.eq."QU24L  ".or.
\$           LATNAM.eq."QU26L  ".or.LATNAM.eq."QU28L  ".or.
\$           LATNAM.eq."QU30L  ".or.LATNAM.eq."QU32L  ") THEN
ck =3D3D -3.85D-01 * 7.8/7.32  ! effective length=3D3D7.8 cm
END IF
[...]
Hope this helps,
Mario
I am trying to build a geometry with lattice and magnetic fields and I am f=
=3D acing some problems.
First question. My reading of the online courses says that the magnetic fie=
ld should only be set for the prototype region. Since I have more than one =
magnetic field, I am using a routine (magfld.f). But what should be written=
in this file?
-Should I find the prototype regions with GEON2R and set the magnetic field=
=3D s for them?
-Should I find the lattice regions with GEON2R  and set the magnetic field =
=3D for the prototype regions they correspond to?
-Should I find the lattice regions and set the magnetic field as it should =
=3D be in the replica area?
For the moment I am using option2 but it doesn't seem to work. Anyway I wou=
=3D ld prefer to calculate the magnetic field just for the prototypes as it=
is a much simpler expressi=3D on.
Second question. I really would like to be able to set two replicas of the =
same prototype to different magnetic fields. Is this possible? How?