Commit 45c8b6ce authored by Tóth János's avatar Tóth János Committed by Janek Kozicki
Browse files

ymport: polyMesh support.

parent d3316825
Pipeline #484624313 passed with stages
in 217 minutes and 33 seconds
......@@ -289,3 +289,37 @@ Two new facets $f^{*}$ are generated from every face $f$:
There are three types of faces: `patch`, `wall` and `empty`. All types are loaded by default, the `patch` and `empty` types can be discarded using the `patchasWall` and `emptyasWall` arguments of :yref:`yade.ymport.blockMeshDict`.
Using polyMesh
===================
The `polyMesh` directory (`constant/polyMesh`) can be loaded as facets (:yref:`yade.utils.facet`) using the :ysrc:`py/ymport.py` module's :yref:`yade.ymport.polyMesh` function::
from yade import ymport
facets = ymport.polyMesh("constant/polyMesh")
O.bodies.append(facets)
The function scans the directory and loads the `points`, `faces` and `boundary` files. The files must be `FoamFiles`` with the correct header (version is `2.0`, type is `ascii`, see: :ysrc:`py/tests/ymport-files/polyMesh/points`).
It parses the files and builds the boundary mesh:
The boundary mesh consists of faces $f$ consists of vertices $v$ in a way that one face is defined by four vertices:
.. math:: f_{i} = (v_{i0}, v_{i1}, v_{i2}, v_{i3}),
:label: eq:face
where vertex $v$ is a point in a three dimensional space:
.. math:: v_{ij} = (x_{ij}, y_{ij}, z_{ij}).
:label: eq:vertex
Two new facets $f^{*}$ are generated from every face $f$:
.. math:: f_{0i}^{*} = (v_{i0}, v_{i1}, v_{i2}),
:label: eq:facets:a
.. math:: f_{1i}^{*} = (v_{i2}, v_{i3}, v_{i0}).
:label: eq:facets:b
There are three types of faces: `patch`, `wall` and `empty`. All types are loaded by default, the `patch` and `empty` types can be discarded using the `patchAsWall` and `emptyAsWall` arguments of :yref:`yade.ymport.polyMesh`.
Note: The `polyMesh` is typically more refined than `blockMeshDict`.
......@@ -88,6 +88,11 @@ ADD_LIBRARY(_customConverters SHARED "${CMAKE_CURRENT_SOURCE_DIR}/wrapper/custom
SET_TARGET_PROPERTIES(_customConverters PROPERTIES PREFIX "")
INSTALL(TARGETS _customConverters DESTINATION "${YADE_PY_PATH}/yade/")
FILE(GLOB_RECURSE YMPORT_CPP_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/ymport/*.cpp)
ADD_LIBRARY(_ymport SHARED "${CMAKE_CURRENT_SOURCE_DIR}/_ymport.cpp" ${YMPORT_CPP_SRCS})
SET_TARGET_PROPERTIES(_ymport PROPERTIES PREFIX "")
INSTALL(TARGETS _ymport DESTINATION "${YADE_PY_PATH}/yade/")
IF(ENABLE_LOGGER AND CMAKE_UNITY_BUILD)
MESSAGE(STATUS "${Esc}[93mENABLE_LOGGER needs a workaround with CMAKE_UNITY_BUILD, adding .cpp files containing CREATE_CPP_LOCAL_LOGGER to SKIP_UNITY_BUILD_INCLUSION.${Esc}[0m")
SET(FIND_CPP_LOGGER_ARGS -rZl CREATE_CPP_LOCAL_LOGGER ${CMAKE_SOURCE_DIR}/py --include=*.cpp)
......
/*************************************************************************
* 2022 Tóth János *
* *
* This program is free software; it is licensed under the terms of the *
* GNU General Public License v2 or later. See file LICENSE for details. *
*************************************************************************/
// C++ backend of the ymport module.
#include <boost/python.hpp>
#include <lib/base/AliasNamespaces.hpp>
#include <lib/base/LoggingUtils.hpp>
#include <lib/pyutil/doc_opts.hpp>
#include <memory>
#include "ymport/foamfile/PolyMesh.hpp"
CREATE_CPP_LOCAL_LOGGER("_ymport.cpp");
namespace yade {
namespace ymport {
namespace foamfile {
py::list readPolyMesh(const std::string& directoryPath, bool patchAsWall, bool emptyAsWall)
{
std::unique_ptr<PolyMesh> polyMesh = std::make_unique<PolyMesh>(directoryPath, patchAsWall, emptyAsWall);
return polyMesh->facetCoords();
}
} // namespace foamfile
} // namespace ymport
} // namespace yade
BOOST_PYTHON_MODULE(_ymport)
try {
using namespace yade::ymport;
namespace py = ::boost::python;
YADE_SET_DOCSTRING_OPTS;
py::def("readPolyMesh", foamfile::readPolyMesh, R"""(
"""C++ backend of :yref:`yade.ymport.polyMesh`.
:param str path: directory path. Typical value is: "constant/polyMesh".
:param bool patchAsWall: load "patch"-es as walls.
:param bool emptyAsWall: load "empty"-es as walls.
:param \*\*kw: (unused keyword arguments) is passed to :yref:`yade.utils.facet`
:returns: list of facets.
)""");
} catch (...) {
LOG_FATAL("Importing this module caused an exception and this module is in an inconsistent state now.");
PyErr_Print();
PyErr_SetString(PyExc_SystemError, __FILE__);
boost::python::handle_exception();
throw;
}
......@@ -18,7 +18,7 @@ allTests = [
, 'testMinieigenHP'
, 'testMath'
, 'enumTest'
, 'ymport-blockMeshDict'
, 'ymport-foamfiles'
#, 'testColliderByGiulia' # to investigate later maybe, my impression is that due to issue #7 the results are randomly different in that ill-posed periodic problem
]
# yapf: enable
......
# encoding: utf-8
# 2021, János Tóth <toth-janos@outlook.com>
import unittest
from pathlib import Path
from yade import ymport
class TestYmportBlockMeshDict(unittest.TestCase):
def testLoadFile(self):
f = str(Path(__file__).parent) + "/ymport-files/blockMeshDict"
faces = ymport.blockMeshDict(f)
self.assertTrue(len(faces) == 40)
......@@ -4,10 +4,24 @@
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Version: 7
\\/ 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 <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
FoamFile
{
version 2.0; // comment
version 2.0; // test comment
format ascii;
class dictionary;
object blockMeshDict;
......@@ -18,7 +32,7 @@ convertToMeters 0.001;
vertices
(
(-20.6 0 -10) // comment
(-20.6 0 -10) // test comment
(-20.6 25.4 -10)
(0 -25.4 -10)
(0 0 -10)
......
/*--------------------------------*- C++ -*----------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Version: 7
\\/ 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 <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
FoamFile
{
version 2.0;
format ascii;
class polyBoundaryMesh;
location "constant/polyMesh";
object boundary;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
5
(
inlet
{
type patch;
nFaces 4;
startFace 80;
}
outlet
{
type patch;
nFaces 8;
startFace 84;
}
upperWall
{
type wall;
inGroups List<word> 1(wall);
nFaces 12;
startFace 92;
}
lowerWall
{
type wall;
inGroups List<word> 1(wall);
nFaces 16;
startFace 104;
}
frontAndBack
{
type wall;
inGroups List<word> 1(wall);
nFaces 40;
startFace 120;
}
)
// ************************************************************************* //
/*--------------------------------*- C++ -*----------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Version: 7
\\/ 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 <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
FoamFile
{
version 2.0;
format ascii;
class faceList;
location "constant/polyMesh";
object faces;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
160
(
4(1 4 13 10)
4(3 12 13 4)
4(9 10 13 12)
4(4 13 14 5)
4(10 11 14 13)
4(2 5 14 11)
4(4 7 16 13)
4(12 13 16 15)
4(13 14 17 16)
4(5 8 17 14)
4(10 13 22 19)
4(12 21 22 13)
4(13 22 23 14)
4(11 14 23 20)
4(13 16 25 22)
4(14 17 26 23)
4(28 31 39 36)
4(30 38 39 31)
4(35 36 39 38)
4(31 39 40 32)
4(36 37 40 39)
4(29 32 40 37)
4(31 33 41 39)
4(38 39 41 11)
4(2 11 41 33)
4(39 40 42 41)
4(33 41 42 34)
4(32 34 42 40)
4(36 39 47 44)
4(38 46 47 39)
4(39 47 48 40)
4(37 40 48 45)
4(39 41 49 47)
4(11 20 49 41)
4(41 49 50 42)
4(40 42 50 48)
4(33 51 55 41)
4(5 14 55 51)
4(11 41 55 14)
4(51 55 56 52)
4(41 42 56 55)
4(34 52 56 42)
4(51 53 57 55)
4(14 55 57 17)
4(55 56 58 57)
4(52 54 58 56)
4(41 55 59 49)
4(14 23 59 55)
4(55 59 60 56)
4(42 56 60 50)
4(55 57 61 59)
4(56 58 62 60)
4(63 65 71 69)
4(32 40 71 65)
4(37 69 71 40)
4(65 71 72 66)
4(69 70 72 71)
4(65 67 73 71)
4(40 71 73 42)
4(34 42 73 67)
4(71 72 74 73)
4(67 73 74 68)
4(69 71 77 75)
4(40 48 77 71)
4(71 77 78 72)
4(71 73 79 77)
4(42 50 79 73)
4(73 79 80 74)
4(67 81 85 73)
4(52 56 85 81)
4(42 73 85 56)
4(81 85 86 82)
4(73 74 86 85)
4(81 83 87 85)
4(56 85 87 58)
4(85 86 88 87)
4(73 85 89 79)
4(56 60 89 85)
4(85 89 90 86)
4(85 87 91 89)
4(0 9 12 3)
4(3 12 15 6)
4(9 18 21 12)
4(12 21 24 15)
4(64 66 72 70)
4(66 68 74 72)
4(70 72 78 76)
4(72 74 80 78)
4(68 82 86 74)
4(82 84 88 86)
4(74 86 90 80)
4(86 88 92 90)
4(6 15 16 7)
4(15 24 25 16)
4(7 16 17 8)
4(16 25 26 17)
4(8 17 57 53)
4(17 26 61 57)
4(53 57 58 54)
4(57 61 62 58)
4(54 58 87 83)
4(58 62 91 87)
4(83 87 88 84)
4(87 91 92 88)
4(0 1 10 9)
4(9 10 19 18)
4(1 2 11 10)
4(10 11 20 19)
4(27 35 38 30)
4(30 38 11 2)
4(35 43 46 38)
4(38 46 20 11)
4(27 28 36 35)
4(35 36 44 43)
4(28 29 37 36)
4(36 37 45 44)
4(29 63 69 37)
4(37 69 75 45)
4(63 64 70 69)
4(69 70 76 75)
4(0 3 4 1)
4(3 6 7 4)
4(1 4 5 2)
4(4 7 8 5)
4(27 30 31 28)
4(30 2 33 31)
4(28 31 32 29)
4(31 33 34 32)
4(2 5 51 33)
4(5 8 53 51)
4(33 51 52 34)
4(51 53 54 52)
4(29 32 65 63)
4(32 34 67 65)
4(63 65 66 64)
4(65 67 68 66)
4(34 52 81 67)
4(52 54 83 81)
4(67 81 82 68)
4(81 83 84 82)
4(18 19 22 21)
4(21 22 25 24)
4(19 20 23 22)
4(22 23 26 25)
4(43 44 47 46)
4(46 47 49 20)
4(44 45 48 47)
4(47 48 50 49)
4(20 49 59 23)
4(23 59 61 26)
4(49 50 60 59)
4(59 60 62 61)
4(45 75 77 48)
4(48 77 79 50)
4(75 76 78 77)
4(77 78 80 79)
4(50 79 89 60)
4(60 89 91 62)
4(79 80 90 89)
4(89 90 92 91)
)
// ************************************************************************* //
/*--------------------------------*- C++ -*----------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Version: 7
\\/ 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 <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
FoamFile
{
version 2.0;
format ascii;
class labelList;
note "nPoints: 93 nCells: 40 nFaces: 160 nInternalFaces: 80";
location "constant/polyMesh";
object neighbour;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
80(
1 2 4 3 5 16 3 6 7 18 5 6 7 20 7 22 9 10 12 11 13 24 11 14 16 15 17 26 13 14 15 28 15 20 21 30 17 18 20 19 21 32 19 22 23 34 21 22 23 36 23 38 25 26 28 27 29 27 30 32 31 33 29 30 31 31 36 37 33 34 36 35 37 35 38 39 37 38 39 39)
// ************************************************************************* //
/*--------------------------------*- C++ -*----------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Version: 7
\\/ 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 <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
FoamFile
{
version 2.0;
format ascii;
class labelList;
note "nPoints: 93 nCells: 40 nFaces: 160 nInternalFaces: 80";
location "constant/polyMesh";
object owner;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
160(
0 0 0 1 1 1 2 2 3 3 4 4 5 5 6 7 8 8 8 9 9 9 10 10 10 11 11 11 12 12 13 13 14 14 15 15 16 16 16 17 17 17 18 18 19 19 20 20 21 21 22 23 24 24 24 25 25 26 26 26 27 27 28 28 29 30 30 31 32 32 32 33 33 34 34 35 36 36 37 38 0 2 4 6 25 27 29 31 33 35 37 39 2 6 3 7 18 22 19 23 34 38 35 39 0 4 1 5 8 10 12 14 8 12 9 13 24 28 25 29 0 2 1 3 8 10 9 11 16 18 17 19 24 26 25 27 32 34 33 35 4 6 5 7 12 14 13 15 20 22 21 23 28 30 29 31 36 38 37 39)
// ************************************************************************* //
/*--------------------------------*- C++ -*----------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Version: 7
\\/ 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 <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
FoamFile
{
version 2.0;
format ascii;
class vectorField;
location "constant/polyMesh";
object points;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
93
(
(-0.0206 0 -0.01)
(-0.0103 0 -0.01)
(0 0 -0.01)
(-0.0206 0.0127 -0.01)
(-0.0103 0.0127 -0.01)
(0 0.0127 -0.01)
(-0.0206 0.0254 -0.01)
(-0.0103 0.0254 -0.01)
(0 0.0254 -0.01)
(-0.0206 0 0)
(-0.0103 0 0)
(0 0 0)
(-0.0206 0.0127 0)
(-0.0103 0.0127 0)
(0 0.0127 0)
(-0.0206 0.0254 0)
(-0.0103 0.0254 0)
(0 0.0254 0)
(-0.0206 0 0.01)
(-0.0103 0 0.01)
(0 0 0.01)
(-0.0206 0.0127 0.01)
(-0.0103 0.0127 0.01)
(0 0.0127 0.01)
(-0.0206 0.0254 0.01)
(-0.0103 0.0254 0.01)
(0 0.0254 0.01)
(0 -0.0254 -0.01)
(0.103 -0.0254 -0.01)
(0.206 -0.0254 -0.01)
(0 -0.0127 -0.01)
(0.103 -0.0127 -0.01)
(0.206 -0.0127 -0.01)
(0.103 0 -0.01)
(0.206 0 -0.01)
(0 -0.0254 0)
(0.103 -0.0254 0)
(0.206 -0.0254 0)
(0 -0.0127 0)
(0.103 -0.0127 0)
(0.206 -0.0127 0)
(0.103 0 0)
(0.206 0 0)
(0 -0.0254 0.01)
(0.103 -0.0254 0.01)
(0.206 -0.0254 0.01)
(0 -0.0127 0.01)
(0.103 -0.0127 0.01)
(0.206 -0.0127 0.01)
(0.103 0 0.01)
(0.206 0 0.01)
(0.103 0.0127 -0.01)
(0.206 0.0127 -0.01)
(0.103 0.0254 -0.01)
(0.206 0.0254 -0.01)
(0.103 0.0127 0)
(0.206 0.0127 0)
(0.103 0.0254 0)
(0.206 0.0254 0)
(0.103 0.0127 0.01)
(0.206 0.0127 0.01)
(0.103 0.0254 0.01)
(0.206 0.0254 0.01)
(0.248 -0.021 -0.01)
(0.29 -0.0166 -0.01)
(0.248 -0.0105 -0.01)
(0.29 -0.0083 -0.01)
(0.248 0 -0.01)
(0.29 0 -0.01)
(0.248 -0.021 0)
(0.29 -0.0166 0)
(0.248 -0.0105 0)
(0.29 -0.0083 0)
(0.248 0 0)
(0.29 0 0)
(0.248 -0.021 0.01)
(0.29 -0.0166 0.01)
(0.248 -0.0105 0.01)
(0.29 -0.0083 0.01)
(0.248 0 0.01)
(0.29 0 0.01)
(0.248 0.0105 -0.01)