Commit 1e3f9823 authored by Andrew Heather's avatar Andrew Heather
Browse files

new foamCalc app and foamCalcFunctions lib, to eventually replace current postProcess functionality

parent a7a97ca8
EXE_INC = \
-I$(LIB_SRC)/finiteVolume/lnInclude
EXE_LIBS = \
-lfiniteVolume \
EXE_INC = \
-I$(LIB_SRC)/finiteVolume/lnInclude
EXE_LIBS = \
-lfiniteVolume \
/*---------------------------------------------------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: 1.0 |
| \\ / A nd | Web: http://www.openfoam.org |
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/
// magGradU tool definition
description "Magnitude of grad(U) calculation";
magGradUDict
{
type dictionary;
description "magGradU control dictionary";
dictionaryPath "system";
entries
{
arguments
{
type rootCaseTimeArguments;
}
}
}
// ************************************************************************* //
EXE_INC = \
-I$(LIB_SRC)/finiteVolume/lnInclude
EXE_LIBS = \
-lfiniteVolume \
foamCalc.C
EXE = $(FOAM_APPBIN)/foamCalc
EXE_INC = \
-I$(LIB_SRC)/finiteVolume/lnInclude \
-I$(LIB_SRC)/postProcessing/foamCalcFunctions/lnInclude
EXE_LIBS = \
-lfiniteVolume \
-lfoamCalcFunctions
......@@ -23,86 +23,69 @@ License
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Application
magGrad
foamCalc
Description
Calculates and writes the magnitude of the gradient of a field for each
time
Generic wrapper for calculating a quantity at each time. Split into four
phases:
1. Intialise
2. Pre-time calculation loop
3. Calculation loop
4. Post-calculation loop
\*---------------------------------------------------------------------------*/
#include "fvCFD.H"
#include "timeSelector.H"
#include "calcType.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#include "writeMagGradField.C"
int main(int argc, char *argv[])
{
timeSelector::addOptions();
argList::validArgs.append("fieldName1 .. fieldNameN"); // abuse for usage
Foam::timeSelector::addOptions();
Foam::argList::validOptions.insert("noWrite", "");
Foam::argList::validOptions.insert("dict", "dictionary name");
// setRootCase, but skip args check
argList args(argc, argv, false);
if (!args.checkRootCase())
if (argc < 2)
{
Foam::FatalError.exit();
FatalError
<< "No utility has been supplied" << nl
<< exit(FatalError);
}
const stringList& params = args.additionalArgs();
if (!params.size())
{
Info<< nl << "must specify one or more fields" << nl;
args.printUsage();
FatalError.exit();
}
word utilityName = argv[1];
Foam::autoPtr<Foam::calcType> utility
(
calcType::New(utilityName)
);
utility().tryInit();
# include "setRootCase.H"
# include "createTime.H"
instantList timeDirs = timeSelector::select0(runTime, args);
Foam::instantList timeDirs = Foam::timeSelector::select0(runTime, args);
# include "createMesh.H"
utility().tryPreCalc(args, runTime, mesh);
forAll(timeDirs, timeI)
{
runTime.setTime(timeDirs[timeI], timeI);
Info<< "Time = " << runTime.timeName() << endl;
Foam::Info<< "Time = " << runTime.timeName() << Foam::endl;
mesh.readUpdate();
forAll(params, paramI)
{
const word fieldName(params[paramI]);
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;
}
}
utility().tryCalc(args, runTime, mesh);
Foam::Info<< Foam::endl;
}
utility().tryPostCalc(args, runTime, mesh);
return 0;
}
// ************************************************************************* //
......@@ -4,4 +4,6 @@ set -x
wmake libo postCalc
wmake libso forces
wmake libso fieldAverage
wmake libso foamCalcFunctions
calcType/calcType.C
calcType/newCalcType.C
field/components/components.C
field/mag/mag.C
field/magSqr/magSqr.C
field/magGrad/magGrad.C
LIB = $(FOAM_LIBBIN)/libfoamCalcFunctions
......@@ -2,5 +2,4 @@ EXE_INC = \
-I$(LIB_SRC)/finiteVolume/lnInclude
EXE_LIBS = \
-lfiniteVolume \
-lfiniteVolume
/*---------------------------------------------------------------------------*\
========= |
\\ / 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 "calcType.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
defineTypeNameAndDebug(calcType, 0);
defineRunTimeSelectionTable(calcType, dictionary);
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::calcType::calcType()
{}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::calcType::~calcType()
{}
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
void Foam::calcType::init()
{
// Do nothing
}
void Foam::calcType::preCalc
(
const argList& args,
const Time& runTime,
const fvMesh& mesh
)
{
// Do nothing
}
void Foam::calcType::calc
(
const argList& args,
const Time& runTime,
const fvMesh& mesh
)
{
// Do nothing
}
void Foam::calcType::postCalc
(
const argList& args,
const Time& runTime,
const fvMesh& mesh
)
{
// Do nothing
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void Foam::calcType::tryInit()
{
FatalIOError.throwExceptions();
try
{
init();
}
catch(IOerror& err)
{
Warning<< err << endl;
}
}
void Foam::calcType::tryPreCalc
(
const argList& args,
const Time& runTime,
const fvMesh& mesh
)
{
FatalIOError.throwExceptions();
try
{
preCalc(args, runTime, mesh);
}
catch(IOerror& err)
{
Warning<< err << endl;
}
}
void Foam::calcType::tryCalc
(
const argList& args,
const Time& runTime,
const fvMesh& mesh
)
{
FatalIOError.throwExceptions();
try
{
calc(args, runTime, mesh);
}
catch(IOerror& err)
{
Warning<< err << endl;
}
}
void Foam::calcType::tryPostCalc
(
const argList& args,
const Time& runTime,
const fvMesh& mesh
)
{
FatalIOError.throwExceptions();
try
{
postCalc(args, runTime, mesh);
}
catch(IOerror& err)
{
Warning<< err << endl;
}
}
// ************************************************************************* //
/*---------------------------------------------------------------------------*\
========= |
\\ / 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::calcType
Description
Base class for post-processing calculation functions
SourceFiles
calcType.C
\*---------------------------------------------------------------------------*/
#ifndef calcType_H
#define calcType_H
#include "autoPtr.H"
#include "runTimeSelectionTables.H"
#include "fvCFD.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
/*---------------------------------------------------------------------------*\
Class calcType Declaration
\*---------------------------------------------------------------------------*/
class calcType
{
// Private Member Functions
//- Disallow default bitwise copy construct
calcType(const calcType&);
//- Disallow default bitwise assignment
void operator=(const calcType&);
protected:
// 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
);
//- Post-time loop calculations
virtual void postCalc
(
const argList& args,
const Time& runTime,
const fvMesh& mesh
);
public:
//- Runtime type information
TypeName("calcType");
// Declare runtime constructor selection table
declareRunTimeSelectionTable
(
autoPtr,
calcType,
dictionary,
(),
()
);
// Constructors
//- Construct null
calcType();
// Selectors
static autoPtr<calcType> New(const word& calcTypeName);
// Destructor
virtual ~calcType();
// Member Functions
// Calculation routines - wrapped by exception handling loop
//- Initialise - typically setting static variables,
// e.g. command line arguments
void tryInit();
//- Pre-time loop calculations
void tryPreCalc
(
const argList& args,
const Time& runTime,
const fvMesh& mesh
);
//- Time loop calculations
void tryCalc
(
const argList& args,
const Time& runTime,
const fvMesh& mesh
);
//- Post-time loop calculations
void tryPostCalc
(
const argList& args,
const Time& runTime,
const fvMesh& mesh
);
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //
/*---------------------------------------------------------------------------*\
========= |
\\ / 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 "calcType.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
Foam::autoPtr<Foam::calcType> Foam::calcType::New
(
const word& calcTypeName
)