Rename AutoDiff::ForwardBlock -> Opm::AutoDiffBlock.

Also moved AutoDiffHelpers.hpp content to Opm namespace, and modified other
files as required by these two changes.
This commit is contained in:
Atgeirr Flø Rasmussen 2013-09-19 12:53:28 +02:00
parent e9b933bf4f
commit 85f79c0e84
15 changed files with 118 additions and 105 deletions

View File

@ -111,7 +111,7 @@ fluxFunc(const std::vector<ADB>& m)
int main()
try
{
typedef AutoDiff::ForwardBlock<double> ADB;
typedef Opm::AutoDiffBlock<double> ADB;
typedef ADB::V V;
typedef ADB::M M;
@ -148,11 +148,11 @@ try
std::cerr << "Opm core " << clock.secsSinceLast() << std::endl;
// Define neighbourhood-derived operator matrices.
const HelperOps ops(grid);
const Opm::HelperOps ops(grid);
const int num_internal = ops.internal_faces.size();
std::cerr << "Topology matrices " << clock.secsSinceLast() << std::endl;
typedef AutoDiff::ForwardBlock<double> ADB;
typedef Opm::AutoDiffBlock<double> ADB;
typedef ADB::V V;
// q
@ -248,7 +248,7 @@ try
V sw1 = 0.5*V::Ones(nc,1);
const V ndp = (ops.ngrad * p1.matrix()).array();
const V dflux = mobtransf * ndp;
const UpwindSelector<double> upwind(grid, ops, dflux);
const Opm::UpwindSelector<double> upwind(grid, ops, dflux);
const V pv = Eigen::Map<const V>(props.porosity(), nc, 1)
* Eigen::Map<const V>(grid.cell_volumes, nc, 1);
const double dt = 0.0005;

View File

@ -58,8 +58,6 @@ try
const Opm::BlackoilPropertiesBasic oldprops(param, 2, nc);
const Opm::BlackoilPropsAd props(oldprops);
typedef AutoDiff::ForwardBlock<double> ADB;
Wells* wells = create_wells(2, 2, 5);
const double inj_frac[] = { 1.0, 0.0 };
const double prod_frac[] = { 0.0, 0.0 };

View File

@ -25,11 +25,11 @@
#include <vector>
#include <cassert>
namespace AutoDiff
namespace Opm
{
template <typename Scalar>
class ForwardBlock
class AutoDiffBlock
{
public:
/// Underlying types for scalar vectors and jacobians.
@ -37,14 +37,14 @@ namespace AutoDiff
typedef Eigen::SparseMatrix<Scalar> M;
/// Named constructor pattern used here.
static ForwardBlock null()
static AutoDiffBlock null()
{
V val;
std::vector<M> jac;
return ForwardBlock(val, jac);
return AutoDiffBlock(val, jac);
}
static ForwardBlock constant(const V& val, const std::vector<int>& blocksizes)
static AutoDiffBlock constant(const V& val, const std::vector<int>& blocksizes)
{
std::vector<M> jac;
const int num_elem = val.size();
@ -54,10 +54,10 @@ namespace AutoDiff
for (int i = 0; i < num_blocks; ++i) {
jac[i] = M(num_elem, blocksizes[i]);
}
return ForwardBlock(val, jac);
return AutoDiffBlock(val, jac);
}
static ForwardBlock variable(const int index, const V& val, const std::vector<int>& blocksizes)
static AutoDiffBlock variable(const int index, const V& val, const std::vector<int>& blocksizes)
{
std::vector<M> jac;
const int num_elem = val.size();
@ -73,24 +73,24 @@ namespace AutoDiff
for (typename M::Index row = 0; row < val.size(); ++row) {
jac[index].insert(row, row) = Scalar(1.0);
}
return ForwardBlock(val, jac);
return AutoDiffBlock(val, jac);
}
static ForwardBlock function(const V& val, const std::vector<M>& jac)
static AutoDiffBlock function(const V& val, const std::vector<M>& jac)
{
return ForwardBlock(val, jac);
return AutoDiffBlock(val, jac);
}
/// Construct a set of primary variables,
/// each initialized to a given vector.
static std::vector<ForwardBlock> variables(const std::vector<V>& initial_values)
static std::vector<AutoDiffBlock> variables(const std::vector<V>& initial_values)
{
const int num_vars = initial_values.size();
std::vector<int> bpat;
for (int v = 0; v < num_vars; ++v) {
bpat.push_back(initial_values[v].size());
}
std::vector<ForwardBlock> vars;
std::vector<AutoDiffBlock> vars;
for (int v = 0; v < num_vars; ++v) {
vars.emplace_back(variable(v, initial_values[v], bpat));
}
@ -98,7 +98,7 @@ namespace AutoDiff
}
/// Operator +=
ForwardBlock& operator+=(const ForwardBlock& rhs)
AutoDiffBlock& operator+=(const AutoDiffBlock& rhs)
{
assert (numBlocks() == rhs.numBlocks());
assert (value().size() == rhs.value().size());
@ -116,7 +116,7 @@ namespace AutoDiff
}
/// Operator +
ForwardBlock operator+(const ForwardBlock& rhs) const
AutoDiffBlock operator+(const AutoDiffBlock& rhs) const
{
std::vector<M> jac = jac_;
assert(numBlocks() == rhs.numBlocks());
@ -130,7 +130,7 @@ namespace AutoDiff
}
/// Operator -
ForwardBlock operator-(const ForwardBlock& rhs) const
AutoDiffBlock operator-(const AutoDiffBlock& rhs) const
{
std::vector<M> jac = jac_;
assert(numBlocks() == rhs.numBlocks());
@ -144,7 +144,7 @@ namespace AutoDiff
}
/// Operator *
ForwardBlock operator*(const ForwardBlock& rhs) const
AutoDiffBlock operator*(const AutoDiffBlock& rhs) const
{
int num_blocks = numBlocks();
std::vector<M> jac(num_blocks);
@ -161,7 +161,7 @@ namespace AutoDiff
}
/// Operator /
ForwardBlock operator/(const ForwardBlock& rhs) const
AutoDiffBlock operator/(const AutoDiffBlock& rhs) const
{
int num_blocks = numBlocks();
std::vector<M> jac(num_blocks);
@ -226,8 +226,8 @@ namespace AutoDiff
}
private:
ForwardBlock(const V& val,
const std::vector<M>& jac)
AutoDiffBlock(const V& val,
const std::vector<M>& jac)
: val_(val), jac_(jac)
{
#ifndef NDEBUG
@ -241,12 +241,12 @@ namespace AutoDiff
V val_;
std::vector<M> jac_;
};
};
template <class Ostream, typename Scalar>
Ostream&
operator<<(Ostream& os, const ForwardBlock<Scalar>& fw)
operator<<(Ostream& os, const AutoDiffBlock<Scalar>& fw)
{
return fw.print(os);
}
@ -254,81 +254,81 @@ namespace AutoDiff
/// Multiply with sparse matrix from the left.
template <typename Scalar>
ForwardBlock<Scalar> operator*(const typename ForwardBlock<Scalar>::M& lhs,
const ForwardBlock<Scalar>& rhs)
AutoDiffBlock<Scalar> operator*(const typename AutoDiffBlock<Scalar>::M& lhs,
const AutoDiffBlock<Scalar>& rhs)
{
int num_blocks = rhs.numBlocks();
std::vector<typename ForwardBlock<Scalar>::M> jac(num_blocks);
std::vector<typename AutoDiffBlock<Scalar>::M> jac(num_blocks);
assert(lhs.cols() == rhs.value().rows());
for (int block = 0; block < num_blocks; ++block) {
jac[block] = lhs*rhs.derivative()[block];
}
typename ForwardBlock<Scalar>::V val = lhs*rhs.value().matrix();
return ForwardBlock<Scalar>::function(val, jac);
typename AutoDiffBlock<Scalar>::V val = lhs*rhs.value().matrix();
return AutoDiffBlock<Scalar>::function(val, jac);
}
template <typename Scalar>
ForwardBlock<Scalar> operator*(const typename ForwardBlock<Scalar>::V& lhs,
const ForwardBlock<Scalar>& rhs)
AutoDiffBlock<Scalar> operator*(const typename AutoDiffBlock<Scalar>::V& lhs,
const AutoDiffBlock<Scalar>& rhs)
{
return ForwardBlock<Scalar>::constant(lhs, rhs.blockPattern()) * rhs;
return AutoDiffBlock<Scalar>::constant(lhs, rhs.blockPattern()) * rhs;
}
template <typename Scalar>
ForwardBlock<Scalar> operator*(const ForwardBlock<Scalar>& lhs,
const typename ForwardBlock<Scalar>::V& rhs)
AutoDiffBlock<Scalar> operator*(const AutoDiffBlock<Scalar>& lhs,
const typename AutoDiffBlock<Scalar>::V& rhs)
{
return rhs * lhs; // Commutative operation.
}
template <typename Scalar>
ForwardBlock<Scalar> operator+(const typename ForwardBlock<Scalar>::V& lhs,
const ForwardBlock<Scalar>& rhs)
AutoDiffBlock<Scalar> operator+(const typename AutoDiffBlock<Scalar>::V& lhs,
const AutoDiffBlock<Scalar>& rhs)
{
return ForwardBlock<Scalar>::constant(lhs, rhs.blockPattern()) + rhs;
return AutoDiffBlock<Scalar>::constant(lhs, rhs.blockPattern()) + rhs;
}
template <typename Scalar>
ForwardBlock<Scalar> operator+(const ForwardBlock<Scalar>& lhs,
const typename ForwardBlock<Scalar>::V& rhs)
AutoDiffBlock<Scalar> operator+(const AutoDiffBlock<Scalar>& lhs,
const typename AutoDiffBlock<Scalar>::V& rhs)
{
return rhs + lhs; // Commutative operation.
}
template <typename Scalar>
ForwardBlock<Scalar> operator-(const typename ForwardBlock<Scalar>::V& lhs,
const ForwardBlock<Scalar>& rhs)
AutoDiffBlock<Scalar> operator-(const typename AutoDiffBlock<Scalar>::V& lhs,
const AutoDiffBlock<Scalar>& rhs)
{
return ForwardBlock<Scalar>::constant(lhs, rhs.blockPattern()) - rhs;
return AutoDiffBlock<Scalar>::constant(lhs, rhs.blockPattern()) - rhs;
}
template <typename Scalar>
ForwardBlock<Scalar> operator-(const ForwardBlock<Scalar>& lhs,
const typename ForwardBlock<Scalar>::V& rhs)
AutoDiffBlock<Scalar> operator-(const AutoDiffBlock<Scalar>& lhs,
const typename AutoDiffBlock<Scalar>::V& rhs)
{
return lhs - ForwardBlock<Scalar>::constant(rhs, lhs.blockPattern());
return lhs - AutoDiffBlock<Scalar>::constant(rhs, lhs.blockPattern());
}
template <typename Scalar>
ForwardBlock<Scalar> operator/(const typename ForwardBlock<Scalar>::V& lhs,
const ForwardBlock<Scalar>& rhs)
AutoDiffBlock<Scalar> operator/(const typename AutoDiffBlock<Scalar>::V& lhs,
const AutoDiffBlock<Scalar>& rhs)
{
return ForwardBlock<Scalar>::constant(lhs, rhs.blockPattern()) / rhs;
return AutoDiffBlock<Scalar>::constant(lhs, rhs.blockPattern()) / rhs;
}
template <typename Scalar>
ForwardBlock<Scalar> operator/(const ForwardBlock<Scalar>& lhs,
const typename ForwardBlock<Scalar>::V& rhs)
AutoDiffBlock<Scalar> operator/(const AutoDiffBlock<Scalar>& lhs,
const typename AutoDiffBlock<Scalar>::V& rhs)
{
return lhs / ForwardBlock<Scalar>::constant(rhs, lhs.blockPattern());
return lhs / AutoDiffBlock<Scalar>::constant(rhs, lhs.blockPattern());
}
@ -340,15 +340,15 @@ namespace AutoDiff
* @return The product
*/
template <typename Scalar>
ForwardBlock<Scalar> operator*(const ForwardBlock<Scalar>& lhs,
const Scalar& rhs)
AutoDiffBlock<Scalar> operator*(const AutoDiffBlock<Scalar>& lhs,
const Scalar& rhs)
{
std::vector< typename ForwardBlock<Scalar>::M > jac;
std::vector< typename AutoDiffBlock<Scalar>::M > jac;
jac.reserve( lhs.numBlocks() );
for (int block=0; block<lhs.numBlocks(); block++) {
jac.emplace_back( lhs.derivative()[block] * rhs );
}
return ForwardBlock<Scalar>::function( lhs.value() * rhs, jac );
return AutoDiffBlock<Scalar>::function( lhs.value() * rhs, jac );
}
@ -360,14 +360,14 @@ namespace AutoDiff
* @return The product
*/
template <typename Scalar>
ForwardBlock<Scalar> operator*(const Scalar& lhs,
const ForwardBlock<Scalar>& rhs)
AutoDiffBlock<Scalar> operator*(const Scalar& lhs,
const AutoDiffBlock<Scalar>& rhs)
{
return rhs * lhs; // Commutative operation.
}
} // namespace Autodiff
} // namespace Opm

View File

@ -26,14 +26,17 @@
#include <iostream>
namespace Opm
{
// -------------------- class HelperOps --------------------
/// Contains vectors and sparse matrices that represent subsets or
/// operations on (AD or regular) vectors of data.
struct HelperOps
{
typedef AutoDiff::ForwardBlock<double>::M M;
typedef AutoDiff::ForwardBlock<double>::V V;
typedef AutoDiffBlock<double>::M M;
typedef AutoDiffBlock<double>::V V;
/// A list of internal faces.
typedef Eigen::Array<int, Eigen::Dynamic, 1> IFaces;
@ -202,7 +205,7 @@ namespace {
template <typename Scalar>
class UpwindSelector {
public:
typedef AutoDiff::ForwardBlock<Scalar> ADB;
typedef AutoDiffBlock<Scalar> ADB;
UpwindSelector(const UnstructuredGrid& g,
const HelperOps& h,
@ -297,11 +300,11 @@ namespace {
/// Returns x(indices).
template <typename Scalar, class IntVec>
AutoDiff::ForwardBlock<Scalar>
subset(const AutoDiff::ForwardBlock<Scalar>& x,
AutoDiffBlock<Scalar>
subset(const AutoDiffBlock<Scalar>& x,
const IntVec& indices)
{
return ::constructSubsetSparseMatrix<Scalar>(x.value().size(), indices) * x;
return constructSubsetSparseMatrix<Scalar>(x.value().size(), indices) * x;
}
@ -312,19 +315,19 @@ Eigen::Array<Scalar, Eigen::Dynamic, 1>
subset(const Eigen::Array<Scalar, Eigen::Dynamic, 1>& x,
const IntVec& indices)
{
return (::constructSubsetSparseMatrix<Scalar>(x.size(), indices) * x.matrix()).array();
return (constructSubsetSparseMatrix<Scalar>(x.size(), indices) * x.matrix()).array();
}
/// Returns v where v(indices) == x, v(!indices) == 0 and v.size() == n.
template <typename Scalar, class IntVec>
AutoDiff::ForwardBlock<Scalar>
superset(const AutoDiff::ForwardBlock<Scalar>& x,
AutoDiffBlock<Scalar>
superset(const AutoDiffBlock<Scalar>& x,
const IntVec& indices,
const int n)
{
return ::constructSupersetSparseMatrix<Scalar>(n, indices) * x;
return constructSupersetSparseMatrix<Scalar>(n, indices) * x;
}
@ -336,7 +339,7 @@ superset(const Eigen::Array<Scalar, Eigen::Dynamic, 1>& x,
const IntVec& indices,
const int n)
{
return ::constructSupersetSparseMatrix<Scalar>(n, indices) * x.matrix();
return constructSupersetSparseMatrix<Scalar>(n, indices) * x.matrix();
}
@ -345,10 +348,10 @@ superset(const Eigen::Array<Scalar, Eigen::Dynamic, 1>& x,
/// elements of d on the diagonal.
/// Need to mark this as inline since it is defined in a header and not a template.
inline
AutoDiff::ForwardBlock<double>::M
spdiag(const AutoDiff::ForwardBlock<double>::V& d)
AutoDiffBlock<double>::M
spdiag(const AutoDiffBlock<double>::V& d)
{
typedef AutoDiff::ForwardBlock<double>::M M;
typedef AutoDiffBlock<double>::M M;
const int n = d.size();
M mat(n, n);
@ -367,7 +370,7 @@ spdiag(const AutoDiff::ForwardBlock<double>::V& d)
template <typename Scalar>
class Selector {
public:
typedef AutoDiff::ForwardBlock<Scalar> ADB;
typedef AutoDiffBlock<Scalar> ADB;
Selector(const typename ADB::V& selection_basis)
{
@ -421,10 +424,10 @@ spdiag(const AutoDiff::ForwardBlock<double>::V& d)
/// Returns the input expression, but with all Jacobians collapsed to one.
inline
AutoDiff::ForwardBlock<double>
collapseJacs(const AutoDiff::ForwardBlock<double>& x)
AutoDiffBlock<double>
collapseJacs(const AutoDiffBlock<double>& x)
{
typedef AutoDiff::ForwardBlock<double> ADB;
typedef AutoDiffBlock<double> ADB;
const int nb = x.numBlocks();
typedef Eigen::Triplet<double> Tri;
int nnz = 0;
@ -457,9 +460,9 @@ collapseJacs(const AutoDiff::ForwardBlock<double>& x)
/// Returns the vertical concatenation [ x; y ] of the inputs.
inline
AutoDiff::ForwardBlock<double>
vertcat(const AutoDiff::ForwardBlock<double>& x,
const AutoDiff::ForwardBlock<double>& y)
AutoDiffBlock<double>
vertcat(const AutoDiffBlock<double>& x,
const AutoDiffBlock<double>& y)
{
const int nx = x.size();
const int ny = y.size();
@ -585,4 +588,7 @@ inline Eigen::ArrayXd sign (const Eigen::ArrayXd& x)
return retval;
}
} // namespace Opm
#endif // OPM_AUTODIFFHELPERS_HEADER_INCLUDED

View File

@ -67,7 +67,7 @@ namespace Opm
// Fluid interface //
////////////////////////////
typedef AutoDiff::ForwardBlock<double> ADB;
typedef AutoDiffBlock<double> ADB;
typedef ADB::V V;
typedef std::vector<int> Cells;

View File

@ -75,7 +75,7 @@ namespace Opm
// Fluid interface //
////////////////////////////
typedef AutoDiff::ForwardBlock<double> ADB;
typedef AutoDiffBlock<double> ADB;
typedef ADB::V V;
typedef std::vector<int> Cells;

View File

@ -64,7 +64,7 @@ namespace Opm
// Fluid interface //
////////////////////////////
typedef AutoDiff::ForwardBlock<double> ADB;
typedef AutoDiffBlock<double> ADB;
typedef ADB::V V;
typedef ADB::M M;
typedef std::vector<int> Cells;

View File

@ -37,6 +37,7 @@
#include <iostream>
#include <iomanip>
// A debugging utility.
#define DUMP(foo) \
do { \
std::cout << "==========================================\n" \
@ -44,7 +45,11 @@
<< collapseJacs(foo) << std::endl; \
} while (0)
typedef AutoDiff::ForwardBlock<double> ADB;
namespace Opm {
typedef AutoDiffBlock<double> ADB;
typedef ADB::V V;
typedef ADB::M M;
typedef Eigen::Array<double,
@ -69,7 +74,7 @@ namespace {
template <class GeoProps>
AutoDiff::ForwardBlock<double>::M
AutoDiffBlock<double>::M
gravityOperator(const UnstructuredGrid& grid,
const HelperOps& ops ,
const GeoProps& geo )
@ -86,8 +91,8 @@ namespace {
}
}
typedef AutoDiff::ForwardBlock<double>::V V;
typedef AutoDiff::ForwardBlock<double>::M M;
typedef AutoDiffBlock<double>::V V;
typedef AutoDiffBlock<double>::M M;
const V& gpot = geo.gravityPotential();
const V& trans = geo.transmissibility();
@ -182,8 +187,6 @@ namespace {
namespace Opm {
FullyImplicitBlackoilSolver::
FullyImplicitBlackoilSolver(const UnstructuredGrid& grid ,

View File

@ -60,7 +60,7 @@ namespace Opm {
private:
// Types and enums
typedef AutoDiff::ForwardBlock<double> ADB;
typedef AutoDiffBlock<double> ADB;
typedef ADB::V V;
typedef ADB::M M;
typedef Eigen::Array<double,

View File

@ -29,9 +29,10 @@
#include <iostream>
#include <iomanip>
namespace Opm {
// Repeated from inside ImpesTPFAAD for convenience.
typedef AutoDiff::ForwardBlock<double> ADB;
typedef AutoDiffBlock<double> ADB;
typedef ADB::V V;
typedef ADB::M M;
@ -48,7 +49,7 @@ namespace {
}
template <class GeoProps>
AutoDiff::ForwardBlock<double>::M
AutoDiffBlock<double>::M
gravityOperator(const UnstructuredGrid& grid,
const HelperOps& ops ,
const GeoProps& geo )
@ -65,8 +66,8 @@ namespace {
}
}
typedef AutoDiff::ForwardBlock<double>::V V;
typedef AutoDiff::ForwardBlock<double>::M M;
typedef AutoDiffBlock<double>::V V;
typedef AutoDiffBlock<double>::M M;
const V& gpot = geo.gravityPotential();
const V& trans = geo.transmissibility();
@ -122,7 +123,6 @@ namespace {
} // anonymous namespace
namespace Opm {

View File

@ -63,7 +63,7 @@ namespace Opm {
ImpesTPFAAD& operator=(const ImpesTPFAAD& rhs);
// Types
typedef AutoDiff::ForwardBlock<double> ADB;
typedef AutoDiffBlock<double> ADB;
typedef ADB::V V;
typedef ADB::M M;
typedef Eigen::Array<double,

View File

@ -68,7 +68,7 @@ namespace Opm
TwophaseState& state);
private:
typedef AutoDiff::ForwardBlock<double> ADB;
typedef AutoDiffBlock<double> ADB;
typedef ADB::V V;
typedef ADB::M M;

View File

@ -32,6 +32,8 @@
#include <Eigen/Eigen>
#include <Eigen/Sparse>
using namespace Opm;
namespace {
template <typename Scalar>
bool
@ -73,7 +75,7 @@ namespace {
BOOST_AUTO_TEST_CASE(ConstantInitialisation)
{
typedef AutoDiff::ForwardBlock<double> ADB;
typedef AutoDiffBlock<double> ADB;
std::vector<int> blocksizes = { 3, 1, 2 };
@ -92,7 +94,7 @@ BOOST_AUTO_TEST_CASE(ConstantInitialisation)
BOOST_AUTO_TEST_CASE(VariableInitialisation)
{
typedef AutoDiff::ForwardBlock<double> ADB;
typedef AutoDiffBlock<double> ADB;
std::vector<int> blocksizes = { 3, 1, 2 };
@ -119,7 +121,7 @@ BOOST_AUTO_TEST_CASE(VariableInitialisation)
BOOST_AUTO_TEST_CASE(FunctionInitialisation)
{
typedef AutoDiff::ForwardBlock<double> ADB;
typedef AutoDiffBlock<double> ADB;
std::vector<int> blocksizes = { 3, 1, 2 };
std::vector<int>::size_type num_blocks = blocksizes.size();
@ -150,7 +152,7 @@ BOOST_AUTO_TEST_CASE(FunctionInitialisation)
BOOST_AUTO_TEST_CASE(Addition)
{
typedef AutoDiff::ForwardBlock<double> ADB;
typedef AutoDiffBlock<double> ADB;
std::vector<int> blocksizes = { 3, 1, 2 };
ADB::V va(3);
@ -195,7 +197,7 @@ BOOST_AUTO_TEST_CASE(Addition)
int main()
try
{
typedef AutoDiff::ForwardBlock<double> ADB;
typedef AutoDiffBlock<double> ADB;
std::vector<int> blocksizes = { 3, 1, 2 };
int num_blocks = blocksizes.size();
ADB::V v1(3);

View File

@ -34,9 +34,11 @@
#include <iostream>
using namespace Opm;
BOOST_AUTO_TEST_CASE(ScalarMultiplication)
{
typedef AutoDiff::ForwardBlock<double> ADB;
typedef AutoDiffBlock<double> ADB;
std::vector<int> blocksizes = { 3, 1, 2 };
ADB::V vx(3);

View File

@ -32,6 +32,8 @@
#include <iostream>
using namespace Opm;
BOOST_AUTO_TEST_CASE(OneArgConstr)
{
const int num = 4;