waveModelNew.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) 2015 IH-Cantabria
9  Copyright (C) 2016-2021 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
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 "waveModel.H"
30 #include "fvMesh.H"
31 
33 (
34  const word& dictName,
35  const fvMesh& mesh,
36  const polyPatch& patch
37 )
38 {
39  IOdictionary waveDict
40  (
41  IOobject
42  (
43  dictName,
44  mesh.time().constant(),
45  mesh,
49  )
50  );
51 
52  word modelType("none");
53  dictionary patchDict;
54  if (waveDict.found(patch.name()))
55  {
56  patchDict = waveDict.subDict(patch.name());
57  modelType = patchDict.get<word>("waveModel");
58  }
59  else
60  {
61  FatalIOErrorInFunction(waveDict)
62  << "Dictionary entry for patch " << patch.name() << " not found"
63  << exit(FatalIOError);
64  }
65 
66  Info<< "Selecting waveModel " << modelType << endl;
67 
68  auto* ctorPtr = patchConstructorTable(modelType);
69 
70  if (!ctorPtr)
71  {
73  (
74  waveDict,
75  "waveModel",
76  modelType,
77  *patchConstructorTablePtr_
78  ) << exit(FatalIOError);
79  }
80 
81  return autoPtr<waveModel>(ctorPtr(patchDict, mesh, patch));
82 }
83 
84 
86 (
87  const polyPatch& patch,
88  const fvMesh& mesh,
89  const word& waveDictName
90 )
91 {
92  const word modelName = waveModel::modelName(patch.name());
93 
94  waveModel* modelPtr = mesh.getObjectPtr<waveModel>(modelName);
95 
96  if (!modelPtr)
97  {
98  modelPtr = waveModel::New(waveDictName, mesh, patch).ptr();
99  modelPtr->store();
100  modelPtr->info(Info);
101  }
102 
103  return *modelPtr;
104 }
105 
106 
107 // ************************************************************************* //
word dictName() const
The local dictionary name (final part of scoped name)
Definition: dictionaryI.H:53
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:125
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
const word dictName("faMeshDefinition")
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:531
Ignore writing from objectRegistry::writeObject()
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 & subDict(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Find and return a sub-dictionary.
Definition: dictionary.C:441
static word modelName(const word &patchName)
Utility function to construct the model name.
Definition: waveModel.C:42
bool found(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Find an entry (const access) with the given keyword.
Definition: dictionaryI.H:104
IOdictionary is derived from dictionary and IOobject to give the dictionary automatic IO functionalit...
Definition: IOdictionary.H:50
dynamicFvMesh & mesh
A class for handling words, derived from Foam::string.
Definition: word.H:63
Type * getObjectPtr(const word &name, const bool recursive=false) const
Return non-const pointer to the object of the given Type, using a const-cast to have it behave like a...
static autoPtr< waveModel > New(const word &dictName, const fvMesh &mesh, const polyPatch &patch)
Return a reference to the selected wave model.
Definition: waveModelNew.C:26
static tmp< waveModel > lookupOrCreate(const polyPatch &patch, const fvMesh &mesh, const word &waveDictName)
Lookup waveModel from database, or create new.
Definition: waveModelNew.C:79
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:627
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:78
const std::string patch
OpenFOAM patch number as a std::string.
messageStream Info
Information stream (stdout output on master, null elsewhere)
Pointer management similar to std::unique_ptr, with some additional methods and type checking...
Definition: HashPtrTable.H:48
A class for managing temporary objects.
Definition: HashPtrTable.H:50
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:69
Defines the attributes of an object for which implicit objectRegistry management is supported...
Definition: IOobject.H:172
#define FatalIOErrorInLookup(ios, lookupTag, lookupName, lookupTable)
Report an error message using Foam::FatalIOError.
Definition: error.H:635
Do not request registration (bool: false)
IOerror FatalIOError
Error stream (stdout output on all processes), with additional &#39;FOAM FATAL IO ERROR&#39; header text and ...