Merge branch 'master' of ssh://git.code.sf.net/p/foam-extend/foam-extend-3.2
[foam-extend-3.2.git] / applications / utilities / preProcessing / fluentDataToFoam / fluentDataConverter.C
blob4cd5253e2968bd2c82c903088591b0a67a45e758
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 "fluentDataConverter.H"
28 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
30 Foam::fluentDataConverter::fluentDataConverter
32     const fvMesh& mesh,
33     const SLList<label>& fieldID,
34     const SLList<label>& zoneID,
35     const SLList<label>& firstID,
36     const SLList<label>& lastID,
37     const SLPtrList<FieldField<Field, scalar> >& zoneData
40     mesh_(mesh),
41     zoneToPatchName_
42     (
43         IOobject
44         (
45             "zoneToPatchName",
46             mesh.time().constant(),
47             mesh.meshSubDir,
48             mesh,
49             IOobject::MUST_READ,
50             IOobject::NO_WRITE
51         )
52     ),
53     fieldID_(fieldID),
54     zoneID_(zoneID),
55     firstID_(firstID),
56     lastID_(lastID),
57     zoneData_(zoneData)
61 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
63 Foam::tmp<Foam::volScalarField> Foam::fluentDataConverter::convertField
65     const word& fieldName,
66     const label unitNumber,
67     const dimensionedScalar& defaultValue
68 ) const
70     // Create field
71     Info << "Creating field " << fieldName << " for unit "<< unitNumber << endl;
73     tmp<volScalarField> tresult
74     (
75         new volScalarField
76         (
77             IOobject
78             (
79                 fieldName,
80                 mesh_.time().timeName(),
81                 mesh_,
82                 IOobject::NO_READ,
83                 IOobject::NO_WRITE
84             ),
85             mesh_,
86             defaultValue
87         )
88     );
89     volScalarField& result = tresult();
91     SLList<label>::const_iterator fieldIDIter = fieldID_.begin();
92     SLList<label>::const_iterator zoneIDIter = zoneID_.begin();
93     SLList<label>::const_iterator firstIDIter = firstID_.begin();
94     SLList<label>::const_iterator lastIDIter = lastID_.begin();
95     SLPtrList<FieldField<Field, scalar> >::const_iterator zoneDataIter =
96         zoneData_.begin();
98     for
99     (
100         ;
101         fieldIDIter != fieldID_.end();
103         ++fieldIDIter,
104         ++zoneIDIter,
105         ++firstIDIter,
106         ++lastIDIter,
107         ++zoneDataIter
108     )
109     {
110         // Look for field index
111         if (fieldIDIter() == unitNumber)
112         {
113             Info<< "Found field ID for zone " << zoneIDIter();
115             word patchName = zoneToPatchName_[zoneIDIter()];
117             // Internal Field
118             if
119             (
120                 patchName == "unknown"
121              && zoneDataIter()[0].size() == mesh_.nCells()
122             )
123             {
124                 Info<< " internal cell zone.  Size = "
125                     << mesh_.nCells() << endl;
126                 result.internalField() = zoneDataIter()[0];
127             }
128             else
129             {
130                 label patchID = mesh_.boundaryMesh().findPatchID(patchName);
132                 if (patchID > -1)
133                 {
134                     Info<< " and patch " << patchName
135                         << " with id " << patchID << endl;
137                     result.boundaryField()[patchID] == zoneDataIter()[0];
138                 }
139                 else
140                 {
141                     Info<< " and patch not found" << endl;
142                 }
143             }
144         }
145     }
147     return tresult;
151 // ************************************************************************* //