|
[Sponsors] |
January 6, 2017, 13:45 |
How to assign value to a single cell?
|
#1 |
Member
Oleg Sutyrin
Join Date: Feb 2016
Location: Russia
Posts: 41
Rep Power: 10 |
Hi!
I'm developing custom solver based on rhoCentralFoam. There I have three main fields initialized as follows: Code:
volScalarField& p = thermo.p(); const volScalarField& T = thermo.T(); volVectorField U ( IOobject ( "U", runTime.timeName(), mesh, IOobject::MUST_READ, IOobject::AUTO_WRITE ), mesh ); Code:
scalar tmpT, tmpP, tmpUx, tmpUy, tmpUz; Now I need to assign them them to cell subset, something like this: Code:
forAll (selectedCellSet, celli) { T[celli] = tmpT; p[celli] = tmpP; U[celli] = Vector(tmpUx, tmpUy, tmpUz); } |
|
January 6, 2017, 16:51 |
|
#2 |
Senior Member
Sergei
Join Date: Dec 2009
Posts: 261
Rep Power: 22 |
Code:
const volScalarField& T = thermo.T(); Code:
volScalarField& T = thermo.T(); |
|
January 6, 2017, 16:57 |
|
#3 |
Member
Oleg Sutyrin
Join Date: Feb 2016
Location: Russia
Posts: 41
Rep Power: 10 |
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? |
|
January 6, 2017, 17:44 |
|
#4 |
Senior Member
Sergei
Join Date: Dec 2009
Posts: 261
Rep Power: 22 |
Code:
volScalarField& T = thermo.T(); T.internalField() = tmpT; // for OF 3.0 //T.primitiveFieldRef() = tmpT; // for OF 4.0 |
|
January 7, 2017, 02:59 |
|
#5 |
Member
Oleg Sutyrin
Join Date: Feb 2016
Location: Russia
Posts: 41
Rep Power: 10 |
||
January 7, 2017, 04:58 |
|
#6 | |
Member
Oleg Sutyrin
Join Date: Feb 2016
Location: Russia
Posts: 41
Rep Power: 10 |
In addition to previous post:
Quote:
Code:
createFields.H:11:29: error: binding ‘const volScalarField {aka const Foam::GeometricField<double, Foam::fvPatchField, Foam::volMesh>}’ to reference of type ‘Foam::volScalarField& {aka Foam::GeometricField<double, Foam::fvPatchField, Foam::volMesh>&}’ discards qualifiers |
||
January 7, 2017, 05:36 |
|
#7 |
Member
Join Date: Mar 2014
Posts: 39
Rep Power: 12 |
Hey,
did you try it with a copy-process ? Code:
volScalarField T = thermo.T(); T.internalField()[celli] = value; 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. |
|
January 7, 2017, 08:02 |
|
#8 |
Member
Oleg Sutyrin
Join Date: Feb 2016
Location: Russia
Posts: 41
Rep Power: 10 |
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: Re-read basicPsiThermo from temperature file. |
|
January 7, 2017, 08:59 |
|
#9 | ||||
Senior Member
Sergei
Join Date: Dec 2009
Posts: 261
Rep Power: 22 |
Quote:
Code:
autoPtr<rhoThermo> thermoPtr = new rhoThermo(vfMesh); const rhoThermo& thermo = thermoPtr(); Code:
volScalarField& T = thermo.T(); Quote:
Code:
T.internalField() = tmpT ; Quote:
Code:
U[celli] = vector(Ux, Uy, Uz); Quote:
Code:
volScalarField T = thermo.T(); |
|||||
January 7, 2017, 09:21 |
|
#10 |
Member
Oleg Sutyrin
Join Date: Feb 2016
Location: Russia
Posts: 41
Rep Power: 10 |
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 ( basicPsiThermo::New(mesh) ); basicPsiThermo& thermo = 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'. |
|
January 7, 2017, 11:10 |
|
#11 | |
Senior Member
Sergei
Join Date: Dec 2009
Posts: 261
Rep Power: 22 |
Quote:
Code:
const Foam::volScalarField& Foam::basicThermo::T() const Meanwhile, you can try this little hacking: Code:
volScalarField& T = const_cast<volScalarField&> ( static_cast<const basicPsiThermo&>(thermo).T() ); |
||
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
[mesh manipulation] Generating a single cell mesh using a patch of a 3d mesh | kebsiali | OpenFOAM Meshing & Mesh Conversion | 3 | May 30, 2016 07:36 |
Journal file error | magicalmarshmallow | FLUENT | 3 | April 4, 2014 13:25 |
[Other] Single cubic cell (full case inc.) with det = 0. Why? :) | anothr_acc | OpenFOAM Meshing & Mesh Conversion | 1 | February 21, 2014 06:04 |
Help Me, what's the Cell Above in 3D. | gomane8 | Main CFD Forum | 0 | September 10, 2011 20:09 |