CFD Online Discussion Forums

CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   OpenFOAM Running, Solving & CFD (http://www.cfd-online.com/Forums/openfoam-solving/)
-   -   Understanding dimensionedScalar (http://www.cfd-online.com/Forums/openfoam-solving/59555-understanding-dimensionedscalar.html)

jaswi July 19, 2007 12:31

Hi OpenFOAM users I have tr
 
Hi OpenFOAM users

I have tried the following and do not understand why it doesn't works.

I have declared a dimensioned scalar, followed by a volVectorField. I need to change "X" component of the mesh.C() field by a constant value , i.e. ecentricity. after doing this operation when i print out the newCellCenter, I found that it hasn't changed.

dimensionedScalar excenter
(
"excenter",
dimensionSet(0,1,0,0,0,0,0),
scalar(3.0)
);


volVectorField newCellCentres = mesh.C();

newCellCentres.component(0) = (mesh.C().component(0) - excenter);
newCellCentres.component(1) = mesh.C().component(1);
newCellCentres.component(2) = mesh.C().component(2);

When I tried this in the creatField.H

volScalarField WALLPOS
(
IOobject
(
"WALLPOS",
runTime.timeName(),
mesh,
IOobject::NO_READ,
IOobject::AUTO_WRITE
),mesh.C().component(0) - excenter
);
It does writes the expected values.

What am I doing wrong !!!!

Please comment

With best Regards
Jaswinder

lr103476 July 19, 2007 13:40

Hi Jaswinder, I think that
 
Hi Jaswinder,

I think that you are not allowed to change the value of mesh.C(). That member function (found in fvMesh class) returns a const.

Frank

jaswi July 19, 2007 13:52

Hi Frank Is there any other
 
Hi Frank

Is there any other way I could save a volVectorField comprising of mesh.C() and then change one of its components and use it for further computations.

Thanks in advance
Regards
Jaswinder

jaswi July 19, 2007 14:08

Hi Frank I just wanted to
 
Hi Frank

I just wanted to inform that when i do the following

Info << "New X component "<< newCellCentres.component(0) -excenter <<endl;

where excenter = 3.0

then i do get as an output what i am expecting. Now i am wondering why is it not possible to do it as i have tried in my original post

Regards
Jaswinder

lr103476 July 19, 2007 16:04

Hi Jaswinder, What exactly
 
Hi Jaswinder,

What exactly do you want? You can't change the value of mesh.C() directly, instead you should create a volScalarField containing the x component and modify that field accordingly.

If your intention is to move the cell centres, you should create a pointField newPoints = mesh.points(), move those points using your excenter, update the mesh and your mesh.C() will be changed accordingly.

Regards, Frank

jaswi July 19, 2007 22:46

Thanks Frank It worked :-)
 
Thanks Frank

It worked :-)

By the way i do not need to move the mesh but your clue did solve my problem

Thanks once again

Regards
Jaswinder

chiven October 20, 2009 21:03

Hi, Foamers, I want to modify "dimensoionedScalar rho1_" to "const volScalarField& rho1_", how can I do it? Thank you very much. Chiven


\*---------------------------------------------------------------------------*/

#include "twoPhaseMixture.H"
#include "addToRunTimeSelectionTable.H"
#include "surfaceFields.H"
#include "fvc.H"

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

namespace Foam
{

// * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * * //

//- Calculate and return the laminar viscosity
void twoPhaseMixture::calcNu()
{
nuModel1_->correct();
nuModel2_->correct();

volScalarField limitedAlpha1
(
"limitedAlpha1",
min(max(alpha1_, scalar(0)), scalar(1))
);

// Average kinematic viscosity calculated from dynamic viscosity
nu_ = mu()/(limitedAlpha1*rho1_ + (scalar(1) - limitedAlpha1)*rho2_);
}


// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //

twoPhaseMixture::twoPhaseMixture
(
const volVectorField& U,
const surfaceScalarField& phi,
const word& alpha1Name
)
:
transportModel(U, phi),

phase1Name_("phase1"),
phase2Name_("phase2"),

nuModel1_
(
viscosityModel::New
(
"nu1",
subDict(phase1Name_),
U,
phi
)
),
nuModel2_
(
viscosityModel::New
(
"nu2",
subDict(phase2Name_),
U,
phi
)
),

rho1_(nuModel1_->viscosityProperties().lookup("rho")),
rho2_(nuModel2_->viscosityProperties().lookup("rho")),

U_(U),
phi_(phi),

alpha1_(U_.db().lookupObject<const volScalarField> (alpha1Name)),

nu_
(
IOobject
(
"nu",
U_.time().timeName(),
U_.db()
),
U_.mesh(),
dimensionedScalar("nu", dimensionSet(0, 2, -1, 0, 0), 0),
calculatedFvPatchScalarField::typeName
)
{
calcNu();
}


// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //

tmp<volScalarField> twoPhaseMixture::mu() const
{
volScalarField limitedAlpha1 = min(max(alpha1_, scalar(0)), scalar(1));

return tmp<volScalarField>
(
new volScalarField
(
"mu",
limitedAlpha1*rho1_*nuModel1_->nu()
+ (scalar(1) - limitedAlpha1)*rho2_*nuModel2_->nu()
)
);
}


tmp<surfaceScalarField> twoPhaseMixture::muf() const
{
surfaceScalarField alpha1f =
min(max(fvc::interpolate(alpha1_), scalar(0)), scalar(1));

return tmp<surfaceScalarField>
(
new surfaceScalarField
(
"muf",
alpha1f*rho1_*fvc::interpolate(nuModel1_->nu())
+ (scalar(1) - alpha1f)*rho2_*fvc::interpolate(nuModel2_->nu())
)
);
}


tmp<surfaceScalarField> twoPhaseMixture::nuf() const
{
surfaceScalarField alpha1f =
min(max(fvc::interpolate(alpha1_), scalar(0)), scalar(1));

return tmp<surfaceScalarField>
(
new surfaceScalarField
(
"nuf",
(
alpha1f*rho1_*fvc::interpolate(nuModel1_->nu())
+ (scalar(1) - alpha1f)*rho2_*fvc::interpolate(nuModel2_->nu())
)/(alpha1f*rho1_ + (scalar(1) - alpha1f)*rho2_)
)
);
}


bool twoPhaseMixture::read()
{
if (transportModel::read())
{
if
(
nuModel1_().read(subDict(phase1Name_))
&& nuModel2_().read(subDict(phase2Name_))
)
{
nuModel1_->viscosityProperties().lookup("rho") >> rho1_;
nuModel2_->viscosityProperties().lookup("rho") >> rho2_;

return true;
}
else
{
return false;
}
}
else
{
return false;
}
}


// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

} // End namespace Foam

// ************************************************** *********************** //

BielawskiR December 4, 2014 13:55

I believe that the root of why you couldn't change the component is because mesh.c is a actually two arrays added together, one that contains all the points (number of cells by 3) and then one array that is the dimensions (1 by 7). So if you looped through mesh.c so you where editing each cell one at a time it would work.


All times are GMT -4. The time now is 09:59.