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

volScalarField to volVectorField

Register Blogs Community New Posts Updated Threads Search

Like Tree10Likes
  • 2 Post By syavash
  • 1 Post By syavash
  • 1 Post By danny123
  • 1 Post By Henning86
  • 1 Post By kmou
  • 2 Post By Tobi
  • 1 Post By danny123
  • 1 Post By danny123

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   July 24, 2015, 07:23
Default volScalarField to volVectorField
  #1
Senior Member
 
Ehsan Asgari
Join Date: Apr 2010
Posts: 473
Rep Power: 18
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
kmou and Kummi like this.

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

Old   July 26, 2015, 03:55
Default
  #2
Senior Member
 
Ehsan Asgari
Join Date: Apr 2010
Posts: 473
Rep Power: 18
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
kmou likes this.
syavash is offline   Reply With Quote

Old   July 28, 2015, 09:03
Default
  #3
Senior Member
 
Ehsan Asgari
Join Date: Apr 2010
Posts: 473
Rep Power: 18
syavash is on a distinguished road
Anyone willing to help??!

Thanks.
syavash is offline   Reply With Quote

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

http://www.cfd-online.com/Forums/ope...ctorfield.html

Best,
Lilla
klilla is offline   Reply With Quote

Old   July 29, 2015, 05:13
Default
  #5
Senior Member
 
Daniel Witte
Join Date: Nov 2011
Posts: 148
Rep Power: 15
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
lpz456 likes this.
danny123 is offline   Reply With Quote

Old   July 29, 2015, 05:17
Default
  #6
Member
 
Join Date: Nov 2012
Posts: 83
Rep Power: 14
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, 09:58
Default
  #7
Senior Member
 
Ehsan Asgari
Join Date: Apr 2010
Posts: 473
Rep Power: 18
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, 10:09
Default
  #8
Member
 
Join Date: Nov 2012
Posts: 83
Rep Power: 14
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

Old   December 2, 2016, 12:29
Default
  #9
Member
 
Camille Bilger
Join Date: Jul 2013
Posts: 43
Rep Power: 13
kmou is on a distinguished road
Quote:
Originally Posted by syavash View Post
@ 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??!
.
Hi Syavash, I am doing exactly this, but I was wondering if you know how to solve this problem, given the answer below (the link does not work anymore), you used the function void replace?
Thank you for any help.
kmou is offline   Reply With Quote

Old   December 2, 2016, 12:59
Default
  #10
Member
 
Join Date: Nov 2012
Posts: 83
Rep Power: 14
Henning86 is on a distinguished road
The component function is not meant to set the internalfield. Try:

Code:
Uvec.internalField().replace(vector::X,avgUx.internalField());
Sry cant test it written with the phone
Henning86 is offline   Reply With Quote

Old   December 2, 2016, 13:20
Default
  #11
Member
 
Camille Bilger
Join Date: Jul 2013
Posts: 43
Rep Power: 13
kmou is on a distinguished road
Quote:
Originally Posted by Henning86 View Post
The component function is not meant to set the internalfield. Try:

Code:
Uvec.internalField().replace(vector::X,avgUx.internalField());
Sry cant test it written with the phone
Thank you very much for your prompt reply, which did the trick!


And if I understood correctly, OpenFOAM cannot store surfaceVectorFields in the time folders? It has to be a mesh-element value of voLVectorField
joshwilliams likes this.

Last edited by kmou; December 2, 2016 at 14:31. Reason: Added thought
kmou is offline   Reply With Quote

Old   September 27, 2018, 17:05
Default Can't convert volScalar Field to volScalarField
  #12
Member
 
Join Date: Apr 2016
Posts: 30
Rep Power: 10
shanvach is on a distinguished road
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.
shanvach is offline   Reply With Quote

Old   September 28, 2018, 03:44
Default
  #13
Super Moderator
 
Tobi's Avatar
 
Tobias Holzmann
Join Date: Oct 2010
Location: Bad Wörishofen
Posts: 2,711
Blog Entries: 6
Rep Power: 52
Tobi has a spectacular aura aboutTobi has a spectacular aura aboutTobi has a spectacular aura about
Send a message via ICQ to Tobi Send a message via Skype™ to Tobi
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];
    ...
}
Of course, there are other possibilities, but this one is the one coming into my mind first. I guess there should be faster ways. To give some feedback to your code:

Code:
volVectorField FV = (KA,KA,KA);
You try to assign a non-defined field - in the sense of c++ - (KA, KA, KA) to a volVectorField. The problem is that the volVectorField operator== cannot handle such assignments and it does not make sense to implement it. Another possibility would be to do it like that:

Code:
volVectorField yourField = U; // copy of the field

forAll(yourField, cellI)
{
    yourField[cellI][0] = KA[cellI][0];
    yourField[cellI][1] = KA[cellI][1];
    ...
}
By the way. Please use code tags for keeping the text clear.
Kummi and lpz456 like this.
__________________
Keep foaming,
Tobias Holzmann
Tobi is offline   Reply With Quote

Old   September 28, 2018, 06:22
Default
  #14
Senior Member
 
Daniel Witte
Join Date: Nov 2011
Posts: 148
Rep Power: 15
danny123 is on a distinguished road
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)
alpha1 is a scalar field and you can replace to any other volScalarField to your liking.
For the source term, the code is:

Code:
fvm::Sp(fvc::div(phi1), U1)
You can replace fvc::div(phi1) by any volScalarField.

The tricky part is:

Code:
fvm::div(phi1, U1)
phi1 is a surfaceScalarField. Basically U1 is interpolated to the faces and the contributions are added to the diagonal and off-diagonal parts of the matrix equation using weight factors. If you mutiply by a volScalarField, the multiplier is not face symmetric anymore. This is out of the scope of OF, I think. What you can do is to build your own fvm object. You just copy one the existing ones that seems close, modify it and define it in fvm.H. Then you compile the work in src/finitVolume. You then can call the object in your application solver.

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
Kummi likes this.
danny123 is offline   Reply With Quote

Old   September 28, 2018, 09:21
Default
  #15
Super Moderator
 
Tobi's Avatar
 
Tobias Holzmann
Join Date: Oct 2010
Location: Bad Wörishofen
Posts: 2,711
Blog Entries: 6
Rep Power: 52
Tobi has a spectacular aura aboutTobi has a spectacular aura aboutTobi has a spectacular aura about
Send a message via ICQ to Tobi Send a message via Skype™ to Tobi
Quote:
Originally Posted by danny123 View Post
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)
alpha1 is a scalar field and you can replace to any other volScalarField to your liking.
For the source term, the code is:

Code:
fvm::Sp(fvc::div(phi1), U1)
You can replace fvc::div(phi1) by any volScalarField.

The tricky part is:

Code:
fvm::div(phi1, U1)
phi1 is a surfaceScalarField. Basically U1 is interpolated to the faces and the contributions are added to the diagonal and off-diagonal parts of the matrix equation using weight factors. If you mutiply by a volScalarField, the multiplier is not face symmetric anymore. This is out of the scope of OF, I think. What you can do is to build your own fvm object. You just copy one the existing ones that seems close, modify it and define it in fvm.H. Then you compile the work in src/finitVolume. You then can call the object in your application solver.

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
Dear Daniel,

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
Tobi is offline   Reply With Quote

Old   September 28, 2018, 11:13
Default
  #16
Senior Member
 
Daniel Witte
Join Date: Nov 2011
Posts: 148
Rep Power: 15
danny123 is on a distinguished road
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
Tobi likes this.
danny123 is offline   Reply With Quote

Old   September 28, 2018, 14:23
Default
  #17
Super Moderator
 
Tobi's Avatar
 
Tobias Holzmann
Join Date: Oct 2010
Location: Bad Wörishofen
Posts: 2,711
Blog Entries: 6
Rep Power: 52
Tobi has a spectacular aura aboutTobi has a spectacular aura aboutTobi has a spectacular aura about
Send a message via ICQ to Tobi Send a message via Skype™ to Tobi
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
Tobi is offline   Reply With Quote

Reply


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


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


All times are GMT -4. The time now is 20:35.