FEI Version of the Day
fei_BlockDescriptor.cpp
00001 /*
00002 // @HEADER
00003 // ************************************************************************
00004 //             FEI: Finite Element Interface to Linear Solvers
00005 //                  Copyright (2005) Sandia Corporation.
00006 //
00007 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, the
00008 // U.S. Government retains certain rights in this software.
00009 //
00010 // Redistribution and use in source and binary forms, with or without
00011 // modification, are permitted provided that the following conditions are
00012 // met:
00013 //
00014 // 1. Redistributions of source code must retain the above copyright
00015 // notice, this list of conditions and the following disclaimer.
00016 //
00017 // 2. Redistributions in binary form must reproduce the above copyright
00018 // notice, this list of conditions and the following disclaimer in the
00019 // documentation and/or other materials provided with the distribution.
00020 //
00021 // 3. Neither the name of the Corporation nor the names of the
00022 // contributors may be used to endorse or promote products derived from
00023 // this software without specific prior written permission.
00024 //
00025 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
00026 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00027 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00028 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
00029 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00030 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00031 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00032 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00033 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00034 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00035 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00036 //
00037 // Questions? Contact Alan Williams (william@sandia.gov) 
00038 //
00039 // ************************************************************************
00040 // @HEADER
00041 */
00042 
00043 
00044 #include <fei_iostream.hpp>
00045 #include <fei_defs.h>
00046 
00047 #include <fei_BlockDescriptor.hpp>
00048 
00049 //====Constructor===============================================================
00050 BlockDescriptor::BlockDescriptor()
00051  : blockID_(-1),
00052    numNodesPerElement_(0),
00053    numFieldsPerNode_(NULL),
00054    nodalFieldIDs_(NULL),
00055    fieldIDsAllocated_(false),
00056    numDistinctFields_(0),
00057    elemDofFieldIDs_(),
00058    interleaveStrategy_(0),
00059    lumpingStrategy_(0),
00060    numElements_(0),
00061    numElemDOFPerElement_(0),
00062    elemDOFEqnNumbers_(),
00063    numEqnsPerElement_(0),
00064    numBlkEqnsPerElement_(0),
00065    numActiveNodes_(0),
00066    totalNumEqns_(0)
00067 {
00068    //There's nothing else for this constructor to do.
00069 }
00070 
00071 //====Destructor================================================================
00072 BlockDescriptor::~BlockDescriptor() {
00073 
00074    destroyFieldArrays();
00075 
00076    numElemDOFPerElement_ = 0;
00077 }
00078 
00079 //==============================================================================
00080 void BlockDescriptor::destroyFieldArrays() {
00081    if (numNodesPerElement_ == 0) return;
00082 
00083    for(int i=0; i<numNodesPerElement_; i++) {
00084       delete [] nodalFieldIDs_[i];
00085    }
00086 
00087    delete [] nodalFieldIDs_;
00088    nodalFieldIDs_ = NULL;
00089    delete [] numFieldsPerNode_;
00090    numFieldsPerNode_ = NULL;
00091    numNodesPerElement_ = 0;
00092 }
00093 
00094 //==============================================================================
00095 int BlockDescriptor::setNumNodesPerElement(int numNodes)
00096 {
00097   if (numNodes < 1) {
00098     return(-1);
00099   }
00100 
00101   destroyFieldArrays();
00102 
00103   numNodesPerElement_ = numNodes;
00104 
00105   numFieldsPerNode_ = new int[numNodesPerElement_];
00106 
00107   for(int i=0; i<numNodesPerElement_; i++) {
00108     numFieldsPerNode_[i] = 0;
00109   }
00110   return(0);
00111 }
00112 
00113 //==============================================================================
00114 int* BlockDescriptor::fieldsPerNodePtr() {
00115 
00116    return(numFieldsPerNode_);
00117 }
00118 
00119 //==============================================================================
00120 int BlockDescriptor::allocateFieldIDsTable()
00121 {
00122   nodalFieldIDs_ = new int*[numNodesPerElement_];
00123   bool rowsAllZeroLength = true;
00124 
00125   for(int i=0; i<numNodesPerElement_; i++) {
00126     if (numFieldsPerNode_[i] > 0) {
00127       nodalFieldIDs_[i] = new int[numFieldsPerNode_[i]];
00128       rowsAllZeroLength = false;
00129     }
00130     else nodalFieldIDs_[i] = NULL;
00131   }
00132 
00133   if (rowsAllZeroLength || numNodesPerElement_ == 0) {
00134     fei::console_out() << "BlockDescriptor::allocateFieldIDsTable: ERROR, all rows of"
00135    << " fieldIDs table have zero length. Set fieldsPerNode entries"
00136    << " first." << FEI_ENDL;
00137     return(-1);
00138   }
00139 
00140   fieldIDsAllocated_ = true;
00141   return(0);
00142 }
00143 
00144 //==============================================================================
00145 bool BlockDescriptor::containsField(int fieldID) {
00146 //
00147 //This function will mostly be called by the BASE_FEI function for
00148 //getting solutions to return to the user.
00149 //
00150 //For cases where each of the nodes in an element have the same fields,
00151 //this function will be quite fast.
00152 //
00153 //It will be slow for cases where there are quite a few nodes per element
00154 //and the different nodes have different solution fields. (i.e., the search
00155 //below has to step through most of the fieldIDs table before finding the
00156 //fieldID in question.
00157 //
00158 //In general though, this function won't be called if the fieldID isn't
00159 //associated with ANY node in this block, because the calling code can first
00160 //query the node to find out if IT is associated with this block. And if the
00161 //node is associated with this block, then the node's fields usually will be
00162 //also, unless the node lies on a block boundary and 'fieldID' is only in
00163 //the other block.
00164 //
00165    for(int i=0; i<numNodesPerElement_; i++) {
00166       for(int j=0; j<numFieldsPerNode_[i]; j++) {
00167          if (nodalFieldIDs_[i][j] == fieldID) return(true);
00168       }
00169    }
00170 
00171    return(false);
00172 }
00173 
00174 //==============================================================================
00175 int BlockDescriptor::setElemDofFieldIDs(int numFields, const int* fieldIDs)
00176 {
00177    if (numFields <= 0) {
00178       elemDOFEqnNumbers_.resize(0);
00179       return(0);
00180    }
00181 
00182    for(int i=0; i<numFields; i++) elemDofFieldIDs_.push_back(fieldIDs[i]);
00183 
00184    elemDOFEqnNumbers_.resize(numElements_);
00185 
00186    for(int j=0; j<numElements_; j++) {
00187       elemDOFEqnNumbers_[j] = -1;
00188    }
00189 
00190    return(0);
00191 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends