Removed unnecessary return statement
[foam-extend-3.2.git] / applications / solvers / surfaceTracking / freeSurface / makeFreeSurfaceData.C
blob1e9d3ddcc7068d8f2bc926954e177b4587a07de9
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | foam-extend: Open Source CFD
4    \\    /   O peration     | Version:     3.2
5     \\  /    A nd           | Web:         http://www.foam-extend.org
6      \\/     M anipulation  | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
8 License
9     This file is part of foam-extend.
11     foam-extend is free software: you can redistribute it and/or modify it
12     under the terms of the GNU General Public License as published by the
13     Free Software Foundation, either version 3 of the License, or (at your
14     option) any later version.
16     foam-extend is distributed in the hope that it will be useful, but
17     WITHOUT ANY WARRANTY; without even the implied warranty of
18     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19     General Public License for more details.
21     You should have received a copy of the GNU General Public License
22     along with foam-extend.  If not, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
26 #include "freeSurface.H"
27 #include "primitivePatchInterpolation.H"
28 #include "wedgeFaPatch.H"
29 #include "wallFvPatch.H"
30 #include "wedgeFaPatchFields.H"
31 #include "slipFaPatchFields.H"
33 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
35 namespace Foam
38 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
40 void freeSurface::makeInterpolators()
42     if (debug)
43     {
44         Info<< "freeSurface::makeInterpolators() : "
45             << "making pathc to patch interpolator"
46             << endl;
47     }
50     // It is an error to attempt to recalculate
51     // if the pointer is already set
52     if
53     (
54         interpolatorBAPtr_ ||
55         interpolatorABPtr_
56     )
57     {
58         FatalErrorIn("freeSurface::makeInterpolators()")
59             << "patch to patch interpolators already exists"
60                 << abort(FatalError);
61     }
64     if(aPatchID() == -1)
65     {
66         FatalErrorIn("freeSurface::makeInterpolators()")
67             << "Free surface patch A not defined."
68             << abort(FatalError);
69     }
72     if(bPatchID() == -1)
73     {
74         FatalErrorIn("freeSurface::makeInterpolators()")
75             << "Free surface patch B not defined."
76             << abort(FatalError);
77     }
79 //     patchToPatchInterpolation::setDirectHitTol(1e-2);
81     interpolatorBAPtr_ = new IOpatchToPatchInterpolation
82     (
83         IOobject
84         (
85             "baInterpolator",
86             DB().timeName(),
87             mesh(),
88             IOobject::READ_IF_PRESENT,
89             IOobject::AUTO_WRITE
90         ),
91         mesh().boundaryMesh()[bPatchID()],
92         mesh().boundaryMesh()[aPatchID()],
93         intersection::VISIBLE
94         // intersection::HALF_RAY
95     );
98     const scalarField& faceDistBA =
99         interpolatorBAPtr_->faceDistanceToIntersection();
101     forAll(faceDistBA, faceI)
102     {
103         if(mag(faceDistBA[faceI] - GREAT) < SMALL)
104         {
105             FatalErrorIn("freeSurface::makeInterpolators()")
106                 << "Error in B-to-A face patchToPatchInterpolation."
107                 << abort(FatalError);
108         }
109     }
111     const scalarField& pointDistBA =
112         interpolatorBAPtr_->pointDistanceToIntersection();
114     forAll(pointDistBA, pointI)
115     {
116         if(mag(pointDistBA[pointI] - GREAT) < SMALL)
117         {
118             FatalErrorIn("freeSurface::makeInterpolators()")
119                 << "Error in B-to-A point patchToPatchInterpolation."
120                 << abort(FatalError);
121         }
122     }
125     interpolatorABPtr_ = new IOpatchToPatchInterpolation
126     (
127         IOobject
128         (
129             "abInterpolator",
130             DB().timeName(),
131             mesh(),
132             IOobject::READ_IF_PRESENT,
133             IOobject::AUTO_WRITE
134         ),
135         mesh().boundaryMesh()[aPatchID()],
136         mesh().boundaryMesh()[bPatchID()],
137         intersection::VISIBLE
138         // intersection::HALF_RAY
139     );
142     const scalarField& faceDistAB =
143         interpolatorABPtr_->faceDistanceToIntersection();
145     forAll(faceDistAB, faceI)
146     {
147         if(mag(faceDistAB[faceI] - GREAT) < SMALL)
148         {
149             FatalErrorIn("freeSurface::makeInterpolators()")
150                 << "Error in A-to-B face patchToPatchInterpolation."
151                 << abort(FatalError);
152         }
153     }
155     const scalarField& pointDistAB =
156         interpolatorABPtr_->pointDistanceToIntersection();
158     forAll(pointDistAB, pointI)
159     {
160         if(mag(pointDistAB[pointI] - GREAT)<SMALL)
161         {
162             FatalErrorIn("freeSurface::makeInterpolators()")
163                 << "Error in A-to-B point patchToPatchInterpolation."
164                 << abort(FatalError);
165         }
166     }
169     Info << "\nCheck A-to-B and B-to-A interpolators" << endl;
171     scalar maxDist = max
172     (
173         mag
174         (
175             interpolatorABPtr_->faceInterpolate
176             (
177                 vectorField(mesh().boundaryMesh()[aPatchID()]
178                .faceCentres())
179             )
180           - mesh().boundaryMesh()[bPatchID()].faceCentres()
181         )
182     );
184     scalar maxDistPt = max
185     (
186         mag
187         (
188             interpolatorABPtr_->pointInterpolate
189             (
190                 vectorField(mesh().boundaryMesh()[aPatchID()]
191                .localPoints())
192             )
193           - mesh().boundaryMesh()[bPatchID()].localPoints()
194         )
195     );
197     Info << "A-to-B interpolation error, face: " << maxDist
198         << ", point: " << maxDistPt << endl;
201     maxDist = max
202     (
203         mag
204         (
205             interpolatorBAPtr_->faceInterpolate
206             (
207                 vectorField
208                 (
209                     mesh().boundaryMesh()[bPatchID()].faceCentres()
210                 )
211             )
212           - mesh().boundaryMesh()[aPatchID()].faceCentres()
213         )
214     );
216     maxDistPt = max
217     (
218         mag
219         (
220             interpolatorBAPtr_->pointInterpolate
221             (
222                 vectorField
223                 (
224                     mesh().boundaryMesh()[bPatchID()].localPoints()
225                 )
226             )
227           - mesh().boundaryMesh()[aPatchID()].localPoints()
228         )
229     );
231     Info << "B-to-A interpolation error, face: " << maxDist
232         << ", point: " << maxDistPt << endl;
236 void freeSurface::makeControlPoints()
238     if (debug)
239     {
240         Info<< "freeSurface::makeControlPoints() : "
241             << "making control points"
242             << endl;
243     }
246     // It is an error to attempt to recalculate
247     // if the pointer is already set
248     if (controlPointsPtr_)
249     {
250         FatalErrorIn("freeSurface::makeInterpolators()")
251             << "patch to patch interpolators already exists"
252             << abort(FatalError);
253     }
255     IOobject controlPointsHeader
256     (
257         "controlPoints",
258         DB().timeName(),
259         mesh(),
260         IOobject::MUST_READ
261     );
263     if (controlPointsHeader.headerOk())
264     {
265         controlPointsPtr_ =
266             new vectorIOField
267             (
268                 IOobject
269                 (
270                     "controlPoints",
271                     DB().timeName(),
272                     mesh(),
273                     IOobject::MUST_READ,
274                     IOobject::AUTO_WRITE
275                 )
276             );
277     }
278     else
279     {
280         controlPointsPtr_ =
281             new vectorIOField
282             (
283                 IOobject
284                 (
285                     "controlPoints",
286                     DB().timeName(),
287                     mesh(),
288                     IOobject::NO_READ,
289                     IOobject::AUTO_WRITE
290                 ),
291                 aMesh().areaCentres().internalField()
292             );
294         initializeControlPointsPosition();
295     }
299 void freeSurface::makeMotionPointsMask()
301     if (debug)
302     {
303         Info<< "freeSurface::makeMotionPointsMask() : "
304             << "making motion points mask"
305             << endl;
306     }
309     // It is an error to attempt to recalculate
310     // if the pointer is already set
311     if (motionPointsMaskPtr_)
312     {
313         FatalErrorIn("freeSurface::motionPointsMask()")
314             << "motion points mask already exists"
315             << abort(FatalError);
316     }
319     if(aPatchID() == -1)
320     {
321         FatalErrorIn("freeSurface::makeMotionPointsMask()")
322             << "Free surface patch A not defined."
323             << abort(FatalError);
324     }
327     motionPointsMaskPtr_ = new labelList
328     (
329         mesh().boundaryMesh()[aPatchID()].nPoints(),
330         1
331     );
335 void freeSurface::makeDirections()
337     if (debug)
338     {
339         Info<< "freeSurface::makeDirections() : "
340             << "making displacement directions for points and "
341             << "control points"
342             << endl;
343     }
346     // It is an error to attempt to recalculate
347     // if the pointer is already set
348     if
349     (
350         pointsDisplacementDirPtr_ ||
351         facesDisplacementDirPtr_
352     )
353     {
354         FatalErrorIn("freeSurface::makeDirections()")
355             << "points and control points displacement directions "
356             << "already exists"
357             << abort(FatalError);
358     }
361     if(aPatchID() == -1)
362     {
363         FatalErrorIn("freeSurface::makeDirections()")
364             << "Free surface patch A not defined."
365             << abort(FatalError);
366     }
369     pointsDisplacementDirPtr_ =
370         new vectorField
371         (
372             mesh().boundaryMesh()[aPatchID()].nPoints(),
373             vector::zero
374         );
376     facesDisplacementDirPtr_ =
377         new vectorField
378         (
379             mesh().boundaryMesh()[aPatchID()].size(),
380             vector::zero
381         );
383     if(!normalMotionDir())
384     {
385         if(mag(motionDir_) < SMALL)
386         {
387             FatalErrorIn("freeSurface::makeDirections()")
388                 << "Zero motion direction"
389                     << abort(FatalError);
390         }
392         facesDisplacementDir() = motionDir_;
393         pointsDisplacementDir() = motionDir_;
394     }
396     updateDisplacementDirections();
400 void freeSurface::makeTotalDisplacement()
402     if (debug)
403     {
404         Info<< "freeSurface::makeTotalDisplacement() : "
405             << "making zero total points displacement"
406             << endl;
407     }
410     // It is an error to attempt to recalculate
411     // if the pointer is already set
412     if (totalDisplacementPtr_)
413     {
414         FatalErrorIn("freeSurface::makeTotalDisplacement()")
415             << "total points displacement already exists"
416             << abort(FatalError);
417     }
419     totalDisplacementPtr_ =
420         new vectorIOField
421         (
422             IOobject
423             (
424                 "totalDisplacement",
425                 DB().timeName(),
426                 mesh(),
427                 IOobject::NO_READ,
428                 IOobject::AUTO_WRITE
429             ),
430             vectorField
431             (
432                 mesh().boundaryMesh()[aPatchID()].nPoints(),
433                 vector::zero
434             )
435         );
439 void freeSurface::readTotalDisplacement()
441     if (debug)
442     {
443         Info<< "freeSurface::readTotalDisplacement() : "
444             << "reading total points displacement if present"
445             << endl;
446     }
449     // It is an error to attempt to recalculate
450     // if the pointer is already set
451     if (totalDisplacementPtr_)
452     {
453         FatalErrorIn("freeSurface::makeTotalDisplacement()")
454             << "total points displacement already exists"
455             << abort(FatalError);
456     }
458     if
459     (
460         IOobject
461         (
462             "totalDisplacement",
463             DB().timeName(),
464             mesh(),
465             IOobject::MUST_READ,
466             IOobject::AUTO_WRITE
467         ).headerOk()
468     )
469     {
470         totalDisplacementPtr_ =
471             new vectorIOField
472             (
473                 IOobject
474                 (
475                     "totalDisplacement",
476                     DB().timeName(),
477                     mesh(),
478                     IOobject::MUST_READ,
479                     IOobject::AUTO_WRITE
480                 )
481             );
482     }
486 void freeSurface::makeFaMesh() const
488     if (debug)
489     {
490         Info<< "freeSurface::makeFaMesh() : "
491             << "making finite area mesh"
492             << endl;
493     }
495     // It is an error to attempt to recalculate
496     // if the pointer is already set
497     if (aMeshPtr_)
498     {
499         FatalErrorIn("freeSurface::makeFaMesh()")
500             << "finite area mesh already exists"
501             << abort(FatalError);
502     }
504     aMeshPtr_ = new faMesh(mesh());
507 void freeSurface::makeUs() const
509     if (debug)
510     {
511         Info<< "freeSurface::makeUs() : "
512             << "making free-surface velocity field"
513             << endl;
514     }
517     // It is an error to attempt to recalculate
518     // if the pointer is already set
519     if (UsPtr_)
520     {
521         FatalErrorIn("freeSurface::makeUs()")
522             << "free-surface velocity field already exists"
523             << abort(FatalError);
524     }
527     wordList patchFieldTypes
528     (
529         aMesh().boundary().size(),
530         zeroGradientFaPatchVectorField::typeName
531     );
533     forAll(aMesh().boundary(), patchI)
534     {
535         if
536         (
537             aMesh().boundary()[patchI].type()
538          == wedgeFaPatch::typeName
539         )
540         {
541             patchFieldTypes[patchI] =
542                 wedgeFaPatchVectorField::typeName;
543         }
544         else
545         {
546             label ngbPolyPatchID =
547                 aMesh().boundary()[patchI].ngbPolyPatchIndex();
549             if (ngbPolyPatchID != -1)
550             {
551                 if
552                 (
553                     mesh().boundary()[ngbPolyPatchID].type()
554                  == wallFvPatch::typeName
555                 )
556                 {
557                     patchFieldTypes[patchI] =
558                         slipFaPatchVectorField::typeName;
559                 }
560             }
561         }
562     }
565     UsPtr_ = new areaVectorField
566     (
567         IOobject
568         (
569             "Us",
570             DB().timeName(),
571             mesh(),
572             IOobject::NO_READ,
573             IOobject::NO_WRITE
574         ),
575         aMesh(),
576         dimensioned<vector>("Us", dimVelocity, vector::zero),
577         patchFieldTypes
578     );
582 void freeSurface::makePhis()
584     if (debug)
585     {
586         Info<< "freeSurface::makePhis() : "
587             << "making free-surface fluid flux"
588             << endl;
589     }
592     // It is an error to attempt to recalculate
593     // if the pointer is already set
594     if (phisPtr_)
595     {
596         FatalErrorIn("freeSurface::makePhis()")
597             << "free-surface fluid flux already exists"
598             << abort(FatalError);
599     }
602     phisPtr_ = new edgeScalarField
603     (
604         IOobject
605         (
606             "phis",
607             DB().timeName(),
608             mesh(),
609             IOobject::NO_READ,
610             IOobject::NO_WRITE
611         ),
612         linearEdgeInterpolate(Us()) & aMesh().Le()
613     );
617 void freeSurface::makeSurfactConc() const
619     if (debug)
620     {
621         Info<< "freeSurface::makeSurfactConc() : "
622             << "making free-surface surfactant concentration field"
623             << endl;
624     }
627     // It is an error to attempt to recalculate
628     // if the pointer is already set
629     if (surfactConcPtr_)
630     {
631         FatalErrorIn("freeSurface::makeSurfaceConc()")
632             << "free-surface surfactant concentratio field already exists"
633             << abort(FatalError);
634     }
636     surfactConcPtr_ = new areaScalarField
637     (
638         IOobject
639         (
640             "Cs",
641             DB().timeName(),
642             mesh(),
643             IOobject::MUST_READ,
644             IOobject::AUTO_WRITE
645         ),
646         aMesh()
647     );
651 void freeSurface::makeSurfaceTension() const
653     if (debug)
654     {
655         Info<< "freeSurface::makeSurfaceTension() : "
656             << "making surface tension field"
657             << endl;
658     }
661     // It is an error to attempt to recalculate
662     // if the pointer is already set
663     if (surfaceTensionPtr_)
664     {
665         FatalErrorIn("freeSurface::makeSurfaceTension()")
666             << "surface tension field already exists"
667             << abort(FatalError);
668     }
671     surfaceTensionPtr_ = new areaScalarField
672     (
673         IOobject
674         (
675             "surfaceTension",
676             DB().timeName(),
677             mesh(),
678             IOobject::NO_READ,
679             IOobject::NO_WRITE
680         ),
681         cleanInterfaceSurfTension()
682       + surfactant().surfactR()*
683         surfactant().surfactT()*
684         surfactant().surfactSaturatedConc()*
685         log(1.0 - surfactantConcentration()/
686         surfactant().surfactSaturatedConc())
687     );
691 void freeSurface::makeSurfactant() const
693     if (debug)
694     {
695         Info<< "freeSurface::makeSurfactant() : "
696             << "making surfactant properties"
697             << endl;
698     }
701     // It is an error to attempt to recalculate
702     // if the pointer is already set
703     if (surfactantPtr_)
704     {
705         FatalErrorIn("freeSurface::makeSurfactant()")
706             << "surfactant properties already exists"
707             << abort(FatalError);
708     }
711     const dictionary& surfactProp =
712         this->subDict("surfactantProperties");
714     surfactantPtr_ = new surfactantProperties(surfactProp);
718 void freeSurface::makeFluidIndicator()
720     if (debug)
721     {
722         Info<< "freeSurface::makeFluidIndicator() : "
723             << "making fluid indicator"
724             << endl;
725     }
728     // It is an error to attempt to recalculate
729     // if the pointer is already set
730     if (fluidIndicatorPtr_)
731     {
732         FatalErrorIn("freeSurface::makeFluidIndicator()")
733             << "fluid indicator already exists"
734             << abort(FatalError);
735     }
737     fluidIndicatorPtr_ = new volScalarField
738     (
739         IOobject
740         (
741             "fluidIndicator",
742             DB().timeName(),
743             mesh(),
744             IOobject::NO_READ,
745             IOobject::NO_WRITE
746         ),
747         mesh(),
748         dimensionedScalar("1", dimless, 1.0),
749         zeroGradientFvPatchScalarField::typeName
750     );
752     volScalarField& fluidIndicator = *fluidIndicatorPtr_;
754     if (twoFluids())
755     {
756         // find start cell
757         label pointOnShadowPatch =
758             mesh().boundaryMesh()[bPatchID()][0][0];
760         label startCell = mesh().pointCells()[pointOnShadowPatch][0];
763         // get cell-cells addressing
764         const labelListList& cellCells = mesh().cellCells();
766         SLList<label> slList(startCell);
768         while (slList.size())
769         {
770             label curCell = slList.removeHead();
772             if (fluidIndicator[curCell] == 1)
773             {
774                 fluidIndicator[curCell] = 0.0;
776                 for (int i = 0; i < cellCells[curCell].size(); i++)
777                 {
778                     slList.append(cellCells[curCell][i]);
779                 }
780             }
781         }
782     }
784     fluidIndicator.correctBoundaryConditions();
788 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
790 const IOpatchToPatchInterpolation& freeSurface::interpolatorAB()
792     if (!interpolatorABPtr_)
793     {
794         makeInterpolators();
795     }
797     return *interpolatorABPtr_;
801 const IOpatchToPatchInterpolation& freeSurface::interpolatorBA()
803     if (!interpolatorBAPtr_)
804     {
805         makeInterpolators();
806     }
808     return *interpolatorBAPtr_;
812 vectorField& freeSurface::controlPoints()
814     if (!controlPointsPtr_)
815     {
816         makeControlPoints();
817     }
819     return *controlPointsPtr_;
823 labelList& freeSurface::motionPointsMask()
825     if (!motionPointsMaskPtr_)
826     {
827         makeMotionPointsMask();
828     }
830     return *motionPointsMaskPtr_;
834 vectorField& freeSurface::pointsDisplacementDir()
836     if (!pointsDisplacementDirPtr_)
837     {
838         makeDirections();
839     }
841     return *pointsDisplacementDirPtr_;
845 vectorField& freeSurface::facesDisplacementDir()
847     if (!facesDisplacementDirPtr_)
848     {
849         makeDirections();
850     }
852     return *facesDisplacementDirPtr_;
856 vectorField& freeSurface::totalDisplacement()
858     if (!totalDisplacementPtr_)
859     {
860         makeTotalDisplacement();
861     }
863     return *totalDisplacementPtr_;
867 faMesh& freeSurface::aMesh()
869     if (!aMeshPtr_)
870     {
871         makeFaMesh();
872     }
874     return *aMeshPtr_;
877 const faMesh& freeSurface::aMesh() const
879     if (!aMeshPtr_)
880     {
881         makeFaMesh();
882     }
884     return *aMeshPtr_;
887 areaVectorField& freeSurface::Us()
889     if (!UsPtr_)
890     {
891         makeUs();
892     }
894     return *UsPtr_;
897 const areaVectorField& freeSurface::Us() const
899     if (!UsPtr_)
900     {
901         makeUs();
902     }
904     return *UsPtr_;
907 edgeScalarField& freeSurface::Phis()
909     if (!phisPtr_)
910     {
911         makePhis();
912     }
914     return *phisPtr_;
917 areaScalarField& freeSurface::surfactantConcentration()
919     if (!surfactConcPtr_)
920     {
921         makeSurfactConc();
922     }
924     return *surfactConcPtr_;
927 const areaScalarField& freeSurface::surfactantConcentration() const
929     if (!surfactConcPtr_)
930     {
931         makeSurfactConc();
932     }
934     return *surfactConcPtr_;
937 areaScalarField& freeSurface::surfaceTension()
939     if (!surfaceTensionPtr_)
940     {
941         makeSurfaceTension();
942     }
944     return *surfaceTensionPtr_;
947 const areaScalarField& freeSurface::surfaceTension() const
949     if (!surfaceTensionPtr_)
950     {
951         makeSurfaceTension();
952     }
954     return *surfaceTensionPtr_;
957 const surfactantProperties& freeSurface::surfactant() const
959     if (!surfactantPtr_)
960     {
961         makeSurfactant();
962     }
964     return *surfactantPtr_;
968 const volScalarField& freeSurface::fluidIndicator()
970     if (!fluidIndicatorPtr_)
971     {
972         makeFluidIndicator();
973     }
975     return *fluidIndicatorPtr_;
979 tmp<areaVectorField> freeSurface::surfaceTensionGrad()
981     tmp<areaVectorField> tgrad
982     (
983         new areaVectorField
984         (
985             IOobject
986             (
987                 "surfaceTensionGrad",
988                 DB().timeName(),
989                 mesh(),
990                 IOobject::NO_READ,
991                 IOobject::NO_WRITE
992             ),
993             (-fac::grad(surfactantConcentration())*
994             surfactant().surfactR()*surfactant().surfactT()/
995             (1.0 - surfactantConcentration()/
996             surfactant().surfactSaturatedConc()))()
997         )
998     );
1000     return tgrad;
1004 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
1006 } // End namespace Foam
1008 // ************************************************************************* //