/[escript]/branches/trilinos_from_5897/dudley/src/NodeFile.h
ViewVC logotype

Diff of /branches/trilinos_from_5897/dudley/src/NodeFile.h

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 6078 by caltinay, Wed Mar 2 04:13:26 2016 UTC revision 6079 by caltinay, Mon Mar 21 12:22:38 2016 UTC
# Line 19  Line 19 
19    
20  #include "Dudley.h"  #include "Dudley.h"
21  #include "NodeMapping.h"  #include "NodeMapping.h"
22  #include "escript/Data.h"  
23  #include "paso/Distribution.h"  #include <paso/Distribution.h>
24  #include "paso/Coupler.h"  #include <paso/Coupler.h>
25    
26  namespace dudley {  namespace dudley {
27    
28  struct Dudley_NodeFile {  class NodeFile
29      escript::JMPI MPIInfo;    /* MPI information */  {
30    public:
31    
32        /// constructor - creates empty node file.
33        /// Use allocTable() to allocate the node table (Id,Coordinates).
34        NodeFile(int nDim, escript::JMPI MPIInfo);
35    
36        /// destructor
37        ~NodeFile();
38    
39        /// allocates the node table within this node file to hold numNodes nodes.
40        void allocTable(dim_t numNodes);
41    
42        /// empties the node table and frees all memory
43        void freeTable();
44    
45        void print() const;
46    
47        inline index_t getFirstNode() const;
48        inline index_t getLastNode() const;
49        inline dim_t getGlobalNumNodes() const;
50        inline const index_t* borrowGlobalNodesIndex() const;
51    
52        /// returns the number of FEM nodes (on this rank)
53        inline dim_t getNumNodes() const;
54    
55        /// returns the number of degrees of freedom (on this rank)
56        inline dim_t getNumDegreesOfFreedom() const;
57    
58        /// returns the number of degrees of freedom targets (own and shared)
59        inline dim_t getNumDegreesOfFreedomTargets() const;
60    
61        /// returns the mapping from target to the local nodes
62        inline const index_t* borrowNodesTarget() const;
63    
64        /// returns the mapping from target to the local degrees of freedom
65        inline const index_t* borrowDegreesOfFreedomTarget() const;
66    
67        /// returns the mapping from local degrees of freedom to a target
68        inline const index_t* borrowTargetDegreesOfFreedom() const;
69    
70        /// returns the mapping from local nodes to a target
71        inline const index_t* borrowTargetNodes() const;
72    
73        inline void updateTagList();
74    
75        /// creates a dense labeling of the global degrees of freedom and returns
76        /// the new number of global degrees of freedom
77        dim_t createDenseDOFLabeling();
78    
79      dim_t numNodes;             /* number of nodes */      dim_t createDenseNodeLabeling(std::vector<index_t>& nodeDistribution,
80      int numDim;         /* spatial dimension */                                    const std::vector<index_t>& dofDistribution);
     index_t *Id;                /* Id[i] is the id number of node i. It need to be unique. */  
     index_t *Tag;               /* Tag[i] is the tag of node i. */  
     index_t *tagsInUse;         /* array of tags which are actually used */  
     dim_t numTagsInUse;         /* number of tags used */  
   
     index_t *globalDegreesOfFreedom;    /* globalDegreesOfFreedom[i] is the global degree of freedom assigned to node i */  
     /* this index is used to consider periodic boundary conditions by assigning */  
     /* the same degreesOfFreedom to the same node */  
     double *Coordinates;        /* Coordinates[INDEX2(k,i,numDim)] is the k-th coordinate of the */  
     /* node i. */  
     index_t *globalReducedDOFIndex;     /* assigns each local node a global unique Id in a dens labeling of reduced DOF */  
     /* value <0 indicates that the DOF is not used */  
     index_t *globalReducedNodesIndex;   /* assigns each local node a global unique Id in a dens labeling */  
     /* value <0 indicates that the DOF is not used */  
     index_t *globalNodesIndex;  /* assigns each local reduced node a global unique Id in a dens labeling */  
   
     Dudley_NodeMapping *nodesMapping;  
     Dudley_NodeMapping *reducedNodesMapping;  
     Dudley_NodeMapping *degreesOfFreedomMapping;  
     Dudley_NodeMapping *reducedDegreesOfFreedomMapping;  
81    
82        void createNodeMappings(const std::vector<index_t>& dofDistribution,
83                                const std::vector<index_t>& nodeDistribution);
84    
85        void assignMPIRankToDOFs(int* mpiRankOfDOF,
86                                 const std::vector<index_t>& distribution);
87    
88        void copyTable(index_t offset, index_t idOffset, index_t dofOffset,
89                       const NodeFile* in);
90    
91        /// gathers nodes from the NodeFile `in` using the entries in
92        /// index[0:numNodes-1] which are between min_index and max_index
93        /// (exclusive)
94        void gather(const index_t* index, const NodeFile* in);
95    
96        void gather_global(const index_t* index, const NodeFile* in);
97    
98        void setCoordinates(const escript::Data& newX);
99    
100        /// set tags to newTag where mask > 0
101        void setTags(int newTag, const escript::Data& mask);
102    
103        std::pair<index_t,index_t> getDOFRange() const;
104    
105    private:
106        std::pair<index_t,index_t> getGlobalIdRange() const;
107        std::pair<index_t,index_t> getGlobalDOFRange() const;
108        std::pair<index_t,index_t> getGlobalNodeIDIndexRange() const;
109        dim_t prepareLabeling(const std::vector<short>& mask,
110                              std::vector<index_t>& buffer,
111                              std::vector<index_t>& distribution, bool useNodes);
112        void createDOFMappingAndCoupling();
113    
114        NodeMapping nodesMapping;
115        NodeMapping degreesOfFreedomMapping;
116    
117        /// number of nodes
118        dim_t numNodes;
119    
120    public:
121        /// MPI information
122        escript::JMPI MPIInfo;
123        /// number of spatial dimensions
124        int numDim;
125        /// Id[i] is the unique ID number of FEM node i
126        index_t* Id;
127        /// Tag[i] is the tag of node i
128        int* Tag;
129        /// vector of tags which are actually used
130        std::vector<int> tagsInUse;
131    
132        /// globalDegreesOfFreedom[i] is the global degree of freedom assigned
133        /// to node i. This index is used to consider periodic boundary conditions
134        /// by assigning the same degree of freedom to different nodes.
135        index_t* globalDegreesOfFreedom;
136        /// Coordinates[INDEX2(k,i,numDim)] is the k-th coordinate of node i
137        double* Coordinates;
138        /// assigns each local node a global unique ID in a dense labeling
139        index_t* globalNodesIndex;
140    
141        /// MPI distribution of nodes
142      paso::Distribution_ptr nodesDistribution;      paso::Distribution_ptr nodesDistribution;
     paso::Distribution_ptr reducedNodesDistribution;  
     paso::Distribution_ptr degreesOfFreedomDistribution;  
     paso::Distribution_ptr reducedDegreesOfFreedomDistribution;  
143    
144      paso::Connector_ptr degreesOfFreedomConnector;      /// MPI distribution of degrees of freedom
145      paso::Connector_ptr reducedDegreesOfFreedomConnector;      paso::Distribution_ptr dofDistribution;
146    
147      /* these a the packed versions of Id */      paso::Connector_ptr degreesOfFreedomConnector;
     index_t *reducedNodesId;  
     index_t *degreesOfFreedomId;  
     index_t *reducedDegreesOfFreedomId;  
148    
149      int status;                 /* the status counts the updates done on the node coordinates */      // these are the packed versions of Id
150      /* the value of status is increased by when the node coordinates are updated. */      index_t* degreesOfFreedomId;
151    
152        /// the status counts the updates done on the node coordinates.
153        /// The value is increased by 1 when the node coordinates are updated.
154        int status;
155  };  };
156    
157  typedef struct Dudley_NodeFile Dudley_NodeFile;  //
158    // implementation of inline methods
159    //
160    
161    inline index_t NodeFile::getFirstNode() const
162    {
163        return nodesDistribution->getFirstComponent();
164    }
165    
166    inline index_t NodeFile::getLastNode() const
167    {
168        return nodesDistribution->getLastComponent();
169    }
170    
171    inline dim_t NodeFile::getGlobalNumNodes() const
172    {
173        return nodesDistribution->getGlobalNumComponents();
174    }
175    
176    inline const index_t* NodeFile::borrowGlobalNodesIndex() const
177    {
178        return globalNodesIndex;
179    }
180    
181    inline dim_t NodeFile::getNumNodes() const
182    {
183        return numNodes;
184    }
185    
186    inline dim_t NodeFile::getNumDegreesOfFreedom() const
187    {
188        return dofDistribution->getMyNumComponents();
189    }
190    
191    inline dim_t NodeFile::getNumDegreesOfFreedomTargets() const
192    {
193        return degreesOfFreedomMapping.numTargets;
194    }
195    
196    inline const index_t* NodeFile::borrowNodesTarget() const
197    {
198        return nodesMapping.map;
199    }
200    
201    inline const index_t* NodeFile::borrowDegreesOfFreedomTarget() const
202    {
203        return degreesOfFreedomMapping.map;
204    }
205    
206    inline const index_t* NodeFile::borrowTargetNodes() const
207    {
208        return nodesMapping.target;
209    }
210    
211    inline const index_t* NodeFile::borrowTargetDegreesOfFreedom() const
212    {
213        return degreesOfFreedomMapping.target;
214    }
215    
216    inline void NodeFile::updateTagList()
217    {
218        util::setValuesInUse(Tag, numNodes, tagsInUse, MPIInfo);
219    }
220    
 Dudley_NodeFile *Dudley_NodeFile_alloc(dim_t, escript::JMPI& MPIInfo);  
 index_t Dudley_NodeFile_getFirstReducedNode(Dudley_NodeFile * in);  
 index_t Dudley_NodeFile_getLastReducedNode(Dudley_NodeFile * in);  
 dim_t Dudley_NodeFile_getGlobalNumReducedNodes(Dudley_NodeFile * in);  
 index_t *Dudley_NodeFile_borrowGlobalReducedNodesIndex(Dudley_NodeFile * in);  
 index_t Dudley_NodeFile_maxGlobalNodeIDIndex(Dudley_NodeFile * in);  
 index_t Dudley_NodeFile_maxGlobalReducedNodeIDIndex(Dudley_NodeFile * in);  
 index_t Dudley_NodeFile_GlobalDegreeOfFreedomIndex(Dudley_NodeFile * in);  
 index_t Dudley_NodeFile_GlobalReducedDegreeOfFreedomIndex(Dudley_NodeFile * in);  
   
 index_t Dudley_NodeFile_getFirstNode(Dudley_NodeFile * in);  
 index_t Dudley_NodeFile_getLastNode(Dudley_NodeFile * in);  
 dim_t Dudley_NodeFile_getGlobalNumNodes(Dudley_NodeFile * in);  
 index_t *Dudley_NodeFile_borrowGlobalNodesIndex(Dudley_NodeFile * in);  
   
 /* returns the number of target */  
 dim_t Dudley_NodeFile_getNumReducedNodes(Dudley_NodeFile * in);  
 dim_t Dudley_NodeFile_getNumDegreesOfFreedom(Dudley_NodeFile * in);  
 dim_t Dudley_NodeFile_getNumNodes(Dudley_NodeFile * in);  
 dim_t Dudley_NodeFile_getNumReducedDegreesOfFreedom(Dudley_NodeFile * in);  
   
 /* returns the mapping from local nodes to a target */  
 index_t *Dudley_NodeFile_borrowTargetReducedNodes(Dudley_NodeFile * in);  
 index_t *Dudley_NodeFile_borrowTargetDegreesOfFreedom(Dudley_NodeFile * in);  
 index_t *Dudley_NodeFile_borrowTargetNodes(Dudley_NodeFile * in);  
 index_t *Dudley_NodeFile_borrowTargetReducedDegreesOfFreedom(Dudley_NodeFile * in);  
 /* returns the mapping from target to the local nodes */  
 index_t *Dudley_NodeFile_borrowReducedNodesTarget(Dudley_NodeFile * in);  
 index_t *Dudley_NodeFile_borrowDegreesOfFreedomTarget(Dudley_NodeFile * in);  
 index_t *Dudley_NodeFile_borrowNodesTarget(Dudley_NodeFile * in);  
 index_t *Dudley_NodeFile_borrowReducedDegreesOfFreedomTarget(Dudley_NodeFile * in);  
   
 void Dudley_NodeFile_allocTable(Dudley_NodeFile *, dim_t);  
 void Dudley_NodeFile_free(Dudley_NodeFile *);  
 void Dudley_NodeFile_freeTable(Dudley_NodeFile *);  
 void Dudley_NodeFile_setIdGlobalRange(index_t *, index_t *, Dudley_NodeFile *);  
 void Dudley_NodeFile_setIdRange(index_t *, index_t *, Dudley_NodeFile *);  
 void Dudley_NodeFile_setDOFGlobalRange(index_t *, index_t *, Dudley_NodeFile *);  
 void Dudley_NodeFile_setDOFRange(index_t *, index_t *, Dudley_NodeFile *);  
   
 void Dudley_NodeFile_setGlobalDOFRange(index_t *, index_t *, Dudley_NodeFile *);  
 void Dudley_NodeFile_setGlobalIdRange(index_t *, index_t *, Dudley_NodeFile *);  
 index_t Dudley_NodeFile_maxGlobalDegreeOfFreedomIndex(Dudley_NodeFile *);  
 index_t Dudley_NodeFile_maxGlobalReducedDegreeOfFreedomIndex(Dudley_NodeFile *);  
   
 void Dudley_NodeFile_setReducedDOFRange(index_t *, index_t *, Dudley_NodeFile *);  
 dim_t Dudley_NodeFile_createDenseDOFLabeling(Dudley_NodeFile *);  
 dim_t Dudley_NodeFile_createDenseNodeLabeling(Dudley_NodeFile * in, index_t * node_distribution,  
                                               const index_t * dof_distribution);  
 dim_t Dudley_NodeFile_createDenseReducedNodeLabeling(Dudley_NodeFile * in, index_t * reducedNodeMask);  
 dim_t Dudley_NodeFile_createDenseReducedDOFLabeling(Dudley_NodeFile * in, index_t * reducedNodeMask);  
 void Dudley_NodeFile_assignMPIRankToDOFs(Dudley_NodeFile * in, int* mpiRankOfDOF, index_t * distribution);  
 void Dudley_NodeFile_gather(index_t *, Dudley_NodeFile *, Dudley_NodeFile *);  
 void Dudley_NodeFile_gather_global(index_t *, Dudley_NodeFile *, Dudley_NodeFile *);  
 void Dudley_NodeFile_gatherEntries(dim_t, index_t *, index_t, index_t, index_t *, index_t *, index_t *, index_t *,  
                                    index_t *, index_t *, dim_t numDim, double *, double *);  
 void Dudley_NodeFile_copyTable(dim_t, Dudley_NodeFile *, dim_t, dim_t, Dudley_NodeFile *);  
 void Dudley_NodeFile_scatter(index_t *, Dudley_NodeFile *, Dudley_NodeFile *);  
 void Dudley_NodeFile_scatterEntries(dim_t, index_t *, index_t, index_t, index_t *, index_t *, index_t *, index_t *,  
                                     index_t *, index_t *, dim_t numDim, double *, double *);  
 void Dudley_NodeFile_copyTable(dim_t, Dudley_NodeFile *, dim_t, dim_t, Dudley_NodeFile *);  
 void Dudley_NodeFile_setGlobalReducedDegreeOfFreedomRange(index_t * min_id, index_t * max_id, Dudley_NodeFile * in);  
 void Dudley_NodeFile_setGlobalNodeIDIndexRange(index_t * min_id, index_t * max_id, Dudley_NodeFile * in);  
 void Dudley_NodeFile_setGlobalReducedNodeIDIndexRange(index_t * min_id, index_t * max_id, Dudley_NodeFile * in);  
   
 /* ===================== */  
 void Dudley_NodeFile_setCoordinates(Dudley_NodeFile *, const escript::Data *);  
 void Dudley_NodeFile_setTags(Dudley_NodeFile *, const int, const escript::Data *);  
 void Dudley_NodeFile_setTagsInUse(Dudley_NodeFile * in);  
221    
222  } // namespace dudley  } // namespace dudley
223    

Legend:
Removed from v.6078  
changed lines
  Added in v.6079

  ViewVC Help
Powered by ViewVC 1.1.26