コード例 #1
0
 def setUp(self):
     numerrin.initlocal("", "PYNUMERRIN_LICENSE", liccode)
     self.pool = NumerrinPool()
     self.code = NumerrinCode(self.pool.ph)
     self.codestring = "a = 10.0\n"
     self.errorcodestring = "a = 10/b\n"
     self.exceptionstring = "Exception(\"Exception\")\n"
コード例 #2
0
    def test_variable_rank(self):
        """Test variable_rank method

        """

        pool = NumerrinPool()
        pool.put_variable(self.variablename, self.variable)
        self.assertEqual(pool.variable_rank(self.variablename), 2)
コード例 #3
0
    def test_put_variable(self):
        """Test put_variable method

        """

        pool = NumerrinPool()
        pool.put_variable(self.variablename, self.variable)
        self.assertEqual(pool.get_variable(self.variablename), self.variable)
コード例 #4
0
    def test_variable_type(self):
        """Test variable_type method

        """

        pool = NumerrinPool()
        pool.import_mesh(self.mesh.name, self.mesh, self.boundaries)
        self.assertEqual(pool.variable_type(self.mesh.name), "Mesh")
コード例 #5
0
    def test_put_variable(self):
        """Test put_variable method

        """

        pool = NumerrinPool()
        pool.put_variable(self.variablename, self.variable)
        self.assertEqual(pool.get_variable(self.variablename), self.variable)
コード例 #6
0
    def test_variable_rank(self):
        """Test variable_rank method

        """

        pool = NumerrinPool()
        pool.put_variable(self.variablename, self.variable)
        self.assertEqual(pool.variable_rank(self.variablename), 2)
コード例 #7
0
    def test_variable_type(self):
        """Test variable_type method

        """

        pool = NumerrinPool()
        pool.import_mesh(self.mesh.name, self.mesh, self.boundaries)
        self.assertEqual(pool.variable_type(self.mesh.name), "Mesh")
コード例 #8
0
    def test_clear(self):
        """Test clear method

        """

        pool = NumerrinPool()
        pool.import_mesh(self.mesh.name, self.mesh, self.boundaries)
        pool.clear()
        with self.assertRaises(RuntimeError):
            numerrin.meshsize(pool.ph, self.mesh.name)
コード例 #9
0
    def test_import_mesh(self):
        """Test import_mesh method

        """

        pool = NumerrinPool()
        pool.import_mesh(self.mesh.name, self.mesh, self.boundaries)
        self.assertEqual(
            numerrin.meshsize(pool.ph, self.mesh.name)[0], len(self.points))
        self.assertEqual(
            numerrin.meshsize(pool.ph, self.mesh.name)[2], len(self.faces))
        self.assertEqual(
            numerrin.meshsize(pool.ph, self.mesh.name)[3], len(self.cells))
コード例 #10
0
    def test_import_mesh(self):
        """Test import_mesh method

        """

        pool = NumerrinPool()
        pool.import_mesh(self.mesh.name, self.mesh, self.boundaries)
        self.assertEqual(numerrin.meshsize(pool.ph, self.mesh.name)[0],
                         len(self.points))
        self.assertEqual(numerrin.meshsize(pool.ph, self.mesh.name)[2],
                         len(self.faces))
        self.assertEqual(numerrin.meshsize(pool.ph, self.mesh.name)[3],
                         len(self.cells))
コード例 #11
0
    def test_delete_mesh_and_variables(self):
        """Test delete_mesh_and_variables method

        """

        pool = NumerrinPool()
        pool.import_mesh(self.mesh.name, self.mesh, self.boundaries)
        pool.put_variable(self.variablename, self.variable)
        pool.delete_mesh_and_variables(self.mesh.name)

        with self.assertRaises(RuntimeError):
            pool.get_variable(self.variablename)
        with self.assertRaises(RuntimeError):
            numerrin.meshsize(pool.ph, self.mesh.name)
コード例 #12
0
 def setUp(self):
     numerrin.initlocal("", "PYNUMERRIN_LICENSE", liccode)
     self.pool = NumerrinPool()
     self.code = NumerrinCode(self.pool.ph)
     self.codestring = "a = 10.0\n"
     self.errorcodestring = "a = 10/b\n"
     self.exceptionstring = "Exception(\"Exception\")\n"
コード例 #13
0
    def test_delete_mesh_and_variables(self):
        """Test delete_mesh_and_variables method

        """

        pool = NumerrinPool()
        pool.import_mesh(self.mesh.name, self.mesh, self.boundaries)
        pool.put_variable(self.variablename, self.variable)
        pool.delete_mesh_and_variables(self.mesh.name)

        with self.assertRaises(RuntimeError):
            pool.get_variable(self.variablename)
        with self.assertRaises(RuntimeError):
            numerrin.meshsize(pool.ph, self.mesh.name)
コード例 #14
0
    def test_modify_variable(self):
        """Test modify_variable method

        """

        pool = NumerrinPool()
        pool.put_variable(self.variablename, self.variable)
        oldvar = pool.get_variable(self.variablename)
        modvar = tuple([(10.0, 10.0, 10.0) for _ in oldvar])
        pool.modify_variable(self.variablename, modvar)
        newvar = pool.get_variable(self.variablename)
        self.assertNotEqual(oldvar, newvar)
コード例 #15
0
    def test_export_mesh(self):
        """Test export_mesh method

        """

        pool = NumerrinPool()
        pool.import_mesh(self.mesh.name, self.mesh, self.boundaries)
        boundary_names = self.boundaries.keys()
        (smesh, mmap, boundaries) = pool.export_mesh(self.mesh.name,
                                                     self.mesh.name,
                                                     boundary_names)
        self.assertEqual(sum(1 for _ in smesh.iter(item_type=CUBA.POINT)),
                         sum(1 for _ in self.mesh.iter(item_type=CUBA.POINT)))
        self.assertEqual(sum(1 for _ in smesh.iter(item_type=CUBA.FACE)),
                         sum(1 for _ in self.mesh.iter(item_type=CUBA.FACE)))
        self.assertEqual(sum(1 for _ in smesh.iter(item_type=CUBA.CELL)),
                         sum(1 for _ in self.mesh.iter(item_type=CUBA.CELL)))
        self.assertEqual(
            set([p.coordinates for p in smesh.iter(item_type=CUBA.POINT)]),
            set([p.coordinates for p in self.mesh.iter(item_type=CUBA.POINT)]))
        self.assertEqual(boundaries.keys(), boundary_names)
コード例 #16
0
    def test_export_mesh(self):
        """Test export_mesh method

        """

        pool = NumerrinPool()
        pool.import_mesh(self.mesh.name, self.mesh, self.boundaries)
        boundary_names = self.boundaries.keys()
        (smesh, mmap, boundaries) = pool.export_mesh(self.mesh.name,
                                                     self.mesh.name,
                                                     boundary_names)
        self.assertEqual(sum(1 for _ in smesh.iter(item_type=CUBA.POINT)),
                         sum(1 for _ in self.mesh.iter(item_type=CUBA.POINT)))
        self.assertEqual(sum(1 for _ in smesh.iter(item_type=CUBA.FACE)),
                         sum(1 for _ in self.mesh.iter(item_type=CUBA.FACE)))
        self.assertEqual(sum(1 for _ in smesh.iter(item_type=CUBA.CELL)),
                         sum(1 for _ in self.mesh.iter(item_type=CUBA.CELL)))
        self.assertEqual(set([p.coordinates
                              for p in smesh.iter(item_type=CUBA.POINT)]),
                         set([p.coordinates
                              for p in self.mesh.iter(item_type=CUBA.POINT)]))
        self.assertEqual(boundaries.keys(), boundary_names)
コード例 #17
0
    def test_modify_variable(self):
        """Test modify_variable method

        """

        pool = NumerrinPool()
        pool.put_variable(self.variablename, self.variable)
        oldvar = pool.get_variable(self.variablename)
        modvar = tuple([(10.0, 10.0, 10.0) for _ in oldvar])
        pool.modify_variable(self.variablename, modvar)
        newvar = pool.get_variable(self.variablename)
        self.assertNotEqual(oldvar, newvar)
コード例 #18
0
    def test_clear(self):
        """Test clear method

        """

        pool = NumerrinPool()
        pool.import_mesh(self.mesh.name, self.mesh, self.boundaries)
        pool.clear()
        with self.assertRaises(RuntimeError):
            numerrin.meshsize(pool.ph, self.mesh.name)
コード例 #19
0
class NumerrinCodeTestCase(unittest.TestCase):
    """Test case for NumerrinCode class"""
    def setUp(self):
        numerrin.initlocal("", "PYNUMERRIN_LICENSE", liccode)
        self.pool = NumerrinPool()
        self.code = NumerrinCode(self.pool.ph)
        self.codestring = "a = 10.0\n"
        self.errorcodestring = "a = 10/b\n"
        self.exceptionstring = "Exception(\"Exception\")\n"

    def test_parse_file(self):
        """Test parse_file method

        """
        codefile = 'test.num'
        with open(codefile, 'w') as f:
            f.write(self.codestring)
        self.code.parse_file(codefile)
        os.remove(codefile)

    def test_parse_string(self):
        """Test parse_string method

        """
        self.code.parse_string(self.codestring)
        with self.assertRaises(RuntimeError):
            self.code.parse_string(self.errorcodestring)

    def test_execute(self):
        """Test execute method

        """
        self.code.parse_string(self.codestring)
        self.code.execute(1)

    def test_clear(self):
        """Test clear method

        """

        self.code.parse_string(self.exceptionstring)
        with self.assertRaises(RuntimeError):
            self.code.execute(1)
        self.code.clear()
        self.code.execute(1)

    def test_generate_code(self):
        """Test generate_init_code and generate_code method

        """
        CM = DataContainer()
        SP = DataContainer()
        SPExt = DataContainer()
        BC = DataContainer()
        CMExt = {}
        mesh_name = "Mesh"
        CM[CUBA.NAME] = mesh_name
        CMExt[CUBAExt.GE] = (CUBAExt.INCOMPRESSIBLE, CUBAExt.LAMINAR_MODEL)
        SP[CUBA.TIME_STEP] = 1
        SP[CUBA.NUMBER_OF_TIME_STEPS] = 2
        SP[CUBA.DENSITY] = 1.0
        SP[CUBA.DYNAMIC_VISCOSITY] = 1.0
        BC[CUBA.VELOCITY] = {'boundary0': ('fixedValue', (0.1, 0, 0))}
        BC[CUBA.PRESSURE] = {'boundary0': 'zeroGradient'}

        boundary_names = ['boundary0', 'boundary1', 'boundary2', 'boundary3']

        corner_points = ((0.0, 0.0), (20.0e-3, 0.0), (20.0e-3, 1.0e-3),
                         (0.0, 1.0e-3))
        mesh_code = textwrap.dedent(
            """
            pts={%f,%f;%f,%f;%f,%f;%f,%f}
            Quadmesh(pts,{%i,%i},{0,0,0,0},{1.0,1.0,-1.0,-1.0},mesh2d,domains2d)
            dvec[0:1]=0.0
            dvec[2]=%f
            Extrude(mesh2d,domains2d,dvec,%i,0,0.0,%s,domains)
            omega->domains[0]
            %s->domains[6]
            %s->domains[4]
            %s=Union(domains[3],domains[5])
            %s=Union(domains[1],domains[2])
            """ %
            (corner_points[0][0], corner_points[0][1], corner_points[1][0],
             corner_points[1][1], corner_points[2][0], corner_points[2][1],
             corner_points[3][0], corner_points[3][1], 1, 1, 1.0, 1, mesh_name,
             mesh_name + boundary_names[0], mesh_name + boundary_names[1],
             mesh_name + boundary_names[2], mesh_name + boundary_names[3]))

        self.code.parse_string(mesh_code)
        self.code.execute(1)
        smesh, _, boundaries = self.pool.export_mesh('simmesh', mesh_name,
                                                     boundary_names)
        nummesh = NumerrinMesh(mesh_name, smesh, self.pool)
        uidmap = nummesh._uuidToNumLabel
        boundary_faces = {}
        for boundary in boundaries:
            boundary_faces[boundary] = []
            for fuid in boundaries[boundary]:
                boundary_faces[boundary].append(uidmap[fuid])
        nummesh.pool.add_boundaries(mesh_name, boundaries, boundary_faces)
        nummesh._boundaries = boundaries

        for key in SP:
            self.pool.put_variable(numname[key], SP[key])

        nummesh.init_point_variables(get_numerrin_solver(CMExt))

        codestring = self.code.generate_init_code(CM, SP, SPExt, BC, CMExt)
        codestring += self.code.generate_code(CM, SP, SPExt, BC, CMExt,
                                              nummesh)

        self.code.parse_string(codestring)

        self.assertEqual(self.pool.variable_type(mesh_name), "Mesh")
        self.assertEqual(self.pool.variable_type(numname[CUBA.TIME_STEP]),
                         "Integer")
        self.assertEqual(self.pool.variable_type(numname[CUBA.DENSITY]),
                         "Real")
コード例 #20
0
class NumerrinCodeTestCase(unittest.TestCase):
    """Test case for NumerrinCode class"""
    def setUp(self):
        numerrin.initlocal("", "PYNUMERRIN_LICENSE", liccode)
        self.pool = NumerrinPool()
        self.code = NumerrinCode(self.pool.ph)
        self.codestring = "a = 10.0\n"
        self.errorcodestring = "a = 10/b\n"
        self.exceptionstring = "Exception(\"Exception\")\n"

    def test_parse_file(self):
        """Test parse_file method

        """
        codefile = 'test.num'
        with open(codefile, 'w') as f:
            f.write(self.codestring)
        self.code.parse_file(codefile)
        os.remove(codefile)

    def test_parse_string(self):
        """Test parse_string method

        """
        self.code.parse_string(self.codestring)
        with self.assertRaises(RuntimeError):
            self.code.parse_string(self.errorcodestring)

    def test_execute(self):
        """Test execute method

        """
        self.code.parse_string(self.codestring)
        self.code.execute(1)

    def test_clear(self):
        """Test clear method

        """

        self.code.parse_string(self.exceptionstring)
        with self.assertRaises(RuntimeError):
            self.code.execute(1)
        self.code.clear()
        self.code.execute(1)

    def test_generate_code(self):
        """Test generate_init_code and generate_code method

        """
        CM = DataContainer()
        SP = DataContainer()
        SPExt = DataContainer()
        BC = DataContainer()
        CMExt = {}
        mesh_name = "Mesh"
        CM[CUBA.NAME] = mesh_name
        CMExt[CUBAExt.GE] = (CUBAExt.INCOMPRESSIBLE,
                             CUBAExt.LAMINAR_MODEL)
        SP[CUBA.TIME_STEP] = 1
        SP[CUBA.NUMBER_OF_TIME_STEPS] = 2
        SP[CUBA.DENSITY] = 1.0
        SP[CUBA.DYNAMIC_VISCOSITY] = 1.0
        BC[CUBA.VELOCITY] = {'boundary0': ('fixedValue', (0.1, 0, 0))}
        BC[CUBA.PRESSURE] = {'boundary0': 'zeroGradient'}

        boundary_names = ['boundary0', 'boundary1', 'boundary2', 'boundary3']

        corner_points = ((0.0, 0.0), (20.0e-3, 0.0), (20.0e-3, 1.0e-3),
                         (0.0, 1.0e-3))
        mesh_code = textwrap.dedent("""
            pts={%f,%f;%f,%f;%f,%f;%f,%f}
            Quadmesh(pts,{%i,%i},{0,0,0,0},{1.0,1.0,-1.0,-1.0},mesh2d,domains2d)
            dvec[0:1]=0.0
            dvec[2]=%f
            Extrude(mesh2d,domains2d,dvec,%i,0,0.0,%s,domains)
            omega->domains[0]
            %s->domains[6]
            %s->domains[4]
            %s=Union(domains[3],domains[5])
            %s=Union(domains[1],domains[2])
            """ % (corner_points[0][0], corner_points[0][1],
                   corner_points[1][0], corner_points[1][1],
                   corner_points[2][0], corner_points[2][1],
                   corner_points[3][0], corner_points[3][1],
                   1, 1, 1.0, 1, mesh_name, mesh_name+boundary_names[0],
                   mesh_name+boundary_names[1],  mesh_name+boundary_names[2],
                   mesh_name+boundary_names[3]))

        self.code.parse_string(mesh_code)
        self.code.execute(1)
        smesh, _, boundaries = self.pool.export_mesh('simmesh', mesh_name,
                                                     boundary_names)
        nummesh = NumerrinMesh(mesh_name, smesh, self.pool)
        uidmap = nummesh._uuidToNumLabel
        boundary_faces = {}
        for boundary in boundaries:
            boundary_faces[boundary] = []
            for fuid in boundaries[boundary]:
                boundary_faces[boundary].append(uidmap[fuid])
        nummesh.pool.add_boundaries(mesh_name, boundaries,
                                    boundary_faces)
        nummesh._boundaries = boundaries

        for key in SP:
            self.pool.put_variable(numname[key], SP[key])

        nummesh.init_point_variables(get_numerrin_solver(CMExt))

        codestring = self.code.generate_init_code(CM, SP, SPExt, BC, CMExt)
        codestring += self.code.generate_code(CM, SP, SPExt, BC, CMExt,
                                              nummesh)

        self.code.parse_string(codestring)

        self.assertEqual(self.pool.variable_type(mesh_name), "Mesh")
        self.assertEqual(self.pool.variable_type(numname[CUBA.TIME_STEP]),
                         "Integer")
        self.assertEqual(self.pool.variable_type(numname[CUBA.DENSITY]),
                         "Real")
コード例 #21
0
    def setUp(self):
        self.mesh = Mesh(name="mesh1")
        numerrin.initlocal("", "PYNUMERRIN_LICENSE", liccode)
        self.pool = NumerrinPool()
        self.points = [
            Point((0.0, 0.0, 0.0),
                  data=DataContainer({
                      CUBA.VELOCITY: (1, 0, 0),
                      CUBA.PRESSURE: 4.0
                  })),
            Point((1.0, 0.0, 0.0),
                  data=DataContainer({
                      CUBA.VELOCITY: (1, 0, 0),
                      CUBA.PRESSURE: 4.0
                  })),
            Point((1.0, 1.0, 0.0),
                  data=DataContainer({
                      CUBA.VELOCITY: (1, 0, 0),
                      CUBA.PRESSURE: 4.0
                  })),
            Point((0.0, 1.0, 0.0),
                  data=DataContainer({
                      CUBA.VELOCITY: (1, 0, 0),
                      CUBA.PRESSURE: 4.0
                  })),
            Point((0.0, 0.0, 1.0),
                  data=DataContainer({
                      CUBA.VELOCITY: (1, 0, 0),
                      CUBA.PRESSURE: 4.0
                  })),
            Point((1.0, 0.0, 1.0),
                  data=DataContainer({
                      CUBA.VELOCITY: (1, 0, 0),
                      CUBA.PRESSURE: 4.0
                  })),
            Point((1.0, 1.0, 1.0),
                  data=DataContainer({
                      CUBA.VELOCITY: (1, 0, 0),
                      CUBA.PRESSURE: 4.0
                  })),
            Point((0.0, 1.0, 1.0),
                  data=DataContainer({
                      CUBA.VELOCITY: (1, 0, 0),
                      CUBA.PRESSURE: 4.0
                  }))
        ]

        puids = self.mesh.add_points(self.points)
        self.puids = puids

        self.faces = [
            Face([puids[0], puids[3], puids[7], puids[4]]),
            Face([puids[1], puids[2], puids[6], puids[5]]),
            Face([puids[0], puids[1], puids[5], puids[4]]),
            Face([puids[3], puids[2], puids[6], puids[7]]),
            Face([puids[0], puids[1], puids[2], puids[3]]),
            Face([puids[4], puids[5], puids[6], puids[7]])
        ]

        self.mesh.add_faces(self.faces)

        self.cells = [Cell(puids)]

        self.puids = puids

        self.mesh.add_cells(self.cells)