CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM (https://www.cfd-online.com/Forums/openfoam/)
-   -   Assign one vector to another - still a field? (https://www.cfd-online.com/Forums/openfoam/88808-assign-one-vector-another-still-field.html)

David* May 26, 2011 11:01

Assign one vector to another - still a field?
 
Hi Foamers,

I have some problems with a vector assignment. To do some further computations, I need the unit normal vector of a patch stored as a vector. My command for this is

Code:

vector unitNormalVector;
...
forAll(wallshearstress4Rho.boundaryField(), patchi)
{
unitNormalVector(-mesh.Sf().boundaryField()[patchi]/mesh.magSf().boundaryField()[patchi]);
...
}

I tried also with an equal (=) symbol. I assume, that on both sides of the equation is a vector with three components. But on the right hand side, it's something more complicated, as wmake's error message shows:

Code:

error: no match for call to ‘(Foam::vector) (Foam::tmp<Foam::Field<Foam::Vector<double> > >)’
Which looks like a template vector field (?). But how can there be a field, if I choose a specific patch by using [patchi] within a forAll-loop?
I'm a beginner with C++, so I ask someone more experienced to tell me what I'm doing wrong. :)

Regards,
David

marupio May 26, 2011 12:39

Hey there fellow David G,

boundaryField()[patchi] is not a single control face - it is an entire patch, made up of several faces. I think you can access it a bit more directly:

wallshearstress4Rho.boundaryField()[patchi].nf()

I believe this returns a vector field of all the normal vectors on the patch faces. As for finding the exact centre unit vector, I'm not sure. Maybe look at an fvPatchField that you guess would need to know its unit vector, and see how they do it.

David* May 27, 2011 09:13

Hi David,

thanks for pointing that out, I was really on the wrong track. The line you posted didn't work for me, maybe I missed something before. But the assignment works, if I define unitNormalVector as a vectorField (like I learned now), and add an "&":
Code:

            unitNormalVector&
            (
                  0.00041
                * -mesh.Sf().boundaryField()[patchi]
                / mesh.magSf().boundaryField()[patchi]
            );

I multiply with a factor to get the point(s) at a specific distance from the wall.

At the moment, my code does compile, but ends with a segmentation fault while running. I'll see if I can fix this.

nice weekend,
David


//Edit: 1 month later: the above is NOT an assignment, but I believe a multiplication. A good way to find out if everythings right is to use the Info output, e.g.
Info<< "Cell number = " << number << endl;

marupio May 27, 2011 10:47

I track down segmentation faults by compiling in debug mode, and using gbd...

gdb solverName
>run
-Crashes
>bt
(backtrace - it shows where in the code it crashed)


All times are GMT -4. The time now is 13:07.