예제 #1
0
파일: test_gem.py 프로젝트: naylor-b/pygem
    def test_StaticModel(self):
        myContext = gem.initialize()
        gem.setAttribute(myContext, "CONTEXT", 0, "Modeler", "OpenCASCADE")
        myModel = gem.loadModel(myContext, sample_file)

        server, filename, modeler, uptodate, myBReps, nparam, nbranch, nattr = gem.getModel(myModel)

        newModel = gem.staticModel(myContext)
        gem.add2Model(newModel, myBReps[0])
        gem.add2Model(newModel, myBReps[0], (0.5, 0, 0, 2, 0, 0.5, 0, 0, 0, 0, 0.5, 0))

        server, filename, modeler, uptodate, myBReps, nparam, nbranch, nattr = gem.getModel(newModel)

        massProps1 = gem.getMassProps(myBReps[0], "BREP", 0)
        massProps2 = gem.getMassProps(myBReps[1], "BREP", 0)

        self.assertAlmostEqual(massProps1[0], 8 * massProps2[0])  # volume
        self.assertAlmostEqual(massProps1[1], 4 * massProps2[1])  # surface area
        self.assertAlmostEqual(massProps1[2], 2 * massProps2[2] - 4)  # xcg
        self.assertAlmostEqual(massProps1[3], 2 * massProps2[3])  # ycg
        self.assertAlmostEqual(massProps1[4], 2 * massProps2[4])  # zcg
        self.assertAlmostEqual(massProps1[5], 32 * massProps2[5])  # Ixx
        self.assertAlmostEqual(massProps1[6], 32 * massProps2[6])  # Ixy
        self.assertAlmostEqual(massProps1[7], 32 * massProps2[7])  # Ixz
        self.assertAlmostEqual(massProps1[8], 32 * massProps2[8])  # Iyx
        self.assertAlmostEqual(massProps1[9], 32 * massProps2[9])  # Iyy
        self.assertAlmostEqual(massProps1[10], 32 * massProps2[10])  # Iyz
        self.assertAlmostEqual(massProps1[11], 32 * massProps2[11])  # Izx
        self.assertAlmostEqual(massProps1[12], 32 * massProps2[12])  # Izy
        self.assertAlmostEqual(massProps1[13], 32 * massProps2[13])  # Izz

        gem.releaseModel(newModel)
        gem.releaseModel(myModel)
        gem.terminate(myContext)
예제 #2
0
파일: test_gem.py 프로젝트: naylor-b/pygem
    def test_BRep(self):
        myContext = gem.initialize()
        gem.setAttribute(myContext, "CONTEXT", 0, "Modeler", "OpenCASCADE")
        myModel = gem.loadModel(myContext, sample_file)

        server, filename, modeler, uptodate, myBReps, nparam, nbranch, nattr = gem.getModel(myModel)
        self.assertEqual(nattr, 0)

        for myBRep in myBReps:
            box, type, nnode, nedge, nloop, nface, nshell, nattr = gem.getBRepInfo(myBRep)

            # check that all nodes are in box
            for inode in range(1, nnode + 1):
                xyz, nattr = gem.getNode(myBRep, inode)
                self.assertEqual(nattr, 0)

                self.assertTrue(xyz[0] >= box[0], "x[%d] < box[0]" % inode)
                self.assertTrue(xyz[1] >= box[1], "y[%d] < box[1]" % inode)
                self.assertTrue(xyz[2] >= box[2], "z[%d] < box[2]" % inode)
                self.assertTrue(xyz[0] <= box[3], "x[%d] > box[3]" % inode)
                self.assertTrue(xyz[1] <= box[4], "y[%d] > box[4]" % inode)
                self.assertTrue(xyz[2] <= box[5], "z[%d] > box[5]" % inode)

            # check consistency of all loops
            for iloop in range(1, nloop + 1):
                iface, type, edges, nattr = gem.getLoop(myBRep, iloop)
                self.assertEqual(nattr, 0, "iloop=%d" % iloop)

                # loop and face point to each other
                ID, uvbox, norm, loops, nattr = gem.getFace(myBRep, iface)
                self.assertTrue(iloop in loops, "iloop=%d, iface=%d" % (iloop, iface))

                # edge and face point to each other
                for i in range(len(edges)):
                    tlimit, nodes, faces, nattr = gem.getEdge(myBRep, edges[i])
                    self.assertTrue(iface in faces, "iloop-%d, i=%d" % (iloop, i))

                # edges link end-to-end in loop
                tlimit, nodes, faces, nattr = gem.getEdge(myBRep, edges[0])
                iend = nodes[1]

                for i in range(1, len(edges)):
                    tlimit, nodes, faces, nattr = gem.getEdge(myBRep, edges[i])
                    self.assertEqual(iend, nodes[0], "iloop=%d, i=%d" % (iloop, i))
                    iend = nodes[1]

            # check consistency of all shells
            for ishell in range(1, nshell + 1):
                type, faces, nattr = gem.getShell(myBRep, ishell)
                self.assertEqual(nattr, 0)

        gem.releaseModel(myModel)
        gem.terminate(myContext)
예제 #3
0
파일: test_gem.py 프로젝트: naylor-b/pygem
    def test_DRep(self):
        myContext = gem.initialize()
        gem.setAttribute(myContext, "CONTEXT", 0, "Modeler", "OpenCASCADE")
        myModel = gem.loadModel(myContext, sample_file)
        myDRep = gem.newDRep(myModel)
        gem.tesselDRep(myDRep, 0, 0, 0, 0)

        iface = 1
        triArray, xyzArray = gem.getTessel(myDRep, 1, 1)

        npnt = (xyzArray.shape)[0]
        ntri = (triArray.shape)[0]

        # make sure that triangle pointers are consistent
        for itri in range(1, ntri + 1):
            for iside in [0, 1, 2]:
                jtri = triArray[itri - 1, iside]
                if not ((jtri > 0) and (jtri <= npnt)):
                    self.fail("jtri not in (0 to %d)" % npnt)

        gem.destroyDRep(myDRep)
        gem.releaseModel(myModel)
        gem.terminate(myContext)
예제 #4
0
파일: test_gem.py 프로젝트: naylor-b/pygem
    def test_LoadModel(self):
        myContext = gem.initialize()
        gem.setAttribute(myContext, "CONTEXT", 0, "Modeler", "OpenCASCADE")
        myModel = gem.loadModel(myContext, sample_file)

        gem.setAttribute(myModel, "MODEL", 0, "s_attr", "model attribute")
        gem.setAttribute(myModel, "MODEL", 0, "i_attrs", (2222222, 3333333, 4444444, 5555555))
        gem.setAttribute(myModel, "MODEL", 0, "r_attrs", (0.2345678901234567, 0.3456789012345678))

        copyModel = gem.copyModel(myModel)
        gem.releaseModel(myModel)

        server, filename, modeler, uptodate, myBReps, nparam, nbranch, nattr = gem.getModel(copyModel)
        self.assertEqual(filename, sample_file)
        self.assertEqual(modeler, "OpenCASCADE")
        self.assertEqual(uptodate, -1)
        self.assertEqual(nattr, 3)

        aname, values = gem.getAttribute(copyModel, "MODEL", 0, 1)
        self.assertEqual(aname, "s_attr")
        self.assertEqual(values, "model attribute")

        aname, values = gem.getAttribute(copyModel, "MODEL", 0, 2)
        self.assertEqual(aname, "i_attrs")
        self.assertEqual(values[0], 2222222)
        self.assertEqual(values[1], 3333333)
        self.assertEqual(values[2], 4444444)
        self.assertEqual(values[3], 5555555)

        aname, values = gem.getAttribute(copyModel, "MODEL", 0, 3)
        self.assertEqual(aname, "r_attrs")
        self.assertEqual(values[0], 0.2345678901234567)
        self.assertEqual(values[1], 0.3456789012345678)

        gem.releaseModel(copyModel)
        gem.terminate(myContext)
예제 #5
0
foo    = gem.retAttribute(myContext, "CONTEXT", 0, "s_attr")
aindex = foo[0]                                   ;print ".  aindex      ->", aindex
values = foo[1]                                   ;print ".  values      ->", values

ydum    = 0                                        ;print "i_attrs(myContext)"
foo    = gem.retAttribute(myContext, "CONTEXT", 0, "i_attrs")
aindex = foo[0]                                   ;print ".  aindex      ->", aindex
values = foo[1]                                   ;print ".  values      ->", values

dum    = 0                                        ;print "r_attrs(myContext)"
foo    = gem.retAttribute(myContext, "CONTEXT", 0, "r_attrs")
aindex = foo[0]                                   ;print ".  aindex      ->", aindex
values = foo[1]                                   ;print ".  values      ->", values

# load the sample OpenCSM Model
myModel = gem.loadModel(myContext, 
                        os.path.join(os.path.dirname(__file__),"sample.csm"))
print "myModel        ->", myModel

gem.setAttribute(myModel, "MODEL",  0, "s_attr", "model attribute")
gem.setAttribute(myModel, "MODEL",  0, "i_attrs", (2222222, 3333333, 4444444, 5555555))
gem.setAttribute(myModel, "MODEL",  0, "r_attrs", (0.2345678901234567, 0.3456789012345678))
gem.setAttribute(myModel, "BRANCH", 2, "s_attr", "branch attribute")
gem.setAttribute(myModel, "PARAM",  1, "s_attr", "param attribute")
gem.setAttribute(myModel, "PARAM",  1, "i_attrs", (3333333, 4444444, 5555555, 6666666))
gem.setAttribute(myModel, "PARAM",  1, "r_attrs", (0.3456789012345678, 0.4567890123456789))

# get information about the Model
foo      = gem.getModel(myModel)

server   = foo[0]                                 ;print "server         ->", server
filename = foo[1]                                 ;print "filename       ->", filename
예제 #6
0
# this is a simple python file that demonstrates optimization using the "gem" module

import numpy
from pygem_quartz import gem

# allow printing of entire arrays
numpy.set_printoptions(threshold=100)

# initialize the context, load the model, and get the first BRep
myContext = gem.initialize()
myModel   = gem.loadModel(myContext, "sample.csm")
foo       = gem.getModel(myModel)
myBRep    = foo[4][0]

# plot initial configuration
print "plotting initial configuration..."
myDRep = gem.newDRep(myModel)
gem.tesselDRep(myDRep, 0, 0, 0, 0)
gem.plotDRep(myDRep);
gem.destroyDRep(myDRep)

# "optimization" loop to vary "ymax" to drive the "volume" to a specified value
volume_target = 15
dvoldymax     =  8

for iter in range(100):
    print "---------------------"
    print "iter  =", iter

    # get current design variable
    foo  = gem.getParam(myModel, 4)