示例#1
0
    def __init__(self, Lspline):
        self.Lspline = Lspline
        self.Lspline.Lagrangian = None
        self.FPD = FormParameterDict(self.Lspline.curve)
        self.verbose = True
        #self.fig = figure()
        self.fig, self.ax = plt.subplots()
        self.fig.subplots_adjust(left=0.3)
        prop = ItemProperties(labelcolor='black',
                              bgcolor='white',
                              fontsize=15,
                              alpha=0.2)
        hoverprop = ItemProperties(labelcolor='white',
                                   bgcolor='blue',
                                   fontsize=15,
                                   alpha=0.2)
        menuitems = []
        for label in ('tangent', 'curvature', 'area', 'Xc', 'Yc', 'clear',
                      'done'):

            def onselect(item):
                print('you selected %s' % item.labelstr)
                getattr(self, item.labelstr)()
                return

            item = MenuItem(self.fig,
                            label,
                            props=prop,
                            hoverprops=hoverprop,
                            on_select=onselect)
            menuitems.append(item)
        menu = Menu(self.fig, menuitems)
        plt.show(block=False)
        return
def init_lagrangian(curve, weight=1.):
    """
    """
    FPD = FormParameterDict(curve)
    #
    FPD.add_E1(kind='LS', weight=weight)
    FPD.add_E2(kind='LS', weight=weight)
    FPD.add_E3(kind='LS', weight=weight)
    FPD.add_ArcLengthApprox(kind='LS', weight=weight)
    return FPD
        sp = 1.e-4
        x = ini_v.vertices[:, 0]
        y = ini_v.vertices[:, 1]
        interval_data, small = interval_bounds(curve)

    if test == 'SAC_4':
        print test
        if True:
            print '\n\n\n\n CURVE 1'
            curve = initial_curve((0., 0.), (36., 0.), num=12, k=4, nump=30)
            v = copy.deepcopy(curve.vertices)
            v[4:7, 1] = 15.

            curve.vertices = v  #updates the curve automagically
            interval_data, small = interval_bounds(curve)
            FPD = FormParameterDict(curve)
            FPD.add_AreaConstraint(kind='equality', value=288.)
            FPD.add_XcConstraint(kind='equality', value=18.)
            FPD.add_AngleConstraint(kind='equality', location=0., value=0.)
            FPD.add_AngleConstraint(kind='equality', location=1., value=0.)
            FPD.add_yPointConstraint(kind='equality',
                                     location=0.3333333333,
                                     value=12.)
            FPD.add_yPointConstraint(kind='equality',
                                     location=0.6666666666,
                                     value=12.)
            FPD.add_E1(kind='LS', weight=.5)
            FPD.add_E2(kind='LS', weight=.5)
            FPD.add_E3(kind='LS', weight=.5)
            FPD.add_ArcLengthApprox(kind='LS', weight=.5)
            L = Lagrangian(FPD)
示例#4
0
 y_interest = 4.0
 yindex = 1
 yval0 = curve.FindPoint(y_interest,yindex)
 
 x_interest = 8.
 x_index = 0
 xval0 = curve.FindPoint(x_interest,x_index)
 
 
 
 #print pval[0]
 #print curve.CurvePoint(yval[0])
 #"""
 ccr = copy.deepcopy(curve)
 interval_data, small = interval_bounds(ccr)        
 FPD = FormParameterDict(ccr) 
 #"""
 """
 FPD.add_yPointConstraint(kind= 'max', value=4., location=.4 )
 FPD.add_xPointConstraint(kind= 'min', value=6., location=.45 )
 FPD.add_yPointConstraint(kind= 'LS', value=4., location=.4,weight=-100. )
 FPD.add_xPointConstraint(kind= 'LS', value=6., location=.45,weight=-100. )
 #"""
 FPD.add_yPointConstraint(kind= 'max', value=4., location=yval0[0] )
 FPD.add_xPointConstraint(kind= 'min', value=8., location=xval0[0] )
 #
 #FPD.add_yPointConstraint(kind= 'min', value=8., location=xval0[0] )#new and not needed
 #"""
 FPD.add_AreaConstraint(kind='equality',value=curve_area)
 FPD.add_AngleConstraint(kind='equality',location=0.,value=alphab)
 FPD.add_AngleConstraint(kind='equality',location=1.,value=alphae)
def setup_interpolation_solver(thbcurve, vtinterp, this_kind='equality'):
    #                           this_kind='equality'):
    #                           this_kind='LS'):
    """setup THBcurve Lspline vertex interpolation solver
    
    
    inputs
    ----------
        thbcurve    = starting base level THB curve (n=4)
        vinterp     = the transverse vertices to be interpolated
                                        (including the endpoints!)
                                        
    dev
    ----------
    Lspline = setup_interpolation_solver(thbcurve,
                                         vtinterp)
    this_kind = 'equality'
    """
    big = 100000.
    interval_data, small = interval_bounds(thbcurve)
    FPD = FormParameterDict(thbcurve)

    FPD.add_E1(kind='LS', weight=1.)
    FPD.add_E2(kind='LS', weight=.5)
    FPD.add_E3(kind='LS', weight=.05)
    FPD.add_ArcLength(kind='LS', weight=big)
    ntinterp = len(vtinterp)
    ukbar = np.linspace(0., 1., ntinterp)[1:-1]
    nth = 1

    start = vtinterp[3]
    end = vtinterp[6]
    dx = np.linalg.norm(end - start)
    for pt, loc in zip(vtinterp[1:-1], ukbar):
        FPD.add_xPointConstraint(kind=this_kind,
                                 value=pt[0],
                                 location=loc,
                                 weight=big)
        FPD.add_yPointConstraint(kind=this_kind,
                                 value=pt[1],
                                 location=loc,
                                 weight=big)
        FPD.add_zPointConstraint(kind=this_kind,
                                 value=pt[2],
                                 location=loc,
                                 weight=big)
        #*********************************************
        # X Fixing
        #        if nth in [4,5,6,7]:
        #            FPD.add_xFixity(index=nth,
        #                            value=pt[0])
        #        else:
        #            FPD.add_xPointConstraint(kind= this_kind,
        #                                 value=pt[0],
        #                                 location=loc,
        #                                 weight = big )
        #        #*********************************************
        #        # Y Fixing
        #        if nth in [3,4,5,6]:
        #            FPD.add_xFixity(index=nth,
        #                            value=pt[1])
        #        else:
        #            FPD.add_yPointConstraint(kind= this_kind,
        #                                 value=pt[1],
        #                                 location=loc,
        #                                 weight = big  )
        #        #*********************************************
        #        # Z Fixing
        #        if nth in [3,4,5,6,7]:
        #            if nth == 4:
        #                #assert(pt[2]==start[2]),'You got START wrong!'
        #                FPD.add_zFixity(index=nth,
        #                                value=start[2]-.1*dx)
        #            elif nth == 5:
        #                FPD.add_zFixity(index=nth,
        #                                value=start[2]-.05*dx)
        #
        #            elif nth == 6:
        #                FPD.add_zFixity(index=nth,
        #                                value=end[2]+.05*dx)
        #            elif nth == 7:
        #                #assert(pt[2]==end[2]),'You got END wrong!'
        #                FPD.add_zFixity(index=nth,
        #                                value=end[2]+.1*dx)
        #            #else:
        #                #assert(1==0),'Logic Failure'
        #        else:
        #            FPD.add_zPointConstraint(kind= this_kind,
        #                                 value=pt[2],
        #                                 location=loc,
        #                                 weight = big  )
        #*********************************************
        #        if nth in [3,4,5,6]:
        #            FPD.add_CurvatureXoverZConstraint(value=0.,
        #                                        location=loc,
        #                                        weight=big)
        #*********************************************
        #        if nth == 1:
        #            FPD.add_zFixity(index=nth,
        #                            value=0.)
        #        else:
        #            FPD.add_zPointConstraint(kind= this_kind,
        #                                 value=pt[2],
        #                                 location=loc,
        #                                 weight = big  )

        #*********************************************
        if nth == 3:
            FPD.add_CurvatureXoverZConstraint(kind=this_kind,
                                              location=loc,
                                              value=0.,
                                              weight=big)
            FPD.add_AngleXoverZConstraint(kind=this_kind,
                                          location=loc,
                                          value=loc,
                                          weight=big)


#        if nth ==4:
#            FPD.add_CurvatureXoverZConstraint(kind=this_kind,
#                                        location=loc+.01,
#                                        value = 0.,
#                                        weight =big)
#        if nth ==5:
#            FPD.add_CurvatureXoverZConstraint(kind=this_kind,
#                                        location=loc-.01,
#                                        value = 0.,
#                                        weight =big)
#            FPD.add_CurvatureXoverZConstraint(kind=this_kind,
#                                        location=loc,
#                                        value = 0.,
#                                        weight =big)
        if nth == 4:
            #            FPD.add_CurvatureXoverZConstraint(kind=this_kind,
            #                                        location=loc,
            #                                        value = 0.,
            #                                        weight =big)
            #-----------------------------
            #            test = FPD.curve.greville_abscissa(7)
            #            FPD.add_CurvatureXoverZConstraint(kind=this_kind,
            #                                        location=loc-.1,
            #                                        value = 0.,
            #                                        weight =big)
            #            FPD.add_CurvatureXoverZConstraint(kind=this_kind,
            #                                        location=loc,
            #                                        value = 0.,
            #                                        weight =big)
            FPD.add_CurvatureXoverZConstraint(kind=this_kind,
                                              location=loc,
                                              value=0.,
                                              weight=big)
            #            FPD.add_CurvatureXoverZConstraint(kind=this_kind,
            #                                        location=test,
            #                                        value = 0.,
            #                                        weight =big)
            #---- --- --- --
            #            FPD.add_AngleXoverZConstraint(kind=this_kind,
            #                                            location = loc,
            #                                            value = 0.,
            #                                            weight=big)
            #            FPD.add_AngleXoverZConstraint(kind=this_kind,
            #                                            location = loc-.01,
            #                                            value = 0.,
            #                                            weight=big)
            FPD.add_AngleXoverZConstraint(kind=this_kind,
                                          location=loc,
                                          value=0.,
                                          weight=big)
        nth += 1
    FPD.add_verticalXoverZAngleConstraint(kind=this_kind,
                                          location=0.,
                                          value=0.,
                                          weight=big)

    #    FPD.add_AngleXoverZConstraint(kind      = this_kind,
    #                                 location   = 0.,
    #                                 value      = 90.,
    #                                 weight     = 10*big)
    L = Lagrangian(FPD)
    interval_data, small = lagrangian_bounds(L, interval_data, small, 1.e4)
    Lspline = IntervalLagrangeSpline(thbcurve, L, data=interval_data)
    return Lspline
def make_curve(section):
    interval_data, small = interval_bounds(section)
    FPD = FormParameterDict(section)
    return
示例#7
0
 def ADILS_optiization(self,curve,yval,xval,x2,y2,
                tanb=0.,tane=0.,cvb=0.,cve=0.,area=72.):
     interval_data, small = interval_bounds(curve)        
     FPD = FormParameterDict(curve) 
     #---box constraint
     FPD.add_yPointConstraint(kind= 'max', value=4., location=xval[0] )
     FPD.add_xPointConstraint(kind= 'min', value=6., location=xval[0] )
     #FPD.add_yPointConstraint(kind= 'LS', value=4., location=yval[0], weight=-100. )
     #FPD.add_xPointConstraint(kind= 'LS', value=6., location=xval[0], weight=-100. )
     #---
     #---box constraint
     FPD.add_yPointConstraint(kind= 'max', value=8., location=y2[0] )
     FPD.add_xPointConstraint(kind= 'min', value=6., location=x2[0] )
     #FPD.add_yPointConstraint(kind= 'LS', value=8., location=y2[0], weight=-100. )
     #FPD.add_xPointConstraint(kind= 'LS', value=6., location=x2[0], weight=-100. )
     #---
     FPD.add_AreaConstraint(kind='LS',value=area)
     FPD.add_AngleConstraint(kind='equality',location=0.,value=tanb)
     FPD.add_AngleConstraint(kind='equality',location=1.,value=tane)
     FPD.add_CurvatureConstraint(kind='equality',location=0.,value=cvb)
     FPD.add_CurvatureConstraint(kind='equality',location=1.,value=cve)
     FPD.add_E1(kind='LS', weight = .5)
     FPD.add_E2(kind='LS', weight = .5)
     FPD.add_E3(kind='LS', weight = .5)
     FPD.add_ArcLengthApprox(kind='LS', weight = .5)
     L = Lagrangian(FPD)
     interval_data, small = lagrangian_bounds(L, interval_data, small, 1.e4)
     Lspline = IntervalLagrangeSpline(curve, L, data = interval_data)
     print 'in the loop'
     Lspline.optimize(stop = 50)
     return Lspline
示例#8
0
    vertices = np.array([[0., 0., 0.], [10., 5., 1.], [15., 7.5, 1.5],
                         [20., 10., 2.], [20., 10., 2.], [20., 10., 2.],
                         [25., 15., 2.5], [25., 15., 2.5], [25., 15., 2.5],
                         [30., 15., 3.], [40., 20., 4.]])

    vertices = np.array([[0., 0., 0.], [10., 5., 1.], [15., 7.5, 1.5],
                         [30., 15., 3.], [40., 20., 4.]])

    k = 4
    nump = 50
    curve = spline.interpolatedBspline(vertices, k, nump)
    cc = copy.deepcopy(curve)

    interval_data, small = interval_bounds(curve)

    FPD = FormParameterDict(curve)
    FPD.add_E1(kind='LS', weight=.5)
    FPD.add_E2(kind='LS', weight=.5)
    FPD.add_E3(kind='LS', weight=.5)
    FPD.add_ArcLengthApprox(kind='LS', weight=.5)

    for i in range(len(curve.vertices[1:-1])):
        j = i + 1
        """TODO, TLM OCT 30 2017:
            find where the curve interpolated pts are : 
                done:  curve.ukbar[i]
            and use these as the targets for the
            optimization z_point_constraints!
        
            Done: NOV 1, 2017
        """
示例#9
0
class FormParameterInteractor:
    def __init__(self, Lspline):
        self.Lspline = Lspline
        self.Lspline.Lagrangian = None
        self.FPD = FormParameterDict(self.Lspline.curve)
        self.verbose = True
        #self.fig = figure()
        self.fig, self.ax = plt.subplots()
        self.fig.subplots_adjust(left=0.3)
        prop = ItemProperties(labelcolor='black',
                              bgcolor='white',
                              fontsize=15,
                              alpha=0.2)
        hoverprop = ItemProperties(labelcolor='white',
                                   bgcolor='blue',
                                   fontsize=15,
                                   alpha=0.2)
        menuitems = []
        for label in ('tangent', 'curvature', 'area', 'Xc', 'Yc', 'clear',
                      'done'):

            def onselect(item):
                print('you selected %s' % item.labelstr)
                getattr(self, item.labelstr)()
                return

            item = MenuItem(self.fig,
                            label,
                            props=prop,
                            hoverprops=hoverprop,
                            on_select=onselect)
            menuitems.append(item)
        menu = Menu(self.fig, menuitems)
        plt.show(block=False)
        return

    def __call__(self):
        return self.Lspline

    def tangent(self):
        if self.verbose: print 'tangent FP'
        loc = -1.
        while not (0. <= loc <= 1.):
            loc = float(
                raw_input('enter location for form parameter [0,1] \n'))
        val = float(raw_input('enter desired tangent angle in degrees \n'))
        self.FPD.add_AngleConstraint(kind='equality', location=loc, value=val)
        return

    def curvature(self):
        if self.verbose: print 'curvature FP'
        loc = -1.
        while not (0. <= loc <= 1.):
            loc = float(
                raw_input('enter location for form parameter [0,1] \n'))
        val = float(
            raw_input(
                'enter desired curvature \n(units are inverse length) \n'))
        self.FPD.add_CurvatureConstraint(kind='equality',
                                         location=loc,
                                         value=val)
        return

    def area(self):
        if self.verbose: print 'area FP'
        val = float(raw_input('enter desired area \n'))
        self.FPD.add_AreaConstraint(kind='equality', value=val)
        return

    def Xc(self):
        if self.verbose: print 'Xc FP'
        val = float(raw_input('enter desire x centroid \n'))
        self.FPD.add_XcConstraint(kind='equality', value=val, weight=2000.)
        return

    def Yc(self):
        if self.verbose: print 'Yc FP'
        val = float(raw_input('enter desire y centroid \n'))
        self.FPD.add_YcConstraint(kind='equality', value=val)
        return

    def clear(self):
        if self.verbose: print 'clear FP'
        self.FPD = FormParameterDict(self.Lspline.curve)
        return

    def done(self):
        if self.verbose: print 'Done'
        interval_data, small = interval_bounds(self.Lspline.curve)
        self.FPD.add_E1(kind='LS', weight=1.)
        self.FPD.add_E2(kind='LS', weight=.5)
        self.FPD.add_E3(kind='LS', weight=.5)
        #self.FPD.add_ArcLength(kind='LS', weight = 1.)
        self.FPD.add_ArcLengthApprox(kind='LS', weight=1.)
        L = Lagrangian(self.FPD)
        interval_data, small = lagrangian_bounds(L, interval_data, small, 1.e4)

        self.Lspline = IntervalLagrangeSpline(self.Lspline.curve,
                                              L,
                                              data=interval_data)
        #self.Lspline = IntervalLagrangeSpline(curve, L, data = interval_data)
        plt.close(3)
        return

    def set_initial_values(self):
        return
示例#10
0
 def clear(self):
     if self.verbose: print 'clear FP'
     self.FPD = FormParameterDict(self.Lspline.curve)
     return
示例#11
0
 y_interest = 4.0
 yindex = 1
 yval0 = curve.FindPoint(y_interest,yindex)
 
 x_interest = 8.
 x_index = 0
 xval0 = curve.FindPoint(x_interest,x_index)
 
 
 
 #print pval[0]
 #print curve.CurvePoint(yval[0])
 #"""
 ccr = copy.deepcopy(curve)
 interval_data, small = interval_bounds(ccr)        
 FPD = FormParameterDict(ccr) 
 #"""
 """
 FPD.add_yPointConstraint(kind= 'max', value=4., location=.4 )
 FPD.add_xPointConstraint(kind= 'min', value=6., location=.45 )
 FPD.add_yPointConstraint(kind= 'LS', value=4., location=.4,weight=-100. )
 FPD.add_xPointConstraint(kind= 'LS', value=6., location=.45,weight=-100. )
 #"""
 FPD.add_yPointConstraint(kind= 'max', value=4., location=yval0[0] )
 FPD.add_xPointConstraint(kind= 'min', value=8., location=xval0[0] )
 #
 #FPD.add_yPointConstraint(kind= 'min', value=8., location=xval0[0] )#new and not needed
 #"""
 FPD.add_AreaConstraint(kind='equality',value=curve_area)
 FPD.add_AngleConstraint(kind='equality',location=0.,value=alphab)
 FPD.add_AngleConstraint(kind='equality',location=1.,value=alphae)
    def stage2(self, Lspline, FPD):
        #
        #******************************************************************
        # SAC
        # NOW Entering Solver Stage 2
        norms = package_norms(Lspline)
        E1_0 = norms[0]
        E2_0 = norms[1]
        E3_0 = norms[2]
        S_0 = norms[3]
        curve = Lspline.curve
        #
        #**********************************************************************
        #
        interval_data, small = interval_bounds(curve)
        FPD = FormParameterDict(curve)
        #
        #******************************************************************
        # Integral Parameters
        FPD.add_AreaConstraint(kind='equality', value=self.BareHullVolume)
        FPD.add_XcConstraint(kind='equality', value=self.LCG)

        #FPD.add_xPointConstraint(kind='max',
        #                         value=0.1,
        #                         location=.001)
        #FPD.add_yPointConstraint(kind='min',
        #                         value=10.,
        #                         location=.001)
        #
        #******************************************************************
        #  FLATS
        #
        #******************************************************************
        # X FLAT SAC
        #
        #print 'using x - fixity'
        #        FPD.add_xFixity(index=5,
        #                        value=self.stations.FOSAC[0])
        #        FPD.add_xFixity(index=6,
        #                        value=self.stations.FOSAC[1])
        #
        FPD.add_relative_xVertexConstraint(kind='equality',
                                           location=None,
                                           value=self.lfsac,
                                           weight=1.0,
                                           index=5,
                                           index2=6,
                                           seperation=-self.lfsac)
        #        FPD.add_relative_xVertexConstraint(kind = 'min', location=None,
        #                                           value = 0., weight = 1.0,
        #                                           index = 5, index2 = 6,
        #                                           seperation = self.lfsac )
        #        FPD.add_relative_xVertexConstraint(kind = 'max', location=None,
        #                                           value = self.lfsac+1., weight = 1.0,
        #                                           index = 5, index2 = 6,
        #                                           seperation = self.lfsac )

        #
        #******************************************************************
        # Y FLAT SAC (3,4,5,6,7)
        #-----------------------?
        #print 'using y - fixity'
        #FPD.add_yFixity(index=3,
        #                value=self.maxSecArea)
        FPD.add_yFixity(index=4, value=self.maxSecArea)
        FPD.add_yFixity(index=5, value=self.maxSecArea)
        FPD.add_yFixity(index=6, value=self.maxSecArea)
        FPD.add_yFixity(index=7, value=self.maxSecArea)
        #-----------------------?
        #FPD.add_yFixity(index=8,
        #                value=self.maxSecArea)
        #
        #******************************************************************
        #
        #        FPD.add_yPointConstraint(kind = 'equality',
        #                                 location=.01,
        #                                 value = self.Ab,
        #                                 )
        #
        #******************************************************************
        #
        #
        #******************************************************************
        #
        print 'adding bulb to the SAC functional'
        A_mid = 10.080798436245335
        BulbLength = 4.341062137105493
        #gfunc = spfuncs.gfunc
        #bbow_sac = spfuncs.BBowSAC(Xb=0.,Xe = BulbLength,
        #                           height=A_mid)
        #******************************************************************
        # Fairness
        FPD.add_E1(kind='LS', weight=1.5 / E1_0)
        FPD.add_E2(kind='LS', weight=.5 / E2_0)
        FPD.add_E3(kind='LS', weight=.5 / E3_0)
        FPD.add_ArcLengthApprox(kind='LS', weight=10. / S_0)
        #
        #******************************************************************
        #
        L = Lagrangian(FPD)
        """
        gfunc_bbow_SAC  = spfuncs.gfunc(curve,
                                         bbow_sac,
                                         0.,
                                         .00001,
                                         np.linspace(0.,1.,
                                                     bbow_sac.nump*5,
                                                     endpoint=True),
                                        10000.)
        gfunc_bbow_SAC.analysis_type = 'min'
        L.sp['bbow_sac'] = gfunc_bbow_SAC
        #"""
        #
        #******************************************************************
        #
        interval_data, small = lagrangian_bounds(L, interval_data, small, 1.e4)
        Lspline = IntervalLagrangeSpline(curve, L, data=interval_data)
        #
        #******************************************************************
        #OPTIMIZE - 2nd pass
        print 'Doing second stage SAC solve'
        Lspline.optimize(stop=100)
        #
        #******************************************************************
        # Done
        return Lspline, FPD
    def stage1(self, curve, flat=False):
        #
        #******************************************************************
        # Begin Stage 1
        interval_data, small = interval_bounds(curve)

        FPD = FormParameterDict(curve)
        #
        #******************************************************************
        #  Integral Parameters:
        FPD.add_AreaConstraint(kind='equality', value=self.BareHullVolume)
        FPD.add_XcConstraint(kind='equality', value=self.LCG)
        #
        #******************************************************************
        #  Flat Portion
        if flat:
            FPD.add_yPointConstraint(kind='equality',
                                     location=0.3333333333,
                                     value=self.maxSecArea)  #*2./3.)

            FPD.add_yPointConstraint(kind='equality',
                                     location=0.6666666666,
                                     value=self.maxSecArea)  #*2./3.)
        else:
            print 'SAC stage 1 not enforcing flat section'
        #
        #******************************************************************
        # starting, ending angles
        #            FPD.add_AngleConstraint(kind='LS',
        #                                    location = 0.,
        #                                    value = alphab)
        #            FPD.add_AngleConstraint(kind='LS',
        #                                    location = 1.,
        #                                    value = alphae)
        #
        #******************************************************************
        # Max S.A.
        FPD.add_yPointConstraint(kind='equality',
                                 location=self.LocMaxSection,
                                 value=self.maxSecArea)
        #
        #******************************************************************
        # Fairness
        FPD.add_E1(kind='LS', weight=.5)
        FPD.add_E2(kind='LS', weight=.5)
        FPD.add_E3(kind='LS', weight=.5)
        FPD.add_ArcLengthApprox(kind='LS', weight=.5)
        #
        #******************************************************************
        #
        L = Lagrangian(FPD)
        interval_data, small = lagrangian_bounds(L, interval_data, small, 1.e4)
        Lspline = IntervalLagrangeSpline(curve, L, data=interval_data)
        #
        #******************************************************************
        #OPTIMIZE - 1st pass
        #
        print 'Doing first stage SAC solve'
        Lspline.optimize()
        #
        #******************************************************************
        # Done
        #
        return Lspline, FPD
示例#14
0
def make2():
    """
    testing
    ----------
    dev
    ----------
    stop=5
    ceiling = 1.e-12,
    relax_grad_bounds=False
    
    self = Lspline
    Lagrangian = self.Lagrangian
    L = self.Lagrangian
    vertices = self.curve.ADvertices
    
    
    vtx = Lspline.curve.project_vertices_all_active()
    
    print Lspline.child.Lagrangian.equality[3].type
    fp = Lspline.child.Lagrangian.equality[3]
    
    Lspline.child.curve.compute_area(vertices=vtx)
    """
    this_kind = 'equality'
    big = 100000.  #1. #
    mig = big/2.  #.5 #
    k=4
    nump=30
    xb = 0.
    yb = 17.33641345
    zb = 0.
    
    xe = 14.15239481
    ye = 17.33641345
    ze = 49.19157975
    
    alphab = 0.
    alphae = 0.
    Cab = 0.
    Cae = 0.
    xc = 4.
    yc = 4.
    curve_area = 80.
    slope = 'down'
    x_offset1 = 3.
    x_offset2 = -2.
    y_offset = 2.
    ae = alphae
    ab = alphab
    #
    curve = initial_curve([xb,yb,zb],
                          [xe,ye,ze],
                          11,nump=30) 
    curve = uopt.make_thb(curve)
    #curve.parent = None
    #curve = curve.dyadic_refinement()
    #curve = curve.dyadic_refinement()
    #curve = curve.dyadic_refinement()
    curve.parent = None
    #
    FPD = FormParameterDict(curve) 
    #
    vtinterp = [np.asarray([12.35339247, 17.33641345, 17.70896871]),
                np.asarray([14.04681792, 17.33641345, 36.89368482])]
    ntinterp = len(vtinterp)
    ukbar = np.linspace(0.,1.,ntinterp+2)[1:-1]
    #
    count = 0
    for pt,loc in zip(vtinterp,ukbar):
        FPD.add_xPointConstraint(kind= this_kind, 
                                 value=pt[0], 
                                 location=loc, 
                                 weight = big ) 
        FPD.add_yPointConstraint(kind= this_kind, 
                                 value=pt[1], 
                                 location=loc, 
                                 weight = big  )
        FPD.add_zPointConstraint(kind= this_kind, 
                                 value=pt[2], 
                                 location=loc, 
                                 weight = big  )
        count += 1
    #
    FPD.add_yFixity(index = 1,
                    value = yb,
                    track_prolongation=False)
    #FPD.add_yFixity(index = 2,
    #                value = yb,
    #                track_prolongation=False)
    #--------------------------
    FPD.add_zFixity(index = 1,
                    value =zb,
                    track_prolongation=False)
    #
    # C2 continuity to midship.
    FPD.add_xFixity(index = -2,
                    value = xe,
                    track_prolongation=False)
    FPD.add_yFixity(index = -2,
                    value = ye,
                    track_prolongation=False)
    #--------------------------------------------------
    #    FPD.add_zFixity(index = -2,
    #                    value = ze,
    #                    track_prolongation=False)
    #--------------------------------------------------
    #FPD.add_xFixity(index = -3,
    #                value = xe,
    #                track_prolongation=False)
    #FPD.add_yFixity(index = -3,
    #                value = ye,
    #                track_prolongation=False)
    #    FPD.add_CurvatureXoverZConstraint(  kind        = this_kind,
    #                                        location    = 1.,
    #                                        value       = 0.,
    #                                        weight      = mig)
    #    FPD.add_CurvatureConstraint(        kind        = this_kind,
    #                                        location    = 1.,
    #                                        value       = 0.,
    #                                        weight      = mig)
    #
    #**************************************************************************
    # fairness
    FPD.add_E1(kind='LS', weight = 1.)
    FPD.add_E2(kind='LS', weight = .5)
    FPD.add_E3(kind='LS', weight = .05)
    FPD.add_ArcLengthApprox(kind='LS', weight =  mig) #1.5)  # 
    #
    #**************************************************************************
    # setup
    #
    Lspline = init_Lspline(curve, FPD)
    #
    #Lspline.optimize_thb(stop = 50,
    #                     ceiling = 1.e-12,
    #                     relax_grad_bounds=False)
    Lspline.verbose = True
    #Lspline = THBsolver(Lspline=Lspline)
    #
    #**************************************************************************
    # solve
    #Lspline.optimize()
    Lspline = uopt.THBsolver(Lspline=Lspline,
                             refinemax=4, 
                             maxlevel=3,
                             normalize=False)
    
    print ukbar
    print vtinterp[0]
    print vtinterp[1]
    print 'ukbar 0'
    print Lspline.curve(ukbar[0])
    print 'ukbar 1'
    print Lspline.curve(ukbar[1])
    print ''
    print 'diff 0'    
    print Lspline.curve(ukbar[0])[0] - vtinterp[0]
    print ''
    print 'diff 1'
    print Lspline.curve(ukbar[1])[0] - vtinterp[1]
    return Lspline
示例#15
0
def make1():
    """
    testing
    ----------
    dev
    ----------
    stop=5
    ceiling = 1.e-12,
    relax_grad_bounds=False
    
    self = Lspline
    Lagrangian = self.Lagrangian
    L = self.Lagrangian
    vertices = self.curve.ADvertices
    
    
    vtx = Lspline.curve.project_vertices_all_active()
    
    print Lspline.child.Lagrangian.equality[3].type
    fp = Lspline.child.Lagrangian.equality[3]
    
    Lspline.child.curve.compute_area(vertices=vtx)
    """
    k=4
    nump=30
    xb = 0.
    yb = 12.
    xe = 15.
    ye = 0.
    alphab = 0.
    alphae = 0.
    Cab = 0.
    Cae = 0.
    xc = 4.
    yc = 4.
    curve_area = 80.
    slope = 'down'
    x_offset1 = 3.
    x_offset2 = -2.
    y_offset = 2.
    ae = alphae
    ab = alphab
    
    curve = initial_curve([xb,yb],[xe,ye],4,nump=200) 
    curve = uopt.make_thb(curve)
    #curve.parent = None
    #curve = curve.dyadic_refinement()
    #curve = curve.dyadic_refinement()
    #curve = curve.dyadic_refinement()
    curve.parent = None
    
    FPD = FormParameterDict(curve) 
    
    
    #
    #**************************************************************************
    # derivative
#    FPD.add_verticalAngleConstraint(kind='equality', 
#                                    location = 0., value = 0.)
    #FPD.add_AngleConstraint(kind='equality', 
    #                        location = .5, value = 45.)
#    FPD.add_AngleConstraint(kind='equality', 
#                            location = 1., value =  0.)
    # curvature
#    FPD.add_CurvatureConstraint(kind='equality',
#                                location=.0,
#                                value = 0.,
#                                weight=1.)
    #
    #**************************************************************************
    # integral
#    FPD.add_AreaConstraint(kind='equality',
#                           value=43.,
#                           weight=1.)
#    FPD.add_XcConstraint(kind       = 'equality',
#                           value    = 3.58,
#                           weight   = 1.)
    #
    #**************************************************************************
    # positional
#    FPD.add_xPointConstraint(kind       = 'equality',
#                             location   = .5,
#                             value      = 3.5)
#    FPD.add_yPointConstraint(kind       = 'equality',
#                             location   = .5,
#                             value      = 5.)
#    FPD.add_yPointConstraint( kind      = 'equality', 
#                             location   = .15, 
#                             value      = 10.)
    #FPD.add_xFixity(value=0. , index=1, track_prolongation=False)
    #FPD.add_xFixity(value=0. , index=2, track_prolongation=False)
    #
    FPD.add_xFixity(value=1. , index=2, track_prolongation=False)
    FPD.add_yFixity(value=1. , index=2, track_prolongation=True) #last vertices might be trickier
    #
    #**************************************************************************
    # fairness
    FPD.add_E1(kind='LS', weight = .5)
    FPD.add_E2(kind='LS', weight = .5)
    FPD.add_E3(kind='LS', weight = .5)
    FPD.add_ArcLengthApprox(kind='LS', weight = .5)
    #
    #**************************************************************************
    # setup
    #
    Lspline = init_Lspline(curve, FPD)
    #
    #Lspline.optimize_thb(stop = 50,
    #                     ceiling = 1.e-12,
    #                     relax_grad_bounds=False)
    Lspline.verbose = True
    #Lspline = THBsolver(Lspline=Lspline)
    #
    #**************************************************************************
    # solve
    Lspline = uopt.THBsolver(Lspline=Lspline,
                             refinemax=4, 
                             maxlevel=3,
                             normalize=True)
    return Lspline
    def compute_midbody_SAC(self):
        k = SAC.k
        nump = SAC.nump
        n = 7
        xb = SAC.xb
        xe = xb + self.Lm
        yb = self.Amax
        ye = self.Amax
        Xc = self.Xm
        ab = 0.
        ae = 0.
        vertices = linear_vertices([xb, yb], [xe, ye], num=n)
        curve = spline.Bspline(vertices, k, nump)

        interval_data, small = interval_bounds(curve)

        FPD = FormParameterDict(curve)
        #FPD.add_AreaConstraint(kind='equality', value = curve_area)
        FPD.add_AngleConstraint(kind='equality', value=0., location=0.)
        FPD.add_AngleConstraint(kind='equality', value=0., location=1.)
        FPD.add_CurvatureConstraint(kind='equality', value=0., location=0.)
        FPD.add_CurvatureConstraint(kind='equality', value=0., location=1.)
        #FPD.add_XcConstraint(kind = 'equality', value = 6.)
        FPD.add_E1(kind='LS', weight=1.)
        FPD.add_E2(kind='LS', weight=1.)
        FPD.add_E3(kind='LS', weight=1.)
        FPD.add_ArcLengthApprox(kind='LS', weight=1.)
        L = Lagrangian(FPD)

        interval_data, small = lagrangian_bounds(L, interval_data, small, 1.e4)
        Lspline = IntervalLagrangeSpline(curve, L, data=interval_data)

        Lspline.compute_lagrangian()
        Lspline.display(mytitle='SAC_mid_ini',
                        x_axis_name='x',
                        y_axis_name='z')
        Lspline.optimize()
        Lspline.display(mytitle='SAC_mid', x_axis_name='x', y_axis_name='z')
        return Lspline
    def compute_entrance_SAC(self):
        k = SAC.k
        nump = SAC.nump
        nCV = 7
        xb = SAC.xb
        xe = xb + self.Lr
        yb = self.Amax
        ye = 0.
        yap = self.Aap
        Xc = self.Xr
        ab = 0.
        ae = 0.
        ini_v = InitializeControlVertices(xb,
                                          yb,
                                          xe,
                                          ye,
                                          alphae=ae,
                                          alphab=ab,
                                          Cab_given=0.,
                                          Cae_given=0.,
                                          nCV=7,
                                          slope='down')
        curve = spline.Bspline(ini_v.vertices, k, nump)

        interval_data, small = interval_bounds(curve)

        FPD = FormParameterDict(curve)
        #FPD.add_AreaConstraint(kind='equality', value = curve_area)
        FPD.add_AngleConstraint(kind='equality', value=0., location=0.)
        FPD.add_AngleConstraint(kind='equality', value=0., location=1.)
        FPD.add_CurvatureConstraint(kind='equality', value=0., location=0.)
        FPD.add_CurvatureConstraint(kind='equality', value=0., location=1.)
        FPD.add_XcConstraint(kind='equality', value=3.5)
        FPD.add_E1(kind='LS', weight=1.)
        FPD.add_E2(kind='LS', weight=1.)
        FPD.add_E3(kind='LS', weight=1.)
        FPD.add_ArcLengthApprox(kind='LS', weight=1.)
        L = Lagrangian(FPD)

        interval_data, small = lagrangian_bounds(L, interval_data, small, 1.e4)
        Lspline = IntervalLagrangeSpline(curve, L, data=interval_data)

        Lspline.compute_lagrangian()
        Lspline.display(mytitle='SAC_fwd_ini',
                        x_axis_name='x',
                        y_axis_name='z')
        Lspline.optimize()
        Lspline.display(mytitle='SAC_fwd', x_axis_name='x', y_axis_name='z')
        return Lspline
    def OSV_bbow(curve):
        """Lspline solver 
        
            for the 
            
            CProfile keel curve
            
         (intended for a transom sterned hull)
        with bulbous bow
        
        dev
        ----------
        
        elevation = self.MaxDraft
        k           = self.k
        nump        = self.nump
        xb          = 0.
        yb          = 0.
        xe          = self.LengthDWL
        ye          = 0.+self.MaxDraft*drop_aft
        #alphab     = 85.##35
        #alphae     = -85.##-35
        Cab_given   = 0.
        Cae_given   = 0.
        slope       = 'down'

        Dmax = self.MaxDraft
        area = self.CLarea

        ab = alphab
        ae = alphae
        """
        print 'OSV_bbow solver Oct 14, 2018'
        #            #
        #            #**********************************************************************
        #            # get weights
        #            if Lspline is not None:
        #                norms = package_norms(Lspline)
        #                E1_0 = norms[0]
        #                E2_0 = norms[1]
        #                E3_0 = norms[2]
        #                S_0  = norms[3]
        #                curve = Lspline.curve
        #            else:
        #                E1_0 = 1.
        #                E2_0 = 1.
        #                E3_0 = 1.
        #                S_0  = 1.
        # CPK
        #**********************************************************************
        # initialize
        interval_data, small = interval_bounds(curve)
        FPD = FormParameterDict(curve)
        #
        #**********************************************************************
        # area  CPKeelProfile stage 1
        FPD.add_AreaConstraint(kind='equality', value=area)
        #
        #**********************************************************************
        # Xc CPKeelProfile
        if Xc is None:
            print 'CPK OSV bbow, equality LCG'
            FPD.add_XcConstraint(kind='LS', value=LCG * .75,
                                 weight=100.)  #cLProfile flat to bulb...
            #FPD.add_XcConstraint(kind='max',
            #                     value=self.LCG*.95)
            #FPD.add_XcConstraint(kind='min',
            #                     value=self.LCG*0.8)
        else:
            print 'Centerplane setting Xc constraint to ', Xc
            FPD.add_XcConstraint(kind='LS', value=Xc)
        #                                     value = 0.)
        #
        ##**************************************************************
        # CPkeelProfile
        #print 'Adding x - fixity!'
        #-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
        # TLM, straight flat stem
#            FPD.add_xFixity(index=1,
#                            value=xb)
#            FPD.add_xFixity(index=2,
#                            value=xb)
#-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
# Dr. Birk, flat stem
#            FPD.add_AngleConstraint(
#                                    kind        = 'equality',
#                                    location    = 0.,
#                                    value       = 75.)
        FPD.add_CurvatureConstraint(kind='equality',
                                    location=0.,
                                    value=0.,
                                    weight=100.)
        #--------------------------------------
        # +++
        #-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
        # TLM, straight flat stem
        #FPD.add_xVertexConstraint(kind='LS',
        #                         index = 3,
        #                         value = 0.)
        FPD.add_xFixity(
            index=3,  #5,
            value=0.)
        FPD.add_relative_xVertexConstraint(kind='equality',
                                           value=0.,
                                           index=3,
                                           index2=4,
                                           seperation=0.)
        #-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
        #--------------------------------------
        # ++
        #            FPD.add_xVertexConstraint(kind='LS',
        #                                     index = 8,
        #                                     value = xe)
        #            FPD.add_xVertexConstraint(kind='LS',
        #                                     index = 9,
        #                                     value = xe)
        #--------------------------------------
        ##**************************************************************
        # CPkeelProfile
        #print 'Adding x - fixity!'
        #tlmOct 14 2018 tweak this:
        FPD.add_xFixity(
            index=5,  #5,
            value=FOCP0)
        FPD.add_xFixity(
            index=6,  #6,
            value=FOCP1)
        #
        #------------------------------- #tlmOct 14 2018 tweak this:
        #print 'Adding y - fixity!'
        #FPD.add_yFixity(index=3,
        #                value=Dmax)
        FPD.add_yFixity(index=4, value=Dmax)
        FPD.add_yFixity(index=5, value=Dmax)
        FPD.add_yFixity(index=6, value=Dmax)
        FPD.add_yFixity(index=7, value=Dmax)
        #-------------------------------
        FPD.add_yFixity(index=8, value=Dmax)
        #FPD.add_yFixity(index=9,
        #                value=Dmax)
        #?-------------------------------?
        #            FPD.add_yVertexConstraint(kind='max',
        #                                     index = 8,
        #                                     value = Dmax)
        #            FPD.add_yVertexConstraint(kind='max',
        #                                     index = 9,
        #                                     value = Dmax)
        #?-------------------------------?
        #
        #
        #**********************************************************************
        # CPkeelProfile Fairness
        FPD.add_E1(kind='LS', weight=.5)
        FPD.add_E2(kind='LS', weight=.5)
        FPD.add_E3(kind='LS', weight=.001)
        FPD.add_ArcLengthApprox(kind='LS', weight=1.5)
        #
        #**********************************************************************
        #Setup and Solve:
        #
        L = Lagrangian(FPD)
        interval_data, small = lagrangian_bounds(L, interval_data, small, 1.e4)
        Lspline = IntervalLagrangeSpline(curve, L, data=interval_data)
        print 'Doing first stage CPkeel solve (include bbow weighting)'
        Lspline.optimize(stop=50)
        return Lspline
示例#19
0
#        bspan = b1.knot_insertion(knot=p2)
#        
#        self = CP_Intersection(c1,box1.curves[0])
#        p1,p2=self.intersect_cp_segments(i=4,j=1)
        
        
        
        
        
        
        
        #print pval[0]
        #print curve.CurvePoint(yval[0])
        #"""
        interval_data, small = interval_bounds(curve)        
        FPD = FormParameterDict(curve) 
        #"""
        """
        FPD.add_yPointConstraint(kind= 'max', value=4., location=.4 )
        FPD.add_xPointConstraint(kind= 'min', value=6., location=.45 )
        FPD.add_yPointConstraint(kind= 'LS', value=4., location=.4,weight=-100. )
        FPD.add_xPointConstraint(kind= 'LS', value=6., location=.45,weight=-100. )
        #"""
        #"""
        FPD.add_AreaConstraint(kind='equality',value=curve_area)
        FPD.add_AngleConstraint(kind='equality',location=0.,value=alphab)
        FPD.add_AngleConstraint(kind='equality',location=1.,value=alphae)
        FPD.add_CurvatureConstraint(kind='equality',location=0.,value=Cab)
        FPD.add_CurvatureConstraint(kind='equality',location=1.,value=Cae)
        #"""
        #"""
示例#20
0
        self = CP_Intersection(curve, box1.curves[0])
        p1, p2 = self.intersect_cp_segments(i=3, j=1)

        c1 = copy.deepcopy(curve)
        cspan = c1.knot_insertion(knot=p1)
        b1 = copy.deepcopy(box1.curves[0])
        bspan = b1.knot_insertion(knot=p2)

        self = CP_Intersection(c1, box1.curves[0])
        p1, p2 = self.intersect_cp_segments(i=4, j=1)

        #print pval[0]
        #print curve.CurvePoint(yval[0])
        #"""
        interval_data, small = interval_bounds(curve)
        FPD = FormParameterDict(curve)
        #"""
        """
        FPD.add_yPointConstraint(kind= 'max', value=4., location=.4 )
        FPD.add_xPointConstraint(kind= 'min', value=6., location=.45 )
        FPD.add_yPointConstraint(kind= 'LS', value=4., location=.4,weight=-100. )
        FPD.add_xPointConstraint(kind= 'LS', value=6., location=.45,weight=-100. )
        #"""
        #"""
        FPD.add_AreaConstraint(kind='equality', value=curve_area)
        FPD.add_AngleConstraint(kind='equality', location=0., value=alphab)
        FPD.add_AngleConstraint(kind='equality', location=1., value=alphae)
        FPD.add_CurvatureConstraint(kind='equality', location=0., value=Cab)
        FPD.add_CurvatureConstraint(kind='equality', location=1., value=Cae)
        #"""
        #"""
        #"""
        #consistent and even August 17 2015
        #"""
        interval_data['xmin'] = [x[0]-ep, x[1]-w,  x[2]-wi, x[3]-wi, x[4]-wi, x[5]-wi, x[6]-ep] 
        interval_data['xmax'] = [x[0]+ep, x[1]+wi, x[2]+wi, x[3]+wi, x[4]+wi, x[5]+w, x[6]]
        interval_data['ymin'] = [y[0]-ep, y[1]-ep, y[2]-wi, y[3]-wi, y[6]-ep,    y[6]-ep,    y[6]-ep] 
        interval_data['ymax'] = [y[0]+ep, y[0]+ep,    y[0]+ep,    y[3]+wi, y[4]+wi, y[5]+ep, y[6]+ep]
        #"""
        #interval_data, small = lagrangian_bounds(L, interval_data, small, 1.e4)
        #"""
        interval_data['lmin'] = [-500.,-100000.,-100000.,-200000.,-200000.,-200000.]
        interval_data['lmax'] = [500.,100000.,100000.,200000.,200000.,200000.]
        #"""
        
        
        FPD = FormParameterDict(curve) 
        FPD.add_AreaConstraint(kind='equality', value = curve_area)#value = AF.fuzzyNumber(60.,70.,80.) )#
        FPD.add_AngleConstraint(kind='equality', location = 0., value = alphab)#AF.fuzzyNumber(-5.,-2.,0.))#
        FPD.add_AngleConstraint(kind='equality', location = 1., value = alphae)
        FPD.add_CurvatureConstraint(kind='equality', location = 0., value = Cab_given)
        FPD.add_CurvatureConstraint(kind='equality', location = 1., value = Cae_given)
        #"""
        FPD.add_E1(kind='LS', weight = 1.0)
        FPD.add_E2(kind='LS', weight = 0.5)
        FPD.add_E3(kind='LS', weight = 0.5)
        FPD.add_ArcLengthApprox(kind='LS', weight = 1.)
        
        L = Lagrangian(FPD)
        Lspline = IntervalLagrangeSpline(curve, L, data = interval_data)
        
#        Lspline.check_IA_correctness = True
示例#22
0
        Cab = 0.
        Cae = 0.
        xc = 4.
        yc = 4.
        curve_area = 80.
        slope = 'down'
        x_offset1 = 3.
        x_offset2 = -2.
        y_offset = 2.
        ae = alphae
        ab = alphab

        curve = initial_curve([xb, yb], [xe, ye], 16, nump=100)
        interval_data, small = interval_bounds(curve)
    if test == 'good_run':
        FPD = FormParameterDict(curve)
        FPD.add_verticalAngleConstraint(kind='equality', location=0., value=0.)
        FPD.add_xVertexConstraint(kind='equality', value=0.0, index=2)
        FPD.add_yVertexConstraint(kind='equality', value=10., index=2)
        FPD.add_xVertexConstraint(kind='equality', value=0.0, index=3)
        FPD.add_yVertexConstraint(kind='equality', value=10., index=3)
        FPD.add_yVertexConstraint(kind='equality', value=10., index=4)
        FPD.add_yPointConstraint(kind='equality', location=.15, value=10.)
        FPD.add_AngleConstraint(kind='equality', location=1., value=0.)
        FPD.add_E1(kind='LS', weight=.1)
        FPD.add_E2(kind='LS', weight=.1)
        FPD.add_E3(kind='LS', weight=.1)
        FPD.add_ArcLengthApprox(kind='LS', weight=.1)
        L = Lagrangian(FPD)
        interval_data, small = lagrangian_bounds(L, interval_data, small, 1.e4)
        Lspline = IntervalLagrangeSpline(curve, L, data=interval_data)