How can I change the value of a face in a field?
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"); 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 |
[QUOTE=sippanspojk;752272]
Code:
myField.boundaryField()["defined patch"][faceIt] == 1.0; |
[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>::operator[]<Foam::fvPatchField<double> >(6))->Foam::fvPatchField<double>::<anonymous>.Foam::Fie ld<double>::<anonymous>.Foam::List<double>::<anony mous>.Foam::UList<T>::operator[]<double>(faceIt)' myField.boundaryField()[6][faceIt] = 1.0; Any idea of what this means? |
Hii there,
Looks like you should use boundaryFieldRef() instead of boundaryField(). |
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; |
I think this one "lookupObjectRef()" should solve the issue. This means now you don't need "const" qualifier.
|
Quote:
Thank you very much for you quick and helpful response. |
All times are GMT -4. The time now is 08:47. |