Loading...
Searching...
No Matches
EntityRep.hpp
//===========================================================================
//
// File: EntityRep.hpp
//
// Created: Tue Jun 9 11:11:24 2009
//
// Author(s): Atgeirr F Rasmussen <atgeirr@sintef.no>
// B�rd Skaflestad <bard.skaflestad@sintef.no>
//
// $Date$
//
// $Revision$
//
//===========================================================================
/*
Copyright 2009, 2010 SINTEF ICT, Applied Mathematics.
Copyright 2009, 2010 Statoil ASA.
This file is part of The Open Porous Media project (OPM).
OPM is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OPM is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with OPM. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef OPM_ENTITYREP_HEADER
#define OPM_ENTITYREP_HEADER
// -------------------------------------------------------------------
// -> Layering violation. --------------------------------------------
//
// We need a unary operator-() for class Dune::FieldVector<K,n>
// within method Dune::SignedEntityVariable<T,codim>::operator[](),
// but Dune::FieldVector<K,n> does not provide such an operator.
//
// Warning suppression for Dune includes.
#include <opm/grid/utility/platform_dependent/disable_warnings.h>
#include <dune/common/fvector.hh>
#include <opm/grid/utility/platform_dependent/reenable_warnings.h>
namespace Dune
{
template<typename K, int n>
FieldVector<K,n>
operator- (const FieldVector<K,n>& v)
{
// Assume 'K' supports a single parameter constructor. The
// assumption holds for all standard C++ built-in arithmetic
// types such as 'int', 'float', and 'complex<double>'.
//
return FieldVector<K,n>(K(0)) - v;
}
}
//
// <- Layering violation. --------------------------------------------
// -------------------------------------------------------------------
//#include <opm/core/utility/SparseTable.hpp>
#include <opm/common/ErrorMacros.hpp>
#include <climits>
#include <vector>
namespace Dune
{
namespace cpgrid
{
template <int codim>
class EntityRep
{
public:
enum{ codimension=codim};
EntityRep()
: entityrep_(0)
{
}
EntityRep(int index_arg, bool orientation_arg)
: entityrep_(orientation_arg ? index_arg : ~index_arg)
{
assert(index_arg >= 0);
}
void setValue(int index_arg, bool orientation_arg)
{
assert(index_arg >= 0);
entityrep_ = orientation_arg ? index_arg : ~index_arg;
}
int index() const
{
return entityrep_ < 0 ? ~entityrep_ : entityrep_;
}
int signedIndex() const
{
return entityrep_;
}
bool orientation() const
{
return entityrep_ >= 0;
}
EntityRep opposite() const
{
return EntityRep(~entityrep_);
}
void increment()
{
if (entityrep_ < 0) {
--entityrep_;
} else {
++entityrep_;
}
}
bool operator<(const EntityRep& other) const
{
int i1 = index();
int i2 = other.index();
if (i1 < i2) return true;
if (orientation() && !other.orientation()) return true;
return false;
}
bool operator==(const EntityRep& other) const
{
return entityrep_ == other.entityrep_;
}
bool operator!=(const EntityRep& other) const
{
return !operator==(other);
}
enum { InvalidIndex = INT_MAX };
private:
explicit EntityRep(int erep)
: entityrep_(erep)
{
}
// Interior representation is documented in class main comment.
int entityrep_;
};
template <typename T>
class EntityVariableBase : private std::vector<T>
{
friend class CpGridData;
public:
typedef std::vector<T> V;
typedef typename std::vector<T>::iterator iterator;
typedef typename std::vector<T>::const_iterator const_iterator;
using V::empty;
using V::size;
using V::assign;
using V::begin;
using V::end;
using typename V::value_type;
using V::reserve;
using V::push_back;
using V::data;
using V::operator[];
using V::resize;
EntityVariableBase()
{
}
const T& get(int i) const
{
return V::operator[](i);
}
T& get(int i)
{
return V::operator[](i);
}
void swap(EntityVariableBase& other)
{
V::swap(static_cast<V&>(other));
}
};
template <typename T, int codim>
class EntityVariable : public EntityVariableBase<T>
{
public:
EntityVariable()
{
}
const T& operator[](const EntityRep<codim>& e) const
{
return EntityVariableBase<T>::get(e.index());
}
T& operator[](const EntityRep<codim>& e)
{
return EntityVariableBase<T>::get(e.index());
}
};
template <typename T, int codim>
class SignedEntityVariable : public EntityVariableBase<T>
{
public:
SignedEntityVariable()
{
}
const T operator[](const EntityRep<codim>& e) const
{
return e.orientation() ?
EntityVariableBase<T>::get(e.index()) :
-EntityVariableBase<T>::get(e.index());
}
};
} // namespace cpgrid
} // namespace Dune
#endif // OPM_ENTITYREP_HEADER
Dune::cpgrid::EntityRep
Represents an entity of a given codim, with positive or negative orientation.
Definition EntityRep.hpp:99
Dune::cpgrid::EntityRep::operator<
bool operator<(const EntityRep &other) const
Ordering relation used for maps etc.
Definition EntityRep.hpp:167
Dune::cpgrid::EntityRep::EntityRep
EntityRep(int index_arg, bool orientation_arg)
Constructor taking an entity index and an orientation.
Definition EntityRep.hpp:111
Dune::cpgrid::EntityRep::operator!=
bool operator!=(const EntityRep &other) const
Inequality operator.
Definition EntityRep.hpp:187
Dune::cpgrid::EntityRep::orientation
bool orientation() const
Returns true if the entity has positive orientation.
Definition EntityRep.hpp:140
Dune::cpgrid::EntityRep::setValue
void setValue(int index_arg, bool orientation_arg)
Set entity value.
Definition EntityRep.hpp:119
Dune::cpgrid::EntityRep::opposite
EntityRep opposite() const
Returns an EntityRep with opposite orientation.
Definition EntityRep.hpp:147
Dune::cpgrid::EntityRep::operator==
bool operator==(const EntityRep &other) const
Equality operator.
Definition EntityRep.hpp:179
Dune::cpgrid::EntityRep::index
int index() const
The (positive) index of an entity.
Definition EntityRep.hpp:126
Dune::cpgrid::EntityRep::EntityRep
EntityRep()
Default constructor.
Definition EntityRep.hpp:104
Dune::cpgrid::EntityRep::signedIndex
int signedIndex() const
The signed index that also tells us the orientation.
Definition EntityRep.hpp:132
Dune::cpgrid::EntityRep::increment
void increment()
Increments the entityrep's index() by one.
Definition EntityRep.hpp:153
Dune::cpgrid::EntityVariableBase::EntityVariableBase
EntityVariableBase()
Default constructor.
Definition EntityRep.hpp:239
Dune::cpgrid::EntityVariable::operator[]
const T & operator[](const EntityRep< codim > &e) const
Random access to the variable through an EntityRep.
Definition EntityRep.hpp:281
Dune::cpgrid::EntityVariable::operator[]
T & operator[](const EntityRep< codim > &e)
Random access to the variable through an EntityRep.
Definition EntityRep.hpp:288
Dune::cpgrid::EntityVariable::EntityVariable
EntityVariable()
Default constructor.
Definition EntityRep.hpp:275
Dune::cpgrid::SignedEntityVariable::operator[]
const T operator[](const EntityRep< codim > &e) const
Random access to the variable through an EntityRep.
Definition EntityRep.hpp:316
Dune::cpgrid::SignedEntityVariable::SignedEntityVariable
SignedEntityVariable()
Default constructor.
Definition EntityRep.hpp:310
Dune::cpgrid
Copyright 2019 Equinor AS.
Definition GridPartitioning.cpp:673
Dune
The namespace Dune is the main namespace for all Dune code.
Definition CartesianIndexMapper.hpp:10