FEI  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
test_FEI_Impl.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_macros.hpp>
11 #include <fei_sstream.hpp>
12 
13 #include <test_utils/test_FEI_Impl.hpp>
14 
15 #include <fei_FEI_Impl.hpp>
16 #ifdef HAVE_FEI_AZTECOO
17 #include <fei_Aztec_LinSysCore.hpp>
18 #endif
19 #include <test_utils/FEData.hpp>
20 #include <fei_LibraryWrapper.hpp>
21 
22 #include <test_utils/testData.hpp>
23 
24 #undef fei_file
25 #define fei_file "test_FEI_Impl.cpp"
26 #include <fei_ErrMacros.hpp>
27 
28 test_FEI_Impl::test_FEI_Impl(MPI_Comm comm)
29  : tester(comm)
30 {
31 }
32 
33 test_FEI_Impl::~test_FEI_Impl()
34 {
35 }
36 
37 int test_FEI_Impl::runtests()
38 {
39  if (numProcs_<2) {
40  CHK_ERR( serialtest1() );
41  }
42 
43  CHK_ERR( test1() );
44  CHK_ERR( test2() );
45  CHK_ERR( test3() );
46  CHK_ERR( test4() );
47  return(0);
48 }
49 
50 int test_FEI_Impl::serialtest1()
51 {
52  return(0);
53 }
54 
55 int test_FEI_Impl::compareCoefs(int n,
56  const double*const* coefs1,
57  const double*const* coefs2)
58 {
59  for(int i=0; i<n; ++i) {
60  for(int j=0; j<n; ++j) {
61  double diff = coefs1[i][j] - coefs2[i][j];
62  if (diff > 1.e-20 || diff < -1.e-20) {
63  return(-1);
64  }
65  }
66  }
67 
68  return(0);
69 }
70 
71 int test_FEI_Impl::test1()
72 {
73  if (numProcs_ > 1) {
74  return(0);
75  }
76 #ifdef HAVE_FEI_AZTECOO
77  testData* testdata = new testData(localProc_, numProcs_);
78 
79  fei::SharedPtr<LinearSystemCore> linSys(new fei_trilinos::Aztec_LinSysCore(comm_));
80  fei::SharedPtr<LibraryWrapper> wrapper(new LibraryWrapper(linSys));
81  fei::SharedPtr<fei::FEI_Impl> fei(new fei::FEI_Impl(wrapper, comm_, 0));
82 
83  std::string param0("name test1");
84  FEI_OSTRINGSTREAM osstr;
85  osstr << "debugOutput ";
86  if (path_.empty()) osstr << ".";
87  else osstr << path_;
88 
89  std::string param1 = osstr.str();
90 
91  int numParams = 2;
92  char** params = new char*[numParams];
93  params[0] = const_cast<char*>(param0.c_str());
94  params[1] = const_cast<char*>(param1.c_str());
95 
96  //call the parameters function a couple of times to test the fei's internal
97  //method for merging string lists when parameters is called more than once.
98  CHK_ERR( fei->parameters(1, &params[0]) );
99  CHK_ERR( fei->parameters(1, &params[1]) );
100  CHK_ERR( fei->parameters(2, params) );
101 
102  delete [] params;
103 
104  CHK_ERR( fei->setIDLists(1, &(testdata->ids[0]),
105  1, &(testdata->ids[0])) );
106 
107  CHK_ERR( fei->initFields(testdata->fieldIDs.size(),
108  &(testdata->fieldSizes[0]),
109  &(testdata->fieldIDs[0])) );
110 
111  int numNodesPerElem = testdata->ids.size();
112  std::vector<int> numFieldsPerNode(numNodesPerElem, 1);
113  std::vector<int*>nodalFieldIDs(numNodesPerElem, &(testdata->fieldIDs[0]));
114 
115  CHK_ERR( fei->initElemBlock(0, //blockID
116  1, //numElements
117  numNodesPerElem,
118  &numFieldsPerNode[0],
119  &nodalFieldIDs[0],
120  0, //numElemDofFieldsPerElement
121  NULL, //elemDofFieldIDs
122  0)); //interleaveStrategy
123 
124  CHK_ERR( fei->initElem(0, //blockID
125  0, //elemID
126  &(testdata->ids[0])) );
127 
128  std::vector<int*> sharingProcs2D(testdata->sharedIDs.size());
129  int offset = 0;
130  for(int i=0; i<(int)testdata->numSharingProcsPerID.size(); ++i) {
131  sharingProcs2D[i] = &(testdata->sharingProcs[offset]);
132  offset += testdata->numSharingProcsPerID[i];
133  }
134 
135  if (testdata->sharedIDs.size() > 0) {
136  CHK_ERR( fei->initSharedNodes(testdata->sharedIDs.size(),
137  &(testdata->sharedIDs[0]),
138  &(testdata->numSharingProcsPerID[0]),
139  &sharingProcs2D[0]) );
140  }
141 
142  CHK_ERR( fei->initComplete() );
143 
144  std::vector<double> rhsData(testdata->ids.size(), 1.0);
145 
146  double one = 1.0;
147  CHK_ERR( fei->setMatScalars(1, &(testdata->ids[0]), &one) );
148  CHK_ERR( fei->setRHSScalars(1, &(testdata->ids[0]), &one) );
149 
150  CHK_ERR( fei->setCurrentMatrix(testdata->ids[0]) );
151  CHK_ERR( fei->setCurrentRHS(testdata->ids[0]) );
152 
153  CHK_ERR( fei->putIntoRHS(FEI_NODE, testdata->fieldIDs[0],
154  testdata->ids.size(),
155  &(testdata->ids[0]),
156  &rhsData[0]) );
157 
158  int numBCNodes = 2;
159  GlobalID* BCNodeIDs = &(testdata->ids[0]);
160  int BCFieldID = testdata->fieldIDs[0];
161  double* values = new double[numBCNodes];
162  int* offsetsIntoField = new int[numBCNodes];
163  for(int ii=0; ii<numBCNodes; ++ii) {
164  values[ii] = 1.0;
165  offsetsIntoField[ii] = 0;
166  }
167 
168  CHK_ERR( fei->loadNodeBCs(numBCNodes, BCNodeIDs, BCFieldID,
169  offsetsIntoField, values) );
170 
171  delete [] offsetsIntoField;
172  delete [] values;
173 
174  CHK_ERR( fei->loadComplete() );
175 
176  int numActiveNodes = 0;
177  CHK_ERR( fei->getNumLocalNodes(numActiveNodes) );
178  if (numActiveNodes != (int)testdata->ids.size()) {
179  ERReturn(-1);
180  }
181 
182  GlobalID* localNodes = new GlobalID[numActiveNodes];
183  CHK_ERR( fei->getLocalNodeIDList(numActiveNodes, localNodes, numActiveNodes) );
184 
185  int totalFieldSize = 0;
186  for(int ii=0; ii<(int)testdata->fieldSizes.size(); ++ii) {
187  totalFieldSize += testdata->fieldSizes[ii];
188  }
189 
190  double* soln = new double[numActiveNodes*totalFieldSize];
191  int* offsets = new int[numActiveNodes+1];
192 
193  CHK_ERR( fei->getNodalSolution(numActiveNodes, localNodes,
194  offsets, soln) );
195  delete [] offsets;
196  delete [] soln;
197  delete [] localNodes;
198 
199  CHK_ERR( fei->resetInitialGuess() );
200 
201  int fieldSize = 0;
202  CHK_ERR( fei->getFieldSize(testdata->fieldIDs[0], fieldSize) );
203 
204  double initTime, loadTime, solveTime, solnReturnTime;
205  CHK_ERR( fei->cumulative_cpu_times(initTime, loadTime, solveTime,
206  solnReturnTime) );
207 
208  delete testdata;
209 #endif
210  return(0);
211 }
212 
213 int test_FEI_Impl::test2()
214 {
215  fei::SharedPtr<testData> testdata(new testData(localProc_, numProcs_));
216  fei::SharedPtr<FiniteElementData> fedata(new FEData(comm_));
217  fei::SharedPtr<LibraryWrapper> wrapper(new LibraryWrapper(fedata));
218  fei::SharedPtr<fei::FEI_Impl> fei(new fei::FEI_Impl(wrapper, comm_, 0));
219 
220  std::string param0("name test1");
221  FEI_OSTRINGSTREAM osstr;
222  osstr << "debugOutput ";
223  if (path_.empty()) osstr << ".";
224  else osstr << path_;
225 
226  std::string param1 = osstr.str();
227 
228  int numParams = 2;
229  char** params = new char*[numParams];
230  params[0] = const_cast<char*>(param0.c_str());
231  params[1] = const_cast<char*>(param1.c_str());
232 
233  //call the parameters function a couple of times to test the fei's internal
234  //method for merging string lists when parameters is called more than once.
235  CHK_ERR( fei->parameters(1, &params[0]) );
236  CHK_ERR( fei->parameters(1, &params[1]) );
237  CHK_ERR( fei->parameters(2, params) );
238 
239  delete [] params;
240 
241  CHK_ERR( fei->setIDLists(1, &(testdata->ids[0]),
242  1, &(testdata->ids[0])) );
243  CHK_ERR( fei->initFields(testdata->fieldIDs.size(),
244  &(testdata->fieldSizes[0]),
245  &(testdata->fieldIDs[0])) );
246 
247  int numNodesPerElem = testdata->ids.size();
248  std::vector<int> numFieldsPerNode(numNodesPerElem, 1);
249  std::vector<int*>nodalFieldIDs(numNodesPerElem, &(testdata->fieldIDs[0]));
250 
251  CHK_ERR( fei->initElemBlock(0, //blockID
252  1, //numElements
253  numNodesPerElem,
254  &numFieldsPerNode[0],
255  &nodalFieldIDs[0],
256  0, //numElemDofFieldsPerElement
257  NULL, //elemDofFieldIDs
258  0)); //interleaveStrategy
259 
260  CHK_ERR( fei->initElem(0, //blockID
261  0, //elemID
262  &(testdata->ids[0])) );
263 
264  std::vector<int*> sharingProcs2D(testdata->sharedIDs.size());
265  int i, offset = 0;
266  for(i=0; i<(int)testdata->numSharingProcsPerID.size(); ++i) {
267  sharingProcs2D[i] = &(testdata->sharingProcs[offset]);
268  offset += testdata->numSharingProcsPerID[i];
269  }
270 
271  if (testdata->sharedIDs.size() > 0) {
272  CHK_ERR( fei->initSharedNodes(testdata->sharedIDs.size(),
273  &(testdata->sharedIDs[0]),
274  &(testdata->numSharingProcsPerID[0]),
275  &sharingProcs2D[0]) );
276  }
277 
278  CHK_ERR( fei->initComplete() );
279 
280  std::vector<double> rhsData(testdata->ids.size(), 1.0);
281 
282  double one = 1.0;
283  CHK_ERR( fei->setMatScalars(1, &(testdata->ids[0]), &one) );
284  CHK_ERR( fei->setRHSScalars(1, &(testdata->ids[0]), &one) );
285 
286  CHK_ERR( fei->setCurrentMatrix(testdata->ids[0]) );
287  CHK_ERR( fei->setCurrentRHS(testdata->ids[0]) );
288 
289  int ii;
290 
291  int numBCNodes = 2;
292  GlobalID* BCNodeIDs = &(testdata->ids[0]);
293  int BCFieldID = testdata->fieldIDs[0];
294  double* values = new double[numBCNodes];
295  int* offsetsIntoField = new int[numBCNodes];
296  for(ii=0; ii<numBCNodes; ++ii) {
297  values[ii] = 1.0;
298  offsetsIntoField[ii] = 0;
299  }
300 
301  CHK_ERR( fei->loadNodeBCs(numBCNodes, BCNodeIDs, BCFieldID,
302  offsetsIntoField, values) );
303 
304  delete [] values;
305  delete [] offsetsIntoField;
306 
307  CHK_ERR( fei->loadComplete() );
308 
309  int numActiveNodes = 0;
310  CHK_ERR( fei->getNumLocalNodes(numActiveNodes) );
311  if (numActiveNodes != (int)testdata->ids.size()) {
312  ERReturn(-1);
313  }
314 
315  GlobalID* localNodes = new GlobalID[numActiveNodes];
316  CHK_ERR( fei->getLocalNodeIDList(numActiveNodes, localNodes, numActiveNodes) );
317 
318  int totalFieldSize = 0;
319  for(ii=0; ii<(int)testdata->fieldSizes.size(); ++ii) {
320  totalFieldSize += testdata->fieldSizes[ii];
321  }
322 
323  double* soln = new double[numActiveNodes*totalFieldSize];
324  int* offsets = new int[numActiveNodes+1];
325 
326  CHK_ERR( fei->getNodalSolution(numActiveNodes, localNodes,
327  offsets, soln) );
328  delete [] offsets;
329  delete [] soln;
330  delete [] localNodes;
331 
332  CHK_ERR( fei->resetInitialGuess() );
333 
334  int fieldSize = 0;
335  CHK_ERR( fei->getFieldSize(testdata->fieldIDs[0], fieldSize) );
336 
337  double initTime, loadTime, solveTime, solnReturnTime;
338  CHK_ERR( fei->cumulative_cpu_times(initTime, loadTime, solveTime,
339  solnReturnTime) );
340 
341  return(0);
342 }
343 
344 int test_FEI_Impl::test3()
345 {
346  return(0);
347 }
348 
349 int test_FEI_Impl::test4()
350 {
351  return(0);
352 }