//////////////////////////////////////////////////////////// // tunit.c: Tunit class implementation. // Copyright(c) 1993 J.N.Hinckel. All rights reserved. /////////////////////////////////////////////////////////// #include "tunit.h" cv Len[] = { {1.0,"m"}, {0.001,"mm"}, {0.01,"cm"}, {1000.,"km"}, {0.0254,"in"}, {0.3048,"ft"}, {0.9144,"yd"}, {1609.347,"mile"}, {1852,"nm"}, {1.495979e11,"AU"}, {0," "} }; cv *Tlength::Length=Len; cv Ms[] = { {1.0,"kg"}, {0.001,"g"}, {0.4535924,"lb"}, {14.5939,"slug"}, {1000.,"ton"}, {0," "} }; cv *Tmass::Mass=Ms; cv Msf[] = { {1.0,"kg/(m^2 s)"}, {10.0,"g/(cm^2 s)"}, {703.06963,"lb/(in^2 s)"}, {4.88243,"lb/(ft^2 s)"}, {0," "} }; cv *TmassFlux::Massflux=Msf; cv Msfr[] = { {1.0,"kg/s"}, {0.001,"g/s"}, {0.4535924,"lb/s"}, {0," "} }; cv *TmassFlowRate::Massflowrate=Msfr; cv Tm[] = { {1.0,"s"}, {60.0,"min"}, {3600.0,"hr"}, {86400.,"day"}, {31536000.0,"yr"}, {0," "} }; cv *Ttime::Time=Tm; cv Ar[] = { {1.0,"m^2"}, {0.0001,"cm^2"}, {1e-6,"mm^2"}, {0.00064516,"in^2"}, {0.09290304,"ft^2"}, {0," "} }; cv *Tarea::Area=Ar; cv Spa[] = { {1.0,"m^2/m^3"}, {100.0,"cm^2/cm^3"}, {39.937,"in^2/in^3"}, {3.28084,"ft^2/ft^3"}, {0," "} }; cv *TspecificArea::Specificarea=Spa; cv Vm[] = { {1.0,"m^3"}, {0.001,"l"}, {1.0e-6,"cm^3"}, {1.639e-5,"in^3"}, {0.02832,"ft^3"}, {0.003785,"gal"}, {0," "} }; cv *Tvolume::Volume=Vm; cv Acl[] = { {1.0,"m/s^2"}, {0.3048,"ft/s^2"}, {0.0254,"in/s^2"}, {0," "} }; cv *Tacceleration::Acceleration=Acl; cv Vel[] = { {1.0,"m/s"}, {0.3048,"ft/s"}, {0.277778,"km/hr"}, {0.44704,"mile/hr"}, {0," "} }; cv *Tvelocity::Velocity = Vel; cv Dst[] = { {1.0,"kg/m^3"}, {1000.0,"g/cm^3"}, {27679.9,"lb/in^3"}, {16.01846,"lb/ft^3"}, {1515.3788,"slug/ft^3"}, {0," "} }; cv *Tdensity::Density=Dst; cv En[] = { {1.0,"J"}, {1.0e-7,"erg"}, {4.1868,"cal"}, {4.184,"cal_th"}, {1055.056,"Btu"}, {1054.35,"Btu_th"}, {11.355818,"ft.lb"}, {3600,"W.hr"}, {3.6e6,"kW.hr"}, {0," "} }; cv *Tenergy::Energy=En; cv Enf[] = { {1.0,"W/m^2"}, {0.001,"erg/(cm^2 s)"}, {41868.,"cal/(cm^2 s)"}, {41840.,"cal_th/(cm^2 s)"}, {11356.56,"Btu/(ft^2 s)"}, {3.1546,"Btu/(ft^2 hr)"}, {0," "} }; cv *TenergyFlux::Energyflux=Enf; cv Fc[] = { {1.0,"N"}, {1000.,"kN"}, {1.0e-5,"dyne"}, {9.80665,"kgf"}, {4.448222,"lbf"}, {9806.65,"ton"}, {0," "} }; cv *Tforce::Force=Fc; cv Htc[] ={ {1.0,"W/(m^2 K)"}, {41868.,"cal/(cm^2 s K)"}, {20441.8,"(Btu/ft^2 s R)"}, {5.6783,"Btu/(ft^2 hr R)"}, {0," "} }; cv *TheatTransferCoefficient::Heattransfercoefficient=Htc; cv Kvsc[] = { {1.0,"m^2/s"}, {1.0e-6,"cSt"}, {1.0e-4,"St"}, {6.4516e-4,"in^2/s"}, {0.09290304,"ft^2/s"}, {0," "} }; cv *TkinematicViscosity::Kinematicviscosity=Kvsc; cv Pw[] = { {1.0,"W"}, {1000.0,"kW"}, {4.1868,"cal/s"}, {0.2930711,"Btu/hr"}, {1055.5596,"Btu/s"}, {11.355818,"ft lbf/s"}, {745.6999,"hp"}, {0," "} }; cv *Tpower::Power=Pw; cv Ps[] = { {1.0,"Pa"}, {1000.0,"kPa"}, {1.0e6,"MPa"}, {1.0e5,"Bar"}, {0.1,"dyne/cm^2"}, {6894.757,"psi"}, {47.88026,"lbf/ft^2"}, {133.322,"torr"}, {98.06378,"mmH2O"}, {101325.0,"atm"}, {0," "} }; cv *Tpressure::Pressure=Ps; cv Spe[] = { {1.0,"J/kg"}, {1000.0,"kJ/kg"}, {4.1868,"cal/g"}, {4.1868,"kcal/kg"}, {4.1868,"Btu/lb"}, {0," "} }; cv *TspecificEnergy::Specificenergy=Spe; cv Sph[] = { {1.0,"J/kg K"}, {1000.0,"kJ/kg K"}, {4.1868,"cal/g K"}, {4.1868,"Btu/lb R"}, {0," "} }; cv *TspecificHeat::Specificheat=Sph; cv Thc[] = { {1.0,"W/(m K)"}, {418.68,"cal/(s cm K)"}, {1.7307,"Btu/(hr ft R)"}, {1.163,"kcal/(hr m K)"}, {0," "} }; cv *TthermalConductivity::Thermalconductivity=Thc; cv Vsc[] = { {1.0,"Pa s"}, {0.001,"cP"}, {0.1,"poise"}, {17.85797,"lb/(in s)"}, {1.488164,"lb/(ft s)"}, {4.133789e-4,"lb/(ft hr)"}, {0," "} }; cv *Tviscosity::Viscosity=Vsc; cv Vfr[] = { {1.0,"m^3/s"}, {0.001,"l/s"}, {0.02831685,"ft^3/s"}, {4.719474e-4,"ft^3/min"}, {6.30902e-5,"gpm"}, {0," "} }; cv *TvolumeFlowRate::Volumeflowrate=Vfr; cv Temp[] = { {1.0,"K"}, {1.0,"C"}, {0.5555555556,"R"}, {0.5555555556,"F"}, {0," "} }; cv *Ttemperature::Temperature=Temp; static double tof[] = {0.0,273.15,0.0,459.67}; double *Ttemperature::toffset=tof; Tunit::Tunit(const Tunit & l){ value = l.value; index = l.index; table = l.table; } Tunit& Tunit::operator=(const Tunit& l){ if (this != &l) { // do nothin if assing to self value = l.value; index = l.index; table = l.table; } return *this; } double Tunit::operator()(int l) const { return value/table[l].cvalue; } void Tunit::SetValue(double v){ value =v*table[index].cvalue; } void Tunit::GetStringVector (vector & sv) { sv.clear(); int nn =0; while (table[nn].cvalue) { sv.push_back(table[nn].unit); nn++; } } double Ttemperature::operator () (int L) const { return value/table[L].cvalue-toffset[L]; } void Ttemperature::SetValue(double v){ value =(v+toffset[index])*table[index].cvalue; } ostream & operator << (ostream & os, const Tunit & tu) { os << tu(tu.index) << " " << tu.table[tu.index].unit; return os; }