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

Selecting cell closest to coordinates (and setting its field value)

Register Blogs Community New Posts Updated Threads Search

Like Tree1Likes
  • 1 Post By Antimony

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   May 13, 2019, 09:03
Default Selecting cell closest to coordinates (and setting its field value)
  #1
New Member
 
Join Date: Mar 2019
Posts: 4
Rep Power: 7
rando_foamer is on a distinguished road
Hi all,

I am wondering how to go about doing the following, and hope someone can help. I've been trying to find a solution using setFields and funkySetFields, but can't find the right approach.

I want to modify the initial condition of a single cell in my geometry, and I want to select this cell based off its proximity to a provided set of coordinates e.g. (x=0.5,y=1.0,z=0.5). This set of coordinates will be close to, but not necessarily directly on, a patch face. For example, given the following simple box as described by this blockMeshDict:

Code:
/*--------------------------------*- C++ -*----------------------------------*\
| =========                 |                                                 |
| \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox           |
|  \\    /   O peration     | Version:  5                                     |
|   \\  /    A nd           | Web:      www.OpenFOAM.org                      |
|    \\/     M anipulation  |                                                 |
\*---------------------------------------------------------------------------*/
FoamFile
{
    version     2.0;
    format      ascii;
    class       dictionary;
    object      blockMeshDict;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

convertToMeters 1;

vertices
(   
    (0 0 0)
    (1 0 0) 
    (1 1 0) 
    (0 1 0)
    (0 0 1)
    (1 0 1) 
    (1 1 1) 
    (0 1 1)
);

blocks
(
    hex (0 1 2 3 4 5 6 7) (3 6 100) simpleGrading (1 1 1)
    
);

edges
(
    
);

boundary
(
    inlet
    {
        type patch;
        faces
        (
          (0 1 2 3)
        );
    }
    
    outlet
    {
        type wall;
        faces
        (
          (7 6 5 4)
        );
    }
    
    defaultFaces
    {
        type empty;
        faces ();
    }
    
);

mergePatchPairs
(
);

// ************************************************************************* //
This is obviously a box of dimensions (1 1 1) with a single block.

Ideally I would do this completely in setFields, by finding the cell that has its centre closest to the coordinates (0.5 1.0 0.5), then set its value for my volScalarField (e.g. T). I would not necessarily know what the coordinates were prior to runtime (they would be defined by some other code) and so can't manually create a block specifically for the location.

From what I can gather, there is no "coordinatesToCell" function in setFields, i.e. the choices are:

Code:
(
boundaryToFace
boxToCell
boxToFace
boxToPoint
cellToCell
cellToFace
cellToPoint
cylinderAnnulusToCell
cylinderToCell
faceToCell
faceToFace
faceToPoint
faceZoneToCell
faceZoneToFaceZone
fieldToCell
labelToCell
labelToFace
labelToPoint
nbrToCell
nearestToCell
nearestToPoint
normalToFace
patchToFace
pointToCell
pointToFace
pointToPoint
regionToCell
rotatedBoxToCell
setToCellZone
setToFaceZone
setToPointZone
setsToFaceZone
shapeToCell
sphereToCell
surfaceToCell
surfaceToPoint
zoneToCell
zoneToFace
zoneToPoint
)
The closest I can find is the "pointTo*" and "nearestToCell" functions. But from what I understand, I would need to provide a point reference, not coordinates. I don't think I can use "boxToCell" without knowing beforehand what the cell size was, so I didn't accidentally select more than one cell (or zero cells). I'm also not sure what many of the above options actually do (descriptions are very vague in places).

At the moment I am contemplating creating a Python script that finds the face that is nearest to the given coordinates (calculating the average of face points from the polyMesh folder), then using the "faceToCell" function in setFields.

Hopefully there's a better way!

Thanks all for your help.
rando_foamer is offline   Reply With Quote

Old   May 13, 2019, 22:30
Default
  #2
Senior Member
 
Join Date: Aug 2013
Posts: 407
Rep Power: 16
Antimony is on a distinguished road
Hi,

Doesn't nearestToCell do exactly what you want it to do? From https://github.com/OpenFOAM/OpenFOAM...et/topoSetDict, what it says is this:

Quote:
// // Cells with cellCentre nearest to coordinates
// source nearestToCell;
// sourceInfo
// {
// points ((0 0 0) (1 1 1)(2 2 2));
// }
So, if you replace the points in the example with your own, should work I think. No?

Cheers,
Antimony
xiangxiang likes this.
Antimony is offline   Reply With Quote

Old   May 14, 2019, 06:15
Default
  #3
New Member
 
Join Date: Mar 2019
Posts: 4
Rep Power: 7
rando_foamer is on a distinguished road
Aha, you are right, of course. I had the syntax wrong, and I misunderstood the error message.

For those interested, the correct syntax to use for the setFieldsDict (rather than topoSetDict) is as follows:

Code:
/*--------------------------------*- C++ -*----------------------------------*\
| =========                 |                                                 |
| \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox           |
|  \\    /   O peration     | Version:  v1812                                 |
|   \\  /    A nd           | Web:      www.OpenFOAM.com                      |
|    \\/     M anipulation  |                                                 |
\*---------------------------------------------------------------------------*/
FoamFile
{
    version     2.0;
    format      ascii;
    class       dictionary;
    location    "system";
    object      setFieldsDict;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

defaultFieldValues
(
  volScalarFieldValue T 0
);

regions
(
nearestToCell
{
  points ( (0.5 1.0 0.5) );
  fieldValues
    (
      volScalarFieldValue T 1.0
    );
}
);
Thanks Antimony, much appreciated.
rando_foamer 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
Setting BC for each cell on face Geisel Fluent UDF and Scheme Programming 3 July 2, 2010 03:52


All times are GMT -4. The time now is 07:12.