|
[Sponsors] |
creating a new field by volume averaging of an existing field and reuse it in Solver |
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
November 7, 2018, 14:03 |
|
#21 |
Senior Member
Join Date: Aug 2015
Posts: 494
Rep Power: 14 |
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(); Code:
scalar alfAvg = gSum(alpha*mesh.V())/mesh.nCells() Caelan |
|
November 7, 2018, 14:26 |
|
#22 |
New Member
Koby Baziani
Join Date: Jul 2018
Location: Canada
Posts: 26
Rep Power: 7 |
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. |
|
November 7, 2018, 14:31 |
|
#23 |
Senior Member
Join Date: Aug 2015
Posts: 494
Rep Power: 14 |
How do you create alpha? That will affect how we reference/use it.
Caelan |
|
November 7, 2018, 14:37 |
|
#24 |
New Member
Koby Baziani
Join Date: Jul 2018
Location: Canada
Posts: 26
Rep Power: 7 |
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); |
|
November 7, 2018, 14:50 |
|
#25 |
Senior Member
Join Date: Aug 2015
Posts: 494
Rep Power: 14 |
Is it a volScalarField? I've got another idea -- lets try using an OF function :
Code:
scalar alfAvg = (fvc::domainIntegrate(alpha)/mesh.nCells()).value() Caelan |
|
November 7, 2018, 14:57 |
|
#26 |
New Member
Koby Baziani
Join Date: Jul 2018
Location: Canada
Posts: 26
Rep Power: 7 |
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() |
|
November 7, 2018, 15:09 |
|
#27 |
New Member
Koby Baziani
Join Date: Jul 2018
Location: Canada
Posts: 26
Rep Power: 7 |
sorry for my mistake. I applied alfAvg definition wrongly. Now it's running. will post you the update soon.
|
|
November 7, 2018, 15:09 |
|
#28 |
Senior Member
Join Date: Aug 2015
Posts: 494
Rep Power: 14 |
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() Caelan |
|
November 7, 2018, 15:39 |
|
#29 |
New Member
Koby Baziani
Join Date: Jul 2018
Location: Canada
Posts: 26
Rep Power: 7 |
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" cheers |
|
November 7, 2018, 15:55 |
|
#30 |
Senior Member
Join Date: Aug 2015
Posts: 494
Rep Power: 14 |
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() ); Caelan |
|
November 9, 2018, 16:41 |
|
#31 |
New Member
Koby Baziani
Join Date: Jul 2018
Location: Canada
Posts: 26
Rep Power: 7 |
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? |
|
November 9, 2018, 18:27 |
|
#32 |
Senior Member
Join Date: Aug 2015
Posts: 494
Rep Power: 14 |
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 |
|
November 10, 2018, 00:43 |
|
#33 |
New Member
Koby Baziani
Join Date: Jul 2018
Location: Canada
Posts: 26
Rep Power: 7 |
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() 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(); ^ |
|
November 10, 2018, 11:41 |
|
#34 |
Senior Member
Join Date: Aug 2015
Posts: 494
Rep Power: 14 |
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 |
|
November 11, 2018, 10:39 |
|
#35 |
New Member
Koby Baziani
Join Date: Jul 2018
Location: Canada
Posts: 26
Rep Power: 7 |
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. . |
|
November 11, 2018, 13:56 |
|
#36 |
Senior Member
Join Date: Aug 2015
Posts: 494
Rep Power: 14 |
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() Code:
mesh.cellVolumes() So lets try Code:
scalar alfAvg = gSum(alpha*mesh.cellVolumes())/alpha.size() Caelan |
|
November 12, 2018, 07:03 |
|
#37 |
New Member
Koby Baziani
Join Date: Jul 2018
Location: Canada
Posts: 26
Rep Power: 7 |
It was fixed this way:
Code:
scalar alfInt = fvc::domainIntegrate(alpha).value() scalar vol = gSum (mesh.V()) scalar alfAvg = alfInt/vol Thanks a lot Caelan for your support. Without your help, this part of the work could take a couple of months longer. |
|
November 12, 2018, 13:22 |
|
#38 |
Senior Member
Join Date: Aug 2015
Posts: 494
Rep Power: 14 |
Guess there are many ways to Rome -- glad you figured out another solution.
Caelan |
|
|
|