Loading...
Searching...
No Matches
faMesh.C
Go to the documentation of this file.
1/*---------------------------------------------------------------------------*\
2 ========= |
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4 \\ / O peration |
5 \\ / A nd | www.openfoam.com
6 \\/ M anipulation |
7-------------------------------------------------------------------------------
8 Copyright (C) 2016-2017 Wikki Ltd
9 Copyright (C) 2020-2025 OpenCFD Ltd.
10-------------------------------------------------------------------------------
11License
12 This file is part of OpenFOAM.
13
14 OpenFOAM is free software: you can redistribute it and/or modify it
15 under the terms of the GNU 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
19 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 for more details.
23
24 You should have received a copy of the GNU General Public License
25 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26
27\*---------------------------------------------------------------------------*/
28
29#include "faMesh.H"
30#include "faMeshBoundaryHalo.H"
31#include "faMeshesRegistry.H"
32#include "faGlobalMeshData.H"
33#include "Time.H"
34#include "polyMesh.H"
35#include "primitiveMesh.H"
36#include "IndirectList.H"
37#include "areaFields.H"
38#include "edgeFields.H"
39#include "faMeshLduAddressing.H"
40#include "processorFaPatch.H"
41#include "wedgeFaPatch.H"
42#include "faPatchData.H"
43#include "registerSwitch.H"
44
45// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
46
47namespace Foam
50
52 (
53 debug::optimisationSwitch("fa:geometryOrder", 2)
54 );
56 (
57 "fa:geometryOrder",
58 int,
60 );
61}
62
63
64const Foam::word Foam::faMesh::prefix_("finite-area");
65
67
68const int Foam::faMesh::quadricsFit_ = 0; // Tuning (experimental)
69
70
71// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
74{
75 return prefix_;
76}
77
78
80{
81 if (areaRegion.empty() || areaRegion == polyMesh::defaultRegion)
82 {
84 }
85
86 return (faMesh::prefix() / areaRegion);
87}
88
89
91(
92 const word& volRegion,
93 const word& areaRegion
94)
95{
96 return
97 (
100 / polyMesh::regionName(areaRegion)
101 );
102}
103
104
106(
107 const polyMesh& pMesh,
108 const word& areaRegion
109)
110{
111 return faMesh::dbDir(pMesh.regionName(), areaRegion);
112}
113
114
116{
117 if (areaRegion.empty() || areaRegion == polyMesh::defaultRegion)
118 {
120 }
121
122 return (areaRegion / faMesh::meshSubDir);
123}
124
125
127(
128 const word& volRegion,
129 const word& areaRegion
130)
131{
132 return
133 (
134 polyMesh::regionName(volRegion)
143(
144 const polyMesh& pMesh,
145 const word& areaRegion
146)
147{
148 return faMesh::meshDir(pMesh.regionName(), areaRegion);
149}
150
151
153{
155}
156
158// const Foam::objectRegistry* Foam::faMesh::registry(const objectRegistry& obr)
159// {
160// return obr.cfindObject<objectRegistry>(faMesh::prefix());
161// }
162
163// Forwarding
165{
166 return faMeshesRegistry::Registry(pMesh);
167}
168
169
171(
172 const polyMesh& pMesh
173)
174{
176}
177
178
180(
181 const polyMesh& pMesh,
182 const word& areaRegion
183)
184{
185 const objectRegistry* obr = faMesh::registry(pMesh);
186
187 if (!obr)
188 {
189 // Fallback - not really valid, but will fail at the next stage
190 obr = &(pMesh.thisDb());
191 }
192
193 if (areaRegion.empty())
194 {
195 return obr->lookupObject<faMesh>(polyMesh::defaultRegion);
196 }
197
198 return obr->lookupObject<faMesh>(areaRegion);
199}
200
202// * * * * * * * * * * * * * * * Local Functions * * * * * * * * * * * * * * //
203
204namespace Foam
205{
206
207// Convert patch names to face labels. Preserve patch order
209(
210 const polyBoundaryMesh& pbm,
211 const wordRes& polyPatchNames
212)
213{
214 const labelList patchIDs
215 (
216 pbm.indices(polyPatchNames, true) // useGroups
217 );
218
219 if (patchIDs.empty())
220 {
222 << "No matching patches: " << polyPatchNames << nl
223 << exit(FatalError);
224 }
225
226 label nFaceLabels = 0;
227 for (const label patchi : patchIDs)
228 {
229 nFaceLabels += pbm[patchi].size();
230 }
231
233
234 nFaceLabels = 0;
235 for (const label patchi : patchIDs)
236 {
237 for (const label facei : pbm[patchi].range())
238 {
239 faceLabels[nFaceLabels] = facei;
240 ++nFaceLabels;
241 }
242 }
243
244 return faceLabels;
245}
246
247} // End namespace Foam
248
249
250// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
251
252void Foam::faMesh::checkBoundaryEdgeLabelRange
253(
254 const labelUList& edgeLabels
255) const
256{
257 label nErrors = 0;
258
259 for (const label edgei : edgeLabels)
260 {
261 if (edgei < nInternalEdges_ || edgei >= nEdges_)
262 {
263 if (!nErrors++)
264 {
266 << "Boundary edge label out of range "
267 << nInternalEdges_ << ".." << (nEdges_-1) << nl
268 << " ";
269 }
270
271 FatalError<< ' ' << edgei;
272 }
273 }
274
275 if (nErrors)
276 {
278 }
279}
280
281
282void Foam::faMesh::initPatch() const
283{
284 patchPtr_ = std::make_unique<uindirectPrimitivePatch>
285 (
286 UIndirectList<face>(mesh().faces(), faceLabels_),
287 mesh().points()
288 );
289
290 // Could set some basic primitive data here...
291 // nEdges_ = patchPtr_->nEdges();
292 // nInternalEdges_ = patchPtr_->nInternalEdges();
293 // nFaces_ = patchPtr_->size();
294 // nPoints_ = patchPtr_->nPoints();
295 bndConnectPtr_.reset(nullptr);
296 haloMapPtr_.reset(nullptr);
297 haloFaceCentresPtr_.reset(nullptr);
298 haloFaceNormalsPtr_.reset(nullptr);
299}
300
301
302void Foam::faMesh::setPrimitiveMeshData()
303{
304 DebugInFunction << "Setting primitive data" << endl;
305
306 const uindirectPrimitivePatch& bp = patch();
307 const labelListList& edgeFaces = bp.edgeFaces();
308
309 // Dimensions
310
311 nEdges_ = bp.nEdges();
312 nInternalEdges_ = bp.nInternalEdges();
313 nFaces_ = bp.size();
314 nPoints_ = bp.nPoints();
315
316 edges_.resize(nEdges_);
317 edgeOwner_.resize(nEdges_);
318 edgeNeighbour_.resize(nInternalEdges_);
319
320 // Internal edges
321 for (label edgei = 0; edgei < nInternalEdges_; ++edgei)
322 {
323 edges_[edgei] = bp.edges()[edgei];
324
325 edgeOwner_[edgei] = edgeFaces[edgei][0];
326
327 edgeNeighbour_[edgei] = edgeFaces[edgei][1];
328 }
329
330 // Continue with boundary edges
331 label edgei = nInternalEdges_;
332
333 for (const faPatch& p : boundary())
334 {
335 for (const label patchEdgei : p.edgeLabels())
336 {
337 edges_[edgei] = bp.edges()[patchEdgei];
338
339 edgeOwner_[edgei] = edgeFaces[patchEdgei][0];
340
341 ++edgei;
342 }
343 }
344}
345
346
347void Foam::faMesh::clearHalo() const
348{
349 DebugInFunction << "Clearing halo information" << endl;
350
351 haloMapPtr_.reset(nullptr);
352 haloFaceCentresPtr_.reset(nullptr);
353 haloFaceNormalsPtr_.reset(nullptr);
354}
355
356
357void Foam::faMesh::clearGeomNotAreas() const
358{
359 DebugInFunction << "Clearing geometry" << endl;
360
361 clearHalo();
362 patchPtr_.reset(nullptr);
363 polyPatchFacesPtr_.reset(nullptr);
364 polyPatchIdsPtr_.reset(nullptr);
365 bndConnectPtr_.reset(nullptr);
366 SPtr_.reset(nullptr);
367 patchStartsPtr_.reset(nullptr);
368 LePtr_.reset(nullptr);
369 magLePtr_.reset(nullptr);
370 faceCentresPtr_.reset(nullptr);
371 edgeCentresPtr_.reset(nullptr);
372 faceAreaNormalsPtr_.reset(nullptr);
373 edgeAreaNormalsPtr_.reset(nullptr);
374 pointAreaNormalsPtr_.reset(nullptr);
375 faceCurvaturesPtr_.reset(nullptr);
376 edgeTransformTensorsPtr_.reset(nullptr);
377}
378
379
380void Foam::faMesh::clearGeom() const
381{
382 DebugInFunction << "Clearing geometry" << endl;
383
384 clearGeomNotAreas();
385 S0Ptr_.reset(nullptr);
386 S00Ptr_.reset(nullptr);
387 correctPatchPointNormalsPtr_.reset(nullptr);
388}
389
390
391void Foam::faMesh::clearAddressing() const
392{
393 DebugInFunction << "Clearing addressing" << endl;
394
395 lduPtr_.reset(nullptr);
396}
397
398
399void Foam::faMesh::clearOut() const
400{
401 clearGeom();
402 clearAddressing();
403 globalMeshDataPtr_.reset(nullptr);
404}
405
406
407// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
408
410{
411 if (UPstream::parRun())
412 {
413 // areaCentres()
414 if (faceCentresPtr_)
415 {
416 faceCentresPtr_->boundaryFieldRef()
417 .evaluateCoupled<processorFaPatch>();
418 }
419
420 // faceAreaNormals()
421 if (faceAreaNormalsPtr_)
422 {
423 faceAreaNormalsPtr_->boundaryFieldRef()
424 .evaluateCoupled<processorFaPatch>();
425 }
426 }
427}
428
429
430bool Foam::faMesh::init(const bool doInit)
431{
432 if (doInit)
433 {
434 setPrimitiveMeshData();
435 }
436
437 // Create global mesh data
438 if (UPstream::parRun())
439 {
440 (void)globalData();
441 }
442
443 // Calculate topology for the patches (processor-processor comms etc.)
444 boundary_.updateMesh();
445
446 // Calculate the geometry for the patches (transformation tensors etc.)
447 boundary_.calcGeometry();
448
449 syncGeom();
451 return false;
452}
453
454
455// * * * * * * * * * * * * * Forwarding Constructors * * * * * * * * * * * * //
456
458(
459 const word& areaName,
460 const polyMesh& pMesh,
462)
463:
464 faMesh(areaName, pMesh, labelList())
465{}
466
467
469(
470 const polyMesh& pMesh,
472)
473:
474 faMesh(polyMesh::defaultRegion, pMesh, labelList())
475{}
476
478Foam::faMesh::faMesh(const polyMesh& pMesh, const bool doInit)
479:
480 faMesh(polyMesh::defaultRegion, pMesh, doInit)
481{}
482
483
485(
486 const word& areaName,
487 const faMesh& baseMesh,
489)
490:
491 faMesh(areaName, baseMesh, labelList())
492{}
493
494
496(
497 const faMesh& baseMesh,
499)
500:
501 faMesh(polyMesh::defaultRegion, baseMesh, labelList())
502{}
503
504
506(
507 const word& areaName,
508 const faMesh& baseMesh,
510)
511:
512 faMesh
513 (
514 areaName,
515 baseMesh,
516 std::move(faceLabels),
517 static_cast<IOobjectOption>(baseMesh.thisDb())
518 )
519{}
520
521
523(
524 const faMesh& baseMesh,
526)
527:
528 faMesh
529 (
530 polyMesh::defaultRegion,
531 baseMesh,
532 std::move(faceLabels),
533 static_cast<IOobjectOption>(baseMesh.thisDb())
534 )
535{}
536
537
539(
540 const polyMesh& pMesh,
542 IOobjectOption ioOpt
543)
544:
545 faMesh
546 (
547 polyMesh::defaultRegion,
548 pMesh,
549 std::move(faceLabels),
550 ioOpt
551 )
552{}
553
554
556(
557 const polyMesh& pMesh,
559)
560:
561 faMesh(polyMesh::defaultRegion, pMesh, std::move(faceLabels))
562{}
563
564
566(
567 const polyPatch& pp,
568 const bool doInit
569)
570:
571 faMesh(polyMesh::defaultRegion, pp, doInit)
572{}
573
574
576(
577 const polyMesh& pMesh,
578 const dictionary& faMeshDefinition,
579 const bool doInit
580)
581:
582 faMesh
583 (
584 polyMesh::defaultRegion,
585 pMesh,
586 faMeshDefinition,
587 doInit
588 )
589{}
590
591
592// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
593
595(
596 const word& areaName,
597 const polyMesh& pMesh,
598 const bool doInit
599)
600:
601 faMeshRegistry(areaName, pMesh),
603 (
604 faMesh::thisDb(),
605 IOobjectOption::MUST_READ
606 ),
608 (
609 faMesh::thisDb(),
610 IOobjectOption::MUST_READ
611 ),
612 edgeInterpolation(*this),
613 faceLabels_
614 (
616 (
617 "faceLabels",
618 time().findInstance(meshDir(), "faceLabels"),
619 faMesh::meshSubDir,
620 faMesh::thisDb(),
621 IOobject::MUST_READ,
622 IOobject::NO_WRITE
623 )
624 ),
625 boundary_
626 (
628 (
629 "faBoundary",
630 // Allow boundary file that is newer than faceLabels
631 time().findInstance
632 (
633 meshDir(),
634 "faBoundary",
635 IOobject::MUST_READ,
636 faceLabels_.instance()
637 ),
638 faMesh::meshSubDir,
639 faMesh::thisDb(),
640 IOobject::MUST_READ,
641 IOobject::NO_WRITE
642 ),
643 *this
644 ),
645 comm_(UPstream::worldComm),
646 curTimeIndex_(time().timeIndex())
647{
648 DebugInFunction << "Creating from IOobject" << endl;
649
650 setPrimitiveMeshData();
651
652 if (doInit)
653 {
654 faMesh::init(false); // do not init lower levels
655 }
656
657 if (doInit)
658 {
659 // Read some optional fields
660 // - logic as per fvMesh
661
662 IOobject rio
663 (
664 "any-name",
665 time().timeName(),
671 );
672
673 // Read old surface areas (if present)
674 rio.resetHeader("S0");
675 if (returnReduceOr(rio.typeHeaderOk<regIOobject>(false)))
676 {
677 S0Ptr_ = std::make_unique<DimensionedField<scalar, areaMesh>>
678 (
679 rio,
680 *this,
682 );
683 }
684 }
685}
686
687
689(
690 const word& areaName,
691 const polyMesh& pMesh,
693)
694:
695 faMeshRegistry(areaName, pMesh),
697 (
698 faMesh::thisDb(),
699 IOobjectOption::MUST_READ
700 ),
702 (
703 faMesh::thisDb(),
704 IOobjectOption::MUST_READ
705 ),
706 edgeInterpolation(*this),
707 faceLabels_
708 (
710 (
711 "faceLabels",
712 pMesh.facesInstance(),
713 faMesh::meshSubDir,
714 faMesh::thisDb(),
715 IOobject::NO_READ,
716 IOobject::NO_WRITE
717 ),
718 std::move(faceLabels)
719 ),
720 boundary_
721 (
723 (
724 "faBoundary",
725 faceLabels_.instance(),
726 faMesh::meshSubDir,
727 faMesh::thisDb(),
728 IOobject::NO_READ,
729 IOobject::NO_WRITE
730 ),
731 *this,
732 Foam::zero{}
733 ),
734 comm_(UPstream::worldComm),
735 curTimeIndex_(time().timeIndex())
736{
737 // Not yet much for primitive mesh data possible...
738 nPoints_ = 0;
739 nEdges_ = 0;
740 nInternalEdges_ = 0;
741 nFaces_ = faceLabels_.size();
742
743 // TDB: can we make a NO_READ readOption persistent for
744 // faSchemes/faSolution? Or not needed anymore?
745}
746
748(
749 const word& areaName,
750 const polyMesh& pMesh,
752 IOobjectOption ioOpt
753)
754:
755 faMeshRegistry(areaName, pMesh),
757 (
758 faMesh::thisDb(),
759 ioOpt.readOpt()
760 ),
762 (
763 faMesh::thisDb(),
764 ioOpt.readOpt()
765 ),
766 edgeInterpolation(*this),
767 faceLabels_
768 (
770 (
771 "faceLabels",
772 pMesh.facesInstance(),
773 faMesh::meshSubDir,
774 faMesh::thisDb(),
775 IOobject::NO_READ,
776 IOobject::NO_WRITE
777 ),
778 std::move(faceLabels)
779 ),
780 boundary_
781 (
783 (
784 "faBoundary",
785 faceLabels_.instance(),
786 faMesh::meshSubDir,
787 faMesh::thisDb(),
788 IOobject::NO_READ,
789 IOobject::NO_WRITE
790 ),
791 *this,
792 Foam::zero{}
793 ),
794 comm_(UPstream::worldComm),
795 curTimeIndex_(time().timeIndex())
796{
797 // Not yet much for primitive mesh data possible...
798 nPoints_ = 0;
799 nEdges_ = 0;
800 nInternalEdges_ = 0;
801 nFaces_ = faceLabels_.size();
802
803 // TDB: can we make a NO_READ readOption persistent for
804 // faSchemes/faSolution? Or not needed anymore?
805}
806
807
808// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
809
811(
812 const word& areaName,
813 const faMesh& baseMesh,
815 IOobjectOption ioOpt
816)
817:
818 faMeshRegistry(areaName, baseMesh.mesh()),
820 (
821 faMesh::thisDb(),
822 ioOpt.readOpt(),
823 static_cast<const dictionary*>(baseMesh.hasSchemes())
824 ),
826 (
827 faMesh::thisDb(),
828 ioOpt.readOpt(),
829 static_cast<const dictionary*>(baseMesh.hasSolution())
830 ),
831 edgeInterpolation(*this),
832 faceLabels_
833 (
835 (
836 "faceLabels",
837 // Topological instance from polyMesh
838 baseMesh.mesh().facesInstance(),
839 faMesh::meshSubDir,
840 faMesh::thisDb(),
841 IOobject::NO_READ,
842 IOobject::NO_WRITE
843 ),
844 std::move(faceLabels)
845 ),
846 boundary_
847 (
849 (
850 "faBoundary",
851 faceLabels_.instance(),
852 faMesh::meshSubDir,
853 faMesh::thisDb(),
854 IOobject::NO_READ,
855 IOobject::NO_WRITE
856 ),
857 *this,
858 Foam::zero{}
859 ),
860 comm_(UPstream::worldComm),
861 curTimeIndex_(time().timeIndex())
862{
863 // Not yet much for primitive mesh data possible...
864 nPoints_ = 0;
865 nEdges_ = 0;
866 nInternalEdges_ = 0;
867 nFaces_ = faceLabels_.size();
868}
869
870
872(
873 const word& areaName,
874 const polyPatch& pp,
875 const bool doInit
876)
877:
878 faMesh
879 (
880 areaName,
881 pp.boundaryMesh().mesh(),
882 identity(pp.range())
883 )
884{
885 DebugInFunction << "Creating from polyPatch:" << pp.name() << endl;
886
887 // Add single faPatch "default", but with processor connections
888 faPatchList newPatches
889 (
890 createOnePatch("default")
891 );
892
893 addFaPatches(newPatches);
894
895 setPrimitiveMeshData();
896
897 if (doInit)
898 {
899 faMesh::init(false); // do not init lower levels
900 }
901}
902
903
905(
906 const word& areaName,
907 const polyMesh& pMesh,
908 const dictionary& faMeshDefinition,
909 const bool doInit
910)
911:
912 faMesh
913 (
914 areaName,
915 pMesh,
917 (
918 pMesh.boundaryMesh(),
919 faMeshDefinition.get<wordRes>("polyMeshPatches")
920 )
921 )
922{
923 DebugInFunction << "Creating from definition (dictionary)" << endl;
924
925 faPatchList newPatches
926 (
927 createPatchList
928 (
929 faMeshDefinition.subDict("boundary"),
930
931 // Optional 'empty' patch
932 faMeshDefinition.getOrDefault<word>("emptyPatch", word::null),
933
934 // Optional specification for default patch
935 faMeshDefinition.findDict("defaultPatch")
936 )
937 );
938
939 addFaPatches(newPatches);
940
941 if (doInit)
942 {
943 faMesh::init(false); // do not init lower levels
944 }
945
946 if (doInit)
947 {
948 // Read old surface areas (if present)
949 // - logic as per fvMesh
950
951 IOobject rio
952 (
953 "any-name",
954 time().timeName(),
960 );
961
962 // Read old surface areas (if present)
963 rio.resetHeader("S0");
964 if (returnReduceOr(rio.typeHeaderOk<regIOobject>(false)))
965 {
966 S0Ptr_ = std::make_unique<DimensionedField<scalar, areaMesh>>
967 (
968 rio,
969 *this,
971 );
973 }
974}
975
976
977// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
978
981 clearOut();
982}
983
984
985// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
988{
989 return static_cast<const faSchemes*>(this);
990}
991
994{
995 return static_cast<const faSolution*>(this);
996}
997
1000{
1001 return static_cast<const faSchemes&>(*this);
1002}
1003
1006{
1007 return static_cast<faSchemes&>(*this);
1008}
1009
1012{
1013 return static_cast<const faSolution&>(*this);
1014}
1015
1018{
1019 return static_cast<faSolution&>(*this);
1020}
1021
1026}
1027
1032}
1033
1035const Foam::Time& Foam::faMesh::time() const
1036{
1037 return faMeshRegistry::time();
1038}
1039
1042{
1043 return mesh().pointsInstance();
1044}
1045
1048{
1049 return mesh().facesInstance();
1050}
1051
1054{
1056}
1057
1058
1060{
1061 const labelList& faceOwner = this->mesh().faceOwner();
1062
1063 labelList list(faceLabels_);
1064
1065 for (label& val : list)
1066 {
1067 // Transcribe from faceId to cellId (owner)
1068 val = faceOwner[val];
1069 }
1070
1071 return list;
1072}
1073
1074
1075void Foam::faMesh::removeFiles(const fileName& instanceDir) const
1076{
1077 fileName meshFilesPath = thisDb().time().path()/instanceDir/meshDir();
1078
1079 Foam::rm(meshFilesPath/"faceLabels");
1080 Foam::rm(meshFilesPath/"faBoundary");
1081}
1082
1084void Foam::faMesh::removeFiles() const
1085{
1087}
1088
1089
1091{
1092 if (!patchStartsPtr_)
1093 {
1094 calcPatchStarts();
1095 }
1096
1097 return *patchStartsPtr_;
1098}
1099
1100
1102{
1103 if (!LePtr_)
1104 {
1105 calcLe();
1106 }
1107
1108 return *LePtr_;
1109}
1110
1111
1113{
1114 if (!magLePtr_)
1115 {
1116 calcMagLe();
1117 }
1118
1119 return *magLePtr_;
1120}
1121
1122
1124{
1125 if (!faceCentresPtr_)
1126 {
1127 calcFaceCentres();
1128 }
1129
1130 return *faceCentresPtr_;
1131}
1132
1133
1135{
1136 if (!edgeCentresPtr_)
1137 {
1138 calcEdgeCentres();
1140
1141 return *edgeCentresPtr_;
1142}
1143
1144
1146Foam::faMesh::S() const
1147{
1148 if (!SPtr_)
1149 {
1150 calcS();
1152
1153 return *SPtr_;
1154}
1155
1156
1158Foam::faMesh::S0() const
1159{
1160 if (!S0Ptr_)
1161 {
1163 << "S0 is not available"
1164 << abort(FatalError);
1166
1167 return *S0Ptr_;
1168}
1169
1170
1172Foam::faMesh::S00() const
1173{
1174 if (!S00Ptr_)
1175 {
1176 S00Ptr_ = std::make_unique<DimensionedField<scalar, areaMesh>>
1177 (
1178 IOobject
1179 (
1180 "S00",
1181 time().timeName(),
1182 *this,
1185 ),
1186 S0()
1187 );
1188
1189 S0Ptr_->writeOpt(IOobject::AUTO_WRITE);
1190 }
1191
1192 return *S00Ptr_;
1193}
1194
1195
1197{
1198 if (!faceAreaNormalsPtr_)
1199 {
1200 calcFaceAreaNormals();
1201 }
1202
1203 return *faceAreaNormalsPtr_;
1204}
1205
1206
1208{
1209 if (!edgeAreaNormalsPtr_)
1210 {
1211 calcEdgeAreaNormals();
1212 }
1213
1214 return *edgeAreaNormalsPtr_;
1215}
1216
1217
1219{
1220 if (!pointAreaNormalsPtr_)
1221 {
1222 pointAreaNormalsPtr_ = std::make_unique<vectorField>(nPoints());
1223
1224 calcPointAreaNormals(*pointAreaNormalsPtr_);
1225
1226 if (quadricsFit_ > 0)
1227 {
1228 calcPointAreaNormalsByQuadricsFit(*pointAreaNormalsPtr_);
1230 }
1231
1232 return *pointAreaNormalsPtr_;
1233}
1234
1235
1237{
1238 if (!faceCurvaturesPtr_)
1239 {
1240 calcFaceCurvatures();
1242
1243 return *faceCurvaturesPtr_;
1244}
1245
1246
1249{
1250 if (!edgeTransformTensorsPtr_)
1251 {
1252 calcEdgeTransformTensors();
1253 }
1254
1255 return *edgeTransformTensorsPtr_;
1256}
1257
1260{
1261 return bool(globalMeshDataPtr_);
1262}
1263
1264
1266{
1267 if (!globalMeshDataPtr_)
1268 {
1269 globalMeshDataPtr_.reset(new faGlobalMeshData(*this));
1270 }
1271
1272 return *globalMeshDataPtr_;
1273}
1274
1275
1277{
1278 if (!lduPtr_)
1279 {
1280 calcLduAddressing();
1281 }
1282
1283 return *lduPtr_;
1284}
1285
1286
1288{
1289 // Grab point motion from polyMesh
1290 const vectorField& newPoints = mesh().points();
1291
1292 // Grab old time areas if the time has been incremented
1293 if (curTimeIndex_ < time().timeIndex())
1294 {
1295 if (S00Ptr_ && S0Ptr_)
1296 {
1297 DebugInfo<< "Copy old-old S" << endl;
1298 *S00Ptr_ = *S0Ptr_;
1299 }
1300
1301 if (S0Ptr_)
1302 {
1303 DebugInfo<< "Copy old S" << endl;
1304 *S0Ptr_ = S();
1305 }
1306 else
1307 {
1308 DebugInfo<< "Creating old cell volumes." << endl;
1309
1310 S0Ptr_ = std::make_unique<DimensionedField<scalar, areaMesh>>
1311 (
1312 IOobject
1313 (
1314 "S0",
1315 time().timeName(),
1316 *this,
1320 ),
1321 S()
1322 );
1323 }
1324
1325 curTimeIndex_ = time().timeIndex();
1326 }
1327
1328 clearGeomNotAreas();
1329
1330 if (patchPtr_)
1331 {
1332 patchPtr_->movePoints(newPoints);
1333 }
1334
1335 // Move boundary points
1336 boundary_.movePoints(newPoints);
1337
1338 // Move interpolation
1340
1341 // Note: Fluxes were dummy?
1343 syncGeom();
1344
1345 return true;
1346}
1347
1348
1349bool Foam::faMesh::correctPatchPointNormals(const label patchID) const
1350{
1351 if
1352 (
1353 bool(correctPatchPointNormalsPtr_)
1354 && patchID >= 0 && patchID < boundary().size()
1355 )
1356 {
1357 return (*correctPatchPointNormalsPtr_)[patchID];
1358 }
1359
1360 return false;
1361}
1362
1363
1365{
1366 if (!correctPatchPointNormalsPtr_)
1367 {
1368 correctPatchPointNormalsPtr_ =
1369 std::make_unique<boolList>(boundary().size(), false);
1370 }
1371
1372 return *correctPatchPointNormalsPtr_;
1373}
1374
1375
1376bool Foam::faMesh::write(const bool writeOnProc) const
1377{
1378 faceLabels_.write();
1379 boundary_.write();
1381 return false;
1382}
1383
1384
1385// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
1387bool Foam::faMesh::operator!=(const faMesh& m) const
1388{
1389 return &m != this;
1390}
1391
1392
1393bool Foam::faMesh::operator==(const faMesh& m) const
1394{
1395 return &m == this;
1396}
1397
1398
1399// ************************************************************************* //
scalar range
label nFaceLabels
labelList faceLabels(nFaceLabels)
uindirectPrimitivePatch pp(UIndirectList< face >(mesh.faces(), faceLabels), mesh.points())
labelList patchIDs
const polyBoundaryMesh & pbm
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
A field of fields is a PtrList of fields with reference counting.
Definition FieldField.H:77
label size() const noexcept
Definition HashTable.H:358
A simple container of IOobject preferences. Can also be used for general handling of read/no-read/rea...
@ NO_REGISTER
Do not request registration (bool: false).
readOption readOpt() const noexcept
Get the read option.
@ NO_READ
Nothing to be read.
@ MUST_READ
Reading required.
@ LAZY_READ
Reading is optional [identical to READ_IF_PRESENT].
@ NO_WRITE
Ignore writing from objectRegistry::writeObject().
@ AUTO_WRITE
Automatically write from objectRegistry::writeObject().
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition IOobject.H:191
const Time & time() const noexcept
Return Time associated with the objectRegistry.
Definition IOobject.C:456
const word & name() const noexcept
Return the object name.
Definition IOobjectI.H:205
bool typeHeaderOk(const bool checkType=true, const bool search=true, const bool verbose=true)
Read header (respects is_globalIOobject trait) and check its info. A void type suppresses trait and t...
void resetHeader(const word &newName=word::null)
Clear various bits (headerClassName, note, sizeof...) that would be obtained when reading from a file...
Definition IOobject.C:644
const fileName & instance() const noexcept
Read access to instance path component.
Definition IOobjectI.H:289
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition Time.H:75
A List with indirect addressing. Like IndirectList but does not store addressing.
void size(const label n)
Older name for setAddressableSize.
Definition UList.H:118
Inter-processor communications stream.
Definition UPstream.H:69
static bool parRun(const bool on) noexcept
Set as parallel run on/off.
Definition UPstream.H:1669
Addressing for all faces on surface of mesh. Can either be read from polyMesh or from triSurface....
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition dictionary.H:133
T get(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Find and return a T. FatalIOError if not found, or if the number of tokens is incorrect.
const dictionary * findDict(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Find and return a sub-dictionary pointer if present (and it is a dictionary) otherwise return nullptr...
const dictionary & subDict(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Find and return a sub-dictionary.
Definition dictionary.C:441
T getOrDefault(const word &keyword, const T &deflt, enum keyType::option matchOpt=keyType::REGEX) const
Find and return a T, or return the given default value. FatalIOError if it is found and the number of...
Face to edge interpolation scheme. Included in faMesh.
bool movePoints() const
Do what is necessary if the mesh has moved.
edgeInterpolation(const edgeInterpolation &)=delete
No copy construct.
Various mesh related information for a parallel run.
The objectRegistry for faMesh.
Definition faMesh.H:97
faMeshRegistry(const word &areaName, const polyMesh &mesh)
Construct an objectRegistry for given area region name. Treat an empty name like polyMesh::defaultReg...
Finite area mesh (used for 2-D non-Euclidian finite area method) defined using a patch of faces on a ...
Definition faMesh.H:140
virtual bool movePoints()
Update after mesh motion.
Definition faMesh.C:1280
boolList & correctPatchPointNormals() const
Set whether point normals should be corrected for a patch.
Definition faMesh.C:1357
virtual const objectRegistry & thisDb() const
Reference to the mesh database.
Definition faMesh.H:1209
bool operator==(const faMesh &m) const
Definition faMesh.C:1386
const fileName & facesInstance() const
Return the current instance directory for faces.
Definition faMesh.C:1040
const labelList & patchStarts() const
Return patch starts.
Definition faMesh.C:1083
bool hasGlobalData() const noexcept
Is demand-driven parallel info available?
Definition faMesh.C:1252
const Time & time() const
Return reference to time.
Definition faMesh.C:1028
faMesh(const faMesh &)=delete
No copy construct.
virtual const lduAddressing & lduAddr() const
Return ldu addressing.
Definition faMesh.C:1269
fileName meshDir() const
Return the local mesh directory (dbDir()/meshSubDir).
Definition faMesh.C:1022
virtual const fileName & dbDir() const
Local directory path of the objectRegistry relative to Time with override for the single-region case.
Definition faMesh.H:1218
const edgeVectorField & edgeCentres() const
Return edge centres as edgeVectorField.
Definition faMesh.C:1127
const DimensionedField< scalar, areaMesh > & S00() const
Return old-old-time face areas.
Definition faMesh.C:1165
const polyMesh & mesh() const
Return access to polyMesh.
Definition faMesh.C:1016
bool init(const bool doInit)
Initialise non-demand-driven data etc.
Definition faMesh.C:423
const edgeScalarField & magLe() const
Return edge length magnitudes.
Definition faMesh.C:1105
const DimensionedField< scalar, areaMesh > & S() const
Return face areas.
Definition faMesh.C:1139
const faSchemes * hasSchemes() const
Non-null if faSchemes exists (can test as bool).
Definition faMesh.C:980
static const objectRegistry * registry(const polyMesh &pMesh)
Find the singleton parent registry (on the polyMesh) that contains all objects related to finite-area...
Definition faMesh.C:145
const faSolution & solution() const
Read-access to the faSolution controls.
Definition faMesh.C:1004
const faSchemes & schemes() const
Read-access to the faSchemes controls.
Definition faMesh.C:992
const edgeVectorField & Le() const
Return edge length vectors.
Definition faMesh.C:1094
const FieldField< Field, tensor > & edgeTransformTensors() const
Return edge transformation tensors.
Definition faMesh.C:1241
const fileName & pointsInstance() const
Return the current instance directory for points.
Definition faMesh.C:1034
static int geometryOrder_
Geometry treatment.
Definition faMesh.H:734
bool operator!=(const faMesh &m) const
Definition faMesh.C:1380
const faGlobalMeshData & globalData() const
Return parallel info (demand-driven).
Definition faMesh.C:1258
const DimensionedField< scalar, areaMesh > & S0() const
Return old-time face areas.
Definition faMesh.C:1151
const areaScalarField & faceCurvatures() const
Return face curvatures.
Definition faMesh.C:1229
labelList faceCells() const
The volume (owner) cells associated with the area-mesh.
Definition faMesh.C:1052
void syncGeom()
Processor/processor synchronisation for geometry fields.
Definition faMesh.C:402
virtual bool write(const bool writeOnProc=true) const
Write mesh.
Definition faMesh.C:1369
void removeFiles(const fileName &instanceDir) const
Remove all files from mesh instance.
Definition faMesh.C:1068
static const word & prefix() noexcept
The prefix to the parent registry name: finite-area.
Definition faMesh.C:66
const edgeVectorField & edgeAreaNormals() const
Return edge area normals.
Definition faMesh.C:1200
static const objectRegistry & Registry(const polyMesh &pMesh)
Return the singleton parent registry (on the polyMesh) that contains all objects related to finite-ar...
Definition faMesh.C:157
void addFaPatches(faPatchList &plist, const bool validBoundary=true)
Add boundary patches. Constructor helper.
void removeFiles() const
Remove all files from mesh instance().
Definition faMesh.C:1077
const labelList & faceLabels() const noexcept
Return the underlying polyMesh face labels.
Definition faMeshI.H:96
static const faMesh & mesh(const polyMesh &pMesh)
The single-region finite-area region on the polyMesh. Uses lookupObject semantics - Fatal if non-exis...
Definition faMesh.C:164
const vectorField & pointAreaNormals() const
Return point area normals.
Definition faMesh.C:1211
virtual ~faMesh()
Destructor.
Definition faMesh.C:972
static word meshSubDir
The mesh sub-directory name (usually "faMesh").
Definition faMesh.H:750
const word & regionName() const
The region name or word::null if polyMesh::defaultRegion.
Definition faMesh.C:1046
const areaVectorField & faceAreaNormals() const
Return face area normals.
Definition faMesh.C:1189
const faSolution * hasSolution() const
Non-null if faSolution exists (can test as bool).
Definition faMesh.C:986
const areaVectorField & areaCentres() const
Return face centres as areaVectorField.
Definition faMesh.C:1116
static FOAM_NO_DANGLING_REFERENCE const objectRegistry & Registry(const polyMesh &mesh)
Return the registry of objects on the singleton.
Finite area patch class. Used for 2-D non-Euclidian finite area method.
Definition faPatch.H:76
Selector class for finite area differencing schemes. faMesh is derived from faSchemes so that all fie...
Definition faSchemes.H:54
faSchemes(const faSchemes &)=delete
No copy construct.
Selector class for finite area solution. faMesh is derived from faSolution so that all fields have ac...
Definition faSolution.H:54
faSolution(const faSolution &)=delete
No copy construct.
A class for handling file names.
Definition fileName.H:75
The class contains the addressing required by the lduMatrix: upper, lower and losort.
Registry of regIOobjects.
const objectRegistry & parent() const noexcept
Return the parent objectRegistry.
const Type * cfindObject(const word &name, const bool recursive=false) const
Return const pointer to the object of the given Type.
const Type & lookupObject(const word &name, const bool recursive=false) const
Lookup and return const reference to the object of the given Type. Fatal if not found or the wrong ty...
A polyBoundaryMesh is a polyPatch list with registered IO, a reference to the associated polyMesh,...
Mesh consisting of general polyhedral cells.
Definition polyMesh.H:79
static const word & regionName(const word &region)
The mesh region name or word::null if polyMesh::defaultRegion.
Definition polyMesh.C:796
const fileName & facesInstance() const
Return the current instance directory for faces.
Definition polyMesh.C:844
static word defaultRegion
Return the default region name.
Definition polyMesh.H:406
virtual const labelList & faceOwner() const
Return face owner.
Definition polyMesh.C:1101
const fileName & pointsInstance() const
Return the current instance directory for points.
Definition polyMesh.C:838
const objectRegistry & thisDb() const noexcept
Return the object registry.
Definition polyMesh.H:690
virtual const pointField & points() const
Return raw points.
Definition polyMesh.C:1063
const word & regionName() const
The mesh region name or word::null if polyMesh::defaultRegion.
Definition polyMesh.C:832
A patch is a list of labels that address the faces in the global face list.
Definition polyPatch.H:73
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
Definition regIOobject.H:71
regIOobject(const IOobject &io, const bool isTimeObject=false)
Construct from IOobject. The optional flag adds special handling if the object is the top-level regIO...
Definition regIOobject.C:43
A List of wordRe with additional matching capabilities.
Definition wordRes.H:56
A class for handling words, derived from Foam::string.
Definition word.H:66
static const word null
An empty word.
Definition word.H:84
A class representing the concept of 0 (zero) that can be used to avoid manipulating objects known to ...
Definition zero.H:58
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
Definition className.H:142
volScalarField & p
faceListList boundary
dynamicFvMesh & mesh
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition error.H:600
const pointField & points
label nPoints
word timeName
Definition getTimeIndex.H:3
#define DebugInfo
Report an information message using Foam::Info.
#define DebugInFunction
Report an information message using Foam::Info.
int optimisationSwitch(const char *name, const int deflt=0)
Lookup optimisation switch or add default value.
Definition debug.C:234
const std::string patch
OpenFOAM patch number as a std::string.
Namespace for OpenFOAM.
bool rm(const fileName &file)
Remove a file (or its gz equivalent), returning true if successful.
Definition POSIX.C:1406
Type & refCast(U &obj)
A dynamic_cast (for references) to Type reference.
Definition typeInfo.H:172
bool returnReduceOr(const bool value, const int communicator=UPstream::worldComm)
Perform logical (or) MPI Allreduce on a copy. Uses UPstream::reduceOr.
GeometricField< vector, faePatchField, edgeMesh > edgeVectorField
List< labelList > labelListList
List of labelList.
Definition labelList.H:38
List< label > labelList
A List of labels.
Definition List.H:62
const dimensionSet dimArea(sqr(dimLength))
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition Ostream.H:519
GeometricField< vector, faPatchField, areaMesh > areaVectorField
GeometricField< scalar, faePatchField, edgeMesh > edgeScalarField
static labelList selectPatchFaces(const polyBoundaryMesh &pbm, const wordRes &polyPatchNames)
Definition faMesh.C:202
labelList identity(const label len, label start=0)
Return an identity map of the given length with (map[i] == i), works like std::iota() but returning a...
GeometricField< scalar, faPatchField, areaMesh > areaScalarField
errorManip< error > abort(error &err)
Definition errorManip.H:139
Field< vector > vectorField
Specialisation of Field<T> for vector.
List< bool > boolList
A List of bools.
Definition List.H:60
static constexpr const zero Zero
Global zero (0).
Definition zero.H:127
const direction noexcept
Definition scalarImpl.H:265
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...
PrimitivePatch< UIndirectList< face >, const pointField & > uindirectPrimitivePatch
A PrimitivePatch with UIndirectList for the faces, const reference for the point field.
dimensioned< scalar > dimensionedScalar
Dimensioned scalar obtained from generic dimensioned type.
PtrList< faPatch > faPatchList
Store lists of faPatch as a PtrList.
Definition faPatch.H:64
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition errorManip.H:125
UList< label > labelUList
A UList of labels.
Definition UList.H:75
constexpr char nl
The newline '\n' character (0x0a).
Definition Ostream.H:50
label timeIndex
#define registerOptSwitch(Name, Type, SwitchVar)