Back to index

salome-paravis  6.5.0
vtkMedLocalization.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2010-2012  CEA/DEN, EDF R&D
00002 //
00003 // This library is free software; you can redistribute it and/or
00004 // modify it under the terms of the GNU Lesser General Public
00005 // License as published by the Free Software Foundation; either
00006 // version 2.1 of the License.
00007 //
00008 // This library is distributed in the hope that it will be useful,
00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011 // Lesser General Public License for more details.
00012 //
00013 // You should have received a copy of the GNU Lesser General Public
00014 // License along with this library; if not, write to the Free Software
00015 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00016 //
00017 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00018 //
00019 
00020 #include "vtkMedLocalization.h"
00021 
00022 #include "vtkObjectFactory.h"
00023 #include "vtkDoubleArray.h"
00024 #include "vtkIntArray.h"
00025 #include "vtkFunctionParser.h"
00026 
00027 #include "vtkMedUtilities.h"
00028 #include "vtkMedSetGet.h"
00029 #include "vtkMedFile.h"
00030 #include "vtkMedDriver.h"
00031 #include "vtkMedInterpolation.h"
00032 #include "vtkMedFraction.h"
00033 
00034 #include "med.h"
00035 
00036 // SEG2
00037 const static int SEG2_dim = 1;
00038 const static int SEG2_nnode = 2;
00039 static const int SEG2_aster2med[SEG2_nnode] =
00040 {0, 1};
00041 static const char* SEG2_varnames[SEG2_dim] = {"x"};
00042 static const char* SEG2_functions[SEG2_nnode] =
00043 {"1/2*(1-x)",
00044  "1/2*(1+x)"};
00045 
00046 // SEG3
00047 const static int SEG3_dim = 1;
00048 const static int SEG3_nnode = 3;
00049 static const int SEG3_aster2med[SEG3_nnode] =
00050 {0, 1, 2};
00051 static const char* SEG3_varnames[SEG3_dim] = {"x"};
00052 static const char* SEG3_functions[SEG3_nnode] =
00053 {"-1/2*(1-x)*x",
00054   "1/2*(1+x)*x",
00055   "(1+x)*(1-x)"};
00056 
00057 // SEG4
00058 const static int SEG4_dim = 1;
00059 const static int SEG4_nnode = 4;
00060 static const int SEG4_aster2med[SEG4_nnode] =
00061 {0, 1, 2, 3};
00062 static const char* SEG4_varnames[SEG4_dim] = {"x"};
00063 static const char* SEG4_functions[SEG4_nnode] =
00064 {"16/9*(1-x)*(x+1/3)*(x-1/3)",
00065 "-16/9*(1+x)*(1/3-x)*(x+1/3)",
00066 "16/27*(x-1)*(x+1)*(x-1/3)",
00067 "-16/27*(x-1)*(x+1)*(x+1/3)"};
00068 
00069 // TRIA3
00070 const static int TRIA3_dim = 2;
00071 const static int TRIA3_nnode = 3;
00072 static const int TRIA3_aster2med[TRIA3_nnode] =
00073 {0, 1, 2};
00074 static const char* TRIA3_varnames[TRIA3_dim] = {"x", "y"};
00075 static const char* TRIA3_functions[TRIA3_nnode] =
00076 {"1-x-y",
00077  "x",
00078  "y"};
00079 
00080 // TRIA6
00081 const static int TRIA6_dim = 2;
00082 const static int TRIA6_nnode = 6;
00083 static const int TRIA6_aster2med[TRIA6_nnode] =
00084 {0, 1, 2, 3, 4, 5};
00085 static const char* TRIA6_varnames[TRIA6_dim] = {"x", "y"};
00086 static const char* TRIA6_functions[TRIA6_nnode] =
00087 {"-(1-x-y)*(1-2*(1-x-y))",
00088  "-x*(1-2*x)",
00089  "-y*(1-2*y)",
00090  "4*x*(1-x-y)",
00091  "4*x*y",
00092  "4*y*(1-x-y)"};
00093 
00094 // TRIA7
00095 const static int TRIA7_dim = 2;
00096 const static int TRIA7_nnode = 7;
00097 static const int TRIA7_aster2med[TRIA7_nnode] =
00098 {0, 1, 2, 3, 4, 5, 6};
00099 static const char* TRIA7_varnames[TRIA7_dim] = {"x", "y"};
00100 static const char* TRIA7_functions[TRIA7_nnode] =
00101 {"1-3*(x+y)+2*(x*x+y*y)+7*x*y-3*x*y*(x+y)",
00102  "x*(-1+2*x+3*y-3*y*(x+y))",
00103  "y*(-1+2*x+3*y-3*x*(x+y))",
00104  "4*x*(1-x-4*y+3*y*(x+y))",
00105  "4*x*y*(-2+3*(x+y))",
00106  "4*y*(1-4*x-y+3*x*(x+y))",
00107  "27*x*y*(1-x-y)"};
00108 
00109 // QUAD4
00110 const static int QUAD4_dim = 2;
00111 const static int QUAD4_nnode = 4;
00112 static const int QUAD4_aster2med[QUAD4_nnode] =
00113 {0, 1, 2, 3};
00114 static const char* QUAD4_varnames[QUAD4_dim] = {"x", "y"};
00115 static const char* QUAD4_functions[QUAD4_nnode] =
00116 {"(1-x)*(1-y)/4",
00117  "(1+x)*(1-y)/4",
00118  "(1+x)*(1+y)/4",
00119  "(1-x)*(1+y)/4"};
00120 
00121 // QUAD8
00122 const static int QUAD8_dim = 2;
00123 const static int QUAD8_nnode = 8;
00124 static const int QUAD8_aster2med[QUAD8_nnode] =
00125 {0, 1, 2, 3, 4, 5, 6, 7};
00126 static const char* QUAD8_varnames[QUAD8_dim] = {"x", "y"};
00127 static const char* QUAD8_functions[QUAD8_nnode] =
00128 {"(1-x)*(1-y)*(-1-x-y)/4",
00129  "(1+x)*(1-y)*(-1+x-y)/4",
00130  "(1+x)*(1+y)*(-1+x+y)/4",
00131  "(1-x)*(1+y)*(-1-x+y)/4",
00132  "(1-x*x)*(1-y)/2",
00133  "(1+x)*(1-y*y)/2",
00134  "(1-x*x)*(1+y)/2",
00135  "(1-x)*(1-y*y)/2"};
00136 
00137 // QUAD9
00138 const static int QUAD9_dim = 2;
00139 const static int QUAD9_nnode = 9;
00140 static const int QUAD9_aster2med[QUAD9_nnode] =
00141 {0, 1, 2, 3, 4, 5, 6, 7, 8};
00142 static const char* QUAD9_varnames[QUAD9_dim] = {"x", "y"};
00143 static const char* QUAD9_functions[QUAD9_nnode] =
00144 {"x*y*(x-1)*(y-1)/4",
00145  "x*y*(x+1)*(y-1)/4",
00146  "x*y*(x+1)*(y+1)/4",
00147  "x*y*(x-1)*(y+1)/4",
00148  "(1-x*x)*y*(y-1)/2",
00149  "x*(x+1)*(1-y*y)/2",
00150  "(1-x*x)*y*(y+1)/2",
00151  "x*(x-1)*(1-y*y)/2",
00152  "(1-x*x)*(1-y*y)"};
00153 
00154 // PENTA6
00155 const static int PENTA6_dim = 3;
00156 const static int PENTA6_nnode = 6;
00157 static const int PENTA6_aster2med[PENTA6_nnode] =
00158 {0, 1, 2, 3, 4, 5};
00159 static const char* PENTA6_varnames[PENTA6_dim] = {"x", "y", "z"};
00160 static const char* PENTA6_functions[PENTA6_nnode] =
00161 {"1/2*y*(1-x)",
00162  "1/2*z*(1-x)",
00163  "1/2*(1-y-z)*(1-x)",
00164  "1/2*y*(1+x)",
00165  "1/2*z*(1+x)",
00166  "1/2*(1-y-z)*(1+x)"};
00167 
00168 // PENTA15
00169 const static int PENTA15_dim = 3;
00170 const static int PENTA15_nnode = 15;
00171 static const int PENTA15_aster2med[PENTA15_nnode] =
00172 {0, 1, 2, 3, 4, 5, 6, 7, 8, 12, 13, 14, 9, 10, 11};
00173 static const char* PENTA15_varnames[PENTA15_dim] = {"x", "y", "z"};
00174 static const char* PENTA15_functions[PENTA15_nnode] =
00175 {"y*(1-x)*(2*y-2-x)/2",
00176  "z*(1-x)*(2*z-2-x)/2",
00177  "(x-1)*(1-y-z)*(x+2*y+2*z)/2",
00178  "y*(1+x)*(2*y-2+x)/2",
00179  "z*(1+x)*(2*z-2+x)/2",
00180  "(-x-1)*(1-y-z)*(-x+2*y+2*z)/2",
00181  "2*y*z*(1-x)",
00182  "2*z*(1-y-z)*(1-x)",
00183  "2*y*(1-y-z)*(1-x)",
00184  "y*(1-x*x)",
00185  "z*(1-x*x)",
00186  "(1-y-z)*(1-x*x)",
00187  "2*y*z*(1+x)",
00188  "2*z*(1-y-z)*(1+x)",
00189  "2*y*(1-y-z)*(1+x)"};
00190 
00191 // PENTA18
00192 const static int PENTA18_dim = 3;
00193 const static int PENTA18_nnode = 18;
00194 const static int PENTA18_aster2med[PENTA18_nnode] =
00195 {0, 1, 2, 3, 4, 5, 6, 7, 8, 12, 13, 14, 9, 10, 11, 15, 16, 17};
00196 static const char* PENTA18_varnames[PENTA18_dim] = {"x", "y", "z"};
00197 static const char* PENTA18_functions[PENTA18_nnode] =
00198 {"x*y*x−1*2*y−1/2",
00199  "x*z*x−1*2*z−1/2",
00200  "x*x−1*zy−1*2*z2*y−1/2",
00201  "x*y*x1*2*y−1/2",
00202  "x*z*x1*2*z−1/2",
00203  "x*x1*zy−1*2*z2*y−1/2",
00204  "2*x*y*z*x−1",
00205  "−2*x*z*x−1*zy−1",
00206  "−2*x*y*x−1*zy−1",
00207  "y*1−x*x*2*y−1",
00208  "z*1−x*x*2*z−1",
00209  "1−x*x*zy−1*2*z2*y−1",
00210  "2*x*y*z*x1",
00211  "−2*x*z*x1*zy−1",
00212  "−2*x*y*x1*zy−1",
00213  "4*y*z*1−x*x",
00214  "4*z*x−1*zy−1",
00215  "4*y*x−1*zy−1"};
00216 
00217 // HEXA8
00218 const static int HEXA8_dim = 3;
00219 const static int HEXA8_nnode = 8;
00220 static const int HEXA8_aster2med[HEXA8_nnode] =
00221 {0, 1, 2, 3, 4, 5, 6, 7};
00222 static const char* HEXA8_varnames[HEXA8_dim] = {"x", "y", "z"};
00223 static const char* HEXA8_functions[HEXA8_nnode] =
00224 {"1/8*(1-x)*(1-y)*(1-z)",
00225  "1/8*(1+x)*(1-y)*(1-z)",
00226  "1/8*(1+x)*(1+y)*(1-z)",
00227  "1/8*(1-x)*(1+y)*(1-z)",
00228  "1/8*(1-x)*(1-y)*(1+z)",
00229  "1/8*(1+x)*(1-y)*(1+z)",
00230  "1/8*(1+x)*(1+y)*(1+z)",
00231  "1/8*(1-x)*(1+y)*(1+z)"
00232    };
00233 
00234 // HEXA20
00235 const static int HEXA20_dim = 3;
00236 const static int HEXA20_nnode = 20;
00237 static const int HEXA20_aster2med[HEXA20_nnode] =
00238 {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 16, 17, 18, 19, 12, 13, 14, 15};
00239 static const char* HEXA20_varnames[HEXA20_dim] = {"x", "y", "z"};
00240 static const char* HEXA20_functions[HEXA20_nnode] =
00241 {"1/8*(1-x)*(1-y)*(1-z)*(-2-x-y-z)",
00242  "1/8*(1+x)*(1-y)*(1-z)*(-2+x-y-z)",
00243  "1/8*(1+x)*(1+y)*(1-z)*(-2+x+y-z)",
00244  "1/8*(1-x)*(1+y)*(1-z)*(-2-x+y-z)",
00245  "1/8*(1-x)*(1-y)*(1+z)*(-2-x-y+z)",
00246  "1/8*(1+x)*(1-y)*(1+z)*(-2+x-y+z)",
00247  "1/8*(1+x)*(1+y)*(1+z)*(-2+x+y+z)",
00248  "1/8*(1-x)*(1+y)*(1+z)*(-2-x+y+z)",
00249  "1/4*(1-x*x)*(1-y)*(1-z)",
00250  "1/4*(1-y*y)*(1+x)*(1-z)",
00251  "1/4*(1-x*x)*(1+y)*(1-z)",
00252  "1/4*(1-y*y)*(1-x)*(1-z)",
00253  "1/4*(1-z*z)*(1-x)*(1-y)",
00254  "1/4*(1-z*z)*(1+x)*(1-y)",
00255  "1/4*(1-z*z)*(1+x)*(1+y)",
00256  "1/4*(1-z*z)*(1-x)*(1+y)",
00257  "1/4*(1-x*x)*(1-y)*(1+z)",
00258  "1/4*(1-y*y)*(1+x)*(1+z)",
00259  "1/4*(1-x*x)*(1+y)*(1+z)",
00260  "1/4*(1-y*y)*(1-x)*(1+z)",
00261   };
00262 
00263 // HEXA27
00264 const static int HEXA27_dim = 3;
00265 const static int HEXA27_nnode = 27;
00266 static const int HEXA27_aster2med[HEXA27_nnode] =
00267 {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 16, 17, 18, 19, 12, 13, 14, 15, 20, 21,
00268  22, 23, 24, 25, 26};
00269 static const char* HEXA27_varnames[HEXA27_dim] = {"x", "y", "z"};
00270 static const char* HEXA27_functions[HEXA27_nnode] =
00271 {"1/8*x*(x-1)*y*(y-1)*z*(z-1)",
00272  "1/8*x*(x+1)*y*(y-1)*z*(z-1)",
00273  "1/8*x*(x+1)*y*(y+1)*z*(z-1)",
00274  "1/8*x*(x-1)*y*(y+1)*z*(z-1)",
00275  "1/8*x*(x-1)*y*(y-1)*z*(z+1)",
00276  "1/8*x*(x+1)*y*(y-1)*z*(z+1)",
00277  "1/8*x*(x+1)*y*(y+1)*z*(z+1)",
00278  "1/8*x*(x-1)*y*(y+1)*z*(z+1)",
00279  "1/4*(1-x*x)*y*(y-1)*z*(z-1)",
00280  "1/4*x*(x+1)*(1-y*y)*z*(z-1)",
00281  "1/4*(1-x*x)*y*(y+1)*z*(z-1)",
00282  "1/4*x*(x-1)*(1-y*y)*z*(z-1)",
00283  "1/4*x*(x-1)*y*(y-1)*(1-z*z)",
00284  "1/4*x*(x+1)*y*(y-1)*(1-z*z)",
00285  "1/4*x*(x+1)*y*(y+1)*(1-z*z)",
00286  "1/4*x*(x-1)*y*(y+1)*(1-z*z)",
00287  "1/4*(1-x*x)*y*(y-1)*z*(z+1)",
00288  "1/4*x*(x+1)*(1-y*y)*z*(z+1)",
00289  "1/4*(1-x*x)*y*(y+1)*z*(z+1)",
00290  "1/4*x*(x-1)*(1-y*y)*z*(z+1)",
00291  "1/2*(1-x*x)*(1-y*y)*z*(z-1)",
00292  "1/2*(1-x*x)*y*(y-1)*(1-z*z)",
00293  "1/2*x*(x-1)*(1-y*y)*(1-z*z)",
00294  "1/2*(1-x*x)*y*(y-1)*(1-z*z)",
00295  "1/2*x*(x-1)*(1-y*y)*(1-z*z)",
00296  "1/2*(1-x*x)*(1-y*y)*z*(z-1)",
00297  "(1-x*x)*(1-y*y)*(1-z*z)"
00298   };
00299 
00300 // TETRA4
00301 const static int TETRA4_dim = 3;
00302 const static int TETRA4_nnode = 4;
00303 static const int TETRA4_aster2med[TETRA4_nnode] =
00304 {0, 1, 2, 3};
00305 static const char* TETRA4_varnames[TETRA4_dim] = {"x", "y", "z"};
00306 static const char* TETRA4_functions[TETRA4_nnode] =
00307 {
00308   "y",
00309   "z",
00310   "1-x-y-z",
00311   "x"
00312 };
00313 
00314 // TETRA10
00315 const static int TETRA10_dim = 3;
00316 const static int TETRA10_nnode = 10;
00317 static const int TETRA10_aster2med[TETRA10_nnode] =
00318 {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
00319 static const char* TETRA10_varnames[TETRA10_dim] = {"x", "y", "z"};
00320 static const char* TETRA10_functions[TETRA10_nnode] =
00321 {
00322   "y*(2*y-1)",
00323   "z*(2*z-1)",
00324   "(1-x-y-z)*(1-2*x-2*y-2*z)",
00325   "x*(2*x-1)",
00326   "4*y*z",
00327   "4*z*(1-x-y-z)",
00328   "4*y*(1-x-y-z)",
00329   "4*x*y",
00330   "4*x*z",
00331   "4*x*(1-x-y-z)"
00332 };
00333 
00334 // PYRA5
00335 const static int PYRA5_dim = 3;
00336 const static int PYRA5_nnode = 5;
00337 static const int PYRA5_aster2med[PYRA5_nnode] =
00338 {0, 1, 2, 3, 4};
00339 static const char* PYRA5_varnames[PYRA5_dim] = {"x", "y", "z"};
00340 static const char* PYRA5_functions[PYRA5_nnode] =
00341 {
00342 "(-x+y+z-1)*(-x-y+z-1)/(4*(1-z))",
00343 "(-x-y+z-1)*( x-y+z-1)/(4*(1-z))",
00344 "( x-y+z-1)*( x+y+z-1)/(4*(1-z))",
00345 "( x+y+z-1)*(-x+y+z-1)/(4*(1-z))",
00346 "z"
00347 };
00348 
00349 // PYRA13
00350 const static int PYRA13_dim = 3;
00351 const static int PYRA13_nnode = 13;
00352 static const int PYRA13_aster2med[PYRA13_nnode] =
00353 {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12};
00354 static const char* PYRA13_varnames[PYRA13_dim] = {"x", "y", "z"};
00355 static const char* PYRA13_functions[PYRA13_nnode] =
00356 {
00357   "(-x+y+z-1)*(-x-y+z-1)*( x-1/2)/(2*(1-z))",
00358   "(-x-y+z-1)*( x-y+z-1)*( y-1/2)/(2*(1-z))",
00359   "( x-y+z-1)*( x+y+z-1)*(-x-1/2)/(2*(1-z))",
00360   "( x+y+z-1)*(-x+y+z-1)*(-y-1/2)/(2*(1-z))",
00361   "2*z*(z-1/2)",
00362   "-(-x+y+z-1)*(-x-y+z-1)*( x-y+z-1)/(2*(1-z))",
00363   "-(-x-y+z-1)*( x-y+z-1)*( x+y+z-1)/(2*(1-z))",
00364   "-( x-y+z-1)*( x+y+z-1)*(-x+y+z-1)/(2*(1-z))",
00365   "-( x+y+z-1)*(-x+y+z-1)*(-x-y+z-1)/(2*(1-z))",
00366   "(-x+y+z-1)*(-x-y+z-1)*z/(1-z)",
00367   "(-x-y+z-1)*( x-y+z-1)*z/(1-z)",
00368   "( x-y+z-1)*( x+y+z-1)*z/(1-z)",
00369   "( x+y+z-1)*(-x+y+z-1)*z/(1-z)"
00370 };
00371 
00372 vtkCxxSetObjectMacro(vtkMedLocalization, ParentFile, vtkMedFile);
00373 vtkCxxSetObjectMacro(vtkMedLocalization, Interpolation, vtkMedInterpolation);
00374 
00375 vtkCxxRevisionMacro(vtkMedLocalization, "$Revision: 1.1.4.5.2.1 $")
00376 vtkStandardNewMacro(vtkMedLocalization)
00377 
00378 vtkMedLocalization::vtkMedLocalization()
00379 {
00380   this->GeometryType = MED_NONE;
00381   this->NumberOfQuadraturePoint = 0;
00382   this->Weights = vtkDoubleArray::New();
00383   this->PointLocalCoordinates = vtkDoubleArray::New();
00384   this->QuadraturePointLocalCoordinates = vtkDoubleArray::New();
00385   this->ShapeFunction = vtkDoubleArray::New();
00386   this->Name = NULL;
00387   this->SectionName = NULL;
00388   this->InterpolationName = NULL;
00389   this->MedIterator = -1;
00390   this->ParentFile = NULL;
00391   this->SpaceDimension = 3;
00392   this->NumberOfCellInSection = 0;
00393   this->SectionGeometryType = MED_NONE;
00394   this->Interpolation = NULL;
00395   this->ShapeFunctionIsBuilt = 0;
00396 }
00397 
00398 vtkMedLocalization::~vtkMedLocalization()
00399 {
00400   this->SetName(NULL);
00401   this->SetSectionName(NULL);
00402   this->SetInterpolationName(NULL);
00403   this->Weights->Delete();
00404   this->PointLocalCoordinates->Delete();
00405   this->QuadraturePointLocalCoordinates->Delete();
00406   this->ShapeFunction->Delete();
00407   this->SetInterpolation(NULL);
00408 
00409 }
00410 
00411 int vtkMedLocalization::GetSizeOfWeights()
00412 {
00413   return this->NumberOfQuadraturePoint;
00414 }
00415 
00416 int vtkMedLocalization::GetSizeOfPointLocalCoordinates()
00417 {
00418   return vtkMedUtilities::GetNumberOfPoint(this->GeometryType)
00419       * vtkMedUtilities::GetDimension(this->GeometryType);
00420 }
00421 
00422 int vtkMedLocalization::GetSizeOfQuadraturePointLocalCoordinates()
00423 {
00424   return this->NumberOfQuadraturePoint * vtkMedUtilities::GetDimension(
00425       this->GeometryType);
00426 }
00427 
00428 int vtkMedLocalization::GetSizeOfShapeFunction()
00429 {
00430   return this->NumberOfQuadraturePoint * vtkMedUtilities::GetNumberOfPoint(
00431       this->GeometryType);
00432 }
00433 
00434 void vtkMedLocalization::BuildShapeFunction()
00435 {
00436   if(this->ShapeFunctionIsBuilt)
00437     return;
00438 
00439   if(this->Interpolation == NULL)
00440     {
00441     // If there is no interpolation given for this localization,
00442     // I build the default aster shape function
00443 
00444     switch (this->GeometryType)
00445     {
00446       case MED_POINT1:
00447         BuildPoint1();
00448         return;
00449       case MED_SEG2:
00450         BuildAsterShapeFunction(SEG2_dim, SEG2_nnode,
00451                            (const int *) SEG2_aster2med,
00452                            (const char**)SEG2_varnames,
00453                            (const char**)SEG2_functions);
00454         break;
00455       case MED_SEG3:
00456         BuildAsterShapeFunction(SEG3_dim, SEG3_nnode,
00457                            (const int *) SEG3_aster2med,
00458                            (const char**)SEG3_varnames,
00459                            (const char**)SEG3_functions);
00460         break;
00461       case MED_SEG4:
00462         BuildAsterShapeFunction(SEG4_dim, SEG4_nnode,
00463                            (const int *) SEG4_aster2med,
00464                            (const char**)SEG4_varnames,
00465                            (const char**)SEG4_functions);
00466         break;
00467       case MED_TRIA3:
00468         BuildAsterShapeFunction(TRIA3_dim, TRIA3_nnode,
00469                            (const int *) TRIA3_aster2med,
00470                            (const char**)TRIA3_varnames,
00471                            (const char**)TRIA3_functions);
00472         break;
00473       case MED_TRIA6:
00474         BuildAsterShapeFunction(TRIA6_dim, TRIA6_nnode,
00475                            (const int *) TRIA6_aster2med,
00476                            (const char**)TRIA6_varnames,
00477                            (const char**)TRIA6_functions);
00478         break;
00479       case MED_TRIA7:
00480         BuildAsterShapeFunction(TRIA7_dim, TRIA7_nnode,
00481                            (const int *) TRIA7_aster2med,
00482                            (const char**)TRIA7_varnames,
00483                            (const char**)TRIA7_functions);
00484         break;
00485       case MED_QUAD4:
00486         BuildAsterShapeFunction(QUAD4_dim, QUAD4_nnode,
00487                            (const int *) QUAD4_aster2med,
00488                            (const char**)QUAD4_varnames,
00489                            (const char**)QUAD4_functions);
00490         break;
00491       case MED_QUAD8:
00492         BuildAsterShapeFunction(QUAD8_dim, QUAD8_nnode,
00493                            (const int *) QUAD8_aster2med,
00494                            (const char**)QUAD8_varnames,
00495                            (const char**)QUAD8_functions);
00496         break;
00497       case MED_QUAD9:
00498         BuildAsterShapeFunction(QUAD9_dim, QUAD9_nnode,
00499                            (const int *) QUAD9_aster2med,
00500                            (const char**)QUAD9_varnames,
00501                            (const char**)QUAD9_functions);
00502         break;
00503       case MED_HEXA8:
00504         BuildAsterShapeFunction(HEXA8_dim, HEXA8_nnode,
00505                            (const int *) HEXA8_aster2med,
00506                            (const char**)HEXA8_varnames,
00507                            (const char**)HEXA8_functions);
00508         break;
00509       case MED_HEXA20:
00510         BuildAsterShapeFunction(HEXA20_dim, HEXA20_nnode,
00511                            (const int *) HEXA20_aster2med,
00512                            (const char**)HEXA20_varnames,
00513                            (const char**)HEXA20_functions);
00514         break;
00515       case MED_HEXA27:
00516         BuildAsterShapeFunction(HEXA27_dim, HEXA27_nnode,
00517                            (const int *) HEXA27_aster2med,
00518                            (const char**)HEXA27_varnames,
00519                            (const char**)HEXA27_functions);
00520         break;
00521       case MED_TETRA4:
00522         BuildAsterShapeFunction(TETRA4_dim, TETRA4_nnode,
00523                            (const int *) TETRA4_aster2med,
00524                            (const char**)TETRA4_varnames,
00525                            (const char**)TETRA4_functions);
00526         break;
00527       case MED_TETRA10:
00528         BuildAsterShapeFunction(TETRA10_dim, TETRA10_nnode,
00529                            (const int *) TETRA10_aster2med,
00530                            (const char**)TETRA10_varnames,
00531                            (const char**)TETRA10_functions);
00532         break;
00533       case MED_PENTA6:
00534         BuildAsterShapeFunction(PENTA6_dim, PENTA6_nnode,
00535                            (const int *) PENTA6_aster2med,
00536                            (const char**)PENTA6_varnames,
00537                            (const char**)PENTA6_functions);
00538         break;
00539       case MED_PENTA15:
00540         BuildAsterShapeFunction(PENTA15_dim, PENTA15_nnode,
00541                            (const int *) PENTA15_aster2med,
00542                            (const char**)PENTA15_varnames,
00543                            (const char**)PENTA15_functions);
00544         break;
00545       case MED_PYRA5:
00546         BuildAsterShapeFunction(PYRA5_dim, PYRA5_nnode,
00547                            (const int *) PYRA5_aster2med,
00548                            (const char**)PYRA5_varnames,
00549                            (const char**)PYRA5_functions);
00550         break;
00551       case MED_PYRA13:
00552         BuildAsterShapeFunction(PYRA13_dim, PYRA13_nnode,
00553                            (const int *) PYRA13_aster2med,
00554                            (const char**)PYRA13_varnames,
00555                            (const char**)PYRA13_functions);
00556         break;
00557       default:
00558         vtkErrorMacro("ERROR in vtkMedLocalization::BuildShapeFunction. "
00559                       << this->GeometryType
00560                       << " : Cell geometry not supported !!! ");
00561         return;
00562       }
00563     }
00564   else
00565     {
00566     this->BuildShapeFunctionFromInterpolation();
00567     }
00568   this->ShapeFunctionIsBuilt = 1;
00569 }
00570 
00571 void  vtkMedLocalization::BuildShapeFunctionFromInterpolation()
00572 {
00573   int nnodes = this->GeometryType % 100;
00574   int dim = this->GeometryType / 100;
00575   this->ShapeFunction->SetNumberOfValues(this->GetSizeOfShapeFunction());
00576 
00577   int qpindex;
00578   int nodeindex;
00579 
00580   vtkMedFraction* func;
00581 
00582   switch(dim)
00583     {
00584     case 0 :
00585       this->ShapeFunction->SetValue(0, 1);
00586       break;
00587     default :
00588       for(qpindex=0; qpindex < this->NumberOfQuadraturePoint; qpindex++ )
00589         {
00590         double *coord = new double[dim];
00591         for(int dimid=0; dimid<dim; dimid++)
00592           {
00593           coord[dimid] = this->QuadraturePointLocalCoordinates
00594                          ->GetValue((qpindex * dim)+dimid);
00595           }
00596 
00597         for(nodeindex=0; nodeindex < nnodes; nodeindex++)
00598           {
00599           func = this->Interpolation->GetBasisFunction(nodeindex);
00600           this->ShapeFunction->SetValue(
00601               qpindex*nnodes + nodeindex, func->Evaluate(coord));
00602           }
00603         }
00604     }
00605 }
00606 
00607 void  vtkMedLocalization::BuildAsterShapeFunction(int dim,
00608                                  int nnodes,
00609                                  const int* aster2med,
00610                                  const char** varnames,
00611                                  const char** functions)
00612 {
00613   this->ShapeFunction->SetNumberOfValues(
00614       this->NumberOfQuadraturePoint * nnodes);
00615 
00616   std::vector<vtkSmartPointer<vtkFunctionParser> > parsers;
00617   parsers.resize(nnodes);
00618   for(int nodeindex=0; nodeindex < nnodes; nodeindex++)
00619     {
00620     parsers[nodeindex] = vtkSmartPointer<vtkFunctionParser>::New();
00621     parsers[nodeindex]->SetFunction(functions[nodeindex]);
00622     }
00623 
00624   for(int qpindex=0; qpindex < this->NumberOfQuadraturePoint; qpindex++ )
00625     {
00626 
00627     for(int nodeindex=0; nodeindex < nnodes; nodeindex++)
00628       {
00629       int mednodeindex = aster2med[nodeindex];
00630       vtkFunctionParser* parser = parsers[mednodeindex];
00631       for(int dimid=0; dimid<dim; dimid++)
00632         {
00633         const char* varname = varnames[dimid];
00634         const double coord = this->QuadraturePointLocalCoordinates
00635                              ->GetValue((qpindex * dim)+dimid);
00636 
00637         parser->SetScalarVariableValue(varname, coord);
00638         }
00639 
00640       double w = parser->GetScalarResult();
00641 
00642       this->ShapeFunction->SetValue(
00643           qpindex*nnodes + mednodeindex, w);
00644       }
00645     }
00646 }
00647 
00648 void vtkMedLocalization::BuildPoint1()
00649 {
00650   this->Weights->SetNumberOfValues(1);
00651   this->ShapeFunction->SetNumberOfValues(1);
00652   this->Weights->SetValue(0, 1);
00653   this->ShapeFunction->SetValue(0, 1);
00654 }
00655 
00656 void vtkMedLocalization::BuildCenter(med_geometry_type geometry)
00657 {
00658   this->GeometryType = geometry;
00659   this->NumberOfQuadraturePoint = 1;
00660   int npts = vtkMedUtilities::GetNumberOfPoint(this->GeometryType);
00661   this->ShapeFunction->SetNumberOfValues(npts);
00662   this->Weights->SetNumberOfValues(1);
00663   for (int i = 0; i < npts; i++)
00664     {
00665     this->ShapeFunction->SetValue(i, 1.0 / (double) npts);
00666     }
00667   this->Weights->SetValue(0, 1);
00668 
00669 }
00670 
00671 void vtkMedLocalization::BuildELNO(med_geometry_type geometry)
00672 {
00673   this->GeometryType = geometry;
00674   this->NumberOfQuadraturePoint = vtkMedUtilities::GetNumberOfPoint(geometry);
00675 
00676   int np2 = this->NumberOfQuadraturePoint * this->NumberOfQuadraturePoint;
00677   this->ShapeFunction->SetNumberOfValues(np2);
00678   this->Weights->SetNumberOfValues(this->NumberOfQuadraturePoint);
00679 
00680   for (int i = 0; i < np2; i++)
00681     {
00682     this->ShapeFunction->SetValue(i, 0);
00683     }
00684   for (int i = 0; i < this->NumberOfQuadraturePoint; i++)
00685     {
00686     this->ShapeFunction->SetValue(i + i * this->NumberOfQuadraturePoint, 1.0);
00687     }
00688   double w = 1.0 / (double) this->NumberOfQuadraturePoint;
00689   for (int i = 0; i < this->NumberOfQuadraturePoint; i++)
00690     {
00691     this->Weights->SetValue(i, w);
00692     }
00693 }
00694 
00695 void vtkMedLocalization::PrintSelf(ostream& os, vtkIndent indent)
00696 {
00697   this->Superclass::PrintSelf(os, indent);
00698   PRINT_IVAR(os, indent, GeometryType);
00699   PRINT_IVAR(os, indent, NumberOfQuadraturePoint);
00700   PRINT_IVAR(os, indent, MedIterator);
00701 }