sensitivity.H
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-2023 PCOpt/NTUA
9  Copyright (C) 2013-2023 FOSS GP
10  Copyright (C) 2019 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 
29 Class
30  Foam::sensitivity
31 
32 Description
33  Abstract base class for adjoint sensitivities
34 
35 SourceFiles
36  sensitivity.C
37 
38 \*---------------------------------------------------------------------------*/
39 
40 #ifndef sensitivity_H
41 #define sensitivity_H
42 
43 #include "volFields.H"
44 #include "surfaceFields.H"
45 #include "dictionary.H"
46 #include "volPointInterpolation.H"
47 
48 #include "pointMesh.H"
49 #include "pointPatchField.H"
50 #include "pointPatchFieldsFwd.H"
52 #include "boundaryFieldsFwd.H"
53 #include "createZeroField.H"
54 
55 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
56 
57 namespace Foam
58 {
59 
60 // Forward declaration
61 class designVariables;
62 
63 /*---------------------------------------------------------------------------*\
64  Class sensitivity Declaration
65 \*---------------------------------------------------------------------------*/
66 
67 class sensitivity
68 {
69 protected:
70 
71  // Protected data
72 
73  const fvMesh& mesh_;
75  bool writeFieldSens_;
76 
77  // Field sensitivities. Topology optimisation
78  //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
80 
81 
82 private:
83 
84  // Private Member Functions
85 
86  //- No copy construct
87  sensitivity(const sensitivity&) = delete;
88 
89  //- No copy assignment
90  void operator=(const sensitivity&) = delete;
91 
92 
93 public:
94 
95  //- Runtime type information
96  TypeName("sensitivity");
97 
98  // Constructors
99 
100  //- Construct from components
102  (
103  const fvMesh& mesh,
104  const dictionary& dict
105  );
106 
107  //- Destructor
108  virtual ~sensitivity() = default;
109 
110 
111  // Member Functions
112 
113  //- Return reference to mesh
114  inline const fvMesh& mesh() const
115  {
116  return mesh_;
117  }
118 
119  //- Return the construction dictionary
120  inline const dictionary& dict() const
121  {
122  return
124  optionalSubDict("sensitivities");
125  }
126 
127  //- Read dictionary if changed
128  virtual bool readDict(const dictionary& dict);
130  //- Calculates and returns sensitivity field
131  virtual const scalarField& calculateSensitivities
132  (
133  autoPtr<designVariables>& designVars
134  ) = 0;
135 
136  //- Get the fieldSensPtr
137  inline const autoPtr<volScalarField>& fieldSensPtr() const
138  {
139  return fieldSensPtr_;
140  }
141 
142  //- Write sensitivity fields.
143  // If valid, copies boundaryFields to volFields and writes them.
144  // Virtual to be reimplemented by control points-based methods
145  // (Bezier, RBF) which do not need to write fields
146  virtual void write(const word& baseName = word::null);
147 };
148 
149 
150 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
151 
152 } // End namespace Foam
153 
154 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
155 
156 //#ifdef NoRepository
157 // #include "sensitivityTemplates.C"
158 //#endif
159 
160 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
161 
162 #endif
163 
164 // ************************************************************************* //
const fvMesh & mesh_
Definition: sensitivity.H:68
Foam::surfaceFields.
virtual void write(const word &baseName=word::null)
Write sensitivity fields.
Definition: sensitivity.C:59
virtual bool readDict(const dictionary &dict)
Read dictionary if changed.
Definition: sensitivity.C:51
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
Abstract base class for adjoint sensitivities.
Definition: sensitivity.H:62
const fvMesh & mesh() const
Return reference to mesh.
Definition: sensitivity.H:121
const dictionary & optionalSubDict(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Find and return a sub-dictionary, otherwise return this dictionary.
Definition: dictionary.C:560
virtual const scalarField & calculateSensitivities(autoPtr< designVariables > &designVars)=0
Calculates and returns sensitivity field.
A class for handling words, derived from Foam::string.
Definition: word.H:63
static const word null
An empty word.
Definition: word.H:84
autoPtr< volScalarField > fieldSensPtr_
Definition: sensitivity.H:74
Useful typenames for fields defined only at the boundaries.
const dictionary & dict() const
Return the construction dictionary.
Definition: sensitivity.H:129
const word & name() const
Return reference to name.
Definition: fvMesh.H:387
TypeName("sensitivity")
Runtime type information.
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:78
Pointer management similar to std::unique_ptr, with some additional methods and type checking...
Definition: HashPtrTable.H:48
dictionary dict_
Definition: sensitivity.H:69
virtual ~sensitivity()=default
Destructor.
const autoPtr< volScalarField > & fieldSensPtr() const
Get the fieldSensPtr.
Definition: sensitivity.H:152
Namespace for OpenFOAM.