void StrokeManager::mouseMoveEvent(QMouseEvent *event) { QPointF pos = getEventPosition(event); m_lastPixel = m_currentPixel; m_currentPixel = pos; if (!m_strokeStarted) return; if (!m_tabletInUse) // a mouse is used instead of a tablet { setPressure(1.0); } // shift queue while (strokeQueue.size() >= STROKE_QUEUE_LENGTH) { strokeQueue.removeFirst(); } strokeQueue << pos; }
void ToolOptionWidget::onToolPropertyChanged( ToolType, ToolPropertyType ePropertyType ) { const Properties& p = editor()->tools()->currentTool()->properties; switch ( ePropertyType ) { case WIDTH: setPenWidth( p.width ); break; case FEATHER: setPenFeather( p.feather ); break; case PRESSURE: setPressure( p.pressure ); break; case INVISIBILITY: setPenInvisibility( p.invisibility ); break; case PRESERVEALPHA: setPreserveAlpha( p.preserveAlpha ); break; case VECTORMERGE: setVectorMergeEnabled(p.vectorMergeEnabled); break; case ANTI_ALIASING: setAA(p.useAA); break; case INTERPOLATION: setInpolLevel(p.inpolLevel); break; } }
// The loop function is called in an endless loop void loop() { delay(SENSOR_CHANGE_TRIGGER_TIME); unsigned long unchangedTime = millis() - lastMotionDetected; if (unchangedTime < MAX_ON_TIME) { lcd.display(); lcd.backlight(); switch (sensor) { case TEMPERATURE_SENSOR_NUM: setTemperature(); break; case HUMIDITY_SENSOR_NUM: setHumidity(); break; case SOIL_SENSOR_NUM: setSoilHumidity(); break; case PRESSURE_SENSOR_NUM: setPressure(); break; } } else { lcd.noDisplay(); lcd.noBacklight(); } delay(500); }
void BrushTool::loadSettings() { m_enabledProperties[WIDTH] = true; m_enabledProperties[FEATHER] = true; m_enabledProperties[PRESSURE] = true; QSettings settings( "Pencil", "Pencil" ); properties.width = settings.value( "brushWidth" ).toDouble(); properties.feather = settings.value( "brushFeather" ).toDouble(); properties.pressure = settings.value( "brushPressure" ).toBool(); properties.invisibility = DISABLED; properties.preserveAlpha = OFF; // First run // if ( properties.width <= 0 ) { setWidth(15); setFeather(15); setPressure(1); } }
// Mean sampling interpolation operation QList<QPointF> StrokeManager::meanInpolOp(QList<QPointF> points, qreal x, qreal y, qreal pressure) { for (int i = 0; i < strokeQueue.size(); i++) { x += strokeQueue[i].x(); y += strokeQueue[i].y(); pressure += getPressure(); } // get arichmic mean of x, y and pressure x /= strokeQueue.size(); y /= strokeQueue.size(); pressure /= strokeQueue.size(); // Use our interpolated points QPointF mNewInterpolated = mLastInterpolated; mNewInterpolated = QPointF(x,y); //save our new pressure value setPressure(pressure); points << mLastPixel << mLastInterpolated << mNewInterpolated << mCurrentPixel; // Set lastPixel non interpolated pixel to our // new interpolated pixel mLastPixel = mNewInterpolated; return points; }
void ToolOptionWidget::updateUI() { BaseTool* currentTool = editor()->tools()->currentTool(); Q_ASSERT( currentTool ); disableAllOptions(); mSizeSlider->setVisible( currentTool->isPropertyEnabled( WIDTH ) ); mBrushSpinBox->setVisible( currentTool->isPropertyEnabled( WIDTH) ); mFeatherSlider->setVisible( currentTool->isPropertyEnabled( FEATHER ) ); mUseFeatherBox->setVisible( currentTool->isPropertyEnabled( FEATHER ) ); mFeatherSpinBox->setVisible( currentTool->isPropertyEnabled( FEATHER) ); mUseBezierBox->setVisible( currentTool->isPropertyEnabled( BEZIER ) ); mUsePressureBox->setVisible( currentTool->isPropertyEnabled( PRESSURE ) ); mMakeInvisibleBox->setVisible( currentTool->isPropertyEnabled( INVISIBILITY ) ); mPreserveAlphaBox->setVisible( currentTool->isPropertyEnabled( PRESERVEALPHA ) ); const Properties& p = currentTool->properties; setPenWidth( p.width ); setPenFeather( p.feather ); setPressure( p.pressure ); setPenInvisibility( p.invisibility ); setPreserveAlpha( p.preserveAlpha ); }
void ThermoPhase::setState_conditional_TP(doublereal t, doublereal p, bool set_p) { setTemperature(t); if (set_p) { setPressure(p); } }
void StrokeManager::tabletEvent(QTabletEvent *event) { if (event->type() == QEvent::TabletPress) { m_tabletInUse = true; } if (event->type() == QEvent::TabletRelease) { m_tabletInUse = false; } m_tabletPosition = event->hiResGlobalPos(); setPressure(event->pressure()); }
/* * Set the thermodynamic state. */ void MolalityVPSSTP::setStateFromXML(const XML_Node& state) { VPStandardStateTP::setStateFromXML(state); string comp = ctml::getChildValue(state,"soluteMolalities"); if (comp != "") { setMolalitiesByName(comp); } if (state.hasChild("pressure")) { double p = ctml::getFloat(state, "pressure", "pressure"); setPressure(p); } }
QList<QPointF> StrokeManager::noInpolOp(QList<QPointF> points) { setPressure(getPressure()); points << mLastPixel << mLastPixel << mCurrentPixel << mCurrentPixel; // Set lastPixel non CurrentPixel // new interpolated pixel mLastPixel = mCurrentPixel; return points; }
void SingleSpeciesTP::setState_SP(doublereal s, doublereal p, doublereal tol) { doublereal dt; setPressure(p); for (int n = 0; n < 50; n++) { dt = clip((s - entropy_mass())*temperature()/cp_mass(), -100.0, 100.0); setState_TP(temperature() + dt, p); if (fabs(dt) < tol) { return; } } throw CanteraError("setState_SP","no convergence. dt = " + fp2str(dt)); }
void PreferencesUnits::syncSettings() { auto units = SettingsObjectWrapper::instance()->unit_settings; QString unitSystem[] = {"metric", "imperial", "personal"}; short unitValue = ui->metric->isChecked() ? METRIC : (ui->imperial->isChecked() ? IMPERIAL : PERSONALIZE); units->setUnitSystem(unitSystem[unitValue]); units->setTemperature(ui->fahrenheit->isChecked() ? units::FAHRENHEIT : units::CELSIUS); units->setLength(ui->feet->isChecked() ? units::FEET : units::METERS); units->setPressure(ui->psi->isChecked() ? units::PSI : units::BAR); units->setVolume(ui->cuft->isChecked() ? units::CUFT : units::LITER); units->setWeight(ui->lbs->isChecked() ? units::LBS : units::KG); units->setVerticalSpeedTime(ui->vertical_speed_minutes->isChecked() ? units::MINUTES : units::SECONDS); units->setCoordinatesTraditional(ui->gpsTraditional->isChecked()); }
void SingleSpeciesTP::setState_HP(doublereal h, doublereal p, doublereal tol) { doublereal dt; setPressure(p); for (int n = 0; n < 50; n++) { dt = (h - enthalpy_mass())/cp_mass(); if (dt > 100.0) dt = 100.0; else if (dt < -100.0) dt = -100.0; setState_TP(temperature() + dt, p); if (fabs(dt) < tol) { return; } } throw CanteraError("setState_HP","no convergence. dt = " + fp2str(dt)); }
void StrokeManager::smoothMousePos(QPointF pos) { // Smooth mouse position before drawing QPointF smoothPos; if (mInpolLevel == 0) { mLastPixel = mCurrentPixel; mCurrentPixel = pos; mLastInterpolated = mCurrentPixel; } else if (mInpolLevel == 1) { // simple interpolation smoothPos = QPointF( ( pos.x() + mCurrentPixel.x() ) / 2.0, ( pos.y() + mCurrentPixel.y() ) / 2.0 ); mLastPixel = mCurrentPixel; mCurrentPixel = smoothPos; mLastInterpolated = mCurrentPixel; // shift queue while ( strokeQueue.size() >= STROKE_QUEUE_LENGTH ) { strokeQueue.pop_front(); } strokeQueue.push_back( smoothPos ); } else if (mInpolLevel == 2 ) { smoothPos = QPointF( ( pos.x() + mLastInterpolated.x() ) / 2.0, ( pos.y() + mLastInterpolated.y() ) / 2.0 ); mLastInterpolated = mCurrentPixel; mCurrentPixel = smoothPos; mLastPixel = mLastInterpolated; } mousePos = pos; if ( !mStrokeStarted ) { return; } if (!mTabletInUse) // a mouse is used instead of a tablet { setPressure(1.0); } }
AP_ADC_HIL::AP_ADC_HIL() { // gyros set to zero for calibration setGyro(0,0); setGyro(1,0); setGyro(2,0); // accels set to zero for calibration setAccel(0,0); setAccel(1,0); setAccel(2,0); // set diff press and temp to zero setGyroTemp(0); setPressure(0); }
Cell::Cell(UNG_FLT volume, UNG_FLT density, UNG_FLT potentialTemperature, UNG_FLT lrSpeed, UNG_FLT udSpeed, UNG_FLT ioSpeed) : m_volume(volume), m_mass(volume*density), m_potentialEnergy(volume*density*potentialTemperature), m_lrSpeed(lrSpeed), m_udSpeed(udSpeed), m_ioSpeed(ioSpeed) { m_lrMom=m_lrSpeed*m_mass; m_udMom=m_udSpeed*m_mass; m_ioMom=m_ioSpeed*m_mass; m_lrSpeedStep=0; m_udSpeedStep=0; m_ioSpeedStep=0; m_densities.potentialEnergyDensity=m_potentialEnergy/m_volume; m_densities.density=density; m_densities.lrMomentumDensity=m_lrMom/m_volume; m_densities.udMomentumDensity=m_udMom/m_volume; m_densities.ioMomentumDensity=m_ioMom/m_volume; setPressure(); }
void SmudgeTool::loadSettings() { m_enabledProperties[WIDTH] = true; m_enabledProperties[FEATHER] = true; QSettings settings( PENCIL2D, PENCIL2D ); properties.width = settings.value("smudgeWidth").toDouble(); properties.feather = settings.value("smudgeFeather").toDouble(); properties.pressure = 0; // First run if (properties.width <= 0) { setWidth(25); setFeather(200); setPressure(0); } }
// Set one channel value void AP_ADC_HIL::setHIL(int16_t p, int16_t q, int16_t r, int16_t gyroTemp, int16_t aX, int16_t aY, int16_t aZ, int16_t diffPress) { // gyros setGyro(0,p); setGyro(1,q); setGyro(2,r); // temp setGyroTemp(gyroTemp); // accel setAccel(0,aX); setAccel(1,aY); setAccel(2,aZ); // differential pressure setPressure(diffPress); }
void assign(const FluidState& fs) { if (enableTemperature || enableEnergy) setTemperature(fs.temperature(/*phaseIdx=*/0)); unsigned pvtRegionIdx = getPvtRegionIndex_<FluidState>(fs); setPvtRegionIndex(pvtRegionIdx); setRs(Opm::BlackOil::getRs_<FluidSystem, FluidState, Scalar>(fs, pvtRegionIdx)); setRv(Opm::BlackOil::getRv_<FluidSystem, FluidState, Scalar>(fs, pvtRegionIdx)); for (unsigned phaseIdx = 0; phaseIdx < numPhases; ++phaseIdx) { setSaturation(phaseIdx, fs.saturation(phaseIdx)); setPressure(phaseIdx, fs.pressure(phaseIdx)); setDensity(phaseIdx, fs.density(phaseIdx)); if (enableEnergy) setEnthalpy(phaseIdx, fs.enthalpy(phaseIdx)); setInvB(phaseIdx, getInvB_<FluidSystem, FluidState, Scalar>(fs, phaseIdx, pvtRegionIdx)); } }
void PenTool::loadSettings() { m_enabledProperties[WIDTH] = true; m_enabledProperties[PRESSURE] = true; QSettings settings( PENCIL2D, PENCIL2D ); properties.width = settings.value( "penWidth" ).toDouble(); properties.feather = 80; properties.pressure = settings.value( "penPressure" ).toBool(); properties.invisibility = OFF; properties.preserveAlpha = OFF; // First run if ( properties.width <= 0 ) { setWidth(1.5); setPressure(1); } mCurrentWidth = properties.width; }
void Cell::completeStep() { m_lrSpeed=m_lrMom/m_mass+m_lrSpeedStep; m_udSpeed=m_udMom/m_mass+m_udSpeedStep; m_ioSpeed=m_ioMom/m_mass+m_ioSpeedStep; m_lrMom=m_lrSpeed*m_mass; m_udMom=m_udSpeed*m_mass; m_ioMom=m_ioSpeed*m_mass; m_lrSpeedStep=0; m_udSpeedStep=0; m_ioSpeedStep=0; m_densities.density=m_mass/m_volume; m_densities.potentialEnergyDensity=m_potentialEnergy/m_volume; m_densities.lrMomentumDensity=m_lrMom/m_volume; m_densities.udMomentumDensity=m_udMom/m_volume; m_densities.ioMomentumDensity=m_ioMom/m_volume; setPressure(); }
void ToolOptionWidget::onToolPropertyChanged( ToolType, ToolPropertyType ePropertyType ) { const Properties& p = editor()->tools()->currentTool()->properties; switch ( ePropertyType ) { case WIDTH: setPenWidth( p.width ); break; case FEATHER: setPenFeather( p.feather ); break; case PRESSURE: setPressure( p.pressure ); break; case INVISIBILITY: setPenInvisibility( p.invisibility ); break; case PRESERVEALPHA: setPreserveAlpha( p.preserveAlpha ); break; } }
void ToolOptionWidget::updateUI() { BaseTool* currentTool = editor()->tools()->currentTool(); Q_ASSERT( currentTool ); disableAllOptions(); mSizeSlider->setVisible( currentTool->isPropertyEnabled( WIDTH ) ); mBrushSpinBox->setVisible( currentTool->isPropertyEnabled( WIDTH) ); mFeatherSlider->setVisible( currentTool->isPropertyEnabled( FEATHER ) ); mUseFeatherBox->setVisible( currentTool->isPropertyEnabled( FEATHER ) ); mFeatherSpinBox->setVisible( currentTool->isPropertyEnabled( FEATHER) ); mUseBezierBox->setVisible( currentTool->isPropertyEnabled( BEZIER ) ); mUsePressureBox->setVisible( currentTool->isPropertyEnabled( PRESSURE ) ); mMakeInvisibleBox->setVisible( currentTool->isPropertyEnabled( INVISIBILITY ) ); mPreserveAlphaBox->setVisible( currentTool->isPropertyEnabled( PRESERVEALPHA ) ); mUseAABox->setVisible(currentTool->isPropertyEnabled( ANTI_ALIASING ) ); mInpolLevelsBox->setVisible(currentTool->isPropertyEnabled( INTERPOLATION ) ); auto currentLayerType = editor()->layers()->currentLayer()->type(); if(currentLayerType == Layer::VECTOR) { mVectorMergeBox->setVisible( currentTool->isPropertyEnabled( VECTORMERGE) ); } const Properties& p = currentTool->properties; setPenWidth( p.width ); setPenFeather( p.feather ); setPressure( p.pressure ); setPenInvisibility( p.invisibility ); setPreserveAlpha( p.preserveAlpha ); setVectorMergeEnabled( p.vectorMergeEnabled ); setAA(p.useAA); setInpolLevel(p.inpolLevel); }
void ThermoPhase::setStateFromXML(const XML_Node& state) { string comp = getChildValue(state,"moleFractions"); if (comp != "") { setMoleFractionsByName(comp); } else { comp = getChildValue(state,"massFractions"); if (comp != "") { setMassFractionsByName(comp); } } if (state.hasChild("temperature")) { double t = getFloat(state, "temperature", "temperature"); setTemperature(t); } if (state.hasChild("pressure")) { double p = getFloat(state, "pressure", "pressure"); setPressure(p); } if (state.hasChild("density")) { double rho = getFloat(state, "density", "density"); setDensity(rho); } }
void ThermoPhase::setState_PX(doublereal p, doublereal* x) { setMoleFractions(x); setPressure(p); }
void PDSS_ConstVol::setState_TP(doublereal temp, doublereal pres) { setTemperature(temp); setPressure(pres); }
void ThermoPhase::setState_SPorSV(doublereal Starget, doublereal p, doublereal dTtol, bool doSV) { doublereal v = 0.0; doublereal dt; if (doSV) { v = p; if (v < 1.0E-300) { throw CanteraError("setState_SPorSV (SV)", "Input specific volume is too small or negative. v = {}", v); } setDensity(1.0/v); } else { if (p < 1.0E-300) { throw CanteraError("setState_SPorSV (SP)", "Input pressure is too small or negative. p = {}", p); } setPressure(p); } double Tmax = maxTemp() + 0.1; double Tmin = minTemp() - 0.1; // Make sure we are within the temperature bounds at the start // of the iteration double Tnew = temperature(); double Tinit = Tnew; if (Tnew > Tmax) { Tnew = Tmax - 1.0; } else if (Tnew < Tmin) { Tnew = Tmin + 1.0; } if (Tnew != Tinit) { setState_conditional_TP(Tnew, p, !doSV); } double Snew = entropy_mass(); double Cpnew = (doSV) ? cv_mass() : cp_mass(); double Stop = Snew; double Ttop = Tnew; double Sbot = Snew; double Tbot = Tnew; bool ignoreBounds = false; // Unstable phases are those for which Cp < 0.0. These are possible for // cases where we have passed the spinodal curve. bool unstablePhase = false; double Tunstable = -1.0; bool unstablePhaseNew = false; // Newton iteration for (int n = 0; n < 500; n++) { double Told = Tnew; double Sold = Snew; double cpd = Cpnew; if (cpd < 0.0) { unstablePhase = true; Tunstable = Tnew; } // limit step size to 100 K dt = clip((Starget - Sold)*Told/cpd, -100.0, 100.0); Tnew = Told + dt; // Limit the step size so that we are convergent if ((dt > 0.0 && unstablePhase) || (dt <= 0.0 && !unstablePhase)) { if (Sbot < Starget && Tnew < Tbot) { dt = 0.75 * (Tbot - Told); Tnew = Told + dt; } } else if (Stop > Starget && Tnew > Ttop) { dt = 0.75 * (Ttop - Told); Tnew = Told + dt; } // Check Max and Min values if (Tnew > Tmax && !ignoreBounds) { setState_conditional_TP(Tmax, p, !doSV); double Smax = entropy_mass(); if (Smax >= Starget) { if (Stop < Starget) { Ttop = Tmax; Stop = Smax; } } else { Tnew = Tmax + 1.0; ignoreBounds = true; } } else if (Tnew < Tmin && !ignoreBounds) { setState_conditional_TP(Tmin, p, !doSV); double Smin = entropy_mass(); if (Smin <= Starget) { if (Sbot > Starget) { Tbot = Tmin; Sbot = Smin; } } else { Tnew = Tmin - 1.0; ignoreBounds = true; } } // Try to keep phase within its region of stability // -> Could do a lot better if I calculate the // spinodal value of H. for (int its = 0; its < 10; its++) { Tnew = Told + dt; setState_conditional_TP(Tnew, p, !doSV); Cpnew = (doSV) ? cv_mass() : cp_mass(); Snew = entropy_mass(); if (Cpnew < 0.0) { unstablePhaseNew = true; Tunstable = Tnew; } else { unstablePhaseNew = false; break; } if (unstablePhase == false && unstablePhaseNew == true) { dt *= 0.25; } } if (Snew == Starget) { return; } else if (Snew > Starget && (Stop < Starget || Snew < Stop)) { Stop = Snew; Ttop = Tnew; } else if (Snew < Starget && (Sbot > Starget || Snew > Sbot)) { Sbot = Snew; Tbot = Tnew; } // Convergence in S double Serr = Starget - Snew; double acpd = std::max(fabs(cpd), 1.0E-5); double denom = std::max(fabs(Starget), acpd * dTtol); double SConvErr = fabs((Serr * Tnew)/denom); if (SConvErr < 0.00001 *dTtol || fabs(dt) < dTtol) { return; } } // We are here when there hasn't been convergence // Formulate a detailed error message, since questions seem to arise often // about the lack of convergence. string ErrString = "No convergence in 500 iterations\n"; if (doSV) { ErrString += fmt::format( "\tTarget Entropy = {}\n" "\tCurrent Specific Volume = {}\n" "\tStarting Temperature = {}\n" "\tCurrent Temperature = {}\n" "\tCurrent Entropy = {}\n" "\tCurrent Delta T = {}\n", Starget, v, Tinit, Tnew, Snew, dt); } else { ErrString += fmt::format( "\tTarget Entropy = {}\n" "\tCurrent Pressure = {}\n" "\tStarting Temperature = {}\n" "\tCurrent Temperature = {}\n" "\tCurrent Entropy = {}\n" "\tCurrent Delta T = {}\n", Starget, p, Tinit, Tnew, Snew, dt); } if (unstablePhase) { ErrString += fmt::format("\t - The phase became unstable (Cp < 0) T_unstable_last = {}\n", Tunstable); } if (doSV) { throw CanteraError("setState_SPorSV (SV)", ErrString); } else { throw CanteraError("setState_SPorSV (SP)", ErrString); } }
void ThermoPhase::setState_HPorUV(doublereal Htarget, doublereal p, doublereal dTtol, bool doUV) { doublereal dt; doublereal v = 0.0; // Assign the specific volume or pressure and make sure it's positive if (doUV) { doublereal v = p; if (v < 1.0E-300) { throw CanteraError("setState_HPorUV (UV)", "Input specific volume is too small or negative. v = {}", v); } setDensity(1.0/v); } else { if (p < 1.0E-300) { throw CanteraError("setState_HPorUV (HP)", "Input pressure is too small or negative. p = {}", p); } setPressure(p); } double Tmax = maxTemp() + 0.1; double Tmin = minTemp() - 0.1; // Make sure we are within the temperature bounds at the start // of the iteration double Tnew = temperature(); double Tinit = Tnew; if (Tnew > Tmax) { Tnew = Tmax - 1.0; } else if (Tnew < Tmin) { Tnew = Tmin + 1.0; } if (Tnew != Tinit) { setState_conditional_TP(Tnew, p, !doUV); } double Hnew = (doUV) ? intEnergy_mass() : enthalpy_mass(); double Cpnew = (doUV) ? cv_mass() : cp_mass(); double Htop = Hnew; double Ttop = Tnew; double Hbot = Hnew; double Tbot = Tnew; bool ignoreBounds = false; // Unstable phases are those for which cp < 0.0. These are possible for // cases where we have passed the spinodal curve. bool unstablePhase = false; // Counter indicating the last temperature point where the // phase was unstable double Tunstable = -1.0; bool unstablePhaseNew = false; // Newton iteration for (int n = 0; n < 500; n++) { double Told = Tnew; double Hold = Hnew; double cpd = Cpnew; if (cpd < 0.0) { unstablePhase = true; Tunstable = Tnew; } // limit step size to 100 K dt = clip((Htarget - Hold)/cpd, -100.0, 100.0); // Calculate the new T Tnew = Told + dt; // Limit the step size so that we are convergent This is the step that // makes it different from a Newton's algorithm if ((dt > 0.0 && unstablePhase) || (dt <= 0.0 && !unstablePhase)) { if (Hbot < Htarget && Tnew < (0.75 * Tbot + 0.25 * Told)) { dt = 0.75 * (Tbot - Told); Tnew = Told + dt; } } else if (Htop > Htarget && Tnew > (0.75 * Ttop + 0.25 * Told)) { dt = 0.75 * (Ttop - Told); Tnew = Told + dt; } // Check Max and Min values if (Tnew > Tmax && !ignoreBounds) { setState_conditional_TP(Tmax, p, !doUV); double Hmax = (doUV) ? intEnergy_mass() : enthalpy_mass(); if (Hmax >= Htarget) { if (Htop < Htarget) { Ttop = Tmax; Htop = Hmax; } } else { Tnew = Tmax + 1.0; ignoreBounds = true; } } if (Tnew < Tmin && !ignoreBounds) { setState_conditional_TP(Tmin, p, !doUV); double Hmin = (doUV) ? intEnergy_mass() : enthalpy_mass(); if (Hmin <= Htarget) { if (Hbot > Htarget) { Tbot = Tmin; Hbot = Hmin; } } else { Tnew = Tmin - 1.0; ignoreBounds = true; } } // Try to keep phase within its region of stability // -> Could do a lot better if I calculate the // spinodal value of H. for (int its = 0; its < 10; its++) { Tnew = Told + dt; if (Tnew < Told / 3.0) { Tnew = Told / 3.0; dt = -2.0 * Told / 3.0; } setState_conditional_TP(Tnew, p, !doUV); if (doUV) { Hnew = intEnergy_mass(); Cpnew = cv_mass(); } else { Hnew = enthalpy_mass(); Cpnew = cp_mass(); } if (Cpnew < 0.0) { unstablePhaseNew = true; Tunstable = Tnew; } else { unstablePhaseNew = false; break; } if (unstablePhase == false && unstablePhaseNew == true) { dt *= 0.25; } } if (Hnew == Htarget) { return; } else if (Hnew > Htarget && (Htop < Htarget || Hnew < Htop)) { Htop = Hnew; Ttop = Tnew; } else if (Hnew < Htarget && (Hbot > Htarget || Hnew > Hbot)) { Hbot = Hnew; Tbot = Tnew; } // Convergence in H double Herr = Htarget - Hnew; double acpd = std::max(fabs(cpd), 1.0E-5); double denom = std::max(fabs(Htarget), acpd * dTtol); double HConvErr = fabs((Herr)/denom); if (HConvErr < 0.00001 *dTtol || fabs(dt) < dTtol) { return; } } // We are here when there hasn't been convergence // Formulate a detailed error message, since questions seem to arise often // about the lack of convergence. string ErrString = "No convergence in 500 iterations\n"; if (doUV) { ErrString += fmt::format( "\tTarget Internal Energy = {}\n" "\tCurrent Specific Volume = {}\n" "\tStarting Temperature = {}\n" "\tCurrent Temperature = {}\n" "\tCurrent Internal Energy = {}\n" "\tCurrent Delta T = {}\n", Htarget, v, Tinit, Tnew, Hnew, dt); } else { ErrString += fmt::format( "\tTarget Enthalpy = {}\n" "\tCurrent Pressure = {}\n" "\tStarting Temperature = {}\n" "\tCurrent Temperature = {}\n" "\tCurrent Enthalpy = {}\n" "\tCurrent Delta T = {}\n", Htarget, p, Tinit, Tnew, Hnew, dt); } if (unstablePhase) { ErrString += fmt::format( "\t - The phase became unstable (Cp < 0) T_unstable_last = {}\n", Tunstable); } if (doUV) { throw CanteraError("setState_HPorUV (UV)", ErrString); } else { throw CanteraError("setState_HPorUV (HP)", ErrString); } }
void WeatherPlugin::element_end(const char *el) { if (!strcmp(el, "obst")){ setLocation(m_data.c_str()); m_data = ""; return; } if (!strcmp(el, "lsup")){ setUpdated(m_data.c_str()); m_data = ""; return; } if (!strcmp(el, "sunr") && m_bCC){ setSun_raise(m_data.c_str()); m_data = ""; return; } if (!strcmp(el, "suns") && m_bCC){ setSun_set(m_data.c_str()); m_data = ""; return; } if (!strcmp(el, "vis") && m_bCC){ setVisibility(m_data.c_str()); m_data = ""; return; } if (!strcmp(el, "tmp") && m_bCC){ setTemperature(atol(m_data.c_str())); m_data = ""; return; } if (!strcmp(el, "flik") && m_bCC){ setFeelsLike(atol(m_data.c_str())); m_data = ""; return; } if (!strcmp(el, "devp") && m_bCC){ setDewPoint(atol(m_data.c_str())); m_data = ""; return; } if (!strcmp(el, "hmid") && m_bCC){ setHumidity(atol(m_data.c_str())); m_data = ""; return; } if (!strcmp(el, "low") && m_day){ setMinT(m_day, m_data.c_str()); m_data = ""; return; } if (!strcmp(el, "hi") && m_day){ setMaxT(m_day, m_data.c_str()); m_data = ""; return; } if (!strcmp(el, "t")){ if (!m_bBar && !m_bWind && !m_bUv){ if (m_bCC){ setConditions(m_data.c_str()); }else{ setDayConditions(m_day, m_data.c_str()); } } if (m_bWind && m_bCC) setWind(m_data.c_str()); m_data = ""; return; } if (!strcmp(el, "icon")){ if (m_bCC){ setIcon(atol(m_data.c_str())); }else{ setDayIcon(m_day, m_data.c_str()); } m_data = ""; return; } if (!strcmp(el, "ut")){ setUT(m_data.c_str()); m_data = ""; return; } if (!strcmp(el, "up")){ setUP(m_data.c_str()); m_data = ""; return; } if (!strcmp(el, "us")){ setUS(m_data.c_str()); m_data = ""; return; } if (!strcmp(el, "gust") && m_bCC){ setWindGust(atol(m_data.c_str())); m_data = ""; return; } if (!strcmp(el, "bar")){ m_bBar = false; return; } if (!strcmp(el, "cc")){ m_bCC = false; return; } if (!strcmp(el, "r") && m_bBar && m_bCC){ unsigned long v = 0; for (const char *p = m_data.c_str(); *p; p++){ if (*p == '.') break; if (*p == ',') continue; v = (v * 10) + (*p - '0'); } setPressure(v); return; } if (!strcmp(el, "d") && m_bBar && m_bCC){ setPressureD(m_data.c_str()); m_data = ""; return; } if (!strcmp(el, "wind")){ m_bWind = false; return; } if (!strcmp(el, "s") && m_bWind && m_bCC){ setWind_speed(atol(m_data.c_str())); return; } if (!strcmp(el, "uv")){ m_bUv = false; return; } }
void ThermoPhase::setState_PY(doublereal p, doublereal* y) { setMassFractions(y); setPressure(p); }