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