Commit 589ddb0c authored by Mark Olesen's avatar Mark Olesen
Browse files

ENH: support local forces/moments calculation

- can specify 'CofR', 'coordinateSystem' or implicitly (0 0 0)
  which increases the flexibility
parent 305bdb59
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
\\ / A nd | Copyright (C) 1991-2011 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
......@@ -188,7 +188,7 @@ Foam::forces::forces
fDName_(""),
rhoRef_(VGREAT),
pRef_(0),
CofR_(vector::zero),
coordSys_(),
forcesFilePtr_(NULL)
{
// Check if the available mesh is an fvMesh otherise deactivate
......@@ -225,14 +225,13 @@ void Foam::forces::read(const dictionary& dict)
if (active_)
{
log_ = dict.lookupOrDefault<Switch>("log", false);
directForceDensity_ = dict.lookupOrDefault("directForceDensity", false);
const fvMesh& mesh = refCast<const fvMesh>(obr_);
patchSet_ =
mesh.boundaryMesh().patchSet(wordList(dict.lookup("patches")));
dict.readIfPresent("directForceDensity", directForceDensity_);
if (directForceDensity_)
{
// Optional entry for fDName
......@@ -245,8 +244,8 @@ void Foam::forces::read(const dictionary& dict)
)
{
active_ = false;
WarningIn("void forces::read(const dictionary& dict)")
<< "Could not find " << fDName_ << " in database." << nl
WarningIn("void forces::read(const dictionary&)")
<< "Could not find " << fDName_ << " in database." << nl
<< " De-activating forces."
<< endl;
}
......@@ -272,7 +271,7 @@ void Foam::forces::read(const dictionary& dict)
{
active_ = false;
WarningIn("void forces::read(const dictionary& dict)")
WarningIn("void forces::read(const dictionary&)")
<< "Could not find " << UName_ << ", " << pName_;
if (rhoName_ != "rhoInf")
......@@ -280,8 +279,8 @@ void Foam::forces::read(const dictionary& dict)
Info<< " or " << rhoName_;
}
Info<< " in database." << nl << " De-activating forces."
<< endl;
Info<< " in database." << nl
<< " De-activating forces." << endl;
}
// Reference density needed for incompressible calculations
......@@ -291,8 +290,14 @@ void Foam::forces::read(const dictionary& dict)
pRef_ = dict.lookupOrDefault<scalar>("pRef", 0.0);
}
coordSys_.clear();
// Centre of rotation for moment calculations
CofR_ = dict.lookup("CofR");
// specified directly, from coordinate system, or implicitly (0 0 0)
if (!dict.readIfPresent<point>("CofR", coordSys_.origin()))
{
coordSys_ = coordinateSystem(dict, obr_);
}
}
}
......@@ -345,6 +350,8 @@ void Foam::forces::writeFileHeader()
forcesFilePtr_()
<< "# Time" << tab
<< "forces(pressure, viscous) moment(pressure, viscous)"
<< tab
<< "local forces(pressure, viscous) local moment(pressure, viscous)"
<< endl;
}
}
......@@ -373,13 +380,32 @@ void Foam::forces::write()
if (Pstream::master())
{
forcesFilePtr_() << obr_.time().value() << tab << fm << endl;
forcesMoments fmLocal;
fmLocal.first().first() =
coordSys_.localVector(fm.first().first());
fmLocal.first().second() =
coordSys_.localVector(fm.first().second());
fmLocal.second().first() =
coordSys_.localVector(fm.second().first());
fmLocal.second().second() =
coordSys_.localVector(fm.second().second());
forcesFilePtr_() << obr_.time().value()
<< tab << fm
<< tab << fmLocal << endl;
if (log_)
{
Info<< "forces output:" << nl
<< " forces(pressure, viscous)" << fm.first() << nl
<< " moment(pressure, viscous)" << fm.second() << nl
<< " local:" << nl
<< " forces(pressure, viscous)" << fmLocal.first() << nl
<< " moment(pressure, viscous)" << fmLocal.second() << nl
<< endl;
}
}
......@@ -408,7 +434,10 @@ Foam::forces::forcesMoments Foam::forces::calcForcesMoment() const
{
label patchi = iter.key();
vectorField Md(mesh.C().boundaryField()[patchi] - CofR_);
vectorField Md
(
mesh.C().boundaryField()[patchi] - coordSys_.origin()
);
scalarField sA(mag(Sfb[patchi]));
......@@ -452,7 +481,10 @@ Foam::forces::forcesMoments Foam::forces::calcForcesMoment() const
{
label patchi = iter.key();
vectorField Md(mesh.C().boundaryField()[patchi] - CofR_);
vectorField Md
(
mesh.C().boundaryField()[patchi] - coordSys_.origin()
);
vectorField pf(Sfb[patchi]*(p.boundaryField()[patchi] - pRef));
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
\\ / A nd | Copyright (C) 1991-2011 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
......@@ -28,11 +28,25 @@ Description
Calculates the forces and moments by integrating the pressure and
skin-friction forces over a given list of patches.
Member function calcForcesMoment()calculates and returns the forces and
moments.
Member function forces::write() calls calcForcesMoment() and writes the
forces and moments into the file \<timeDir\>/forces.dat
Member function forces::write() calculates the forces/moments and
writes the forces/moments into the file \<timeDir\>/forces.dat
Note
The centre of rotation for moment calculations can either be specified
by an @c CofR entry, or be taken from origin of the local coordinateSystem.
For example,
@verbatim
CofR (0 0 0);
@endverbatim
or
@verbatim
coordinateSystem
{
origin (0 0 0);
e3 (0 0 1);
e1 (1 0 0);
}
@endverbatim
SourceFiles
forces.C
......@@ -43,6 +57,8 @@ SourceFiles
#ifndef forces_H
#define forces_H
#include "coordinateSystem.H"
#include "coordinateSystems.H"
#include "primitiveFieldsFwd.H"
#include "volFieldsFwd.H"
#include "HashSet.H"
......@@ -69,15 +85,14 @@ class forces
{
public:
// Tuple which holds the pressure (.first()) and viscous (.second) forces
// Tuple for pressure (.first()) and viscous (.second()) forces
typedef Tuple2<vector, vector> pressureViscous;
// Tuple which holds the forces (.first()) and moment (.second)
// Tuple for forces (.first()) and moment (.second())
// pressure/viscous forces Tuples.
typedef Tuple2<pressureViscous, pressureViscous> forcesMoments;
//- Sum operation class to accumulate the pressure, viscous forces
// and moments
//- Sum operation class to accumulate pressure/viscous forces and moments
class sumOp
{
public:
......@@ -92,12 +107,12 @@ public:
(
pressureViscous
(
fm1.first().first() + fm2.first().first(),
fm1.first().first() + fm2.first().first(),
fm1.first().second() + fm2.first().second()
),
pressureViscous
(
fm1.second().first() + fm2.second().first(),
fm1.second().first() + fm2.second().first(),
fm1.second().second() + fm2.second().second()
)
);
......@@ -147,8 +162,8 @@ protected:
//- Reference pressure
scalar pRef_;
//- Centre of rotation
vector CofR_;
//- Coordinate system used when evaluting forces/moments
coordinateSystem coordSys_;
//- Forces/moment file ptr
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment