FEI  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
snl_fei_Broker_FEData.hpp
1 /*--------------------------------------------------------------------*/
2 /* Copyright 2005 Sandia Corporation. */
3 /* Under the terms of Contract DE-AC04-94AL85000, there is a */
4 /* non-exclusive license for use of this work by or on behalf */
5 /* of the U.S. Government. Export of this program may require */
6 /* a license from the United States Government. */
7 /*--------------------------------------------------------------------*/
8 
9 #ifndef _snl_fei_Broker_FEData_hpp_
10 #define _snl_fei_Broker_FEData_hpp_
11 
12 #include <fei_macros.hpp>
13 #include <fei_mpi.h>
14 #include <snl_fei_Broker.hpp>
15 #include <fei_FiniteElementData.hpp>
16 #include <fei_VectorSpace.hpp>
17 #include <fei_MatrixGraph.hpp>
18 #include <fei_Matrix_Impl.hpp>
19 #include <fei_Pattern.hpp>
20 #include <fei_Vector_Impl.hpp>
21 #include <fei_ConnectivityBlock.hpp>
22 #include <snl_fei_LinearSystem_FEData.hpp>
23 #include <fei_Lookup_Impl.hpp>
24 
25 #undef fei_file
26 #define fei_file "snl_fei_Broker_FEData.hpp"
27 #include <fei_ErrMacros.hpp>
28 
29 namespace snl_fei {
30 
34  class Broker_FEData : public snl_fei::Broker {
35  public:
39  int nodeIDType);
40 
42  virtual ~Broker_FEData();
43 
53  virtual fei::SharedPtr<fei::Vector> createVector(bool isSolutionVector=false)
54  {
56  if (matrixGraph_.get() == NULL) return(vptr);
57 
58  if (setStructure() != 0) return(vptr);
59 
60  int localsize = matrixGraph_->getRowSpace()->getNumIndices_Owned();
62  vecptr.reset(new fei::Vector_Impl<FiniteElementData>(matrixGraph_->getRowSpace(),
63  feData_.get(), localsize,
64  isSolutionVector));
65  return(vecptr);
66  }
67 
71  {
73  if (matrixGraph_.get() == NULL) return(mptr);
74 
75  if (setStructure() != 0) return(mptr);
76  int localsize = matrixGraph_->getRowSpace()->getNumIndices_Owned();
77 
78  bool zeroSharedRows = false;
80  matptr.reset(new fei::Matrix_Impl<FiniteElementData>(feData_,
81  matrixGraph_, localsize, zeroSharedRows));
82  return(matptr);
83  }
84 
88  {
90  if (matrixGraph_.get() == NULL) return(lsptr);
91 
92  if (setStructure() != 0) return(lsptr);
93 
95  linsysfed = new LinearSystem_FEData(feData_,
96  matrixGraph_);
97  linsysfed->setLookup(lookup_);
98  fei::SharedPtr<fei::LinearSystem> linsysptr(linsysfed);
99  return(linsysptr);
100  }
101 
104  {
105  matrixGraph_ = matrixGraph;
106  }
107 
108  private:
109  int setStructure()
110  {
111  if (matrixGraph_.get() == NULL) ERReturn(-1);
112  if (setStructure_ == true) return(0);
113 
114  lookup_ = new fei::Lookup_Impl(matrixGraph_, nodeIDType_);
115 
116  CHK_ERR( feData_->setLookup(*lookup_) );
117 
118  fei::SharedPtr<fei::VectorSpace> vspace = matrixGraph_->getRowSpace();
119 
120  int numLocalNodes = vspace->getNumOwnedAndSharedIDs(nodeIDType_);
121 
122  int numElemBlocks = matrixGraph_->getNumConnectivityBlocks();
123 
124  int nodeType = 0;
125  snl_fei::RecordCollection* nodeRecords = NULL;
126  vspace->getRecordCollection(nodeType, nodeRecords);
127 
128  int* intData = new int[numElemBlocks*3];
129  int* numElemsPerBlock = intData;
130  int* numNodesPerElem = intData+numElemBlocks;
131  int* elemMatrixSizePerBlock = intData+2*numElemBlocks;
132  int i;
133 
134  std::vector<int> elemBlockIDs;
135  CHK_ERR( matrixGraph_->getConnectivityBlockIDs( elemBlockIDs) );
136 
137  for(i=0; i<numElemBlocks; ++i) {
138  const fei::ConnectivityBlock* cblock =
139  matrixGraph_->getConnectivityBlock(elemBlockIDs[i]);
140  if (cblock==NULL) return(-1);
141  numElemsPerBlock[i] = cblock->getConnectivityIDs().size();
142  numNodesPerElem[i] = cblock->getRowPattern()->getNumIDs();
143  elemMatrixSizePerBlock[i] = cblock->getRowPattern()->getNumIndices();
144  }
145 
146  int numSharedNodes = 0;
147  CHK_ERR( vspace->getNumSharedIDs(nodeIDType_, numSharedNodes) );
148 
149  int numLagrangeConstraints = matrixGraph_->getLocalNumLagrangeConstraints();
150 
151  CHK_ERR( feData_->describeStructure(numElemBlocks,
152  numElemsPerBlock,
153  numNodesPerElem,
154  elemMatrixSizePerBlock,
155  numLocalNodes,
156  numSharedNodes,
157  numLagrangeConstraints) );
158 
159  std::map<int,fei::ConnectivityBlock*>::const_iterator
160  cdb_iter = matrixGraph_->getConnectivityBlocks().begin();
161 
162  std::vector<int> nodeNumbers, numDofPerNode, dof_ids;
163  int total_num_dof = 0;
164  for(i=0; i<numElemBlocks; ++i, ++cdb_iter) {
165  fei::ConnectivityBlock* cblock = (*cdb_iter).second;
166  fei::Pattern* pattern = cblock->getRowPattern();
167 
168  int numConnectedNodes = pattern->getNumIDs();
169  nodeNumbers.resize(numConnectedNodes);
170  numDofPerNode.resize(numConnectedNodes);
171  int* nodeNumPtr = &nodeNumbers[0];
172  int* numDofPtr = &numDofPerNode[0];
173 
174  //For the calls to FiniteElementData::setConnectivity, we're going to
175  //need a list of num-dof-per-node. So construct that now.
176  const int* numFieldsPerID = pattern->getNumFieldsPerID();
177  const int* fieldIDs = pattern->getFieldIDs();
178 
179  int foffset = 0;
180  for(int ii=0; ii<numConnectedNodes; ++ii) {
181  int dof = 0;
182  for(int f=0; f<numFieldsPerID[ii]; ++f) {
183  dof += vspace->getFieldSize(fieldIDs[foffset++]);
184  }
185  numDofPtr[ii] = dof;
186  total_num_dof += dof;
187  }
188 
189  dof_ids.resize(total_num_dof, 0);
190  int* dof_ids_ptr = &dof_ids[0];
191 
193  //Next we'll loop over the connectivity-lists in this block,
194  //making a call to FiniteElementData::setConnectivity for each one.
195 
196  std::map<int,int>& elemIDs = cblock->getConnectivityIDs();
197  int numElems = elemIDs.size();
198  int* nodes = &(cblock->getRowConnectivities()[0]);
199 
200  int offset = 0;
201  for(int elem=0; elem<numElems; ++elem) {
202  for(int n=0; n<numConnectedNodes; ++n) {
203  fei::Record<int>* node = nodeRecords->getRecordWithLocalID(nodes[offset++]);
204  nodeNumPtr[n] = node->getNumber();
205  }
206 
207  CHK_ERR( feData_->setConnectivity(elemBlockIDs[i], elem,
208  numConnectedNodes,
209  nodeNumPtr, numDofPtr, dof_ids_ptr));
210  }//end for(...numElems...)
211  }//end for(...numElemBlocks...)
212 
213  delete [] intData;
214 
215  setStructure_ = true;
216  return(0);
217  }
218 
221 
222  int nodeIDType_;
223  bool setStructure_;
224  bool setMatrixMatrixGraph_;
225 
226  fei::Lookup_Impl* lookup_;
227  };//class Broker_FEData
228 }//namespace snl_fei
229 
230 
231 #endif // _snl_fei_Broker_FEData_hpp_
GlobalIDType getNumber() const
Definition: fei_Record.hpp:58
const std::map< int, int > & getConnectivityIDs() const
int getNumIndices() const
Definition: fei_Pattern.hpp:92
const int * getNumFieldsPerID() const
Definition: fei_Pattern.hpp:73
virtual fei::SharedPtr< fei::LinearSystem > createLinearSystem()
virtual const fei::ConnectivityBlock * getConnectivityBlock(int blockID) const =0
const int * getFieldIDs() const
Definition: fei_Pattern.hpp:76
virtual std::map< int, fei::ConnectivityBlock * > & getConnectivityBlocks()=0
void reset(T *p=0)
std::vector< int > & getRowConnectivities()
virtual int setConnectivity(int elemBlockID, int elemID, int numNodes, const int *nodeNumbers, const int *numDofPerNode, const int *dof_ids)=0
virtual fei::SharedPtr< fei::VectorSpace > getRowSpace()=0
virtual int setLookup(Lookup &lookup)=0
virtual void setMatrixGraph(fei::SharedPtr< fei::MatrixGraph > matrixGraph)
T * get() const
Broker_FEData(fei::SharedPtr< FiniteElementData > feData, fei::SharedPtr< fei::MatrixGraph > matrixGraph, int nodeIDType)
int getNumIDs() const
Definition: fei_Pattern.hpp:64
virtual fei::SharedPtr< fei::Vector > createVector(bool isSolutionVector=false)
int getNumOwnedAndSharedIDs(int idType)
virtual fei::SharedPtr< fei::Matrix > createMatrix()
virtual int getLocalNumLagrangeConstraints() const =0
virtual int getNumConnectivityBlocks() const =0
virtual int getConnectivityBlockIDs(std::vector< int > &blockIDs) const =0
virtual int describeStructure(int numElemBlocks, const int *numElemsPerBlock, const int *numNodesPerElem, const int *elemMatrixSizePerBlock, int totalNumNodes, int numSharedNodes, int numMultCRs)=0
const fei::Pattern * getRowPattern() const
int getNumIndices_Owned() const