|
[Sponsors] |
Selecting cell closest to coordinates (and setting its field value) |
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
May 13, 2019, 09:03 |
Selecting cell closest to coordinates (and setting its field value)
|
#1 |
New Member
Join Date: Mar 2019
Posts: 4
Rep Power: 7 |
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. |
|
May 13, 2019, 22:30 |
|
#2 | |
Senior Member
Join Date: Aug 2013
Posts: 407
Rep Power: 16 |
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 |
||
May 14, 2019, 06:15 |
|
#3 |
New Member
Join Date: Mar 2019
Posts: 4
Rep Power: 7 |
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 ); } ); |
|
|
|
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 |