bocon.cpp
来自「Finite element program for mechanical pr」· C++ 代码 · 共 147 行
CPP
147 行
#include "bocon.h"#include "../../GEFEL/intools.h"#include <string.h>#include <stdlib.h>bocon::bocon()/**< Constructor initializes data members Parameters : none Returns : nothing*/{ nn = 0L; ndir = 0L; dir = NULL; con = NULL; expr = NULL;}long bocon::read(FILE *in)/**< Method reads data from the text file specified by parameter in Parameters : @param in - pointer to the opened text file, where the data will be read Returns : @retval 0 - on success*/{/* long nbc, td, i; double tc; fscanf(in, "%ld%ld", &nn, &nbc); if ((nn < 1) || (nn > T->nn)) return(1); nn--; ndof = T->nodes[nn].ndofn; if ((nbc < 1) || (nbc > ndof)) return(2); dir = new long[ndof]; for (i = 0; i < ndof; dir[i] = -1, i++); con = new double[ndof]; memset(con, 0, sizeof(*cond)*ndof); for (i = 0, i < nbc; i++) { fsacnf(in,"%ld%le", &td, &tc); if ((td < 1) || (td > ndof)) return(3); td--; dir[td] = td; con[td] = tc; }*/ return(0);}long bocon::read_prop(FILE *in, long ndofn)/**< Method reads data from the text file specified by parameter in, data are in preprocessor format Parameters : @param in - pointer to the opened text file, where the data will be read @param ndofn - number of dofs in given node with prescribed condition Returns : @retval 0 - on success*/{ long nbc, td, i; double tc; Parser par; Equation *eq; if ((ndofn < 1) || (ndofn > 6)) // test number of dofs return(2); ndir = ndofn; getlong(in, nbc); // reading number of conditions if ((nbc < 1) || (nbc > ndir)) // which should be in range <1,ndofn> return(3); // allocating memory for arrays dir = new long[ndir]; for (i = 0; i < ndir; dir[i] = -1, i++); // if dir[i] == -1 there is no codition in the i direction con = new double[ndir]; memset(con, 0, sizeof(*con)*ndir); expr = new char*[ndir]; memset(expr, 0, sizeof(*expr)*ndir); // loop which reads conditions in each directions for (i = 0; i < nbc; i++) { getlong(in, td); // reading direction getdouble(in, tc); // reading condition if ((labs(td) < 1) || (labs(td) > ndir)) // direction should be in range <1, ndir> return(4); if (td > 0) // if number of direction is positive -> static condition { td--; dir[td] = td; con[td] = tc; } if (td < 0) // if number of direction is negative -> dynamic condition { td = labs(td); td--; dir[td] = td; con[td] = tc; expr[i] = new char[1025]; expr[0] = '\0'; getstring(in, expr[i], 1024); // read string with expression eq = par.TextToTree(expr[i]); // expansion expression in the string // by parser to binary tree if (eq == NULL) // expansion failed { fprintf(stderr, "\nError parsing expression in function bocon::read_prop()\n"); fprintf(stderr, " in file bocon.cpp, direction number %ld\n", i+1); return(5); } } } return(0);}bocon::~bocon(){ delete [] dir; delete [] con; if (expr) { for (long i = 0; i < ndir; i++) delete [] expr[i]; } delete [] expr;}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?