39template <
template <
class>
class PatchField,
class GeoMesh>
41 GeometricField<tensor, PatchField, GeoMesh>& field)
44 out.resize(label(field.size() * 9));
46 for (label l = 0; l < field.size(); l++)
48 for (label j = 0; j < 9; j++)
50 out(j * field.size() + l) = field[l][j];
58 volTensorField& field);
60template <
template <
class>
class PatchField,
class GeoMesh>
62 GeometricField<vector, PatchField, GeoMesh>& field)
65 out.resize(label(field.size() * 3));
67 for (label l = 0; l < field.size(); l++)
69 for (label j = 0; j < 3; j++)
71 out(j * field.size() + l) = field[l][j];
79 volVectorField& field);
81template <
template <
class>
class PatchField,
class GeoMesh>
83 GeometricField<scalar, PatchField, GeoMesh>& field)
86 out.resize(label(field.size()));
88 for (label l = 0; l < field.size(); l++)
96template <
template <
class>
class PatchField,
class GeoMesh>
98 GeometricField<scalar, PatchField, GeoMesh>& field)
100 Eigen::Map<Eigen::MatrixXd> output(field.ref().data(), field.size(), 1);
101 return std::move(output);
104template <
template <
class>
class PatchField,
class GeoMesh>
106 GeometricField<scalar, PatchField, GeoMesh>& field,
int BC_index)
108 Eigen::Map<Eigen::MatrixXd> output(field.boundaryFieldRef()[BC_index].data(), field.boundaryField()[BC_index].size(), 1);
109 return std::move(output);
113 volScalarField& field);
116 volScalarField& field,
int BC_index);
119 volScalarField& field);
121 surfaceScalarField& field);
127 out.resize(label(field.size()));
129 for (label l = 0; l < field.size(); l++)
141 out.resize(label(field.size() * 3));
143 for (label l = 0; l < field.size(); l++)
145 for (label j = 0; j < 3; j++)
147 out(j * field.size() + l) = field[l][j];
158 out.resize(label(field.size() * 9));
160 for (label l = 0; l < field.size(); l++)
162 for (label j = 0; j < 9; j++)
164 out(j * field.size() + l) = field[l][j];
173 DimensionedField<scalar, Foam::volMesh>& field)
176 out.resize(label(field.size()));
178 for (label l = 0; l < field.size(); l++)
186template <
template <
class>
class PatchField,
class GeoMesh>
188 GeometricField<tensor, PatchField, GeoMesh>& field)
190 List<Eigen::VectorXd> Out;
191 label size = field.boundaryField().size();
194 for (label
i = 0;
i < size;
i++)
196 label sizei = field.boundaryField()[
i].size();
197 Out[
i].resize(sizei * 9);
199 for (label k = 0; k < sizei; k++)
201 for (label j = 0; j < 9; j++)
203 Out[
i](k + j * sizei) = field.boundaryField()[
i][k][j];
212 volTensorField& field);
214template <
template <
class>
class PatchField,
class GeoMesh>
216 GeometricField<vector, PatchField, GeoMesh>& field)
218 List<Eigen::VectorXd> Out;
219 label size = field.boundaryField().size();
222 for (label
i = 0;
i < size;
i++)
224 label sizei = field.boundaryField()[
i].size();
225 Out[
i].resize(sizei * 3);
227 for (label k = 0; k < sizei; k++)
229 for (label j = 0; j < 3; j++)
231 Out[
i](k + j * sizei) = field.boundaryField()[
i][k][j];
240 volVectorField& field);
243template <
template <
class>
class PatchField,
class GeoMesh>
245 GeometricField<scalar, PatchField, GeoMesh>& field)
247 List<Eigen::VectorXd> Out;
248 label size = field.boundaryField().size();
251 for (label
i = 0;
i < size;
i++)
253 label sizei = field.boundaryField()[
i].size();
254 Out[
i].resize(sizei);
256 for (label k = 0; k < sizei; k++)
258 Out[
i](k) = field.boundaryField()[
i][k];
265 volScalarField& field);
267template <
template <
class>
class PatchField,
class GeoMesh>
269 PtrList<GeometricField<scalar, PatchField, GeoMesh>>&
275 "The Number of requested fields cannot be bigger than the number of requested entries.");
286 List<Eigen::MatrixXd> Out;
287 label NBound = fields[0].boundaryField().size();
290 for (label
i = 0;
i < NBound;
i++)
292 label sizei = fields[0].boundaryField()[
i].size();
293 Out[
i].resize(sizei, Nf);
296 for (label k = 0; k < Nf; k++)
298 List<Eigen::VectorXd> temp;
301 for (label
i = 0;
i < NBound;
i++)
303 Out[
i].col(k) = temp[
i];
311 PtrList<volScalarField>& fields, label Nfields);
313 PtrList<surfaceScalarField>& fields, label Nfields);
316template <
template <
class>
class PatchField,
class GeoMesh>
318 PtrList<GeometricField<vector, PatchField, GeoMesh>>&
324 "The Number of requested fields cannot be bigger than the number of requested entries.");
335 List<Eigen::MatrixXd> Out;
336 label NBound = fields[0].boundaryField().size();
339 for (label
i = 0;
i < NBound;
i++)
341 label sizei = fields[0].boundaryField()[
i].size();
342 Out[
i].resize(sizei * 3, Nf);
345 for (label k = 0; k < Nf; k++)
347 List<Eigen::VectorXd> temp;
350 for (label
i = 0;
i < NBound;
i++)
352 Out[
i].col(k) = temp[
i];
360 PtrList<volVectorField>& fields, label Nfields);
363template <
template <
class>
class PatchField,
class GeoMesh>
365 PtrList<GeometricField<tensor, PatchField, GeoMesh>>&
371 "The Number of requested fields cannot be bigger than the number of requested entries.");
382 List<Eigen::MatrixXd> Out;
383 label NBound = fields[0].boundaryField().size();
386 for (label
i = 0;
i < NBound;
i++)
388 label sizei = fields[0].boundaryField()[
i].size();
389 Out[
i].resize(sizei * 9, Nf);
392 for (label k = 0; k < Nf; k++)
394 List<Eigen::VectorXd> temp;
397 for (label
i = 0;
i < NBound;
i++)
399 Out[
i].col(k) = temp[
i];
407 PtrList<volTensorField>& fields, label Nfields);
409template <
template <
class>
class PatchField,
class GeoMesh>
411 GeometricField<tensor, PatchField, GeoMesh>& field_in,
412 Eigen::VectorXd& eigen_vector,
bool correctBC)
414 GeometricField<tensor, PatchField, GeoMesh> field_out(field_in);
416 for (
auto i = 0;
i < field_out.size();
i++)
418 for (label j = 0; j < 9; j++)
420 field_out.ref()[
i][j] = eigen_vector(
i + field_out.size() * j);
426 field_out.correctBoundaryConditions();
433 volTensorField& field_in, Eigen::VectorXd& eigen_vector,
bool correctBC);
435template <
template <
class>
class PatchField,
class GeoMesh>
437 GeometricField<vector, PatchField, GeoMesh>& field_in,
438 Eigen::VectorXd& eigen_vector, List<Eigen::VectorXd>& eigen_vector_boundary)
440 GeometricField<vector, PatchField, GeoMesh> field_out(field_in);
442 for (
auto i = 0;
i < field_out.size();
i++)
444 field_out.ref()[
i][0] = eigen_vector(
i);
445 field_out.ref()[
i][1] = eigen_vector(
i + field_out.size());
446 field_out.ref()[
i][2] = eigen_vector(
i + field_out.size() * 2);
449 for(
unsigned int id = 0;
id < field_out.boundaryField().size();
id++)
451 unsigned int idBSize = field_out.boundaryField()[id].size();
452 for (
unsigned int ith_bcell = 0; ith_bcell < idBSize; ith_bcell++)
462 volVectorField& field_in, Eigen::VectorXd& eigen_vector, List<Eigen::VectorXd>& eigen_vector_boundary);
464template<
template<
class>
class PatchField,
class GeoMesh>
466 GeometricField<scalar, PatchField, GeoMesh>& field_in,
467 Eigen::VectorXd& eigen_vector, List<Eigen::VectorXd>& eigen_vector_boundary)
469 GeometricField<scalar, PatchField, GeoMesh> field_out(field_in);
471 for (
auto i = 0;
i < field_out.size();
i++)
473 field_out.ref()[
i] = eigen_vector(
i);
476 for(
unsigned int id = 0;
id < field_out.boundaryField().size();
id++)
478 for (
unsigned int ith_bcell = 0; ith_bcell < field_out.boundaryField()[
id].size(); ith_bcell++)
488 volScalarField& field_in, Eigen::VectorXd& eigen_vector, List<Eigen::VectorXd>& eigen_vector_boundary);
490template<
template<
class>
class PatchField,
class GeoMesh>
492 GeometricField<vector, PatchField, GeoMesh>& field_in,
493 Eigen::VectorXd& eigen_vector,
bool correctBC)
495 GeometricField<vector, PatchField, GeoMesh> field_out(field_in);
497 for (
auto i = 0;
i < field_out.size();
i++)
499 for (label j = 0; j < 3; j++)
501 field_out.ref()[
i][j] = eigen_vector(
i + field_out.size() * j);
507 field_out.correctBoundaryConditions();
514 volVectorField& field_in, Eigen::VectorXd& eigen_vector,
bool correctBC);
516template <
template <
class>
class PatchField,
class GeoMesh>
518 GeometricField<scalar, PatchField, GeoMesh>& field_in,
519 Eigen::VectorXd& eigen_vector,
bool correctBC)
521 GeometricField<scalar, PatchField, GeoMesh> field_out(field_in);
523 for (
auto i = 0;
i < field_out.size();
i++)
525 field_out.ref()[
i] = eigen_vector(
i);
532 surfaceScalarField& field_in,
533 Eigen::VectorXd& eigen_vector,
538 volScalarField& field_in, Eigen::VectorXd& eigen_vector,
bool correctBC)
540 GeometricField<scalar, fvPatchField, volMesh> field_out(field_in);
542 for (
auto i = 0;
i < field_out.size();
i++)
544 field_out.ref()[
i] = eigen_vector(
i);
549 field_out.correctBoundaryConditions();
557 Field<scalar>& field, Eigen::MatrixXd& matrix,
bool correctBC)
559 label sizeBC = field.size();
561 "The number of columns of the Input members is not correct, it should be 1");
563 if (matrix.rows() == 1)
565 Eigen::MatrixXd new_matrix = matrix.replicate(sizeBC, 1);
566 matrix.conservativeResize(sizeBC, 1);
570 std::string message =
"The input Eigen::MatrixXd has size " + name(
572 ". It should have the same size of the Field, i.e. " +
574 M_Assert(matrix.rows() == sizeBC, message.c_str());
576 for (
auto i = 0;
i < sizeBC;
i++)
578 field[
i] = matrix(
i, 0);
586 Field<vector>& field, Eigen::MatrixXd& matrix,
bool correctBC)
588 label sizeBC = field.size();
590 "The number of columns of the Input members is not correct, it should be 1");
592 if (matrix.rows() == 1)
594 Eigen::MatrixXd new_matrix = matrix.replicate(sizeBC, 1);
595 matrix.conservativeResize(sizeBC, 3);
599 std::string message =
"The input Eigen::MatrixXd has size " + name(
601 ". It should have the same size of the Field, i.e. " +
603 M_Assert(matrix.rows() == sizeBC, message.c_str());
605 for (
auto i = 0;
i < sizeBC;
i++)
607 for (label j = 0; j < 3; j++)
609 field[
i][j] = matrix(
i, j);
618 Field<tensor>& field, Eigen::MatrixXd& matrix,
bool correctBC)
620 label sizeBC = field.size();
622 "The number of columns of the Input members is not correct, it should be 1");
624 if (matrix.rows() == 1)
626 Eigen::MatrixXd new_matrix = matrix.replicate(sizeBC, 1);
627 matrix.conservativeResize(sizeBC, 9);
631 std::string message =
"The input Eigen::MatrixXd has size " + name(
633 ". It should have the same size of the Field, i.e. " +
635 M_Assert(matrix.rows() == sizeBC, message.c_str());
637 for (
auto i = 0;
i < sizeBC;
i++)
639 for (label j = 0; j < 9; j++)
641 field[
i][j] = matrix(
i, j);
648template <
class Type,
template <
class>
class PatchField,
class GeoMesh>
650 PtrList<GeometricField<Type, PatchField, GeoMesh>>& fields,
655 "The Number of requested fields cannot be bigger than the number of requested entries.");
668 out.resize(nrows, Nf);
670 for (label k = 0; k < Nf; k++)
678template Eigen::MatrixXd
685template Eigen::MatrixXd
689template Eigen::MatrixXd
699 label sizeA = foam_matrix.diag().size();
700 A.setZero(sizeA, sizeA);
703 for (
auto i = 0;
i < sizeA;
i++)
705 A(
i,
i) = foam_matrix.diag()[
i];
706 b(
i, 0) = foam_matrix.source()[
i];
709 const lduAddressing& addr = foam_matrix.lduAddr();
710 const labelList& lowerAddr = addr.lowerAddr();
711 const labelList& upperAddr = addr.upperAddr();
714 A(lowerAddr[
i], upperAddr[
i]) = foam_matrix.upper()[
i];
715 A(upperAddr[
i], lowerAddr[
i]) = foam_matrix.lower()[
i];
717 forAll(foam_matrix.psi().boundaryField(), I)
719 const fvPatch& ptch = foam_matrix.psi().boundaryField()[I].patch();
722 label w = ptch.faceCells()[J];
723 const double intern = foam_matrix.internalCoeffs()[I][J];
725 b(w, 0) += foam_matrix.boundaryCoeffs()[I][J];
735 label sizeA = foam_matrix.diag().size();
736 A.resize(sizeA * 3, sizeA * 3);
739 for (
auto i = 0;
i < sizeA;
i++)
741 A(
i,
i) = foam_matrix.diag()[
i];
742 A(sizeA +
i, sizeA +
i) = foam_matrix.diag()[
i];
743 A(2 * sizeA +
i, 2 * sizeA +
i) = foam_matrix.diag()[
i];
744 b(
i) = foam_matrix.source()[
i][0];
745 b(sizeA +
i) = foam_matrix.source()[
i][1];
746 b(2 * sizeA +
i) = foam_matrix.source()[
i][2];
749 const lduAddressing& addr = foam_matrix.lduAddr();
750 const labelList& lowerAddr = addr.lowerAddr();
751 const labelList& upperAddr = addr.upperAddr();
754 A(lowerAddr[
i], upperAddr[
i]) = foam_matrix.upper()[
i];
755 A(lowerAddr[
i] + sizeA, upperAddr[
i] + sizeA) = foam_matrix.upper()[
i];
756 A(lowerAddr[
i] + sizeA * 2, upperAddr[
i] + sizeA * 2) = foam_matrix.upper()[
i];
757 A(upperAddr[
i], lowerAddr[
i]) = foam_matrix.lower()[
i];
758 A(upperAddr[
i] + sizeA, lowerAddr[
i] + sizeA) = foam_matrix.lower()[
i];
759 A(upperAddr[
i] + sizeA * 2, lowerAddr[
i] + sizeA * 2) = foam_matrix.lower()[
i];
761 forAll(foam_matrix.psi().boundaryField(), I)
763 const fvPatch& ptch = foam_matrix.psi().boundaryField()[I].patch();
766 label w = ptch.faceCells()[J];
767 A(w, w) += foam_matrix.internalCoeffs()[I][J][0];
768 A(w + sizeA, w + sizeA) += foam_matrix.internalCoeffs()[I][J][1];
769 A(w + sizeA * 2, w + sizeA * 2) += foam_matrix.internalCoeffs()[I][J][2];
770 b(w) += foam_matrix.boundaryCoeffs()[I][J][0];
771 b(w + sizeA) += foam_matrix.boundaryCoeffs()[I][J][1];
772 b(w + sizeA * 2) += foam_matrix.boundaryCoeffs()[I][J][2];
779 Eigen::SparseMatrix<double>&
A, Eigen::VectorXd& b)
781 label sizeA = foam_matrix.diag().size();
782 label nel = foam_matrix.diag().size() + foam_matrix.upper().size() +
783 foam_matrix.lower().size();
784 A.resize(sizeA, sizeA);
787 typedef Eigen::Triplet<double> Trip;
788 std::vector<Trip> tripletList;
789 tripletList.reserve(nel);
791 for (
auto i = 0;
i < sizeA;
i++)
793 tripletList.push_back(Trip(
i,
i, foam_matrix.diag()[
i]));
794 b(
i, 0) = foam_matrix.source()[
i];
797 const lduAddressing& addr = foam_matrix.lduAddr();
798 const labelList& lowerAddr = addr.lowerAddr();
799 const labelList& upperAddr = addr.upperAddr();
802 tripletList.push_back(Trip(lowerAddr[
i], upperAddr[
i], foam_matrix.upper()[
i]));
803 tripletList.push_back(Trip(upperAddr[
i], lowerAddr[
i], foam_matrix.lower()[
i]));
805 forAll(foam_matrix.psi().boundaryField(), I)
807 const fvPatch& ptch = foam_matrix.psi().boundaryField()[I].patch();
810 label w = ptch.faceCells()[J];
811 tripletList.push_back(Trip(w, w, foam_matrix.internalCoeffs()[I][J]));
812 b(w, 0) += foam_matrix.boundaryCoeffs()[I][J];
815 A.setFromTriplets(tripletList.begin(), tripletList.end());
820 Eigen::SparseMatrix<double>&
A, Eigen::VectorXd& b)
822 label sizeA = foam_matrix.diag().size();
823 label nel = foam_matrix.diag().size() + foam_matrix.upper().size() +
824 foam_matrix.lower().size();
825 A.resize(sizeA * 3, sizeA * 3);
828 typedef Eigen::Triplet<double> Trip;
829 std::vector<Trip> tripletList;
830 tripletList.reserve(nel * 3);
832 for (
auto i = 0;
i < sizeA;
i++)
834 tripletList.push_back(Trip(
i,
i, foam_matrix.diag()[
i]));
835 tripletList.push_back(Trip(sizeA +
i, sizeA +
i, foam_matrix.diag()[
i]));
836 tripletList.push_back(Trip(2 * sizeA +
i, 2 * sizeA +
i,
837 foam_matrix.diag()[
i]));
838 b(
i) = foam_matrix.source()[
i][0];
839 b(sizeA +
i) = foam_matrix.source()[
i][1];
840 b(2 * sizeA +
i) = foam_matrix.source()[
i][2];
843 const lduAddressing& addr = foam_matrix.lduAddr();
844 const labelList& lowerAddr = addr.lowerAddr();
845 const labelList& upperAddr = addr.upperAddr();
848 tripletList.push_back(Trip(lowerAddr[
i], upperAddr[
i], foam_matrix.upper()[
i]));
849 tripletList.push_back(Trip(lowerAddr[
i] + sizeA, upperAddr[
i] + sizeA,
850 foam_matrix.upper()[
i]));
851 tripletList.push_back(Trip(lowerAddr[
i] + sizeA * 2, upperAddr[
i] + sizeA * 2,
852 foam_matrix.upper()[
i]));
853 tripletList.push_back(Trip(upperAddr[
i], lowerAddr[
i], foam_matrix.lower()[
i]));
854 tripletList.push_back(Trip(upperAddr[
i] + sizeA, lowerAddr[
i] + sizeA,
855 foam_matrix.lower()[
i]));
856 tripletList.push_back(Trip(upperAddr[
i] + sizeA * 2, lowerAddr[
i] + sizeA * 2,
857 foam_matrix.lower()[
i]));
859 forAll(foam_matrix.psi().boundaryField(), I)
861 const fvPatch& ptch = foam_matrix.psi().boundaryField()[I].patch();
864 label w = ptch.faceCells()[J];
865 tripletList.push_back(Trip(w, w, foam_matrix.internalCoeffs()[I][J][0]));
866 tripletList.push_back(Trip(w + sizeA, w + sizeA,
867 foam_matrix.internalCoeffs()[I][J][1]));
868 tripletList.push_back(Trip(w + sizeA * 2, w + sizeA * 2,
869 foam_matrix.internalCoeffs()[I][J][2]));
870 b(w) += foam_matrix.boundaryCoeffs()[I][J][0];
871 b(w + sizeA) += foam_matrix.boundaryCoeffs()[I][J][1];
872 b(w + sizeA * 2) += foam_matrix.boundaryCoeffs()[I][J][2];
875 A.setFromTriplets(tripletList.begin(), tripletList.end());
882 label sizeA = foam_matrix.diag().size();
883 A.setZero(sizeA, sizeA);
885 for (
auto i = 0;
i < sizeA;
i++)
887 A(
i,
i) = foam_matrix.diag()[
i];
890 const lduAddressing& addr = foam_matrix.lduAddr();
891 const labelList& lowerAddr = addr.lowerAddr();
892 const labelList& upperAddr = addr.upperAddr();
895 A(lowerAddr[
i], upperAddr[
i]) = foam_matrix.upper()[
i];
896 A(upperAddr[
i], lowerAddr[
i]) = foam_matrix.lower()[
i];
898 forAll(foam_matrix.psi().boundaryField(), I)
900 const fvPatch& ptch = foam_matrix.psi().boundaryField()[I].patch();
903 label w = ptch.faceCells()[J];
904 A(w, w) += foam_matrix.internalCoeffs()[I][J];
911 Eigen::SparseMatrix<double>&
A)
913 label sizeA = foam_matrix.diag().size();
914 label nel = foam_matrix.diag().size() + foam_matrix.upper().size() +
915 foam_matrix.lower().size();
916 A.resize(sizeA, sizeA);
918 typedef Eigen::Triplet<double> Trip;
919 std::vector<Trip> tripletList;
920 tripletList.reserve(nel);
922 for (
auto i = 0;
i < sizeA;
i++)
924 tripletList.push_back(Trip(
i,
i, foam_matrix.diag()[
i]));
927 const lduAddressing& addr = foam_matrix.lduAddr();
928 const labelList& lowerAddr = addr.lowerAddr();
929 const labelList& upperAddr = addr.upperAddr();
932 tripletList.push_back(Trip(lowerAddr[
i], upperAddr[
i], foam_matrix.upper()[
i]));
933 tripletList.push_back(Trip(upperAddr[
i], lowerAddr[
i], foam_matrix.lower()[
i]));
935 forAll(foam_matrix.psi().boundaryField(), I)
937 const fvPatch& ptch = foam_matrix.psi().boundaryField()[I].patch();
940 label w = ptch.faceCells()[J];
941 tripletList.push_back(Trip(w, w, foam_matrix.internalCoeffs()[I][J]));
944 A.setFromTriplets(tripletList.begin(), tripletList.end());
951 label sizeA = foam_matrix.diag().size();
952 A.resize(sizeA * 3, sizeA * 3);
954 for (
auto i = 0;
i < sizeA;
i++)
956 A(
i,
i) = foam_matrix.diag()[
i];
957 A(sizeA +
i, sizeA +
i) = foam_matrix.diag()[
i];
958 A(2 * sizeA +
i, 2 * sizeA +
i) = foam_matrix.diag()[
i];
961 const lduAddressing& addr = foam_matrix.lduAddr();
962 const labelList& lowerAddr = addr.lowerAddr();
963 const labelList& upperAddr = addr.upperAddr();
966 A(lowerAddr[
i], upperAddr[
i]) = foam_matrix.upper()[
i];
967 A(lowerAddr[
i] + sizeA, upperAddr[
i] + sizeA) = foam_matrix.upper()[
i];
968 A(lowerAddr[
i] + sizeA * 2, upperAddr[
i] + sizeA * 2) = foam_matrix.upper()[
i];
969 A(upperAddr[
i], lowerAddr[
i]) = foam_matrix.lower()[
i];
970 A(upperAddr[
i] + sizeA, lowerAddr[
i] + sizeA) = foam_matrix.lower()[
i];
971 A(upperAddr[
i] + sizeA * 2, lowerAddr[
i] + sizeA * 2) = foam_matrix.lower()[
i];
973 forAll(foam_matrix.psi().boundaryField(), I)
975 const fvPatch& ptch = foam_matrix.psi().boundaryField()[I].patch();
978 label w = ptch.faceCells()[J];
979 A(w, w) += foam_matrix.internalCoeffs()[I][J][0];
980 A(w + sizeA, w + sizeA) += foam_matrix.internalCoeffs()[I][J][1];
981 A(w + sizeA * 2, w + sizeA * 2) += foam_matrix.internalCoeffs()[I][J][2];
989 Eigen::SparseMatrix<double>&
A)
991 label sizeA = foam_matrix.diag().size();
992 label nel = foam_matrix.diag().size() + foam_matrix.upper().size() +
993 foam_matrix.lower().size();
994 A.resize(sizeA * 3, sizeA * 3);
996 typedef Eigen::Triplet<double> Trip;
997 std::vector<Trip> tripletList;
998 tripletList.reserve(nel * 3);
1000 for (
auto i = 0;
i < sizeA;
i++)
1002 tripletList.push_back(Trip(
i,
i, foam_matrix.diag()[
i]));
1003 tripletList.push_back(Trip(sizeA +
i, sizeA +
i, foam_matrix.diag()[
i]));
1004 tripletList.push_back(Trip(2 * sizeA +
i, 2 * sizeA +
i,
1005 foam_matrix.diag()[
i]));
1008 const lduAddressing& addr = foam_matrix.lduAddr();
1009 const labelList& lowerAddr = addr.lowerAddr();
1010 const labelList& upperAddr = addr.upperAddr();
1013 tripletList.push_back(Trip(lowerAddr[
i], upperAddr[
i], foam_matrix.upper()[
i]));
1014 tripletList.push_back(Trip(lowerAddr[
i] + sizeA, upperAddr[
i] + sizeA,
1015 foam_matrix.upper()[
i]));
1016 tripletList.push_back(Trip(lowerAddr[
i] + sizeA * 2, upperAddr[
i] + sizeA * 2,
1017 foam_matrix.upper()[
i]));
1018 tripletList.push_back(Trip(upperAddr[
i], lowerAddr[
i], foam_matrix.lower()[
i]));
1019 tripletList.push_back(Trip(upperAddr[
i] + sizeA, lowerAddr[
i] + sizeA,
1020 foam_matrix.lower()[
i]));
1021 tripletList.push_back(Trip(upperAddr[
i] + sizeA * 2, lowerAddr[
i] + sizeA * 2,
1022 foam_matrix.lower()[
i]));
1024 forAll(foam_matrix.psi().boundaryField(), I)
1026 const fvPatch& ptch = foam_matrix.psi().boundaryField()[I].patch();
1029 label w = ptch.faceCells()[J];
1030 tripletList.push_back(Trip(w, w, foam_matrix.internalCoeffs()[I][J][0]));
1031 tripletList.push_back(Trip(w + sizeA, w + sizeA,
1032 foam_matrix.internalCoeffs()[I][J][1]));
1033 tripletList.push_back(Trip(w + sizeA * 2, w + sizeA * 2,
1034 foam_matrix.internalCoeffs()[I][J][2]));
1037 A.setFromTriplets(tripletList.begin(), tripletList.end());
1044 label sizeA = foam_matrix.diag().size();
1047 for (
auto i = 0;
i < sizeA;
i++)
1049 b(
i, 0) = foam_matrix.source()[
i];
1052 forAll(foam_matrix.psi().boundaryField(), I)
1054 const fvPatch& ptch = foam_matrix.psi().boundaryField()[I].patch();
1057 label w = ptch.faceCells()[J];
1058 b(w, 0) += foam_matrix.boundaryCoeffs()[I][J];
1067 label sizeA = foam_matrix.diag().size();
1068 b.resize(sizeA * 3);
1070 for (
auto i = 0;
i < sizeA;
i++)
1072 b(
i) = foam_matrix.source()[
i][0];
1073 b(sizeA +
i) = foam_matrix.source()[
i][1];
1074 b(2 * sizeA +
i) = foam_matrix.source()[
i][2];
1077 forAll(foam_matrix.psi().boundaryField(), I)
1079 const fvPatch& ptch = foam_matrix.psi().boundaryField()[I].patch();
1082 label w = ptch.faceCells()[J];
1083 b(w) += foam_matrix.boundaryCoeffs()[I][J][0];
1084 b(w + sizeA) += foam_matrix.boundaryCoeffs()[I][J][1];
1085 b(w + sizeA * 2) += foam_matrix.boundaryCoeffs()[I][J][2];
1090template <
class Type,
template <
class>
class PatchField,
class GeoMesh>
1092 GeometricField<Type, PatchField, GeoMesh>& field,
1093 PtrList<GeometricField<Type, PatchField, GeoMesh>>& modes,
1100 Eigen::MatrixXd VolumesN(Volumes.rows(), 1);
1103 if (Volumes.rows() != Eig_Modes.rows())
1105 VolumesN.resize(Eig_Modes.rows(), 1);
1106 VolumesN.col(0).segment(0, Volumes.rows()) = Volumes;
1107 VolumesN.col(0).segment(Volumes.rows() + 1, Volumes.rows() * 2) = Volumes;
1108 VolumesN.col(0).segment(Volumes.rows() * 2 + 1, Volumes.rows() * 3) = Volumes;
1111 fr = Eig_Modes.transpose() * (f.cwiseProduct(VolumesN));
1115template <
class Type,
template <
class>
class PatchField,
class GeoMesh>
1117 fvMatrix<Type>& matrix,
1118 PtrList<GeometricField<Type, PatchField, GeoMesh>>& modes, label Nmodes)
1120 Eigen::SparseMatrix<double>
A;
1127 Eigen::MatrixXd VolumesN(Volumes.rows(), Nmodes);
1129 if (Volumes.rows() != Eig_Modes.rows())
1131 VolumesN.resize(Eig_Modes.rows(), Nmodes);
1134 if (Volumes.rows() == Eig_Modes.rows())
1136 for (
auto i = 0;
i < Nmodes;
i++)
1138 VolumesN.col(
i) = Volumes;
1143 for (
auto i = 0;
i < Nmodes;
i++)
1145 VolumesN.col(
i).segment(0, Volumes.rows()) = Volumes;
1146 VolumesN.col(
i).segment(Volumes.rows() + 1, Volumes.rows() * 2) = Volumes;
1147 VolumesN.col(
i).segment(Volumes.rows() * 2 + 1, Volumes.rows() * 3) = Volumes;
1151 Ar = Eig_Modes.transpose() *
A * Eig_Modes;
1152 br = Eig_Modes.transpose() * b;
1153 std::tuple<Eigen::MatrixXd, Eigen::VectorXd> tupla;
1154 tupla = std::make_tuple(Ar, br);
1158template <
class Type,
template <
class>
class PatchField,
class GeoMesh>
1160 PtrList<GeometricField<Type, PatchField, GeoMesh>>& modes, label Nmodes)
1165 Eigen::MatrixXd VolumesN(Volumes.rows(), Nmodes);
1167 if (Volumes.rows() != Eig_Modes.rows())
1169 VolumesN.resize(Eig_Modes.rows(), Nmodes);
1172 if (Volumes.rows() == Eig_Modes.rows())
1174 for (
auto i = 0;
i < Nmodes;
i++)
1176 VolumesN.col(
i) = Volumes;
1181 for (
auto i = 0;
i < Nmodes;
i++)
1183 VolumesN.col(
i).segment(0, Volumes.rows()) = Volumes;
1184 VolumesN.col(
i).segment(Volumes.rows() + 1, Volumes.rows() * 2) = Volumes;
1185 VolumesN.col(
i).segment(Volumes.rows() * 2 + 1, Volumes.rows() * 3) = Volumes;
1189 Mr = Eig_Modes.transpose() * (Eig_Modes.cwiseProduct(VolumesN));
1193template <
class Type>
1194std::tuple<List<Eigen::SparseMatrix<double>>, List<Eigen::VectorXd>>
1197 List<Eigen::SparseMatrix<double>> SM_list;
1198 List<Eigen::VectorXd> V_list;
1199 label LSize = MatrixList.size();
1200 SM_list.resize(LSize);
1201 V_list.resize(LSize);
1202 Eigen::SparseMatrix<double>
A;
1205 for (label j = 0; j < LSize; j++)
1212 std::tuple<List<Eigen::SparseMatrix<double>>, List<Eigen::VectorXd>> tupla;
1213 tupla = std::make_tuple(SM_list, V_list);
1217template std::tuple<List<Eigen::SparseMatrix<double>>, List<Eigen::VectorXd>>
1219template std::tuple<List<Eigen::SparseMatrix<double>>, List<Eigen::VectorXd>>
1222template <
class type_matrix>
1223Eigen::Matrix<type_matrix, Eigen::Dynamic, Eigen::Dynamic>
1226 Eigen::Matrix<type_matrix, Eigen::Dynamic, Eigen::Dynamic> matrix(list.size(),
1229 for (label
i = 0;
i < matrix.rows();
i++)
1231 matrix(
i, 0) = list[
i];
1237template Eigen::Matrix<int, Eigen::Dynamic, Eigen::Dynamic>
1239template Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic>
1242template <
class type_matrix>
1244 Eigen::Matrix<type_matrix, Eigen::Dynamic, Eigen::Dynamic> matrix)
1246 if (matrix.cols() == 1)
1248 List<type_matrix> list(matrix.rows());
1250 for (label
i = 0;
i < matrix.rows();
i++)
1252 list[
i] = matrix(
i, 0);
1259 Info <<
"Foam2Eigen::EigenMatrix2List only accepts matrices with 1 column, exiting"
1266 Eigen::Matrix<int, Eigen::Dynamic, Eigen::Dynamic> matrix);
1268 Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic> matrix);
1273 Eigen::MatrixXd out;
1274 out.resize(label(field.size() * 3), 1);
1276 for (label l = 0; l < field.size(); l++)
1278 for (label j = 0; j < 3; j++)
1280 out(j * field.size() + l, 0) = field[l][j];
1290 Eigen::MatrixXd out;
1291 out.resize(label(field.size()), 1);
1293 for (label l = 0; l < field.size(); l++)
1295 out(l, 0) = field[l];
forAll(example_CG.gList, solutionI)
Header file of the Foam2Eigen class.
#define M_Assert(Expr, Msg)
static GeometricField< scalar, PatchField, GeoMesh > Eigen2field(GeometricField< scalar, PatchField, GeoMesh > &field, Eigen::VectorXd &eigen_vector, bool correctBC=true)
Convert a vector in Eigen format into an OpenFOAM scalar GeometricField.
static Eigen::VectorXd field2Eigen(GeometricField< tensor, PatchField, GeoMesh > &field)
Convert a vector OpenFOAM field into an Eigen Vector.
static List< Eigen::VectorXd > field2EigenBC(GeometricField< scalar, PatchField, GeoMesh > &field)
Convert an OpenFOAM scalar field to a List of Eigen Vectors, one for each boundary.
static Eigen::Map< Eigen::MatrixXd > field2EigenMap(GeometricField< scalar, PatchField, GeoMesh > &field)
Convert a scalar OpenFOAM field into an Eigen Vector.
static std::tuple< List< Eigen::SparseMatrix< double > >, List< Eigen::VectorXd > > LFvMatrix2LSM(PtrList< fvMatrix< Type > > &MatrixList)
Convert a PtrList of OpenFOAM fvMatrix into a tuple of lists of Eigen Sparse Matrices and source vect...
static Eigen::Matrix< type_matrix, Eigen::Dynamic, Eigen::Dynamic > List2EigenMatrix(List< type_matrix > list)
Convert a Foam List into an Eigen matrix with one column.
static Eigen::VectorXd projectField(GeometricField< Type, PatchField, GeoMesh > &field, PtrList< GeometricField< Type, PatchField, GeoMesh > > &modes, label Nmodes)
Perform the projection of an OpenFOAM field onto a set of modes using the Eigen matrix multiplication...
static Eigen::MatrixXd MassMatrix(PtrList< GeometricField< Type, PatchField, GeoMesh > > &modes, label Nmodes)
Obtain the Mass Matrix from a list of reduced basis.
static List< type_matrix > EigenMatrix2List(Eigen::Matrix< type_matrix, Eigen::Dynamic, Eigen::Dynamic > matrix)
Convert an Eigen matrix with one column into a Foam List.
static void fvMatrix2EigenV(fvMatrix< type_foam_matrix > &foam_matrix, type_B &b)
Convert a ldu OpenFOAM matrix into a source vector b.
static List< Eigen::MatrixXd > PtrList2EigenBC(PtrList< GeometricField< scalar, PatchField, GeoMesh > > &fields, label Nfields=-1)
Convert an OpenFOAM scalar field to a List of Eigen Vectors, one for each boundary.
static Eigen::MatrixXd PtrList2Eigen(PtrList< GeometricField< Type, PatchField, GeoMesh > > &fields, label Nfields=-1)
Convert a PtrList of snapshots to Eigen matrix (only internal field)
static void fvMatrix2Eigen(fvMatrix< type_foam_matrix > foam_matrix, type_A &A, type_B &b)
Convert a FvMatrix OpenFOAM matrix (Linear System) into a Eigen Matrix A and a source vector b.
static std::tuple< Eigen::MatrixXd, Eigen::VectorXd > projectFvMatrix(fvMatrix< Type > &matrix, PtrList< GeometricField< Type, PatchField, GeoMesh > > &modes, label Nmodes)
Obtain the Mass Matrix from a list of reduced basis.
static Eigen::Map< Eigen::MatrixXd > field2EigenMapBC(GeometricField< scalar, PatchField, GeoMesh > &field, int BC_index)
Map a scalar OpenFOAM field boundary into an Eigen Matrix.
static void fvMatrix2EigenM(fvMatrix< type_foam_matrix > &foam_matrix, type_A &A)
Convert a ldu OpenFOAM matrix into a Eigen Matrix A.
void assignBC(GeometricField< scalar, fvPatchField, volMesh > &s, label BC_ind, double value)
Assign uniform Boundary Condition to a volScalarField.