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

renamed toZeroedMatrix -> createZeroedMatrix

parent e5e6d5d4
No related branches found
No related tags found
No related merge requests found
...@@ -16,7 +16,8 @@ ...@@ -16,7 +16,8 @@
namespace MathLib namespace MathLib
{ {
/*! Creates an Eigen mapped matrix from the given data vector. /*! Creates an Eigen mapped matrix having its entries stored in the given
* \c data vector.
* *
* \return An Eigen mapped matrix of the given size. All values of the matrix * \return An Eigen mapped matrix of the given size. All values of the matrix
* are set to zero. * are set to zero.
...@@ -28,9 +29,9 @@ namespace MathLib ...@@ -28,9 +29,9 @@ namespace MathLib
* as the requested matrix type. * as the requested matrix type.
*/ */
template <typename Matrix> template <typename Matrix>
Eigen::Map<Matrix> toZeroedMatrix(std::vector<double>& data, Eigen::Map<Matrix> createZeroedMatrix(std::vector<double>& data,
Eigen::MatrixXd::Index rows, Eigen::MatrixXd::Index rows,
Eigen::MatrixXd::Index cols) Eigen::MatrixXd::Index cols)
{ {
static_assert(Matrix::IsRowMajor || Matrix::IsVectorAtCompileTime, static_assert(Matrix::IsRowMajor || Matrix::IsVectorAtCompileTime,
"The default storage order in OGS is row major storage for " "The default storage order in OGS is row major storage for "
...@@ -45,18 +46,19 @@ Eigen::Map<Matrix> toZeroedMatrix(std::vector<double>& data, ...@@ -45,18 +46,19 @@ Eigen::Map<Matrix> toZeroedMatrix(std::vector<double>& data,
return {data.data(), rows, cols}; return {data.data(), rows, cols};
} }
/*! Creates an Eigen mapped matrix from the given data vector. /*! Creates an Eigen mapped matrix having its entries stored in the given
* \c data vector.
* *
* This is a convienence method which makes the specification of dynamically * This is a convienence method which makes the specification of dynamically
* allocated Eigen matrices as return type easier. * allocated Eigen matrices as return type easier.
*/ */
inline Eigen::Map< inline Eigen::Map<
Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor>> Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor>>
toZeroedMatrix(std::vector<double>& data, createZeroedMatrix(std::vector<double>& data,
Eigen::MatrixXd::Index rows, Eigen::MatrixXd::Index rows,
Eigen::MatrixXd::Index cols) Eigen::MatrixXd::Index cols)
{ {
return toZeroedMatrix< return createZeroedMatrix<
Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor>>( Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor>>(
data, rows, cols); data, rows, cols);
} }
...@@ -138,7 +140,8 @@ toMatrix(std::vector<double>& data, ...@@ -138,7 +140,8 @@ toMatrix(std::vector<double>& data,
data, rows, cols); data, rows, cols);
} }
/*! Creates an Eigen mapped vector from the given data vector. /*! Creates an Eigen mapped vector having its entries stored in the given
* \c data vector.
* *
* \return An Eigen mapped vector of the given size. All values of the vector * \return An Eigen mapped vector of the given size. All values of the vector
* are set to zero. * are set to zero.
...@@ -147,8 +150,8 @@ toMatrix(std::vector<double>& data, ...@@ -147,8 +150,8 @@ toMatrix(std::vector<double>& data,
* \post The \c data has size \c size. * \post The \c data has size \c size.
*/ */
template <typename Vector> template <typename Vector>
Eigen::Map<Vector> toZeroedVector(std::vector<double>& data, Eigen::Map<Vector> createZeroedVector(std::vector<double>& data,
Eigen::VectorXd::Index size) Eigen::VectorXd::Index size)
{ {
static_assert(Vector::IsVectorAtCompileTime, "A vector type is required."); static_assert(Vector::IsVectorAtCompileTime, "A vector type is required.");
assert(Vector::SizeAtCompileTime == Eigen::Dynamic || assert(Vector::SizeAtCompileTime == Eigen::Dynamic ||
......
...@@ -45,7 +45,7 @@ void CentralDifferencesJacobianAssembler::assembleWithJacobian( ...@@ -45,7 +45,7 @@ void CentralDifferencesJacobianAssembler::assembleWithJacobian(
auto const local_xdot = auto const local_xdot =
MathLib::toVector<Eigen::VectorXd>(local_xdot_data, num_r_c); MathLib::toVector<Eigen::VectorXd>(local_xdot_data, num_r_c);
auto local_Jac = MathLib::toZeroedMatrix(local_Jac_data, auto local_Jac = MathLib::createZeroedMatrix(local_Jac_data,
num_r_c, num_r_c); num_r_c, num_r_c);
_local_x_perturbed_data = local_x_data; _local_x_perturbed_data = local_x_data;
......
...@@ -86,7 +86,7 @@ public: ...@@ -86,7 +86,7 @@ public:
// This assertion is valid only if all nodal d.o.f. use the same shape matrices. // This assertion is valid only if all nodal d.o.f. use the same shape matrices.
assert(local_matrix_size == ShapeFunction::NPOINTS * NUM_NODAL_DOF); assert(local_matrix_size == ShapeFunction::NPOINTS * NUM_NODAL_DOF);
auto local_K = MathLib::toZeroedMatrix<NodalMatrixType>( auto local_K = MathLib::createZeroedMatrix<NodalMatrixType>(
local_K_data, local_matrix_size, local_matrix_size); local_K_data, local_matrix_size, local_matrix_size);
unsigned const n_integration_points = unsigned const n_integration_points =
......
...@@ -136,11 +136,11 @@ void TESLocalAssembler<ShapeFunction_, IntegrationMethod_, GlobalDim>::assemble( ...@@ -136,11 +136,11 @@ void TESLocalAssembler<ShapeFunction_, IntegrationMethod_, GlobalDim>::assemble(
// This assertion is valid only if all nodal d.o.f. use the same shape matrices. // This assertion is valid only if all nodal d.o.f. use the same shape matrices.
assert(local_matrix_size == ShapeFunction::NPOINTS * NODAL_DOF); assert(local_matrix_size == ShapeFunction::NPOINTS * NODAL_DOF);
auto local_M = MathLib::toZeroedMatrix<NodalMatrixType>( auto local_M = MathLib::createZeroedMatrix<NodalMatrixType>(
local_M_data, local_matrix_size, local_matrix_size); local_M_data, local_matrix_size, local_matrix_size);
auto local_K = MathLib::toZeroedMatrix<NodalMatrixType>( auto local_K = MathLib::createZeroedMatrix<NodalMatrixType>(
local_K_data, local_matrix_size, local_matrix_size); local_K_data, local_matrix_size, local_matrix_size);
auto local_b = MathLib::toZeroedVector<NodalVectorType>(local_b_data, auto local_b = MathLib::createZeroedVector<NodalVectorType>(local_b_data,
local_matrix_size); local_matrix_size);
unsigned const n_integration_points = unsigned const n_integration_points =
......
...@@ -47,7 +47,7 @@ struct MatDiagX ...@@ -47,7 +47,7 @@ struct MatDiagX
std::vector<double>& mat_data) std::vector<double>& mat_data)
{ {
auto mat = auto mat =
MathLib::toZeroedMatrix(mat_data, x_data.size(), x_data.size()); MathLib::createZeroedMatrix(mat_data, x_data.size(), x_data.size());
mat.diagonal().noalias() = mat.diagonal().noalias() =
MathLib::toVector<Eigen::VectorXd>(x_data, x_data.size()); MathLib::toVector<Eigen::VectorXd>(x_data, x_data.size());
} }
...@@ -58,7 +58,7 @@ struct MatDiagX ...@@ -58,7 +58,7 @@ struct MatDiagX
std::vector<double>& dMdxTy_data) std::vector<double>& dMdxTy_data)
{ {
auto dMdxTy = auto dMdxTy =
MathLib::toZeroedMatrix(dMdxTy_data, x_data.size(), x_data.size()); MathLib::createZeroedMatrix(dMdxTy_data, x_data.size(), x_data.size());
dMdxTy.diagonal().noalias() = dMdxTy.diagonal().noalias() =
MathLib::toVector<Eigen::VectorXd>(y_data, y_data.size()); MathLib::toVector<Eigen::VectorXd>(y_data, y_data.size());
} }
...@@ -78,7 +78,7 @@ struct VecX ...@@ -78,7 +78,7 @@ struct VecX
std::vector<double>& mat_data) std::vector<double>& mat_data)
{ {
auto mat = auto mat =
MathLib::toZeroedMatrix(mat_data, x_data.size(), x_data.size()); MathLib::createZeroedMatrix(mat_data, x_data.size(), x_data.size());
mat = Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic, mat = Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic,
Eigen::RowMajor>::Identity(x_data.size(), Eigen::RowMajor>::Identity(x_data.size(),
x_data.size()); x_data.size());
...@@ -96,7 +96,7 @@ struct MatXY ...@@ -96,7 +96,7 @@ struct MatXY
std::vector<double>& mat_data) std::vector<double>& mat_data)
{ {
auto mat = auto mat =
MathLib::toZeroedMatrix(mat_data, x_data.size(), x_data.size()); MathLib::createZeroedMatrix(mat_data, x_data.size(), x_data.size());
for (std::size_t r=0; r<x_data.size(); ++r) { for (std::size_t r=0; r<x_data.size(); ++r) {
for (std::size_t c=0; c<x_data.size(); ++c) { for (std::size_t c=0; c<x_data.size(); ++c) {
mat(r, c) = x_data[r] * x_data[c]; mat(r, c) = x_data[r] * x_data[c];
...@@ -118,7 +118,7 @@ struct MatXY ...@@ -118,7 +118,7 @@ struct MatXY
auto const x_dot_y = MathLib::toVector<Eigen::VectorXd>(x_data, N).dot( auto const x_dot_y = MathLib::toVector<Eigen::VectorXd>(x_data, N).dot(
MathLib::toVector<Eigen::VectorXd>(y_data, N)); MathLib::toVector<Eigen::VectorXd>(y_data, N));
auto dMdxTy = auto dMdxTy =
MathLib::toZeroedMatrix(dMdxTy_data, N, N); MathLib::createZeroedMatrix(dMdxTy_data, N, N);
for (std::size_t r=0; r<N; ++r) { for (std::size_t r=0; r<N; ++r) {
for (std::size_t c=0; c<N; ++c) { for (std::size_t c=0; c<N; ++c) {
dMdxTy(r, c) = x_data[r] * y_data[c]; dMdxTy(r, c) = x_data[r] * y_data[c];
...@@ -150,7 +150,7 @@ struct VecXRevX ...@@ -150,7 +150,7 @@ struct VecXRevX
std::vector<double>& mat_data) std::vector<double>& mat_data)
{ {
auto mat = auto mat =
MathLib::toZeroedMatrix(mat_data, x_data.size(), x_data.size()); MathLib::createZeroedMatrix(mat_data, x_data.size(), x_data.size());
auto const N = x_data.size(); auto const N = x_data.size();
for (std::size_t i=0; i<N; ++i) { for (std::size_t i=0; i<N; ++i) {
mat(i, i) += x_data[N-i-1]; mat(i, i) += x_data[N-i-1];
...@@ -166,7 +166,7 @@ struct MatDiagXSquared ...@@ -166,7 +166,7 @@ struct MatDiagXSquared
std::vector<double>& mat_data) std::vector<double>& mat_data)
{ {
auto mat = auto mat =
MathLib::toZeroedMatrix(mat_data, x_data.size(), x_data.size()); MathLib::createZeroedMatrix(mat_data, x_data.size(), x_data.size());
for (std::size_t i=0; i<x_data.size(); ++i) for (std::size_t i=0; i<x_data.size(); ++i)
mat(i, i) = x_data[i] * x_data[i]; mat(i, i) = x_data[i] * x_data[i];
...@@ -178,7 +178,7 @@ struct MatDiagXSquared ...@@ -178,7 +178,7 @@ struct MatDiagXSquared
std::vector<double>& dMdxTy_data) std::vector<double>& dMdxTy_data)
{ {
auto dMdxTy = auto dMdxTy =
MathLib::toZeroedMatrix(dMdxTy_data, x_data.size(), x_data.size()); MathLib::createZeroedMatrix(dMdxTy_data, x_data.size(), x_data.size());
for (std::size_t i=0; i<x_data.size(); ++i) for (std::size_t i=0; i<x_data.size(); ++i)
dMdxTy(i, i) = 2.0 * x_data[i] * y_data[i]; dMdxTy(i, i) = 2.0 * x_data[i] * y_data[i];
...@@ -201,7 +201,7 @@ struct VecXSquared ...@@ -201,7 +201,7 @@ struct VecXSquared
std::vector<double>& mat_data) std::vector<double>& mat_data)
{ {
auto mat = auto mat =
MathLib::toZeroedMatrix(mat_data, x_data.size(), x_data.size()); MathLib::createZeroedMatrix(mat_data, x_data.size(), x_data.size());
for (std::size_t i=0; i< x_data.size(); ++i) { for (std::size_t i=0; i< x_data.size(); ++i) {
mat(i, i) = 2.0 * x_data[i]; mat(i, i) = 2.0 * x_data[i];
} }
...@@ -221,7 +221,7 @@ struct MatXSquaredShifted ...@@ -221,7 +221,7 @@ struct MatXSquaredShifted
{ {
auto const N = x_data.size(); auto const N = x_data.size();
auto mat = auto mat =
MathLib::toZeroedMatrix(mat_data, N, N); MathLib::createZeroedMatrix(mat_data, N, N);
for (std::size_t r=0; r<N; ++r) { for (std::size_t r=0; r<N; ++r) {
for (std::size_t c=0; c<N; ++c) { for (std::size_t c=0; c<N; ++c) {
auto const i = (r + c) % N; auto const i = (r + c) % N;
...@@ -241,7 +241,7 @@ struct MatXSquaredShifted ...@@ -241,7 +241,7 @@ struct MatXSquaredShifted
{ {
auto const N = x_data.size(); auto const N = x_data.size();
auto dMdxTy = auto dMdxTy =
MathLib::toZeroedMatrix(dMdxTy_data, N, N); MathLib::createZeroedMatrix(dMdxTy_data, N, N);
for (std::size_t r=0; r<N; ++r) { for (std::size_t r=0; r<N; ++r) {
for (std::size_t c=0; c<N; ++c) { for (std::size_t c=0; c<N; ++c) {
auto const i = (r + c) % N; auto const i = (r + c) % N;
......
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