|
[Sponsors] |
How to include cell volumes in calculation of volScalarField? |
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
April 9, 2014, 09:55 |
How to include cell volumes in calculation of volScalarField?
|
#1 |
Member
Pekka Pasanen
Join Date: Feb 2012
Location: Finland
Posts: 87
Rep Power: 14 |
Hi, I'm currently programming a RAS version of kOmegaSSTSAS turbulence model and I ran into a problem when the cell volumes are needed in calculation. Cell volumes are needed in the calculation of high frequency eddy viscosity limiter Lvk2.
The LES model from current OpenFOAM-2.3.x has this: Code:
tmp<volScalarField> kOmegaSSTSAS::Lvk2 ( const volScalarField& S2 ) const { return max ( kappa_*sqrt(S2) /( mag(fvc::laplacian(U())) + dimensionedScalar ( "ROOTVSMALL", dimensionSet(0, -1 , -1, 0, 0, 0, 0), ROOTVSMALL ) ), Cs_*delta() ); } Code:
tmp<volScalarField> mykOmegaSSTSAS::Lvk ( const volScalarField& S2, const volScalarField& F1 ) const { return max ( kappa_*sqrt(S2) /( mag(fvc::laplacian(U_)) + dimensionedScalar ( "ROOTVSMALL", dimensionSet(0, -1 , -1, 0, 0, 0, 0), ROOTVSMALL ) ), Cs_*sqrt((kappa_*zeta2_)/((beta(F1)/Cmu_)-gamma(F1)))*pow(mesh_.V(),(1.0/3.0)) ); } This is the error message: Code:
mykOmegaSSTSAS/mykOmegaSSTSAS.C:89:12: error: no matching function for call to 'max' return max ^~~ /home/zordiack/OpenFOAM/OpenFOAM-2.3.x/src/OpenFOAM/lnInclude/label.H:295:1: note: candidate function not viable: no known conversion from 'tmp<GeometricField<scalar, fvPatchField, Foam::volMesh> >' to 'const char' for 1st argument MAXMIN(char, char, char) ^ /home/zordiack/OpenFOAM/OpenFOAM-2.3.x/src/OpenFOAM/lnInclude/label.H:284:16: note: expanded from macro 'MAXMIN' inline retType max(const type1 s1, const type2 s2) \ ^ |
|
April 9, 2014, 15:28 |
|
#2 |
Senior Member
Tomislav Maric
Join Date: Mar 2009
Location: Darmstadt, Germany
Posts: 284
Blog Entries: 5
Rep Power: 21 |
The relationship between the GeometricField and the DimensionedField is a clear cut example of why inheriting for implementation does not work.
On one hand side, there is a public inheritance from DimensionedField: Code:
template<class Type, template<class> class PatchField, class GeoMesh> class GeometricField : public DimensionedField<Type, GeoMesh> { Code:
// Member operators void operator=(const GeometricField<Type, PatchField, GeoMesh>&); void operator=(const tmp<GeometricField<Type, PatchField, GeoMesh> >&); void operator=(const dimensioned<Type>&); void operator==(const tmp<GeometricField<Type, PatchField, GeoMesh> >&); void operator==(const dimensioned<Type>&); So if someone would code: Code:
dimensionedScalarField p_1; volScalarField p2 = p_1; Code:
//- Return dimensioned internal field DimensionedInternalField& dimensionedInternalField();
Cs_*sqrt((kappa_*zeta2_)/((beta(F1)/Cmu_)-gamma(F1)))*pow(mesh_.V(),(1.0/3.0)) will make it very difficult for anyone trying to maintain your code to debug it and extend it. Also, if you are working with temporary objects, take a look at how they are used in the code, you can see how the interpolation/convection/diffusion schemes work, how they first initialize the temporary, operate on it, then return it. Make the code humanly readable, you will be grateful for it after enough time passes and you forget what you did - and so will all your users. Here is a working example with that what is available in the GeometricField, off the top of my head. I am not sure if you can copy-paste-use that directly, but it is a start: Code:
#include "fvCFD.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // Main program: tmp<volScalarField> Lvk( const volScalarField& S2, const volScalarField& F1 ) { const Time& runTime = S2.time(); const fvMesh& mesh = S2.mesh(); // Initialize the temporary object that is to be returned. tmp<volScalarField> resultTmp ( new volScalarField ( IOobject ( "Lvk", runTime.timeName(), mesh, IOobject::NO_READ, IOobject::NO_WRITE ), mesh, dimensionedScalar ( "zero", S2.dimensions(), // Judging by your max() call, you are returning S2 dimensions 0 ) ) ); // Get the non-const reference to the temporary object. volScalarField& result = resultTmp(); // Keep dimensions of the result but re-name the field. volScalarField h ("h", result); // Get the non-const ref to the internal field which is of dimensioned field type. DimensionedField<scalar, volMesh>& hInternal = h.dimensionedInternalField(); // Set the internal field values. hInternal = pow(mesh.V(), 1.0 / 3.0); // Calculate the result. // FIXME: separate your huge return call into separate clearly readable calculations and put // them here. result = Foam::max(S2, h); return resultTmp; } int main(int argc, char *argv[]) { #include "setRootCase.H" #include "createTime.H" #include "createMesh.H" volScalarField S2 ( IOobject ( "S2", runTime.timeName(), mesh, IOobject::MUST_READ, IOobject::AUTO_WRITE ), mesh ); volScalarField F1 ( IOobject ( "F1", runTime.timeName(), mesh, IOobject::MUST_READ, IOobject::AUTO_WRITE ), mesh ); tmp<volScalarField> result = Lvk(S2, F1); // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // Info<< "\nEnd\n" << endl; return 0; } |
|
April 10, 2014, 01:36 |
|
#3 |
Member
Pekka Pasanen
Join Date: Feb 2012
Location: Finland
Posts: 87
Rep Power: 14 |
Wow, thank you so much for the detailed explanation and example. As my coding skill level is currently mostly "copy-paste", this kind of information is really helpful and I might actually learn something by doing this.
I will try to implement this as soon as possible and I'll split my calculation into smaller pieces, I promise |
|
April 11, 2014, 06:57 |
|
#5 |
Member
Pekka Pasanen
Join Date: Feb 2012
Location: Finland
Posts: 87
Rep Power: 14 |
The solver compiled and it runs! Thanks again for the advice Now I have to test that it gives reasonable and physically sound results.
|
|
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Questions on dynamicTopoFvMesh | danvica | OpenFOAM Running, Solving & CFD | 80 | April 16, 2019 17:58 |
interFoam running blowing up | sandy13 | OpenFOAM Running, Solving & CFD | 2 | May 5, 2015 08:16 |
volScalarField for cell volumes and face surfaces | AlmostSurelyRob | OpenFOAM | 2 | December 13, 2010 06:24 |
OpenFOAM15 paraFoam bug | koen | OpenFOAM Bugs | 19 | June 30, 2009 11:46 |
Error #285UNSUPPORTED CELL TYPE IN CALCULATION OF | Nahidh Hamid Sharif | Siemens | 0 | September 19, 2007 03:00 |