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

writing a snippet for monitoring and saving components of a transport equation

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

Like Tree2Likes
  • 1 Post By babakflame
  • 1 Post By arvindpj

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   December 19, 2016, 16:35
Default writing a snippet for monitoring and saving components of a transport equation
  #1
Senior Member
 
Bobby
Join Date: Oct 2012
Location: Michigan
Posts: 454
Rep Power: 15
babakflame is on a distinguished road
Dear Fellows

I have a transport equation in my solver as:


Code:
 surfaceScalarField rhoEFlux = -fvc::interpolate(sgm)*mesh.magSf()*fvc::snGrad(Ue);
            fvScalarMatrix rhoEEqn
            (
                fvm::ddt(rhoE)
              + fvm::div(phi, rhoE)
              + fvc::div(rhoEFlux)
           - fvm::laplacian(kappa, rhoE)    
            );
            rhoEEqn.solve();
Here, "kappa" is the diffusion constant and "rhoE" is the charge density. I want to write a snippet for calculating and saving each term of above transport equation, separately. I am thinking of the following:

These line are added to createFields.H:

Code:
   volScalarField timeDerivative
    ( 
     IOobject
        (
            "timeDerivative",
             runTime.timeName(),
             mesh,
             IOobject::NO_READ,
             IOobject::AUTO_WRITE
         ),
        fvm::ddt(rhoE)
     );

     volScalarField Convective
    ( 
     IOobject
        (
            "Convective",
             runTime.timeName(),
             mesh,
             IOobject::NO_READ,
             IOobject::AUTO_WRITE
         ),
         fvm::div(phi, rhoE)
     );

    

    volScalarField Conductive
    ( 
     IOobject
        (
            "Conductive",
             runTime.timeName(),
             mesh,
             IOobject::NO_READ,
             IOobject::AUTO_WRITE
         ),
         -fvc::div(rhoEFlux)
     );

     volScalarField Diffusive
    ( 
     IOobject
        (
            "Diffusive",
             runTime.timeName(),
             mesh,
             IOobject::NO_READ,
             IOobject::AUTO_WRITE
         ),
         fvm::laplacian(kappa, rhoE)
     );
and the following lines are added to ElectricEqn.H file which includes the charge transport equation as well:


Code:
         timeDerivative = fvm::ddt(rhoE);


         Convective = fvm::div(phi, rhoE);
    
          Diffusive  = fvm::laplacian(kappa, rhoE);

         Conductive = -fvc::div(rhoEFlux);
However, compiling the code brings the following error: Even, by just keeping one of the new defined variables (timeDerivative, conductive, Convective and Diffusive) still the same error pops up:

Code:
/home/babak/OpenFOAM/OpenFOAM-2.1.x/src/OpenFOAM/lnInclude/GeometricField.C:1108:6: note:   no known conversion for argument 1 from ‘Foam::tmp<Foam::fvMatrix<double> >’ to ‘const Foam::tmp<Foam::GeometricField<double, Foam::fvPatchField, Foam::volMesh> >&’
/home/babak/OpenFOAM/OpenFOAM-2.1.x/src/OpenFOAM/lnInclude/GeometricField.C:1144:6: note: void Foam::GeometricField<Type, PatchField, GeoMesh>::operator=(const Foam::dimensioned<Type>&) [with Type = double; PatchField = Foam::fvPatchField; GeoMesh = Foam::volMesh]
/home/babak/OpenFOAM/OpenFOAM-2.1.x/src/OpenFOAM/lnInclude/GeometricField.C:1144:6: note:   no known conversion for argument 1 from ‘Foam::tmp<Foam::fvMatrix<double> >’ to ‘const Foam::dimensioned<double>&’
In file included from interFoamEHDFullChannelScrape.C:79:0:
/home/babak/OpenFOAM/OpenFOAM-2.1.x/src/finiteVolume/lnInclude/readTimeControls.H:38:8: warning: unused variable ‘maxDeltaT’ [-Wunused-variable]
make: *** [Make/linux64GccDPOpt/interFoamEHDFullChannelScrape.o] Error 1
Would some body hint me how to fix this?

Regards
babakflame is offline   Reply With Quote

Old   December 19, 2016, 16:48
Default
  #2
Member
 
Arvind Jay
Join Date: Sep 2012
Posts: 96
Rep Power: 14
arvindpj is on a distinguished road
I have seen a similar error before.

Try using XXX.ref options to access the internal fields without the boundary patches. or the .value option. I may be completely wrong.

Cheers
arvindpj is offline   Reply With Quote

Old   December 19, 2016, 16:51
Default
  #3
Senior Member
 
Bobby
Join Date: Oct 2012
Location: Michigan
Posts: 454
Rep Power: 15
babakflame is on a distinguished road
Dear Arvind

Thanks for your reply

I want to avoid writing for internal fields, since it needs a lot of extra lines.

About .value(), I thought of that, but these fields are volScalarFields, isn't it?

AFA I know, .value() is for scalars not volScalarFields. Here, I just want to save and track a volScalarField which is used in the transport equation.

Regards
babakflame is offline   Reply With Quote

Old   December 19, 2016, 17:25
Default
  #4
Senior Member
 
Bobby
Join Date: Oct 2012
Location: Michigan
Posts: 454
Rep Power: 15
babakflame is on a distinguished road
I think my problem is due to defining terms implicitly in transport equation:

Code:
fvScalarMatrix rhoEEqn
            (
                fvm::ddt(rhoE)
              + fvm::div(phi, rhoE)
              + fvc::div(rhoEFlux)
           - fvm::laplacian(kappa, rhoE)    
            );
            rhoEEqn.solve();
If you want each term separately, you need to use fvc:: instead of fvm::


Since fvm:: is actually the implicit method and since the matrix of coeffiecients in the transport equation is coupled, you can not extract any term from it.

However, you can easily reproduce and track each term of your transport equation separately, by simply using fvc:: which reprodues that term explicitly.

Hope, these lines helped people with the same problem. Above snippet is correct, However, you need to replace fvm:: with fvc:: when defining volScalarFields in createFields.H file and updating variable at suitabe file inside the main section of code (My solver in electricEqn.H)



Keep Foaming Fellows
arvindpj likes this.

Last edited by babakflame; December 19, 2016 at 19:29.
babakflame is offline   Reply With Quote

Old   December 20, 2016, 10:35
Default Converting from one class to another
  #5
Member
 
Arvind Jay
Join Date: Sep 2012
Posts: 96
Rep Power: 14
arvindpj is on a distinguished road
Note to myself:

Here is a brief description on some major data classes in OF (Ref):
  • dimensionedScalar : number, associated with a dimension. OpenFOAM checks dimension consistency and reports possible dimension errors.
  • volScalarField : scalar defined at the center of each cell. It also includes its dimension (defined for example during the initiation of quantities), and its boundary conditions.
  • volVectorField : Vector defined at the center of each cell, including its dimension and its boundary conditions
  • surfaceScalarField : Scalar defined at the center of each faces, including its dimension and its boundary conditions

    One can go from one class to the other with the operator interpolate (average at the faces of the centered values), reconstruct (average at the center from the faces values) and the inner product with the normal to the face times the surface of the face & mesh.Sf() (to compute fluxes)
Attached Images
File Type: jpg class conversion.jpg (47.9 KB, 9 views)
babakflame likes this.
arvindpj is offline   Reply With Quote

Reply

Thread Tools Search this Thread
Search this Thread:

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
[OpenFOAM.org] Compile OF 2.3 on Mac OS X .... the patch gschaider OpenFOAM Installation 225 August 25, 2015 19:43


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