CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Programming & Development (https://www.cfd-online.com/Forums/openfoam-programming-development/)
-   -   redefinition problems for a custom boundary condition (https://www.cfd-online.com/Forums/openfoam-programming-development/238054-redefinition-problems-custom-boundary-condition.html)

ywem August 20, 2021 02:21

redefinition problems for a custom boundary condition
 
Dear all,
I am defining a custom fvPatchField named "niMixedFvPatchField", which is derived from the standard "mixedFvPatchField". Here is the code:

niMixedFvPatchField.H

#ifndef niMixedFvPatchField_H
#define niMixedFvPatchField_H

#include "mixedFvPatchFields.H"
#include "scalarField.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
class niMixedFvPatchField
:
public mixedFvPatchField<scalar>
{
public:

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

// Constructors

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

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

//- Construct by mapping the given niMixedFvPatchField onto a new patch
niMixedFvPatchField
(
const niMixedFvPatchField&,
const fvPatch&,
const DimensionedField<scalar, volMesh>&,
const fvPatchFieldMapper&,
const bool mappingRequired=true
);

//- Copy constructor
niMixedFvPatchField
(
const niMixedFvPatchField&
);

//- Construct and return a clone
virtual tmp<fvPatchField<scalar>> clone() const
{
return tmp<fvPatchField<scalar>>
(
new niMixedFvPatchField (*this)
);
}

//- Copy constructor setting internal field reference
niMixedFvPatchField
(
const niMixedFvPatchField&,
const DimensionedField<scalar, volMesh>&
);

//- Construct and return a clone setting internal field reference
virtual tmp<fvPatchField<scalar>> clone
(
const DimensionedField<scalar, volMesh>& iF
) const
{
return tmp<fvPatchField<scalar>>
(
new niMixedFvPatchField(*this, iF)
);
}

// Member Functions

// Evaluation functions

//- Return gradient at boundary
virtual tmp<scalarField> snGrad() const;

//- Evaluate the patch field
virtual void evaluate
(
const Pstream::commsTypes commsType =
Pstream::commsTypes::blocking
);

//- Return the matrix diagonal coefficients corresponding to the
// evaluation of the value of this patchField with given weights
virtual tmp<scalarField> valueInternalCoeffs
(
const tmp<scalarField>&
) const;

//- Return the matrix source coefficients corresponding to the
// evaluation of the value of this patchField with given weights
virtual tmp<scalarField> valueBoundaryCoeffs
(
const tmp<scalarField>&
) const;

//- Return the matrix diagonal coefficients corresponding to the
// evaluation of the gradient of this patchField
virtual tmp<scalarField> gradientInternalCoeffs() const;

//- Return the matrix source coefficients corresponding to the
// evaluation of the gradient of this patchField
virtual tmp<scalarField> gradientBoundaryCoeffs() const;


//- Write
virtual void write(Ostream&) const;
};


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

} // End namespace Foam

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


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

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

#endif



niMixedFvPatchField.C

#include "niMixedFvPatchField.H"
#include "addToRunTimeSelectionTable.H"
#include "fvPatchFieldMapper.H"
#include "mappedPatchBase.H"
#include "volFields.H"
#include "surfaceFields.H"

namespace Foam
{
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //

niMixedFvPatchField::niMixedFvPatchField
(
const fvPatch& p,
const DimensionedField<scalar, volMesh>& iF
)
:
mixedFvPatchField<scalar>(p, iF)
{
this->refValue() = 0.0;
this->refGrad() = 0.0;
this->valueFraction() =0.0;
}


niMixedFvPatchField::niMixedFvPatchField
(
const fvPatch& p,
const DimensionedField<scalar, volMesh>& iF,
const dictionary& dict
)
:
mixedFvPatchField<scalar>(p, iF, dict)
{
if (!isA<mappedPatchBase>(this->patch().patch()))
{
FatalErrorIn
(
"niMixedFvPatchField::"
"niMixedFvPatchField\n"
"(\n"
" const fvPatch& p,\n"
" const DimensionedField<scalar, volMesh>& iF,\n"
" const dictionary& dict\n"
")\n"
)
<< "\n patch type '" << p.type()
<< "' not type '" << mappedPatchBase::typeName << "'"
<< "\n for patch " << p.name()
<< exit(FatalError);
}
fvPatchScalarField::operator = (scalarField("value", dict, p.size()));
if(dict.found("refValue"))
{
refValue() = scalarField("refValue", dict, p.size());
refGrad() = scalarField("refGradient", dict, p.size());
valueFraction() = scalarField("valueFraction", dict, p.size());
}
else
{
refValue() = *this;
refGrad() = 0.0;
valueFraction() = 1.0;
}
}

niMixedFvPatchField::niMixedFvPatchField
(
const niMixedFvPatchField& ptf,
const fvPatch& p,
const DimensionedField<scalar, volMesh>& iF,
const fvPatchFieldMapper& mapper,
const bool mappingRequired
)
:
mixedFvPatchField<scalar>(ptf, p, iF, mapper, mappingRequired)
{ }


niMixedFvPatchField::niMixedFvPatchField
(
const niMixedFvPatchField& ptf
)
:
mixedFvPatchField<scalar>(ptf)
{}


niMixedFvPatchField::niMixedFvPatchField
(
const niMixedFvPatchField& ptf,
const DimensionedField<scalar, volMesh>& iF
)
:
mixedFvPatchField<scalar>(ptf, iF)
{}


// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
/*
void Foam::niMixedFvPatchField::autoMap
(
const fvPatchFieldMapper& m
)
{
mixedFvPatchField<scalar>::autoMap(m);
m(refValue_, refValue_);
m(refGrad_, refGrad_);
m(valueFraction_, valueFraction_);
// m(I_, I_);
}


void Foam::niMixedFvPatchField::rmap
(
const fvPatchField<scalar>& ptf,
const labelList& addr
)
{
mixedFvPatchField<scalar>::rmap(ptf, addr);
const niMixedFvPatchField& mptf = refCast<const niMixedFvPatchField>(ptf);
refValue_.rmap(mptf.refValue_, addr);
refGrad_.rmap(mptf.refGrad_, addr);
valueFraction_.rmap(mptf.valueFraction_, addr);
}
*/

void niMixedFvPatchField::evaluate(const Pstream::commsTypes)
{
if (!this->updated())
{
this->updateCoeffs();
}

const fvPatchField<scalar>& ni_patch = patch().lookupPatchField<volScalarField, scalar>("ni");
scalarField gradni_patch = ni_patch.snGrad();
const scalarField& En = patch().lookupPatchField<volVectorField, vector>("E") & patch().nf();
const scalarField& Di = patch().lookupPatchField<volScalarField, scalar>("Di");
const scalar Zi = 1.33e-4;
const scalar I = 4.1e-3;
const scalar s = 2.512e-9;
scalar e = 1.60217e-19;

this->valueFraction() = scalarField(gradni_patch.size(), 1.0);
this->refGrad() = scalarField(gradni_patch.size(), 0.0);
this->refValue() = (Di/(Zi*En))*gradni_patch - I/(e*s*Zi*En);

/*
Field<scalar>::operator=
(
valueFraction_*refValue_
+
(1.0 - valueFraction_)*
(
this->patchInternalField()
+ refGrad_/this->patch().deltaCoeffs()
)
);
*/
mixedFvPatchField<scalar>::evaluate();
}


tmp<scalarField> niMixedFvPatchField::snGrad() const
{
return
this->patch().deltaCoeffs()
*
(*this - this->patchInternalField());
}


tmp<scalarField> niMixedFvPatchField::valueInternalCoeffs
(
const tmp<scalarField>&
) const
{
return tmp<scalarField> (new scalarField(this->size(), pTraits<scalar>::zero));

}


tmp<scalarField> niMixedFvPatchField::valueBoundaryCoeffs
(
const tmp<scalarField>&
) const
{
const fvPatchField<scalar>& ni_patch = patch().lookupPatchField<volScalarField, scalar>("ni");
scalarField gradni_patch = ni_patch.snGrad();
const scalarField& En = patch().lookupPatchField<volVectorField, vector>("E") & patch().nf();
const scalarField& Di = patch().lookupPatchField<volScalarField, scalar>("Di");
const scalar Zi = 1.33e-4;
const scalar I = 4.1e-3;
const scalar s = 2.512e-9;
scalar e = 1.60217e-19;
return (Di/(Zi*En))*gradni_patch - I/(e*s*Zi*En);
}


tmp<scalarField> niMixedFvPatchField::gradientInternalCoeffs() const
{
const fvPatchField<scalar>& ni_patch = patch().lookupPatchField<volScalarField, scalar>("ni");
const scalarField& En = patch().lookupPatchField<volVectorField, vector>("E") & patch().nf();
const scalarField& Di = patch().lookupPatchField<volScalarField, vector>("Di");
const scalar Zi = 1.33e-4;
return Zi*En*ni_patch/Di;
}


tmp<scalarField> niMixedFvPatchField::gradientBoundaryCoeffs() const
{
const scalarField& En = patch().lookupPatchField<volVectorField, vector>("E") & patch().nf();
const scalar Zi = 1.33e-4;
const scalar I = 4.1e-3;
const scalar s = 2.512e-9;
scalar e = 1.60217e-19;
return I/(e*s*Zi*En);
}


void niMixedFvPatchField::write(Ostream& os) const
{
mixedFvPatchField<scalar>::write(os);
}

makePatchTypeField
(
fvPatchScalarField,
niMixedFvPatchField
);

}

When I compile it, the following errors display,

niMixedFvPatchField.C:39:1: error: redefinition of ‘Foam::niMixedFvPatchField::niMixedFvPatchField(co nst Foam::fvPatch&, const Foam::DimensionedField<double, Foam::volMesh>&)’
39 | niMixedFvPatchField::niMixedFvPatchField
| ^~~~~~~~~~~~~~~~~~~
In file included from include/niMixedFvPatchField.H:324,
from niMixedFvPatchField.C:26:
./niMixedFvPatchField.C:39:1: note: ‘Foam::niMixedFvPatchField::niMixedFvPatchField(co nst Foam::fvPatch&, const Foam::DimensionedField<double, Foam::volMesh>&)’ previously defined here
39 | niMixedFvPatchField::niMixedFvPatchField
| ^~~~~~~~~~~~~~~~~~~
niMixedFvPatchField.C:53:1: error: redefinition of ‘Foam::niMixedFvPatchField::niMixedFvPatchField(co nst Foam::fvPatch&, const Foam::DimensionedField<double, Foam::volMesh>&, const Foam::dictionary&)’
53 | niMixedFvPatchField::niMixedFvPatchField
| ^~~~~~~~~~~~~~~~~~~
In file included from include/niMixedFvPatchField.H:324,
from niMixedFvPatchField.C:26:
./niMixedFvPatchField.C:53:1: note: ‘Foam::niMixedFvPatchField::niMixedFvPatchField(co nst Foam::fvPatch&, const Foam::DimensionedField<double, Foam::volMesh>&, const Foam::dictionary&)’ previously defined here
53 | niMixedFvPatchField::niMixedFvPatchField


Can anyone help me for this problem? Thanks in advance.


All times are GMT -4. The time now is 09:12.