|
[Sponsors] |
July 24, 2015, 07:23 |
volScalarField to volVectorField
|
#1 |
Senior Member
Ehsan Asgari
Join Date: Apr 2010
Posts: 473
Rep Power: 18 |
Dear Foamers,
I have three volScalarField namely: avgUx, avgUy, and avgUz as follows in the code: Code:
volScalarField avgUx ( IOobject ( "avgUx", runTime.timeName(), mesh, IOobject::NO_READ, IOobject::AUTO_WRITE ), mesh, dimensionedScalar("avgUx", dimVelocity, 0.0) ); volScalarField avgUy ( IOobject ( "avgUy", runTime.timeName(), mesh, IOobject::NO_READ, IOobject::AUTO_WRITE ), mesh, dimensionedScalar("avgUy", dimVelocity, 0.0) ); volScalarField avgUz ( IOobject ( "avgUz", runTime.timeName(), mesh, IOobject::NO_READ, IOobject::AUTO_WRITE ), mesh, dimensionedScalar("avgUz", dimVelocity, 0.0) ); Code:
scalarField spanavgUMeanX ( meshIndexing.collapse(UMean.component(vector::X)()) ); avgUx.internalField() = spanavgUMeanX; avgUx.write(); Thanks, Syavash Last edited by syavash; July 26, 2015 at 04:40. |
|
July 26, 2015, 03:55 |
|
#2 |
Senior Member
Ehsan Asgari
Join Date: Apr 2010
Posts: 473
Rep Power: 18 |
Well, I have tried to construct a volVectorField from aforementioned volScalarField using the following block:
Code:
volVectorField Uvec ( IOobject ( "Uvec", runTime.timeName(), mesh, IOobject::NO_READ, IOobject::AUTO_WRITE ), mesh, dimensionedVector("Uvec",dimVelocity,vector(avgUx,avgUy,avgUz)) ); Code:
In file included from postSpanwiseAverage.C:82:0: collapse.H: In function ‘int main(int, char**)’: collapse.H:128:70: error: no matching function for call to ‘Foam::Vector<double>::Vector(Foam::volScalarField&, Foam::volScalarField&, Foam::volScalarField&)’ dimensionedVector("Uvec",dimVelocity,vector(avgUx,avgUy,avgUz)) ^ collapse.H:128:70: note: candidates are: In file included from /home/syavash/OpenFOAM/OpenFOAM-2.3.1/src/OpenFOAM/lnInclude/Vector.H:153:0, from /home/syavash/OpenFOAM/OpenFOAM-2.3.1/src/OpenFOAM/lnInclude/vector.H:39, from /home/syavash/OpenFOAM/OpenFOAM-2.3.1/src/OpenFOAM/lnInclude/point.H:35, from /home/syavash/OpenFOAM/OpenFOAM-2.3.1/src/OpenFOAM/lnInclude/pointField.H:35, from /home/syavash/OpenFOAM/OpenFOAM-2.3.1/src/OpenFOAM/lnInclude/edge.H:40, from /home/syavash/OpenFOAM/OpenFOAM-2.3.1/src/OpenFOAM/lnInclude/edgeList.H:32, from /home/syavash/OpenFOAM/OpenFOAM-2.3.1/src/OpenFOAM/lnInclude/primitiveMesh.H:54, from /home/syavash/OpenFOAM/OpenFOAM-2.3.1/src/OpenFOAM/lnInclude/polyMesh.H:45, from /home/syavash/OpenFOAM/OpenFOAM-2.3.1/src/finiteVolume/lnInclude/fvMesh.H:50, from /home/syavash/OpenFOAM/OpenFOAM-2.3.1/src/finiteVolume/lnInclude/fvCFD.H:7, from postSpanwiseAverage.C:33: /home/syavash/OpenFOAM/OpenFOAM-2.3.1/src/OpenFOAM/lnInclude/VectorI.H:56:8: note: Foam::Vector<Cmpt>::Vector(Foam::Istream&) [with Cmpt = double] inline Vector<Cmpt>::Vector(Istream& is) ^ /home/syavash/OpenFOAM/OpenFOAM-2.3.1/src/OpenFOAM/lnInclude/VectorI.H:56:8: note: candidate expects 1 argument, 3 provided /home/syavash/OpenFOAM/OpenFOAM-2.3.1/src/OpenFOAM/lnInclude/VectorI.H:47:8: note: Foam::Vector<Cmpt>::Vector(const Cmpt&, const Cmpt&, const Cmpt&) [with Cmpt = double] inline Vector<Cmpt>::Vector(const Cmpt& vx, const Cmpt& vy, const Cmpt& vz) ^ /home/syavash/OpenFOAM/OpenFOAM-2.3.1/src/OpenFOAM/lnInclude/VectorI.H:47:8: note: no known conversion for argument 1 from ‘Foam::volScalarField {aka Foam::GeometricField<double, Foam::fvPatchField, Foam::volMesh>}’ to ‘const double&’ In file included from /home/syavash/OpenFOAM/OpenFOAM-2.3.1/src/OpenFOAM/lnInclude/vector.H:39:0, from /home/syavash/OpenFOAM/OpenFOAM-2.3.1/src/OpenFOAM/lnInclude/point.H:35, from /home/syavash/OpenFOAM/OpenFOAM-2.3.1/src/OpenFOAM/lnInclude/pointField.H:35, from /home/syavash/OpenFOAM/OpenFOAM-2.3.1/src/OpenFOAM/lnInclude/edge.H:40, from /home/syavash/OpenFOAM/OpenFOAM-2.3.1/src/OpenFOAM/lnInclude/edgeList.H:32, from /home/syavash/OpenFOAM/OpenFOAM-2.3.1/src/OpenFOAM/lnInclude/primitiveMesh.H:54, from /home/syavash/OpenFOAM/OpenFOAM-2.3.1/src/OpenFOAM/lnInclude/polyMesh.H:45, from /home/syavash/OpenFOAM/OpenFOAM-2.3.1/src/finiteVolume/lnInclude/fvMesh.H:50, from /home/syavash/OpenFOAM/OpenFOAM-2.3.1/src/finiteVolume/lnInclude/fvCFD.H:7, from postSpanwiseAverage.C:33: /home/syavash/OpenFOAM/OpenFOAM-2.3.1/src/OpenFOAM/lnInclude/Vector.H:100:16: note: template<class Cmpt2> Foam::Vector<Cmpt>::Vector(const Foam::VectorSpace<Foam::Vector<Cmpt2>, Cmpt2, 3>&) inline Vector(const VectorSpace<Vector<Cmpt2>, Cmpt2, 3>&); ^ /home/syavash/OpenFOAM/OpenFOAM-2.3.1/src/OpenFOAM/lnInclude/Vector.H:100:16: note: template argument deduction/substitution failed: In file included from postSpanwiseAverage.C:82:0: collapse.H:128:70: note: ‘Foam::volScalarField {aka Foam::GeometricField<double, Foam::fvPatchField, Foam::volMesh>}’ is not derived from ‘const Foam::VectorSpace<Foam::Vector<Cmpt>, Cmpt, 3>’ dimensionedVector("Uvec",dimVelocity,vector(avgUx,avgUy,avgUz)) ^ In file included from /home/syavash/OpenFOAM/OpenFOAM-2.3.1/src/OpenFOAM/lnInclude/Vector.H:153:0, from /home/syavash/OpenFOAM/OpenFOAM-2.3.1/src/OpenFOAM/lnInclude/vector.H:39, from /home/syavash/OpenFOAM/OpenFOAM-2.3.1/src/OpenFOAM/lnInclude/point.H:35, from /home/syavash/OpenFOAM/OpenFOAM-2.3.1/src/OpenFOAM/lnInclude/pointField.H:35, from /home/syavash/OpenFOAM/OpenFOAM-2.3.1/src/OpenFOAM/lnInclude/edge.H:40, from /home/syavash/OpenFOAM/OpenFOAM-2.3.1/src/OpenFOAM/lnInclude/edgeList.H:32, from /home/syavash/OpenFOAM/OpenFOAM-2.3.1/src/OpenFOAM/lnInclude/primitiveMesh.H:54, from /home/syavash/OpenFOAM/OpenFOAM-2.3.1/src/OpenFOAM/lnInclude/polyMesh.H:45, from /home/syavash/OpenFOAM/OpenFOAM-2.3.1/src/finiteVolume/lnInclude/fvMesh.H:50, from /home/syavash/OpenFOAM/OpenFOAM-2.3.1/src/finiteVolume/lnInclude/fvCFD.H:7, from postSpanwiseAverage.C:33: /home/syavash/OpenFOAM/OpenFOAM-2.3.1/src/OpenFOAM/lnInclude/VectorI.H:34:8: note: Foam::Vector<Cmpt>::Vector() [with Cmpt = double] inline Vector<Cmpt>::Vector() ^ /home/syavash/OpenFOAM/OpenFOAM-2.3.1/src/OpenFOAM/lnInclude/VectorI.H:34:8: note: candidate expects 0 arguments, 3 provided In file included from /home/syavash/OpenFOAM/OpenFOAM-2.3.1/src/OpenFOAM/lnInclude/vector.H:39:0, from /home/syavash/OpenFOAM/OpenFOAM-2.3.1/src/OpenFOAM/lnInclude/point.H:35, from /home/syavash/OpenFOAM/OpenFOAM-2.3.1/src/OpenFOAM/lnInclude/pointField.H:35, from /home/syavash/OpenFOAM/OpenFOAM-2.3.1/src/OpenFOAM/lnInclude/edge.H:40, from /home/syavash/OpenFOAM/OpenFOAM-2.3.1/src/OpenFOAM/lnInclude/edgeList.H:32, from /home/syavash/OpenFOAM/OpenFOAM-2.3.1/src/OpenFOAM/lnInclude/primitiveMesh.H:54, from /home/syavash/OpenFOAM/OpenFOAM-2.3.1/src/OpenFOAM/lnInclude/polyMesh.H:45, from /home/syavash/OpenFOAM/OpenFOAM-2.3.1/src/finiteVolume/lnInclude/fvMesh.H:50, from /home/syavash/OpenFOAM/OpenFOAM-2.3.1/src/finiteVolume/lnInclude/fvCFD.H:7, from postSpanwiseAverage.C:33: /home/syavash/OpenFOAM/OpenFOAM-2.3.1/src/OpenFOAM/lnInclude/Vector.H:58:7: note: Foam::Vector<double>::Vector(const Foam::Vector<double>&) class Vector ^ /home/syavash/OpenFOAM/OpenFOAM-2.3.1/src/OpenFOAM/lnInclude/Vector.H:58:7: note: candidate expects 1 argument, 3 provided make: *** [Make/linux64GccDPOpt/postSpanwiseAverage.o] Error 1 Any kind of help is highly appreciated Syavash |
|
July 28, 2015, 09:03 |
|
#3 |
Senior Member
Ehsan Asgari
Join Date: Apr 2010
Posts: 473
Rep Power: 18 |
Anyone willing to help??!
Thanks. |
|
July 28, 2015, 12:49 |
|
#4 |
Member
Kapa Lilla
Join Date: Mar 2009
Location: Bruxelles, Belgium
Posts: 57
Rep Power: 17 |
||
July 29, 2015, 05:13 |
|
#5 |
Senior Member
Daniel Witte
Join Date: Nov 2011
Posts: 148
Rep Power: 15 |
You can access the individual carthesian coordinates of a volume vector field directly. I think it is something like U[cellI].x or something similar. Just try it out. Then you formulate a ForAll loop and overwrite them. The access of individual memeber of your volume scalar field is even more simple, just avgUx[cellI] is the value of cellI member of avgUx.
Regards, Daniel |
|
July 30, 2015, 09:58 |
|
#7 |
Senior Member
Ehsan Asgari
Join Date: Apr 2010
Posts: 473
Rep Power: 18 |
@ Lilla
I tried something like this: Code:
volVectorField Uvec ( IOobject ( "Uvec", runTime.timeName(), mesh, IOobject::NO_READ, IOobject::AUTO_WRITE ), mesh, dimensionedVector ( "Uvec", dimVelocity, vector::zero ) ); Uvec.internalField().component(vector::X)=avgUx.internalField(); Uvec.internalField().component(vector::Y)=avgUy.internalField(); Uvec.internalField().component(vector::Z)=avgUz.internalField(); Code:
FOAM FATAL ERROR: attempted to assign to a const reference to constant object of type N4Foam5FieldIdEE From function Foam::tmp<T>::operator=(const tmp<T>&) in file /home/syavash/OpenFOAM/OpenFOAM-2.3.1/src/OpenFOAM/lnInclude/tmpI.H at line 306. FOAM aborting #0 Foam::error::printStack(Foam::Ostream&) at ??:? #1 Foam::error::abort() at ??:? #2 at ??:? #3 __libc_start_main in "/lib/x86_64-linux-gnu/libc.so.6" #4 at ??:? Aborted (core dumped) @Henning86: Thanks for your reply. I know the difference between sclalarfield, volScalarField, and volVectorField but I am not really an OF programmer! Could you be more specific regarding my case?!! What syntax should I use? A simple example is highly appreciated. |
|
July 30, 2015, 10:09 |
|
#8 |
Member
Join Date: Nov 2012
Posts: 83
Rep Power: 14 |
This function only allows only to get the compoenents in each direction.
attempted to assign to a const reference to constant object of type Hadn't seen this: The function you are looking for is: http://foam.sourceforge.net/docs/cpp/a00911.html void replace (const direction, const GeometricField< cmptType, PatchField, GeoMesh > &) void replace (const direction, const dimensioned< cmptType > &) |
|
December 2, 2016, 12:29 |
|
#9 | |
Member
Camille Bilger
Join Date: Jul 2013
Posts: 43
Rep Power: 13 |
Quote:
Thank you for any help. |
||
December 2, 2016, 12:59 |
|
#10 |
Member
Join Date: Nov 2012
Posts: 83
Rep Power: 14 |
The component function is not meant to set the internalfield. Try:
Code:
Uvec.internalField().replace(vector::X,avgUx.internalField()); |
|
December 2, 2016, 13:20 |
|
#11 | |
Member
Camille Bilger
Join Date: Jul 2013
Posts: 43
Rep Power: 13 |
Quote:
And if I understood correctly, OpenFOAM cannot store surfaceVectorFields in the time folders? It has to be a mesh-element value of voLVectorField Last edited by kmou; December 2, 2016 at 14:31. Reason: Added thought |
||
September 27, 2018, 17:05 |
Can't convert volScalar Field to volScalarField
|
#12 |
Member
Join Date: Apr 2016
Posts: 30
Rep Power: 10 |
Hi all,
I am trying to edit twoPhaseEulerFoam solver by introducing another force in the momentum equation.Below is the UEqns.H file that I am editing.The bold part is what I am introducing in the code. However the third bolded line where I introduce volVectorField it gives me an error saying "error: conversion from ‘Foam::volScalarField {aka Foam::GeometricField<double, Foam::fvPatchField, Foam::volMesh>}’ to non-scalar type ‘Foam::volVectorField {aka Foam::GeometricField<Foam::Vector<double>, Foam::fvPatchField, Foam::volMesh>}’ requested volVectorField FV = (KA,KA,KA); " How do I introduce the scalar in the volScalarField into volVectorField? Your help in this matter is greatly appreciated. Thanks and Regards, Code:
Info<< "Constructing momentum equations" << endl; MRF.correctBoundaryVelocity(U1); MRF.correctBoundaryVelocity(U2); MRF.correctBoundaryVelocity(U); fvVectorMatrix U1Eqn(U1, rho1.dimensions()*U1.dimensions()*dimVol/dimTime); fvVectorMatrix U2Eqn(U2, rho2.dimensions()*U2.dimensions()*dimVol/dimTime); volTensorField grU_1 = fvc::grad(U1); volScalarField KA = grU_1 && (grU_1 + grU_1.T()); volVectorField FV = (KA,KA,KA); volScalarField Kd(fluid.Kd()); { volScalarField Vm(fluid.Vm()); { U1Eqn = ( fvm::ddt(alpha1, rho1, U1) + fvm::div(alphaRhoPhi1, U1) - fvm::Sp(contErr1, U1) + MRF.DDt(alpha1*rho1 + Vm, U1) + phase1.turbulence().divDevRhoReff(U1) == - Vm *( fvm::ddt(U1) + fvm::div(phi1, U1) - fvm::Sp(fvc::div(phi1), U1) - DDtU2 ) + fvOptions(alpha1, rho1, U1) ); U1Eqn.relax(); U1Eqn += fvm::Sp(Kd, U1); fvOptions.constrain(U1Eqn); U1.correctBoundaryConditions(); fvOptions.correct(U1); } Last edited by Tobi; September 28, 2018 at 03:45. |
|
September 28, 2018, 03:44 |
|
#13 |
Super Moderator
Tobias Holzmann
Join Date: Oct 2010
Location: Bad Wörishofen
Posts: 2,711
Blog Entries: 6
Rep Power: 52 |
Hi,
what you are trying to do is not possible. The easiest way is to do it somehow like that: Code:
volVectorField yourField ( IOobject ( "tmp", ..., mesh, IOobject::NO_READ, IOobject::AUTO_READ ), mesh, dimensionedVector("tmp", dimensionSet(...), vector(0,0,0)), "zeroGradient" // what you need; you can use a wordList too ); forAll(yourField, cellI) { yourField[cellI][0] = KA[cellI][0]; yourField[cellI][1] = KA[cellI][1]; ... } Code:
volVectorField FV = (KA,KA,KA); Code:
volVectorField yourField = U; // copy of the field forAll(yourField, cellI) { yourField[cellI][0] = KA[cellI][0]; yourField[cellI][1] = KA[cellI][1]; ... }
__________________
Keep foaming, Tobias Holzmann |
|
September 28, 2018, 06:22 |
|
#14 |
Senior Member
Daniel Witte
Join Date: Nov 2011
Posts: 148
Rep Power: 15 |
Hi shanvach,
In OF, the fvVectorMatrix is a special object, which describes a linear equation system consisting of a scalar matrix, an unknown vector field and a source term. You cannot just multiply the terms by something. The structure of that operation is that each of those terms (fvm:... etc) does a specific operation to add or assign values to the matrix coefficients or the source term. So, you have to include your mutiplier to each of those component by respecting what kind of field term is asked for. For a scalar field multiplied to the temporal derivative, you somewhat have already have the syntax in the upper part of your code: Code:
fvm::ddt(alpha1, U1) For the source term, the code is: Code:
fvm::Sp(fvc::div(phi1), U1) The tricky part is: Code:
fvm::div(phi1, U1) Just be aware: this is a little work to do and you have to spend some time understanding the structure of fvm objects. Regards, Daniel |
|
September 28, 2018, 09:21 |
|
#15 | |
Super Moderator
Tobias Holzmann
Join Date: Oct 2010
Location: Bad Wörishofen
Posts: 2,711
Blog Entries: 6
Rep Power: 52 |
Quote:
maybe I missed the point when one was starting to talk about fvMatrix class, but shanvach was actually asking for the bold lines in his code?
__________________
Keep foaming, Tobias Holzmann |
||
September 28, 2018, 11:13 |
|
#16 |
Senior Member
Daniel Witte
Join Date: Nov 2011
Posts: 148
Rep Power: 15 |
Dear Tobi,
You are correct. I should read the question more carefully. But the code further below will not work, I think. This popped up immediately when I read it. Regards, Daniel |
|
September 28, 2018, 14:23 |
|
#17 |
Super Moderator
Tobias Holzmann
Join Date: Oct 2010
Location: Bad Wörishofen
Posts: 2,711
Blog Entries: 6
Rep Power: 52 |
Hi,
you are right too. I stopped reading the code after I reached the bolded lines; its a matter of available time I have. However, your answer is of benefit too based on the missing matrix definition.
__________________
Keep foaming, Tobias Holzmann |
|
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
[openSmoke] libOpenSMOKE | Tobi | OpenFOAM Community Contributions | 562 | January 25, 2023 10:21 |
using chemkin | JMDag2004 | OpenFOAM Pre-Processing | 2 | March 8, 2016 23:38 |
make a dimensionedScalar to be volScalarField | sharonyue | OpenFOAM Programming & Development | 4 | April 2, 2014 06:44 |
multiplicate all elements of volScalarField with scalar to get new volScalarField | maybee | OpenFOAM Programming & Development | 2 | February 18, 2014 16:43 |
writing execFlowFunctionObjects | immortality | OpenFOAM Post-Processing | 30 | September 15, 2013 07:16 |