Esempio n. 1
0
    def setUp(self):
        import numpy
        from openmdao.utils.file_wrap import FileParser

        global parser  # global so we don't need `self.` in feature doc
        parser = FileParser()

        # A way to "cheat" and do this without a file.
        parser._data = []
        parser._data.append(
            'FREQ  DELTA  -8.5  -8.5  -8.5  -8.5  -8.5  -8.5  -8.5  -8.5  -8.5  -8.5'
        )
        parser._data.append(' Hz')
        parser._data.append(
            ' 50.   1.0   30.0  34.8  36.3  36.1  34.6  32.0  28.4  23.9  18.5  12.2'
        )
        parser._data.append(
            ' 63.   1.0   36.5  41.3  42.8  42.6  41.1  38.5  34.9  30.4  25.0  18.7'
        )
        parser._data.append(
            ' 80.   1.0   42.8  47.6  49.1  48.9  47.4  44.8  41.2  36.7  31.3  25.0'
        )
        parser._data.append(
            '100.   1.0   48.4  53.1  54.7  54.5  53.0  50.4  46.8  42.3  36.9  30.6'
        )
Esempio n. 2
0
    def setUp(self):
        from openmdao.utils.file_wrap import FileParser

        global parser  # global so we don't need `self.` in feature doc
        parser = FileParser()

        parser._data = ["CASE 1", "3,7,2,4,5,6"]
Esempio n. 3
0
    def setUp(self):

        global parser  # global so we don't need `self.` in feature doc
        parser = FileParser()

        parser._data = [
            "CASE 1",
            "3,7,2,4,5,6"
        ]
Esempio n. 4
0
    def setUp(self):
        from openmdao.utils.file_wrap import FileParser

        global parser  # global so we don't need `self.` in feature doc
        parser = FileParser()

        parser._data = [
            "CASE 1", "12345678901234567890", "TTF    3.7-9.4434967"
        ]
Esempio n. 5
0
    def setUp(self):

        global parser  # global so we don't need `self.` in feature doc
        parser = FileParser()

        parser._data = [
            "CASE 1",
            "12345678901234567890",
            "TTF    3.7-9.4434967"
        ]
Esempio n. 6
0
    def setUp(self):
        from openmdao.utils.file_wrap import FileParser

        global parser  # global so we don't need `self.` in feature doc
        parser = FileParser()

        parser._data = [
            "CASE 1",
            "3,7,2,4,5,6"
        ]
Esempio n. 7
0
    def setUp(self):
        from openmdao.utils.file_wrap import FileParser

        global parser  # global so we don't need `self.` in feature doc
        parser = FileParser()

        parser._data = [
            "CASE 2", "123456789012345678901234567890",
            "NODE 11 22 33 COMMENT", "NODE 44 55 66 STUFF"
        ]
Esempio n. 8
0
    def setUp(self):
        from openmdao.utils.file_wrap import FileParser

        global parser  # global so we don't need `self.` in feature doc
        parser = FileParser()

        parser._data = [
            "CASE 1",
            "12345678901234567890",
            "TTF    3.7-9.4434967"
        ]
Esempio n. 9
0
    def setUp(self):

        global parser  # global so we don't need `self.` in feature doc
        parser = FileParser()

        parser._data = [
            "CASE 2",
            "123456789012345678901234567890",
            "NODE 11 22 33 COMMENT",
            "NODE 44 55 66 STUFF"
        ]
Esempio n. 10
0
    def setUp(self):
        from openmdao.utils.file_wrap import FileParser

        global parser  # global so we don't need `self.` in feature doc
        parser = FileParser()

        parser._data = [
            "CASE 2",
            "123456789012345678901234567890",
            "NODE 11 22 33 COMMENT",
            "NODE 44 55 66 STUFF"
        ]
Esempio n. 11
0
    def setUp(self):
        import numpy
        from openmdao.utils.file_wrap import FileParser

        global parser  # global so we don't need `self.` in feature doc
        parser = FileParser()

        parser._data = [
            "LOAD CASE 1", "STRESS 1.3334e7 3.9342e7 NaN 2.654e5",
            "DISPLACEMENT 2.1 4.6 3.1 2.22234", "LOAD CASE 2",
            "STRESS 11 22 33 44 55 66", "DISPLACEMENT 1.0 2.0 3.0 4.0 5.0"
        ]
Esempio n. 12
0
    def setUp(self):
        import numpy
        from openmdao.utils.file_wrap import FileParser

        global parser  # global so we don't need `self.` in feature doc
        parser = FileParser()

        # A way to "cheat" and do this without a file.
        parser._data = []
        parser._data.append('FREQ  DELTA  -8.5  -8.5  -8.5  -8.5  -8.5  -8.5  -8.5  -8.5  -8.5  -8.5')
        parser._data.append(' Hz')
        parser._data.append(' 50.   1.0   30.0  34.8  36.3  36.1  34.6  32.0  28.4  23.9  18.5  12.2')
        parser._data.append(' 63.   1.0   36.5  41.3  42.8  42.6  41.1  38.5  34.9  30.4  25.0  18.7')
        parser._data.append(' 80.   1.0   42.8  47.6  49.1  48.9  47.4  44.8  41.2  36.7  31.3  25.0')
        parser._data.append('100.   1.0   48.4  53.1  54.7  54.5  53.0  50.4  46.8  42.3  36.9  30.6')
Esempio n. 13
0
    def setUp(self):
        import numpy
        from openmdao.utils.file_wrap import FileParser

        global parser  # global so we don't need `self.` in feature doc
        parser = FileParser()

        parser._data = [
            "LOAD CASE 1",
            "STRESS 1.3334e7 3.9342e7 NaN 2.654e5",
            "DISPLACEMENT 2.1 4.6 3.1 2.22234",
            "LOAD CASE 2",
            "STRESS 11 22 33 44 55 66",
            "DISPLACEMENT 1.0 2.0 3.0 4.0 5.0"
        ]
Esempio n. 14
0
    def compute(self, inputs, outputs):
        x = inputs['RadLen']
        var = '{0};'.format(float(x)) 

        # generate the input file for esatan thermal analysis
        generator = InputFileGenerator()
        generator.set_template_file('radiator_templ.txt')
        generator.set_generated_file('radiator.d')
        generator.mark_anchor("$CONSTANTS")
        generator.transfer_var(var, 4, 3)
        generator.generate()

        # the parent compute function actually runs the external code
        super(Radiator, self).compute(inputs, outputs)

        # parse the output file from the external code and set the value of T_max
        parser = FileParser()
        parser.set_file('radiator.out')
        parser.mark_anchor("+RADIATOR ")
        T_max = parser.transfer_var(5, 6)

        outputs['T_max'] = T_max
Esempio n. 15
0
    def test_comment_char(self):
        # Check to see if the use of the comment
        #   characters works
        data = '\n'.join([
            "Junk",
            "CAnchor",
            " Z 11, 22 344, Test 1e65",
            " B 4 Stuff",
            "  $ Anchor",
            " Q 1, 2 34, Test 1e65",
            " B 4 Stuff",
            "Anchor",
            " A 1, 2 34, Test 1e65",
            " B 4 Stuff",
            "Anchor",
            " C 77 False NaN 333.444",
            " 1,2,3,4,5",
            " Inf 1.#QNAN -1.#IND"
        ])

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

        # Test full line comments
        gen = FileParser(full_line_comment_char="C")
        gen.set_file(self.filename)
        gen.set_delimiters(' ')
        gen.mark_anchor('Anchor')
        val = gen.transfer_var(1, 1)
        self.assertEqual(val, 'A')

        # Test end of line comments also
        gen = FileParser(full_line_comment_char="C", end_of_line_comment_char="$")
        gen.set_file(self.filename)
        gen.set_delimiters(' ')
        gen.mark_anchor('Anchor')
        val = gen.transfer_var(1, 1)
        self.assertEqual(val, 'A')
Esempio n. 16
0
    def test_output_parse_2Darray(self):
        data = '''
        Anchor
            FREQ  DELTA  -8.5  -8.5  -8.5  -8.5  -8.5  -8.5  -8.5  -8.5  -8.5  -8.5  -8.5  -8.5  -8.5  -8.5  -8.5  -8.5  -8.5
             Hz
             50.   1.0   30.0  34.8  36.3  36.1  34.6  32.0  28.4  23.9  18.5  12.2   5.0  -3.1 -12.3 -22.5 -34.0 -47.2 -63.7
             63.   1.0   36.5  41.3  42.8  42.6  41.1  38.5  34.9  30.4  25.0  18.7  11.5   3.4  -5.8 -16.0 -27.5 -40.7 -57.2
             80.   1.0   42.8  47.6  49.1  48.9  47.4  44.8  41.2  36.7  31.3  25.0  17.8   9.7   0.5  -9.7 -21.2 -34.4 -50.9
            100.   1.0   48.4  53.1  54.7  54.5  53.0  50.4  46.8  42.3  36.9  30.6  23.3  15.2   6.1  -4.2 -15.7 -28.9 -45.4
            125.   1.0   53.6  58.3  59.9  59.6  58.1  55.5  52.0  47.5  42.0  35.7  28.5  20.4  11.2   1.0 -10.5 -23.7 -40.2
            160.   1.0   58.9  63.7  65.2  65.0  63.5  60.9  57.3  52.8  47.4  41.0  33.8  25.7  16.5   6.3  -5.2 -18.4 -34.9
            200.   1.0   63.4  68.1  69.6  69.4  67.9  65.3  61.7  57.2  51.8  45.5  38.3  30.1  21.0  10.7  -0.8 -14.0 -30.5
            250.   1.0   67.5  72.2  73.7  73.5  72.0  69.4  65.8  61.3  55.9  49.5  42.3  34.2  25.0  14.8   3.3 -10.0 -26.5
            315.   1.0   71.3  76.1  77.6  77.4  75.8  73.2  69.7  65.1  59.7  53.4  46.1  38.0  28.8  18.6   7.1  -6.2 -22.7
            400.   1.0   74.9  79.7  81.2  81.0  79.4  76.8  73.2  68.7  63.2  56.9  49.7  41.5  32.4  22.1  10.6  -2.7 -19.2
            500.   1.0   77.9  82.7  84.2  83.9  82.4  79.8  76.2  71.6  66.2  59.8  52.6  44.4  35.3  25.0  13.5   0.2 -16.3
            630.   1.0   80.7  85.4  86.9  86.6  85.1  82.4  78.8  74.3  68.8  62.5  55.2  47.0  37.9  27.6  16.1   2.8 -13.7
            800.   1.0   83.1  87.8  89.2  89.0  87.4  84.8  81.2  76.6  71.1  64.8  57.5  49.3  40.1  29.9  18.3   5.0 -11.5
           1000.   1.0   84.9  89.6  91.1  90.8  89.2  86.6  82.9  78.4  72.9  66.5  59.2  51.0  41.8  31.5  20.0   6.6  -9.9
           1250.   1.0   86.4  91.1  92.5  92.2  90.7  88.0  84.3  79.7  74.2  67.8  60.5  52.3  43.1  32.8  21.2   7.9  -8.7
           1600.   1.0   87.6  92.3  93.7  93.4  91.8  89.1  85.4  80.8  75.2  68.8  61.5  53.3  44.0  33.7  22.1   8.7  -7.9
           2000.   1.0   88.4  93.0  94.4  94.0  92.4  89.6  85.9  81.3  75.7  69.3  61.9  53.7  44.4  34.0  22.4   9.0  -7.6
           2500.   1.0   88.7  93.3  94.6  94.2  92.6  89.8  86.1  81.4  75.8  69.3  61.9  53.6  44.3  33.9  22.2   8.8  -7.9
           3150.   1.0   88.7  93.2  94.5  94.1  92.4  89.5  85.7  81.0  75.4  68.8  61.4  53.0  43.7  33.3  21.5   8.1  -8.6
           4000.   1.0   88.3  92.7  94.0  93.5  91.7  88.8  85.0  80.2  74.5  67.9  60.4  52.0  42.5  32.0  20.2   6.7 -10.0
           5000.   1.0   87.5  91.9  93.1  92.5  90.7  87.7  83.8  78.9  73.2  66.5  58.9  50.4  40.9  30.4  18.5   4.9 -11.9
           6300.   1.0   86.5  90.8  91.9  91.2  89.3  86.2  82.2  77.3  71.4  64.6  57.0  48.4  38.8  28.1  16.2   2.5 -14.5
           8000.   1.0   85.3  89.5  90.4  89.6  87.6  84.4  80.2  75.2  69.2  62.3  54.5  45.8  36.1  25.3  13.2  -0.6 -17.7
          10000.   1.0   84.2  88.2  89.0  88.1  85.9  82.5  78.3  73.0  66.9  59.9  51.9  43.1  33.2  22.3  10.1  -3.9 -21.1
        '''

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

        gen = FileParser()
        gen.set_file(self.filename)

        # whitespace delim; with end field
        gen.set_delimiters(' \t')
        gen.mark_anchor('Anchor')
        val = gen.transfer_2Darray(3, 2, 26, 19)
        self.assertEqual(val[0, 1], 30.0)
        self.assertEqual(val[0, 17], -63.7)
        self.assertEqual(val[1, 17], -57.2)
        self.assertEqual(val[23, 17], -21.1)
        self.assertEqual(val.shape[0], 24)
        self.assertEqual(val.shape[1], 18)

        # whitespace delim; no end field
        val = gen.transfer_2Darray(3, 2, 26)
        self.assertEqual(val[0, 1], 30.0)
        self.assertEqual(val[23, 17], -21.1)
        self.assertEqual(val.shape[0], 24)
        self.assertEqual(val.shape[1], 18)

        # column delim; with end field
        gen.set_delimiters('columns')
        val = gen.transfer_2Darray(3, 19, 26, 125)
        self.assertEqual(val[0, 1], 30.0)
        self.assertEqual(val[0, 17], -63.7)
        self.assertEqual(val[1, 17], -57.2)
        self.assertEqual(val[23, 17], -21.1)
        self.assertEqual(val.shape[0], 24)
        self.assertEqual(val.shape[1], 18)

        # column delim; no end field
        val = gen.transfer_2Darray(3, 19, 26)
        self.assertEqual(val[0, 1], 30.0)
        self.assertEqual(val[0, 17], -63.7)
        self.assertEqual(val[1, 17], -57.2)
        self.assertEqual(val[23, 17], -21.1)
        self.assertEqual(val.shape[0], 24)
        self.assertEqual(val.shape[1], 18)

        # make sure single line works
        gen.set_delimiters(' \t')
        val = gen.transfer_2Darray(5, 3, 5, 5)
        self.assertEqual(val[0, 2], 49.1)

        # Small block read
        val = gen.transfer_2Darray(7, 3, 9, 6)
        self.assertEqual(val[0, 0], 53.6)
        self.assertEqual(val[2, 0], 63.4)

        # Error messages for bad values
        try:
            gen.transfer_2Darray(7, 3, 9, 1)
        except ValueError as err:
            msg = "fieldend must be greater than fieldstart"
            self.assertEqual(str(err), msg)
        else:
            self.fail('ValueError expected')

        try:
            gen.transfer_2Darray(9, 2, 8, 4)
        except ValueError as err:
            msg = "rowend must be greater than rowstart"
            self.assertEqual(str(err), msg)
        else:
            self.fail('ValueError expected')
Esempio n. 17
0
    def test_output_parse_array(self):
        data = '\n'.join([
            "Anchor",
            "10 20 30 40 50 60 70 80",
            "11 21 31 41 51 61 71 81",
            "Key a b c d e"
        ])

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

        gen = FileParser()
        gen.set_file(self.filename)
        gen.set_delimiters(' ')

        gen.mark_anchor('Anchor')
        val = gen.transfer_array(1, 1, 1, 8)
        self.assertEqual(val[0], 10)
        self.assertEqual(val[7], 80)
        val = gen.transfer_array(1, 5, 2, 6)
        self.assertEqual(val[0], 50)
        self.assertEqual(val[9], 61)
        gen.mark_anchor('Key')
        val = gen.transfer_array(0, 2, 0, 6)
        self.assertEqual(val[4], 'e')
        val = gen.transfer_array(0, 2, fieldend=6)
        self.assertEqual(val[4], 'e')

        # Now, let's try column delimiters
        gen.reset_anchor()
        gen.mark_anchor('Anchor')
        gen.set_delimiters('columns')
        val = gen.transfer_array(1, 7, 1, 15)
        self.assertEqual(val[0], 30)
        self.assertEqual(val[2], 50)
        val = gen.transfer_array(1, 10, 2, 18)
        self.assertEqual(val[0], 40)
        self.assertEqual(val[5], 61)
        val = gen.transfer_array(3, 5, 3, 10)
        self.assertEqual(val[0], 'a b c')

        try:
            gen.transfer_array(1, 7, 1)
        except ValueError as err:
            msg = "fieldend is missing, currently required"
            self.assertEqual(str(err), msg)
        else:
            self.fail('ValueError expected')
Esempio n. 18
0
    def test_output_parse_keyvar(self):
        data = '\n'.join([
            "Anchor",
            " Key1 1 2 3.7 Test 1e65",
            " Key1 3 4 3.2 ibg 0.0003",
            " Key1 5 6 6.7 Tst xxx"
        ])

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

        gen = FileParser()
        gen.set_file(self.filename)
        gen.set_delimiters(' ')

        gen.mark_anchor('Anchor')
        val = gen.transfer_keyvar('Key1', 3)
        self.assertEqual(val, 3.7)
        val = gen.transfer_keyvar('Key1', 4, -2)
        self.assertEqual(val, 'ibg')
        val = gen.transfer_keyvar('Key1', 4, -2, -1)
        self.assertEqual(val, 'Test')

        try:
            gen.transfer_keyvar('Key1', 4, 0)
        except ValueError as err:
            msg = "The value for occurrence must be a nonzero integer"
            self.assertEqual(str(err), msg)
        else:
            self.fail('ValueError expected')

        try:
            gen.transfer_keyvar('Key1', 4, -3.4)
        except ValueError as err:
            msg = "The value for occurrence must be a nonzero integer"
            self.assertEqual(str(err), msg)
        else:
            self.fail('ValueError expected')
Esempio n. 19
0
    def test_comment_char(self):
        # Check to see if the use of the comment
        #   characters works
        data = '\n'.join([
            "Junk", "CAnchor", " Z 11, 22 344, Test 1e65", " B 4 Stuff",
            "  $ Anchor", " Q 1, 2 34, Test 1e65", " B 4 Stuff", "Anchor",
            " A 1, 2 34, Test 1e65", " B 4 Stuff", "Anchor",
            " C 77 False NaN 333.444", " 1,2,3,4,5", " Inf 1.#QNAN -1.#IND"
        ])

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

        # Test full line comments
        gen = FileParser(full_line_comment_char="C")
        gen.set_file(self.filename)
        gen.set_delimiters(' ')
        gen.mark_anchor('Anchor')
        val = gen.transfer_var(1, 1)
        self.assertEqual(val, 'A')

        # Test end of line comments also
        gen = FileParser(full_line_comment_char="C",
                         end_of_line_comment_char="$")
        gen.set_file(self.filename)
        gen.set_delimiters(' ')
        gen.mark_anchor('Anchor')
        val = gen.transfer_var(1, 1)
        self.assertEqual(val, 'A')
Esempio n. 20
0
    def compute(self, inputs, outputs):

        # Results Folder creation if needed --------------------------------------------------------
        result_folder_path = self.options[OPTION_RESULT_FOLDER_PATH]
        if result_folder_path != "":
            os.makedirs(result_folder_path, exist_ok=True)

        # Creation of the temporary directory ------------------------------------------------------
        tmp_dir = TemporaryDirectory()
        if self.options[OPTION_AVL_EXE_PATH] != "":
            copy_resource(xfoil_resources, _PROFILE_FILE_NAME, tmp_dir.name)
            self.options["command"] = [self.options[OPTION_AVL_EXE_PATH]]
        else:
            copy_resource(avl336, _AVL_EXE_NAME, tmp_dir.name)
            copy_resource(xfoil_resources, _PROFILE_FILE_NAME, tmp_dir.name)
            self.options["command"] = [pth.join(tmp_dir.name, _AVL_EXE_NAME)]

        self.stdin = pth.join(tmp_dir.name, _STDIN_FILE_NANE)
        self.stdout = pth.join(tmp_dir.name, _STDOUT_FILE_NAME)
        self.stderr = pth.join(tmp_dir.name, _STDERR_FILE_NAME)

        # AVL geometry file (.avl) creation --------------------------------------------------------
        input_geom_file = pth.join(tmp_dir.name, _AVL_GEOM_NAME)
        profile_file = pth.join(tmp_dir.name, _PROFILE_FILE_NAME)
        self._get_avl_geom_file(inputs, input_geom_file, _PROFILE_FILE_NAME)

        # AVL session file creation ----------------------------------------------------------------

        s_ref = inputs["data:geometry:wing:area"]
        b_ref = inputs["data:geometry:wing:span"]
        c_ref = inputs["data:geometry:wing:MAC:length"]
        mach = inputs["data:aerostructural:load_case:mach"]
        alt = inputs["data:aerostructural:load_case:altitude"]
        rho = Atm(alt).density
        vtas = Atm(alt).speed_of_sound * mach
        q = 0.5 * rho * vtas ** 2

        m_lc = inputs["data:aerostructural:load_case:weight"]
        nz = inputs["data:aerostructural:load_case:load_factor"]
        cl = nz * m_lc * g / (q * s_ref)

        tmp_result_file = pth.join(tmp_dir.name, self.options[OPTION_RESULT_AVL_FILENAME])
        parser = InputFileGenerator()
        with path(ressources, _STDIN_FILE_NANE) as stdin_template:
            parser.set_template_file(stdin_template)
            parser.set_generated_file(self.stdin)

            # Update session file with target values:
            parser.mark_anchor("LOAD")
            parser.transfer_var(input_geom_file, 1, 1)
            parser.mark_anchor("OPER")
            parser.transfer_var(float(cl), 1, 3)
            parser.mark_anchor("M")
            parser.transfer_var(float(mach), 1, 2)
            parser.transfer_var(float(vtas), 2, 2)
            parser.transfer_var(float(rho), 3, 2)
            parser.mark_anchor("W")
            parser.transfer_var(tmp_result_file, 1, 1)

            parser.generate()

        # Check for input and output file presence -------------------------------------------------
        self.options["external_input_files"] = [
            self.stdin,
            input_geom_file,
            profile_file,
        ]
        self.options["external_output_files"] = [tmp_result_file]

        # Launch AVL -------------------------------------------------------------------------------
        super().compute(inputs, outputs)

        # Gather results ---------------------------------------------------------------------------
        parser_out = FileParser()
        parser_out.set_file(tmp_result_file)
        parser_out.mark_anchor("Alpha =")
        aoa = parser_out.transfer_var(0, 3)
        parser_out.mark_anchor("CLtot =")
        outputs["data:aerostructural:aerodynamic:CL"] = parser_out.transfer_var(0, 3)
        parser_out.mark_anchor("CDind =")
        outputs["data:aerostructural:aerodynamic:CDi"] = parser_out.transfer_var(0, 6)
        outputs["data:aerostructural:aerodynamic:Oswald_Coeff"] = parser_out.transfer_var(2, 6)
        for (comp, sect) in zip(self.options["components"], self.options["components_sections"]):
            size = sect  # default number of section for non symmetric components
            if comp in ("wing", "horizontal_tail", "strut"):
                size = sect * 2  # number of sections doubled for symmetric components
            elif comp == "fuselage":
                size = 4  # particular case for fuselage due to specific VLM modelling
            avl_comp = AVL_COMPONENT_NAMES[comp]
            parser_out.mark_anchor(avl_comp)
            comp_coef = parser_out.transfer_2Darray(0, 3, size - 1, 8)
            #  Reorganise result array to have coefficient in direct axis order
            comp_coef[:, :] = comp_coef[:, [1, 3, 0, 5, 2, 4]]
            #  Comvert coefficients into forces and moments
            comp_coef[:, :3] *= q * s_ref
            comp_coef[:, [3, 5]] *= q * s_ref * b_ref
            comp_coef[:, 4] *= q * s_ref * c_ref
            #  Change forces and moment from aerodynamic to body axis
            r_mat = self._get_rotation_matrix(aoa * degree, axis="y")
            comp_coef[:, :3] = np.dot(comp_coef[:, :3], r_mat)
            comp_coef[:, 3:] = np.dot(comp_coef[:, 3:], r_mat)  # Moments in std axis ie X fwd
            outputs["data:aerostructural:aerodynamic:" + comp + ":forces"] = comp_coef
        # outputs["data:aerostructural:aerodynamic:forces"] = q * s_ref * surface_coef

        # Store input and result files if necessary ------------------------------------------------
        if self.options[OPTION_RESULT_FOLDER_PATH]:
            if pth.exists(tmp_result_file):
                forces_file = pth.join(result_folder_path, self.options[OPTION_RESULT_AVL_FILENAME])
                shutil.move(tmp_result_file, forces_file)
            if pth.exists(input_geom_file):
                geometry_file = pth.join(result_folder_path, _AVL_GEOM_NAME)
                shutil.move(input_geom_file, geometry_file)
            if pth.exists(self.stdin):
                stdin_path = pth.join(result_folder_path, _STDIN_FILE_NANE)
                shutil.move(self.stdin, stdin_path)
            if pth.exists(self.stdout):
                stdout_path = pth.join(result_folder_path, _STDOUT_FILE_NAME)
                shutil.move(self.stdout, stdout_path)
            if pth.exists(self.stderr):
                stderr_path = pth.join(result_folder_path, _STDERR_FILE_NAME)
                shutil.move(self.stderr, stderr_path)
        tmp_dir.cleanup()
Esempio n. 21
0
    def test_output_parse_same_anchors(self):
        data = '\n'.join(
            ["CQUAD4 1 3.456", "CQUAD4 2 4.123", "CQUAD4 3 7.222", "CQUAD4 4"])

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

        gen = FileParser()
        gen.set_file(self.filename)
        gen.set_delimiters(' ')

        gen.mark_anchor('CQUAD4')
        val = gen.transfer_var(0, 3)
        self.assertEqual(val, 3.456)

        gen.mark_anchor('CQUAD4')
        val = gen.transfer_var(0, 3)
        self.assertEqual(val, 4.123)

        gen.mark_anchor('CQUAD4', 2)
        val = gen.transfer_var(0, 2)
        self.assertEqual(val, 4)

        gen.reset_anchor()

        gen.mark_anchor('CQUAD4', -1)
        val = gen.transfer_var(0, 2)
        self.assertEqual(val, 4)

        gen.mark_anchor('CQUAD4', -1)
        val = gen.transfer_var(0, 3)
        self.assertEqual(val, 7.222)

        gen.mark_anchor('CQUAD4', -2)
        val = gen.transfer_var(0, 3)
        self.assertEqual(val, 4.123)
Esempio n. 22
0
    def test_output_parse_keyvar(self):
        data = '\n'.join([
            "Anchor", " Key1 1 2 3.7 Test 1e65", " Key1 3 4 3.2 ibg 0.0003",
            " Key1 5 6 6.7 Tst xxx"
        ])

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

        gen = FileParser()
        gen.set_file(self.filename)
        gen.set_delimiters(' ')

        gen.mark_anchor('Anchor')
        val = gen.transfer_keyvar('Key1', 3)
        self.assertEqual(val, 3.7)
        val = gen.transfer_keyvar('Key1', 4, -2)
        self.assertEqual(val, 'ibg')
        val = gen.transfer_keyvar('Key1', 4, -2, -1)
        self.assertEqual(val, 'Test')

        try:
            gen.transfer_keyvar('Key1', 4, 0)
        except ValueError as err:
            msg = "The value for occurrence must be a nonzero integer"
            self.assertEqual(str(err), msg)
        else:
            self.fail('ValueError expected')

        try:
            gen.transfer_keyvar('Key1', 4, -3.4)
        except ValueError as err:
            msg = "The value for occurrence must be a nonzero integer"
            self.assertEqual(str(err), msg)
        else:
            self.fail('ValueError expected')
Esempio n. 23
0
    def test_output_parse_array(self):
        data = '\n'.join([
            "Anchor", "10 20 30 40 50 60 70 80", "11 21 31 41 51 61 71 81",
            "Key a b c d e"
        ])

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

        gen = FileParser()
        gen.set_file(self.filename)
        gen.set_delimiters(' ')

        gen.mark_anchor('Anchor')
        val = gen.transfer_array(1, 1, 1, 8)
        self.assertEqual(val[0], 10)
        self.assertEqual(val[7], 80)
        val = gen.transfer_array(1, 5, 2, 6)
        self.assertEqual(val[0], 50)
        self.assertEqual(val[9], 61)
        gen.mark_anchor('Key')
        val = gen.transfer_array(0, 2, 0, 6)
        self.assertEqual(val[4], 'e')
        val = gen.transfer_array(0, 2, fieldend=6)
        self.assertEqual(val[4], 'e')

        # Now, let's try column delimiters
        gen.reset_anchor()
        gen.mark_anchor('Anchor')
        gen.set_delimiters('columns')
        val = gen.transfer_array(1, 7, 1, 15)
        self.assertEqual(val[0], 30)
        self.assertEqual(val[2], 50)
        val = gen.transfer_array(1, 10, 2, 18)
        self.assertEqual(val[0], 40)
        self.assertEqual(val[5], 61)
        val = gen.transfer_array(3, 5, 3, 10)
        self.assertEqual(val[0], 'a b c')

        try:
            gen.transfer_array(1, 7, 1)
        except ValueError as err:
            msg = "fieldend is missing, currently required"
            self.assertEqual(str(err), msg)
        else:
            self.fail('ValueError expected')
Esempio n. 24
0
    def test_more_delims(self):
        data = '\n'.join([
            "anchor,1.0,2.0", "abc=123.456", "c=1,2,Word,6",
            "d=C:/abc/def,a+b*c^2,(%#%),!true", "a^33 1.#QNAN^#$%^"
        ])

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

        op = FileParser()
        op.set_file(self.filename)

        op.set_delimiters(' \t,=')

        op.mark_anchor('anchor')

        val = op.transfer_var(0, 1)
        self.assertEqual(val, 'anchor')
        val = op.transfer_var(0, 2)
        self.assertEqual(val, 1.0)
        val = op.transfer_var(1, 1)
        self.assertEqual(val, 'abc')
        val = op.transfer_var(1, 2)
        self.assertEqual(val, 123.456)
        val = op.transfer_var(2, 4)
        self.assertEqual(val, 'Word')
        val = op.transfer_var(2, 5)
        self.assertEqual(val, 6)
        val = op.transfer_var(3, 2)
        self.assertEqual(val, 'C:/abc/def')
        val = op.transfer_var(3, 3)
        self.assertEqual(val, 'a+b*c^2')
        val = op.transfer_var(3, 4)
        self.assertEqual(val, '(%#%)')
        val = op.transfer_var(3, 5)
        self.assertEqual(val, '!true')

        op.set_delimiters(' \t^')
        val = op.transfer_var(4, 1)
        self.assertEqual(val, 'a')
        val = op.transfer_var(4, 2)
        self.assertEqual(val, 33)
        val = op.transfer_var(4, 3)
        self.assertEqual(isnan(val), True)
        val = op.transfer_var(4, 4)
        self.assertEqual(val, '#$%')
Esempio n. 25
0
    def test_more_delims(self):
        data = '\n'.join([
            "anchor,1.0,2.0",
            "abc=123.456",
            "c=1,2,Word,6",
            "d=C:/abc/def,a+b*c^2,(%#%),!true",
            "a^33 1.#QNAN^#$%^"
        ])

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

        op = FileParser()
        op.set_file(self.filename)

        op.set_delimiters(' \t,=')

        op.mark_anchor('anchor')

        val = op.transfer_var(0, 1)
        self.assertEqual(val, 'anchor')
        val = op.transfer_var(0, 2)
        self.assertEqual(val, 1.0)
        val = op.transfer_var(1, 1)
        self.assertEqual(val, 'abc')
        val = op.transfer_var(1, 2)
        self.assertEqual(val, 123.456)
        val = op.transfer_var(2, 4)
        self.assertEqual(val, 'Word')
        val = op.transfer_var(2, 5)
        self.assertEqual(val, 6)
        val = op.transfer_var(3, 2)
        self.assertEqual(val, 'C:/abc/def')
        val = op.transfer_var(3, 3)
        self.assertEqual(val, 'a+b*c^2')
        val = op.transfer_var(3, 4)
        self.assertEqual(val, '(%#%)')
        val = op.transfer_var(3, 5)
        self.assertEqual(val, '!true')

        op.set_delimiters(' \t^')
        val = op.transfer_var(4, 1)
        self.assertEqual(val, 'a')
        val = op.transfer_var(4, 2)
        self.assertEqual(val, 33)
        val = op.transfer_var(4, 3)
        self.assertEqual(isnan(val), True)
        val = op.transfer_var(4, 4)
        self.assertEqual(val, '#$%')
Esempio n. 26
0
import openmdao.api as om
import numpy as np
import pandas as pd

from openmdao.utils.file_wrap import InputFileGenerator
from openmdao.utils.file_wrap import FileParser

writeParser = InputFileGenerator()
readParser = FileParser()


class BladeDesignOptimizerMDAO(om.ExternalCodeComp):
    def setup(self):

        #link inputs
        #self.add_input('dev')
        self.add_input('t')
        self.add_input('in_beta')
        self.add_input('out_beta')
        self.add_input('cur1')
        self.add_input('cur2')
        self.add_input('cur3')
        self.add_input('cur4')
        self.add_input('cur5')
        self.add_input('cur6')
        self.add_input('cur7')
        self.add_input('u_max')
        self.add_input('LE_radius')
        self.add_input('t_TE')
        self.add_input('dydxTE')
Esempio n. 27
0
    def test_output_parse(self):
        data = '\n'.join([
            "Junk",
            "Anchor",
            " A 1, 2 34, Test 1e65",
            " B 4 Stuff",
            "Anchor",
            " C 77 False NaN 333.444",
            " 1,2,3,4,5",
            " Inf 1.#QNAN -1.#IND"
        ])

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

        gen = FileParser()
        gen.set_file(self.filename)
        gen.set_delimiters(' ')

        gen.mark_anchor('Anchor')
        val = gen.transfer_var(1, 1)
        self.assertEqual(val, 'A')
        gen.reset_anchor()
        val = gen.transfer_var(3, 2)
        self.assertEqual(val, 4)
        self.assertEqual(type(val), int)
        gen.mark_anchor('Anchor',2)
        val = gen.transfer_var(1, 4)
        self.assertEqual(isnan(val), True)
        val = gen.transfer_var(3, 1)
        self.assertEqual(isinf(val), True)
        val = gen.transfer_var(3, 2)
        self.assertEqual(isnan(val), True)
        val = gen.transfer_var(3, 3)
        self.assertEqual(isnan(val), True)
        val = gen.transfer_line(-1)
        self.assertEqual(val, ' B 4 Stuff')

        # Now, let's try column delimiters
        gen.set_delimiters('columns')
        gen.mark_anchor('Anchor',-1)
        val = gen.transfer_var(1, 8, 10)
        self.assertEqual(val, 'als')
        val = gen.transfer_var(1, 17)
        self.assertEqual(val, 333.444)

        # Test some errors
        try:
            gen.mark_anchor('C 77', 3.14)
        except ValueError as err:
            msg = "The value for occurrence must be an integer"
            self.assertEqual(str(err), msg)
        else:
            self.fail('ValueError expected')

        try:
            gen.mark_anchor('C 77', 0)
        except ValueError as err:
            msg = "0 is not valid for an anchor occurrence."
            self.assertEqual(str(err), msg)
        else:
            self.fail('ValueError expected')

        try:
            gen.mark_anchor('ZZZ')
        except RuntimeError as err:
            msg = "Could not find pattern ZZZ in output file filename.dat"
            self.assertEqual(str(err), msg)
        else:
            self.fail('RuntimeError expected')
Esempio n. 28
0
    def test_output_parse(self):
        data = '\n'.join([
            "Junk", "Anchor", " A 1, 2 34, Test 1e65", " B 4 Stuff", "Anchor",
            " C 77 False NaN 333.444", " 1,2,3,4,5", " Inf 1.#QNAN -1.#IND"
        ])

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

        gen = FileParser()
        gen.set_file(self.filename)
        gen.set_delimiters(' ')

        gen.mark_anchor('Anchor')
        val = gen.transfer_var(1, 1)
        self.assertEqual(val, 'A')
        gen.reset_anchor()
        val = gen.transfer_var(3, 2)
        self.assertEqual(val, 4)
        self.assertEqual(type(val), int)
        gen.mark_anchor('Anchor', 2)
        val = gen.transfer_var(1, 4)
        self.assertEqual(isnan(val), True)
        val = gen.transfer_var(3, 1)
        self.assertEqual(isinf(val), True)
        val = gen.transfer_var(3, 2)
        self.assertEqual(isnan(val), True)
        val = gen.transfer_var(3, 3)
        self.assertEqual(isnan(val), True)
        val = gen.transfer_line(-1)
        self.assertEqual(val, ' B 4 Stuff')

        # Now, let's try column delimiters
        gen.set_delimiters('columns')
        gen.mark_anchor('Anchor', -1)
        val = gen.transfer_var(1, 8, 10)
        self.assertEqual(val, 'als')
        val = gen.transfer_var(1, 17)
        self.assertEqual(val, 333.444)

        # Test some errors
        try:
            gen.mark_anchor('C 77', 3.14)
        except ValueError as err:
            msg = "The value for occurrence must be an integer"
            self.assertEqual(str(err), msg)
        else:
            self.fail('ValueError expected')

        try:
            gen.mark_anchor('C 77', 0)
        except ValueError as err:
            msg = "0 is not valid for an anchor occurrence."
            self.assertEqual(str(err), msg)
        else:
            self.fail('ValueError expected')

        try:
            gen.mark_anchor('ZZZ')
        except RuntimeError as err:
            msg = "Could not find pattern ZZZ in output file filename.dat"
            self.assertEqual(str(err), msg)
        else:
            self.fail('RuntimeError expected')
Esempio n. 29
0
    def test_output_parse_same_anchors(self):
        data = '\n'.join([
            "CQUAD4 1 3.456",
            "CQUAD4 2 4.123",
            "CQUAD4 3 7.222",
            "CQUAD4 4"
        ])

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

        gen = FileParser()
        gen.set_file(self.filename)
        gen.set_delimiters(' ')

        gen.mark_anchor('CQUAD4')
        val = gen.transfer_var(0, 3)
        self.assertEqual(val, 3.456)

        gen.mark_anchor('CQUAD4')
        val = gen.transfer_var(0, 3)
        self.assertEqual(val, 4.123)

        gen.mark_anchor('CQUAD4', 2)
        val = gen.transfer_var(0, 2)
        self.assertEqual(val, 4)

        gen.reset_anchor()

        gen.mark_anchor('CQUAD4', -1)
        val = gen.transfer_var(0, 2)
        self.assertEqual(val, 4)

        gen.mark_anchor('CQUAD4', -1)
        val = gen.transfer_var(0, 3)
        self.assertEqual(val, 7.222)

        gen.mark_anchor('CQUAD4', -2)
        val = gen.transfer_var(0, 3)
        self.assertEqual(val, 4.123)
Esempio n. 30
0
    def compute(self, inputs, outputs):
        eff = inputs['eff']
        length = inputs['length']
        alp = inputs['alp']
        eps = inputs['eps']
        GL107_200 = 1 / inputs['R_m']
        GL111_300 = 1 / inputs['R_p']
        GL103_400 = inputs['GlTether']
        GL102_601 = 1 / inputs['R_s']
        GL107_111 = inputs['ci1']
        GL107_109 = inputs['ci2']
        GL103_109 = inputs['ci3']
        GL101_109 = inputs['ci4']
        GL109_111 = inputs['ci5']
        GL101_103 = inputs['ci6']
        GL103_111 = inputs['ci7']
        GL101_107 = inputs['ci8']
        GL103_105 = inputs['ci9']
        GL101_105 = inputs['ci10']
        GL105_111 = inputs['ci11']
        GL105_107 = inputs['ci12']
        r_bat = inputs['r_bat']
        ht_gain = inputs['ht_gain']
        q_s = inputs['q_s']

        eff = '{0};'.format(float(eff))
        length = '{0};'.format(float(length))
        ht_gain = '{0};'.format(float(ht_gain))
        r_bat = '{0};'.format(float(r_bat))
        q_s = '{0};'.format(float(q_s))
        alp = '{0},'.format(float(alp))
        eps = '{0},'.format(float(eps))
        GL107_200 = '{0};'.format(float(GL107_200))
        GL111_300 = '{0};'.format(float(GL111_300))
        GL103_400 = '{0};'.format(float(GL103_400))
        GL102_601 = '{0};'.format(float(GL102_601))
        GL107_111 = '{0};'.format(float(GL107_111))
        GL107_109 = '{0};'.format(float(GL107_109))
        GL103_109 = '{0};'.format(float(GL103_109))
        GL101_109 = '{0};'.format(float(GL101_109))
        GL109_111 = '{0};'.format(float(GL109_111))
        GL101_103 = '{0};'.format(float(GL101_103))
        GL103_111 = '{0};'.format(float(GL103_111))
        GL101_107 = '{0};'.format(float(GL101_107))
        GL103_105 = '{0};'.format(float(GL103_105))
        GL101_105 = '{0};'.format(float(GL101_105))
        GL105_111 = '{0};'.format(float(GL105_111))
        GL105_107 = '{0};'.format(float(GL105_107))

        # generate the input file for RU_tm thermal analysis
        generator = InputFileGenerator()
        generator.set_template_file('./esatan/RU_template.txt')
        generator.set_generated_file('./esatan/RU_tm.d')
        generator.mark_anchor("$LOCALS")
        generator.transfer_var(length, 21, 3)
        generator.transfer_var(eff, 23, 3)
        generator.transfer_var(r_bat, 25, 3)
        generator.transfer_var(ht_gain, 27, 3)
        generator.transfer_var(q_s, 29, 3)
        generator.mark_anchor("$NODES")
        generator.transfer_var(alp, 53, 6)
        generator.transfer_var(eps, 53, 9)
        generator.transfer_var(alp, 61, 6)
        generator.transfer_var(eps, 61, 9)
        generator.transfer_var(alp, 69, 6)
        generator.transfer_var(eps, 69, 9)
        generator.transfer_var(alp, 77, 6)
        generator.transfer_var(eps, 77, 9)
        generator.transfer_var(alp, 85, 6)
        generator.transfer_var(eps, 85, 9)
        generator.transfer_var(alp, 93, 6)
        generator.transfer_var(eps, 93, 9)
        generator.mark_anchor("Generated conductors")
        generator.transfer_var(GL107_200, 3, 3)
        generator.transfer_var(GL111_300, 4, 3)
        generator.transfer_var(GL107_111, 5, 3)
        generator.transfer_var(GL107_109, 6, 3)
        generator.transfer_var(GL103_109, 7, 3)
        generator.transfer_var(GL101_109, 8, 3)
        generator.transfer_var(GL109_111, 9, 3)
        generator.transfer_var(GL101_103, 10, 3)
        generator.transfer_var(GL103_111, 11, 3)
        generator.transfer_var(GL101_107, 12, 3)
        generator.transfer_var(GL103_105, 13, 3)
        generator.transfer_var(GL101_105, 14, 3)
        generator.transfer_var(GL105_111, 15, 3)
        generator.transfer_var(GL105_107, 16, 3)
        generator.transfer_var(GL102_601, 17, 3)
        generator.transfer_var(GL103_400, 45, 3)
        generator.generate()

        # the parent compute function actually runs the external code
        super(RUextCodeComp, self).compute(inputs, outputs)

        # parse the output file from the external code and set the value of T_max
        parser = FileParser()
        parser.set_file('./esatan/RU_TM.out')
        parser.mark_anchor("+RU_TM")
        tBat = parser.transfer_var(7, 3)
        tMain = parser.transfer_var(34, 3)
        tProp = parser.transfer_var(35, 3)
        tTether = parser.transfer_var(36, 3)
        tBPanel = parser.transfer_var(41, 3)
        tDPanel = parser.transfer_var(43, 3)

        outputs['tBat'] = tBat
        outputs['tMain'] = tMain
        outputs['tProp'] = tProp
        outputs['tTether'] = tTether
        outputs['tBPanel'] = tBPanel
        outputs['tDPanel'] = tDPanel
Esempio n. 31
0
    def test_output_parse_2Darray(self):
        data = '''
        Anchor
            FREQ  DELTA  -8.5  -8.5  -8.5  -8.5  -8.5  -8.5  -8.5  -8.5  -8.5  -8.5  -8.5  -8.5  -8.5  -8.5  -8.5  -8.5  -8.5
             Hz
             50.   1.0   30.0  34.8  36.3  36.1  34.6  32.0  28.4  23.9  18.5  12.2   5.0  -3.1 -12.3 -22.5 -34.0 -47.2 -63.7
             63.   1.0   36.5  41.3  42.8  42.6  41.1  38.5  34.9  30.4  25.0  18.7  11.5   3.4  -5.8 -16.0 -27.5 -40.7 -57.2
             80.   1.0   42.8  47.6  49.1  48.9  47.4  44.8  41.2  36.7  31.3  25.0  17.8   9.7   0.5  -9.7 -21.2 -34.4 -50.9
            100.   1.0   48.4  53.1  54.7  54.5  53.0  50.4  46.8  42.3  36.9  30.6  23.3  15.2   6.1  -4.2 -15.7 -28.9 -45.4
            125.   1.0   53.6  58.3  59.9  59.6  58.1  55.5  52.0  47.5  42.0  35.7  28.5  20.4  11.2   1.0 -10.5 -23.7 -40.2
            160.   1.0   58.9  63.7  65.2  65.0  63.5  60.9  57.3  52.8  47.4  41.0  33.8  25.7  16.5   6.3  -5.2 -18.4 -34.9
            200.   1.0   63.4  68.1  69.6  69.4  67.9  65.3  61.7  57.2  51.8  45.5  38.3  30.1  21.0  10.7  -0.8 -14.0 -30.5
            250.   1.0   67.5  72.2  73.7  73.5  72.0  69.4  65.8  61.3  55.9  49.5  42.3  34.2  25.0  14.8   3.3 -10.0 -26.5
            315.   1.0   71.3  76.1  77.6  77.4  75.8  73.2  69.7  65.1  59.7  53.4  46.1  38.0  28.8  18.6   7.1  -6.2 -22.7
            400.   1.0   74.9  79.7  81.2  81.0  79.4  76.8  73.2  68.7  63.2  56.9  49.7  41.5  32.4  22.1  10.6  -2.7 -19.2
            500.   1.0   77.9  82.7  84.2  83.9  82.4  79.8  76.2  71.6  66.2  59.8  52.6  44.4  35.3  25.0  13.5   0.2 -16.3
            630.   1.0   80.7  85.4  86.9  86.6  85.1  82.4  78.8  74.3  68.8  62.5  55.2  47.0  37.9  27.6  16.1   2.8 -13.7
            800.   1.0   83.1  87.8  89.2  89.0  87.4  84.8  81.2  76.6  71.1  64.8  57.5  49.3  40.1  29.9  18.3   5.0 -11.5
           1000.   1.0   84.9  89.6  91.1  90.8  89.2  86.6  82.9  78.4  72.9  66.5  59.2  51.0  41.8  31.5  20.0   6.6  -9.9
           1250.   1.0   86.4  91.1  92.5  92.2  90.7  88.0  84.3  79.7  74.2  67.8  60.5  52.3  43.1  32.8  21.2   7.9  -8.7
           1600.   1.0   87.6  92.3  93.7  93.4  91.8  89.1  85.4  80.8  75.2  68.8  61.5  53.3  44.0  33.7  22.1   8.7  -7.9
           2000.   1.0   88.4  93.0  94.4  94.0  92.4  89.6  85.9  81.3  75.7  69.3  61.9  53.7  44.4  34.0  22.4   9.0  -7.6
           2500.   1.0   88.7  93.3  94.6  94.2  92.6  89.8  86.1  81.4  75.8  69.3  61.9  53.6  44.3  33.9  22.2   8.8  -7.9
           3150.   1.0   88.7  93.2  94.5  94.1  92.4  89.5  85.7  81.0  75.4  68.8  61.4  53.0  43.7  33.3  21.5   8.1  -8.6
           4000.   1.0   88.3  92.7  94.0  93.5  91.7  88.8  85.0  80.2  74.5  67.9  60.4  52.0  42.5  32.0  20.2   6.7 -10.0
           5000.   1.0   87.5  91.9  93.1  92.5  90.7  87.7  83.8  78.9  73.2  66.5  58.9  50.4  40.9  30.4  18.5   4.9 -11.9
           6300.   1.0   86.5  90.8  91.9  91.2  89.3  86.2  82.2  77.3  71.4  64.6  57.0  48.4  38.8  28.1  16.2   2.5 -14.5
           8000.   1.0   85.3  89.5  90.4  89.6  87.6  84.4  80.2  75.2  69.2  62.3  54.5  45.8  36.1  25.3  13.2  -0.6 -17.7
          10000.   1.0   84.2  88.2  89.0  88.1  85.9  82.5  78.3  73.0  66.9  59.9  51.9  43.1  33.2  22.3  10.1  -3.9 -21.1
        '''

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

        gen = FileParser()
        gen.set_file(self.filename)

        # whitespace delim; with end field
        gen.set_delimiters(' \t')
        gen.mark_anchor('Anchor')
        val = gen.transfer_2Darray(3, 2, 26, 19)
        self.assertEqual(val[0, 1], 30.0)
        self.assertEqual(val[0, 17], -63.7)
        self.assertEqual(val[1, 17], -57.2)
        self.assertEqual(val[23, 17], -21.1)
        self.assertEqual(val.shape[0], 24)
        self.assertEqual(val.shape[1], 18)

        # whitespace delim; no end field
        val = gen.transfer_2Darray(3, 2, 26)
        self.assertEqual(val[0, 1], 30.0)
        self.assertEqual(val[23, 17], -21.1)
        self.assertEqual(val.shape[0], 24)
        self.assertEqual(val.shape[1], 18)

        # column delim; with end field
        gen.set_delimiters('columns')
        val = gen.transfer_2Darray(3, 19, 26, 125)
        self.assertEqual(val[0, 1], 30.0)
        self.assertEqual(val[0, 17], -63.7)
        self.assertEqual(val[1, 17], -57.2)
        self.assertEqual(val[23, 17], -21.1)
        self.assertEqual(val.shape[0], 24)
        self.assertEqual(val.shape[1], 18)

        # column delim; no end field
        val = gen.transfer_2Darray(3, 19, 26)
        self.assertEqual(val[0, 1], 30.0)
        self.assertEqual(val[0, 17], -63.7)
        self.assertEqual(val[1, 17], -57.2)
        self.assertEqual(val[23, 17], -21.1)
        self.assertEqual(val.shape[0], 24)
        self.assertEqual(val.shape[1], 18)

        # make sure single line works
        gen.set_delimiters(' \t')
        val = gen.transfer_2Darray(5, 3, 5, 5)
        self.assertEqual(val[0, 2], 49.1)

        # Small block read
        val = gen.transfer_2Darray(7, 3, 9, 6)
        self.assertEqual(val[0, 0], 53.6)
        self.assertEqual(val[2, 0], 63.4)

        # Error messages for bad values
        try:
            gen.transfer_2Darray(7, 3, 9, 1)
        except ValueError as err:
            msg = "fieldend must be greater than fieldstart"
            self.assertEqual(str(err), msg)
        else:
            self.fail('ValueError expected')

        try:
            gen.transfer_2Darray(9, 2, 8, 4)
        except ValueError as err:
            msg = "rowend must be greater than rowstart"
            self.assertEqual(str(err), msg)
        else:
            self.fail('ValueError expected')