Skip to content

Commit

Permalink
Merge pull request #945 from LLNL/feature/yang39/slam-virtual-iface
Browse files Browse the repository at this point in the history
Slam: Add polymorphic policies, other changes
  • Loading branch information
publixsubfan authored Mar 13, 2023
2 parents 0525f1a + 40df37d commit 4267397
Show file tree
Hide file tree
Showing 22 changed files with 690 additions and 316 deletions.
4 changes: 2 additions & 2 deletions src/axom/multimat/multimat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -425,8 +425,8 @@ void MultiMat::convertToDynamic()
}
StaticVariableRelationType& rel = relStatic(layout);

SetType* set1 = rel.fromSet();
SetType* set2 = rel.toSet();
RangeSetType* set1 = &relDominantSet(layout);
RangeSetType* set2 = &relSecondarySet(layout);

DynamicVariableRelationType relDyn(set1, set2);
for(int i = 0; i < rel.fromSetSize(); i++)
Expand Down
13 changes: 8 additions & 5 deletions src/axom/multimat/multimat.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,16 +65,19 @@ class MMField2DTemplated;
*/
class MultiMat
{
public:
using BivariateSetType = slam::BivariateSet<>; //RangeSetType, RangeSetType>;
using ProductSetType = slam::ProductSet<>; //RangeSetType, RangeSetType>;

protected:
// SLAM Set type definitions
using SetPosType = slam::DefaultPositionType;
using SetElemType = slam::DefaultPositionType;
using SetType = slam::Set<SetPosType, SetElemType>;
using RangeSetType = slam::RangeSet<SetPosType, SetElemType>;

public:
// SLAM Bivariate set type definitions
using BivariateSetType = slam::BivariateSet<RangeSetType, RangeSetType>;
using ProductSetType = slam::ProductSet<RangeSetType, RangeSetType>;

private:
// SLAM Relation typedef
using IndBufferType = std::vector<SetPosType>;
template <typename T>
Expand All @@ -89,7 +92,7 @@ class MultiMat
RangeSetType>;

using DynamicVariableRelationType =
slam::DynamicVariableRelation<SetPosType, SetElemType>;
slam::DynamicVariableRelation<RangeSetType, RangeSetType>;
using OrderedSetType =
slam::OrderedSet<SetPosType,
SetElemType,
Expand Down
78 changes: 42 additions & 36 deletions src/axom/slam/BivariateMap.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,11 @@ template <typename T,
typename BSet = BivariateSet<>,
typename IndPol =
policies::STLVectorIndirection<typename BSet::PositionType, T>,
typename StrPol = policies::StrideOne<typename BSet::PositionType>>
class BivariateMap : public MapBase<typename BSet::PositionType>, public StrPol
typename StrPol = policies::StrideOne<typename BSet::PositionType>,
typename IfacePol = policies::VirtualInterface>
class BivariateMap
: public policies::MapInterface<IfacePol, typename BSet::PositionType>,
public StrPol
{
public:
using DataType = T;
Expand All @@ -94,14 +97,14 @@ class BivariateMap : public MapBase<typename BSet::PositionType>, public StrPol
using SetPosition = typename BSet::PositionType;
using SetElement = typename BSet::ElementType;

using SetType = slam::RangeSet<SetPosition, SetElement>;
using MapType = Map<DataType, SetType, IndPol, StrPol>;
using OrderedSetType = typename BSet::OrderedSetType;
using SetType = typename slam::RangeSet<SetPosition, SetElement>::ConcreteSet;
using MapType = Map<DataType, SetType, IndPol, StrPol, IfacePol>;
using OrderedSetType = typename BSet::SubsetType;

using BivariateMapType = BivariateMap<DataType, BSet, IndPol, StrPol>;
using BivariateMapType = BivariateMap<DataType, BSet, IndPol, StrPol, IfacePol>;

using SubMapType = SubMap<BivariateMapType, SetType>;
using ConstSubMapType = const SubMap<const BivariateMapType, SetType>;
using SubMapType = SubMap<BivariateMapType, SetType, IfacePol>;
using ConstSubMapType = const SubMap<const BivariateMapType, SetType, IfacePol>;
using SubMapIterator = typename SubMapType::SubMapIterator;

using NullBivariateSetType =
Expand All @@ -110,6 +113,12 @@ class BivariateMap : public MapBase<typename BSet::PositionType>, public StrPol
private:
static const NullBivariateSetType s_nullBiSet;

public:
using ConcreteMap =
BivariateMap<T, BSet, IndPol, StrPol, policies::ConcreteInterface>;
using VirtualMap =
BivariateMap<T, BSet, IndPol, StrPol, policies::VirtualInterface>;

public:
/**
* \brief Constructor for a BivariateMap
Expand All @@ -123,14 +132,13 @@ class BivariateMap : public MapBase<typename BSet::PositionType>, public StrPol
* \note When using a compile time StridePolicy, \a stride must be equal to
* \a StridePolicy::stride(), when provided.
*/

BivariateMap(const BivariateSetType* bSet = &s_nullBiSet,
DataType defaultValue = DataType(),
SetPosition stride = StridePolicyType::DEFAULT_VALUE)
SetPosition stride = StridePolicyType::DEFAULT_VALUE,
int allocatorID = axom::getDefaultAllocatorID())
: StridePolicyType(stride)
, m_bset(bSet)
, m_map(SetType(bSet->size()), defaultValue, stride)
, m_managesBSet(false)
, m_map(SetType(bSet->size()), defaultValue, stride, allocatorID)
{ }

// (KW) Problem -- does not work with RelationSet
Expand All @@ -141,8 +149,8 @@ class BivariateMap : public MapBase<typename BSet::PositionType>, public StrPol
{
using OuterSet = const typename BivariateSetRetType::FirstSetType;
using InnerSet = const typename BivariateSetRetType::SecondSetType;
OuterSet* outer = dynamic_cast<OuterSet*>(m_bset->getFirstSet());
InnerSet* inner = dynamic_cast<InnerSet*>(m_bset->getSecondSet());
OuterSet* outer = dynamic_cast<OuterSet*>(set()->getFirstSet());
InnerSet* inner = dynamic_cast<InnerSet*>(set()->getSecondSet());

return BivariateSetRetType(outer, inner);
}
Expand Down Expand Up @@ -185,15 +193,15 @@ class BivariateMap : public MapBase<typename BSet::PositionType>, public StrPol
const ConstSubMapType operator()(SetPosition firstIdx) const
{
verifyFirstSetIndex(firstIdx);
auto s = m_bset->elementRangeSet(firstIdx);
auto s = set()->elementRangeSet(firstIdx);
const bool hasInd = submapIndicesHaveIndirection();
return ConstSubMapType(this, s, hasInd);
}

SubMapType operator()(SetPosition firstIdx)
{
verifyFirstSetIndex(firstIdx);
auto s = m_bset->elementRangeSet(firstIdx);
auto s = set()->elementRangeSet(firstIdx);
const bool hasInd = submapIndicesHaveIndirection();
return SubMapType(this, s, hasInd);
}
Expand Down Expand Up @@ -235,7 +243,7 @@ class BivariateMap : public MapBase<typename BSet::PositionType>, public StrPol
*/
const DataType* findValue(SetPosition s1, SetPosition s2, SetPosition comp = 0) const
{
SetPosition i = m_bset->findElementFlatIndex(s1, s2);
SetPosition i = set()->findElementFlatIndex(s1, s2);
if(i == BivariateSetType::INVALID_POS)
{
//the BivariateSet does not contain this index pair
Expand All @@ -246,7 +254,7 @@ class BivariateMap : public MapBase<typename BSet::PositionType>, public StrPol

DataType* findValue(SetPosition s1, SetPosition s2, SetPosition comp = 0)
{
SetPosition i = m_bset->findElementFlatIndex(s1, s2);
SetPosition i = set()->findElementFlatIndex(s1, s2);
if(i == BivariateSetType::INVALID_POS)
{
//the BivariateSet does not contain this index pair
Expand All @@ -269,7 +277,7 @@ class BivariateMap : public MapBase<typename BSet::PositionType>, public StrPol
*/
SetPosition index(SetPosition s1, SetPosition s2) const
{
return m_bset->findElementIndex(s1, s2);
return set()->findElementIndex(s1, s2);
}

/**
Expand All @@ -280,7 +288,7 @@ class BivariateMap : public MapBase<typename BSet::PositionType>, public StrPol
*/
OrderedSetType indexSet(SetPosition s1) const
{
return m_bset->getElements(s1);
return set()->getElements(s1);
}

/**
Expand All @@ -289,7 +297,7 @@ class BivariateMap : public MapBase<typename BSet::PositionType>, public StrPol
*/
inline SetPosition flatIndex(SetPosition s1, SetPosition s2) const
{
return m_bset->findElementFlatIndex(s1, s2);
return set()->findElementFlatIndex(s1, s2);
}

/// @}
Expand All @@ -315,7 +323,7 @@ class BivariateMap : public MapBase<typename BSet::PositionType>, public StrPol
constexpr bool submapIndicesHaveIndirection() const
{
return traits::indices_use_indirection<BivariateSetType>::value ||
(m_bset->getSecondSet()->at(0) != 0);
(set()->getSecondSet()->at(0) != 0);
}

public:
Expand Down Expand Up @@ -511,25 +519,25 @@ class BivariateMap : public MapBase<typename BSet::PositionType>, public StrPol
const MapType* getMap() const { return &m_map; }
MapType* getMap() { return &m_map; }

virtual bool isValid(bool verboseOutput = false) const override
bool isValid(bool verboseOutput = false) const
{
return m_bset->isValid(verboseOutput) && m_map.isValid(verboseOutput);
return set()->isValid(verboseOutput) && m_map.isValid(verboseOutput);
}

/// \name BivariateMap cardinality functions
/// @{
///

/** \brief Returns the BivariateSet size. */
SetPosition size() const override { return m_bset->size(); }
SetPosition size() const { return set()->size(); }
/** \brief Returns the BivariateSet size. */
SetPosition totalSize() const { return m_bset->size(); }
SetPosition totalSize() const { return set()->size(); }

SetPosition firstSetSize() const { return m_bset->firstSetSize(); }
SetPosition secondSetSize() const { return m_bset->secondSetSize(); }
SetPosition firstSetSize() const { return set()->firstSetSize(); }
SetPosition secondSetSize() const { return set()->secondSetSize(); }
/** \brief Returns the number of the BivariateSet ordered pairs with
* the given first set index. */
SetPosition size(SetPosition s) const { return m_bset->size(s); }
SetPosition size(SetPosition s) const { return set()->size(s); }
/** \brief Return the number of components of the map */
SetPosition numComp() const { return StrPol::stride(); }

Expand Down Expand Up @@ -559,11 +567,11 @@ class BivariateMap : public MapBase<typename BSet::PositionType>, public StrPol
/** \brief Check the indices (DenseIndex) are valid */
void verifyPosition(SetPosition s1, SetPosition s2) const
{
m_bset->verifyPosition(s1, s2);
set()->verifyPosition(s1, s2);
}

/** \brief Check the given ElementFlatIndex is valid. */
void verifyPosition(SetPosition AXOM_DEBUG_PARAM(pos)) const override
void verifyPosition(SetPosition AXOM_DEBUG_PARAM(pos)) const
{
SLIC_ASSERT_MSG(pos >= 0 && pos < SetPosition(m_map.size()),
"Attempted to access element "
Expand All @@ -582,13 +590,11 @@ class BivariateMap : public MapBase<typename BSet::PositionType>, public StrPol
private:
const BivariateSetType* m_bset;
MapType m_map;
bool m_managesBSet;

}; //end BivariateMap

template <typename T, typename BSet, typename IndPol, typename StrPol>
typename BivariateMap<T, BSet, IndPol, StrPol>::NullBivariateSetType const
BivariateMap<T, BSet, IndPol, StrPol>::s_nullBiSet;
template <typename T, typename BSet, typename IndPol, typename StrPol, typename IfacePol>
typename BivariateMap<T, BSet, IndPol, StrPol, IfacePol>::NullBivariateSetType const
BivariateMap<T, BSet, IndPol, StrPol, IfacePol>::s_nullBiSet;

} // end namespace slam
} // end namespace axom
Expand Down
13 changes: 7 additions & 6 deletions src/axom/slam/BivariateSet.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "axom/slam/OrderedSet.hpp"
#include "axom/slam/NullSet.hpp"
#include "axom/slam/RangeSet.hpp"
#include "axom/slam/policies/PolicyTraits.hpp"

#include <cassert>
#include <type_traits>
Expand Down Expand Up @@ -85,7 +86,7 @@ class BivariateSet
using ElementType = typename FirstSetType::ElementType;
using NullSetType = NullSet<PositionType, ElementType>;

using OrderedSetType =
using SubsetType =
OrderedSet<PositionType,
ElementType,
policies::RuntimeSize<PositionType>,
Expand Down Expand Up @@ -206,13 +207,13 @@ class BivariateSet
* \return An OrderedSet containing the elements
* \pre 0 <= pos1 <= set1.size()
*/
virtual const OrderedSetType getElements(PositionType s1) const = 0;
virtual SubsetType getElements(PositionType s1) const = 0;

virtual bool isValid(bool verboseOutput = false) const;

private:
virtual void verifyPosition(PositionType s1, PositionType s2) const = 0;

private:
template <typename SetType>
typename std::enable_if<std::is_abstract<SetType>::value, PositionType>::type
getSize(const SetType* s) const
Expand Down Expand Up @@ -266,7 +267,7 @@ class NullBivariateSet : public BivariateSet<SetType1, SetType2>
using BSet = BivariateSet<FirstSetType, SecondSetType>;
using PositionType = typename BSet::PositionType;
using ElementType = typename BSet::ElementType;
using OrderedSetType = typename BSet::OrderedSetType;
using SubsetType = typename BSet::SubsetType;
using RangeSetType = typename BSet::RangeSetType;

public:
Expand Down Expand Up @@ -301,9 +302,9 @@ class NullBivariateSet : public BivariateSet<SetType1, SetType2>

PositionType size(PositionType) const override { return PositionType(); }

const OrderedSetType getElements(PositionType) const override
SubsetType getElements(PositionType) const override
{
using OrderedSetBuilder = typename OrderedSetType::SetBuilder;
using OrderedSetBuilder = typename SubsetType::SetBuilder;
return OrderedSetBuilder();
}

Expand Down
4 changes: 4 additions & 0 deletions src/axom/slam/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ set(slam_headers
policies/IndirectionPolicies.hpp
policies/SubsettingPolicies.hpp
policies/PolicyTraits.hpp
policies/InterfacePolicies.hpp
policies/SetInterfacePolicies.hpp
policies/MapInterfacePolicies.hpp
policies/BivariateSetInterfacePolicies.hpp

# SRM Set headers
IndirectionSet.hpp
Expand Down
Loading

0 comments on commit 4267397

Please sign in to comment.