def GetFlow(self): ''' Calculating inlet flow (coefficients of the FFT x(t)=A0+sum(2*Ck*exp(j*k*2*pi*f*t))) Timestep and period from SimulationContext are necessary. ''' try: timestep = self.SimulationContext.Context['timestep'] except KeyError: print "Error, Please set timestep in Simulation Context XML File" raise try: period = self.SimulationContext.Context['period'] except KeyError: print "Error, Please set period in Simulation Context XML File" raise t = arange(0.0,period+timestep,timestep).reshape((1,ceil(period/timestep+1.0))) Cc = self.f_coeff*1.0/2.0*1e-6 Flow = zeros((1, ceil(period/timestep+1.0))) for freq in arange(0,ceil(period/timestep+1.0)): Flow[0, freq] = self.A0_v for k in arange(0,self.f_coeff.shape[0]): Flow[0, freq] = Flow[0, freq]+real(2.0*complex(Cc[k,0],Cc[k,1])*exp(1j*(k+1)*2.0*pi*t[0,freq]/period)) self.Flow = Flow return Flow
def find_distn(lgbinwidth, numlgbins, transient, N, M_t, M_i): totspkhist = zeros((numlgbins, 1)) skiptime = transient * ms skipbin = int(ceil(skiptime / lgbinwidth)) for i in xrange(numlgbins): step_start = (i) * lgbinwidth #30*ms # step_end = (i + 1) * lgbinwidth #30*ms # for j in xrange(N): #spks=where(logical_and(M[j]>step_start, M[j]<step_end)) #totspkhist[i]+=len(M[j][spks]) totspkhist[i] += len(M_i[logical_and(M_t > step_start, M_t < step_end)]) #totspkhist_1D=reshape(totspkhist,len(totspkhist)) ###smooth plot first so thresholds work better #b,a=butter(3,0.4,'low') #totspkhist_smooth=filtfilt(b,a,totspkhist_1D) totspkhist_smooth = reshape( totspkhist, len(totspkhist) ) #here we took out the actual smoothing and left it as raw distn. #create distn based on hist, but skip first skiptime to cut out transient excessive spiking if max(totspkhist_smooth[skipbin:]) > 0: totspkdist_smooth = totspkhist_smooth / max( totspkhist_smooth[skipbin:]) else: totspkdist_smooth = totspkhist_smooth totspkhist_list = [val for subl in totspkhist for val in subl] return [totspkhist, totspkdist_smooth, totspkhist_list]
def plot_KLDiv_with_logscale(series): length = len(series) fig = plt.figure() ax = fig.gca() ax.set_xticks(np.arange(0, float(len(series))), 1) ymin = min(series) ymax = max(series) ymin = floor(ymin * 10) / 10 ymax = ceil(ymax * 10) / 10 ax.set_yticks(np.arange(ymin, ymax, 0.1)) plt.axis([0, length - 1, ymin, ymax]) fontProperties = {'family': 'sans-serif', 'sans-serif': ['Helvetica'], 'weight': 'normal', 'size': 20} rc('text', usetex=True) rc('font', **fontProperties) # ax.set_xticklabels([r'$\frac{%d}{%d}$' % (i+1, length-i) for i in range(length)], fontProperties) plt.grid() a = plt.axes() # plt.axis([0, length-1, ymin, ymax]) plt.yscale('log') c = CVALUE[COLORS[0]] m = MARKERS[0] plt.plot(list(range(len(series))), series, '-', marker=m, color=c, linewidth=2.5, markersize=12, fillstyle='full', label='Label') c = CVALUE[COLORS[1]] m = MARKERS[1] plt.plot(list(range(len(series))), series, '-', marker=m, color=c, linewidth=2.5, markersize=12, fillstyle='full', label='Label') plt.legend(loc="best") plt.ylabel(r'$F_1$') plt.xlabel(r'$k$')
def plot_fscores(labels, series): length = max(list(map(len, series))) fig = plt.figure() ax = fig.gca() ax.set_xticks(np.arange(0, float(len(series))), 1) ymin = min(list(map(min, series))) ymax = max(list(map(max, series))) ymin = floor(ymin * 10) / 10 ymax = ceil(ymax * 10) / 10 ax.set_yticks(np.arange(ymin, ymax, 0.1)) plt.axis([0, length - 1, ymin, ymax]) fontProperties = {'family': 'sans-serif', 'sans-serif': ['Helvetica'], 'weight': 'normal', 'size': 20} rc('text', usetex=True) rc('font', **fontProperties) ax.set_xticklabels( [r'$\frac{%d}{%d}$' % (i + 1, length - i) for i in range(length)], fontProperties) plt.grid() for i, [l, s] in enumerate(zip(labels, series)): c = CVALUE[COLORS[i]] plt.plot(list(range(len(s))), s, '-', marker=MARKERS[i], color=c, linewidth=2.5, markersize=12, fillstyle='full', label=l) plt.legend(loc="best") plt.ylabel(r'$F_1$') plt.xlabel(r'$k$')
def calcPhonemeDurations(self): ''' rule-based assignment of durations using Initial-Middle-final rules all consonant durations set to CONSONANT_DURATION ''' cofficinetTempo = 1 if self.phonemes is None: self.expandToPhonemes() if self.getNumPhonemes() == 0: sys.exit("syllable with no phonemes!") return #copy to local var consonant_duration = ParametersAlgo.CONSONANT_DURATION # Workaraound: reduce consonant durationInMinUnit for syllables with very short note value. while (self.getNumPhonemes() - 1) * consonant_duration >= self.durationInNumFrames: logger.warning("Syllable {} has very short durationInMinUnit: {} . reducing the fixed durationInMinUnit of consonants".format(self.text, self.durationInMinUnit) ) consonant_duration /=2 ################# ## assign durations ############# initPhoneme = self.phonemes[0] finalPhoneme = self.phonemes[-1] # if not initPhoneme.isVowel(): # initial is consonant initPhoneme.durationInNumFrames = consonant_duration if not finalPhoneme.isVowel(): # final is consonant finalPhoneme.durationInNumFrames = consonant_duration # assign middle for currPhoneme in self.phonemes[1:-1]: currPhoneme.durationInNumFrames = (self.durationInNumFrames - 2 * consonant_duration) / len(self.phonemes[1:-1]) else: # final is vowel dur = (self.durationInNumFrames - float(consonant_duration) ) / len(self.phonemes[1:]) ceilDur = int(ceil(dur)) # assign middle for currPhoneme in self.phonemes[1:-1]: currPhoneme.durationInNumFrames = ceilDur finalPhoneme.durationInNumFrames = self.durationInNumFrames - (len(self.phonemes[1:-1]) * ceilDur) else: # initial is vowel if not finalPhoneme.isVowel(): finalPhoneme.durationInNumFrames = consonant_duration # assign middle for currPhoneme in self.phonemes[:-1]: currPhoneme.durationInNumFrames = (self.durationInNumFrames - consonant_duration) / len(self.phonemes[:-1]) else: # final is vowel # assign middle for currPhoneme in self.phonemes: currPhoneme.durationInNumFrames = self.durationInNumFrames / len(self.phonemes)
def get_mean(self, frac=1): # frac between 0 and 1. 0 means take last element, 1 means take all, 5 means take half if frac <= 0: return list(self.samples)[-1] if frac >= 1: return np.mean(list(self.samples), 0) #else nr = int(max(1, ceil(len(self.samples) / frac))) return np.mean(list(self.samples)[-nr:], 0)
def get_selbins(grids, inds, c_pts, bbox): return np.minimum( grids, np.maximum( 1, ceil( (c_pts[inds,:] - np.tile(np.matrix([bbox[0], bbox[1]]),(len(inds),1)))/ np.tile(np.matrix([(bbox[2]-1)/grids, (bbox[3]-1)/grids]),(len(inds),1)) ) ) );
def get_mean(self,frac=1): # frac between 0 and 1. 0 means take last element, 1 means take all, 5 means take half if frac<=0: return list(self.samples)[-1] if frac>=1: return np.mean(list(self.samples),0) #else nr = int(max(1,ceil(len(self.samples)/frac))) return np.mean(list(self.samples)[-nr:],0)
def calcPhonemeDurations(self): ''' rule-based assignment of durations using Initial-Middle-final rules all consonant durations set to CONSONANT_DURATION ''' cofficinetTempo = 1 if self.phonemes is None: self.expandToPhonemes() if self.getNumPhonemes() == 0: sys.exit("syllable with no phonemes!") return #copy to local var consonant_duration = ParametersAlgo.CONSONANT_DURATION # Workaraound: reduce consonant durationInMinUnit for syllables with very short note value. while (self.getNumPhonemes() - 1) * consonant_duration >= self.durationInNumFrames: logger.warn("Syllable {} has very short durationInMinUnit: {} . reducing the fixed durationInMinUnit of consonants".format(self.text, self.durationInMinUnit) ) consonant_duration /=2 ################# ## assign durations ############# initPhoneme = self.phonemes[0] finalPhoneme = self.phonemes[-1] # if not initPhoneme.isVowel(): # initial is consonant initPhoneme.durationInNumFrames = consonant_duration if not finalPhoneme.isVowel(): # final is consonant finalPhoneme.durationInNumFrames = consonant_duration for currPhoneme in self.phonemes[1:-1]: currPhoneme.durationInNumFrames = (self.durationInNumFrames - 2 * consonant_duration) / len(self.phonemes[1:-1]) else: # final is vowel dur = (self.durationInNumFrames - float(consonant_duration) ) / len(self.phonemes[1:]) ceilDur = int(ceil(dur)) for currPhoneme in self.phonemes[1:-1]: currPhoneme.durationInNumFrames = ceilDur finalPhoneme.durationInNumFrames = self.durationInNumFrames - (len(self.phonemes[1:-1]) * ceilDur) else: # initial is vowel if not finalPhoneme.isVowel(): finalPhoneme.durationInNumFrames = consonant_duration for currPhoneme in self.phonemes[:-1]: currPhoneme.durationInNumFrames = (self.durationInNumFrames - consonant_duration) / len(self.phonemes[:-1]) else: # final is vowel for currPhoneme in self.phonemes: currPhoneme.durationInNumFrames = self.durationInNumFrames / len(self.phonemes)
def generate_poisson_tex(params): seed = params.seed # TODO: select seed length = params.length cell_size = params.cell_size sigma = params.smoothing_sigma intensity = params.intensity buffer_len = int(ceil(length / cell_size)) cell_size = (1.0 * length) / buffer_len buffer = zeros(shape=(buffer_len,)) def generate_inverted_colors_sequence(length): colors = zeros(shape=(length,)) for i in range(length): colors[i] = i % 2 return colors def generate_random_colors_sequence(length): return numpy.random.rand(length) events = generate_poisson_events(intensity, length) colors = generate_random_colors_sequence(len(events)) current_event = 0 for i in xrange(buffer_len): current_time = i * cell_size if current_event < len(events) - 1 and current_time > events[current_event]: # XXX current_event += 1 buffer[i] = colors[current_event] tail = 4 * sigma gaussian_filter_len = int(ceil(tail / cell_size)) xcoord = linspace(-tail, tail, gaussian_filter_len) gaussian_filter = numpy.exp(-xcoord ** 2 / (2 * sigma ** 2)) gaussian_filter = gaussian_filter / gaussian_filter.sum() buffer = loop_convolve(buffer, gaussian_filter) return Texture(buffer=buffer, cell_size=cell_size)
def middleEdge(v,w,sigma = 5): n = len(v) m = len(w) m_mid = int(ceil(m/2)) s = [-sigma*i for i in range(n)] for j in range(1,m_mid+1): s_back = s s = [0 for i in range(n) ] for i in range(1,n): sg = s_back[i-1] + blosum62[(v[i-1],w[j-1])] sd = s[i-1] - sigma sr = s_back[i] - sigma s[i] = max(sg,sd,sr) sm = -65535 smi = 0 for i in range(n): if s[i]>sm: sm = s[i] smi = i x = (smi,j) s_back = s for i in range(1,n): sg = s_back[i-1] + blosum62[(v[i-1],w[j-1])] sd = s[i-1] - sigma sr = s_back[i] - sigma s[i] = max(sg,sd,sr) sd = s_back[smi+1] sr = s[smi] sg = s[smi+1] s_max = max(sd,sg,sr) if s_max == sd: y = (smi+1,j) elif s_max == sr: y = (smi,j+1) else: y= (smi+1,j+1) return x,y
def Solve(self): ''' This method builds System Matrix and gets Solution ''' if self.SimulationContext.Id != self.NetworkMesh.Id: raise self.SimulationContext.XMLIdError() try: self.TimeStep = self.SimulationContext.Context['timestep'] self.SquareTimeStep = self.TimeStep*self.TimeStep except KeyError: print "Error, Please set timestep in Simulation Context XML File" raise try: self.Period = self.SimulationContext.Context['period'] self.TimeStepFreq = int(self.Period/self.TimeStep) except KeyError: print "Error, Please set period in Simulation Context XML File" raise try: self.Cycles = self.SimulationContext.Context['cycles'] self.NumberOfIncrements = (self.Cycles*self.TimeStepFreq) except KeyError: print "Error, Please set cycles number in Simulation Context XML File" raise history = [] assembler = Assembler() assembler.SetNetworkMesh(self.NetworkMesh) assembler.SetBoundaryConditions(self.BoundaryConditions) info = {'dofmap':assembler.DofMap,'solution':None,'incrementNumber':self.IncrementNumber,'history':history} self.Evaluator.SetInfo(info) self.PrescribedPressures = assembler.AssembleBoundaryConditions(self.SimulationContext) self.LinearZeroOrderGlobalMatrix, self.LinearFirstOrderGlobalMatrix, self.LinearSecondOrderGlobalMatrix = \ assembler.AssembleInit(self.SimulationContext, self.Evaluator) self.ZeroOrderGlobalMatrix = assembler.ZeroOrderGlobalMatrix self.FirstOrderGlobalMatrix = assembler.FirstOrderGlobalMatrix self.SecondOrderGlobalMatrix = assembler.SecondOrderGlobalMatrix NumberOfGlobalDofs = assembler.GetNumberOfGlobalDofs() # number of dofs self.UnknownPressures = arange(0,NumberOfGlobalDofs).reshape(NumberOfGlobalDofs,1) # unknown pressures self.UnknownPressures = delete(self.UnknownPressures, s_[self.PrescribedPressures[:,0]], axis=0) PressuresMatrix = zeros((NumberOfGlobalDofs, self.NumberOfIncrements)) self.p = zeros((NumberOfGlobalDofs,1)) self.pt = zeros((NumberOfGlobalDofs,1)) self.ptt = zeros((NumberOfGlobalDofs,1)) self.dp = zeros((NumberOfGlobalDofs,1)) self.ddp = zeros((NumberOfGlobalDofs,1)) self.dpt = zeros((NumberOfGlobalDofs,1)) self.ddpt = zeros((NumberOfGlobalDofs,1)) self.fe = zeros((NumberOfGlobalDofs,1)) self.fet = zeros((NumberOfGlobalDofs,1)) self.dfe = zeros((NumberOfGlobalDofs,1)) self.dfet = zeros((NumberOfGlobalDofs,1)) self.fi = zeros((NumberOfGlobalDofs,1)) self.fit = zeros((NumberOfGlobalDofs,1)) self.sumv = zeros((NumberOfGlobalDofs,1)) sumvbk = zeros((NumberOfGlobalDofs,1)) nonLinear = False for el in self.NetworkMesh.Elements: if el.IsNonLinear() == True: nonLinear = True break while self.IncrementNumber<=self.NumberOfIncrements: icc = (self.IncrementNumber%self.TimeStepFreq) if icc == 0: icc = self.TimeStepFreq #for flow in self.BoundaryConditions.elementFlow: for el in self.BoundaryConditions.elementFlow: if self.steady == True: self.Flow = assembler.BoundaryConditions.GetSteadyFlow(el, self.TimeStep,icc*self.TimeStep) else: self.Flow = assembler.BoundaryConditions.GetTimeFlow(el, icc*self.TimeStep) self.fe[assembler.FlowDof[el.Id]]= self.Flow CoeffRelax = 0.9 nltol = self.nltol self.pi = None pI = None sumvbk[:,:] = self.sumv[:,:] counter = 0 while True: #Build the algebric equation system for the increment SystemMatrix = (2.0/self.TimeStep)*self.SecondOrderGlobalMatrix + self.FirstOrderGlobalMatrix + (self.TimeStep/2.0)*self.ZeroOrderGlobalMatrix #system matrix RightVector = self.fe + (2.0/self.TimeStep)*dot(self.SecondOrderGlobalMatrix,(self.pt)) + dot(self.SecondOrderGlobalMatrix,(self.dpt)) - dot(self.ZeroOrderGlobalMatrix,(self.sumv))-(self.TimeStep/2.0)*dot(self.ZeroOrderGlobalMatrix,(self.pt)) # right hand side vector #The reduced (partioned) system of equations is generated. RightVector[:,:] = RightVector[:,:] - dot(SystemMatrix[:,self.PrescribedPressures[:,0]],self.PrescribedPressures[:,1:]) SystemMatrix = SystemMatrix[:,s_[self.UnknownPressures[:,0]]] if SystemMatrix.shape[0]> 0.0: SystemMatrix = SystemMatrix[s_[self.UnknownPressures[:,0]],:] RightVector = RightVector[s_[self.UnknownPressures[:,0]],:] #Unknown nodal point values are solved from this system. # Prescribed nodal values are inserted in the solution vector. Solution = solve(SystemMatrix,RightVector) # solutions, unknown pressures self.p[self.UnknownPressures,0] = Solution[:,:] self.p[self.PrescribedPressures[:,0],0] = self.PrescribedPressures[:,1] #Calculating derivatives. #Calculating internal nodal flow values. self.dp = dot((2.0/self.TimeStep),(self.p-self.pt)) - self.dpt self.ddp = dot((4.0/self.SquareTimeStep),(self.p-self.pt)) - dot((4.0/self.TimeStep),self.dpt) -self.ddpt self.sumv = sumvbk + dot((self.TimeStep/2.0),(self.pt+self.p)) self.fi = dot(self.SecondOrderGlobalMatrix,(self.dp)) + dot(self.FirstOrderGlobalMatrix,(self.p)) + dot(self.ZeroOrderGlobalMatrix,(self.sumv)) if not nonLinear : break if self.pi == None: self.pi = zeros((NumberOfGlobalDofs,1)) self.pi[:,:] = self.pt[:,:] pI = CoeffRelax * self.p + self.pi * (1.0-CoeffRelax) self.p[:,:] = pI[:,:] den = norm(self.pi,Inf) if den < 1e-12: den = 1.0 nlerr = norm(self.p-self.pi,Inf) / den info = {'dofmap':assembler.DofMap,'solution':[self.p, self.pt, self.ptt],'incrementNumber':self.IncrementNumber,'history':history} self.Evaluator.SetInfo(info) assembler.Assemble(self.SimulationContext, self.Evaluator, self.LinearZeroOrderGlobalMatrix, self.LinearFirstOrderGlobalMatrix, self.LinearSecondOrderGlobalMatrix) self.ZeroOrderGlobalMatrix = assembler.ZeroOrderGlobalMatrix self.FirstOrderGlobalMatrix = assembler.FirstOrderGlobalMatrix self.SecondOrderGlobalMatrix = assembler.SecondOrderGlobalMatrix #Dynamic nonlinear relaxing coefficient if counter == 100: print "relaxing..." print nlerr, nltol, CoeffRelax counter = 0 self.pi[:,:] = None self.sumv[:,:] = sumvbk[:,:] CoeffRelax *= 0.6 nltol *= 0.95 if nlerr < nltol: nltol = self.nltol counter = 0 break counter+=1 self.pi[:,:] = self.p[:,:] self.ptt[:,:] = self.pt[:,:] self.pt[:,:] = self.p[:,:] self.dpt[:,:] = self.dp[:,:] self.ddpt[:,:] = self.ddp[:,:] self.fet[:,:] = self.fe[:,:] self.fit[:,:] = self.fi[:,:] PressuresMatrix[:,(self.IncrementNumber-1)] = self.p[:,0] history.insert(0,self.IncrementNumber) history = history[:3] if self.steady == True: self.MinimumIncrementNumber = 0.01* self.NumberOfIncrements if norm(self.fi-self.fe,Inf)<self.convergence and self.IncrementNumber > self.MinimumIncrementNumber: self.IncrementNumber = self.NumberOfIncrements else: pass if self.IncrementNumber==ceil(0.05*self.NumberOfIncrements): print "->5%" if self.IncrementNumber==ceil(0.25*self.NumberOfIncrements): print "->25%" if self.IncrementNumber==ceil(0.5*self.NumberOfIncrements): print "->50%" if self.IncrementNumber==ceil(0.70*self.NumberOfIncrements): print "->70%" if self.IncrementNumber==ceil(0.90*self.NumberOfIncrements): print "->90%" if self.IncrementNumber==ceil(0.99*self.NumberOfIncrements): print "->99%" self.IncrementNumber = self.IncrementNumber+1 self.EndIncrementTime = self.EndIncrementTime + self.TimeStep # increment info = {'dofmap':assembler.DofMap,'solution':[self.p, self.pt, self.ptt],'incrementNumber':self.IncrementNumber,'history':history,'allSolution':PressuresMatrix} self.Evaluator.SetInfo(info) self.Solutions = PressuresMatrix return PressuresMatrix
def createAdvDoubleTrapezoidWing(myWing, id, cTip, cRoot, span, Sref, dfus, phiLE, dihedral, twist, xMAC25, etakf, strUID, yfus, xRoot, etaEng, tcRoot, tcTip): ''' This method creates a double trapezoid wing geometry in the 'myWing' parameter. ** Introduced a linear twist distribution from *0* at root to *twist* at tip @author: Jonas Jepsen @param myWing: wings CPACS object @param id: the VAMPzero-id of the wing @param cTip: length of chord at wing tip [m] @param cRoot: length of chord at wing root [m] @param span: span of the wing [m] @param Sref: reference area [m^2] @param dfus: fuselage diameter [m] @param phiLE: sweep angle at the leading edge [deg] @param dihedral: dihedralangle of the wing [deg] @param twist: twist of the outer wing section [deg] @param etakf: dimensionless span coordinate [-] @param strUID: the CPACS-uID of the wing ''' # sections and positionings will be created, all existing sections and positionings will be deleted mySections = wingSectionsType() myPositionings = positioningsType() # calc Lvl 1 parameters taperRatio = (cTip / cRoot) cRoot, cKink, cTip = calcWing(span, Sref, taperRatio, phiLE, etakf, dfus) # calc length from span, sweep and dihedral sweep_rad = phiLE / 180. * pi dihedral_rad = dihedral / 180. * pi # trying to correct the commented statement that uses dfus. will try to use yfus # length1 = dfus / 2. length1 = yfus length2 = (etakf * span / 2. - length1) / cos(sweep_rad) / cos(dihedral_rad) length3 = span / 2.*(1 - etakf) / cos(sweep_rad) / cos(dihedral_rad) # Increase (or reduce the twist by 4deg as that is the overall angle of incidence of the wing) twist = twist - 4. twistgrad = twist / (span / 2.) twist1 = twistgrad * length1 twist2 = twistgrad * etakf * (span / 2.) twist3 = twist createWingSection(mySections, tcRoot / 0.09, 0., 0., 0., cRoot, 1., cRoot, 0., 0., 0., 'NACA0009', 1, strUID + '_Sec1', strUID + '_Sec1', strUID + '_Sec1') createWingSection(mySections, tcRoot / 0.18, 0., 0., 0., cRoot, 1., cRoot, 0., 0., 0., 'NACA653218', 1, strUID + '_Sec2', strUID + '_Sec2', strUID + '_Sec2') createWingSection(mySections, tcTip / 0.18, 0., 0., 0., cKink, 1., cKink, 0., twist2, 0., 'NACA653218', 1, strUID + '_Sec3', strUID + '_Sec3', strUID + '_Sec3') createWingSection(mySections, tcTip / 0.18, 0., 0., 0., cTip, 1., cTip, 0., twist3, 0., 'NACA653218', 1, strUID + '_Sec4', strUID + '_Sec4', strUID + '_Sec4') createPositioning(myPositionings, str(id) + '_Pos1', None, str(id) + '_Sec1', 0., 0., 0., id) createPositioning(myPositionings, str(id) + '_Pos2', str(id) + '_Sec1', str(id) + '_Sec2', length1, 0., 0., id) createPositioning(myPositionings, str(id) + '_Pos3', str(id) + '_Sec2', str(id) + '_Sec3', length2, phiLE, dihedral, id) createPositioning(myPositionings, str(id) + '_Pos4', str(id) + '_Sec3', str(id) + '_Sec4', length3, phiLE, dihedral, id) myWing.set_sections(mySections) myWing.set_positionings(myPositionings) createWingSegments(myWing, strUID, 3) createComponentSegment(myWing, strUID) etafus = yfus / (span / 2.) # Ribs outboard of the Fuselage section are placed at 0.8 m distance nouterRibs = int(ceil((0.95 - etafus - 0.05) * span / 2. / 0.8)) createRibs(myWing.get_componentSegments().get_componentSegment()[0], strUID, 'advDoubletrapezoid', etaFus=etafus, nRibs=nouterRibs, etaEng=etaEng, span=span / 2.) createSpars(myWing.get_componentSegments().get_componentSegment()[0], strUID, 'advDoubletrapezoid', length1 / (span / 2.), etakf / cos(dihedral_rad), cTip=cTip, cRoot=cRoot) createShell(myWing.get_componentSegments().get_componentSegment()[0], strUID, 'advDoubletrapezoid') createWingFuselageAttachment(myWing.get_componentSegments().get_componentSegment()[0], strUID, 'advDoubletrapezoid') # Estimate ribNum of outer Rib iRib = int(span * (0.85 - etaEng) / (2 * 0.8)) - 1 createTanks(myWing.get_componentSegments().get_componentSegment()[0], strUID, 'advDoubletrapezoid', nRib=iRib) # calc wing position tauK = cTip / cKink etar = dfus / span # XN25F = calcXN25F(cRoot, span, phiLE, etar, etakf, tauK, taperRatio) # xRoot.py = calcXRoot(xMAC25, XN25F) # set wing x - position and twist myWing.get_transformation().get_translation().set_x(doubleBaseType(valueOf_=str(xRoot))) myWing.get_transformation().get_rotation().set_y(doubleBaseType(valueOf_=str(4.)))
def capacity_value(env, prediciton_value, cores_allocation_by_server): capacity = int(maximum(int(ceil(round((prediciton_value / float(env.reference_value) / cores_allocation_by_server), 2))), int(env.min_instance_num))) return capacity
def find_bursts(duration, dt, transient, N, M_t, M_i, max_freq): base = 2 #round lgbinwidth to nearest 2 so will always divide into durations expnum = 2.0264 * exp(-0.2656 * max_freq + 2.9288) + 5.7907 lgbinwidth = (int(base * round( (-max_freq + 33) / base))) * ms #23-good for higher freq stuff #lgbinwidth=(int(base*round((expnum)/base)))/1000 #use exptl based on some fit of choice binwidths #lgbinwidth=10*ms numlgbins = int(ceil(duration / lgbinwidth)) #totspkhist=zeros((numlgbins,1)) totspkhist = zeros(numlgbins) #totspkdist_smooth=zeros((numlgbins,1)) skiptime = transient * ms skipbin = int(ceil(skiptime / lgbinwidth)) inc_past_thresh = [] dec_past_thresh = [] #Create histogram given the bins calculated for i in xrange(numlgbins): step_start = (i) * lgbinwidth step_end = (i + 1) * lgbinwidth totspkhist[i] = len(M_i[logical_and(M_t > step_start, M_t < step_end)]) ###smooth plot first so thresholds work better #totspkhist_1D=reshape(totspkhist,len(totspkhist)) #first just reshape so single row not single colm #b,a=butter(3,0.4,'low') #totspkhist_smooth=filtfilt(b,a,totspkhist_1D) #totspkhist_smooth=reshape(totspkhist,len(totspkhist)) #here we took out the actual smoothing and left it as raw distn. here just reshape so single row not single colm totspkdist_smooth = totspkhist / max( totspkhist[skipbin:] ) #create distn based on hist, but skip first skiptime to cut out transient excessive spiking # ####### FOR MOVING THRESHOLD ################# ## find points where increases and decreases over some threshold dist_thresh = [] thresh_plot = [] mul_fac = 0.35 switch = 0 #keeps track of whether inc or dec last elim_noise = 1 / (max_freq * 2.5 * Hz) #For line 95, somehow not required in previous version? #elim_noise_units = 1/(max_freq*Hz*2.5) thresh_time = 5 / (max_freq) #capture 5 cycles thresh_ind = int(floor( (thresh_time / lgbinwidth) / 2)) #the number of indices on each side of the window #dist_thresh moves with window capturing approx 5 cycles (need special cases for borders) Find where increases and decreases past threshold (as long as a certain distance apart, based on "elim_noise" which is based on avg freq of bursts dist_thresh.append( totspkdist_smooth[skipbin:skipbin + thresh_ind].mean(0) + mul_fac * totspkdist_smooth[skipbin:skipbin + thresh_ind].std(0)) for i in xrange(1, numlgbins): step_start = (i) * lgbinwidth step_end = (i + 1) * lgbinwidth #moving threshold if i > (skipbin + thresh_ind) and (i + thresh_ind) < len(totspkdist_smooth): #print(totspkdist_smooth[i-thresh_ind:i+thresh_ind]) dist_thresh.append( totspkdist_smooth[i - thresh_ind:i + thresh_ind].mean(0) + mul_fac * totspkdist_smooth[i - thresh_ind:i + thresh_ind].std(0)) elif (i + thresh_ind) >= len(totspkdist_smooth): dist_thresh.append(totspkdist_smooth[-thresh_ind:].mean(0) + mul_fac * totspkdist_smooth[-thresh_ind:].std(0)) else: dist_thresh.append( totspkdist_smooth[skipbin:skipbin + thresh_ind].mean(0) + mul_fac * totspkdist_smooth[skipbin:skipbin + thresh_ind].std(0)) if (totspkdist_smooth[i - 1] < dist_thresh[i]) and (totspkdist_smooth[i] >= dist_thresh[i]): #inc_past_thresh.append(step_start-0.5*lgbinwidth) if (inc_past_thresh): #there has already been at least one inc, if ( abs(inc_past_thresh[-1] - (step_start - 0.5 * lgbinwidth)) > elim_noise ) and switch == 0: #must be at least x ms apart (yHz), and it was dec last.. inc_past_thresh.append( step_start - 0.5 * lgbinwidth ) #take lower point (therefore first) when increasing. Need to -0.5binwidth to adjust for shift between index of bin width and index of bin distn #print (['incr=%f'%inc_past_thresh[-1]]) thresh_plot.append(dist_thresh[i]) switch = 1 else: inc_past_thresh.append( step_start - 0.5 * lgbinwidth ) #take lower point (therefore first) when increasing. Need to -0.5binwidth to adjust for shift between index of bin width and index of bin distn thresh_plot.append(dist_thresh[i]) switch = 1 #keeps track of that it was inc. last elif (totspkdist_smooth[i - 1] >= dist_thresh[i]) and (totspkdist_smooth[i] < dist_thresh[i]): # dec_past_thresh.append(step_end-0.5*lgbinwidth) #take lower point (therefore second) when decreasing if (dec_past_thresh): #there has already been at least one dec if ( abs(dec_past_thresh[-1] - (step_end - 0.5 * lgbinwidth)) > elim_noise ) and switch == 1: #must be at least x ms apart (y Hz), and it was inc last dec_past_thresh.append( step_end - 0.5 * lgbinwidth ) #take lower point (therefore second) when decreasing #print (['decr=%f'%dec_past_thresh[-1]]) switch = 0 else: dec_past_thresh.append( step_end - 0.5 * lgbinwidth ) #take lower point (therefore second) when decreasing switch = 0 #keeps track of that it was dec last if totspkdist_smooth[0] < dist_thresh[ 0]: #if you are starting below thresh, then pop first inc. otherwise, don't (since will decrease first) if inc_past_thresh: #if list is not empty inc_past_thresh.pop(0) # ##################################################################### # ######### TO DEFINE A STATIC THRESHOLD AND FIND CROSSING POINTS # dist_thresh=0.15 #static threshold # switch=0 #keeps track of whether inc or dec last # overall_freq=3.6 #0.9 # elim_noise=1/(overall_freq*5)#2.5) # # # for i in xrange(1,numlgbins): # step_start=(i)*lgbinwidth # step_end=(i+1)*lgbinwidth # # if (totspkdist_smooth[i-1]<dist_thresh) and (totspkdist_smooth[i]>=dist_thresh): #if cross threshold (increasing) # if (inc_past_thresh): #there has already been at least one inc, # if (abs(dec_past_thresh[-1]-(step_start-0.5*lgbinwidth))>elim_noise) and switch==0: #must be at least x ms apart (yHz) from the previous dec, and it was dec last.. # inc_past_thresh.append(step_start-0.5*lgbinwidth) #take lower point (therefore first) when increasing. Need to -0.5binwidth to adjust for shift between index of bin width and index of bin distn # #print (['incr=%f'%inc_past_thresh[-1]]) #-0.5*lgbinwidth # switch=1 # else: # inc_past_thresh.append(step_start-0.5*lgbinwidth) #take lower point (therefore first) when increasing. Need to -0.5binwidth to adjust for shift between index of bin width and index of bin distn # switch=1 #keeps track of that it was inc. last # elif (totspkdist_smooth[i-1]>=dist_thresh) and (totspkdist_smooth[i]<dist_thresh): # if (dec_past_thresh): #there has already been at least one dec # if (abs(inc_past_thresh[-1]-(step_end-0.5*lgbinwidth))>elim_noise) and switch==1: #must be at least x ms apart (y Hz) from the previous incr, and it was inc last # dec_past_thresh.append(step_end-0.5*lgbinwidth) #take lower point (therefore second) when decreasing # #print (['decr=%f'%dec_past_thresh[-1]]) # switch=0 # else: # dec_past_thresh.append(step_end-0.5*lgbinwidth) #take lower point (therefore second) when decreasing # switch=0 #keeps track of that it was dec last # # # if totspkdist_smooth[0]<dist_thresh: #if you are starting below thresh, then pop first inc. otherwise, don't (since will decrease first) # if inc_past_thresh: #if list is not empty # inc_past_thresh.pop(0) ################################################################ ############################################################### ######## DEFINE INTER AND INTRA BURSTS ######## #since always start with dec, intraburst=time points from 1st inc:2nd dec, from 2nd inc:3rd dec, etc. #interburst=time points from 1st dec:1st inc, from 2nd dec:2nd inc, etc. intraburst_time_ms_compound_list = [] interburst_time_ms_compound_list = [] intraburst_bins = [] #in seconds interburst_bins = [] #print(inc_past_thresh) if len(inc_past_thresh) < len(dec_past_thresh): #if you end on a decrease for i in xrange(len(inc_past_thresh)): intraburst_time_ms_compound_list.append( arange(inc_past_thresh[i] / ms, dec_past_thresh[i + 1] / ms, 1)) #10 is timestep interburst_time_ms_compound_list.append( arange((dec_past_thresh[i] + dt) / ms, (inc_past_thresh[i] - dt) / ms, 1)) #10 is timestep intraburst_bins.append(inc_past_thresh[i]) intraburst_bins.append(dec_past_thresh[i + 1]) interburst_bins.append(dec_past_thresh[i]) interburst_bins.append(inc_past_thresh[i]) else: #if you end on an increase for i in xrange(len(inc_past_thresh) - 1): intraburst_time_ms_compound_list.append( arange(inc_past_thresh[i] / ms, dec_past_thresh[i + 1] / ms, 1)) #10 is timestep interburst_time_ms_compound_list.append( arange((dec_past_thresh[i] + dt) / ms, (inc_past_thresh[i] - dt) / ms, 1)) #10 is timestep intraburst_bins.append(inc_past_thresh[i]) intraburst_bins.append(dec_past_thresh[i + 1]) interburst_bins.append(dec_past_thresh[i] + dt) interburst_bins.append(inc_past_thresh[i] - dt) if dec_past_thresh and inc_past_thresh: #if neither dec_past_thresh nor inc_past_thresh is empty interburst_bins.append(dec_past_thresh[-1] + dt) #will have one more inter than intra interburst_bins.append(inc_past_thresh[-1] + dt) interburst_bins = interburst_bins / second intraburst_bins = intraburst_bins / second intraburst_time_ms = [ num for elem in intraburst_time_ms_compound_list for num in elem ] #flatten list interburst_time_ms = [ num for elem in interburst_time_ms_compound_list for num in elem ] #flatten list num_intraburst_bins = len( intraburst_bins ) / 2 #/2 since have both start and end points for each bin num_interburst_bins = len(interburst_bins) / 2 intraburst_bins_ms = [x * 1000 for x in intraburst_bins] interburst_bins_ms = [x * 1000 for x in interburst_bins] ###################################### #bin_s=[((inc_past_thresh-dec_past_thresh)/2+dec_past_thresh) for inc_past_thresh, dec_past_thresh in zip(inc_past_thresh,dec_past_thresh)] bin_s = [((x - y) / 2 + y) for x, y in zip(inc_past_thresh, dec_past_thresh)] / second binpt_ind = [int(floor(x / lgbinwidth)) for x in bin_s] ########## FIND PEAK TO TROUGH AND SAVE VALUES ################### ########## CATEGORIZE BURSTING BASED ON PEAK TO TROUGH VALUES ################### ########## DISCARD BINPTS IF PEAK TO TROUGH IS TOO SMALL ################### peaks = [] trough = [] peak_to_trough_diff = [] min_burst_size = 0.2 #defines a burst as 0.2 or larger. for i in xrange(len(binpt_ind) - 1): peaks.append(max(totspkdist_smooth[binpt_ind[i]:binpt_ind[i + 1]])) trough.append(min(totspkdist_smooth[binpt_ind[i]:binpt_ind[i + 1]])) peak_to_trough_diff = [ max_dist - min_dist for max_dist, min_dist in zip(peaks, trough) ] #to delete all bins following any <min_burst_size first_ind_not_burst = next( (x[0] for x in enumerate(peak_to_trough_diff) if x[1] < 0.2), None) # if first_ind_not_burst: # del bin_s[first_ind_not_burst+1:] #needs +1 since bin_s has one additional value (since counts edges) #to keep track of any bins <0.2 so can ignore in stats later all_ind_not_burst = [ x[0] for x in enumerate(peak_to_trough_diff) if x[1] < 0.2 ] #defines a burst as 0.2 or larger. bin_ms = [x * 1000 for x in bin_s] binpt_ind = [int(floor(x / lgbinwidth)) for x in bin_s] #for moving threshold only thresh_plot = [] thresh_plot = [dist_thresh[x] for x in binpt_ind] #for static threshold #thresh_plot=[dist_thresh]*len(bin_ms) # # # bin_s=[((inc_past_thresh-dec_past_thresh)/2+dec_past_thresh) for inc_past_thresh, dec_past_thresh in zip(inc_past_thresh,dec_past_thresh)] # bin_ms=[x*1000 for x in bin_s] # thresh_plot=[] # binpt_ind=[int(floor(x/lgbinwidth)) for x in bin_s] # thresh_plot=[dist_thresh[x] for x in binpt_ind] # binpts = xrange(int(lgbinwidth * 1000 / 2), int(numlgbins * lgbinwidth * 1000), int(lgbinwidth * 1000)) totspkhist_list = totspkhist.tolist( ) #[val for subl in totspkhist for val in subl] #find first index after transient to see if have enough bins to do stats bin_ind_no_trans = bisect.bisect(bin_ms, transient) intrabin_ind_no_trans = bisect.bisect(intraburst_bins, transient / 1000) #transient to seconds if intrabin_ind_no_trans % 2 != 0: #index must be even since format is ind0=start_bin, ind1=end_bin, ind2=start_bin, .... . intrabin_ind_no_trans += 1 interbin_ind_no_trans = bisect.bisect(interburst_bins, transient / 1000) if interbin_ind_no_trans % 2 != 0: interbin_ind_no_trans += 1 return [ bin_s, bin_ms, binpts, totspkhist, totspkdist_smooth, dist_thresh, totspkhist_list, thresh_plot, binpt_ind, lgbinwidth, numlgbins, intraburst_bins, interburst_bins, intraburst_bins_ms, interburst_bins_ms, intraburst_time_ms, interburst_time_ms, num_intraburst_bins, num_interburst_bins, bin_ind_no_trans, intrabin_ind_no_trans, interbin_ind_no_trans ]
def Solve(self): ''' This method builds System Matrix and gets Solution ''' if self.SimulationContext.Id != self.NetworkMesh.Id: raise self.SimulationContext.XMLIdError() try: self.TimeStep = self.SimulationContext.Context['timestep'] self.SquareTimeStep = self.TimeStep * self.TimeStep except KeyError: print "Error, Please set timestep in Simulation Context XML File" raise try: self.Period = self.SimulationContext.Context['period'] self.TimeStepFreq = int(self.Period / self.TimeStep) except KeyError: print "Error, Please set period in Simulation Context XML File" raise try: self.Cycles = self.SimulationContext.Context['cycles'] self.NumberOfIncrements = (self.Cycles * self.TimeStepFreq) except KeyError: print "Error, Please set cycles number in Simulation Context XML File" raise history = [] assembler = Assembler() assembler.SetNetworkMesh(self.NetworkMesh) assembler.SetBoundaryConditions(self.BoundaryConditions) info = { 'dofmap': assembler.DofMap, 'solution': None, 'incrementNumber': self.IncrementNumber, 'history': history } self.Evaluator.SetInfo(info) self.PrescribedPressures = assembler.AssembleBoundaryConditions( self.SimulationContext) self.LinearZeroOrderGlobalMatrix, self.LinearFirstOrderGlobalMatrix, self.LinearSecondOrderGlobalMatrix = \ assembler.AssembleInit(self.SimulationContext, self.Evaluator) self.ZeroOrderGlobalMatrix = assembler.ZeroOrderGlobalMatrix self.FirstOrderGlobalMatrix = assembler.FirstOrderGlobalMatrix self.SecondOrderGlobalMatrix = assembler.SecondOrderGlobalMatrix NumberOfGlobalDofs = assembler.GetNumberOfGlobalDofs( ) # number of dofs self.UnknownPressures = arange(0, NumberOfGlobalDofs).reshape( NumberOfGlobalDofs, 1) # unknown pressures self.UnknownPressures = delete(self.UnknownPressures, s_[self.PrescribedPressures[:, 0]], axis=0) PressuresMatrix = zeros((NumberOfGlobalDofs, self.NumberOfIncrements)) self.p = zeros((NumberOfGlobalDofs, 1)) self.pt = zeros((NumberOfGlobalDofs, 1)) self.ptt = zeros((NumberOfGlobalDofs, 1)) self.dp = zeros((NumberOfGlobalDofs, 1)) self.ddp = zeros((NumberOfGlobalDofs, 1)) self.dpt = zeros((NumberOfGlobalDofs, 1)) self.ddpt = zeros((NumberOfGlobalDofs, 1)) self.fe = zeros((NumberOfGlobalDofs, 1)) self.fet = zeros((NumberOfGlobalDofs, 1)) self.dfe = zeros((NumberOfGlobalDofs, 1)) self.dfet = zeros((NumberOfGlobalDofs, 1)) self.fi = zeros((NumberOfGlobalDofs, 1)) self.fit = zeros((NumberOfGlobalDofs, 1)) self.sumv = zeros((NumberOfGlobalDofs, 1)) sumvbk = zeros((NumberOfGlobalDofs, 1)) nonLinear = False for el in self.NetworkMesh.Elements: if el.IsNonLinear() == True: nonLinear = True break while self.IncrementNumber <= self.NumberOfIncrements: icc = (self.IncrementNumber % self.TimeStepFreq) if icc == 0: icc = self.TimeStepFreq #for flow in self.BoundaryConditions.elementFlow: for el in self.BoundaryConditions.elementFlow: if self.steady == True: self.Flow = assembler.BoundaryConditions.GetSteadyFlow( el, self.TimeStep, icc * self.TimeStep) else: self.Flow = assembler.BoundaryConditions.GetTimeFlow( el, icc * self.TimeStep) self.fe[assembler.FlowDof[el.Id]] = self.Flow CoeffRelax = 0.9 nltol = self.nltol self.pi = None pI = None sumvbk[:, :] = self.sumv[:, :] counter = 0 while True: #Build the algebric equation system for the increment SystemMatrix = ( 2.0 / self.TimeStep ) * self.SecondOrderGlobalMatrix + self.FirstOrderGlobalMatrix + ( self.TimeStep / 2.0) * self.ZeroOrderGlobalMatrix #system matrix RightVector = self.fe + (2.0 / self.TimeStep) * dot( self.SecondOrderGlobalMatrix, (self.pt)) + dot( self.SecondOrderGlobalMatrix, (self.dpt)) - dot( self.ZeroOrderGlobalMatrix, (self.sumv)) - (self.TimeStep / 2.0) * dot( self.ZeroOrderGlobalMatrix, (self.pt)) # right hand side vector #The reduced (partioned) system of equations is generated. RightVector[:, :] = RightVector[:, :] - dot( SystemMatrix[:, self.PrescribedPressures[:, 0]], self.PrescribedPressures[:, 1:]) SystemMatrix = SystemMatrix[:, s_[self.UnknownPressures[:, 0]]] if SystemMatrix.shape[0] > 0.0: SystemMatrix = SystemMatrix[ s_[self.UnknownPressures[:, 0]], :] RightVector = RightVector[s_[self.UnknownPressures[:, 0]], :] #Unknown nodal point values are solved from this system. # Prescribed nodal values are inserted in the solution vector. Solution = solve(SystemMatrix, RightVector) # solutions, unknown pressures self.p[self.UnknownPressures, 0] = Solution[:, :] self.p[self.PrescribedPressures[:, 0], 0] = self.PrescribedPressures[:, 1] #Calculating derivatives. #Calculating internal nodal flow values. self.dp = dot((2.0 / self.TimeStep), (self.p - self.pt)) - self.dpt self.ddp = dot((4.0 / self.SquareTimeStep), (self.p - self.pt)) - dot( (4.0 / self.TimeStep), self.dpt) - self.ddpt self.sumv = sumvbk + dot((self.TimeStep / 2.0), (self.pt + self.p)) self.fi = dot(self.SecondOrderGlobalMatrix, (self.dp)) + dot( self.FirstOrderGlobalMatrix, (self.p)) + dot(self.ZeroOrderGlobalMatrix, (self.sumv)) if not nonLinear: break if self.pi == None: self.pi = zeros((NumberOfGlobalDofs, 1)) self.pi[:, :] = self.pt[:, :] pI = CoeffRelax * self.p + self.pi * (1.0 - CoeffRelax) self.p[:, :] = pI[:, :] den = norm(self.pi, Inf) if den < 1e-12: den = 1.0 nlerr = norm(self.p - self.pi, Inf) / den info = { 'dofmap': assembler.DofMap, 'solution': [self.p, self.pt, self.ptt], 'incrementNumber': self.IncrementNumber, 'history': history } self.Evaluator.SetInfo(info) assembler.Assemble(self.SimulationContext, self.Evaluator, self.LinearZeroOrderGlobalMatrix, self.LinearFirstOrderGlobalMatrix, self.LinearSecondOrderGlobalMatrix) self.ZeroOrderGlobalMatrix = assembler.ZeroOrderGlobalMatrix self.FirstOrderGlobalMatrix = assembler.FirstOrderGlobalMatrix self.SecondOrderGlobalMatrix = assembler.SecondOrderGlobalMatrix #Dynamic nonlinear relaxing coefficient if counter == 100: print "relaxing..." print nlerr, nltol, CoeffRelax counter = 0 self.pi[:, :] = None self.sumv[:, :] = sumvbk[:, :] CoeffRelax *= 0.6 nltol *= 0.95 if nlerr < nltol: nltol = self.nltol counter = 0 break counter += 1 self.pi[:, :] = self.p[:, :] self.ptt[:, :] = self.pt[:, :] self.pt[:, :] = self.p[:, :] self.dpt[:, :] = self.dp[:, :] self.ddpt[:, :] = self.ddp[:, :] self.fet[:, :] = self.fe[:, :] self.fit[:, :] = self.fi[:, :] PressuresMatrix[:, (self.IncrementNumber - 1)] = self.p[:, 0] history.insert(0, self.IncrementNumber) history = history[:3] if self.steady == True: self.MinimumIncrementNumber = 0.01 * self.NumberOfIncrements if norm( self.fi - self.fe, Inf ) < self.convergence and self.IncrementNumber > self.MinimumIncrementNumber: self.IncrementNumber = self.NumberOfIncrements else: pass if self.IncrementNumber == ceil(0.05 * self.NumberOfIncrements): print "->5%" if self.IncrementNumber == ceil(0.25 * self.NumberOfIncrements): print "->25%" if self.IncrementNumber == ceil(0.5 * self.NumberOfIncrements): print "->50%" if self.IncrementNumber == ceil(0.70 * self.NumberOfIncrements): print "->70%" if self.IncrementNumber == ceil(0.90 * self.NumberOfIncrements): print "->90%" if self.IncrementNumber == ceil(0.99 * self.NumberOfIncrements): print "->99%" self.IncrementNumber = self.IncrementNumber + 1 self.EndIncrementTime = self.EndIncrementTime + self.TimeStep # increment info = { 'dofmap': assembler.DofMap, 'solution': [self.p, self.pt, self.ptt], 'incrementNumber': self.IncrementNumber, 'history': history, 'allSolution': PressuresMatrix } self.Evaluator.SetInfo(info) self.Solutions = PressuresMatrix return PressuresMatrix
def createRibs(parent, parentUID, typeOfSeg, thickness=0.03, pitch=.8, nRibs=None, etaFus=0.2, etaEng=.3, span=17., fanDiameter=1.9, etaStrut=0.0, phi25 = 0.0): ''' Used for generation of a ribs definition in the wing @param parent: ComponentSegment object, ribsDefinition will be added here @param thickness: thickness of the ribs @param pitch: pitch of the ribs @param typeOfSeg: either advDoubleTrapezoid or trapezoid ''' myUID = parentUID + '_ribs' ribsList = [] #=============================================================================== # Advanced Double Trapezoid #=============================================================================== if typeOfSeg.lower() == 'advdoubletrapezoid': myName = stringBaseType(valueOf_='wing_ribs') # Rib Cross Section #======================================================================= myMaterial = materialDefinitionType(materialUID=stringUIDBaseType(valueOf_='aluminium7075'), thickness=doubleBaseType(valueOf_=str(thickness))) myCrossSection = wingRibCrossSectionType(material=myMaterial) ribReference = stringBaseType(valueOf_=parentUID + '_Spar_FS') ribStart = stringBaseType(valueOf_=parentUID + '_Spar_FS') ribEnd = stringBaseType(valueOf_=parentUID + '_Spar_RS') ribRotation = ribRotationType(ribRotationReference=stringBaseType(valueOf_='globalY'), z=doubleBaseType(valueOf_=str('90.'))) ribCrossing = ribCrossingBehaviourType(valueOf_='cross') #======================================================================= # First set of 4 ribs inside the fuselage #======================================================================= etaStart = doubleBaseType(valueOf_='0.0') etaEnd = doubleBaseType(valueOf_=str(etaFus)) innerRibs = doubleBaseType(valueOf_= 4) ribsPositioning = wingRibsPositioningType(ribReference=ribReference, etaStart=etaStart, etaEnd=etaEnd, ribStart=ribStart, ribEnd=ribEnd, \ numberOfRibs=innerRibs, ribCrossingBehaviour=ribCrossing, ribRotation=ribRotation) myUID = parentUID + '_ribs_inner' ribsList.append(wingRibsDefinitionType(uID=myUID, name=myName, ribsPositioning=ribsPositioning, ribCrossSection=myCrossSection)) #=============================================================== # Second set outside of the fuselage up to the engine #=============================================================== etaPylon = 1. / 10. * fanDiameter / span etaStart = doubleBaseType(valueOf_=str(etaFus + pitch / span)) etaEnd = doubleBaseType(valueOf_=str(etaEng - etaPylon)) middleRibs = int(ceil((etaEng - etaPylon - etaFus) * span / pitch)) - 1 if middleRibs < 1: middleRibs = 1 middleRibs = doubleBaseType(valueOf_=middleRibs) ribsPositioning = wingRibsPositioningType(ribReference=ribReference, etaStart=etaStart, etaEnd=etaEnd, ribStart=ribStart, ribEnd=ribEnd, \ numberOfRibs=middleRibs, ribCrossingBehaviour=ribCrossing, ribRotation=ribRotation) myUID = parentUID + '_ribs_engine1' ribsList.append(wingRibsDefinitionType(uID=myUID, name=myName, ribsPositioning=ribsPositioning, ribCrossSection=myCrossSection)) #=============================================================== # Third set one ribs outside of the pylon #=============================================================== etaEnd = doubleBaseType(valueOf_= str(etaEng + etaPylon)) pylonRibs = doubleBaseType(valueOf_= str(1)) ribsPositioning = wingRibsPositioningType(ribReference=ribReference, etaStart=etaStart, etaEnd=etaEnd, ribStart=ribStart, ribEnd=ribEnd, \ numberOfRibs=pylonRibs, ribCrossingBehaviour=ribCrossing, ribRotation=ribRotation) myUID = parentUID + '_ribs_engine2' ribsList.append(wingRibsDefinitionType(uID=myUID, name=myName, ribsPositioning=ribsPositioning, ribCrossSection=myCrossSection)) #=============================================================== # Fourth set outside of the engine #=============================================================== etaStart = doubleBaseType(valueOf_= str(etaEng + etaPylon + pitch / span)) etaEnd = doubleBaseType(valueOf_= '0.95') ribCrossing = ribCrossingBehaviourType(valueOf_='end') ribRotation = ribRotationType(ribRotationReference=stringBaseType(valueOf_='wing_Spar_FS'), \ z=doubleBaseType(valueOf_='90.')) outerRibs = int(ceil((0.95 - etaEng + etaPylon) * span / pitch)) - 1 outerRibs = doubleBaseType(valueOf_= outerRibs) ribsPositioning = wingRibsPositioningType(ribReference=ribReference, etaStart=etaStart, etaEnd=etaEnd, ribStart=ribStart, ribEnd=ribEnd, \ numberOfRibs=outerRibs, ribCrossingBehaviour=ribCrossing, ribRotation=ribRotation) myUID = parentUID + '_ribs_outer' ribsList.append(wingRibsDefinitionType(uID=myUID, name=myName, ribsPositioning=ribsPositioning, ribCrossSection=myCrossSection)) #=============================================================================== # Strut Braced Wing #=============================================================================== if typeOfSeg.lower() == 'strutbracedwing': myName = stringBaseType(valueOf_='wing_ribs') # Rib Cross Section #======================================================================= myMaterial = materialDefinitionType(materialUID=stringUIDBaseType(valueOf_='aluminium7075'), thickness=doubleBaseType(valueOf_=str(thickness))) myCrossSection = wingRibCrossSectionType(material=myMaterial) ribReference = stringBaseType(valueOf_=parentUID + '_Spar_FS') ribStart = stringBaseType(valueOf_=parentUID + '_Spar_FS') ribEnd = stringBaseType(valueOf_=parentUID + '_Spar_RS') ribRotation = ribRotationType(ribRotationReference=stringBaseType(valueOf_='globalY'), z=doubleBaseType(valueOf_=str('90.'))) ribCrossing = ribCrossingBehaviourType(valueOf_='cross') #======================================================================= # First set of 4 ribs inside the fuselage #======================================================================= etaStart = doubleBaseType(valueOf_='0.0') etaEnd = doubleBaseType(valueOf_=str(etaFus)) innerRibs = doubleBaseType(valueOf_=4) ribsPositioning = wingRibsPositioningType(ribReference=ribReference, etaStart=etaStart, etaEnd=etaEnd, ribStart=ribStart, ribEnd=ribEnd, \ numberOfRibs=innerRibs, ribCrossingBehaviour=ribCrossing, ribRotation=ribRotation) myUID = parentUID + '_ribs_inner' ribsList.append(wingRibsDefinitionType(uID=myUID, name=myName, ribsPositioning=ribsPositioning, ribCrossSection=myCrossSection)) #=============================================================== # Second set outside of the fuselage up to the strut #=============================================================== etaStart = doubleBaseType(valueOf_=str(etaFus + pitch / span + phi25 * 0.0002)) etaEnd = doubleBaseType(valueOf_=str(etaStrut)) middleRibs = int(ceil((etaStrut - etaFus) * span / pitch)) - 1 middleRibs = doubleBaseType(valueOf_=middleRibs) ribsPositioning = wingRibsPositioningType(ribReference=ribReference, etaStart=etaStart, etaEnd=etaEnd, ribStart=ribStart, ribEnd=ribEnd, \ numberOfRibs=middleRibs, ribCrossingBehaviour=ribCrossing, ribRotation=ribRotation) myUID = parentUID + '_ribs_strut' ribsList.append(wingRibsDefinitionType(uID=myUID, name=myName, ribsPositioning=ribsPositioning, ribCrossSection=myCrossSection)) #=============================================================== # Third set outside of the spar #=============================================================== etaStart = doubleBaseType(valueOf_=str(etaStrut + pitch / span)) etaEnd = doubleBaseType(valueOf_='0.95') ribCrossing = ribCrossingBehaviourType(valueOf_='end') ribRotation = ribRotationType(ribRotationReference=stringBaseType(valueOf_='wing_Spar_FS'), z=doubleBaseType(valueOf_=str('90.'))) outerRibs = int(ceil((0.95 - etaStrut) * span / pitch)) - 1 outerRibs = doubleBaseType(valueOf_=outerRibs) ribsPositioning = wingRibsPositioningType(ribReference=ribReference, etaStart=etaStart, etaEnd=etaEnd, ribStart=ribStart, ribEnd=ribEnd, \ numberOfRibs=outerRibs, ribCrossingBehaviour=ribCrossing, ribRotation=ribRotation) myUID = parentUID + '_ribs_outer' ribsList.append(wingRibsDefinitionType(uID=myUID, name=myName, ribsPositioning=ribsPositioning, ribCrossSection=myCrossSection)) #=============================================================================== # Strut (And only the strut not the wing that goes along with it) #=============================================================================== if typeOfSeg.lower() == 'strut': myName = stringBaseType(valueOf_='strut_ribs') # Rib Cross Section #======================================================================= #myMaterial = materialDefinitionType(compositeUID=stringUIDBaseType(isLink='True',valueOf_='Comp_Shear'), orthotropyDirection=doubleBaseType(valueOf_='0.'),\ # thicknessScaling=doubleBaseType(valueOf_='0.001')) myMaterial = materialDefinitionType(materialUID=stringUIDBaseType(valueOf_='aluminium7075'), thickness=doubleBaseType(valueOf_=str(thickness))) myCrossSection = wingRibCrossSectionType(material=myMaterial) ribReference = stringBaseType(valueOf_='leadingEdge') ribStart = stringBaseType(valueOf_='leadingEdge') ribEnd = stringBaseType(valueOf_='trailingEdge') ribRotation = ribRotationType(ribRotationReference=stringBaseType(valueOf_='globalY'), z=doubleBaseType(valueOf_=str('90.'))) ribCrossing = ribCrossingBehaviourType(valueOf_='cross') etaStart = doubleBaseType(valueOf_=str(0.)) etaEnd = doubleBaseType(valueOf_=str(1.)) middleRibs = doubleBaseType(valueOf_=5.) ribsPositioning = wingRibsPositioningType(ribReference=ribReference, etaStart=etaStart, etaEnd=etaEnd, ribStart=ribStart, ribEnd=ribEnd, \ numberOfRibs=middleRibs, ribCrossingBehaviour=ribCrossing, ribRotation=ribRotation) myUID = parentUID + '_ribs' ribsList.append(wingRibsDefinitionType(uID=myUID, name=myName, ribsPositioning=ribsPositioning, ribCrossSection=myCrossSection)) #=============================================================================== # Aileron #=============================================================================== if typeOfSeg.lower() == 'aileron': myName = stringBaseType(valueOf_='aileron_ribs') # Rib Cross Section #======================================================================= myMaterial = materialDefinitionType(materialUID=stringUIDBaseType(valueOf_='aluminium7075'), thickness=doubleBaseType(valueOf_=str(thickness))) myCrossSection = wingRibCrossSectionType(material= myMaterial) # Rib Positioning #======================================================================= etaStart = doubleBaseType(valueOf_='0.') etaEnd = doubleBaseType(valueOf_='1.') ribReference = stringBaseType(valueOf_=parentUID + '_Spar_FS') ribStart = stringBaseType(valueOf_='leadingEdge') ribEnd = stringBaseType(valueOf_='trailingEdge') ribRotation = ribRotationType(ribRotationReference=stringBaseType(valueOf_='globalY'), z=doubleBaseType(valueOf_=str('90.'))) ribCrossing = ribCrossingBehaviourType(valueOf_='cross') if nRibs is None: ribSpacing = doubleBaseType(valueOf_=pitch) ribsPositioning = wingRibsPositioningType(ribReference=ribReference, etaStart=etaStart, etaEnd=etaEnd, ribStart=ribStart, ribEnd=ribEnd, \ spacing=ribSpacing, ribCrossingBehaviour=ribCrossing, ribRotation=ribRotation) else: nRibs = doubleBaseType(valueOf_=nRibs) ribsPositioning = wingRibsPositioningType(ribReference=ribReference, etaStart=etaStart, etaEnd=etaEnd, ribStart=ribStart, ribEnd=ribEnd, \ numberOfRibs=nRibs, ribCrossingBehaviour=ribCrossing, ribRotation=ribRotation) ribsList.append(wingRibsDefinitionType(uID=myUID, name=myName, ribsPositioning=ribsPositioning, ribCrossSection=myCrossSection)) if typeOfSeg.lower() == 'trapezoid': myName = stringBaseType(valueOf_='trapezoid_ribs') # Rib Cross Section #======================================================================= myMaterial = materialDefinitionType(materialUID=stringUIDBaseType(valueOf_='aluminium7075'), thickness=doubleBaseType(valueOf_=str(thickness))) myCrossSection = wingRibCrossSectionType(material= myMaterial) # Rib Positioning #======================================================================= etaStart = doubleBaseType(valueOf_='0.') etaEnd = doubleBaseType(valueOf_='1.') ribReference = stringBaseType(valueOf_=parentUID + '_Spar_FS') ribStart = stringBaseType(valueOf_='leadingEdge') ribEnd = stringBaseType(valueOf_='trailingEdge') ribRotation = ribRotationType(ribRotationReference=stringBaseType(valueOf_='globalY'), z=doubleBaseType(valueOf_=str('90.'))) ribCrossing = ribCrossingBehaviourType(valueOf_='cross') middleRibs = doubleBaseType(valueOf_=5.) ribsPositioning = wingRibsPositioningType(ribReference=ribReference, etaStart=etaStart, etaEnd=etaEnd, ribStart=ribStart, ribEnd=ribEnd, \ numberOfRibs=middleRibs, ribCrossingBehaviour=ribCrossing, ribRotation=ribRotation) ribsList.append(wingRibsDefinitionType(uID=myUID, name=myName, ribsPositioning=ribsPositioning, ribCrossSection=myCrossSection)) #=============================================================================== # Flap #=============================================================================== if typeOfSeg.lower() == 'flap' or typeOfSeg.lower() == 'innerflap': myName = stringBaseType(valueOf_='flap_ribs') # Rib Cross Section #======================================================================= myMaterial = materialDefinitionType(materialUID=stringUIDBaseType(valueOf_='aluminium7075'), thickness=doubleBaseType(valueOf_=str(thickness))) myCrossSection = wingRibCrossSectionType(material= myMaterial) # Rib Positioning #======================================================================= etaStart = doubleBaseType(valueOf_='0.') etaEnd = doubleBaseType(valueOf_='1.') ribReference = stringBaseType(valueOf_=parentUID + '_Spar_FS') ribStart = stringBaseType(valueOf_='leadingEdge') ribEnd = stringBaseType(valueOf_='trailingEdge') ribRotation = ribRotationType(ribRotationReference=stringBaseType(valueOf_='globalY'), z=doubleBaseType(valueOf_=str('90.'))) ribCrossing = ribCrossingBehaviourType(valueOf_='cross') if nRibs is None: ribSpacing = doubleBaseType(valueOf_=pitch) ribsPositioning = wingRibsPositioningType(ribReference=ribReference, etaStart=etaStart, etaEnd=etaEnd, ribStart=ribStart, ribEnd=ribEnd, \ spacing=ribSpacing, ribCrossingBehaviour=ribCrossing, ribRotation=ribRotation) else: nRibs = doubleBaseType(valueOf_=nRibs) ribsPositioning = wingRibsPositioningType(ribReference=ribReference, etaStart=etaStart, etaEnd=etaEnd, ribStart=ribStart, ribEnd=ribEnd, \ numberOfRibs=nRibs, ribCrossingBehaviour=ribCrossing, ribRotation=ribRotation) ribsList.append(wingRibsDefinitionType(uID=myUID, name=myName, ribsPositioning=ribsPositioning, ribCrossSection=myCrossSection)) #=============================================================================== # Spoiler #=============================================================================== if typeOfSeg.lower() == 'spoiler': myName = stringBaseType(valueOf_='spoiler_ribs') # Rib Cross Section #======================================================================= myMaterial = materialDefinitionType(materialUID=stringUIDBaseType(valueOf_='aluminium7075'), thickness=doubleBaseType(valueOf_=str(thickness))) myCrossSection = wingRibCrossSectionType(material= myMaterial) # Rib Positioning #======================================================================= etaStart = doubleBaseType(valueOf_='0.') etaEnd = doubleBaseType(valueOf_='1.') ribReference = stringBaseType(valueOf_='leadingEdge') ribStart = stringBaseType(valueOf_='leadingEdge') ribEnd = stringBaseType(valueOf_='trailingEdge') ribRotation = ribRotationType(ribRotationReference=stringBaseType(valueOf_='globalY'), z=doubleBaseType(valueOf_=str('90.'))) ribCrossing = ribCrossingBehaviourType(valueOf_='cross') if nRibs is None: ribSpacing = doubleBaseType(valueOf_=pitch) ribsPositioning = wingRibsPositioningType(ribReference=ribReference, etaStart=etaStart, etaEnd=etaEnd, ribStart=ribStart, ribEnd=ribEnd, \ spacing=ribSpacing, ribCrossingBehaviour=ribCrossing, ribRotation=ribRotation) else: nRibs = doubleBaseType(valueOf_=nRibs) ribsPositioning = wingRibsPositioningType(ribReference=ribReference, etaStart=etaStart, etaEnd=etaEnd, ribStart=ribStart, ribEnd=ribEnd, \ numberOfRibs=nRibs, ribCrossingBehaviour=ribCrossing, ribRotation=ribRotation) ribsList.append(wingRibsDefinitionType(uID=myUID, name=myName, ribsPositioning=ribsPositioning, ribCrossSection=myCrossSection)) #======================================================================= # RibsDefinition #======================================================================= myRibsDefinitions = wingRibsDefinitionsType(None, None, None, ribsList) parent.get_structure().set_ribsDefinitions(myRibsDefinitions)
def createAdvDoubleTrapezoidWing(myWing, id, cTip, cRoot, span, Sref, dfus, phiLE, dihedral, twist, xMAC25, etakf, strUID, yfus, xRoot, etaEng, tcRoot, tcTip): ''' This method creates a double trapezoid wing geometry in the 'myWing' parameter. ** Introduced a linear twist distribution from *0* at root to *twist* at tip @author: Jonas Jepsen @param myWing: wings CPACS object @param id: the VAMPzero-id of the wing @param cTip: length of chord at wing tip [m] @param cRoot: length of chord at wing root [m] @param span: span of the wing [m] @param Sref: reference area [m^2] @param dfus: fuselage diameter [m] @param phiLE: sweep angle at the leading edge [deg] @param dihedral: dihedralangle of the wing [deg] @param twist: twist of the outer wing section [deg] @param etakf: dimensionless span coordinate [-] @param strUID: the CPACS-uID of the wing ''' # sections and positionings will be created, all existing sections and positionings will be deleted mySections = wingSectionsType() myPositionings = positioningsType() # calc Lvl 1 parameters taperRatio = (cTip / cRoot) cRoot, cKink, cTip = calcWing(span, Sref, taperRatio, phiLE, etakf, dfus) # calc length from span, sweep and dihedral sweep_rad = phiLE / 180. * pi dihedral_rad = dihedral / 180. * pi # trying to correct the commented statement that uses dfus. will try to use yfus # length1 = dfus / 2. length1 = yfus length2 = (etakf * span / 2. - length1) / cos(sweep_rad) / cos(dihedral_rad) length3 = span / 2. * (1 - etakf) / cos(sweep_rad) / cos(dihedral_rad) # Increase (or reduce the twist by 4deg as that is the overall angle of incidence of the wing) twist = twist - 4. twistgrad = twist / (span / 2.) twist1 = twistgrad * length1 twist2 = twistgrad * etakf * (span / 2.) twist3 = twist createWingSection(mySections, tcRoot / 0.09, 0., 0., 0., cRoot, 1., cRoot, 0., 0., 0., 'NACA0009', 1, strUID + '_Sec1', strUID + '_Sec1', strUID + '_Sec1') createWingSection(mySections, tcRoot / 0.18, 0., 0., 0., cRoot, 1., cRoot, 0., 0., 0., 'NACA653218', 1, strUID + '_Sec2', strUID + '_Sec2', strUID + '_Sec2') createWingSection(mySections, tcTip / 0.18, 0., 0., 0., cKink, 1., cKink, 0., twist2, 0., 'NACA653218', 1, strUID + '_Sec3', strUID + '_Sec3', strUID + '_Sec3') createWingSection(mySections, tcTip / 0.18, 0., 0., 0., cTip, 1., cTip, 0., twist3, 0., 'NACA653218', 1, strUID + '_Sec4', strUID + '_Sec4', strUID + '_Sec4') createPositioning(myPositionings, str(id) + '_Pos1', None, str(id) + '_Sec1', 0., 0., 0., id) createPositioning(myPositionings, str(id) + '_Pos2', str(id) + '_Sec1', str(id) + '_Sec2', length1, 0., 0., id) createPositioning(myPositionings, str(id) + '_Pos3', str(id) + '_Sec2', str(id) + '_Sec3', length2, phiLE, dihedral, id) createPositioning(myPositionings, str(id) + '_Pos4', str(id) + '_Sec3', str(id) + '_Sec4', length3, phiLE, dihedral, id) myWing.set_sections(mySections) myWing.set_positionings(myPositionings) createWingSegments(myWing, strUID, 3) createComponentSegment(myWing, strUID) etafus = yfus / (span / 2.) # Ribs outboard of the Fuselage section are placed at 0.8 m distance nouterRibs = int(ceil((0.95 - etafus - 0.05) * span / 2. / 0.8)) createRibs(myWing.get_componentSegments().get_componentSegment()[0], strUID, 'advDoubletrapezoid', etaFus=etafus, nRibs=nouterRibs, etaEng=etaEng, span=span / 2.) createSpars(myWing.get_componentSegments().get_componentSegment()[0], strUID, 'advDoubletrapezoid', length1 / (span / 2.), etakf / cos(dihedral_rad), cTip=cTip, cRoot=cRoot) createShell(myWing.get_componentSegments().get_componentSegment()[0], strUID, 'advDoubletrapezoid') createWingFuselageAttachment( myWing.get_componentSegments().get_componentSegment()[0], strUID, 'advDoubletrapezoid') # Estimate ribNum of outer Rib iRib = int(span * (0.85 - etaEng) / (2 * 0.8)) - 1 createTanks(myWing.get_componentSegments().get_componentSegment()[0], strUID, 'advDoubletrapezoid', nRib=iRib) # calc wing position tauK = cTip / cKink etar = dfus / span # XN25F = calcXN25F(cRoot, span, phiLE, etar, etakf, tauK, taperRatio) # xRoot.py = calcXRoot(xMAC25, XN25F) # set wing x - position and twist myWing.get_transformation().get_translation().set_x( doubleBaseType(None, None, None, str(xRoot))) myWing.get_transformation().get_rotation().set_y( doubleBaseType(None, None, None, str(4.)))
def createRibs(parent, parentUID, typeOfSeg, thickness=0.03, pitch=.8, nRibs=None, etaFus=0.2, etaEng=.3, span=17., fanDiameter=1.9, etaStrut=0.0, phi25=0.0): ''' Used for generation of a ribs definition in the wing @param parent: ComponentSegment object, ribsDefinition will be added here @param thickness: thickness of the ribs @param pitch: pitch of the ribs @param typeOfSeg: either advDoubleTrapezoid or trapezoid ''' myUID = parentUID + '_ribs' ribsList = [] #=============================================================================== # Advanced Double Trapezoid #=============================================================================== if typeOfSeg.lower() == 'advdoubletrapezoid': myName = stringBaseType(None, None, None, 'wing_ribs') # Rib Cross Section #======================================================================= myMaterial = materialDefinitionType(None, None, None, None, None, None, stringUIDBaseType(None, None, 'True', None, 'aluminium7075'), \ doubleBaseType(None, None, None, str(thickness))) myCrossSection = wingRibCrossSectionType(None, None, None, myMaterial, None) ribReference = stringBaseType(None, None, None, parentUID + '_Spar_FS') ribStart = stringBaseType(None, None, None, parentUID + '_Spar_FS') ribEnd = stringBaseType(None, None, None, parentUID + '_Spar_RS') ribRotation = ribRotationType(None, None, None, stringBaseType(None, None, None, 'globalY'), \ doubleBaseType(None, None, None, '90.')) ribCrossing = ribCrossingBehaviourType(None, None, None, 'cross') #======================================================================= # First set of 4 ribs inside the fuselage #======================================================================= etaStart = doubleBaseType(None, None, None, '0.0') etaEnd = doubleBaseType(None, None, None, str(etaFus)) innerRibs = doubleBaseType(None, None, None, 4) ribsPositioning = wingRibsPositioningType(None, None, None, ribReference, etaStart, etaEnd, ribStart, ribEnd, \ None, innerRibs, ribCrossing, ribRotation) myUID = parentUID + '_ribs_inner' ribsList.append( wingRibsDefinitionType(None, None, None, myUID, myName, None, ribsPositioning, myCrossSection)) #=============================================================== # Second set outside of the fuselage up to the engine #=============================================================== etaPylon = 1. / 10. * fanDiameter / span etaStart = doubleBaseType(None, None, None, str(etaFus + pitch / span)) etaEnd = doubleBaseType(None, None, None, str(etaEng - etaPylon)) middleRibs = int(ceil((etaEng - etaPylon - etaFus) * span / pitch)) - 1 if middleRibs < 1: middleRibs = 1 middleRibs = doubleBaseType(None, None, None, middleRibs) ribsPositioning = wingRibsPositioningType(None, None, None, ribReference, etaStart, etaEnd, ribStart, ribEnd, \ None, middleRibs, ribCrossing, ribRotation) myUID = parentUID + '_ribs_engine1' ribsList.append( wingRibsDefinitionType(None, None, None, myUID, myName, None, ribsPositioning, myCrossSection)) #=============================================================== # Third set one ribs outside of the pylon #=============================================================== etaEnd = doubleBaseType(None, None, None, str(etaEng + etaPylon)) pylonRibs = doubleBaseType(None, None, None, str(1)) ribsPositioning = wingRibsPositioningType(None, None, None, ribReference, etaEnd, etaEnd, ribStart, ribEnd, \ None, pylonRibs, ribCrossing, ribRotation) myUID = parentUID + '_ribs_engine2' ribsList.append( wingRibsDefinitionType(None, None, None, myUID, myName, None, ribsPositioning, myCrossSection)) #=============================================================== # Fourth set outside of the engine #=============================================================== etaStart = doubleBaseType(None, None, None, str(etaEng + etaPylon + pitch / span)) etaEnd = doubleBaseType(None, None, None, '0.95') ribCrossing = ribCrossingBehaviourType(None, None, None, 'end') ribRotation = ribRotationType(None, None, None, stringBaseType(None, None, None, 'wing_Spar_FS'), \ doubleBaseType(None, None, None, '90.')) outerRibs = int(ceil((0.95 - etaEng + etaPylon) * span / pitch)) - 1 outerRibs = doubleBaseType(None, None, None, outerRibs) ribsPositioning = wingRibsPositioningType(None, None, None, ribReference, etaStart, etaEnd, ribStart, ribEnd, \ None, outerRibs, ribCrossing, ribRotation) myUID = parentUID + '_ribs_outer' ribsList.append( wingRibsDefinitionType(None, None, None, myUID, myName, None, ribsPositioning, myCrossSection)) #=============================================================================== # Strut Braced Wing #=============================================================================== if typeOfSeg.lower() == 'strutbracedwing': myName = stringBaseType(None, None, None, 'wing_ribs') # Rib Cross Section #======================================================================= myMaterial = materialDefinitionType(None, None, None, None, None, None, stringUIDBaseType(None, None, 'True', None, 'aluminium7075'), \ doubleBaseType(None, None, None, str(thickness))) myCrossSection = wingRibCrossSectionType(None, None, None, myMaterial, None) ribReference = stringBaseType(None, None, None, parentUID + '_Spar_FS') ribStart = stringBaseType(None, None, None, parentUID + '_Spar_FS') ribEnd = stringBaseType(None, None, None, parentUID + '_Spar_RS') ribRotation = ribRotationType(None, None, None, stringBaseType(None, None, None, 'globalY'), \ doubleBaseType(None, None, None, '90.')) ribCrossing = ribCrossingBehaviourType(None, None, None, 'cross') #======================================================================= # First set of 4 ribs inside the fuselage #======================================================================= etaStart = doubleBaseType(None, None, None, '0.0') etaEnd = doubleBaseType(None, None, None, str(etaFus)) innerRibs = doubleBaseType(None, None, None, 4) ribsPositioning = wingRibsPositioningType(None, None, None, ribReference, etaStart, etaEnd, ribStart, ribEnd, \ None, innerRibs, ribCrossing, ribRotation) myUID = parentUID + '_ribs_inner' ribsList.append( wingRibsDefinitionType(None, None, None, myUID, myName, None, ribsPositioning, myCrossSection)) #=============================================================== # Second set outside of the fuselage up to the strut #=============================================================== etaStart = doubleBaseType(None, None, None, str(etaFus + pitch / span + phi25 * 0.0002)) etaEnd = doubleBaseType(None, None, None, str(etaStrut)) middleRibs = int(ceil((etaStrut - etaFus) * span / pitch)) - 1 middleRibs = doubleBaseType(None, None, None, middleRibs) ribsPositioning = wingRibsPositioningType(None, None, None, ribReference, etaStart, etaEnd, ribStart, ribEnd, \ None, middleRibs, ribCrossing, ribRotation) myUID = parentUID + '_ribs_strut' ribsList.append( wingRibsDefinitionType(None, None, None, myUID, myName, None, ribsPositioning, myCrossSection)) #=============================================================== # Third set outside of the spar #=============================================================== etaStart = doubleBaseType(None, None, None, str(etaStrut + pitch / span)) etaEnd = doubleBaseType(None, None, None, '0.95') ribCrossing = ribCrossingBehaviourType(None, None, None, 'end') ribRotation = ribRotationType(None, None, None, stringBaseType(None, None, None, 'wing_Spar_FS'), \ doubleBaseType(None, None, None, '90.')) outerRibs = int(ceil((0.95 - etaStrut) * span / pitch)) - 1 outerRibs = doubleBaseType(None, None, None, outerRibs) ribsPositioning = wingRibsPositioningType(None, None, None, ribReference, etaStart, etaEnd, ribStart, ribEnd, \ None, outerRibs, ribCrossing, ribRotation) myUID = parentUID + '_ribs_outer' ribsList.append( wingRibsDefinitionType(None, None, None, myUID, myName, None, ribsPositioning, myCrossSection)) #=============================================================================== # Strut (And only the strut not the wing that goes along with it) #=============================================================================== if typeOfSeg.lower() == 'strut': myName = stringBaseType(None, None, None, 'strut_ribs') # Rib Cross Section #======================================================================= myMaterial = materialDefinitionType(compositeUID=stringUIDBaseType(isLink='True',valueOf_='Comp_Shear'), orthotropyDirection=doubleBaseType(valueOf_='0.'),\ thicknessScaling=doubleBaseType(valueOf_='0.001')) myCrossSection = wingRibCrossSectionType(None, None, None, myMaterial, None) ribReference = stringBaseType(None, None, None, 'leadingEdge') ribStart = stringBaseType(None, None, None, 'leadingEdge') ribEnd = stringBaseType(None, None, None, 'trailingEdge') ribRotation = ribRotationType(None, None, None, stringBaseType(None, None, None, 'globalY'), \ doubleBaseType(None, None, None, '90.')) ribCrossing = ribCrossingBehaviourType(None, None, None, 'cross') etaStart = doubleBaseType(None, None, None, str(0.001)) etaEnd = doubleBaseType(None, None, None, str(0.999)) #middleRibs = int(ceil(span / 0.70)) - 1 middleRibs = doubleBaseType(None, None, None, 5.) ribsPositioning = wingRibsPositioningType(None, None, None, ribReference, etaStart, etaEnd, ribStart, ribEnd, \ None, middleRibs, ribCrossing, ribRotation) myUID = parentUID + '_ribs' ribsList.append( wingRibsDefinitionType(None, None, None, myUID, myName, None, ribsPositioning, myCrossSection)) #=============================================================================== # Aileron #=============================================================================== if typeOfSeg.lower() == 'aileron': myName = stringBaseType(None, None, None, 'aileron_ribs') # Rib Cross Section #======================================================================= myMaterial = materialDefinitionType(None, None, None, None, None, None, stringUIDBaseType(None, None, 'True', None, 'aluminium2024'), \ doubleBaseType(None, None, None, str(thickness))) myCrossSection = wingRibCrossSectionType(None, None, None, myMaterial, None) # Rib Positioning #======================================================================= etaStart = doubleBaseType(None, None, None, '0.') etaEnd = doubleBaseType(None, None, None, '1.') ribReference = stringBaseType(None, None, None, parentUID + '_Spar_FS') ribStart = stringBaseType(None, None, None, 'leadingEdge') ribEnd = stringBaseType(None, None, None, 'trailingEdge') ribRotation = ribRotationType(None, None, None, stringBaseType(None, None, None, 'globalY'), \ doubleBaseType(None, None, None, '90.')) ribCrossing = ribCrossingBehaviourType(None, None, None, 'cross') if nRibs is None: ribSpacing = doubleBaseType(None, None, None, pitch) ribsPositioning = wingRibsPositioningType(None, None, None, ribReference, etaStart, etaEnd, ribStart, ribEnd, \ ribSpacing, None, ribCrossing, ribRotation) else: nRibs = doubleBaseType(None, None, None, nRibs) ribsPositioning = wingRibsPositioningType(None, None, None, ribReference, etaStart, etaEnd, ribStart, ribEnd, \ None, nRibs, ribCrossing, ribRotation) ribsList.append( wingRibsDefinitionType(None, None, None, myUID, myName, None, ribsPositioning, myCrossSection)) if typeOfSeg.lower() == 'trapezoid': myName = stringBaseType(None, None, None, 'trapezoid_ribs') # Rib Cross Section #======================================================================= myMaterial = materialDefinitionType(None, None, None, None, None, None, stringUIDBaseType(None, None, 'True', None, 'aluminium2024'), \ doubleBaseType(None, None, None, str(thickness))) myCrossSection = wingRibCrossSectionType(None, None, None, myMaterial, None) # Rib Positioning #======================================================================= etaStart = doubleBaseType(None, None, None, '0.') etaEnd = doubleBaseType(None, None, None, '1.') ribReference = stringBaseType(None, None, None, parentUID + '_Spar_FS') ribStart = stringBaseType(None, None, None, 'leadingEdge') ribEnd = stringBaseType(None, None, None, 'trailingEdge') ribRotation = ribRotationType(None, None, None, stringBaseType(None, None, None, 'globalY'), \ doubleBaseType(None, None, None, '90.')) ribCrossing = ribCrossingBehaviourType(None, None, None, 'cross') etaStart = doubleBaseType(None, None, None, str(0.0)) etaEnd = doubleBaseType(None, None, None, str(0.95)) middleRibs = doubleBaseType(None, None, None, 5.) ribsPositioning = wingRibsPositioningType(None, None, None, ribReference, etaStart, etaEnd, ribStart, ribEnd, \ None, middleRibs, ribCrossing, ribRotation) ribsList.append( wingRibsDefinitionType(None, None, None, myUID, myName, None, ribsPositioning, myCrossSection)) #=============================================================================== # Flap #=============================================================================== if typeOfSeg.lower() == 'flap' or typeOfSeg.lower() == 'innerflap': myName = stringBaseType(None, None, None, 'flap_ribs') # Rib Cross Section #======================================================================= myMaterial = materialDefinitionType(None, None, None, None, None, None, stringUIDBaseType(None, None, 'True', None, 'aluminium2024'), \ doubleBaseType(None, None, None, str(thickness))) myCrossSection = wingRibCrossSectionType(None, None, None, myMaterial, None) # Rib Positioning #======================================================================= etaStart = doubleBaseType(None, None, None, '0.') etaEnd = doubleBaseType(None, None, None, '1.') ribReference = stringBaseType(None, None, None, parentUID + '_Spar_FS') ribStart = stringBaseType(None, None, None, 'leadingEdge') ribEnd = stringBaseType(None, None, None, 'trailingEdge') ribRotation = ribRotationType(None, None, None, stringBaseType(None, None, None, 'globalY'), \ doubleBaseType(None, None, None, '90.')) ribCrossing = ribCrossingBehaviourType(None, None, None, 'cross') if nRibs is None: ribSpacing = doubleBaseType(None, None, None, pitch) ribsPositioning = wingRibsPositioningType(None, None, None, ribReference, etaStart, etaEnd, ribStart, ribEnd, \ ribSpacing, None, ribCrossing, ribRotation) else: nRibs = doubleBaseType(None, None, None, nRibs) ribsPositioning = wingRibsPositioningType(None, None, None, ribReference, etaStart, etaEnd, ribStart, ribEnd, \ None, nRibs, ribCrossing, ribRotation) ribsList.append( wingRibsDefinitionType(None, None, None, myUID, myName, None, ribsPositioning, myCrossSection)) #=============================================================================== # Spoiler #=============================================================================== if typeOfSeg.lower() == 'spoiler': myName = stringBaseType(None, None, None, 'spoiler_ribs') # Rib Cross Section #======================================================================= myMaterial = materialDefinitionType(None, None, None, None, None, None, stringUIDBaseType(None, None, 'True', None, 'aluminium2024'), \ doubleBaseType(None, None, None, str(thickness))) myCrossSection = wingRibCrossSectionType(None, None, None, myMaterial, None) # Rib Positioning #======================================================================= etaStart = doubleBaseType(None, None, None, '0.') etaEnd = doubleBaseType(None, None, None, '1.') ribReference = stringBaseType(None, None, None, 'leadingEdge') ribStart = stringBaseType(None, None, None, 'leadingEdge') ribEnd = stringBaseType(None, None, None, 'trailingEdge') ribRotation = ribRotationType(None, None, None, stringBaseType(None, None, None, 'leadingEdge'), \ doubleBaseType(None, None, None, '90.')) ribCrossing = ribCrossingBehaviourType(None, None, None, 'cross') if nRibs is None: ribSpacing = doubleBaseType(None, None, None, pitch) ribsPositioning = wingRibsPositioningType(None, None, None, ribReference, etaStart, etaEnd, ribStart, ribEnd, \ ribSpacing, None, ribCrossing, ribRotation) else: nRibs = doubleBaseType(None, None, None, nRibs) ribsPositioning = wingRibsPositioningType(None, None, None, ribReference, etaStart, etaEnd, ribStart, ribEnd, \ None, nRibs, ribCrossing, ribRotation) ribsList.append( wingRibsDefinitionType(None, None, None, myUID, myName, None, ribsPositioning, myCrossSection)) #======================================================================= # RibsDefinition #======================================================================= myRibsDefinitions = wingRibsDefinitionsType(None, None, None, ribsList) parent.get_structure().set_ribsDefinitions(myRibsDefinitions)