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

Calculate distance from vol to patch cells

Register Blogs Members List Search Today's Posts Mark Forums Read

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   June 10, 2019, 06:31
Default Calculate distance from vol to patch cells
  #1
New Member
 
HBR
Join Date: Jun 2018
Posts: 6
Rep Power: 4
landau is on a distinguished road
Hello!

I'm a very beginner in OpenFoam programming, and I would like to ask the community some help with an issue I have not been able to find any information of in this forum, or even in google.

First of all I am modelling the wind over complex terrain. I have introduced some source terms in the equations that depend on the vertical coordinate. The problem is that I need to fix the reference for the z coordinate over the ground and not over the plane z=0. Therefore I need to subtract from every cell z coordinate in the volume mesh the corresponding height of the coincident (x,y) point of the ground.

I have think of the function FoamatchWave:atchWave().distance()

For this reason I've used (I don't think that properly) this function as follows:
Code:
  
label patchID = mesh.boundaryMesh().findPatchID("terrain");
scalarField d;//distances are stored in this variable
patchWave w(mesh, patchID, true);
d = w.distance();
The only distance it has computed is a negative one:
Code:
204901{-1e+15}
and obviously it gives an error but I do not know why.

Thank you in advance.

Héctor
landau is offline   Reply With Quote

Old   June 10, 2019, 07:11
Default
  #2
Senior Member
 
Join Date: Aug 2015
Posts: 464
Rep Power: 11
clapointe is on a distinguished road
Have you looked into wallDist (https://github.com/OpenFOAM/OpenFOAM...ist/wallDist.H)? It should be what you need.

Caelan
clapointe is offline   Reply With Quote

Old   June 10, 2019, 07:21
Default
  #3
New Member
 
HBR
Join Date: Jun 2018
Posts: 6
Rep Power: 4
landau is on a distinguished road
Thank you so much for your suggestion. The fact is that I saw this function but I didn't know how to extract a new volScalarField from the function wallDist. Could you guide me a little?

I know that the functions that wallDist has return a newmesh with updateMesh. But my goal is obtain a volscalarField with all the cell distances to the required patch.

Thank you so much for your patience.

Héctor
landau is offline   Reply With Quote

Old   June 10, 2019, 07:43
Default
  #4
Senior Member
 
Join Date: Aug 2015
Posts: 464
Rep Power: 11
clapointe is on a distinguished road
Fair warning -- I'm not sure if I've used it before, but I've seen it in e.g. turbulence models. I pulled this snippet from the kOmegaSST base... it might help :

Code:
y_(wallDist::New(this->mesh_).y())
.

Caelan
clapointe is offline   Reply With Quote

Old   June 11, 2019, 02:46
Default
  #5
New Member
 
HBR
Join Date: Jun 2018
Posts: 6
Rep Power: 4
landau is on a distinguished road
Thank you so much Caelan. So much appreciated! At the end it was much easier than I thought.
landau is offline   Reply With Quote

Old   March 8, 2021, 05:52
Default
  #6
hef
New Member
 
H Fossum
Join Date: Jan 2021
Posts: 3
Rep Power: 2
hef is on a distinguished road
Quote:
Originally Posted by landau View Post
Thank you so much Caelan. So much appreciated! At the end it was much easier than I thought.
If this thread is not dead, can I ask you how you got this to work? I tried the following, which gave the same error you got:

Code:
label patchID = mesh.boundaryMesh().findPatchID("topo");
wallDist wD(mesh, patchID, "wall");
gD = wD.y();
where gD is a volScalarField which I've set up earlier in the code:

Code:
volScalarField gD
(
    IOobject
    (
        "gD",
        runTime.timeName(),
        mesh,
        IOobject::READ_IF_PRESENT,
        IOobject::AUTO_WRITE
    ),
    mesh
);
Is this the approach you have been using, or do you do something completely different?
hef is offline   Reply With Quote

Old   April 6, 2021, 09:48
Default
  #7
New Member
 
Jérémy Chevalier
Join Date: Feb 2021
Posts: 4
Rep Power: 2
JeremyChvlr is on a distinguished road
Quote:
Originally Posted by hef View Post
If this thread is not dead, can I ask you how you got this to work? I tried the following, which gave the same error you got:

Code:
label patchID = mesh.boundaryMesh().findPatchID("topo");
wallDist wD(mesh, patchID, "wall");
gD = wD.y();
where gD is a volScalarField which I've set up earlier in the code:

Code:
volScalarField gD
(
    IOobject
    (
        "gD",
        runTime.timeName(),
        mesh,
        IOobject::READ_IF_PRESENT,
        IOobject::AUTO_WRITE
    ),
    mesh
);
Is this the approach you have been using, or do you do something completely different?

Hi all,
I have the same problem as you, has anyone found the solution? The function wallDist return a internalField equal to 1e+15.
Thank you !


Edit : In fact it was just a problem in the boundaries settings

Last edited by JeremyChvlr; April 7, 2021 at 06:02.
JeremyChvlr is online now   Reply With Quote

Old   April 8, 2021, 04:15
Lightbulb A Solution
  #8
hef
New Member
 
H Fossum
Join Date: Jan 2021
Posts: 3
Rep Power: 2
hef is on a distinguished road
I eventually found a working solution to this problem. I will post it here for future reference, even if no one may need it at the moment.

I set up a volScalarField, called gD, in the same way described in my earlier post. To calculate the distance to one specific wall, I do the following

Code:
label patchID = mesh.boundaryMesh().findPatchID("nameOfSpecificWall");
labelHashSet myPatchSet;
myPatchSet.insert(patchID);
wallDist wD(mesh, myPatchSet, "wall");
gD = wD.y();
In short, the trick to avoid spurious-number errors in the resulting field (gD) is to not use the patchID directly when constructing the wallDist object, but first make a labelHashSet and use that instead (which can be seen from the source code for the relevant wallDist constructor).

I also have a follow-up question, if anyone knows the answer: Is it possible to compute the distance to a wall using only one component of the distance, e.g. the z-direction? I tried directionalMeshWave, but that did not work as I was hoping.
hef is offline   Reply With Quote

Reply

Tags
distance, patch, vertical distance

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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
[snappyHexMesh] SnappyHexMesh running killed! Mark JIN OpenFOAM Meshing & Mesh Conversion 3 March 12, 2020 17:50
y+ and u+ values with low-Re RANS turbulence models: utility + testcase florian_krause OpenFOAM 113 June 25, 2019 00:58
[snappyHexMesh] sHM layer process keeps getting killed MBttR OpenFOAM Meshing & Mesh Conversion 4 August 15, 2016 03:21
[snappyHexMesh] snappyHexMesh won't work - zeros everywhere! sc298 OpenFOAM Meshing & Mesh Conversion 2 March 27, 2011 21:11
[snappyHexMesh] snappyHexMesh aborting Tobi OpenFOAM Meshing & Mesh Conversion 0 November 10, 2010 03:23


All times are GMT -4. The time now is 09:30.