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
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 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
#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) ini = copy.deepcopy(Lspline) #""" #ini.curve.plotcurve_detailed() #TLM Sep 4 2017 #ini.curve.plotCurvature_spines() #ini.curve.plotCurvature_nospines(alpha=0.) box1.plot() #""" print 'doing first one' Lspline.optimize(stop = 50) curve = Lspline.curve Lspline.curve.plotcurve_detailed() Lspline.curve.plotCurvature_expensive(scale=3.5, nump=5, flip=True) Lspline.curve.plot_area_to_x_shiftaxis(shift_axis=12.) box1.plot() if True: #"""
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.333, value=12.) FPD.add_yPointConstraint(kind='equality', location=0.666, value=12.) FPD.add_E1(kind='LS', weight=.1) 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) Lspline.optimize() save1 = copy.deepcopy(Lspline.curve) curve = Lspline.curve 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.333, value=12.) FPD.add_yPointConstraint(kind='equality', location=0.666, value=12.) FPD.add_AngleConstraint(kind='equality', location=.333, value=0.) FPD.add_AngleConstraint(kind='equality', location=.666, value=0.) #FPD.add_CurvatureConstraint(kind='equality', location = 0., value = 0.) #FPD.add_CurvatureConstraint(kind='equality', location = 1., value = 0.)
# FPD.add_xVertexConstraint(kind='min', value=4.6, index=3) # #********************************************************************** FPD.add_E1(kind='LS', weight=1.) FPD.add_E2(kind='LS', weight=1.) FPD.add_E3(kind='LS', weight=1.) #FPD.add_ArcLength(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) vertices = [Lspline.curve.xpts, Lspline.curve.ypts] Lspline.compute_lagrangian(vertices, Lspline.Lagrangian) Lspline.display(mytitle='initial_basic_curve') Lspline.curve.verbose = True self = Lspline vertices = [self.curve.xpts, self.curve.ypts] vertices = Lspline.optimize(vertices, stop=100, Lagrangian=self.Lagrangian) #Lspline.display(mytitle = 'final basic curve') Lspline.curve.plotcurve_detailed() print Lspline.curve.vertices
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
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