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 can I change the value of a face in a field? (https://www.cfd-online.com/Forums/openfoam-programming-development/222890-how-can-i-change-value-face-field.html)

sippanspojk December 12, 2019 11:44

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");

    forAll(myField.boundaryField()["defined patch"], faceIt){
        myField.boundaryField()["defined patch"][faceIt] == 1.0;
        Info << myField.boundaryField()["defined patch"][faceIt] << endl;
    }

The functionObject does compile but with a warning saying:

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

jherb December 12, 2019 15:49

[QUOTE=sippanspojk;752272]
Code:

        myField.boundaryField()["defined patch"][faceIt] == 1.0;
This compares your boundary field value with 1.0 and then throws away the result. You should use just one "=".

sippanspojk December 13, 2019 02:14

[QUOTE=jherb;752291]
Quote:

Originally Posted by sippanspojk (Post 752272)

This compares your boundary field value with 1.0 and then throws away the result. You should use just one "=".

Ok that makes sence actually. "==" returns either false or true and then moves on, right?


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?

einstein_zee December 16, 2019 05:03

Hii there,

Looks like you should use boundaryFieldRef() instead of boundaryField().

sippanspojk December 17, 2019 03:04

Quote:

Originally Posted by einstein_zee (Post 752520)
Hii there,

Looks like you should use boundaryFieldRef() instead of boundaryField().

Thanks Hosein, this helps!

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;

einstein_zee December 17, 2019 04:44

I think this one "lookupObjectRef()" should solve the issue. This means now you don't need "const" qualifier.

sippanspojk December 17, 2019 04:52

Quote:

Originally Posted by einstein_zee (Post 752609)
I think this one "lookupObjectRef()" should solve the issue. This means now you don't need "const" qualifier.

That did the trick!

Thank you very much for you quick and helpful response.


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