# How to convert vectorField to volVectorField

 Register Blogs Members List Search Today's Posts Mark Forums Read

 August 9, 2019, 00:04 How to convert vectorField to volVectorField #1 Member   Wenming Yang Join Date: Jun 2018 Posts: 42 Rep Power: 7 Dear Foamers, I am working on solving an equation like fvm::ddt(M) +fvm::div(phi, M) == -(M-M0)/tau where tau is a constant, M and M0 are volVectorField. M0 is calculated by M0=H*tem1/mag(H), here I calculate tem1 as follows, scalarField tem1(0.0); forAll(H,i) { tem1[i] = 1.0/Foam::tanh(gamma.value()*mag(H).ref()[i])-1.0/(gamma.value()*mag(H).ref()[i]); } H is a volVectorField. M, M0, and H are defined in the file createFields.H. But when I typed M0=H*tem1/mag(H) and compiled, the following error occur, error: no match for ‘operator*’ (operand types are ‘Foam::tmp, Foam::fvPatchField, Foam::volMesh> >’ and ‘Foam::scalarField {aka Foam::Field}’) It seems that tem1 must be a geometricField. Can anyone help me for this problem? Thanks in advance.

August 12, 2019, 12:56
#2
New Member

Sen Wang
Join Date: Jul 2018
Location: Singapore / Notre Dame, U.S.
Posts: 19
Blog Entries: 1
Rep Power: 7
Quote:
 Originally Posted by ywem scalarField tem1(0.0); forAll(H,i) { tem1[i] = 1.0/Foam::tanh(gamma.value()*mag(H).ref()[i])-1.0/(gamma.value()*mag(H).ref()[i]); } H is a volVectorField. M, M0, and H are defined in the file createFields.H. But when I typed M0=H*tem1/mag(H)
Hi there,

I'm new to the code part of OpenFOAM but I will try to help with the best of my understanding.

If you go back to section 3.2.1 of the programmer's guide, you will see that scalarField is only a typedef-declared class name for List<Type>, which is distinctively different from geometricField<Type>. The problem here lies in the fact that there is no way for the operator to match the values since one is a List while the other includes the mesh.

The solution here, I suppose, is to initiate tem1 in 0/ directory as well, and initialize it with the equation you used.

Another solution is to use the static function (geometricField<Type>::New())[https://www.openfoam.com/documentati...b1bfde253137a] and calculate your tem1.

I hope this would give some ideas.

Cheers!

August 12, 2019, 23:56
#3
Member

Wenming Yang
Join Date: Jun 2018
Posts: 42
Rep Power: 7
Quote:
 Originally Posted by wangsen992 Hi there, I'm new to the code part of OpenFOAM but I will try to help with the best of my understanding. If you go back to section 3.2.1 of the programmer's guide, you will see that scalarField is only a typedef-declared class name for List, which is distinctively different from geometricField. The problem here lies in the fact that there is no way for the operator to match the values since one is a List while the other includes the mesh. The solution here, I suppose, is to initiate tem1 in 0/ directory as well, and initialize it with the equation you used. Another solution is to use the static function (geometricField::New())[https://www.openfoam.com/documentati...b1bfde253137a] and calculate your tem1. I hope this would give some ideas. Cheers!
Dear Wang,
I think your first method works well.

 Tags field, geometricfield