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

operate on volScalarField as a whole

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   March 26, 2022, 00:23
Post operate on volScalarField as a whole
  #1
New Member
 
becher
Join Date: Dec 2018
Posts: 4
Rep Power: 7
becher97 is on a distinguished road
hello,
I am trying to add a scalar transport equation to multiPhaseInterFoam.The diffusion coefficient Ds is defined as a volScalarField cause it should be weighted based on the value of the fraction of phases in each cell.

i.e. Ds = D1*alpha1+D2*alpha2+D3*alpha3...

Following code was used to achieve that, ScalarList Dlist stores diffusivity D for each phase.
Code:
        forAll(Ds, celli)
        {
            Ds[celli] = scalar(0);
            int im = 0;
            for (volScalarField alpha : mixture.phases())
            {
               Ds[celli] += Dlist[im] * alpha[celli];
               im +=1;
            }  
        }
Result shows the code works as expected. However, it takes long time to traverse every cells, the compute time increased about four times compared to a constant Ds.

So I wonder if I can operate the volScalarField as a whole to save time, following code was used.
Code:
        Ds = volScalarField<0>;
        int im = 0;
        for (volScalarField alpha : mixture.phases())
        {
               dimensionedScalar a = (dimensionSet(0,2,-1,0,0,0,0),Dlist[im]);
               Ds += a * alpha;
               im += 1;
        }
The code could be compiled without any error. But when run case, follow error message was shown.

Code:
--> FOAM FATAL ERROR: (openfoam-2106)
tmp<N4Foam14GeometricFieldIdNS_12fvPatchFieldENS_7volMeshEEE> deallocated

    From const T& Foam::tmp<T>::cref() const [with T = Foam::GeometricField<double, Foam::fvPatchField, Foam::volMesh>]
    in file /home/beck/OpenFOAM/OpenFOAM-v2106/src/OpenFOAM/lnInclude/tmpI.H at line 217.

FOAM aborting

#0  Foam::error::printStack(Foam::Ostream&) at ??:?
#1  Foam::error::exitOrAbort(int, bool) at ??:?
#2  Foam::GeometricField<double, Foam::fvPatchField, Foam::volMesh>::GeometricField(Foam::tmp<Foam::GeometricField<double, Foam::fvPatchField, Foam::volMesh> > const&) in ~/OpenFOAM/beck-v2106/platforms/linux64GccDPInt32Opt/bin/ladleFoam
#3  ? in ~/OpenFOAM/beck-v2106/platforms/linux64GccDPInt32Opt/bin/ladleFoam
#4  __libc_start_main in /lib/x86_64-linux-gnu/libc.so.6
#5  ? in ~/OpenFOAM/beck-v2106/platforms/linux64GccDPInt32Opt/bin/ladleFoam
I can't figure out what's wrong in the error message.
Sorry for my bad English and programing skills. Any advice on where I'm going wrong is appreciated.
Thanks
becher97 is offline   Reply With Quote

Reply

Tags
multiphaseinterfoam, scalar transport, volscalarfield


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
Error message Bruno_Jorge Main CFD Forum 1 February 5, 2019 12:12
namespace Foam Argen OpenFOAM 4 February 5, 2019 09:55
execFlowFunctionObjects - unknown field problem Toorop OpenFOAM Post-Processing 16 March 14, 2016 04:25
writing execFlowFunctionObjects immortality OpenFOAM Post-Processing 30 September 15, 2013 07:16
Operate on volScalarField as whole v access elements adhiraj OpenFOAM 2 November 29, 2012 13:35


All times are GMT -4. The time now is 16:24.