diff --git a/applications/utilities/mesh/generation/snappyHexMesh/snappyHexMeshDict b/applications/utilities/mesh/generation/snappyHexMesh/snappyHexMeshDict index 74d24954aaf0f5ba14a0f5af85945c396abd4a0a..d3aefb6445c3754e107db549ab4e97a395a8d3c9 100644 --- a/applications/utilities/mesh/generation/snappyHexMesh/snappyHexMeshDict +++ b/applications/utilities/mesh/generation/snappyHexMesh/snappyHexMeshDict @@ -396,7 +396,7 @@ meshQualityControls // Flags for optional output // 0 : only write final meshes // 1 : write intermediate meshes -// 2 : write volScalarField with cellLevel for postprocessing +// 2 : write volScalarFields with cellLevel and cell centres for postprocessing // 4 : write current intersections as .obj files debug 0; diff --git a/applications/utilities/mesh/manipulation/singleCellMesh/singleCellMesh.C b/applications/utilities/mesh/manipulation/singleCellMesh/singleCellMesh.C index e47e27461ba24212bfb1c6eb04901ff992d63d84..facacddcb0203315bd37a97ac3e803775e2baea8 100644 --- a/applications/utilities/mesh/manipulation/singleCellMesh/singleCellMesh.C +++ b/applications/utilities/mesh/manipulation/singleCellMesh/singleCellMesh.C @@ -25,25 +25,32 @@ Application singleCellMesh Description - Removes all but one cells of the mesh. Used to generate mesh and fields + Reads all fields and maps them to a mesh with all internal faces removed + (singleCellFvMesh) which gets written to region "singleCell". + + Used to generate mesh and fields that can be used for boundary-only data. Might easily result in illegal mesh though so only look at boundaries in paraview. \*---------------------------------------------------------------------------*/ - #include "argList.H" #include "fvMesh.H" #include "volFields.H" #include "Time.H" #include "ReadFields.H" #include "singleCellFvMesh.H" +#include "timeSelector.H" using namespace Foam; // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // +// Name of region to create +const string singleCellName = "singleCell"; + + template<class GeoField> void interpolateFields ( @@ -65,72 +72,115 @@ void interpolateFields int main(int argc, char *argv[]) { -# include "addOverwriteOption.H" -# include "addTimeOptions.H" + // constant, not false + timeSelector::addOptions(true, false); # include "setRootCase.H" # include "createTime.H" - // Get times list - instantList Times = runTime.times(); -# include "checkTimeOptions.H" - runTime.setTime(Times[startTime], startTime); -# include "createMesh.H" - const word oldInstance = mesh.pointsInstance(); - - const bool overwrite = args.optionFound("overwrite"); - - - // Read objects in time directory - IOobjectList objects(mesh, runTime.timeName()); - - // Read vol fields. - PtrList<volScalarField> vsFlds; - ReadFields(mesh, objects, vsFlds); - - PtrList<volVectorField> vvFlds; - ReadFields(mesh, objects, vvFlds); - - PtrList<volSphericalTensorField> vstFlds; - ReadFields(mesh, objects, vstFlds); - PtrList<volSymmTensorField> vsymtFlds; - ReadFields(mesh, objects, vsymtFlds); + instantList timeDirs = timeSelector::select0(runTime, args); - PtrList<volTensorField> vtFlds; - ReadFields(mesh, objects, vtFlds); +# include "createNamedMesh.H" - - if (!overwrite) + if (regionName == singleCellName) { - runTime++; + FatalErrorIn(args.executable()) + << "Cannot convert region " << singleCellName + << " since result would overwrite it. Please rename your region." + << exit(FatalError); } // Create the mesh - singleCellFvMesh scMesh + Info<< "Creating singleCell mesh" << nl << endl; + autoPtr<singleCellFvMesh> scMesh ( - IOobject + new singleCellFvMesh ( - mesh.name(), - mesh.polyMesh::instance(), - runTime, - IOobject::NO_READ, - IOobject::AUTO_WRITE - ), - mesh + IOobject + ( + singleCellName, + mesh.polyMesh::instance(), + runTime, + IOobject::NO_READ, + IOobject::AUTO_WRITE + ), + mesh + ) ); + // For convenience create any fv* files + if (!exists(scMesh().fvSolution::objectPath())) + { + mkDir(scMesh().fvSolution::path()); + ln("../fvSolution", scMesh().fvSolution::objectPath()); + } + if (!exists(scMesh().fvSchemes::objectPath())) + { + mkDir(scMesh().fvSolution::path()); + ln("../fvSchemes", scMesh().fvSchemes::objectPath()); + } - // Map and store the fields on the scMesh. - interpolateFields(scMesh, vsFlds); - interpolateFields(scMesh, vvFlds); - interpolateFields(scMesh, vstFlds); - interpolateFields(scMesh, vsymtFlds); - interpolateFields(scMesh, vtFlds); - - - // Write - Info<< "Writing mesh to time " << runTime.timeName() << endl; - scMesh.write(); + forAll(timeDirs, timeI) + { + runTime.setTime(timeDirs[timeI], timeI); + + Info<< nl << "Time = " << runTime.timeName() << endl; + + + // Check for new mesh + if (mesh.readUpdate() != polyMesh::UNCHANGED) + { + Info<< "Detected changed mesh. Recreating singleCell mesh." << endl; + scMesh.clear(); // remove any registered objects + scMesh.reset + ( + new singleCellFvMesh + ( + IOobject + ( + singleCellName, + mesh.polyMesh::instance(), + runTime, + IOobject::NO_READ, + IOobject::AUTO_WRITE + ), + mesh + ) + ); + } + + + // Read objects in time directory + IOobjectList objects(mesh, runTime.timeName()); + + // Read vol fields. + PtrList<volScalarField> vsFlds; + ReadFields(mesh, objects, vsFlds); + + PtrList<volVectorField> vvFlds; + ReadFields(mesh, objects, vvFlds); + + PtrList<volSphericalTensorField> vstFlds; + ReadFields(mesh, objects, vstFlds); + + PtrList<volSymmTensorField> vsymtFlds; + ReadFields(mesh, objects, vsymtFlds); + + PtrList<volTensorField> vtFlds; + ReadFields(mesh, objects, vtFlds); + + // Map and store the fields on the scMesh. + interpolateFields(scMesh(), vsFlds); + interpolateFields(scMesh(), vvFlds); + interpolateFields(scMesh(), vstFlds); + interpolateFields(scMesh(), vsymtFlds); + interpolateFields(scMesh(), vtFlds); + + + // Write + Info<< "Writing mesh to time " << runTime.timeName() << endl; + scMesh().write(); + } Info<< "End\n" << endl; diff --git a/src/OSspecific/POSIX/POSIX.C b/src/OSspecific/POSIX/POSIX.C index 7a16679511c654bd484bbdc61b499bde83b255a2..34290315c7636b19e11b67a2509c664cf3f5040f 100644 --- a/src/OSspecific/POSIX/POSIX.C +++ b/src/OSspecific/POSIX/POSIX.C @@ -864,7 +864,7 @@ bool Foam::ln(const fileName& src, const fileName& dst) return false; } - if (!exists(src)) + if (src.isAbsolute() && !exists(src)) { WarningIn("ln(const fileName&, const fileName&)") << "source " << src << " does not exist." << endl; diff --git a/src/OpenFOAM/containers/Lists/UIndirectList/UIndirectList.H b/src/OpenFOAM/containers/Lists/UIndirectList/UIndirectList.H index c8de5d15f87d3a934815c504495d0cb89bcfd1ca..33e929baccdfe64220b30295a9ce7c7cd28621c3 100644 --- a/src/OpenFOAM/containers/Lists/UIndirectList/UIndirectList.H +++ b/src/OpenFOAM/containers/Lists/UIndirectList/UIndirectList.H @@ -112,6 +112,9 @@ public: //- Assignment from UList of addressed elements inline void operator=(const UList<T>&); + //- Assignment from UIndirectList of addressed elements + inline void operator=(const UIndirectList<T>&); + //- Assignment of all entries to the given value inline void operator=(const T&); diff --git a/src/OpenFOAM/containers/Lists/UIndirectList/UIndirectListI.H b/src/OpenFOAM/containers/Lists/UIndirectList/UIndirectListI.H index 9489ef0fe5c37a650f6cf7d96a0def812e19cd2d..62276afd42d92607cff712594f12b6aa8c65ad33 100644 --- a/src/OpenFOAM/containers/Lists/UIndirectList/UIndirectListI.H +++ b/src/OpenFOAM/containers/Lists/UIndirectList/UIndirectListI.H @@ -144,6 +144,25 @@ inline void Foam::UIndirectList<T>::operator=(const UList<T>& ae) } +template<class T> +inline void Foam::UIndirectList<T>::operator=(const UIndirectList<T>& ae) +{ + if (addressing_.size() != ae.size()) + { + FatalErrorIn("UIndirectList<T>::operator=(const UIndirectList<T>&)") + << "Addressing and list of addressed elements " + "have different sizes: " + << addressing_.size() << " " << ae.size() + << abort(FatalError); + } + + forAll(addressing_, i) + { + completeList_[addressing_[i]] = ae[i]; + } +} + + template<class T> inline void Foam::UIndirectList<T>::operator=(const T& t) { diff --git a/src/mesh/autoMesh/autoHexMesh/meshRefinement/meshRefinement.C b/src/mesh/autoMesh/autoHexMesh/meshRefinement/meshRefinement.C index 059e2a9d6d3b328bb36d5c77c2a694bcb30062bf..30816931670d1957bd3e0713521d7f56c514659e 100644 --- a/src/mesh/autoMesh/autoHexMesh/meshRefinement/meshRefinement.C +++ b/src/mesh/autoMesh/autoHexMesh/meshRefinement/meshRefinement.C @@ -2200,57 +2200,83 @@ void Foam::meshRefinement::dumpRefinementLevel() const { // Note: use time().timeName(), not meshRefinement::timeName() // so as to dump the fields to 0, not to constant. - volScalarField volRefLevel - ( - IOobject + { + volScalarField volRefLevel ( - "cellLevel", - mesh_.time().timeName(), + IOobject + ( + "cellLevel", + mesh_.time().timeName(), + mesh_, + IOobject::NO_READ, + IOobject::AUTO_WRITE, + false + ), mesh_, - IOobject::NO_READ, - IOobject::AUTO_WRITE, - false - ), - mesh_, - dimensionedScalar("zero", dimless, 0), - zeroGradientFvPatchScalarField::typeName - ); + dimensionedScalar("zero", dimless, 0), + zeroGradientFvPatchScalarField::typeName + ); - const labelList& cellLevel = meshCutter_.cellLevel(); + const labelList& cellLevel = meshCutter_.cellLevel(); - forAll(volRefLevel, cellI) - { - volRefLevel[cellI] = cellLevel[cellI]; + forAll(volRefLevel, cellI) + { + volRefLevel[cellI] = cellLevel[cellI]; + } + + volRefLevel.write(); } - volRefLevel.write(); + // Dump pointLevel + { + const pointMesh& pMesh = pointMesh::New(mesh_); + pointScalarField pointRefLevel + ( + IOobject + ( + "pointLevel", + mesh_.time().timeName(), + mesh_, + IOobject::NO_READ, + IOobject::NO_WRITE, + false + ), + pMesh, + dimensionedScalar("zero", dimless, 0) + ); - const pointMesh& pMesh = pointMesh::New(mesh_); + const labelList& pointLevel = meshCutter_.pointLevel(); - pointScalarField pointRefLevel - ( - IOobject - ( - "pointLevel", - mesh_.time().timeName(), - mesh_, - IOobject::NO_READ, - IOobject::NO_WRITE, - false - ), - pMesh, - dimensionedScalar("zero", dimless, 0) - ); + forAll(pointRefLevel, pointI) + { + pointRefLevel[pointI] = pointLevel[pointI]; + } - const labelList& pointLevel = meshCutter_.pointLevel(); + pointRefLevel.write(); + } - forAll(pointRefLevel, pointI) + // Dump cell centres { - pointRefLevel[pointI] = pointLevel[pointI]; - } + for (direction i=0; i<vector::nComponents; i++) + { + volScalarField cci + ( + IOobject + ( + "cc" + word(vector::componentNames[i]), + mesh_.time().timeName(), + mesh_, + IOobject::NO_READ, + IOobject::NO_WRITE, + false + ), + mesh_.C().component(i) + ); - pointRefLevel.write(); + cci.write(); + } + } }