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

invalid conversion error

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   July 26, 2017, 17:12
Default invalid conversion error
  #1
New Member
 
Saddam Hijazi
Join Date: May 2016
Posts: 17
Rep Power: 10
SaddamH is on a distinguished road
Hello all, I am having a problem in compiling a piece of code that is the related to the following method :


void reductionProblem::reconstruct_from_matrix(PtrList< volVectorField> rec_field2, PtrList<volVectorField> modes, label Nmodes, Eigen::MatrixXd coeff_matrix)
{
volVectorField tmp
(
IOobject
(
"tmp",
modes[0].time().timeName(),
modes[0].mesh(),
IOobject::NO_READ,
IOobject::AUTO_WRITE
),
modes[0].mesh(),
dimensionedVector("zero", modes[0].dimensions(), vector::zero)
);


for (label k = 0; k < coeff_matrix.rows(); k++)
{
tmp = tmp * 0;
for (label i = 0; i < Nmodes; i++)
{
tmp += coeff_matrix(k, i)*modes[i];
}
rec_field2.append(tmp);
}
}




When I compile it, I got this error

error: invalid conversion from ‘Foam:imensionedField<Foam::Vector<double>, Foam::volMesh>*’ to ‘Foam::GeometricField<Foam::Vector<double>, Foam::fvPatchField, Foam::volMesh>*’ [-fpermissive]
ptrs_[i] = (a[i]).clone().ptr();
^

Could you help me please in solving this problem.
Thanks in advance.
SaddamH is offline   Reply With Quote

Old   July 28, 2017, 13:41
Default
  #2
Senior Member
 
Zeppo's Avatar
 
Sergei
Join Date: Dec 2009
Posts: 261
Rep Power: 21
Zeppo will become famous soon enough
Code:
void reductionProblem::reconstruct_from_matrix
(
    PtrList< volVectorField>& rec_field2,
    const PtrList<volVectorField>& modes,
    const label Nmodes,
    const Eigen::MatrixXd& coeff_matrix
)
{
    for (const label k = 0; k < coeff_matrix.rows(); ++k)
    {
        volVectorField* tmp = new volVectorField
        (
            IOobject
            (
                "tmp",
                modes[0].time().timeName(),
                modes[0].mesh(),
                IOobject::NO_READ,
                IOobject::AUTO_WRITE
            ),
            false, //- I suppose you don't want it to be registered
            modes[0].mesh(),
            dimensionedVector("zero", modes[0].dimensions(), vector::zero)
        );
        
        for (const label i = 0; i < Nmodes; ++i)
        {
            *tmp += coeff_matrix(k, i)*modes[i];
        }
        
        rec_field2.append(tmp);
    }
}
And let me see how you are about to use this function. Post the line where you invoke it in your code.
Zeppo is offline   Reply With Quote

Old   September 21, 2017, 10:02
Default
  #3
New Member
 
ANKUR GARG
Join Date: Mar 2017
Posts: 23
Rep Power: 9
ankur_garg is on a distinguished road
I am also getting the same kind of error.
error: invalid conversion from ‘Foam:imensionedField<Foam::Vector<double>, Foam::volMesh>*’ to ‘Foam::GeometricField<Foam::Vector<double>, Foam::fvPatchField, Foam::volMesh>*’ [-fpermissive]
ptrs_[i] = (a[i]).clone().ptr();

I am using std::vector, in which i am trying to push a variable of type PtrList<volScalarField>. The piece of code is here:

autoPtr<volScalarField> IDefaultPtr;

const label s = nLambda_;
PtrList<volScalarField>ILambda(s);

forAll(ILambda, lambdaI)
{
IOobject IHeader
(
dfm_intensityPrefix + Foam::name(rayI) + Foam::name(lambdaI),
mesh_.time().timeName(),
mesh_,
IOobject::MUST_READ,
IOobject::AUTO_WRITE
);

ILambda.set
(
lambdaI,
new volScalarField(IHeader, mesh_)
);
// Check if field exists and can be read
if (IHeader.typeHeaderOk<volScalarField>(true))
{
ILambda.set
(
lambdaI,
new volScalarField(IHeader, mesh_)
);
}
else
{

// Reset the MUST_READ flag
IOobject noReadHeader(IHeader);

ILambda.set
(
lambdaI,
new volScalarField(noReadHeader, IDefaultPtr())
);
}
}
vec_ILambda_.push_back(ILambda);

Where vec_ILambda_ is declared as: std::vector< PtrList<volScalarField> > vec_ILambda_;
ankur_garg 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
[OpenFOAM.org] Compile OF 2.3 on Mac OS X .... the patch gschaider OpenFOAM Installation 225 August 25, 2015 19:43
Ansys Fluent 13.0 UDF compilation problem in Window XP (32 bit) Yogini Fluent UDF and Scheme Programming 7 October 3, 2012 07:24
Accessing phi from a fvPatchField at same patch johndeas OpenFOAM 1 September 13, 2010 20:23
checking the system setup and Qt version vivek070176 OpenFOAM Installation 22 June 1, 2010 12:34
Installation OF1.5-dev ttdtud OpenFOAM Installation 46 May 5, 2009 02:32


All times are GMT -4. The time now is 18:14.