CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Programming & Development (https://www.cfd-online.com/Forums/openfoam-programming-development/)
-   -   how to change a volScalarField in bc? (https://www.cfd-online.com/Forums/openfoam-programming-development/95866-how-change-volscalarfield-bc.html)

Fransje February 2, 2012 06:10

Quote:

Originally Posted by tomislav_maric (Post 342168)
From

OpenFOAM-1.6-ext/src/finiteVolume/fields/fvPatchFields/derived/parabolicVelocity

comes:

Code:

void parabolicVelocityFvPatchVectorField::updateCoeffs()
{
    if (updated())
    {
        return;
    }

    // Get range and orientation
    boundBox bb(patch().patch().localPoints(), true);

    vector ctr = 0.5*(bb.max() + bb.min());

    const vectorField& c = patch().Cf();

    // Calculate local 1-D coordinate for the parabolic profile
    scalarField coord = 2*((c - ctr) & y_)/((bb.max() - bb.min()) & y_);

    vectorField::operator=(n_*maxValue_*(1.0 - sqr(coord)));
}

This is called upcasting in C++: stripping the inherited object to the base class. All bcs are hidden *fields. No need for *_cast magic.

Just so you don't miss it , the key line is
Code:

vectorField::operator=  blah blah
, this converts "this" (the class, in this case parabolicBlah...) to a vectorField.

T.

Dear Tomislav,

Thank you for your contribution, but this is missing the point slightly.
The const_cast< > here is used to be able to change an object / variable in the database, which is of type const, so theoretically not modifiable.

Kind regards,

Francois.


All times are GMT -4. The time now is 08:16.