CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > OpenFOAM Programming & Development

volScalarField to volVectorField

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

Like Tree1Likes
  • 1 Post By Henning86

Reply
 
LinkBack Thread Tools Display Modes
Old   July 24, 2015, 06:23
Default volScalarField to volVectorField
  #1
Senior Member
 
Syavash
Join Date: Apr 2010
Location: Tehran, Karaj
Posts: 241
Rep Power: 8
syavash is on a distinguished road
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)
    );
Each of these volScalarField variables takes value, e.g. avgUx something like this:


Code:
scalarField spanavgUMeanX
    (
        meshIndexing.collapse(UMean.component(vector::X)())
    );
    
    avgUx.internalField() = spanavgUMeanX;
    avgUx.write();
Now, I need to construct a volVectorField from these scalars, but I do not know the right syntax. I am beginner in OF, so please help me to write this code.

Thanks,
Syavash

Last edited by syavash; July 26, 2015 at 03:40.
syavash is offline   Reply With Quote

Old   July 26, 2015, 02:55
Default
  #2
Senior Member
 
Syavash
Join Date: Apr 2010
Location: Tehran, Karaj
Posts: 241
Rep Power: 8
syavash is on a distinguished road
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))
    );
but when compiling the code, the following error message appears:

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
I have also tried different combinations but with no success.
Any kind of help is highly appreciated

Syavash
syavash is offline   Reply With Quote

Old   July 28, 2015, 08:03
Default
  #3
Senior Member
 
Syavash
Join Date: Apr 2010
Location: Tehran, Karaj
Posts: 241
Rep Power: 8
syavash is on a distinguished road
Anyone willing to help??!

Thanks.
syavash is offline   Reply With Quote

Old   July 28, 2015, 11:49
Default
  #4
Member
 
Kapa Lilla
Join Date: Mar 2009
Location: Bruxelles, Belgium
Posts: 45
Rep Power: 8
klilla is on a distinguished road
See this tread:

scalar points to vectorField

Best,
Lilla
klilla is offline   Reply With Quote

Old   July 29, 2015, 04:13
Default
  #5
Senior Member
 
Daniel Witte
Join Date: Nov 2011
Posts: 127
Rep Power: 5
danny123 is on a distinguished road
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
danny123 is offline   Reply With Quote

Old   July 29, 2015, 04:17
Default
  #6
Member
 
Join Date: Nov 2012
Posts: 57
Rep Power: 4
Henning86 is on a distinguished road
tmp< GeometricField< cmptType,
PatchField, GeoMesh > > component (const direction) const Return a component of the field. More...

try:

volVectorField FieldName.component (const direction) const
Henning86 is offline   Reply With Quote

Old   July 30, 2015, 08:58
Default
  #7
Senior Member
 
Syavash
Join Date: Apr 2010
Location: Tehran, Karaj
Posts: 241
Rep Power: 8
syavash is on a distinguished road
@ 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();
It compiled properly but I get a runtime error:

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)
Any Idea??!

@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.
syavash is offline   Reply With Quote

Old   July 30, 2015, 09:09
Default
  #8
Member
 
Join Date: Nov 2012
Posts: 57
Rep Power: 4
Henning86 is on a distinguished road
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 > &)
syavash likes this.
Henning86 is offline   Reply With Quote

Reply

Thread Tools
Display Modes

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 On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
libOpenSMOKE Tobi OpenFOAM Programming & Development 502 July 23, 2015 21:14
using chemkin JMDag2004 OpenFOAM Pre-Processing 1 December 15, 2014 17:38
make a dimensionedScalar to be volScalarField sharonyue OpenFOAM Programming & Development 4 April 2, 2014 05: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 06:16


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