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

📄 dloadn.cpp

📁 Finite element program for mechanical problem. It can solve various problem in solid problem
💻 CPP
字号:
#include "dloadn.h"#include "global.h"#include "genfile.h"#include <string.h>/**  This constructor initializes class attributes to the zero values*/dloadn::dloadn(){  idn = nlc = ndir = neqs = 0L;  f = NULL;  eq = NULL;  var = NULL;  func = NULL;  tabf = NULL;}/**  This destructor deallocates used memory.*/dloadn::~dloadn(){  long i;  switch (tfunc)  {    case stat:      delete [] f;      break;    case pars:      for (i = 0; i < ndir; i++)      {        delete func[i];        delete var[i];        delete eq[i];      }      delete [] func;      delete [] eq;      delete [] var;      break;        case tab:      delete [] tabf;     break;        case pars_set :    {      delete [] f;      for (i = 0; i < neqs*ndir; i++)      {        delete func[i];        delete var[i];        delete eq[i];      }      delete [] func;      delete [] eq;      delete [] var;      break;    }    default:{      fprintf (stderr,"\n\n unknown time function is required in function (file %s, line %d).\n",__FILE__,__LINE__);    }  }}/**  This function reads data for the dynamical nodal load from the opened text file  given by the parameter in.  @param in - pointer to the opened text file  @retval 0 - on success.  @retval 1 - error parsing string expression*/long dloadn::read(XFILE *in){  long i,j,id,ndofn;  Parser par;  xfscanf(in, "%ld",&idn);  if (idn<1)    fprintf (stderr,"\n\n number of loaded node in function dloadn::read (dloadn.cpp) is nonpositive");  if (idn>Mt->nn){    fprintf (stderr,"\n\n number of loaded node in function dloadn::read (dloadn.cpp)");    fprintf (stderr,"\n is greater than total number of nodes.\n");  }  idn--;  ndir = ndofn = Mt->give_ndofn (idn);  xfscanf (in,"%d",(int*)&tfunc);  switch (tfunc){  case stat:{    f = new double [ndofn];    for (i=0;i<ndofn;i++){      xfscanf (in,"%lf",f+i);    }    break;  }  case pars:{    neqs = 1;    eq = new Equation* [ndofn];    var = new variable* [ndofn];    func = new char* [ndofn];    for (i = 0; i < ndofn; i++){      func[i]=new char [256];      getnexttxt(in->file);      fgets(func[i], 255, in->file);      eq[i] = par.TextToTree(func[i]);      if (eq[i] == NULL)        {          fprintf(stderr, "\nError parsing expression\n");          return(1);        }      var[i] = eq[i]->Variables.at(0);    }    break;  }  case tab:{    tabf = new tablefunct [ndofn];    for (i=0;i<ndofn;i++){      tabf[i].read(in);    }    break;  }  case pars_set :  {    xfscanf (in, "%ld", &neqs);    if (neqs <= 0)      fprintf (stderr,"\n\n number of expressions in set <= 0 \n in function dloadn::read (dloadn.cpp)\n");    eq   = new Equation* [ndofn*neqs];    var  = new variable* [ndofn*neqs];    func = new char*     [ndofn*neqs];    f    = new double    [ndofn*neqs];    for (i = 0; i < ndofn; i++)    {      for (j = 0; j < neqs; j++)      {        id = i * neqs + j;        xfscanf(in, "%lf", f+id);        func[id]=new char [256];        getnexttxt(in->file);        fgets(func[id], 255, in->file);        eq[id] = par.TextToTree(func[id]);        if (eq[id] == NULL)        {          fprintf(stderr, "\nError parsing expression\n");          return(1);        }        var[id] = eq[id]->Variables.at(0);      }    }    break;  }  default:{    fprintf (stderr,"\n\n unknown time function is required in function (dloadn.cpp).\n");  }  }  return(0);}/**  This function return value of the dynamical nodal load for the time given by the parameter t.  @param t - desired value of time.  @param id - load direction id  @retval The function returns value of the dynamical nodal load for the given time.*/double dloadn::getval(double t, long id){  long i, idx;  double ret;  switch (tfunc){  case stat:{    ret=f[id];    break;  }  case pars:{    if (var[id])      var[id]->Value = t;    ret = eq[id]->Evaluate();    break;  }  case tab:{    ret=tabf[id].getval(t);    break;  }  case pars_set :  {    for (i = 0; i < neqs; i++)    {      idx = id * neqs + i;      if (f[idx] >= t)      {        if (var[idx])          var[idx]->Value = t;        ret = eq[idx]->Evaluate();        break;      }      if (i == neqs-1)      {        if (var[idx])          var[idx]->Value = t;        ret = eq[idx]->Evaluate();      }    }    break;  }  default:{    fprintf (stderr,"\n\n unknown time function is required in function (file %s, line %d).\n",__FILE__,__LINE__);  }  }  return(ret);}/**  This function reads data for the dynamical nodal load from the opened text preprocessor file  given by the parameter in. This function is used in the mechprep  @param in - pointer to the opened text file  @param ndofn - number of nodal dof.  @param lc   - total number of load cases  @retval 0 - on success.  @retval 1 - error reading string with exprssion  @retval 2 - error parsing string expression*/long dloadn::read_prop(FILE *in, long ndofn, long lc){  long i,j,id;  Parser par;  ndir = ndofn;  getlong(in, nlc);  if ((nlc < 1) || (nlc > lc))    return(2);  getint(in, (int &)tfunc);  switch (tfunc){  case stat:{    f = new double [ndofn];    for (i=0;i<ndofn;i++){      getdouble (in,f[i]);    }    break;  }  case pars:{    neqs = 1;    eq = new Equation* [ndofn];    var = new variable* [ndofn];    func = new char* [ndofn];    for (i = 0; i < ndofn; i++){      func[i]=new char [256];      getstring(in, func[i], 255);      eq[i] = par.TextToTree(func[i]);      if (eq[i] == NULL)        {          fprintf(stderr, "\n\n Error parsing expression\n");          fprintf(stderr, " in function dloadn::read_prop, (file %s, line %d)\n", __FILE__, __LINE__);          return(1);        }      var[i] = eq[i]->Variables.at(0);    }    break;  }  case tab:{    tabf = new tablefunct [ndofn];    for (i=0;i<ndofn;i++){      tabf[i].read_prop(in);    }    break;  }  case pars_set :  {    fscanf (in, "%ld", &neqs);    if (neqs <= 0)      fprintf (stderr,"\n\n number of expressions in set <= 0 \n in function dloadn::read (dloadn.cpp)\n");    eq   = new Equation* [ndofn*neqs];    var  = new variable* [ndofn*neqs];    func = new char*     [ndofn*neqs];    f    = new double    [ndofn*neqs];    for (i = 0; i < ndofn; i++)    {      for (j = 0; j < neqs; j++)      {        id = i * neqs + j;        fscanf(in, "%lf", f+id);        func[id]=new char [256];        getstring(in, func[id], 255);        eq[id] = par.TextToTree(func[id]);        if (eq[id] == NULL)        {          fprintf(stderr, "\n\nError parsing expression\n");          fprintf(stderr, " in function dloadn::read_prop, (file %s, line %d)\n", __FILE__, __LINE__);          return(1);        }        var[id] = eq[id]->Variables.at(0);      }    }    break;  }  default:{    fprintf (stderr,"\n\n unknown time function is required in function (dloadn.cpp).\n");  }  }    return(0);}/**  This function prints data for the dynamical nodal load to the opened text preprocessor file  given by the parameter out. This function is used in the mechprep  @param in - pointer to the opened text file  @param ndofn - number of nodal dof.  @param lc   - total number of load cases  @retval 0 - on success.  @retval 1 - error reading string with exprssion  @retval 2 - error parsing string expression*/long dloadn::print_prop(FILE *out, long ndofn){  long i, j, id;  fprintf (out," %d",tfunc);  switch (tfunc){  case stat:{    for (i=0;i<ndofn;i++){      fprintf (out," %lf\n",f[i]);    }    break;  }  case pars:{    for (i = 0; i < ndofn; i++){      fprintf(out, " %s\n", func[i]);    }    break;  }  case tab:{    for (i=0;i<ndofn;i++){      tabf[i].print(out);    }    break;  }  case pars_set :  {    fprintf (out, " %ld\n", neqs);    for (i = 0; i < ndofn; i++)    {      for (j = 0; j < neqs; j++)      {        id = i * neqs + j;        fprintf(out, " %lf", f[id]);        fprintf(out, " %s\n", func[id]);      }    }    break;  }  default:{    fprintf (stderr,"\n\n unknown time function is required in function (dloadn.cpp).\n");  }  }  return(0);}

⌨️ 快捷键说明

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