foamNewBC: script to create template code for a new boundary condition

Run foamNewBC -h for details
This commit is contained in:
Chris Greenshields
2015-12-04 14:33:56 +00:00
parent 10ded8a669
commit 6b67e39136
8 changed files with 854 additions and 0 deletions

240
etc/codeTemplates/BC/BC.C Normal file
View File

@ -0,0 +1,240 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2015 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "CONSTRUCT.H"
#include "addToRunTimeSelectionTable.H"
#include "fvPatchFieldMapper.H"
#include "volFields.H"
#include "surfaceFields.H"
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
template<class Type>
Foam::scalar Foam::CLASS::t() const
{
return this->db().time().timeOutputValue();
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<class Type>
Foam::CLASS::
CONSTRUCT
(
const fvPatch& p,
const DimensionedField<TYPE, volMesh>& iF
)
:
PARENT(p, iF),
scalarData_(0.0),
data_(pTraits<TYPE>::zero),
fieldData_(p.size(), pTraits<TYPE>::zero),
timeVsData_(),
wordData_("wordDefault"),
labelData_(-1),
boolData_(false)
{
this->refValue() = pTraits<TYPE>::zero;
this->refGrad() = pTraits<TYPE>::zero;
this->valueFraction() = 0.0;
}
template<class Type>
Foam::CLASS::
CONSTRUCT
(
const fvPatch& p,
const DimensionedField<TYPE, volMesh>& iF,
const dictionary& dict
)
:
PARENT(p, iF),
scalarData_(readScalar(dict.lookup("scalarData"))),
data_(pTraits<TYPE>(dict.lookup("data"))),
fieldData_("fieldData", dict, p.size()),
timeVsData_(DataEntry<TYPE>::New("timeVsData", dict)),
wordData_(dict.lookupOrDefault<word>("wordName", "wordDefault")),
labelData_(-1),
boolData_(false)
{
this->refGrad() = pTraits<TYPE>::zero;
this->valueFraction() = 0.0;
this->refValue() = FIELD("fieldData", dict, p.size());
FVPATCHF::operator=(this->refValue());
PARENT::evaluate();
/*
//Initialise with the value entry if evaluation is not possible
FVPATCHF::operator=
(
FIELD("value", dict, p.size())
);
this->refValue() = *this;
*/
}
template<class Type>
Foam::CLASS::
CONSTRUCT
(
const CLASS& ptf,
const fvPatch& p,
const DimensionedField<TYPE, volMesh>& iF,
const fvPatchFieldMapper& mapper
)
:
PARENT(ptf, p, iF, mapper),
scalarData_(ptf.scalarData_),
data_(ptf.data_),
fieldData_(ptf.fieldData_, mapper),
timeVsData_(ptf.timeVsData_, false),
wordData_(ptf.wordData_),
labelData_(-1),
boolData_(ptf.boolData_)
{}
template<class Type>
Foam::CLASS::
CONSTRUCT
(
const CLASS& ptf
)
:
PARENT(ptf),
scalarData_(ptf.scalarData_),
data_(ptf.data_),
fieldData_(ptf.fieldData_),
timeVsData_(ptf.timeVsData_, false),
wordData_(ptf.wordData_),
labelData_(-1),
boolData_(ptf.boolData_)
{}
template<class Type>
Foam::CLASS::
CONSTRUCT
(
const CLASS& ptf,
const DimensionedField<TYPE, volMesh>& iF
)
:
PARENT(ptf, iF),
scalarData_(ptf.scalarData_),
data_(ptf.data_),
fieldData_(ptf.fieldData_),
timeVsData_(ptf.timeVsData_, false),
wordData_(ptf.wordData_),
labelData_(-1),
boolData_(ptf.boolData_)
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class Type>
void Foam::CLASS::autoMap
(
const fvPatchFieldMapper& m
)
{
PARENT::autoMap(m);
fieldData_.autoMap(m);
}
template<class Type>
void Foam::CLASS::rmap
(
const FVPATCHF& ptf,
const labelList& addr
)
{
PARENT::rmap(ptf, addr);
const CLASS& tiptf =
refCast<const CLASS>(ptf);
fieldData_.rmap(tiptf.fieldData_, addr);
}
template<class Type>
void Foam::CLASS::updateCoeffs()
{
if (this->updated())
{
return;
}
PARENT::operator==
(
data_
+ fieldData_
+ scalarData_*timeVsData_->value(t())
);
const scalarField& phip =
this->patch().template lookupPatchField<surfaceScalarField, scalar>("phi");
this->valueFraction() = 1.0 - pos(phip);
PARENT::updateCoeffs();
}
template<class Type>
void Foam::CLASS::write
(
Ostream& os
) const
{
FVPATCHF::write(os);
os.writeKeyword("scalarData") << scalarData_ << token::END_STATEMENT << nl;
os.writeKeyword("data") << data_ << token::END_STATEMENT << nl;
fieldData_.writeEntry("fieldData", os);
timeVsData_->writeData(os);
os.writeKeyword("wordData") << wordData_ << token::END_STATEMENT << nl;
this->writeEntry("value", os);
}
// * * * * * * * * * * * * * * Build Macro Function * * * * * * * * * * * * //
namespace Foam
{
makePatchTypeField
(
FVPATCHF,
CLASS
);
}
// ************************************************************************* //

246
etc/codeTemplates/BC/BC.H Normal file
View File

@ -0,0 +1,246 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2015 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
Class
Foam::CONSTRUCT
Group
grpGenericBoundaryConditions
Description
This boundary condition provides a NAME condition,
calculated as:
\f[
Q = Q_{0} + Q_{p} + s*Q_{t}
\f]
where
\vartable
s | single scalar value [units]
Q_{0} | single TYPE value [units]
Q_{p} | TYPE field across patch [units]
Q_{t} | TYPE function of time [units]
\endtable
\heading Patch usage
\table
Property | Description | Req'd? | Default
scalarData | single scalar value | yes |
data | single TYPE value | yes |
fieldData | TYPE field across patch | yes |
timeVsData | TYPE function of time | yes |
wordData | word, eg name of data object | no | wordDefault
\endtable
Example of the boundary condition specification:
\verbatim
myPatch
{
type NAME;
scalarData -1;
data ONE;
fieldData uniform THREE;
timeVsData table (
(0 ZERO)
(1 TWO)
);
wordName anotherName;
value uniform FOUR; // optional initial value
}
\endverbatim
SourceFiles
CONSTRUCT.C
\*---------------------------------------------------------------------------*/
#ifndef CONSTRUCT_H
#define CONSTRUCT_H
#include "BASEFvPatchFields.H"
#include "DataEntry.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
/*---------------------------------------------------------------------------*\
Class CONSTRUCT Declaration
\*---------------------------------------------------------------------------*/
template<class Type>
class CONSTRUCT
:
public PARENT
{
// Private data
//- Single valued scalar quantity, e.g. a coefficient
scalar scalarData_;
//- Single valued Type quantity, e.g. reference pressure pRefValue_
// Other options include vector, tensor
TYPE data_;
//- Field of Types, typically defined across patch faces
// e.g. total pressure p0_. Other options include vectorField
FIELD fieldData_;
//- Type specified as a function of time for time-varying BCs
autoPtr<DataEntry<TYPE> > timeVsData_;
//- Word entry, e.g. pName_ for name of the pressure field on database
word wordData_;
//- Label, e.g. patch index, current time index
label labelData_;
//- Boolean for true/false, e.g. specify if flow rate is volumetric_
bool boolData_;
// Private Member Functions
//- Return current time
scalar t() const;
public:
//- Runtime type information
TypeName("NAME");
// Constructors
//- Construct from patch and internal field
CONSTRUCT
(
const fvPatch&,
const DimensionedField<TYPE, volMesh>&
);
//- Construct from patch, internal field and dictionary
CONSTRUCT
(
const fvPatch&,
const DimensionedField<TYPE, volMesh>&,
const dictionary&
);
//- Construct by mapping given BASETypeFvPatchField
// onto a new patch
CONSTRUCT
(
const CLASS&,
const fvPatch&,
const DimensionedField<TYPE, volMesh>&,
const fvPatchFieldMapper&
);
//- Construct as copy
CONSTRUCT
(
const CLASS&
);
//- Construct and return a clone
virtual tmp<FVPATCHF> clone() const
{
return tmp<FVPATCHF>
(
new CLASS(*this)
);
}
//- Construct as copy setting internal field reference
CONSTRUCT
(
const CLASS&,
const DimensionedField<TYPE, volMesh>&
);
//- Construct and return a clone setting internal field reference
virtual tmp<FVPATCHF> clone
(
const DimensionedField<TYPE, volMesh>& iF
) const
{
return tmp<FVPATCHF>
(
new CLASS
(
*this,
iF
)
);
}
// Member functions
// Mapping functions
//- Map (and resize as needed) from self given a mapping object
virtual void autoMap
(
const fvPatchFieldMapper&
);
//- Reverse map the given fvPatchField onto this fvPatchField
virtual void rmap
(
const FVPATCHF&,
const labelList&
);
// Evaluation functions
//- Update the coefficients associated with the patch field
virtual void updateCoeffs();
//- Write
virtual void write(Ostream&) const;
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#ifdef NoRepository
# include "CONSTRUCT.C"
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,43 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2015 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "CONSTRUCTs.H"
#include "addToRunTimeSelectionTable.H"
#include "volFields.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
makePatchFields(NAME);
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// ************************************************************************* //

View File

@ -0,0 +1,49 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2015 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#ifndef CONSTRUCTs_H
#define CONSTRUCTs_H
#include "CONSTRUCT.H"
#include "fieldTypes.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
makePatchTypeFieldTypedefs(NAME);
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,50 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2015 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#ifndef CONSTRUCTsFwd_H
#define CONSTRUCTsFwd_H
#include "fieldTypes.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
template<class Type> class CONSTRUCT;
makePatchTypeFieldTypedefs(NAME);
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,3 @@
COMPILED.C
LIB = $(FOAM_USER_LIBBIN)/libNAME

View File

@ -0,0 +1,7 @@
EXE_INC = \
-I$(LIB_SRC)/finiteVolume/lnInclude \
-I$(LIB_SRC)/meshTools/lnInclude
LIB_LIBS = \
-lfiniteVolume \
-lmeshTools