# looping over cells

 User Name Remember Me Password
 Register Blogs Members List Search Today's Posts Mark Forums Read

August 3, 2010, 08:42
looping over cells
#1
Senior Member

Join Date: Jan 2010
Location: Stuttgart
Posts: 150
Rep Power: 16
Hi all,

I am using the chtMultiRegionSimpleFoam solver.
I want to define different properties (cp, K, rho) for different zones of my solid.
Therefor I edited the "solveSolid.H"-file in this way:

Quote:
 { for (int nonOrth=0; nonOrth<=nNonOrthCorr; nonOrth++) { fvScalarMatrix tEqn ( -fvm::laplacian(K, T) ); tEqn.relax(); eqnResidual = tEqn.solve().initialResidual(); maxResidual = max(eqnResidual, maxResidual); } Info<< "Min/max T:" << min(T).value() << ' ' << max(T).value() << endl; ////////////////////////////////////// forAll(solidRegions[i].cellZones(), iZone) //loop over all cellZones { if (solidRegions[i].cellZones()[iZone].name() == "s-oc") //with "bla" being name of porous cellZone { forAll(solidRegions[i].cellZones()[iZone], iCell) //loop over all cells in Zone { cp=cp0_1+cp1_1*T+cp2_1*T*T; K=K0_1+K1_1*T+K2_1*T*T; rho=rho_1; } } if (solidRegions[i].cellZones()[iZone].name() == "s-outer-jacket") //with "bla" being name of porous cellZone { forAll(solidRegions[i].cellZones()[iZone], iCell) //loop over all cells in Zone { cp=cp0_1+cp1_1*T+cp2_1*T*T; K=K0_1+K1_1*T+K2_1*T*T; rho=rho_1; } } if (solidRegions[i].cellZones()[iZone].name() == "s-insu-mat") //with "bla" being name of porous cellZone { forAll(solidRegions[i].cellZones()[iZone], iCell) //loop over all cells in Zone { cp=cp0_3; K=K0_3+K1_3*T+K2_3*T*T; rho=rho_2; } } if (solidRegions[i].cellZones()[iZone].name() == "s-inner-jacket") //with "bla" being name of porous cellZone { forAll(solidRegions[i].cellZones()[iZone], iCell) //loop over all cells in Zone { cp=cp0_1+cp1_1*T+cp2_1*T*T; K=K0_1+K1_1*T+K2_1*T*T; rho=rho_1; } } if (solidRegions[i].cellZones()[iZone].name() == "s-sm2") //with bla being name of porous cellZone { forAll(solidRegions[i].cellZones()[iZone], iCell) //loop over all cells in Zone { cp=cp0_3; K=K0_2+K1_2*T+K2_2*T*T; rho=rho_2; } } if (solidRegions[i].cellZones()[iZone].name() == "s-sm1") //with bla being name of porous cellZone { forAll(solidRegions[i].cellZones()[iZone], iCell) //loop over all cells in Zone { cp=cp0_3; K=K0_2+K1_2*T+K2_2*T*T; rho=rho_2; } } if (solidRegions[i].cellZones()[iZone].name() == "s-ic-oj") //with bla being name of porous cellZone { forAll(solidRegions[i].cellZones()[iZone], iCell) //loop over all cells in Zone { cp=cp0_1+cp1_1*T+cp2_1*T*T; K=K0_1+K1_1*T+K2_1*T*T; rho=rho_1; } } if (solidRegions[i].cellZones()[iZone].name() == "s-ic-ij") //with bla being name of porous cellZone { forAll(solidRegions[i].cellZones()[iZone], iCell) //loop over all cells in Zone { cp=cp0_1+cp1_1*T+cp2_1*T*T; K=K0_1+K1_1*T+K2_1*T*T; rho=rho_1; } } if (solidRegions[i].cellZones()[iZone].name() == "s-ip") //with bla being name of porous cellZone { forAll(solidRegions[i].cellZones()[iZone], iCell) //loop over all cells in Zone { cp=cp0_1+cp1_1*T+cp2_1*T*T; K=K0_1+K1_1*T+K2_1*T*T; rho=rho_1; } } } ///////////////////////////////////// }
I derive the parameters by an aditional dict. The solver compiles without any probleme.
But when I start the simulation, it lasts very long to solve my solid region. I think the loops are responsible for that.
An additinal problem is that, that the values for cp, K and rho are not calculated different in the different zones.

Is there a mistake in my loops construction?

Is there a better alternative to calculate the properties different in different zones of the solid instead of my loops over all cells, which lasts so long?

Best regards
Chrisi

August 4, 2010, 05:55
#2
Senior Member

Mark Olesen
Join Date: Mar 2009
Location: https://olesenm.github.io/
Posts: 1,709
Rep Power: 40
Quote:
 Originally Posted by Chrisi1984 Hi all, I am using the chtMultiRegionSimpleFoam solver. I want to define different properties (cp, K, rho) for different zones of my solid. Therefor I edited the "solveSolid.H"-file in this way: I derive the parameters by an aditional dict. The solver compiles without any probleme. But when I start the simulation, it lasts very long to solve my solid region. I think the loops are responsible for that. An additinal problem is that, that the values for cp, K and rho are not calculated different in the different zones. Is there a mistake in my loops construction? Is there a better alternative to calculate the properties different in different zones of the solid instead of my loops over all cells, which lasts so long? Thanks in advance! Best regards Chrisi

There are a number of problems. From what you write, you are trying to adjust the entire fields (rho, cp, K) within each loop and using entire fields for everything (including T) instead of doing it element-wise. This would certainly slow things down a lot, and probably is not what you want.

If you didn't make any other changes, you also have cp defined as const volScalarField& , so I don't see how any of it actually compiled at all.

August 4, 2010, 08:12
#3
Senior Member

Join Date: Jan 2010
Location: Stuttgart
Posts: 150
Rep Power: 16
Thank you for your hint!

I now did it this way

Quote:
 forAll (solidRegions[i].cellZones(), zoneI) { if (solidRegions[i].cellZones()[zoneI].name() == ("s-oc")) //with "bla" being name cellZone { forAll(solidRegions[i].cellZones()[zoneI], iCells) //loop over all cells in Zone { cp[solidRegions[i].cellZones()[zoneI][iCells]]=380.68+0.35536*T[solidRegions[i].cellZones()[zoneI][iCells]]-0.00012713*T[solidRegions[i].cellZones()[zoneI][iCells]]*T[solidRegions[i].cellZones()[zoneI][iCells]]; K[solidRegions[i].cellZones()[zoneI][iCells]]=9.6995954+0.017429246*T[solidRegions[i].cellZones()[zoneI][iCells]]-2.0551036e-06*T[solidRegions[i].cellZones()[zoneI][iCells]]*T[solidRegions[i].cellZones()[zoneI][iCells]]; rho[solidRegions[i].cellZones()[zoneI][iCells]]=7920; } } }
It seems running correctly and much faster than before.

Best regards

Chrisi

August 4, 2010, 08:26
#4
Senior Member

Mark Olesen
Join Date: Mar 2009
Location: https://olesenm.github.io/
Posts: 1,709
Rep Power: 40
Quote:
 Originally Posted by Chrisi1984 Thank you for your hint! I now did it this way It seems running correctly and much faster than before.
For readability, don't be afraid to use intermediate variables. Most of them should be optimized away anyhow. For example,
Code:
```forAll(solidRegions[i].cellZones(), zoneI)
{
const cellZone& cz = solidRegions[i].cellZones()[zoneI];
const labelList& cells = cz;

if (cz.name() == "s-oc")
{
forAll(cells, iCells)
{
const label cellId = cells[iCells];
const scalar& cellT = T[cellId];

cp[cellId] = 380.68 + cellT * (0.35536 - 0.00012713 * cellT);
K[cellId] = 9.6995954 + cellT * (0.017429246 - 2.0551036e-06 * cellT);
rho[cellId] = 7920;
}
}
}```

 August 5, 2010, 02:44 #5 Senior Member   Join Date: Jan 2010 Location: Stuttgart Posts: 150 Rep Power: 16 Thank you again. I changed it. Regards Chrisi

 Thread Tools Search this Thread Search this Thread: Advanced Search Display Modes Linear Mode

 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 OffTrackbacks are Off Pingbacks are On Refbacks are On Forum Rules

 Similar Threads Thread Thread Starter Forum Replies Last Post [Netgen] Import netgen mesh to OpenFOAM hsieh OpenFOAM Meshing & Mesh Conversion 32 September 13, 2011 05:50 [snappyHexMesh] external flow with snappyHexMesh chelvistero OpenFOAM Meshing & Mesh Conversion 11 January 15, 2010 19:43 kris Siemens 2 August 3, 2005 00:32 Jimmy FLUENT 0 September 5, 2002 15:33 Karl FLUENT 4 March 26, 2002 21:18

All times are GMT -4. The time now is 23:44.

 Contact Us - CFD Online - Privacy Statement - Top