CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > OpenFOAM > OpenFOAM Running, Solving & CFD

ForAll loop and vector comparison

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   August 11, 2008, 04:39
Default I'm having trouble with a for
  #1
Member
 
Juho Peltola
Join Date: Mar 2009
Location: Finland
Posts: 89
Rep Power: 17
juho is on a distinguished road
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 is offline   Reply With Quote

Old   August 12, 2008, 04:11
Default Hi again. I actually manage
  #2
Member
 
Juho Peltola
Join Date: Mar 2009
Location: Finland
Posts: 89
Rep Power: 17
juho is on a distinguished road
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.

Juho
juho is offline   Reply With Quote

Old   August 15, 2008, 06:05
Default U returns a vector mag(U) ret
  #3
Senior Member
 
Eugene de Villiers
Join Date: Mar 2009
Posts: 725
Rep Power: 21
eugene is on a distinguished road
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 is offline   Reply With Quote

Old   August 15, 2008, 06:06
Default Missed a bracket, should be:
  #4
Senior Member
 
Eugene de Villiers
Join Date: Mar 2009
Posts: 725
Rep Power: 21
eugene is on a distinguished road
Missed a bracket, should be:

if (mag(U[ccelli]) > ULimit.value())
eugene is offline   Reply With Quote

Old   June 17, 2011, 10:51
Default
  #5
Senior Member
 
Francois Beaubert
Join Date: Mar 2009
Location: Lille, France
Posts: 147
Rep Power: 17
francois is on a distinguished road
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
(
IOobject
(
"ccCyl",
runTime.timeName(),
mesh,
IOobject::NO_READ,
IOobject::NO_WRITE
),
mesh,
vector(0,0,0)
);

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

Francois
francois is offline   Reply With Quote

Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Tensor mathematics forAll macro combination tensors with vectors olesen OpenFOAM Running, Solving & CFD 4 February 25, 2009 06:03
Vector devide by vector bhuve OpenFOAM Running, Solving & CFD 2 June 2, 2008 08:14
which is a better way to loop in fortran? zonexo Main CFD Forum 7 June 23, 2006 05:47
Why doesnbt the macro forall work for the volVectorField variable siwen OpenFOAM Running, Solving & CFD 2 February 24, 2006 16:27
loop(p,I->p) how this loop works? Sinan FLUENT 0 January 18, 2005 19:04


All times are GMT -4. The time now is 21:10.