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

Update all cells in volVectorField from my BC

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

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   February 18, 2018, 06:20
Default Update all cells in volVectorField from my BC
  #1
Member
 
Ruggiero Guida
Join Date: Apr 2013
Location: World
Posts: 46
Rep Power: 12
Rojj is on a distinguished road
Hi,

I would like to update all cell values from my boundary condition. This is what I have done so far

Code:
const volVectorField& U = db().lookupObject<volVectorField>("U");
Info << "U(164): " << U.internalField()[164].x() << nl << endl;
This works, so I can access cell values. Then I try to extend the above to all cells:

Code:
forAll(U.internalField(), cellID)
{
  U.internalField()[cellID].x() = 1.2 * U.internalField()[cellID].x();
  U.internalField()[cellID].y() = 1.2 * U.internalField()[cellID].y();
  U.internalField()[cellID].z() = 1.2 * U.internalField()[cellID].z();
}
but the compiler complains with

Code:
error: assignment of read-only location
I believe that I have to use a specific mutator rather than simple assignment, but I am struggling to find it in the of source code.

Any advice?
Rojj is offline   Reply With Quote

Old   February 20, 2018, 14:00
Default
  #2
Member
 
Ruggiero Guida
Join Date: Apr 2013
Location: World
Posts: 46
Rep Power: 12
Rojj is on a distinguished road
I have also tried

Code:
U.internalField()[cellID].x().value() = ...
but I still get an error.

Any hint?
Rojj is offline   Reply With Quote

Old   February 21, 2018, 05:50
Default
  #3
New Member
 
Join Date: Dec 2015
Posts: 24
Rep Power: 10
metalfox is on a distinguished road
You are trying to modify a const reference to the U field. Remove the const keyword.
metalfox is offline   Reply With Quote

Old   March 6, 2018, 12:08
Default
  #4
New Member
 
A.KvJ
Join Date: Feb 2012
Posts: 3
Rep Power: 14
akabat is on a distinguished road
Hello Ruggiero,
could you solve the issue? In my case with version 17.12 I have to const cast the field (I know it is not the best solution, but at least it works) and modify the fields with using the primitiveFieldRef

const volVectorField& U = db().lookupObject<volVectorField>("U");
velVectorField& Umod = const_cast<volVectorField&>(U);
Umod.primitiveFieldRef()[cellID] = ...

Regards
Alex
akabat is offline   Reply With Quote

Reply

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
Accessing a vector in a volVectorField by cell label andrewryan OpenFOAM Programming & Development 7 June 8, 2018 05:48
Simulating fire in a tunnel luca1992 OpenFOAM 14 August 16, 2017 14:50
Update Dynamic mesh failed- Negative cell volume detected kywong5 Fluent UDF and Scheme Programming 0 April 24, 2017 09:57
monitoring cell Jane Siemens 2 March 4, 2004 22:01
cell to cell relation CMB Siemens 1 December 4, 2003 05:05


All times are GMT -4. The time now is 00:49.