From 1686692ce648bc42be024bc2af75c501db66a1ca Mon Sep 17 00:00:00 2001 From: Anthony Geay Date: Fri, 7 Sep 2018 16:46:29 +0200 Subject: [PATCH] [EDF17279] : integration computation --- src/INTERP_KERNEL/InterpolationUtils.hxx | 6 ++++ src/MEDCoupling/MEDCoupling.hxx | 2 +- src/MEDCoupling/MEDCouplingMemArray.cxx | 38 ++++++++++++++++++++++ src/MEDCoupling/MEDCouplingMemArray.hxx | 1 + src/MEDCoupling_Swig/MEDCouplingMemArray.i | 22 +++++++++++++ 5 files changed, 68 insertions(+), 1 deletion(-) diff --git a/src/INTERP_KERNEL/InterpolationUtils.hxx b/src/INTERP_KERNEL/InterpolationUtils.hxx index 70d4ca9b8..d037a1fa7 100644 --- a/src/INTERP_KERNEL/InterpolationUtils.hxx +++ b/src/INTERP_KERNEL/InterpolationUtils.hxx @@ -101,6 +101,12 @@ namespace INTERP_KERNEL return sqrt(X*X+Y*Y); } + inline void mid_of_seg2(const double P1[2], const double P2[2], double MID[2]) + { + MID[0]=(P1[0]+P2[0])/2.; + MID[1]=(P1[1]+P1[1])/2.; + } + /*_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ */ /* calcul le cos et le sin de l'angle P1P2,P1P3 */ /*_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ */ diff --git a/src/MEDCoupling/MEDCoupling.hxx b/src/MEDCoupling/MEDCoupling.hxx index 391b9d378..5b6208fb3 100644 --- a/src/MEDCoupling/MEDCoupling.hxx +++ b/src/MEDCoupling/MEDCoupling.hxx @@ -22,7 +22,7 @@ #define _MEDCOUPLING_HXX_ #ifdef WIN32 -# if defined(medcoupling_EXPORTS) || defined(medcouplingcpp_EXPORTS) || defined(MEDCOUPLING_WIN32_SWIG) +# if defined(medcoupling_EXPORTS) || defined(medcouplingcpp_EXPORTS) # define MEDCOUPLING_EXPORT __declspec( dllexport ) # else # define MEDCOUPLING_EXPORT __declspec( dllimport ) diff --git a/src/MEDCoupling/MEDCouplingMemArray.cxx b/src/MEDCoupling/MEDCouplingMemArray.cxx index 4346c26be..0642d3161 100644 --- a/src/MEDCoupling/MEDCouplingMemArray.cxx +++ b/src/MEDCoupling/MEDCouplingMemArray.cxx @@ -3611,6 +3611,44 @@ void DataArrayDouble::GiveBaseForPlane(const double normalVector[3], double base baseOfPlane[6]=normalVector[0]/ni; baseOfPlane[7]=normalVector[1]/ni; baseOfPlane[8]=normalVector[2]/ni; } +/*! + * \param [in] seg2 : coordinates of input seg2 expected to have spacedim==2 + * \param [in] tri3 : coordinates of input tri3 also expected to have spacedim==2 + * \param [out] coeffs : the result of integration normalized to 1. along \a seg2 inside tri3 sorted by the node id of \a tri3 + * \param [out] length : the length of seg2. That is too say the length of integration + */ +void DataArrayDouble::ComputeIntegralOfSeg2IntoTri3(const double seg2[4], const double tri3[6], double coeffs[3], double& length) +{ + length=INTERP_KERNEL::norme_vecteur(seg2,seg2+2); + constexpr double eps(std::numeric_limits::min()); + double n2(INTERP_KERNEL::norme_vecteur(tri3,tri3+2)); + n2=std::min(n2,INTERP_KERNEL::norme_vecteur(tri3+2,tri3+4)); n2=std::min(n2,INTERP_KERNEL::norme_vecteur(tri3+4,tri3)); + double myeps(eps*n2); + if(length>myeps*1000.) + { + constexpr unsigned NB_EVAL=10; + constexpr double NB_EVAL_FL=(double)NB_EVAL; + constexpr double INTEG_LEN(1./NB_EVAL_FL); + double curPt[2],curBaryCoo[3]; + double dirVect[2]={seg2[2]-seg2[0],seg2[3]-seg2[1]}; + coeffs[0]=0.; coeffs[1]=0.; coeffs[2]=0.; + for(unsigned i=0;i(tri3,curPt,curBaryCoo); + curBaryCoo[0]*=INTEG_LEN; curBaryCoo[1]*=INTEG_LEN; curBaryCoo[2]*=INTEG_LEN; + coeffs[0]+=curBaryCoo[0]; coeffs[1]+=curBaryCoo[1]; coeffs[2]+=curBaryCoo[2]; + } + } + else + { + double mid[2]; + INTERP_KERNEL::mid_of_seg2(seg2,seg2+2,mid); + INTERP_KERNEL::barycentric_coords<2>(tri3,mid,coeffs); + } +} + /*! * Low static method that operates 3D rotation of \a nbNodes 3D nodes whose coordinates are arranged in \a coords * around the center point \a center and with angle \a angle. diff --git a/src/MEDCoupling/MEDCouplingMemArray.hxx b/src/MEDCoupling/MEDCouplingMemArray.hxx index af887b919..de2101fea 100644 --- a/src/MEDCoupling/MEDCouplingMemArray.hxx +++ b/src/MEDCoupling/MEDCouplingMemArray.hxx @@ -504,6 +504,7 @@ namespace MEDCoupling MEDCOUPLING_EXPORT static void Rotate3DAlg(const double *center, const double *vect, double angle, int nbNodes, const double *coordsIn, double *coordsOut); MEDCOUPLING_EXPORT static void Symmetry3DPlane(const double point[3], const double normalVector[3], int nbNodes, const double *coordsIn, double *coordsOut); MEDCOUPLING_EXPORT static void GiveBaseForPlane(const double normalVector[3], double baseOfPlane[9]); + MEDCOUPLING_EXPORT static void ComputeIntegralOfSeg2IntoTri3(const double seg2[4], const double tri3[6], double coeffs[3], double& length); public: MEDCOUPLING_EXPORT void getTinySerializationIntInformation(std::vector& tinyInfo) const; MEDCOUPLING_EXPORT void getTinySerializationStrInformation(std::vector& tinyInfo) const; diff --git a/src/MEDCoupling_Swig/MEDCouplingMemArray.i b/src/MEDCoupling_Swig/MEDCouplingMemArray.i index 9ef614e64..7eda73d98 100644 --- a/src/MEDCoupling_Swig/MEDCouplingMemArray.i +++ b/src/MEDCoupling_Swig/MEDCouplingMemArray.i @@ -1144,6 +1144,28 @@ namespace MEDCoupling return convertDblArrToPyListOfTuple(vals,nbOfComp,nbOfTuples); } + static PyObject *ComputeIntegralOfSeg2IntoTri3(PyObject *seg2, PyObject *tri3) throw(INTERP_KERNEL::Exception) + { + const char msg[]="Python wrap of DataArrayDouble::ComputeIntegralOfSeg2IntoTri3 : "; + double val,val2; + DataArrayDouble *a,*a2; + DataArrayDoubleTuple *aa,*aa2; + std::vector bb,bb2; + int sw; + const double *seg2Ptr(convertObjToPossibleCpp5_Safe(seg2,sw,val,a,aa,bb,msg,2,2,true)); + const double *tri3Ptr(convertObjToPossibleCpp5_Safe(tri3,sw,val2,a2,aa2,bb2,msg,3,2,true)); + // + double res0[3],res1; + DataArrayDouble::ComputeIntegralOfSeg2IntoTri3(seg2Ptr,tri3Ptr,res0,res1); + PyObject *ret(PyTuple_New(2)),*ret0(PyTuple_New(3)); + PyTuple_SetItem(ret0,0,PyFloat_FromDouble(res0[0])); + PyTuple_SetItem(ret0,1,PyFloat_FromDouble(res0[1])); + PyTuple_SetItem(ret0,2,PyFloat_FromDouble(res0[2])); + PyTuple_SetItem(ret,0,ret0); + PyTuple_SetItem(ret,1,PyFloat_FromDouble(res1)); + return ret; + } + DataArrayDouble *symmetry3DPlane(PyObject *point, PyObject *normalVector) throw(INTERP_KERNEL::Exception) { const char msg[]="Python wrap of DataArrayDouble::symmetry3DPlane : "; -- 2.39.2