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

convert a "volScalarField" to an "fvScalarMatrix"

Register Blogs Community New Posts Updated Threads Search

Like Tree8Likes
  • 3 Post By Zeppo
  • 1 Post By Zeppo
  • 2 Post By Zeppo
  • 1 Post By agustinvo
  • 1 Post By rarnaunot

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   January 20, 2018, 09:00
Default convert a "volScalarField" to an "fvScalarMatrix"
  #1
Senior Member
 
A. Min
Join Date: Mar 2015
Posts: 308
Rep Power: 12
alimea is on a distinguished road
Hi

How can I convert a "volScalarField" to an "fvScalarMatrix"?

I want to add a volScalarField term to energy Eqn.

Thanks
alimea is offline   Reply With Quote

Old   January 21, 2018, 12:22
Default
  #2
Senior Member
 
Zeppo's Avatar
 
Sergei
Join Date: Dec 2009
Posts: 261
Rep Power: 22
Zeppo will become famous soon enough
Adding a volScalarField to a fvScalarMatrix is as simple as this:

Code:
volScalarField source = ...;
fvScalarMatrix equation = ...;

equation == source;
This way volScalarField goes directly to the rhs (source) of fvScalarMatrix.
Tobi, babakflame and rarnaunot like this.
Zeppo is offline   Reply With Quote

Old   January 21, 2018, 13:53
Default
  #3
Senior Member
 
A. Min
Join Date: Mar 2015
Posts: 308
Rep Power: 12
alimea is on a distinguished road
Quote:
Originally Posted by Zeppo View Post
Adding a volScalarField to a fvScalarMatrix is as simple as this:

Code:
volScalarField source = ...;
fvScalarMatrix equation = ...;

equation == source;
This way volScalarField goes directly to the rhs (source) of fvScalarMatrix.
Thank you for your answer.
Yes, I did it by chance and it didn't give me any error😁
I thought that these kind of variables are different.
Again thanks
alimea is offline   Reply With Quote

Old   January 21, 2018, 17:24
Default
  #4
Senior Member
 
Zeppo's Avatar
 
Sergei
Join Date: Dec 2009
Posts: 261
Rep Power: 22
Zeppo will become famous soon enough
Even though types of variables are different they can be operated that way just fine giving you the result that you might expect.
alimea likes this.
Zeppo is offline   Reply With Quote

Old   April 3, 2020, 07:14
Default Upside down
  #5
Member
 
Rosario Arnau
Join Date: Feb 2017
Location: Spain
Posts: 57
Rep Power: 9
rarnaunot is on a distinguished road
Hi Foamers,

I would like to save the values of the fvScalarMatrix after solving it. But the operator "==" doesn't work upside down, I mean, assigning the values of the fvScalarMatrix to a volScalarField.

Do you know how to do it?

Thanks,
rarnaunot is offline   Reply With Quote

Old   April 3, 2020, 11:41
Default
  #6
Senior Member
 
Agustín Villa
Join Date: Apr 2013
Location: Alcorcón
Posts: 314
Rep Power: 15
agustinvo is on a distinguished road
Hi,


you can't do this because a volScalarField is a scalar variable. fvScalarMatrix is an equation for a scalar variable. What do you want to save from it?
agustinvo is offline   Reply With Quote

Old   April 3, 2020, 11:48
Default
  #7
Member
 
Rosario Arnau
Join Date: Feb 2017
Location: Spain
Posts: 57
Rep Power: 9
rarnaunot is on a distinguished road
Hi agustinvo,

I would like to save the solution of the fvScalarMatrix and then, pass the solution as a volScalarField to another fvScalarMatrix something like:

Code:
fvScalarMatrix equation0 ();

equation0.solve();
fvScalarMatrix equation1 (blablablah=solution of equation0)
Thanks,
rarnaunot is offline   Reply With Quote

Old   April 3, 2020, 12:29
Default
  #8
Senior Member
 
Agustín Villa
Join Date: Apr 2013
Location: Alcorcón
Posts: 314
Rep Power: 15
agustinvo is on a distinguished road
Well, when you solve your fvScalarMatrix equation0 you compute the value of a certain variable var0. Then just add it as a source term into equation1.
agustinvo is offline   Reply With Quote

Old   April 3, 2020, 12:38
Default
  #9
Member
 
Rosario Arnau
Join Date: Feb 2017
Location: Spain
Posts: 57
Rep Power: 9
rarnaunot is on a distinguished road
The problem is that the dependent variable of equation0 is not the same as the one in equation1...

Thanks for your quick reply,
rarnaunot is offline   Reply With Quote

Old   April 3, 2020, 12:59
Default
  #10
Senior Member
 
Agustín Villa
Join Date: Apr 2013
Location: Alcorcón
Posts: 314
Rep Power: 15
agustinvo is on a distinguished road
That is not a problem! Look:


Code:
fvScalarMatrix TEqn
(
     fvm::div(phi, T)
   - fvm::laplacian(alphaEff, T)
   ==
     fvOptions(T) 

);
Here you solve for T, which is a volScalarField


You can add later on T in a source term of any other equation, like


Code:
tmp<fvVectorMatrix> tUEqn
 (
    fvm::div(phi, U)
 + turbulence->divDevReff(U)
 ==
    g*beta*(T-TRef)
 + fvOptions(U)
);
I hope it helps a bit. If you share your code we can help you better

Last edited by agustinvo; April 3, 2020 at 13:05. Reason: Code
agustinvo is offline   Reply With Quote

Old   April 3, 2020, 13:19
Default
  #11
Member
 
Rosario Arnau
Join Date: Feb 2017
Location: Spain
Posts: 57
Rep Power: 9
rarnaunot is on a distinguished road
My code is something like:

Code:
        fvScalarMatrix STransfer
                (
                    K*S2Sat - fvm::Sp(K,S2)  
                );

        STransfer.solve();
 
        fvScalarMatrix S2Eqn
        (
            fvm::ddt(alpha2, S2)
          + fvm::div(alphaPhi2, S2)

           ==
            STransfer
          );
        S2Eqn.solve();


        fvScalarMatrix S1Eqn
        (
            fvm::ddt(alpha1, S1)
          + fvm::div(alphaPhi1, S1)
        ==
         -STransfer
        );

        S1Eqn.solve();
The problem is at S1Eqn as the dependent variable is S1 in the left side of == and S2 in the right-hand side ==.

That's one of the problems and probably I would face more after solving this one...

Thanks in advance,

PD: Do not hesitate to sent my a private message.
rarnaunot is offline   Reply With Quote

Old   April 3, 2020, 16:26
Default
  #12
Senior Member
 
Zeppo's Avatar
 
Sergei
Join Date: Dec 2009
Posts: 261
Rep Power: 22
Zeppo will become famous soon enough
You may want to use S2 field for which S2Eqn equation has been solved for
Code:
        fvScalarMatrix S1Eqn
        (
            fvm::ddt(alpha1, S1)
          + fvm::div(alphaPhi1, S1)
        ==
         -(K*S2Sat - K*S2)
        );

        S1Eqn.solve();
rarnaunot and lpz456 like this.
Zeppo is offline   Reply With Quote

Old   April 4, 2020, 05:15
Default
  #13
Senior Member
 
Agustín Villa
Join Date: Apr 2013
Location: Alcorcón
Posts: 314
Rep Power: 15
agustinvo is on a distinguished road
Indeed, this is what it was planned to add.
rarnaunot likes this.
agustinvo is offline   Reply With Quote

Old   April 6, 2020, 13:11
Default
  #14
Member
 
Rosario Arnau
Join Date: Feb 2017
Location: Spain
Posts: 57
Rep Power: 9
rarnaunot is on a distinguished road
Thanks for your help Zeppo and agustinvo.

I have compiled that code and I'm trying it at a simple case.
lpz456 likes this.
rarnaunot is offline   Reply With Quote

Reply

Tags
openfoam, programing


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
Tool to convert OpenFoam mesh to SU2 mesh (2D and 3D) Combas SU2 45 October 16, 2024 18:26
[snappyHexMesh] Convert stl files and multi region abrunet OpenFOAM Meshing & Mesh Conversion 1 July 1, 2014 11:15
convert a structured multiblock grid to an one unstructured: modification of cells Mirage ANSYS 0 July 18, 2012 10:14
ImageMagick will not convert jpg to mpg musahossein Main CFD Forum 1 December 2, 2011 11:44


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