fei_BlockDescriptor.cpp

00001 /*--------------------------------------------------------------------*/
00002 /*    Copyright 2005 Sandia Corporation.                              */
00003 /*    Under the terms of Contract DE-AC04-94AL85000, there is a       */
00004 /*    non-exclusive license for use of this work by or on behalf      */
00005 /*    of the U.S. Government.  Export of this program may require     */
00006 /*    a license from the United States Government.                    */
00007 /*--------------------------------------------------------------------*/
00008 
00009 #include <fei_iostream.hpp>
00010 #include <fei_defs.h>
00011 
00012 #include <fei_BlockDescriptor.hpp>
00013 
00014 //====Constructor===============================================================
00015 BlockDescriptor::BlockDescriptor()
00016  : blockID_(-1),
00017    numNodesPerElement_(0),
00018    numFieldsPerNode_(NULL),
00019    nodalFieldIDs_(NULL),
00020    fieldIDsAllocated_(false),
00021    numDistinctFields_(0),
00022    elemDofFieldIDs_(),
00023    interleaveStrategy_(0),
00024    lumpingStrategy_(0),
00025    numElements_(0),
00026    numElemDOFPerElement_(0),
00027    elemDOFEqnNumbers_(),
00028    numEqnsPerElement_(0),
00029    numBlkEqnsPerElement_(0),
00030    numActiveNodes_(0),
00031    totalNumEqns_(0)
00032 {
00033    //There's nothing else for this constructor to do.
00034 }
00035 
00036 //====Destructor================================================================
00037 BlockDescriptor::~BlockDescriptor() {
00038 
00039    destroyFieldArrays();
00040 
00041    numElemDOFPerElement_ = 0;
00042 }
00043 
00044 //==============================================================================
00045 void BlockDescriptor::destroyFieldArrays() {
00046    if (numNodesPerElement_ == 0) return;
00047 
00048    for(int i=0; i<numNodesPerElement_; i++) {
00049       delete [] nodalFieldIDs_[i];
00050    }
00051 
00052    delete [] nodalFieldIDs_;
00053    nodalFieldIDs_ = NULL;
00054    delete [] numFieldsPerNode_;
00055    numFieldsPerNode_ = NULL;
00056    numNodesPerElement_ = 0;
00057 }
00058 
00059 //==============================================================================
00060 int BlockDescriptor::setNumNodesPerElement(int numNodes)
00061 {
00062   if (numNodes < 1) {
00063     return(-1);
00064   }
00065 
00066   destroyFieldArrays();
00067 
00068   numNodesPerElement_ = numNodes;
00069 
00070   numFieldsPerNode_ = new int[numNodesPerElement_];
00071 
00072   for(int i=0; i<numNodesPerElement_; i++) {
00073     numFieldsPerNode_[i] = 0;
00074   }
00075   return(0);
00076 }
00077 
00078 //==============================================================================
00079 int* BlockDescriptor::fieldsPerNodePtr() {
00080 
00081    return(numFieldsPerNode_);
00082 }
00083 
00084 //==============================================================================
00085 int BlockDescriptor::allocateFieldIDsTable()
00086 {
00087   nodalFieldIDs_ = new int*[numNodesPerElement_];
00088   bool rowsAllZeroLength = true;
00089 
00090   for(int i=0; i<numNodesPerElement_; i++) {
00091     if (numFieldsPerNode_[i] > 0) {
00092       nodalFieldIDs_[i] = new int[numFieldsPerNode_[i]];
00093       rowsAllZeroLength = false;
00094     }
00095     else nodalFieldIDs_[i] = NULL;
00096   }
00097 
00098   if (rowsAllZeroLength || numNodesPerElement_ == 0) {
00099     FEI_CERR << "BlockDescriptor::allocateFieldIDsTable: ERROR, all rows of"
00100    << " fieldIDs table have zero length. Set fieldsPerNode entries"
00101    << " first." << FEI_ENDL;
00102     return(-1);
00103   }
00104 
00105   fieldIDsAllocated_ = true;
00106   return(0);
00107 }
00108 
00109 //==============================================================================
00110 bool BlockDescriptor::containsField(int fieldID) {
00111 //
00112 //This function will mostly be called by the BASE_FEI function for
00113 //getting solutions to return to the user.
00114 //
00115 //For cases where each of the nodes in an element have the same fields,
00116 //this function will be quite fast.
00117 //
00118 //It will be slow for cases where there are quite a few nodes per element
00119 //and the different nodes have different solution fields. (i.e., the search
00120 //below has to step through most of the fieldIDs table before finding the
00121 //fieldID in question.
00122 //
00123 //In general though, this function won't be called if the fieldID isn't
00124 //associated with ANY node in this block, because the calling code can first
00125 //query the node to find out if IT is associated with this block. And if the
00126 //node is associated with this block, then the node's fields usually will be
00127 //also, unless the node lies on a block boundary and 'fieldID' is only in
00128 //the other block.
00129 //
00130    for(int i=0; i<numNodesPerElement_; i++) {
00131       for(int j=0; j<numFieldsPerNode_[i]; j++) {
00132          if (nodalFieldIDs_[i][j] == fieldID) return(true);
00133       }
00134    }
00135 
00136    return(false);
00137 }
00138 
00139 //==============================================================================
00140 int BlockDescriptor::setElemDofFieldIDs(int numFields, const int* fieldIDs)
00141 {
00142    if (numFields <= 0) {
00143       elemDOFEqnNumbers_.resize(0);
00144       return(0);
00145    }
00146 
00147    for(int i=0; i<numFields; i++) elemDofFieldIDs_.push_back(fieldIDs[i]);
00148 
00149    elemDOFEqnNumbers_.resize(numElements_);
00150 
00151    for(int j=0; j<numElements_; j++) {
00152       elemDOFEqnNumbers_[j] = -1;
00153    }
00154 
00155    return(0);
00156 }

Generated on Tue Jul 13 09:27:44 2010 for FEI by  doxygen 1.4.7