12 #include <fei_macros.hpp>
16 class ElemContribution {
19 ElemContribution(
const ElemContribution& src)
21 rhsContributions = src.rhsContributions;
26 bool operator==(
const ElemContribution& rhs)
28 if (matrixContributions != rhs.matrixContributions) {
29 cout <<
"matrixContributions don't match." << endl;
33 if ( rhsContributions != rhs.rhsContributions ) {
34 cout <<
"rhsContributions don't match." << endl;
41 bool operator!=(
const ElemContribution& rhs)
43 return( !( *
this == rhs) );
46 std::vector<double> matrixContributions;
47 std::vector<double> rhsContributions;
55 for(
int i=0; i<elemIDs.length(); i++)
delete elemIDs[i];
58 std::vector<int> elemBlockIDs;
59 std::vector<std::vector<int>*> elemIDs;
60 std::vector<std::vector<ElemContribution>*> elemContributions;
62 bool operator==(
const InputData& rhs)
64 if (elemBlockIDs != rhs.elemBlockIDs) {
65 cout <<
"elemBlockIDs don't match." << endl;
69 for(
int i=0; i<elemIDs.length(); i++) {
70 std::vector<ElemContribution>& elems = *(elemContributions[i]);
71 std::vector<ElemContribution>& rhsElems = *(rhs.elemContributions[i]);
73 for(
int j=0; j<elemIDs[i]->length(); j++) {
74 int id1 = (*(elemIDs[i]))[j];
75 int id2 = (*(rhs.elemIDs[i]))[j];
78 cout <<
"elemIDs don't match. element-block " << elemBlockIDs[i]
79 <<
", elemID in position " << j <<
" is " << id1
80 <<
", doesn't match " << id2 <<
"." << endl;
84 if (elems[j] != rhsElems[j]) {
85 cout <<
"element-block " << elemBlockIDs[i] <<
", elemID " << id1
86 <<
"'s element-contributions don't match." << endl;
95 bool operator!=(
const InputData& rhs)
97 return( !( (*
this) == rhs) );
100 int addElemID(
int elemBlockID,
int elemID)
105 int err, insertPoint = -1;
106 int blkInd = elemBlockIDs.binarySearch(elemBlockID, insertPoint);
108 err = elemBlockIDs.insert(elemBlockIDs.begin()+insertPoint, elemBlockID);
109 err += elemIDs.insert(elemIDs.begin()+insertPoint,
new std::vector<int>);
110 err += elemContributions.insert(elemContributions.begin()+insertPoint,
new std::vector<ElemContribution>);
111 if (err != 0)
return(err);
112 blkInd = insertPoint;
115 std::vector<int>& IDs = *(elemIDs[blkInd]);
116 std::vector<ElemContribution>& ec = *(elemContributions[blkInd]);
118 err = IDs.insertSorted(elemID);
119 if (err == -2)
return(err);
121 ElemContribution dummy;
122 if (err >= 0) err = ec.insert(ec.begin()+err, dummy);
123 if (err == -2)
return(err);
128 int addElemMatrix(
int elemBlockID,
int elemID, std::vector<double>& matrixData)
130 int insertPoint = -1;
131 int blkInd = elemBlockIDs.binarySearch(elemBlockID, insertPoint);
133 cerr <<
" addElemMatrix ERROR, elemBlockID " << (int)elemBlockID
134 <<
" not found" << endl;
138 int elemIdx = elemIDs[blkInd]->binarySearch(elemID);
140 cerr <<
"addElemMatrix ERROR, elemID " << (int)elemID <<
" not found."
145 ElemContribution& elemContr = (*(elemContributions[blkInd]))[elemIdx];
147 std::vector<double>& elemContrMatrix = elemContr.matrixContributions;
148 int len = matrixData.length();
149 int oldLen = elemContrMatrix.length();
151 elemContrMatrix.resize(len);
152 for(
int i=oldLen; i<len; i++) elemContrMatrix[i] = 0.0;
155 for(
int i=0; i<matrixData.length(); i++) {
156 elemContrMatrix[i] += matrixData[i];
162 int addElemRHS(
int elemBlockID,
int elemID, std::vector<double>& rhsData)
164 int insertPoint = -1;
165 int blkInd = elemBlockIDs.binarySearch(elemBlockID, insertPoint);
167 cerr <<
" addElemRHS ERROR, elemBlockID " << (int)elemBlockID
168 <<
" not found" << endl;
172 int elemIdx = elemIDs[blkInd]->binarySearch(elemID);
174 cerr <<
"addElemRHS ERROR, elemID " << (int)elemID <<
" not found."<<endl;
178 ElemContribution& elemContr = (*(elemContributions[blkInd]))[elemIdx];
180 std::vector<double>& elemContrRHS = elemContr.rhsContributions;
181 int len = rhsData.length();
182 int oldLen = elemContrRHS.length();
184 elemContrRHS.resize(len);
185 for(
int i=oldLen; i<len; i++) elemContrRHS[i] = 0.0;
188 for(
int i=0; i<rhsData.length(); i++) {
189 elemContrRHS[i] += rhsData[i];
196 #endif // _InputData_h_