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

creating a new field by volume averaging of an existing field and reuse it in Solver

Register Blogs Community New Posts Updated Threads Search

Like Tree1Likes

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   November 7, 2018, 14:03
Default
  #21
Senior Member
 
Join Date: Aug 2015
Posts: 494
Rep Power: 14
clapointe is on a distinguished road
Did you recompile when you added the info lines? Your alfAvg is not updating bc you have competing things -- one volScalarField (declared in createFields.H) that is not getting updated. Then the scalar alfAvg at the end of the PIMPLE loop. I'm surprised this even compiled -- oh, I see that they're slightly different in name. So, to be clear, you should have alfAvg and Tsol computed before using in Teqn.H to be safe and sure that they're updated. Thus :

Code:
scalar alfAvg = gSum(alpha*mesh.V())/(mesh.V().size())
dimensionedScalar Tsol("Tsol", dimTemperature, 0.5*(Ts+Tl)*pow(alfAvg,10));

//see alfAvg

Info << "\nalfAvg : " << alfAvg << nl << endl;

//see Tsol

Info << "\nTsol : " << Tsol << nl << endl;

fvScalarMatrix TEqn
    (
        fvm::ddt(cp, T)
      + fvm::div(phi*fvc::interpolate(cp), T)
      + hs*4.0*exp(-pow(4.0*(T-Tsol)/(Tl-Ts),2))/Foam::sqrt(pi)/(Tl-Ts)*fvm::ddt(T)
      + hs*4.0*exp(-pow(4.0*(T-Tsol)/(Tl-Ts),2))/Foam::sqrt(pi)/(Tl-Ts)*(U & fvc::grad(T))
      - fvm::laplacian(lambda/rho, T)
    );

    TEqn.relax();
    TEqn.solve();
I also thought about the volume-scaled averaging and this might be better :

Code:
scalar alfAvg = gSum(alpha*mesh.V())/mesh.nCells()
Also make sure that alpha is actually changing in time -- if not, there's no reason that it's average will change in time either.

Caelan
clapointe is offline   Reply With Quote

Old   November 7, 2018, 14:26
Default
  #22
New Member
 
Koby Baziani
Join Date: Jul 2018
Location: Canada
Posts: 26
Rep Power: 7
Gbaz is on a distinguished road
with this gSum, I get this compiling error:

Code:
pimpleFoam.C:91:37: error: no matching function for call to 'gSum(Foam::tmp<Foam::DimensionedField<double, Foam::volMesh>                          >)'
  scalar alfAvg = gSum(alpha*mesh.V())/mesh.nCells()
                                     ^
In file included from C:/PROGRA~1/BLUECF~1/OpenFOAM-5.x/src/OpenFOAM/fields/Fields/Field/Field.T.C:877:0,


alpha is changing correctly with time.
Gbaz is offline   Reply With Quote

Old   November 7, 2018, 14:31
Default
  #23
Senior Member
 
Join Date: Aug 2015
Posts: 494
Rep Power: 14
clapointe is on a distinguished road
How do you create alpha? That will affect how we reference/use it.

Caelan
clapointe is offline   Reply With Quote

Old   November 7, 2018, 14:37
Default
  #24
New Member
 
Koby Baziani
Join Date: Jul 2018
Location: Canada
Posts: 26
Rep Power: 7
Gbaz is on a distinguished road
alpha is defined in TEqn as this (last line):

Code:
    fvScalarMatrix TEqn

    (
        fvm::ddt(cp, T)
      + fvm::div(phi*fvc::interpolate(cp), T)
      + hs*4.0*exp(-pow(4.0*(T-Tsol)/(Tl-Ts),2))/Foam::sqrt(pi)/(Tl-Ts)*fvm::ddt(T)
      + hs*4.0*exp(-pow(4.0*(T-Tsol)/(Tl-Ts),2))/Foam::sqrt(pi)/(Tl-Ts)*(U & fvc::grad(T))
      - fvm::laplacian(lambda/rho, T)
    );

    TEqn.relax();
    TEqn.solve();

    

    alpha = 0.5*Foam::erf(4.0*(T-Tsol)/(Tl-Ts))+scalar(0.5);
Gbaz is offline   Reply With Quote

Old   November 7, 2018, 14:50
Default
  #25
Senior Member
 
Join Date: Aug 2015
Posts: 494
Rep Power: 14
clapointe is on a distinguished road
Is it a volScalarField? I've got another idea -- lets try using an OF function :

Code:
scalar alfAvg = (fvc::domainIntegrate(alpha)/mesh.nCells()).value()
See eg : https://github.com/OpenFOAM/OpenFOAM...ntinuityErrs.H.

Caelan
clapointe is offline   Reply With Quote

Old   November 7, 2018, 14:57
Default
  #26
New Member
 
Koby Baziani
Join Date: Jul 2018
Location: Canada
Posts: 26
Rep Power: 7
Gbaz is on a distinguished road
yes it is a volScalarField.

with the new averageing I get this compilation error:

Code:
pimpleFoam.C:92:59: error: cannot convert 'Foam::dimensioned<double>' to 'Foam::scalar {aka double}' in initialization
   scalar alfAvg = fvc::domainIntegrate(alpha)/mesh.nCells()
                                                           ^
pimpleFoam.C:92:10: warning: unused variable 'alfAvg' [-Wunused-variable]
   scalar alfAvg = fvc::domainIntegrate(alpha)/mesh.nCells()
Gbaz is offline   Reply With Quote

Old   November 7, 2018, 15:09
Default
  #27
New Member
 
Koby Baziani
Join Date: Jul 2018
Location: Canada
Posts: 26
Rep Power: 7
Gbaz is on a distinguished road
sorry for my mistake. I applied alfAvg definition wrongly. Now it's running. will post you the update soon.
Gbaz is offline   Reply With Quote

Old   November 7, 2018, 15:09
Default
  #28
Senior Member
 
Join Date: Aug 2015
Posts: 494
Rep Power: 14
clapointe is on a distinguished road
Oh I see -- it looks to be complaining about

Code:
mesh.nCells()
.

Looks like it actually is a label instead of a scalar. Oops.

Realizing that you've already defined alpha as a volScalarField :

Code:
scalar alfAvg = fvc::domainIntegratte(alpha).value()/alpha.size()
should do the trick. This compiled for me. I also put the .value() in the wrong place previously -- sorry!

Caelan
clapointe is offline   Reply With Quote

Old   November 7, 2018, 15:39
Default
  #29
New Member
 
Koby Baziani
Join Date: Jul 2018
Location: Canada
Posts: 26
Rep Power: 7
Gbaz is on a distinguished road
I think it's going to start.

for initial file of Tsol what do you suggest?

Code:
cannot find file "C:/PROGRA~1/BLUECF~1/ofuser-of5/run/solidif/0/Tsol"
do I need something like T ?

cheers
Gbaz is offline   Reply With Quote

Old   November 7, 2018, 15:55
Default
  #30
Senior Member
 
Join Date: Aug 2015
Posts: 494
Rep Power: 14
clapointe is on a distinguished road
If you use Tsol as a dimensionedScalar you should not need it in createFields (defined as a volScalarField that must be read). If it is a volScalarField like alpha then you can just use something like :

Code:
volScalarField Tsol
(
    IOobject
    (
        "Tsol",
        runTime.timeName(),
        mesh,
        IOobject::NO_READ,
        IOobject::AUTO_WRITE
    ),
    thermo.T()
);
The "NO_READ" will make sure the solver doesn't look for Tsol in the 0 folder. Of course, you could also do as you suggested and make a file like T (in the 0 folder named Tsol).

Caelan
clapointe is offline   Reply With Quote

Old   November 9, 2018, 16:41
Default
  #31
New Member
 
Koby Baziani
Join Date: Jul 2018
Location: Canada
Posts: 26
Rep Power: 7
Gbaz is on a distinguished road
Daer Caelan,

None of the above definitions for alfAvg give me the corrsct Volume Avarged alpha.

Code:
scalar alfAvg = fvc::domainIntegratte(alpha).value()/alpha.size()scalar 

alfAvg = (fvc::domainIntegrate(alpha)/mesh.nCells()).value()

alfAvg = gSum(alpha*mesh.V())/mesh.nCells()

Basically iit should be as alfAvg=int(alpha, dV)/V
could you please check and confirm?
Gbaz is offline   Reply With Quote

Old   November 9, 2018, 18:27
Default
  #32
Senior Member
 
Join Date: Aug 2015
Posts: 494
Rep Power: 14
clapointe is on a distinguished road
I'm not sure why it's not working, but if you know the correct value -- how are you calculating it? How do you know that the calculated value is wrong?

Caelan
clapointe is offline   Reply With Quote

Old   November 10, 2018, 00:43
Default
  #33
New Member
 
Koby Baziani
Join Date: Jul 2018
Location: Canada
Posts: 26
Rep Power: 7
Gbaz is on a distinguished road
Here, based on domain integrate, the calculated value is close to zero (1e-9).
but using volFieldValue as a functionObject, the obtained alfAvg was accurate (varying smoothly from 1 to 0.8). This is my understanding based on the physics of the problem.

by the way
Code:
alfAvg = gSum(alpha*mesh.V())/mesh.nCells()
can't be compiled and getting this error:

Code:
solidFoam.C:93:41: error: no matching function for call to 'gSum(Foam::tmp                                                                        <Foam::DimensionedField<double, Foam::volMesh> >)'
   scalar alfAvg   = gSum (alpha*mesh.V())/mesh.nCells();
                                         ^
did I write something wrong?
Gbaz is offline   Reply With Quote

Old   November 10, 2018, 11:41
Default
  #34
Senior Member
 
Join Date: Aug 2015
Posts: 494
Rep Power: 14
clapointe is on a distinguished road
A few basic questions, then. Have you inspected alpha visually (eg in paraview)? Does it match what you compute with the function object? I don't know offhand why you're getting the error -- I've used gsum before without error. It looks like the error you provided has been cut off. Have you inspected the function object code? What happens there?

Caelan
clapointe is offline   Reply With Quote

Old   November 11, 2018, 10:39
Default
  #35
New Member
 
Koby Baziani
Join Date: Jul 2018
Location: Canada
Posts: 26
Rep Power: 7
Gbaz is on a distinguished road
Yes Actually I use parafoam to visualize the results.

when alpha is correct, (keeping all parameters controlled), the above formula doesn't give me the correct average value for alpha. It always shows very small numbers,(e.g. 1e-9). I'm thinking the above formula of " scalar alfAvg =...." does not show the correct volume-averaged of alpha.
.
Gbaz is offline   Reply With Quote

Old   November 11, 2018, 13:56
Default
  #36
Senior Member
 
Join Date: Aug 2015
Posts: 494
Rep Power: 14
clapointe is on a distinguished road
Alright -- not sure why domainIntegrate wasn't working for you, but I think I found another solution. I replicated the error you got related to compilation of

Code:
gSum(alpha*mesh.V()
So, I looked into a way to get cellVolumes differently and found

Code:
mesh.cellVolumes()
.

So lets try

Code:
scalar alfAvg = gSum(alpha*mesh.cellVolumes())/alpha.size()
Comparable code compiled for me.

Caelan
clapointe is offline   Reply With Quote

Old   November 12, 2018, 07:03
Default
  #37
New Member
 
Koby Baziani
Join Date: Jul 2018
Location: Canada
Posts: 26
Rep Power: 7
Gbaz is on a distinguished road
It was fixed this way:

Code:
scalar alfInt   = fvc::domainIntegrate(alpha).value()
scalar vol      = gSum (mesh.V())
scalar alfAvg = alfInt/vol
now results make sense.

Thanks a lot Caelan for your support.
Without your help, this part of the work could take a couple of months longer.
Gbaz is offline   Reply With Quote

Old   November 12, 2018, 13:22
Default
  #38
Senior Member
 
Join Date: Aug 2015
Posts: 494
Rep Power: 14
clapointe is on a distinguished road
Guess there are many ways to Rome -- glad you figured out another solution.

Caelan
clapointe 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



All times are GMT -4. The time now is 23:03.