Merge branch 'develop' of develop.openfoam.com:Development/OpenFOAM-plus into develop

This commit is contained in:
sergio
2017-11-15 10:06:35 -08:00
1565 changed files with 31114 additions and 28829 deletions

View File

@ -209,16 +209,14 @@ void Foam::smoluchowskiJumpTFvPatchScalarField::write(Ostream& os) const
{
fvPatchScalarField::write(os);
writeEntryIfDifferent<word>(os, "U", "U", UName_);
writeEntryIfDifferent<word>(os, "rho", "rho", rhoName_);
writeEntryIfDifferent<word>(os, "psi", "thermo:psi", psiName_);
writeEntryIfDifferent<word>(os, "mu", "thermo:mu", muName_);
os.writeEntryIfDifferent<word>("U", "U", UName_);
os.writeEntryIfDifferent<word>("rho", "rho", rhoName_);
os.writeEntryIfDifferent<word>("psi", "thermo:psi", psiName_);
os.writeEntryIfDifferent<word>("mu", "thermo:mu", muName_);
os.writeKeyword("accommodationCoeff")
<< accommodationCoeff_ << token::END_STATEMENT << nl;
os.writeEntry("accommodationCoeff", accommodationCoeff_);
Twall_.writeEntry("Twall", os);
os.writeKeyword("gamma")
<< gamma_ << token::END_STATEMENT << nl;
os.writeEntry("gamma", gamma_);
writeEntry("value", os);
}

View File

@ -32,8 +32,8 @@ SourceFiles
\*---------------------------------------------------------------------------*/
#ifndef smoluchowskiJumpTFvPatchScalarFields_H
#define smoluchowskiJumpTFvPatchScalarFields_H
#ifndef smoluchowskiJumpTFvPatchScalarField_H
#define smoluchowskiJumpTFvPatchScalarField_H
#include "mixedFvPatchFields.H"
@ -43,7 +43,7 @@ namespace Foam
{
/*---------------------------------------------------------------------------*\
Class smoluchowskiJumpTFvPatch Declaration
Class smoluchowskiJumpTFvPatchScalarField Declaration
\*---------------------------------------------------------------------------*/
class smoluchowskiJumpTFvPatchScalarField
@ -74,6 +74,7 @@ class smoluchowskiJumpTFvPatchScalarField
//- Heat capacity ratio (default 1.4)
scalar gamma_;
public:
//- Runtime type information

View File

@ -200,18 +200,16 @@ void Foam::maxwellSlipUFvPatchVectorField::updateCoeffs()
void Foam::maxwellSlipUFvPatchVectorField::write(Ostream& os) const
{
fvPatchVectorField::write(os);
writeEntryIfDifferent<word>(os, "T", "T", TName_);
writeEntryIfDifferent<word>(os, "rho", "rho", rhoName_);
writeEntryIfDifferent<word>(os, "psi", "thermo:psi", psiName_);
writeEntryIfDifferent<word>(os, "mu", "thermo:mu", muName_);
writeEntryIfDifferent<word>(os, "tauMC", "tauMC", tauMCName_);
os.writeEntryIfDifferent<word>("T", "T", TName_);
os.writeEntryIfDifferent<word>("rho", "rho", rhoName_);
os.writeEntryIfDifferent<word>("psi", "thermo:psi", psiName_);
os.writeEntryIfDifferent<word>("mu", "thermo:mu", muName_);
os.writeEntryIfDifferent<word>("tauMC", "tauMC", tauMCName_);
os.writeKeyword("accommodationCoeff")
<< accommodationCoeff_ << token::END_STATEMENT << nl;
os.writeEntry("accommodationCoeff", accommodationCoeff_);
Uwall_.writeEntry("Uwall", os);
os.writeKeyword("thermalCreep")
<< thermalCreep_ << token::END_STATEMENT << nl;
os.writeKeyword("curvature") << curvature_ << token::END_STATEMENT << nl;
os.writeEntry("thermalCreep", thermalCreep_);
os.writeEntry("curvature", curvature_);
refValue().writeEntry("refValue", os);
valueFraction().writeEntry("valueFraction", os);

View File

@ -117,8 +117,8 @@ void Foam::fixedRhoFvPatchScalarField::write(Ostream& os) const
{
fvPatchScalarField::write(os);
writeEntryIfDifferent<word>(os, "p", "p", this->pName_);
writeEntryIfDifferent<word>(os, "psi", "thermo:psi", psiName_);
os.writeEntryIfDifferent<word>("p", "p", pName_);
os.writeEntryIfDifferent<word>("psi", "thermo:psi", psiName_);
writeEntry("value", os);
}

View File

@ -113,6 +113,9 @@ int main(int argc, char *argv[])
phiv_pos -= mesh.phi();
phiv_neg -= mesh.phi();
}
// Note: extracted out the orientation so becomes unoriented
phiv_pos.setOriented(false);
phiv_neg.setOriented(false);
volScalarField c("c", sqrt(thermo.Cp()/thermo.Cv()*rPsi));
surfaceScalarField cSf_pos
@ -120,14 +123,11 @@ int main(int argc, char *argv[])
"cSf_pos",
interpolate(c, pos, T.name())*mesh.magSf()
);
cSf_pos.setOriented();
surfaceScalarField cSf_neg
(
"cSf_neg",
interpolate(c, neg, T.name())*mesh.magSf()
);
cSf_neg.setOriented();
surfaceScalarField ap
(
@ -168,11 +168,12 @@ int main(int argc, char *argv[])
phi = aphiv_pos*rho_pos + aphiv_neg*rho_neg;
surfaceVectorField phiUp
(
(aphiv_pos*rhoU_pos + aphiv_neg*rhoU_neg)
+ (a_pos*p_pos + a_neg*p_neg)*mesh.Sf()
);
surfaceVectorField phiU(aphiv_pos*rhoU_pos + aphiv_neg*rhoU_neg);
// Note: reassembled orientation from the pos and neg parts so becomes
// oriented
phiU.setOriented(true);
surfaceVectorField phiUp(phiU + (a_pos*p_pos + a_neg*p_neg)*mesh.Sf());
surfaceScalarField phiEp
(
@ -185,7 +186,10 @@ int main(int argc, char *argv[])
// Make flux for pressure-work absolute
if (mesh.moving())
{
phiEp += mesh.phi()*(a_pos*p_pos + a_neg*p_neg);
surfaceScalarField phia(a_pos*p_pos + a_neg*p_neg);
phia.setOriented(true);
phiEp += mesh.phi()*phia;
}
volScalarField muEff("muEff", turbulence->muEff());

View File

@ -93,7 +93,10 @@ int main(int argc, char *argv[])
surfaceScalarField p_neg("p_neg", rho_neg*rPsi_neg);
surfaceScalarField phiv_pos("phiv_pos", U_pos & mesh.Sf());
// Note: extracted out the orientation so becomes unoriented
phiv_pos.setOriented(false);
surfaceScalarField phiv_neg("phiv_neg", U_neg & mesh.Sf());
phiv_neg.setOriented(false);
volScalarField c("c", sqrt(thermo.Cp()/thermo.Cv()*rPsi));
surfaceScalarField cSf_pos
@ -101,20 +104,19 @@ int main(int argc, char *argv[])
"cSf_pos",
interpolate(c, pos, T.name())*mesh.magSf()
);
cSf_pos.setOriented();
surfaceScalarField cSf_neg
(
"cSf_neg",
interpolate(c, neg, T.name())*mesh.magSf()
);
cSf_neg.setOriented();
surfaceScalarField ap
(
"ap",
max(max(phiv_pos + cSf_pos, phiv_neg + cSf_neg), v_zero)
);
surfaceScalarField am
(
"am",
@ -163,11 +165,12 @@ int main(int argc, char *argv[])
phi = aphiv_pos*rho_pos + aphiv_neg*rho_neg;
surfaceVectorField phiUp
(
(aphiv_pos*rhoU_pos + aphiv_neg*rhoU_neg)
+ (a_pos*p_pos + a_neg*p_neg)*mesh.Sf()
);
surfaceVectorField phiU(aphiv_pos*rhoU_pos + aphiv_neg*rhoU_neg);
// Note: reassembled orientation from the pos and neg parts so becomes
// oriented
phiU.setOriented(true);
surfaceVectorField phiUp(phiU + (a_pos*p_pos + a_neg*p_neg)*mesh.Sf());
surfaceScalarField phiEp
(

View File

@ -27,8 +27,8 @@ Description
\*---------------------------------------------------------------------------*/
#ifndef solidRegionDiff_H
#define solidRegionDiff_H
#ifndef solidRegionDiffNo_H
#define solidRegionDiffNo_H
#include "fvMesh.H"

View File

@ -15,12 +15,16 @@
)
: -dpdt
)
- fvm::laplacian(alphaEff, he)
==
radiation->Sh(thermo, he)
+ fvOptions(rho, he)
);
if (turbulence.valid())
{
EEqn -= fvm::laplacian(turbulence->alphaEff(), he);
}
EEqn.relax();
fvOptions.constrain(EEqn);

View File

@ -35,7 +35,31 @@ volVectorField U
#include "compressibleCreatePhi.H"
#include "setAlphaEff.H"
autoPtr<compressible::turbulenceModel> turbulence;
IOobject turbulencePropertiesHeader
(
"turbulenceProperties",
runTime.constant(),
mesh,
IOobject::MUST_READ_IF_MODIFIED,
IOobject::NO_WRITE,
false
);
if (turbulencePropertiesHeader.typeHeaderOk<IOdictionary>(false))
{
Info<< "Creating turbulence model\n" << endl;
turbulence =
compressible::turbulenceModel::New
(
rho,
U,
phi,
thermo
);
}
#include "createDpdt.H"

View File

@ -1,47 +0,0 @@
Info<< "Creating turbulence model\n" << endl;
tmp<volScalarField> talphaEff;
IOobject turbulencePropertiesHeader
(
"turbulenceProperties",
runTime.constant(),
mesh,
IOobject::MUST_READ_IF_MODIFIED,
IOobject::NO_WRITE,
false
);
if (turbulencePropertiesHeader.typeHeaderOk<IOdictionary>(true))
{
autoPtr<compressible::turbulenceModel> turbulence
(
compressible::turbulenceModel::New
(
rho,
U,
phi,
thermo
)
);
talphaEff = turbulence->alphaEff();
}
else
{
talphaEff = tmp<volScalarField>
(
new volScalarField
(
IOobject
(
"alphaEff",
runTime.timeName(),
mesh,
IOobject::NO_READ,
IOobject::NO_WRITE
),
mesh,
dimensionedScalar("0", dimMass/dimLength/dimTime, 0.0)
)
);
}

View File

@ -54,8 +54,6 @@ int main(int argc, char *argv[])
#include "createFields.H"
#include "createFvOptions.H"
const volScalarField& alphaEff = talphaEff();
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
Info<< "\nEvolving thermodynamics\n" << endl;

View File

@ -125,8 +125,7 @@ alphaContactAngleFvPatchScalarField::alphaContactAngleFvPatchScalarField
void alphaContactAngleFvPatchScalarField::write(Ostream& os) const
{
fvPatchScalarField::write(os);
os.writeKeyword("thetaProperties")
<< thetaProps_ << token::END_STATEMENT << nl;
os.writeEntry("thetaProperties", thetaProps_);
writeEntry("value", os);
}

View File

@ -35,8 +35,8 @@ SourceFiles
\*---------------------------------------------------------------------------*/
#ifndef flashThermo_H
#define flashThermo_H
#ifndef twoPhaseMixtureEThermo_H
#define twoPhaseMixtureEThermo_H
#include "volFields.H"

View File

@ -125,8 +125,7 @@ alphaContactAngleFvPatchScalarField::alphaContactAngleFvPatchScalarField
void alphaContactAngleFvPatchScalarField::write(Ostream& os) const
{
fvPatchScalarField::write(os);
os.writeKeyword("thetaProperties")
<< thetaProps_ << token::END_STATEMENT << nl;
os.writeEntry("thetaProperties", thetaProps_);
writeEntry("value", os);
}

View File

@ -32,8 +32,8 @@ SourceFiles
\*---------------------------------------------------------------------------*/
#ifndef constant_H
#define constant_H
#ifndef diameterModels_constant_H
#define diameterModels_constant_H
#include "diameterModel.H"

View File

@ -22,7 +22,7 @@ License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
Class
Foam::isothermal
Foam::diameterModels::isothermal
Description
Isothermal dispersed-phase particle diameter model.
@ -32,8 +32,8 @@ SourceFiles
\*---------------------------------------------------------------------------*/
#ifndef isothermal_H
#define isothermal_H
#ifndef diameterModels_isothermal_H
#define diameterModels_isothermal_H
#include "diameterModel.H"

View File

@ -125,8 +125,7 @@ alphaContactAngleFvPatchScalarField::alphaContactAngleFvPatchScalarField
void alphaContactAngleFvPatchScalarField::write(Ostream& os) const
{
fvPatchScalarField::write(os);
os.writeKeyword("thetaProperties")
<< thetaProps_ << token::END_STATEMENT << nl;
os.writeEntry("thetaProperties", thetaProps_);
writeEntry("value", os);
}

View File

@ -72,8 +72,8 @@ SourceFiles
\*---------------------------------------------------------------------------*/
#ifndef function1_saturationModel_H
#define function1_saturationModel_H
#ifndef saturationModels_function1_H
#define saturationModels_function1_H
#include "saturationModel.H"
#include "Function1.H"

View File

@ -125,8 +125,7 @@ alphaContactAngleFvPatchScalarField::alphaContactAngleFvPatchScalarField
void alphaContactAngleFvPatchScalarField::write(Ostream& os) const
{
fvPatchScalarField::write(os);
os.writeKeyword("thetaProperties")
<< thetaProps_ << token::END_STATEMENT << nl;
os.writeEntry("thetaProperties", thetaProps_);
writeEntry("value", os);
}

View File

@ -138,9 +138,9 @@ void alphatFixedDmdtWallBoilingWallFunctionFvPatchScalarField::write
) const
{
fvPatchField<scalar>::write(os);
os.writeKeyword("relax") << relax_ << token::END_STATEMENT << nl;
os.writeKeyword("fixedDmdt") << fixedDmdt_ << token::END_STATEMENT << nl;
os.writeKeyword("L") << L_ << token::END_STATEMENT << nl;
os.writeEntry("relax", relax_);
os.writeEntry("fixedDmdt", fixedDmdt_);
os.writeEntry("L", L_);
dmdt_.writeEntry("dmdt", os);
writeEntry("value", os);
}

View File

@ -334,10 +334,10 @@ void alphatPhaseChangeJayatillekeWallFunctionFvPatchScalarField::write
) const
{
fvPatchField<scalar>::write(os);
os.writeKeyword("Prt") << Prt_ << token::END_STATEMENT << nl;
os.writeKeyword("Cmu") << Cmu_ << token::END_STATEMENT << nl;
os.writeKeyword("kappa") << kappa_ << token::END_STATEMENT << nl;
os.writeKeyword("E") << E_ << token::END_STATEMENT << nl;
os.writeEntry("Prt", Prt_);
os.writeEntry("Cmu", Cmu_);
os.writeEntry("kappa", kappa_);
os.writeEntry("E", E_);
dmdt_.writeEntry("dmdt", os);
writeEntry("value", os);
}

View File

@ -596,42 +596,36 @@ void alphatWallBoilingWallFunctionFvPatchScalarField::write(Ostream& os) const
{
fvPatchField<scalar>::write(os);
os.writeKeyword("phaseType") << phaseTypeNames_[phaseType_]
<< token::END_STATEMENT << nl;
os.writeEntry("phaseType", phaseTypeNames_[phaseType_]);
os.writeKeyword("relax") << relax_ << token::END_STATEMENT << nl;
os.writeEntry("relax", relax_);
switch (phaseType_)
{
case vaporPhase:
{
os.writeKeyword("partitioningModel") << nl;
os << indent << token::BEGIN_BLOCK << incrIndent << nl;
os.beginBlock("partitioningModel");
partitioningModel_->write(os);
os << decrIndent << indent << token::END_BLOCK << nl;
os.endBlock();
break;
}
case liquidPhase:
{
os.writeKeyword("partitioningModel") << nl;
os << indent << token::BEGIN_BLOCK << incrIndent << nl;
os.beginBlock("partitioningModel");
partitioningModel_->write(os);
os << decrIndent << indent << token::END_BLOCK << nl;
os.endBlock();
os.writeKeyword("nucleationSiteModel") << nl;
os << indent << token::BEGIN_BLOCK << incrIndent << nl;
os.beginBlock("nucleationSiteModel");
nucleationSiteModel_->write(os);
os << decrIndent << indent << token::END_BLOCK << nl;
os.endBlock();
os.writeKeyword("departureDiamModel") << nl;
os << indent << token::BEGIN_BLOCK << incrIndent << nl;
os.beginBlock("departureDiamModel");
departureDiamModel_->write(os);
os << decrIndent << indent << token::END_BLOCK << nl;
os.endBlock();
os.writeKeyword("departureFreqModel") << nl;
os << indent << token::BEGIN_BLOCK << incrIndent << nl;
os.beginBlock("departureFreqModel");
departureFreqModel_->write(os);
os << decrIndent << indent << token::END_BLOCK << nl;
os.endBlock();
break;
}

View File

@ -109,8 +109,7 @@ void Foam::copiedFixedValueFvPatchScalarField::updateCoeffs()
void Foam::copiedFixedValueFvPatchScalarField::write(Ostream& os) const
{
fvPatchField<scalar>::write(os);
os.writeKeyword("sourceField")
<< sourceFieldName_ << token::END_STATEMENT << nl;
os.writeEntry("sourceField", sourceFieldName_);
writeEntry("value", os);
}

View File

@ -183,7 +183,7 @@ void Foam::fixedMultiPhaseHeatFluxFvPatchScalarField::updateCoeffs()
void Foam::fixedMultiPhaseHeatFluxFvPatchScalarField::write(Ostream& os) const
{
fvPatchField<scalar>::write(os);
os.writeKeyword("relax") << relax_ << token::END_STATEMENT << nl;
os.writeEntry("relax", relax_);
q_.writeEntry("q", os);
writeEntry("value", os);
}

View File

@ -114,7 +114,7 @@ void Foam::wallBoilingModels::departureDiameterModels::
KocamustafaogullariIshii::write(Ostream& os) const
{
departureDiameterModel::write(os);
os.writeKeyword("phi") << phi_ << token::END_STATEMENT << nl;
os.writeEntry("phi", phi_);
}

View File

@ -90,9 +90,9 @@ void Foam::wallBoilingModels::departureDiameterModels::
TolubinskiKostanchuk::write(Ostream& os) const
{
departureDiameterModel::write(os);
os.writeKeyword("dRef") << dRef_ << token::END_STATEMENT << nl;
os.writeKeyword("dMax") << dMax_ << token::END_STATEMENT << nl;
os.writeKeyword("dMin") << dMin_ << token::END_STATEMENT << nl;
os.writeEntry("dRef", dRef_);
os.writeEntry("dMax", dMax_);
os.writeEntry("dMin", dMin_);
}

View File

@ -53,7 +53,7 @@ Foam::wallBoilingModels::departureDiameterModel::~departureDiameterModel()
void Foam::wallBoilingModels::departureDiameterModel::write(Ostream& os) const
{
os.writeKeyword("type") << this->type() << token::END_STATEMENT << nl;
os.writeEntry("type", this->type());
}
// ************************************************************************* //

View File

@ -53,7 +53,7 @@ Foam::wallBoilingModels::departureFrequencyModel::~departureFrequencyModel()
void Foam::wallBoilingModels::departureFrequencyModel::write(Ostream& os) const
{
os.writeKeyword("type") << this->type() << token::END_STATEMENT << nl;
os.writeEntry("type", this->type());
}

View File

@ -53,7 +53,7 @@ Foam::wallBoilingModels::nucleationSiteModel::~nucleationSiteModel()
void Foam::wallBoilingModels::nucleationSiteModel::write(Ostream& os) const
{
os.writeKeyword("type") << this->type() << token::END_STATEMENT << nl;
os.writeEntry("type", this->type());
}

View File

@ -88,7 +88,7 @@ void Foam::wallBoilingModels::partitioningModels::
Lavieville::write(Ostream& os) const
{
partitioningModel::write(os);
os.writeKeyword("alphaCrit") << alphaCrit_ << token::END_STATEMENT << nl;
os.writeEntry("alphaCrit", alphaCrit_);
}

View File

@ -97,10 +97,8 @@ void Foam::wallBoilingModels::partitioningModels::
cosine::write(Ostream& os) const
{
partitioningModel::write(os);
os.writeKeyword("alphaLiquid1") << alphaLiquid1_
<< token::END_STATEMENT << nl;
os.writeKeyword("alphaLiquid0") << alphaLiquid0_
<< token::END_STATEMENT << nl;
os.writeEntry("alphaLiquid1", alphaLiquid1_);
os.writeEntry("alphaLiquid0", alphaLiquid0_);
}

View File

@ -90,10 +90,8 @@ void Foam::wallBoilingModels::partitioningModels::
linear::write(Ostream& os) const
{
partitioningModel::write(os);
os.writeKeyword("alphaLiquid1") << alphaLiquid1_
<< token::END_STATEMENT << nl;
os.writeKeyword("alphaLiquid0") << alphaLiquid0_
<< token::END_STATEMENT << nl;
os.writeEntry("alphaLiquid1", alphaLiquid1_);
os.writeEntry("alphaLiquid0", alphaLiquid0_);
}

View File

@ -53,7 +53,7 @@ Foam::wallBoilingModels::partitioningModel::~partitioningModel()
void Foam::wallBoilingModels::partitioningModel::write(Ostream& os) const
{
os.writeKeyword("type") << this->type() << token::END_STATEMENT << nl;
os.writeEntry("type", this->type());
}

View File

@ -245,8 +245,7 @@ void Foam::JohnsonJacksonParticleSlipFvPatchVectorField::write
) const
{
fvPatchVectorField::write(os);
os.writeKeyword("specularityCoefficient")
<< specularityCoefficient_ << token::END_STATEMENT << nl;
os.writeEntry("specularityCoefficient", specularityCoefficient_);
writeEntry("value", os);
}

View File

@ -289,10 +289,8 @@ void Foam::JohnsonJacksonParticleThetaFvPatchScalarField::write
) const
{
fvPatchScalarField::write(os);
os.writeKeyword("restitutionCoefficient")
<< restitutionCoefficient_ << token::END_STATEMENT << nl;
os.writeKeyword("specularityCoefficient")
<< specularityCoefficient_ << token::END_STATEMENT << nl;
os.writeEntry("restitutionCoefficient", restitutionCoefficient_);
os.writeEntry("specularityCoefficient", specularityCoefficient_);
writeEntry("value", os);
}

View File

@ -245,8 +245,7 @@ void Foam::JohnsonJacksonParticleSlipFvPatchVectorField::write
) const
{
fvPatchVectorField::write(os);
os.writeKeyword("specularityCoefficient")
<< specularityCoefficient_ << token::END_STATEMENT << nl;
os.writeEntry("specularityCoefficient", specularityCoefficient_);
writeEntry("value", os);
}

View File

@ -289,10 +289,8 @@ void Foam::JohnsonJacksonParticleThetaFvPatchScalarField::write
) const
{
fvPatchScalarField::write(os);
os.writeKeyword("restitutionCoefficient")
<< restitutionCoefficient_ << token::END_STATEMENT << nl;
os.writeKeyword("specularityCoefficient")
<< specularityCoefficient_ << token::END_STATEMENT << nl;
os.writeEntry("restitutionCoefficient", restitutionCoefficient_);
os.writeEntry("specularityCoefficient", specularityCoefficient_);
writeEntry("value", os);
}

View File

@ -32,8 +32,8 @@ SourceFiles
\*---------------------------------------------------------------------------*/
#ifndef constant_H
#define constant_H
#ifndef diameterModels_constant_H
#define diameterModels_constant_H
#include "diameterModel.H"

View File

@ -32,8 +32,8 @@ SourceFiles
\*---------------------------------------------------------------------------*/
#ifndef isothermal_H
#define isothermal_H
#ifndef diameterModels_isothermal_H
#define diameterModels_isothermal_H
#include "diameterModel.H"

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation |
\\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -27,7 +27,10 @@ Description
#include "DynamicList.H"
#include "IOstreams.H"
#include "FlatOutput.H"
#include "ListOps.H"
#include "labelRange.H"
#include "labelIndList.H"
using namespace Foam;
@ -43,16 +46,24 @@ void printInfo
if (showSize)
{
Info<< " size=\"" << lst.size() << "\"";
if (lst.cdata())
{
Info<< " ptr=\"" << long(lst.cdata()) << "\"";
}
Info<< ">" << lst << "</" << tag << ">" << endl;
else
{
Info<< " ptr=\"nullptr\"";
}
}
Info<< ">" << nl << flatOutput(lst) << nl << "</" << tag << ">" << endl;
}
template<class T, unsigned SizeInc, unsigned SizeMult, unsigned SizeDiv>
template<class T, int SizeMin>
void printInfo
(
const word& tag,
const DynamicList<T, SizeInc, SizeMult, SizeDiv>& lst,
const DynamicList<T, SizeMin>& lst,
const bool showSize = false
)
{
@ -61,8 +72,16 @@ void printInfo
{
Info<< " size=\"" << lst.size()
<< "\" capacity=\"" << lst.capacity() << "\"";
if (lst.cdata())
{
Info<< " ptr=\"" << long(lst.cdata()) << "\"";
}
Info<< ">" << lst << "</" << tag << ">" << endl;
else
{
Info<< " ptr=\"nullptr\"";
}
}
Info<< ">" << nl << flatOutput(lst) << nl << "</" << tag << ">" << endl;
}
@ -71,7 +90,7 @@ void printInfo
int main(int argc, char *argv[])
{
List<DynamicList<label, 1, 0>> ldl(2);
List<DynamicList<label>> ldl(2);
ldl[0](0) = 0;
ldl[0](2) = 2;
@ -89,7 +108,7 @@ int main(int argc, char *argv[])
ldl[1] = 3;
Info<< "<ldl>" << ldl << "</ldl>" << nl << "sizes: ";
Info<< "<ldl>" << flatOutput(ldl) << "</ldl>" << nl << "sizes: ";
forAll(ldl, i)
{
Info<< " " << ldl[i].size() << "/" << ldl[i].capacity();
@ -100,7 +119,7 @@ int main(int argc, char *argv[])
ll[0].transfer(ldl[0]);
ll[1].transfer(ldl[1].shrink());
Info<< "<ldl>" << ldl << "</ldl>" << nl << "sizes: ";
Info<< "<ldl>" << flatOutput(ldl) << "</ldl>" << nl << "sizes: ";
forAll(ldl, i)
{
Info<< " " << ldl[i].size() << "/" << ldl[i].capacity();
@ -111,18 +130,18 @@ int main(int argc, char *argv[])
// test the transfer between DynamicLists
DynamicList<label, 1, 0> dlA
DynamicList<label> dlA
{
0, 1, 2, 3, 4
};
dlA.append({ 5, 6 });
dlA = { 1, 2, 4 };
DynamicList<label, 1, 0> dlB;
DynamicList<label> dlB;
dlA.setCapacity(10);
Info<< "<dlA>" << dlA << "</dlA>" << nl << "sizes: "
Info<< "<dlA>" << flatOutput(dlA) << "</dlA>" << nl << "sizes: "
<< " " << dlA.size() << "/" << dlA.capacity() << endl;
dlB.transfer(dlA);
@ -132,9 +151,9 @@ int main(int argc, char *argv[])
dlB[6] = 6;
Info<< "Transferred to dlB" << endl;
Info<< "<dlA>" << dlA << "</dlA>" << nl << "sizes: "
Info<< "<dlA>" << flatOutput(dlA) << "</dlA>" << nl << "sizes: "
<< " " << dlA.size() << "/" << dlA.capacity() << endl;
Info<< "<dlB>" << dlB << "</dlB>" << nl << "sizes: "
Info<< "<dlB>" << flatOutput(dlB) << "</dlB>" << nl << "sizes: "
<< " " << dlB.size() << "/" << dlB.capacity() << endl;
// try with a normal list:
@ -166,7 +185,7 @@ int main(int argc, char *argv[])
// check allocation granularity
DynamicList<label, 6, 0> dlC;
DynamicList<label> dlC;
printInfo("dlC", dlC, true);
@ -227,7 +246,7 @@ int main(int argc, char *argv[])
dlE2[i] *= 10;
}
UIndirectList<label> uil
labelUIndList uil
(
dlE2, addr
);
@ -236,6 +255,93 @@ int main(int argc, char *argv[])
printInfo("dlE4", dlE4, true);
}
{
Info<< nl << "Test moving:" << nl;
labelList input1 = identity(15);
labelList input2 = identity(15);
inplaceReverseList(input2);
DynamicList<label> list1(std::move(input1));
DynamicList<label> list2;
Info<< "move construct:" << nl
<< "input: " << flatOutput(input1) << nl
<< "list: " << flatOutput(list1) << endl;
list1 = std::move(input2);
Info<< "move assignment:" << nl
<< "input: " << flatOutput(input2) << nl
<< "list: " << flatOutput(list1) << endl;
list2 = std::move(list1);
Info<< "list in: " << flatOutput(list1) << nl
<< "list out: " << flatOutput(list2) << endl;
input2 = std::move(identity(15));
list2 = std::move(input2);
Info<< "list in: " << flatOutput(input2) << nl
<< "list out: " << flatOutput(list2) << endl;
input1 = identity(15);
input2 = identity(15);
inplaceReverseList(input2);
Info<< "test move-append with "
<< flatOutput(input1) << " and " << flatOutput(input2) << endl;
list2.append(std::move(list1));
list2.append(std::move(input1));
list2.append(std::move(input2));
Info<< "result: " << flatOutput(list2) << nl
<< "inputs: " << flatOutput(list1) << " / "
<< flatOutput(input1) << " / "
<< flatOutput(input2) << nl;
Info<< "test move dissimilar sizing:" << nl;
list1 = list2;
list1.reserve(100);
// DynamicList<label,1000> list3; // (std::move(list1));
DynamicList<label,1000> list3(std::move(list1));
Info<< "orig: " << flatOutput(list1) << nl;
// list3.swap(list1);
// list3 = std::move(list1);
printInfo("input", list1, true);
printInfo("output", list3, true);
input1 = list2;
Info<< nl << "test subset/remove with "
<< flatOutput(input1) << endl;
for
(
const labelRange range :
{
labelRange(-10, 8), // invalid range
labelRange(40, 18), // trailing portion
labelRange(-5, 10), // leading portion
labelRange(10, 8), // mid-portion
labelRange(0, input1.size()), // everything
}
)
{
list1 = input1;
list2 = input1;
list1.remove(range);
list2.subset(range);
Info<< "input = " << flatOutput(input1) << nl
<< "remove " << range << " = " << flatOutput(list1) << nl
<< "subset " << range << " = " << flatOutput(list2) << nl;
}
}
Info<< "\nEnd\n";

View File

@ -1,3 +0,0 @@
Test-Field.C
EXE = $(FOAM_USER_APPBIN)/Test-Field

View File

@ -1,11 +0,0 @@
#include "Test-Field.H"
int main()
{
Vector<double> v1(1, 2);
Vector<double> v2(2, 3);
std::cout << v1 + v2;
return 0;
}

View File

@ -1,58 +0,0 @@
#include <iostream>
template<class C>
class Vector;
template<class C>
Vector<C> operator+(const Vector<C>& v1, const Vector<C>& v2);
template<class C>
std::ostream& operator<<(std::ostream& os, const Vector<C>& v);
/*---------------------------------------------------------------------------*\
Class Vector Declaration
\*---------------------------------------------------------------------------*/
template<class C>
class Vector
{
double X, Y;
public:
inline Vector(const double x, const double y);
C x() const
{
return X;
}
C y() const
{
return Y;
}
friend Vector<C> operator+ <C>(const Vector<C>& v1, const Vector<C>& v2);
friend std::ostream& operator<<(std::ostream& os, const Vector<C>& v)
{
os << v.X << '\t' << v.Y << '\n';
return os;
}
};
template<class C>
inline Vector<C>::Vector(const double x, const double y)
{
X = x;
Y = y;
}
template<class C>
inline Vector<C> operator+(const Vector<C>& v1, const Vector<C>& v2)
{
return Vector<C>(v1.X+v2.X, v1.Y+v2.Y);
}

View File

@ -35,8 +35,10 @@ See also
#include "argList.H"
#include "FixedList.H"
#include "Fstream.H"
#include "List.H"
#include "IPstream.H"
#include "OPstream.H"
#include <numeric>
using namespace Foam;
@ -47,14 +49,68 @@ int main(int argc, char *argv[])
{
argList args(argc, argv);
FixedList<label, 4> list;
list[0] = 1;
list[1] = 2;
list[2] = 3;
list[3] = 4;
if (false)
{
FixedList<string, 1> ident;
Info<< "list:" << list
<< " hash:" << FixedList<label, 4>::Hash<>()(list) << endl;
auto iter = ident.begin();
Info << iter->size() << endl;
auto riter = ident.rbegin();
Info << riter->size() << endl;
auto iter2 = ident.rbegin();
iter2 = iter;
}
{
FixedList<label, 15> ident;
std::iota(ident.begin(), ident.end(), 0);
// auto iter = ident.begin();
//
// iter += 5;
// Info << *iter << "< " << endl;
// iter -= 2;
// Info << *iter << "< " << endl;
// Don't yet bother with making reverse iterators random access
// auto riter = ident.crbegin();
// riter += 5;
// Info << *riter << "< " << endl;
// riter += 2;
// Info << *riter << "< " << endl;
Info<<"Ident:";
forAllConstIters(ident, iter)
{
Info<<" " << *iter;
}
Info<< nl;
Info<<"reverse:";
forAllReverseIters(ident, iter)
{
Info<<" " << *iter;
}
Info<< nl;
Info<<"const reverse:";
forAllConstReverseIters(ident, iter)
{
Info<<" " << *iter;
}
Info<< nl;
}
{
FixedList<label, 4> list1{1, 2, 3, 4};
Info<< "list1:" << list1
<< " hash:" << FixedList<label, 4>::Hash<>()(list1) << endl;
label a[4] = {0, 1, 2, 3};
FixedList<label, 4> list2(a);
@ -64,20 +120,31 @@ int main(int argc, char *argv[])
// Using FixedList for content too
{
List<FixedList<label, 4>> twolists{list, list2};
List<FixedList<label, 4>> twolists{list1, list2};
Info<<"List of FixedList: " << flatOutput(twolists) << endl;
sort(twolists);
// outer-sort only
Info<<"sorted FixedList : " << flatOutput(twolists) << endl;
}
Info<< "list: " << list << nl
Info<< "====" << nl
<< "Test swap" << nl;
Info<< "list1: " << list1 << nl
<< "list2: " << list2 << endl;
list.swap(list2);
Info<< "Swapped via the swap() method" << endl;
Info<< "list: " << list << nl
list1.swap(list2);
Info<< "The swap() method" << endl;
Info<< "list1: " << list1 << nl
<< "list2: " << list2 << endl;
Swap(list1, list2);
Info<< "The Swap() function" << endl;
Info<< "list1: " << list1 << nl
<< "list2: " << list2 << endl;
Info<< "====" << nl;
}
List<label> list3{0, 1, 2, 3};
FixedList<label, 4> list4(list3.begin(), list3.end());
Info<< "list3: " << list3 << nl

View File

@ -0,0 +1,3 @@
Test-FixedList2.C
EXE = $(FOAM_USER_APPBIN)/Test-FixedList2

View File

@ -0,0 +1,190 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2017 OpenCFD Ltd.
\\/ 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/>.
Application
Test-FixedList2
Description
Test speeds, usability of some List/FixedList operations
See also
Foam::FixedList
\*---------------------------------------------------------------------------*/
#include "argList.H"
#include "FixedList.H"
#include "labelList.H"
#include "vectorList.H"
#include "ListOps.H"
#include "IFstream.H"
#include "OFstream.H"
#include "cpuTime.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
using namespace Foam;
template<class ListType>
void runSwapTest
(
const label nLoops,
ListType& list1,
ListType& list2
)
{
cpuTime timer;
Info<<"Swapping fixed lists with " << list1.size() << " elements\n";
Info<< "input 1: " << list1.first() << nl;
Info<< "input 2: " << list2.first() << nl;
// Should be zero, since this is a compile-time value
Info<< "Perform " << nLoops << " swaps..." << nl;
for (label iLoop = 0; iLoop < nLoops; ++iLoop)
{
Swap(list1, list2);
}
Info<< "output 1: " << list1.first() << nl;
Info<< "output 2: " << list2.first() << nl;
Info<< "Operation took"
<< " " << timer.cpuTimeIncrement() << " s\n\n";
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
int main(int argc, char *argv[])
{
argList::addBoolOption("label");
argList::addBoolOption("float");
argList::addBoolOption("vector");
argList::addBoolOption("labelList");
argList::addBoolOption("vectorList");
argList::addBoolOption("fixedLabel");
argList::addBoolOption("fixedLabelList");
argList args(argc, argv);
if (args.options().empty())
{
Info<< nl << "Specify an option! " << nl << endl;
}
if (args.optionFound("label"))
{
FixedList<label, 100000> list1(1);
FixedList<label, 100000> list2(0);
runSwapTest(1000001, list1, list2);
}
if (args.optionFound("float"))
{
FixedList<double, 100000> list1(1.0);
FixedList<double, 100000> list2(0.0);
runSwapTest(1000001, list1, list2);
}
if (args.optionFound("vector"))
{
FixedList<vector, 100000> list1(vector::one);
FixedList<vector, 100000> list2(vector::zero);
runSwapTest(100001, list1, list2);
}
if (args.optionFound("labelList"))
{
typedef labelList testType;
testType initVal(500);
initVal = 0;
FixedList<testType, 1000> list1(initVal);
initVal = 1;
FixedList<testType, 1000> list2(initVal);
runSwapTest(100001, list1, list2);
}
if (args.optionFound("vectorList"))
{
typedef vectorList testType;
testType initVal(500);
initVal = vector::zero;
FixedList<testType, 1000> list1(initVal);
initVal = vector::one;
FixedList<testType, 1000> list2(initVal);
runSwapTest(100001, list1, list2);
}
if (args.optionFound("fixedLabel"))
{
typedef FixedList<label,1000> testType;
testType initVal;
initVal = 0;
FixedList<testType, 1000> list1(initVal);
initVal = 1;
FixedList<testType, 1000> list2(initVal);
runSwapTest(100001, list1, list2);
}
if (args.optionFound("fixedLabelList"))
{
typedef labelList testType;
typedef FixedList<testType,10> containerType;
testType tinitVal(500);
containerType initVal;
tinitVal = 0;
initVal = tinitVal;
FixedList<containerType, 1000> list1(initVal);
tinitVal = 1;
initVal = tinitVal;
FixedList<containerType, 1000> list2(initVal);
runSwapTest(10001, list1, list2);
}
Info<< nl << "Done" << nl << endl;
return 0;
}
// ************************************************************************* //

View File

@ -31,6 +31,7 @@ Description
#include "fvCFD.H"
#include "Function1.H"
#include "scalarIndList.H"
#include "IOdictionary.H"
#include "linearInterpolationWeights.H"
#include "splineInterpolationWeights.H"
@ -69,7 +70,7 @@ int main(int argc, char *argv[])
scalar baseSum = interpolator.weightedSum
(
weights,
UIndirectList<scalar>(values, indices)
scalarUIndList(values, indices)
);
Pout<< "baseSum=" << baseSum << nl << nl << endl;
@ -78,7 +79,7 @@ int main(int argc, char *argv[])
// scalar partialSum = interpolator.weightedSum
// (
// weights,
// UIndirectList<scalar>(values, indices)
// scalarUIndList(values, indices)
// );
// Pout<< "partialSum=" << partialSum << nl << nl << endl;
//
@ -90,7 +91,7 @@ int main(int argc, char *argv[])
// scalar sum = interpolator.weightedSum
// (
// weights,
// UIndirectList<scalar>(values, indices)
// scalarUIndList(values, indices)
// );
// Pout<< "integrand=" << sum << nl << nl << endl;

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -26,6 +26,7 @@ Description
\*---------------------------------------------------------------------------*/
#include "hashedWordList.H"
#include "nil.H"
#include "HashSet.H"
#include "Map.H"
#include "labelPairHashes.H"
@ -69,6 +70,8 @@ int main(int argc, char *argv[])
Info<< "tableA keys: "; tableA.writeKeys(Info) << endl;
Info<< "tableB content: " << tableB << endl;
auto keyIterPair = tableA.keys();
for (const auto& i : keyIterPair)
{
@ -223,6 +226,31 @@ int main(int argc, char *argv[])
Info << i << endl;
}
Info<< nl << "Test swapping, moving etc." << nl;
setA.insert({ "some", "more", "entries" });
Info<< "input" << nl;
Info<< "setA: " << setA << nl;
wordHashSet setA1(std::move(setA));
Info<< "move construct" << nl;
Info<< "setA: " << setA << nl
<< "setA1: " << setA1 << nl;
wordHashSet setB1;
Info<< "move assign" << nl;
setB1 = std::move(setA1);
Info<< "setA1: " << setA1 << nl
<< "setB1: " << setB1 << nl;
setB1.swap(setA1);
Info<< "setA1: " << setA1 << nl
<< "setB1: " << setB1 << nl;
return 0;
}

View File

@ -1,3 +0,0 @@
Test-hashTable.C
EXE = $(FOAM_USER_APPBIN)/Test-hashTable

View File

@ -0,0 +1,3 @@
Test-HashTable1.C
EXE = $(FOAM_USER_APPBIN)/Test-HashTable1

View File

@ -324,6 +324,34 @@ int main()
<< nl;
// Start again with new value
table2.set("ada", 14.0);
table2.set("aeq", 15.0);
table2.set("aaw", 16.0);
Info<< nl << "input values" << nl;
Info<<"table1 = " << table1 << nl <<"table2 = " << table2 << nl;
Info<<"global Swap function" << nl;
Swap(table1, table2);
Info<<"table1 = " << table1 << nl <<"table2 = " << table2 << nl;
Info<<"swap method" << nl;
table1.swap(table2);
Info<<"table1 = " << table1 << nl <<"table2 = " << table2 << nl;
Info<<"transfer" << nl;
table1.transfer(table2);
Info<<"table1 = " << table1 << nl <<"table2 = " << table2 << nl;
Info<<"move assign" << nl;
table2 = std::move(table1);
Info<<"table1 = " << table1 << nl <<"table2 = " << table2 << nl;
Info<<"move construct" << nl;
HashTable<scalar> table1b(std::move(table2));
Info<<"table1 = " << table1b << nl <<"table2 = " << table2 << nl;
Info<< "\nDone\n";
return 0;

View File

@ -30,17 +30,24 @@ Description
#include "HashTable.H"
#include "HashPtrTable.H"
#include "Map.H"
#include "StaticHashTable.H"
#include "cpuTime.H"
using namespace Foam;
template<class T>
Ostream& printInfo(Ostream& os, const HashTable<T, T, Hash<T>>& ht)
{
os << " (size " << ht.size() << " capacity " << ht.capacity() << ") ";
return os;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// Main program:
int main(int argc, char *argv[])
{
const label nLoops = 30;
const label nLoops = 300;
const label nBase = 100000;
const label nSize = nLoops * nBase;
@ -49,20 +56,20 @@ int main(int argc, char *argv[])
// ie, a
// Map<label> map(2 * nSize);
// HashTable<label, label, Hash<label>> map(2 * nSize);
// StaticHashTable<label, label, Hash<label>> map(2 * nSize);
HashTable<label, label, Hash<label>> map(2 * nSize);
Info<< "Constructed map of size: " << nSize
<< " (size " << map.size() << " capacity " << map.capacity() << ") "
<< " " << timer.cpuTimeIncrement() << " s\n\n";
Info<< "Constructed map of size: " << nSize;
printInfo(Info, map);
Info<< timer.cpuTimeIncrement() << " s\n\n";
for (label i = 0; i < nSize; i++)
{
map.insert(i, i);
}
Info<< "Inserted " << nSize << " elements"
<< " (size " << map.size() << " capacity " << map.capacity() << ") "
<< timer.cpuTimeIncrement() << " s\n";
Info<< "Inserted " << nSize << " elements";
printInfo(Info, map);
Info<< timer.cpuTimeIncrement() << " s\n\n";
label elemI = 0;
for (label iLoop = 0; iLoop < nLoops; iLoop++)
@ -72,12 +79,14 @@ int main(int argc, char *argv[])
map.erase(elemI++);
}
map.shrink();
Info<< "loop " << iLoop << " - Erased " << nBase << " elements"
<< " (size " << map.size() << " capacity " << map.capacity() << ") "
<< timer.cpuTimeIncrement() << " s\n";
// map.shrink();
Info<< "loop " << iLoop << " - Erased " << nBase << " elements";
printInfo(Info, map);
Info << nl;
}
Info<< timer.cpuTimeIncrement() << " s\n";
return 0;
}

View File

@ -0,0 +1,3 @@
Test-HashTable4.C
EXE = $(FOAM_USER_APPBIN)/Test-HashTable4

View File

@ -0,0 +1,312 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2017 OpenCFD Ltd.
\\/ 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/>.
Description
Test HashTable resizing
\*---------------------------------------------------------------------------*/
#include "argList.H"
#include "HashSet.H"
#include "HashTable.H"
#include "Map.H"
#include "cpuTime.H"
#include "memInfo.H"
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
// #undef ORDERED
// #define ORDERED
using namespace Foam;
template<class T>
Ostream& printInfo(Ostream& os, const HashTable<T, T, Hash<T>>& ht)
{
os << " (size " << ht.size() << " capacity " << ht.capacity() << ") ";
return os;
}
template<class K, class V>
inline void insertElem
(
#ifdef ORDERED
std::set<K>& container,
#else
std::unordered_set<K, Hash<K>>& container,
#endif
K k,
V v
)
{
container.insert(k);
}
template<class K, class V>
inline void insertElem
(
#ifdef ORDERED
std::map<K, V>& container,
#else
std::unordered_map<K, V, Hash<K>>& container,
#endif
K k,
V v
)
{
container.insert(std::make_pair(k, v));
}
template<class K, class V>
inline void insertElem
(
HashSet<K, Hash<K>>& container,
K k,
V v
)
{
container.insert(k);
}
template<class K, class V>
inline void insertElem
(
HashTable<K, V, Hash<K>>& container,
K k,
V v
)
{
container.insert(k, v);
}
template<class Container>
inline void loopInsert(Container& container, const label n)
{
for (label i = 0; i < n; i++)
{
insertElem(container, i, i);
}
}
template<class Container>
inline unsigned long loopFind(const Container& container, const label n)
{
const auto endIter = container.end();
unsigned long sum = 0;
for (label i = 0; i < n; i++)
{
if (container.find(i) != endIter)
{
++sum;
}
}
return sum;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// Main program:
int main(int argc, char *argv[])
{
const label nLoops = 200;
const label nFind = 10;
const label nElem = 1000000;
argList::noBanner();
argList::addBoolOption("std", "use std::unordered_map or std::set");
argList::addBoolOption("set", "test HashSet");
argList::addBoolOption("find", "test find");
argList args(argc, argv);
const bool optStd = args.optionFound("std");
const bool optSet = args.optionFound("set");
const bool optFnd = args.optionFound("find");
cpuTime timer;
memInfo mem;
Info<< "insert " << nElem << " (int) elements";
if (optFnd)
{
Info<< ", then find " << (nFind*nLoops) << " times\n";
}
else
{
Info<< " repeated " << nLoops << " times " << endl;
}
if (false)
{
// verify that resizing around (0) doesn't fail
HashTable<label, label, Hash<label>> map(32);
printInfo(Info, map) << endl;
map.insert(10, 1000);
map.resize(0);
printInfo(Info, map) << endl;
map.resize(10);
printInfo(Info, map) << endl;
map.clear();
printInfo(Info, map) << endl;
map.resize(0);
printInfo(Info, map) << endl;
return 0;
}
if (optStd)
{
if (optFnd)
{
#ifdef ORDERED
Info<< "using stl::set" << endl;
std::set<label> map;
#else
Info<< "using stl::unordered_set" << endl;
std::unordered_set<label, Hash<label>> map(32);
#endif
loopInsert(map, nElem);
(void)timer.cpuTimeIncrement();
unsigned long sum = 0;
for (label loopi = 0; loopi < nFind*nLoops; ++loopi)
{
sum += loopFind(map, nElem);
}
// check result (suppress compiler optimizations?)
if (sum == 0)
{
Info<<"sum=0\n";
}
}
else if (optSet)
{
#ifdef ORDERED
Info<< "using stl::set" << endl;
#else
Info<< "using stl::unordered_set" << endl;
#endif
for (label loopi = 0; loopi < nLoops; ++loopi)
{
#ifdef ORDERED
std::set<label> map;
#else
std::unordered_set<label, Hash<label>> map(32);
#endif
loopInsert(map, nElem);
}
}
else
{
#ifdef ORDERED
Info<< "using stl::map" << endl;
#else
Info<< "using stl::unordered_set" << endl;
#endif
for (label loopi = 0; loopi < nLoops; ++loopi)
{
#ifdef ORDERED
std::map<label, label> map;
#else
std::unordered_map<label, label, Hash<label>> map(32);
#endif
loopInsert(map, nElem);
}
}
}
else
{
if (optFnd)
{
Info<< "using HashSet" << endl;
HashSet<label, Hash<label>> map(32);
loopInsert(map, nElem);
(void)timer.cpuTimeIncrement();
unsigned long sum = 0;
for (label loopi = 0; loopi < nFind*nLoops; ++loopi)
{
sum += loopFind(map, nElem);
}
// check result (suppress compiler optimizations?)
if (sum == 0)
{
Info<<"sum=0\n";
}
}
else if (optSet)
{
Info<< "using HashSet" << endl;
for (label loopi = 0; loopi < nLoops; ++loopi)
{
HashSet<label, Hash<label>> map(32);
loopInsert(map, nElem);
}
}
else
{
Info<< "using HashTable" << endl;
for (label loopi = 0; loopi < nLoops; ++loopi)
{
HashTable<label, label, Hash<label>> map(32);
loopInsert(map, nElem);
}
}
}
Info<< timer.cpuTimeIncrement() << " s\n";
Info<< "mem info: " << mem.update() << endl;
return 0;
}
// ************************************************************************* //

View File

@ -0,0 +1,3 @@
EXE_INC = ${c++LESSWARN}
/* EXE_LIBS = */

View File

@ -0,0 +1,3 @@
EXE_INC = ${c++LESSWARN}
/* EXE_LIBS = */

View File

@ -0,0 +1,3 @@
Test-IListStream.C
EXE = $(FOAM_USER_APPBIN)/Test-IListStream

View File

@ -0,0 +1,2 @@
/* EXE_INC = */
/* EXE_LIBS = */

View File

@ -0,0 +1,151 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2017 OpenCFD Ltd.
\\/ 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/>.
Description
\*---------------------------------------------------------------------------*/
#include "ListStream.H"
#include "UListStream.H"
#include "wordList.H"
#include "IOstreams.H"
#include "argList.H"
using namespace Foam;
Ostream& toString(Ostream& os, const UList<char>& list)
{
os << '"';
for (const char c : list)
{
os << c;
}
os << '"';
return os;
}
template<class BufType>
void printInfo(const BufType& buf)
{
Info<< nl << "=========================" << endl;
buf.print(Info);
toString(Info, buf.list());
Info<< nl << "=========================" << endl;
}
void printTokens(Istream& is)
{
label count = 0;
token t;
while (is.good())
{
is >> t;
if (t.good())
{
++count;
Info<<"token: " << t << endl;
}
}
Info<< count << " tokens" << endl;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// Main program:
int main(int argc, char *argv[])
{
// Buffer storage
DynamicList<char> storage(16);
OListStream obuf(std::move(storage));
obuf << 1002 << " " << "abcd" << " " << "def" << " " << 3.14159 << ";\n";
// Move contents to output buffer
printInfo(obuf);
Info<<nl << "as string: ";
toString(Info, obuf.list()) << endl;
Info<< "transfer contents to a List" << endl;
IListStream ibuf(obuf.xfer());
Info<< nl;
Info<< nl << "input string:";
printInfo(ibuf);
Info<< nl << "orig output:";
printInfo(obuf);
printTokens(ibuf);
Info<<nl << "after:";
printInfo(ibuf);
// This should also work
ibuf.list() = 'X';
Info<<nl << "overwritten with const value:";
printInfo(ibuf);
// Can also change content like this:
{
const int n = min(26, ibuf.size());
for (int i=0; i<n; ++i)
{
ibuf.list()[i] = 'A' + i;
}
}
Info<<nl << "directly written:";
printInfo(ibuf);
// But cannot easily swap in/out an entirely new list storage:
//
// List<char> newvalues(52);
// {
// for (int i=0; i<26; ++i)
// {
// newvalues[2*i+0] = char('a' + i);
// newvalues[2*i+1] = char('A' + i);
// }
// }
// ibuf.swap(newvalues);
//
// Info<<nl << "after swap:";
// printInfo(ibuf);
Info<< "\nEnd\n" << endl;
return 0;
}
// ************************************************************************* //

View File

@ -36,20 +36,22 @@ using namespace Foam;
int main(int argc, char *argv[])
{
IStringStream testStream(Foam::string("1002 sfsd sdfsd"));
IStringStream testStream(Foam::string(" 1002 abcd defg;"));
label i(readLabel(testStream));
Info<< i << endl;
Info<< "label=" << i << nl;
word bla(testStream);
word bla2(testStream);
word w1(testStream);
word w2(testStream);
Info<< bla << tab << bla2 << endl;
Info<< "word=" << w1 << nl;
Info<< "word=" << w2 << nl;
wordList wl(IStringStream("(hello1")());
testStream.reset("(hello1)");
Info<< wl << endl;
wordList wl(testStream);
Info<< wl << nl;
Info<< "\nEnd\n" << endl;

View File

@ -0,0 +1,3 @@
Test-ITstream.C
EXE = $(FOAM_USER_APPBIN)/Test-ITstream

View File

@ -0,0 +1,2 @@
/* EXE_INC = */
/* EXE_LIBS = */

View File

@ -0,0 +1,137 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2017 OpenCFD Ltd.
\\/ 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/>.
Description
\*---------------------------------------------------------------------------*/
#include "ListStream.H"
#include "UListStream.H"
#include "wordList.H"
#include "IOstreams.H"
#include "argList.H"
#include "ITstream.H"
using namespace Foam;
template<class T>
Ostream& toString(Ostream& os, const T& str)
{
os << str;
return os;
}
template<>
Ostream& toString(Ostream& os, const UList<char>& list)
{
for (const char c : list)
{
os << c;
}
return os;
}
template<>
Ostream& toString(Ostream& os, const List<char>& list)
{
for (const char c : list)
{
os << c;
}
return os;
}
void printTokens(Istream& is)
{
label count = 0;
token t;
while (is.good())
{
is >> t;
if (t.good())
{
++count;
Info<<"token: " << t << endl;
}
}
Info<< count << " tokens" << endl;
}
template<class BUF>
void doTest(const string& name, const BUF& input, bool verbose=false)
{
Info<<"test " << name.c_str() << ":" << nl
<<"====" << nl;
toString(Info, input)
<< nl
<<"====" << nl << endl;
ITstream its(name, input);
Info<< "got " << its.size() << " tokens - index at "
<< its.tokenIndex() << endl;
if (verbose)
{
for (const token& tok : its)
{
Info<< " " << tok.info() << nl;
}
Info<< nl;
}
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// Main program:
int main(int argc, char *argv[])
{
const char* charInput =
"( const char input \"string\" to tokenize )"
"List<label> 5(0 1 2 3 4);";
string stringInput("( string ; input \"string\" to tokenize )");
List<char> listInput(stringInput.cbegin(), stringInput.cend());
doTest("char*", charInput, true);
doTest("string", stringInput, true);
doTest("List<char>", listInput, true);
reverse(listInput);
doTest("List<char>", listInput, true);
Info<< "\nEnd\n" << endl;
return 0;
}
// ************************************************************************* //

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
\\/ M anipulation |
\\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -27,58 +27,82 @@ Description
#include "IndirectList.H"
#include "IOstreams.H"
#include "Fstream.H"
#include "ListOps.H"
#include "labelIndList.H"
#include "argList.H"
using namespace Foam;
template<class ListType>
void printInfo(const ListType& lst)
{
Info<< "addr: " << lst.addressing() << nl
<< "list: " << lst << nl
Info<< "full: " << flatOutput(lst.completeList()) << nl
<< "addr: " << flatOutput(lst.addressing()) << nl
<< "list: " << flatOutput(lst) << nl
<< endl;
}
template<class T, class ListType>
void testFind(const T& val, const ListType& lst)
{
Info<< nl
<< "Search for "<< val << " in " << flatOutput(lst) << nl
<<" found() = " << lst.found(val)
<<" find() = " << lst.find(val)
<<" rfind() = " << lst.rfind(val)
<<" find(2) = " << lst.find(val, 2)
<<" rfind(2) = " << lst.rfind(val, 2)
<<" findIndex = " << findIndex(lst, val) << nl
<< nl;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// Main program:
int main(int argc, char *argv[])
{
List<double> completeList(10);
argList::addOption
(
"binary",
"file",
"write lists in binary to specified file"
);
argList args(argc, argv);
List<label> completeList(20);
forAll(completeList, i)
{
completeList[i] = 0.1*i;
completeList[i] = 10*i;
}
Info<< "raw : " << completeList << nl << endl;
Info<< "raw : " << flatOutput(completeList) << nl << endl;
List<label> addresses{1, 0, 3, 7, 4, 8, 5, 1, 0, 3, 7, 4, 8, 5, };
List<label> addresses(5);
addresses[0] = 1;
addresses[1] = 0;
addresses[2] = 7;
addresses[3] = 8;
addresses[4] = 5;
IndirectList<double> idl1(completeList, addresses);
labelIndList idl1(completeList, addresses);
printInfo(idl1);
addresses[4] = 1;
addresses[3] = 0;
addresses[2] = 7;
addresses[1] = 8;
addresses[0] = 5;
for (const label val : { 10, 30, 40, 50, 90, 80, 120 } )
{
testFind(val, idl1);
}
inplaceReverseList(addresses);
idl1.resetAddressing(addresses.xfer());
printInfo(idl1);
// test copying
UIndirectList<double> uidl1(idl1);
IndirectList<double> idl2(uidl1);
IndirectList<double> idl3(idl2);
// Test copying
labelUIndList uidl1(idl1);
labelIndList idl2(uidl1);
labelIndList idl3(idl2);
printInfo(uidl1);
@ -92,6 +116,55 @@ int main(int argc, char *argv[])
printInfo(idl2);
printInfo(idl3);
fileName binaryOutput;
if (args.optionReadIfPresent("binary", binaryOutput))
{
Info<<"Writing output to " << binaryOutput << endl;
OFstream os(binaryOutput, IOstream::BINARY);
os.writeEntry("idl1", idl1);
os.writeEntry("idl2", idl2);
os.writeEntry("idl3", idl3);
}
if (Pstream::parRun())
{
if (Pstream::master())
{
Pout<< "full: " << flatOutput(idl3.completeList()) << nl
<< "send: " << flatOutput(idl3) << endl;
for
(
int slave = Pstream::firstSlave();
slave <= Pstream::lastSlave();
++slave
)
{
OPstream toSlave(Pstream::commsTypes::scheduled, slave);
toSlave << idl3;
}
}
else
{
// From master
IPstream fromMaster
(
Pstream::commsTypes::scheduled,
Pstream::masterNo()
);
List<label> recv(fromMaster);
Pout<<"recv: " << flatOutput(recv) << endl;
}
// MPI barrier
bool barrier = true;
Pstream::scatter(barrier);
}
Info<< "End\n" << endl;
return 0;

View File

@ -47,9 +47,24 @@ See also
#include "SubList.H"
#include <list>
#include <numeric>
using namespace Foam;
template<class T, class ListType>
void testFind(const T& val, const ListType& lst)
{
Info<< nl
<< "Search for "<< val << " in " << flatOutput(lst) << nl
<<" found() = " << lst.found(val)
<<" find() = " << lst.find(val)
<<" rfind() = " << lst.rfind(val)
<<" find(2) = " << lst.find(val, 2)
<<" rfind(2) = " << lst.rfind(val, 2)
<<" findIndex = " << findIndex(lst, val) << nl
<< nl;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// Main program:
@ -65,6 +80,33 @@ int main(int argc, char *argv[])
#include "setRootCase.H"
{
List<label> ident(15);
std::iota(ident.begin(), ident.end(), 0);
Info<<"Ident:";
forAllConstIters(ident, iter)
{
Info<<" " << *iter;
}
Info<< nl;
Info<<"reverse:";
forAllReverseIters(ident, iter)
{
Info<<" " << *iter;
}
Info<< nl;
Info<<"const reverse:";
forAllConstReverseIters(ident, iter)
{
Info<<" " << *iter;
}
Info<< nl;
}
if (false)
{
labelList intlist(IStringStream("(0 1 2)")());
@ -84,14 +126,36 @@ int main(int argc, char *argv[])
{
vector(0, 1, 2),
vector(3, 4, 5),
vector(6, 7, 8)
vector(6, 7, 8),
vector(0, 1, 2),
vector(3, 4, 5),
vector(6, 7, 8),
};
Info<< "list2: " << list2 << endl;
Info<< "forAllConstIters(list2): ";
forAllConstIters(list2, iter) { Info<< " " << *iter; }
Info<< endl;
Info<< "forAllConstReverseIters(list2): ";
forAllConstReverseIters(list2, iter) { Info<< " " << *iter; }
Info<< endl;
Info<< "forAllConstIters(list2): ";
forAllIters(list2, iter) { *iter *= 2; Info<< " " << *iter; }
Info<< endl;
Info<< "forAllReverseIters(list2): ";
forAllReverseIters(list2, iter) { *iter *= 0.5; Info<< " " << *iter; }
Info<< endl;
list1.append(list2);
Info<< "list1.append(list2): " << list1 << endl;
Info<< findIndex(list2, vector(3, 4, 5)) << endl;
for (const vector& val : { vector(3, 4, 5), vector(10,11, 12)} )
{
testFind(val, list2);
}
list2.setSize(10, vector(1, 2, 3));
Info<< "list2: " << list2 << endl;

View File

@ -0,0 +1,3 @@
Test-List2.C
EXE = $(FOAM_USER_APPBIN)/Test-List2

View File

View File

@ -0,0 +1,269 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2017 OpenCFD Ltd.
\\/ 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/>.
Application
Test-List2
Description
Test speeds, usability of some List/FixedList operations
\*---------------------------------------------------------------------------*/
#include "argList.H"
#include "FixedList.H"
#include "labelList.H"
#include "vectorList.H"
#include "ListOps.H"
#include "IFstream.H"
#include "OFstream.H"
#include "cpuTime.H"
#include <initializer_list>
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
using namespace Foam;
template<class ListType>
void runResizeTest
(
const label nLoops,
ListType& list,
std::initializer_list<label> sizes
)
{
cpuTime timer;
const label size0 = list.size();
const auto val = list.first();
Info<<"Resize list(" << list.size() << ") to";
for (auto len : sizes)
{
Info<< " " << len;
}
Info<< nl;
Info<< "Perform " << nLoops << " times..." << nl;
for (label iLoop = 0; iLoop < nLoops; ++iLoop)
{
list.setSize(size0, val);
for (auto len : sizes)
{
list.setSize(len, val);
}
}
Info<< "Operation took"
<< " " << timer.cpuTimeIncrement() << " s\n\n";
}
template<class ListType>
void runOrderingTest(const label nLoops, const ListType& list)
{
if (true)
{
cpuTime timer;
float total = 0;
Info<<"forAll - perform " << nLoops << " times..." << nl;
for (label iLoop = 0; iLoop < nLoops; ++iLoop)
{
float sum = 0;
forAll(list, i)
{
sum += list[i];
}
total += sum;
}
Info<< "Operation (sum " << total << ") took"
<< " " << timer.cpuTimeIncrement() << " s\n\n";
}
if (true)
{
cpuTime timer;
float total = 0;
Info<<"reverse pointer loop - perform " << nLoops << " times..." << nl;
for (label iLoop = 0; iLoop < nLoops; ++iLoop)
{
float sum = 0;
const typename ListType::value_type* __restrict__ fp
= (list).end();
label i = (list).size();
while (i--)
{
sum += (*--fp);
}
total += sum;
}
Info<< "Operation (sum " << total << ") took"
<< " " << timer.cpuTimeIncrement() << " s\n\n";
}
if (true)
{
cpuTime timer;
float total = 0;
Info<<"forward pointer loop - perform " << nLoops << " times..." << nl;
for (label iLoop = 0; iLoop < nLoops; ++iLoop)
{
float sum = 0;
const typename ListType::value_type* __restrict__ fp
= (list).begin();
label i = (list).size();
while (i--)
{
sum += (*fp++);
}
total += sum;
}
Info<< "Operation (sum " << total << ") took"
<< " " << timer.cpuTimeIncrement() << " s\n\n";
}
if (true)
{
cpuTime timer;
float total = 0;
Info<<"for loop - perform " << nLoops << " times..." << nl;
for (label iLoop = 0; iLoop < nLoops; ++iLoop)
{
float sum = 0;
const typename ListType::value_type* __restrict__ fp
= (list).begin();
const label sz = (list).size();
for (label i=0; i<sz; ++i)
{
sum += fp[i];
}
total += sum;
}
Info<< "Operation (sum " << total << ") took"
<< " " << timer.cpuTimeIncrement() << " s\n\n";
}
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
int main(int argc, char *argv[])
{
argList::addBoolOption("label");
argList::addBoolOption("float");
argList::addBoolOption("vector");
argList::addBoolOption("order");
argList::addBoolOption("labelList");
argList::addBoolOption("vectorList");
argList args(argc, argv);
if (args.options().empty())
{
Info<< nl << "Specify an option! " << nl << endl;
}
std::initializer_list<label> increments
= {10000, 20000, 40000, 80000, 160000};
if (args.optionFound("label"))
{
List<label> list(10, 1);
runResizeTest(100000, list, increments);
}
if (args.optionFound("float"))
{
List<double> list(10, 1.0);
runResizeTest(10000, list, increments);
}
if (args.optionFound("vector"))
{
List<vector> list(10, vector::one);
runResizeTest(10000, list, increments);
}
if (args.optionFound("labelList"))
{
typedef labelList testType;
testType initVal(500, label(1));
List<testType> list(10, initVal);
runResizeTest(200, list, increments);
}
if (args.optionFound("vectorList"))
{
typedef vectorList testType;
testType initVal(500, vector::one);
List<testType> list(10, initVal);
runResizeTest(100, list, increments);
}
if (args.optionFound("order"))
{
List<label> list(100000000, 1);
runOrderingTest(100, list);
}
Info<< nl << "Done" << nl << endl;
return 0;
}
// ************************************************************************* //

View File

@ -0,0 +1,2 @@
Test-ListOps2.C
EXE = $(FOAM_USER_APPBIN)/Test-ListOps2

View File

@ -0,0 +1,3 @@
EXE_INC = /*-DFULLDEBUG -O0 -g*/ \
EXE_LIBS =

View File

@ -0,0 +1,144 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2017 OpenCFD Ltd.
\\/ 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/>.
Application
Test-ListOps2
Description
\*---------------------------------------------------------------------------*/
#include "argList.H"
#include "List.H"
#include "FixedList.H"
#include "DynamicList.H"
#include "SubList.H"
#include "ListOps.H"
#include "FlatOutput.H"
using namespace Foam;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
template<class ListType>
void testFind(const ListType& list)
{
Info<< nl << "list: " << flatOutput(list) << nl << endl;
for (auto val : { 20, 35, 6, 13, 12, -12})
{
Info<< "lookup " << val
<< " found " << list.found(val)
<< " index " << list.find(val) << nl;
}
}
template<class ListType>
void testMoving(ListType& list)
{
Info<< nl << "list: " << flatOutput(list) << nl << endl;
{
const label i = 3;
list.swapFirst(i);
Info<<"swapFirst: " << i << " = " << flatOutput(list) << nl;
}
{
const label i = 6;
list.moveFirst(i);
Info<<"moveFirst: " << i << " = " << flatOutput(list) << nl;
}
{
const label i = 6;
list.moveLast(i);
Info<<"moveLast: " << i << " = " << flatOutput(list) << nl;
}
{
const label i = 8;
list.swapLast(i);
Info<<"swapLast: " << i << " = " << flatOutput(list) << nl;
}
}
// Main program:
int main(int argc, char *argv[])
{
List<label> list1(identity(15));
shuffle(list1);
FixedList<label, 15> list2(list1);
inplaceReverseList(list2);
DynamicList<label> list3(list1);
inplaceReverseList(list3);
testFind(list1);
testFind(list2);
testFind(list3);
testMoving(list1);
testMoving(list2);
testMoving(list3);
// Test remove
{
auto& list = list3;
Info<< nl << "list: " << flatOutput(list) << nl << endl;
list.remove();
Info<<"remove = " << flatOutput(list) << nl;
{
const label i = 6;
list.remove(i);
Info<<"rmSwap: " << i << " = " << flatOutput(list) << nl;
}
{
const label i = 3;
list.remove(i);
Info<<"rmSwap: " << i << " = " << flatOutput(list) << nl;
}
{
const label i = 8;
list.remove(i);
Info<<"rmMove: " << i << " = " << flatOutput(list) << nl;
}
}
Info<< "\nEnd\n" << endl;
return 0;
}
// ************************************************************************* //

View File

@ -38,41 +38,75 @@ using namespace Foam;
int main(int argc, char *argv[])
{
Map<bool> banana{{5, true}};
Map<bool> map1
{
{1, true}, {2, false}, {3, true}, {4, false}, {5, true}
};
// Taking a const iterator from find does not work!
// Also, fails later on op==
Map<bool>::const_iterator bananaIter = banana.find(5);
Map<bool>::const_iterator map1Iter = map1.cfind(5);
// This works but now I can change the value.
//Map<bool>::iterator bananaIter = banana.find(5);
// Same, but with non-const access
// Map<bool>::iterator map1Iter = map1.find(5);
if (!bananaIter.found()) // same as (bananaIter == banana.end())
if (!map1Iter.found()) // same as (map1Iter == map1.end())
{
Info<< "not found" << endl;
}
else
{
Info<< "5 is " << bananaIter() << endl;
Info<< "5 is " << *map1Iter << endl;
}
// Same with STL
// Repeat with std::map
Info<< "Same with STL" << endl;
std::map<label, bool> STLbanana{{5, true}};
std::map<label, bool>::const_iterator STLbananaIter = STLbanana.find(5);
std::map<label, bool> stdmap1
{
{1, true}, {2, false}, {3, true}, {4, false}, {5, true}
};
if (STLbananaIter == STLbanana.end())
std::map<label, bool>::const_iterator stdmap1Iter = stdmap1.find(5);
if (stdmap1Iter == stdmap1.cend())
{
Info<< "not found" << endl;
}
else
{
Info<< "5 is " << STLbananaIter->second << endl;
Info<< "5 is " << stdmap1Iter->second << endl;
}
Info<< "End\n" << endl;
Info<<"test move construct" << nl;
Map<bool> map2(std::move(map1));
Map<bool> map3;
std::map<label, bool> stdmap2(std::move(stdmap1));
std::map<label, bool> stdmap3;
Info<<"map1: " << map1 << nl
<<"map2: " << map2 << nl;
Info
<<"stdmap1: " << stdmap1.size() << nl
<<"stdmap2: " << stdmap2.size() << nl;
Info<<"test move assign" << nl;
map3 = std::move(map2);
stdmap3 = std::move(stdmap2);
Info<<"map2: " << map2 << nl
<<"map3: " << map3 << nl;
Info
<<"stdmap2: " << stdmap2.size() << nl
<<"stdmap3: " << stdmap3.size() << nl;
Info<< nl << "End\n" << endl;
return 0;
}

View File

@ -0,0 +1,3 @@
Test-OCountStream.C
EXE = $(FOAM_USER_APPBIN)/Test-OCountStream

View File

@ -0,0 +1,2 @@
/* EXE_INC = */
/* EXE_LIBS = */

View File

@ -0,0 +1,61 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2017 OpenCFD Ltd.
\\/ 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/>.
Description
\*---------------------------------------------------------------------------*/
#include "OCountStream.H"
#include "StringStream.H"
#include "IOstreams.H"
#include "argList.H"
using namespace Foam;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// Main program:
int main(int argc, char *argv[])
{
OCountStream cnt;
OStringStream str;
for (label i = 0; i < 50; ++i)
{
str << 1002 << " " << "abcd" << " "
<< "def" << " " << 3.14159 << ";\n";
cnt << 1002 << " " << "abcd" << " "
<< "def" << " " << 3.14159 << ";\n";
}
cnt.print(Info);
Info<< "via string-stream: " << str.str().size() << " chars" << endl;
Info<< "\nEnd\n" << endl;
return 0;
}
// ************************************************************************* //

View File

@ -0,0 +1,3 @@
Test-OListStream.C
EXE = $(FOAM_USER_APPBIN)/Test-OListStream

View File

@ -0,0 +1,2 @@
/* EXE_INC = */
/* EXE_LIBS = */

View File

@ -0,0 +1,208 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2017 OpenCFD Ltd.
\\/ 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/>.
Description
\*---------------------------------------------------------------------------*/
#include "ListStream.H"
#include "wordList.H"
#include "IOstreams.H"
#include "argList.H"
using namespace Foam;
Ostream& toString(Ostream& os, const UList<char>& list)
{
os << '"';
for (const char c : list)
{
os << c;
}
os << '"';
return os;
}
template<class BufType>
void printInfo(const BufType& buf)
{
Info<< nl << "=========================" << endl;
buf.print(Info);
toString(Info, buf.list());
Info<< nl << "=========================" << endl;
}
void printTokens(Istream& is)
{
label count = 0;
token t;
while (is.good())
{
is >> t;
if (t.good())
{
++count;
Info<<"token: " << t << endl;
}
}
Info<< count << " tokens" << endl;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// Main program:
int main(int argc, char *argv[])
{
// Buffer storage
DynamicList<char> storage(16);
OListStream obuf(std::move(storage));
obuf.setBlockSize(100);
printInfo(obuf);
// Fill with some content
for (label i = 0; i < 50; ++i)
{
obuf<< 1002 << " " << "abcd" << " "
<< "def" << " " << 3.14159 << ";\n";
}
printInfo(obuf);
obuf.rewind();
printInfo(obuf);
for (label i=0; i < 10; ++i)
{
obuf << "item" << i << "\n";
}
printInfo(obuf);
obuf.shrink();
Info<< "after shrink" << nl;
printInfo(obuf);
// Add some more
for (label i=10; i < 15; ++i)
{
obuf << "more" << i << nl;
}
Info<< "appended more" << nl;
printInfo(obuf);
// Overwrite at some position
obuf.stdStream().rdbuf()->pubseekpos(0.60 * obuf.size());
obuf << "<" << nl << "OVERWRITE" << nl;
Info<<"after overwrite" << nl;
printInfo(obuf);
Info<< "transfer contents to a List or IListStream" << nl;
IListStream ibuf(obuf.xfer());
Info<<"original:";
printInfo(obuf);
Info<<"new input:" << nl;
printInfo(ibuf);
printTokens(ibuf);
// Create from other storage types
Info<< nl;
{
Info<<"create std::move(List)" << endl;
List<char> list(16, 'A');
Info<<"input:";
toString(Info, list) << endl;
OListStream buf1(std::move(list));
for (label i = 0; i < 26; ++i)
{
buf1 << char('A' +i);
}
for (label i = 0; i < 26; ++i)
{
buf1 << char('a' +i);
}
Info<<"orig:";
toString(Info, list) << endl;
printInfo(buf1);
}
Info<< nl;
List<char> written;
{
Info<<"create List.xfer()" << endl;
List<char> list(16, 'B');
Info<<"input:";
toString(Info, list) << endl;
OListStream buf1(list.xfer());
for (label i = 0; i < 26; ++i)
{
buf1 << char('A' + i);
}
for (label i = 0; i < 26; ++i)
{
buf1 << char('a' +i);
}
Info<<"orig:";
toString(Info, list) << endl;
printInfo(buf1);
// Move back to written
written = buf1.xfer();
printInfo(buf1);
}
Info<<"'captured' content ";
toString(Info, written);
Info<< "\nEnd\n" << endl;
return 0;
}
// ************************************************************************* //

View File

@ -41,7 +41,7 @@ using namespace Foam;
template<unsigned nBits>
inline void reportInfo()
{
unsigned offset = PackedList<nBits>::packing();
const unsigned offset = PackedList<nBits>::packing();
unsigned useSHL = ((1u << (nBits * offset)) - 1);
unsigned useSHR = (~0u >> (sizeof(unsigned)*CHAR_BIT - nBits * offset));

View File

@ -31,12 +31,26 @@ Description
#include "boolList.H"
#include "PackedBoolList.H"
#include "HashSet.H"
#include "StaticHashTable.H"
#include "cpuTime.H"
#include <vector>
#include <unordered_set>
using namespace Foam;
#undef TEST_STD_BOOLLIST
#undef TEST_STD_UNORDERED_SET
template<class T>
void printInfo(const std::unordered_set<T, Foam::Hash<T>>& ht)
{
Info<<"std::unordered_set elements:"
<< ht.size()
<< " buckets:" << ht.bucket_count()
<< " load_factor: " << ht.load_factor()
<< nl;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -47,11 +61,16 @@ int main(int argc, char *argv[])
const label n = 1000000;
const label nIters = 1000;
unsigned int sum = 0;
unsigned long sum = 0;
PackedBoolList packed(n, 1);
boolList unpacked(n, true);
std::vector<bool> stlVector(n, true);
#ifdef TEST_STD_BOOLLIST
std::vector<bool> stdBoolList(n, true);
#endif
cpuTime timer;
labelHashSet emptyHash;
labelHashSet fullHash(1024);
@ -60,22 +79,27 @@ int main(int argc, char *argv[])
fullHash.insert(i);
}
// fullStaticHash is really slow
// give it lots of slots to help
StaticHashTable<nil, label, Hash<label>> emptyStaticHash;
StaticHashTable<nil, label, Hash<label>> fullStaticHash(100000);
Info<< "populated labelHashSet in "
<< timer.cpuTimeIncrement() << " s\n\n";
#ifdef TEST_STD_UNORDERED_SET
std::unordered_set<label, Foam::Hash<label>> emptyStdHash;
std::unordered_set<label, Foam::Hash<label>> fullStdHash;
fullStdHash.reserve(1024);
for (label i = 0; i < n; i++)
{
fullStaticHash.insert(i, nil());
fullStdHash.insert(i);
}
Info<< "populated unordered_set in "
<< timer.cpuTimeIncrement() << " s\n\n";
#endif
emptyHash.printInfo(Info);
fullHash.printInfo(Info);
emptyStaticHash.printInfo(Info);
fullStaticHash.printInfo(Info);
cpuTime timer;
#ifdef TEST_STD_UNORDERED_SET
printInfo(emptyStdHash);
printInfo(fullStdHash);
#endif
for (label iter = 0; iter < nIters; ++iter)
{
@ -104,9 +128,11 @@ int main(int argc, char *argv[])
sum += packed[i];
}
}
Info<< "Counting brute-force:" << timer.cpuTimeIncrement()
std::cout
<< "Counting brute-force:" << timer.cpuTimeIncrement()
<< " s" << nl
<< " sum " << sum << endl;
<< " sum " << sum << nl;
// Count packed
@ -115,9 +141,11 @@ int main(int argc, char *argv[])
{
sum += packed.count();
}
Info<< "Counting via count():" << timer.cpuTimeIncrement()
std::cout
<< "Counting via count():" << timer.cpuTimeIncrement()
<< " s" << nl
<< " sum " << sum << endl;
<< " sum " << sum << nl;
// Dummy addition
@ -129,25 +157,29 @@ int main(int argc, char *argv[])
sum += i + 1;
}
}
Info<< "Dummy loop:" << timer.cpuTimeIncrement() << " s" << nl
<< " sum " << sum << " (sum is meaningless)" << endl;
std::cout
<< "Dummy loop:" << timer.cpuTimeIncrement() << " s" << nl
<< " sum " << sum << " (sum is meaningless)" << nl;
//
// Read
//
#ifdef TEST_STD_BOOLLIST
// Read stl
sum = 0;
for (label iter = 0; iter < nIters; ++iter)
{
for (unsigned int i = 0; i < stlVector.size(); i++)
for (unsigned int i = 0; i < stdBoolList.size(); i++)
{
sum += stlVector[i];
sum += stdBoolList[i];
}
}
Info<< "Reading stl:" << timer.cpuTimeIncrement() << " s" << nl
<< " sum " << sum << endl;
std::cout
<< "Reading stdBoolList:" << timer.cpuTimeIncrement() << " s" << nl
<< " sum " << sum << nl;
#endif
// Read unpacked
sum = 0;
@ -158,8 +190,9 @@ int main(int argc, char *argv[])
sum += unpacked[i];
}
}
Info<< "Reading unpacked:" << timer.cpuTimeIncrement() << " s" << nl
<< " sum " << sum << endl;
std::cout
<< "Reading unpacked:" << timer.cpuTimeIncrement() << " s" << nl
<< " sum " << sum << nl;
// Read packed
@ -171,9 +204,10 @@ int main(int argc, char *argv[])
sum += packed.get(i);
}
}
Info<< "Reading packed using get:" << timer.cpuTimeIncrement()
std::cout
<< "Reading packed using get:" << timer.cpuTimeIncrement()
<< " s" << nl
<< " sum " << sum << endl;
<< " sum " << sum << nl;
// Read packed
@ -185,9 +219,10 @@ int main(int argc, char *argv[])
sum += packed[i];
}
}
Info<< "Reading packed using reference:" << timer.cpuTimeIncrement()
std::cout
<< "Reading packed using reference:" << timer.cpuTimeIncrement()
<< " s" << nl
<< " sum " << sum << endl;
<< " sum " << sum << nl;
// Read via iterator
@ -199,9 +234,10 @@ int main(int argc, char *argv[])
sum += it;
}
}
Info<< "Reading packed using iterator:" << timer.cpuTimeIncrement()
std::cout
<< "Reading packed using iterator:" << timer.cpuTimeIncrement()
<< " s" << nl
<< " sum " << sum << endl;
<< " sum " << sum << nl;
// Read via iterator
@ -213,9 +249,10 @@ int main(int argc, char *argv[])
sum += cit();
}
}
Info<< "Reading packed using const_iterator():" << timer.cpuTimeIncrement()
std::cout
<< "Reading packed using const_iterator():" << timer.cpuTimeIncrement()
<< " s" << nl
<< " sum " << sum << endl;
<< " sum " << sum << nl;
// Read empty hash
@ -227,9 +264,10 @@ int main(int argc, char *argv[])
sum += emptyHash.found(i);
}
}
Info<< "Reading empty labelHashSet:" << timer.cpuTimeIncrement()
std::cout
<< "Reading empty labelHashSet:" << timer.cpuTimeIncrement()
<< " s" << nl
<< " sum " << sum << endl;
<< " sum " << sum << nl;
// Read full hash
@ -241,55 +279,59 @@ int main(int argc, char *argv[])
sum += fullHash.found(i);
}
}
Info<< "Reading full labelHashSet:" << timer.cpuTimeIncrement()
std::cout
<< "Reading full labelHashSet:" << timer.cpuTimeIncrement()
<< " s" << nl
<< " sum " << sum << endl;
<< " sum " << sum << nl;
// Read empty static hash
#ifdef TEST_STD_UNORDERED_SET
// Read empty stl set
sum = 0;
for (label iter = 0; iter < nIters; ++iter)
{
forAll(unpacked, i)
{
sum += emptyStaticHash.found(i);
sum += (emptyStdHash.find(i) != emptyStdHash.cend());
}
}
Info<< "Reading empty StaticHash:" << timer.cpuTimeIncrement()
std::cout
<< "Reading empty std::unordered_set:" << timer.cpuTimeIncrement()
<< " s" << nl
<< " sum " << sum << endl;
<< " sum " << sum << nl;
#if 0
// we can skip this test - it is usually quite slow
// Read full static hash
// Read full stl set
sum = 0;
for (label iter = 0; iter < nIters; ++iter)
{
forAll(unpacked, i)
{
sum += fullStaticHash.found(i);
sum += (fullStdHash.find(i) != fullStdHash.cend());
}
}
Info<< "Reading full StaticHash:" << timer.cpuTimeIncrement()
std::cout
<< "Reading full std::unordered_set:" << timer.cpuTimeIncrement()
<< " s" << nl
<< " sum " << sum << endl;
<< " sum " << sum << nl;
#endif
Info<< "Starting write tests" << endl;
Info<< "Starting write tests" << nl;
//
// Write
//
// Write stl
#ifdef TEST_STD_BOOLLIST
// Read stl
for (label iter = 0; iter < nIters; ++iter)
{
for (unsigned int i = 0; i < stlVector.size(); i++)
for (unsigned int i = 0; i < stdBoolList.size(); i++)
{
stlVector[i] = true;
stdBoolList[i] = true;
}
}
Info<< "Writing stl:" << timer.cpuTimeIncrement() << " s" << endl;
Info<< "Writing stdBoolList:" << timer.cpuTimeIncrement() << " s" << nl;
#endif
// Write unpacked
for (label iter = 0; iter < nIters; ++iter)
@ -299,7 +341,7 @@ int main(int argc, char *argv[])
unpacked[i] = true;
}
}
Info<< "Writing unpacked:" << timer.cpuTimeIncrement() << " s" << endl;
Info<< "Writing unpacked:" << timer.cpuTimeIncrement() << " s" << nl;
// Write packed
@ -311,7 +353,7 @@ int main(int argc, char *argv[])
}
}
Info<< "Writing packed using reference:" << timer.cpuTimeIncrement()
<< " s" << endl;
<< " s" << nl;
// Write packed
@ -323,7 +365,7 @@ int main(int argc, char *argv[])
}
}
Info<< "Writing packed using set:" << timer.cpuTimeIncrement()
<< " s" << endl;
<< " s" << nl;
// Write packed
for (label iter = 0; iter < nIters; ++iter)
@ -334,7 +376,7 @@ int main(int argc, char *argv[])
}
}
Info<< "Writing packed using iterator:" << timer.cpuTimeIncrement()
<< " s" << endl;
<< " s" << nl;
// Write packed
@ -343,7 +385,7 @@ int main(int argc, char *argv[])
packed = 0;
}
Info<< "Writing packed uniform 0:" << timer.cpuTimeIncrement()
<< " s" << endl;
<< " s" << nl;
// Write packed
@ -352,7 +394,7 @@ int main(int argc, char *argv[])
packed = 1;
}
Info<< "Writing packed uniform 1:" << timer.cpuTimeIncrement()
<< " s" << endl;
<< " s" << nl;
PackedList<3> oddPacked(n, 3);
@ -363,7 +405,7 @@ int main(int argc, char *argv[])
packed = 0;
}
Info<< "Writing packed<3> uniform 0:" << timer.cpuTimeIncrement()
<< " s" << endl;
<< " s" << nl;
// Write packed
@ -372,7 +414,7 @@ int main(int argc, char *argv[])
packed = 1;
}
Info<< "Writing packed<3> uniform 1:" << timer.cpuTimeIncrement()
<< " s" << endl;
<< " s" << nl;
Info<< "End\n" << endl;

View File

@ -28,11 +28,7 @@ Description
\*---------------------------------------------------------------------------*/
#include "argList.H"
#include "boolList.H"
#include "HashSet.H"
#include "StaticHashTable.H"
#include "cpuTime.H"
#include <vector>
#include "PackedBoolList.H"
using namespace Foam;
@ -44,24 +40,29 @@ using namespace Foam;
int main(int argc, char *argv[])
{
const label nLoop = 5;
const label n = 100000000;
const label nReport = 1000000;
// const label nReport = 1000000;
cpuTime timer;
// test inserts
// PackedBoolList
PackedBoolList packed;
for (label i = 0; i < n; i++)
for (label iloop = 0; iloop < nLoop; ++iloop)
{
if ((i % nReport) == 0 && i)
for (label i = 0; i < n; ++i)
{
Info<< "i:" << i << " in " << timer.cpuTimeIncrement() << " s"
<<endl;
}
// if ((i % nReport) == 0 && i)
// {
// Info<< "." << flush;
// }
packed[i] = 1;
// Make compiler do something else too
packed[i/2] = 0;
}
Info<< "insert test: " << n << " elements in "
}
Info<< nl
<< "insert test: " << nLoop << "*" << n << " elements in "
<< timer.cpuTimeIncrement() << " s\n\n";
Info << "\nEnd\n" << endl;

View File

@ -28,6 +28,7 @@ Description
\*---------------------------------------------------------------------------*/
#include "uLabel.H"
#include "boolList.H"
#include "IOstreams.H"
#include "PackedBoolList.H"
#include "StringStream.H"
@ -146,17 +147,16 @@ int main(int argc, char *argv[])
Info<< list4 << " indices: " << list4.used()() << nl;
Info<< "\nassign from labelList\n";
list4 = labelList
(
IStringStream
(
"(0 1 2 3 12 13 14 19 20 21)"
)()
);
list4 = labelList{0, 1, 2, 3, 12, 13, 14, 19, 20, 21};
list4.printInfo(Info, true);
Info<< list4 << " indices: " << list4.used()() << nl;
// Not yet:
// PackedBoolList list5{0, 1, 2, 3, 12, 13, 14, 19, 20, 21};
// list5.printInfo(Info, true);
// Info<< list5 << " indices: " << list5.used()() << nl;
Info<< "\nassign from indices\n";
list4.read
(
@ -170,13 +170,13 @@ int main(int argc, char *argv[])
list4.printInfo(Info, true);
Info<< list4 << " indices: " << list4.used()() << nl;
List<bool> boolLst(list4.size());
boolList bools(list4.size());
forAll(list4, i)
{
boolLst[i] = list4[i];
bools[i] = list4[i];
}
Info<< "List<bool>: " << boolLst << nl;
Info<< "boolList: " << bools << nl;
// check roundabout assignments
PackedList<2> pl2

View File

@ -1,3 +0,0 @@
Test-staticHashTable.C
EXE = $(FOAM_USER_APPBIN)/Test-staticHashTable

View File

@ -1,170 +0,0 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011 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 "StaticHashTable.H"
#include "IOstreams.H"
#include "StringStream.H"
using namespace Foam;
// use define so we can easily test other implementations
#define HASHTABLE_CLASS StaticHashTable
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// Main program:
int main()
{
HASHTABLE_CLASS<double> table1(13);
table1.insert("aaa", 1.0);
table1.insert("aba", 2.0);
table1.insert("aca", 3.0);
table1.insert("ada", 4.0);
table1.insert("aeq", 5.0);
table1.insert("aaw", 6.0);
table1.insert("abs", 7.0);
table1.insert("acr", 8.0);
table1.insert("adx", 9.0);
table1.insert("aec", 10.0);
table1.erase("aaw");
table1.erase("abs");
Info<< "\ntable1 toc: " << table1.toc() << endl;
table1.printInfo(Info)
<< "table1 [" << table1.size() << "] " << endl;
forAllIter(HASHTABLE_CLASS<double>, table1, iter)
{
Info<< iter.key() << " => " << iter() << nl;
}
table1.set("acr", 108);
table1.set("adx", 109);
table1.set("aec", 100);
table1("aaw") -= 1000;
table1("aeq") += 1000;
Info<< "\noverwrote some values table1: " << table1 << endl;
Info<< "\ntest find:" << endl;
Info<< table1.find("aaa")() << nl
<< table1.find("aba")() << nl
<< table1.find("aca")() << nl
<< table1.find("ada")() << nl
<< table1.find("aeq")() << nl
<< table1.find("acr")() << nl
<< table1.find("adx")() << nl
<< table1.find("aec")() << nl
<< table1["aaa"] << nl;
{
OStringStream os;
os << table1;
HASHTABLE_CLASS<double> readTable(IStringStream(os.str())(), 100);
Info<< "Istream constructor:" << readTable << endl;
}
HASHTABLE_CLASS<double> table2(table1);
HASHTABLE_CLASS<double> table3(table1.xfer());
Info<< "\ncopy table1 -> table2" << nl
<< "transfer table1 -> table3 via the xfer() method" << nl;
Info<< "\ntable1" << table1 << nl
<< "\ntable2" << table2 << nl
<< "\ntable3" << table3 << nl;
Info<< "\nerase table2 by iterator" << nl;
forAllIter(HASHTABLE_CLASS<double>, table2, iter)
{
Info<< "erasing " << iter.key() << " => " << iter() << " ... ";
table2.erase(iter);
Info<< "erased" << endl;
}
Info<< "\ntable1" << table1 << nl
<< "\ntable2" << table2 << nl
<< "\ntable3" << table3 << nl;
table3.resize(1);
Info<< "\nresize(1) table3" << nl;
table3.printInfo(Info)
<< table3 << nl;
table3.resize(10000);
Info<< "\nresize(10000) table3" << nl;
table3.printInfo(Info)
<< table3 << nl;
HASHTABLE_CLASS<double> table4;
table4 = table3;
Info<< "\ncopy table3 -> table4 " << table4 << nl;
Info<< "\nclear table4 ... ";
table4.clear();
Info<< "[" << table4.size() << "] " << table4 << nl;
table1 = table3;
Info<< "\ncopy table3 -> table1 (previously transferred)" << table1 << nl;
Info<< "test table1 == table3 : " << (table1 == table3) << nl;
table1.erase(table1.begin());
Info<< "removed an element - test table1 != table3 : "
<< (table1 != table3) << nl;
// insert a few things into table2
table2.set("ada", 14.0);
table2.set("aeq", 15.0);
table2.set("aaw", 16.0);
table2.set("abs", 17.0);
table2.set("adx", 20.0);
Info<< "\ntable1" << table1 << nl
<< "\ntable2" << table2 << nl;
label nErased = table1.erase(table2);
Info<< "\nerase table2 keys from table1 (removed "
<< nErased << " elements)" << nl
<< "\ntable1" << table1 << nl
<< "\ntable2" << table2 << nl;
Info<< "\ntable3" << table3
<< "\nclearStorage table3 ... ";
table3.clearStorage();
Info<< table3 << nl;
Info<< "\nDone\n";
return 0;
}
// ************************************************************************* //

View File

@ -0,0 +1,3 @@
Test-UIListStream.C
EXE = $(FOAM_USER_APPBIN)/Test-UIListStream

View File

@ -0,0 +1,2 @@
/* EXE_INC = */
/* EXE_LIBS = */

View File

@ -0,0 +1,111 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2017 OpenCFD Ltd.
\\/ 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/>.
Description
\*---------------------------------------------------------------------------*/
#include "UListStream.H"
#include "wordList.H"
#include "IOstreams.H"
#include "argList.H"
using namespace Foam;
Ostream& toString(Ostream& os, const UList<char>& list)
{
os << '"';
for (const char c : list)
{
os << c;
}
os << '"';
return os;
}
template<class BufType>
void printInfo(const BufType& buf)
{
Info<< nl << "=========================" << endl;
buf.print(Info);
toString(Info, buf.list());
Info<< nl << "=========================" << endl;
}
void printTokens(Istream& is)
{
label count = 0;
token t;
while (is.good())
{
is >> t;
if (t.good())
{
++count;
Info<<"token: " << t << endl;
}
}
Info<< count << " tokens" << endl;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// Main program:
int main(int argc, char *argv[])
{
// Buffer storage
DynamicList<char> storage(1000);
UOListStream obuf(storage);
obuf << 1002 << " " << "abcd" << " " << "def" << " " << 3.14159 << ";\n";
obuf.print(Info);
// Match size
storage.resize(obuf.size());
Info<<"as string: " << string(storage.cdata(), storage.size()) << endl;
// Attach input buffer - could also do without previous resize
UIListStream ibuf(storage);
printTokens(ibuf);
Info<< nl << "Repeat..." << endl;
ibuf.rewind();
printTokens(ibuf);
Info<< "\nEnd\n" << endl;
return 0;
}
// ************************************************************************* //

View File

@ -29,75 +29,102 @@ Description
#include "DynamicList.H"
#include "IOstreams.H"
#include "ListOps.H"
#include "OFstream.H"
#include "labelIndList.H"
using namespace Foam;
template<class ListType>
void printInfo(const ListType& lst)
{
Info<< "addr: " << flatOutput(lst.addressing()) << nl
<< "list: " << flatOutput(lst) << nl
<< endl;
}
template<class T, class ListType>
void testFind(const T& val, const ListType& lst)
{
Info<< nl
<< "Search for "<< val << " in " << flatOutput(lst) << nl
<<" found() = " << lst.found(val)
<<" find() = " << lst.find(val)
<<" rfind() = " << lst.rfind(val)
<<" find(2) = " << lst.find(val, 2)
<<" rfind(2) = " << lst.rfind(val, 2)
<<" findIndex = " << findIndex(lst, val) << nl
<< nl;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// Main program:
int main(int argc, char *argv[])
{
List<double> completeList(10);
List<label> completeList(20);
forAll(completeList, i)
{
completeList[i] = 0.1*i;
completeList[i] = 10*i;
}
List<label> addresses(5);
addresses[0] = 1;
addresses[1] = 0;
addresses[2] = 7;
addresses[3] = 8;
addresses[4] = 5;
Info<< "raw : " << flatOutput(completeList) << nl << endl;
UIndirectList<double> idl(completeList, addresses);
List<label> addresses{1, 0, 3, 7, 4, 8, 5, 1, 0, 3, 7, 4, 8, 5, };
Info<< idl << "\n";
labelUIndList idl1(completeList, addresses);
idl[1] = -666;
printInfo(idl1);
Info<< "idl[1] changed: " << idl << endl;
for (const label val : { 10, 30, 40, 50, 90, 80, 120 } )
{
testFind(val, idl1);
}
idl = -999;
Info<< flatOutput(idl1) << nl;
Info<< "idl changed: " << idl << endl;
idl1[1] = -666;
UIndirectList<double> idl2(idl);
Info<< "idl1[1] changed: " << flatOutput(idl1) << endl;
Info<< "idl2: " << idl2 << endl;
idl1 = -999;
Info<< "idl1 changed: " << flatOutput(idl1) << endl;
labelUIndList idl2(idl1);
Info<< "idl2: " << flatOutput(idl2) << endl;
{
List<double> ident(idl.size());
List<label> ident(idl1.size());
forAll(ident, i)
{
ident[i] = ident.size() - i;
}
idl = ident;
idl1 = ident;
}
Info<< "idl assigned from UList: " << idl << endl;
Info<< "idl1 assigned from UList: " << flatOutput(idl1) << endl;
// test List operations
List<double> flatList(UIndirectList<double>(completeList, addresses));
Info<< "List constructed from UIndirectList: " << flatList << endl;
List<label> flatList(labelUIndList(completeList, addresses));
Info<< "List construct from UIndirectList: " << flatOutput(flatList) << nl;
flatList = UIndirectList<double>(completeList, addresses);
Info<< "List assigned from UIndirectList: " << flatList << endl;
flatList = labelUIndList(completeList, addresses);
Info<< "List assign from UIndirectList: " << flatOutput(flatList) << nl;
flatList.append(UIndirectList<double>(completeList, addresses));
Info<< "List::append(UIndirectList): " << flatList << endl;
flatList.append(labelUIndList(completeList, addresses));
Info<< "List::append(UIndirectList): " << flatOutput(flatList) << nl;
DynamicList<double> dynList(UIndirectList<double>(completeList, addresses));
Info<< "DynamicList constructed from UIndirectList: " << dynList << endl;
DynamicList<label> dynList(labelUIndList(completeList, addresses));
Info<< "DynamicList construct from UIndirectList: " << flatOutput(dynList)
<< nl;
dynList.append(UIndirectList<double>(completeList, addresses));
Info<< "DynamicList::append(UIndirectList): " << dynList << endl;
dynList.append(labelUIndList(completeList, addresses));
Info<< "DynamicList::append(UIndirectList): " << flatOutput(dynList) << nl;
Info<< "\nEnd\n" << endl;

View File

@ -0,0 +1,3 @@
Test-checkDecomposePar.C
EXE = $(FOAM_APPBIN)/Test-checkDecomposePar

View File

@ -0,0 +1,11 @@
EXE_INC = \
-I$(LIB_SRC)/parallel/decompose/decompose/lnInclude \
-I$(LIB_SRC)/parallel/decompose/decompositionMethods/lnInclude \
-I$(LIB_SRC)/finiteVolume/lnInclude \
-I$(LIB_SRC)/meshTools/lnInclude \
-I$(LIB_SRC)/regionModels/regionModel/lnInclude
EXE_LIBS = \
-ldecompose \
-ldecompositionMethods \
-lregionModels

View File

@ -0,0 +1,193 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2017 OpenCFD Ltd.
\\/ 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/>.
Application
checkDecomposePar
Group
grpParallelUtilities
Description
Check decomposition from kaffpa (KaHIP) output.
foamToMetisGraph was likely used for producing the kaffpa input.
\*---------------------------------------------------------------------------*/
#include "OSspecific.H"
#include "fvCFD.H"
#include "cpuTime.H"
#include "IFstream.H"
#include "regionProperties.H"
#include "decompositionInformation.H"
#include "decompositionModel.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
int main(int argc, char *argv[])
{
argList::addNote
(
"Check decomposition from kaffpa (KaHIP) output"
);
argList::noParallel();
argList::noBanner();
#include "addRegionOption.H"
argList::addBoolOption
(
"allRegions",
"operate on all regions in regionProperties"
);
argList::addBoolOption
(
"verbose",
"more information about decomposition"
);
argList::validArgs.append("kaffpa-output-file");
// Include explicit constant options, have zero from time range
timeSelector::addOptions(true, false);
#include "setRootCase.H"
const fileName decompFile = args[1];
const bool region = args.optionFound("region");
const bool allRegions = args.optionFound("allRegions");
const bool verbose = args.optionFound("verbose");
// Set time from database
#include "createTime.H"
// Allow override of time
instantList times = timeSelector::selectIfPresent(runTime, args);
// Allow override of decomposeParDict location
fileName decompDictFile;
args.optionReadIfPresent("decomposeParDict", decompDictFile);
wordList regionNames;
wordList regionDirs;
if (allRegions)
{
Info<< "Decomposing all regions in regionProperties" << nl << endl;
regionProperties rp(runTime);
forAllConstIters(rp, iter)
{
const wordList& regions = iter();
forAll(regions, i)
{
if (!regionNames.found(regions[i]))
{
regionNames.append(regions[i]);
}
}
}
regionDirs = regionNames;
}
else
{
word regionName;
if (args.optionReadIfPresent("region", regionName))
{
regionNames = wordList(1, regionName);
regionDirs = regionNames;
}
else
{
regionNames = wordList(1, fvMesh::defaultRegion);
regionDirs = wordList(1, word::null);
}
}
labelList cellToProc;
forAll(regionNames, regioni)
{
const word& regionName = regionNames[regioni];
const word& regionDir = regionDirs[regioni];
Info<< "\n\nDecomposing mesh " << regionName << nl << endl;
Info<< "Create mesh..." << flush;
fvMesh mesh
(
IOobject
(
regionName,
runTime.timeName(),
runTime,
IOobject::MUST_READ,
IOobject::NO_WRITE,
false
)
);
Info<< " nCells = " << mesh.nCells() << endl;
// Expected format is a simple ASCII list
cellToProc.setSize(mesh.nCells());
{
IFstream is(decompFile);
forAll(cellToProc, celli)
{
cellToProc[celli] = readLabel(is);
}
}
const label nDomains = max(cellToProc) + 1;
CompactListList<label> cellCells;
decompositionMethod::calcCellCells
(
mesh,
identity(mesh.nCells()),
mesh.nCells(),
false,
cellCells
);
decompositionInformation info
(
cellCells,
cellToProc,
nDomains
);
if (verbose)
{
info.printDetails(Info);
Info<< nl;
}
info.printSummary(Info);
}
Info<< "\nEnd\n" << endl;
return 0;
}
// ************************************************************************* //

View File

@ -0,0 +1,3 @@
Test-decomposePar.C
EXE = $(FOAM_APPBIN)/Test-decomposePar

View File

@ -0,0 +1,13 @@
EXE_INC = \
-I$(LIB_SRC)/parallel/decompose/decompose/lnInclude \
-I$(LIB_SRC)/parallel/decompose/decompositionMethods/lnInclude \
-I$(LIB_SRC)/finiteVolume/lnInclude \
-I$(LIB_SRC)/meshTools/lnInclude \
-I$(LIB_SRC)/regionModels/regionModel/lnInclude
EXE_LIBS = \
-ldecompose \
-ldecompositionMethods \
-L$(FOAM_LIBBIN)/dummy \
-lkahipDecomp -lmetisDecomp -lscotchDecomp \
-lregionModels

View File

@ -0,0 +1,278 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2017 OpenCFD Ltd.
\\/ 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/>.
Application
decomposePar
Group
grpParallelUtilities
Description
Automatically decomposes a mesh and fields of a case for parallel
execution of OpenFOAM.
Usage
\b decomposePar [OPTION]
Options:
- \par -region \<regionName\>
Decompose named region. Does not check for existence of processor*.
- \par -allRegions
Decompose all regions in regionProperties. Does not check for
existence of processor*.
- \par -constant
- \par -time xxx:yyy
Override controlDict settings and decompose selected times. Does not
re-decompose the mesh i.e. does not handle moving mesh or changing
mesh cases.
\*---------------------------------------------------------------------------*/
#include "OSspecific.H"
#include "fvCFD.H"
#include "cpuTime.H"
#include "IOobjectList.H"
#include "regionProperties.H"
#include "decompositionInformation.H"
#include "decompositionModel.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
int main(int argc, char *argv[])
{
argList::addNote
(
"decompose a mesh and fields of a case for parallel execution"
);
argList::noParallel();
argList::addOption
(
"decomposeParDict",
"file",
"read decomposePar dictionary from specified location"
);
#include "addRegionOption.H"
argList::addBoolOption
(
"allRegions",
"operate on all regions in regionProperties"
);
argList::addBoolOption
(
"verbose",
"more information about decomposition"
);
argList::addOption
(
"domains",
"N"
"override numberOfSubdomains"
);
argList::addOption
(
"method",
"name"
"override method"
);
// Include explicit constant options, have zero from time range
timeSelector::addOptions(true, false);
#include "setRootCase.H"
const bool region = args.optionFound("region");
const bool allRegions = args.optionFound("allRegions");
const bool verbose = args.optionFound("verbose");
const label numSubdomains =
args.optionLookupOrDefault<label>("domains", 0);
const word methodName =
args.optionLookupOrDefault<word>("method", word::null);
// Set time from database
#include "createTime.H"
// Allow override of time
instantList times = timeSelector::selectIfPresent(runTime, args);
// Allow override of decomposeParDict location
fileName decompDictFile;
args.optionReadIfPresent("decomposeParDict", decompDictFile);
wordList regionNames;
wordList regionDirs;
if (allRegions)
{
Info<< "Decomposing all regions in regionProperties" << nl << endl;
regionProperties rp(runTime);
forAllConstIters(rp, iter)
{
const wordList& regions = iter();
forAll(regions, i)
{
if (!regionNames.found(regions[i]))
{
regionNames.append(regions[i]);
}
}
}
regionDirs = regionNames;
}
else
{
word regionName;
if (args.optionReadIfPresent("region", regionName))
{
regionNames = wordList(1, regionName);
regionDirs = regionNames;
}
else
{
regionNames = wordList(1, fvMesh::defaultRegion);
regionDirs = wordList(1, word::null);
}
}
forAll(regionNames, regioni)
{
const word& regionName = regionNames[regioni];
const word& regionDir = regionDirs[regioni];
Info<< "\n\nDecomposing mesh " << regionName << nl << endl;
Info<< "Create mesh..." << flush;
fvMesh mesh
(
IOobject
(
regionName,
runTime.timeName(),
runTime,
IOobject::MUST_READ,
IOobject::NO_WRITE,
false
)
);
Info<< " nCells = " << mesh.nCells() << endl;
Info<< "\nCalculating distribution of cells" << endl;
cpuTime decompositionTime;
const decompositionModel& model = decompositionModel::New
(
mesh,
decompDictFile
);
// Allow command-line override for quick testing
dictionary& modelDict = const_cast<decompositionModel&>(model);
if (numSubdomains)
{
modelDict.add
(
word("numberOfSubdomains"),
numSubdomains,
true
);
}
if (!methodName.empty())
{
modelDict.add
(
word("method"),
methodName,
true
);
}
scalarField cellWeights;
word weightName;
if (model.readIfPresent("weightField", weightName))
{
volScalarField weights
(
IOobject
(
weightName,
mesh.time().timeName(),
mesh,
IOobject::MUST_READ,
IOobject::NO_WRITE
),
mesh
);
cellWeights = weights.primitiveField();
}
decompositionMethod& method = model.decomposer();
CompactListList<label> cellCells;
decompositionMethod::calcCellCells
(
mesh,
identity(mesh.nCells()),
mesh.nCells(),
false,
cellCells
);
labelList cellToProc = method.decompose(mesh, cellWeights);
Info<< "\nFinished decomposition into "
<< method.nDomains() << " domains in "
<< decompositionTime.elapsedCpuTime()
<< " s" << nl << endl;
decompositionInformation info
(
cellCells,
cellToProc,
method.nDomains()
);
if (verbose)
{
info.printDetails(Info);
Info<< nl;
}
info.printSummary(Info);
}
Info<< "\nEnd\n" << endl;
return 0;
}
// ************************************************************************* //

View File

@ -13,18 +13,19 @@ FoamFile
object testDict;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#inputMode merge
#includeIfPresent "someUnknownFile"
#includeIfPresent "$FOAM_CASE/someUnknownFile"
#includeIfPresent "$FOAM_CASE/someUnknownFile-$FOAM_CASENAME"
internalField uniform 1;
// use 'protect' to supply defaults
#inputMode protect
internalField uniform 10;
dimensions [ 0 2 -2 0 0 0 0 ];
#inputMode merge
// supply defaults
#default internalField uniform 10;
#default dimensions [ 1 2 -2 0 0 0 0 ];
#overwrite dimensions [ 0 2 -2 0 0 0 0 ];
// #warn dimensions [ 0 2 -2 0 0 0 0 ];
// #error dimensions [ 0 2 -2 0 0 0 0 ];
active
{
@ -86,14 +87,22 @@ boundaryField
#remove inactive
inlet_7 { ${${varType}}} // Test indirection/recursive expansion
#inputMode overwrite
inlet_8 { $active }
#overwrite inlet_8 { type none; }
}
// NB: the inputMode has a global scope
#inputMode merge
#include "testDict2"
verbatim #{
This is a somewhat larger chunk of verbatim text that we would much
prefer to move as a token rather than copying its entire content each
time we do parsing or need to resize the token list.
#};
foo
{
$active

View File

@ -17,6 +17,8 @@ FoamFile
// #inputMode overwrite
key1 val1;
val1 val1;
val2 val2;
subdict
{
@ -35,19 +37,75 @@ update
key3 val3;
key2b ${..key2};
key3b $^key1;
key100 100;
key200 200;
key300 300;
key400 400;
}
}
// expands update into top-level
$update
// Can a leading '^' or ':' as anchor for scoping
key3 $^subdict.key1;
_cleanup
{
#remove "/subdict/key300"
"/subdict/key400" 400000;
// Self-destruct not possible
// #remove "/_cleanup"
}
#remove "/_cleanup"
// Can use a leading '^' or ':' as anchor for scoping, but slashes are clearer
key3dot ${^subdict.key1};
key3slash ${/subdict/key1};
key3 ${^update.subdict.key3};
key4 ${:update.subdict...subdict.key1};
// This is currently not working
#remove update.key1
// #remove update
// This will not work, but globs would be interesting:
#remove "/update/subdict/key*"
// This is okay, uses a regexp directly
#remove "val.*"
#remove "/update/subdict/key100"
"/subdict/key2" overridden;
active
{
type turbulentIntensityKineticEnergyInlet;
intensity 0.1;
value 100;
}
// Some more with scoping
"/active/value(pwd)" 200;
"/active/'(pwd|foo)'" 200; // Can use single or double quotes
"/active/intensity" 0.05;
// Auto-vivify intermediate dictionaries
"/active/subdict/type" anotherType;
"/active/subdict/value/type" anotherType;
// This is an error - cannot change type of intermediate dictionaries!
// "active/value/type/of/things" newType;
"/active/subdict/value" change;
"/active/subdict/value" { entry1 value1; entry2 value2; }
// Handle remove as per changeDictionary? TBD
// Removal:
// "~/active/subdict/value"
// "~active"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

Some files were not shown because too many files have changed in this diff Show More