CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > OpenFOAM > OpenFOAM Programming & Development

How can I change the value of a face in a field?

Register Blogs Members List Search Today's Posts Mark Forums Read

Like Tree3Likes
  • 2 Post By einstein_zee
  • 1 Post By einstein_zee

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   December 12, 2019, 12:44
Default How can I change the value of a face in a field?
  #1
Member
 
David Andersson
Join Date: Oct 2019
Posts: 46
Rep Power: 6
sippanspojk is on a distinguished road
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
sippanspojk is offline   Reply With Quote

Old   December 12, 2019, 16:49
Default
  #2
Senior Member
 
Joachim Herb
Join Date: Sep 2010
Posts: 650
Rep Power: 21
jherb is on a distinguished road
[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 "=".
jherb is offline   Reply With Quote

Old   December 13, 2019, 03:14
Default
  #3
Member
 
David Andersson
Join Date: Oct 2019
Posts: 46
Rep Power: 6
sippanspojk is on a distinguished road
[QUOTE=jherb;752291]
Quote:
Originally Posted by sippanspojk View Post

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>: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?
sippanspojk is offline   Reply With Quote

Old   December 16, 2019, 06:03
Default
  #4
Member
 
Hosein
Join Date: Nov 2011
Location: Germany
Posts: 93
Rep Power: 14
einstein_zee is on a distinguished road
Hii there,

Looks like you should use boundaryFieldRef() instead of boundaryField().
jherb and Tobi like this.
einstein_zee is offline   Reply With Quote

Old   December 17, 2019, 04:04
Default
  #5
Member
 
David Andersson
Join Date: Oct 2019
Posts: 46
Rep Power: 6
sippanspojk is on a distinguished road
Quote:
Originally Posted by einstein_zee View Post
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;
sippanspojk is offline   Reply With Quote

Old   December 17, 2019, 05:44
Default
  #6
Member
 
Hosein
Join Date: Nov 2011
Location: Germany
Posts: 93
Rep Power: 14
einstein_zee is on a distinguished road
I think this one "lookupObjectRef()" should solve the issue. This means now you don't need "const" qualifier.
nado likes this.
einstein_zee is offline   Reply With Quote

Old   December 17, 2019, 05:52
Default
  #7
Member
 
David Andersson
Join Date: Oct 2019
Posts: 46
Rep Power: 6
sippanspojk is on a distinguished road
Quote:
Originally Posted by einstein_zee View Post
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.
sippanspojk is offline   Reply With Quote

Reply

Tags
functionobject, volscalarfield

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


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


All times are GMT -4. The time now is 14:16.