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

New problem in version 4.0! The boundary field become read only!

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

Like Tree31Likes
  • 3 Post By Democritus
  • 7 Post By hk318i
  • 20 Post By kittychunk
  • 1 Post By Zhiheng Wang

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   July 4, 2016, 22:03
Default New problem in version 4.0! The boundary field become read only!
  #1
New Member
 
Democritus's Avatar
 
Xiaoqiu HE
Join Date: Mar 2016
Location: Wuhan, China
Posts: 29
Rep Power: 10
Democritus is on a distinguished road
I used to adopt following way in order to impose a complex fixedValue type BC:
1. Implement a program to manipulate the value of boundary field directly and write the field into file. The code is as follow:
Code:
    const fvBoundaryMesh & thisBoundary = mesh.boundary(); //here I get the boundary of the mesh
    forAll( thisBoundary, fvPatchID ) // go through all the patchs of the boundary
    {
      const fvPatch & thisPatch = thisBoundary[ fvPatchID ];
      Info << "\n Imposing the boundary condition on the fvPatch of " <<
      thisPatch.name() << endl;

      const vectorField & position = thisPatch.Cf(); // get the cell face centers' positions
      forAll( thisPatch, elmtID ) // imposing values on the centers of all the cell faces of this patch   
      {
        const scalar & x = position[elmtID].component(0);
        const scalar & y = position[elmtID].component(1);

        //you can replace your function on the right side of the =
        pS.boundaryField()[fvPatchID][elmtID] = -1 * Foam::exp(-1 * x) * Foam::cos( x );
        pC.boundaryField()[fvPatchID][elmtID] = Foam::exp(-1 * x) * Foam::sin( x );

        vS.boundaryField()[fvPatchID][elmtID].component(0) = -1 * Foam::exp(-1 * x) * Foam::cos( x );
        vS.boundaryField()[fvPatchID][elmtID].component(1) = 2 * Foam::cos( x ) * Foam::sin( y ) ;

        vC.boundaryField()[fvPatchID][elmtID].component(0) = Foam::exp(-1 * x) * Foam::sin( x );
        vC.boundaryField()[fvPatchID][elmtID].component(1) = Foam::sin( x ) * Foam::cos( y );

      }

    }
2. Then I open the file, change the BC type from "calculated" to "fixedValue"

3. After that, I can run my solver

But!!!
Now in new 4.0 version OpenFOAM, the boundary field is read only! When I compile the BC implement program, the compiler indicates that
Quote:
vC.boundaryField()[fvPatchID][elmtID].component(0) is read only!
For information the detailed error is as follow:
Code:
error: assignment of read-only location (&(&(& u2.Foam::GeometricField<Type, PatchField, GeoMesh>::boundaryField<Foam::Vector<double>, Foam::fvPatchField, Foam::volMesh>())->Foam::GeometricField<Foam::Vector<double>, Foam::fvPatchField, Foam::volMesh>::Boundary::<anonymous>.Foam::FieldField<Foam::fvPatchField, Foam::Vector<double> >::<anonymous>.Foam::PtrList<Foam::fvPatchField<Foam::Vector<double> > >::<anonymous>.Foam::UPtrList<T>::operator[]<Foam::fvPatchField<Foam::Vector<double> > >(fvPatchID))->Foam::fvPatchField<Foam::Vector<double> >::<anonymous>.Foam::Field<Foam::Vector<double> >::<anonymous>.Foam::List<Foam::Vector<double> >::<anonymous>.Foam::UList<T>::operator[]<Foam::Vector<double> >(elmtID))->Foam::Vector<double>::<anonymous>.Foam::VectorSpace<Form, Cmpt, Ncmpts>::component<Foam::Vector<double>, double, 3u>(1)
           vC.boundaryField()[fvPatchID][elmtID].component(1) = 0.1*x*y
What can I do for that? Can I have the full control over every single elements of fields in new 4.0 OF?
Thanks!
Danillo, Kummi and Mansur like this.
Democritus is offline   Reply With Quote

Old   July 5, 2016, 06:50
Default
  #2
Senior Member
 
Hassan Kassem
Join Date: May 2010
Location: Germany
Posts: 242
Rep Power: 18
hk318i is on a distinguished road
I think it is related to this commit [LINK]
__________________
@HIKassem | HassanKassem.me
hk318i is offline   Reply With Quote

Old   July 6, 2016, 02:10
Default
  #3
New Member
 
Quinn Reynolds
Join Date: Jun 2014
Posts: 7
Rep Power: 12
kittychunk is on a distinguished road
Quote:
Originally Posted by hk318i View Post
I think it is related to this commit [LINK]
This solved the problem for me.

The summary version is that you need to replace instances of "boundaryField()" and "internalField()" with "boundaryFieldRef()" and "internalFieldRef()" if you want to modify them in your code. The non-"Ref" calls are const now.

Update

Seems like internalField and internalFieldRef have been replaced by direct calls to the field variable. Eg: U.internalField() becomes U() for a const reference to the internal field, or U.ref() for non-const access. See associated bug report.
nimasam, hk318i, jherb and 17 others like this.

Last edited by kittychunk; July 7, 2016 at 01:54. Reason: Additional info from bug report
kittychunk is offline   Reply With Quote

Old   July 7, 2016, 01:18
Default
  #4
New Member
 
Democritus's Avatar
 
Xiaoqiu HE
Join Date: Mar 2016
Location: Wuhan, China
Posts: 29
Rep Power: 10
Democritus is on a distinguished road
Quote:
Originally Posted by hk318i View Post
I think it is related to this commit [LINK]
Thank you very much!
Democritus is offline   Reply With Quote

Old   July 7, 2016, 01:20
Default
  #5
New Member
 
Democritus's Avatar
 
Xiaoqiu HE
Join Date: Mar 2016
Location: Wuhan, China
Posts: 29
Rep Power: 10
Democritus is on a distinguished road
Quote:
Originally Posted by kittychunk View Post
This solved the problem for me.

The summary version is that you need to replace instances of "boundaryField()" and "internalField()" with "boundaryFieldRef()" and "internalFieldRef()" if you want to modify them in your code. The non-"Ref" calls are const now.
Thank you very much! My problem is solved~!
Democritus is offline   Reply With Quote

Old   August 17, 2016, 08:53
Default
  #6
Member
 
Zhiheng Wang
Join Date: Mar 2016
Posts: 72
Rep Power: 10
Zhiheng Wang is on a distinguished road
Quote:
Originally Posted by Democritus View Post
Thank you very much! My problem is solved~!
Hi my createField.H has defination of T as

const volScalarField& T = thermo.T();
I want to impliment my code on boundaryCondition correction as

forAll(T.boundaryField()[patchID],i)
{

T.boundaryField)([patchID][i] = T.boundaryField()[patchID][i]-DT;
------------
-------------------------- (some code for spoces) ........
T.write();

}

I am getting following error

error: assignment of read-only location (&(&(& T)->Foam::GeometricField<Type, PatchField, GeoMesh>::boundaryField<double,.....

How to resolve this condition I want to correct the temperature T with some differet function based on spices flux. please help

Zhiheng Wang is offline   Reply With Quote

Old   May 23, 2017, 19:12
Default boundaryFieldRef does not affect the actual field
  #7
Member
 
Sugajen
Join Date: Jan 2012
Location: Tempe, USA
Posts: 52
Rep Power: 14
Sugajen is on a distinguished road
Hi all,

I had a similar problem of read-only and added Ref to the boundaryField. But the values that I assign are not reflected on the output. Where am I going wrong ?

Code:
 label upMem = mesh.boundaryMesh().findPatchID("upperMembrane");
forAll( U.boundaryFieldRef()[upMem], i)
{
	U.boundaryFieldRef()[upMem][i].component(vector::X) = 0;
	U.boundaryFieldRef()[upMem][i].component(vector::Y) = 0;
	U.boundaryFieldRef()[upMem][i].component(vector::Z) = Jw.boundaryFieldRef()[upMem][i];

}
Sugajen is offline   Reply With Quote

Old   June 5, 2017, 06:27
Default
  #8
Member
 
Zhiheng Wang
Join Date: Mar 2016
Posts: 72
Rep Power: 10
Zhiheng Wang is on a distinguished road
Store script in some file "patch.H" and include file as #include "patch.H" in pEqn.H before U.correctBoundary()
This will reflect effect of code in boundary

Sent from my Lenovo K50a40 using CFD Online Forum mobile app
Zhiheng Wang is offline   Reply With Quote

Old   June 5, 2017, 21:10
Default
  #9
Member
 
Sugajen
Join Date: Jan 2012
Location: Tempe, USA
Posts: 52
Rep Power: 14
Sugajen is on a distinguished road
Thank you Zhiheng!

It worked after I changed the boundary conditions to (0.0, 0.0, 0.0) instead of noSlip. Looks like noSlip overwrites whatever we do!
Sugajen is offline   Reply With Quote

Old   June 6, 2017, 04:43
Default
  #10
Member
 
Zhiheng Wang
Join Date: Mar 2016
Posts: 72
Rep Power: 10
Zhiheng Wang is on a distinguished road
Yes you need to write type fixedValue ;
Uniform (0.0 0.0 0.0);

Sent from my Lenovo K50a40 using CFD Online Forum mobile app
Sugajen likes this.
Zhiheng Wang is offline   Reply With Quote

Old   April 11, 2020, 09:58
Unhappy
  #11
Member
 
alexander thierfelder
Join Date: Dec 2019
Posts: 71
Rep Power: 6
superkelle is on a distinguished road
Quote:
Originally Posted by kittychunk View Post
This solved the problem for me.

The summary version is that you need to replace instances of "boundaryField()" and "internalField()" with "boundaryFieldRef()" and "internalFieldRef()" if you want to modify them in your code. The non-"Ref" calls are const now.

Update

Seems like internalField and internalFieldRef have been replaced by direct calls to the field variable. Eg: U.internalField() becomes U() for a const reference to the internal field, or U.ref() for non-const access. See associated bug report.
I now searched a whole day for this. For me it is nearly impossible to get solutions for those problems by myself. Does anybody has an advice how to find those problems that occure by changes in the "openfoam language"? I mean I read many codes where
Code:
.boundaryField()
worked fine, and I got nearly crazy when it did not work for me. What is the best workflow to find the root of the problem in openfoam? I mean, I would never have assumed that they changed the functionality of ".boundaryField()" in the src code.
superkelle is offline   Reply With Quote

Reply

Tags
boundary condition, boundary field

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
sliding mesh problem in CFX Saima CFX 46 September 11, 2021 07:38
Moving mesh Niklas Wikstrom (Wikstrom) OpenFOAM Running, Solving & CFD 122 June 15, 2014 06:20
domain imbalance for enrgy equation happy CFX 14 September 6, 2012 01:54
Problem with rhoSimpleFoam matteo_gautero OpenFOAM Running, Solving & CFD 0 February 28, 2008 06:51
New topic on same subject - Flow around race car Tudor Miron CFX 15 April 2, 2004 06:18


All times are GMT -4. The time now is 02:24.