Ejemplo n.º 1
0
    def test_read3(self):
        # Parse a single group in a deck with non-unique group names

        namelist1 = "Testing\n" + \
                    "$GROUP\n" + \
                    "  intvar = 99\n" + \
                    "$END\n" + \
                    "$GROUP\n" + \
                    "  floatvar = 3.5e-23\n" + \
                    "$END\n"

        outfile = open(self.filename, 'w')
        outfile.write(namelist1)
        outfile.close()

        my_comp = VarComponent()
        sb = Namelist(my_comp)
        sb.set_filename(self.filename)

        sb.parse_file()

        sb.load_model(single_group=1)

        # Unchanged
        self.assertEqual(my_comp.intvar, 333)
        # Changed
        self.assertEqual(my_comp.floatvar, 3.5e-23)
    def test_read3(self):
        # Parse a single group in a deck with non-unique group names

        namelist1 = "Testing\n" + \
                    "$GROUP\n" + \
                    "  intvar = 99\n" + \
                    "$END\n" + \
                    "$GROUP\n" + \
                    "  floatvar = 3.5e-23\n" + \
                    "$END\n"
        
        outfile = open(self.filename, 'w')
        outfile.write(namelist1)
        outfile.close()
        
        my_comp = VarComponent()
        sb = Namelist(my_comp)
        sb.set_filename(self.filename)

        sb.parse_file()
        
        sb.load_model(single_group=1)

        # Unchanged
        self.assertEqual(my_comp.intvar, 333)
        # Changed
        self.assertEqual(my_comp.floatvar, 3.5e-23)
Ejemplo n.º 3
0
    def test_2Darray_read(self):

        namelist1 = "Testing\n" + \
                    "$GROUP\n" + \
                    "  arrayvartwod(1,1) = 12, 24, 36\n" + \
                    "  arrayvartwod(1,2) = 33, 66, 99\n" + \
                    "$END\n"

        outfile = open(self.filename, 'w')
        outfile.write(namelist1)
        outfile.close()

        top = Problem()
        top.root = Group()
        top.root.add('my_comp', VarComponent())

        top.setup(check=False)
        top.run()

        sb = Namelist(top.root.my_comp)
        sb.set_filename(self.filename)

        sb.parse_file()

        sb.load_model()

        # Unchanged
        self.assertEqual(top['my_comp.arrayvartwod'][0][0], 12)
        self.assertEqual(top['my_comp.arrayvartwod'][1][2], 99)
Ejemplo n.º 4
0
    def test_read3(self):
        # Parse a single group in a deck with non-unique group names

        namelist1 = "Testing\n" + \
                    "$GROUP\n" + \
                    "  intvar = 99\n" + \
                    "$END\n" + \
                    "$GROUP\n" + \
                    "  floatvar = 3.5e-23\n" + \
                    "$END\n"

        outfile = open(self.filename, 'w')
        outfile.write(namelist1)
        outfile.close()

        top = Problem()
        top.root = Group()
        top.root.add('my_comp', VarComponent())

        top.setup(check=False)
        top.run()

        sb = Namelist(top.root.my_comp)
        sb.set_filename(self.filename)

        sb.parse_file()

        sb.load_model(single_group=1)

        # Unchanged
        self.assertEqual(top['my_comp.intvar'], 333)
        # Changed
        self.assertEqual(top['my_comp.floatvar'], 3.5e-23)
Ejemplo n.º 5
0
    def test_read4(self):
        # Variables on same line as header

        namelist1 = "Testing\n" + \
                    "  \n" + \
                    "&OPTION boolvar = T, arrayvar = 3.5, 7.76, 1.23\n" + \
                    "/\n"

        outfile = open(self.filename, 'w')
        outfile.write(namelist1)
        outfile.close()

        top = Problem()
        top.root = Group()
        top.root.add('my_comp', VarComponent())

        top.setup(check=False)
        top.run()

        sb = Namelist(top.root.my_comp)
        sb.set_filename(self.filename)

        sb.parse_file()

        sb.load_model()

        self.assertEqual(top['my_comp.boolvar'], True)
        self.assertEqual(top['my_comp.arrayvar'][0], 3.5)

        namelist1 = "Testing\n" + \
                    "  \n" + \
                    "$OPTION boolvar = T, arrayvar = 3.5, 7.76, 1.23, $END\n"

        outfile = open(self.filename, 'w')
        outfile.write(namelist1)
        outfile.close()

        top = Problem()
        top.root = Group()
        top.root.add('my_comp', VarComponent())

        top.setup(check=False)
        top.run()

        sb = Namelist(top.root.my_comp)
        sb.set_filename(self.filename)

        sb.parse_file()

        sb.load_model()

        self.assertEqual(top['my_comp.boolvar'], True)
        self.assertEqual(top['my_comp.arrayvar'][0], 3.5)
Ejemplo n.º 6
0
    def test_read2(self):
        # Put variables in container, using rules_dict

        namelist1 = "Testing\n" + \
                    "  \n" + \
                    "&OPTION\n" + \
                    "  This is a comment\n" + \
                    "  intvar = 777\n" + \
                    "  boolvar = .FALSE.\n" + \
                    "  floatvar = -3.14\n" + \
                    "  extravar = 555\n" + \
                    "  TEXTVAR = 'That'\n" + \
                    "  ! This is a comment too\n" + \
                    "/\n" + \
                    "&NODICT\n" + \
                    "  noval = 0\n" + \
                    "/\n" + \
                    "&DUPE\n" + \
                    "  some = 0\n" + \
                    "/\n" + \
                    "&DUPE\n" + \
                    "  some = 0\n" + \
                    "/\n" + \
                    "FREEFORM\n"

        outfile = open(self.filename, 'w')
        outfile.write(namelist1)
        outfile.close()

        top = Problem()
        top.root = Group()
        top.root.add('my_comp', VarComponent())

        top.setup(check=False)
        top.run()

        sb = Namelist(top.root.my_comp)
        sb.set_filename(self.filename)

        sb.parse_file()

        rules_dict = { "OPTION" : ["varcontainer"] }
        n1, n2, n3 = sb.load_model(rules_dict)

        self.assertEqual(n1[4], 'FREEFORM')
        self.assertEqual(n2[1], 'NODICT')
        self.assertEqual(n2[2], 'DUPE')
        self.assertEqual(n2[3], 'DUPE')
        self.assertEqual(n3, ['extravar'])
        self.assertEqual(top['my_comp.varcontainer:intvar'], 777)
        self.assertEqual(top['my_comp.varcontainer:boolvar'], False)
        self.assertEqual(top['my_comp.varcontainer:floatvar'], -3.14)
        self.assertEqual(top['my_comp.varcontainer:textvar'], 'That')
    def test_read2(self):
        # Put variables in container, using rules_dict

        namelist1 = "Testing\n" + \
                    "  \n" + \
                    "&OPTION\n" + \
                    "  This is a comment\n" + \
                    "  intvar = 777\n" + \
                    "  boolvar = .FALSE.\n" + \
                    "  floatvar = -3.14\n" + \
                    "  extravar = 555\n" + \
                    "  TEXTVAR = 'That'\n" + \
                    "  ! This is a comment too\n" + \
                    "  listenumvar = 3,3,2,2\n" + \
                    "/\n" + \
                    "&NODICT\n" + \
                    "  noval = 0\n" + \
                    "/\n" + \
                    "&DUPE\n" + \
                    "  some = 0\n" + \
                    "/\n" + \
                    "&DUPE\n" + \
                    "  some = 0\n" + \
                    "/\n" + \
                    "FREEFORM\n"

        outfile = open(self.filename, 'w')
        outfile.write(namelist1)
        outfile.close()
        
        my_comp = VarComponent()
        sb = Namelist(my_comp)
        sb.set_filename(self.filename)

        sb.parse_file()
        
        rules_dict = { "OPTION" : ["varcontainer"] }
        n1, n2, n3 = sb.load_model(rules_dict)
        
        self.assertEqual(n1[4], 'FREEFORM')
        self.assertEqual(n2[1], 'NODICT')
        self.assertEqual(n2[2], 'DUPE')
        self.assertEqual(n2[3], 'DUPE')
        self.assertEqual(n3, ['extravar'])
        self.assertEqual(my_comp.varcontainer.intvar, 777)
        self.assertEqual(my_comp.varcontainer.boolvar, False)
        self.assertEqual(my_comp.varcontainer.floatvar, -3.14)
        self.assertEqual(my_comp.varcontainer.textvar, 'That')
        self.assertEqual(my_comp.varcontainer.listenumvar, [3, 3, 2, 2])
Ejemplo n.º 8
0
    def test_read2(self):
        # Put variables in container, using rules_dict

        namelist1 = "Testing\n" + \
                    "  \n" + \
                    "&OPTION\n" + \
                    "  This is a comment\n" + \
                    "  intvar = 777\n" + \
                    "  boolvar = .FALSE.\n" + \
                    "  floatvar = -3.14\n" + \
                    "  extravar = 555\n" + \
                    "  TEXTVAR = 'That'\n" + \
                    "  ! This is a comment too\n" + \
                    "  listenumvar = 3,3,2,2\n" + \
                    "/\n" + \
                    "&NODICT\n" + \
                    "  noval = 0\n" + \
                    "/\n" + \
                    "&DUPE\n" + \
                    "  some = 0\n" + \
                    "/\n" + \
                    "&DUPE\n" + \
                    "  some = 0\n" + \
                    "/\n" + \
                    "FREEFORM\n"

        outfile = open(self.filename, 'w')
        outfile.write(namelist1)
        outfile.close()

        my_comp = VarComponent()
        sb = Namelist(my_comp)
        sb.set_filename(self.filename)

        sb.parse_file()

        rules_dict = {"OPTION": ["varcontainer"]}
        n1, n2, n3 = sb.load_model(rules_dict)

        self.assertEqual(n1[4], 'FREEFORM')
        self.assertEqual(n2[1], 'NODICT')
        self.assertEqual(n2[2], 'DUPE')
        self.assertEqual(n2[3], 'DUPE')
        self.assertEqual(n3, ['extravar'])
        self.assertEqual(my_comp.varcontainer.intvar, 777)
        self.assertEqual(my_comp.varcontainer.boolvar, False)
        self.assertEqual(my_comp.varcontainer.floatvar, -3.14)
        self.assertEqual(my_comp.varcontainer.textvar, 'That')
        self.assertEqual(my_comp.varcontainer.listenumvar, [3, 3, 2, 2])
Ejemplo n.º 9
0
    def test_read4(self):
        # Variables on same line as header

        namelist1 = "Testing\n" + \
                    "  \n" + \
                    "&OPTION boolvar = T, arrayvar = 3.5, 7.76, 1.23\n" + \
                    "/\n"

        outfile = open(self.filename, 'w')
        outfile.write(namelist1)
        outfile.close()

        my_comp = VarComponent()
        sb = Namelist(my_comp)
        sb.set_filename(self.filename)

        sb.parse_file()

        sb.load_model()

        self.assertEqual(my_comp.boolvar, True)
        self.assertEqual(my_comp.arrayvar[0], 3.5)

        namelist1 = "Testing\n" + \
                    "  \n" + \
                    "$OPTION boolvar = T, arrayvar = 3.5, 7.76, 1.23, $END\n"

        outfile = open(self.filename, 'w')
        outfile.write(namelist1)
        outfile.close()

        my_comp = VarComponent()
        sb = Namelist(my_comp)
        sb.set_filename(self.filename)

        sb.parse_file()

        sb.load_model()

        self.assertEqual(my_comp.boolvar, True)
        self.assertEqual(my_comp.arrayvar[0], 3.5)
Ejemplo n.º 10
0
    def test_read4(self):
        # Variables on same line as header

        namelist1 = "Testing\n" + \
                    "  \n" + \
                    "&OPTION boolvar = T, arrayvar = 3.5, 7.76, 1.23\n" + \
                    "/\n"

        outfile = open(self.filename, 'w')
        outfile.write(namelist1)
        outfile.close()
        
        my_comp = VarComponent()
        sb = Namelist(my_comp)
        sb.set_filename(self.filename)

        sb.parse_file()
        
        sb.load_model()
        
        self.assertEqual(my_comp.boolvar, True)
        self.assertEqual(my_comp.arrayvar[0], 3.5)

        namelist1 = "Testing\n" + \
                    "  \n" + \
                    "$OPTION boolvar = T, arrayvar = 3.5, 7.76, 1.23, $END\n"

        outfile = open(self.filename, 'w')
        outfile.write(namelist1)
        outfile.close()
        
        my_comp = VarComponent()
        sb = Namelist(my_comp)
        sb.set_filename(self.filename)

        sb.parse_file()
        
        sb.load_model()
        
        self.assertEqual(my_comp.boolvar, True)
        self.assertEqual(my_comp.arrayvar[0], 3.5)
Ejemplo n.º 11
0
    def test_2Darray_read(self):

        namelist1 = "Testing\n" + \
                    "$GROUP\n" + \
                    "  arrayvartwod(1,1) = 12, 24, 36\n" + \
                    "  arrayvartwod(1,2) = 33, 66, 99\n" + \
                    "$END\n"

        outfile = open(self.filename, 'w')
        outfile.write(namelist1)
        outfile.close()

        my_comp = VarComponent()
        sb = Namelist(my_comp)
        sb.set_filename(self.filename)

        sb.parse_file()

        sb.load_model()

        # Unchanged
        self.assertEqual(my_comp.arrayvartwod[0][0], 12)
        self.assertEqual(my_comp.arrayvartwod[1][2], 99)
Ejemplo n.º 12
0
    def test_2Darray_read(self):
        
        namelist1 = "Testing\n" + \
                    "$GROUP\n" + \
                    "  arrayvartwod(1,1) = 12, 24, 36\n" + \
                    "  arrayvartwod(1,2) = 33, 66, 99\n" + \
                    "$END\n"
        
        outfile = open(self.filename, 'w')
        outfile.write(namelist1)
        outfile.close()
        
        my_comp = VarComponent()
        sb = Namelist(my_comp)
        sb.set_filename(self.filename)

        sb.parse_file()
        
        sb.load_model()

        # Unchanged
        self.assertEqual(my_comp.arrayvartwod[0][0], 12)
        self.assertEqual(my_comp.arrayvartwod[1][2], 99)
Ejemplo n.º 13
0
    def load_model(self):
        ct = Namelist(self)
        ct.set_filename('control.in')
        ct.parse_file()
        ct.load_model()

        fc = Namelist(self)
        fc.set_filename('flocond.in')
        fc.parse_file()
        fc.load_model()
        
        ep = Namelist(self)
        ep.set_filename('expnd.in')
        ep.parse_file()
        ep.load_model()
        
        zr = Namelist(self)
        zr.set_filename('zrdmix.in')
        zr.parse_file()
        zr.load_model()
Ejemplo n.º 14
0
    def load_model(self):
        ct = Namelist(self)
        ct.set_filename('control.in')
        ct.parse_file()
        ct.load_model()

        fc = Namelist(self)
        fc.set_filename('flocond.in')
        fc.parse_file()
        fc.load_model()

        ep = Namelist(self)
        ep.set_filename('expnd.in')
        ep.parse_file()
        ep.load_model()

        zr = Namelist(self)
        zr.set_filename('zrdmix.in')
        zr.parse_file()
        zr.load_model()
Ejemplo n.º 15
0
    def test_read1(self):
        # Put variables in top container, so no rules_dict

        namelist1 = "Testing\n" + \
                    "  \n" + \
                    "&OPTION\n" + \
                    "  This is a comment\n" + \
                    "  INTVAR = 777, single(1) = 15.0, floatvar = -3.14\n" + \
                    "  singleint(2) = 3,4,5\n" + \
                    "  stringarray(3) = 'xyz'\n" + \
                    "  boolvar = T\n" + \
                    "  textvar = 'That'\n" + \
                    "  ! This is a comment too\n" + \
                    "  listenumvar = 3,3,2,2\n" + \
                    "  listenumvar2 = 1.5\n" + \
                    "  arrayvar = 3.5, 7.76, 1.23\n" + \
                    "  arrayvarsplit = 3.5, 7.76\n" + \
                    "                  5.45, 22.0\n" + \
                    "                  1.23\n" + \
                    "  arrayvarsplit2 = 1\n" + \
                    "                   2\n" + \
                    "                   3\n" + \
                    "  arraysmall = 1.75\n" + \
                    "  arrayshorthand = 3.456*8\n" + \
                    "  expvar1 = 1.5e-12\n" + \
                    "  expvar2 = -1.5D12\n" + \
                    "/\n"

        outfile = open(self.filename, 'w')
        outfile.write(namelist1)
        outfile.close()

        my_comp = VarComponent()
        sb = Namelist(my_comp)
        sb.set_filename(self.filename)

        sb.parse_file()

        sb.load_model()

        self.assertEqual(sb.title, 'Testing')
        self.assertEqual(my_comp.intvar, 777)
        self.assertEqual(my_comp.boolvar, True)
        self.assertEqual(my_comp.floatvar, -3.14)
        self.assertEqual(my_comp.expvar1, 1.5e-12)
        self.assertEqual(my_comp.expvar2, -1.5e12)
        self.assertEqual(my_comp.textvar, 'That')
        self.assertEqual(my_comp.listenumvar, [3, 3, 2, 2])
        self.assertEqual(my_comp.listenumvar2, [1.5])
        self.assertEqual(my_comp.arrayvar[0], 3.5)
        self.assertEqual(my_comp.arrayvar[1], 7.76)
        self.assertEqual(my_comp.arrayvar[2], 1.23)
        self.assertEqual(my_comp.arrayvarsplit[0], 3.5)
        self.assertEqual(my_comp.arrayvarsplit[1], 7.76)
        self.assertEqual(my_comp.arrayvarsplit[2], 5.45)
        self.assertEqual(my_comp.arrayvarsplit[3], 22.0)
        self.assertEqual(my_comp.arrayvarsplit[4], 1.23)
        self.assertEqual(my_comp.arrayvarsplit2[0], 1)
        self.assertEqual(my_comp.arrayvarsplit2[1], 2)
        self.assertEqual(my_comp.arrayvarsplit2[2], 3)
        self.assertEqual(my_comp.arraysmall[0], 1.75)
        self.assertEqual(len(my_comp.arraysmall), 1)
        self.assertEqual(my_comp.arrayshorthand[4], 3.456)
        self.assertEqual(len(my_comp.arrayshorthand), 8)
        self.assertEqual(my_comp.single[0], 15.0)
        self.assertEqual(my_comp.singleint[3], 5)
        self.assertEqual(my_comp.stringarray[2], 'xyz')
        self.assertEqual(type(my_comp.singleint[2]), numpy_int32)

        # Test out reading a single card by name
        self.assertEqual(sb.find_card('OPTION', 'floatvar'), -3.14)
Ejemplo n.º 16
0
    def load_model(self, control_input='control.in',
                         flocond_input='flocond.in',
                         expnd_input='expnd.in',
                         zrdmix_input='zrdmix.in',
                         hwall_input='hwall.in'):
        '''Reads in an existing set of input files and populates the model.'''
        
        ignore = ['ist', 'ifab']
        ct = Namelist(self)
        ct.set_filename(control_input)
        ct.parse_file()
        ct.load_model(ignore=ignore)

        ignore = ['p01d', 'p02d', 't01d', 't02d', 'rm1', 'rm2', 'gam', 'pinf',
                  'a1d', 'a2d', 'a3d']
        fc = Namelist(self)
        fc.set_filename(flocond_input)
        fc.parse_file()
        fc.load_model(ignore=ignore)
        self.flow_in.pri.Pt = fc.find_card('floc', 'p01d')
        self.flow_in.sec.Pt = fc.find_card('floc', 'p02d')
        self.flow_in.pri.Tt = fc.find_card('floc', 't01d')
        self.flow_in.sec.Tt = fc.find_card('floc', 't02d')
        self.flow_in.pri.Mach = fc.find_card('floc', 'rm1')
        self.flow_in.sec.Mach = fc.find_card('floc', 'rm2')
        self.flow_in.gamma = fc.find_card('floc', 'gam')
        self.flow_in.Pstatic = fc.find_card('floc', 'pinf')
        a1d = fc.find_card('floc', 'a1d')
        a2d = fc.find_card('floc', 'a2d')
        a3d = fc.find_card('floc', 'a3d')
        
        ep = Namelist(self)
        ep.set_filename(expnd_input)
        ep.parse_file()
        ep.load_model()
        
        ignore = ['RLD', 'H0LM', 'H0HY', 'ALP1', 'ALP2', 'BWID']
        zr = Namelist(self)
        zr.set_filename(zrdmix_input)
        zr.parse_file()
        zr.load_model(ignore=ignore)
        self.geo_in.length = zr.find_card('zrd', 'RLD')
        self.geo_in.LhWave = zr.find_card('zrd', 'H0LM')
        self.geo_in.LhMh = zr.find_card('zrd', 'H0HY')
        self.geo_in.ChuteAngles = zr.find_card('zrd', 'ALP1')
        #self.geo_in.ChuteAngles = zr.find_card('zrd', 'ALP2')
        BWID = zr.find_card('zrd', 'BWID')

        parser = FileParser()
        parser.set_file(hwall_input)
        parser.set_delimiters(", ")
        nrow = parser.transfer_var(0, 1)
        geom = zeros((nrow, 2), 'd')
        for index in range(nrow):
            geom[index, :] = parser.transfer_array(1+index, 1, 1+index, 2)
            
        self.geom = geom
        
        # Reverse area calculations for AsAp, AeAt and AR
        # Note that DREA only uses half the area as it assumes a plane of symmetry
        self.geo_in.Apri = 2.0*a1d
        self.geo_in.AsAp = 2.0*a2d/self.geo_in.Apri
        self.geo_in.Asec = self.geo_in.AsAp*self.geo_in.Apri
        self.geo_in.AeAt = 2.0*a3d/(self.geo_in.Apri+self.geo_in.Asec)
        self.geo_in.AR = BWID*BWID/(self.geo_in.Apri+self.geo_in.Asec)
        
        #self.geo_in.length = self.geom[-1, 0]
        self.geo_in.width = 0.5*(self.geo_in.Apri + self.geo_in.Asec)/self.geom[0,1]
        self.geo_in.Aexit = 2.0*self.geom[-1,1]*self.geo_in.width  
Ejemplo n.º 17
0
    def test_read1(self):
        # Put variables in top container, so no rules_dict

        namelist1 = "Testing\n" + \
                    "  \n" + \
                    "&OPTION\n" + \
                    "  This is a comment\n" + \
                    "  INTVAR = 777, single(1) = 15.0, floatvar = -3.14\n" + \
                    "  singleint(2) = 3,4,5\n" + \
                    "  stringarray(3) = 'xyz'\n" + \
                    "  boolvar = T\n" + \
                    "  textvar = 'That'\n" + \
                    "  ! This is a comment too\n" + \
                    "  listenumvar = 3,3,2,2\n" + \
                    "  listenumvar2 = 1.5\n" + \
                    "  arrayvar = 3.5, 7.76, 1.23\n" + \
                    "  arrayvarsplit = 3.5, 7.76\n" + \
                    "                  5.45, 22.0\n" + \
                    "                  1.23\n" + \
                    "  arrayvarsplit2 = 1\n" + \
                    "                   2\n" + \
                    "                   3\n" + \
                    "  arraysmall = 1.75\n" + \
                    "  arrayshorthand = 3.456*8\n" + \
                    "  expvar1 = 1.5e-12\n" + \
                    "  expvar2 = -1.5D12\n" + \
                    "/\n"

        outfile = open(self.filename, 'w')
        outfile.write(namelist1)
        outfile.close()
        
        my_comp = VarComponent()
        sb = Namelist(my_comp)
        sb.set_filename(self.filename)

        sb.parse_file()
        
        sb.load_model()
        
        self.assertEqual(sb.title, 'Testing')
        self.assertEqual(my_comp.intvar, 777)
        self.assertEqual(my_comp.boolvar, True)
        self.assertEqual(my_comp.floatvar, -3.14)
        self.assertEqual(my_comp.expvar1, 1.5e-12)
        self.assertEqual(my_comp.expvar2, -1.5e12)
        self.assertEqual(my_comp.textvar, 'That')
        self.assertEqual(my_comp.listenumvar, [3, 3, 2, 2])
        self.assertEqual(my_comp.listenumvar2, [1.5])
        self.assertEqual(my_comp.arrayvar[0], 3.5)
        self.assertEqual(my_comp.arrayvar[1], 7.76)
        self.assertEqual(my_comp.arrayvar[2], 1.23)
        self.assertEqual(my_comp.arrayvarsplit[0], 3.5)
        self.assertEqual(my_comp.arrayvarsplit[1], 7.76)
        self.assertEqual(my_comp.arrayvarsplit[2], 5.45)
        self.assertEqual(my_comp.arrayvarsplit[3], 22.0)
        self.assertEqual(my_comp.arrayvarsplit[4], 1.23)
        self.assertEqual(my_comp.arrayvarsplit2[0], 1)
        self.assertEqual(my_comp.arrayvarsplit2[1], 2)
        self.assertEqual(my_comp.arrayvarsplit2[2], 3)
        self.assertEqual(my_comp.arraysmall[0], 1.75)
        self.assertEqual(len(my_comp.arraysmall), 1)
        self.assertEqual(my_comp.arrayshorthand[4], 3.456)
        self.assertEqual(len(my_comp.arrayshorthand), 8)
        self.assertEqual(my_comp.single[0], 15.0)
        self.assertEqual(my_comp.singleint[3], 5)
        self.assertEqual(my_comp.stringarray[2], 'xyz')
        self.assertEqual(type(my_comp.singleint[2]), numpy_int32)
        
        # Test out reading a single card by name
        self.assertEqual(sb.find_card('OPTION', 'floatvar'), -3.14)
Ejemplo n.º 18
0
    def test_read_pre_setup(self):
        # Put variables in top container, so no rules_dict

        namelist1 = "Testing\n" + \
                    "  \n" + \
                    "&OPTION\n" + \
                    "  This is a comment\n" + \
                    "  INTVAR = 777, single(1) = 15.0, floatvar = -3.14\n" + \
                    "  singleint(2) = 3,4,5\n" + \
                    "  stringarray(3) = 'xyz'\n" + \
                    "  boolvar = T\n" + \
                    "  textvar = 'That'\n" + \
                    "  ! This is a comment too\n" + \
                    "  arrayvar = 3.5, 7.76, 1.23\n" + \
                    "  arrayvarsplit = 3.5, 7.76\n" + \
                    "                  5.45, 22.0\n" + \
                    "                  1.23\n" + \
                    "  arrayvarsplit2 = 1\n" + \
                    "                   2\n" + \
                    "                   3\n" + \
                    "  arraysmall = 1.75\n" + \
                    "  arrayshorthand = 3.456*8\n" + \
                    "  expvar1 = 1.5e-12\n" + \
                    "  expvar2 = -1.5D12\n" + \
                    "/\n"

        outfile = open(self.filename, 'w')
        outfile.write(namelist1)
        outfile.close()

        top = Problem()
        top.root = Group()
        my_comp = top.root.add('my_comp', VarComponent())

        sb = Namelist(my_comp)
        sb.set_filename(self.filename)

        sb.parse_file()

        sb.load_model()

        self.assertEqual(sb.title, 'Testing')
        self.assertEqual(my_comp._init_params_dict['intvar']['val'], 777)
        self.assertEqual(my_comp._init_params_dict['boolvar']['val'], True)
        self.assertEqual(my_comp._init_params_dict['floatvar']['val'], -3.14)
        self.assertEqual(my_comp._init_params_dict['expvar1']['val'], 1.5e-12)
        self.assertEqual(my_comp._init_params_dict['expvar2']['val'], -1.5e12)
        self.assertEqual(my_comp._init_params_dict['textvar']['val'], 'That')
        self.assertEqual(my_comp._init_params_dict['arrayvar']['val'][0], 3.5)
        self.assertEqual(my_comp._init_params_dict['arrayvar']['val'][1], 7.76)
        self.assertEqual(my_comp._init_params_dict['arrayvar']['val'][2], 1.23)
        self.assertEqual(my_comp._init_params_dict['arrayvarsplit']['val'][0], 3.5)
        self.assertEqual(my_comp._init_params_dict['arrayvarsplit']['val'][1], 7.76)
        self.assertEqual(my_comp._init_params_dict['arrayvarsplit']['val'][2], 5.45)
        self.assertEqual(my_comp._init_params_dict['arrayvarsplit']['val'][3], 22.0)
        self.assertEqual(my_comp._init_params_dict['arrayvarsplit']['val'][4], 1.23)
        self.assertEqual(my_comp._init_params_dict['arrayvarsplit2']['val'][0], 1)
        self.assertEqual(my_comp._init_params_dict['arrayvarsplit2']['val'][1], 2)
        self.assertEqual(my_comp._init_params_dict['arrayvarsplit2']['val'][2], 3)
        self.assertEqual(my_comp._init_params_dict['arraysmall']['val'], 1.75)
        self.assertEqual(my_comp._init_params_dict['arrayshorthand']['val'][4], 3.456)
        self.assertEqual(len(my_comp._init_params_dict['arrayshorthand']['val']), 8)
        self.assertEqual(my_comp._init_params_dict['single']['val'][0], 15.0)
        self.assertEqual(my_comp._init_params_dict['singleint']['val'][3], 5)
        self.assertEqual(my_comp._init_params_dict['stringarray']['val'][2], 'xyz')