Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions apf/apf.cc
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,6 @@ Field* makeField(
f = new MatrixField();
else if (valueType == PACKED)
f = new PackedField(components);
else if (valueType == COMPLEX_PACKED)
f = new ComplexPackedField(components);
else
fail("invalid valueType in field construction\n");
f->init(name,m,shape,data);
Expand Down Expand Up @@ -163,13 +161,15 @@ void destroyField(Field* f)

void setScalar(Field* f, MeshEntity* e, int node, double value)
{
PCU_DEBUG_ASSERT(f->getValueType() == SCALAR);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we are now allowing c++11 in CORE can this be done with a static assert?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Core has been C++11 for a while IIRC. I've been using auto and range-based for's for a while no one has complained so far.

This assert has to be runtime though.

ScalarField* field = static_cast<ScalarField*>(f);
double tmp[1] = {value};
field->setNodeValue(e,node,tmp);
}

double getScalar(Field* f, MeshEntity* e, int node)
{
PCU_DEBUG_ASSERT(f->getValueType() == SCALAR);
ScalarField* field = static_cast<ScalarField*>(f);
double value[1];
field->getNodeValue(e,node,value);
Expand All @@ -178,13 +178,15 @@ double getScalar(Field* f, MeshEntity* e, int node)

void setVector(Field* f, MeshEntity* e, int node, Vector3 const& value)
{
PCU_DEBUG_ASSERT(f->getValueType() == VECTOR);
VectorField* field = static_cast<VectorField*>(f);
Vector3 tmp[1] = {value};
field->setNodeValue(e,node,tmp);
}

void getVector(Field* f, MeshEntity* e, int node, Vector3& value)
{
PCU_DEBUG_ASSERT(f->getValueType() == VECTOR);
VectorField* field = static_cast<VectorField*>(f);
Vector3 tmp[1];
field->getNodeValue(e,node,tmp);
Expand All @@ -193,13 +195,15 @@ void getVector(Field* f, MeshEntity* e, int node, Vector3& value)

void setMatrix(Field* f, MeshEntity* e, int node, Matrix3x3 const& value)
{
PCU_DEBUG_ASSERT(f->getValueType() == MATRIX);
MatrixField* field = static_cast<MatrixField*>(f);
Matrix3x3 tmp[1] = {value};
field->setNodeValue(e,node,tmp);
}

void getMatrix(Field* f, MeshEntity* e, int node, Matrix3x3& value)
{
PCU_DEBUG_ASSERT(f->getValueType() == MATRIX);
MatrixField* field = static_cast<MatrixField*>(f);
Matrix3x3 tmp[1];
field->getNodeValue(e,node,tmp);
Expand All @@ -208,11 +212,15 @@ void getMatrix(Field* f, MeshEntity* e, int node, Matrix3x3& value)

void setComponents(Field* f, MeshEntity* e, int node, double const* components)
{
PCU_DEBUG_ASSERT(f->getScalarType() == Mesh::DOUBLE &&
(f->getValueType() == SCALAR || f->getValueType() == PACKED);
f->getData()->setNodeComponents(e,node,components);
}

void getComponents(Field* f, MeshEntity* e, int node, double* components)
{
PCU_DEBUG_ASSERT(f->getScalarType() == Mesh::DOUBLE &&
(f->getValueType() == SCALAR || f->getValueType() == PACKED);
f->getData()->getNodeComponents(e,node,components);
}

Expand Down
29 changes: 21 additions & 8 deletions apf/apf.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "apfMatrix.h"
#include "apfNew.h"
#include "apfDynamicArray.h"
#include "apfComplex.h"

#include <vector>
#include <limits>
Expand Down Expand Up @@ -133,8 +134,6 @@ enum ValueType {
MATRIX,
/** \brief a user-defined set of components */
PACKED,
/** \brief a user-defined set of complex-components */
COMPLEX_PACKED,
/** \brief placeholder used to set array sizes */
VALUE_TYPES
};
Expand Down Expand Up @@ -706,9 +705,6 @@ bool isPrintable(Field* f);
*/
void fail(const char* why) __attribute__((noreturn));




/** \brief Convert a Field from Tag to array storage. */
void freeze(Field* f);

Expand All @@ -718,15 +714,32 @@ void unfreeze(Field* f);
/** \brief Returns true iff the Field uses array storage. */
bool isFrozen(Field* f);

template <typename T>
T* getArrayDataT(Field * f);
/** \brief Return the contiguous array storing this field.
\details This function is only defined for fields
which are using array storage, for which apf::isFrozen
returns true.
\note If the underlying field data type is NOT double,
this will cause an assert fail in all compile modes.
*/
double* getArrayData(Field* f);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have a mechanism for depreciation? If so, this should probably be depreciated and replaced with getDoubleArrayData to have a consistent API.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since C++14 we have [[deprecated]], though this codebase is explicitly only up to C++11 IIRC and we haven't put in a deprecation mechanism as far as I know.

C++14 was basically just a small step from 11 so moving core to that should be possible, but is a different issue.

For the time being I will introduce a more consistent API function and not in the doxygen this is deprecated (see apfNumbering.h near the bottom for the only other place this has been done I think).


/** \brief Return the contiguous array storing this field.
\details This function is only defined for fields
which are using array storage, for which apf::isFrozen
returns true.
\note If the underlying field data type is NOT int,
this will cause an assert fail in all compile modes.
*/
int* getIntArrayData(Field* f);

/** \brief Return the contiguous array storing this field.
\details This function is only defined for fields
which are using array storage, for which apf::isFrozen
returns true.
\note If the underlying field data type is NOT double_complex,
this will cause an assert fail in all compile modes.
*/
inline double * getArrayData(Field* f) { return getArrayDataT<double>(f); }
double_complex* getComplexArrayData(Field * f);

/** \brief Initialize all nodal values with all-zero components */
void zeroField(Field* f);
Expand Down