mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
new foamCalc app and foamCalcFunctions lib, to eventually replace current postProcess functionality
This commit is contained in:
128
src/postProcessing/foamCalcFunctions/field/magGrad/magGrad.C
Normal file
128
src/postProcessing/foamCalcFunctions/field/magGrad/magGrad.C
Normal file
@ -0,0 +1,128 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 1991-2007 OpenCFD Ltd.
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
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 2 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, write to the Free Software Foundation,
|
||||
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "magGrad.H"
|
||||
#include "addToRunTimeSelectionTable.H"
|
||||
|
||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
namespace calcTypes
|
||||
{
|
||||
defineTypeNameAndDebug(magGrad, 0);
|
||||
addToRunTimeSelectionTable(calcType, magGrad, dictionary);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::calcTypes::magGrad::magGrad()
|
||||
:
|
||||
calcType()
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::calcTypes::magGrad::~magGrad()
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
void Foam::calcTypes::magGrad::init()
|
||||
{
|
||||
Foam::argList::validArgs.append("magGrad");
|
||||
argList::validArgs.append("fieldName1 .. fieldNameN");
|
||||
}
|
||||
|
||||
|
||||
void Foam::calcTypes::magGrad::preCalc
|
||||
(
|
||||
const argList& args,
|
||||
const Time& runTime,
|
||||
const fvMesh& mesh
|
||||
)
|
||||
{
|
||||
if (args.additionalArgs().size() < 2)
|
||||
{
|
||||
Info<< nl << "must specify one or more fields" << nl;
|
||||
args.printUsage();
|
||||
FatalError.exit();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Foam::calcTypes::magGrad::calc
|
||||
(
|
||||
const argList& args,
|
||||
const Time& runTime,
|
||||
const fvMesh& mesh
|
||||
)
|
||||
{
|
||||
const stringList& params = args.additionalArgs();
|
||||
|
||||
for (label fieldi=1; fieldi<params.size(); fieldi++)
|
||||
{
|
||||
const word fieldName(params[fieldi]);
|
||||
|
||||
IOobject fieldHeader
|
||||
(
|
||||
fieldName,
|
||||
runTime.timeName(),
|
||||
mesh,
|
||||
IOobject::MUST_READ
|
||||
);
|
||||
|
||||
// Check field exists
|
||||
if (fieldHeader.headerOk())
|
||||
{
|
||||
bool processed = false;
|
||||
|
||||
writeMagGradField<scalar>(fieldHeader, mesh, processed);
|
||||
writeMagGradField<vector>(fieldHeader, mesh, processed);
|
||||
|
||||
if (!processed)
|
||||
{
|
||||
FatalError
|
||||
<< "Unable to process " << fieldName << nl
|
||||
<< "No call to magGrad for fields of type "
|
||||
<< fieldHeader.headerClassName() << nl << nl
|
||||
<< exit(FatalError);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Info<< " No " << fieldName << endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
|
||||
139
src/postProcessing/foamCalcFunctions/field/magGrad/magGrad.H
Normal file
139
src/postProcessing/foamCalcFunctions/field/magGrad/magGrad.H
Normal file
@ -0,0 +1,139 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 1991-2007 OpenCFD Ltd.
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
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 2 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, write to the Free Software Foundation,
|
||||
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Class
|
||||
Foam::magGrad
|
||||
|
||||
Description
|
||||
Writes scalar fields corresponding to the magnitude ot the gradient
|
||||
of the supplied field (name) for each time.
|
||||
|
||||
SourceFiles
|
||||
magGrad.C
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef magGrad_H
|
||||
#define magGrad_H
|
||||
|
||||
#include "calcType.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
namespace calcTypes
|
||||
{
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class magGrad Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
class magGrad
|
||||
:
|
||||
public calcType
|
||||
{
|
||||
// Private Member Functions
|
||||
|
||||
//- Disallow default bitwise copy construct
|
||||
magGrad(const magGrad&);
|
||||
|
||||
//- Disallow default bitwise assignment
|
||||
void operator=(const magGrad&);
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
// Member Functions
|
||||
|
||||
// Calculation routines
|
||||
|
||||
//- Initialise - typically setting static variables,
|
||||
// e.g. command line arguments
|
||||
virtual void init();
|
||||
|
||||
//- Pre-time loop calculations
|
||||
virtual void preCalc
|
||||
(
|
||||
const argList& args,
|
||||
const Time& runTime,
|
||||
const fvMesh& mesh
|
||||
);
|
||||
|
||||
//- Time loop calculations
|
||||
virtual void calc
|
||||
(
|
||||
const argList& args,
|
||||
const Time& runTime,
|
||||
const fvMesh& mesh
|
||||
);
|
||||
|
||||
|
||||
// I-O
|
||||
|
||||
//- Write magGrad fields
|
||||
template<class Type>
|
||||
void writeMagGradField
|
||||
(
|
||||
const IOobject& header,
|
||||
const fvMesh& mesh,
|
||||
bool& processed
|
||||
);
|
||||
|
||||
|
||||
public:
|
||||
|
||||
//- Runtime type information
|
||||
TypeName("magGrad");
|
||||
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct null
|
||||
magGrad();
|
||||
|
||||
|
||||
// Destructor
|
||||
|
||||
virtual ~magGrad();
|
||||
};
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace calcTypes
|
||||
} // End namespace Foam
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#ifdef NoRepository
|
||||
# include "writeMagGradField.C"
|
||||
#endif
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -0,0 +1,61 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 1991-2007 OpenCFD Ltd.
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
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 2 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, write to the Free Software Foundation,
|
||||
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
template<class Type>
|
||||
void Foam::calcTypes::magGrad::writeMagGradField
|
||||
(
|
||||
const IOobject& header,
|
||||
const fvMesh& mesh,
|
||||
bool& processed
|
||||
)
|
||||
{
|
||||
typedef GeometricField<Type, fvPatchField, volMesh> fieldType;
|
||||
|
||||
if (header.headerClassName() == fieldType::typeName)
|
||||
{
|
||||
Info<< " Reading " << header.name() << endl;
|
||||
fieldType field(header, mesh);
|
||||
|
||||
Info<< " Calculating magGrad" << header.name() << endl;
|
||||
volScalarField magGradField
|
||||
(
|
||||
IOobject
|
||||
(
|
||||
"magGrad" + header.name(),
|
||||
mesh.time().timeName(),
|
||||
mesh,
|
||||
IOobject::NO_READ
|
||||
),
|
||||
Foam::mag(fvc::grad(field))
|
||||
);
|
||||
magGradField.write();
|
||||
|
||||
processed = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
Reference in New Issue
Block a user