Пример #1
0
    def setUp(self):
        if not hasattr(UFOParserTest, 'model'):
            self.cmd = Cmd.MasterCmd()
            self.cmd.exec_cmd("import model loop_qcd_qed_sm")
            UFOParserTest.model = self.cmd._curr_model

        if not hasattr(self, 'calc'):
            self.calc = parsers.UFOExpressionParserFortran(UFOParserTest.model)
        if not hasattr(self, 'mp_calc'):
            self.mp_calc = parsers.UFOExpressionParserMPFortran(
                UFOParserTest.model)
Пример #2
0
    def test_parse_to_fortran(self):
        """Test Python to Fortran expression parser"""

        ufo_to_fortran = ufo_expression_parsers.UFOExpressionParserFortran(
            TestUFOExpressionParsers.model)
        expr = 'cmath.sqrt(2)'
        converted = ufo_to_fortran.parse(expr)
        self.assertTrue(isinstance(converted, str))
        self.assertEqual(converted, 'sqrt(dcmplx(2.000000d+00))')

        expr = 'cmath.sqrt(2.)'
        converted = ufo_to_fortran.parse(expr)
        self.assertEqual(converted, 'sqrt(dcmplx(2.000000d+00))')

        expr = 'randomfunction(2.)'
        converted = ufo_to_fortran.parse(expr)
        self.assertEqual(converted, 'randomfunction(2.000000d+00)')

        expr = 'function(2., a+b)'
        converted = ufo_to_fortran.parse(expr)
        self.assertEqual(converted, 'function(2.000000d+00,a+b)')

        expr = 'cmath.sqrt(2.5)'
        converted = ufo_to_fortran.parse(expr)
        self.assertEqual(converted, 'sqrt(dcmplx(2.500000d+00))')

        expr = 'cmath.testfcn(2.00, a+b)'
        converted = ufo_to_fortran.parse(expr)
        self.assertEqual(converted, 'testfcn(2.000000d+00,a+b)')

        expr = 'cmath.sin(2.00)'
        converted = ufo_to_fortran.parse(expr)
        self.assertEqual(converted, 'sin(2.000000d+00)')

        expr = '(ee**2*IMAG/(2.*sw**2) * (cmath.sin(cmath.sqrt(2)*ee)**2/3.))'
        converted = ufo_to_fortran.parse(expr)
        self.assertEqual(
            converted,
            '(ee**2*imag/(2.000000d+00*sw**2)*(sin(sqrt(dcmplx(2.000000d+00))*ee)**2/3.000000d+00))'
        )
Пример #3
0
    def test_convert_number_to_fortran(self):
        """ test it can convert number in fortran string"""

        py2f77 = ufo_expression_parsers.UFOExpressionParserFortran()
        expr = str(2)
        converted = py2f77.parse(expr)
        self.assertTrue(isinstance(converted, str))
        self.assertEqual(converted, '2.000000d+00')

        expr = str(0.23)
        converted = py2f77.parse(expr)
        self.assertTrue(isinstance(converted, str))
        self.assertEqual(converted, '2.300000d-01')

        expr = str(2.5e6)
        converted = py2f77.parse(expr)
        self.assertTrue(isinstance(converted, str))
        self.assertEqual(converted, '2.500000d+06')

        expr = str(0.0000116639)
        converted = py2f77.parse(expr)
        self.assertTrue(isinstance(converted, str))
        self.assertEqual(converted, '1.166390d-05')
Пример #4
0
 def setUp(self):
     if not hasattr(self, 'calc'):
         self.calc = parsers.UFOExpressionParserFortran()
     if not hasattr(self, 'mp_calc'):
         self.mp_calc = parsers.UFOExpressionParserMPFortran()