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

redefinition problems for a custom boundary condition

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   August 20, 2021, 03:21
Default redefinition problems for a custom boundary condition
  #1
Member
 
Wenming Yang
Join Date: Jun 2018
Posts: 42
Rep Power: 8
ywem is on a distinguished road
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:perator = (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>:perator=
(
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:imensionedField<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:imensionedField<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:imensionedField<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:imensionedField<double, Foam::volMesh>&, const Foam::dictionary&)’ previously defined here
53 | niMixedFvPatchField::niMixedFvPatchField


Can anyone help me for this problem? Thanks in advance.
ywem is offline   Reply With Quote

Reply

Tags
boundary, fvpatchfield, redefinition


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
Fatal overflow in linear solver. iamnotfajar CFX 9 October 28, 2020 05:47
Radiation in semi-transparent media with surface-to-surface model? mpeppels CFX 11 August 22, 2019 08:30
CFD analaysis of Pelton turbine amodpanthee CFX 31 April 19, 2018 19:02
Define functions for Boundary Condition of Thermal Problems in Ansys cyrusIII ANSYS 0 October 16, 2016 18:50
Question about heat transfer coefficient setting for CFX Anna Tian CFX 1 June 16, 2013 07:28


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