0

現在、次のコード スニペットを分析しています。

fvc::surfaceSum(mag(phi))().internalField() 

template<class Type>
tmp<GeometricField<Type, fvPatchField, volMesh> > surfaceSum
(
    const tmp<GeometricField<Type, fvsPatchField, surfaceMesh> >& tssf
)
{
    tmp<GeometricField<Type, fvPatchField, volMesh> > tvf = surfaceSum(tssf());
    tssf.clear();  //If object pointer points to valid object:delete object and 
                           //set pointer to NULL
    return tvf;
}

template<class Type, template<class> class PatchField, class GeoMesh>
tmp<GeometricField<scalar, PatchField, GeoMesh> > mag
(
    const GeometricField<Type, PatchField, GeoMesh>& gf
)
{
    tmp<GeometricField<scalar, PatchField, GeoMesh> > tMag
    (
          new GeometricField<scalar, PatchField, GeoMesh>
          (
                IOobject
                (
                      "mag(" + gf.name() + ')',
                      gf.instance(),
                      gf.db(),
                      IOobject::NO_READ,
                      IOobject::NO_WRITE
                ),
                gf.mesh(),
                gf.dimensions()
          )
    );

    mag(tMag(), gf);

    return tMag;
}

template<class T>
inline const T& Foam::tmp<T>::operator()() const       
{
    if (isTmp_) // bool isTmp_//Flag for whether object is a temporary or a constant object
    {
          if (!ptr_)   //mutable T* ptr_;  //- Pointer to temporary object   
          {
                FatalErrorIn("const T& Foam::tmp<T>::operator()() const")
                << "temporary deallocated"
                << abort(FatalError);
          }

          return *ptr_;  
    }
    else
    {
          return ref_; //const T& ref_  //- Const reference to constant object
    }
}

template<class Type, template<class> class PatchField, class GeoMesh>
typename
Foam::GeometricField<Type, PatchField, GeoMesh>::InternalField 
{                                                                                                                         
    this->setUpToDate();  //Set up to date                                                   
    storeOldTimes();    //Store the old-time fields.
    return *this;
}

2 番目のコード スニペットのメソッド surfaceSum(...) は const tmp<GeometricField<Type, fvsPatchField, surfaceMesh> >&入力パラメーターとして期待されますが、他のメソッドを通過すると、得られる結果は非 const パラメーターtmp<GeometricField<scalar, PatchField, GeoMesh> > tMagです (3 番目のコード ニペットを参照)。したがって、const 入力パラメーターに非 const オブジェクトを渡すことは可能ですか、それともここで何かを誤解していますか?

あいさつ

4

1 に答える 1