def fini_lagrangian(FPD, this_kind='equality'): curve = FPD.curve interval_data, small = interval_bounds(curve) L = Lagrangian(FPD) interval_data, small = lagrangian_bounds(L, interval_data, small, 1.e4) Lspline = IntervalLagrangeSpline(curve, L, data=interval_data) return Lspline
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 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 init_Lspline(thbcurve, FPD): """setup THBcurve Lspline solver parameters ---------- thbcurve : a myspline.rbspline THB curve FRP : form parameter design constraint object dev ---------- thbcurve = curve """ interval_data, small = interval_bounds(thbcurve) L = Lagrangian(FPD) interval_data, small = lagrangian_bounds(L, interval_data, small, 1.e4) Lspline = IntervalLagrangeSpline(thbcurve, L, data = interval_data) 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_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) #""" #""" #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) 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,
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 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