|
[Sponsors] |
How can I change the value of a face in a field? |
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
December 12, 2019, 12:44 |
How can I change the value of a face in a field?
|
#1 |
Member
David Andersson
Join Date: Oct 2019
Posts: 46
Rep Power: 7 |
Dear foamers, I need your help!
As the title says I am trying to change the value of the faces of a defined patch. I have modified the pimpleFoam solver to generate a dimensionless volScalarField that I have initialized to 0.0. I would then like to within a functionObject loop over the faces of the desired patch and assign a specific value to each face. As I start I did a very simple case where I wanted to try to change the initial value 0.0 to 1.0 but that didn't work. In my myFunctionObject.C file I have the following code Code:
const volScalarField& myField = lookupObject<volScalarField>("myField"); forAll(myField.boundaryField()["defined patch"], faceIt){ myField.boundaryField()["defined patch"][faceIt] == 1.0; Info << myField.boundaryField()["defined patch"][faceIt] << endl; } myFunctionObject.C:178:41: warning: value computed is not used [-Wunused-value] myField.boundaryField()[6][faceIt] == 1.0; When I then run the case the output is still 0 and not 1 as I was hoping for. Can someone help me whit this one?? Thank you! David |
|
December 12, 2019, 16:49 |
|
#2 |
Senior Member
Joachim Herb
Join Date: Sep 2010
Posts: 650
Rep Power: 22 |
[QUOTE=sippanspojk;752272]
Code:
myField.boundaryField()["defined patch"][faceIt] == 1.0; |
|
December 13, 2019, 03:14 |
|
#3 | |
Member
David Andersson
Join Date: Oct 2019
Posts: 46
Rep Power: 7 |
[QUOTE=jherb;752291]
Quote:
I tried it out with only one "=" and then I couldn't compile my functionObject. I got the following error message: myFunctionObject.C:178:41: error: assignment of read-only location '(&(&(& myField)->Foam::GeometricField<Type, PatchField, GeoMesh>::boundaryField<double, Foam::fvPatchField, Foam::volMesh>())->Foam::GeometricField<double, Foam::fvPatchField, Foam::volMesh>::Boundary::<anonymous>.Foam::FieldF ield<Foam::fvPatchField, double>::<anonymous>.Foam::PtrList<Foam::fvPatchFi eld<double> >::<anonymous>.Foam::UPtrList<T>:perator[]<Foam::fvPatchField<double> >(6))->Foam::fvPatchField<double>::<anonymous>.Foam::Fie ld<double>::<anonymous>.Foam::List<double>::<anony mous>.Foam::UList<T>:perator[]<double>(faceIt)' myField.boundaryField()[6][faceIt] = 1.0; Any idea of what this means? |
||
December 16, 2019, 06:03 |
|
#4 |
Member
Hosein
Join Date: Nov 2011
Location: Germany
Posts: 94
Rep Power: 15 |
Hii there,
Looks like you should use boundaryFieldRef() instead of boundaryField(). |
|
December 17, 2019, 04:04 |
|
#5 | |
Member
David Andersson
Join Date: Oct 2019
Posts: 46
Rep Power: 7 |
Quote:
However, only if I modify the solver and change the boundary value from there. But If I take the exact same row in my functionObject it complains: myFunctionObject.C:179:34: error: passing ‘const volScalarField {aka const Foam::GeometricField<double, Foam::fvPatchField, Foam::volMesh>}’ as ‘this’ argument of ‘Foam::GeometricField<Type, PatchField, GeoMesh>::Boundary& Foam::GeometricField<Type, PatchField, GeoMesh>::boundaryFieldRef() [with Type = double; PatchField = Foam::fvPatchField; GeoMesh = Foam::volMesh]’ discards qualifiers [-fpermissive] myField.boundaryFieldRef()[patchIt][faceIt] = 1.0; |
||
December 17, 2019, 05:44 |
|
#6 |
Member
Hosein
Join Date: Nov 2011
Location: Germany
Posts: 94
Rep Power: 15 |
I think this one "lookupObjectRef()" should solve the issue. This means now you don't need "const" qualifier.
|
|
December 17, 2019, 05:52 |
|
#7 |
Member
David Andersson
Join Date: Oct 2019
Posts: 46
Rep Power: 7 |
||
Tags |
functionobject, volscalarfield |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
[blockMesh] Internal walls of zero thickness | anger | OpenFOAM Meshing & Mesh Conversion | 23 | February 6, 2020 19:25 |
[mesh manipulation] Importing Multiple Meshes | thomasnwalshiii | OpenFOAM Meshing & Mesh Conversion | 18 | December 19, 2015 19:57 |
change velocity field | LM4112 | OpenFOAM Running, Solving & CFD | 12 | February 5, 2014 12:56 |
[blockMesh] non-orthogonal faces and incorrect orientation? | nennbs | OpenFOAM Meshing & Mesh Conversion | 7 | April 17, 2013 06:42 |
Error message: 8 face(s) not in face lists of adjacent cells | jyoung79 | FLUENT | 0 | November 10, 2012 17:09 |