CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Programming & Development (https://www.cfd-online.com/Forums/openfoam-programming-development/)
-   -   creating a new field by volume averaging of an existing field and reuse it in Solver (https://www.cfd-online.com/Forums/openfoam-programming-development/210796-creating-new-field-volume-averaging-existing-field-reuse-solver.html)

clapointe November 7, 2018 14:03

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

Gbaz November 7, 2018 14:26

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.

clapointe November 7, 2018 14:31

How do you create alpha? That will affect how we reference/use it.

Caelan

Gbaz November 7, 2018 14:37

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);


clapointe November 7, 2018 14:50

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

Gbaz November 7, 2018 14:57

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 November 7, 2018 15:09

sorry for my mistake. I applied alfAvg definition wrongly. Now it's running. will post you the update soon.

clapointe November 7, 2018 15:09

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

Gbaz November 7, 2018 15:39

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

clapointe November 7, 2018 15:55

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

Gbaz November 9, 2018 16:41

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?

clapointe November 9, 2018 18:27

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

Gbaz November 10, 2018 00:43

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?

clapointe November 10, 2018 11:41

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

Gbaz November 11, 2018 10:39

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.
.

clapointe November 11, 2018 13:56

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

Gbaz November 12, 2018 07:03

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.

clapointe November 12, 2018 13:22

Guess there are many ways to Rome -- glad you figured out another solution.

Caelan


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