CFD Online Discussion Forums

CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   OpenFOAM Running, Solving & CFD (http://www.cfd-online.com/Forums/openfoam-solving/)
-   -   Obtaining velocity components (http://www.cfd-online.com/Forums/openfoam-solving/58091-obtaining-velocity-components.html)

srinath August 8, 2008 03:03

Hello This is rather trivia
 
Hello

This is rather trivial, but for some reason i can't seem to get this line to work.
volScalarField vx = U.x();
The compilation error i get is
error: 'struct Foam::volVectorField' has no member named 'x'

Could someone tell me the right way to get velocity components?

Thanks
Srinath

kmurphy August 8, 2008 10:49

Srinath, You could try
 
Srinath,

You could try

U.component(vector::X)

or

U.component(0)

Regards,
Kieran

zhoubinwx August 9, 2008 04:52

Hi, could I ask the way I set:
 
Hi, could I ask the way I set: partial(Ux)/partial(x) is right?

grad(U.component(vector::X)).component(0)

Thanks

Bin

srinath August 9, 2008 06:10

Thanks Kieran That worked f
 
Thanks Kieran

That worked for the expression

vx= U.component(0)

But i get a runtime error if i do this

volVectorField newphiU = phiU
newphiU.componet(0) = f(scalars).

The error i get is
--> FOAM FATAL ERROR : attempted to assign to a const reference to constant object#0 Foam::error::printStack(Foam:http://www.cfd-online.com/OpenFOAM_D...part/proud.gifstream&) in "/home/srinath/OpenFOAM/OpenFOAM-1.4.1/lib/linuxGccDPOpt/libOpenFOAM.so"
#1 Foam::error::abort() in "/home/srinath/OpenFOAM/OpenFOAM-1.4.1/lib/linuxGccDPOpt/libOpenFOAM.so"

Could someone tell me the 'correct way' to assign components of a volVector field?

Regards
Srinath

luca_g August 9, 2008 06:44

Srinath, I believe that (in
 
Srinath,

I believe that (in most cases) you should be able to find a way to deal with vectors as a whole, and not with individual components. This will keep code more compact and readable.
Maybe it is worth trying.

Regards,
Luca

srinath August 9, 2008 07:37

Dear Luca Suppose i have a
 
Dear Luca

Suppose i have a matrix A times vector B
C= A*B
A is 5*5, B is 5*1
i want to group rhoU from the central 3 components
Any ideas?

Thanks
Srinath

nadine August 9, 2008 16:56

What do you mean by central co
 
What do you mean by central components? C_2,C_3 and C_4?

If yes:
rhoU=D*C where
D=[
0 1 0 0 0
0 0 1 0 0
0 0 0 1 0].

If not, post the complete example code, because your questions hardly make sense.

srinath August 10, 2008 00:10

Nadine Since i didn't know
 
Nadine

Since i didn't know how to assemble a 5 component pseudoVector in OpenFoam, i explicitly carried out the multiplication A*B
Right now, i have C(1), C(2)....C(5).
If i could group these entries into a pseudovector C, i could do what u suggest.

I am trying to solve dw/dt + A\Sigma F.\Delta S = 0
\Sigma F\Delta S is computed previously and plays the role of B.
I know it's components B(1), [B(2), B(3),B(4)],B(5).

I have copied and pasted the relevant portion of the code with some comments

----------Here is B----------------------------
volScalarField res_rho = fvc::div(phi_rho);
volVectorField res_rhoU = fvc::div(phi_rhoU);
volScalarField res_rhoE = fvc::div(phi_rhoE);
------------------------------------------------
--------Entries of A are computed(I don't assemble them together as A---------------

-------I explicitly calculate C=A*B------------
volScalarField newphi_rho = .....ugly stuff....
volScalarField newphi_rhoU1 = ..........
volScalarField newphi_rhoU2 = ......
volScalarField newphi_rhoU3 = .......
volScalarField newphi_rhoE = ........
-------------------------------------------------
I don't know how to group the scalars newphi_* into a vector C to do rhoU = D*C

---I then proceed to say------------
solve(fvm::ddt(rho) == - newphi_rho)
solve(fvm::ddt(rhoU) == -newphi_rhoU)->Cant assemble from newphi_rhoU1 etc
solve(fvm::ddt(rhoE) == -newphi_rhoE

If this isn't clear i can mail you the code.
I tried pasting it, but i don't think it would be relevant to post 200 other lines doing other stuff in between.

Regards
Srinath

nadine August 10, 2008 05:58

If you think your code is not
 
If you think your code is not relevant, then I think your question isn't either.

I don't want to make more guesses how your "volScalarField newphi_rho = .....ugly stuff...." looks in detail, if you provide information bit by bit. You could easily have attached the full 200 lines of code, while pointing out the relevant portions in the body of your post.

You could also put your problem in a more general context, so that somebody could recognize a problem that has a standard solution, but your
http://www.cfd-online.com/OpenFOAM_D...ges/1/8685.png
simply looks like an ordinary differential equation.

Good luck!

srinath August 13, 2008 01:29

Issue is resolved. Used the
 
Issue is resolved.
Used the following command to replace scalar fields in a volVectorField
newphi_rhoU.replace(0,newphi_rhoU1);

Srinath

luca_g August 18, 2008 05:27

Srinath, I still suggest yo
 
Srinath,

I still suggest you that you don't need to explicitely use components.

For example:
vx*res_rhoU.component(0) + vy*res_rhoU.component(1) + vz*res_rhoU.component(2))
==> U & res_rhoU

Similarly you can formulate the three scalar equations for newphi_rhoU1, ..U2, ..U3 into a single vector equation for newphi_rhoU: just have a carefull look at them and collect all the terms appropriately. Than, it will look much nicer.. http://www.cfd-online.com/OpenFOAM_D...part/happy.gif

Regards,
Luca

markc January 16, 2009 16:27

Hello All, A new question w
 
Hello All,

A new question which seems to fit here:

I want to combine 3 scalarFields into 1 vectorField:
>>>
scalarField Xdot(vectOmega & (pointCentres ^ vectX) );
scalarField Ydot(vectOmega & (pointCentres ^ vectY) );
scalarField Zdot(vectOmega & (pointCentres ^ vectZ) );
>>>
with:
vectX = (1,0,0), vectY=(0,1,0), vectZ=(0,0,1)
omega is a vector and pointCentres is a pointField defined as:
pointCentres = mesh.boundaryMesh()[patchI].localPoints();
<<<
Now I need a vectorField which looks likehttp://www.cfd-online.com/OpenFOAM_D...lipart/sad.gifXdot, Ydot, Zdot).

Any ideas how to accomplish this task? Does anyone see a possibility to define such a vectorField with one description, as Luca suggests?

Brgds,

Mark

linch September 19, 2013 11:08

Hi foamers,

does anyone know, how to overwrite a single component of a vector? For example: I have two dimensionedVectors V1 & V2 with same dimensions. And I want to set the Z-Component of the V2 to the Z-value of the V1. What i tried is:is:
Code:

V2.component(2) = V1.component(2);
and
Code:

V2.component(2).value() = V1.component(2).value();
, but the vector V2 doesn't change.

Best regards.

linch September 19, 2013 11:23

Solved:
Code:

V2.value().component(2) = V1.value().component(2);

wadekar October 20, 2014 11:53

volScalarField U.x(1)
(
IOobject
(
"U.x(1)",
runTime.timeName(),
mesh,
IOobject::MUST_READ,
IOobject::AUTO_WRITE
),
mesh
);

I have tried this code for the velocity component, but i get the error-
ycleAvg.C:57:21: error: expected initializer before ‘.’ token
volScalarField U.x(1)

syavash July 30, 2015 07:31

Quote:

Originally Posted by markc (Post 198193)
Hello All,

A new question which seems to fit here:

I want to combine 3 scalarFields into 1 vectorField:
>>>
scalarField Xdot(vectOmega & (pointCentres ^ vectX) );
scalarField Ydot(vectOmega & (pointCentres ^ vectY) );
scalarField Zdot(vectOmega & (pointCentres ^ vectZ) );
>>>
with:
vectX = (1,0,0), vectY=(0,1,0), vectZ=(0,0,1)
omega is a vector and pointCentres is a pointField defined as:
pointCentres = mesh.boundaryMesh()[patchI].localPoints();
<<<
Now I need a vectorField which looks likehttp://www.cfd-online.com/OpenFOAM_D...lipart/sad.gifXdot, Ydot, Zdot).

Any ideas how to accomplish this task? Does anyone see a possibility to define such a vectorField with one description, as Luca suggests?

Brgds,

Mark

Hi Mark,

Could you solve this problem? because I have a very similar problem like this.
I need to construct a volVectorField from three volScalarField, I have tried but got no success.

Thanks,
Syavash


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