Donate. I desperately need donations to survive due to my health

Get paid by answering surveys Click here

Click here to donate

Remote/Work from Home jobs

How do I prevent the redefinition of a class? C++

I am trying to compile some C++ for an opensource CFD software, however I am getting some redefinition errors:

    jumpCyclicMHFvPatchField.C:31:2: error: redefinition of ‘Foam::jumpCyclicMHFvPatchField<Type>::jumpCyclicMHFvPatchField(const Foam::fvPatch&, const Foam::DimensionedField<Type, Foam::volMesh>&)’
  Foam::jumpCyclicMHFvPatchField<Type>::jumpCyclicMHFvPatchField
  ^
In file included from jumpCyclicMHFvPatchField.H:181:0,
                 from jumpCyclicMHFvPatchField.C:26:
jumpCyclicMHFvPatchField.C:31:2: note: ‘Foam::jumpCyclicMHFvPatchField<Type>::jumpCyclicMHFvPatchField(const Foam::fvPatch&, const Foam::DimensionedField<Type, Foam::volMesh>&)’ previously declared here
  Foam::jumpCyclicMHFvPatchField<Type>::jumpCyclicMHFvPatchField

I can see that I am defining jumpCyclicMHFvPatchField in the header and the C file, but unfortunately my C++ skills are very limited and I cannot figure out why this is happening.

Is there a simple way prevent the redefinition of the class?

Header File:

#ifndef jumpCyclicMHFvPatchField_H
 #define jumpCyclicMHFvPatchField_H

 #include "cyclicFvPatchField.H"

 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

 namespace Foam
 {

 /*---------------------------------------------------------------------------*\
                    Class jumpCyclicMHFvPatchField Declaration
 \*---------------------------------------------------------------------------*/

 template<class Type>
 class jumpCyclicMHFvPatchField
 :
     public cyclicFvPatchField<Type>
 {

 public:

     //- Runtime type information
     TypeName("jumpCyclic");


     // Constructors

         //- Construct from patch and internal field
         jumpCyclicMHFvPatchField
         (
             const fvPatch&,
             const DimensionedField<Type, volMesh>&
         );

         //- Construct from patch, internal field and dictionary
         jumpCyclicMHFvPatchField
         (
             const fvPatch&,
             const DimensionedField<Type, volMesh>&,
             const dictionary&
         );

         //- Construct by mapping given jumpCyclicMHFvPatchField onto a new patch
         jumpCyclicMHFvPatchField
         (
             const jumpCyclicMHFvPatchField<Type>&,
             const fvPatch&,
             const DimensionedField<Type, volMesh>&,
             const fvPatchFieldMapper&
         );

         //- Construct as copy
         jumpCyclicMHFvPatchField
         (
             const jumpCyclicMHFvPatchField<Type>&
         );

         //- Construct as copy setting internal field reference
         jumpCyclicMHFvPatchField
         (
             const jumpCyclicMHFvPatchField<Type>&,
             const DimensionedField<Type, volMesh>&
         );


     // Member functions

         // Access

             //- Return the interface type
             virtual const word& interfaceFieldType() const
             {
                 return cyclicFvPatchField<Type>::type();
             }

             //- Return the "jump" across the patch as a "half" field
             virtual tmp<Field<Type>> jump() const = 0;


         // Evaluation functions

             //- Return neighbour coupled given internal cell data
             tmp<Field<Type>> patchNeighbourField() const;

             //- Update result field based on interface functionality
             virtual void updateInterfaceMatrix
             (
                 scalarField& result,
                 const bool add,
                 const scalarField& psiInternal,
                 const scalarField& coeffs,
                 const direction cmpt,
                 const Pstream::commsTypes commsType
             ) const;

             //- Update result field based on interface functionality
             virtual void updateInterfaceMatrix
             (
                 Field<Type>&,
                 const bool add,
                 const Field<Type>&,
                 const scalarField&,
                 const Pstream::commsTypes commsType
             ) const;
 };

 //- Update result field based on interface functionality
 template<>
 void jumpCyclicMHFvPatchField<scalar>::updateInterfaceMatrix
 (
     scalarField& result,
     const bool add,
     const scalarField& psiInternal,
     const scalarField& coeffs,
     const direction cmpt,
     const Pstream::commsTypes commsType
 ) const;


 template<>
 void jumpCyclicMHFvPatchField<vector>::updateInterfaceMatrix
 (
     scalarField& result,
     const bool add,
     const scalarField& psiInternal,
     const scalarField& coeffs,
     const direction cmpt,
     const Pstream::commsTypes commsType
 ) const;


 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

 } // End namespace Foam

 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

 #ifdef NoRepository
     #include "jumpCyclicMHFvPatchField.C"
 #endif

 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

 #endif

C File:

#include "jumpCyclicMHFvPatchField.H"

 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //

 template<class Type>
 Foam::jumpCyclicMHFvPatchField<Type>::jumpCyclicMHFvPatchField
 (
     const fvPatch& p,
     const DimensionedField<Type, volMesh>& iF
 )
 :
     cyclicFvPatchField<Type>(p, iF)
 {}


 template<class Type>
 Foam::jumpCyclicMHFvPatchField<Type>::jumpCyclicMHFvPatchField
 (
     const jumpCyclicMHFvPatchField<Type>& ptf,
     const fvPatch& p,
     const DimensionedField<Type, volMesh>& iF,
     const fvPatchFieldMapper& mapper
 )
 :
     cyclicFvPatchField<Type>(ptf, p, iF, mapper)
 {}


 template<class Type>
 Foam::jumpCyclicMHFvPatchField<Type>::jumpCyclicMHFvPatchField
 (
     const fvPatch& p,
     const DimensionedField<Type, volMesh>& iF,
     const dictionary& dict
 )
 :
     cyclicFvPatchField<Type>(p, iF, dict)
 {
     // Call this evaluation in derived classes
     //this->evaluate(Pstream::commsTypes::blocking);
 }


 template<class Type>
 Foam::jumpCyclicMHFvPatchField<Type>::jumpCyclicMHFvPatchField
 (
     const jumpCyclicMHFvPatchField<Type>& ptf
 )
 :
     cyclicFvPatchField<Type>(ptf)
 {}


 template<class Type>
 Foam::jumpCyclicMHFvPatchField<Type>::jumpCyclicMHFvPatchField
 (
     const jumpCyclicMHFvPatchField<Type>& ptf,
     const DimensionedField<Type, volMesh>& iF
 )
 :
     cyclicFvPatchField<Type>(ptf, iF)
 {}


 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //

 template<class Type>
 Foam::tmp<Foam::Field<Type>>
 Foam::jumpCyclicMHFvPatchField<Type>::patchNeighbourField() const
 {
     const Field<Type>& iField = this->primitiveField();
     const labelUList& nbrFaceCells =
         this->cyclicPatch().neighbFvPatch().faceCells();

     tmp<Field<Type>> tpnf(new Field<Type>(this->size()));
     Field<Type>& pnf = tpnf.ref();

     Field<Type> jf(this->jump());
     if (!this->cyclicPatch().owner())
     {
         jf *= -1.0;
     }

     if (this->doTransform())
     {
         forAll(*this, facei)
         {
             pnf[facei] = transform
             (
                 this->forwardT()[0], iField[nbrFaceCells[facei]]
             ) - jf[facei];
         }
     }
     else
     {
         forAll(*this, facei)
         {
             pnf[facei] = iField[nbrFaceCells[facei]] - jf[facei];
         }
     }

     return tpnf;
 }


 template<class Type>
 void Foam::jumpCyclicMHFvPatchField<Type>::updateInterfaceMatrix
 (
     scalarField& result,
     const bool add,
     const scalarField& psiInternal,
     const scalarField& coeffs,
     const direction cmpt,
     const Pstream::commsTypes
 ) const
 {
     NotImplemented;
 }


 template<class Type>
 void Foam::jumpCyclicMHFvPatchField<Type>::updateInterfaceMatrix
 (
     Field<Type>& result,
     const bool add,
     const Field<Type>& psiInternal,
     const scalarField& coeffs,
     const Pstream::commsTypes
 ) const
 {
     Field<Type> pnf(this->size());

     const labelUList& nbrFaceCells =
         this->cyclicPatch().neighbFvPatch().faceCells();

     // only apply jump to original field
     if (&psiInternal == &this->primitiveField())
     {
         Field<Type> jf(this->jump());

         if (!this->cyclicPatch().owner())
         {
             jf *= -1.0;
         }

         forAll(*this, facei)
         {
             pnf[facei] = psiInternal[nbrFaceCells[facei]] - jf[facei];
         }
     }
     else
     {
         forAll(*this, facei)
         {
             pnf[facei] = psiInternal[nbrFaceCells[facei]];
         }
     }

     // Transform according to the transformation tensors
     this->transformCoupleField(pnf);

     // Multiply the field by coefficients and add into the result
     const labelUList& faceCells = this->cyclicPatch().faceCells();
    forAll(faceCells, elemI)
    {
        result[faceCells[elemI]] -= coeffs[elemI]*pnf[elemI];
    }
 }

Comments