FEI  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
test_SNL_FEI_Structure.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_mpi.h>
12 
13 #include <test_utils/test_SNL_FEI_Structure.hpp>
14 
15 #include <SNL_FEI_Structure.hpp>
16 
17 #include <test_utils/testData.hpp>
18 
19 #undef fei_file
20 #define fei_file "test_SNL_FEI_Structure.cpp"
21 #include <fei_ErrMacros.hpp>
22 
23 test_SNL_FEI_Structure::test_SNL_FEI_Structure(MPI_Comm comm)
24  : tester(comm)
25 {
26 }
27 
28 test_SNL_FEI_Structure::~test_SNL_FEI_Structure()
29 {
30 }
31 
32 int test_SNL_FEI_Structure::runtests()
33 {
34  CHK_ERR( test1() );
35  CHK_ERR( test2() );
36  CHK_ERR( test3() );
37  CHK_ERR( test4() );
38  return(0);
39 }
40 
41 int test_SNL_FEI_Structure::test1()
42 {
43  testData* testdata = new testData(localProc_, numProcs_);
44 
45  SNL_FEI_Structure structure(comm_);
46 
47  CHK_ERR( structure.initFields(testdata->fieldIDs.size(),
48  &(testdata->fieldSizes[0]),
49  &(testdata->fieldIDs[0])) );
50 
51  int numNodesPerElem = testdata->ids.size();
52  std::vector<int> numFieldsPerNode(numNodesPerElem, 1);
53  std::vector<int*>nodalFieldIDs(numNodesPerElem, &(testdata->fieldIDs[0]));
54 
55  CHK_ERR( structure.initElemBlock(0, //blockID
56  1, //numElements
57  numNodesPerElem,
58  &numFieldsPerNode[0],
59  &nodalFieldIDs[0],
60  0, //numElemDofFieldsPerElement
61  NULL, //elemDofFieldIDs
62  0)); //interleaveStrategy
63 
64  CHK_ERR( structure.initElem(0, //blockID
65  0, //elemID
66  &(testdata->ids[0])) );
67 
68  std::vector<int*> sharingProcs2D(testdata->sharedIDs.size());
69  int i, offset = 0;
70  for(i=0; i<(int)testdata->numSharingProcsPerID.size(); ++i) {
71  sharingProcs2D[i] = &(testdata->sharingProcs[offset]);
72  offset += testdata->numSharingProcsPerID[i];
73  }
74 
75  if (testdata->sharedIDs.size() > 0) {
76  CHK_ERR( structure.initSharedNodes(testdata->sharedIDs.size(),
77  testdata->sharedIDs.size() ? &(testdata->sharedIDs[0]) : 0,
78  testdata->numSharingProcsPerID.size() ? &(testdata->numSharingProcsPerID[0]) : 0,
79  &sharingProcs2D[0]) );
80  }
81 
82  CHK_ERR( structure.initComplete() );
83 
84  int numActiveNodes = structure.getNumActiveNodes();
85  if (numActiveNodes != (int)testdata->ids.size()) {
86  ERReturn(-1);
87  }
88 
89  int fieldSize = structure.getFieldSize(testdata->fieldIDs[0]);
90 
91  int numLocalEqns = fieldSize*2;
92  if (localProc_ == 0) numLocalEqns += 2;
93  int checkNumLocalEqns = structure.getNumLocalEqns();
94  if (numLocalEqns != checkNumLocalEqns) {
95  ERReturn(-1);
96  }
97 
98  int numGlobalEqns = fieldSize*(numProcs_*2 + 2);
99  int checkNumGlobalEqns = structure.getNumGlobalEqns();
100  if (checkNumGlobalEqns != numGlobalEqns) {
101  ERReturn(-1);
102  }
103 
104  std::vector<int> rowLengths;
105  CHK_ERR( structure.getMatrixRowLengths(rowLengths) );
106 
107  int numNonzeros = 0;
108  for(size_t j=0; j<rowLengths.size(); ++j) {
109  numNonzeros += rowLengths[j];
110  }
111 
112  std::vector<int> colIndices_1d(numNonzeros);
113  std::vector<int*> colIndPtrs(rowLengths.size());
114 
115  offset = 0;
116  for(size_t j=0; j<rowLengths.size(); ++j) {
117  colIndPtrs[j] = &(colIndices_1d[offset]);
118  offset += rowLengths[j];
119  }
120 
121  CHK_ERR( structure.getMatrixStructure(&colIndPtrs[0],
122  rowLengths) );
123 
124  delete testdata;
125 
126  return(0);
127 }
128 
129 int test_SNL_FEI_Structure::test2()
130 {
131  testData* testdata = new testData(localProc_, numProcs_);
132 
133  SNL_FEI_Structure structure(comm_);
134 
135  CHK_ERR( structure.initFields(testdata->fieldIDs.size(),
136  &(testdata->fieldSizes[0]),
137  &(testdata->fieldIDs[0])) );
138 
139  int numNodesPerElem = testdata->ids.size();
140  std::vector<int> numFieldsPerNode(numNodesPerElem, testdata->fieldIDs.size());
141  std::vector<int*>nodalFieldIDs(numNodesPerElem, &(testdata->fieldIDs[0]));
142  std::vector<int> elemDofFieldIDs = testdata->fieldIDs;
143 
144  CHK_ERR( structure.initElemBlock(0, //blockID
145  1, //numElements
146  numNodesPerElem,
147  &numFieldsPerNode[0],
148  &nodalFieldIDs[0],
149  elemDofFieldIDs.size(),
150  &elemDofFieldIDs[0],
151  0)); //interleaveStrategy
152 
153  CHK_ERR( structure.initElem(0, //blockID
154  0, //elemID
155  &(testdata->ids[0])) );
156 
157  std::vector<int*> sharingProcs2D(testdata->sharedIDs.size());
158  int i, offset = 0;
159  for(i=0; i<(int)testdata->numSharingProcsPerID.size(); ++i) {
160  sharingProcs2D[i] = &(testdata->sharingProcs[offset]);
161  offset += testdata->numSharingProcsPerID[i];
162  }
163 
164  if (testdata->sharedIDs.size() > 0) {
165  CHK_ERR( structure.initSharedNodes(testdata->sharedIDs.size(),
166  testdata->sharedIDs.size() ? &(testdata->sharedIDs[0]) : 0,
167  testdata->numSharingProcsPerID.size() ? &(testdata->numSharingProcsPerID[0]) : 0,
168  &sharingProcs2D[0]) );
169  }
170 
171  CHK_ERR( structure.initComplete() );
172 
173  int numActiveNodes = structure.getNumActiveNodes();
174  if (numActiveNodes != (int)testdata->ids.size()) {
175  ERReturn(-1);
176  }
177 
178  int numEqnsPerNode = 0;
179  for(i=0; i<(int)testdata->fieldSizes.size(); ++i) {
180  numEqnsPerNode += testdata->fieldSizes[i];
181  }
182 
183  int numLocalEqns = 3*numEqnsPerNode;//2 nodes + elem-dofs
184 
185  if (localProc_ == 0) numLocalEqns += 2*numEqnsPerNode;
186  int checkNumLocalEqns = structure.getNumLocalEqns();
187  if (numLocalEqns != checkNumLocalEqns) {
188  ERReturn(-1);
189  }
190 
191  int numGlobalEqns = (numProcs_*3+2)*numEqnsPerNode;
192  int checkNumGlobalEqns = structure.getNumGlobalEqns();
193  if (checkNumGlobalEqns != numGlobalEqns) {
194  ERReturn(-1);
195  }
196 
197  std::vector<int> rowLengths;
198  CHK_ERR( structure.getMatrixRowLengths(rowLengths) );
199 
200  int numNonzeros = 0;
201  for(size_t j=0; j<rowLengths.size(); ++j) {
202  numNonzeros += rowLengths[j];
203  }
204 
205  std::vector<int> colIndices_1d(numNonzeros);
206  std::vector<int*> colIndPtrs(rowLengths.size());
207 
208  offset = 0;
209  for(size_t j=0; j<rowLengths.size(); ++j) {
210  colIndPtrs[j] = &(colIndices_1d[offset]);
211  offset += rowLengths[j];
212  }
213 
214  CHK_ERR( structure.getMatrixStructure(&colIndPtrs[0],
215  rowLengths) );
216 
217  delete testdata;
218 
219  return(0);
220 }
221 
222 int test_SNL_FEI_Structure::test3()
223 {
224  return(0);
225 }
226 
227 int test_SNL_FEI_Structure::test4()
228 {
229  return(0);
230 }