View Issue Details

IDProjectCategoryView StatusLast Update
0003875OpenFOAMBugpublic2022-08-19 22:10
Reportertniemi Assigned Tohenry  
PrioritynormalSeverityminorReproducibilityalways
Status resolvedResolutionfixed 
Product Versiondev 
Fixed in Versiondev 
Summary0003875: Possible bug in some of the individual fvModel source functions?
DescriptionA while ago a new feature was added which allows to evaluate individual fvModels (fvOptions back then)
https://github.com/OpenFOAM/OpenFOAM-dev/commit/bd6c02167b1cd955d962d8b673d6cc851740dc8c

I was now trying to use this feature and evaluate individual fvModels using their source(...)-functions. However, for some reason the functions which accept rho or alpha appear to simply drop these parameters when calling the source template function resulting to wrong addSup call.
(functions from line 105 downwards in https://github.com/OpenFOAM/OpenFOAM-dev/blob/master/src/finiteVolume/cfdTools/general/fvModels/fvModelTemplates.C)

Is this a bug, or am I just misunderstanding something? If a bug, the source functions should be similar to those in fvModelsTemplates, which correctly passes alpha&rho.
TagsNo tags attached.

Activities

henry

2022-08-19 10:08

manager   ~0012712

It is not clear what the problem is, can you reproduce it in one of the tutorials?

tniemi

2022-08-19 10:57

reporter   ~0012713

I'm not sure if this feature is currently being used anywhere, but I have attached a very artificial example case based on the cavity tutorial (untar+blockMesh+foamRun).

I have defined two coded fvModels, where the second one tries to print the maximum value of the source-term produced by the first one. However, fvModels["s1"].source(rho, eqn.psi()) does not call codeAddRhoSup and instead calls codeAddSup which contains NotImplemented. Same would happen with source(alpha, rho, field) -call

My real use case is a custom functionObject which would need to evaluate the sources produced by fvModels separately for each source. These sources need rho and alpha fields to work correctly.
cavity.tar.gz (2,810 bytes)

tniemi

2022-08-19 11:17

reporter   ~0012714

To further clarify, in https://github.com/OpenFOAM/OpenFOAM-dev/blob/dafc8f283389abc85fa374e391e1ba1b3c458a39/src/finiteVolume/cfdTools/general/fvModels/fvModelTemplates.C#L112
I would expect
return this->source(rho, field, field.name());
instead of
return this->source(field, field.name());

and
return source(field, fieldName, dimVolume/dimTime, rho);
indtead of
return source(field, fieldName, dimVolume/dimTime);

And similar changes for the alpha+rho versions. fvModels-interface also includes special versions for geometricOne-fields, which might be possibly useful also for fvModel?

henry

2022-08-19 11:37

manager   ~0012715

What happens if you make your suggested changes? Does it then operate the way you wish?

tniemi

2022-08-19 12:45

reporter   ~0012716

Here is a patch which modifies fvModel to work as I would like it to work. The patch is basically copy&paste from fvModels making all the functions to act identically. I added d2dt and geometricOne-versions for consistency.
patch.diff (5,854 bytes)   
diff --git a/src/finiteVolume/cfdTools/general/fvModels/fvModel.H b/src/finiteVolume/cfdTools/general/fvModels/fvModel.H
index faaeff8c6e..bd03cddd42 100644
--- a/src/finiteVolume/cfdTools/general/fvModels/fvModel.H
+++ b/src/finiteVolume/cfdTools/general/fvModels/fvModel.H
@@ -36,10 +36,12 @@ SourceFiles
 #define fvModel_H
 
 #include "fvMatricesFwd.H"
-#include "volFieldsFwd.H"
+#include "volFields.H"
 #include "dictionary.H"
 #include "dimensionSet.H"
 #include "fvModelM.H"
+#include "geometricOneField.H"
+#include "MeshObject.H"
 
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
 
@@ -325,6 +327,48 @@ public:
                 const word& fieldName
             ) const;
 
+            //- Return source for a phase equation
+            template<class Type>
+            tmp<fvMatrix<Type>> source
+            (
+                const volScalarField& alpha,
+                const geometricOneField& rho,
+                const GeometricField<Type, fvPatchField, volMesh>& field
+            ) const;
+
+            //- Return source for a phase equation
+            template<class Type>
+            tmp<fvMatrix<Type>> source
+            (
+                const geometricOneField& alpha,
+                const volScalarField& rho,
+                const GeometricField<Type, fvPatchField, volMesh>& field
+            ) const;
+
+            //- Return source for a phase equation
+            template<class Type>
+            tmp<fvMatrix<Type>> source
+            (
+                const geometricOneField& alpha,
+                const geometricOneField& rho,
+                const GeometricField<Type, fvPatchField, volMesh>& field
+            ) const;
+
+            //- Return source for an equation with a second time derivative
+            template<class Type>
+            tmp<fvMatrix<Type>> d2dt2
+            (
+                const GeometricField<Type, fvPatchField, volMesh>& field
+            ) const;
+
+            //- Return source for an equation with a second time derivative
+            template<class Type>
+            tmp<fvMatrix<Type>> d2dt2
+            (
+                const GeometricField<Type, fvPatchField, volMesh>& field,
+                const word& fieldName
+            ) const;
+
 
         // Mesh changes
 
diff --git a/src/finiteVolume/cfdTools/general/fvModels/fvModelTemplates.C b/src/finiteVolume/cfdTools/general/fvModels/fvModelTemplates.C
index 50282a046b..ea2ac65935 100644
--- a/src/finiteVolume/cfdTools/general/fvModels/fvModelTemplates.C
+++ b/src/finiteVolume/cfdTools/general/fvModels/fvModelTemplates.C
@@ -2,7 +2,7 @@
   =========                 |
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     | Website:  https://openfoam.org
-    \\  /    A nd           | Copyright (C) 2021 OpenFOAM Foundation
+    \\  /    A nd           | Copyright (C) 2021-2022 OpenFOAM Foundation
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
 License
@@ -109,7 +109,7 @@ Foam::tmp<Foam::fvMatrix<Type>> Foam::fvModel::source
     const GeometricField<Type, fvPatchField, volMesh>& field
 ) const
 {
-    return this->source(field, field.name());
+    return this->source(rho, field, field.name());
 }
 
 
@@ -121,7 +121,7 @@ Foam::tmp<Foam::fvMatrix<Type>> Foam::fvModel::source
     const word& fieldName
 ) const
 {
-    return source(field, fieldName, dimVolume/dimTime);
+    return source(field, fieldName, dimVolume/dimTime, rho);
 }
 
 
@@ -133,7 +133,7 @@ Foam::tmp<Foam::fvMatrix<Type>> Foam::fvModel::source
     const GeometricField<Type, fvPatchField, volMesh>& field
 ) const
 {
-    return this->source(field, field.name());
+    return this->source(alpha, rho, field, field.name());
 }
 
 
@@ -146,8 +146,81 @@ Foam::tmp<Foam::fvMatrix<Type>> Foam::fvModel::source
     const word& fieldName
 ) const
 {
-    return source(field, fieldName, dimVolume/dimTime);
+    return source(field, fieldName, dimVolume/dimTime, alpha, rho);
+}
+
+
+template<class Type>
+Foam::tmp<Foam::fvMatrix<Type>> Foam::fvModel::source
+(
+    const geometricOneField& alpha,
+    const geometricOneField& rho,
+    const GeometricField<Type, fvPatchField, volMesh>& field
+) const
+{
+    return this->source(field, field.name());
+}
+
+
+template<class Type>
+Foam::tmp<Foam::fvMatrix<Type>> Foam::fvModel::source
+(
+    const volScalarField& alpha,
+    const geometricOneField& rho,
+    const GeometricField<Type, fvPatchField, volMesh>& field
+) const
+{
+    volScalarField one
+    (
+        IOobject
+        (
+            "one",
+            this->mesh_.time().timeName(),
+            this->mesh_,
+            IOobject::NO_READ,
+            IOobject::NO_WRITE,
+            false
+        ),
+        this->mesh_,
+        dimensionedScalar(dimless, 1.0)
+    );
+
+    return this->source(alpha, one, field, field.name());
 }
 
 
+template<class Type>
+Foam::tmp<Foam::fvMatrix<Type>> Foam::fvModel::source
+(
+    const geometricOneField& alpha,
+    const volScalarField& rho,
+    const GeometricField<Type, fvPatchField, volMesh>& field
+) const
+{
+    return this->source(rho, field, field.name());
+}
+
+
+// * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * * //
+
+template<class Type>
+Foam::tmp<Foam::fvMatrix<Type>> Foam::fvModel::d2dt2
+(
+    const GeometricField<Type, fvPatchField, volMesh>& field
+) const
+{
+    return this->d2dt2(field, field.name());
+}
+
+
+template<class Type>
+Foam::tmp<Foam::fvMatrix<Type>> Foam::fvModel::d2dt2
+(
+    const GeometricField<Type, fvPatchField, volMesh>& field,
+    const word& fieldName
+) const
+{
+    return source(field, fieldName, dimVolume/sqr(dimTime));
+}
+
 // ************************************************************************* //
patch.diff (5,854 bytes)   

henry

2022-08-19 22:10

manager   ~0012717

Resolved by commit d4f9f9efcdf0d3623f0a19f98ed89840085d5af1

Issue History

Date Modified Username Field Change
2022-08-19 08:22 tniemi New Issue
2022-08-19 10:08 henry Note Added: 0012712
2022-08-19 10:57 tniemi Note Added: 0012713
2022-08-19 10:57 tniemi File Added: cavity.tar.gz
2022-08-19 11:17 tniemi Note Added: 0012714
2022-08-19 11:37 henry Note Added: 0012715
2022-08-19 12:45 tniemi Note Added: 0012716
2022-08-19 12:45 tniemi File Added: patch.diff
2022-08-19 22:10 henry Assigned To => henry
2022-08-19 22:10 henry Status new => resolved
2022-08-19 22:10 henry Resolution open => fixed
2022-08-19 22:10 henry Fixed in Version => dev
2022-08-19 22:10 henry Note Added: 0012717