MOOSE - Multiscale Object Oriented Simulation Environment
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
FieldElement.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-2013 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 "../shell/Shell.h"
12 
14  const Cinfo* c, const string& name,
15  const FieldElementFinfoBase* fef
16  )
17  :
18  Element( self, c, name ),
19  parent_( parent ),
20  fef_( fef )
21 {
22  ;
23 }
24 
31 {
32  ;
33 }
34 
36  unsigned int n, bool toGlobal ) const
37 {
38  return new FieldElement( newParent, newId, cinfo(), getName(), fef_ );
39 }
40 
42 // Element info functions
44 
45 unsigned int FieldElement::numData() const
46 {
47  return parent_.element()->numData();
48 }
49 
50 unsigned int FieldElement::numLocalData() const
51 {
52  return parent_.element()->numLocalData();
53 }
54 
55 unsigned int FieldElement::localDataStart() const
56 {
57  return parent_.element()->localDataStart();
58 }
59 
60 unsigned int FieldElement::numField( unsigned int rawIndex ) const
61 {
62  const char* data = parent_.element()->data( rawIndex );
63  assert( data );
64  return fef_->getNumField( data );
65 }
66 
67 unsigned int FieldElement::totNumLocalField() const
68 {
69  unsigned int ret = 0;
70  unsigned int nd = numLocalData();
71  for ( unsigned int i = 0; i < nd; ++i )
72  ret += numField( i );
73  return ret;
74 }
75 
76 unsigned int FieldElement::getNode( unsigned int dataId ) const
77 {
78  return parent_.element()->getNode( dataId );
79 }
80 
81 unsigned int FieldElement::startDataIndex( unsigned int node ) const
82 {
83  return parent_.element()->startDataIndex( node );
84 }
85 
86 unsigned int FieldElement::rawIndex( unsigned int dataId ) const
87 {
88  return parent_.element()->rawIndex( dataId );
89 }
90 
92 {
93  return parent_.element()->isGlobal();
94 }
95 
96 unsigned int FieldElement::getNumOnNode( unsigned int node ) const
97 {
98  if ( node == Shell::myNode() || parent_.element()->isGlobal() )
99  {
100  return totNumLocalField();
101  }
102  // Here we need to refer to a postmaster function to get the
103  // number of field entries on specified node. For now, a dummy.
104  return totNumLocalField();
105 }
106 
108 
109 char* FieldElement::data( unsigned int rawIndex, unsigned int fieldIndex )
110 const
111 {
112  char* data = parent_.element()->data( rawIndex );
113  return fef_->lookupField( data, fieldIndex );
114 }
115 
116 void FieldElement::resize( unsigned int newNumData )
117 {
118  assert( 0 );
119 }
120 
122  unsigned int rawIndex, unsigned int newNumField )
123 {
124  char* data = parent_.element()->data( rawIndex );
125  fef_->setNumField( data, newNumField );
126 }
127 
129 
130 void FieldElement::zombieSwap( const Cinfo* zCinfo )
131 {
132  const Finfo* f = zCinfo->findFinfo( getName() );
133  assert( f );
134 
135  const FieldElementFinfoBase* zfef = dynamic_cast<
136  const FieldElementFinfoBase* >( f );
137  assert( zfef );
138  fef_ = zfef;
139  replaceCinfo( zCinfo );
140 }
unsigned int startDataIndex(unsigned int node) const
Virtual: Returns start DataIndex on specified node.
void resize(unsigned int newNumData)
Element * element() const
Synonym for Id::operator()()
Definition: Id.cpp:113
unsigned int numField(unsigned int rawIndex) const
Virtual: Returns number of field entries for specified data.
const FieldElementFinfoBase * fef_
Definition: FieldElement.h:119
virtual void setNumField(char *parent, unsigned int num) const =0
virtual func to resize Field array, using char* for parent
Element * copyElement(Id newParent, Id newId, unsigned int n, bool toGlobal) const
virtual unsigned int getNumField(const char *parent) const =0
virtual func to get size of Field array, using char* for parent
unsigned int getNumOnNode(unsigned int node) const
Inherited virtual.
char * data(unsigned int rawIndex, unsigned int fieldIndex=0) const
unsigned int numLocalData() const
Virtual: Returns number of data entries on current node.
unsigned int localDataStart() const
Virtual: Returns index of first data entry on this node.
unsigned int getNode(unsigned int dataId) const
Virtual: Returns location of specified dataId.
const Cinfo * cinfo() const
Definition: Element.cpp:66
FieldElement(Id parent, Id kid, const Cinfo *c, const string &name, const FieldElementFinfoBase *fef)
virtual unsigned int numData() const =0
Returns number of data entries across all nodes.
virtual bool isGlobal() const =0
True if there is a copy of every dataEntry on all nodes.
void resizeField(unsigned int rawIndex, unsigned int newNumField)
virtual unsigned int localDataStart() const =0
Returns index of first data entry on this node.
virtual unsigned int numLocalData() const =0
Returns number of local data entries on this node.
static char name[]
Definition: mfield.cpp:401
virtual char * data(unsigned int rawIndex, unsigned int fieldIndex=0) const =0
void zombieSwap(const Cinfo *zCinfo)
unsigned int numData() const
Virtual: Returns number of data entries.
Definition: Id.h:17
virtual unsigned int rawIndex(unsigned int dataIndex) const =0
virtual unsigned int getNode(unsigned int dataIndex) const =0
Returns node number of specified dataIndex.
static unsigned int myNode()
unsigned int rawIndex(unsigned int dataId) const
Virtual: Returns converted dataId to index on current node.
unsigned int totNumLocalField() const
Virtual: Returns number of field entries on current node.
const string & getName() const
Definition: Element.cpp:56
void replaceCinfo(const Cinfo *newCinfo)
Support function for zombieSwap, replaces Cinfo.
Definition: Element.cpp:740
Definition: Cinfo.h:18
virtual unsigned int startDataIndex(unsigned int nodeNum) const =0
Returns start dataIndex on specified node.
virtual char * lookupField(char *parent, unsigned int fieldIndex) const =0
bool isGlobal() const
Virtual. Returns true if global, ie, if its parent is global.
const Finfo * findFinfo(const string &name) const
Definition: Cinfo.cpp:224
Definition: Finfo.h:12