From e05825d634e30818d89c5ca1485f5bde8bbb07f7 Mon Sep 17 00:00:00 2001 From: graham Date: Thu, 9 Oct 2008 19:29:47 +0100 Subject: [PATCH] Changed all reading to IOobjects and using the time controls for run control. Printing the tet vertex locations before calculating the dual to see assertion failure cause. --- .../mesh/generation/CV3DMesher/CV3D.C | 83 ++++++++++++++----- .../mesh/generation/CV3DMesher/CV3D.H | 21 +++-- .../mesh/generation/CV3DMesher/CV3DIO.C | 30 +++++-- .../mesh/generation/CV3DMesher/CV3DMesher.C | 36 ++++---- .../mesh/generation/CV3DMesher/calcDualMesh.C | 2 - .../mesh/generation/CV3DMesher/controls.C | 2 +- .../mesh/generation/CV3DMesher/tolerances.C | 2 +- 7 files changed, 125 insertions(+), 51 deletions(-) diff --git a/applications/utilities/mesh/generation/CV3DMesher/CV3D.C b/applications/utilities/mesh/generation/CV3DMesher/CV3D.C index 2263d46fce..03341ca422 100644 --- a/applications/utilities/mesh/generation/CV3DMesher/CV3D.C +++ b/applications/utilities/mesh/generation/CV3DMesher/CV3D.C @@ -26,7 +26,6 @@ License #include "CV3D.H" #include "Random.H" -#include "IFstream.H" #include "uint.H" #include "ulong.H" @@ -49,7 +48,7 @@ void Foam::CV3D::insertBoundingBox() void Foam::CV3D::reinsertPoints(const pointField& points) { - Info<< "Reinserting points after motion. "; + Info<< nl << "Reinserting points after motion. "; startOfInternalPoints_ = number_of_vertices(); label nVert = startOfInternalPoints_; @@ -70,14 +69,43 @@ void Foam::CV3D::reinsertPoints(const pointField& points) Foam::CV3D::CV3D ( - const dictionary& controlDict, + const Time& runTime, const querySurface& qSurf ) : HTriangulation(), qSurf_(qSurf), - controls_(controlDict), - tols_(controlDict, controls_.minCellSize, qSurf.bb()), + runTime_(runTime), + controls_ + ( + IOdictionary + ( + IOobject + ( + "CV3DMesherDict", + runTime_.system(), + runTime_, + IOobject::MUST_READ, + IOobject::NO_WRITE + ) + ) + ), + tols_ + ( + IOdictionary + ( + IOobject + ( + "CV3DMesherDict", + runTime_.system(), + runTime_, + IOobject::MUST_READ, + IOobject::NO_WRITE + ) + ), + controls_.minCellSize, + qSurf.bb() + ), startOfInternalPoints_(0), startOfSurfacePointPairs_(0), featureConstrainingVertices_(0) @@ -137,18 +165,19 @@ void Foam::CV3D::insertPoints void Foam::CV3D::insertPoints(const fileName& pointFileName) { - IFstream pointsFile(pointFileName); + pointIOField points + ( + IOobject + ( + pointFileName.name(), + pointFileName.path(), + runTime_, + IOobject::MUST_READ, + IOobject::NO_WRITE + ) + ); - if (pointsFile.good()) - { - insertPoints(pointField(pointsFile), 0.5*controls_.minCellSize2); - } - else - { - FatalErrorIn("insertInitialPoints") - << "Could not open pointsFile " << pointFileName - << exit(FatalError); - } + insertPoints(points, 0.5*controls_.minCellSize2); } @@ -262,7 +291,15 @@ void Foam::CV3D::relaxPoints(const scalar relaxation) ) { cit->cellIndex() = dualVerti; + + Info<< nl << topoint(cit->vertex(0)->point()) + << nl << topoint(cit->vertex(1)->point()) + << nl << topoint(cit->vertex(2)->point()) + << nl << topoint(cit->vertex(3)->point()) + << endl; + dualVertices[dualVerti] = topoint(dual(cit)); + dualVerti++; } else @@ -369,6 +406,12 @@ void Foam::CV3D::relaxPoints(const scalar relaxation) startOfInternalPoints_ ); + // Write the mesh before clearing it + if (runTime_.outputTime()) + { + writeMesh(true); + } + // Remove the entire triangulation this->clear(); @@ -426,18 +469,18 @@ void Foam::CV3D::removeSurfacePointPairs() } -void Foam::CV3D::write() const +void Foam::CV3D::write() { if (controls_.writeFinalTriangulation) { writePoints("allPoints.obj", false); writePoints("points.obj", true); -// writeFaces("allFaces.obj", false); -// writeFaces("faces.obj", true); writeTriangles("allTriangles.obj", false); writeTriangles("triangles.obj", true); -// writeMesh(); + writeDual("dualMesh.obj"); } + + writeMesh(); } // ************************************************************************* // diff --git a/applications/utilities/mesh/generation/CV3DMesher/CV3D.H b/applications/utilities/mesh/generation/CV3DMesher/CV3D.H index 784cf8db92..c2a837cb93 100644 --- a/applications/utilities/mesh/generation/CV3DMesher/CV3D.H +++ b/applications/utilities/mesh/generation/CV3DMesher/CV3D.H @@ -49,7 +49,9 @@ SourceFiles #include "CGALTriangulation3Ddefs.H" #include "querySurface.H" -#include "dictionary.H" +#include "IOdictionary.H" +#include "pointIOField.H" +#include "argList.H" #include "DynamicList.H" #include "Switch.H" #include "Time.H" @@ -132,7 +134,7 @@ public: Switch randomiseInitialGrid; scalar randomPerturbation; - controls(const dictionary& controlDict); + controls(const IOdictionary& controlDict); }; class tolerances @@ -178,7 +180,7 @@ public: tolerances ( - const dictionary& controlDict, + const IOdictionary& controlDict, scalar minCellSize, const boundBox& ); @@ -191,6 +193,9 @@ private: //- The surface to mesh const querySurface& qSurf_; + //- The time registry of the application + const Time& runTime_; + //- Meshing controls controls controls_; @@ -330,7 +335,11 @@ public: // Constructors //- Construct for given surface - CV3D(const dictionary& controlDict, const querySurface& qSurf); + CV3D + ( + const Time& runTime, + const querySurface& qSurf + ); // Destructor @@ -415,9 +424,9 @@ public: void writeDual(const fileName& fName) const; //- Write polyMesh - void writeMesh(const Time& runTime); + void writeMesh(bool writeToTimestep = false); - void write() const; + void write(); }; diff --git a/applications/utilities/mesh/generation/CV3DMesher/CV3DIO.C b/applications/utilities/mesh/generation/CV3DMesher/CV3DIO.C index 309011284e..28c0f55755 100644 --- a/applications/utilities/mesh/generation/CV3DMesher/CV3DIO.C +++ b/applications/utilities/mesh/generation/CV3DMesher/CV3DIO.C @@ -187,10 +187,8 @@ void Foam::CV3D::writeTriangles(const fileName& fName, bool internalOnly) const } } -void Foam::CV3D::writeMesh(const Time& runTime) +void Foam::CV3D::writeMesh(bool writeToTimestep) { - Info<< nl << "Writing polyMesh." << endl; - pointField points(0); faceList faces(0); labelList owner(0); @@ -210,15 +208,35 @@ void Foam::CV3D::writeMesh(const Time& runTime) patchStarts ); + IOobject io ( Foam::polyMesh::defaultRegion, - runTime.constant(), - runTime, + runTime_.constant(), + runTime_, IOobject::NO_READ, IOobject::AUTO_WRITE ); + if (writeToTimestep) + { + Info<< nl << "Writing polyMesh to time directory " + << runTime_.timeName() << endl; + + io = IOobject + ( + Foam::polyMesh::defaultRegion, + runTime_.path()/runTime_.timeName(), + runTime_, + IOobject::NO_READ, + IOobject::AUTO_WRITE + ); + } + else + { + Info<< nl << "Writing polyMesh to constant." << endl; + } + polyMesh pMesh ( io, @@ -246,7 +264,7 @@ void Foam::CV3D::writeMesh(const Time& runTime) if (!pMesh.write()) { - FatalErrorIn("CV3D::writeMesh(const Time& runTime)") + FatalErrorIn("CV3D::writeMesh()") << "Failed writing polyMesh." << exit(FatalError); } diff --git a/applications/utilities/mesh/generation/CV3DMesher/CV3DMesher.C b/applications/utilities/mesh/generation/CV3DMesher/CV3DMesher.C index cefaa6104e..60a60bb545 100644 --- a/applications/utilities/mesh/generation/CV3DMesher/CV3DMesher.C +++ b/applications/utilities/mesh/generation/CV3DMesher/CV3DMesher.C @@ -49,22 +49,24 @@ int main(int argc, char *argv[]) # include "setRootCase.H" # include "createTime.H" - // Read control dictionary - // ~~~~~~~~~~~~~~~~~~~~~~~ - - dictionary controlDict + IOdictionary CV3DMesherDict ( - IFstream(runTime.system()/args.executable() + "Dict")() + IOobject + ( + "CV3DMesherDict", + runTime.system(), + runTime, + IOobject::MUST_READ, + IOobject::NO_WRITE + ) ); - label nIterations(readLabel(controlDict.lookup("nIterations"))); - // Read the surface to conform to // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ querySurface surf ( args.args()[1], - readScalar(controlDict.lookup("includedAngle")) + readScalar(CV3DMesherDict.lookup("includedAngle")) ); Info<< nl @@ -74,7 +76,7 @@ int main(int argc, char *argv[]) // Read and triangulation // ~~~~~~~~~~~~~~~~~~~~~~ - CV3D mesh(controlDict, surf); + CV3D mesh(runTime, surf); if (args.options().found("pointsFile")) { @@ -93,6 +95,12 @@ int main(int argc, char *argv[]) scalar relaxation = mesh.meshingControls().relaxationFactorStart; + label nIterations = label + ( + (runTime.endTime().value() - runTime.startTime().value()) + /runTime.deltaT().value() + ); + scalar relaxationDelta = ( mesh.meshingControls().relaxationFactorStart @@ -100,10 +108,12 @@ int main(int argc, char *argv[]) ) /max(nIterations, 1); - for (label iter = 0; iter < nIterations; iter++) + while (runTime.run()) { + runTime++; + Info<< nl - << "Relaxation iteration " << iter << nl + << "Relaxation iteration " << runTime.timeIndex() << nl << "~~~~~~~~~~~~~~~~~~~~~~~~" << endl; Info<< "relaxation = " << relaxation << endl; @@ -119,10 +129,6 @@ int main(int argc, char *argv[]) mesh.write(); - mesh.writeDual("dualMesh.obj"); - - mesh.writeMesh(runTime); - Info << nl << "End\n" << endl; return 0; diff --git a/applications/utilities/mesh/generation/CV3DMesher/calcDualMesh.C b/applications/utilities/mesh/generation/CV3DMesher/calcDualMesh.C index 0f694eddaa..035e6de674 100644 --- a/applications/utilities/mesh/generation/CV3DMesher/calcDualMesh.C +++ b/applications/utilities/mesh/generation/CV3DMesher/calcDualMesh.C @@ -39,8 +39,6 @@ void Foam::CV3D::calcDualMesh labelList& patchStarts ) { - Info << nl << "Calculating Voronoi diagram." << endl; - // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ dual points ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ points.setSize(number_of_cells()); diff --git a/applications/utilities/mesh/generation/CV3DMesher/controls.C b/applications/utilities/mesh/generation/CV3DMesher/controls.C index 41bab6789c..6675af0dfe 100644 --- a/applications/utilities/mesh/generation/CV3DMesher/controls.C +++ b/applications/utilities/mesh/generation/CV3DMesher/controls.C @@ -28,7 +28,7 @@ License // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // -Foam::CV3D::controls::controls(const dictionary& controlDict) +Foam::CV3D::controls::controls(const IOdictionary& controlDict) : relaxationFactorStart ( diff --git a/applications/utilities/mesh/generation/CV3DMesher/tolerances.C b/applications/utilities/mesh/generation/CV3DMesher/tolerances.C index 1127024ce3..21a11b7afe 100644 --- a/applications/utilities/mesh/generation/CV3DMesher/tolerances.C +++ b/applications/utilities/mesh/generation/CV3DMesher/tolerances.C @@ -30,7 +30,7 @@ License Foam::CV3D::tolerances::tolerances ( - const dictionary& controlDict, + const IOdictionary& controlDict, const scalar minCellSize, const boundBox& bb )