|
[Sponsors] | |||||
Selecting cell closest to coordinates (and setting its field value) |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
|
|
|
#1 |
|
New Member
Join Date: Mar 2019
Posts: 4
Rep Power: 8 ![]() |
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
(
);
// ************************************************************************* //
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 ) 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. |
|
|
|
|
|
|
|
|
#2 | |
|
Senior Member
Join Date: Aug 2013
Posts: 407
Rep Power: 17 ![]() |
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:
Cheers, Antimony |
||
|
|
|
||
|
|
|
#3 |
|
New Member
Join Date: Mar 2019
Posts: 4
Rep Power: 8 ![]() |
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
);
}
);
|
|
|
|
|
|
|
|
|
#4 |
|
New Member
Hansjoerg Seybold
Join Date: Mar 2009
Posts: 16
Rep Power: 18 ![]() |
Hi,
I know this is a very old thread, but I could not find a valid solution to a very related the question, namely finding the cell(s) containing points (given by their coordinates). The suggested solution "nearestToCell" is only valid for isotropic meshes as nearestToCell finds the Cell whose cell-center is closest to the given point. In anisotropic meshes, with big and small cells next to each other, it can happen that the closest cell center of a point is not the cell containing the point, but a neighboring cell. Thus I am still looking for a way to select the cell(s) by a list of coordinates. (a cell is marked if any of the points is inside the cell) Thanks a lot! |
|
|
|
|
|
|
|
|
#5 |
|
New Member
anonymous.
Join Date: Jan 2020
Posts: 18
Rep Power: 7 ![]() |
Hi hansjoerg
I think the simplest method is to use BoxToCell, which select cells based on cell centres inside box(es). There is another more complex method, if you look at the source file of nearestToCell, you will find the following code void Foam::nearestToCell::combine(topoSet& set, const bool add) const { forAll(points_, pointi) { addOrDelete(set, mesh_.findNearestCell(points_[pointi]), add); } } It actually calls the findNearestCell function, which is located in the meshSearch. H file. In fact, the file also has a function called findCell //- Find cell containing location. // If seed provided walks and falls back to linear/tree search. // (so handles holes correctly)s // Returns -1 if not in domain. label findCell ( const point& location, const label seedCelli = -1, const bool useTreeSearch = true ) const; I think you can try manually modifying the code to meet your needs |
|
|
|
|
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|
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 |