void RecoveryModulus<EvalT, Traits>:: evaluateFields(typename Traits::EvalData workset) { int numCells = workset.numCells; if (is_constant) { for (int cell=0; cell < numCells; ++cell) { for (int qp=0; qp < numQPs; ++qp) { recoveryModulus(cell,qp) = constant_value; } } } #ifdef ALBANY_STOKHOS else { for (int cell=0; cell < numCells; ++cell) { for (int qp=0; qp < numQPs; ++qp) { Teuchos::Array<MeshScalarT> point(numDims); for (int i=0; i<numDims; i++) point[i] = Sacado::ScalarValue<MeshScalarT>::eval(coordVec(cell,qp,i)); recoveryModulus(cell,qp) = exp_rf_kl->evaluate(point, rv); } } } #endif if (isThermoElastic) { for (int cell=0; cell < numCells; ++cell) { for (int qp=0; qp < numQPs; ++qp) { if (Temperature(cell,qp) != 0) recoveryModulus(cell,qp) = c1 * std::exp(c2 / Temperature(cell,qp)); else recoveryModulus(cell,qp) = 0.0; } } } }
//double MatterFreeE::DeltaFree(double T) double MatterFreeE::Pressure(double Dencity,double Energy) { double T; if (fabs(L_D-Dencity)+fabs(L_E-Energy)<MathZer) T=L_T; else T=Temperature(Dencity,Energy); return FreeEPtr->Pressure(Dencity,T); };
void MatterFreeE::Pressure(double *P,double *Dencity,double *Energy,int Num) { double *T=new double[Num+1]; Temperature(T,Dencity,Energy,Num); FreeEPtr->Pressure(P,Dencity,T,Num); delete []T; };
BOOL AD7466_Driver::Initialize() { AD7466_CONFIG* Config = &g_AD7466_Config; HAL_CONFIG_BLOCK::ApplyConfig( Config->GetDriverName(), Config, sizeof(*Config) ); g_AD7466_Driver.m_Rb = Config->Thermistor_Rb; // 3.24k nominally, but may change for earlier P3s to 32.4k VoltageFilter_Reset(); // General Rule: Enable all GPIO OUTPUTs to peripherals before checking inputs from it // enable the CS for the ADC and bring it high (inactive) CPU_GPIO_EnableOutputPin( Config->SPI_Config.DeviceCS, !Config->SPI_Config.CS_Active ); // enable the ADMUX GPIO output control lines, and leave it inactive CPU_GPIO_EnableOutputPin( Config->ADMUX_EN_L_GPIO_PIN, TRUE ); CPU_GPIO_EnableOutputPin( Config->ADMUX_A0_GPIO_PIN, FALSE ); CPU_GPIO_EnableOutputPin( Config->ADMUX_A1_GPIO_PIN, FALSE ); // read the battery temp, at init, to: // 1. clear the over temp state set as default // 2. decide which bottom resistor we have INT32 DegreesCelcius_x10; if(!Temperature( DegreesCelcius_x10 )) { ASSERT(0); return FALSE; } return TRUE; }
void BMP085NB::pollData (int *temperature, long *pressure, float *alti) { switch (pressureState){ case 0: pressureState = 1; newData = false; timer = millis(); StartUT(); break; case 1: if (millis() - timer >= 5) { pressureState = 2; ut = ReadUT(); *temperature = Temperature(ut); } break; case 2: timer1 = millis(); StartUP(); pressureState = 3; break; case 3: if (millis() - timer1 >= 2 + (3<<OSS)) { up = ReadUP(); *pressure = Pressure(up); *alti = Altitude(*pressure); newData = true; pressureState = 0; } break; default: break; } }
void HardeningModulus<EvalT, Traits>:: evaluateFields(typename Traits::EvalData workset) { int numCells = workset.numCells; if (is_constant) { for (int cell=0; cell < numCells; ++cell) { for (int qp=0; qp < numQPs; ++qp) { hardeningModulus(cell,qp) = constant_value; } } } else { for (int cell=0; cell < numCells; ++cell) { for (int qp=0; qp < numQPs; ++qp) { Teuchos::Array<MeshScalarT> point(numDims); for (int i=0; i<numDims; i++) point[i] = Sacado::ScalarValue<MeshScalarT>::eval(coordVec(cell,qp,i)); hardeningModulus(cell,qp) = exp_rf_kl->evaluate(point, rv); } } } if (isThermoElastic) { for (int cell=0; cell < numCells; ++cell) { for (int qp=0; qp < numQPs; ++qp) { hardeningModulus(cell,qp) -= dHdT_value * (Temperature(cell,qp) - refTemp); } } } }
void BulkModulus<EvalT, Traits>:: evaluateFields(typename Traits::EvalData workset) { if (is_constant) { for (unsigned int cell=0; cell < workset.numCells; ++cell) { for (unsigned int qp=0; qp < numQPs; ++qp) { bulkModulus(cell,qp) = constant_value; } } } #ifdef ALBANY_STOKHOS else { for (unsigned int cell=0; cell < workset.numCells; ++cell) { for (unsigned int qp=0; qp < numQPs; ++qp) { Teuchos::Array<MeshScalarT> point(numDims); for (unsigned int i=0; i<numDims; i++) point[i] = Sacado::ScalarValue<MeshScalarT>::eval(coordVec(cell,qp,i)); bulkModulus(cell,qp) = exp_rf_kl->evaluate(point, rv); } } } #endif if (isThermoElastic) { for (int cell=0; cell < workset.numCells; ++cell) { for (int qp=0; qp < numQPs; ++qp) { bulkModulus(cell,qp) -= dKdT_value * (Temperature(cell,qp) - refTemp); } } } }
static SIZE_OR_ERROR OWQ_parse_output_float(struct one_wire_query *owq) { /* should only need suglen+1, but uClibc's snprintf() seem to trash 'len' if not increased */ int len; char c[PROPERTY_LENGTH_FLOAT + 2]; _FLOAT F; switch (OWQ_pn(owq).selected_filetype->format) { case ft_pressure: F = Pressure(OWQ_F(owq), PN(owq)); break; case ft_temperature: F = Temperature(OWQ_F(owq), PN(owq)); break; case ft_tempgap: F = TemperatureGap(OWQ_F(owq), PN(owq)); break; default: F = OWQ_F(owq); break; } UCLIBCLOCK; if ( ShouldTrim(PN(owq)) ) { len = snprintf(c, PROPERTY_LENGTH_FLOAT + 1, "%1G", F); } else { len = snprintf(c, PROPERTY_LENGTH_FLOAT + 1, "%*G", PROPERTY_LENGTH_FLOAT, F); } UCLIBCUNLOCK; if ((len < 0) || ((size_t) len > PROPERTY_LENGTH_FLOAT)) { return -EMSGSIZE; } return OWQ_parse_output_offset_and_size(c, len, owq); }
void SaturationModulus<EvalT, Traits>:: evaluateFields(typename Traits::EvalData workset) { bool print = false; //if (typeid(ScalarT) == typeid(RealType)) print = true; if (print) std::cout << " *** SaturatioModulus *** " << std::endl; int numCells = workset.numCells; if (is_constant) { for (int cell=0; cell < numCells; ++cell) { for (int qp=0; qp < numQPs; ++qp) { satMod(cell,qp) = constant_value; } } } #ifdef ALBANY_STOKHOS else { for (int cell=0; cell < numCells; ++cell) { for (int qp=0; qp < numQPs; ++qp) { Teuchos::Array<MeshScalarT> point(numDims); for (int i=0; i<numDims; i++) point[i] = Sacado::ScalarValue<MeshScalarT>::eval(coordVec(cell,qp,i)); satMod(cell,qp) = exp_rf_kl->evaluate(point, rv); } } } #endif if (isThermoElastic) { for (int cell=0; cell < numCells; ++cell) { for (int qp=0; qp < numQPs; ++qp) { satMod(cell,qp) -= dSdT_value * (Temperature(cell,qp) - refTemp); if (print) { std::cout << " S : " << satMod(cell,qp) << std::endl; std::cout << " temp: " << Temperature(cell,qp) << std::endl; std::cout << " dSdT: " << dSdT_value << std::endl; std::cout << " refT: " << refTemp << std::endl; } } } } }
Temperature Sensor::get_temperature() { byte present = 0; byte data[12]; if (!sensorFound) { return Temperature("Sensor no encontrado"); } if (OneWire::crc8(sensor, 7) != sensor[7]) { Temperature("CRC inválido!"); } if (sensor[0] != 0x28) { return Temperature("Sólo DS18B20 soportado!"); } ds->reset(); ds->select(sensor); ds->write(0x44, 1); // start conversion, with parasite power on at the end delay(1000); // maybe 750ms is enough, maybe not // we might do a ds.depower() here, but the reset will take care of it. present = ds->reset(); ds->select(sensor); ds->write(READ_SCRATCHPAD); // Read Scratchpad for (byte i = 0; i < 9; i++) { // we need 9 bytes data[i] = ds->read(); } // convert the data to actual temperature unsigned int raw = (data[1] << 8) | data[0]; byte cfg = (data[4] & 0x60); if (cfg == 0x00) { raw = raw << 3; // 9 bit resolution, 93.75 ms } else if (cfg == 0x20) { raw = raw << 2; // 10 bit res, 187.5 ms } else if (cfg == 0x40) { raw = raw << 1; // 11 bit res, 375 ms } // default is 12 bit resolution, 750 ms conversion time return Temperature((float)raw / 16.0); }
void FORTE_iCreateBattery::executeEvent(int pa_nEIID){ switch (pa_nEIID){ case scm_nEventREQID: create_battery_charge(); Charging() = static_cast<TForteInt16>(gc_charge_state); //get_create_charging_state(LAG()); Voltage() = static_cast<TForteInt16>(gc_batt_voltage); Current() = static_cast<TForteInt16>(gc_current_flow); Temperature() = static_cast<TForteInt16>(gc_batt_temp); Charge() = static_cast<TForteInt16>(gc_batt_charge); Capacity() = static_cast<TForteInt16>(gc_batt_capacity); sendOutputEvent(scm_nEventCNFID); break; } }
char SCI_InCharInitial(void){ CRGINT = 0x80; // RTIE=1 enable rti RTICTL = 0x7F; // Interrupt Every 0.131seconds TimeoutCount=0; //Reset Counter while(((SCISR1 & 0x20) == 0)){ if(TimeoutCount==23){ Temperature();TimeoutCount=0; } } CRGINT = 0x0; // RTIE=0 disable rti TimeoutCount=0; //Reset Counter return(SCIDRL); //Return the input character }
void MatterFreeE::Sound(double *S,double *Dencity,double *Energy,int Num) { VecCl T(Num),Eplus(Num),Tplus(Num),Dplus(Num),Pplus(Num),P(Num); Temperature(T.Ptr,Dencity,Energy,Num); FreeEPtr->Pressure(P.Ptr,Dencity,T.Ptr,Num); Tplus= T * (1 + MinimT2EstpCoef) + MinimT2EstpMin; FreeEPtr->Energy(Eplus.Ptr,Dencity,Tplus.Ptr,Num); for (int k=1;k<=Num;k++) { Dplus[k]=Dencity[k]; if (Dencity[k]<MathZer) { cout<<"MatterFreeEIO::Sound; Dencity<MathZer :" <<Dencity<<"\n";Tplus[k]=0;continue;} double dE=max<double>(Eplus[k]-Energy[k],MathZer); double dr=Dencity[k]+dE*sqr(Dencity[k])/max<double>(1e-4,P.Ptr[k]); if (fabs(dr)<MathZer) {Tplus[k]=0;continue;} Dplus[k]=Dplus[k]+dr; } FreeEPtr->Pressure(Pplus.Ptr,Dplus.Ptr,Tplus.Ptr,Num); for (int k=1;k<=Num;k++) S[k]=sqrt( max<double>(0,Pplus[k]-P[k])/(Dplus[k]-Dencity[k]) ); };
LOCAL void g_fprint_raw_Fstate( FILE *file, Locstate state, int dim) { int i; static char vname[3][3] = { "vx", "vy", "vz"}; (void) fprintf(file,"\tdensity = %"FFMT" temperature = %"FFMT" ", Dens(state),Temperature(state)); for (i = 0; i < dim; i++) (void) fprintf(file,"%-8s = %"FFMT" ",vname[i],Vel(state)[i]); if (debugging("prt_params")) fprint_Gas_param(file,Params(state)); else (void) fprintf(file,"Gas_param = %llu\n", gas_param_number(Params(state))); } /*end g_fprint_raw_Fstate*/
int cgiMain() { #if DEBUG /* Load a saved CGI scenario if we're debugging */ cgiReadEnvironment("/home/boutell/public_html/capcgi.dat"); #endif cgiHeaderContentType("text/html"); fprintf(cgiOut, "<HTML><HEAD>\n"); fprintf(cgiOut, "<TITLE>cgic test</TITLE></HEAD>\n"); fprintf(cgiOut, "<BODY><H1>cgic test</H1>\n"); Name(); Address(); Hungry(); Temperature(); Frogs(); Color(); Flavors(); NonExButtons(); RadioButtons(); fprintf(cgiOut, "</BODY></HTML>\n"); return 0; }
void HandleSubmit() { Name(); Address(); Hungry(); Temperature(); Frogs(); Color(); Flavors(); NonExButtons(); RadioButtons(); File(); Entries(); Cookies(); /* The saveenvironment button, in addition to submitting the form, also saves the resulting CGI scenario to disk for later replay with the 'load saved environment' button. */ if (cgiFormSubmitClicked("saveenvironment") == cgiFormSuccess) { SaveEnvironment(); } }
void ElasticModulus<EvalT, Traits>:: evaluateFields(typename Traits::EvalData workset) { int numCells = workset.numCells; if (is_constant) { for (int cell=0; cell < numCells; ++cell) { for (int qp=0; qp < numQPs; ++qp) { elasticModulus(cell,qp) = constant_value; } } } else { for (int cell=0; cell < numCells; ++cell) { for (int qp=0; qp < numQPs; ++qp) { Teuchos::Array<MeshScalarT> point(numDims); for (int i=0; i<numDims; i++) point[i] = Sacado::ScalarValue<MeshScalarT>::eval(coordVec(cell,qp,i)); elasticModulus(cell,qp) = exp_rf_kl->evaluate(point, rv); } } } if (isThermoElastic) { for (int cell=0; cell < numCells; ++cell) { for (int qp=0; qp < numQPs; ++qp) { elasticModulus(cell,qp) += dEdT_value * (Temperature(cell,qp) - refTemp); } } } if (isPoroElastic) { for (int cell=0; cell < numCells; ++cell) { for (int qp=0; qp < numQPs; ++qp) { // porosity dependent Young's Modulus. It will be replaced by // the hyperelasticity model in (Borja, Tamagnini and Amorosi, ASCE JGGE 1997). elasticModulus(cell,qp) = constant_value; // *sqrt(2.0 - porosity(cell,qp)); } } } }
double MatterFreeE::Sound(double Dencity,double Energy) { if (Dencity<MathZer) { cout<<"MatterFreeEIO::Sound; Dencity<MathZer :" <<Dencity<<"\n";return 0;} double r=Dencity; double T; if (fabs(L_D-Dencity)+fabs(L_E-Energy)<MathZer) T=L_T; else T=Temperature(Dencity,Energy); double dT = T * MinimT2EstpCoef + MinimT2EstpMin;//*StndErr; double P=FreeEPtr->Pressure(r,T); double E=FreeEPtr->Energy(r,T); double dE=max<double>(FreeEPtr->Energy(r,T+dT)-E,MathZer); double dr=dE*sqr(Dencity)/max<double>(1e-4,P); if (fabs(dr)<MathZer) return 0; double Pp=FreeEPtr->Pressure(r+dr,T+dT)-P; if (Pp<0) { // cout<<" MatterIO::Sound; deriv is negative: " <<Pp<<" Sqrt from negative value \n"; } double S=sqrt( max<double>(0,Pp)/dr ); return S; };
int main() { vector<Temperature> temp; Temperature input; input=Temperature(); cout << "Input the temperature: 10F-Fahrenheit,10C-Celsius,10K-Kelvin: "; while (cin >>input.value >>input.scale) { if (!cin) break; cout << "Input the temperature: 10F-Fahrenheit,10C-Celsius,10K-Kelvin: "; try { temp.push_back(convert(input,'C')); temp.push_back(convert(input,'K')); temp.push_back(convert(input,'F')); } catch (const invalid_argument& e) { cerr << e.what() << "\n"; } catch (const logic_error& e) { cerr << e.what() << "\n"; } catch (...) { cerr << "Unknown error! Try again! \n"; } } cout <<"C \t" <<"K \t" <<"F \t \n"; for (int i = 0; i < (temp.size()); ++i) { printf("%4.2f\t", temp[i]); if ((i+1)%3==0) cout <<"\n"; } }
void YieldStrength<EvalT, Traits>:: evaluateFields(typename Traits::EvalData workset) { bool print = false; //if (typeid(ScalarT) == typeid(RealType)) print = true; if (print) std::cout << " *** YieldStrength *** " << std::endl; int numCells = workset.numCells; if (is_constant) { for (int cell=0; cell < numCells; ++cell) { for (int qp=0; qp < numQPs; ++qp) { yieldStrength(cell,qp) = constant_value; } } } else { for (int cell=0; cell < numCells; ++cell) { for (int qp=0; qp < numQPs; ++qp) { Teuchos::Array<MeshScalarT> point(numDims); for (int i=0; i<numDims; i++) point[i] = Sacado::ScalarValue<MeshScalarT>::eval(coordVec(cell,qp,i)); yieldStrength(cell,qp) = exp_rf_kl->evaluate(point, rv); } } } if (isThermoElastic) { for (int cell=0; cell < numCells; ++cell) { for (int qp=0; qp < numQPs; ++qp) { yieldStrength(cell,qp) -= dYdT_value * (Temperature(cell,qp) - refTemp); if (print) { std::cout << " Y : " << yieldStrength(cell,qp) << std::endl; std::cout << " temp: " << Temperature(cell,qp) << std::endl; std::cout << " dYdT: " << dYdT_value << std::endl; std::cout << " refT: " << refTemp << std::endl; } } } } if (isDiffuseDeformation) { Albany::MDArray CLold = (*workset.stateArrayPtr)[CLname]; for (int cell=0; cell < numCells; ++cell) { for (int qp=0; qp < numQPs; ++qp) { // yieldStrength(cell,qp) = constant_value*( 1.0 + (zeta-1.0)*CL(cell,qp) ); yieldStrength(cell,qp) -= constant_value*(zeta-1.0)*(CL(cell,qp) -CLold(cell,qp) ); if (print) { std::cout << " Y : " << yieldStrength(cell,qp) << std::endl; std::cout << " CT : " << CT(cell,qp) << std::endl; std::cout << " zeta : " << zeta << std::endl; } } } } }
char SCI_InChar2(void){ while((SCISR1 & 0x20) == 0){Temperature();}; return(SCIDRL); }
void InitGraphics( ) { //init proj2 data for (int i = 0; i < NX; i++) { for (int j = 0; j < NY; j++) { for (int k = 0; k < NZ; k++) { Nodes[i][j][k].x = -1. + 2. * (float)i / (float)(NX - 1); Nodes[i][j][k].y = -1. + 2. * (float)j / (float)(NY - 1); Nodes[i][j][k].z = -1. + 2. * (float)k / (float)(NZ - 1); Nodes[i][j][k].t = Temperature(Nodes[i][j][k].x, Nodes[i][j][k].y, Nodes[i][j][k].z); } } } //init proj3 data for (int i = 0; i < NX; i++) { for (int j = 0; j < NY; j++) { for (int k = 0; k < NZ; k++) { float hsv[3], rgb[3]; hsv[0] = 240. - 240.*((Nodes[i][j][k].t - TEMPMIN) / (TEMPMAX - TEMPMIN)); hsv[1] = 1.; hsv[2] = 1.; HsvRgb(hsv, rgb); Nodes[i][j][k].rgb[0] = rgb[0]; Nodes[i][j][k].rgb[1] = rgb[1]; Nodes[i][j][k].rgb[2] = rgb[2]; Nodes[i][j][k].rad = sqrt(SQR(Nodes[i][j][k].x) + SQR(Nodes[i][j][k].y) + SQR(Nodes[i][j][k].z)); if (i == 0) Nodes[i][j][k].dTdx = (Nodes[i + 1][j][k].t - Nodes[i][j][k].t) / (Nodes[i + 1][j][k].x - Nodes[i][j][k].x); else if (i + 1 == NX) Nodes[i][j][k].dTdx = (Nodes[i][j][k].t - Nodes[i - 1][j][k].t) / (Nodes[i][j][k].x - Nodes[i - 1][j][k].x); else Nodes[i][j][k].dTdx = (Nodes[i + 1][j][k].t - Nodes[i - 1][j][k].t) / (Nodes[i + 1][j][k].x - Nodes[i - 1][j][k].x); if (j == 0) Nodes[i][j][k].dTdy = (Nodes[i][j + 1][k].t - Nodes[i][j][k].t) / (Nodes[i][j + 1][k].y - Nodes[i][j][k].y); else if (j + 1 == NY) Nodes[i][j][k].dTdy = (Nodes[i][j][k].t - Nodes[i][j - 1][k].t) / (Nodes[i][j][k].y - Nodes[i][j - 1][k].y); else Nodes[i][j][k].dTdy = (Nodes[i][j + 1][k].t - Nodes[i][j - 1][k].t) / (Nodes[i][j + 1][k].y - Nodes[i][j - 1][k].y); if (k == 0) Nodes[i][j][k].dTdz = (Nodes[i][j][k + 1].t - Nodes[i][j][k].t) / (Nodes[i][j][k + 1].z - Nodes[i][j][k].z); else if (k + 1 == NZ) Nodes[i][j][k].dTdz = (Nodes[i][j][k].t - Nodes[i][j][k - 1].t) / (Nodes[i][j][k].z - Nodes[i][j][k - 1].z); else Nodes[i][j][k].dTdz = (Nodes[i][j][k + 1].t - Nodes[i][j][k - 1].t) / (Nodes[i][j][k + 1].z - Nodes[i][j][k - 1].z); Nodes[i][j][k].grad = sqrt(SQR(Nodes[i][j][k].dTdx) + SQR(Nodes[i][j][k].dTdy) + SQR(Nodes[i][j][k].dTdz)); } } } // setup the display mode: // ( *must* be done before call to glutCreateWindow( ) ) // ask for color, double-buffering, and z-buffering: glutInitDisplayMode( GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH ); // set the initial window configuration: glutInitWindowPosition( 0, 0 ); glutInitWindowSize( INIT_WINDOW_SIZE, INIT_WINDOW_SIZE ); // open the window and set its title: MainWindow = glutCreateWindow( WINDOWTITLE ); glutSetWindowTitle( WINDOWTITLE ); // setup the clear values: glClearColor( BACKCOLOR[0], BACKCOLOR[1], BACKCOLOR[2], BACKCOLOR[3] ); // setup the callback functions: // DisplayFunc -- redraw the window // ReshapeFunc -- handle the user resizing the window // KeyboardFunc -- handle a keyboard input // MouseFunc -- handle the mouse button going down or up // MotionFunc -- handle the mouse moving with a button down // PassiveMotionFunc -- handle the mouse moving with a button up // VisibilityFunc -- handle a change in window visibility // EntryFunc -- handle the cursor entering or leaving the window // SpecialFunc -- handle special keys on the keyboard // SpaceballMotionFunc -- handle spaceball translation // SpaceballRotateFunc -- handle spaceball rotation // SpaceballButtonFunc -- handle spaceball button hits // ButtonBoxFunc -- handle button box hits // DialsFunc -- handle dial rotations // TabletMotionFunc -- handle digitizing tablet motion // TabletButtonFunc -- handle digitizing tablet button hits // MenuStateFunc -- declare when a pop-up menu is in use // TimerFunc -- trigger something to happen a certain time from now // IdleFunc -- what to do when nothing else is going on glutSetWindow( MainWindow ); glutDisplayFunc( Display ); glutReshapeFunc( Resize ); glutKeyboardFunc( Keyboard ); glutMouseFunc( MouseButton ); glutMotionFunc( MouseMotion ); glutPassiveMotionFunc( NULL ); glutVisibilityFunc( Visibility ); glutEntryFunc( NULL ); glutSpecialFunc( NULL ); glutSpaceballMotionFunc( NULL ); glutSpaceballRotateFunc( NULL ); glutSpaceballButtonFunc( NULL ); glutButtonBoxFunc( NULL ); glutDialsFunc( NULL ); glutTabletMotionFunc( NULL ); glutTabletButtonFunc( NULL ); glutMenuStateFunc( NULL ); glutTimerFunc( 0, NULL, 0 ); // DO NOT SET THE GLUT IDLE FUNCTION HERE !! // glutIdleFunc( NULL ); // let glui take care of it in InitGlui( ) }
bool CXbowDriver::GetData() { //here we actually access serial ports etc if(m_pPort->IsStreaming()) { MOOSTrace("Crossbow must not be streaming\n"); return false; } //ask the crossbow for a reading m_pPort->Write("G",1); string sWhat; unsigned char Reply[CROSSBOW_POLLED_ANGLE_MODE_REPLY_LENGTH]; //note local call back invoked here to specify termination int nRead = m_pPort->ReadNWithTimeOut((char*)Reply,sizeof(Reply)); if(nRead == CROSSBOW_POLLED_ANGLE_MODE_REPLY_LENGTH) { if(Reply[0]!=255) { MOOSTrace("Unexpected Header in CrossBow reply\n"); } //angles short nRoll = (Reply[1]<<8) + Reply[2]; short nPitch = (Reply[3]<<8) + Reply[4]; short nYaw = (Reply[5]<<8) + Reply[6]; //This is roll, pitch and yaw for the DMU-AHRS, which is rotated //relative to the vehicle body. It has Z down and X out the tail. double df_deg_CBRoll = nRoll*180.0/pow(2.0,15.0); double df_deg_CBPitch = nPitch*180.0/pow(2.0,15.0); double df_deg_CBYaw = nYaw*180.0/pow(2.0,15.0); //account for alignment of crossbow in vehicle frame //this is the angle measured from the vehicle center line(y) double dfHeading = df_deg_CBYaw+m_dfVehicleYToINSX; //now correct for magnetic offset dfHeading+=m_dfMagneticOffset; //convert to Yaw.. //Notice that Heading is in DEGREES, positive CLOCKWISE //while Yaw is in RADIANS, positive COUNTERCLOCKWISE double dfYaw = -dfHeading*PI/180.0; dfYaw = MOOS_ANGLE_WRAP(dfYaw); //initialise transformed angles (in degrees) double df_deg_TRoll = df_deg_CBRoll; double df_deg_TPitch = df_deg_CBPitch; if( m_dfVehicleYToINSX == 0 ) { //Crossbow roll and vehicle body roll match. df_deg_TRoll = df_deg_TRoll; //same for Pitch. df_deg_TPitch = df_deg_TPitch; } else if (m_dfVehicleYToINSX == 180) { df_deg_TRoll = -df_deg_TRoll; df_deg_TPitch = -df_deg_TPitch; } else { MOOSTrace("Bad 'TWIST' value (use 0 or 180)!\r\n"); return false; } //look after pitch double dfPitch = MOOSDeg2Rad(df_deg_TPitch); //look after roll double dfRoll = MOOSDeg2Rad(df_deg_TRoll); //find the temperature every so often m_nTempCnt++; if((m_nTempCnt % 100) == 0) { short nTemp = ( Reply[25] << 8 ) + Reply[26]; m_dfTemp = 44.4 * ( ((double)nTemp * 5.0/4096.0) - 1.375); CMOOSMsg Temperature(MOOS_NOTIFY, "INS_TEMPERATURE", m_dfTemp); m_Notifications.push_back(Temperature); } //notify the MOOS CMOOSMsg Heading(MOOS_NOTIFY, "INS_HEADING", dfHeading); m_Notifications.push_back(Heading); CMOOSMsg Yaw(MOOS_NOTIFY, "INS_YAW", dfYaw); m_Notifications.push_back(Yaw); CMOOSMsg Pitch(MOOS_NOTIFY, "INS_PITCH", dfPitch); m_Notifications.push_back(Pitch); CMOOSMsg Roll(MOOS_NOTIFY, "INS_ROLL", dfRoll); m_Notifications.push_back(Roll); //rates short nRollRate = (Reply[7]<<8) + Reply[8];//p-dot short nPitchRate = (Reply[9]<<8) + Reply[10];//q-dot short nYawRate = (Reply[11]<<8) + Reply[12];//r-dot //xbow calib constant double RR = 100.0;//deg/sec double dfRollRate = nRollRate * RR * 1.5/pow(2.0,15); double dfPitchRate = nPitchRate * RR * 1.5/pow(2.0,15); double dfYawRate = nYawRate * RR * 1.5/pow(2.0,15); //note X and Y axes are switched CMOOSMsg RollRate(MOOS_NOTIFY, "INS_ROLLRATE_Y", dfRollRate); m_Notifications.push_back(RollRate); CMOOSMsg PitchRate(MOOS_NOTIFY, "INS_ROLLRATE_X", dfPitchRate); m_Notifications.push_back(PitchRate); CMOOSMsg YawRate(MOOS_NOTIFY, "INS_ROLLRATE_Z", dfYawRate); m_Notifications.push_back(YawRate); //accelerations short nXAccel = (Reply[13]<<8) + Reply[14];//v-dot short nYAccel = (Reply[15]<<8) + Reply[16];//u-dot short nZAccel = (Reply[17]<<8) + Reply[18];//w-dot //xbow calib constant double GR = 2.0;//G's double dfXAccel = nXAccel * GR * 1.5/pow(2.0,15); double dfYAccel = nYAccel * GR * 1.5/pow(2.0,15); double dfZAccel = nZAccel * GR * 1.5/pow(2.0,15); //note X and Y axes are switched CMOOSMsg XAccel(MOOS_NOTIFY, "INS_ACCEL_Y", dfXAccel); m_Notifications.push_back(XAccel); CMOOSMsg YAccel(MOOS_NOTIFY, "INS_ACCEL_X", dfYAccel); m_Notifications.push_back(YAccel); CMOOSMsg ZAccel(MOOS_NOTIFY, "INS_ACCEL_Z", dfZAccel); m_Notifications.push_back(ZAccel); //magnetic field data short nXMag = (Reply[19]<<8) + Reply[20]; short nYMag = (Reply[21]<<8) + Reply[22]; short nZMag = (Reply[23]<<8) + Reply[24]; double dfGaussX = nXMag * 1.25 * 1.5/pow(2.0,15.0); double dfGaussY = nYMag * 1.25 * 1.5/pow(2.0,15.0); double dfGaussZ = nZMag * 1.25 * 1.5/pow(2.0,15.0); CMOOSMsg GaussX(MOOS_NOTIFY, "INS_MAG_Y", dfGaussX); m_Notifications.push_back(GaussX); CMOOSMsg GaussY(MOOS_NOTIFY, "INS_MAG_X", dfGaussY); m_Notifications.push_back(GaussY); CMOOSMsg GaussZ(MOOS_NOTIFY, "INS_MAG_Z", dfGaussZ); m_Notifications.push_back(GaussZ); if(m_pPort->IsVerbose()) { //this allows us to print data in verbose mode //when teh port couldn't as it is verbose MOOSTrace("Roll = %7.3f Pitch = %7.3f Yaw = %7.3f Heading = %7.3f Temp = %3.2f\n", df_deg_TRoll, df_deg_TPitch, dfYaw*180/PI, dfHeading, m_dfTemp); } } else { MOOSTrace("read %d byte while expecting %d\n", nRead, CROSSBOW_POLLED_ANGLE_MODE_REPLY_LENGTH); } return true; }
LOCAL void add_ext_deposition( Locstate state, COMPONENT comp, float *coords, int dim) { float dep, tcrds[MAXD+1]; int i, d; if (is_obstacle_state(state)) return; //TMP vel pertb if(NO) { if(coords[2] < 0.8 && coords[2] > -0.8 && comp == deparam[0].comp) { set_state(state,TGAS_STATE,state); Vel(state)[0] = 0.25*rand()/((float)RAND_MAX + 1); Vel(state)[1] = 0.25*rand()/((float)RAND_MAX + 1); Vel(state)[2] = 0.25*rand()/((float)RAND_MAX + 1); set_state(state,GAS_STATE,state); } } // set tcrds tcrds[0] = 0; for (d = 0; d < dim; d++) tcrds[d+1] = coords[d]; //TMP for cylindy depo //tcrds[3] = 0; for (i = 0; i < dep_number; i++) { if (comp != -1 && comp != deparam[i].comp) continue; // comp = -1 for all components // check if within deposition boundary if ( tcrds[0] < deparam[i].bd[0][0] || tcrds[0] > deparam[i].bd[0][1] ) continue; // check time if (deparam[i].region == DEP_RECT) { for (d = 1; d < dim+1; d++) if ( tcrds[d] < deparam[i].bd[d][0] || tcrds[d] > deparam[i].bd[d][1] ) break; if (d < dim+1) continue; } else // DEP_ELLIP { float sum = 0; for (d = 1; d < dim+1; d++) sum += sqr((tcrds[d]-deparam[i].bd[d][0])/deparam[i].bd[d][1]); //if (sum > 1) continue; } dep = deparam[i].amp; for (d = 0; d < dim+1; d++) { if (deparam[i].prof[d] == GAUSSIAN) { // param[d][0] = decay length if (deparam[i].flag[d][0] == false) // Gaussian dep /= exp(sqr((tcrds[d]-deparam[i].orig[d])/deparam[i].param[d][0])); else // exponential dep /= exp((tcrds[d]-deparam[i].orig[d])/deparam[i].param[d][0]); } else if (deparam[i].prof[d] == POWER) { // param[d][0] = decay exponent dep /= pow(fabs(tcrds[d]-deparam[i].orig[d]),deparam[i].param[d][0]); } else if (deparam[i].prof[d] == SINUSOIDAL) { // param[d][0] = wavelength, params[d][1] = phase dep *= sin(2*PI*( (tcrds[d] - deparam[i].orig[d]) / deparam[i].param[d][0] + deparam[i].param[d][1]/360 )); } } dep += deparam[i].base; switch(deparam[i].type) { case EXT_ENERGY: // total energy density Energy(state) = dep; break; case EXT_PRESSURE: set_state(state,TGAS_STATE,state); //dep = interp_from_data(coords)*13000.0/0.009351; //dep = interp_from_data(coords)*17500.0/0.03976; //dep = interp_from_data(coords); dep = interp_from_data(coords)*15000.0/0.01544; Press(state) += dep; set_state(state,GAS_STATE,state); break; case EXT_TEMPER: // keep density fixed set_state(state,FGAS_STATE,state); Temperature(state) = dep; set_state(state,GAS_STATE,state); break; case EXT_VX: set_state(state,TGAS_STATE,state); Vel(state)[0] = dep; set_state(state,GAS_STATE,state); break; case EXT_VY: set_state(state,TGAS_STATE,state); Vel(state)[1] = dep; set_state(state,GAS_STATE,state); break; case EXT_VZ: set_state(state,TGAS_STATE,state); Vel(state)[2] = dep; set_state(state,GAS_STATE,state); break; case EXT_DENSITY: Dens(state) = dep; break; } if (debugging("deposition")) { printf("{%c}dep[",dep_name[deparam[i].type]); for (d = 0;d < dim-1;d++) printf("%g,",coords[d]); printf("%g]=%g, ",coords[dim-1],dep); } } } /* end add_ext_deposition() */
void ThermoMechanicalEnergyResidual<EvalT, Traits>:: evaluateFields(typename Traits::EvalData workset) { bool print = false; //if (typeid(ScalarT) == typeid(RealType)) print = true; // alias the function space tools typedef Intrepid2::FunctionSpaceTools FST; // get old temperature Albany::MDArray Temperature_old = (*workset.stateArrayPtr)[tempName]; // time step ScalarT dt = deltaTime(0); // compute the 'material' flux FST::tensorMultiplyDataData<ScalarT> (C, F, F, 'T'); Intrepid2::RealSpaceTools<ScalarT>::inverse(Cinv, C); FST::tensorMultiplyDataData<ScalarT> (CinvTgrad, Cinv, TGrad); FST::scalarMultiplyDataData<ScalarT> (flux, ThermalCond, CinvTgrad); FST::integrate<ScalarT>(TResidual, flux, wGradBF, Intrepid2::COMP_CPP, false); // "false" overwrites if (haveSource) { for (int i=0; i<Source.dimension(0); i++) for (int j=0; j<Source.dimension(1); j++) Source(i,j) *= -1.0; FST::integrate<ScalarT>(TResidual, Source, wBF, Intrepid2::COMP_CPP, true); // "true" sums into } for (int i=0; i<mechSource.dimension(0); i++) for (int j=0; j<mechSource.dimension(1); j++) mechSource(i,j) *= -1.0; FST::integrate<ScalarT>(TResidual, mechSource, wBF, Intrepid2::COMP_CPP, true); // "true" sums into //Irina comment: code below was commented out //if (workset.transientTerms && enableTransient) // FST::integrate<ScalarT>(TResidual, Tdot, wBF, Intrepid2::COMP_CPP, true); // "true" sums into // // compute factor ScalarT fac(0.0); if (dt > 0.0) fac = ( density * Cv ) / dt; for (int cell=0; cell < workset.numCells; ++cell) for (int qp=0; qp < numQPs; ++qp) Tdot(cell,qp) = fac * ( Temperature(cell,qp) - Temperature_old(cell,qp) ); FST::integrate<ScalarT>(TResidual, Tdot, wBF, Intrepid2::COMP_CPP, true); // "true" sums into if (print) { std::cout << " *** ThermoMechanicalEnergyResidual *** " << std::endl; std::cout << " ** dt: " << dt << std::endl; std::cout << " ** rho: " << density << std::endl; std::cout << " ** Cv: " << Cv << std::endl; for (unsigned int cell(0); cell < workset.numCells; ++cell) { std::cout << " ** Cell: " << cell << std::endl; for (unsigned int qp(0); qp < numQPs; ++qp) { std::cout << " * QP: " << std::endl; std::cout << " F : "; for (unsigned int i(0); i < numDims; ++i) for (unsigned int j(0); j < numDims; ++j) std::cout << F(cell,qp,i,j) << " "; std::cout << std::endl; std::cout << " C : "; for (unsigned int i(0); i < numDims; ++i) for (unsigned int j(0); j < numDims; ++j) std::cout << C(cell,qp,i,j) << " "; std::cout << std::endl; std::cout << " T : " << Temperature(cell,qp) << std::endl; std::cout << " Told: " << Temperature(cell,qp) << std::endl; std::cout << " k : " << ThermalCond(cell,qp) << std::endl; } } } }
Temperature TemperatureSensor::GetCurrentReading() { //TODO define proper translation to degrees Temperature t = Temperature(_arduino.readSignal() * 50 - 10); std::cout << "Temp-S:: el nivel de temperatura sensado es: " << LevelHandler::Serialize(t.levelOf()) << std::endl; return t; }
TEST_F(SettingsTest, AddSettingTemperature) { settings.add("test_setting", "245.5"); EXPECT_DOUBLE_EQ(Temperature(245.5), settings.get<Temperature>("test_setting")); }
void HeatEqResid<EvalT, Traits>:: evaluateFields(typename Traits::EvalData workset) { //// workset.print(std::cout); typedef Intrepid::FunctionSpaceTools FST; // Since Intrepid will later perform calculations on the entire workset size // and not just the used portion, we must fill the excess with reasonable // values. Leaving this out leads to floating point exceptions !!! for (std::size_t cell=workset.numCells; cell < worksetSize; ++cell) for (std::size_t qp=0; qp < numQPs; ++qp){ ThermalCond(cell,qp) = 0.0; for (std::size_t i=0; i < numDims; ++i){ flux(cell,qp,i) = 0.0; TGrad(cell,qp,i) = 0.0; } } FST::scalarMultiplyDataData<ScalarT> (flux, ThermalCond, TGrad); FST::integrate<ScalarT>(TResidual, flux, wGradBF, Intrepid::COMP_CPP, false); // "false" overwrites if (haveSource) { for (std::size_t cell=workset.numCells; cell < worksetSize; ++cell) for (std::size_t qp=0; qp < numQPs; ++qp) Source(cell,qp) = 0.0; for (int i =0; i< Source.dimension(0); i++) for (int j =0; j< Source.dimension(1); j++) Source(i,j) *= -1.0; FST::integrate<ScalarT>(TResidual, Source, wBF, Intrepid::COMP_CPP, true); // "true" sums into } if (workset.transientTerms && enableTransient){ for (std::size_t cell=workset.numCells; cell < worksetSize; ++cell) for (std::size_t qp=0; qp < numQPs; ++qp) Tdot(cell,qp) = 0.0; FST::integrate<ScalarT>(TResidual, Tdot, wBF, Intrepid::COMP_CPP, true); // "true" sums into } if (haveConvection) { Intrepid::FieldContainer<ScalarT> convection(worksetSize, numQPs); for (std::size_t cell=workset.numCells; cell < worksetSize; ++cell) for (std::size_t qp=0; qp < numQPs; ++qp) convection(cell,qp) = 0.0; for (std::size_t cell=0; cell < workset.numCells; ++cell) { for (std::size_t qp=0; qp < numQPs; ++qp) { convection(cell,qp) = 0.0; for (std::size_t i=0; i < numDims; ++i) { if (haverhoCp) convection(cell,qp) += rhoCp(cell,qp) * convectionVels[i] * TGrad(cell,qp,i); else convection(cell,qp) += convectionVels[i] * TGrad(cell,qp,i); } } } FST::integrate<ScalarT>(TResidual, convection, wBF, Intrepid::COMP_CPP, true); // "true" sums into } if (haveAbsorption) { // Since Intrepid will later perform calculations on the entire workset size // and not just the used portion, we must fill the excess with reasonable // values. Leaving this out leads to floating point exceptions !!! for (std::size_t cell=workset.numCells; cell < worksetSize; ++cell) for (std::size_t qp=0; qp < numQPs; ++qp){ aterm(cell,qp) = 0.0; Absorption(cell,qp) = 0.0; Temperature(cell,qp) = 0.0; } FST::scalarMultiplyDataData<ScalarT> (aterm, Absorption, Temperature); FST::integrate<ScalarT>(TResidual, aterm, wBF, Intrepid::COMP_CPP, true); } //TResidual.print(std::cout, true); }
void XZHydrostatic_EtaDotPi<EvalT, Traits>:: evaluateFields(typename Traits::EvalData workset) { const Eta<EvalT> &E = Eta<EvalT>::self(); //etadotpi(level) shifted by 1/2 std::vector<ScalarT> etadotpi(numLevels+1); if(!pureAdvection){ for (int cell=0; cell < workset.numCells; ++cell) { for (int qp=0; qp < numQPs; ++qp) { ScalarT pdotp0 = 0; for (int level=0; level < numLevels; ++level) pdotp0 -= divpivelx(cell,qp,level) * E.delta(level); for (int level=0; level < numLevels; ++level) { ScalarT integral = 0; for (int j=0; j<=level; ++j) integral += divpivelx(cell,qp,j) * E.delta(j); etadotpi[level] = -E.B(level+.5)*pdotp0 - integral; } etadotpi[0] = etadotpi[numLevels] = 0; //Vertical Finite Differencing for (int level=0; level < numLevels; ++level) { const ScalarT factor = 1.0/(2.0*Pi(cell,qp,level)*E.delta(level)); const int level_m = level ? level-1 : 0; const int level_p = level+1<numLevels ? level+1 : level; const ScalarT etadotpi_m = etadotpi[level ]; const ScalarT etadotpi_p = etadotpi[level+1]; const ScalarT dT_m = Temperature(cell,qp,level) - Temperature(cell,qp,level_m); const ScalarT dT_p = Temperature(cell,qp,level_p) - Temperature(cell,qp,level); etadotdT(cell,qp,level) = factor * ( etadotpi_p*dT_p + etadotpi_m*dT_m ); for (int dim=0; dim<numDims; ++dim) { const ScalarT dVx_m = Velx(cell,qp,level,dim) - Velx(cell,qp,level_m,dim); const ScalarT dVx_p = Velx(cell,qp,level_p,dim) - Velx(cell,qp,level,dim); etadotdVelx(cell,qp,level,dim) = factor * ( etadotpi_p*dVx_p + etadotpi_m*dVx_m ); } for (int i = 0; i < tracerNames.size(); ++i) { const ScalarT q_m = 0.5*( Tracer[tracerNames[i]](cell,qp,level) / Pi(cell,qp,level) + Tracer[tracerNames[i]](cell,qp,level_m) / Pi(cell,qp,level_m) ); const ScalarT q_p = 0.5*( Tracer[tracerNames[i]](cell,qp,level_p) / Pi(cell,qp,level_p) + Tracer[tracerNames[i]](cell,qp,level) / Pi(cell,qp,level) ); //etadotdTracer[tracerNames[i]](cell,qp,level) = ( etadotpi_p*q_p - etadotpi_m*q_m ) / E.delta(level); dedotpiTracerde[tracerNames[i]](cell,qp,level) = ( etadotpi_p*q_p - etadotpi_m*q_m ) / E.delta(level); } Pidot(cell,qp,level) = - divpivelx(cell,qp,level) - (etadotpi_p - etadotpi_m)/E.delta(level); } } } }//end of (not pure Advection) //pure advection: there are amny auxiliary variables. else{ for (int cell=0; cell < workset.numCells; ++cell) { for (int qp=0; qp < numQPs; ++qp) { //Vertical Finite Differencing for (int level=0; level < numLevels; ++level) { etadotdT(cell,qp,level) = 0.0; for (int dim=0; dim<numDims; ++dim) etadotdVelx(cell,qp,level,dim) = 0.0; for (int i = 0; i < tracerNames.size(); ++i) dedotpiTracerde[tracerNames[i]](cell,qp,level) = 0.0; Pidot(cell,qp,level) = - divpivelx(cell,qp,level); } } } } }
// double Sound(double Dencity,double Energy); double MatterFreeE::Temperature(double Dencity,double Energy) { VecCl Den(1),En(1),Temper(1);Den[1]=Dencity;En[1]=Energy; Temperature(Temper.Ptr,Den.Ptr,En.Ptr,1); return Temper[1]; }