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