How to assign value to a single cell?
Hi!
I'm developing custom solver based on rhoCentralFoam. There I have three main fields initialized as follows: Code:
volScalarField& p = thermo.p(); Code:
Now I need to assign them them to cell subset, something like this: Code:
forAll (selectedCellSet, celli) |
Code:
const volScalarField& T = thermo.T(); Code:
volScalarField& T = thermo.T(); |
Thanks, Zeppo! That solved the problem with 'assignment of read-only location'.
The main question still stands: how to assign scalar value to T[celli]? Maybe somehow through dimensionedScalar / dimensionedVector construction? |
Code:
volScalarField& T = thermo.T(); |
Quote:
And what is the correct syntax for U[celli], which is vector? |
In addition to previous post:
Quote:
Code:
createFields.H:11:29: error: binding ‘const volScalarField |
Hey,
did you try it with a copy-process ? Code:
volScalarField T = thermo.T(); Otherwise you can try to assign a non dimensioned scalar with: Code:
T.internalField()[celli].value() = value; You will need a volVectorField to assign a vector or a dimensionedVector to it. In addition you can assign single vector components by the functions vector.x() or vector.y() or vector.z(). Please note that this can vary depending on the OF versions you use. |
Thanks, Traction!
The first way compiles OK in foam-extend 3.2 (which is based on OF 3, I believe). It generates some weird patchy field value assignments, which is probably have no relation to this thread (some errors in cell indexes, probably). For now I'm abandoning this approach in favor of re-using some part of setFields code, which is much simpler. I've posted some problems I have with it in another thread: https://www.cfd-online.com/Forums/op...tml#post632372 |
Quote:
Code:
autoPtr<rhoThermo> thermoPtr = new rhoThermo(vfMesh); Code:
volScalarField& T = thermo.T(); Quote:
Code:
T.internalField() = tmpT ; Quote:
Code:
U[celli] = vector(Ux, Uy, Uz); Quote:
Code:
volScalarField T = thermo.T(); |
Zeppo, thanks again for such an elaborate answer!
The thing that puzzles me is that pThermo is created as non-const: Code:
autoPtr<basicPsiThermo> pThermo And I agree, the copy of my 'thermo.T' would be useless for me since I need to update 'rho', which is derived 'thermo'. |
Quote:
Code:
const Foam::volScalarField& Foam::basicThermo::T() const Meanwhile, you can try this little hacking: Code:
volScalarField& T = const_cast<volScalarField&> |
All times are GMT -4. The time now is 10:31. |