Пример #1
0
    def initialize_ship_parameters_and_values(self):  #, rgp=None):
        #if rgp is None:
        #    rgp = self.rgp
        #-----------------------------------------
        # quantities of m**1
        self.ship_beam = lp.PStates(name='ship_beam')
        # note: could use bare_hull var names instead.
        #       e.g. lp.PStates(name=self.init_ship_beam.name)
        self.ship_depth = lp.PStates(name='ship_depth')
        self.ship_Lpp = lp.PStates(name='ship_Lpp')
        #
        #quantities of m**2
        self.ship_Amshp = lp.PStates(name='ship_Amshp')
        self.ship_Acp = lp.PStates(name='ship_Acp')
        self.ship_Awp = lp.PStates(name='ship_Awp')
        #
        #quantities of m**3
        self.ship_Vol = lp.PStates(name='ship_Vol')
        #-----------------------------------------
        #
        #existing ship:
        #-----------------------------------------
        # set the ship values in the bulb environement:
        self.ship_beam = self.ship_beam == self.get_value(self.init_ship_beam)
        self.ship_depth = self.ship_depth == self.get_value(
            self.init_ship_depth)
        self.ship_Lpp = self.ship_Lpp == self.get_value(self.init_ship_Lpp)
        self.ship_Amshp = self.ship_Amshp == self.get_value(
            self.init_ship_Amshp)
        self.ship_Acp = self.ship_Acp == self.get_value(self.init_ship_Acp)
        self.ship_Awp = self.ship_Awp == self.get_value(self.init_ship_Awp)
        self.ship_Vol = self.ship_Vol == self.get_value(self.init_ship_Vol)
        #-----------------------------------------

        #-----------------------------------------
        self.rgp.add_one_rule(self.ship_beam, self.ship_beam.name)
        self.rgp.add_one_rule(self.ship_depth, self.ship_depth.name)
        self.rgp.add_one_rule(self.ship_Lpp, self.ship_Lpp.name)
        self.rgp.add_one_rule(self.ship_Amshp, self.ship_Amshp.name)
        self.rgp.add_one_rule(self.ship_Acp, self.ship_Acp.name)
        self.rgp.add_one_rule(self.ship_Awp, self.ship_Awp.name)
        self.rgp.add_one_rule(self.ship_Vol, self.ship_Vol.name)
        #-----------------------------------------
        self.rgp.compute_fresh_rules_graph()
        return  #rgp
Пример #2
0
 def coupling_constants(self, rgp=None):
     if rgp is None:
         rgp = self.rgp
     #
     #linear
     #-----------------------------------------
     self.Cbb = lp.PStates(name='Cbb')
     self.Clpr = lp.PStates(name='Clpr')
     self.Czb = lp.PStates(name='Czb')
     #
     #nonlinear
     #-----------------------------------------
     self.Cabt = lp.PStates(name='Cabt')
     self.Cabl = lp.PStates(name='Cabl')
     self.Cvpr = lp.PStates(name='Cvpr')
     #
     return rgp
#             #            self.arc_sets[c] = set([])
#             #            self.get_arc_sets()
#             #            self.var_sets[c] = set([])
#             count += 1
#             print count
#
#         return
#
#==============================================================================

if __name__ == "__main__":
    print '\n\n\n Do Not Use\n\n\n'
    print 'BulbRules2 '
    print 'testing '

    A_BT = lp.PStates(name='A_BT')
    A_BL = lp.PStates(name='A_BL')
    Bb = lp.PStates(name='Bb')
    c = lp.PStates(name='c')
    d = lp.PStates(name='d')

    C_BB = lp.PStates(name='C_BB')
    A_Bb = lp.PStates(name='A_Bb')

    A_Bmid = lp.PStates(name='A_Bmid')
    A_Llateral = lp.PStates(name='A_Llateral')
    A_Lflat = lp.PStates(name='A_Lflat')

    A_mid = lp.PStates(name='A_mid')
    A_lateral = lp.PStates(name='A_lateral')
    A_flat = lp.PStates(name='A_flat')
@author: luke
"""

import copy
import sqKanren as lp
import sobol
ia = lp.ia
#
#from extended_interval_arithmetic import ia
#use import from lp instead to match isinstance

GraphScaleNode = lp.GraphScaleNode
RulesGraphProcessor = lp.RulesGraphProcessor

if __name__ == """__main__""":
    A_mid = lp.PStates(name='A_mid')
    A_lateral = lp.PStates(name='A_lateral')

    #use the principle of the minimum square enclosing box (cartesian b/c ia is cartesian)
    BulbBeam = lp.PStates(name='BulbBeam')  #Bulb half beam
    BulbDepth = lp.PStates(name='BulbDepth')  #Bulb depth
    BulbLength = lp.PStates(
        name='BulbLength')  #Bulb max length (min square enclosing box length)

    BulbVolume = lp.PStates(name='BulbVolume')

    CBulbMid = lp.PStates(name='CBulbMid')  #Bulb midsection coefficient

    CBulbBlock = lp.PStates(name='CBulbBlock')
    CBulbPrismatic = lp.PStates(name='CBulbPrismatic')
Пример #5
0
    *******************************************
    *******************************************
    Done with Checkers
'''

if __name__ == """__main__""":

    start = True
    after_ship = True
    check_interval_splitting = True
    start_ship_to_bulb = True
    final_test = True

    if start:

        A_mid = lp.PStates(name='A_mid')
        A_lateral = lp.PStates(name='A_lateral')

        #use the principle of the minimum square enclosing box (cartesian b/c ia is cartesian)
        BulbBeam = lp.PStates(name='BulbBeam')  #Bulb half beam
        BulbDepth = lp.PStates(name='BulbDepth')  #Bulb depth
        BulbLength = lp.PStates(
            name='BulbLength'
        )  #Bulb max length (min square enclosing box length)

        BulbVolume = lp.PStates(name='BulbVolume')

        CBulbMid = lp.PStates(name='CBulbMid')  #Bulb midsection coefficient

        CBulbBlock = lp.PStates(name='CBulbBlock')
        CBulbPrismatic = lp.PStates(name='CBulbPrismatic')
def old_test():
    print 'Kraft Bulbous Bow Parameters'
    print '\n Linear Parameters:'

    A_BT = lp.PStates(name='A_BT')  #cross section area at fwd pp
    A_BL = lp.PStates(name='A_BL')  #area in longitudinal plane
    Bb = lp.PStates(name='Bb')
    #c = lp.PStates(name='c')
    #d = lp.PStates(name='d')

    C_BB = lp.PStates(name='C_BB')  #breadth parameter
    A_Bb = lp.PStates(name='A_Bb')  #

    A_Bmid = lp.PStates(name='A_Bmid')
    A_Llateral = lp.PStates(name='A_Llateral')
    A_Lflat = lp.PStates(name='A_Lflat')

    A_mid = lp.PStates(name='A_mid')
    A_lateral = lp.PStates(name='A_lateral')
    A_flat = lp.PStates(name='A_flat')
    A_BBwl = lp.PStates(name='A_BBwl')

    #use the principle of the minimum square enclosing box (cartesian b/c ia is cartesian)
    BulbBeam = lp.PStates(name='BulbBeam')  #Bulb half beam
    BulbDepth = lp.PStates(name='BulbDepth')  #Bulb depth
    BulbLength = lp.PStates(
        name='BulbLength')  #Bulb max length (min square enclosing box length)

    CBulbMid = lp.PStates(name='CBulbMid')  #Bulb midsection coefficient
    CBulbCtrPln = lp.PStates(
        name='CBulbCtrPln')  #Bulb centerplane profile area coefficient
    CBulbWtrPln = lp.PStates(
        name='CBulbWtrPln')  #Bulb waterplane area coefficient

    #TODO: fix this with class to construct rules graph!

    A_mid = A_mid == ia(10., 20.)  #issue: order of assignment "matters"
    BulbBeam = BulbBeam == ia(5., 10.)
    CBulbMid = CBulbMid == ia(.5, 1.)
    CBulbWtrPln = CBulbWtrPln == ia(.5, 1.)
    #BulbDepth = BulbDepth == ia(-10.1,10.)

    bgp = RulesGraphProcessor()
    #"""

    #bgp.add_one_rule(BulbDepth,'BulbDepth')
    bgp.add_one_rule(A_mid, 'A_mid')
    bgp.add_one_rule(BulbBeam, 'BulbBeam')
    bgp.add_one_rule(CBulbMid, 'CBulbMid')
    bgp.add_one_rule(CBulbWtrPln, 'CBulbWtrPln')
    bgp.compute_rules_graph()
    #bgp.add_one_rule(BulbDepth,'BulbDepth') #should not be needed!

    bgp.compute_rules_graph()
    #bgp.AC_revise()
    #bgp.env
    """-----------------------------------------------
    Rule:  Midbulb_Area < max_Beam * max_Depth
    CBulbMid -> [0.,1.]
    CBulbMid ==  A_mid/(BulbBeam*BulbDepth)
    """
    CBulbMid = CBulbMid == A_mid / (BulbBeam * BulbDepth)
    """-----------------------------------------------
    Rule: z-y_area < max_length * max_Depth
    """
    CBulbCtrPln = CBulbCtrPln == A_lateral / (BulbLength * BulbDepth)
    """-----------------------------------------------
    Rule: wL_area < max_length * max_Depth
    """
    #CBulbWtrPln = CBulbWtrPln == A_BBwl/(BulbLength*BulbDepth)
    CBulbWtrPln = CBulbWtrPln == A_BBwl / (BulbLength * BulbBeam)

    bgp.add_one_rule(CBulbMid, 'CBulbMid')
    bgp.add_one_rule(CBulbCtrPln, 'CBulbCtrPln')
    bgp.add_one_rule(CBulbWtrPln, 'CBulbWtrPln')

    bgp.compute_rules_graph()
    #"""

    BulbLength = BulbLength == ia(10., 15.)
    CBulbCtrPln = CBulbCtrPln == ia(.5, 1.)
    bgp.add_one_rule(BulbLength, 'BulbLength')
    bgp.add_one_rule(CBulbCtrPln, 'CBulbCtrPln')

    bgp.compute_rules_graph()

    BulbDepth = BulbDepth == ia(5., 10.)
    bgp.add_one_rule(BulbDepth, 'BulbDepth')
    bgp.compute_rules_graph()

    print '\n\n state after:'
    #print st

    print bgp.env
    return
def setup_dummy_bare_hull(bbobj, rgp=None):
    if rgp is None:
        rgp = bbobj.rgp
    #-----------------------------------------
    # quantities of m**1
    bbobj.ship_beam = lp.PStates(name='ship_beam')
    # note: could use bare_hull var names instead.
    #       e.g. lp.PStates(name=self.init_ship_beam.name)
    bbobj.ship_depth = lp.PStates(name='ship_depth')
    bbobj.ship_Lpp = lp.PStates(name='ship_Lpp')
    #
    #quantities of m**2
    bbobj.ship_Amshp = lp.PStates(name='ship_Amshp')
    bbobj.ship_Acp = lp.PStates(name='ship_Acp')
    bbobj.ship_Awp = lp.PStates(name='ship_Awp')
    #
    #quantities of m**3
    bbobj.ship_Vol = lp.PStates(name='ship_Vol')
    #-----------------------------------------
    #
    #existing ship:
    #-----------------------------------------
    # quantities of m**1
    ship_beam = bbobj.ship_beam
    ship_depth = bbobj.ship_depth
    ship_Lpp = bbobj.ship_Lpp
    #
    #quantities of m**2
    ship_Amshp = bbobj.ship_Amshp
    ship_Acp = bbobj.ship_Acp
    ship_Awp = bbobj.ship_Awp
    #
    #quantities of m**3
    ship_Vol = bbobj.ship_Vol
    #-----------------------------------------
    #
    #-----------------------------------------
    # set the ship values in the bulb environement:
    ship_beam = ship_beam == ia(17.4663142374, 17.4663142374)

    ship_depth = ship_depth == ia(16.2051841085, 16.2051841085)

    ship_Lpp = ship_Lpp == ia(111.099919763, 111.099919763)

    ship_Amshp = ship_Amshp == ia(261.639572047, 261.639572047)

    ship_Acp = ship_Acp == ia(1656.36308186, 1656.36308186)

    ship_Awp = ship_Awp == ia(1736.75296874, 1736.75296874)

    ship_Vol = ship_Vol == ia(27043.7825521, 27043.7825521)
    #-----------------------------------------

    #-----------------------------------------
    rgp.add_one_rule(ship_beam, 'ship_beam')
    rgp.add_one_rule(ship_depth, 'ship_depth')
    rgp.add_one_rule(ship_Lpp, 'ship_Lpp')
    rgp.add_one_rule(ship_Amshp, 'ship_Amshp')
    rgp.add_one_rule(ship_Acp, 'ship_Acp')
    rgp.add_one_rule(ship_Awp, 'ship_Awp')
    rgp.add_one_rule(ship_Vol, 'ship_Vol')
    #-----------------------------------------
    rgp.compute_rules_graph()
    return bbobj, rgp
    def DOIT(self, rgp=None):
        if rgp is None:
            rgp = self.rgp
        #
        #linear
        #-----------------------------------------
        self.Cbb = lp.PStates(name='Cbb')
        self.Clpr = lp.PStates(name='Clpr')
        self.Czb = lp.PStates(name='Czb')
        #
        #nonlinear
        #-----------------------------------------
        self.Cabt = lp.PStates(name='Cabt')
        self.Cabl = lp.PStates(name='Cabl')
        self.Cvpr = lp.PStates(name='Cvpr')

        #
        #--------------------
        # quantities of m**1
        self.ship_beam = lp.PStates(name='ship_beam')
        # note: could use bare_hull var names instead.
        #       e.g. lp.PStates(name=self.init_ship_beam.name)
        self.ship_depth = lp.PStates(name='ship_depth')
        self.ship_Lpp = lp.PStates(name='ship_Lpp')
        #
        #quantities of m**2
        self.ship_Amshp = lp.PStates(name='ship_Amshp')
        self.ship_Acp = lp.PStates(name='ship_Acp')
        self.ship_Awp = lp.PStates(name='ship_Awp')
        #
        #quantities of m**3
        self.ship_Vol = lp.PStates(name='ship_Vol')
        #-----------------------------------------
        #
        #existing ship:
        #-----------------------------------------
        # quantities of m**1
        ship_beam = self.ship_beam
        ship_depth = self.ship_depth
        ship_Lpp = self.ship_Lpp
        #
        #quantities of m**2
        ship_Amshp = self.ship_Amshp
        ship_Acp = self.ship_Acp
        ship_Awp = self.ship_Awp
        #
        #quantities of m**3
        ship_Vol = self.ship_Vol
        #-----------------------------------------
        #
        #-----------------------------------------
        # set the ship values in the bulb environement:
        self.ship_beam = self.ship_beam == self.get_value(self.init_ship_beam)
        self.ship_depth = self.ship_depth == self.get_value(
            self.init_ship_depth)
        self.ship_Lpp = self.ship_Lpp == self.get_value(self.init_ship_Lpp)
        self.ship_Amshp = self.ship_Amshp == self.get_value(
            self.init_ship_Amshp)
        self.ship_Acp = self.ship_Acp == self.get_value(self.init_ship_Acp)
        self.ship_Awp = self.ship_Awp == self.get_value(self.init_ship_Awp)
        self.ship_Vol = self.ship_Vol == self.get_value(self.init_ship_Vol)
        #-----------------------------------------

        #-----------------------------------------
        rgp.add_one_rule(self.ship_beam, 'ship_beam')
        rgp.add_one_rule(self.ship_depth, 'ship_depth')
        rgp.add_one_rule(self.ship_Lpp, 'ship_Lpp')
        rgp.add_one_rule(self.ship_Amshp, 'ship_Amshp')
        rgp.add_one_rule(self.ship_Acp, 'ship_Acp')
        rgp.add_one_rule(self.ship_Awp, 'ship_Awp')
        rgp.add_one_rule(self.ship_Vol, 'ship_Vol')
        #-----------------------------------------
        rgp.compute_rules_graph()

        #def initialize_bulb_parameters(self, rgp=None):

        #bulb areas
        self.A_mid = lp.PStates(name='A_mid')
        self.A_lateral = lp.PStates(name='A_lateral')
        self.A_flat = lp.PStates(name='A_flat')
        self.A_BBwl = lp.PStates(name='A_BBwl')

        #use the principle of the minimum square enclosing box (cartesian b/c ia is cartesian)
        self.BulbBeam = lp.PStates(name='BulbBeam')  #Bulb half beam
        self.BulbDepth = lp.PStates(name='BulbDepth')  #Bulb depth
        self.BulbLength = lp.PStates(
            name='BulbLength'
        )  #Bulb max length (min square enclosing box length)

        self.BulbVolume = lp.PStates(name='BulbVolume')

        self.CBulbMid = lp.PStates(
            name='CBulbMid')  #Bulb midsection coefficient
        self.CBulbCtrPln = lp.PStates(
            name='CBulbCtrPln')  #Bulb centerplane profile area coefficient
        self.CBulbWtrPln = lp.PStates(
            name='CBulbWtrPln')  #Bulb waterplane area coefficient

        self.CBulbBlock = lp.PStates(
            name='CBulbBlock')  #Bulb block coefficient
        self.CBulbPrismatic = lp.PStates(
            name='CBulbPrismatic')  #Bulb prismatic coefficient
        """-----------------------------------------------
        Rule:  Midbulb_Area < max_Beam * max_Depth
        CBulbMid -> [0.,1.]
        CBulbMid ==  A_mid/(BulbBeam*BulbDepth)
        """
        self.CBulbMid = self.CBulbMid == self.A_mid / (self.BulbBeam *
                                                       self.BulbDepth)
        #
        """-----------------------------------------------
        Rule: z-y_area < max_length * max_Depth
        """
        self.CBulbCtrPln = self.CBulbCtrPln == self.A_lateral / (
            self.BulbLength * self.BulbDepth)
        #
        """-----------------------------------------------
        Rule: wL_area < max_length * max half-Beam
        """
        self.CBulbWtrPln = self.CBulbWtrPln == self.A_BBwl / (self.BulbLength *
                                                              self.BulbBeam)
        #
        """-----------------------------------------------
        Rule: Bulb_vol < max_length * max_Depth * max *BulbBeam
        """
        self.CBulbBlock = self.CBulbBlock == self.BulbVolume / (
            self.BulbLength * self.BulbDepth * self.BulbBeam)
        #
        """-----------------------------------------------
        Rule: Bulb_vol < max_length * mid_bulb_area
        """
        self.CBulbPrismatic = self.CBulbPrismatic == self.BulbVolume / (
            self.BulbLength * self.A_mid)
        #
        rgp.add_one_rule(self.CBulbMid, 'CBulbMid')
        rgp.add_one_rule(self.CBulbCtrPln, 'CBulbCtrPln')
        rgp.add_one_rule(self.CBulbWtrPln, 'CBulbWtrPln')
        rgp.add_one_rule(self.CBulbBlock, 'CBulbBlock')
        rgp.add_one_rule(self.CBulbPrismatic, 'CBulbPrismatic')
        #
        rgp.compute_rules_graph()
        #

        #def linear_parameters(self, rgp=None):
        """Kracht Design of Bulbous Bows, 1978
        """

        #Kracht linear relations:
        self.Cbb = self.Cbb == self.BulbBeam / self.ship_beam
        self.Clpr = self.Clpr == self.BulbLength / self.ship_Lpp
        self.Czb = self.Czb == self.BulbLength / self.ship_depth
        #
        rgp.add_one_rule(self.Cbb, 'Cbb')
        rgp.add_one_rule(self.Clpr, 'Clpr')
        rgp.add_one_rule(self.Czb, 'Czb')
        #
        rgp.compute_rules_graph()
        #

        #def nonlinear_parameters(self, rgp=None):
        """Kracht Design of Bulbous Bows, 1978
        """

        #Kracht nonlinear relations:
        self.Cabt = self.Cabt == self.A_mid / self.ship_Amshp
        self.Cabl = self.Cabl == self.A_lateral / self.ship_Acp  #departure from Kracht
        self.Cvpr = self.Cvpr == self.BulbVolume / self.ship_Vol
        #
        self.rgp.add_one_rule(self.Cabt)
        self.rgp.add_one_rule(self.Cabl)
        self.rgp.add_one_rule(self.Cvpr)
        #
        rgp.compute_rules_graph()
        #

        #def experiment_bulb_parameters(self, rgp=None):

        self.A_mid = self.A_mid == ia(
            10., 15.)  #20.) #issue: order of assignment "matters"
        self.BulbBeam = self.BulbBeam == ia(5., 10.)
        self.CBulbMid = self.CBulbMid == ia(.5, 1.)
        self.CBulbWtrPln = self.CBulbWtrPln == ia(.5, 1.)
        #BulbDepth = BulbDepth == ia(-10.1,10.)

        #bgp.add_one_rule(BulbDepth,'BulbDepth')
        rgp.add_one_rule(self.A_mid, 'A_mid')
        rgp.add_one_rule(self.BulbBeam, 'BulbBeam')
        rgp.add_one_rule(self.CBulbMid, 'CBulbMid')
        rgp.add_one_rule(self.CBulbWtrPln, 'CBulbWtrPln')
        #self.bgp.add_one_rule(self.BulbDepth,'BulbDepth')

        self.BulbLength = self.BulbLength == ia(10., 15.)
        self.BulbDepth = self.BulbDepth == ia(5., 10.)
        self.CBulbCtrPln = self.CBulbCtrPln == ia(.5, 1.)
        rgp.add_one_rule(self.BulbLength, 'BulbLength')
        rgp.add_one_rule(self.BulbDepth, 'BulbDepth')
        rgp.add_one_rule(self.CBulbCtrPln, 'CBulbCtrPln')

        rgp.compute_rules_graph()

        return
    #print st

    print bgp.env
    return


if __name__ == "__main__":
    #old_test()
    #self = BulbGenerator()
    #self.rgp._verbose = True
    #print self.rgp.env

    #type(self.rgp.nodes[0].vars['ship_beam'])

    low_down_dirty_testing = False
    x1 = lp.PStates(name='x1')
    x2 = lp.PStates(name='x2')
    x3 = lp.PStates(name='x3')
    #x4 = lp.PStates(name='x4')

    x1 = x1 == ia(1., 10.)
    x2 = x2 == ia(1., 10.)
    x3 = x3 == ia(1., 10.)

    env = lp.States(lp.State())

    # add x1 rule to env
    env, vars_ = x1.construct(x1, env, {})
    fundict = x1.compile(x1, vars_)
    for el in fundict:
        env = fundict[el](env)
Пример #10
0
def older_test():
    print 'Kraft Bulbous Bow Parameters'
    print '\n Linear Parameters:'

    ##
    ##************************************* bulb
    ##
    A_mid = lp.PStates(name='A_mid')
    A_lateral = lp.PStates(name='A_lateral')
    #A_flat = lp.PStates(name='A_flat')  #BBwl instead
    A_BBwl = lp.PStates(name='A_BBwl')

    #use the principle of the minimum square enclosing box (cartesian b/c ia is cartesian)
    BulbBeam = lp.PStates(name='BulbBeam')  #Bulb half beam
    BulbDepth = lp.PStates(name='BulbDepth')  #Bulb depth
    BulbLength = lp.PStates(
        name='BulbLength')  #Bulb max length (min square enclosing box length)

    BulbVolume = lp.PStates(name='BulbVolume')

    CBulbMid = lp.PStates(name='CBulbMid')  #Bulb midsection coefficient
    CBulbCtrPln = lp.PStates(
        name='CBulbCtrPln')  #Bulb centerplane profile area coefficient
    CBulbWtrPln = lp.PStates(
        name='CBulbWtrPln')  #Bulb waterplane area coefficient

    CBulbBlock = lp.PStates(name='CBulbBlock')
    CBulbPrismatic = lp.PStates(name='CBulbPrismatic')

    #TODO: fix this with class to construct rules graph!

    A_mid = A_mid == ia(10., 20.)  #issue: order of assignment "matters"
    BulbBeam = BulbBeam == ia(5., 10.)
    CBulbMid = CBulbMid == ia(.5, 1.)
    CBulbWtrPln = CBulbWtrPln == ia(.5, 1.)
    #BulbDepth = BulbDepth == ia(-10.1,10.)

    rgp = RulesGraphProcessor()
    #"""

    #rgp.add_one_rule(BulbDepth,'BulbDepth')
    rgp.add_one_rule(A_mid, 'A_mid')
    rgp.add_one_rule(BulbBeam, 'BulbBeam')
    rgp.add_one_rule(CBulbMid, 'CBulbMid')
    rgp.add_one_rule(CBulbWtrPln, 'CBulbWtrPln')
    #rgp.add_one_rule(BulbDepth,'BulbDepth') #should not older_testbe needed!

    rgp.compute_fresh_rules_graph()
    #rgp.compute_rules_graph()

    #rgp.AC_revise()
    #rgp.env

    ##
    ##************************************* end bulb
    ##

    ##
    ##************************************* ship
    ##
    ship_beam = lp.PStates(name='ship_beam')
    # note: could use bare_hull var names instead.
    #       e.g. lp.PStates(name=self.init_ship_beam.name)
    ship_depth = lp.PStates(name='ship_depth')
    ship_Lpp = lp.PStates(name='ship_Lpp')
    #
    #quantities of m**2
    ship_Amshp = lp.PStates(name='ship_Amshp')
    ship_Acp = lp.PStates(name='ship_Acp')
    ship_Awp = lp.PStates(name='ship_Awp')
    #
    #quantities of m**3
    ship_Vol = lp.PStates(name='ship_Vol')

    #-----------------------------------------
    # set the ship values in the bulb environement:
    ship_beam = ship_beam == ia(17.4663142374, 17.4663142374)

    ship_depth = ship_depth == ia(16.2051841085, 16.2051841085)

    ship_Lpp = ship_Lpp == ia(111.099919763, 111.099919763)

    ship_Amshp = ship_Amshp == ia(261.639572047, 261.639572047)

    ship_Acp = ship_Acp == ia(1656.36308186, 1656.36308186)

    ship_Awp = ship_Awp == ia(1736.75296874, 1736.75296874)

    ship_Vol = ship_Vol == ia(27043.7825521, 27043.7825521)
    #-----------------------------------------

    #-----------------------------------------
    rgp.add_one_rule(ship_beam, 'ship_beam')
    rgp.add_one_rule(ship_depth, 'ship_depth')
    rgp.add_one_rule(ship_Lpp, 'ship_Lpp')
    rgp.add_one_rule(ship_Amshp, 'ship_Amshp')
    rgp.add_one_rule(ship_Acp, 'ship_Acp')
    rgp.add_one_rule(ship_Awp, 'ship_Awp')
    rgp.add_one_rule(ship_Vol, 'ship_Vol')
    #-----------------------------------------
    ##
    ##************************************* end ship
    ##
    rgp.compute_fresh_rules_graph()
    #rgp.compute_rules_graph()

    ##
    ##************************************* bulb rules
    ##
    """-----------------------------------------------
    Rule:  Midbulb_Area < max_Beam * max_Depth
    CBulbMid -> [0.,1.]
    CBulbMid ==  A_mid/(BulbBeam*BulbDepth)
    """
    CBulbMid = CBulbMid == A_mid / (BulbBeam * BulbDepth)
    """-----------------------------------------------
    Rule: z-y_area < max_length * max_Depth
    """
    CBulbCtrPln = CBulbCtrPln == A_lateral / (BulbLength * BulbDepth)
    """-----------------------------------------------
    Rule: wL_area < max_length * max_Depth
    """
    #CBulbWtrPln = CBulbWtrPln == A_BBwl/(BulbLength*BulbDepth)
    CBulbWtrPln = CBulbWtrPln == A_BBwl / (BulbLength * BulbBeam)

    #2 more rules!
    """-----------------------------------------------
    Rule: Bulb_vol < max_length * max_Depth * max *BulbBeam
    """
    CBulbBlock = CBulbBlock == BulbVolume / (BulbLength * BulbDepth * BulbBeam)
    #
    """-----------------------------------------------
    Rule: Bulb_vol < max_length * mid_bulb_area
    """
    CBulbPrismatic = CBulbPrismatic == BulbVolume / (BulbLength * A_mid)
    #

    rgp.add_one_rule(CBulbMid, 'CBulbMid')
    rgp.add_one_rule(CBulbCtrPln, 'CBulbCtrPln')
    rgp.add_one_rule(CBulbWtrPln, 'CBulbWtrPln')

    rgp.add_one_rule(CBulbBlock, 'CBulbBlock')
    rgp.add_one_rule(CBulbPrismatic, 'CBulbPrismatic')

    rgp.compute_fresh_rules_graph()
    #rgp.compute_rules_graph()
    #"""

    #BulbLength  = BulbLength == ia(10.,15.)
    BulbLength = BulbLength == ia(1., 15.)
    #CBulbCtrPln = CBulbCtrPln == ia(.5,1.)
    CBulbCtrPln = CBulbCtrPln == ia(0., 1.)
    rgp.add_one_rule(BulbLength, 'BulbLength')
    rgp.add_one_rule(CBulbCtrPln, 'CBulbCtrPln')

    rgp.compute_fresh_rules_graph()
    #rgp.compute_rules_graph()

    #BulbDepth = BulbDepth == ia(1.,10.)
    BulbDepth = BulbDepth == ia(5., 10.)
    rgp.add_one_rule(BulbDepth, 'BulbDepth')

    CBulbBlock = CBulbBlock == ia(0., 1.)
    CBulbPrismatic = CBulbPrismatic == ia(0., 1.)
    rgp.add_one_rule(BulbLength, 'CBulbBlock')
    rgp.add_one_rule(CBulbPrismatic, 'CBulbPrismatic')

    rgp.compute_fresh_rules_graph()
    #rgp.compute_rules_graph()

    ##
    ##************************************* end bulb rules
    ##

    ##
    ##************************************* Ship to Bulb Coefficients
    ##
    #
    #linear
    #-----------------------------------------
    Cbb = lp.PStates(name='Cbb')
    Clpr = lp.PStates(name='Clpr')
    Czb = lp.PStates(name='Czb')
    #
    #nonlinear
    #-----------------------------------------
    Cabt = lp.PStates(name='Cabt')
    Cabl = lp.PStates(name='Cabl')
    Cvpr = lp.PStates(name='Cvpr')
    #
    ##
    ##************************************* end Ship to Bulb Coefficients
    ##

    ##
    ##************************************* nonlinear relations
    ##
    #Kracht nonlinear relations:
    Cabt = Cabt == A_mid / ship_Amshp
    Cabl = Cabl == A_lateral / ship_Acp  #departure from Kracht
    Cvpr = Cvpr == BulbVolume / ship_Vol
    #
    """
    rgp.add_one_rule( Cbb, 'Cbb')
    rgp.add_one_rule(Clpr, 'Clpr')
    rgp.add_one_rule( Czb, 'Czb')
    #"""
    #
    rgp.compute_fresh_rules_graph()
    #rgp.compute_rules_graph()
    #
    ##
    ##************************************* end nonlinear relations
    ##

    ##
    ##************************************* linear relations
    ##
    #Kracht linear relations:
    Cbb = Cbb == BulbBeam / ship_beam
    Clpr = Clpr == BulbLength / ship_Lpp
    Czb = Czb == BulbLength / ship_depth
    #
    """
    rgp.add_one_rule( Cbb, 'Cbb')
    rgp.add_one_rule(Clpr, 'Clpr')
    rgp.add_one_rule( Czb, 'Czb')
    #"""
    #
    rgp.compute_fresh_rules_graph()
    #rgp.compute_rules_graph()
    #
    ##
    ##************************************* end linear relations
    ##

    print '\n\n state after:'
    #print st

    print rgp.env

    ellist = [
        BulbDepth,
        CBulbMid,
        CBulbBlock,
        BulbBeam,
        BulbLength,
        BulbVolume,
        #A_mid,
        #A_lateral,
        #A_BBwl,
        CBulbCtrPln,
        CBulbWtrPln,
        CBulbPrismatic
    ]

    sobol_seq = sobol.sobolSeq([1, 1], [1, 1])
    ith = -1
    #x=.5
    redo = []
    for i in range(len(ellist)):
        x = sobol_seq.next()
        var = ellist[i]
        mk_name, mk_val = rgp.get_name_and_value(var)
        print mk_name, mk_val
        val = mk_val[ith].getpoint(x)
        value = ia(val, val)
        var = var == value
        #-----------------------------------------
        ret_state = copy.copy(rgp.env)
        rgp.add_one_rule(var, var.name)
        rgp.compute_fresh_rules_graph()
        #rgp.compute_rules_graph()
        #-----------------------------------------

        if len(rgp.env.states) == 0:
            rgp.env = ret_state
            #rgp.env.states = ret_state.states
            redo.append(var)
        else:
            if rgp._verbose: print 'done ', mk_name, '=>', value

    def checker():
        print '\n CBulbMid'
        print gv(A_mid) / (gv(BulbBeam) * gv(BulbDepth))
        print gv(CBulbMid)

        print '\n CBulbCtrPln'
        print gv(A_lateral) / (gv(BulbLength) * gv(BulbDepth))
        print gv(CBulbCtrPln)

        print '\n CBulbWtrPln'
        print gv(A_BBwl) / (gv(BulbLength) * gv(BulbBeam))
        print gv(CBulbWtrPln)

        print '\n CBulbBlock'
        print gv(BulbVolume) / (gv(BulbLength) * gv(BulbBeam) * gv(BulbDepth))
        print gv(CBulbBlock)

        print '\n CBulbPrismatic'
        print gv(BulbVolume) / (gv(BulbLength) * gv(A_mid))
        print gv(CBulbPrismatic)
        return

    def gv(var):
        return rgp.get_name_and_value(var)[1][0]

    checker()
    return redo, rgp
Пример #11
0
def old_test():
    print 'Kraft Bulbous Bow Parameters'
    print '\n Linear Parameters:'

    A_mid = lp.PStates(name='A_mid')

    #use the principle of the minimum square enclosing box (cartesian b/c ia is cartesian)
    BulbBeam = lp.PStates(name='BulbBeam')  #Bulb half beam
    BulbDepth = lp.PStates(name='BulbDepth')  #Bulb depth

    CBulbMid = lp.PStates(name='CBulbMid')  #Bulb midsection coefficient

    #TODO: fix this with class to construct rules graph!

    A_mid = A_mid == ia(10., 20.)  #issue: order of assignment "matters"
    BulbBeam = BulbBeam == ia(5., 10.)
    CBulbMid = CBulbMid == ia(.5, 1.)

    rgp = RulesGraphProcessor()

    rgp.add_one_rule(A_mid, A_mid.name)
    rgp.add_one_rule(BulbBeam, BulbBeam.name)
    rgp.add_one_rule(CBulbMid, CBulbMid.name)

    rgp.compute_fresh_rules_graph()
    """-----------------------------------------------
    Rule:  Midbulb_Area < max_Beam * max_Depth
    CBulbMid -> [0.,1.]
    CBulbMid ==  A_mid/(BulbBeam*BulbDepth)
    """
    CBulbMid = CBulbMid == A_mid / (BulbBeam * BulbDepth)

    #rgp.add_one_rule(BulbDepth,BulbDepth.name)
    rgp.add_one_rule(CBulbMid, CBulbMid.name)

    rgp.compute_fresh_rules_graph()
    #"""

    #rgp.compute_fresh_rules_graph()

    #BulbDepth = BulbDepth == ia(5.,10.)
    #rgp.add_one_rule(BulbDepth,BulbDepth.name)
    #rgp.compute_fresh_rules_graph()

    print '\n\n state after:'
    #print st

    print rgp.env

    ellist = [BulbDepth, CBulbMid, BulbBeam, A_mid]

    ith = -1
    x = .5
    redo = []
    for i in range(len(ellist)):
        var = ellist[i]
        mk_name, mk_val = rgp.get_name_and_value(var)
        print mk_name, mk_val
        val = mk_val[ith].getpoint(x)
        value = ia(val, val)
        var = var == value
        #-----------------------------------------
        ret_state = copy.copy(rgp.env)
        rgp.add_one_rule(var, var.name)
        rgp.compute_fresh_rules_graph()
        #rgp.compute_rules_graph()
        #-----------------------------------------

        if len(rgp.env.states) == 0:
            rgp.env = ret_state
            redo.append(var)
        else:
            if rgp._verbose: print 'done ', mk_name, '=>', value

    return
Пример #12
0
    def initialize_bulb_parameters(self):  #, rgp=None):
        #if rgp is None:
        #    rgp = self.rgp

        #bulb areas
        self.A_mid = lp.PStates(name='A_mid')
        self.A_lateral = lp.PStates(name='A_lateral')
        #self.A_flat     = lp.PStates(name='A_flat') #A_BBwl instead
        self.A_BBwl = lp.PStates(name='A_BBwl')

        #use the principle of the minimum square enclosing box (cartesian b/c ia is cartesian)
        self.BulbBeam = lp.PStates(name='BulbBeam')  #Bulb half beam
        self.BulbDepth = lp.PStates(name='BulbDepth')  #Bulb depth
        self.BulbLength = lp.PStates(
            name='BulbLength'
        )  #Bulb max length (min square enclosing box length)

        self.BulbVolume = lp.PStates(name='BulbVolume')

        self.CBulbMid = lp.PStates(
            name='CBulbMid')  #Bulb midsection coefficient
        self.CBulbCtrPln = lp.PStates(
            name='CBulbCtrPln')  #Bulb centerplane profile area coefficient
        self.CBulbWtrPln = lp.PStates(
            name='CBulbWtrPln')  #Bulb waterplane area coefficient

        self.CBulbBlock = lp.PStates(
            name='CBulbBlock')  #Bulb block coefficient
        self.CBulbPrismatic = lp.PStates(
            name='CBulbPrismatic')  #Bulb prismatic coefficient

        return  #rgp
Пример #13
0
    #st.update({_:None})
    #st.bind(_)
    st.bind_if_not_extant(_)
    #st.states[0].update({_:None})
    #st.states[0] = st.states[0].bind('_')
    #smm = (st + ( ( _,'+',[x,y,_] ), z, a) )

    #    import inspect
    #
    #    def fi(st):
    #        spec = inspect.getargs(st)
    #        return spec,st
    #
    #    spec,sc = fi([y,ia(1.,2.)]), y, ia(2.,4.))

    ps = lp.PStates(name='ps')
    a = lp.PStates(name='a')
    b = lp.PStates(name='b')
    c = lp.PStates(name='c')
    d = lp.PStates(name='d')
    #ps1 = (ps == (a,b) ) #does not work this way anymore...
    ps1 = a == b

    #e =  ( ps + (a,b,c) )
    e = a + b + c
    e.name = 'e'

    f = a + b + c * d
    f.name = 'f'

    ps1 = (ps == (d, (ps + (a, b, c))))