CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > OpenFOAM > OpenFOAM Running, Solving & CFD

looping over cells

Register Blogs Community New Posts Updated Threads Search

Like Tree2Likes
  • 1 Post By Chrisi1984
  • 1 Post By olesen

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   August 3, 2010, 09:42
Default looping over cells
  #1
Senior Member
 
Join Date: Jan 2010
Location: Stuttgart
Posts: 150
Rep Power: 16
Chrisi1984 is on a distinguished road
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?

Thanks in advance!

Best regards
Chrisi
mm.abdollahzadeh likes this.
Chrisi1984 is offline   Reply With Quote

Old   August 4, 2010, 06:55
Default
  #2
Senior Member
 
Mark Olesen
Join Date: Mar 2009
Location: https://olesenm.github.io/
Posts: 1,714
Rep Power: 40
olesen has a spectacular aura aboutolesen has a spectacular aura about
Quote:
Originally Posted by Chrisi1984 View Post
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.
olesen is offline   Reply With Quote

Old   August 4, 2010, 09:12
Default
  #3
Senior Member
 
Join Date: Jan 2010
Location: Stuttgart
Posts: 150
Rep Power: 16
Chrisi1984 is on a distinguished road
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
Chrisi1984 is offline   Reply With Quote

Old   August 4, 2010, 09:26
Default
  #4
Senior Member
 
Mark Olesen
Join Date: Mar 2009
Location: https://olesenm.github.io/
Posts: 1,714
Rep Power: 40
olesen has a spectacular aura aboutolesen has a spectacular aura about
Quote:
Originally Posted by Chrisi1984 View Post
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;
        }
    }
}
mm.abdollahzadeh likes this.
olesen is offline   Reply With Quote

Old   August 5, 2010, 03:44
Default
  #5
Senior Member
 
Join Date: Jan 2010
Location: Stuttgart
Posts: 150
Rep Power: 16
Chrisi1984 is on a distinguished road
Thank you again.

I changed it.

Regards
Chrisi
Chrisi1984 is offline   Reply With Quote

Reply


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
[Netgen] Import netgen mesh to OpenFOAM hsieh OpenFOAM Meshing & Mesh Conversion 32 September 13, 2011 06:50
[snappyHexMesh] external flow with snappyHexMesh chelvistero OpenFOAM Meshing & Mesh Conversion 11 January 15, 2010 20:43
physical boundary error!! kris Siemens 2 August 3, 2005 01:32
problem while looping over cells in LES Jimmy FLUENT 0 September 5, 2002 16:33
Looping over cells Karl FLUENT 4 March 26, 2002 22:18


All times are GMT -4. The time now is 11:15.