|
[Sponsors] |
New problem in version 4.0! The boundary field become read only! |
![]() |
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
![]() |
![]() |
#1 | |
New Member
Xiaoqiu HE
Join Date: Mar 2016
Location: Wuhan, China
Posts: 29
Rep Power: 10 ![]() |
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 ); } } 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:
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 Thanks! |
||
![]() |
![]() |
![]() |
![]() |
#3 | |
New Member
Quinn Reynolds
Join Date: Jun 2014
Posts: 7
Rep Power: 12 ![]() |
Quote:
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. Last edited by kittychunk; July 7, 2016 at 01:54. Reason: Additional info from bug report |
||
![]() |
![]() |
![]() |
![]() |
#5 | |
New Member
Xiaoqiu HE
Join Date: Mar 2016
Location: Wuhan, China
Posts: 29
Rep Power: 10 ![]() |
Quote:
![]() |
||
![]() |
![]() |
![]() |
![]() |
#6 |
Member
Zhiheng Wang
Join Date: Mar 2016
Posts: 72
Rep Power: 10 ![]() |
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 |
|
![]() |
![]() |
![]() |
![]() |
#7 |
Member
Sugajen
Join Date: Jan 2012
Location: Tempe, USA
Posts: 52
Rep Power: 14 ![]() |
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]; } |
|
![]() |
![]() |
![]() |
![]() |
#8 |
Member
Zhiheng Wang
Join Date: Mar 2016
Posts: 72
Rep Power: 10 ![]() |
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 |
|
![]() |
![]() |
![]() |
![]() |
#9 |
Member
Sugajen
Join Date: Jan 2012
Location: Tempe, USA
Posts: 52
Rep Power: 14 ![]() |
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! |
|
![]() |
![]() |
![]() |
![]() |
#10 |
Member
Zhiheng Wang
Join Date: Mar 2016
Posts: 72
Rep Power: 10 ![]() |
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 |
|
![]() |
![]() |
![]() |
![]() |
#11 | |
Member
alexander thierfelder
Join Date: Dec 2019
Posts: 71
Rep Power: 6 ![]() |
Quote:
Code:
.boundaryField() |
||
![]() |
![]() |
![]() |
Tags |
boundary condition, boundary field |
|
|
![]() |
||||
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 |