void VectorialFunction::parse() { clear(); for(Uint i = 0; i < m_functions.size(); ++i) { FunctionParser* ptr = new FunctionParser(); ptr->AddConstant("pi", Consts::pi()); m_parsers.push_back(ptr); // CFinfo << "Parsing Function: \'" << m_functions[i] << "\' Vars: \'" << m_vars << "\'\n" << CFendl; ptr->Parse(m_functions[i],m_vars); if ( ptr->GetParseErrorType() != FunctionParser::FP_NO_ERROR ) { std::string msg("ParseError in VectorialFunction::parse(): "); msg += " Error [" +std::string(ptr->ErrorMsg()) + "]"; msg += " Function [" + m_functions[i] + "]"; msg += " Vars: [" + m_vars + "]"; throw common::ParsingFailed (FromHere(),msg); } } m_result.resize(m_functions.size()); m_is_parsed = true; }
void Excitation::CalcCustomExcitation(double f0, int nTS, string signal) { if (dT==0) return; if (nTS<=0) return; Length = (unsigned int)(nTS); // cerr << "Operator::CalcSinusExcitation: Length of the excite signal: " << ExciteLength << " timesteps" << endl; delete[] Signal_volt; delete[] Signal_curr; Signal_volt = new FDTD_FLOAT[Length+1]; Signal_curr = new FDTD_FLOAT[Length+1]; Signal_volt[0]=0.0; Signal_curr[0]=0.0; FunctionParser fParse; fParse.AddConstant("pi", 3.14159265358979323846); fParse.AddConstant("e", 2.71828182845904523536); fParse.Parse(signal,"t"); if (fParse.GetParseErrorType()!=FunctionParser::FP_NO_ERROR) { cerr << "Operator::CalcCustomExcitation: Function Parser error: " << fParse.ErrorMsg() << endl; exit(1); } double vars[1]; for (unsigned int n=1; n<Length+1; ++n) { vars[0] = (n-1)*dT; Signal_volt[n] = fParse.Eval(vars); vars[0] += 0.5*dT; Signal_curr[n] = fParse.Eval(vars); } m_f_max = f0; m_foi = f0; SetNyquistNum( CalcNyquistNum(f0,dT) ); }
//_____________________________________________________________________________ // void tf_set_formula() //----------------------------------------------------------------------------- { // Parse transfer function formula if( tf_fun_formula[0] == '\0' ) return ; FunctionParser fparser ; int res = fparser.Parse( (const char*)tf_fun_formula, "x" ) ; if( fparser.GetParseErrorType() != FunctionParser::NO_SYNTAX_ERROR ) { printf( "transfer formula error: %s\n\t%s\n\t% *d\n", fparser.ErrorMsg(), tf_fun_formula, res, 1 ) ; return ; } // Retreives the color map if( tf_colmap < 0 || tf_colmap >= CMAP_NB ) return ; const float *colmap = cmaps[tf_colmap] ; // allocate the transfer function int tf_size = tf_sym ? 512 : 256 ; vsvr.tf_set_intern() ; vsvr.tf_set_size( tf_size ) ; vsvr.tf_alloc() ; // fills the texture float x = 0.0f ; float dx = 1.0f / (tf_size-1) ; for( int i = 0 ; i < tf_size ; ++i, x += dx ) { int k = i ; // symmetric if( i > 255 ) k = 511 - i ; // inverse if( tf_inv ) k = 255 - k ; const float *col = colmap + 3*k ; float a = fparser.Eval( &x ) ; if( a < 0.0f ) a = 0.0f ; if( a > 1.0f ) a = 1.0f ; vsvr.tf_set( i, col[0], col[1], col[2], a*opacity ) ; } force_reload = true ; }
//------------------------------------------------------------------------------------------------- double BenchFParser::DoBenchmark(const std::string& sExpr, long iCount) { double fRes (0); double fSum (0); FunctionParser Parser; Parser.AddConstant("pi", (double)M_PI); Parser.AddConstant("e", (double)M_E); if (Parser.Parse(sExpr.c_str(), "a,b,c,x,y,z,w") >= 0) { StopTimerAndReport(Parser.ErrorMsg()); return m_fTime1; } else { double vals[] = { 1.1, 2.2, 3.3, 2.123456, 3.123456, 4.123456, 5.123456 }; fRes = Parser.Eval(vals); StartTimer(); for (int j = 0; j < iCount; ++j) { fSum += Parser.Eval(vals); std::swap(vals[0], vals[1]); std::swap(vals[3], vals[4]); } StopTimer(fRes, fSum, iCount); } return m_fTime1; }
//------------------------------------------------------------------------------------------------- double BenchFParser::DoBenchmark(const std::string& sExpr, long iCount) { double fRes = 0.0; double fSum = 0.0; FunctionParser Parser; Parser.AddConstant("pi", (double)M_PI); Parser.AddConstant("e", (double)M_E); if (Parser.Parse(sExpr.c_str(), "a,b,c,x,y,z,w") >= 0) { StopTimerAndReport(Parser.ErrorMsg()); return m_fTime1; } else { double vals[] = { 1.1, 2.2, 3.3, 2.123456, 3.123456, 4.123456, 5.123456 }; //Prime the I and D caches for the expression { double d0 = 0.0; double d1 = 0.0; for (std::size_t i = 0; i < priming_rounds; ++i) { if (i & 1) d0 += Parser.Eval(vals); else d1 += Parser.Eval(vals); } if ( (d0 == std::numeric_limits<double>::infinity()) && (d1 == std::numeric_limits<double>::infinity()) ) { printf("\n"); } } fRes = Parser.Eval(vals); StartTimer(); for (int j = 0; j < iCount; ++j) { fSum += Parser.Eval(vals); std::swap(vals[0], vals[1]); std::swap(vals[3], vals[4]); } StopTimer(fRes, fSum, iCount); } return m_fTime1; }