CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > OpenFOAM > OpenFOAM Programming & Development

Setting normal gradient of each face of patch

Register Blogs Community New Posts Updated Threads Search

Like Tree3Likes
  • 2 Post By Dozer_94
  • 1 Post By einstein_zee

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   July 16, 2019, 10:36
Default Setting normal gradient of each face of patch
  #1
New Member
 
Join Date: Dec 2016
Posts: 24
Rep Power: 9
Dozer_94 is on a distinguished road
Hi all,

In my simulation, I have to reset the fixed gradient of a scalar field "s" as a BC on a patch each time step.

Now, I am aware that if all faces of a patch get the same value, you can use

Code:
    label BCID = mesh.boundaryMesh().findPatchID("part0");
    if(s.boundaryField()[BCID].type() == fixedGradientFvPatchScalarField::typeName)
    {
        fixedGradientFvPatchScalarField& spatch = refCast<fixedGradientFvPatchScalarField>(s.boundaryFieldRef()[BCID]);
        spatch.gradient() = dp;
    }
See this thread: Updating Boundary Conditions Each Iteration

This will set the normal gradient of scalar "s" on all faces of patch "part0" to value "dp". Which works perfectly. But what if I want to give each face a different value? Say something like this:

Code:
    label BCID = mesh.boundaryMesh().findPatchID("part0");  
    if(s.boundaryField()[BCID].type() == fixedGradientFvPatchScalarField::typeName)
    {
        fixedGradientFvPatchScalarField& spatch = refCast<fixedGradientFvPatchScalarField>(s.boundaryFieldRef()[BCID]);
        forAll (spatch, faceI)
        {
            spatch[faceI].gradient() = dp[faceI];
        }
    }
In which "dp" is now not a float, but a list of floats. This does not work, as OF throws the following error:

Code:
   sBC.H:32:18: error: request for member ‘gradient’ in 
‘(& spatch)->Foam::fixedGradientFvPatchField<double>::
 <anonymous>.Foam::fvPatchField<double>::<anonymous>.Foam::Field<double>::
  <anonymous>.Foam::List<double>::<anonymous>.Foam::UList<double>::operator[](faceI)’, 
which is of non-class type ‘double’
      spatch[faceI].gradient() = dp[faceI];
Anyone ideas on what is going wrong here?

Thanks in advance,
arashn18 and ssc0109 like this.
Dozer_94 is offline   Reply With Quote

Old   July 16, 2019, 11:00
Default
  #2
Member
 
Hosein
Join Date: Nov 2011
Location: Germany
Posts: 94
Rep Power: 14
einstein_zee is on a distinguished road
Quote:
Originally Posted by Dozer_94 View Post
Hi all,

In my simulation, I have to reset the fixed gradient of a scalar field "s" as a BC on a patch each time step.

Now, I am aware that if all faces of a patch get the same value, you can use

Code:
    label BCID = mesh.boundaryMesh().findPatchID("part0");
    if(s.boundaryField()[BCID].type() == fixedGradientFvPatchScalarField::typeName)
    {
        fixedGradientFvPatchScalarField& spatch = refCast<fixedGradientFvPatchScalarField>(s.boundaryFieldRef()[BCID]);
        spatch.gradient() = dp;
    }
See this thread: Updating Boundary Conditions Each Iteration

This will set the normal gradient of scalar "s" on all faces of patch "part0" to value "dp". Which works perfectly. But what if I want to give each face a different value? Say something like this:

Code:
    label BCID = mesh.boundaryMesh().findPatchID("part0");  
    if(s.boundaryField()[BCID].type() == fixedGradientFvPatchScalarField::typeName)
    {
        fixedGradientFvPatchScalarField& spatch = refCast<fixedGradientFvPatchScalarField>(s.boundaryFieldRef()[BCID]);
        forAll (spatch, faceI)
        {
            spatch[faceI].gradient() = dp[faceI];
        }
    }
In which "dp" is now not a float, but a list of floats. This does not work, as OF throws the following error:

Code:
   sBC.H:32:18: error: request for member ‘gradient’ in 
‘(& spatch)->Foam::fixedGradientFvPatchField<double>::
 <anonymous>.Foam::fvPatchField<double>::<anonymous>.Foam::Field<double>::
  <anonymous>.Foam::List<double>::<anonymous>.Foam::UList<double>::operator[](faceI)’, 
which is of non-class type ‘double’
      spatch[faceI].gradient() = dp[faceI];
Anyone ideas on what is going wrong here?

Thanks in advance,
Hey there,

have you tried it this way: spatch.gradient()[faceI] = dp[faceI]
ssc0109 likes this.
einstein_zee is offline   Reply With Quote

Old   July 16, 2019, 11:08
Default
  #3
New Member
 
Join Date: Dec 2016
Posts: 24
Rep Power: 9
Dozer_94 is on a distinguished road
Oh my... Not my brightest moment. Thanks a lot for the superfast reply!
Dozer_94 is offline   Reply With Quote

Reply

Tags
boudary condition, patch gradient


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
steadyUniversalMRFFoam Tutorial fails in MixingPlane HenrikJohansson OpenFOAM Bugs 0 February 14, 2019 05:48
[mesh manipulation] Importing Multiple Meshes thomasnwalshiii OpenFOAM Meshing & Mesh Conversion 18 December 19, 2015 19:57
NACA0012 geometry/design software needed Franny Main CFD Forum 13 July 7, 2007 16:57
[Gmsh] Import gmsh msh to Foam adorean OpenFOAM Meshing & Mesh Conversion 24 April 27, 2005 09:19
Multicomponent fluid Andrea CFX 2 October 11, 2004 06:12


All times are GMT -4. The time now is 23:57.