Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
O
ogs
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Yuhao Liu
ogs
Commits
4135b1e6
Commit
4135b1e6
authored
9 years ago
by
Christoph Lehmann
Browse files
Options
Downloads
Patches
Plain Diff
[MaL] extended matrix traits to matrix and vector traits
parent
023baf73
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
MathLib/LinAlg/MatrixVectorTraits.cpp
+163
-0
163 additions, 0 deletions
MathLib/LinAlg/MatrixVectorTraits.cpp
MathLib/LinAlg/MatrixVectorTraits.h
+72
-0
72 additions, 0 deletions
MathLib/LinAlg/MatrixVectorTraits.h
with
235 additions
and
0 deletions
MathLib/LinAlg/MatrixVectorTraits.cpp
0 → 100644
+
163
−
0
View file @
4135b1e6
/**
* \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)
This diff is collapsed.
Click to expand it.
MathLib/LinAlg/MatrixVectorTraits.h
0 → 100644
+
72
−
0
View file @
4135b1e6
/**
* \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
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment