Skip to content

Commit 321127b

Browse files
author
William Tobin
committed
splitting the class specification into its own header to mimic the implementation of Numbering, also adding an explicit up-casting function to the API
1 parent e089dae commit 321127b

File tree

3 files changed

+109
-74
lines changed

3 files changed

+109
-74
lines changed

apf/apfAggregateNumbering.cc

Lines changed: 29 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "apfAggregateNumbering.h"
2+
#include "apfAggregateNumberingClass.h"
23
#include "apfField.h"
34
#include "apfNumberingClass.h"
45
#include "apfTagData.h"
@@ -8,51 +9,9 @@
89
#include <set>
910
namespace apf
1011
{
11-
template <class T>
12-
class AggregateNumberingOf : public NumberingOf<T>
13-
{
14-
public:
15-
AggregateNumberingOf()
16-
: NumberingOf<T>()
17-
, nd_ids(NULL)
18-
, shr(NULL)
19-
, blks_per_nd(0)
20-
, dofs_per_blk(0)
21-
, slf(-1)
22-
, strds()
23-
, frsts()
24-
, lcl_strd(0)
25-
{ }
26-
void init(const char * n,
27-
Mesh * m,
28-
Sharing * sh,
29-
FieldShape * s,
30-
int blks,
31-
int bs);
32-
void init(Field * f, Sharing * sh, int blks, int bs);
33-
void globalize();
34-
virtual void getAll(MeshEntity * e, T * dat);
35-
virtual T get(MeshEntity * e, int nd, int cmp);
36-
virtual void set(MeshEntity*,int,int,T) {}
37-
Sharing * getSharing() const { return shr; }
38-
void setSharing(Sharing * s) { shr = s; }
39-
int countBlocks() const { return blks_per_nd; }
40-
int blockSize() const { return dofs_per_blk; }
41-
T getLocalStride() const { return lcl_strd; }
42-
T getScopeStride() const { return strds[slf]; }
43-
T getLocalFirstDof() const { return frsts[slf]; }
44-
T getStride(int peer) const { return strds[peer]; };
45-
T getFirstDof(int peer) const { return frsts[peer]; }
46-
private:
47-
FieldDataOf<T> * nd_ids;
48-
Sharing * shr;
49-
int blks_per_nd;
50-
int dofs_per_blk;
51-
int slf;
52-
DynamicArray<T> strds;
53-
DynamicArray<T> frsts;
54-
int lcl_strd;
55-
};
12+
// explicit instantiations
13+
template class AggregateNumberingOf<int>;
14+
template class AggregateNumberingOf<long>;
5615
// this assumes that the ranks returned by a sharing
5716
// do not change when the pcu comm changes
5817
// if the sharing can handle the pcu comm changing
@@ -288,16 +247,11 @@ namespace apf
288247
getAll(e,&data[0]);
289248
return data[nd*cmps + cmp];
290249
}
291-
// explicit instantiations
292-
template class AggregateNumberingOf<int>;
293-
template class AggregateNumberingOf<long>;
294-
typedef AggregateNumberingOf<int> AggNumbering;
295-
typedef AggregateNumberingOf<long> GlobalAggNumbering;
296-
Numbering * createAggNumbering(Field * f,
297-
int blocks,
298-
int dofs_per_block,
299-
MPI_Comm cm,
300-
Sharing * share)
250+
AggNumbering * createAggNumbering(Field * f,
251+
int blocks,
252+
int dofs_per_block,
253+
MPI_Comm cm,
254+
Sharing * share)
301255
{
302256
bool dlt = false;
303257
if(!share)
@@ -330,13 +284,13 @@ namespace apf
330284
f->getMesh()->addNumbering(n);
331285
return n;
332286
}
333-
Numbering * createAggNumbering(Mesh * m,
334-
const char * name,
335-
FieldShape * shape,
336-
int blocks,
337-
int dofs_per_block,
338-
MPI_Comm cm,
339-
Sharing * share)
287+
AggNumbering * createAggNumbering(Mesh * m,
288+
const char * name,
289+
FieldShape * shape,
290+
int blocks,
291+
int dofs_per_block,
292+
MPI_Comm cm,
293+
Sharing * share)
340294
{
341295
bool dlt = false;
342296
if(!share)
@@ -364,4 +318,17 @@ namespace apf
364318
m->addNumbering(n);
365319
return n;
366320
}
321+
/* Public API */
322+
Numbering * getNumbering(AggNumbering * n)
323+
{
324+
return static_cast<Numbering*>(n);
325+
}
326+
int countBlocks(AggNumbering * n)
327+
{
328+
return n->blockSize();
329+
}
330+
int countDOFsPerBlock(AggNumbering * n)
331+
{
332+
return n->blockSize();
333+
}
367334
}

apf/apfAggregateNumbering.h

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,36 @@
22
#define APF_AGGREGATE_NUMBERING_H_
33
#include "apfNew.h"
44
#include "apfMesh.h"
5+
#include "apfNumbering.h"
56
#include <PCU.h>
67
namespace apf
78
{
8-
Numbering * createAggNumbering(Field * f,
9-
int blocks,
10-
int dofs_per_block,
11-
MPI_Comm cm,
12-
Sharing * share = NULL);
13-
Numbering * createAggNumbering(Mesh * m,
14-
const char * name,
15-
FieldShape * shape,
16-
int blocks,
17-
int dofs_per_block,
18-
MPI_Comm cm,
19-
Sharing * share = NULL);
9+
// class declaration
10+
template <class T>
11+
class AggregateNumberingOf;
12+
typedef AggregateNumberingOf<int> AggNumbering;
13+
typedef AggregateNumberingOf<long> GlobalAggNumbering;
14+
// numbering creation functions
15+
AggNumbering * createAggNumbering(Field * f,
16+
int blocks,
17+
int dofs_per_block,
18+
MPI_Comm cm,
19+
Sharing * share = NULL);
20+
AggNumbering * createAggNumbering(Mesh * m,
21+
const char * name,
22+
FieldShape * shape,
23+
int blocks,
24+
int dofs_per_block,
25+
MPI_Comm cm,
26+
Sharing * share = NULL);
27+
/*
28+
* @brief Since the class implementation is not public
29+
* we need an API to up-cast AggNumbering to
30+
* Numbering.
31+
*/
32+
Numbering * getNumbering(AggNumbering * n);
33+
int countBlocks(AggNumbering * n);
34+
int countDOFsPerBlock(AggNumbering * n);
2035
}
2136
#endif
2237
/******************************************************************************

apf/apfAggregateNumberingClass.h

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#ifndef APF_AGGREGATE_NUMBERING_CLASS_H_
2+
#define APF_AGGREGATE_NUMBERING_CLASS_H_
3+
#include "apfFieldData.h"
4+
#include "apfNumberingClass.h"
5+
namespace apf
6+
{
7+
template <class T>
8+
class AggregateNumberingOf : public NumberingOf<T>
9+
{
10+
public:
11+
AggregateNumberingOf()
12+
: NumberingOf<T>()
13+
, nd_ids(NULL)
14+
, shr(NULL)
15+
, blks_per_nd(0)
16+
, dofs_per_blk(0)
17+
, slf(-1)
18+
, strds()
19+
, frsts()
20+
, lcl_strd(0)
21+
{ }
22+
void init(const char * n,
23+
Mesh * m,
24+
Sharing * sh,
25+
FieldShape * s,
26+
int blks,
27+
int bs);
28+
void init(Field * f, Sharing * sh, int blks, int bs);
29+
void globalize();
30+
virtual void getAll(MeshEntity * e, T * dat);
31+
virtual T get(MeshEntity * e, int nd, int cmp);
32+
virtual void set(MeshEntity*,int,int,T) {}
33+
Sharing * getSharing() const { return shr; }
34+
void setSharing(Sharing * s) { shr = s; }
35+
int countBlocks() const { return blks_per_nd; }
36+
int blockSize() const { return dofs_per_blk; }
37+
T getLocalStride() const { return lcl_strd; }
38+
T getScopeStride() const { return strds[slf]; }
39+
T getLocalFirstDof() const { return frsts[slf]; }
40+
T getStride(int peer) const { return strds[peer]; };
41+
T getFirstDof(int peer) const { return frsts[peer]; }
42+
private:
43+
FieldDataOf<T> * nd_ids;
44+
Sharing * shr;
45+
int blks_per_nd;
46+
int dofs_per_blk;
47+
int slf;
48+
DynamicArray<T> strds;
49+
DynamicArray<T> frsts;
50+
int lcl_strd;
51+
};
52+
}
53+
#endif

0 commit comments

Comments
 (0)