template<class MyMeshType, class MyMatrix>
void Intersector3D<MyMeshType,MyMatrix>::getRealTargetCoordinates(ConnType icellT, std::vector<double>& coordsT) const
{
- const ConnType *myConectT=_target_mesh.getConnectivityPtr();
- const ConnType *myConIndexT=_target_mesh.getConnectivityIndexPtr();
- const double *myCoordsT=_target_mesh.getCoordinatesPtr();
- int nbNodesT=myConIndexT[OTT<ConnType,numPol>::ind2C(icellT)+1]-myConIndexT[OTT<ConnType,numPol>::ind2C(icellT)];
+ int nbNodesT=_target_mesh.getNumberOfNodesOfElement(icellT);
coordsT.resize(SPACEDIM*nbNodesT);
+ std::vector<double>::iterator iter=coordsT.begin();
for (ConnType iT=0; iT<nbNodesT; iT++)
- for(int idim=0; idim<SPACEDIM; idim++)
- coordsT[SPACEDIM*iT+idim]=myCoordsT[SPACEDIM*OTT<ConnType,numPol>::coo2C(myConectT[OTT<ConnType,numPol>::conn2C(myConIndexT[OTT<ConnType,numPol>::ind2C(icellT)]+iT)])+idim];
+ {
+ const double *coordsCur=getCoordsOfNode(iT,icellT,_target_mesh);
+ iter=std::copy(coordsCur,coordsCur+SPACEDIM,iter);
+ }
}
/*!
template<class MyMeshType, class MyMatrix>
void Intersector3D<MyMeshType,MyMatrix>::getRealSourceCoordinates(ConnType icellS, std::vector<double>& coordsS) const
{
- const ConnType *myConectS=_src_mesh.getConnectivityPtr();
- const ConnType *myConIndexS=_src_mesh.getConnectivityIndexPtr();
- const double *myCoordsS=_src_mesh.getCoordinatesPtr();
- int nbNodesS=myConIndexS[OTT<ConnType,numPol>::ind2C(icellS)+1]-myConIndexS[OTT<ConnType,numPol>::ind2C(icellS)];
+ int nbNodesS=_src_mesh.getNumberOfNodesOfElement(icellS);
coordsS.resize(SPACEDIM*nbNodesS);
+ std::vector<double>::iterator iter=coordsS.begin();
for (ConnType iS=0; iS<nbNodesS; iS++)
- for(int idim=0; idim<SPACEDIM; idim++)
- coordsS[SPACEDIM*iS+idim]=myCoordsS[SPACEDIM*OTT<ConnType,numPol>::coo2C(myConectS[OTT<ConnType,numPol>::conn2C(myConIndexS[OTT<ConnType,numPol>::ind2C(icellS)]+iS)])+idim];
+ {
+ const double *coordsCur=getCoordsOfNode(iS,icellS,_src_mesh);
+ iter=std::copy(coordsCur,coordsCur+SPACEDIM,iter);
+ }
}
/*!
* @param node the node for which the global number is sought (ALWAYS in C mode)
* @param element an element of the mesh (in numPol policy)
* @param mesh a mesh
- * @return the node's global number so that (its coordinates in the coordinates array are at [SPACEDIM*globalNumber, SPACEDIM*globalNumber + 2]
+ * @return the node's global number so that (its coordinates in the coordinates array are at [SPACEDIM*globalNumber, SPACEDIM*globalNumber + SPACEDIM]
*/
template<class MyMeshType>
inline typename MyMeshType::MyConnType getGlobalNumberOfNode(typename MyMeshType::MyConnType node, typename MyMeshType::MyConnType element, const MyMeshType& mesh)
typedef typename MyMeshType::MyConnType ConnType;
const NumberingPolicy numPol=MyMeshType::My_numPol;
const ConnType elemIdx=OTT<ConnType,numPol>::conn2C(mesh.getConnectivityIndexPtr()[OTT<ConnType,numPol>::ind2C(element)]);
- return OTT<ConnType,numPol>::coo2C(mesh.getConnectivityPtr()[elemIdx + node]);
+ if(mesh.getTypeOfElement(element)!=INTERP_KERNEL::NORM_POLYHED)
+ return OTT<ConnType,numPol>::coo2C(mesh.getConnectivityPtr()[elemIdx + node]);
+ else
+ {
+ const ConnType *startNodalConnOfElem=mesh.getConnectivityPtr()+elemIdx;
+ ConnType ptr=0,ret=0;
+ while(startNodalConnOfElem[ret]==-1 || ptr!=node)
+ {
+ ret++;
+ if(startNodalConnOfElem[ret]!=-1)
+ ptr++;
+ }
+ return OTT<ConnType,numPol>::coo2C(startNodalConnOfElem[ret]);
+ }
}
/**
{
typedef typename MyMeshType::MyConnType ConnType;
const ConnType connIdx = getGlobalNumberOfNode(node, element, mesh);
- return mesh.getCoordinatesPtr()+MyMeshType::MY_SPACEDIM*connIdx;
+ const double *ret=mesh.getCoordinatesPtr()+MyMeshType::MY_SPACEDIM*connIdx;
+ return ret;
}
/**
const CellModel& cmTypeS=CellModel::getCellModel(tS);
std::vector<ConnType> connOfCurCellS;
Intersector3DP0P0<MyMeshType,MyMatrix>::getConnOfSourceCell(OTT<ConnType,numPol>::indFC(*iterCellS),connOfCurCellS);
- if(PointLocatorAlgos<MyMeshType>::isElementContainsPointAlg3D(bary,&connOfCurCellS[0],coordsS,cmTypeS,_precision))
+ if(PointLocatorAlgos<MyMeshType>::isElementContainsPointAlg3D(bary,&connOfCurCellS[0],connOfCurCellS.size(),coordsS,cmTypeS,_precision))
{
resRow.insert(std::make_pair(OTT<ConnType,numPol>::indFC(*iterCellS),1));
}
Intersector3DP0P1<MyMeshType,MyMatrix>::getConnOfSourceCell(OTT<ConnType,numPol>::indFC(*iterCellS),connOfCurCellS);
for(int nodeIdT=0;nodeIdT<nbNodesT;nodeIdT++)
{
- if(PointLocatorAlgos<MyMeshType>::isElementContainsPointAlg3D(&coordsTarget[nodeIdT*SPACEDIM],&connOfCurCellS[0],coordsS,cmTypeS,_precision))
+ if(PointLocatorAlgos<MyMeshType>::isElementContainsPointAlg3D(&coordsTarget[nodeIdT*SPACEDIM],&connOfCurCellS[0],connOfCurCellS.size(),coordsS,cmTypeS,_precision))
{
ConnType curNodeTInCmode=OTT<ConnType,numPol>::coo2C(startOfCellNodeConnT[nodeIdT]);
typename MyMatrix::value_type& resRow=res[curNodeTInCmode];
const CellModel& cmTypeS=CellModel::getCellModel(tS);
std::vector<ConnType> connOfCurCellS;
Intersector3DP1P0<MyMeshType,MyMatrix>::getConnOfSourceCell(OTT<ConnType,numPol>::indFC(*iterCellS),connOfCurCellS);
- if( PointLocatorAlgos<MyMeshType>::isElementContainsPointAlg3D(baryT,&connOfCurCellS[0],coordsS,cmTypeS,_precision) )
+ if( PointLocatorAlgos<MyMeshType>::isElementContainsPointAlg3D(baryT,&connOfCurCellS[0],connOfCurCellS.size(),coordsS,cmTypeS,_precision) )
{
double resLoc[4];
std::vector<double> srcCell;
typename MyMatrix::value_type& resRow=res[OTT<ConnType,numPol>::ind2C(startOfCellNodeConnT[nodeIdT])];
std::vector<ConnType> connOfCurCellS;
Intersector3DP1P1<MyMeshType,MyMatrix>::getConnOfSourceCell(OTT<ConnType,numPol>::indFC(*iterCellS),connOfCurCellS);
- if( PointLocatorAlgos<MyMeshType>::isElementContainsPointAlg3D(&CoordsT[nodeIdT*SPACEDIM],&connOfCurCellS[0],coordsS,cmTypeS,_precision) )
+ if( PointLocatorAlgos<MyMeshType>::isElementContainsPointAlg3D(&CoordsT[nodeIdT*SPACEDIM],&connOfCurCellS[0],connOfCurCellS.size(),coordsS,cmTypeS,_precision) )
{
double resLoc[4];
std::vector<double> localCoordsS;
return ret;
}
- static bool isElementContainsPointAlg3D(const double *ptToTest, const int *conn_elem, const double *coords, const CellModel& cmType, double eps)
+ static bool isElementContainsPointAlg3D(const double *ptToTest, const typename MyMeshType::MyConnType *conn_elem, int conn_elem_sz, const double *coords, const CellModel& cmType, double eps)
{
const int SPACEDIM=MyMeshType::MY_SPACEDIM;
typedef typename MyMeshType::MyConnType ConnType;
const NumberingPolicy numPol=MyMeshType::My_numPol;
- int nbfaces = cmType.getNumberOfSons();
- int* sign = new int[nbfaces];
+ int nbfaces = cmType.getNumberOfSons2(conn_elem,conn_elem_sz);
+ int *sign = new int[nbfaces];
+ int *connOfSon = new int[conn_elem_sz];
for (int iface=0; iface<nbfaces; iface++)
{
- const unsigned* connface=cmType.getNodesConstituentTheSon(iface);
- const double* AA=coords+SPACEDIM*(OTT<ConnType,numPol>::ind2C(conn_elem[connface[0]]));
- const double* BB=coords+SPACEDIM*(OTT<ConnType,numPol>::ind2C(conn_elem[connface[1]]));
- const double* CC=coords+SPACEDIM*(OTT<ConnType,numPol>::ind2C(conn_elem[connface[2]]));
-
+ NormalizedCellType typeOfSon;
+ cmType.fillSonCellNodalConnectivity2(iface,conn_elem,conn_elem_sz,connOfSon,typeOfSon);
+ const double* AA=coords+SPACEDIM*(OTT<ConnType,numPol>::coo2C(connOfSon[0]));
+ const double* BB=coords+SPACEDIM*(OTT<ConnType,numPol>::coo2C(connOfSon[1]));
+ const double* CC=coords+SPACEDIM*(OTT<ConnType,numPol>::coo2C(connOfSon[2]));
double Vol=triple_product(AA,BB,CC,ptToTest);
if (Vol<-eps)
sign[iface]=-1;
}
bool ret=decideFromSign(sign, nbfaces);
delete [] sign;
+ delete [] connOfSon;
return ret;
}
- static bool isElementContainsPoint(const double *ptToTest, NormalizedCellType type, const double *coords, const int *conn_elem)
+ static bool isElementContainsPoint(const double *ptToTest, NormalizedCellType type, const double *coords, const typename MyMeshType::MyConnType *conn_elem, int conn_elem_sz)
{
const int SPACEDIM=MyMeshType::MY_SPACEDIM;
typedef typename MyMeshType::MyConnType ConnType;
if (SPACEDIM==3)
{
- return isElementContainsPointAlg3D(ptToTest,conn_elem,coords,cmType,1e-12);
+ return isElementContainsPointAlg3D(ptToTest,conn_elem,conn_elem_sz,coords,cmType,1e-12);
}
}
const ConnType* conn=_mesh.getConnectivityPtr();
const ConnType* conn_index= _mesh.getConnectivityIndexPtr();
const ConnType* conn_elem=conn+OTT<ConnType,numPol>::ind2C(conn_index[i]);
+ int conn_elem_sz=conn_index[i+1]-conn_index[i];
NormalizedCellType type=_mesh.getTypeOfElement(OTT<ConnType,numPol>::indFC(i));
- return isElementContainsPoint(x,type,coords,conn_elem);
+ return isElementContainsPoint(x,type,coords,conn_elem,conn_elem_sz);
}
static bool decideFromSign(const int* sign, int nbelem)
int MEDCouplingUMesh::getNumberOfNodesInCell(int cellId) const
{
- int *ptI=_nodal_connec_index->getPointer();
- return ptI[cellId+1]-ptI[cellId]-1;
+ const int *ptI=_nodal_connec_index->getConstPointer();
+ const int *pt=_nodal_connec->getConstPointer();
+ if(pt[ptI[cellId]]!=INTERP_KERNEL::NORM_POLYHED)
+ return ptI[cellId+1]-ptI[cellId]-1;
+ else
+ return std::count_if(pt+ptI[cellId]+1,pt+ptI[cellId+1],std::bind2nd(std::not_equal_to<int>(),-1));
}
void MEDCouplingUMesh::setConnectivity(DataArrayInt *conn, DataArrayInt *connIndex, bool isComputingTypes)
targetMesh->decrRef();
}
+void MEDCouplingBasicsTest::test3DInterpP0P0PL_2()
+{
+ MEDCouplingUMesh *sourceMesh=build3DSourceMesh_1();
+ MEDCouplingUMesh *targetMesh=build3DTargetMesh_1();
+ std::vector<int> cellsIds(targetMesh->getNumberOfCells());
+ for(int i=0;i<targetMesh->getNumberOfCells();i++)
+ cellsIds[i]=i;
+ targetMesh->convertToPolyTypes(cellsIds);
+ //
+ MEDCouplingNormalizedUnstructuredMesh<3,3> sourceWrapper(sourceMesh);
+ MEDCouplingNormalizedUnstructuredMesh<3,3> targetWrapper(targetMesh);
+ INTERP_KERNEL::Interpolation3D myInterpolator;
+ vector<map<int,double> > res;
+ myInterpolator.setPrecision(1e-12);
+ myInterpolator.setIntersectionType(INTERP_KERNEL::PointLocator);
+ myInterpolator.interpolateMeshes(sourceWrapper,targetWrapper,res,"P0P0");
+ CPPUNIT_ASSERT_EQUAL(8,(int)res.size());
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(1.,res[0][0],1e-12);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(1.,res[0][6],1e-12);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(1.,res[0][7],1e-12);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(1.,res[0][8],1e-12);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(1.,res[0][10],1e-12);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(1.,res[1][7],1e-12);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(1.,res[1][8],1e-12);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(1.,res[2][0],1e-12);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(1.,res[2][6],1e-12);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(1.,res[3][0],1e-12);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(1.,res[3][8],1e-12);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(1.,res[4][6],1e-12);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(1.,res[4][10],1e-12);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(1.,res[5][7],1e-12);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(1.,res[5][10],1e-12);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(1.,res[6][9],1e-12);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(1.,res[7][1],1e-12);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(1.,res[7][3],1e-12);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(1.,res[7][4],1e-12);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(1.,res[7][5],1e-12);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(1.,res[7][11],1e-12);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(21.,sumAll(res),1e-12);
+ //clean up
+ sourceMesh->decrRef();
+ targetMesh->decrRef();
+}
+
+void MEDCouplingBasicsTest::test3DInterpP0P0PL_3()
+{
+ MEDCouplingUMesh *sourceMesh=build3DSourceMesh_1();
+ MEDCouplingUMesh *targetMesh=build3DTargetMesh_1();
+ std::vector<int> cellsIds(sourceMesh->getNumberOfCells());
+ for(int i=0;i<sourceMesh->getNumberOfCells();i++)
+ cellsIds[i]=i;
+ sourceMesh->convertToPolyTypes(cellsIds);
+ //
+ MEDCouplingNormalizedUnstructuredMesh<3,3> sourceWrapper(sourceMesh);
+ MEDCouplingNormalizedUnstructuredMesh<3,3> targetWrapper(targetMesh);
+ INTERP_KERNEL::Interpolation3D myInterpolator;
+ vector<map<int,double> > res;
+ myInterpolator.setPrecision(1e-12);
+ myInterpolator.setIntersectionType(INTERP_KERNEL::PointLocator);
+ myInterpolator.interpolateMeshes(sourceWrapper,targetWrapper,res,"P0P0");
+ CPPUNIT_ASSERT_EQUAL(8,(int)res.size());
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(1.,res[0][0],1e-12);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(1.,res[0][6],1e-12);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(1.,res[0][7],1e-12);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(1.,res[0][8],1e-12);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(1.,res[0][10],1e-12);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(1.,res[1][7],1e-12);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(1.,res[1][8],1e-12);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(1.,res[2][0],1e-12);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(1.,res[2][6],1e-12);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(1.,res[3][0],1e-12);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(1.,res[3][8],1e-12);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(1.,res[4][6],1e-12);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(1.,res[4][10],1e-12);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(1.,res[5][7],1e-12);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(1.,res[5][10],1e-12);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(1.,res[6][9],1e-12);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(1.,res[7][1],1e-12);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(1.,res[7][3],1e-12);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(1.,res[7][4],1e-12);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(1.,res[7][5],1e-12);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(1.,res[7][11],1e-12);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(21.,sumAll(res),1e-12);
+ //clean up
+ sourceMesh->decrRef();
+ targetMesh->decrRef();
+}
+
+void MEDCouplingBasicsTest::test3DInterpP0P0PL_4()
+{
+ MEDCouplingUMesh *sourceMesh=build3DSourceMesh_1();
+ MEDCouplingUMesh *targetMesh=build3DTargetMesh_1();
+ std::vector<int> cellsIds(sourceMesh->getNumberOfCells());
+ for(int i=0;i<sourceMesh->getNumberOfCells();i++)
+ cellsIds[i]=i;
+ sourceMesh->convertToPolyTypes(cellsIds);
+ cellsIds.resize(targetMesh->getNumberOfCells());
+ for(int j=0;j<targetMesh->getNumberOfCells();j++)
+ cellsIds[j]=j;
+ targetMesh->convertToPolyTypes(cellsIds);
+ //
+ MEDCouplingNormalizedUnstructuredMesh<3,3> sourceWrapper(sourceMesh);
+ MEDCouplingNormalizedUnstructuredMesh<3,3> targetWrapper(targetMesh);
+ INTERP_KERNEL::Interpolation3D myInterpolator;
+ vector<map<int,double> > res;
+ myInterpolator.setPrecision(1e-12);
+ myInterpolator.setIntersectionType(INTERP_KERNEL::PointLocator);
+ myInterpolator.interpolateMeshes(sourceWrapper,targetWrapper,res,"P0P0");
+ CPPUNIT_ASSERT_EQUAL(8,(int)res.size());
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(1.,res[0][0],1e-12);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(1.,res[0][6],1e-12);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(1.,res[0][7],1e-12);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(1.,res[0][8],1e-12);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(1.,res[0][10],1e-12);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(1.,res[1][7],1e-12);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(1.,res[1][8],1e-12);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(1.,res[2][0],1e-12);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(1.,res[2][6],1e-12);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(1.,res[3][0],1e-12);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(1.,res[3][8],1e-12);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(1.,res[4][6],1e-12);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(1.,res[4][10],1e-12);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(1.,res[5][7],1e-12);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(1.,res[5][10],1e-12);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(1.,res[6][9],1e-12);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(1.,res[7][1],1e-12);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(1.,res[7][3],1e-12);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(1.,res[7][4],1e-12);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(1.,res[7][5],1e-12);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(1.,res[7][11],1e-12);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(21.,sumAll(res),1e-12);
+ //clean up
+ sourceMesh->decrRef();
+ targetMesh->decrRef();
+}
+
void MEDCouplingBasicsTest::test3DInterpP0P1_1()
{
MEDCouplingUMesh *sourceMesh=build3DTargetMesh_1();
CPPUNIT_TEST( testInterpolationCC );
CPPUNIT_TEST( test3DInterpP0P0_1 );
CPPUNIT_TEST( test3DInterpP0P0PL_1 );
+ CPPUNIT_TEST( test3DInterpP0P0PL_2 );
+ CPPUNIT_TEST( test3DInterpP0P0PL_3 );
+ CPPUNIT_TEST( test3DInterpP0P0PL_4 );
CPPUNIT_TEST( test3DInterpP0P1_1 );
CPPUNIT_TEST( test3DInterpP0P1PL_1 );
CPPUNIT_TEST( test3DInterpP1P0_1 );
void test3DSurfInterpP0P0_3();
void test3DInterpP0P0_1();
void test3DInterpP0P0PL_1();
+ void test3DInterpP0P0PL_2();
+ void test3DInterpP0P0PL_3();
+ void test3DInterpP0P0PL_4();
void test3DInterpP0P1_1();
void test3DInterpP0P1PL_1();
void test3DInterpP1P0_1();