CFD Online Discussion Forums

CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   OpenFOAM Programming & Development (http://www.cfd-online.com/Forums/openfoam-programming-development/)
-   -   Problem with using function object to compute Nu number in parallel. (http://www.cfd-online.com/Forums/openfoam-programming-development/92319-problem-using-function-object-compute-nu-number-parallel.html)

feldy77 September 9, 2011 20:17

Problem with using function object to compute Nu number in parallel.
 
Hi ,
I use a function object tool to compute Nu number directly during the the simulation (not as a postprocessing utility that works with a saved data after the simulation is done). For this purpose I use a function object tool. Attached please see three files: Nu.H, Nu.C, and controlDict:

Nu.H-----------------------------------------------------------
#ifndef Nu_H
#define Nu_H
#include "pointFieldFwd.H"
#include "volFields.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// Forward declaration of classes
class objectRegistry;
class dictionary;
class mapPolyMesh;
/*---------------------------------------------------------------------------*\
Class Nu Declaration
\*---------------------------------------------------------------------------*/
class Nu
{
//- on/off switch
bool active_;
//- Name of this set of Nu,
// Also used as the name of the probes directory.
word name_;
const objectRegistry& obr_;
//- Maximal temperature
scalar Tmax_;
//- Minimal temperature
scalar Tmin_;
//-Nusselt number
scalar Nusselt_;
// External radius Ro
scalar Ro_;
//Inyternal radius Ri
scalar Ri_;
//Gap width
scalar L_;
//Temperature difference
scalar DT_;
//name for the temperature field
word TName_;

//- Disallow default bitwise copy construct
Nu(const Nu&);
//- Disallow default bitwise assignment
void operator=(const Nu&);

const fvMesh& mesh();
public:
//- Runtime type information
TypeName("Nu");
 
// Constructors
//- Construct for given objectRegistry and dictionary.
// Allow the possibility to load fields from files
Nu
(
const word& name,
const objectRegistry&,
const dictionary&,
const bool loadFromFiles = false
);
 
//- Destructor
virtual ~Nu();
 
// Member Functions
//- Return name of the set of Nu
virtual const word& name() const
{
return name_;
}
//- Read the Nu data
virtual void read(const dictionary&);
//- Execute, currently does nothing
virtual void execute();
//- Execute at the final time-loop, currently does nothing
virtual void end();
//- Write the Nu
virtual void write();

//- Update for changes of mesh
virtual void updateMesh(const mapPolyMesh&)
{}
//- Update for changes of mesh
virtual void movePoints(const pointField&)
{}
};
 
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************** *********************** //
Nu.C

\*---------------------------------------------------------------------------*/
#include "Nu.H"
#include "dictionary.H"
#include "Time.H"
#include "fvCFD.H"
#include "wallFvPatch.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
defineTypeNameAndDebug(Nu, 0);
}
 
 
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::Nu::Nu
(
const word& name,
const objectRegistry& obr,
const dictionary& dict,
const bool loadFromFiles
)
:
active_(true),
name_(name),
obr_(obr)
{
// Check if the available mesh is an fvMesh otherise deactivate

if (!isA<fvMesh>(obr_))
{
active_ = false;
WarningIn
(
"Foam::Nu::Nu"
"("
"const word&, "
"const objectRegistry&, "
"const dictionary&, "
"const bool"
")"
) << "No fvMesh available, deactivating."
<< endl;
}
read(dict);
}
 
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::Nu::~Nu()
{}
 
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void Foam::Nu::read(const dictionary& dict)
{
if (active_)
{
dict.lookup("TName")>> TName_;
dict.lookup("Tmax")>>Tmax_;
dict.lookup("Tmin")>>Tmin_;
dict.lookup("Rin") >>Ri_;
dict.lookup("Rout")>>Ro_;
DT_=Tmax_-Tmin_;
L_=Ro_-Ri_;

Info<<"Tmax="<<Tmax_<<endl;
Info<<"Tmin="<<Tmin_<<endl;
Info<<"Rin=" <<Ri_ <<endl;
Info<<"Rout="<<Ro_ <<endl;
 
}
}
 
void Foam::Nu::execute()
{
// Do nothing - only valid on write
}
 
void Foam::Nu::end()
{
// Do nothing - only valid on write
}
 
void Foam::Nu::write()
{
if (active_)
{
const volScalarField& T=
obr_.lookupObject<volScalarField>(TName_);
surfaceScalarField heatFlux =
fvc::snGrad(T);
const surfaceScalarField::GeometricBoundaryField& patchHeatFlux =
heatFlux.boundaryField();
const fvMesh& mesh=refCast<const fvMesh>(obr_);
forAll(patchHeatFlux, patchi)
{
if (isA<wallFvPatch>(mesh.boundary()[patchi]))
{
if (mesh.boundary()[patchi].name()=="internal")
{
Nusselt_ = sum
(
mesh.magSf().boundaryField()[patchi]
*patchHeatFlux[patchi])
*L_/4/3.141592653589793/DT_/Ri_/Ro_;
Info<<Nusselt_;
}
}
}
}

Info<< endl;
}
 
 
// ************************************************** *********************** //
controlDict
libs ("/home/yurifeld/OpenFOAM/yurifeld-1.7.1/lib/linux64GccDPOpt/libuserFunctionObjects.so");
functions
(
Nusselt
{
type Nu;
TName T;
Tmin 293;
Tmax 333;
Rin 0.1;
Rout 0.06667;
outputControl timeStep;
outputInterval 1;
}
);
// ************************************************** *********************** //
The program works perfect when it is runnining in sequential mode, however when I try to run it in parallel it gives me the Nu number only for the zerro processor while I want to get total Nu number which should utilize the sum of all values computed on all the processors. My question is how to make it to do this. I tried to define IO scalar object so that each processor would write its Nu in for in the corresponding time step directory, however I did not suceed to define scalr IO object. If you have any idea please help me to resolve this problem.
Many thanks.


All times are GMT -4. The time now is 04:00.