Skip to content
Snippets Groups Projects
Commit 4135b1e6 authored by Christoph Lehmann's avatar Christoph Lehmann
Browse files

[MaL] extended matrix traits to matrix and vector traits

parent 023baf73
No related branches found
No related tags found
No related merge requests found
/**
* \copyright
* Copyright (c) 2012-2016, OpenGeoSys Community (http://www.opengeosys.org)
* Distributed under a Modified BSD License.
* See accompanying file LICENSE.txt or
* http://www.opengeosys.org/project/license
*
*/
#include "MatrixVectorTraits.h"
#ifdef OGS_USE_EIGEN
namespace MathLib
{
std::unique_ptr<Eigen::MatrixXd>
MatrixVectorTraits<Eigen::MatrixXd>::
newInstance()
{
return std::unique_ptr<Eigen::MatrixXd>(new Eigen::MatrixXd);
}
std::unique_ptr<Eigen::MatrixXd>
MatrixVectorTraits<Eigen::MatrixXd>::
newInstance(Eigen::MatrixXd const& A)
{
return std::unique_ptr<Eigen::MatrixXd>(new Eigen::MatrixXd(A));
}
std::unique_ptr<Eigen::MatrixXd>
MatrixVectorTraits<Eigen::MatrixXd>::
newInstance(MatrixSpecifications const& spec)
{
return std::unique_ptr<Eigen::MatrixXd>(new Eigen::MatrixXd(spec.nrows, spec.ncols));
}
std::unique_ptr<Eigen::VectorXd>
MatrixVectorTraits<Eigen::VectorXd>::
newInstance()
{
return std::unique_ptr<Eigen::VectorXd>(new Eigen::VectorXd);
}
std::unique_ptr<Eigen::VectorXd>
MatrixVectorTraits<Eigen::VectorXd>::
newInstance(Eigen::VectorXd const& A)
{
return std::unique_ptr<Eigen::VectorXd>(new Eigen::VectorXd(A));
}
std::unique_ptr<Eigen::VectorXd>
MatrixVectorTraits<Eigen::VectorXd>::
newInstance(MatrixSpecifications const& spec)
{
return std::unique_ptr<Eigen::VectorXd>(new Eigen::VectorXd(spec.nrows));
}
} // namespace MathLib
#endif // OGS_USE_EIGEN
#ifdef USE_PETSC
namespace MathLib
{
std::unique_ptr<PETScMatrix>
MatrixVectorTraits<PETScMatrix>::
newInstance()
{
return std::unique_ptr<PETScMatrix>(new PETScMatrix(0, 0)); // TODO default constructor
}
std::unique_ptr<PETScMatrix>
MatrixVectorTraits<PETScMatrix>::
newInstance(PETScMatrix const& A)
{
return std::unique_ptr<PETScMatrix>(new PETScMatrix(A));
}
std::unique_ptr<PETScMatrix>
MatrixVectorTraits<PETScMatrix>::
newInstance(MatrixSpecifications const& spec)
{
return std::unique_ptr<PETScMatrix>(new PETScMatrix(spec.nrows)); // TODO sparsity pattern
}
std::unique_ptr<PETScVector>
MatrixVectorTraits<PETScVector>::
newInstance()
{
return std::unique_ptr<PETScVector>(new PETScVector);
}
std::unique_ptr<PETScVector>
MatrixVectorTraits<PETScVector>::
newInstance(PETScVector const& x)
{
return std::unique_ptr<PETScVector>(new PETScVector(x));
}
std::unique_ptr<PETScVector>
MatrixVectorTraits<PETScVector>::
newInstance(MatrixSpecifications const& spec)
{
return std::unique_ptr<PETScVector>(new PETScVector(spec.nrows));
}
} // namespace MathLib
#elif defined(OGS_USE_EIGEN)
namespace MathLib
{
std::unique_ptr<EigenMatrix>
MatrixVectorTraits<EigenMatrix>::
newInstance()
{
return std::unique_ptr<EigenMatrix>(new EigenMatrix(0, 0)); // TODO default constructor
}
std::unique_ptr<EigenMatrix>
MatrixVectorTraits<EigenMatrix>::
newInstance(EigenMatrix const& A)
{
return std::unique_ptr<EigenMatrix>(new EigenMatrix(A));
}
std::unique_ptr<EigenMatrix>
MatrixVectorTraits<EigenMatrix>::
newInstance(MatrixSpecifications const& spec)
{
return std::unique_ptr<EigenMatrix>(new EigenMatrix(spec.nrows)); // TODO sparsity pattern
}
std::unique_ptr<EigenVector>
MatrixVectorTraits<EigenVector>::
newInstance()
{
return std::unique_ptr<EigenVector>(new EigenVector);
}
std::unique_ptr<EigenVector>
MatrixVectorTraits<EigenVector>::
newInstance(EigenVector const& x)
{
return std::unique_ptr<EigenVector>(new EigenVector(x));
}
std::unique_ptr<EigenVector>
MatrixVectorTraits<EigenVector>::
newInstance(MatrixSpecifications const& spec)
{
return std::unique_ptr<EigenVector>(new EigenVector(spec.nrows));
}
} // namespace MathLib
#endif // defined(OGS_USE_EIGEN)
/**
* \copyright
* Copyright (c) 2012-2016, OpenGeoSys Community (http://www.opengeosys.org)
* Distributed under a Modified BSD License.
* See accompanying file LICENSE.txt or
* http://www.opengeosys.org/project/license
*
*/
#ifndef MATHLIB_MATRIX_VECTOR_TRAITS_H
#define MATHLIB_MATRIX_VECTOR_TRAITS_H
#include<memory>
#include "MatrixProviderUser.h"
namespace MathLib
{
template<typename Matrix>
struct MatrixVectorTraits;
}
#define SPECIALIZE_MATRIX_VECTOR_TRAITS(MATVEC, IDX) \
template<> struct MatrixVectorTraits<MATVEC> { \
using Index = IDX; \
static std::unique_ptr<MATVEC> newInstance(); \
static std::unique_ptr<MATVEC> newInstance(MATVEC const& A); \
static std::unique_ptr<MATVEC> newInstance(MatrixSpecifications const& spec); \
};
#ifdef OGS_USE_EIGEN
#include<Eigen/Core>
namespace MathLib
{
SPECIALIZE_MATRIX_VECTOR_TRAITS(Eigen::MatrixXd, Eigen::MatrixXd::Index);
SPECIALIZE_MATRIX_VECTOR_TRAITS(Eigen::VectorXd, Eigen::VectorXd::Index);
}
#endif
#ifdef USE_PETSC
#include "MathLib/LinAlg/PETSc/PETScMatrix.h"
#include "MathLib/LinAlg/PETSc/PETScVector.h"
namespace MathLib
{
SPECIALIZE_MATRIX_VECTOR_TRAITS(PETScMatrix, PETScMatrix::IndexType);
SPECIALIZE_MATRIX_VECTOR_TRAITS(PETScVector, PETScVector::IndexType);
}
#elif defined(OGS_USE_EIGEN)
#include "MathLib/LinAlg/Eigen/EigenMatrix.h"
#include "MathLib/LinAlg/Eigen/EigenVector.h"
namespace MathLib
{
SPECIALIZE_MATRIX_VECTOR_TRAITS(EigenMatrix, EigenMatrix::IndexType);
SPECIALIZE_MATRIX_VECTOR_TRAITS(EigenVector, EigenVector::IndexType);
}
#endif
#undef SPECIALIZE_MATRIX_VECTOR_TRAITS
#endif // MATHLIB_MATRIX_VECTOR_TRAITS_H
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment