commit c4bb8c516deceb290978d0f2cb2997085c4000d9 Author: changfly Date: Sat Sep 16 00:55:00 2017 +0900 Foam utility to check particle positions are in the domain diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..6f4ea81 --- /dev/null +++ b/.gitignore @@ -0,0 +1,72 @@ +# git-ls-files --others --exclude-from=.git/info/exclude +# Lines that start with '#' are comments. + +# Editor and misc backup files - anywhere +*~ +.*~ +*.bak +*.bak[0-9][0-9] +\#*\# + +# File-browser settings - anywhere +.directory + +# CVS recovered versions - anywhere +.#* + +# Objects and archives - anywhere +*.[oa] +*.la +*.so + +# Derived files +lex.yy.c + +# Corefiles +core + +# Dependency files - anywhere +*.dep + +# lnInclude (symlink) directories - anywhere +lnInclude + +# Build directories - anywhere +linux*Clang*/ +linux*Gcc*/ +linux*Icc*/ +solaris*Gcc*/ +SunOS*Gcc*/ +platforms/ + +# Generated files in the main directory (e.g. ReleaseNotes-?.?.html) +# and in the doc directory +/*.html +/doc/*.html + +# Source packages - anywhere +*.tar.bz2 +*.tar.gz +*.tar +*.tgz +*.gtgz + +# Ignore the persistent .build tag in the main directory +/.build + +# Ignore .timeStamp in the main directory +/.timeStamp + +# Ignore .tags in the main directory +/.tags + +# Ignore project files in the main directory +/.cproject +/.project +/.dir-locals.el + +# Ignore the test directory +/tutorialsTest + +.*.swp +*.gz diff --git a/Make/files b/Make/files new file mode 100644 index 0000000..b2e858b --- /dev/null +++ b/Make/files @@ -0,0 +1,3 @@ +checkParticles.C + +EXE = $(FOAM_USER_APPBIN)/checkParticles diff --git a/Make/options b/Make/options new file mode 100644 index 0000000..d27c95d --- /dev/null +++ b/Make/options @@ -0,0 +1,7 @@ +EXE_INC = \ + -I$(LIB_SRC)/finiteVolume/lnInclude \ + -I$(LIB_SRC)/meshTools/lnInclude + +EXE_LIBS = \ + -lfiniteVolume \ + -lmeshTools diff --git a/checkParticles.C b/checkParticles.C new file mode 100644 index 0000000..82ed8df --- /dev/null +++ b/checkParticles.C @@ -0,0 +1,150 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2011-2016 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 . + +Application + checkParticles + +Description + Utility for checking position of manually injected particles + +\*---------------------------------------------------------------------------*/ + +#include "fvCFD.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +int main(int argc, char *argv[]) +{ + argList::addOption + ( + "cloud", + "cloudPrefix", + "cloudPrefix := { kinematic, reacting, ... }, default is reacting" + ); + + #include "setRootCase.H" + #include "createTime.H" + #include "createMesh.H" + + const word modExt ("valid"); + + word cloudKind ("reacting"); + args.optionReadIfPresent("cloud", cloudKind); + + IOdictionary cloudProp + ( + IOobject + ( + cloudKind + "CloudProperties", + runTime.constant(), + mesh, + IOobject::MUST_READ_IF_MODIFIED, + IOobject::NO_WRITE + ) + ); + + dictionary injDict (cloudProp.subDict("subModels").subDict("injectionModels")); + + for (dictionary::iterator i = injDict.begin(); i != injDict.end(); ++i) + { + Info << "Checking " << (*i).name().name() << endl; + + Info << *i; + + word injectionType ((*i).dict().lookup("type")); + + if (injectionType == "manualInjection") + { + word posFileName ((*i).dict().lookup("positionsFile")); + + vectorIOField positions_ + ( + IOobject + ( + posFileName, + runTime.constant(), + mesh, + IOobject::MUST_READ, + IOobject::NO_WRITE + ) + ); + + vectorIOField oldPositions + ( + IOobject + ( + posFileName + ".old", + runTime.constant(), + mesh, + IOobject::NO_READ, + IOobject::NO_WRITE + ), + positions_ + ); + + // Info << vectorIOField::subField(positions_, 10); + + labelList validIndices (positions_.size(), -1); + label validCount = 0; + + forAll (positions_, pI) + { + label celli, tfi, tpi; + point pos (positions_[pI]); + mesh.findCellFacePt (pos, celli, tfi, tpi); + + if (celli < 0) + { + Info << "Particle " << pI + << " at " << pos << " not in the domain" + << endl; + } + else + { + validIndices[validCount] = pI; + validCount++; + } + } + + Info << (positions_.size() - validCount) << " particles are in bad position" << endl; + + if (validCount < positions_.size()) + { + Info << "Update positions file " << posFileName << endl; + + vectorField newPositions_ (positions_, labelList::subList(validIndices, validCount)); + positions_.transfer(newPositions_); + + positions_.write(); + oldPositions.write(); + } + } + } + + Info<< "End\n" << endl; + + return 0; +} + + +// ************************************************************************* //