Skip to content

Commit

Permalink
splitting the class specification into its own header to mimic the im…
Browse files Browse the repository at this point in the history
…plementation of Numbering, also adding an explicit up-casting function to the API
  • Loading branch information
William Tobin committed Aug 13, 2018
1 parent 338ebc8 commit b552b32
Show file tree
Hide file tree
Showing 3 changed files with 109 additions and 74 deletions.
91 changes: 29 additions & 62 deletions apf/apfAggregateNumbering.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "apfAggregateNumbering.h"
#include "apfAggregateNumberingClass.h"
#include "apfField.h"
#include "apfNumberingClass.h"
#include "apfTagData.h"
Expand All @@ -8,51 +9,9 @@
#include <set>
namespace apf
{
template <class T>
class AggregateNumberingOf : public NumberingOf<T>
{
public:
AggregateNumberingOf()
: NumberingOf<T>()
, nd_ids(NULL)
, shr(NULL)
, blks_per_nd(0)
, dofs_per_blk(0)
, slf(-1)
, strds()
, frsts()
, lcl_strd(0)
{ }
void init(const char * n,
Mesh * m,
Sharing * sh,
FieldShape * s,
int blks,
int bs);
void init(Field * f, Sharing * sh, int blks, int bs);
void globalize();
virtual void getAll(MeshEntity * e, T * dat);
virtual T get(MeshEntity * e, int nd, int cmp);
virtual void set(MeshEntity*,int,int,T) {}
Sharing * getSharing() const { return shr; }
void setSharing(Sharing * s) { shr = s; }
int countBlocks() const { return blks_per_nd; }
int blockSize() const { return dofs_per_blk; }
T getLocalStride() const { return lcl_strd; }
T getScopeStride() const { return strds[slf]; }
T getLocalFirstDof() const { return frsts[slf]; }
T getStride(int peer) const { return strds[peer]; };
T getFirstDof(int peer) const { return frsts[peer]; }
private:
FieldDataOf<T> * nd_ids;
Sharing * shr;
int blks_per_nd;
int dofs_per_blk;
int slf;
DynamicArray<T> strds;
DynamicArray<T> frsts;
int lcl_strd;
};
// explicit instantiations
template class AggregateNumberingOf<int>;
template class AggregateNumberingOf<long>;
// this assumes that the ranks returned by a sharing
// do not change when the pcu comm changes
// if the sharing can handle the pcu comm changing
Expand Down Expand Up @@ -288,16 +247,11 @@ namespace apf
getAll(e,&data[0]);
return data[nd*cmps + cmp];
}
// explicit instantiations
template class AggregateNumberingOf<int>;
template class AggregateNumberingOf<long>;
typedef AggregateNumberingOf<int> AggNumbering;
typedef AggregateNumberingOf<long> GlobalAggNumbering;
Numbering * createAggNumbering(Field * f,
int blocks,
int dofs_per_block,
MPI_Comm cm,
Sharing * share)
AggNumbering * createAggNumbering(Field * f,
int blocks,
int dofs_per_block,
MPI_Comm cm,
Sharing * share)
{
bool dlt = false;
if(!share)
Expand Down Expand Up @@ -330,13 +284,13 @@ namespace apf
f->getMesh()->addNumbering(n);
return n;
}
Numbering * createAggNumbering(Mesh * m,
const char * name,
FieldShape * shape,
int blocks,
int dofs_per_block,
MPI_Comm cm,
Sharing * share)
AggNumbering * createAggNumbering(Mesh * m,
const char * name,
FieldShape * shape,
int blocks,
int dofs_per_block,
MPI_Comm cm,
Sharing * share)
{
bool dlt = false;
if(!share)
Expand Down Expand Up @@ -364,4 +318,17 @@ namespace apf
m->addNumbering(n);
return n;
}
/* Public API */
Numbering * getNumbering(AggNumbering * n)
{
return static_cast<Numbering*>(n);
}
int countBlocks(AggNumbering * n)
{
return n->blockSize();
}
int countDOFsPerBlock(AggNumbering * n)
{
return n->blockSize();
}
}
39 changes: 27 additions & 12 deletions apf/apfAggregateNumbering.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,36 @@
#define APF_AGGREGATE_NUMBERING_H_
#include "apfNew.h"
#include "apfMesh.h"
#include "apfNumbering.h"
#include <PCU.h>
namespace apf
{
Numbering * createAggNumbering(Field * f,
int blocks,
int dofs_per_block,
MPI_Comm cm,
Sharing * share = NULL);
Numbering * createAggNumbering(Mesh * m,
const char * name,
FieldShape * shape,
int blocks,
int dofs_per_block,
MPI_Comm cm,
Sharing * share = NULL);
// class declaration
template <class T>
class AggregateNumberingOf;
typedef AggregateNumberingOf<int> AggNumbering;
typedef AggregateNumberingOf<long> GlobalAggNumbering;
// numbering creation functions
AggNumbering * createAggNumbering(Field * f,
int blocks,
int dofs_per_block,
MPI_Comm cm,
Sharing * share = NULL);
AggNumbering * createAggNumbering(Mesh * m,
const char * name,
FieldShape * shape,
int blocks,
int dofs_per_block,
MPI_Comm cm,
Sharing * share = NULL);
/*
* @brief Since the class implementation is not public
* we need an API to up-cast AggNumbering to
* Numbering.
*/
Numbering * getNumbering(AggNumbering * n);
int countBlocks(AggNumbering * n);
int countDOFsPerBlock(AggNumbering * n);
}
#endif
/******************************************************************************
Expand Down
53 changes: 53 additions & 0 deletions apf/apfAggregateNumberingClass.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#ifndef APF_AGGREGATE_NUMBERING_CLASS_H_
#define APF_AGGREGATE_NUMBERING_CLASS_H_
#include "apfFieldData.h"
#include "apfNumberingClass.h"
namespace apf
{
template <class T>
class AggregateNumberingOf : public NumberingOf<T>
{
public:
AggregateNumberingOf()
: NumberingOf<T>()
, nd_ids(NULL)
, shr(NULL)
, blks_per_nd(0)
, dofs_per_blk(0)
, slf(-1)
, strds()
, frsts()
, lcl_strd(0)
{ }
void init(const char * n,
Mesh * m,
Sharing * sh,
FieldShape * s,
int blks,
int bs);
void init(Field * f, Sharing * sh, int blks, int bs);
void globalize();
virtual void getAll(MeshEntity * e, T * dat);
virtual T get(MeshEntity * e, int nd, int cmp);
virtual void set(MeshEntity*,int,int,T) {}
Sharing * getSharing() const { return shr; }
void setSharing(Sharing * s) { shr = s; }
int countBlocks() const { return blks_per_nd; }
int blockSize() const { return dofs_per_blk; }
T getLocalStride() const { return lcl_strd; }
T getScopeStride() const { return strds[slf]; }
T getLocalFirstDof() const { return frsts[slf]; }
T getStride(int peer) const { return strds[peer]; };
T getFirstDof(int peer) const { return frsts[peer]; }
private:
FieldDataOf<T> * nd_ids;
Sharing * shr;
int blks_per_nd;
int dofs_per_blk;
int slf;
DynamicArray<T> strds;
DynamicArray<T> frsts;
int lcl_strd;
};
}
#endif

0 comments on commit b552b32

Please sign in to comment.