//return Pressure, Velocity, Density Real4 HalfProblemDepressionWave(Real PressureOut, Real VelocityOut, Real DensityOut, Real GammaOut, Real SoundOut, Real PressureContact, Real VelocityContact) { Real4 Result; Real WaveLeftBoundarySpeed = VelocityOut - SoundOut, WaveRightBoundarySpeed = VelocityContact * Real(0.5) * (1 + GammaOut) - VelocityOut * Real(0.5) * (GammaOut - 1) - SoundOut; if (WaveLeftBoundarySpeed > 0) { Pressure(Result) = PressureOut; Velocity(Result) = VelocityOut; Density(Result) = DensityOut; } else { Real SoundContact = SoundOut + Real(0.5) * (GammaOut - 1) * (VelocityOut - VelocityContact); Real DensityContact = GammaOut * PressureContact / Sqr(SoundContact); if (WaveRightBoundarySpeed < 0) { Velocity(Result) = VelocityContact; Pressure(Result) = PressureContact; Density(Result) = DensityContact; } else { Real Ratio = WaveLeftBoundarySpeed / (WaveLeftBoundarySpeed - WaveRightBoundarySpeed); Pressure(Result) = PressureOut + (PressureContact - PressureOut) * Ratio; Density(Result) = DensityOut + (DensityContact - DensityOut) * Ratio; Velocity(Result) = VelocityOut + (VelocityContact - VelocityOut) * Ratio; }; }; return Result; }
//return Pressure, Velocity, Density Real4 HalfProblemShockWave(Real PressureOut, Real VelocityOut, Real DensityOut, Real GammaOut, Real SoundOut, Real PressureContact, Real VelocityContact) { Real WaveSpeed; Real4 Result; Real DPressure = PressureContact / PressureOut; if (fabs(1 - DPressure) < Epsilon) WaveSpeed = VelocityOut - SoundOut; else { Real DGamma = (GammaOut - 1) / (2 * GammaOut); WaveSpeed = VelocityOut - DGamma * SoundOut * (1 - DPressure) / (1 - pow(DPressure, DGamma)); }; if (WaveSpeed >= 0) { Pressure(Result) = PressureOut; Velocity(Result) = VelocityOut; Density(Result) = DensityOut; } else { Pressure(Result) = PressureContact; Velocity(Result) = VelocityContact; Density(Result) = DensityOut * ((GammaOut + 1) * PressureContact + (GammaOut - 1) * PressureOut) / ((GammaOut - 1) * PressureContact + (GammaOut + 1) * PressureOut); }; return Result; }
Spectrum GridDensityMedium::Sample(const Ray &rWorld, Sampler &sampler, MemoryArena &arena, MediumInteraction *mi) const { Ray ray = WorldToMedium( Ray(rWorld.o, Normalize(rWorld.d), rWorld.tMax * rWorld.d.Length())); // Compute $[\tmin, \tmax]$ interval of _ray_'s overlap with medium bounds const Bounds3f b(Point3f(0, 0, 0), Point3f(1, 1, 1)); Float tMin, tMax; if (!b.IntersectP(ray, &tMin, &tMax)) return Spectrum(1.f); // Run delta-tracking iterations to sample a medium interaction Float t = tMin; while (true) { t -= std::log(1 - sampler.Get1D()) * invMaxDensity; if (t >= tMax) break; if (Density(ray(t)) * invMaxDensity * sigma_t > sampler.Get1D()) { // Populate _mi_ with medium interaction information and return PhaseFunction *phase = ARENA_ALLOC(arena, HenyeyGreenstein)(g); *mi = MediumInteraction(rWorld(t), -rWorld.d, rWorld.time, this, phase); return sigma_s / sigma_t; } } return Spectrum(1.f); }
Spectrum GridDensityMedium::Sample(const Ray &_ray, Sampler &sampler, MemoryArena &arena, MediumInteraction *mi) const { // Transform the ray into local coordinates and determine overlap interval // [_tMin, tMax_] const Bounds3f dataBounds(Point3f(0.f, 0.f, 0.f), Point3f(1.f, 1.f, 1.f)); Ray ray = WorldToMedium( Ray(_ray.o, Normalize(_ray.d), _ray.tMax * _ray.d.Length())); Float tMin, tMax; if (!dataBounds.IntersectP(ray, &tMin, &tMax)) return Spectrum(1.f); tMin = std::max(tMin, (Float)0.f); tMax = std::min(tMax, ray.tMax); if (tMin >= tMax) return Spectrum(1.f); // Run Delta-Tracking iterations to sample a medium interaction Float t = tMin; while (true) { t -= std::log(1 - sampler.Get1D()) * invMaxDensity; if (t >= tMax) break; Float density = Density(ray(t)); if (density * invMaxDensity * sigma_t > sampler.Get1D()) { // Populate _mi_ with medium interaction information and return PhaseFunction *phase = ARENA_ALLOC(arena, HenyeyGreenstein)(g); *mi = MediumInteraction(_ray(t), -_ray.d, _ray.time, this, phase); return sigma_s / sigma_t; } } return Spectrum(1.0f); }
void ParticleEmitterComponent::update(double time) { auto last_spawn_position = math::get_translation(WorldTransform()); TransformableComponent::update(time); Density.update(time); if (!ParticleSystem) { ParticleSystem = get_user()->get_component<ParticleSystemComponent>(ParticleSystemLabel()); } if (ParticleSystem) { particles_to_spawn_ += time * Density(); if (particles_to_spawn_ > 1.f) { auto pos(math::get_translation(WorldTransform())); auto rot(math::get_rotation(WorldTransform())); int count = particles_to_spawn_; particles_to_spawn_ = particles_to_spawn_ - count; for (int i(0); i<count; ++i) { auto p = pos + 1.f*i/count*(last_spawn_position-pos); ParticleSystem->spawn(p, rot, Velocity()); } } } }
int main() { char cmd; do { printf("\n\n\n"); printf(" Menu: Help Bethe Reaction Straggling Density Meter Gram Ispin Exit\n"); printf(" Press first letter : "); cmd = getchar(); cmd = tolower(cmd); switch (cmd) { case 'h': Menu(); break; case 'b': Absorbator(); break; case 'r': Relkinematic(); break; case 's': Straggling(); break; case 'd': Density(); break; case 'm': Meter(); break; case 'g': Gram(); break; case 'i': Ispin(); break; case 'e': break; default : printf(" Invalid choice. Try again\n"); } }while (cmd != 'e'); return 0; }
void OpenSMOKE_GasStream::lock() { if (assignedKineticScheme == false) ErrorMessage("The kinetic scheme was not defined!!"); if (assignedMassFlowRate == false && assignedMoleFlowRate == false && assignedVolumetricFlowRate == false) { // ErrorMessage("The flow rate was not defined!!"); AssignMassFlowRate(1.e-10, "kg/s"); iUndefinedFlowRate = true; } if (assignedMoleFractions == false && assignedMassFractions == false) ErrorMessage("The composition was not defined!!"); Composition(); if (assignedTemperature == true && assignedPressure == true && assignedDensity == true) ErrorMessage("Only 2 between: T || P || rho"); if (assignedTemperature == true && assignedPressure == true) { /* Nothing to do */ } else if (assignedDensity == true && assignedPressure == true) { T = P*MW/Constants::R_J_kmol/rho; } else if (assignedDensity == true && assignedTemperature == true) { P = rho*Constants::R_J_kmol*T/MW; } else ErrorMessage("2 between must be assigned: T || P || rho"); Concentrations(); Density(); FlowRates(); SpecificEnthalpies(); Enthalpy(); SpecificEntropies(); Entropy(); }
//return Pressure, Velocity, Density Real4 HalfProblemContactDiscontinuty(Real PressureOut, Real VelocityOut, Real DensityOut, Real GammaOut, Real SoundOut, Real PressureContact, Real VelocityContact) { Real4 Result; Pressure(Result) = PressureContact; Density(Result) = DensityOut; Velocity(Result) = VelocityContact; return Result; }
double Chevalier::rho_star(double r) { double rho = Density(r); //g cm^-3 double M_dot_prime = M_dot * msun_in_g/year_in_sec; // g/s double R_prime = R * parsec_in_cm; //cm double rho_prime = pow(M_dot_prime,1.5)/(sqrt(E_dot)*R_prime*R_prime); //dimensionless density return rho/rho_prime; }
void OpenSMOKE_GasStream::ChangePressure(const double _value, const std::string _units) { if (_value<=0.) ErrorMessage("The pressure must be greater than zero!"); P = OpenSMOKE_Conversions::conversion_pressure(_value, _units); Concentrations(); Density(); FlowRates(); Enthalpy(); }
void OpenSMOKE_GasStream::ChangeMoleFractions(BzzVector &_values) { AssignMoleFractions(_values); Composition(); Concentrations(); Density(); FlowRates(); SpecificEnthalpies(); Enthalpy(); SpecificEntropies(); Entropy(); }
double Chevalier::Temperature(double r) { //temperature in K double T; double P = Pressure(r); // dyn cm^-2 double u = WindVelocity(r); //km/s double rho = Density(r); // g/cm^3 double n = rho / mp_in_grams; T = P / (n*kb_cgs); return T; //in Kelvin }
void OpenSMOKE_GasStream::ChangeTemperature(const double _value, const std::string _units) { if (_value<=0.) ErrorMessage("The temperature must be greater than zero!"); T = OpenSMOKE_Conversions::conversion_temperature(_value, _units); Concentrations(); Density(); FlowRates(); SpecificEnthalpies(); Enthalpy(); SpecificEntropies(); Entropy(); }
// Use. bool run (Treelog& msg) { // Find it. std::auto_ptr<Rootdens> rootdens = Rootdens::create_row (metalib, msg, row_width, row_position, true); rootdens->initialize (*geo, row_width, row_position, msg); std::vector<double> Density (geo->cell_size ()); rootdens->set_density (*geo, soil_depth, crop_depth, crop_width, WRoot, DS, Density, msg); // Print it. table_center (*geo, Density, msg); // Ok. return true; }
//return Pressure, Velocity, Density, Energy Real4 CaseVacuum(Real PressureLeft, Real VelocityLeft, Real DensityLeft, Real GammaLeft, Real SoundLeft, Real PressureRight, Real VelocityRight, Real DensityRight, Real GammaRight, Real SoundRight) { Real4 Result; if (VelocityLeft - SoundLeft >= 0) { Density(Result) = DensityLeft; Pressure(Result) = PressureLeft; Velocity(Result) = VelocityLeft; Energy(Result) = Pressure(Result) / ((GammaLeft - 1) * Density(Result)); } else if (VelocityLeft + 2 * SoundLeft / (GammaLeft - 1) >= 0) { Real Ratio = 2 / (GammaLeft + 1); Density(Result) = DensityLeft * Ratio; Pressure(Result) = PressureLeft * Ratio; Velocity(Result) = VelocityLeft + SoundLeft * Ratio; Energy(Result) = Pressure(Result) / ((GammaLeft - 1) * Density(Result)); } if (VelocityRight + SoundRight <= 0) { Density(Result) = DensityRight; Pressure(Result) = PressureRight; Velocity(Result) = VelocityRight; Energy(Result) = Pressure(Result) / ((GammaRight - 1) * Density(Result)); } else if (VelocityLeft - 2 * SoundRight / (GammaRight - 1) <= 0) { Real Ratio = 2 / (GammaRight + 1); Density(Result) = DensityRight * Ratio; Pressure(Result) = PressureRight * Ratio; Velocity(Result) = VelocityRight - SoundLeft * Ratio; Energy(Result) = Pressure(Result) / ((GammaRight - 1) * Density(Result)); } else { Density(Result) = 0; Pressure(Result) = 0; Velocity(Result) = 0; Energy(Result) = 0; }; return Result; }
Spectrum GridDensityMedium::Tr(const Ray &rWorld, Sampler &sampler) const { Ray ray = WorldToMedium( Ray(rWorld.o, Normalize(rWorld.d), rWorld.tMax * rWorld.d.Length())); // Compute $[\tmin, \tmax]$ interval of _ray_'s overlap with medium bounds const Bounds3f b(Point3f(0, 0, 0), Point3f(1, 1, 1)); Float tMin, tMax; if (!b.IntersectP(ray, &tMin, &tMax)) return Spectrum(1.f); // Perform ratio tracking to estimate the transmittance value Float Tr = 1, t = tMin; while (true) { t += -std::log(1 - sampler.Get1D()) * invMaxDensity; if (t >= tMax) break; Float density = Density(ray(t)); Tr *= 1 - std::max((Float)0, sigma_t * density * invMaxDensity); } return Spectrum(Tr); }
//return Pressure, Velocity, Density, Energy Real4 SolveHalfProblem(Real PressureOut, Real VelocityOut, Real DensityOut, Real GammaOut, Real SoundOut, Real PressureContact, Real VelocityContact, bool Left) { Real Sign = Left ? Real(1) : Real(-1); Real4 Result; if (PressureOut > PressureContact) Result = HalfProblemDepressionWave(PressureOut, Sign * VelocityOut, DensityOut, GammaOut, SoundOut, PressureContact, Sign * VelocityContact); else if (PressureOut < PressureContact) Result = HalfProblemShockWave(PressureOut, Sign * VelocityOut, DensityOut, GammaOut, SoundOut, PressureContact, Sign * VelocityContact); else Result = HalfProblemContactDiscontinuty(PressureOut, Sign * VelocityOut, DensityOut, GammaOut, SoundOut, PressureContact, Sign * VelocityContact); Energy(Result) = Pressure(Result) / ((GammaOut - 1) * Density(Result)); Velocity(Result) = Sign * Velocity(Result); return Result; }
Spectrum GridDensityMedium::T(const Ray &_ray, Sampler &sampler) const { // Transform the ray into local coordinates and determine overlap interval // [_tMin, tMax_] const Bounds3f dataBounds(Point3f(0.f, 0.f, 0.f), Point3f(1.f, 1.f, 1.f)); Ray ray = WorldToMedium( Ray(_ray.o, Normalize(_ray.d), _ray.tMax * _ray.d.Length())); Float tMin, tMax; if (!dataBounds.IntersectP(ray, &tMin, &tMax)) return Spectrum(1.f); tMin = std::max(tMin, (Float)0.f); tMax = std::min(tMax, ray.tMax); if (tMin >= tMax) return Spectrum(1.f); Float tr = 1.f; // Perform ratio tracking to estimate the transmittance value Float t = tMin; while (true) { t -= std::log(1 - sampler.Get1D()) * invMaxDensity; if (t >= tMax) break; Float density = Density(ray(t)); tr *= 1.f - std::max((Float)0, sigma_t * density * invMaxDensity); } return Spectrum(tr); }
void PoissonReconstruction::PoissonRecon(int argc , char* argv[], const MagicDGP::Point3DSet* pPC, std::vector< PlyValueVertex< float > >& vertices, std::vector< std::vector< int > >& polygons) { cmdLineString In( "in" ) , Out( "out" ) , VoxelGrid( "voxel" ) , XForm( "xForm" ); cmdLineReadable Performance( "performance" ) , ShowResidual( "showResidual" ) , NoComments( "noComments" ) , PolygonMesh( "polygonMesh" ) , Confidence( "confidence" ) , NonManifold( "nonManifold" ) , ASCII( "ascii" ) , Density( "density" ) , Verbose( "verbose" ); cmdLineInt Depth( "depth" , 8 ) , SolverDivide( "solverDivide" , 8 ) , IsoDivide( "isoDivide" , 8 ) , KernelDepth( "kernelDepth" ) , AdaptiveExponent( "adaptiveExp" , 1 ) , MinIters( "minIters" , 24 ) , FixedIters( "iters" , -1 ) , VoxelDepth( "voxelDepth" , -1 ) , MinDepth( "minDepth" , 5 ) , MaxSolveDepth( "maxSolveDepth" ) , BoundaryType( "boundary" , 1 ) , Threads( "threads" , omp_get_num_procs() ); cmdLineFloat SamplesPerNode( "samplesPerNode" , 1.f ) , Scale( "scale" , 1.1f ) , SolverAccuracy( "accuracy" , float(1e-3) ) , PointWeight( "pointWeight" , 4.f ); cmdLineReadable* params[] = { &In , &Depth , &Out , &XForm , &SolverDivide , &IsoDivide , &Scale , &Verbose , &SolverAccuracy , &NoComments , &KernelDepth , &SamplesPerNode , &Confidence , &NonManifold , &PolygonMesh , &ASCII , &ShowResidual , &MinIters , &FixedIters , &VoxelDepth , &PointWeight , &VoxelGrid , &Threads , &MinDepth , &MaxSolveDepth , &AdaptiveExponent , &BoundaryType , &Density }; cmdLineParse( argc , argv , sizeof(params)/sizeof(cmdLineReadable*) , params , 1 ); /*if( Density.set ) return Execute< 2 , PlyValueVertex< Real > , true >(argc , argv, pPC); else return Execute< 2 , PlyVertex< Real > , false >(argc , argv, pPC);*/ //Execute int i; int paramNum = sizeof(params)/sizeof(cmdLineReadable*); int commentNum=0; char **comments; comments = new char*[paramNum + 7]; for( i=0 ; i<paramNum+7 ; i++ ) comments[i] = new char[1024]; //if( Verbose.set ) echoStdout=1; XForm4x4< Real > xForm , iXForm; if( XForm.set ) { FILE* fp = fopen( XForm.value , "r" ); if( !fp ) { fprintf( stderr , "[WARNING] Could not read x-form from: %s\n" , XForm.value ); xForm = XForm4x4< Real >::Identity(); } else { for( int i=0 ; i<4 ; i++ ) for( int j=0 ; j<4 ; j++ ) fscanf( fp , " %f " , &xForm( i , j ) ); fclose( fp ); } } else xForm = XForm4x4< Real >::Identity(); iXForm = xForm.inverse(); //DumpOutput2( comments[commentNum++] , "Running Screened Poisson Reconstruction (Version 5.0)\n" , Degree ); //char str[1024]; //for( int i=0 ; i<paramNum ; i++ ) // if( params[i]->set ) // { // params[i]->writeValue( str ); // if( strlen( str ) ) DumpOutput2( comments[commentNum++] , "\t--%s %s\n" , params[i]->name , str ); // else DumpOutput2( comments[commentNum++] , "\t--%s\n" , params[i]->name ); // } double t; double tt=Time(); Real isoValue = 0; //Octree< Degree , OutputDensity > tree; Octree< 2 , true > tree; tree.threads = Threads.value; //if( !In.set ) //{ // ShowUsage(argv[0]); // return 0; //} if( !MaxSolveDepth.set ) MaxSolveDepth.value = Depth.value; if( SolverDivide.value<MinDepth.value ) { fprintf( stderr , "[WARNING] %s must be at least as large as %s: %d>=%d\n" , SolverDivide.name , MinDepth.name , SolverDivide.value , MinDepth.value ); SolverDivide.value = MinDepth.value; } if( IsoDivide.value<MinDepth.value ) { fprintf( stderr , "[WARNING] %s must be at least as large as %s: %d>=%d\n" , IsoDivide.name , MinDepth.name , IsoDivide.value , IsoDivide.value ); IsoDivide.value = MinDepth.value; } OctNode< TreeNodeData< true > , Real >::SetAllocator( MEMORY_ALLOCATOR_BLOCK_SIZE ); t=Time(); int kernelDepth = KernelDepth.set ? KernelDepth.value : Depth.value-2; tree.setBSplineData( Depth.value , BoundaryType.value ); //if( kernelDepth>Depth.value ) //{ // fprintf( stderr,"[ERROR] %s can't be greater than %s: %d <= %d\n" , KernelDepth.name , Depth.name , KernelDepth.value , Depth.value ); // return EXIT_FAILURE; //} // int pointNumber = pPC->GetPointNumber(); std::vector<float> posList(pointNumber * 3); std::vector<float> norList(pointNumber * 3); for (int pIndex = 0; pIndex < pointNumber; pIndex++) { posList.at(3 * pIndex + 0) = pPC->GetPoint(pIndex)->GetPosition()[0]; posList.at(3 * pIndex + 1) = pPC->GetPoint(pIndex)->GetPosition()[1]; posList.at(3 * pIndex + 2) = pPC->GetPoint(pIndex)->GetPosition()[2]; norList.at(3 * pIndex + 0) = pPC->GetPoint(pIndex)->GetNormal()[0]; norList.at(3 * pIndex + 1) = pPC->GetPoint(pIndex)->GetNormal()[1]; norList.at(3 * pIndex + 2) = pPC->GetPoint(pIndex)->GetNormal()[2]; } // double maxMemoryUsage; t=Time() , tree.maxMemoryUsage=0; //int pointCount = tree.setTree( In.value , Depth.value , MinDepth.value , kernelDepth , Real(SamplesPerNode.value) , Scale.value , Confidence.set , PointWeight.value , AdaptiveExponent.value , xForm ); int pointCount = tree.setTree( posList, norList, Depth.value , MinDepth.value , kernelDepth , Real(SamplesPerNode.value) , Scale.value , Confidence.set , PointWeight.value , AdaptiveExponent.value , xForm ); tree.ClipTree(); tree.finalize( IsoDivide.value ); /*DumpOutput2( comments[commentNum++] , "# Tree set in: %9.1f (s), %9.1f (MB)\n" , Time()-t , tree.maxMemoryUsage ); DumpOutput( "Input Points: %d\n" , pointCount ); DumpOutput( "Leaves/Nodes: %d/%d\n" , tree.tree.leaves() , tree.tree.nodes() ); DumpOutput( "Memory Usage: %.3f MB\n" , float( MemoryInfo::Usage() )/(1<<20) );*/ maxMemoryUsage = tree.maxMemoryUsage; t=Time() , tree.maxMemoryUsage=0; tree.SetLaplacianConstraints(); /*DumpOutput2( comments[commentNum++] , "# Constraints set in: %9.1f (s), %9.1f (MB)\n" , Time()-t , tree.maxMemoryUsage ); DumpOutput( "Memory Usage: %.3f MB\n" , float( MemoryInfo::Usage())/(1<<20) );*/ maxMemoryUsage = std::max< double >( maxMemoryUsage , tree.maxMemoryUsage ); t=Time() , tree.maxMemoryUsage=0; tree.LaplacianMatrixIteration( SolverDivide.value, ShowResidual.set , MinIters.value , SolverAccuracy.value , MaxSolveDepth.value , FixedIters.value ); /*DumpOutput2( comments[commentNum++] , "# Linear system solved in: %9.1f (s), %9.1f (MB)\n" , Time()-t , tree.maxMemoryUsage ); DumpOutput( "Memory Usage: %.3f MB\n" , float( MemoryInfo::Usage() )/(1<<20) );*/ maxMemoryUsage = std::max< double >( maxMemoryUsage , tree.maxMemoryUsage ); CoredFileMeshData< PlyValueVertex< Real > > mesh; if( Verbose.set ) tree.maxMemoryUsage=0; t=Time(); isoValue = tree.GetIsoValue(); //DumpOutput( "Got average in: %f\n" , Time()-t ); //DumpOutput( "Iso-Value: %e\n" , isoValue ); if( VoxelGrid.set ) { double t = Time(); FILE* fp = fopen( VoxelGrid.value , "wb" ); if( !fp ) fprintf( stderr , "Failed to open voxel file for writing: %s\n" , VoxelGrid.value ); else { int res; Pointer( Real ) values = tree.GetSolutionGrid( res , isoValue , VoxelDepth.value ); fwrite( &res , sizeof(int) , 1 , fp ); if( sizeof(Real)==sizeof(float) ) fwrite( values , sizeof(float) , res*res*res , fp ); else { float *fValues = new float[res*res*res]; for( int i=0 ; i<res*res*res ; i++ ) fValues[i] = float( values[i] ); fwrite( fValues , sizeof(float) , res*res*res , fp ); delete[] fValues; } fclose( fp ); DeletePointer( values ); } //DumpOutput( "Got voxel grid in: %f\n" , Time()-t ); } if( Out.set ) { t = Time() , tree.maxMemoryUsage = 0; tree.GetMCIsoTriangles( isoValue , IsoDivide.value , &mesh , 0 , 1 , !NonManifold.set , PolygonMesh.set ); //if( PolygonMesh.set ) DumpOutput2( comments[commentNum++] , "# Got polygons in: %9.1f (s), %9.1f (MB)\n" , Time()-t , tree.maxMemoryUsage ); //else DumpOutput2( comments[commentNum++] , "# Got triangles in: %9.1f (s), %9.1f (MB)\n" , Time()-t , tree.maxMemoryUsage ); maxMemoryUsage = std::max< double >( maxMemoryUsage , tree.maxMemoryUsage ); //DumpOutput2( comments[commentNum++],"# Total Solve: %9.1f (s), %9.1f (MB)\n" , Time()-tt , maxMemoryUsage ); //if( NoComments.set ) //{ // if( ASCII.set ) PlyWritePolygons( Out.value , &mesh , PLY_ASCII , NULL , 0 , iXForm ); // else PlyWritePolygons( Out.value , &mesh , PLY_BINARY_NATIVE , NULL , 0 , iXForm ); //} //else //{ // if( ASCII.set ) PlyWritePolygons( Out.value , &mesh , PLY_ASCII , comments , commentNum , iXForm ); // else PlyWritePolygons( Out.value , &mesh , PLY_BINARY_NATIVE , comments , commentNum , iXForm ); //} vertices.clear(); polygons.clear(); int incorePointNum = int( mesh.inCorePoints.size() ); int outofcorePointNum = mesh.outOfCorePointCount(); DebugLog << "incorePointNum: " << incorePointNum << std::endl; DebugLog << "outofcorePointNum: " << outofcorePointNum << std::endl; mesh.resetIterator(); for(int pIndex = 0 ; pIndex < incorePointNum ; pIndex++ ) { PlyValueVertex< Real > vertex = iXForm * mesh.inCorePoints[pIndex]; vertices.push_back(vertex); //ply_put_element(ply, (void *) &vertex); } for(int pIndex = 0; pIndex < outofcorePointNum; pIndex++ ) { PlyValueVertex< Real > vertex; mesh.nextOutOfCorePoint( vertex ); vertex = iXForm * ( vertex ); vertices.push_back(vertex); //ply_put_element(ply, (void *) &vertex); } int polyNum = mesh.polygonCount(); DebugLog << "polyNum: " << polyNum << std::endl; for (int pIndex = 0; pIndex < polyNum; pIndex++) { std::vector< CoredVertexIndex > coreIndex; mesh.nextPolygon(coreIndex); std::vector< int > pureIndex; for (int ii = 0; ii < coreIndex.size(); ii++) { if (coreIndex.at(ii).inCore) { pureIndex.push_back(coreIndex.at(ii).idx); } else { pureIndex.push_back(coreIndex.at(ii).idx + incorePointNum); } } if (coreIndex.size() != 3) { DebugLog << "Error: coreIndex.size: " << coreIndex.size() << std::endl; } polygons.push_back(pureIndex); } //just for test /*DebugLog << "Export inter object" << std::endl; std::ofstream fout("pc_inter.obj"); for (int pIndex = 0; pIndex < vertices.size(); pIndex++) { PlyValueVertex< float > vert = vertices.at(pIndex); fout << "v " << vert.point[0] << " " << vert.point[1] << " " << vert.point[2] << std::endl; } for (int pIndex = 0; pIndex < polygons.size(); pIndex++) { fout << "f " << polygons.at(pIndex).at(0) + 1 << " " << polygons.at(pIndex).at(1) + 1 << " " << polygons.at(pIndex).at(2) + 1 << std::endl; } fout.close();*/ } }
double PosteriorElasticPDF3D::FindDensity(const double & vp, const double & vs, const double & rho, const double & s1, const double & s2, const Simbox * const volume) const { double value = 0.0; // if the size of v1 and v2 > 0 the PDF has been constructed with dimension reduction and one trend value if (v1_.size()>0 && v2_.size()>0) { value = Density(vp, vs, rho, s1, s2); if (value == RMISSING) value = 0.0; } else { double jFull, kFull, lFull; volume->getInterpolationIndexes(vp, vs, rho, jFull, kFull, lFull); int j1,k1,l1; int j2,k2,l2; float wj,wk,wl; j1=k1=l1=j2=k2=l2=0; j1 = static_cast<int>(floor(jFull)); if(j1<0) { j1 = 0; j2 = 0; wj = 0; } else if(j1>=volume->getnx()-1) { j1 = volume->getnx()-1; j2 = j1; wj = 0; } else { j2 = j1 + 1; wj = static_cast<float>(jFull-j1); } k1 = static_cast<int>(floor(kFull)); if(k1<0) { k1 = 0; k2 = 0; wk = 0; } else if(k1>=volume->getny()-1) { k1 = volume->getny()-1; k2 = k1; wk = 0; } else { k2 = k1 + 1; wk = static_cast<float>(kFull-k1); } l1 = static_cast<int>(floor(lFull)); if(l1<0) { l1 = 0; l2 = 0; wl = 0; } else if(l1>=volume->getnz()-1) { l1 = volume->getnz()-1; l2 = l1; wl = 0; } else { l2 = l1 + 1; wl = static_cast<float>(lFull-l1); } histogram_->setAccessMode(FFTGrid::RANDOMACCESS); float value1 = std::max<float>(0,histogram_->getRealValue(j1,k1,l1)); float value2 = std::max<float>(0,histogram_->getRealValue(j1,k1,l2)); float value3 = std::max<float>(0,histogram_->getRealValue(j1,k2,l1)); float value4 = std::max<float>(0,histogram_->getRealValue(j1,k2,l2)); float value5 = std::max<float>(0,histogram_->getRealValue(j2,k1,l1)); float value6 = std::max<float>(0,histogram_->getRealValue(j2,k1,l2)); float value7 = std::max<float>(0,histogram_->getRealValue(j2,k2,l1)); float value8 = std::max<float>(0,histogram_->getRealValue(j2,k2,l2)); histogram_->endAccess(); value += (1.0f-wj)*(1.0f-wk)*(1.0f-wl)*value1; value += (1.0f-wj)*(1.0f-wk)*( wl)*value2; value += (1.0f-wj)*( wk)*(1.0f-wl)*value3; value += (1.0f-wj)*( wk)*( wl)*value4; value += ( wj)*(1.0f-wk)*(1.0f-wl)*value5; value += ( wj)*(1.0f-wk)*( wl)*value6; value += ( wj)*( wk)*(1.0f-wl)*value7; value += ( wj)*( wk)*( wl)*value8; } return value; }
double MOCFluid::TranMassToQ(double dMass) { return dMass / Density(); }
//计算本结点出,入口动压变化,只要是交接处管道出入口静压都要减去该动压损失 double MOCFluid::CalcPressLoss(double dMass,double dArea) { double dV = dMass/Density()/dArea; return 0.5*Density()*pow(dV,2); }
double MOCFluid::TranQToMass(double dQ) { return Density()*dQ; }
double MOCFluid::TranPressToH(double dPress) { return dPress/Density()/Gravity(); }
double MOCFluid::TranPressToHGL(double dPress) { return (dPress-m_dAtmosphericPressure)/Density()/Gravity(); }
double MOCFluid::TranHToPress(double dH) { return Density()*Gravity()*dH; }