1 // Copyright (C) 2009-2015 OPEN CASCADE
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 // File : IntersectorCU3D.txx
20 // Created : Thu Dec 17 14:17:49 2009
21 // Author : Edward AGAPOV (eap)
23 #ifndef __IntersectorCU3D_TXX__
24 #define __IntersectorCU3D_TXX__
26 #include "IntersectorCU3D.hxx"
27 #include "IntersectorCU.txx"
28 #include "SplitterTetra.txx"
30 #define IntersectorCU3D_TEMPLATE template<class MyCMeshType, class MyUMeshType, class MyMatrix>
31 #define INTERSECTOR_CU3D IntersectorCU3D<MyCMeshType,MyUMeshType,MyMatrix >
32 #define _INTERSECTOR_CU IntersectorCU <MyCMeshType,MyUMeshType,MyMatrix,IntersectorCU3D<MyCMeshType,MyUMeshType,MyMatrix> >
34 namespace INTERP_KERNEL
36 //================================================================================
38 * \brief Unstructured hexahedral mesh derived from cartesian 3D mesh.
39 * Mesh contains one HEXA8 element
41 //================================================================================
43 class _Cartesian3D2UnstructHexMesh
46 static const int MY_SPACEDIM=3;
47 static const int MY_MESHDIM=3;
48 typedef int MyConnType;
49 static const NumberingPolicy My_numPol=ALL_C_MODE;
51 _Cartesian3D2UnstructHexMesh(const double * coords[3]): _coordsC(coords) {}
52 void setHexa(int I, int J, int K) // indices in C mode
54 double* pCoord = _coordsU;
55 for ( int k = K; k < K+2; ++k )
56 for ( int j = J; j < J+2; ++j )
57 for ( int i = I; i < I+2; ++i )
59 *pCoord++ = _coordsC[0][i];
60 *pCoord++ = _coordsC[1][j];
61 *pCoord++ = _coordsC[2][k];
64 const int *getConnectivityPtr() const
66 static int conn[] = { 1,0,2,3,5,4,6,7 };
69 const int *getConnectivityIndexPtr() const
71 static int conInd[] = { 0,8 };
74 void getBoundingBox(double *boundingBox) const
76 boundingBox[BoundingBox::XMIN] = _coordsU[0];
77 boundingBox[BoundingBox::XMAX] = _coordsU[0+1*MY_SPACEDIM];
78 boundingBox[BoundingBox::YMIN] = _coordsU[1];
79 boundingBox[BoundingBox::YMAX] = _coordsU[1+2*MY_SPACEDIM];
80 boundingBox[BoundingBox::ZMIN] = _coordsU[2];
81 boundingBox[BoundingBox::ZMAX] = _coordsU[2+4*MY_SPACEDIM];
83 NormalizedCellType getTypeOfElement(int eltId) const { return NORM_HEXA8; }
84 unsigned char getNumberOfNodesOfElement(int eltId) const { return 8; }
85 unsigned long getNumberOfElements() const { return 1; }
86 unsigned long getNumberOfNodes() const { return 8; }
87 const double *getCoordinatesPtr() const { return _coordsU; }
88 void releaseTempArrays() {}
90 const double** _coordsC;
94 //================================================================================
96 * \brief intersector of the unstructured mesh and the cartesian mesh in 3D
98 //================================================================================
100 IntersectorCU3D_TEMPLATE
101 INTERSECTOR_CU3D::IntersectorCU3D(const MyCMeshType& meshS,
102 const MyUMeshType& meshT,
103 SplittingPolicy splitting_policy):
104 _INTERSECTOR_CU( meshS, meshT )
106 if ( MyCMeshType::MY_SPACEDIM != 3 || MyCMeshType::MY_MESHDIM != 3 ||
107 MyUMeshType::MY_SPACEDIM != 3 || MyUMeshType::MY_MESHDIM != 3 )
108 throw Exception("IntersectorCU3D(): Invalid mesh dimension, it must be 3");
110 _uHexMesh = new _Cartesian3D2UnstructHexMesh( _INTERSECTOR_CU::_coordsC );
111 _split = new TSplitter( meshT, *_uHexMesh, splitting_policy );
114 //================================================================================
118 //================================================================================
120 IntersectorCU3D_TEMPLATE
121 INTERSECTOR_CU3D::~IntersectorCU3D()
123 delete _uHexMesh; _uHexMesh=0;
124 delete _split; _split=0;
127 //================================================================================
129 * \brief Calculate volume of intersection of an unstructured cell and a cartesian one.
130 * The cartesian cell is given by its [i,j,k] indices
132 //================================================================================
134 IntersectorCU3D_TEMPLATE
135 double INTERSECTOR_CU3D::intersectGeometry(UConnType icellT,
136 const std::vector<CConnType>& icellS)
138 // split an unstructured cell into tetra
139 std::vector< TTetra* > tetra;
141 _INTERSECTOR_CU::_connIndexU[icellT+1] - _INTERSECTOR_CU::_connIndexU[icellT];
142 _split->releaseArrays();
143 _split->splitTargetCell( icellT, nb_nodes, tetra);
145 // intersect a cartesian 3d cell with tetra
146 _uHexMesh->setHexa( _FMIC(icellS[0]),_FMIC(icellS[1]),_FMIC(icellS[2])); // set cell at i,j,k
148 for ( unsigned int t = 0; t < tetra.size(); ++t )
150 res += tetra[t]->intersectSourceCell( 0 );