|
[Sponsors] |
June 27, 2012, 06:29 |
assign values to selected cells
|
#1 |
Senior Member
Jian Zhong
Join Date: Feb 2012
Location: Birmingham
Posts: 109
Rep Power: 14 |
Does anyone have the experience to set values to selected cells.
How to check the x y z coordinates of the grid points and store their ID in an array? With the ID, I may then set the values of them by direct assignment? |
|
June 27, 2012, 07:19 |
|
#2 |
Super Moderator
Niklas Nordin
Join Date: Mar 2009
Location: Stockholm, Sweden
Posts: 693
Rep Power: 29 |
check the Allrun-script in the tutorial
tutorials/multiphase/interFoam/ras/damBreak what you're after is probably setFields and the setFieldsDict |
|
June 27, 2012, 07:40 |
|
#3 |
Senior Member
Jian Zhong
Join Date: Feb 2012
Location: Birmingham
Posts: 109
Rep Power: 14 |
Thanks. Is it possible to store a list of cells and defined value for them? I also want to the stored list unchanged (NO_WRITE) when calculated each time step.
|
|
June 27, 2012, 07:53 |
|
#4 |
Super Moderator
Niklas Nordin
Join Date: Mar 2009
Location: Stockholm, Sweden
Posts: 693
Rep Power: 29 |
sounds like you should use topoSet and setsToZones to create a cell-selection then.
and you can use the code option in functionObjects to do whatever you want with that selection here's my controlDict for doing some averaging over certain cell-selections (and to calculate total pressure drop) that should get you started Code:
functions { cuttingAverage { type coded; functionObjectLibs ( "libutilityFunctionObjects.so" ); redirectType average; //outputControl timeStep; code #{ vector normal(1.0, 0.0, 0.0); const volScalarField& T = mesh().lookupObject<volScalarField>("T"); const labelList& ids = mesh().cellZones().findIndices("docInlet"); scalar Tav = 0.0; scalar Tdev = 0.0; scalar vol = 0.0; forAll(ids, i) { const labelList& cells = mesh().cellZones()[ids[i]]; forAll(cells, j) { label celli = cells[j]; scalar V = mesh().V()[celli]; vol += V; Tav += T[celli]*V; } } reduce(vol, sumOp<scalar>()); reduce(Tav, sumOp<scalar>()); Tav /= vol + VSMALL; forAll(ids, i) { const labelList& cells = mesh().cellZones()[ids[i]]; forAll(cells, j) { label celli = cells[j]; scalar V = mesh().V()[celli]; Tdev += sqr(T[celli]-Tav)*V; } } reduce(Tdev, sumOp<scalar>()); Tdev /= vol + VSMALL; Tdev = sqrt(Tdev); Info << "T avg = " << Tav << ", dev = " << Tdev << endl; Info << "T min/max = " << min(T).value() << ", " << max(T).value() << endl; const volScalarField& p = mesh().lookupObject<volScalarField>("p"); const volScalarField& rho = mesh().lookupObject<volScalarField>("rho"); const volVectorField& U = mesh().lookupObject<volVectorField>("U"); volScalarField pTot = p + 0.5*rho*(U&U); label inletID = mesh().boundaryMesh().findPatchID("STL_inlet"); label outletID = mesh().boundaryMesh().findPatchID("STL_outlet"); scalar areaIn = sum(mag(mesh().boundaryMesh()[inletID].faceAreas())); reduce(areaIn, sumOp<scalar>()); scalar areaOut = sum(mag(mesh().boundaryMesh()[outletID].faceAreas())); reduce(areaOut, sumOp<scalar>()); scalar pTotIn = sum(pTot.boundaryField()[inletID]*mag(mesh().boundaryMesh()[inletID].faceAreas())); reduce(pTotIn, sumOp<scalar>()); scalar pTotOut = sum(pTot.boundaryField()[outletID]*mag(mesh().boundaryMesh()[outletID].faceAreas())); reduce(pTotOut, sumOp<scalar>()); Info << "pressure drop: " << pTotIn/areaIn - pTotOut/areaOut << " in: " << pTotIn/areaIn << " out: " << pTotOut/areaOut << endl; vector Uav = vector::zero; forAll(ids, i) { const labelList& cells = mesh().cellZones()[ids[i]]; forAll(cells, j) { label celli = cells[j]; scalar V = mesh().V()[celli]; Uav += U[celli]*V; } } reduce(Uav, sumOp<vector>()); Uav /= vol + VSMALL; scalar Uavn = Uav & normal; scalar Udevn = 0.0; forAll(ids, i) { const labelList& cells = mesh().cellZones()[ids[i]]; forAll(cells, j) { label celli = cells[j]; scalar V = mesh().V()[celli]; scalar Un = U[celli] & normal; Udevn += (Un - Uavn)*(Un - Uavn)*V; } } reduce(Udevn, sumOp<scalar>()); Udevn /= vol*Uavn + VSMALL; Udevn = sqrt(mag(Udevn)); Info << "Udevn = " << Udevn << endl; #}; } } Code:
actions ( { name doc; action new ; type cellSet; source cylinderToCell; sourceInfo { p1 ( 0.0 0.0 0.553); p2 ( 0.0 0.0 0.656); radius 0.17; } } { name docInlet; action new ; type cellSet; source cylinderToCell; sourceInfo { p1 ( 0.0 0.0 0.553); p2 ( 0.0 0.0 0.557); radius 0.17; } } ); |
|
June 29, 2012, 13:17 |
|
#5 | |
Senior Member
Jian Zhong
Join Date: Feb 2012
Location: Birmingham
Posts: 109
Rep Power: 14 |
Quote:
|
||
Tags |
selected cells |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
[snappyHexMesh] No layers in a small gap | bobburnquist | OpenFOAM Meshing & Mesh Conversion | 6 | August 26, 2015 10:38 |
Range of wall y+ values | rks171 | Main CFD Forum | 1 | January 4, 2012 17:54 |
[snappyHexMesh] external flow with snappyHexMesh | chelvistero | OpenFOAM Meshing & Mesh Conversion | 11 | January 15, 2010 20:43 |
strange node values @ solid/fluid interface - help | JB | FLUENT | 2 | November 1, 2008 13:04 |
node values or cell values? | aPpA | FLUENT | 0 | November 10, 2006 09:56 |