Skip to content

Commit 923bbae

Browse files
Fixing getMassMatrixFV with the new Foam2Eigen convention
1 parent 400bf3a commit 923bbae

3 files changed

Lines changed: 34 additions & 2 deletions

File tree

src/ITHACA_CORE/EigenFunctions/EigenFunctions.C

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,4 +121,25 @@ vectorTensorProduct(
121121
const Eigen::Matrix<float, Eigen::Dynamic, 1>& g,
122122
const Eigen::Tensor<float, 3 >& c,
123123
const Eigen::Matrix<float, Eigen::Dynamic, 1>& a);
124+
125+
Eigen::VectorXd repeatElements(Eigen::VectorXd input, int n)
126+
{
127+
if (!(n > 0))
128+
{
129+
Info << "The integer for the EigenFunctions::repeat method must be positive. Aborting" << endl;
130+
abort();
131+
}
132+
else
133+
{
134+
Eigen::VectorXd output(input.size() * n);
135+
for (int i = 0; i < input.size(); i++)
136+
{
137+
for (int r = 0; r < n; r++)
138+
{
139+
output(i * n + r) = input(i);
140+
}
141+
}
142+
return output;
143+
}
144+
}
124145
}

src/ITHACA_CORE/EigenFunctions/EigenFunctions.H

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,17 @@ Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic> vectorTensorProduct(
249249
const Eigen::Tensor<T, 3 >& c,
250250
const Eigen::Matrix<T, Eigen::Dynamic, 1>& a);
251251

252+
253+
//------------------------------------------------------------------------------
254+
/// @brief Repeat each element n times after themselves
255+
///
256+
/// @details Example: input = (a, b); n = 3
257+
/// output = (a, a, a, b, b, b)
258+
///
259+
/// @param input Eigen::VectorXd
260+
/// @param n int
261+
Eigen::VectorXd repeatElements(Eigen::VectorXd input, int n);
262+
252263
};
253264

254265
template <typename T>

src/ITHACA_CORE/ITHACAutilities/ITHACAcoeffsMass.C

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ Eigen::VectorXd getMassMatrixFV(
321321
Eigen::MatrixXd snapEigen = Foam2Eigen::field2Eigen(snapshot);
322322
label dim = std::nearbyint(snapEigen.rows() / (snapshot.mesh().V()).size());
323323
Eigen::VectorXd volumes = Foam2Eigen::field2Eigen(snapshot.mesh().V());
324-
Eigen::VectorXd vol3 = volumes.replicate(dim, 1);
324+
Eigen::VectorXd vol3 = EigenFunctions::repeatElements(volumes, dim);
325325
return vol3;
326326
}
327327
else if constexpr(std::is_same<pointMesh, GeoMesh>::value)
@@ -330,7 +330,7 @@ Eigen::VectorXd getMassMatrixFV(
330330
label dim = std::nearbyint(snapEigen.rows() / (snapshot.mesh()
331331
().points()).size());
332332
Eigen::VectorXd pointsdata = Foam2Eigen::field2Eigen(snapshot);
333-
Eigen::VectorXd points3 = pointsdata.replicate(dim, 1);
333+
Eigen::VectorXd points3 = EigenFunctions::repeatElements(pointsdata, dim);
334334
return points3;
335335
}
336336
}

0 commit comments

Comments
 (0)