Browse files

Updated ns.h to reflect version 1.3

Sparse fields:
  Better counting of totalLoadedBlocks()
  Improved efficiency of SparseField::clear() - was using m_blocks.end() in comparison.
  SparseField::setupBlocks now correctly swap-clears the m_blocks array.
Refcount.h: Enable use of atomic ref counters (instead of mutex/lock)
Use field_dynamic_cast instead of dynamic_pointer_cast. (MACFieldUtil.h, FieldMapping.cpp)
Inlined methods in MACField that were tested to improve performance.
FieldRes::isInBounds should be const - fixed.
  • Loading branch information...
1 parent 7c1da78 commit e44aaa3f5b166deaf0a0f70cf3ad26db276c5117 @magnusw magnusw committed Nov 16, 2011
Showing with 42 additions and 30 deletions.
  1. +2 −2 export/Field.h
  2. +13 −13 export/MACField.h
  3. +2 −2 export/MACFieldUtil.h
  4. +1 −1 export/RefCount.h
  5. +7 −4 export/SparseField.h
  6. +12 −3 export/SparseFile.h
  7. +3 −3 export/ns.h
  8. +1 −1 src/FieldMapping.cpp
  9. +1 −1 src/FieldMappingIO.cpp
View
4 export/Field.h
@@ -270,7 +270,7 @@ class FieldRes : public FieldBase
{ return m_mapping; }
//! Returns true is the indicies are in bounds of the data window
- bool isInBounds(int i, int j, int k);
+ bool isInBounds(int i, int j, int k) const;
// To be implemented by subclasses -------------------------------------------
@@ -346,7 +346,7 @@ inline void FieldRes::setMapping(FieldMapping::Ptr mapping)
//----------------------------------------------------------------------------//
-inline bool FieldRes::isInBounds(int i, int j, int k)
+inline bool FieldRes::isInBounds(int i, int j, int k) const
{
// Check bounds
if (i < m_dataWindow.min.x || i > m_dataWindow.max.x ||
View
26 export/MACField.h
@@ -606,7 +606,7 @@ MACField<Data_T>::MACField()
//----------------------------------------------------------------------------//
template <class Data_T>
-void MACField<Data_T>::clear(const Data_T &value)
+inline void MACField<Data_T>::clear(const Data_T &value)
{
std::fill(m_u.begin(), m_u.end(), value.x);
std::fill(m_v.begin(), m_v.end(), value.y);
@@ -683,7 +683,7 @@ void MACField<Data_T>::sizeChanged()
//----------------------------------------------------------------------------//
template <class Data_T>
-const typename MACField<Data_T>::real_t&
+inline const typename MACField<Data_T>::real_t&
MACField<Data_T>::u(int i, int j, int k) const
{
assert (i >= base::m_dataWindow.min.x);
@@ -702,7 +702,7 @@ MACField<Data_T>::u(int i, int j, int k) const
//----------------------------------------------------------------------------//
template <class Data_T>
-typename MACField<Data_T>::real_t&
+inline typename MACField<Data_T>::real_t&
MACField<Data_T>::u(int i, int j, int k)
{
assert (i >= base::m_dataWindow.min.x);
@@ -721,7 +721,7 @@ MACField<Data_T>::u(int i, int j, int k)
//----------------------------------------------------------------------------//
template <class Data_T>
-const typename MACField<Data_T>::real_t&
+inline const typename MACField<Data_T>::real_t&
MACField<Data_T>::v(int i, int j, int k) const
{
assert (i >= base::m_dataWindow.min.x);
@@ -740,7 +740,7 @@ MACField<Data_T>::v(int i, int j, int k) const
//----------------------------------------------------------------------------//
template <class Data_T>
-typename MACField<Data_T>::real_t&
+inline typename MACField<Data_T>::real_t&
MACField<Data_T>::v(int i, int j, int k)
{
assert (i >= base::m_dataWindow.min.x);
@@ -759,7 +759,7 @@ MACField<Data_T>::v(int i, int j, int k)
//----------------------------------------------------------------------------//
template <class Data_T>
-const typename MACField<Data_T>::real_t&
+inline const typename MACField<Data_T>::real_t&
MACField<Data_T>::w(int i, int j, int k) const
{
assert (i >= base::m_dataWindow.min.x);
@@ -778,7 +778,7 @@ MACField<Data_T>::w(int i, int j, int k) const
//----------------------------------------------------------------------------//
template <class Data_T>
-typename MACField<Data_T>::real_t&
+inline typename MACField<Data_T>::real_t&
MACField<Data_T>::w(int i, int j, int k)
{
assert (i >= base::m_dataWindow.min.x);
@@ -905,7 +905,7 @@ MACField<Data_T>::end_comp(MACComponent comp, const Box3i &subset)
//----------------------------------------------------------------------------//
template <class Data_T>
-const typename MACField<Data_T>::real_t*
+inline const typename MACField<Data_T>::real_t*
MACField<Data_T>::uPtr(int i, int j, int k) const
{
// Add crop window offset
@@ -918,7 +918,7 @@ MACField<Data_T>::uPtr(int i, int j, int k) const
//----------------------------------------------------------------------------//
template <class Data_T>
-typename MACField<Data_T>::real_t*
+inline typename MACField<Data_T>::real_t*
MACField<Data_T>::uPtr(int i, int j, int k)
{
// Add crop window offset
@@ -931,7 +931,7 @@ MACField<Data_T>::uPtr(int i, int j, int k)
//----------------------------------------------------------------------------//
template <class Data_T>
-const typename MACField<Data_T>::real_t*
+inline const typename MACField<Data_T>::real_t*
MACField<Data_T>::vPtr(int i, int j, int k) const
{
// Add crop window offset
@@ -944,7 +944,7 @@ MACField<Data_T>::vPtr(int i, int j, int k) const
//----------------------------------------------------------------------------//
template <class Data_T>
-typename MACField<Data_T>::real_t*
+inline typename MACField<Data_T>::real_t*
MACField<Data_T>::vPtr(int i, int j, int k)
{
// Add crop window offset
@@ -957,7 +957,7 @@ MACField<Data_T>::vPtr(int i, int j, int k)
//----------------------------------------------------------------------------//
template <class Data_T>
-const typename MACField<Data_T>::real_t*
+inline const typename MACField<Data_T>::real_t*
MACField<Data_T>::wPtr(int i, int j, int k) const
{
// Add crop window offset
@@ -970,7 +970,7 @@ MACField<Data_T>::wPtr(int i, int j, int k) const
//----------------------------------------------------------------------------//
template <class Data_T>
-typename MACField<Data_T>::real_t*
+inline typename MACField<Data_T>::real_t*
MACField<Data_T>::wPtr(int i, int j, int k)
{
// Add crop window offset
View
4 export/MACFieldUtil.h
@@ -99,7 +99,7 @@ void convertMACToCellCentered(typename MACField<Data_T>::Ptr mac,
bool rotateVector = false;
M44d ssToWsMtx;
MatrixFieldMapping::Ptr mapping =
- boost::dynamic_pointer_cast<MatrixFieldMapping>(mac->mapping());
+ field_dynamic_cast<MatrixFieldMapping>(mac->mapping());
if (mapping) {
M44d localToWorldMtx = mapping->localToWorld();
V3d scale, rot, trans, shear;
@@ -155,7 +155,7 @@ void convertCellCenteredToMAC(typename Field_T::Ptr cc,
bool rotateVector = false;
M44d wsToSsMtx;
MatrixFieldMapping::Ptr mapping =
- boost::dynamic_pointer_cast<MatrixFieldMapping>(mac->mapping());
+ field_dynamic_cast<MatrixFieldMapping>(mac->mapping());
if (mapping) {
M44d localToWorld = mapping->localToWorld();
V3d scale, rot, trans, shear;
View
2 export/RefCount.h
@@ -44,7 +44,7 @@
#ifndef _INCLUDED_Field3D_REF_COUNT_H_
#define _INCLUDED_Field3D_REF_COUNT_H_
-//#define FIELD3D_USE_ATOMIC_COUNT
+#define FIELD3D_USE_ATOMIC_COUNT
//----------------------------------------------------------------------------//
#include <boost/intrusive_ptr.hpp>
View
11 export/SparseField.h
@@ -1161,7 +1161,8 @@ void SparseField<Data_T>::clear(const Data_T &value)
setupBlocks();
// Then just fill in the default values
typename std::vector<Block>::iterator i;
- for (i = m_blocks.begin(); i != m_blocks.end(); ++i) {
+ typename std::vector<Block>::iterator end;
+ for (i = m_blocks.begin(), end = m_blocks.end(); i != end; ++i) {
i->emptyValue = value;
}
}
@@ -1544,10 +1545,11 @@ void SparseField<Data_T>::setupBlocks()
static_cast<int>(blockRes.z));
m_blockRes = intBlockRes;
m_blockXYSize = m_blockRes.x * m_blockRes.y;
- //! \todo clear() won't resize. Do the swap trick.
- m_blocks.clear();
+ // clear() won't deallocate data. Do the swap trick.
+ //m_blocks.clear();
+ std::vector<Block>().swap(m_blocks);
+
m_blocks.resize(intBlockRes.x * intBlockRes.y * intBlockRes.z);
-
}
//----------------------------------------------------------------------------//
@@ -1594,6 +1596,7 @@ template <class Data_T>
void SparseField<Data_T>::deallocBlock(Block &block, const Data_T &emptyValue)
{
block.isAllocated = false;
+ //! Block::clear() deallocates the data
block.clear();
block.emptyValue = emptyValue;
}
View
15 export/SparseFile.h
@@ -687,10 +687,19 @@ int Reference<Data_T>::totalLoadedBlocks() const
std::vector<int>::const_iterator li = blockLoaded.begin();
std::vector<int>::const_iterator end = loadCounts.end();
int numBlocks = 0;
- for (; i != end; ++i, ++li)
- if (*i || *li)
- numBlocks++;
+ if (blockLoaded.size() == 0) {
+ for (; i != end; ++i)
+ if (*i)
+ numBlocks++;
+ } else {
+ assert(loadCounts.size() == blockLoaded.size());
+
+ for (; i != end; ++i, ++li)
+ if (*i || *li)
+ numBlocks++;
+ }
+
return numBlocks;
}
View
6 export/ns.h
@@ -36,10 +36,10 @@
//----------------------------------------------------------------------------//
#define FIELD3D_MAJOR_VER 1
-#define FIELD3D_MINOR_VER 2
-#define FIELD3D_MICRO_VER 1
+#define FIELD3D_MINOR_VER 3
+#define FIELD3D_MICRO_VER 0
-#define FIELD3D_VERSION_NS v1_2
+#define FIELD3D_VERSION_NS v1_3
#ifdef FIELD3D_EXTRA_NAMESPACE
View
2 src/FieldMapping.cpp
@@ -239,7 +239,7 @@ bool MatrixFieldMapping::isIdentical(FieldMapping::Ptr other,
return false;
} else {
MatrixFieldMapping::Ptr mm =
- dynamic_pointer_cast<MatrixFieldMapping>(other);
+ field_dynamic_cast<MatrixFieldMapping>(other);
if (mm) {
// first preserve the same test as before:
if (mm->m_lsToWs.equalWithRelError(m_lsToWs, tolerance) &&
View
2 src/FieldMappingIO.cpp
@@ -131,7 +131,7 @@ bool
MatrixFieldMappingIO::write(hid_t mappingGroup, FieldMapping::Ptr mapping)
{
MatrixFieldMapping::Ptr mm =
- boost::dynamic_pointer_cast<MatrixFieldMapping>(mapping);
+ field_dynamic_cast<MatrixFieldMapping>(mapping);
if (!mm) {
Msg::print(Msg::SevWarning, "Couldn't get MatrixFieldMapping from pointer");
return false;

0 comments on commit e44aaa3

Please sign in to comment.