def accept(self): Dp = 0 elements = list() Q = float(self.form.editFlow.text()) / 3600 if self.form.comboWhat.currentText() == '<on selection>': elements = FreeCADGui.Selection.getSelection() else: o = FreeCAD.ActiveDocument.getObjectsByLabel( self.form.comboWhat.currentText())[0] if hasattr(o, 'PType') and o.PType == 'PypeBranch': elements = o.Tubes + o.Curves for o in elements: if hasattr(o, 'PType') and o.PType in ['Pipe', 'Elbow']: ID = float(o.ID) / 1000 e = float(self.form.editRough.text()) * 1e-6 / ID if self.isLiquid: v = Q / ((ID)**2 * pi / 4) else: v = Q / ((ID)**2 * pi / 4) / self.Rho Re = Reynolds(V=v, D=ID, rho=self.Rho, mu=self.Mu) f = friction.friction_factor(Re, eD=e) # Darcy, =4xFanning if o.PType == 'Pipe': L = float(o.Height) / 1000 K = K_from_f(fd=f, L=L, D=ID) FreeCAD.Console.PrintMessage( 'ID=%.2f\nV=%.2f\ne=%f\nf=%f\nK=%f\nL=%.3f\n***\n' % (ID, v, e, f, K, L)) Dp += dP_from_K(K, rho=self.Rho, V=v) elif o.PType == 'Elbow': ang = float(o.BendAngle) R = float(o.BendRadius) / 1000 K = fittings.bend_rounded(ID, ang, f, R) FreeCAD.Console.PrintMessage( 'ID=%.2f\nV=%.2f\ne=%f\nf=%f\nK=%f\nang=%.3f\nR=%f\n***\n' % (ID, v, e, f, K, ang, R)) Dp += dP_from_K(K, rho=self.Rho, V=v) elif o.PType == 'Reduct': pass elif hasattr(o, 'Kv') and o.Kv > 0: if self.isLiquid: Dp += (Q * 3600 / o.Kv)**2 * 100000 else: pass if Dp > 200: result = ' = %.3f bar' % (Dp / 100000) else: result = ' = %.2e bar' % (Dp / 100000) self.form.labResult.setText(result)
def accept(self): Dp = Ltot = nc = 0 elements = list() Q = float(self.form.editFlow.text()) / 3600 if not self.isLiquid: Q = Q / self.Rho if self.form.comboWhat.currentText() == '<on selection>': elements = FreeCADGui.Selection.getSelection() else: o = FreeCAD.ActiveDocument.getObjectsByLabel( self.form.comboWhat.currentText())[0] if hasattr(o, 'PType') and o.PType == 'PypeBranch': elements = [ FreeCAD.ActiveDocument.getObject(name) for name in o.Tubes + o.Curves ] elif hasattr(o, 'PType') and o.PType == 'PypeLine': group = FreeCAD.ActiveDocument.getObjectsByLabel(o.Label + '_pieces')[0] elements = group.OutList self.form.editResults.clear() for o in elements: loss = 0 if hasattr(o, 'PType') and o.PType in ['Pipe', 'Elbow', 'Reduct']: if o.PType in ['Pipe', 'Elbow']: ID = float(o.ID) / 1000 else: ID = float(o.OD - 2 * o.thk) / 1000 e = float(self.form.editRough.text()) * 1e-6 / ID v = Q / ((ID)**2 * pi / 4) if isFluidsAvailable: Re = Reynolds(V=v, D=ID, rho=self.Rho, mu=self.Mu) f = friction.friction_factor(Re, eD=e) # Darcy, =4xFanning else: Re = v * ID * self.Rho / self.Mu if Re <= 2300: f = 64 / Re else: f = (-1.8 * log((e / 3.7)**1.11 + 6.9 / Re, 10))**-2 if o.PType == 'Pipe': L = float(o.Height) / 1000 Ltot += L if isFluidsAvailable: K = K_from_f(fd=f, L=L, D=ID) loss = dP_from_K(K, rho=self.Rho, V=v) else: loss = v**2 / 2 * self.Rho * f * L / ID self.form.editResults.append( '%s\t%.1f mm\t%.1f m/s\t%.5f bar' % (o.Label, ID * 1000, v, loss / 1e5)) elif o.PType == 'Elbow': ang = float(o.BendAngle) R = float(o.BendRadius) / 1000 nc += 1 if isFluidsAvailable: K = fittings.bend_rounded(ID, ang, f, R) loss = dP_from_K(K, rho=self.Rho, V=v) else: ang = radians(ang) K = f * ang * R / ID + (0.10 + 2.4 * f) * sin( ang / 2) + (6.6 * f * (sqrt(sin(ang / 2)) + sin(ang / 2))) / ( (R / ID)**(4 * ang / pi)) # Rennels loss = self.Rho * K * v**2 / 2 self.form.editResults.append( '%s\t%.1f mm\t%.1f m/s\t%.5f bar' % (o.Label, ID * 1000, v, loss / 1e5)) elif o.PType == 'Reduct': ID1 = float(o.OD - o.thk * 2) ID2 = float(o.OD2 - o.thk2 * 2) teta = 2 * atan((ID1 - ID2) / 2.0 / float(o.Height)) if isFluidsAvailable: K = fittings.contraction_conical(ID1, ID2, angle=degrees(teta), Re=Re) loss = dP_from_K(K, rho=self.Rho, V=v) else: beta = ID2 / ID1 if teta < pi / 4: K = 0.8 * sin(teta / 2) * (1 - beta**2) else: K = 0.5 * sqrt(sin(teta / 2)) * (1 - beta**2) loss = self.Rho * K * v**2 / 2 self.form.editResults.append( '%s\t%.1f mm\t%.1f m/s\t%.5f bar' % (o.Label, ID * 1000, v, loss / 1e5)) elif hasattr(o, 'Kv') and o.Kv > 0: if self.isLiquid: loss = (Q * 3600 / o.Kv)**2 * 100000 * self.Rho / 1000 elif self.form.comboFluid.currentText( ) == 'water' and not self.isLiquid: pass # TODO formula for steam else: pass # TODO formula for gases if hasattr(o, 'ID'): ID = float(o.ID) / 1000 v = Q / (ID**2 * pi / 4) else: v = 0 ID = 0 self.form.editResults.append( '%s\t%.1f mm\t%.1f m/s\t%.5f bar' % (o.Label, ID * 1000, v, loss / 1e5)) Dp += loss if Dp > 200: result = ' = %.3f bar' % (Dp / 100000) else: result = ' = %.2e bar' % (Dp / 100000) self.form.labResult.setText(result) self.form.labLength.setText('Total length = %.3f m' % Ltot) self.form.labCurves.setText('Nr. of curves = %i' % nc)
def accept(self): Dp=Ltot=nc=0 elements=list() Q=float(self.form.editFlow.text())/3600 if not self.isLiquid: Q=Q/self.Rho if self.form.comboWhat.currentText()=='<on selection>': elements = FreeCADGui.Selection.getSelection() else: o=FreeCAD.ActiveDocument.getObjectsByLabel(self.form.comboWhat.currentText())[0] if hasattr(o,'PType') and o.PType=='PypeBranch': elements=[FreeCAD.ActiveDocument.getObject(name) for name in o.Tubes+o.Curves] elif hasattr(o,'PType') and o.PType=='PypeLine': group=FreeCAD.ActiveDocument.getObjectsByLabel(o.Label+'_pieces')[0] elements=group.OutList self.form.editResults.clear() for o in elements: loss=0 if hasattr(o,'PType') and o.PType in ['Pipe','Elbow']: ID=float(o.ID)/1000 e=float(self.form.editRough.text())*1e-6/ID v=Q/((ID)**2*pi/4) Re=Reynolds(V=v,D=ID,rho=self.Rho, mu=self.Mu) f=friction.friction_factor(Re, eD=e) # Darcy, =4xFanning if o.PType=='Pipe': L=float(o.Height)/1000 Ltot+=L K=K_from_f(fd=f, L=L, D=ID) loss=dP_from_K(K,rho=self.Rho,V=v) FreeCAD.Console.PrintMessage('%s: %s\nID=%.2f\nV=%.2f\ne=%f\nf=%f\nK=%f\nL=%.3f\nDp = %.5f bar\n***'%(o.PType,o.Label,ID,v,e,f,K,L,loss/1e5)) self.form.editResults.append('%s\t%.1f mm\t%.1f m/s\t%.5f bar'%(o.Label,ID*1000,v,loss/1e5)) elif o.PType=='Elbow': ang=float(o.BendAngle) R=float(o.BendRadius)/1000 nc+=1 K=fittings.bend_rounded(ID,ang,f,R) loss=dP_from_K(K,rho=self.Rho,V=v) FreeCAD.Console.PrintMessage('%s: %s\nID=%.2f\nV=%.2f\ne=%f\nf=%f\nK=%f\nang=%.3f\nR=%f\nDp = %.5f bar\n***'%(o.PType,o.Label,ID,v,e,f,K,ang,R,loss/1e5)) self.form.editResults.append('%s\t%.1f mm\t%.1f m/s\t%.5f bar'%(o.Label,ID*1000,v,loss/1e5)) elif o.PType=='Reduct': pass elif hasattr(o,'Kv') and o.Kv>0: if self.isLiquid: loss=(Q*3600/o.Kv)**2*100000 elif self.form.comboFluid.currentText()=='water' and not self.isLiquid: pass # TODO formula for steam else: pass # TODO formula for gases if hasattr(o,'ID'): ID = float(o.ID)/1000 v=Q/(ID**2*pi/4) else: v = 0 ID = 0 self.form.editResults.append('%s\t%.1f mm\t%.1f m/s\t%.5f bar'%(o.Label,ID*1000,v,loss/1e5)) Dp+=loss if Dp>200: result=' = %.3f bar'%(Dp/100000) else: result=' = %.2e bar'%(Dp/100000) self.form.labResult.setText(result) self.form.labLength.setText('Total length = %.3f m' %Ltot) self.form.labCurves.setText('Nr. of curves = %i' %nc)