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

Object inside PtrList does not update when its target does

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   January 14, 2020, 14:00
Default Object inside PtrList does not update when its target does
  #1
Member
 
Fabien Robaux
Join Date: Oct 2016
Posts: 51
Rep Power: 9
frobaux is on a distinguished road
Hello Foamers,
I need help on a PtrList object,
My goal is to create a solver that has the capabilities of interFoam with multiregion physics.



So I convert interFoam
Code:
   volScalarField& alpha1(mixture.alpha1());
To

Code:
    PtrList<volScalarField> l_alpha1(fluidRegions.size());
    l_alpha1.set
    (
        i,
        l_mixture[i].alpha1()
    );
The problem is, when I update l_mixture[i].alpha1()=something (modify the internal field),
The l_alpha1[i] does not update and both fields are thus different.

Reciprocally, when I modify l_alpha1[i], l_mixture[i].alpha1() is not updated.

Maybe I'm wrong, but I order to mimic the interFoam behavior, both fields are in fact one, and should behave as such?

Thank you a lot for your help
frobaux is offline   Reply With Quote

Old   January 17, 2020, 14:03
Default
  #2
Senior Member
 
Adhiraj
Join Date: Sep 2010
Location: Karnataka, India
Posts: 187
Rep Power: 15
adhiraj is on a distinguished road
Please correct me if I'm wrong, but from what I understand,

Code:
volScalarField& alpha1(mixture.alpha1());
creates a reference to the volScalarField returned by mixture.alpha1(), and thus if you change either, the other is updated.

When you write

Code:
l_alpha1.set
(
    i,
    l_mixture[i].alpha1()
);
you are initializing l_alpha1[i] using the "value" of the volScalarField returned by mixture.alpha1(). Thus they are not the same object.
adhiraj is offline   Reply With Quote

Old   January 21, 2020, 04:28
Default
  #3
Member
 
Fabien Robaux
Join Date: Oct 2016
Posts: 51
Rep Power: 9
frobaux is on a distinguished road
Quote:
Originally Posted by adhiraj View Post
When you write

Code:
l_alpha1.set
(
    i,
    l_mixture[i].alpha1()
);
you are initializing l_alpha1[i] using the "value" of the volScalarField returned by mixture.alpha1(). Thus they are not the same object.

Yes, This is what happens, but as l_alpha1 is a list of pointers (PtrList), I thought that l_alpha1[i] would point to the l_mixture[i].alpha1(). Maybe it is the normal behavior, but then I don't understand the name of the structure : "PtrList"...


Otherwise, is there a way to obtain l_alpha1[i] => l_mixture[i].alpha1().



Thanks a lot for your help!
frobaux is offline   Reply With Quote

Reply

Tags
mixture, pointer, pointers, ptrlist


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
[OpenFOAM.org] Instructions to install OpenFOAM-2.4.x on CentOS-6.10 redbullah OpenFOAM Installation 9 September 7, 2019 17:18
ParaView 3.8.0 problem on debian Unseen OpenFOAM Installation 4 August 16, 2010 10:26
Compilation error OF1.5-dev on Suse10.3 darenyang OpenFOAM Installation 0 April 29, 2009 04:55
[blockMesh] BlockMeshmergePatchPairs hjasak OpenFOAM Meshing & Mesh Conversion 11 August 15, 2008 07:36
OpenFOAM141dev linking error on IBM AIX 52 matthias OpenFOAM Installation 24 April 28, 2008 15:49


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