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,
46  IOobject::MUST_READ,
47  IOobject::NO_WRITE,
48  false // Not registering
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 // ************************************************************************* //
waveModel.H
Foam::IOdictionary
IOdictionary is derived from dictionary and IOobject to give the dictionary automatic IO functionalit...
Definition: IOdictionary.H:54
Foam::IOobject
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:169
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::waveModel
Base class for waveModels.
Definition: waveModel.H:57
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:61
Foam::dictionary::found
bool found(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Search for an entry (const access) with the given keyword.
Definition: dictionaryI.H:87
dictName
const word dictName("faMeshDefinition")
Foam::FatalIOError
IOerror FatalIOError
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:369
Foam::waveModel::New
static autoPtr< waveModel > New(const word &dictName, const fvMesh &mesh, const polyPatch &patch)
Return a reference to the selected wave model.
Definition: waveModelNew.C:33
Foam::dictionary::get
T get(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Definition: dictionaryTemplates.C:107
FatalIOErrorInLookup
#define FatalIOErrorInLookup(ios, lookupTag, lookupName, lookupTable)
Report an error message using Foam::FatalIOError.
Definition: error.H:478
Foam::Info
messageStream Info
Information stream (stdout output on master, null elsewhere)
Foam::polyPatch
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:68
Foam::dictionary::subDict
const dictionary & subDict(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Find and return a sub-dictionary.
Definition: dictionary.C:460
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:123
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
Foam::fvMesh
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:85
fvMesh.H
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
Foam::New
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh >> &tdf1, const word &name, const dimensionSet &dimensions)
Global function forwards to reuseTmpDimensionedField::New.
Definition: DimensionedFieldReuseFunctions.H:105
Foam::autoPtr
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: HashPtrTable.H:53
Foam::foamVersion::patch
const std::string patch
OpenFOAM patch number as a std::string.
FatalIOErrorInFunction
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:473
Foam::waveModel::lookupOrCreate
static tmp< waveModel > lookupOrCreate(const polyPatch &patch, const fvMesh &mesh, const word &waveDictName)
Lookup waveModel from database, or create new.
Definition: waveModelNew.C:86