loadxc Subroutine

public subroutine loadxc()

Routine to load the physics and engineering variables into the optimisation variables array author: P J Knight, CCFE, Culham Science Centre author: J Morris, CCFE, Culham Science Centre None This subroutine loads the physics and engineering variables into the optimisation variables array XCM.

Arguments

None

Contents

Source Code


Source Code

  subroutine loadxc
    !! Routine to load the physics and engineering variables into the
    !! optimisation variables array
    !! author: P J Knight, CCFE, Culham Science Centre
    !! author: J Morris, CCFE, Culham Science Centre
    !! None
    !! This subroutine loads the physics and engineering variables
    !! into the optimisation variables array <CODE>XCM</CODE>.
    !
    ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

    use constants, only: nout
    use maths_library, only: variable_error
    use error_handling, only: idiags, fdiags, report_error
    use numerics, only: nvar, xcm, ixc, name_xc, lablxc, scafc, scale
    use physics_variables, only: i_plasma_current
    use global_variables, only: vlabel
    implicit none

    !  Local variables
    integer :: i
    ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    do i = 1,nvar

       select case (ixc(i))
           case (1);  xcm(i) = itv_1()
           case (2);  xcm(i) = itv_2()
           case (3);  xcm(i) = itv_3()
           case (4);  xcm(i) = itv_4()
           case (5);  xcm(i) = itv_5()
           case (6);  xcm(i) = itv_6()
           case (7);  xcm(i) = itv_7()
           case (8);  xcm(i) = itv_8()
           case (9);  xcm(i) = itv_9()
           case (10);  xcm(i) = itv_10()
           case (11);  xcm(i) = itv_11()
           case (12);  xcm(i) = itv_12()
           case (13);  xcm(i) = itv_13()
           case (14);  xcm(i) = itv_14()
           case (15);  xcm(i) = itv_15()
           case (16);  xcm(i) = itv_16()
           case (17);  xcm(i) = itv_17()
           case (18);  xcm(i) = itv_18()
           case (19);  xcm(i) = itv_19()
           case (20);  xcm(i) = itv_20()
           case (21);  xcm(i) = itv_21()
           case (22);  xcm(i) = itv_22()
           case (23);  xcm(i) = itv_23()
           case (24);  xcm(i) = itv_24()
           case (25);  xcm(i) = itv_25()
           case (26);  xcm(i) = itv_26()
           case (27);  xcm(i) = itv_27()
           case (28);  xcm(i) = itv_28()
           case (29);  xcm(i) = itv_29()
           case (30);  xcm(i) = itv_30()
           case (31);  xcm(i) = itv_31()
           case (32);  xcm(i) = itv_32()
           case (33);  xcm(i) = itv_33()
           case (34);  xcm(i) = itv_34()
           case (35);  xcm(i) = itv_35()
           case (36);  xcm(i) = itv_36()
           case (37);  xcm(i) = itv_37()
           case (38);  xcm(i) = itv_38()
           case (39);  xcm(i) = itv_39()
           case (40);  xcm(i) = itv_40()
           case (41);  xcm(i) = itv_41()
           case (42);  xcm(i) = itv_42()
           case (43);
           case (44);  xcm(i) = itv_44()
           case (45);  xcm(i) = itv_45()
           case (46);  xcm(i) = itv_46()
           case (47);  xcm(i) = itv_47()
           case (48);  xcm(i) = itv_48()
           case (49);  xcm(i) = itv_49()
           case (50);  xcm(i) = itv_50()
           case (51);  xcm(i) = itv_51()
           case (52);  xcm(i) = itv_52()
           case (53);  xcm(i) = itv_53()
           case (54);  xcm(i) = itv_54()
           case (55);  xcm(i) = itv_55()
           case (56);  xcm(i) = itv_56()
           case (57);  xcm(i) = itv_57()
           case (58);  xcm(i) = itv_58()
           case (59);  xcm(i) = itv_59()
           case (60);  xcm(i) = itv_60()
           case (61);  xcm(i) = itv_61()
           case (62);  xcm(i) = itv_62()
           case (63);  xcm(i) = itv_63()
           case (64);  xcm(i) = itv_64()
           case (65);  xcm(i) = itv_65()
           case (66);  xcm(i) = itv_66()
           case (67);  xcm(i) = itv_67()
           case (68);  xcm(i) = itv_68()
           case (69);  xcm(i) = itv_69()
           case (70);  xcm(i) = itv_70()
           case (71);  xcm(i) = itv_71()
           case (72);  xcm(i) = itv_72()
           case (73);  xcm(i) = itv_73()
           case (74);  xcm(i) = itv_74()
           case (75);  xcm(i) = itv_75()
           case (76);  xcm(i) = itv_76()
           case (77);  xcm(i) = itv_77()
           case (78);  xcm(i) = itv_78()
           case (79);  xcm(i) = itv_79()
           case (80);  xcm(i) = itv_80()
           case (81);  xcm(i) = itv_81()
           case (82);  xcm(i) = itv_82()
           case (83);  xcm(i) = itv_83()
           case (84);  xcm(i) = itv_84()
           case (85);  xcm(i) = itv_85()
           case (86);  xcm(i) = itv_86()
           case (87);
           case (88);
           case (89);  xcm(i) = itv_89()
           case (90);  xcm(i) = itv_90()
           case (91);  xcm(i) = itv_91()
           case (92);  xcm(i) = itv_92()
           case (93);  xcm(i) = itv_93()
           case (94);  xcm(i) = itv_94()
           case (95);  xcm(i) = itv_95()
           case (96);  xcm(i) = itv_96()
           case (97);  xcm(i) = itv_97()
           case (98);  xcm(i) = itv_98()
           case (99);
           case (100);
           case (101);
           case (102);
           case (103);  xcm(i) = itv_103()
           case (104);  xcm(i) = itv_104()
           case (105);  xcm(i) = itv_105()
           case (106);  xcm(i) = itv_106()
           case (107);  xcm(i) = itv_107()
           case (108);  xcm(i) = itv_108()
           case (109);  xcm(i) = itv_109()
           case (110);  xcm(i) = itv_110()
           case (111);  xcm(i) = itv_111()
           case (112);  xcm(i) = itv_112()
           case (113);  xcm(i) = itv_113()
           case (114);  xcm(i) = itv_114()
           case (115);  xcm(i) = itv_115()
           case (116);  xcm(i) = itv_116()
           case (117);  xcm(i) = itv_117()
           case (118);  xcm(i) = itv_118()
           case (119);  xcm(i) = itv_119()
           case (120);  xcm(i) = itv_120()
           case (121);  xcm(i) = itv_121()
           case (122);  xcm(i) = itv_122()
           case (123);  xcm(i) = itv_123()
           case (124);  xcm(i) = itv_124()
           case (125);  xcm(i) = itv_125()
           case (126);  xcm(i) = itv_126()
           case (127);  xcm(i) = itv_127()
           case (128);  xcm(i) = itv_128()
           case (129);  xcm(i) = itv_129()
           case (130);  xcm(i) = itv_130()
           case (131);  xcm(i) = itv_131()
           case (132);  xcm(i) = itv_132()
           case (133);  xcm(i) = itv_133()
           case (134);  xcm(i) = itv_134()
           case (135);  xcm(i) = itv_135()
           case (136);  xcm(i) = itv_136()
           case (137);  xcm(i) = itv_137()
           case (138);  xcm(i) = itv_138()
           case (139);  xcm(i) = itv_139()
           case (140);  xcm(i) = itv_140()
           case (141);  xcm(i) = itv_141()
           case (142);  xcm(i) = itv_142()
           case (143);  xcm(i) = itv_143()
           case (144);  xcm(i) = itv_144()
           case (145);  xcm(i) = itv_145()
           case (146);  xcm(i) = itv_146()
           case (147);  xcm(i) = itv_147()
           case (148);  xcm(i) = itv_148()
           case (149);  xcm(i) = itv_149()
           case (150);
           case (151);
           case (152);  xcm(i) = itv_152()
           case (153);  xcm(i) = itv_153()
           case (154);  xcm(i) = itv_154()
           case (155);  xcm(i) = itv_155()
           case (156);  xcm(i) = itv_156()
           case (157);  xcm(i) = itv_157()
           case (158);  xcm(i) = itv_158()
           case (159);  xcm(i) = itv_159()
           case (160);  xcm(i) = itv_160()
           case (161);  xcm(i) = itv_161()
           case (162);  xcm(i) = itv_162()
           case (163);  xcm(i) = itv_163()
           case (164);  xcm(i) = itv_164()
           case (165);  xcm(i) = itv_165()
           case (166);  xcm(i) = itv_166()
           case (167);  xcm(i) = itv_167()
           case (168);  xcm(i) = itv_168()
           case (169);  xcm(i) = itv_169()
           case (170);  xcm(i) = itv_170()
           case (171);  xcm(i) = itv_171()
           case (172);  xcm(i) = itv_172()
            ! DUMMY Cases
           case (173);  xcm(i) = itv_173()
           case (174);  xcm(i) = itv_174()
           case (175);  xcm(i) = itv_175()

       case default
          idiags(1) = i ; idiags(2) = ixc(i)
          call report_error(54)

       end select


        ! Simple list of iteration variable names
        name_xc(i) = lablxc(ixc(i))
        ! Note that iteration variable 18 has more than one name:
        if ((ixc(i) == 18).and.(i_plasma_current /= 2)) name_xc(i) = 'q95'
        if ((ixc(i) == 18).and.(i_plasma_current == 2)) name_xc(i) = 'qbar'


         ! MDK Check if sweep variable is also an iteration variable
         if (name_xc(i) == vlabel) then
              write(nout,*) 'WARNING: The sweep variable is also an iteration variable.'
              write(nout,*) 'The values of the sweep variable will be overwritten by the optimiser.'
              write(*,*) 'WARNING: The sweep variable is also an iteration variable.'
         end if

       !  Check that no iteration variable is zero

       if (abs(xcm(i)) <= 1.0D-12) then
          idiags(1) = i ; idiags(2) = ixc(i)
          write(*,*) 'Iteration variable ',ixc(i),'(',trim(lablxc(ixc(i))),') is zero.'
          call report_error(55)
       end if

       !  Crude method of catching NaN errors

       !if ( (abs(xcm(i)) > 9.99D99).or.(xcm(i) /= xcm(i)) ) then
       if ( variable_error(xcm(i)) ) then
          idiags(1) = i ; idiags(2) = ixc(i) ; fdiags(1) = xcm(i)
          call report_error(56)
       end if

    end do

    do i = 1,nvar
       if (abs(xcm(i)) > 1.0D-99) then
          scale(i) = 1.0D0/xcm(i)
       else
          scale(i) = 1.0D0
       end if
       scafc(i) = 1.0D0/scale(i)
       xcm(i) = xcm(i)*scale(i)
    end do

  end subroutine loadxc