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

autoPtr doesn't create a "new"

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   November 15, 2019, 10:34
Default autoPtr doesn't create a "new"
  #1
Member
 
Fabien Robaux
Join Date: Oct 2016
Posts: 51
Rep Power: 10
frobaux is on a distinguished road
Hello everyone,
I've a noticed a strange behavior in my code, I'm sure it is my mistake or my lack of understanding but I could understand it:


I have a field that I want to interpolate. I've coded something like


Code:
autoPtr<interpolation<vector>> interpV
(
       interpolation<vector>::New(mapMethod2, srcV)
 );
forAll(tgtMesh.C(), tgtCelli)
 {
      const point & p=tgtMesh.C()[tgtCelli];
      const label & srcCelli= srcMesh.findCell(p);

       VfromExternal[tgtCelli]= interpV().interpolate(p, srcCelli, -1);
}
where srcV is my source field and mapMethod2 is "cellPoint". By diving into the source, and written a couple of "Info <<" inside interpolation.H/C and interpolationCellPoint.H/C it seems that the "interpolation::new" is called. Inside this function:

Code:
    return autoPtr<interpolation<Type>>(cstrIter()(psi));
Which in turns call interpolationCellPoint constructor:
Code:
template<class Type>
Foam::interpolationCellPoint<Type>::interpolationCellPoint
(
    const GeometricField<Type, fvPatchField, volMesh>& psi
)
:
    interpolation<Type>(psi),
    psip_
    (
        volPointInterpolation::New(psi.mesh()).interpolate
        (
            psi,
            "volPointInterpolate(" + psi.name() + ')',
            true        // use cache
        )
    )
    
{
    psip_.write(); // local modif
    Info << "should write pointField" << psip_.name() << endl; //local modif
    // Uses cellPointWeight to do interpolation which needs tet decomposition
    (void)psi.mesh().tetBasePtIs();
}
But psip_ is not computed, except at the first time step! (but the Info in blue prints out, so the contructor is called, but volPointInterpolation is definetly not called => the psip_ written in blue above stays the same during to consecutive time step, except in the openFoam header, even with psi different(checked)!!). The really troubling thing is that the same procedure applied to the pressure works well and its "psip_" seems to be recomputed at every time step.


My guess is the new srcV is so close (~10^-3) from the previous one that autoPtr does not actually recompute the volPointInterpolation needed : psip_ is not recomputed inside interpolationCellPoint.H. The problem is I need to and the final results are really sensitive to that! should I manually destroy the interpV at the end? (and how do I do that?) Am I doing something wrong?


Edit: The same behavior is obtained when I tried to define interpV as a const reference of directly interpolationCellPoint
Code:
const interpolationCellPoint<vector>  & interpV (srcV);
=> even if srcV changes (slightly) from 1 instant to the next, interpV.psip_ doesn't!!!



Thanks a lot for your inputs!
Sincerely,

Fabien

Last edited by frobaux; November 15, 2019 at 13:23.
frobaux is offline   Reply With Quote

Old   November 18, 2019, 05:14
Default
  #2
Member
 
Fabien Robaux
Join Date: Oct 2016
Posts: 51
Rep Power: 10
frobaux is on a distinguished road
Well, after a lot of print and research everywhere, I've found the culprit!!!


The problem was in
Code:
psip_
    (
        volPointInterpolation::New(psi.mesh()).interpolate
        (
            psi,
            "volPointInterpolate(" + psi.name() + ')',
            true        // use cache // THIS IS THE CULPRIT
        )
    )
Where the "cache" was used. Digging deeper I saw that my modification of the sourceV didn't modify sourceV.eventNo_.

Now, I do it manually
Code:
sourceV.evenNo()=sourceV.eventNo()+1 // this is wrong, see edits
and it works fine


EDIT:

I was wrong, it does not run well. I forgot to recompile the "true".. Inside the volPointInterpolation::New(psi.mesh()).interpolate the eventNo is way to important. +1 does not help matching it...


EDIT2:
Well I was an idiot, I found out that -If this time I'm right- the eventNo is more of a global number counting all occurence. To set a n object as updated, used myObject.setUpToDate() instead (it sets myObject.eventNo_= db().getEvent() )

Last edited by frobaux; November 18, 2019 at 12:32.
frobaux is offline   Reply With Quote

Reply


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
create the file *.foam phongstar OpenFOAM 12 October 14, 2018 19:06
[GAMBIT] How to plot S pipe mariam.sara ANSYS Meshing & Geometry 36 November 7, 2013 16:22
[ANSYS Meshing] is it possible to create virtual edges on the blades er_ijaz ANSYS Meshing & Geometry 0 November 3, 2013 06:15
[DesignModeler] Design Modeller create surface papis ANSYS Meshing & Geometry 0 October 31, 2013 14:52
About create interface! xinzhiyu2008 STAR-CCM+ 2 August 6, 2010 21:47


All times are GMT -4. The time now is 01:44.