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

assign values to selected cells

Register Blogs Community New Posts Updated Threads Search

Like Tree4Likes
  • 3 Post By niklas
  • 1 Post By zxj160

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   June 27, 2012, 06:29
Default assign values to selected cells
  #1
Senior Member
 
Jian Zhong
Join Date: Feb 2012
Location: Birmingham
Posts: 109
Rep Power: 14
zxj160 is on a distinguished road
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?
zxj160 is offline   Reply With Quote

Old   June 27, 2012, 07:19
Default
  #2
Super Moderator
 
niklas's Avatar
 
Niklas Nordin
Join Date: Mar 2009
Location: Stockholm, Sweden
Posts: 693
Rep Power: 29
niklas will become famous soon enoughniklas will become famous soon enough
check the Allrun-script in the tutorial
tutorials/multiphase/interFoam/ras/damBreak

what you're after is probably setFields and the setFieldsDict
niklas is offline   Reply With Quote

Old   June 27, 2012, 07:40
Default
  #3
Senior Member
 
Jian Zhong
Join Date: Feb 2012
Location: Birmingham
Posts: 109
Rep Power: 14
zxj160 is on a distinguished road
Quote:
Originally Posted by niklas View Post
check the Allrun-script in the tutorial
tutorials/multiphase/interFoam/ras/damBreak

what you're after is probably setFields and the setFieldsDict
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.
zxj160 is offline   Reply With Quote

Old   June 27, 2012, 07:53
Default
  #4
Super Moderator
 
niklas's Avatar
 
Niklas Nordin
Join Date: Mar 2009
Location: Stockholm, Sweden
Posts: 693
Rep Power: 29
niklas will become famous soon enoughniklas will become famous soon enough
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;
	#};
    }

}
and this is my topoSetDict

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;
	}
    }
);
[/code]
sharonyue, BlnPhoenix and wht like this.
niklas is offline   Reply With Quote

Old   June 29, 2012, 13:17
Default
  #5
Senior Member
 
Jian Zhong
Join Date: Feb 2012
Location: Birmingham
Posts: 109
Rep Power: 14
zxj160 is on a distinguished road
Quote:
Originally Posted by niklas View Post
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;
    #};
    }

}
and this is my topoSetDict

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;
    }
    }
);
[/code]
Many thanks. Actually, my purpose is to select the first layers near the inlet and outlet and then give values to them. Since the inlet and outlet are cyclic patches and they do not accept other type of BCs. Do you have this kind of experience?
wht likes this.
zxj160 is offline   Reply With Quote

Reply

Tags
selected cells


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] 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


All times are GMT -4. The time now is 21:56.