MOOSE - Multiscale Object Oriented Simulation Environment
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
LocalDataElement.cpp
Go to the documentation of this file.
1 /**********************************************************************
2 ** This program is part of 'MOOSE', the
3 ** Messaging Object Oriented Simulation Environment.
4 ** Copyright (C) 2003-2009 Upinder S. Bhalla. and NCBS
5 ** It is made available under the terms of the
6 ** GNU Lesser General Public License version 2.1
7 ** See the file COPYING.LIB for the full notice.
8 **********************************************************************/
9 
10 #include "header.h"
11 #include "FuncOrder.h"
12 #include "../shell/Shell.h"
13 
15  const string& name, unsigned int numData )
16  :
17  DataElement( id, c, name, setDataSize( numData ) )
18 {;}
19 
20 
21 /*
22  * Used for copies. Note that it does NOT call the postCreation Func,
23  * so FieldElements are copied rather than created by the Cinfo when
24  * the parent element is created. This allows the copied FieldElements to
25  * retain info from the originals.
26  * n is the number of new entries made.
27  */
29  unsigned int n )
30  :
31  DataElement( id, orig, setDataSize( n ),
32  ( 1 + (n - 1 ) / Shell::numNodes() ) * Shell::myNode() )
33 {;}
34 
35 // Virtual destructor, but the base DataElement does the needful
37 {;}
38 
39 // This is somewhat problematic to do as a low-level function. Will need
40 // to look up all other nodes to get their conent
42  unsigned int n, bool toGlobal ) const
43 {
44  if ( toGlobal ) {
45  cout << "Don't know yet how to copy LocalDataElement to global\n";
46  assert( 0 );
47  return 0;
48  } else {
49  return new LocalDataElement( newId, this, n );
50  }
51 }
52 
53 
55 // LocalDataElement info functions
57 
58 // virtual func.
59 unsigned int LocalDataElement::numData() const
60 {
61  return numData_;
62 }
63 
65 {
66  // return numPerNode_ * Shell::myNode();
67  return localDataStart_;
68 }
69 
70 // localNumData() is inherited from DataElement.
71 
72 unsigned int LocalDataElement::getNode( unsigned int dataId ) const {
73  // Assume numData = 95. DataId = 0-9: 0, DataId=80-89:8, DataId >= 90:9
74  if ( dataId == ALLDATA ) {
75  if ( numLocalData() > 0 ) {
76  return Shell::myNode();
77  } else {
78  return 0; // Sure to have some data on node 0.
79  }
80  }
81  return dataId / numPerNode_;
82 }
83 
85 unsigned int LocalDataElement::startDataIndex( unsigned int node ) const
86 {
87  if ( numPerNode_ * node < numData_ )
88  return numPerNode_ * node;
89  else
90  return numData_; // error.
91 }
92 
93 unsigned int LocalDataElement::rawIndex( unsigned int dataId ) const {
94  return dataId % numPerNode_;
95 }
96 
97 // Utility function for computing the data size.
98 // Returns the number of entries on current node.
99 // As a side effect assigns the total numData_ for all nodes, and the
100 // numPerNode_ helper field.
101 unsigned int LocalDataElement::setDataSize( unsigned int numData )
102 {
103  numData_ = numData;
104  numPerNode_ = 1 + (numData_ -1 ) / Shell::numNodes();
106 
107  unsigned int lastUsedNode = numData / numPerNode_;
108  if ( lastUsedNode > Shell::myNode() )
109  return numPerNode_;
110  if ( lastUsedNode == Shell::myNode() )
111  return numData - Shell::myNode() * numPerNode_;
112  return 0;
113 }
114 
115 // virtual func, overridden.
116 void LocalDataElement::resize( unsigned int newNumData )
117 {
118  DataElement::resize( setDataSize( newNumData ) );
119 }
120 
121 unsigned int LocalDataElement::getNumOnNode( unsigned int node ) const
122 {
123  unsigned int lastUsedNode = numData_ / numPerNode_;
124  if ( lastUsedNode > node )
125  return numPerNode_;
126  if ( lastUsedNode == node )
127  return numData() - node * numPerNode_;
128  return 0;
129 }
unsigned int numData_
unsigned int getNode(unsigned int dataId) const
Inherited virtual. Returns node location of specified object.
unsigned int localDataStart() const
Inherited virtual. Returns index of first entry on this node.
void resize(unsigned int newNumData)
Element * copyElement(Id newParent, Id newId, unsigned int n, bool toGlobal) const
void resize(unsigned int newNumData)
Definition: DataElement.cpp:95
const unsigned int ALLDATA
Used by ObjId and Eref.
Definition: consts.cpp:22
static unsigned int myNode
unsigned int numData() const
Inherited virtual. Returns number of data entries over all nodes.
unsigned int setDataSize(unsigned int numData)
unsigned int numPerNode_
unsigned int startDataIndex(unsigned int node) const
Inherited virtual. Returns start DataIndex on specified node.
static unsigned int numNodes
static char name[]
Definition: mfield.cpp:401
unsigned int getNumOnNode(unsigned int node) const
Inherited virtual.
Definition: Id.h:17
static unsigned int myNode()
unsigned int rawIndex(unsigned int dataId) const
Converts dataId to index on current node.
unsigned int localDataStart_
static unsigned int numNodes()
unsigned int numLocalData() const
Defined only in derived classes: unsigned int numData() const;.
Definition: DataElement.cpp:61
Definition: Cinfo.h:18
LocalDataElement(Id id, const Cinfo *c, const string &name, unsigned int numData=1)
Definition: Shell.h:43