Changed: Removed option to suppress print during parsing (not needed).

Added: type="expression" as default.
This commit is contained in:
Knut Morten Okstad 2016-08-06 15:11:33 +02:00
parent 161aceaac2
commit fccea559f1
2 changed files with 33 additions and 29 deletions

View File

@ -140,7 +140,8 @@ Interpolate1D::Interpolate1D (const char* file, int dir_, int col, Real ramp) :
return; return;
} }
while (is.good() && !is.eof()) { while (is.good() && !is.eof())
{
char temp[1024]; char temp[1024];
is.getline(temp,1024); is.getline(temp,1024);
if (is.eof()) return; if (is.eof()) return;
@ -269,7 +270,8 @@ const RealFunc* utl::parseRealFunc (char* cline, Real A)
{ {
double x1 = atof(strtok(nullptr," ")); double x1 = atof(strtok(nullptr," "));
double y1 = atof(strtok(nullptr," ")); double y1 = atof(strtok(nullptr," "));
IFEM::cout <<"StepXY(["<< x0 <<","<< x1 <<"]x["<< y0 <<","<<y1 <<"]))"; IFEM::cout <<"StepXY(["<< x0 <<","<< x1
<<"]x["<< y0 <<","<< y1 <<"]))";
f = new StepXYFunc(A,x1,y1,x0,y0); f = new StepXYFunc(A,x1,y1,x0,y0);
} }
else else
@ -284,13 +286,15 @@ const RealFunc* utl::parseRealFunc (char* cline, Real A)
int dir = atoi(strtok(nullptr," ")), col = 2; int dir = atoi(strtok(nullptr," ")), col = 2;
IFEM::cout <<"Interpolate1D("<< cline; IFEM::cout <<"Interpolate1D("<< cline;
const char* t = strtok(nullptr," "); const char* t = strtok(nullptr," ");
if (t && t[0] == 'c') { if (t && t[0] == 'c')
{
col = atoi(t+1); col = atoi(t+1);
t = strtok(nullptr," "); t = strtok(nullptr," ");
IFEM::cout <<",column #"<< col; IFEM::cout <<",column #"<< col;
} }
IFEM::cout <<","<< (char)('X'+dir); IFEM::cout <<","<< (char)('X'+dir);
if (t) { if (t)
{
double time = atof(t); double time = atof(t);
IFEM::cout <<")*Ramp("<< time; IFEM::cout <<")*Ramp("<< time;
f = new Interpolate1D(cline,dir,col,time); f = new Interpolate1D(cline,dir,col,time);
@ -345,7 +349,7 @@ const RealFunc* utl::parseRealFunc (char* cline, Real A)
if (!cline) return f; // constant in time if (!cline) return f; // constant in time
IFEM::cout <<" * "; IFEM::cout <<" * ";
const ScalarFunc* s = parseTimeFunc(cline,nullptr,C); const ScalarFunc* s = parseTimeFunction(cline,nullptr,C);
if (f) if (f)
return new SpaceTimeFunc(f,s); return new SpaceTimeFunc(f,s);
@ -354,7 +358,7 @@ const RealFunc* utl::parseRealFunc (char* cline, Real A)
} }
const ScalarFunc* utl::parseTimeFunc (const char* type, char* cline, Real C) const ScalarFunc* utl::parseTimeFunction (const char* type, char* cline, Real C)
{ {
if (strncasecmp(type,"expr",4) == 0 && cline != nullptr) if (strncasecmp(type,"expr",4) == 0 && cline != nullptr)
{ {
@ -418,14 +422,14 @@ ScalarFunc* utl::parseTimeFunc (const char* func, const std::string& type)
{ {
IFEM::cout <<"(expression) "; IFEM::cout <<"(expression) ";
if (func) cstr = strdup(func); if (func) cstr = strdup(func);
sf = parseTimeFunc("expression",cstr); sf = parseTimeFunction("expression",cstr);
} }
else if (type == "linear") else if (type == "linear")
sf = parseTimeFunc(func); sf = parseTimeFunction(func,cstr);
else else
{ {
if (func) cstr = strdup(func); if (func) cstr = strdup(func);
sf = parseTimeFunc(type.c_str(),cstr); sf = parseTimeFunction(type.c_str(),cstr);
} }
IFEM::cout << std::endl; IFEM::cout << std::endl;
if (cstr) free(cstr); if (cstr) free(cstr);
@ -434,17 +438,15 @@ ScalarFunc* utl::parseTimeFunc (const char* func, const std::string& type)
} }
RealFunc* utl::parseRealFunc (const std::string& func, const std::string& type, bool print) RealFunc* utl::parseRealFunc (const std::string& func, const std::string& type)
{ {
if (func.empty()) return nullptr; if (func.empty()) return nullptr;
if (print) IFEM::cout <<": ";
IFEM::cout <<": ";
Real p = Real(0); Real p = Real(0);
if (type == "expression") if (type == "expression")
{ {
if (print) IFEM::cout << func;
IFEM::cout << func;
EvalFunc::numError = 0; EvalFunc::numError = 0;
RealFunc* rf = new EvalFunction(func.c_str()); RealFunc* rf = new EvalFunction(func.c_str());
if (EvalFunc::numError > 0) if (EvalFunc::numError > 0)
@ -457,15 +459,13 @@ RealFunc* utl::parseRealFunc (const std::string& func, const std::string& type,
else if (type == "linear") else if (type == "linear")
{ {
p = atof(func.c_str()); p = atof(func.c_str());
if (print) IFEM::cout << p <<"*t";
IFEM::cout << p <<"*t";
return new ConstTimeFunc(new LinearFunc(p)); return new ConstTimeFunc(new LinearFunc(p));
} }
else if (type == "constant" || func.find_first_of("\t ") == std::string::npos) else if (type == "constant" || func.find_first_of("\t ") == std::string::npos)
{ {
p = atof(func.c_str()); p = atof(func.c_str());
if (print) IFEM::cout << p;
IFEM::cout << p;
return new ConstFunc(p); return new ConstFunc(p);
} }

View File

@ -502,35 +502,39 @@ protected:
namespace utl namespace utl
{ {
//! \brief Creates a time function by parsing a character string. //! \brief Creates a time function by parsing a character string.
const ScalarFunc* parseTimeFunc(const char* type, char* cline = nullptr, const ScalarFunc* parseTimeFunction(const char* type, char* cline,
Real C = Real(1)); Real C = Real(1));
//! \brief Creates a scalar-valued function by parsing a character string. //! \brief Creates a scalar-valued function by parsing a character string.
const RealFunc* parseRealFunc(char* cline, Real A = Real(1)); const RealFunc* parseRealFunc(char* cline, Real A = Real(1));
//! \brief Creates a time function by parsing a character string. //! \brief Creates a time function by parsing a character string.
ScalarFunc* parseTimeFunc(const char* func, const std::string& type); //! \param[in] func Character string to parse function definition from
//! \param[in] type Function definition type flag
ScalarFunc* parseTimeFunc(const char* func,
const std::string& type = "expression");
//! \brief Creates a scalar-valued function by parsing a character string. //! \brief Creates a scalar-valued function by parsing a character string.
//! \param[in] func Character string to parse function definition from //! \param[in] func Character string to parse function definition from
//! \param[in] type Function definition type flag //! \param[in] type Function definition type flag
//! \param[in] print If \e false, do not print out function definition RealFunc* parseRealFunc(const std::string& func,
RealFunc* parseRealFunc(const std::string& func, const std::string& type, const std::string& type = "expression");
bool print = true);
//! \brief Creates a vector-valued function by parsing a character string. //! \brief Creates a vector-valued function by parsing a character string.
//! \param[in] func Character string to parse function definition from //! \param[in] func Character string to parse function definition from
//! \param[in] type Function defintion type flag //! \param[in] type Function definition type flag
//! \param[in] variables Variable definition for expression functions //! \param[in] variables Optional variable definition for expression functions
VecFunc* parseVecFunc(const std::string& func, const std::string& type, VecFunc* parseVecFunc(const std::string& func,
const std::string& type = "expression",
const std::string& variables = ""); const std::string& variables = "");
//! \brief Creates a vector-valued function defining a surface traction. //! \brief Creates a vector-valued function defining a surface traction.
//! \param[in] func Character string to parse function definition from //! \param[in] func Character string to parse function definition from
//! \param[in] type Function defintion type flag //! \param[in] type Function definition type flag
//! \param[in] dir Coordinate direction of the traction (0=normal direction) //! \param[in] dir Coordinate direction of the traction (0=normal direction)
TractionFunc* parseTracFunc(const std::string& func, TractionFunc* parseTracFunc(const std::string& func,
const std::string& type, int dir); const std::string& type = "expression",
int dir = 0);
} }
#endif #endif