30template<
class TypeField>
32 fields, Eigen::MatrixXd ind, PtrList<TypeField>& ave)
34 PtrList<TypeField> aveSubtracted;
35 Eigen::VectorXd newInd;
36 newInd.resize(ind.size() + 1);
37 newInd.head(ind.size()) = ind;
38 newInd(ind.size()) = fields.size();
40 for (label
i = 0;
i < ind.size();
i++)
42 TypeField aveTemp(
"nut", fields[0] * 0);
44 for (label j = newInd(
i); j < newInd(
i + 1); j++)
49 aveTemp /= newInd(
i + 1) - newInd(
i);
50 ave.append(aveTemp.clone());
53 for (label
i = 0;
i < ind.size();
i++)
55 for (label j = newInd(
i); j < newInd(
i + 1); j++)
57 TypeField newfield(
"nut", fields[0] * 0);
58 newfield = fields[j] - ave[
i];
59 aveSubtracted.append(newfield.clone());
67 PtrList<volScalarField>
68 fields, Eigen::MatrixXd ind, PtrList<volScalarField>& ave);
70 PtrList<volVectorField>
71 fields, Eigen::MatrixXd ind, PtrList<volVectorField>& ave);
73template<
class TypeField>
76 TypeField av(fields[0]);
78 for (label
i = 1;
i < fields.size();
i++)
83 av = av / fields.size();
88 PtrList<volVectorField>& fields);
90 PtrList<volScalarField>& fields);
93template<
typename Type>
94void assignIF(GeometricField<Type, fvPatchField, volMesh>& s,
97 for (label
i = 0;
i < s.internalField().size();
i++)
104 GeometricField<scalar, fvPatchField, volMesh>& field, scalar value);
106 GeometricField<vector, fvPatchField, volMesh>& field, vector value);
108template<
typename Type>
109void assignIF(GeometricField<Type, fvPatchField, volMesh>& s,
110 Type& value, List<label>& indices)
112 for (label
i = 0;
i < indices.size();
i++)
114 s.ref()[indices[
i]] = value;
118template void assignIF(GeometricField<scalar, fvPatchField, volMesh>& s,
119 scalar& value, List<label>& indices);
120template void assignIF(GeometricField<vector, fvPatchField, volMesh>& s,
121 vector& value, List<label>& indices);
123template<
typename Type>
124void assignIF(GeometricField<Type, fvPatchField, volMesh>& s,
125 Type& value, label index)
127 s.ref()[index] = value;
130template void assignIF(GeometricField<scalar, fvPatchField, volMesh>& field,
131 scalar& value, label index);
132template void assignIF(GeometricField<vector, fvPatchField, volMesh>& field,
133 vector& value, label index);
137 for (label
i = 0;
i < L.size();
i++)
143void assignBC(GeometricField<scalar, fvPatchField, volMesh>& s, label BC_ind,
146 label sizeBC = s.boundaryField()[BC_ind].size();
147 List<double> valueList(sizeBC);
149 for (label
i = 0;
i < sizeBC;
i++)
151 valueList[
i] = value;
157void assignBC(GeometricField<scalar, fvPatchField, volMesh>& s, label BC_ind,
158 Eigen::MatrixXd valueVec)
160 label sizeBC = s.boundaryField()[BC_ind].size();
162 "The size of the given values matrix has to be equal to the dimension of the boundaryField");
163 List<double> valueList(sizeBC);
165 for (label
i = 0;
i < sizeBC;
i++)
167 valueList[
i] = valueVec(
i);
174void assignBC(GeometricField<scalar, fvPatchField, volMesh>& s, label BC_ind,
175 List<double> valueList)
177 word typeBC = s.boundaryField()[BC_ind].type();
178 label sizeBC = s.boundaryField()[BC_ind].size();
179 M_Assert(sizeBC == valueList.size(),
180 "The size of the given values list has to be equal to the dimension of the boundaryField");
183 if (typeBC ==
"fixedGradient")
185 fixedGradientFvPatchScalarField& Tpatch =
186 refCast<fixedGradientFvPatchScalarField>(s.boundaryFieldRef()[BC_ind]);
187 scalarField& gradTpatch = Tpatch.gradient();
190 double value = valueList[faceI];
191 gradTpatch[faceI] = value;
194 else if (typeBC ==
"freestream")
196 for (label
i = 0;
i < sizeBC;
i++)
198 double value = valueList[
i];
199 s.boundaryFieldRef()[BC_ind][
i] = value;
202 freestreamFvPatchField<scalar>& Tpatch =
203 refCast<freestreamFvPatchField<scalar>>(s.boundaryFieldRef()[BC_ind]);
204 scalarField& gradTpatch = Tpatch.freestreamValue();
207 double value = valueList[faceI];
208 gradTpatch[faceI] = value;
211 else if (typeBC ==
"empty" || typeBC ==
"zeroGradient")
217 if (typeBC !=
"fixedGradient" && typeBC !=
"freestream" && typeBC !=
"empty"
218 && typeBC !=
"zeroGradient" && typeBC !=
"fixedValue" && typeBC !=
"calculated"
219 && typeBC !=
"fixedFluxPressure" && typeBC !=
"processor"
220 && typeBC !=
"nutkWallFunction" && typeBC !=
"mixedEnergy")
222 word message =
"Pay attention, your typeBC " + typeBC +
" for " + s.name() +
223 " is not included into the developed ones. Your BC will be treated as a classical fixedValue.";
227 catch (
const word message)
231 WarningInFunction << message << endl;
235 for (label
i = 0;
i < sizeBC;
i++)
237 double value = valueList[
i];
238 s.boundaryFieldRef()[BC_ind][
i] = value;
243void assignBC(GeometricField<vector, fvPatchField, volMesh>& s, label BC_ind,
247 "The size of the given vector has to be equal to 3 for the 3 components");
248 label sizeBC = s.boundaryField()[BC_ind].size();
249 List<vector> valueList(sizeBC);
251 for (label
i = 0;
i < sizeBC;
i++)
253 valueList[
i] = value;
259void assignBC(GeometricField<tensor, fvPatchField, volMesh>& s, label BC_ind,
263 "The size of the given vector has to be equal to 3x3 for the 3x3 components");
264 label sizeBC = s.boundaryField()[BC_ind].size();
265 List<tensor> valueList(sizeBC);
267 for (label
i = 0;
i < sizeBC;
i++)
269 valueList[
i] = value;
275void assignBC(GeometricField<vector, fvPatchField, volMesh>& s, label BC_ind,
276 Eigen::MatrixXd valueVec)
278 label sizeBC = s.boundaryField()[BC_ind].size();
279 M_Assert(sizeBC * 3 == valueVec.size(),
280 "The size of the given values matrix has to be equal to 3 times the dimension of the boundaryField");
281 List<vector> valueList(sizeBC);
282 for (label
i = 0;
i < sizeBC;
i++)
284 for (label j = 0; j < 3; j++)
286 valueList[
i].component(j) = valueVec(
i + sizeBC * j);
293void assignBC(GeometricField<tensor, fvPatchField, volMesh>& s, label BC_ind,
294 Eigen::MatrixXd valueVec)
296 label sizeBC = s.boundaryField()[BC_ind].size();
297 M_Assert(sizeBC * 9 == valueVec.size(),
298 "The size of the given values matrix has to be equal to 9 times the dimension of the boundaryField");
299 List<tensor> valueList(sizeBC);
301 for (label
i = 0;
i < sizeBC;
i++)
303 for (label j = 0; j < 9; j++)
305 valueList[
i].component(j) = valueVec(
i + sizeBC * j);
312void assignBC(GeometricField<scalar, fvsPatchField, surfaceMesh>& s,
313 label BC_ind, Eigen::MatrixXd valueVec)
315 label sizeBC = s.boundaryField()[BC_ind].size();
316 M_Assert(sizeBC == valueVec.rows() && valueVec.cols() == 1,
317 "The given matrix must be a column one with the size equal to 3 times the dimension of the boundaryField");
318 List<scalar> valueList(sizeBC);
320 for (label
i = 0;
i < sizeBC;
i++)
322 valueList[
i] = valueVec(
i);
328void assignBC(GeometricField<vector, fvsPatchField, surfaceMesh>& s,
329 label BC_ind, Eigen::MatrixXd valueVec)
331 label sizeBC = s.boundaryField()[BC_ind].size();
332 M_Assert(sizeBC * 3 == valueVec.rows() && valueVec.cols() == 1,
333 "The given matrix must be a column one with the size equal to the dimension of the boundaryField");
334 List<vector> valueList(sizeBC);
336 for (label
i = 0;
i < sizeBC;
i++)
338 valueList[
i].component(0) = valueVec(
i);
339 valueList[
i].component(1) = valueVec(
i + sizeBC);
340 valueList[
i].component(2) = valueVec(
i + sizeBC * 2);
347void assignBC(GeometricField<vector, fvPatchField, volMesh>& s, label BC_ind,
348 List<vector> valueList)
350 word typeBC = s.boundaryField()[BC_ind].type();
351 label sizeBC = s.boundaryField()[BC_ind].size();
352 M_Assert(sizeBC == valueList.size(),
353 "The size of the given values list has to be equal to the dimension of the boundaryField");
356 if (s.boundaryField()[BC_ind].type() ==
"fixedGradient")
358 Info <<
"This Feature is not implemented for this boundary condition" << endl;
361 else if (s.boundaryField()[BC_ind].type() ==
"freestream")
363 for (label
i = 0;
i < s.boundaryField()[BC_ind].size();
i++)
365 s.boundaryFieldRef()[BC_ind][
i] = valueList[
i];
368 freestreamFvPatchField<vector>& Tpatch =
369 refCast<freestreamFvPatchField<vector>>(s.boundaryFieldRef()[BC_ind]);
370 vectorField& gradTpatch = Tpatch.freestreamValue();
373 gradTpatch[faceI] = valueList[faceI];
376 else if (s.boundaryField()[BC_ind].type() ==
"empty"
377 || s.boundaryField()[BC_ind].type() ==
"zeroGradient")
383 if (typeBC !=
"fixedGradient" && typeBC !=
"freestream" && typeBC !=
"empty"
384 && typeBC !=
"zeroGradient" && typeBC !=
"fixedValue" && typeBC !=
"calculated"
385 && typeBC !=
"processor")
387 word message =
"Pay attention, your typeBC " + typeBC +
" for " + s.name() +
388 " is not included into the developed ones. Your BC will be treated as a classical fixedValue.";
392 catch (
const word message)
396 WarningInFunction << message << endl;
400 for (label
i = 0;
i < sizeBC;
i++)
402 s.boundaryFieldRef()[BC_ind][
i] = valueList[
i];
409void assignBC(GeometricField<tensor, fvPatchField, volMesh>& s, label BC_ind,
410 List<tensor> valueList)
412 word typeBC = s.boundaryField()[BC_ind].type();
413 label sizeBC = s.boundaryField()[BC_ind].size();
414 M_Assert(sizeBC == valueList.size(),
415 "The size of the given values list has to be equal to the dimension of the boundaryField");
418 if (s.boundaryField()[BC_ind].type() ==
"fixedGradient")
420 Info <<
"This Feature is not implemented for this boundary condition" << endl;
423 else if (s.boundaryField()[BC_ind].type() ==
"freestream")
425 for (label
i = 0;
i < s.boundaryField()[BC_ind].size();
i++)
427 s.boundaryFieldRef()[BC_ind][
i] = valueList[
i];
430 freestreamFvPatchField<tensor>& Tpatch =
431 refCast<freestreamFvPatchField<tensor>>(s.boundaryFieldRef()[BC_ind]);
432 tensorField& gradTpatch = Tpatch.freestreamValue();
435 gradTpatch[faceI] = valueList[faceI];
438 else if (s.boundaryField()[BC_ind].type() ==
"empty"
439 || s.boundaryField()[BC_ind].type() ==
"zeroGradient")
445 if (typeBC !=
"fixedGradient" && typeBC !=
"freestream" && typeBC !=
"empty"
446 && typeBC !=
"zeroGradient" && typeBC !=
"fixedValue" && typeBC !=
"calculated"
447 && typeBC !=
"processor")
449 word message =
"Pay attention, your typeBC " + typeBC +
" for " + s.name() +
450 " is not included into the developed ones. Your BC will be treated as a classical fixedValue.";
454 catch (
const word message)
458 WarningInFunction << message << endl;
462 for (label
i = 0;
i < sizeBC;
i++)
464 s.boundaryFieldRef()[BC_ind][
i] = valueList[
i];
470template<
typename Type>
471void assignBC(GeometricField<Type, fvsPatchField, surfaceMesh>& s, label BC_ind,
472 List<Type>& valueList)
474 word typeBC = s.boundaryField()[BC_ind].type();
475 label sizeBC = s.boundaryField()[BC_ind].size();
476 M_Assert(sizeBC == valueList.size(),
477 "The size of the given values list has to be equal to the dimension of the boundaryField");
480 if (s.boundaryField()[BC_ind].type() ==
"fixedGradient")
482 fixedGradientFvPatchField<Type>& Tpatch =
483 refCast<fixedGradientFvPatchField<Type>>(s.boundaryFieldRef()[BC_ind]);
484 Field<Type>& gradTpatch = Tpatch.gradient();
487 gradTpatch[faceI] = valueList[faceI];
490 else if (s.boundaryField()[BC_ind].type() ==
"freestream")
492 for (label
i = 0;
i < s.boundaryField()[BC_ind].size();
i++)
494 s.boundaryFieldRef()[BC_ind][
i] = valueList[
i];
497 freestreamFvPatchField<Type>& Tpatch =
498 refCast<freestreamFvPatchField<Type>>(s.boundaryFieldRef()[BC_ind]);
499 Field<Type>& gradTpatch = Tpatch.freestreamValue();
502 gradTpatch[faceI] = valueList[faceI];
505 else if (s.boundaryField()[BC_ind].type() ==
"empty"
506 || s.boundaryField()[BC_ind].type() ==
"zeroGradient")
512 if (typeBC !=
"fixedGradient" && typeBC !=
"freestream" && typeBC !=
"empty"
513 || typeBC !=
"zeroGradient" && typeBC !=
"fixedValue" && typeBC !=
"calculated"
514 && typeBC !=
"fixedFluxPressure" && typeBC !=
"processor")
516 word message =
"Pay attention, your typeBC " + typeBC +
" for " + s.name() +
517 " is not included into the developed ones. Your BC will be treated as a classical fixedValue.";
521 catch (
const word message)
525 WarningInFunction << message << endl;
529 for (label
i = 0;
i < s.boundaryField()[BC_ind].size();
i++)
531 s.boundaryFieldRef()[BC_ind][
i] = valueList[
i];
537 GeometricField<scalar, fvsPatchField, surfaceMesh>& s, label BC_ind,
538 List<scalar>& valueList);
540 GeometricField<vector, fvsPatchField, surfaceMesh>& s, label BC_ind,
541 List<vector>& valueList);
543template<
typename Type>
544void assignBC(GeometricField<Type, fvsPatchField, surfaceMesh>& s, label BC_ind,
547 label sizeBC = s.boundaryField()[BC_ind].size();
548 List<Type> valueList(sizeBC);
550 for (label
i = 0;
i < sizeBC;
i++)
552 valueList[
i] = value;
559 GeometricField<scalar, fvsPatchField, surfaceMesh>& s, label BC_ind,
562 GeometricField<vector, fvsPatchField, surfaceMesh>& s, label BC_ind,
565template<
typename Type>
569 forAll(field.mesh().boundary(),
i)
571 if (field.boundaryField()[
i].type() ==
"zeroGradient" ||
572 field.boundaryField()[
i].type() ==
"fixedGradient")
581 GeometricField<scalar, fvPatchField, volMesh>& field, scalar& value);
583 GeometricField<vector, fvPatchField, volMesh>& field, vector& value);
585template<
typename Type>
591 forAll(field.mesh().boundary(),
i)
593 if (field.boundaryField()[
i].type() ==
"fixedValue")
601 GeometricField<vector, fvPatchField, volMesh>& field);
603 GeometricField<scalar, fvPatchField, volMesh>& field);
605template<
typename Type>
607 Eigen::MatrixXd Box, Type value)
611 "The box must be a 2*3 matrix shaped in this way: \nBox = \t|x0, y0, z0|\n\t|x1, yi, z1|\n");
613 for (label
i = 0;
i < field.internalField().size();
i++)
615 auto cx = field.mesh().C()[
i].component(vector::X);
616 auto cy = field.mesh().C()[
i].component(vector::Y);
617 auto cz = field.mesh().C()[
i].component(vector::Z);
619 if (cx >= Box(0, 0) && cy >= Box(0, 1) && cz >= Box(0, 2) && cx <= Box(1, 0)
620 && cy <= Box(1, 1) && cz <= Box(1, 2) )
622 field.ref()[
i] = value;
626 for (label
i = 0;
i < field.boundaryField().size();
i++)
628 for (label j = 0; j < field.boundaryField()[
i].size(); j++)
630 if (field.boundaryField()[
i].type() ==
"fixedValue"
631 || field.boundaryField()[
i].type() ==
"calculated")
633 auto cx = field.mesh().C().boundaryField()[
i][j][0];
634 auto cy = field.mesh().C().boundaryField()[
i][j][1];
635 auto cz = field.mesh().C().boundaryField()[
i][j][2];
637 if (cx >= Box(0, 0) && cy >= Box(0, 1) && cz >= Box(0, 2) && cx <= Box(1, 0)
638 && cy <= Box(1, 1) && cz <= Box(1, 2) )
640 field.boundaryFieldRef()[
i][j] = value;
648 field, Eigen::MatrixXd Box, scalar value);
650 field, Eigen::MatrixXd Box, vector value);
652template<
typename Type>
654 labelList& movingIDS, List<Type>& originalList)
656 M_Assert(ind2set.size() == value2set.size(),
657 "The size of the indices must be equal to the size of the values list");
658 M_Assert(originalList.size() >= value2set.size(),
659 "The size of the original list of values must be bigger than the size of the list of values you want to set");
660 labelList ind_ok(ind2set);
662 for (label
i = 0;
i < ind2set.size();
i++)
664 for (label k = 0; k < movingIDS.size(); k++)
666 if (ind2set[
i] == movingIDS[k])
674 for (label
i = 0;
i < ind2set.size();
i++)
676 originalList[ind_ok[
i]] = value2set[
i];
681 labelList& movingIDS, List<scalar>& originalList);
683 labelList& movingIDS, List<vector>& originalList);
687 GeometricField<Type, fvPatchField, volMesh>& field, word BCtype,
690 field.boundaryFieldRef().set(BC_ind, fvPatchField<Type>::New(BCtype,
691 field.mesh().boundary()[BC_ind], field));
695(GeometricField<scalar, fvPatchField, volMesh>& field, word BCtype,
698(GeometricField<vector, fvPatchField, volMesh>& field, word BCtype,
701template<
typename Type>
703 GeometricField<Type, fvPatchField, volMesh>& field, label BC_ind,
704 List<Type>& value, List<Type>& grad, List<scalar>& valueFrac)
706 std::string message =
"Patch is NOT mixed. It is of type: " +
707 field.boundaryField()[BC_ind].type();
708 M_Assert(field.boundaryField()[BC_ind].type() ==
"mixed", message.c_str());
710 if (field.boundaryField()[BC_ind].type() ==
"mixed")
712 mixedFvPatchField<Type>& Tpatch =
713 refCast<mixedFvPatchField<Type>>(field.boundaryFieldRef()[BC_ind]);
714 Field<Type>& valueTpatch = Tpatch.refValue();
715 Field<Type>& gradTpatch = Tpatch.refGrad();
716 Field<scalar>& valueFracTpatch = Tpatch.valueFraction();
719 valueFracTpatch = valueFrac;
724 GeometricField<scalar, fvPatchField, volMesh>& field, label BC_ind,
725 List<scalar>& value, List<scalar>& grad, List<scalar>& valueFrac);
728 GeometricField<vector, fvPatchField, volMesh>& field, label BC_ind,
729 List<vector>& value, List<vector>& grad, List<scalar>& valueFrac);
731template<
typename Type>
733 PtrList<GeometricField<Type, fvPatchField, volMesh>>& fields)
736 word normType = para->
ITHACAdict->lookupOrDefault<word>(
"normalizationNorm",
739 normType ==
"Frobenius",
"The normalizationNorm can be only L2 or Frobenius" );
743 for (label
i = 0;
i < fields.size();
i++)
747 if (normType ==
"L2")
751 else if (normType ==
"Frobenius")
756 GeometricField<Type, fvPatchField, volMesh> tmp2(fields[0].name(),
758 Eigen::VectorXd vec = eigenFields.col(
i) / norm;
762 for (label k = 0; k < tmp2.boundaryField().size(); k++)
764 Eigen::MatrixXd vec = eigenFieldsBC[k].col(
i) / norm;
768 fields.set(
i, tmp2.clone());
773 PtrList<GeometricField<scalar, fvPatchField, volMesh>>& fields);
775 PtrList<GeometricField<vector, fvPatchField, volMesh>>& fields);
778template<
typename Type>
779Eigen::MatrixXd
getValues(GeometricField<Type, fvPatchField,
780 volMesh>& field, labelList& indices)
782 List<Type> list(indices.size());
783 M_Assert(max(indices) < field.size(),
784 "The list indices are too large respect to field dimension");
786 for (label
i = 0;
i < indices.size();
i++)
788 list[
i] = field[indices[
i]];
795Eigen::MatrixXd
getValues(GeometricField<vector, fvPatchField,
796 volMesh>& field, labelList& indices, labelList* xyz)
798 M_Assert(max(indices) < field.size(),
799 "The list of indices is too large respect to field dimension. There is at least one value larger than the dimension of the list");
804 list.resize(indices.size());
806 "The list of xyz positions contains at list one value larger than 2");
809 for (label
i = 0;
i < indices.size();
i++)
811 list[
i] = field[indices[
i]][l[
i]];
819 list.resize(indices.size());
821 for (label
i = 0;
i < indices.size();
i++)
823 list[
i] = field[indices[
i]];
831Eigen::MatrixXd
getValues(GeometricField<scalar, fvPatchField,
832 volMesh>& field, labelList& indices, labelList* xyz)
834 M_Assert(max(indices) < field.size(),
835 "The list of indices is too large respect to field dimension. There is at least one value larger than the dimension of the list");
837 list.resize(indices.size());
839 for (label
i = 0;
i < indices.size();
i++)
841 list[
i] = field[indices[
i]];
848Eigen::MatrixXd
getValues(PtrList<GeometricField<
T, fvPatchField,
849 volMesh>>& fields, labelList& indices, labelList* xyz)
852 Eigen::MatrixXd a =
getValues(fields[0], indices, xyz);
853 out.resize(a.rows(), fields.size());
856 for (label
i = 1;
i < fields.size();
i++)
866Eigen::MatrixXd
getValues(PtrList<GeometricField<scalar, fvPatchField,
867 volMesh>>& fields, labelList& indices, labelList* xyz);
869Eigen::MatrixXd
getValues(PtrList<GeometricField<vector, fvPatchField,
870 volMesh>>& fields, labelList& indices, labelList* xyz);