diff --git a/applications/utilities/mesh/conversion/vtkUnstructuredToFoam/Make/options b/applications/utilities/mesh/conversion/vtkUnstructuredToFoam/Make/options index 7ce182425d..89e5059ff9 100644 --- a/applications/utilities/mesh/conversion/vtkUnstructuredToFoam/Make/options +++ b/applications/utilities/mesh/conversion/vtkUnstructuredToFoam/Make/options @@ -1,5 +1,7 @@ EXE_INC = \ + -I$(LIB_SRC)/finiteVolume/lnInclude \ -I$(LIB_SRC)/fileFormats/lnInclude EXE_LIBS = \ + -lfiniteVolume \ -lfileFormats diff --git a/applications/utilities/mesh/conversion/vtkUnstructuredToFoam/vtkUnstructuredToFoam.C b/applications/utilities/mesh/conversion/vtkUnstructuredToFoam/vtkUnstructuredToFoam.C index cdc97fab33..9f43ea0fb3 100644 --- a/applications/utilities/mesh/conversion/vtkUnstructuredToFoam/vtkUnstructuredToFoam.C +++ b/applications/utilities/mesh/conversion/vtkUnstructuredToFoam/vtkUnstructuredToFoam.C @@ -34,23 +34,84 @@ Description Convert legacy VTK file (ascii) containing an unstructured grid to an OpenFOAM mesh without boundary information. +Usage + \b vtkUnstructuredToFoam \ + + Options: + - \par -no-fields + Do not attempt to recreate volFields + Note The .vtk format does not contain any boundary information. - It is purely a description of the internal mesh. + It is purely a description of the internal mesh. This also limits the + usefulness of reconstructing the volFields. + Not extensively tested. \*---------------------------------------------------------------------------*/ #include "argList.H" #include "Time.H" -#include "polyMesh.H" +#include "fvMesh.H" #include "IFstream.H" #include "vtkUnstructuredReader.H" +#include "columnFvMesh.H" +#include "scalarIOField.H" +#include "vectorIOField.H" +#include "volFields.H" + using namespace Foam; // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // +template +void constructVolFields(fvMesh& mesh, const vtkUnstructuredReader& reader) +{ + const auto fields(reader.cellData().csorted>()); + for (const auto& field : fields) + { + Info<< "Constructing volField " << field.name() << endl; + + // field is + // - cell data followed by + // - boundary face data + + + auto tfld = GeometricField::New + ( + field.name(), + mesh, + dimless + ); + auto& fld = tfld.ref(); + fld.instance() = mesh.time().timeName(); + fld.writeOpt() = IOobject::AUTO_WRITE; + + // Fill cell values + fld.internalFieldRef().field() = + UIndirectList(field, reader.cellMap()); + + // Fill boundary values + const auto& map = reader.faceMap(); + if (map.size()) + { + for (auto& pfld : fld.boundaryFieldRef()) + { + const auto& pp = pfld.patch(); + + forAll(pfld, i) + { + const label bFacei = pp.patch().offset()+i; + pfld[i] = field[map[bFacei]]; + } + } + } + + regIOobject::store(std::move(tfld)); + } +} + int main(int argc, char *argv[]) { @@ -61,11 +122,14 @@ int main(int argc, char *argv[]) ); argList::noParallel(); + argList::addOptionCompat("no-fields", {"noFields", 2106}); argList::addArgument("vtk-file", "The input legacy ascii vtk file"); #include "setRootCase.H" #include "createTime.H" + const bool doFields = !args.found("no-fields"); + IFstream mshStream(args.get(1)); vtkUnstructuredReader reader(runTime, mshStream); @@ -96,6 +160,24 @@ int main(int argc, char *argv[]) mesh.removeFiles(); mesh.write(); + + if (doFields) + { + // Re-read mesh as fvMesh so we can have fields + Info<< "Re-reading mesh ..." << endl; + #include "createMesh.H" + + constructVolFields(mesh, reader); + constructVolFields(mesh, reader); + constructVolFields(mesh, reader); + constructVolFields(mesh, reader); + constructVolFields(mesh, reader); + + // No need to write the mesh, only fields + mesh.thisDb().write(); + } + + Info<< "End\n" << endl; return 0;