writeActiveDesignVariables.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) 2007-2019 PCOpt/NTUA
9  Copyright (C) 2013-2019 FOSS GP
10  Copyright (C) 2019-2020 OpenCFD Ltd.
11 -------------------------------------------------------------------------------
12 License
13  This file is part of OpenFOAM.
14 
15  OpenFOAM is free software: you can redistribute it and/or modify it
16  under the terms of the GNU General Public License as published by
17  the Free Software Foundation, either version 3 of the License, or
18  (at your option) any later version.
19 
20  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
21  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
22  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
23  for more details.
24 
25  You should have received a copy of the GNU General Public License
26  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
27 
28 Application
29  writeActiveDesignVariables
30 
31 Description
32  Writes the active design variables based on the selected parameterisation
33  scheme, as read from the meshMovement part of optimisationDict.
34  Keeps a back-up of the original optimisationDict in
35  system/optimisationDict.org, as comments in the dict will be lost.
36 
37 \*---------------------------------------------------------------------------*/
38 
39 #include "fvCFD.H"
40 #include "optMeshMovement.H"
41 #include "updateMethod.H"
42 #include "OFstream.H"
43 
44 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
45 
46 int main(int argc, char *argv[])
47 {
48  #include "setRootCase.H"
49  #include "createTime.H"
50  #include "createMesh.H"
51 
52  IOdictionary optDict
53  (
54  IOobject
55  (
56  "optimisationDict",
57  mesh.time().caseSystem(),
58  mesh,
59  IOobject::MUST_READ_IF_MODIFIED,
60  IOobject::NO_WRITE
61  )
62  );
63 
64  // Back-up old optimisationDict, to maintain potential comments in it
65  if (Pstream::master())
66  {
67  Foam::cp(optDict.objectPath(), optDict.objectPath() + ".org");
68  }
69 
70  // Construct mesh movement object and grab active design variables
71  // Will exit with error if not implemented for this type
72  const dictionary& movementDict =
73  optDict.subDict("optimisation").subDict("meshMovement");
74  // Empty patch list will do
75  labelList patchIDs(0);
76  autoPtr<optMeshMovement> movementPtr
77  (optMeshMovement::New(mesh, movementDict, patchIDs));
78  const labelList activeDesignVariables =
79  movementPtr().getActiveDesignVariables();
80 
81  // Construct update method to grab the type
82  dictionary& updateMethodDict =
83  optDict.subDict("optimisation").subDict("updateMethod");
84  autoPtr<updateMethod> updMethod(updateMethod::New(mesh, updateMethodDict));
85 
86  // Add to appropriate dictionary (creates it if it does not exist)
87  dictionary& coeffsDict = updateMethodDict.subDictOrAdd(updMethod().type());
88  coeffsDict.add<labelList>
89  (
90  "activeDesignVariables",
91  activeDesignVariables,
92  true
93  );
94 
95  // Write modified dictionary
96  optDict.regIOobject::writeObject
97  (
98  IOstreamOption(IOstream::ASCII),
99  true
100  );
101 
102  Info<< "End\n" << endl;
103 
104  return 0;
105 }
106 
107 
108 // ************************************************************************* //
Foam::labelList
List< label > labelList
A List of labels.
Definition: List.H:63
updateMethod.H
Foam::endl
Ostream & endl(Ostream &os)
Definition: Ostream.H:381
OFstream.H
Foam::Info
messageStream Info
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
Foam::New
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh >> &tdf1, const word &name, const dimensionSet &dimensions)
Definition: DimensionedFieldReuseFunctions.H:100
setRootCase.H
Foam::cp
bool cp(const fileName &src, const fileName &dst, const bool followLink=true)
Definition: POSIX.C:975
createMesh.H
Required Variables.
createTime.H
Foam::roots::type
type
Definition: Roots.H:52
fvCFD.H
optMeshMovement.H