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;
212 else if (typeBC ==
"empty" || typeBC ==
"zeroGradient")
219 if (typeBC !=
"fixedGradient" && typeBC !=
"freestream" && typeBC !=
"empty"
220 && typeBC !=
"zeroGradient" && typeBC !=
"fixedValue" && typeBC !=
"calculated"
221 && typeBC !=
"fixedFluxPressure" && typeBC !=
"processor"
222 && typeBC !=
"nutkWallFunction" && typeBC !=
"mixedEnergy")
224 word message =
"Pay attention, your typeBC " + typeBC +
" for " + s.name() +
225 " is not included into the developed ones. Your BC will be treated as a classical fixedValue.";
229 catch (
const word message)
233 WarningInFunction << message << endl;
237 for (label
i = 0;
i < sizeBC;
i++)
239 double value = valueList[
i];
240 s.boundaryFieldRef()[BC_ind][
i] = value;
245void assignBC(GeometricField<vector, fvPatchField, volMesh>& s, label BC_ind,
249 "The size of the given vector has to be equal to 3 for the 3 components");
250 label sizeBC = s.boundaryField()[BC_ind].size();
251 List<vector> valueList(sizeBC);
253 for (label
i = 0;
i < sizeBC;
i++)
255 valueList[
i] = value;
261void assignBC(GeometricField<tensor, fvPatchField, volMesh>& s, label BC_ind,
265 "The size of the given vector has to be equal to 3x3 for the 3x3 components");
266 label sizeBC = s.boundaryField()[BC_ind].size();
267 List<tensor> valueList(sizeBC);
269 for (label
i = 0;
i < sizeBC;
i++)
271 valueList[
i] = value;
277void assignBC(GeometricField<vector, fvPatchField, volMesh>& s, label BC_ind,
278 Eigen::MatrixXd valueVec)
280 label sizeBC = s.boundaryField()[BC_ind].size();
281 M_Assert(sizeBC * 3 == valueVec.size(),
282 "The size of the given values matrix has to be equal to 3 times the dimension of the boundaryField");
283 List<vector> valueList(sizeBC);
285 for (label
i = 0;
i < sizeBC;
i++)
287 for (label j = 0; j < 3; j++)
289 valueList[
i].component(j) = valueVec(
i + sizeBC * j);
296void assignBC(GeometricField<tensor, fvPatchField, volMesh>& s, label BC_ind,
297 Eigen::MatrixXd valueVec)
299 label sizeBC = s.boundaryField()[BC_ind].size();
300 M_Assert(sizeBC * 9 == valueVec.size(),
301 "The size of the given values matrix has to be equal to 9 times the dimension of the boundaryField");
302 List<tensor> valueList(sizeBC);
304 for (label
i = 0;
i < sizeBC;
i++)
306 for (label j = 0; j < 9; j++)
308 valueList[
i].component(j) = valueVec(
i + sizeBC * j);
315void assignBC(GeometricField<scalar, fvsPatchField, surfaceMesh>& s,
316 label BC_ind, Eigen::MatrixXd valueVec)
318 label sizeBC = s.boundaryField()[BC_ind].size();
319 M_Assert(sizeBC == valueVec.rows() && valueVec.cols() == 1,
320 "The given matrix must be a column one with the size equal to 3 times the dimension of the boundaryField");
321 List<scalar> valueList(sizeBC);
323 for (label
i = 0;
i < sizeBC;
i++)
325 valueList[
i] = valueVec(
i);
331void assignBC(GeometricField<vector, fvsPatchField, surfaceMesh>& s,
332 label BC_ind, Eigen::MatrixXd valueVec)
334 label sizeBC = s.boundaryField()[BC_ind].size();
335 M_Assert(sizeBC * 3 == valueVec.rows() && valueVec.cols() == 1,
336 "The given matrix must be a column one with the size equal to the dimension of the boundaryField");
337 List<vector> valueList(sizeBC);
339 for (label
i = 0;
i < sizeBC;
i++)
341 valueList[
i].component(0) = valueVec(
i);
342 valueList[
i].component(1) = valueVec(
i + sizeBC);
343 valueList[
i].component(2) = valueVec(
i + sizeBC * 2);
350void assignBC(GeometricField<vector, fvPatchField, volMesh>& s, label BC_ind,
351 List<vector> valueList)
353 word typeBC = s.boundaryField()[BC_ind].type();
354 label sizeBC = s.boundaryField()[BC_ind].size();
355 M_Assert(sizeBC == valueList.size(),
356 "The size of the given values list has to be equal to the dimension of the boundaryField");
359 if (s.boundaryField()[BC_ind].type() ==
"fixedGradient")
361 Info <<
"This Feature is not implemented for this boundary condition" << endl;
364 else if (s.boundaryField()[BC_ind].type() ==
"freestream")
366 for (label
i = 0;
i < s.boundaryField()[BC_ind].size();
i++)
368 s.boundaryFieldRef()[BC_ind][
i] = valueList[
i];
371 freestreamFvPatchField<vector>& Tpatch =
372 refCast<freestreamFvPatchField<vector >> (s.boundaryFieldRef()[BC_ind]);
373 vectorField& gradTpatch = Tpatch.freestreamValue();
376 gradTpatch[faceI] = valueList[faceI];
380 else if (s.boundaryField()[BC_ind].type() ==
"empty"
381 || s.boundaryField()[BC_ind].type() ==
"zeroGradient")
388 if (typeBC !=
"fixedGradient" && typeBC !=
"freestream" && typeBC !=
"empty"
389 && typeBC !=
"zeroGradient" && typeBC !=
"fixedValue" && typeBC !=
"calculated"
390 && typeBC !=
"processor")
392 word message =
"Pay attention, your typeBC " + typeBC +
" for " + s.name() +
393 " is not included into the developed ones. Your BC will be treated as a classical fixedValue.";
397 catch (
const word message)
401 WarningInFunction << message << endl;
405 for (label
i = 0;
i < sizeBC;
i++)
407 s.boundaryFieldRef()[BC_ind][
i] = valueList[
i];
414void assignBC(GeometricField<tensor, fvPatchField, volMesh>& s, label BC_ind,
415 List<tensor> valueList)
417 word typeBC = s.boundaryField()[BC_ind].type();
418 label sizeBC = s.boundaryField()[BC_ind].size();
419 M_Assert(sizeBC == valueList.size(),
420 "The size of the given values list has to be equal to the dimension of the boundaryField");
423 if (s.boundaryField()[BC_ind].type() ==
"fixedGradient")
425 Info <<
"This Feature is not implemented for this boundary condition" << endl;
428 else if (s.boundaryField()[BC_ind].type() ==
"freestream")
430 for (label
i = 0;
i < s.boundaryField()[BC_ind].size();
i++)
432 s.boundaryFieldRef()[BC_ind][
i] = valueList[
i];
435 freestreamFvPatchField<tensor>& Tpatch =
436 refCast<freestreamFvPatchField<tensor >> (s.boundaryFieldRef()[BC_ind]);
437 tensorField& gradTpatch = Tpatch.freestreamValue();
440 gradTpatch[faceI] = valueList[faceI];
444 else if (s.boundaryField()[BC_ind].type() ==
"empty"
445 || s.boundaryField()[BC_ind].type() ==
"zeroGradient")
452 if (typeBC !=
"fixedGradient" && typeBC !=
"freestream" && typeBC !=
"empty"
453 && typeBC !=
"zeroGradient" && typeBC !=
"fixedValue" && typeBC !=
"calculated"
454 && typeBC !=
"processor")
456 word message =
"Pay attention, your typeBC " + typeBC +
" for " + s.name() +
457 " is not included into the developed ones. Your BC will be treated as a classical fixedValue.";
461 catch (
const word message)
465 WarningInFunction << message << endl;
469 for (label
i = 0;
i < sizeBC;
i++)
471 s.boundaryFieldRef()[BC_ind][
i] = valueList[
i];
477template<
typename Type>
478void assignBC(GeometricField<Type, fvsPatchField, surfaceMesh>& s,
480 List<Type>& valueList)
482 word typeBC = s.boundaryField()[BC_ind].type();
483 label sizeBC = s.boundaryField()[BC_ind].size();
484 M_Assert(sizeBC == valueList.size(),
485 "The size of the given values list has to be equal to the dimension of the boundaryField");
488 if (s.boundaryField()[BC_ind].type() ==
"fixedGradient")
490 fixedGradientFvPatchField<Type>& Tpatch =
491 refCast<fixedGradientFvPatchField<Type >> (s.boundaryFieldRef()[BC_ind]);
492 Field<Type>& gradTpatch = Tpatch.gradient();
495 gradTpatch[faceI] = valueList[faceI];
498 else if (s.boundaryField()[BC_ind].type() ==
"freestream")
500 for (label
i = 0;
i < s.boundaryField()[BC_ind].size();
i++)
502 s.boundaryFieldRef()[BC_ind][
i] = valueList[
i];
505 freestreamFvPatchField<Type>& Tpatch =
506 refCast<freestreamFvPatchField<Type >> (s.boundaryFieldRef()[BC_ind]);
507 Field<Type>& gradTpatch = Tpatch.freestreamValue();
510 gradTpatch[faceI] = valueList[faceI];
513 else if (s.boundaryField()[BC_ind].type() ==
"empty"
514 || s.boundaryField()[BC_ind].type() ==
"zeroGradient")
520 if (typeBC !=
"fixedGradient" && typeBC !=
"freestream" && typeBC !=
"empty"
521 || typeBC !=
"zeroGradient" && typeBC !=
"fixedValue" && typeBC !=
"calculated"
522 && typeBC !=
"fixedFluxPressure" && typeBC !=
"processor")
524 word message =
"Pay attention, your typeBC " + typeBC +
" for " + s.name() +
525 " is not included into the developed ones. Your BC will be treated as a classical fixedValue.";
529 catch (
const word message)
533 WarningInFunction << message << endl;
537 for (label
i = 0;
i < s.boundaryField()[BC_ind].size();
i++)
539 s.boundaryFieldRef()[BC_ind][
i] = valueList[
i];
545 GeometricField<scalar, fvsPatchField, surfaceMesh>& s, label BC_ind,
546 List<scalar>& valueList);
548 GeometricField<vector, fvsPatchField, surfaceMesh>& s, label BC_ind,
549 List<vector>& valueList);
551template<
typename Type>
552void assignBC(GeometricField<Type, fvsPatchField, surfaceMesh>& s,
556 label sizeBC = s.boundaryField()[BC_ind].size();
557 List<Type> valueList(sizeBC);
559 for (label
i = 0;
i < sizeBC;
i++)
561 valueList[
i] = value;
568 GeometricField<scalar, fvsPatchField, surfaceMesh>& s, label BC_ind,
571 GeometricField<vector, fvsPatchField, surfaceMesh>& s, label BC_ind,
574template<
typename Type>
579 forAll(field.mesh().boundary(),
i)
581 if (field.boundaryField()[
i].type() ==
"zeroGradient" ||
582 field.boundaryField()[
i].type() ==
"fixedGradient")
591 GeometricField<scalar, fvPatchField, volMesh>& field, scalar& value);
593 GeometricField<vector, fvPatchField, volMesh>& field, vector& value);
595template<
typename Type>
601 forAll(field.mesh().boundary(),
i)
603 if (field.boundaryField()[
i].type() ==
"fixedValue")
613 GeometricField<vector, fvPatchField, volMesh>& field);
615 GeometricField<scalar, fvPatchField, volMesh>& field);
617template<
typename Type>
619 Eigen::MatrixXd Box, Type value)
623 "The box must be a 2*3 matrix shaped in this way: \nBox = \t|x0, y0, z0|\n\t|x1, yi, z1|\n");
625 for (label
i = 0;
i < field.internalField().size();
i++)
627 auto cx = field.mesh().C()[
i].component(vector::X);
628 auto cy = field.mesh().C()[
i].component(vector::Y);
629 auto cz = field.mesh().C()[
i].component(vector::Z);
631 if (cx >= Box(0, 0) && cy >= Box(0, 1) && cz >= Box(0, 2) && cx <= Box(1, 0)
632 && cy <= Box(1, 1) && cz <= Box(1, 2) )
634 field.ref()[
i] = value;
638 for (label
i = 0;
i < field.boundaryField().size();
i++)
640 for (label j = 0; j < field.boundaryField()[
i].size(); j++)
642 if (field.boundaryField()[
i].type() ==
"fixedValue"
643 || field.boundaryField()[
i].type() ==
"calculated")
645 auto cx = field.mesh().C().boundaryField()[
i][j][0];
646 auto cy = field.mesh().C().boundaryField()[
i][j][1];
647 auto cz = field.mesh().C().boundaryField()[
i][j][2];
649 if (cx >= Box(0, 0) && cy >= Box(0, 1) && cz >= Box(0, 2) && cx <= Box(1, 0)
650 && cy <= Box(1, 1) && cz <= Box(1, 2) )
652 field.boundaryFieldRef()[
i][j] = value;
660 field, Eigen::MatrixXd Box, scalar value);
662 field, Eigen::MatrixXd Box, vector value);
664template<
typename Type>
666 labelList& movingIDS, List<Type>& originalList)
668 M_Assert(ind2set.size() == value2set.size(),
669 "The size of the indices must be equal to the size of the values list");
670 M_Assert(originalList.size() >= value2set.size(),
671 "The size of the original list of values must be bigger than the size of the list of values you want to set");
672 labelList ind_ok(ind2set);
674 for (label
i = 0;
i < ind2set.size();
i++)
676 for (label k = 0; k < movingIDS.size(); k++)
678 if (ind2set[
i] == movingIDS[k])
686 for (label
i = 0;
i < ind2set.size();
i++)
688 originalList[ind_ok[
i]] = value2set[
i];
693 labelList& movingIDS, List<scalar>& originalList);
695 labelList& movingIDS, List<vector>& originalList);
699 GeometricField<Type, fvPatchField, volMesh>& field, word BCtype,
702 field.boundaryFieldRef().set(BC_ind, fvPatchField<Type>::New(BCtype,
703 field.mesh().boundary()[BC_ind], field));
707(GeometricField<scalar, fvPatchField, volMesh>& field, word BCtype,
710(GeometricField<vector, fvPatchField, volMesh>& field, word BCtype,
713template<
typename Type>
715 GeometricField<Type, fvPatchField, volMesh>& field, label BC_ind,
716 List<Type>& value, List<Type>& grad, List<scalar>& valueFrac)
718 std::string message =
"Patch is NOT mixed. It is of type: " +
719 field.boundaryField()[BC_ind].type();
720 M_Assert(field.boundaryField()[BC_ind].type() ==
"mixed", message.c_str());
722 if (field.boundaryField()[BC_ind].type() ==
"mixed")
724 mixedFvPatchField<Type>& Tpatch =
725 refCast<mixedFvPatchField<Type >> (field.boundaryFieldRef()[BC_ind]);
726 Field<Type>& valueTpatch = Tpatch.refValue();
727 Field<Type>& gradTpatch = Tpatch.refGrad();
728 Field<scalar>& valueFracTpatch = Tpatch.valueFraction();
731 valueFracTpatch = valueFrac;
736 GeometricField<scalar, fvPatchField, volMesh>& field, label BC_ind,
737 List<scalar>& value, List<scalar>& grad, List<scalar>& valueFrac);
740 GeometricField<vector, fvPatchField, volMesh>& field, label BC_ind,
741 List<vector>& value, List<vector>& grad, List<scalar>& valueFrac);
743template<
typename Type>
745 PtrList<GeometricField<Type, fvPatchField, volMesh >> & fields)
748 word normType =
para->ITHACAdict->lookupOrDefault<word>(
"normalizationNorm",
751 normType ==
"Frobenius",
"The normalizationNorm can be only L2 or Frobenius" );
755 for (label
i = 0;
i < fields.size();
i++)
759 if (normType ==
"L2")
763 else if (normType ==
"Frobenius")
768 GeometricField<Type, fvPatchField, volMesh> tmp2(fields[0].name(),
770 Eigen::VectorXd vec = eigenFields.col(
i) / norm;
774 for (label k = 0; k < tmp2.boundaryField().size(); k++)
776 Eigen::MatrixXd vec = eigenFieldsBC[k].col(
i) / norm;
780 fields.set(
i, tmp2.clone());
785 PtrList<GeometricField<scalar, fvPatchField, volMesh >> & fields);
787 PtrList<GeometricField<vector, fvPatchField, volMesh >>& fields);
790template<
typename Type>
791Eigen::MatrixXd
getValues(GeometricField<Type, fvPatchField,
792 volMesh>& field, labelList& indices)
794 List<Type> list(indices.size());
795 M_Assert(max(indices) < field.size(),
796 "The list indices are too large respect to field dimension");
798 for (label
i = 0;
i < indices.size();
i++)
800 list[
i] = field[indices[
i]];
807Eigen::MatrixXd
getValues(GeometricField<vector, fvPatchField,
808 volMesh>& field, labelList& indices, labelList* xyz)
810 M_Assert(max(indices) < field.size(),
811 "The list of indices is too large respect to field dimension. There is at least one value larger than the dimension of the list");
816 list.resize(indices.size());
818 "The list of xyz positions contains at list one value larger than 2");
821 for (label
i = 0;
i < indices.size();
i++)
823 list[
i] = field[indices[
i]][l[
i]];
831 list.resize(indices.size());
833 for (label
i = 0;
i < indices.size();
i++)
835 list[
i] = field[indices[
i]];
843Eigen::MatrixXd
getValues(GeometricField<scalar, fvPatchField,
844 volMesh>& field, labelList& indices, labelList* xyz)
846 M_Assert(max(indices) < field.size(),
847 "The list of indices is too large respect to field dimension. There is at least one value larger than the dimension of the list");
849 list.resize(indices.size());
851 for (label
i = 0;
i < indices.size();
i++)
853 list[
i] = field[indices[
i]];
860Eigen::MatrixXd
getValues(PtrList<GeometricField<
T, fvPatchField,
861 volMesh >> & fields, labelList& indices, labelList* xyz)
864 Eigen::MatrixXd a =
getValues(fields[0], indices, xyz);
865 out.resize(a.rows(), fields.size());
867 for (label
i = 1;
i < fields.size();
i++)
877Eigen::MatrixXd
getValues(PtrList<GeometricField<scalar, fvPatchField,
878 volMesh >>& fields, labelList& indices, labelList* xyz);
880Eigen::MatrixXd
getValues(PtrList<GeometricField<vector, fvPatchField,
881 volMesh >> & fields, labelList& indices, labelList* xyz);