Commit df283b54 authored by henry's avatar henry
Browse files
parents 26f2c24d 33e30cda
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2008 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::regularExpression
Description
Wrapper around regular expressions.
SourceFiles
\*---------------------------------------------------------------------------*/
#ifndef regularExpression_H
#define regularExpression_H
#include <sys/types.h>
#include <regex.h>
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
/*---------------------------------------------------------------------------*\
Class regularExpression Declaration
\*---------------------------------------------------------------------------*/
class regularExpression
{
// Private data
//- Precompiled regular expression
regex_t* preg_;
// Private member functions
//- Disallow default bitwise copy construct
regularExpression(const regularExpression&);
//- Disallow default bitwise assignment
void operator=(const regularExpression&);
public:
// Constructors
//- Construct from string
inline regularExpression(const string& s)
{
preg_ = new regex_t;
if (regcomp(preg_, s.c_str(), REG_EXTENDED|REG_NOSUB) != 0)
{
FatalErrorIn
(
"regularExpression::regularExpression(const char*)"
) << "Failed to compile regular expression " << s
<< exit(FatalError);
}
}
// Destructor
//- Construct from string
inline ~regularExpression()
{
if (preg_)
{
regfree(preg_);
delete preg_;
}
}
// Member functions
//- Matches?
inline bool matches(const string& s)
{
size_t nmatch = 0;
regmatch_t *pmatch = NULL;
return regexec(preg_, s.c_str(), nmatch, pmatch, 0) == 0;
}
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //
......@@ -526,7 +526,7 @@ Foam::point Foam::face::centre(const pointField& meshPoints) const
}
Foam::vector Foam::face::normal(const pointField& meshPoints) const
Foam::vector Foam::face::normal(const pointField& p) const
{
// Calculate the normal by summing the face triangle normals.
// Changed to deal with small concavity by using a central decomposition
......@@ -539,38 +539,43 @@ Foam::vector Foam::face::normal(const pointField& meshPoints) const
{
return triPointRef
(
meshPoints[operator[](0)],
meshPoints[operator[](1)],
meshPoints[operator[](2)]
p[operator[](0)],
p[operator[](1)],
p[operator[](2)]
).normal();
}
vector n = vector::zero;
label nPoints = size();
point centrePoint = Foam::average(points(meshPoints));
register label pI;
label nPoints = size();
point centrePoint = vector::zero;
for (pI = 0; pI < nPoints; pI++)
{
centrePoint += p[operator[](pI)];
}
centrePoint /= nPoints;
point nextPoint = centrePoint;
vector n = vector::zero;
register label pI;
point nextPoint = centrePoint;
for (pI = 0; pI < nPoints; pI++)
{
if (pI < nPoints - 1)
{
nextPoint = meshPoints[operator[](pI + 1)];
nextPoint = p[operator[](pI + 1)];
}
else
{
nextPoint = meshPoints[operator[](0)];
nextPoint = p[operator[](0)];
}
// Note: for best accuracy, centre point always comes last
//
n += triPointRef
(
meshPoints[operator[](pI)],
p[operator[](pI)],
nextPoint,
centrePoint
).normal();
......
......@@ -25,9 +25,7 @@ License
\*---------------------------------------------------------------------------*/
#include "labelList.H"
#include <sys/types.h>
#include <regex.h>
#include "regularExpression.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
......@@ -41,24 +39,12 @@ labelList findStrings(const string& regexp, const StringList& sl)
{
labelList matches(sl.size());
regex_t *preg = new regex_t;
if (regcomp(preg, regexp.c_str(), REG_EXTENDED|REG_NOSUB) != 0)
{
WarningIn("findStrings(const string& regexp, const stringList& sl)")
<< "Failed to compile regular expression " << regexp
<< endl;
return matches;
}
size_t nmatch = 0;
regmatch_t *pmatch = NULL;
regularExpression re(regexp);
label matchi = 0;
forAll(sl, i)
{
if (regexec(preg, sl[i].c_str(), nmatch, pmatch, 0) == 0)
if (re.matches(sl[i]))
{
matches[matchi++] = i;
}
......@@ -66,9 +52,6 @@ labelList findStrings(const string& regexp, const StringList& sl)
matches.setSize(matchi);
regfree(preg);
delete preg;
return matches;
}
......
......@@ -205,11 +205,12 @@ void faceSet::sync(const polyMesh& mesh)
reduce(nAdded, sumOp<label>());
if (nAdded > 0)
{
Info<< "Added an additional " << nAdded << " faces on coupled patches. "
<< "(processorPolyPatch, cyclicPolyPatch)" << endl;
}
//if (nAdded > 0)
//{
// Info<< "Added an additional " << nAdded
// << " faces on coupled patches. "
// << "(processorPolyPatch, cyclicPolyPatch)" << endl;
//}
}
......
......@@ -6,5 +6,6 @@ wmake libo postCalc
wmake libso forces
wmake libso fieldAverage
wmake libso foamCalcFunctions
wmake libso minMaxFields
# ----------------------------------------------------------------- end-of-file
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2008 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
Typedef
Foam::IOminMaxFields
Description
Instance of the generic IOOutputFilter for minMaxFields.
\*---------------------------------------------------------------------------*/
#ifndef IOminMaxFields_H
#define IOminMaxFields_H
#include "minMaxFields.H"
#include "IOOutputFilter.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
typedef IOOutputFilter<minMaxFields> IOminMaxFields;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //
minMaxFields.C
minMaxFieldsFunctionObject.C
LIB = $(FOAM_LIBBIN)/libminMaxFields
EXE_INC = \
-I$(LIB_SRC)/finiteVolume/lnInclude \
-I$(LIB_SRC)/meshTools/lnInclude \
-I$(LIB_SRC)/sampling/lnInclude
LIB_LIBS = \
-lfiniteVolume \
-lmeshTools
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2008 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 "minMaxFields.H"
#include "volFields.H"
#include "dictionary.H"
#include "Time.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
defineTypeNameAndDebug(minMaxFields, 0);
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::minMaxFields::minMaxFields
(
const word& name,
const objectRegistry& obr,
const dictionary& dict,
const bool loadFromFiles
)
:
name_(name),
obr_(obr),
active_(true),
log_(false),
fieldSet_(),
minMaxFieldsFilePtr_(NULL)
{
// Check if the available mesh is an fvMesh otherise deactivate
if (!isA<fvMesh>(obr_))
{
active_ = false;
WarningIn
(
"minMaxFields::minMaxFields"
"(const objectRegistry& obr, const dictionary& dict)"
) << "No fvMesh available, deactivating."
<< endl;
}
read(dict);
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::minMaxFields::~minMaxFields()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void Foam::minMaxFields::read(const dictionary& dict)
{
if (active_)
{
log_ = dict.lookupOrDefault<Switch>("log", false);
dict.lookup("fields") >> fieldSet_;
}
}
void Foam::minMaxFields::makeFile()
{
// Create the minMaxFields file if not already created
if (!minMaxFieldsFilePtr_.valid())
{
if (debug)
{
Info<< "Creating minMaxFields file." << endl;
}
// File update
if (Pstream::master())
{
fileName minMaxFieldsDir;
if (Pstream::parRun())
{
// Put in undecomposed case (Note: gives problems for
// distributed data running)
minMaxFieldsDir =
obr_.time().path()/".."/name_/obr_.time().timeName();
}
else
{
minMaxFieldsDir =
obr_.time().path()/name_/obr_.time().timeName();
}
// Create directory if does not exist.
mkDir(minMaxFieldsDir);
// Open new file at start up
minMaxFieldsFilePtr_.reset
(
new OFstream(minMaxFieldsDir/(type() + ".dat"))
);
// Add headers to output data
writeFileHeader();
}
}
}
void Foam::minMaxFields::writeFileHeader()
{
if (minMaxFieldsFilePtr_.valid())
{
minMaxFieldsFilePtr_()
<< "# Time" << tab << "field" << tab << "min" << tab << "max"
<< endl;
}
}
void Foam::minMaxFields::execute()
{
// Do nothing - only valid on write
}
void Foam::minMaxFields::write()
{
if (active_)
{
// Create the minMaxFields file if not already created
makeFile();
forAll(fieldSet_, fieldI)
{
calcMinMaxFields<scalar>(fieldSet_[fieldI]);
calcMinMaxFields<vector>(fieldSet_[fieldI]);
calcMinMaxFields<sphericalTensor>(fieldSet_[fieldI]);
calcMinMaxFields<symmTensor>(fieldSet_[fieldI]);
calcMinMaxFields<tensor>(fieldSet_[fieldI]);
}
}
}
template<>
void Foam::minMaxFields::calcMinMaxFields<Foam::scalar>
(
const word& fieldName
)
{
if (obr_.foundObject<volScalarField>(fieldName))
{
const scalarField& field = obr_.lookupObject<scalarField>(fieldName);
scalar minValue = min(field);
scalar maxValue = max(field);
reduce(minValue, minOp<scalar>());
reduce(maxValue, maxOp<scalar>());
if (Pstream::master())
{
minMaxFieldsFilePtr_() << obr_.time().value() << tab
<< fieldName << tab << minValue << tab << maxValue << endl;
if (log_)
{
Info<< "minMaxFields output:" << nl
<< " min(" << fieldName << ") = " << minValue << nl
<< " max(" << fieldName << ") = " << maxValue << nl
<< endl;
}
}
}
}
// ************************************************************************* //
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2008 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::minMaxFields
Description
Calculates scalar minimim and maximum field values.
For variables with rank > 0, computes the magnitude of the min/max
values.
Data written to the file \<timeDir\>/minMaxFields.dat
SourceFiles
minMaxFields.C
IOminMaxFields.H
\*---------------------------------------------------------------------------*/
#ifndef minMaxFields_H
#define minMaxFields_H
#include "primitiveFieldsFwd.H"
#include "volFieldsFwd.H"
#include "labelHashSet.H"
#include "OFstream.H"
#include "Switch.H"
#include "pointFieldFwd.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// Forward declaration of classes
class objectRegistry;
class dictionary;
class mapPolyMesh;
/*---------------------------------------------------------------------------*\
Class minMaxFields Declaration
\*---------------------------------------------------------------------------*/
class minMaxFields
{
protected:
// Private data
//- Name of this set of forces,
// Also used as the name of the probes directory.
word name_;
const objectRegistry& obr_;
//- on/off switch
bool active_;
//- Switch to send output to Info as well as to file
Switch log_;
//- Patches to integrate forces over
wordList fieldSet_;