CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Community Contributions (https://www.cfd-online.com/Forums/openfoam-community-contributions/)
-   -   [swak4Foam] How to sample a patch with swak? (https://www.cfd-online.com/Forums/openfoam-community-contributions/101990-how-sample-patch-swak.html)

PekkaRo May 18, 2012 17:23

How to sample a patch with swak?
 
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

gschaider May 21, 2012 17:44

Quote:

Originally Posted by PekkaRo (Post 361928)
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?

PekkaRo May 22, 2012 05:46

Quote:

Originally Posted by gschaider (Post 362293)
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

gschaider May 22, 2012 08:57

Quote:

Originally Posted by PekkaRo (Post 362387)
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

PekkaRo May 23, 2012 15:25

Quote:

Originally Posted by gschaider (Post 362445)
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 ";
      }


gschaider May 24, 2012 09:35

Quote:

Originally Posted by PekkaRo (Post 362736)
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)

ganeshv May 31, 2012 06:58

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()?

gschaider May 31, 2012 13:54

Quote:

Originally Posted by ganeshv (Post 364017)
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 (Post 364017)
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.

PekkaRo May 31, 2012 13:55

EDIT:
I was too slow, ignore this. Wiki coming up.

ganeshv May 31, 2012 14:34

Quote:

Originally Posted by gschaider (Post 364121)
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 June 4, 2012 12:01

Quote:

Originally Posted by ganeshv (Post 364135)
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 June 4, 2012 15:17

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

ganeshv June 4, 2012 15:59

Quote:

Originally Posted by gschaider (Post 364121)
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.

gschaider June 4, 2012 17:46

Quote:

Originally Posted by ganeshv (Post 364705)
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

ganeshv June 4, 2012 21:07

1 Attachment(s)
Quote:

Originally Posted by gschaider (Post 364716)
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 ;
}

gschaider June 6, 2012 04:55

Quote:

Originally Posted by ganeshv (Post 364726)
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

himanshu28 November 7, 2015 20:48

Quote:

Originally Posted by gschaider (Post 362904)
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


All times are GMT -4. The time now is 14:13.