solverNew.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2022-2026 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "solver.H"
27 
28 // * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * * //
29 
30 void Foam::solver::load(const word& solverName)
31 {
32  libs.open("lib" + solverName + "Solver.so");
33 }
34 
35 
37 (
38  const word& solverName,
39  fvMesh& mesh
40 )
41 {
42  Info<< indentOrNl << "Selecting solver " << solverName << endl;
43 
44  load(solverName);
45 
46  fvMeshConstructorTable::iterator cstrIter =
47  fvMeshConstructorTablePtr_
48  ? fvMeshConstructorTablePtr_->find(solverName)
49  : fvMeshConstructorTable::end();
50 
51  if (cstrIter == fvMeshConstructorTable::end())
52  {
53  libs.openPattern("lib.*Solver.so");
54  }
55 
56  if (!fvMeshConstructorTablePtr_)
57  {
59  << "Solvers table is empty"
60  << exit(FatalError);
61  }
62 
63  if (cstrIter == fvMeshConstructorTable::end())
64  {
66  << "Unknown solver type "
67  << solverName << nl << nl
68  << "Valid solvers are :" << endl
69  << fvMeshConstructorTablePtr_->sortedToc()
70  << exit(FatalError);
71  }
72 
73  autoPtr<solver> solverPtr(cstrIter()(mesh));
74 
75  // Ensure fvModels and fvConstraints are constructed
76  // before time is incremented
77  solverPtr->fvModels();
78  solverPtr->fvConstraints();
79 
80  return solverPtr;
81 }
82 
83 
84 // ************************************************************************* //
bool open(const fileName &libName, const bool verbose=true)
Open the named library, optionally with warnings if problems occur.
bool openPattern(const regExp &pattern, const bool verbose=true)
Open the named libraries, optionally with warnings if problems occur.
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:98
static autoPtr< solver > New(const word &solverName, fvMesh &mesh)
Select, construct and return the solver.
Definition: solverNew.C:37
static void load(const word &solverName)
Load the specified solver library.
Definition: solverNew.C:30
A class for handling words, derived from string.
Definition: word.H:63
Foam::fvMesh mesh(Foam::IOobject(regionName, runTime.name(), runTime, Foam::IOobject::MUST_READ), false)
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:334
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
dlLibraryTable libs
Table of loaded dynamic libraries.
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:288
messageStream Info
Ostream & indentOrNl(Ostream &os)
Indent stream or add newline if indent level == 0.
Definition: Ostream.H:250
error FatalError
static const char nl
Definition: Ostream.H:297