Loading...
Searching...
No Matches
ITHACAassign.C
Go to the documentation of this file.
1/*---------------------------------------------------------------------------*\
2 ██╗████████╗██╗ ██╗ █████╗ ██████╗ █████╗ ███████╗██╗ ██╗
3 ██║╚══██╔══╝██║ ██║██╔══██╗██╔════╝██╔══██╗ ██╔════╝██║ ██║
4 ██║ ██║ ███████║███████║██║ ███████║█████╗█████╗ ██║ ██║
5 ██║ ██║ ██╔══██║██╔══██║██║ ██╔══██║╚════╝██╔══╝ ╚██╗ ██╔╝
6 ██║ ██║ ██║ ██║██║ ██║╚██████╗██║ ██║ ██║ ╚████╔╝
7 ╚═╝ ╚═╝ ╚═╝ ╚═╝╚═╝ ╚═╝ ╚═════╝╚═╝ ╚═╝ ╚═╝ ╚═══╝
8
9 * In real Time Highly Advanced Computational Applications for Finite Volumes
10 * Copyright (C) 2017 by the ITHACA-FV authors
11-------------------------------------------------------------------------------
12License
13 This file is part of ITHACA-FV
14 ITHACA-FV is free software: you can redistribute it and/or modify
15 it under the terms of the GNU Lesser General Public License as published by
16 the Free Software Foundation, either version 3 of the License, or
17 (at your option) any later version.
18 ITHACA-FV is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU Lesser General Public License for more details.
22 You should have received a copy of the GNU Lesser General Public License
23 along with ITHACA-FV. If not, see <http://www.gnu.org/licenses/>.
24\*---------------------------------------------------------------------------*/
25#include "ITHACAassign.H"
26
28{
29
30template<class TypeField>
31PtrList<TypeField> averageSubtract(PtrList<TypeField>
32 fields, Eigen::MatrixXd ind, PtrList<TypeField>& ave)
33{
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();
39
40 for (label i = 0; i < ind.size(); i++)
41 {
42 TypeField aveTemp("nut", fields[0] * 0);
43
44 for (label j = newInd(i); j < newInd(i + 1); j++)
45 {
46 aveTemp += fields[j];
47 }
48
49 aveTemp /= newInd(i + 1) - newInd(i);
50 ave.append(aveTemp.clone());
51 }
52
53 for (label i = 0; i < ind.size(); i++)
54 {
55 for (label j = newInd(i); j < newInd(i + 1); j++)
56 {
57 TypeField newfield("nut", fields[0] * 0);
58 newfield = fields[j] - ave[i];
59 aveSubtracted.append(newfield.clone());
60 }
61 }
62
63 return aveSubtracted;
64}
65
66template PtrList<volScalarField> averageSubtract(
67 PtrList<volScalarField>
68 fields, Eigen::MatrixXd ind, PtrList<volScalarField>& ave);
69template PtrList<volVectorField> averageSubtract(
70 PtrList<volVectorField>
71 fields, Eigen::MatrixXd ind, PtrList<volVectorField>& ave);
72
73template<class TypeField>
74TypeField computeAverage(PtrList<TypeField>& fields)
75{
76 TypeField av(fields[0]);
77
78 for (label i = 1; i < fields.size(); i++)
79 {
80 av += fields[i];
81 }
82
83 av = av / fields.size();
84 return av;
85}
86
87template volVectorField computeAverage(
88 PtrList<volVectorField>& fields);
89template volScalarField computeAverage(
90 PtrList<volScalarField>& fields);
91
92
93template<typename Type>
94void assignIF(GeometricField<Type, fvPatchField, volMesh>& s,
95 Type value)
96{
97 for (label i = 0; i < s.internalField().size(); i++)
98 {
99 s.ref()[i] = value;
100 }
101}
102
103template void assignIF(
104 GeometricField<scalar, fvPatchField, volMesh>& field, scalar value);
105template void assignIF(
106 GeometricField<vector, fvPatchField, volMesh>& field, vector value);
107
108template<typename Type>
109void assignIF(GeometricField<Type, fvPatchField, volMesh>& s,
110 Type& value, List<label>& indices)
111{
112 for (label i = 0; i < indices.size(); i++)
113 {
114 s.ref()[indices[i]] = value;
115 }
116}
117
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);
122
123template<typename Type>
124void assignIF(GeometricField<Type, fvPatchField, volMesh>& s,
125 Type& value, label index)
126{
127 s.ref()[index] = value;
128}
129
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);
134
135void assignONE(volScalarField& s, List<label>& L)
136{
137 for (label i = 0; i < L.size(); i++)
138 {
139 s.ref()[L[i]] = 1;
140 }
141}
142
143void assignBC(GeometricField<scalar, fvPatchField, volMesh>& s, label BC_ind,
144 double value)
145{
146 label sizeBC = s.boundaryField()[BC_ind].size();
147 List<double> valueList(sizeBC);
148
149 for (label i = 0; i < sizeBC; i++)
150 {
151 valueList[i] = value;
152 }
153
154 assignBC(s, BC_ind, valueList);
155}
156
157void assignBC(GeometricField<scalar, fvPatchField, volMesh>& s, label BC_ind,
158 Eigen::MatrixXd valueVec)
159{
160 label sizeBC = s.boundaryField()[BC_ind].size();
161 M_Assert(sizeBC == valueVec.size(),
162 "The size of the given values matrix has to be equal to the dimension of the boundaryField");
163 List<double> valueList(sizeBC);
164
165 for (label i = 0; i < sizeBC; i++)
166 {
167 valueList[i] = valueVec(i);
168 }
169
170 assignBC(s, BC_ind, valueList);
171}
172
173// Assign a BC for a scalar field
174void assignBC(GeometricField<scalar, fvPatchField, volMesh>& s, label BC_ind,
175 List<double> valueList)
176{
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");
182
183 if (typeBC == "fixedGradient")
184 {
185 fixedGradientFvPatchScalarField& Tpatch =
186 refCast<fixedGradientFvPatchScalarField>(s.boundaryFieldRef()[BC_ind]);
187 scalarField& gradTpatch = Tpatch.gradient();
188 forAll(gradTpatch, faceI)
189 {
190 double value = valueList[faceI];
191 gradTpatch[faceI] = value;
192 }
193 }
194 else if (typeBC == "freestream")
195 {
196 for (label i = 0; i < sizeBC; i++)
197 {
198 double value = valueList[i];
199 s.boundaryFieldRef()[BC_ind][i] = value;
200 }
201
202 freestreamFvPatchField<scalar>& Tpatch =
203 refCast<freestreamFvPatchField<scalar>>(s.boundaryFieldRef()[BC_ind]);
204 scalarField& gradTpatch = Tpatch.freestreamValue();
205 forAll(gradTpatch, faceI)
206 {
207 double value = valueList[faceI];
208 gradTpatch[faceI] = value;
209 }
210 }
211 else if (typeBC == "empty" || typeBC == "zeroGradient")
212 {}
213 else
214 {
215 try
216 {
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")
221 {
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.";
224 throw (message);
225 }
226 }
227 catch (const word message)
228 {
229 if (para->warnings)
230 {
231 WarningInFunction << message << endl;
232 }
233 }
234
235 for (label i = 0; i < sizeBC; i++)
236 {
237 double value = valueList[i];
238 s.boundaryFieldRef()[BC_ind][i] = value;
239 }
240 }
241}
242
243void assignBC(GeometricField<vector, fvPatchField, volMesh>& s, label BC_ind,
244 vector value)
245{
246 M_Assert(value.size() == 3,
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);
250
251 for (label i = 0; i < sizeBC; i++)
252 {
253 valueList[i] = value;
254 }
255
256 assignBC(s, BC_ind, valueList);
257}
258
259void assignBC(GeometricField<tensor, fvPatchField, volMesh>& s, label BC_ind,
260 tensor value)
261{
262 M_Assert(value.size() == 9,
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);
266
267 for (label i = 0; i < sizeBC; i++)
268 {
269 valueList[i] = value;
270 }
271
272 assignBC(s, BC_ind, valueList);
273}
274
275void assignBC(GeometricField<vector, fvPatchField, volMesh>& s, label BC_ind,
276 Eigen::MatrixXd valueVec)
277{
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++)
283 {
284 for (label j = 0; j < 3; j++)
285 {
286 valueList[i].component(j) = valueVec(i + sizeBC * j);
287 }
288 }
289
290 assignBC(s, BC_ind, valueList);
291}
292
293void assignBC(GeometricField<tensor, fvPatchField, volMesh>& s, label BC_ind,
294 Eigen::MatrixXd valueVec)
295{
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);
300
301 for (label i = 0; i < sizeBC; i++)
302 {
303 for (label j = 0; j < 9; j++)
304 {
305 valueList[i].component(j) = valueVec(i + sizeBC * j);
306 }
307 }
308
309 assignBC(s, BC_ind, valueList);
310}
311
312void assignBC(GeometricField<scalar, fvsPatchField, surfaceMesh>& s,
313 label BC_ind, Eigen::MatrixXd valueVec)
314{
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);
319
320 for (label i = 0; i < sizeBC; i++)
321 {
322 valueList[i] = valueVec(i);
323 }
324
325 assignBC(s, BC_ind, valueList);
326}
327
328void assignBC(GeometricField<vector, fvsPatchField, surfaceMesh>& s,
329 label BC_ind, Eigen::MatrixXd valueVec)
330{
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);
335
336 for (label i = 0; i < sizeBC; i++)
337 {
338 valueList[i].component(0) = valueVec(i);
339 valueList[i].component(1) = valueVec(i + sizeBC);
340 valueList[i].component(2) = valueVec(i + sizeBC * 2);
341 }
342
343 assignBC(s, BC_ind, valueList);
344}
345
346// Assign a BC for a vector field
347void assignBC(GeometricField<vector, fvPatchField, volMesh>& s, label BC_ind,
348 List<vector> valueList)
349{
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");
355
356 if (s.boundaryField()[BC_ind].type() == "fixedGradient")
357 {
358 Info << "This Feature is not implemented for this boundary condition" << endl;
359 exit(0);
360 }
361 else if (s.boundaryField()[BC_ind].type() == "freestream")
362 {
363 for (label i = 0; i < s.boundaryField()[BC_ind].size(); i++)
364 {
365 s.boundaryFieldRef()[BC_ind][i] = valueList[i];
366 }
367
368 freestreamFvPatchField<vector>& Tpatch =
369 refCast<freestreamFvPatchField<vector>>(s.boundaryFieldRef()[BC_ind]);
370 vectorField& gradTpatch = Tpatch.freestreamValue();
371 forAll(gradTpatch, faceI)
372 {
373 gradTpatch[faceI] = valueList[faceI];
374 }
375 }
376 else if (s.boundaryField()[BC_ind].type() == "empty"
377 || s.boundaryField()[BC_ind].type() == "zeroGradient")
378 {}
379 else
380 {
381 try
382 {
383 if (typeBC != "fixedGradient" && typeBC != "freestream" && typeBC != "empty"
384 && typeBC != "zeroGradient" && typeBC != "fixedValue" && typeBC != "calculated"
385 && typeBC != "processor")
386 {
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.";
389 throw (message);
390 }
391 }
392 catch (const word message)
393 {
394 if (para->warnings)
395 {
396 WarningInFunction << message << endl;
397 }
398 }
399
400 for (label i = 0; i < sizeBC; i++)
401 {
402 s.boundaryFieldRef()[BC_ind][i] = valueList[i];
403 }
404 }
405}
406
407
408// Assign a BC for a tensor field
409void assignBC(GeometricField<tensor, fvPatchField, volMesh>& s, label BC_ind,
410 List<tensor> valueList)
411{
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");
417
418 if (s.boundaryField()[BC_ind].type() == "fixedGradient")
419 {
420 Info << "This Feature is not implemented for this boundary condition" << endl;
421 exit(0);
422 }
423 else if (s.boundaryField()[BC_ind].type() == "freestream")
424 {
425 for (label i = 0; i < s.boundaryField()[BC_ind].size(); i++)
426 {
427 s.boundaryFieldRef()[BC_ind][i] = valueList[i];
428 }
429
430 freestreamFvPatchField<tensor>& Tpatch =
431 refCast<freestreamFvPatchField<tensor>>(s.boundaryFieldRef()[BC_ind]);
432 tensorField& gradTpatch = Tpatch.freestreamValue();
433 forAll(gradTpatch, faceI)
434 {
435 gradTpatch[faceI] = valueList[faceI];
436 }
437 }
438 else if (s.boundaryField()[BC_ind].type() == "empty"
439 || s.boundaryField()[BC_ind].type() == "zeroGradient")
440 {}
441 else
442 {
443 try
444 {
445 if (typeBC != "fixedGradient" && typeBC != "freestream" && typeBC != "empty"
446 && typeBC != "zeroGradient" && typeBC != "fixedValue" && typeBC != "calculated"
447 && typeBC != "processor")
448 {
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.";
451 throw (message);
452 }
453 }
454 catch (const word message)
455 {
456 if (para->warnings)
457 {
458 WarningInFunction << message << endl;
459 }
460 }
461
462 for (label i = 0; i < sizeBC; i++)
463 {
464 s.boundaryFieldRef()[BC_ind][i] = valueList[i];
465 }
466 }
467}
468
469
470template<typename Type>
471void assignBC(GeometricField<Type, fvsPatchField, surfaceMesh>& s, label BC_ind,
472 List<Type>& valueList)
473{
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");
479
480 if (s.boundaryField()[BC_ind].type() == "fixedGradient")
481 {
482 fixedGradientFvPatchField<Type>& Tpatch =
483 refCast<fixedGradientFvPatchField<Type>>(s.boundaryFieldRef()[BC_ind]);
484 Field<Type>& gradTpatch = Tpatch.gradient();
485 forAll(gradTpatch, faceI)
486 {
487 gradTpatch[faceI] = valueList[faceI];
488 }
489 }
490 else if (s.boundaryField()[BC_ind].type() == "freestream")
491 {
492 for (label i = 0; i < s.boundaryField()[BC_ind].size(); i++)
493 {
494 s.boundaryFieldRef()[BC_ind][i] = valueList[i];
495 }
496
497 freestreamFvPatchField<Type>& Tpatch =
498 refCast<freestreamFvPatchField<Type>>(s.boundaryFieldRef()[BC_ind]);
499 Field<Type>& gradTpatch = Tpatch.freestreamValue();
500 forAll(gradTpatch, faceI)
501 {
502 gradTpatch[faceI] = valueList[faceI];
503 }
504 }
505 else if (s.boundaryField()[BC_ind].type() == "empty"
506 || s.boundaryField()[BC_ind].type() == "zeroGradient")
507 {}
508 else
509 {
510 try
511 {
512 if (typeBC != "fixedGradient" && typeBC != "freestream" && typeBC != "empty"
513 || typeBC != "zeroGradient" && typeBC != "fixedValue" && typeBC != "calculated"
514 && typeBC != "fixedFluxPressure" && typeBC != "processor")
515 {
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.";
518 throw (message);
519 }
520 }
521 catch (const word message)
522 {
523 if (para->warnings)
524 {
525 WarningInFunction << message << endl;
526 }
527 }
528
529 for (label i = 0; i < s.boundaryField()[BC_ind].size(); i++)
530 {
531 s.boundaryFieldRef()[BC_ind][i] = valueList[i];
532 }
533 }
534}
535
536template void assignBC(
537 GeometricField<scalar, fvsPatchField, surfaceMesh>& s, label BC_ind,
538 List<scalar>& valueList);
539template void assignBC(
540 GeometricField<vector, fvsPatchField, surfaceMesh>& s, label BC_ind,
541 List<vector>& valueList);
542
543template<typename Type>
544void assignBC(GeometricField<Type, fvsPatchField, surfaceMesh>& s, label BC_ind,
545 Type& value)
546{
547 label sizeBC = s.boundaryField()[BC_ind].size();
548 List<Type> valueList(sizeBC);
549
550 for (label i = 0; i < sizeBC; i++)
551 {
552 valueList[i] = value;
553 }
554
555 assignBC(s, BC_ind, valueList);
556}
557
558template void assignBC(
559 GeometricField<scalar, fvsPatchField, surfaceMesh>& s, label BC_ind,
560 scalar& valueList);
561template void assignBC(
562 GeometricField<vector, fvsPatchField, surfaceMesh>& s, label BC_ind,
563 vector& valueList);
564
565template<typename Type>
566void changeNeumann2Dirichlet(GeometricField<Type, fvPatchField, volMesh>& field,
567 Type& value)
568{
569 forAll(field.mesh().boundary(), i)
570 {
571 if (field.boundaryField()[i].type() == "zeroGradient" ||
572 field.boundaryField()[i].type() == "fixedGradient")
573 {
574 ITHACAutilities::changeBCtype(field, "fixedValue", i);
575 assignBC(field, i, value);
576 }
577 }
578}
579
581 GeometricField<scalar, fvPatchField, volMesh>& field, scalar& value);
583 GeometricField<vector, fvPatchField, volMesh>& field, vector& value);
584
585template<typename Type>
586void assignZeroDirichlet(GeometricField<Type, fvPatchField, volMesh>& field)
587{
588 Type v;
589 v = v * 0;
590 assignIF(field, v);
591 forAll(field.mesh().boundary(), i)
592 {
593 if (field.boundaryField()[i].type() == "fixedValue")
594 {
595 assignBC(field, i, v);
596 }
597 }
599}
601 GeometricField<vector, fvPatchField, volMesh>& field);
603 GeometricField<scalar, fvPatchField, volMesh>& field);
604
605template<typename Type>
606void setBoxToValue(GeometricField<Type, fvPatchField, volMesh>& field,
607 Eigen::MatrixXd Box, Type value)
608{
609 M_Assert(Box.rows() == 2
610 && Box.cols() == 3,
611 "The box must be a 2*3 matrix shaped in this way: \nBox = \t|x0, y0, z0|\n\t|x1, yi, z1|\n");
612
613 for (label i = 0; i < field.internalField().size(); i++)
614 {
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);
618
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) )
621 {
622 field.ref()[i] = value;
623 }
624 }
625
626 for (label i = 0; i < field.boundaryField().size(); i++)
627 {
628 for (label j = 0; j < field.boundaryField()[i].size(); j++)
629 {
630 if (field.boundaryField()[i].type() == "fixedValue"
631 || field.boundaryField()[i].type() == "calculated")
632 {
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];
636
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) )
639 {
640 field.boundaryFieldRef()[i][j] = value;
641 }
642 }
643 }
644 }
645}
646
647template void setBoxToValue(GeometricField<scalar, fvPatchField, volMesh>&
648 field, Eigen::MatrixXd Box, scalar value);
649template void setBoxToValue(GeometricField<vector, fvPatchField, volMesh>&
650 field, Eigen::MatrixXd Box, vector value);
651
652template<typename Type>
653void setIndices2Value(labelList& ind2set, List<Type>& value2set,
654 labelList& movingIDS, List<Type>& originalList)
655{
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);
661
662 for (label i = 0; i < ind2set.size(); i++)
663 {
664 for (label k = 0; k < movingIDS.size(); k++)
665 {
666 if (ind2set[i] == movingIDS[k])
667 {
668 ind_ok[i] = k;
669 break;
670 }
671 }
672 }
673
674 for (label i = 0; i < ind2set.size(); i++)
675 {
676 originalList[ind_ok[i]] = value2set[i];
677 }
678}
679
680template void setIndices2Value(labelList& ind2set, List<scalar>& value2set,
681 labelList& movingIDS, List<scalar>& originalList);
682template void setIndices2Value(labelList& ind2set, List<vector>& value2set,
683 labelList& movingIDS, List<vector>& originalList);
684
685template<class Type>
687 GeometricField<Type, fvPatchField, volMesh>& field, word BCtype,
688 label BC_ind)
689{
690 field.boundaryFieldRef().set(BC_ind, fvPatchField<Type>::New(BCtype,
691 field.mesh().boundary()[BC_ind], field));
692}
693
695(GeometricField<scalar, fvPatchField, volMesh>& field, word BCtype,
696 label BC_ind);
698(GeometricField<vector, fvPatchField, volMesh>& field, word BCtype,
699 label BC_ind);
700
701template<typename Type>
703 GeometricField<Type, fvPatchField, volMesh>& field, label BC_ind,
704 List<Type>& value, List<Type>& grad, List<scalar>& valueFrac)
705{
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());
709
710 if (field.boundaryField()[BC_ind].type() == "mixed")
711 {
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();
717 valueTpatch = value;
718 gradTpatch = grad;
719 valueFracTpatch = valueFrac;
720 }
721}
722
724 GeometricField<scalar, fvPatchField, volMesh>& field, label BC_ind,
725 List<scalar>& value, List<scalar>& grad, List<scalar>& valueFrac);
726
728 GeometricField<vector, fvPatchField, volMesh>& field, label BC_ind,
729 List<vector>& value, List<vector>& grad, List<scalar>& valueFrac);
730
731template<typename Type>
733 PtrList<GeometricField<Type, fvPatchField, volMesh>>& fields)
734{
736 word normType = para->ITHACAdict->lookupOrDefault<word>("normalizationNorm",
737 "L2");
738 M_Assert(normType == "L2" ||
739 normType == "Frobenius", "The normalizationNorm can be only L2 or Frobenius" );
740 Eigen::MatrixXd eigenFields = Foam2Eigen::PtrList2Eigen(fields);
741 List<Eigen::MatrixXd> eigenFieldsBC = Foam2Eigen::PtrList2EigenBC(fields);
742
743 for (label i = 0; i < fields.size(); i++)
744 {
745 double norm;
746
747 if (normType == "L2")
748 {
749 norm = L2Norm(fields[i]);
750 }
751 else if (normType == "Frobenius")
752 {
753 norm = frobNorm(fields[i]);
754 }
755
756 GeometricField<Type, fvPatchField, volMesh> tmp2(fields[0].name(),
757 fields[0] * 0);
758 Eigen::VectorXd vec = eigenFields.col(i) / norm;
759 tmp2 = Foam2Eigen::Eigen2field(tmp2, vec);
760
761 // Adjusting boundary conditions
762 for (label k = 0; k < tmp2.boundaryField().size(); k++)
763 {
764 Eigen::MatrixXd vec = eigenFieldsBC[k].col(i) / norm;
765 assignBC(tmp2, k, vec);
766 }
767
768 fields.set(i, tmp2.clone());
769 }
770}
771
772template void normalizeFields(
773 PtrList<GeometricField<scalar, fvPatchField, volMesh>>& fields);
774template void normalizeFields(
775 PtrList<GeometricField<vector, fvPatchField, volMesh>>& fields);
776
777
778template<typename Type>
779Eigen::MatrixXd getValues(GeometricField<Type, fvPatchField,
780 volMesh>& field, labelList& indices)
781{
782 List<Type> list(indices.size());
783 M_Assert(max(indices) < field.size(),
784 "The list indices are too large respect to field dimension");
785
786 for (label i = 0; i < indices.size(); i++)
787 {
788 list[i] = field[indices[i]];
789 }
790
791 return Foam2Eigen::field2Eigen(list);
792}
793
794template<>
795Eigen::MatrixXd getValues(GeometricField<vector, fvPatchField,
796 volMesh>& field, labelList& indices, labelList* xyz)
797{
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");
800
801 if (xyz != NULL)
802 {
803 List<scalar> list;
804 list.resize(indices.size());
805 M_Assert(max(*xyz) <= 2,
806 "The list of xyz positions contains at list one value larger than 2");
807 labelList l = *xyz;
808
809 for (label i = 0; i < indices.size(); i++)
810 {
811 list[i] = field[indices[i]][l[i]];
812 }
813
814 return Foam2Eigen::field2Eigen(list);
815 }
816 else
817 {
818 List<vector> list;
819 list.resize(indices.size());
820
821 for (label i = 0; i < indices.size(); i++)
822 {
823 list[i] = field[indices[i]];
824 }
825
826 return Foam2Eigen::field2Eigen(list);
827 }
828}
829
830template<>
831Eigen::MatrixXd getValues(GeometricField<scalar, fvPatchField,
832 volMesh>& field, labelList& indices, labelList* xyz)
833{
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");
836 List<scalar> list;
837 list.resize(indices.size());
838
839 for (label i = 0; i < indices.size(); i++)
840 {
841 list[i] = field[indices[i]];
842 }
843
844 return Foam2Eigen::field2Eigen(list);
845}
846
847template<typename T>
848Eigen::MatrixXd getValues(PtrList<GeometricField<T, fvPatchField,
849 volMesh>>& fields, labelList& indices, labelList* xyz)
850{
851 Eigen::MatrixXd out;
852 Eigen::MatrixXd a = getValues(fields[0], indices, xyz);
853 out.resize(a.rows(), fields.size());
854 out.col(0) = a;
855
856 for (label i = 1; i < fields.size(); i++)
857 {
858 out.col(i) = getValues(fields[i], indices, xyz);
859 }
860
861 return out;
862}
863
864
865template
866Eigen::MatrixXd getValues(PtrList<GeometricField<scalar, fvPatchField,
867 volMesh>>& fields, labelList& indices, labelList* xyz);
868template
869Eigen::MatrixXd getValues(PtrList<GeometricField<vector, fvPatchField,
870 volMesh>>& fields, labelList& indices, labelList* xyz);
871
872
873}
forAll(example_CG.gList, solutionI)
Definition CGtest.H:21
#define M_Assert(Expr, Msg)
Header file of the ITHACAassign file.
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.
Definition Foam2Eigen.C:517
static Eigen::VectorXd field2Eigen(GeometricField< tensor, PatchField, GeoMesh > &field)
Convert a vector OpenFOAM field into an Eigen Vector.
Definition Foam2Eigen.C:40
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.
Definition Foam2Eigen.C:268
static Eigen::MatrixXd PtrList2Eigen(PtrList< GeometricField< Type, PatchField, GeoMesh > > &fields, label Nfields=-1)
Convert a PtrList of snapshots to Eigen matrix (only internal field)
Definition Foam2Eigen.C:649
Class for the definition of some general parameters, the parameters must be defined from the file ITH...
IOdictionary * ITHACAdict
Dictionary for input objects from file.
static ITHACAparameters * getInstance()
Gets an instance of ITHACAparameters, to be used if the instance is already existing.
volScalarField & T
Definition createT.H:46
volScalarField & v
Namespace to implement some useful assign operation of OF fields.
template void changeBCtype< vector >(GeometricField< vector, fvPatchField, volMesh > &field, word BCtype, label BC_ind)
void assignMixedBC(GeometricField< Type, fvPatchField, volMesh > &field, label BC_ind, List< Type > &value, List< Type > &grad, List< scalar > &valueFrac)
Assign value of a boundary condition of type "mixed".
void assignIF(GeometricField< Type, fvPatchField, volMesh > &s, Type value)
Assign internal field.
void changeNeumann2Dirichlet(GeometricField< Type, fvPatchField, volMesh > &field, Type &value)
Change all Neumann boundary conditions to Dirichlet boundary conditions.
double L2Norm(GeometricField< scalar, fvPatchField, volMesh > &field)
Definition ITHACAerror.C:41
template void changeBCtype< scalar >(GeometricField< scalar, fvPatchField, volMesh > &field, word BCtype, label BC_ind)
TypeField computeAverage(PtrList< TypeField > &fields)
Calculates the average of a list of fields.
void normalizeFields(PtrList< GeometricField< Type, fvPatchField, volMesh > > &fields)
Normalize list of Geometric fields.
void assignONE(volScalarField &s, List< label > &L)
Assign one to volScalarField.
double frobNorm(GeometricField< Type, PatchField, GeoMesh > &field)
Evaluate the Frobenius norm of a field.
void setIndices2Value(labelList &ind2set, List< Type > &value2set, labelList &movingIDS, List< Type > &originalList)
Sets some given Indices of a list of objects to given values.
PtrList< TypeField > averageSubtract(PtrList< TypeField > fields, Eigen::MatrixXd ind, PtrList< TypeField > &ave)
A function to compute time-averaged fields for a set of different parameter samples and also the fiel...
void assignZeroDirichlet(GeometricField< Type, fvPatchField, volMesh > &field)
Assign zero internal field.
void assignBC(GeometricField< scalar, fvPatchField, volMesh > &s, label BC_ind, double value)
Assign uniform Boundary Condition to a volScalarField.
Eigen::MatrixXd getValues(GeometricField< Type, fvPatchField, volMesh > &field, labelList &indices)
template void assignMixedBC< scalar >(GeometricField< scalar, fvPatchField, volMesh > &field, label BC_ind, List< scalar > &value, List< scalar > &grad, List< scalar > &valueFrac)
void changeBCtype(GeometricField< Type, fvPatchField, volMesh > &field, word BCtype, label BC_ind)
Change the boundary condition type for a GeometricField.
template void assignMixedBC< vector >(GeometricField< vector, fvPatchField, volMesh > &field, label BC_ind, List< vector > &value, List< vector > &grad, List< scalar > &valueFrac)
void setBoxToValue(GeometricField< Type, fvPatchField, volMesh > &field, Eigen::MatrixXd Box, Type value)
Set value of a volScalarField to a constant inside a given box.
label i
Definition pEqn.H:46