diff --git a/applications/solvers/combustion/PDRFoam/PDRModels/turbulence/PDRkEpsilon/PDRkEpsilon.C b/applications/solvers/combustion/PDRFoam/PDRModels/turbulence/PDRkEpsilon/PDRkEpsilon.C index aa9fd58b70..fdddddfbfe 100644 --- a/applications/solvers/combustion/PDRFoam/PDRModels/turbulence/PDRkEpsilon/PDRkEpsilon.C +++ b/applications/solvers/combustion/PDRFoam/PDRModels/turbulence/PDRkEpsilon/PDRkEpsilon.C @@ -270,7 +270,7 @@ void PDRkEpsilon::correct() } tmp tgradU = fvc::grad(U_); - volScalarField G = 2*mut_*(tgradU() && dev(symm(tgradU()))); + volScalarField G("RASModel::G", mut_*(tgradU() && dev(twoSymm(tgradU())))); tgradU.clear(); // Update espsilon and G at the wall diff --git a/applications/solvers/combustion/fireFoam/combustionModels/Make/options b/applications/solvers/combustion/fireFoam/combustionModels/Make/options index 42f59c8e17..3f557113c4 100644 --- a/applications/solvers/combustion/fireFoam/combustionModels/Make/options +++ b/applications/solvers/combustion/fireFoam/combustionModels/Make/options @@ -1,6 +1,4 @@ EXE_INC = \ - -I../sensibleEnthalpyCombustionThermophysicalModels/basic/lnInclude \ - -I../sensibleEnthalpyCombustionThermophysicalModels/reactionThermo/lnInclude \ -I$(LIB_SRC)/thermophysicalModels/basic/lnInclude \ -I$(LIB_SRC)/thermophysicalModels/reactionThermo/lnInclude \ -I$(LIB_SRC)/thermophysicalModels/specie/lnInclude \ diff --git a/applications/solvers/electromagnetics/mhdFoam/createFields.H b/applications/solvers/electromagnetics/mhdFoam/createFields.H index 5b346858b6..04e05c032d 100644 --- a/applications/solvers/electromagnetics/mhdFoam/createFields.H +++ b/applications/solvers/electromagnetics/mhdFoam/createFields.H @@ -61,7 +61,7 @@ mesh ); -# include "createPhi.H" + #include "createPhi.H" Info<< "Reading field pB\n" << endl; volScalarField pB @@ -93,15 +93,15 @@ ); -# include "createPhiB.H" + #include "createPhiB.H" -dimensionedScalar DB = 1.0/(mu*sigma); -DB.name() = "DB"; + dimensionedScalar DB = 1.0/(mu*sigma); + DB.name() = "DB"; -dimensionedScalar DBU = 1.0/(2.0*mu*rho); -DBU.name() = "DBU"; + dimensionedScalar DBU = 1.0/(2.0*mu*rho); + DBU.name() = "DBU"; -label pRefCell = 0; -scalar pRefValue = 0.0; -setRefCell(p, mesh.solutionDict().subDict("PISO"), pRefCell, pRefValue); + label pRefCell = 0; + scalar pRefValue = 0.0; + setRefCell(p, mesh.solutionDict().subDict("PISO"), pRefCell, pRefValue); diff --git a/applications/solvers/electromagnetics/mhdFoam/mhdFoam.C b/applications/solvers/electromagnetics/mhdFoam/mhdFoam.C index f09b35efc9..3603d04070 100644 --- a/applications/solvers/electromagnetics/mhdFoam/mhdFoam.C +++ b/applications/solvers/electromagnetics/mhdFoam/mhdFoam.C @@ -49,8 +49,6 @@ Description \*---------------------------------------------------------------------------*/ -#include "string.H" -#include "Time.H" #include "fvCFD.H" #include "OSspecific.H" diff --git a/applications/solvers/heatTransfer/chtMultiRegionFoam/derivedFvPatchFields/solidWallHeatFluxTemperature/solidWallHeatFluxTemperatureFvPatchScalarField.C b/applications/solvers/heatTransfer/chtMultiRegionFoam/derivedFvPatchFields/solidWallHeatFluxTemperature/solidWallHeatFluxTemperatureFvPatchScalarField.C index b1f8c3bed2..5013a4e6a2 100644 --- a/applications/solvers/heatTransfer/chtMultiRegionFoam/derivedFvPatchFields/solidWallHeatFluxTemperature/solidWallHeatFluxTemperatureFvPatchScalarField.C +++ b/applications/solvers/heatTransfer/chtMultiRegionFoam/derivedFvPatchFields/solidWallHeatFluxTemperature/solidWallHeatFluxTemperatureFvPatchScalarField.C @@ -38,7 +38,7 @@ solidWallHeatFluxTemperatureFvPatchScalarField const DimensionedField& iF ) : - fixedValueFvPatchScalarField(p, iF), + fixedGradientFvPatchScalarField(p, iF), q_(p.size(), 0.0), KName_("undefined-K") {} @@ -53,7 +53,7 @@ solidWallHeatFluxTemperatureFvPatchScalarField const fvPatchFieldMapper& mapper ) : - fixedValueFvPatchScalarField(ptf, p, iF, mapper), + fixedGradientFvPatchScalarField(ptf, p, iF, mapper), q_(ptf.q_, mapper), KName_(ptf.KName_) {} @@ -67,7 +67,7 @@ solidWallHeatFluxTemperatureFvPatchScalarField const dictionary& dict ) : - fixedValueFvPatchScalarField(p, iF, dict), + fixedGradientFvPatchScalarField(p, iF, dict), q_("q", dict, p.size()), KName_(dict.lookup("K")) {} @@ -79,7 +79,7 @@ solidWallHeatFluxTemperatureFvPatchScalarField const solidWallHeatFluxTemperatureFvPatchScalarField& tppsf ) : - fixedValueFvPatchScalarField(tppsf), + fixedGradientFvPatchScalarField(tppsf), q_(tppsf.q_), KName_(tppsf.KName_) {} @@ -92,7 +92,7 @@ solidWallHeatFluxTemperatureFvPatchScalarField const DimensionedField& iF ) : - fixedValueFvPatchScalarField(tppsf, iF), + fixedGradientFvPatchScalarField(tppsf, iF), q_(tppsf.q_), KName_(tppsf.KName_) {} @@ -105,7 +105,7 @@ void Foam::solidWallHeatFluxTemperatureFvPatchScalarField::autoMap const fvPatchFieldMapper& m ) { - fixedValueFvPatchScalarField::autoMap(m); + fixedGradientFvPatchScalarField::autoMap(m); q_.autoMap(m); } @@ -116,7 +116,7 @@ void Foam::solidWallHeatFluxTemperatureFvPatchScalarField::rmap const labelList& addr ) { - fixedValueFvPatchScalarField::rmap(ptf, addr); + fixedGradientFvPatchScalarField::rmap(ptf, addr); const solidWallHeatFluxTemperatureFvPatchScalarField& hfptf = refCast(ptf); @@ -132,14 +132,14 @@ void Foam::solidWallHeatFluxTemperatureFvPatchScalarField::updateCoeffs() return; } - const scalarField& Kw = - patch().lookupPatchField(KName_); + const scalarField& Kw = patch().lookupPatchField + ( + KName_ + ); - const fvPatchScalarField& Tw = *this; + gradient() = q_/Kw; - operator==(q_/(patch().deltaCoeffs()*Kw) + Tw.patchInternalField()); - - fixedValueFvPatchScalarField::updateCoeffs(); + fixedGradientFvPatchScalarField::updateCoeffs(); } @@ -148,9 +148,10 @@ void Foam::solidWallHeatFluxTemperatureFvPatchScalarField::write Ostream& os ) const { - fixedValueFvPatchScalarField::write(os); + fixedGradientFvPatchScalarField::write(os); q_.writeEntry("q", os); os.writeKeyword("K") << KName_ << token::END_STATEMENT << nl; + this->writeEntry("value", os); } diff --git a/applications/solvers/heatTransfer/chtMultiRegionFoam/derivedFvPatchFields/solidWallHeatFluxTemperature/solidWallHeatFluxTemperatureFvPatchScalarField.H b/applications/solvers/heatTransfer/chtMultiRegionFoam/derivedFvPatchFields/solidWallHeatFluxTemperature/solidWallHeatFluxTemperatureFvPatchScalarField.H index 85a1ef1cf1..d621e4d15a 100644 --- a/applications/solvers/heatTransfer/chtMultiRegionFoam/derivedFvPatchFields/solidWallHeatFluxTemperature/solidWallHeatFluxTemperatureFvPatchScalarField.H +++ b/applications/solvers/heatTransfer/chtMultiRegionFoam/derivedFvPatchFields/solidWallHeatFluxTemperature/solidWallHeatFluxTemperatureFvPatchScalarField.H @@ -46,7 +46,7 @@ SourceFiles #ifndef solidWallHeatFluxTemperatureFvPatchScalarField_H #define solidWallHeatFluxTemperatureFvPatchScalarField_H -#include "fixedValueFvPatchFields.H" +#include "fixedGradientFvPatchFields.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -59,7 +59,7 @@ namespace Foam class solidWallHeatFluxTemperatureFvPatchScalarField : - public fixedValueFvPatchScalarField + public fixedGradientFvPatchScalarField { // Private data diff --git a/applications/solvers/incompressible/ajointShapeOptimizationFoam/Make/files b/applications/solvers/incompressible/ajointShapeOptimizationFoam/Make/files new file mode 100644 index 0000000000..d42156d410 --- /dev/null +++ b/applications/solvers/incompressible/ajointShapeOptimizationFoam/Make/files @@ -0,0 +1,5 @@ +adjointOutletPressure/adjointOutletPressureFvPatchScalarField.C +adjointOutletVelocity/adjointOutletVelocityFvPatchVectorField.C +adjointShapeOptimizationFoam.C + +EXE = $(FOAM_APPBIN)/adjointShapeOptimizationFoam diff --git a/applications/solvers/incompressible/ajointShapeOptimizationFoam/Make/options b/applications/solvers/incompressible/ajointShapeOptimizationFoam/Make/options new file mode 100644 index 0000000000..1223bdd06f --- /dev/null +++ b/applications/solvers/incompressible/ajointShapeOptimizationFoam/Make/options @@ -0,0 +1,11 @@ +EXE_INC = \ + -I$(LIB_SRC)/turbulenceModels \ + -I$(LIB_SRC)/turbulenceModels/incompressible/RAS/RASModel \ + -I$(LIB_SRC)/transportModels \ + -I$(LIB_SRC)/transportModels/incompressible/singlePhaseTransportModel \ + -I$(LIB_SRC)/finiteVolume/lnInclude + +EXE_LIBS = \ + -lincompressibleRASModels \ + -lincompressibleTransportModels \ + -lfiniteVolume diff --git a/applications/solvers/incompressible/ajointShapeOptimizationFoam/adjointContinuityErrs.H b/applications/solvers/incompressible/ajointShapeOptimizationFoam/adjointContinuityErrs.H new file mode 100644 index 0000000000..74ebd457c0 --- /dev/null +++ b/applications/solvers/incompressible/ajointShapeOptimizationFoam/adjointContinuityErrs.H @@ -0,0 +1,47 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 1991-2010 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 2 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, write to the Free Software Foundation, + Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +Global + continuityErrs + +Description + Calculates and prints the continuity errors. + +\*---------------------------------------------------------------------------*/ + +{ + scalar sumLocalContErr = runTime.deltaT().value()* + mag(fvc::div(phia))().weightedAverage(mesh.V()).value(); + + scalar globalContErr = runTime.deltaT().value()* + fvc::div(phia)().weightedAverage(mesh.V()).value(); + cumulativeContErr += globalContErr; + + Info<< "Adjoint continuity errors : sum local = " << sumLocalContErr + << ", global = " << globalContErr + << ", cumulative = " << cumulativeContErr + << endl; +} + +// ************************************************************************* // diff --git a/applications/solvers/incompressible/ajointShapeOptimizationFoam/adjointOutletPressure/adjointOutletPressureFvPatchScalarField.C b/applications/solvers/incompressible/ajointShapeOptimizationFoam/adjointOutletPressure/adjointOutletPressureFvPatchScalarField.C new file mode 100644 index 0000000000..13debc1786 --- /dev/null +++ b/applications/solvers/incompressible/ajointShapeOptimizationFoam/adjointOutletPressure/adjointOutletPressureFvPatchScalarField.C @@ -0,0 +1,132 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 1991-2007 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 2 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, write to the Free Software Foundation, + Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +\*---------------------------------------------------------------------------*/ + +#include "adjointOutletPressureFvPatchScalarField.H" +#include "addToRunTimeSelectionTable.H" +#include "fvPatchMapper.H" +#include "volFields.H" +#include "surfaceFields.H" + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +Foam::adjointOutletPressureFvPatchScalarField:: +adjointOutletPressureFvPatchScalarField +( + const fvPatch& p, + const DimensionedField& iF +) +: + fixedValueFvPatchScalarField(p, iF) +{} + + +Foam::adjointOutletPressureFvPatchScalarField:: +adjointOutletPressureFvPatchScalarField +( + const adjointOutletPressureFvPatchScalarField& ptf, + const fvPatch& p, + const DimensionedField& iF, + const fvPatchFieldMapper& mapper +) +: + fixedValueFvPatchScalarField(ptf, p, iF, mapper) +{} + + +Foam::adjointOutletPressureFvPatchScalarField:: +adjointOutletPressureFvPatchScalarField +( + const fvPatch& p, + const DimensionedField& iF, + const dictionary& dict +) +: + fixedValueFvPatchScalarField(p, iF) +{ + fvPatchField::operator= + ( + scalarField("value", dict, p.size()) + ); +} + + +Foam::adjointOutletPressureFvPatchScalarField:: +adjointOutletPressureFvPatchScalarField +( + const adjointOutletPressureFvPatchScalarField& tppsf, + const DimensionedField& iF +) +: + fixedValueFvPatchScalarField(tppsf, iF) +{} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +void Foam::adjointOutletPressureFvPatchScalarField::updateCoeffs() +{ + if (updated()) + { + return; + } + + const fvsPatchField& phip = + patch().lookupPatchField("phi"); + + const fvsPatchField& phiap = + patch().lookupPatchField("phia"); + + const fvPatchField& Up = + patch().lookupPatchField("U"); + + const fvPatchField& Uap = + patch().lookupPatchField("Ua"); + + operator==((phiap/patch().magSf() - 1.0)*phip/patch().magSf() + (Up & Uap)); + + fixedValueFvPatchScalarField::updateCoeffs(); +} + + +void Foam::adjointOutletPressureFvPatchScalarField::write(Ostream& os) const +{ + fvPatchScalarField::write(os); + writeEntry("value", os); +} + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + makePatchTypeField + ( + fvPatchScalarField, + adjointOutletPressureFvPatchScalarField + ); +} + +// ************************************************************************* // diff --git a/applications/solvers/incompressible/ajointShapeOptimizationFoam/adjointOutletPressure/adjointOutletPressureFvPatchScalarField.H b/applications/solvers/incompressible/ajointShapeOptimizationFoam/adjointOutletPressure/adjointOutletPressureFvPatchScalarField.H new file mode 100644 index 0000000000..59514cb67f --- /dev/null +++ b/applications/solvers/incompressible/ajointShapeOptimizationFoam/adjointOutletPressure/adjointOutletPressureFvPatchScalarField.H @@ -0,0 +1,137 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 1991-2007 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 2 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, write to the Free Software Foundation, + Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +Class + adjointOutletPressureFvPatchScalarField + +Description + +SourceFiles + adjointOutletPressureFvPatchScalarField.C + +\*---------------------------------------------------------------------------*/ + +#ifndef adjointOutletPressureFvPatchScalarField_H +#define adjointOutletPressureFvPatchScalarField_H + +#include "fixedValueFvPatchFields.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +/*---------------------------------------------------------------------------*\ + Class adjointOutletPressureFvPatch Declaration +\*---------------------------------------------------------------------------*/ + +class adjointOutletPressureFvPatchScalarField +: + public fixedValueFvPatchScalarField +{ + +public: + + //- Runtime type information + TypeName("adjointOutletPressure"); + + + // Constructors + + //- Construct from patch and internal field + adjointOutletPressureFvPatchScalarField + ( + const fvPatch&, + const DimensionedField& + ); + + //- Construct from patch, internal field and dictionary + adjointOutletPressureFvPatchScalarField + ( + const fvPatch&, + const DimensionedField&, + const dictionary& + ); + + //- Construct by mapping given adjointOutletPressureFvPatchScalarField + // onto a new patch + adjointOutletPressureFvPatchScalarField + ( + const adjointOutletPressureFvPatchScalarField&, + const fvPatch&, + const DimensionedField&, + const fvPatchFieldMapper& + ); + + //- Construct and return a clone + virtual tmp clone() const + { + return tmp + ( + new adjointOutletPressureFvPatchScalarField(*this) + ); + } + + //- Construct as copy setting internal field reference + adjointOutletPressureFvPatchScalarField + ( + const adjointOutletPressureFvPatchScalarField&, + const DimensionedField& + ); + + //- Construct and return a clone setting internal field reference + virtual tmp clone + ( + const DimensionedField& iF + ) const + { + return tmp + ( + new adjointOutletPressureFvPatchScalarField(*this, iF) + ); + } + + + // Member functions + + // Evaluation functions + + //- Update the coefficients associated with the patch field + virtual void updateCoeffs(); + + + //- Write + virtual void write(Ostream&) const; +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/applications/solvers/incompressible/ajointShapeOptimizationFoam/adjointOutletVelocity/adjointOutletVelocityFvPatchVectorField.C b/applications/solvers/incompressible/ajointShapeOptimizationFoam/adjointOutletVelocity/adjointOutletVelocityFvPatchVectorField.C new file mode 100644 index 0000000000..e99550c619 --- /dev/null +++ b/applications/solvers/incompressible/ajointShapeOptimizationFoam/adjointOutletVelocity/adjointOutletVelocityFvPatchVectorField.C @@ -0,0 +1,131 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 1991-2007 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 2 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, write to the Free Software Foundation, + Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +\*---------------------------------------------------------------------------*/ + +#include "adjointOutletVelocityFvPatchVectorField.H" +#include "volFields.H" +#include "addToRunTimeSelectionTable.H" +#include "surfaceFields.H" +#include "fvPatchFieldMapper.H" + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +Foam::adjointOutletVelocityFvPatchVectorField:: +adjointOutletVelocityFvPatchVectorField +( + const fvPatch& p, + const DimensionedField& iF +) +: + fixedValueFvPatchVectorField(p, iF) +{} + + +Foam::adjointOutletVelocityFvPatchVectorField:: +adjointOutletVelocityFvPatchVectorField +( + const fvPatch& p, + const DimensionedField& iF, + const dictionary& dict +) +: + fixedValueFvPatchVectorField(p, iF) +{ + fvPatchVectorField::operator=(vectorField("value", dict, p.size())); +} + + +Foam::adjointOutletVelocityFvPatchVectorField:: +adjointOutletVelocityFvPatchVectorField +( + const adjointOutletVelocityFvPatchVectorField& ptf, + const fvPatch& p, + const DimensionedField& iF, + const fvPatchFieldMapper& mapper +) +: + fixedValueFvPatchVectorField(ptf, p, iF, mapper) +{} + + +Foam::adjointOutletVelocityFvPatchVectorField:: +adjointOutletVelocityFvPatchVectorField +( + const adjointOutletVelocityFvPatchVectorField& pivpvf, + const DimensionedField& iF +) +: + fixedValueFvPatchVectorField(pivpvf, iF) +{} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +// Update the coefficients associated with the patch field +void Foam::adjointOutletVelocityFvPatchVectorField::updateCoeffs() +{ + if (updated()) + { + return; + } + + const fvsPatchField& phiap = + patch().lookupPatchField("phia"); + + const fvPatchField& Up = + patch().lookupPatchField("U"); + + scalarField Un = mag(patch().nf() & Up); + vectorField UtHat = (Up - patch().nf()*Un)/(Un + SMALL); + + vectorField Uan = patch().nf()*(patch().nf() & patchInternalField()); + + vectorField::operator=(phiap*patch().Sf()/sqr(patch().magSf()) + UtHat); + //vectorField::operator=(Uan + UtHat); + + fixedValueFvPatchVectorField::updateCoeffs(); +} + + +void Foam::adjointOutletVelocityFvPatchVectorField::write(Ostream& os) const +{ + fvPatchVectorField::write(os); + writeEntry("value", os); +} + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + makePatchTypeField + ( + fvPatchVectorField, + adjointOutletVelocityFvPatchVectorField + ); +} + + +// ************************************************************************* // diff --git a/applications/solvers/incompressible/ajointShapeOptimizationFoam/adjointOutletVelocity/adjointOutletVelocityFvPatchVectorField.H b/applications/solvers/incompressible/ajointShapeOptimizationFoam/adjointOutletVelocity/adjointOutletVelocityFvPatchVectorField.H new file mode 100644 index 0000000000..2e14f96f9b --- /dev/null +++ b/applications/solvers/incompressible/ajointShapeOptimizationFoam/adjointOutletVelocity/adjointOutletVelocityFvPatchVectorField.H @@ -0,0 +1,131 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 1991-2007 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 2 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, write to the Free Software Foundation, + Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +Class + adjointOutletVelocityFvPatchVectorField + +Description + +SourceFiles + adjointOutletVelocityFvPatchVectorField.C + +\*---------------------------------------------------------------------------*/ + +#ifndef adjointOutletVelocityFvPatchVectorField_H +#define adjointOutletVelocityFvPatchVectorField_H + +#include "fixedValueFvPatchFields.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +/*---------------------------------------------------------------------------*\ + Class adjointOutletVelocityFvPatch Declaration +\*---------------------------------------------------------------------------*/ + +class adjointOutletVelocityFvPatchVectorField +: + public fixedValueFvPatchVectorField +{ + +public: + + //- Runtime type information + TypeName("adjointOutletVelocity"); + + + // Constructors + + //- Construct from patch and internal field + adjointOutletVelocityFvPatchVectorField + ( + const fvPatch&, + const DimensionedField& + ); + + //- Construct from patch, internal field and dictionary + adjointOutletVelocityFvPatchVectorField + ( + const fvPatch&, + const DimensionedField&, + const dictionary& + ); + + //- Construct by mapping given adjointOutletVelocityFvPatchVectorField + // onto a new patch + adjointOutletVelocityFvPatchVectorField + ( + const adjointOutletVelocityFvPatchVectorField&, + const fvPatch&, + const DimensionedField&, + const fvPatchFieldMapper& + ); + + //- Construct and return a clone + virtual tmp clone() const + { + return tmp + ( + new adjointOutletVelocityFvPatchVectorField(*this) + ); + } + + //- Construct as copy setting internal field reference + adjointOutletVelocityFvPatchVectorField + ( + const adjointOutletVelocityFvPatchVectorField&, + const DimensionedField& + ); + + //- Construct and return a clone setting internal field reference + virtual tmp clone(const DimensionedField& iF) const + { + return tmp + ( + new adjointOutletVelocityFvPatchVectorField(*this, iF) + ); + } + + + // Member functions + + //- Update the coefficients associated with the patch field + virtual void updateCoeffs(); + + //- Write + virtual void write(Ostream&) const; +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/applications/solvers/incompressible/ajointShapeOptimizationFoam/adjointShapeOptimizationFoam.C b/applications/solvers/incompressible/ajointShapeOptimizationFoam/adjointShapeOptimizationFoam.C new file mode 100644 index 0000000000..acf1be057f --- /dev/null +++ b/applications/solvers/incompressible/ajointShapeOptimizationFoam/adjointShapeOptimizationFoam.C @@ -0,0 +1,226 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 1991-2010 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 2 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, write to the Free Software Foundation, + Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +Application + ajointShapeOptimizationFoam + +Description + Steady-state solver for incompressible, turbulent flow of non-Newtonian + fluids with optimisation of duct shape by applying "blockage" in regions + causing pressure loss as estimated using an adjoint formulation. + + References: + @verbatim + "Implementation of a continuous adjoint for topology optimization of + ducted flows" + C. Othmer, + E. de Villiers, + H.G. Weller + AIAA-2007-3947 + http://pdf.aiaa.org/preview/CDReadyMCFD07_1379/PV2007_3947.pdf + @endverbatim + + Note that this solver optimises for total pressure loss whereas the + above paper describes the method for optimising power-loss. + +\*---------------------------------------------------------------------------*/ + +#include "fvCFD.H" +#include "singlePhaseTransportModel.H" +#include "RASModel.H" + +template +void zeroCells +( + GeometricField& vf, + const labelList& cells +) +{ + forAll(cells, i) + { + vf[cells[i]] = pTraits::zero; + } +} + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +int main(int argc, char *argv[]) +{ + #include "setRootCase.H" + + #include "createTime.H" + #include "createMesh.H" + #include "createFields.H" + #include "initContinuityErrs.H" + + // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + + Info<< "\nStarting time loop\n" << endl; + + for (runTime++; !runTime.end(); runTime++) + { + Info<< "Time = " << runTime.timeName() << nl << endl; + + #include "readSIMPLEControls.H" + + p.storePrevIter(); + + laminarTransport.lookup("lambda") >> lambda; + + //alpha += + // mesh.relaxationFactor("alpha") + // *(lambda*max(Ua & U, zeroSensitivity) - alpha); + alpha += + mesh.relaxationFactor("alpha") + *(min(max(alpha + lambda*(Ua & U), zeroAlpha), alphaMax) - alpha); + + zeroCells(alpha, inletCells); + //zeroCells(alpha, outletCells); + + // Pressure-velocity SIMPLE corrector + { + // Momentum predictor + + tmp UEqn + ( + fvm::div(phi, U) + + turbulence->divDevReff(U) + + fvm::Sp(alpha, U) + ); + + UEqn().relax(); + + solve(UEqn() == -fvc::grad(p)); + + p.boundaryField().updateCoeffs(); + volScalarField rAU = 1.0/UEqn().A(); + U = rAU*UEqn().H(); + UEqn.clear(); + phi = fvc::interpolate(U) & mesh.Sf(); + adjustPhi(phi, U, p); + + // Non-orthogonal pressure corrector loop + for (int nonOrth=0; nonOrth<=nNonOrthCorr; nonOrth++) + { + fvScalarMatrix pEqn + ( + fvm::laplacian(rAU, p) == fvc::div(phi) + ); + + pEqn.setReference(pRefCell, pRefValue); + pEqn.solve(); + + if (nonOrth == nNonOrthCorr) + { + phi -= pEqn.flux(); + } + } + + #include "continuityErrs.H" + + // Explicitly relax pressure for momentum corrector + p.relax(); + + // Momentum corrector + U -= rAU*fvc::grad(p); + U.correctBoundaryConditions(); + } + + pa.storePrevIter(); + + // Adjoint Pressure-velocity SIMPLE corrector + { + // Adjoint Momentum predictor + + volVectorField adjointTransposeConvection = (fvc::grad(Ua) & U); + //volVectorField adjointTransposeConvection = fvc::reconstruct + //( + // mesh.magSf()*(fvc::snGrad(Ua) & fvc::interpolate(U)) + //); + + zeroCells(adjointTransposeConvection, inletCells); + + tmp UaEqn + ( + fvm::div(-phi, Ua) + - adjointTransposeConvection + + turbulence->divDevReff(Ua) + + fvm::Sp(alpha, Ua) + ); + + UaEqn().relax(); + + solve(UaEqn() == -fvc::grad(pa)); + + pa.boundaryField().updateCoeffs(); + volScalarField rAUa = 1.0/UaEqn().A(); + Ua = rAUa*UaEqn().H(); + UaEqn.clear(); + phia = fvc::interpolate(Ua) & mesh.Sf(); + adjustPhi(phia, Ua, pa); + + // Non-orthogonal pressure corrector loop + for (int nonOrth=0; nonOrth<=nNonOrthCorr; nonOrth++) + { + fvScalarMatrix paEqn + ( + fvm::laplacian(rAUa, pa) == fvc::div(phia) + ); + + paEqn.setReference(paRefCell, paRefValue); + paEqn.solve(); + + if (nonOrth == nNonOrthCorr) + { + phia -= paEqn.flux(); + } + } + + #include "adjointContinuityErrs.H" + + // Explicitly relax pressure for adjoint momentum corrector + pa.relax(); + + // Adjoint momentum corrector + Ua -= rAUa*fvc::grad(pa); + Ua.correctBoundaryConditions(); + } + + turbulence->correct(); + + runTime.write(); + + Info<< "ExecutionTime = " + << runTime.elapsedCpuTime() + << " s\n\n" << endl; + } + + Info<< "End\n" << endl; + + return(0); +} + + +// ************************************************************************* // diff --git a/applications/solvers/incompressible/ajointShapeOptimizationFoam/createFields.H b/applications/solvers/incompressible/ajointShapeOptimizationFoam/createFields.H new file mode 100644 index 0000000000..dd2f6416ee --- /dev/null +++ b/applications/solvers/incompressible/ajointShapeOptimizationFoam/createFields.H @@ -0,0 +1,105 @@ + Info << "Reading field p\n" << endl; + volScalarField p + ( + IOobject + ( + "p", + runTime.timeName(), + mesh, + IOobject::MUST_READ, + IOobject::AUTO_WRITE + ), + mesh + ); + + Info << "Reading field U\n" << endl; + volVectorField U + ( + IOobject + ( + "U", + runTime.timeName(), + mesh, + IOobject::MUST_READ, + IOobject::AUTO_WRITE + ), + mesh + ); + + #include "createPhi.H" + + + label pRefCell = 0; + scalar pRefValue = 0.0; + setRefCell(p, mesh.solutionDict().subDict("SIMPLE"), pRefCell, pRefValue); + + + Info << "Reading field pa\n" << endl; + volScalarField pa + ( + IOobject + ( + "pa", + runTime.timeName(), + mesh, + IOobject::MUST_READ, + IOobject::AUTO_WRITE + ), + mesh + ); + + Info << "Reading field Ua\n" << endl; + volVectorField Ua + ( + IOobject + ( + "Ua", + runTime.timeName(), + mesh, + IOobject::MUST_READ, + IOobject::AUTO_WRITE + ), + mesh + ); + + #include "createPhia.H" + + + label paRefCell = 0; + scalar paRefValue = 0.0; + setRefCell(pa, mesh.solutionDict().subDict("SIMPLE"), paRefCell, paRefValue); + + + singlePhaseTransportModel laminarTransport(U, phi); + + autoPtr turbulence + ( + incompressible::RASModel::New(U, phi, laminarTransport) + ); + + + dimensionedScalar zeroSensitivity("0", dimVelocity*dimVelocity, 0.0); + dimensionedScalar zeroAlpha("0", dimless/dimTime, 0.0); + + dimensionedScalar lambda(laminarTransport.lookup("lambda")); + dimensionedScalar alphaMax(laminarTransport.lookup("alphaMax")); + + const labelList& inletCells = + mesh.boundary()[mesh.boundaryMesh().findPatchID("inlet")].faceCells(); + //const labelList& outletCells = + // mesh.boundary()[mesh.boundaryMesh().findPatchID("outlet")].faceCells(); + + volScalarField alpha + ( + IOobject + ( + "alpha", + runTime.timeName(), + mesh, + IOobject::READ_IF_PRESENT, + IOobject::AUTO_WRITE + ), + lambda*max(Ua & U, zeroSensitivity) + ); + zeroCells(alpha, inletCells); + //zeroCells(alpha, outletCells); diff --git a/src/finiteVolume/interpolation/surfaceInterpolation/limitedSchemes/MC/MC.H b/applications/solvers/incompressible/ajointShapeOptimizationFoam/createPhia.H similarity index 51% rename from src/finiteVolume/interpolation/surfaceInterpolation/limitedSchemes/MC/MC.H rename to applications/solvers/incompressible/ajointShapeOptimizationFoam/createPhia.H index fa47fe13b7..ea227ab133 100644 --- a/src/finiteVolume/interpolation/surfaceInterpolation/limitedSchemes/MC/MC.H +++ b/applications/solvers/incompressible/ajointShapeOptimizationFoam/createPhia.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd. + \\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -22,70 +22,33 @@ License along with OpenFOAM; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -Class - Foam::MCLimiter +Global + createPhia Description - Class with limiter function which returns the limiter for the - monotonised centred differencing scheme based on r obtained from - the LimiterFunc class. - - Used in conjunction with the template class LimitedScheme. - -SourceFiles - MC.C + Creates and initialises the face-flux field phia. \*---------------------------------------------------------------------------*/ -#ifndef MC_H -#define MC_H - -#include "vector.H" +#ifndef createPhia_H +#define createPhia_H // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // -namespace Foam -{ +Info<< "Reading/calculating face flux field phia\n" << endl; -/*---------------------------------------------------------------------------*\ - Class MCLimiter Declaration -\*---------------------------------------------------------------------------*/ - -template -class MCLimiter -: - public LimiterFunc -{ - -public: - - MCLimiter(Istream&) - {} - - scalar limiter +surfaceScalarField phia +( + IOobject ( - const scalar cdWeight, - const scalar faceFlux, - const typename LimiterFunc::phiType& phiP, - const typename LimiterFunc::phiType& phiN, - const typename LimiterFunc::gradPhiType& gradcP, - const typename LimiterFunc::gradPhiType& gradcN, - const vector& d - ) const - { - scalar r = LimiterFunc::r - ( - faceFlux, phiP, phiN, gradcP, gradcN, d - ); - - return max(min(min(2*r, 0.5*(1 + r)), 2), 0); - } -}; - - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -} // End namespace Foam + "phia", + runTime.timeName(), + mesh, + IOobject::READ_IF_PRESENT, + IOobject::AUTO_WRITE + ), + linearInterpolate(Ua) & mesh.Sf() +); // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/applications/utilities/mesh/manipulation/checkMesh/checkTopology.C b/applications/utilities/mesh/manipulation/checkMesh/checkTopology.C index 364c59075f..f0aa4a0aaa 100644 --- a/applications/utilities/mesh/manipulation/checkMesh/checkTopology.C +++ b/applications/utilities/mesh/manipulation/checkMesh/checkTopology.C @@ -71,7 +71,7 @@ Foam::label Foam::checkTopology { Info<< " ***FaceZone " << mesh.faceZones()[zoneI].name() << " is not correctly synchronised" - << " acrosss coupled boundaries." + << " across coupled boundaries." << " (coupled faces both" << " present in set but with opposite flipmap)" << endl; noFailedChecks++; diff --git a/applications/utilities/postProcessing/dataConversion/foamToEnsight/ensightField.C b/applications/utilities/postProcessing/dataConversion/foamToEnsight/ensightField.C index 1204ac5976..e446dcac89 100644 --- a/applications/utilities/postProcessing/dataConversion/foamToEnsight/ensightField.C +++ b/applications/utilities/postProcessing/dataConversion/foamToEnsight/ensightField.C @@ -110,40 +110,30 @@ void writeAllData { if (nPrims) { - PstreamBuffers pBufs(Pstream::nonBlocking); - - if (!Pstream::master()) - { - UOPstream toMaster(Pstream::masterNo(), pBufs); - for (direction cmpt=0; cmpt::nComponents; cmpt++) - { - toMaster<< map(vf, prims, cmpt); - } - } - - pBufs.finishedSends(); - if (Pstream::master()) { ensightFile << key << nl; - PtrList fromSlaves(Pstream::nProcs()); - for (int slave=1; slave::nComponents; cmpt++) { writeData(map(vf, prims, cmpt), ensightFile); for (int slave=1; slave::nComponents; cmpt++) + { + OPstream toMaster(Pstream::scheduled, Pstream::masterNo()); + toMaster<< map(vf, prims, cmpt); + } + } } } @@ -160,40 +150,30 @@ void writeAllDataBinary { if (nPrims) { - PstreamBuffers pBufs(Pstream::nonBlocking); - - if (!Pstream::master()) - { - UOPstream toMaster(Pstream::masterNo(), pBufs); - for (direction cmpt=0; cmpt::nComponents; cmpt++) - { - toMaster<< map(vf, prims, cmpt); - } - } - - pBufs.finishedSends(); - if (Pstream::master()) { writeEnsDataBinary(key,ensightFile); - PtrList fromSlaves(Pstream::nProcs()); - for (int slave=1; slave::nComponents; cmpt++) { writeEnsDataBinary(map(vf, prims, cmpt), ensightFile); for (int slave=1; slave::nComponents; cmpt++) + { + OPstream toMaster(Pstream::scheduled, Pstream::masterNo()); + toMaster<< map(vf, prims, cmpt); + } + } } } @@ -210,40 +190,31 @@ void writeAllFaceData { if (nPrims) { - PstreamBuffers pBufs(Pstream::nonBlocking); - - if (!Pstream::master()) - { - UOPstream toMaster(Pstream::masterNo(), pBufs); - for (direction cmpt=0; cmpt::nComponents; cmpt++) - { - toMaster<< map(pf, prims, cmpt); - } - } - - pBufs.finishedSends(); - if (Pstream::master()) { ensightFile << key << nl; - PtrList fromSlaves(Pstream::nProcs()); - for (int slave=1; slave::nComponents; cmpt++) { writeData(map(pf, prims, cmpt), ensightFile); for (int slave=1; slave::nComponents; cmpt++) + { + OPstream toMaster(Pstream::scheduled, Pstream::masterNo()); + toMaster<< map(pf, prims, cmpt); + } + } } } @@ -260,40 +231,31 @@ void writeAllFaceDataBinary { if (nPrims) { - PstreamBuffers pBufs(Pstream::nonBlocking); - - if (!Pstream::master()) - { - UOPstream toMaster(Pstream::masterNo(), pBufs); - for (direction cmpt=0; cmpt::nComponents; cmpt++) - { - toMaster<< map(pf, prims, cmpt); - } - } - - pBufs.finishedSends(); - if (Pstream::master()) { writeEnsDataBinary(key,ensightFile); - PtrList fromSlaves(Pstream::nProcs()); - for (int slave=1; slave::nComponents; cmpt++) { writeEnsDataBinary(map(pf, prims, cmpt), ensightFile); for (int slave=1; slave::nComponents; cmpt++) + { + OPstream toMaster(Pstream::scheduled, Pstream::masterNo()); + toMaster<< map(pf, prims, cmpt); + } + } } } @@ -539,6 +501,10 @@ void ensightFieldAscii const wordHashSet& patchNames = eMesh.patchNames(); const HashTable& nPatchPrims = eMesh.nPatchPrims(); + const List& faceZoneFaceSets = eMesh.faceZoneFaceSets(); + const wordHashSet& faceZoneNames = eMesh.faceZoneNames(); + const HashTable& + nFaceZonePrims = eMesh.nFaceZonePrims(); const labelList& tets = meshCellSets.tets; const labelList& pyrs = meshCellSets.pyrs; @@ -557,7 +523,7 @@ void ensightFieldAscii postProcPath/ensightFileName, runTime.writeFormat(), runTime.writeVersion(), - runTime.writeCompression() + IOstream::UNCOMPRESSED ); } @@ -567,6 +533,8 @@ void ensightFieldAscii if (patchNames.empty()) { + eMesh.barrier(); + if (Pstream::master()) { if (timeIndex == 0) @@ -592,29 +560,10 @@ void ensightFieldAscii if (meshCellSets.nHexesWedges) { - PstreamBuffers pBufs(Pstream::nonBlocking); - - if (!Pstream::master()) - { - UOPstream toMaster(Pstream::masterNo(), pBufs); - for (direction cmpt=0; cmpt::nComponents; cmpt++) - { - toMaster<< map(vf, hexes, wedges, cmpt); - } - } - - pBufs.finishedSends(); - if (Pstream::master()) { ensightFile << "hexa8" << nl; - PtrList fromSlaves(Pstream::nProcs()); - for (int slave=1; slave::nComponents; cmpt++) { writeData @@ -625,17 +574,57 @@ void ensightFieldAscii for (int slave=1; slave::nComponents; cmpt++) + { + OPstream toMaster(Pstream::scheduled, Pstream::masterNo()); + toMaster<< map(vf, hexes, wedges, cmpt); + } + } } - writeAllData("penta6", vf, prisms, meshCellSets.nPrisms, ensightFile); - writeAllData("pyramid5", vf, pyrs, meshCellSets.nPyrs, ensightFile); - writeAllData("tetra4", vf, tets, meshCellSets.nTets, ensightFile); - writeAllData("nfaced", vf, polys, meshCellSets.nPolys, ensightFile); + writeAllData + ( + "penta6", + vf, + prisms, + meshCellSets.nPrisms, + ensightFile + ); + + writeAllData + ( + "pyramid5", + vf, + pyrs, + meshCellSets.nPyrs, + ensightFile + ); + + writeAllData + ( + "tetra4", + vf, + tets, + meshCellSets.nTets, + ensightFile + ); + + writeAllData + ( + "nfaced", + vf, + polys, + meshCellSets.nPolys, + ensightFile + ); } label ensightPatchI = eMesh.patchPartOffset(); @@ -644,6 +633,8 @@ void ensightFieldAscii { const word& patchName = allPatchNames[patchi]; + eMesh.barrier(); + if (patchNames.empty() || patchNames.found(patchName)) { if @@ -664,6 +655,80 @@ void ensightFieldAscii } } + // write faceZones, if requested + if (faceZoneNames.size()) + { + // Interpolates cell values to faces - needed only when exporting + // faceZones... + GeometricField sf + ( + linearInterpolate(vf) + ); + + forAllConstIter(wordHashSet, faceZoneNames, iter) + { + const word& faceZoneName = iter.key(); + + eMesh.barrier(); + + label zoneID = mesh.faceZones().findZoneID(faceZoneName); + + const faceZone& fz = mesh.faceZones()[zoneID]; + + // Prepare data to write + label nIncluded = 0; + forAll(fz, i) + { + if (eMesh.faceToBeIncluded(fz[i])) + { + ++nIncluded; + } + } + + Field values(nIncluded); + + // Loop on the faceZone and store the needed field values + label j = 0; + forAll(fz, i) + { + label faceI = fz[i]; + if (mesh.isInternalFace(faceI)) + { + values[j] = sf[faceI]; + ++j; + } + else + { + if (eMesh.faceToBeIncluded(faceI)) + { + label patchI = mesh.boundaryMesh().whichPatch(faceI); + const polyPatch& pp = mesh.boundaryMesh()[patchI]; + label patchFaceI = pp.whichFace(faceI); + Type value = sf.boundaryField()[patchI][patchFaceI]; + values[j] = value; + ++j; + } + } + } + + if + ( + writePatchField + ( + values, + zoneID, + ensightPatchI, + faceZoneFaceSets[zoneID], + nFaceZonePrims.find(faceZoneName)(), + ensightFile + ) + ) + { + ensightPatchI++; + } + } + } + if (Pstream::master()) { delete ensightFilePtr; @@ -695,6 +760,10 @@ void ensightFieldBinary const wordHashSet& patchNames = eMesh.patchNames(); const HashTable& nPatchPrims = eMesh.nPatchPrims(); + const List& faceZoneFaceSets = eMesh.faceZoneFaceSets(); + const wordHashSet& faceZoneNames = eMesh.faceZoneNames(); + const HashTable& + nFaceZonePrims = eMesh.nFaceZonePrims(); const labelList& tets = meshCellSets.tets; const labelList& pyrs = meshCellSets.pyrs; @@ -722,6 +791,8 @@ void ensightFieldBinary if (patchNames.empty()) { + eMesh.barrier(); + if (Pstream::master()) { if (timeIndex == 0) @@ -743,29 +814,10 @@ void ensightFieldBinary if (meshCellSets.nHexesWedges) { - PstreamBuffers pBufs(Pstream::nonBlocking); - - if (!Pstream::master()) - { - UOPstream toMaster(Pstream::masterNo(), pBufs); - for (direction cmpt=0; cmpt::nComponents; cmpt++) - { - toMaster<< map(vf, hexes, wedges, cmpt); - } - } - - pBufs.finishedSends(); - if (Pstream::master()) { writeEnsDataBinary("hexa8",ensightFile); - PtrList fromSlaves(Pstream::nProcs()); - for (int slave=1; slave::nComponents; cmpt++) { writeEnsDataBinary @@ -776,11 +828,20 @@ void ensightFieldBinary for (int slave=1; slave::nComponents; cmpt++) + { + OPstream toMaster(Pstream::scheduled, Pstream::masterNo()); + toMaster<< map(vf, hexes, wedges, cmpt); + } + } } writeAllDataBinary @@ -826,6 +887,8 @@ void ensightFieldBinary { const word& patchName = allPatchNames[patchi]; + eMesh.barrier(); + if (patchNames.empty() || patchNames.found(patchName)) { if @@ -844,6 +907,81 @@ void ensightFieldBinary ensightPatchI++; } } + + } + + // write faceZones, if requested + if (faceZoneNames.size()) + { + // Interpolates cell values to faces - needed only when exporting + // faceZones... + GeometricField sf + ( + linearInterpolate(vf) + ); + + forAllConstIter(wordHashSet, faceZoneNames, iter) + { + const word& faceZoneName = iter.key(); + + eMesh.barrier(); + + label zoneID = mesh.faceZones().findZoneID(faceZoneName); + + const faceZone& fz = mesh.faceZones()[zoneID]; + + // Prepare data to write + label nIncluded = 0; + forAll(fz, i) + { + if (eMesh.faceToBeIncluded(fz[i])) + { + ++nIncluded; + } + } + + Field values(nIncluded); + + // Loop on the faceZone and store the needed field values + label j = 0; + forAll(fz, i) + { + label faceI = fz[i]; + if (mesh.isInternalFace(faceI)) + { + values[j] = sf[faceI]; + ++j; + } + else + { + if (eMesh.faceToBeIncluded(faceI)) + { + label patchI = mesh.boundaryMesh().whichPatch(faceI); + const polyPatch& pp = mesh.boundaryMesh()[patchI]; + label patchFaceI = pp.whichFace(faceI); + Type value = sf.boundaryField()[patchI][patchFaceI]; + values[j] = value; + ++j; + } + } + } + + if + ( + writePatchFieldBinary + ( + values, + zoneID, + ensightPatchI, + faceZoneFaceSets[zoneID], + nFaceZonePrims.find(faceZoneName)(), + ensightFile + ) + ) + { + ensightPatchI++; + } + } } if (Pstream::master()) diff --git a/applications/utilities/postProcessing/dataConversion/foamToEnsight/ensightMesh.C b/applications/utilities/postProcessing/dataConversion/foamToEnsight/ensightMesh.C index 5f848736be..daece0473b 100644 --- a/applications/utilities/postProcessing/dataConversion/foamToEnsight/ensightMesh.C +++ b/applications/utilities/postProcessing/dataConversion/foamToEnsight/ensightMesh.C @@ -30,11 +30,14 @@ License #include "fvMesh.H" #include "globalMeshData.H" #include "PstreamCombineReduceOps.H" +#include "processorPolyPatch.H" #include "cellModeller.H" #include "IOmanip.H" #include "itoa.H" #include "ensightWriteBinary.H" +#include "globalIndex.H" #include "mapDistribute.H" +#include "stringListOps.H" #include @@ -56,7 +59,11 @@ Foam::ensightMesh::ensightMesh boundaryFaceSets_(mesh_.boundary().size()), allPatchNames_(0), patchNames_(0), - nPatchPrims_(0) + nPatchPrims_(0), + faceZoneFaceSets_(mesh_.faceZones().size()), + faceZoneNames_(0), + nFaceZonePrims_(0), + boundaryFaceToBeIncluded_(0) { const cellShapeList& cellShapes = mesh.cellShapes(); @@ -80,10 +87,7 @@ Foam::ensightMesh::ensightMesh if (args.optionFound("patches")) { - wordList patchNameList - ( - args.optionLookup("patches")() - ); + wordList patchNameList(args.optionLookup("patches")()); if (patchNameList.empty()) { @@ -218,7 +222,6 @@ Foam::ensightMesh::ensightMesh } } - forAll(allPatchNames_, patchi) { const word& patchName = allPatchNames_[patchi]; @@ -240,6 +243,133 @@ Foam::ensightMesh::ensightMesh nPatchPrims_.insert(patchName, nfp); } + + // faceZones + if (args.optionFound("faceZones")) + { + wordList patchNameList(args.optionLookup("faceZones")()); + + const wordList faceZoneNamesAll = mesh_.faceZones().names(); + + // Find out faceZone names that match with what requested at command + // line + forAll(patchNameList, i) + { + labelList matches = findStrings(patchNameList[i], faceZoneNamesAll); + + forAll(matches, matchI) + { + faceZoneNames_.insert(faceZoneNamesAll[matches[matchI]]); + } + } + + // Build list of boundary faces to be exported + boundaryFaceToBeIncluded_.setSize + ( + mesh_.nFaces() + - mesh_.nInternalFaces(), + 1 + ); + + forAll(mesh_.boundaryMesh(), patchI) + { + const polyPatch& pp = mesh_.boundaryMesh()[patchI]; + if + ( + isA(pp) + && !refCast(pp).owner() + ) + { + label bFaceI = pp.start()-mesh_.nInternalFaces(); + forAll(pp, i) + { + boundaryFaceToBeIncluded_[bFaceI++] = 0; + } + } + } + + // Count face types in each faceZone + forAll(faceZoneNamesAll, zoneI) + { + //const word& zoneName = faceZoneNamesAll[zoneI]; + + const faceZone& fz = mesh.faceZones()[zoneI]; + + if (fz.size()) + { + labelList& tris = faceZoneFaceSets_[zoneI].tris; + labelList& quads = faceZoneFaceSets_[zoneI].quads; + labelList& polys = faceZoneFaceSets_[zoneI].polys; + + tris.setSize(fz.size()); + quads.setSize(fz.size()); + polys.setSize(fz.size()); + + label nTris = 0; + label nQuads = 0; + label nPolys = 0; + + label faceCounter = 0; + + forAll(fz, i) + { + label faceI = fz[i]; + + // Avoid counting faces on processor boundaries twice + if (faceToBeIncluded(faceI)) + { + const face& f = mesh_.faces()[faceI]; + + if (f.size() == 3) + { + tris[nTris++] = faceCounter; + } + else if (f.size() == 4) + { + quads[nQuads++] = faceCounter; + } + else + { + polys[nPolys++] = faceCounter; + } + + ++faceCounter; + } + } + + tris.setSize(nTris); + quads.setSize(nQuads); + polys.setSize(nPolys); + } + } + + forAll(faceZoneNamesAll, zoneI) + { + const word& zoneName = faceZoneNamesAll[zoneI]; + nFacePrimitives nfp; + + if (faceZoneNames_.found(zoneName)) + { + if + ( + faceZoneFaceSets_[zoneI].tris.size() + || faceZoneFaceSets_[zoneI].quads.size() || + faceZoneFaceSets_[zoneI].polys.size() + ) + { + nfp.nTris = faceZoneFaceSets_[zoneI].tris.size(); + nfp.nQuads = faceZoneFaceSets_[zoneI].quads.size(); + nfp.nPolys = faceZoneFaceSets_[zoneI].polys.size(); + } + } + + reduce(nfp.nTris, sumOp