Patch to NewField/Field.h (3/3)
Dave Nystrom
wdn at lanl.gov
Tue Oct 16 22:26:40 UTC 2001
}
//-----------------------------------------------------------------------------
// Functions for getting the number of materials for Arrays and Fields.
//
// This is complicated because of the recursive nature of sub-field storage.
// We assume that multi-material fields are constructed by replicating
// a centering. This means that
// (1) multi-material fields must have sub-fields; if not, there is one
// material
// (2) if there is one sub-field at the top level, there is one material
// (3) if there are multiple sub-fields and those have sub-fields themselves,
// we assume they represent materials
// (4) if there are multiple sub-fields and they do not have sub-fields,
// they represent materials if the data is replicated
//-----------------------------------------------------------------------------
template<int Dim, class T, class EngineTag>
inline int numMaterials(const Array<Dim, T, EngineTag> &a)
{
return 1;
}
template<class GeometryTag, class T, class EngineTag>
int numMaterials(const Field<GeometryTag, T, EngineTag> &f)
{
int n0 = f.numSubFields();
if (n0 < 2)
{
return 1;
}
else
{
int n1 = f[0].numSubFields();
if (n1 > 0)
{
return n1;
}
else if (f[0].fieldEngine().offsets() == f[1].fieldEngine().offsets())
{
return n0;
}
else
{
return 1;
}
}
}
//-----------------------------------------------------------------------------
// Functions for getting the number of centering points for Arrays and Fields.
// We assume that multi-material fields are constructed by replicating
// a centering. The analysis goes much like numMaterials above.
//-----------------------------------------------------------------------------
template<int Dim, class T, class EngineTag>
inline int centeringSize(const Array<Dim, T, EngineTag> &a)
{
return 1;
}
template<class GeometryTag, class T, class EngineTag>
int centeringSize(const Field<GeometryTag, T, EngineTag> &f)
{
int n0 = f.numSubFields();
if (n0 == 0)
{
return 1;
}
else
{
int n1 = f[0].numSubFields();
if (n1 == 0)
{
if (n0 == 1 || f[0].fieldEngine().offsets() == f[1].fieldEngine().offsets())
{
return 1;
}
else
{
return n0;
}
}
else
{
return n1;
}
}
}
//-----------------------------------------------------------------------------
// Functions for taking subfield views of Arrays and Fields.
//-----------------------------------------------------------------------------
template<int Dim, class T, class EngineTag>
inline Array<Dim, T, EngineTag> &subField(Array<Dim, T, EngineTag> &a, int, int)
{
return a;
}
template<class GeometryTag, class T, class EngineTag>
typename SubFieldView<Field<GeometryTag, T, EngineTag> >::Type_t
subField(const Field<GeometryTag, T, EngineTag> &f, int m, int c)
{
int n0 = f.numSubFields();
if (n0 == 0)
{
PAssert(m == 0);
PAssert(c == 0);
return f;
}
else
{
if (m == 0)
{
PAssert(c < n0);
return f[c];
}
else if (c == 0)
{
PAssert(m < n0);
return f[m];
}
else
{
return subField(f[m], 0, c);
}
}
}
#endif // POOMA_NEWFIELD_FIELD_H
// ACL:rcsinfo
// ----------------------------------------------------------------------
// $RCSfile: Field.h,v $ $Author: haney $
// $Revision: 1.16.2.1 $ $Date: 2001/09/21 19:42:25 $
// ----------------------------------------------------------------------
// ACL:rcsinfo
More information about the pooma-dev
mailing list