Skip to content

Commit 7c4e7d6

Browse files
authored
Merge pull request ITHACA-FV#632 from giovastabile/foam2eigenfix
Foam2eigenfix fixing bug on volVectorField
2 parents 5005d8a + 65e6dfa commit 7c4e7d6

22 files changed

Lines changed: 1032 additions & 17 deletions

File tree

src/ITHACA_CORE/Foam2Eigen/Foam2Eigen.C

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ Eigen::VectorXd Foam2Eigen::field2Eigen(const
187187

188188
return out;
189189
}
190-
190+
// To be modified with map
191191
template <template <class> class PatchField, class GeoMesh>
192192
List<Eigen::VectorXd> Foam2Eigen::field2EigenBC(
193193
GeometricField<tensor, PatchField, GeoMesh>& field)
@@ -215,7 +215,7 @@ List<Eigen::VectorXd> Foam2Eigen::field2EigenBC(
215215

216216
template List<Eigen::VectorXd> Foam2Eigen::field2EigenBC(
217217
volTensorField& field);
218-
218+
// To be modified with map
219219
template <template <class> class PatchField, class GeoMesh>
220220
List<Eigen::VectorXd> Foam2Eigen::field2EigenBC(
221221
GeometricField<vector, PatchField, GeoMesh>& field)
@@ -265,7 +265,7 @@ List<Eigen::VectorXd> Foam2Eigen::field2EigenBC(
265265
template List<Eigen::VectorXd> Foam2Eigen::field2EigenBC(
266266
volVectorField& field);
267267

268-
268+
// To be modified with map
269269
template <template <class> class PatchField, class GeoMesh>
270270
List<Eigen::VectorXd> Foam2Eigen::field2EigenBC(
271271
GeometricField<scalar, PatchField, GeoMesh>& field)
@@ -425,7 +425,7 @@ List<Eigen::MatrixXd> Foam2Eigen::PtrList2EigenBC(
425425

426426
template List<Eigen::MatrixXd> Foam2Eigen::PtrList2EigenBC(
427427
PtrList<volTensorField>& fields, label Nfields);
428-
428+
// Not consistent with the others, to be fixed, it is changing just the BC
429429
template <template <class> class PatchField, class GeoMesh>
430430
GeometricField<tensor, PatchField, GeoMesh> Foam2Eigen::Eigen2field(
431431
GeometricField<tensor, PatchField, GeoMesh>& field_in,
@@ -451,7 +451,7 @@ GeometricField<tensor, PatchField, GeoMesh> Foam2Eigen::Eigen2field(
451451

452452
template volTensorField Foam2Eigen::Eigen2field(
453453
volTensorField& field_in, Eigen::VectorXd& eigen_vector, bool correctBC);
454-
454+
// This is correct to assign also BCs
455455
template <template <class> class PatchField, class GeoMesh>
456456
GeometricField<vector, PatchField, GeoMesh> Foam2Eigen::Eigen2field(
457457
GeometricField<vector, PatchField, GeoMesh>& field_in,
@@ -512,6 +512,8 @@ template volScalarField Foam2Eigen::Eigen2field(
512512
volScalarField& field_in, Eigen::VectorXd& eigen_vector,
513513
List<Eigen::VectorXd>& eigen_vector_boundary);
514514

515+
516+
// Now this is correct, the one for tensor is missing
515517
template<template<class> class PatchField, class GeoMesh>
516518
GeometricField<vector, PatchField, GeoMesh> Foam2Eigen::Eigen2field(
517519
GeometricField<vector, PatchField, GeoMesh>& field_in,
@@ -523,7 +525,7 @@ GeometricField<vector, PatchField, GeoMesh> Foam2Eigen::Eigen2field(
523525
{
524526
for (label j = 0; j < 3; j++)
525527
{
526-
field_out.ref()[i][j] = eigen_vector(i + field_out.size() * j);
528+
field_out.ref()[i][j] = eigen_vector(i*3 + j);
527529
}
528530
}
529531

@@ -607,7 +609,7 @@ Field<scalar> Foam2Eigen::Eigen2field(
607609

608610
return field;
609611
}
610-
612+
// This needs to be changed with MAP and changing the order of assignment
611613
template <>
612614
Field<vector> Foam2Eigen::Eigen2field(
613615
Field<vector>& field, Eigen::MatrixXd& matrix, bool correctBC)
@@ -639,7 +641,7 @@ Field<vector> Foam2Eigen::Eigen2field(
639641

640642
return field;
641643
}
642-
644+
// This needs to be changed with MAP and changing the order of assignment
643645
template <>
644646
Field<tensor> Foam2Eigen::Eigen2field(
645647
Field<tensor>& field, Eigen::MatrixXd& matrix, bool correctBC)
@@ -1455,7 +1457,7 @@ Eigen::MatrixXd Foam2Eigen::field2Eigen(const List<vector>& field)
14551457

14561458
return out;
14571459
}
1458-
1460+
// There might repetions of functions (Matrix vs Vector). I wouls only use matrices
14591461
template <>
14601462
Eigen::MatrixXd Foam2Eigen::field2Eigen(const List<scalar>& field)
14611463
{

src/ITHACA_CORE/ITHACAutilities/ITHACAassign.C

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ void assignBC(GeometricField<vector, fvPatchField, volMesh>& s, label BC_ind,
286286
{
287287
for (label j = 0; j < 3; j++)
288288
{
289-
valueList[i].component(j) = valueVec(i + sizeBC * j);
289+
valueList[i].component(j) = valueVec(i * 3 + j);
290290
}
291291
}
292292

@@ -305,7 +305,7 @@ void assignBC(GeometricField<tensor, fvPatchField, volMesh>& s, label BC_ind,
305305
{
306306
for (label j = 0; j < 9; j++)
307307
{
308-
valueList[i].component(j) = valueVec(i + sizeBC * j);
308+
valueList[i].component(j) = valueVec(i *9 + j);
309309
}
310310
}
311311

@@ -321,9 +321,9 @@ void assignBC(GeometricField<vector, pointPatchField, pointMesh>& s, label BC_in
321321

322322
for (label i = 0; i < sizeBC; i++)
323323
{
324-
valueList[i].component(0) = valueVec(i);
325-
valueList[i].component(1) = valueVec(i + sizeBC);
326-
valueList[i].component(2) = valueVec(i + sizeBC * 2);
324+
valueList[i].component(0) = valueVec(i*3);
325+
valueList[i].component(1) = valueVec(i*3 + 1);
326+
valueList[i].component(2) = valueVec(i*3 + 2);
327327
}
328328

329329
assignBC(s, BC_ind, valueList);
@@ -368,9 +368,9 @@ void assignBC(GeometricField<vector, fvsPatchField, surfaceMesh>& s,
368368

369369
for (label i = 0; i < sizeBC; i++)
370370
{
371-
valueList[i].component(0) = valueVec(i);
372-
valueList[i].component(1) = valueVec(i + sizeBC);
373-
valueList[i].component(2) = valueVec(i + sizeBC * 2);
371+
valueList[i].component(0) = valueVec(i*3);
372+
valueList[i].component(1) = valueVec(i*3 + 1);
373+
valueList[i].component(2) = valueVec(i*3 + 2);
374374
}
375375

376376
assignBC(s, BC_ind, valueList);

unitTests/Foam2Eigen/0/R

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*--------------------------------*- C++ -*----------------------------------*\
2+
| ========= | |
3+
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
4+
| \\ / O peration | Version: v2406 |
5+
| \\ / A nd | Website: www.openfoam.com |
6+
| \\/ M anipulation | |
7+
\*---------------------------------------------------------------------------*/
8+
FoamFile
9+
{
10+
version 2.0;
11+
format ascii;
12+
class volTensorField;
13+
object R;
14+
}
15+
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
16+
17+
dimensions [0 1 -1 0 0 0 0];
18+
19+
internalField nonuniform List<tensor>
20+
9
21+
(
22+
(0.5627519 0.29181145 0.28462197 0.57400058 0.4035641 0.77061236 0.70690672 0.74452486 0.62652557)
23+
(0.69557811 0.06141166 0.47935036 0.77075943 0.81715622 0.49681256 0.89278688 0.86556539 0.87408196)
24+
(0.7669962 0.34741633 0.03897115 0.7084794 0.69924475 0.97304192 0.62685379 0.20484854 0.03407128)
25+
(0.34010845 0.32642773 0.96446465 0.8921832 0.96303873 0.72409701 0.76203081 0.32020959 0.90977821)
26+
(0.05821342 0.19182089 0.766128 0.3673941 0.00136123 0.78987992 0.43909767 0.60476928 0.65546178)
27+
(0.42241117 0.10171041 0.4869757 0.28613934 0.14843946 0.91206661 0.81983309 0.82441992 0.9805341 )
28+
(0.89249965 0.62821434 0.87326178 0.18050006 0.23324646 0.3946645 0.20235204 0.41437868 0.01136425)
29+
(0.18654547 0.19546352 0.49102678 0.19965476 0.72438439 0.98217826 0.53671787 0.24718701 0.55385028)
30+
(0.02552712 0.58269207 0.07486959 0.56967971 0.91339065 0.93712675 0.86183445 0.50107396 0.88059432)
31+
)
32+
;
33+
34+
boundaryField
35+
{
36+
movingWall
37+
{
38+
type fixedValue;
39+
value uniform (1 0 0 1 0 0 1 0 0);
40+
}
41+
42+
fixedWalls
43+
{
44+
type zeroGradient;
45+
}
46+
47+
frontAndBack
48+
{
49+
type empty;
50+
}
51+
}
52+
53+
54+
// ************************************************************************* //

unitTests/Foam2Eigen/0/U

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*--------------------------------*- C++ -*----------------------------------*\
2+
| ========= | |
3+
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
4+
| \\ / O peration | Version: v2406 |
5+
| \\ / A nd | Website: www.openfoam.com |
6+
| \\/ M anipulation | |
7+
\*---------------------------------------------------------------------------*/
8+
FoamFile
9+
{
10+
version 2.0;
11+
format ascii;
12+
class volVectorField;
13+
object U;
14+
}
15+
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
16+
17+
dimensions [0 1 -1 0 0 0 0];
18+
19+
internalField nonuniform List<vector>
20+
9
21+
(
22+
(0.80093626 0.16845964 0.72741327)
23+
(0.82078459 0.29191422 0.99396549)
24+
(0.86606836 0.6883854 0.0463758 )
25+
(0.35404089 0.32368873 0.64384439)
26+
(0.80305602 0.93725668 0.82662493)
27+
(0.28995787 0.86748605 0.1556299 )
28+
(0.26138227 0.90689398 0.45691658)
29+
(0.22674645 0.66441032 0.93668346)
30+
(0.54623615 0.71569204 0.54570119)
31+
)
32+
;
33+
34+
boundaryField
35+
{
36+
movingWall
37+
{
38+
type fixedValue;
39+
value uniform (1 0 0);
40+
}
41+
42+
fixedWalls
43+
{
44+
type noSlip;
45+
}
46+
47+
frontAndBack
48+
{
49+
type empty;
50+
}
51+
}
52+
53+
54+
// ************************************************************************* //

unitTests/Foam2Eigen/0/p

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*--------------------------------*- C++ -*----------------------------------*\
2+
| ========= | |
3+
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
4+
| \\ / O peration | Version: v2406 |
5+
| \\ / A nd | Website: www.openfoam.com |
6+
| \\/ M anipulation | |
7+
\*---------------------------------------------------------------------------*/
8+
FoamFile
9+
{
10+
version 2.0;
11+
format ascii;
12+
class volScalarField;
13+
object p;
14+
}
15+
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
16+
17+
dimensions [0 2 -2 0 0 0 0];
18+
19+
internalField nonuniform List<scalar>
20+
9
21+
(
22+
4.29931e-06
23+
-0.00582257
24+
-0.0129603
25+
-0.0184126
26+
-0.0204301
27+
-0.0182365
28+
-0.011772
29+
-0.00148187
30+
0.0118391
31+
)
32+
;
33+
34+
boundaryField
35+
{
36+
movingWall
37+
{
38+
type zeroGradient;
39+
}
40+
41+
fixedWalls
42+
{
43+
type zeroGradient;
44+
}
45+
46+
frontAndBack
47+
{
48+
type empty;
49+
}
50+
}
51+
52+
53+
// ************************************************************************* //
513 KB
Binary file not shown.

0 commit comments

Comments
 (0)