Salome HOME
3ac70163fd6182d0c2a3f21e5a1b0665dbae14ac
[modules/med.git] / src / INTERP_KERNEL / Interpolation.txx
1 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D
2 //
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.
7 //
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.
12 //
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
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19 #ifndef __INTERPOLATION_TXX__
20 #define __INTERPOLATION_TXX__
21
22 #include "Interpolation.hxx"
23 #include "IntegralUniformIntersector.hxx"
24 #include "IntegralUniformIntersector.txx"
25 #include "VectorUtils.hxx"
26
27 namespace INTERP_KERNEL
28
29   template<class TrueMainInterpolator>
30   template<class MyMeshType, class MatrixType>
31   int Interpolation<TrueMainInterpolator>::fromToIntegralUniform(bool fromTo, const MyMeshType& mesh, MatrixType& result, const char *method)
32   {
33     typedef typename MyMeshType::MyConnType ConnType;
34     std::string methodCPP(method);
35     int ret=-1;
36     if(methodCPP=="P0")
37       {
38         IntegralUniformIntersectorP0<MyMeshType,MatrixType> intersector(mesh,InterpolationOptions::getMeasureAbsStatus());
39         intersector.setFromTo(fromTo);
40         std::vector<ConnType> tmp;
41         intersector.intersectCells(0,tmp,result);
42         ret=intersector.getNumberOfColsOfResMatrix();
43       }
44     else if(methodCPP=="P1")
45       {
46         IntegralUniformIntersectorP1<MyMeshType,MatrixType> intersector(mesh,InterpolationOptions::getMeasureAbsStatus());
47         intersector.setFromTo(fromTo);
48         std::vector<ConnType> tmp;
49         intersector.intersectCells(0,tmp,result);
50         ret=intersector.getNumberOfColsOfResMatrix();
51       }
52     else
53       throw INTERP_KERNEL::Exception("Invalid method specified in fromIntegralUniform : must be in { \"P0\", \"P1\"}");
54     return ret;
55   }
56
57   template<class TrueMainInterpolator>
58   void Interpolation<TrueMainInterpolator>::checkAndSplitInterpolationMethod(const char *method, std::string& srcMeth, std::string& trgMeth) throw(INTERP_KERNEL::Exception)
59   {
60     const int NB_OF_METH_MANAGED=4;
61     const char *METH_MANAGED[NB_OF_METH_MANAGED]={"P0P0","P0P1","P1P0","P1P1"};
62     std::string methodC(method);
63     bool found=false;
64     for(int i=0;i<NB_OF_METH_MANAGED && !found;i++)
65       found=(methodC==METH_MANAGED[i]);
66     if(!found)
67       {
68         std::string msg("The interpolation method : \'"); msg+=method; msg+="\' not managed !";
69         throw INTERP_KERNEL::Exception(msg.c_str());
70       }
71     srcMeth=methodC.substr(0,2);
72     trgMeth=methodC.substr(2);
73   }
74
75   template<class TrueMainInterpolator>
76   template<class MyMeshType>
77   double Interpolation<TrueMainInterpolator>::CalculateCharacteristicSizeOfMeshes(const MyMeshType& myMeshS, const MyMeshType& myMeshT, const int printLevel)
78   {
79     static const int SPACEDIM=MyMeshType::MY_SPACEDIM;
80
81     long nbMailleS=myMeshS.getNumberOfElements();
82     long nbMailleT=myMeshT.getNumberOfElements();
83
84     /**************************************************/
85     /* Search the characteristic size of the meshes   */
86     /**************************************************/
87
88     double BoxS[2*SPACEDIM]; myMeshS.getBoundingBox(BoxS);
89     double BoxT[2*SPACEDIM]; myMeshT.getBoundingBox(BoxT);
90     double diagonalS,dimCaracteristicS=std::numeric_limits<double>::max();
91     if(nbMailleS!=0)
92       {
93         diagonalS=getDistanceBtw2Pts<SPACEDIM>(BoxS+SPACEDIM,BoxS);
94         dimCaracteristicS=diagonalS/nbMailleS;
95       }
96     double diagonalT,dimCaracteristicT=std::numeric_limits<double>::max();
97     if(nbMailleT!=0)
98       {
99         diagonalT=getDistanceBtw2Pts<SPACEDIM>(BoxT+SPACEDIM,BoxT);
100         dimCaracteristicT=diagonalT/nbMailleT;
101       }
102     if (printLevel>=1)
103       {
104         std::cout << "  - Characteristic size of the source mesh : " << dimCaracteristicS << std::endl;
105         std::cout << "  - Characteristic size of the target mesh: " << dimCaracteristicT << std::endl;
106       }
107
108     return std::min(dimCaracteristicS, dimCaracteristicT);
109
110   }
111
112 }
113
114 #endif
115