CFD Online Discussion Forums

CFD Online Discussion Forums (
-   OpenFOAM Running, Solving & CFD (
-   -   ForAll loop and vector comparison (

juho August 11, 2008 03:39

I'm having trouble with a for
I'm having trouble with a for loop over the velocity field. Could anyone point out where the problem might be? I've tried a quite a few variations but I've ran out of ideas.

I've included the relevant part of the code ant the error message below.

================================================== ==========

dimensionedScalar ULimit("ULimit",U.dimensions(),50);

forAll (U, celli) {

if (mag(U[celli]) > ULimit) {


================================================== =========
About line "if (mag(U[celli]) > ULimit)":
================================================== ==========

error: no match for 'operator>' in 'Foam::mag [with Form = Foam::Vector<double>, Cmpt = double, int nCmpt = 3](((const Foam::VectorSpace<foam::vector<double>, double, 3>&)((const Foam::VectorSpace<foam::vector<double>, double, 3>*)(&((Foam::Vector<double>*)((Foam::volVectorFie ld*)Ua)->Foam::GeometricField< foam::vector<double>, Foam::fvPatchField, Foam::volMesh>::<anonymous>.Foam::DimensionedField <foam::vector<double>, Foam::volMesh>::<anonymous>.Foam::Field<foam::vect or<double> >::<anonymous>.Foam::List<foam::vector<double> >::<anonymous>.Foam::UList<t>::operator[] [with T = Foam::Vector<double>](celli))->Foam::Vector<double>::<anonymous>)))) > ULimit'

================================================== =========

juho August 12, 2008 03:11

Hi again. I actually manage
Hi again.

I actually managed to do what I wanted to do without any for loops - which is probably the right way - but for the future I would like to know how a forAll loop, such as described in the first post, could be made to work.


eugene August 15, 2008 05:05

U returns a vector mag(U) ret
U[celli] returns a vector
mag(U[cellI]) returns a scalar
you have defined ULimit as a dimensionedScalar

A dimensionedScalar is not a scalar and the > operation is not defined for comparing these two types. To make it work you can do one of the following:

1. define ULimit as a scalar
2. Write the if statement like this:
if (mag(U[celli] > ULimit.value())

eugene August 15, 2008 05:06

Missed a bracket, should be:
Missed a bracket, should be:

if (mag(U[ccelli]) > ULimit.value())

francois June 17, 2011 09:51

I'm also having trouble with a forAll loop over a volVectorField.

Sorry for the dummy question but I'm not able to find the mistake on the simple snippet code below which doesn't work for ccCyl.boundaryField()[patchI] but do work for ccCyl[patchI]

I've got the following error message

error: no matching function for call to ‘Foam::fvPatchField<Foam::Vector<double> >::component(<unre
solved overloaded function type>)’

--------------------The snippet --------------------------------------------------------------------------------------

volVectorField cc = mesh.C();

//The vector field cc will now be transformed into cylindrical coordinates
volVectorField ccCyl

ccCyl.internalField() = ccs.localVector(cc.internalField());

forAll (ccCyl.boundaryField(), patchI)
ccCyl.boundaryField()[patchI] = ccs.localVector(cc.boundaryField()[patchI]);
if (ccCyl.boundaryField()[patchI].component(vector::y) < 0.0)
Info << "ccCyl.boundaryField = " << ccCyl.boundaryField()[patchI].component(vector::Y);

-------------------------End of the snippet ---------------------------------------------------------------------------------------

Any idea?
Thank you for your kind help


All times are GMT -4. The time now is 16:46.