ComputeTorque

From OpenFOAMWiki

1 Intro

The torque or the power consumption is an usual request in compressor/turbine computations. So here is an atempt to fulfill this request. The code computes the torqe due to pressure forces on a patch.

It applies to Valid versions: OF version 141.png

2 Code

Inside the code, there is a commented loop left there just for clarification purposes. The next line does the same thing in a more elegant way.

 
/*----------------------------------------------------------------------------*\
Application
	computeTorque
 
Description
	computes the pressure torque on a given surface
 
\*---------------------------------------------------------------------------*/
 
// Main program:
 
#include "fvCFD.H"
 
void computeTorq(word patchName, fvMesh& mesh, volScalarField& p);
 
int main(int argc, char *argv[])
{
 
#   include "setRootCase.H"
 
#   include "createTime.H"
#   include "createMesh.H"
#   include "createFields.H"
	
	computeTorq("rotor", mesh, p);
	
	const label buff = findMax(p);
	Info << "label: " << buff << " pMax: " << p[buff] << " point: " << mesh.C()[buff] << endl;
 
 
	
}
 
void computeTorq(word patchName, fvMesh& mesh, volScalarField& p)
{
 
	// get the label for the requested patch
 	label patchID = mesh.boundaryMesh().findPatchID(patchName);
	
	if (-1 == patchID)
	{
		Info << "no patch named "+patchName << endl <<"Available patches:" << endl;
		error err("Error!\n");
 
		//access boundary elements
		const fvPatchList& patches = mesh.boundary();
		
		//loop over boundaries
		forAll(patches, patchI)
		{ 	
			Info << patches[patchI].name() << endl;
		}
		
		err.exit();
	}
	
	const fvPatch& cPatch = mesh.boundary()[patchID];
	
	vector torque(0,0,0);
	const vector r0(0.48,0,0);
	const scalar omega = 104.72; //[rad/s] - 1000 rpm
	
/*	forAll(cPatch,faceI)
	{
		scalar pabs = p.boundaryField()[patchID][faceI]+101325;
		vector Area = cPatch.Sf()[faceI];
		vector r = cPatch.Cf()[faceI]-r0;
		vector force = pabs*Area;
		torque = torque+(r^force);
	}
*/	
	torque = sum((cPatch.Cf()-r0)^((p.boundaryField()[patchID]+101325)*cPatch.Sf()));
	Info << "torque(" << patchName << "): " << torque << " power: " << torque.x()*omega << "[W]" << endl;
}

If the patch is a closed one (as a real boundary should be), then the reference pressure is no longer necessary. Also, for a parallel calculation, the "sum" function should be replaced by a "gSum" call.

3 Download

The utility can be downloaded here: [[1]]

A slightly modified version that computes the torque by reading an MRFZones file is available here: [[2]]

Both versions assume a hard coded pressure reference of 101325 Pa and a fluid density of 1 kg/m3.

A version of MRFSimpleFoam that uses the above described classes and computes the torque at runtime is available here: [[3]]