Commit 90c6eb77 authored by Kutalmis Bercin's avatar Kutalmis Bercin
Browse files

ENH: binModels: new bin models for forces/forceCoeffs

three runtime selectable bin models:
- noBin
- singleDirectionUniformBin
- uniformBin (including Cartesian and cylindrical bins)
parent 22a1eec8
forces/forces.C
forceCoeffs/forceCoeffs.C
binModels/binModel/binModel.C
binModels/binModel/binModelNew.C
binModels/derived/noBin/noBin.C
binModels/derived/singleDirectionUniformBin/singleDirectionUniformBin.C
binModels/derived/uniformBin/uniformBin.C
LIB = $(FOAM_LIBBIN)/libforces
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "binModel.H"
#include "fvMesh.H"
#include "fluidThermo.H"
#include "turbulentTransportModel.H"
#include "turbulentFluidThermoModel.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
defineTypeNameAndDebug(binModel, 0);
defineRunTimeSelectionTable(binModel, dictionary);
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::binModel::binModel
(
const word& name,
const dictionary& dict,
const fvMesh& mesh
)
:
mesh_(mesh),
porosity_(false),
nBin_(1),
patchSet_(),
forceBinFilePtr_(nullptr),
momentBinFilePtr_(nullptr),
coeffBinFilePtrs_()
{}
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
bool Foam::binModel::read(const dictionary& dict)
{
dict.readIfPresent("porosity", porosity_);
patchSet_ =
mesh_.boundaryMesh().patchSet
(
dict.get<wordRes>("patches")
);
if (!(dict.found("binModel")) && dict.found("binData")) // old behaviour
{
Info<< " Selecting bin model: singleDirectionBin" << endl;
}
else
{
const word modelType(dict.getOrDefault<word>("binModel", "noBin"));
Info<< " Selecting bin model: " << modelType << endl;
}
coeffBinFilePtrs_.setSize(6);
return true;
}
// ************************************************************************* //
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
Namespace
Foam::binModels
Description
A namespace for various bin model implementations.
Class
Foam::binModel
Description
Abstract base class for bin models to handle bin
characteristics for \c force and \c forceCoeffs function objects.
See also
- Foam::binModel
- Foam::binModels::noBin
- Foam::binModels::singleDirectionUniformBin
- Foam::binModels::uniformBin
SourceFiles
binModel.C
binModelNew.C
\*---------------------------------------------------------------------------*/
#ifndef binModel_H
#define binModel_H
#include "dictionary.H"
#include "HashSet.H"
#include "volFields.H"
#include "runTimeSelectionTables.H"
#include "OFstream.H"
#include "cartesianCS.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// Forward Declarations
class fvMesh;
/*---------------------------------------------------------------------------*\
Class binModel Declaration
\*---------------------------------------------------------------------------*/
class binModel
{
protected:
// Protected Data
//- Reference to mesh
const fvMesh& mesh_;
//- Flag to include porosity effects
bool porosity_;
//- Total number of bins (internal)
label nBin_;
//- Names of operand patches
labelHashSet patchSet_;
// File streams
//- File stream for forces in bins
autoPtr<OFstream> forceBinFilePtr_;
//- File stream for moments in bins
autoPtr<OFstream> momentBinFilePtr_;
//- File streams for force and moment coefficients in bins
PtrList<OFstream> coeffBinFilePtrs_;
// Generated Methods
//- No copy construct
binModel(const binModel&) = delete;
//- No copy assignment
void operator=(const binModel&) = delete;
public:
//- Runtime type information
TypeName("binModel");
// Declare runtime constructor selection table
declareRunTimeSelectionTable
(
autoPtr,
binModel,
dictionary,
(
const word& name,
const dictionary& dict,
const fvMesh& mesh
),
(name, dict, mesh)
);
// Selectors
//- Return a reference to the selected bin model
static autoPtr<binModel> New
(
const word& name,
const dictionary& dict,
const fvMesh& mesh
);
// Constructors
//- Construct from components
binModel
(
const word& name,
const dictionary& dict,
const fvMesh& mesh
);
//- Destructor
virtual ~binModel() = default;
// Member Functions
// Access
//- Read the dictionary
virtual bool read(const dictionary& dict);
//- Return the total number of bins
label nBin() const noexcept
{
return nBin_;
};
// Evaluate
//- Initialise bin properties
virtual void initialise() = 0;
//- Apply bins to force and moment containers
virtual void applyBins
(
List<Field<vector>>& force,
List<Field<vector>>& moment,
const vectorField& d,
const vectorField& Md,
const vectorField& fN,
const vectorField& fT
) = 0;
//- Apply bins to force and moment
//- containers, and include porosity effects
virtual void applyBins
(
List<Field<vector>>& force,
List<Field<vector>>& moment,
const vectorField& d,
const vectorField& Md,
const vectorField& fN,
const vectorField& fT,
const vectorField& fP
) = 0;
// Write
//- Create binned-data files
virtual void createBinnedDataFiles() = 0;
//- Create a binned-data file - coefficients
virtual void createBinnedDataFile
(
const word& title,
const label id
) = 0;
//- Write binned force and moment data to files
virtual void writeBinnedDataFiles
(
const List<Field<vector>>& force,
const List<Field<vector>>& moment,
const coordSystem::cartesian& coordSys
) = 0;
//- Write binned force and moment coefficient data to a file
virtual void writeBinnedDataFile
(
List<Field<scalar>> coeff,
const label id
) = 0;
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "binModel.H"
#include "fvMesh.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
Foam::autoPtr<Foam::binModel> Foam::binModel::New
(
const word& name,
const dictionary& dict,
const fvMesh& mesh
)
{
word modelType(dict.getOrDefault<word>("binModel", "none"));
if (!(dict.found("binModel")) && dict.found("binData")) // old behaviour
{
modelType = word("singleDirectionUniformBin");
}
auto cstrIter = dictionaryConstructorTablePtr_->cfind(modelType);
if (!cstrIter.found())
{
FatalIOErrorInLookup
(
dict,
"binModel",
modelType,
*dictionaryConstructorTablePtr_
) << exit(FatalIOError);
}
return autoPtr<binModel>(cstrIter()(name, dict, mesh));
}
// ************************************************************************* //
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "noBin.H"
#include "addToRunTimeSelectionTable.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
namespace binModels
{
defineTypeNameAndDebug(noBin, 0);
addToRunTimeSelectionTable(binModel, noBin, dictionary);
}
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::binModels::noBin::noBin
(
const word& name,
const dictionary& dict,
const fvMesh& mesh
)
:
binModel(name, dict, mesh)
{}
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
bool Foam::binModels::noBin::read(const dictionary& dict)
{
return binModel::read(dict);
}
void Foam::binModels::noBin::initialise()
{
nBin_ = 1;
}
void Foam::binModels::noBin::applyBins
(
List<Field<vector>>& force,
List<Field<vector>>& moment,
const vectorField& d,
const vectorField& Md,
const vectorField& fN,
const vectorField& fT
)
{
force[0][0] += sum(fN);
force[1][0] += sum(fT);
moment[0][0] += sum(Md^fN);
moment[1][0] += sum(Md^fT);
}
void Foam::binModels::noBin::applyBins
(
List<Field<vector>>& force,
List<Field<vector>>& moment,
const vectorField& d,
const vectorField& Md,
const vectorField& fN,
const vectorField& fT,
const vectorField& fP
)
{
force[0][0] += sum(fN);
force[1][0] += sum(fT);
force[2][0] += sum(fP);
moment[0][0] += sum(Md^fN);
moment[1][0] += sum(Md^fT);
moment[2][0] += sum(Md^fP);
}
// ************************************************************************* //
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
Class
Foam::binModels::noBin
Description
Bin model providing an interface to bin properties without any active bin.
Usage
Minimal example by using \c system/controlDict.functions:
\verbatim
<forces1/forceCoeffs1>
{
// Mandatory and optional entries
...
// Optional entries (runtime modifiable)
binModel none;
}
\endverbatim
where the entries mean:
\table
Property | Description | Type | Reqd | Deflt
binModel | Type name: noBin | word | no | -
\endtable
See also
- Foam::binModel
- Foam::binModels::singleDirectionUniformBin
- Foam::binModels::uniformBin
SourceFiles
noBin.C
\*---------------------------------------------------------------------------*/
#ifndef binModels_noBin_H
#define binModels_noBin_H
#include "binModel.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
namespace binModels
{
/*---------------------------------------------------------------------------*\
Class noBin Declaration
\*---------------------------------------------------------------------------*/
class noBin
:
public binModel
{
// Generated Methods
//- No copy construct
noBin(const noBin&) = delete;