Пример #1
0
    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
    for iattr in range(1, nattr+1):
        dum    = 0                                ;print ".  iattr       ->", iattr
        foo    = gem.getAttribute(myModel, "BRANCH", ibranch, iattr)
        aname  = foo[0]                           ;print ".  .  aname    ->", aname
        values = foo[1]                           ;print ".  .  values   ->", values

# get information about each of the BReps
for myBRep in myBReps:
    dum      = 0                                  ;print "myBRep         ->", myBRep
    foo      = gem.getBRepOwner(myBRep)
    model    = foo[0]                             ;print ".  model       ->", model
    instance = foo[1]                             ;print ".  instance    ->", instance
    branch   = foo[2]                             ;print ".  branch      ->", branch

    foo    = gem.getMassProps(myBRep, "BREP", 0)
    volume = foo[ 0]                              ;print ".  volume      ->", volume
    area   = foo[ 1]                              ;print ".  area        ->", area
    xcg    = foo[ 2]                              ;print ".  xcg         ->", xcg
    ycg    = foo[ 3]                              ;print ".  ycg         ->", ycg
    zcg    = foo[ 4]                              ;print ".  zcg         ->", zcg
    Ixx    = foo[ 5]                              ;print ".  Ixx         ->", Ixx
    Ixy    = foo[ 6]                              ;print ".  Ixy         ->", Ixy
    Ixz    = foo[ 7]                              ;print ".  Ixz         ->", Ixz
    Iyx    = foo[ 8]                              ;print ".  Iyx         ->", Iyx
    Iyy    = foo[ 9]                              ;print ".  Iyy         ->", Iyy
    Iyz    = foo[10]                              ;print ".  Iyz         ->", Iyz
    Izx    = foo[11]                              ;print ".  Izx         ->", Izx
    Izy    = foo[12]                              ;print ".  Izy         ->", Izy
    Izz    = foo[13]                              ;print ".  Izz         ->", Izz
Пример #3
0
volume_target = 15
dvoldymax     =  8

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

    # get current design variable
    foo  = gem.getParam(myModel, 4)
    ymax = foo[3][0]
    print "ymax  =", ymax

    # get the objective function
    foo    = gem.getModel(myModel)
    myBRep = foo[4][0]
    foo    = gem.getMassProps(myBRep, "BREP", 0)
    volume = foo[0]
    print "volume=", volume

    # if we have converged, stop the iterations
    if (abs(volume-volume_target) < 0.001):
        break

    # change the box height and regenerate the model
    ymax = ymax + (volume_target - volume) / dvoldymax
    print "ymax  =", ymax
    gem.setParam(myModel, 4, (ymax,))
    gem.regenModel(myModel)

# print and plot "final" configuration
print "*******************************"