FEI  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
driverData.cpp
1 /*--------------------------------------------------------------------*/
2 /* Copyright 2005 Sandia Corporation. */
3 /* Under the terms of Contract DE-AC04-94AL85000, there is a */
4 /* non-exclusive license for use of this work by or on behalf */
5 /* of the U.S. Government. Export of this program may require */
6 /* a license from the United States Government. */
7 /*--------------------------------------------------------------------*/
8 
9 
10 #include <fei_fstream.hpp>
11 
12 #include <FEI.hpp>
13 #include <fei_defs.h>
14 
15 #include <snl_fei_Utils.hpp>
16 #include <test_utils/DataReader.hpp>
17 
18 #include <test_utils/driverData.hpp>
19 
20 #include <cstring>
21 
22 #ifdef CHK_ERR
23 #undef CHK_ERR
24 #endif
25 #define CHK_ERR(a) {int chkerr; if ((chkerr = a) != 0) { \
26  fei::console_out() << "file " << __FILE__ << ", line " << __LINE__ \
27  << ", err " << chkerr << FEI_ENDL; \
28  return(chkerr); } }
29 
30 driverData::driverData()
31  :
32  methodNames(),
33  temp_(NULL),
34  tempLen_(0),
35  initFields_fieldSizes_(NULL),
36  initFields_fieldIDs_(NULL),
37  initElemBlock_ints_(NULL),
38  initElemBlock_fieldsPerNode_(NULL),
39  initElemBlock_fieldIDs_(NULL),
40  initElemBlock_elemDofFieldIDs_(NULL),
41  initElems_(),
42  initElemCounter_(0),
43  sumInElems_(),
44  sumInElemCounter_(0),
45  sumInElemMatrix_(),
46  sumInElemMatrixCounter_(0),
47  sumInElemRHS_(),
48  sumInElemRHSCounter_(0),
49  loadNodeBCs_(),
50  loadNodeBCsCounter_(0),
51  initCRMult_(),
52  initCRMultCounter_(0),
53  loadCRMult_(),
54  loadCRMultCounter_(0),
55  initSharedNodes_(),
56  initSharedNodesCounter_(0),
57  parameters_(),
58  parametersCounter_(0),
59  setIDLists_(),
60  setIDListsCounter_(0),
61  setCurrentMatrix_(),
62  setCurrentMatrixCounter_(0),
63  setCurrentRHS_(),
64  setCurrentRHSCounter_(0),
65  putBlockFieldNodeSolution_(),
66  putBlockFieldNodeSolutionCounter_(0)
67 {
68  tempLen_ = 512;
69  temp_ = new char[tempLen_];
70 }
71 
72 driverData::~driverData()
73 {
74  tempLen_ = 0;
75  delete [] temp_;
76 
77  for(size_t i=0; i<methodNames.size(); i++) {
78  delete [] methodNames[i];
79  }
80 
81  delete [] initFields_fieldSizes_;
82  delete [] initFields_fieldIDs_;
83 
84  if (initElemBlock_numInts_ > 0 && initElemBlock_ints_ != NULL) {
85  int len = initElemBlock_ints_[2];
86  for(int j=0; j<len; ++j) delete [] initElemBlock_fieldIDs_[j];
87  delete [] initElemBlock_fieldIDs_;
88  delete [] initElemBlock_fieldsPerNode_;
89  delete [] initElemBlock_ints_;
90  initElemBlock_ints_ = NULL;
91  }
92 
93  for(size_t i=0; i<initElems_.size(); ++i) delete initElems_[i];
94  for(size_t i=0; i<sumInElems_.size(); ++i) delete sumInElems_[i];
95  for(size_t i=0; i<sumInElemMatrix_.size(); ++i) delete sumInElemMatrix_[i];
96  for(size_t i=0; i<sumInElemRHS_.size(); ++i) delete sumInElemRHS_[i];
97  for(size_t i=0; i<loadNodeBCs_.size(); ++i) delete loadNodeBCs_[i];
98  for(size_t i=0; i<initCRMult_.size(); ++i) delete initCRMult_[i];
99  for(size_t i=0; i<loadCRMult_.size(); ++i) delete loadCRMult_[i];
100  for(size_t i=0; i<initSharedNodes_.size(); ++i) delete initSharedNodes_[i];
101  for(size_t i=0; i<parameters_.size(); ++i) delete parameters_[i];
102  for(size_t i=0; i<setIDLists_.size(); ++i) delete setIDLists_[i];
103 }
104 
105 int driverData::readData(const char* fileName)
106 {
107  FEI_IFSTREAM* instr = NULL;
108  instr = new FEI_IFSTREAM(fileName);
109 
110  if (instr->bad()) {
111  fei::console_out() << "driverData::readData: ERROR opening " << fileName << FEI_ENDL;
112  return(-1);
113  }
114  FEI_COUT << "driverData reading from " << fileName << FEI_ENDL;
115  char* keyword = NULL;
116 
117  int err = getKeyword(instr, keyword);
118  while (!instr->eof() && !err) {
119  FEI_COUT << "driverData read keyword: " << keyword << FEI_ENDL;
120  err = readData(instr, keyword);
121  if (err != 0) {
122  fei::console_out() << "driverData: ERROR reading data for keyword: " << keyword << FEI_ENDL;
123  break;
124  }
125  delete [] keyword;
126  err = getKeyword(instr, keyword);
127  }
128 
129  delete instr;
130 
131  return(0);
132 }
133 
134 int driverData::call_fei_method(const char* method, FEI* fei)
135 {
136  if (!std::strcmp("setSolveType", method)) {
137  return( fei->setSolveType(solveType_) );
138  }
139 
140  if (!std::strcmp("setIDLists", method)) {
141  if (setIDListsCounter_ >= (int)setIDLists_.size()) {
142  fei::console_out() << "driverData ERROR, can't call setIDLists again" << FEI_ENDL;
143  return(-1);
144  }
145 
146  setIDLists* sidl = setIDLists_[setIDListsCounter_++];
147 
148  return( fei->setIDLists(sidl->numMatrices, sidl->matrixIDs,
149  sidl->numRHSs, sidl->rhsIDs) );
150  }
151 
152  if (!std::strcmp("setCurrentMatrix", method)) {
153  if (setCurrentMatrixCounter_ >= (int)setCurrentMatrix_.size()) {
154  fei::console_out() << "driverData ERROR, can't call setCurrentMatrix again" << FEI_ENDL;
155  return(-1);
156  }
157 
158  int matID = setCurrentMatrix_[setCurrentMatrixCounter_++];
159 
160  return( fei->setCurrentMatrix(matID) );
161  }
162 
163  if (!std::strcmp("setCurrentRHS", method)) {
164  if (setCurrentRHSCounter_ >= (int)setCurrentRHS_.size()) {
165  fei::console_out() << "driverData ERROR, can't call setCurrentRHS again" << FEI_ENDL;
166  return(-1);
167  }
168 
169  int rhsID = setCurrentRHS_[setCurrentRHSCounter_++];
170 
171  return( fei->setCurrentMatrix(rhsID) );
172  }
173 
174  if (!std::strcmp("initFields", method)) {
175  return( fei->initFields(initFields_numFields_,
176  initFields_fieldSizes_,
177  initFields_fieldIDs_) );
178  }
179 
180  if (!std::strcmp("initElemBlock", method)) {
181  return( fei->initElemBlock((GlobalID)initElemBlock_ints_[0],
182  initElemBlock_ints_[1],
183  initElemBlock_ints_[2],
184  initElemBlock_fieldsPerNode_,
185  initElemBlock_fieldIDs_,
186  initElemBlock_ints_[3],
187  initElemBlock_elemDofFieldIDs_,
188  initElemBlock_ints_[4]) );
189 
190  }
191 
192  if (!std::strcmp("parameters", method)) {
193  if (parametersCounter_ >= (int)parameters_.size()) {
194  fei::console_out() << "driverData ERROR, can't call parameters again" << FEI_ENDL;
195  return(-1);
196  }
197 
198  parameters* param = parameters_[parametersCounter_++];
199 
200  return( fei->parameters(param->paramList.size(),
201  &param->paramList[0]) );
202  }
203 
204  if (!std::strcmp("initCRMult", method)) {
205  if (initCRMultCounter_ >= (int)initCRMult_.size()) {
206  fei::console_out() << "driverData ERROR, can't call initCRMult again" << FEI_ENDL;
207  return(-1);
208  }
209 
210  initCR* icr = initCRMult_[initCRMultCounter_++];
211 
212  return( fei->initCRMult(icr->numNodes, icr->nodeIDs,
213  icr->fieldIDs, icr->CRID) );
214  }
215 
216  if (!std::strcmp("initSharedNodes", method)) {
217  if (initSharedNodesCounter_ >= (int)initSharedNodes_.size()) {
218  fei::console_out() << "driverData ERROR, can't call initSharedNodes again" << FEI_ENDL;
219  return(-1);
220  }
221 
222  sharedNodes* sn = initSharedNodes_[initSharedNodesCounter_++];
223 
224  return( fei->initSharedNodes(sn->numNodes, sn->nodeIDs,
225  sn->numProcsPerNode, sn->sharedProcIDs) );
226  }
227 
228  if (!std::strcmp("loadCRMult", method)) {
229  if (loadCRMultCounter_ >= (int)loadCRMult_.size()) {
230  fei::console_out() << "driverData ERROR, can't call loadCRMult again" << FEI_ENDL;
231  return(-1);
232  }
233 
234  loadCR* lcr = loadCRMult_[loadCRMultCounter_++];
235 
236  return( fei->loadCRMult(lcr->CRID, lcr->numNodes, lcr->nodeIDs,
237  lcr->fieldIDs, lcr->weights, lcr->CRValue) );
238  }
239 
240  if (!std::strcmp("deleteMultCRs", method)) {
241  return( fei->deleteMultCRs() );
242  }
243 
244  if (!std::strcmp("initElem", method)) {
245  if (initElemCounter_ >= (int)initElems_.size()) {
246  fei::console_out() << "driverData ERROR, can't call initElem again" << FEI_ENDL;
247  return(-1);
248  }
249 
250  initElem* ie = initElems_[initElemCounter_++];
251 
252  return( fei->initElem(ie->elemBlockID, ie->elemID, ie->nodeIDs) );
253  }
254 
255  if (!std::strcmp("initComplete", method)) {
256  return( fei->initComplete() );
257  }
258 
259  if (!std::strcmp("resetSystem", method)) {
260  return( fei->resetSystem(resetSystem_) );
261  }
262 
263  if (!std::strcmp("resetMatrix", method)) {
264  return( fei->resetMatrix(resetMatrix_) );
265  }
266 
267  if (!std::strcmp("resetRHSVector", method)) {
268  return( fei->resetRHSVector(resetRHSVector_) );
269  }
270 
271  if (!std::strcmp("resetInitialGuess", method)) {
272  return( fei->resetInitialGuess(resetInitialGuess_) );
273  }
274 
275  if (!std::strcmp("sumInElem", method)) {
276  if (sumInElemCounter_ >= (int)sumInElems_.size()) {
277  fei::console_out() << "driverData ERROR, can't call sumInElem again" << FEI_ENDL;
278  return(-1);
279  }
280 
281  sumInElem* sie = sumInElems_[sumInElemCounter_++];
282 
283  return( fei->sumInElem(sie->elemBlockID, sie->elemID, sie->nodeIDs,
284  sie->stiffness, sie->load, sie->elemFormat) );
285  }
286 
287  if (!std::strcmp("sumInElemMatrix", method)) {
288  if (sumInElemMatrixCounter_ >= (int)sumInElemMatrix_.size()) {
289  fei::console_out() << "driverData ERROR, can't call sumInElemMatrix again" << FEI_ENDL;
290  return(-1);
291  }
292 
293  sumInElem* sie = sumInElemMatrix_[sumInElemMatrixCounter_++];
294 
295  return( fei->sumInElemMatrix(sie->elemBlockID, sie->elemID, sie->nodeIDs,
296  sie->stiffness, sie->elemFormat) );
297  }
298 
299  if (!std::strcmp("sumInElemRHS", method)) {
300  if (sumInElemRHSCounter_ >= (int)sumInElemRHS_.size()) {
301  fei::console_out() << "driverData ERROR, can't call sumInElemRHS again" << FEI_ENDL;
302  return(-1);
303  }
304 
305  sumInElem* sie = sumInElemRHS_[sumInElemRHSCounter_++];
306 
307  return( fei->sumInElemRHS(sie->elemBlockID, sie->elemID, sie->nodeIDs,
308  sie->load) );
309  }
310 
311  if (!std::strcmp("putBlockFieldNodeSolution", method)) {
312  if (putBlockFieldNodeSolutionCounter_ >=
313  (int)putBlockFieldNodeSolution_.size()) {
314  fei::console_out() << "driverData ERROR, can't call putBlockFieldNodeSolution again"
315  << FEI_ENDL;
316  return(-1);
317  }
318 
319  putBlockFieldNodeSolution* pbfns =
320  putBlockFieldNodeSolution_[putBlockFieldNodeSolutionCounter_++];
321 
322  return( fei->putBlockFieldNodeSolution(pbfns->elemBlockID,
323  pbfns->fieldID,
324  pbfns->numNodes,
325  pbfns->nodeIDs,
326  pbfns->estimates) );
327  }
328 
329  if (!std::strcmp("loadNodeBCs", method)) {
330  if (loadNodeBCsCounter_ >= (int)loadNodeBCs_.size()) {
331  fei::console_out() << "driverData ERROR, can't call loadNodeBCs again" << FEI_ENDL;
332  return(-1);
333  }
334 
335  fei::console_out() << "driverData: ERROR, loadNodeBCs needs to be re-examined..." << FEI_ENDL;
336  return( -1 );
337  }
338 
339  if (!std::strcmp("loadComplete", method)) {
340  return( fei->loadComplete() );
341  }
342 
343  if (!std::strcmp("solve", method)) {
344  int status;
345  return( fei->solve(status) );
346  }
347 
348  if (!std::strcmp("getBlockNodeIDList", method) ||
349  !std::strcmp("residualNorm", method) ||
350  !std::strcmp("getBlockFieldNodeSolution", method)) {
351  return(0);
352  }
353 
354  fei::console_out() << "driverData: ERROR unrecognized method name '" << method << "'"<<FEI_ENDL;
355  return(1);
356 }
357 
358 int driverData::readData(FEI_ISTREAM* instr, char* keyword)
359 {
360  if (!std::strcmp("setSolveType", keyword)) {
361  CHK_ERR( appendName(keyword) );
362  return(readData(instr, solveType_));
363  }
364 
365  if (!std::strcmp("setIDLists", keyword)) {
366  int numMatrices = 0;
367  CHK_ERR( readData(instr, numMatrices) );
368  setIDLists* sidl = new setIDLists;
369  sidl->numMatrices = numMatrices;
370  sidl->matrixIDs = new int[numMatrices];
371  int i;
372  for(i=0; i<numMatrices; ++i) {
373  CHK_ERR( readData(instr, sidl->matrixIDs[i]) );
374  }
375  int numRHSs = 0;
376  CHK_ERR( readData(instr, numRHSs) );
377  sidl->numRHSs = numRHSs;
378  sidl->rhsIDs = new int[numRHSs];
379  for(i=0; i<numRHSs; ++i) {
380  CHK_ERR( readData(instr, sidl->rhsIDs[i]) );
381  }
382 
383  setIDLists_.push_back(sidl);
384  return( appendName(keyword) );
385  }
386 
387  if (!std::strcmp("setCurrentMatrix", keyword)) {
388  int matID = 0;
389  CHK_ERR( readData(instr, matID) );
390  setCurrentMatrix_.push_back(matID);
391  return( appendName(keyword) );
392  }
393 
394  if (!std::strcmp("setCurrentRHS", keyword)) {
395  int rhsID = 0;
396  CHK_ERR( readData(instr, rhsID) );
397  setCurrentRHS_.push_back(rhsID);
398  return( appendName(keyword) );
399  }
400 
401  if (!std::strcmp("initFields", keyword)) {
402  int i;
403  CHK_ERR( readData(instr, initFields_numFields_) );
404  initFields_fieldSizes_ = new int[initFields_numFields_];
405  initFields_fieldIDs_ = new int[initFields_numFields_];
406 
407  for(i=0; i<initFields_numFields_; ++i) {
408  CHK_ERR( readData(instr, initFields_fieldSizes_[i]) );
409  }
410  for(i=0; i<initFields_numFields_; ++i) {
411  CHK_ERR( readData(instr, initFields_fieldIDs_[i]) );
412  }
413 
414  return( appendName(keyword) );
415  }
416 
417  if (!std::strcmp("parameters", keyword)) {
418  int numParams = 0;
419  CHK_ERR( readData(instr, numParams) );
420  parameters* param = new parameters;
421  param->paramList.resize(numParams);
422  CHK_ERR( skipWhite(instr) );
423  for(int i=0; i<numParams; ++i) {
424  char* line = new char[512];
425  instr->getline(line, 512);
426  param->paramList[i] = line;
427  }
428  parameters_.push_back(param);
429  return( appendName(keyword) );
430  }
431 
432  if (!std::strcmp("initElemBlock", keyword)) {
433  initElemBlock_numInts_ = 5;
434  int i, intOffset = 0;
435  initElemBlock_ints_ = new int[initElemBlock_numInts_];
436  //elemBlockID
437  CHK_ERR( readData(instr, initElemBlock_ints_[intOffset++]) );
438  //numElements
439  CHK_ERR( readData(instr, initElemBlock_ints_[intOffset++]) );
440  //numNodesPerElement
441  CHK_ERR( readData(instr, initElemBlock_ints_[intOffset++]) );
442  //now loop and read numFieldsPerNode
443  int len = initElemBlock_ints_[intOffset-1];
444  initElemBlock_fieldsPerNode_ = new int[len];
445  initElemBlock_fieldIDs_ = new int*[len];
446  for(i=0; i<len; ++i) {
447  CHK_ERR( readData(instr, initElemBlock_fieldsPerNode_[i]) );
448  }
449  //now double-loop and read nodalFieldIDs
450  for(i=0; i<len; ++i) {
451  int len2 = initElemBlock_fieldsPerNode_[i];
452  initElemBlock_fieldIDs_[i] = new int[len2];
453  for(int ii=0; ii<len2; ++ii) {
454  CHK_ERR( readData(instr, initElemBlock_fieldIDs_[i][ii]) );
455  }
456  }
457  //numElemDOFPerElement
458  CHK_ERR( readData(instr, initElemBlock_ints_[intOffset++]) );
459  //now loop and read elemDOFFieldIDs
460  len = initElemBlock_ints_[intOffset-1];
461  if (len > 0) {
462  initElemBlock_elemDofFieldIDs_ = new int[len];
463  for(i=0; i<len; ++i) {
464  CHK_ERR( readData(instr, initElemBlock_elemDofFieldIDs_[i]) );
465  }
466  }
467  //interleaveStrategy
468  CHK_ERR( readData(instr, initElemBlock_ints_[intOffset++]) );
469  return( appendName(keyword) );
470  }
471 
472  if (!std::strcmp("initElem", keyword) ) {
473  initElem* ie = new initElem;
474  int tmp;
475  CHK_ERR( readData(instr, tmp) );
476  ie->elemBlockID = (GlobalID)tmp;
477  CHK_ERR( readData(instr, tmp) );
478  ie->elemID = (GlobalID)tmp;
479  CHK_ERR( readData(instr, tmp) );
480  ie->nodeIDs = new GlobalID[tmp];
481  ie->numNodes = tmp;
482  for(int i=0; i<ie->numNodes; ++i) {
483  CHK_ERR( readData(instr, tmp) );
484  ie->nodeIDs[i] = (GlobalID)tmp;
485  }
486  initElems_.push_back(ie);
487  return( appendName(keyword) );
488  }
489 
490  if (!std::strcmp("initCRMult", keyword) ) {
491  initCR* icr = new initCR;
492  CHK_ERR( readData(instr, icr->numNodes) );
493  if (icr->numNodes > 0) {
494  icr->nodeIDs = new GlobalID[icr->numNodes];
495  icr->fieldIDs = new int[icr->numNodes];
496  int i, tmp;
497  //read the nodeIDs
498  for(i=0; i<icr->numNodes; ++i) {
499  CHK_ERR( readData(instr, tmp) ); icr->nodeIDs[i] = (GlobalID)tmp;
500  }
501  //read the fieldIDs
502  for(i=0; i<icr->numNodes; ++i) {
503  CHK_ERR( readData(instr, icr->fieldIDs[i]) );
504  }
505  }
506  //read the CRID
507  CHK_ERR( readData(instr, icr->CRID) );
508 
509  initCRMult_.push_back(icr);
510  return( appendName(keyword) );
511  }
512 
513  if (!std::strcmp("loadCRMult", keyword) ) {
514  loadCR* lcr = new loadCR;
515  CHK_ERR( readData(instr, lcr->numNodes) );
516  if (lcr->numNodes > 0) {
517  lcr->nodeIDs = new GlobalID[lcr->numNodes];
518  lcr->fieldIDs = new int[lcr->numNodes];
519  lcr->fieldSizes = new int[lcr->numNodes];
520  int i, tmp;
521  //read the nodeIDs
522  for(i=0; i<lcr->numNodes; ++i) {
523  CHK_ERR( readData(instr, tmp) ); lcr->nodeIDs[i] = (GlobalID)tmp;
524  }
525  //read the fieldIDs
526  for(i=0; i<lcr->numNodes; ++i) {
527  CHK_ERR( readData(instr, lcr->fieldIDs[i]) );
528  }
529  //read the field-sizes
530  tmp = 0;
531  for(i=0; i<lcr->numNodes; ++i) {
532  CHK_ERR( readData(instr, lcr->fieldSizes[i]) );
533  tmp += lcr->fieldSizes[i];
534  }
535  //read the weights
536  lcr->weights = new double[tmp];
537  int offset = 0;
538  for(i=0; i<lcr->numNodes; ++i) {
539  int size = lcr->fieldSizes[i];
540  for(int j=0; j<size; ++j) {
541  CHK_ERR( readData(instr, lcr->weights[offset++]) );
542  }
543  }
544  //read the CRValue
545  CHK_ERR( readData(instr, lcr->CRValue) );
546  }
547  //read the CRID
548  CHK_ERR( readData(instr, lcr->CRID) );
549 
550  loadCRMult_.push_back(lcr);
551  return( appendName(keyword) );
552  }
553 
554  if (!std::strcmp("deleteMultCRs", keyword) ) {
555  return( appendName(keyword) );
556  }
557 
558  if (!std::strcmp("initSharedNodes", keyword) ) {
559  sharedNodes* sn = new sharedNodes;
560  CHK_ERR( readData(instr, sn->numNodes) );
561  if (sn->numNodes > 0) {
562  sn->nodeIDs = new GlobalID[sn->numNodes];
563  sn->numProcsPerNode = new int[sn->numNodes];
564  sn->sharedProcIDs = new int*[sn->numNodes];
565  int i, tmp;
566  //read the numProcsPerNode list
567  for(i=0; i<sn->numNodes; ++i) {
568  CHK_ERR( readData(instr, sn->numProcsPerNode[i]) );
569  sn->sharedProcIDs[i] = new int[sn->numProcsPerNode[i]];
570  }
571  //read the nodeIDs and sharing-proc-ids
572  for(i=0; i<sn->numNodes; ++i) {
573  CHK_ERR( readData(instr, tmp) ); sn->nodeIDs[i] = (GlobalID)tmp;
574  for(int j=0; j<sn->numProcsPerNode[i]; ++j) {
575  CHK_ERR( readData(instr, sn->sharedProcIDs[i][j]) );
576  }
577  }
578  }
579 
580  initSharedNodes_.push_back(sn);
581  return( appendName(keyword) );
582  }
583 
584  if (!std::strcmp("initComplete", keyword) ) {
585  return( appendName(keyword) );
586  }
587 
588  if (!std::strcmp("sumInElem", keyword) ) {
589  sumInElem* sie = new sumInElem;
590  int tmp;
591  double dtmp;
592  CHK_ERR( readData(instr, tmp) );
593  sie->elemBlockID = (GlobalID)tmp;
594  CHK_ERR( readData(instr, tmp) );
595  sie->elemID = (GlobalID)tmp;
596  CHK_ERR( readData(instr, tmp) );
597  sie->nodeIDs = new GlobalID[tmp];
598  sie->numNodes = tmp;
599  int i;
600  for(i=0; i<sie->numNodes; ++i) {
601  CHK_ERR( readData(instr, tmp) );
602  sie->nodeIDs[i] = (GlobalID)tmp;
603  }
604 
605  CHK_ERR( readData(instr, tmp) );
606  sie->numRows = tmp;
607  sie->stiff1D = new double[tmp*tmp];
608  sie->load = new double[tmp];
609  sie->stiffness = new double*[tmp];
610  int offset = 0;
611  for(i=0; i<sie->numRows; ++i) {
612  for(int j=0; j<sie->numRows; ++j) {
613  CHK_ERR( readData(instr, dtmp) );
614  sie->stiff1D[offset++] = dtmp;
615  }
616  sie->stiffness[i] = &(sie->stiff1D[i*sie->numRows]);
617  }
618 
619  for(int j=0; j<sie->numRows; ++j) {
620  CHK_ERR( readData(instr, dtmp) );
621  sie->load[j] = dtmp;
622  }
623 
624  CHK_ERR( readData(instr, tmp) );
625  sie->elemFormat = tmp;
626 
627  sumInElems_.push_back(sie);
628  return( appendName(keyword) );
629  }
630 
631  if (!std::strcmp("sumInElemMatrix", keyword) ) {
632  sumInElem* sie = new sumInElem;
633  int tmp;
634  double dtmp;
635  CHK_ERR( readData(instr, tmp) );
636  sie->elemBlockID = (GlobalID)tmp;
637  CHK_ERR( readData(instr, tmp) );
638  sie->elemID = (GlobalID)tmp;
639  CHK_ERR( readData(instr, tmp) );
640  sie->nodeIDs = new GlobalID[tmp];
641  sie->numNodes = tmp;
642  int i;
643  for(i=0; i<sie->numNodes; ++i) {
644  CHK_ERR( readData(instr, tmp) );
645  sie->nodeIDs[i] = (GlobalID)tmp;
646  }
647 
648  CHK_ERR( readData(instr, tmp) );
649  sie->numRows = tmp;
650  sie->stiff1D = new double[tmp*tmp];
651  sie->load = new double[tmp];
652  sie->stiffness = new double*[tmp];
653  int offset = 0;
654  for(i=0; i<sie->numRows; ++i) {
655  for(int j=0; j<sie->numRows; ++j) {
656  CHK_ERR( readData(instr, dtmp) );
657  sie->stiff1D[offset++] = dtmp;
658  }
659  sie->stiffness[i] = &(sie->stiff1D[i*sie->numRows]);
660  }
661 
662  CHK_ERR( readData(instr, tmp) );
663  sie->elemFormat = tmp;
664 
665  sumInElemMatrix_.push_back(sie);
666  return( appendName(keyword) );
667  }
668 
669  if (!std::strcmp("sumInElemRHS", keyword) ) {
670  sumInElem* sie = new sumInElem;
671  int tmp;
672  double dtmp;
673  CHK_ERR( readData(instr, tmp) );
674  sie->elemBlockID = (GlobalID)tmp;
675  CHK_ERR( readData(instr, tmp) );
676  sie->elemID = (GlobalID)tmp;
677  CHK_ERR( readData(instr, tmp) );
678  sie->nodeIDs = new GlobalID[tmp];
679  sie->numNodes = tmp;
680  for(int i=0; i<sie->numNodes; ++i) {
681  CHK_ERR( readData(instr, tmp) );
682  sie->nodeIDs[i] = (GlobalID)tmp;
683  }
684 
685  CHK_ERR( readData(instr, tmp) );
686  sie->numRows = tmp;
687 
688  sie->load = new double[sie->numRows];
689  for(int j=0; j<sie->numRows; ++j) {
690  CHK_ERR( readData(instr, dtmp) );
691  sie->load[j] = dtmp;
692  }
693 
694  sumInElemRHS_.push_back(sie);
695  return( appendName(keyword) );
696  }
697 
698  if (!std::strcmp("resetSystem", keyword) ) {
699  CHK_ERR( readData(instr, resetSystem_) );
700  return( appendName(keyword) );
701  }
702 
703  if (!std::strcmp("resetMatrix", keyword) ) {
704  CHK_ERR( readData(instr, resetMatrix_) );
705  return( appendName(keyword) );
706  }
707 
708  if (!std::strcmp("resetRHSVector", keyword) ) {
709  CHK_ERR( readData(instr, resetRHSVector_) );
710  return( appendName(keyword) );
711  }
712 
713  if (!std::strcmp("resetInitialGuess", keyword) ) {
714  CHK_ERR( readData(instr, resetInitialGuess_) );
715  return( appendName(keyword) );
716  }
717 
718  if (!std::strcmp("putBlockFieldNodeSolution", keyword) ) {
719  putBlockFieldNodeSolution* pbfns = new putBlockFieldNodeSolution;
720  CHK_ERR( readData(instr, pbfns->elemBlockID) );
721  CHK_ERR( readData(instr, pbfns->fieldID) );
722  CHK_ERR( readData(instr, pbfns->fieldSize) );
723  CHK_ERR( readData(instr, pbfns->numNodes) );
724  if (pbfns->numNodes > 0) {
725  pbfns->nodeIDs = new GlobalID[pbfns->numNodes];
726 
727  int i=0;
728  for(i=0; i<pbfns->numNodes; ++i) {
729  CHK_ERR( readData(instr, pbfns->nodeIDs[i]) );
730  }
731  int len = pbfns->numNodes * pbfns->fieldSize;
732  pbfns->estimates = new double[len];
733 
734  for(i=0; i<pbfns->numNodes * pbfns->fieldSize; ++i) {
735  CHK_ERR( readData(instr, pbfns->estimates[i]) );
736  }
737  }
738 
739  putBlockFieldNodeSolution_.push_back(pbfns);
740  return( appendName(keyword) );
741  }
742 
743  if (!std::strcmp("loadNodeBCs", keyword) ) {
744  nodeBC* nbc = new nodeBC;
745  CHK_ERR( readData(instr, nbc->numNodes) );
746  CHK_ERR( readData(instr, nbc->fieldID) );
747  CHK_ERR( readData(instr, nbc->fieldSize) );
748 
749  if (nbc->numNodes > 0) {
750  nbc->nodeIDs = new GlobalID[nbc->numNodes];
751  nbc->alpha = new double*[nbc->numNodes];
752  nbc->beta = new double*[nbc->numNodes];
753  nbc->gamma = new double*[nbc->numNodes];
754 
755  int i, j, tmp;
756  for(i=0; i<nbc->numNodes; ++i) {
757  nbc->alpha[i] = new double[nbc->fieldSize];
758  nbc->beta[i] = new double[nbc->fieldSize];
759  nbc->gamma[i] = new double[nbc->fieldSize];
760 
761  CHK_ERR( readData(instr, tmp) );
762  nbc->nodeIDs[i] = (GlobalID)tmp;
763 
764  for(j=0; j<nbc->fieldSize; ++j) {
765  CHK_ERR( readData(instr, nbc->alpha[i][j]));
766  }
767  for(j=0; j<nbc->fieldSize; ++j) {
768  CHK_ERR( readData(instr, nbc->beta[i][j]));
769  }
770  for(j=0; j<nbc->fieldSize; ++j) {
771  CHK_ERR( readData(instr, nbc->gamma[i][j]));
772  }
773  }
774  }
775 
776  loadNodeBCs_.push_back(nbc);
777  return( appendName(keyword) );
778  }
779 
780  if (!std::strcmp("loadComplete", keyword) ||
781  !std::strcmp("solve", keyword) ||
782  !std::strcmp("destructor", keyword) ||
783  !std::strcmp("getBlockNodeIDList", keyword) ||
784  !std::strcmp("getBlockFieldNodeSolution", keyword) ||
785  !std::strcmp("residualNorm", keyword)) {
786  return( appendName(keyword) );
787  }
788 
789  return(-1);
790 }
791 
792 int driverData::appendName(const char* name)
793 {
794  if (name == NULL) return(-1);
795  char* str = new char[strlen(name)+1];
796  strcpy(str, name);
797  methodNames.push_back(str);
798  return(0);
799 }
800 
801 int driverData::getKeyword(FEI_ISTREAM* instr, char*& keyword)
802 {
803  int err = skipWhite(instr);
804  if (err) return(err);
805 
806  for(int i=0; i<tempLen_; i++) temp_[i] = '\0';
807 
808  do {
809  instr->getline(temp_, tempLen_);
810  } while ((strlen(temp_) == 0) && (!instr->eof()));
811 
812  if (instr->eof() || strlen(temp_) == 0) return(-1);
813 
814  keyword = new char[strlen(temp_)+1];
815  const char* temp2 = snl_fei::getParamValue("FEI:", 1, &temp_);
816 
817  if (temp2 != NULL) {
818  strcpy(keyword, temp2);
819  return(0);
820  }
821 
822  return(-1);
823 }
824 
825 //==============================================================================
826 int driverData::is_reg_char(char c) {
827  int i = (int)c;
828  if (i<1 || i>126) return(0);
829 
830  return(1);
831 }
832 
833 //==============================================================================
834 int driverData::skipWhite(FEI_ISTREAM* instr) {
835  char c = '\0';
836  instr->get(c);
837 
838  if (!is_reg_char(c)) {
839  return(-1);
840  }
841 
842  while(c == '#' || c == '\n' || c == ' ') {
843  if (c=='#') {
844  char* buf = new char[128];
845  for(int i=0; i<128; i++) buf[i] = '\0';
846  instr->getline(buf, 128);
847  delete [] buf;
848  }
849 
850  instr->get(c);
851 
852  if (instr->eof()) return(1);
853  if ((int)c == EOF) return(1);
854 
855  if (!is_reg_char(c)) {
856  return(-1);
857  }
858  }
859 
860  instr->putback(c);
861  return(0);
862 }
863 
864 //==============================================================================
865 int driverData::readData(FEI_ISTREAM* instr, int& n) {
866  int err = skipWhite(instr);
867  if (err) return(err);
868  (*instr) >> n;
869  return(0);
870 }
871 
872 //==============================================================================
873 int driverData::readData(FEI_ISTREAM* instr, double& val) {
874  int err = skipWhite(instr);
875  if (err) return(err);
876  (*instr) >> val;
877  return(0);
878 }
879 
virtual int sumInElemMatrix(GlobalID elemBlockID, GlobalID elemID, const GlobalID *elemConn, const double *const *elemStiffness, int elemFormat)=0
virtual int parameters(int numParams, const char *const *paramStrings)=0
virtual int initComplete()=0
virtual int solve(int &status)=0
virtual int loadCRMult(int CRMultID, int numCRNodes, const GlobalID *CRNodeIDs, const int *CRFieldIDs, const double *CRWeights, double CRValue)=0
virtual int initCRMult(int numCRNodes, const GlobalID *CRNodeIDs, const int *CRFieldIDs, int &CRID)=0
Definition: FEI.hpp:144
virtual int deleteMultCRs()=0
virtual int initSharedNodes(int numSharedNodes, const GlobalID *sharedNodeIDs, const int *numProcsPerNode, const int *const *sharingProcIDs)=0
virtual int resetInitialGuess(double s)=0
virtual int initFields(int numFields, const int *fieldSizes, const int *fieldIDs, const int *fieldTypes=NULL)=0
virtual int initElemBlock(GlobalID elemBlockID, int numElements, int numNodesPerElement, const int *numFieldsPerNode, const int *const *nodalFieldIDs, int numElemDofFieldsPerElement, const int *elemDOFFieldIDs, int interleaveStrategy)=0
virtual int setSolveType(int solveType)=0
virtual int resetMatrix(double s=0.0)=0
std::ostream & console_out()
virtual int loadComplete(bool applyBCs=true, bool globalAssemble=true)=0
virtual int resetSystem(double s=0.0)=0
virtual int sumInElemRHS(GlobalID elemBlockID, GlobalID elemID, const GlobalID *elemConn, const double *elemLoad)=0
virtual int resetRHSVector(double s=0.0)=0
virtual int setIDLists(int numMatrices, const int *matrixIDs, int numRHSs, const int *rhsIDs)=0
virtual int setCurrentMatrix(int matrixID)=0
virtual int sumInElem(GlobalID elemBlockID, GlobalID elemID, const GlobalID *elemConn, const double *const *elemStiffness, const double *elemLoad, int elemFormat)=0
virtual int putBlockFieldNodeSolution(GlobalID elemBlockID, int fieldID, int numNodes, const GlobalID *nodeIDs, const double *estimates)=0
virtual int initElem(GlobalID elemBlockID, GlobalID elemID, const GlobalID *elemConn)=0