FEI Version of the Day
fei_NodeDescriptor.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 <string>
00010 #include <fei_macros.hpp>
00011 #include <fei_defs.h>
00012 
00013 #include <fei_NodeDescriptor.hpp>
00014 
00015 //======Constructor=============================================================
00016 NodeDescriptor::NodeDescriptor()
00017  : nodeID_((GlobalID)-1),
00018    nodeNumber_(-1),
00019    numNodalDOF_(0),
00020    fieldIDList_(NULL),
00021    fieldEqnNumbers_(NULL),
00022    numFields_(0),
00023    blkEqnNumber_(0),
00024    ownerProc_(-1),
00025    blockList_(NULL),
00026    numBlocks_(0)
00027 {
00028    //There's nothing for this constructor to do, apart from the
00029    //above initializations.
00030 }
00031 
00032 //======Destructor==============================================================
00033 NodeDescriptor::~NodeDescriptor() {
00034   delete [] fieldIDList_;
00035   delete [] fieldEqnNumbers_;
00036   numFields_ = 0;
00037 
00038   delete [] blockList_;
00039   numBlocks_ = 0;
00040 }
00041 
00042 //==============================================================================
00043 void NodeDescriptor::addField(int fieldID) {
00044 //
00045 //Add a field identifier to this node, ONLY if that field identifier
00046 //is not already present.
00047 //
00048 //If fieldID is added, lengthen the corresponding list for equation numbers.
00049 //
00050 
00051    int tmp = numFields_;
00052    int allocLen = numFields_;
00053    int index = fei::sortedListInsert(fieldID, fieldIDList_, numFields_,
00054                                          allocLen);
00055 
00056    //index is the position at which fieldID was inserted, or found
00057 
00058    //if tmp < numFields_ then fieldID wasn't already present
00059    if (tmp < numFields_) {
00060       //
00061       //if the length of fieldIDList_ changed, let's lengthen the 
00062       //fieldEqnNumbers_ list.
00063       //fieldEqnNumbers_ will have an empty position 'index', which we'll set to
00064       //-99 for now. The calling code (BASE_FEI) will set the fieldEqnNumber for
00065       //this fieldID using setFieldEqnNumber(...).
00066       //
00067 
00068       allocLen = numFields_ - 1;
00069       fei::listInsert(-99, index, fieldEqnNumbers_, tmp, allocLen);
00070    }
00071 }
00072 
00073 //==============================================================================
00074 void NodeDescriptor::setFieldEqnNumber(int fieldID, int eqn) {
00075 //
00076 //Set the equation number corresponding to fieldID. fieldID must
00077 //already have been added to this node using the addField function.
00078 //If it was already added, then the fieldEqnNumbers_ list was lengthened
00079 //appropriately, with an empty spot left for this eqn number.
00080 //
00081    int insert = -1;
00082    int index = fei::binarySearch(fieldID, fieldIDList_,
00083               numFields_, insert);
00084 
00085    if (index < 0) {
00086       return;
00087    }
00088 
00089    fieldEqnNumbers_[index] = eqn;
00090 }
00091 
00092 //==============================================================================
00093 bool NodeDescriptor::getFieldEqnNumber(int fieldID, int& eqnNumber) const
00094 {
00095    int insert = -1;
00096    int index = fei::binarySearch(fieldID, fieldIDList_,
00097               numFields_, insert);
00098 
00099    if (index < 0) {
00100       return(false);
00101    }
00102 
00103    eqnNumber = fieldEqnNumbers_[index];
00104    return(true);
00105 }
00106 
00107 //==============================================================================
00108 void NodeDescriptor::getFieldID(int eqnNumber, int& fieldID, int& offset_into_field) const
00109 {
00110   if (numFields_ < 1) {
00111     throw std::runtime_error("fei::NodeDescriptor::getFieldID ERROR, no nodal dofs on this node.");
00112   }
00113 
00114   int firstNodalEqn = fieldEqnNumbers_[0];
00115   if (eqnNumber - firstNodalEqn > numNodalDOF_) {
00116     throw std::runtime_error("fei::NodeDescriptor::getFieldID ERROR, eqnNumber out of range.");
00117   }
00118 
00119   bool found_field = false;
00120   for(int i=numFields_-1; i>=0; --i) {
00121     if (fieldEqnNumbers_[i] <= eqnNumber) {
00122       fieldID = fieldIDList_[i];
00123       offset_into_field = eqnNumber - fieldEqnNumbers_[i];
00124       found_field = true;
00125       break;
00126     }
00127   }
00128 
00129   if (!found_field) {
00130     throw std::runtime_error("fei::NodeDescriptor::getFieldID ERROR, fieldID not found for eqnNumber.");
00131   }
00132 }
00133 
00134 //==============================================================================
00135 bool NodeDescriptor::containedInBlock(GlobalID blk) const
00136 {
00137   //return true if this node is contained in element-block 'blk'.
00138 
00139    int insert;
00140    int index = fei::binarySearch(blk, blockList_, numBlocks_, insert);
00141    if (index >= 0) return(true);
00142    else return(false);
00143 }
00144 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends