9 #include "fei_sstream.hpp"
11 #include "fei_CommUtils.hpp"
12 #include "fei_TemplateUtils.hpp"
15 #include "fei_NodeDescriptor.hpp"
16 #include "fei_NodeDatabase.hpp"
17 #include "fei_BlockDescriptor.hpp"
18 #include "SNL_FEI_Structure.hpp"
19 #include "snl_fei_Utils.hpp"
20 #include "fei_Filter.hpp"
26 #define fei_file "fei_Filter.cpp"
28 #include "fei_ErrMacros.hpp"
32 : problemStructure_(probStruct),
34 logInputStream_(NULL),
44 void Filter::setLogStream(FEI_OSTREAM* logstrm)
46 logInputStream_ = logstrm;
50 FEI_OSTREAM* Filter::logStream()
52 return( logInputStream_ );
56 void Filter::copyStiffness(
const double*
const* elemStiff,
57 int numRows,
int elemFormat,
65 const double* elStiff_i = NULL;
70 for (i = 0; i < numRows; i++) {
71 elStiff_i = elemStiff[i];
72 for (j = 0; j < numRows; j++) {
73 copy[i][j] = elStiff_i[j];
78 case FEI_UPPER_SYMM_ROW:
79 for (i = 0; i < numRows; i++) {
80 elStiff_i = elemStiff[i];
82 for (j = i; j < numRows; j++) {
83 copy[i][j] = elStiff_i[jcol++];
84 copy[j][i] = copy[i][j];
89 case FEI_LOWER_SYMM_ROW:
90 for (i = 0; i < numRows; i++) {
91 elStiff_i = elemStiff[i];
92 for (j = 0; j <=i; j++) {
93 copy[i][j] = elStiff_i[j];
94 copy[j][i] = copy[i][j];
100 for (i = 0; i < numRows; i++) {
101 elStiff_i = elemStiff[i];
102 for (j = 0; j < numRows; j++) {
103 copy[j][i] = elStiff_i[j];
108 case FEI_UPPER_SYMM_COL:
109 for (i = 0; i < numRows; i++) {
110 elStiff_i = elemStiff[i];
111 for (j = 0; j <= i; j++) {
112 copy[i][j] = elStiff_i[j];
113 copy[j][i] = copy[i][j];
118 case FEI_LOWER_SYMM_COL:
119 for (i = 0; i < numRows; i++) {
120 elStiff_i = elemStiff[i];
122 for (j = i; j < numRows; j++) {
123 copy[i][j] = elStiff_i[jcol++];
124 copy[j][i] = copy[i][j];
130 throw std::runtime_error(
"copyStiffness ERROR, unrecognized elem-format");
140 problemStructure_->getNodeDatabase().
getNodeWithID(nodeID, node);
145 const NodeDescriptor& Filter::findNodeDescriptor(GlobalID nodeID)
const {
150 int err = problemStructure_->getNodeDatabase().
getNodeWithID(nodeID, node);
153 fei::console_out() <<
"ERROR, Filter::findNodeDescriptor unable to find node "
154 <<
static_cast<int>(nodeID) << FEI_ENDL;
161 int Filter::calculateResidualNorms(
int whichNorm,
int numFields,
162 int* fieldIDs,
double* norms,
163 std::vector<double>& residValues)
165 std::vector<double> normsArray(numFields, 0.0);
167 std::fill(fieldIDs, fieldIDs+numFields, -999);
169 std::vector<double> tmpNorms(numFields);
170 double* tmpNormsPtr = &tmpNorms[0];
172 double* residPtr = &(residValues[0]);
174 const std::vector<int>& pfieldIDs = problemStructure_->getFieldIDs();
175 int numDBFields = pfieldIDs.size();
176 std::vector<int>::const_iterator
177 f_iter = pfieldIDs.begin(),
178 f_end = pfieldIDs.end();
183 for(; f_iter != f_end; ++f_iter) {
185 if (offset == 0) DBFieldSize = problemStructure_->
getFieldSize(*f_iter);
188 if (offset < numFields) {
189 fieldIDs[offset] = *f_iter;
190 tmpNormsPtr[offset++] = 0.0;
195 int reducedStartRow = problemStructure_->getFirstReducedEqn();
196 int reducedEndRow = problemStructure_->getLastReducedEqn();
198 NodeDatabase& nodeDB = problemStructure_->getNodeDatabase();
201 bool haveSlaves = problemStructure_->numSlaveEquations() > 0;
203 for(
int i=0; i<numNodes; i++) {
207 if (node==NULL || node->getOwnerProc() != localRank_)
continue;
209 const int* fieldIDList = node->getFieldIDList();
210 const int* fieldEqnNums = node->getFieldEqnNumbers();
211 int numNodeFields = node->getNumFields();
213 for(
int j=0; j<numNodeFields; j++) {
215 int fSize = DBFieldSize;
217 if (numDBFields > 1) {
219 if (fIndex < 0)
return(-1);
220 fSize = problemStructure_->
getFieldSize(fieldIDList[j]);
221 if (fSize < 0)
return(-1);
224 for(
int k=0; k<fSize; k++) {
225 int eqn = fieldEqnNums[j]+k;
228 if (problemStructure_->
isSlaveEqn(eqn))
continue;
232 if (reducedEqn < reducedStartRow || reducedEqn > reducedEndRow) {
238 double rval = residPtr[eqn - reducedStartRow];
242 if (tmpNormsPtr[fIndex] < std::abs(rval)) tmpNormsPtr[fIndex] = rval;
245 tmpNormsPtr[fIndex] += std::abs(rval);
248 tmpNormsPtr[fIndex] += rval*rval;
251 FEI_COUT <<
"Filter::residualNorm: ERROR, whichNorm="<<whichNorm
252 <<
" not recognized." << FEI_ENDL;
262 MPI_Comm comm = problemStructure_->getCommunicator();
264 if (whichNorm != 0) {
271 for(
int i=0; i<numFields; ++i) {
272 norms[i] = normsArray[i];
275 if (whichNorm == 2) {
276 for(
int i=0; i<numFields; ++i) norms[i] = std::sqrt(norms[i]);
283 int Filter::parameters(
int numParams,
const char *
const* paramStrings)
285 if (numParams == 0 || paramStrings == NULL)
return(0);
287 const char* param = snl_fei::getParam(
"outputLevel",numParams,paramStrings);
290 std::string str(&(param[11]));
291 FEI_ISTRINGSTREAM isstr(str);
292 isstr >> outputLevel_;
int GlobalSum(MPI_Comm comm, std::vector< T > &local, std::vector< T > &global)
int getFieldSize(int fieldID)
Filter(SNL_FEI_Structure *probStruct)
int binarySearch(const T &item, const T *list, int len)
void getNodeAtIndex(int i, const NodeDescriptor *&node) const
bool translateToReducedEqn(int eqn, int &reducedEqn)
std::ostream & console_out()
int GlobalMax(MPI_Comm comm, std::vector< T > &local, std::vector< T > &global)
int getNumNodeDescriptors() const
int getNodeWithID(GlobalID nodeID, const NodeDescriptor *&node) const