Back to index

salome-med  6.5.0
test_copie_fieldT.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 /* Programme de test du constructeur de copies de la classe FIELD_ de MEDMEM
00023    jroy - 12/12/2002 */
00024 
00025 #include "MEDMEM_Exception.hxx"
00026 #include "MEDMEM_Mesh.hxx"
00027 #include "MEDMEM_Family.hxx"
00028 #include "MEDMEM_Group.hxx"
00029 
00030 #include "MEDMEM_MedMeshDriver.hxx"
00031 #include "MEDMEM_MedFieldDriver.hxx"
00032 #include "MEDMEM_Support.hxx"
00033 #include "MEDMEM_Field.hxx"
00034 #include "MEDMEM_FieldConvert.hxx"
00035 #include "MEDMEM_define.hxx"
00036 
00037 #include<string>
00038 
00039 #include <math.h>
00040 #include <stdlib.h>
00041 
00042 using namespace std;
00043 using namespace MEDMEM;
00044 using namespace MED_EN;
00045 
00046 
00047 static void affiche_field_(FIELD_ * myField, const SUPPORT * mySupport)
00048 {
00049   cout << "Field "<< myField->getName() << " : " <<myField->getDescription() <<  endl ;
00050   int NumberOfComponents = myField->getNumberOfComponents() ;
00051   cout << "- Nombre de composantes : "<< NumberOfComponents << endl ;
00052   for (int i=1; i<NumberOfComponents+1; i++) {
00053     cout << "  - composante "<<i<<" :"<<endl ;
00054     cout << "      - nom         : "<<myField->getComponentName(i)<< endl;
00055     cout << "      - description : "<<myField->getComponentDescription(i) << endl;
00056     cout << "      - units       : "<<myField->getMEDComponentUnit(i) << endl;
00057   }
00058   cout << "- iteration :" << endl ;
00059   cout << "    - numero : " << myField->getIterationNumber()<< endl  ;
00060   cout << "    - ordre  : " << myField->getOrderNumber()<< endl  ;
00061   cout << "    - temps  : " << myField->getTime()<< endl  ;
00062 
00063   cout << "- Type : " << myField->getValueType()<< endl;
00064 
00065   cout << "- Adresse support : " << mySupport << endl;
00066 }
00067 
00068 template <class INTERLACING_TAG>
00069 void affiche_fieldT(FIELD<double, INTERLACING_TAG> * myField,
00070                     const SUPPORT * mySupport)
00071 {
00072   affiche_field_((FIELD_ *) myField, mySupport);
00073 
00074   cout << "- Valeurs :"<<endl;
00075   int NumberOf = mySupport->getNumberOfElements(MED_ALL_ELEMENTS);
00076   int NumberOfComponents = myField->getNumberOfComponents() ;
00077 
00078   if ( myField->getInterlacingType() == MED_EN::MED_FULL_INTERLACE ) {
00079     for (int i=1; i<NumberOf+1; i++) {
00080       const double * value = myField->getRow(i) ;
00081       for (int j=0; j<NumberOfComponents; j++)
00082         cout << value[j]<< " ";
00083       cout<<endl;
00084     }
00085   }
00086   else {
00087     for (int j=1; j<NumberOfComponents+1; j++) {
00088       const double * value = myField->getColumn(j) ;
00089       for (int i=0; i<NumberOf; i++)
00090         cout << value[i]<< " ";
00091       cout<<endl;
00092     }
00093   }
00094 }
00095 
00096 int main (int argc, char ** argv)
00097 {
00098   if ((argc !=3) && (argc != 4))
00099     {
00100       cerr << "Usage : " << argv[0] 
00101            << " filename meshname fieldname" << endl << endl;
00102       exit(-1);
00103     }
00104 
00105   string filename = argv[1] ;
00106   string meshname = argv[2] ;
00107 
00108   MESH * myMesh= new MESH;
00109   myMesh->setName(meshname);
00110   MED_MESH_RDONLY_DRIVER myMeshDriver(filename,myMesh) ;
00111   myMeshDriver.setMeshName(meshname);
00112   int current = myMesh->addDriver(myMeshDriver);
00113   myMesh->read(current);
00114 
00115   // read field :
00116   if (argc != 4) exit(0) ;
00117   // else we have a field !
00118   string fieldname = argv[3];
00119 
00120   FIELD<double> * myField ;
00121   const SUPPORT * mySupport = myMesh->getSupportOnAll(MED_CELL);
00122   try
00123     {
00124       myField = new FIELD<double>(mySupport,MED_DRIVER,filename,fieldname) ;
00125     }
00126   catch (...)
00127     {
00128       mySupport = myMesh->getSupportOnAll(MED_NODE);
00129       try
00130         {
00131           myField = new FIELD<double>(mySupport,MED_DRIVER,filename,fieldname) ;
00132         }
00133       catch (...)
00134         {
00135           cout << "Field double " << fieldname << " not found !!!" << endl ;
00136           exit (-1) ;
00137         }
00138     }
00139 
00140   affiche_fieldT(myField, mySupport);
00141   FIELD<double> * myField2 = new FIELD<double>(* myField); // Contructeur par recopie, sauf SUPPORT
00142   myField->removeReference(); // Ne détruit pas le Support 
00143   affiche_fieldT(myField2, myField2->getSupport());
00144   FIELD<double,NoInterlace>   * myField3  = FieldConvert( *myField2 );
00145   myField2->removeReference();
00146 
00147   affiche_fieldT(myField3, myField3->getSupport());
00148   FIELD<double,FullInterlace> * myField4  = FieldConvert( *myField3 );
00149   myField3->removeReference();
00150   affiche_fieldT(myField4, myField4->getSupport());
00151   myField4->removeReference();
00152 
00153   FIELD<double,NoInterlace> * myField5 = new FIELD<double,NoInterlace>(mySupport,MED_DRIVER,filename,fieldname) ;
00154   affiche_fieldT(myField5, myField5->getSupport());
00155   myField5->removeReference();
00156 
00157   myMesh->removeReference();
00158 
00159   return 0;
00160 }