|
[Sponsors] |
March 16, 2011, 05:18 |
fvc::div for surfaceVectorField
|
#1 |
Member
Artem Shaklein
Join Date: Feb 2010
Location: Russia, Izhevsk
Posts: 43
Rep Power: 16 |
Greetings !
I want to calculate divergence of velocity. Firstly, I have volVectorField U. After some manipulations with U, I obtain surfaceScalarField Usurface. Next, i try to calculate divergence: fvc::div(Usurface), but this action leads to unexpected result. For example, when i compute div of mesh.Sf() (dimension [m^2]), i recieve volVectorField (dimension [m^-1]) instead of volScalarField (dimension [m^1]). But computation grad of mag(mesg.Sf()) (surfaceScalarField, dimension [m^2]) leads to volVectorField with dimension [m^1]. This is right, There are my questions: -Why fvc::grad(surfaceScalarField) gives correct result, but fvc::div(surfaceVectorField) - incorrect? May be i make mistake in calculations? -Can i calculate divergence of surfaceVectorField using fvc::div? Thank you! Best regards! Last edited by ARTem; March 16, 2011 at 11:10. |
|
January 9, 2017, 08:21 |
|
#2 | |
New Member
toboto
Join Date: Jun 2016
Posts: 20
Rep Power: 10 |
I've exactly the same problem. When I interpolate velocity field to the surface I got a surfaceVectorField. When I try to calculate the divergence of this field I got a volVectorField while I expect a volScalarField.
According to the programmers' manual: Quote:
I found in the source code of fvcDiv.H that if the fvc::div is applied to a volField it will return a field of one rank lower Code:
GeometricField <typename innerProduct<vector, Type>::type, fvPatchField, volMesh> > div ( const GeometricField<Type, fvPatchField, volMesh>&, const word& name ); Code:
tmp<GeometricField<Type, fvPatchField, volMesh>> div ( const GeometricField<Type, fvsPatchField, surfaceMesh>& ); Any explanation is highly appreciated. Best regards. Last edited by toboto; January 9, 2017 at 09:52. Reason: Add additional information |
||
January 14, 2017, 17:47 |
|
#3 |
Senior Member
Sergei
Join Date: Dec 2009
Posts: 261
Rep Power: 22 |
If you check source code you'll see there're 14 overloaded functions fvc:div() for several combinations of input parameters. This set of functions can be broken down into three groups with one "primary" function within each group being called by other functions in the same group. Those primary functions are declared as:
Code:
template<class Type > tmp< GeometricField< typename innerProduct< vector, Type >::type, fvPatchField, volMesh > > div ( const GeometricField< Type, fvPatchField, volMesh > & vf, const word &name ) Code:
template<class Type > tmp< GeometricField< Type, fvPatchField, volMesh > > div ( const surfaceScalarField &flux, const GeometricField< Type, fvPatchField, volMesh > &vf, const word &name ) Code:
template<class Type > tmp< GeometricField< Type, fvPatchField, volMesh > > div ( const GeometricField< Type, fvsPatchField, surfaceMesh > &ssf ) Code:
75 template<class Type> 76 tmp 77 < 78 GeometricField 79 < 80 typename innerProduct<vector, Type>::type, fvPatchField, volMesh 81 > 82 > 83 div 84 ( 85 const GeometricField<Type, fvPatchField, volMesh>& vf, 86 const word& name 87 ) 88 { 89 return fv::divScheme<Type>::New 90 ( 91 vf.mesh(), vf.mesh().divScheme(name) 92 )().fvcDiv(vf); 93 } Code:
42 template<class Type> 43 tmp 44 < 45 GeometricField 46 <typename innerProduct<vector, Type>::type, fvPatchField, volMesh> 47 > 48 gaussDivScheme<Type>::fvcDiv 49 ( 50 const GeometricField<Type, fvPatchField, volMesh>& vf 51 ) 52 { 53 tmp 54 < 55 GeometricField 56 <typename innerProduct<vector, Type>::type, fvPatchField, volMesh> 57 > tDiv 58 ( 59 fvc::surfaceIntegrate 60 ( 61 this->mesh_.Sf() & this->tinterpScheme_().interpolate(vf) 62 ) 63 ); 64 65 tDiv().rename("div(" + vf.name() + ')'); 66 67 return tDiv; 68 } Code:
this->tinterpScheme_().interpolate(vf) Code:
this->mesh_.Sf() & this->tinterpScheme_().interpolate(vf) Lastly, it loops over the cells and for each cell it sums the fluxes through the cell's faces. This total sum of fluxes for each cell is then divided by a cell's volume Code:
42 template<class Type> 43 void surfaceIntegrate 44 ( 45 Field<Type>& ivf, 46 const GeometricField<Type, fvsPatchField, surfaceMesh>& ssf 47 ) 48 { 49 const fvMesh& mesh = ssf.mesh(); 50 51 const labelUList& owner = mesh.owner(); 52 const labelUList& neighbour = mesh.neighbour(); 53 54 const Field<Type>& issf = ssf; 55 56 forAll(owner, facei) 57 { 58 ivf[owner[facei]] += issf[facei]; 59 ivf[neighbour[facei]] -= issf[facei]; 60 } 61 62 forAll(mesh.boundary(), patchi) 63 { 64 const labelUList& pFaceCells = 65 mesh.boundary()[patchi].faceCells(); 66 67 const fvsPatchField<Type>& pssf = ssf.boundaryField()[patchi]; 68 69 forAll(mesh.boundary()[patchi], facei) 70 { 71 ivf[pFaceCells[facei]] += pssf[facei]; 72 } 73 } 74 75 ivf /= mesh.Vsc(); 76 } Code:
45 GeometricField 46 <typename innerProduct<vector, Type>::type, fvPatchField, volMesh> Code:
88 template<class arg1, class arg2> 89 class innerProduct 90 { 91 public: 92 93 typedef typename typeOfRank 94 < 95 typename pTraits<arg1>::cmptType, 96 int(pTraits<arg1>::rank) + int(pTraits<arg2>::rank) - 2 97 >::type type; 98 }; Code:
44 template<class Cmpt, int rank> 45 class typeOfRank 46 {}; Code:
41 template<class Cmpt> 42 class typeOfRank<Cmpt, 0> 43 { 44 public: 45 46 typedef Cmpt type; 47 }; Code:
129 template<class Cmpt> 130 class typeOfRank<Cmpt, 1> 131 { 132 public: 133 134 typedef Vector<Cmpt> type; 135 }; Code:
178 template<class Cmpt> 179 class typeOfRank<Cmpt, 2> 180 { 181 public: 182 183 typedef Tensor<Cmpt> type; 184 }; The other two "primary" fvc:div functions mentioned in the very beginning of this very lengthy post can be dissected in the similar way. If something is unclear please feel free to ask. Last edited by Zeppo; January 15, 2017 at 06:21. |
|
November 2, 2018, 13:23 |
|
#4 |
Member
Alejandro Valeije
Join Date: Nov 2014
Location: Spain
Posts: 52
Rep Power: 12 |
Hi,
I'm stucked with this kind of problem also, and I did not understand really well the answer (maybe because my knowledge about the programming is not very good). I want to do the divergence of a surfaceVectorField (it actually is a volVector, but i can convert it) to add it to a ddt term, which is a volScalarField, but the divergence is not converting the vector into a scalar. Can somebody explain to me what I'm doing wrong?? Thank u very much Alex |
|
November 2, 2018, 13:41 |
|
#5 | |
Member
Alejandro Valeije
Join Date: Nov 2014
Location: Spain
Posts: 52
Rep Power: 12 |
Quote:
Never mind, I realized I was doing another mistake I was unable to see, and once corrected, I was able to permorm the operation Regards, Alex |
||
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
fvc::div() strange behaviour | ivan_cozza | OpenFOAM Running, Solving & CFD | 2 | February 6, 2010 07:09 |
help needed with fvc::div() | johanna | OpenFOAM Programming & Development | 2 | August 31, 2009 08:12 |
What type return fvcdiv | su_junwei | OpenFOAM Running, Solving & CFD | 6 | October 13, 2008 08:09 |