⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 timefunc.h

📁 pic 模拟程序!面向对象
💻 H
字号:
/*====================================================================timefunc.h	This class contains parameters for time-dependent operation of   boundaries.  It can be used in any place where time parameterization	is needed.0.95  (PeterM 3/8/95) Creation	0.97  (PeterM 6/11/96) Added string parser using strings==================================================================== */#ifndef TimeFunction_H#define TimeFunction_H#include "misc.h"#include "math.h"#include "eval.h"#include "ostring.h"extern Evaluator *adv_eval;class TimeFunction {	  int time_function_flag; /* selects from any various interpretations of above */  Scalar A,C;   /*  Usually AC and then DC values respectively */  Scalar w, phase;  /*parameters for the AC component usually */  Scalar trise, tfall, tpulse, tdelay;  /* parameters for the envelope function */  Scalar a0,a1; /* more parameters for the time dependent function */  Scalar local_time; // This can now be Scalar -- RT, 2003/12/09  ostring Func;  Evaluator *evaluator;	  Scalar Envelope(Scalar t)     {      if(t<tdelay)        return a0;      if(t<trise+tdelay)         return (a1-a0)*(t-tdelay)/trise + a0;      if(t<trise+tpulse+tdelay)        return a1;      if(t<trise+tpulse+tfall+tdelay)        return a1 - (a1-a0)*(t - trise - tpulse- tdelay)/tfall;      return a0;    };  Scalar TanhEnvelope(Scalar t)    {      if(t<tdelay)        return 0;      if(t<trise+tdelay)        return 0.5*(tanh(14*(t-tdelay)/trise-6)+1);      if(t<trise+tdelay+tpulse)        return 1;      if(t<trise+tdelay+tpulse+tfall)        return 0.5*(tanh(-14*(t-tdelay-trise-tpulse)/tfall+8)                    +1);    };  Scalar DerivEnvelope(Scalar t)     {      if(t<tdelay)        return 0;      if(t<trise+tdelay)         return (a1-a0)/trise;      if(t<trise+tpulse+tdelay)        return 0.0;      if(t<trise+tpulse+tfall+tdelay)        return - (a1-a0)/tfall;      return 0;    };	  Scalar IntTimeValue(Scalar t)    {      Scalar iw;//, itrise;      if (w)        iw=1/(w);      else        iw=0;				      if(t<tdelay)        return (a0+C)*t;      if(t<trise+tdelay)         return a0*C + C*(a1+a0)*t*t/(2*trise) +           cos(w * t + phase)*(-a0*A*iw - t*A*(a1-a0)*iw/trise) +           sin(w * t + phase)*A*(a1-a0)*iw*iw/trise;      if(t<trise+tpulse+tdelay)        return a1*(C*t-A*cos(w * t + phase)*iw);      if(t<trise+tpulse+tfall+tdelay)        {          Scalar a = a1+(trise+tpulse)/tfall;          Scalar m = -(a1-a0)/tfall;          Scalar Coeff1 = m*A*iw*iw;          Scalar Coeff2 = a*A*iw + Coeff1;          return a*C*t + C*m*t*t/2 + Coeff1*sin(w * t + phase) -              Coeff2*cos(w * t + phase);         }      return a0*(C*t-A*cos(w * t + phase)*iw);    };	  Scalar DerivSinusoid(Scalar t)     {      return A * w*sin(w * t + phase);    };  Scalar Sinusoid(Scalar t)     {      return C + A * sin(w * t + phase);    };  Scalar CoSinusoid(Scalar t)     {      return C + A * cos(w * t + phase);    };		                      public:  TimeFunction(Scalar _A, Scalar _C, Scalar _f, Scalar _p, Scalar _tr,               Scalar _tf, Scalar _tp, Scalar _td, Scalar _a0, Scalar _a1,                ostring F,int _tflag=0)     {      A=_A; C = _C; w = _f*TWOPI; phase = _p; trise = _tr;      tfall = _tf; tpulse = _tp; tdelay = _td;      a0 = _a0; a1 = _a1; time_function_flag = _tflag;      Func = "0";      evaluator = new Evaluator(adv_eval);      if(time_function_flag==1) {        Func=F+ (ostring)'\n';        evaluator->add_indirect_variable("t",&local_time);      };    };  Scalar TimeValue(Scalar t) {    switch(time_function_flag) {    case 0:      return Envelope(t) * Sinusoid(t);    case 1:      {        local_time = t;        return evaluator->Evaluate(Func.c_str());      }    default:      return 0;    };  };  Scalar TimeValueDeriv(Scalar t) {    switch(time_function_flag) {    case 0:      return Sinusoid(t)*DerivEnvelope(t) + Envelope(t)*DerivSinusoid(t);    default:      return 0;    };  };  Scalar TimeValueInt(Scalar t) {    switch(time_function_flag){    case 0:      return IntTimeValue(t);    default:      return 0;    };  };  Scalar TimeValue2(Scalar t) {    switch(time_function_flag) {    case 0:      return Envelope(t) * CoSinusoid(t);    default:      return 0;    };  };  Scalar TimeValue3(Scalar t) {    switch(time_function_flag) {    case 0:      return TanhEnvelope(t);    default:      return 0;    };  };		};#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -