CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > OpenFOAM > OpenFOAM Community Contributions

[swak4Foam] How to sample a patch with swak?

Register Blogs Community New Posts Updated Threads Search

Like Tree1Likes
  • 1 Post By ganeshv

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   May 18, 2012, 17:23
Default How to sample a patch with swak?
  #1
New Member
 
Pekka Röyttä
Join Date: Nov 2010
Location: Singapore
Posts: 7
Rep Power: 15
PekkaRo is on a distinguished road
Hi all,

I would like to replicate the behaviour of a heat flux sensor on surface. I think a nice way to do this is to sample running average over a subset of my wall patch. I need the time trace of this running average to calculate the spectrum. For internal mesh this was easy enough, but patches seem more difficult.

First, this succeeds in calculating Nusselt number (in controlDict):
Code:
functions
{
 NusseltNumber
      {
    type swakExpression;
    valueType patch;
    patchName Wall;
    verbose true;
    variables (
           "T0=293;"
           "lc2D=0.025;"
           );
    expression "lc2D*snGrad(T)/(T-T0)";
    accumulations (
               max
               min
               average
               );
          }
}
Should this be something in internalField I would use this

Code:
nuSensor {
      type dumpSwakExpression;
      verbose true;
      valueType cellSet;
      setName sensor0c;
      expression "NusseltNumber";
}
Where sensor0c is cell set generated with topoSet based on the sensor area.

Since I am writing here, it's not that easy. I can dump the whole patch, but since I need around 2*150k timesteps, it is a bit too much data. The cellSet method fails because NusseltNumber apparently belongs to patch, it's not found in cellSet. I also tried faceSet on surface, but with no improvement.

Could someone please point me to right direction? Also non-swak solutions are welcome.

br,
Pekka
PekkaRo is offline   Reply With Quote

Old   May 21, 2012, 17:44
Default
  #2
Assistant Moderator
 
Bernhard Gschaider
Join Date: Mar 2009
Posts: 4,225
Rep Power: 51
gschaider will become famous soon enoughgschaider will become famous soon enough
Quote:
Originally Posted by PekkaRo View Post
Hi all,

I would like to replicate the behaviour of a heat flux sensor on surface. I think a nice way to do this is to sample running average over a subset of my wall patch. I need the time trace of this running average to calculate the spectrum. For internal mesh this was easy enough, but patches seem more difficult.

First, this succeeds in calculating Nusselt number (in controlDict):
Code:
functions
{
 NusseltNumber
      {
    type swakExpression;
    valueType patch;
    patchName Wall;
    verbose true;
    variables (
           "T0=293;"
           "lc2D=0.025;"
           );
    expression "lc2D*snGrad(T)/(T-T0)";
    accumulations (
               max
               min
               average
               );
          }
}
Should this be something in internalField I would use this

Code:
nuSensor {
      type dumpSwakExpression;
      verbose true;
      valueType cellSet;
      setName sensor0c;
      expression "NusseltNumber";
}
Where sensor0c is cell set generated with topoSet based on the sensor area.

Since I am writing here, it's not that easy. I can dump the whole patch, but since I need around 2*150k timesteps, it is a bit too much data. The cellSet method fails because NusseltNumber apparently belongs to patch, it's not found in cellSet. I also tried faceSet on surface, but with no improvement.

Could someone please point me to right direction? Also non-swak solutions are welcome.

br,
Pekka
I'm not sure whether I understand your problem correctly: the first example is basically OK, but your problem is that you don't want the accumulated values for the whole patch, but values for a small subset of the patch faces. Right?

The problem with the faceSet approach was what? Maybe that the snGrad is not supported on faceSets?
gschaider is offline   Reply With Quote

Old   May 22, 2012, 05:46
Default
  #3
New Member
 
Pekka Röyttä
Join Date: Nov 2010
Location: Singapore
Posts: 7
Rep Power: 15
PekkaRo is on a distinguished road
Quote:
Originally Posted by gschaider View Post
I'm not sure whether I understand your problem correctly: the first example is basically OK, but your problem is that you don't want the accumulated values for the whole patch, but values for a small subset of the patch faces. Right?

The problem with the faceSet approach was what? Maybe that the snGrad is not supported on faceSets?
Yes, you are right on both occasions. Sorry for the messy description. The problem is that I don't know how to sample a patch, and that the Nusselt number is stored in the wall patch (snGrad is undefined in internal nodes).

I noticed that it's possible to cheat a bit and calculate the Nusselt number in wall adjacent cells if I know the geometry exactly. I'll post that solution when I get to my computer. But it will only work for relatively simple geometries.

br,
Pekka
PekkaRo is offline   Reply With Quote

Old   May 22, 2012, 08:57
Default
  #4
Assistant Moderator
 
Bernhard Gschaider
Join Date: Mar 2009
Posts: 4,225
Rep Power: 51
gschaider will become famous soon enoughgschaider will become famous soon enough
Quote:
Originally Posted by PekkaRo View Post
Yes, you are right on both occasions. Sorry for the messy description. The problem is that I don't know how to sample a patch, and that the Nusselt number is stored in the wall patch (snGrad is undefined in internal nodes).

I noticed that it's possible to cheat a bit and calculate the Nusselt number in wall adjacent cells if I know the geometry exactly. I'll post that solution when I get to my computer. But it will only work for relatively simple geometries.

br,
Pekka
OK. One solution would be to
  1. Create a bogus field-file which in the patches of interest has a groovyBC that implements the Nusselt number
  2. Use a functionObject that at the start of the simulation loads the bogus field, updates the boundary conditions at every timestep (-> the groovyBC will calculate the Nusselt-number). If necessary the field is written at the usual times
  3. Postprocess the field. Either by looking at the written instance in paraview or using sampledPatch from the surfaces-facility in OF

The problem here is that I'm not aware of a functionObject described in point 2. Neither in OF nor in swak. But I could persuade the developer of swak to write such a FO (I'm on rather good terms with him ) provided you promise to write a small description of the usage on the swak-page on the Wiki afterwards
gschaider is offline   Reply With Quote

Old   May 23, 2012, 15:25
Default
  #5
New Member
 
Pekka Röyttä
Join Date: Nov 2010
Location: Singapore
Posts: 7
Rep Power: 15
PekkaRo is on a distinguished road
Quote:
Originally Posted by gschaider View Post
OK. One solution would be to
  1. Create a bogus field-file which in the patches of interest has a groovyBC that implements the Nusselt number
  2. Use a functionObject that at the start of the simulation loads the bogus field, updates the boundary conditions at every timestep (-> the groovyBC will calculate the Nusselt-number). If necessary the field is written at the usual times
  3. Postprocess the field. Either by looking at the written instance in paraview or using sampledPatch from the surfaces-facility in OF

The problem here is that I'm not aware of a functionObject described in point 2. Neither in OF nor in swak. But I could persuade the developer of swak to write such a FO (I'm on rather good terms with him ) provided you promise to write a small description of the usage on the swak-page on the Wiki afterwards
Great, sounds like a deal to me. Thanks in advance.

I promised the cheat around the problem, so here it goes. I simplified a bit so that avid readers are not totally lost. This works still. My case is a circular cylinder in a cross flow, origin is at cylinder center. Further this approach works for constant wall temperature, but constant heat flux would be as easy.

This is in controlDict and under functions:

Code:
 sensorDumb
      {
    type dumpSwakExpression;
    valueType cellSet;
    setName sensor0c;
    variables (
          "rCyl=0.0125;"
          "T0=293;"
          "lc2D=0.025;"
          "Tw=343;"
           );
    expression "(Tw-T)/(Tw-T0)/(sqrt(pos().y*pos().y+pos().x*pos().x) - rCyl)*lc2D ";
      }
PekkaRo is offline   Reply With Quote

Old   May 24, 2012, 09:35
Default
  #6
Assistant Moderator
 
Bernhard Gschaider
Join Date: Mar 2009
Posts: 4,225
Rep Power: 51
gschaider will become famous soon enoughgschaider will become famous soon enough
Quote:
Originally Posted by PekkaRo View Post
Great, sounds like a deal to me. Thanks in advance.
OK. Changed version hit the server (see Wiki-page on how to get the development-version). The new functionObject is both in default branch (1.x) as well as in the 2.x-branch. For "documentation" have a look at the bottom of the README. Example of usage is in Examples/other/angledDuctImplicit (controlDict and 0/heatFlux). The example is a bit unfortunate as due to the boundary-conditions (gradT=0) the heatFlux is zero. But that is calculated correctly (I tried other values too but didn't verify them)
gschaider is offline   Reply With Quote

Old   May 31, 2012, 06:58
Default
  #7
Member
 
Ganesh Vijayakumar
Join Date: Jan 2010
Posts: 44
Rep Power: 16
ganeshv is on a distinguished road
I do not understand what exactly is the functionObject that hit the development version. Although I understand that pulling that file is the correct thing to do since I already have the development version on the git, I'm still not comfortable messing with my openfoam installation lest I break it. So is there any way I can check it out online?

This post seems to be the closest to what I want.. i.e probes/faceSets on a patch. See post here.

http://www.cfd-online.com/Forums/ope...tml#post364016

@Bernhard: Is there any way I can use swak to create faceSets on a patch based on pos()?
ganeshv is offline   Reply With Quote

Old   May 31, 2012, 13:54
Default
  #8
Assistant Moderator
 
Bernhard Gschaider
Join Date: Mar 2009
Posts: 4,225
Rep Power: 51
gschaider will become famous soon enoughgschaider will become famous soon enough
Quote:
Originally Posted by ganeshv View Post
I do not understand what exactly is the functionObject that hit the development version. Although I understand that pulling that file is the correct thing to do since I already have the development version on the git, I'm still not comfortable messing with my openfoam installation lest I break it. So is there any way I can check it out online?
The location of the development-repository for swak is described on its page on the Wiki

Quote:
Originally Posted by ganeshv View Post
IThis post seems to be the closest to what I want.. i.e probes/faceSets on a patch. See post here.

http://www.cfd-online.com/Forums/ope...tml#post364016

@Bernhard: Is there any way I can use swak to create faceSets on a patch based on pos()?
The swakTopoSources adds a topo source named expressionToFace to the topoSet-utility. The problem is that swak currently doesn't support testing whether a face is on a patch. But if you use the appropriate topoSource first to put all faces on the patch foo into a faceSet fooPatchSet then an expression "fset(fooPatchSet) && fpos().x>0" might get you what you want.
gschaider is offline   Reply With Quote

Old   May 31, 2012, 13:55
Default
  #9
New Member
 
Pekka Röyttä
Join Date: Nov 2010
Location: Singapore
Posts: 7
Rep Power: 15
PekkaRo is on a distinguished road
EDIT:
I was too slow, ignore this. Wiki coming up.
PekkaRo is offline   Reply With Quote

Old   May 31, 2012, 14:34
Default
  #10
Member
 
Ganesh Vijayakumar
Join Date: Jan 2010
Posts: 44
Rep Power: 16
ganeshv is on a distinguished road
Quote:
Originally Posted by gschaider View Post
The swakTopoSources adds a topo source named expressionToFace to the topoSet-utility. The problem is that swak currently doesn't support testing whether a face is on a patch. But if you use the appropriate topoSource first to put all faces on the patch foo into a faceSet fooPatchSet then an expression "fset(fooPatchSet) && fpos().x>0" might get you what you want.
This is awesome. Thanks. That might just do the trick.
ganeshv is offline   Reply With Quote

Old   June 4, 2012, 12:01
Default
  #11
Member
 
Ganesh Vijayakumar
Join Date: Jan 2010
Posts: 44
Rep Power: 16
ganeshv is on a distinguished road
Quote:
Originally Posted by ganeshv View Post
This is awesome. Thanks. That might just do the trick.
That is awesome. But I can't seem to figure it out. Any examples of using it? And topoSet doesn't seem to know where swakTopoSources are and hence says that "expressionToFace" is not a valid topoSource. Could you help Bernhard? I have OpenFOAM 2.1.x installed and the swak4Foam installed from the svn repo.

ganesh
ganeshv is offline   Reply With Quote

Old   June 4, 2012, 15:17
Default
  #12
Member
 
Ganesh Vijayakumar
Join Date: Jan 2010
Posts: 44
Rep Power: 16
ganeshv is on a distinguished road
Never mind the previous question. I never thought that a library included in the controlDict would have an effect on topoSet. Once I included it, it was able to run. However it doesn't seem to understand fpos.


Quote:
Create polyMesh for time = 0

Time:0 cells:1064178 faces:2452093 points:440639 patches:7 bb-40 -103.923 -1.47898e-15) (40 103.923 120)
faceSets:
blade size:21432
jump1 size:13696
faceZones:
blade size:21432

Successfully read history from .setSet
Time = 0
mesh not changed.
Please type 'help', 'quit' or a set command after prompt.
readline>faceSet jump1 new expressionToFace "mag(fpos().z - 11.75) < 2.0"
Set:jump1 Size:0 Action:new
Adding all elements of for which "mag(fpos().z - 11.75) < 2.0" evaluates to true ...
Parser Error at "1.16-20" :"syntax error, unexpected number"
"mag(fpos().z - 11.75) < 2.0"
" ^^^^^ "

Usage: expressionToFace <expression>

Select all faces for which expression evaluates to true on one and false on the other side
letzel likes this.
ganeshv is offline   Reply With Quote

Old   June 4, 2012, 15:59
Default
  #13
Member
 
Ganesh Vijayakumar
Join Date: Jan 2010
Posts: 44
Rep Power: 16
ganeshv is on a distinguished road
Quote:
Originally Posted by gschaider View Post
The swakTopoSources adds a topo source named expressionToFace to the topoSet-utility. The problem is that swak currently doesn't support testing whether a face is on a patch. But if you use the appropriate topoSource first to put all faces on the patch foo into a faceSet fooPatchSet then an expression "fset(fooPatchSet) && fpos().x>0" might get you what you want.

I understand from the README for swak that "expressionToFace" works only on internal faces. Is this true or my misunderstanding? I tried the following in setSet

faceSet jump1 new expressionToFace "fset(blade)"

It just seg faults. I do have a face set called blade.
ganeshv is offline   Reply With Quote

Old   June 4, 2012, 17:46
Default
  #14
Assistant Moderator
 
Bernhard Gschaider
Join Date: Mar 2009
Posts: 4,225
Rep Power: 51
gschaider will become famous soon enoughgschaider will become famous soon enough
Quote:
Originally Posted by ganeshv View Post
I understand from the README for swak that "expressionToFace" works only on internal faces. Is this true or my misunderstanding? I tried the following in setSet

faceSet jump1 new expressionToFace "fset(blade)"

It just seg faults. I do have a face set called blade.
Oh, sorry. Forgot about that limitation. Sorry that I led you in blind alley.

Will have a look at how to fix it ASAIFT (Hint: this process is usually sped up by a bug report with a small test-case)

PS: ASAIFT stands for "As Soon As I Find Time" - a yet unknown abbreviation with a big future

Last edited by gschaider; June 5, 2012 at 04:56. Reason: Corrected Freudian slip
gschaider is offline   Reply With Quote

Old   June 4, 2012, 21:07
Default
  #15
Member
 
Ganesh Vijayakumar
Join Date: Jan 2010
Posts: 44
Rep Power: 16
ganeshv is on a distinguished road
Quote:
Originally Posted by gschaider View Post
Oh, sorry. Forgot about that limitation. Sorry that I led you in blade alley.

Will have a look at how to fix it ASAIFT (Hint: this process is usually sped up by a bug report with a small test-case)

PS: ASAIFT stands for "As Soon As I Find Time" - a yet unknown abbreviation with a big future

ASAIFT! No probs Bernard. I wrote my own utility. Hopefully this will serve as an example to others to create their own faceSets. The essence of it is this

Quote:
const label patchID = mesh.boundaryMesh().findPatchID("Blade") ;
if((patchID >= 0) && (mesh.boundary()[patchID].size() > 0)) {
const fvPatch& cPatch = mesh.boundary()[patchID] ;
label patchStart = cPatch.patch().start() ;
forAll(rProps,i) {
bladeLocation << "r" << rProps[0][0];
faceSet rLoc(mesh,bladeLocation.str(),0);
forAll(cPatch, faceI) {
if( mag(mesh.Cf()[faceI+patchStart].z()- rProps[i][1]) < 0.2) {
Info << "face " << faceI << " " << mesh.Cf()[faceI+patchStart] << endl ;
rLoc.insert(faceI+patchStart) ;
}
rLoc.write();
}
}
}
else {
Info << "No Boundary named Blade " << endl ;
}
Attached Files
File Type: c createFaceSets.C (2.8 KB, 13 views)
ganeshv is offline   Reply With Quote

Old   June 6, 2012, 04:55
Default
  #16
Assistant Moderator
 
Bernhard Gschaider
Join Date: Mar 2009
Posts: 4,225
Rep Power: 51
gschaider will become famous soon enoughgschaider will become famous soon enough
Quote:
Originally Posted by ganeshv View Post
ASAIFT! No probs Bernard. I wrote my own utility. Hopefully this will serve as an example to others to create their own faceSets. The essence of it is this
Had a case of WTFITTT (What the f###, I'll take the time). A version that fixes the crash with faceSet on patches and adds two functions onPatch and internalFace (guess what they do) is in the development version (the mercurial repository). See the README for details
gschaider is offline   Reply With Quote

Old   November 7, 2015, 20:48
Default
  #17
Senior Member
 
Himanshu Sharma
Join Date: Jul 2012
Posts: 101
Rep Power: 13
himanshu28 is on a distinguished road
Quote:
Originally Posted by gschaider View Post
OK. Changed version hit the server (see Wiki-page on how to get the development-version). The new functionObject is both in default branch (1.x) as well as in the 2.x-branch. For "documentation" have a look at the bottom of the README. Example of usage is in Examples/other/angledDuctImplicit (controlDict and 0/heatFlux). The example is a bit unfortunate as due to the boundary-conditions (gradT=0) the heatFlux is zero. But that is calculated correctly (I tried other values too but didn't verify them)
Hi Bernhard,

I am trying to calculated snGradT on the faceset made using the following
toposet on the Top wall of my geometry
Code:
actions
(
   {
        name    Dummycell;
        type    cellSet;
        action  new;
        source  boxToCell;
        sourceInfo
        {
            box (0.1 2.8 0.0)(8.8 3.1 0.3);
        }
    }   
            
   {
        name    Dummyface;
        type    faceSet;
        action  new;
        source  cellToFace;
        sourceInfo
        {
            set Dummycell;
            option all;
        }
    }       
{
        name    Dummyface;
        type    faceSet;
        action  subset;
        source  patchToFace;
        sourceInfo
        {
            name "wall.ceiling";
        }
    }
(faces of Interest)
|-------|----------------------|------- |
|
|_
|
| (Faces of Interest)
|
|_
|

But when I am using the faceset "Dummyface" in the swak4Foam function
in controlDict
Code:
Nu_ceiling_test
{
type swakExpression;
valueType faceSet;
setName  Dummyface;
verbose true;
variables (
"Tsat=283.61;"
"lc2D=0.1452;"
);
expression "lc2D*snGrad(T)/(T-Tsat)";
accumulations (
max
min
average
); 
outputControl timeStep;
       outputInterval 100;
}
I am getting Following error.
Code:
--> FOAM FATAL ERROR: 
 Parser Error for driver FaceSetValueExpressionDriver at "1.6-11" :"field snGrad not existing or of wrong type"
"lc2D*snGrad(T)/(T-Tsat)"
       ^^^^^^
-------|     

Context of the error:


- From dictionary: .Nu_ceiling_test
  Evaluating expression "lc2D*snGrad(T)/(T-Tsat)"


    From function parsingValue
    in file lnInclude/CommonValueExpressionDriverI.H at line 1189.

FOAM exiting
I looked into the Example Case as directed by couldn't find out what actually is needed to solve the problem.
I will be thankful if you can provide some advice on it and how it can be done using Swak.
The main objective is to calculate "Nusselt Number on the Selected Faces of Interest on the patch"

Thank you

Regards
himanshu28 is offline   Reply With Quote

Reply


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
y+ and u+ values with low-Re RANS turbulence models: utility + testcase florian_krause OpenFOAM 114 August 23, 2023 05:37
Near wall treatment in k-omega SST Arnoldinho OpenFOAM Running, Solving & CFD 38 March 8, 2017 13:48
[mesh manipulation] Importing Multiple Meshes thomasnwalshiii OpenFOAM Meshing & Mesh Conversion 18 December 19, 2015 18:57
[Gmsh] Import gmsh msh to Foam adorean OpenFOAM Meshing & Mesh Conversion 24 April 27, 2005 08:19
Multicomponent fluid Andrea CFX 2 October 11, 2004 05:12


All times are GMT -4. The time now is 17:20.