Back to index

salome-med  6.5.0
TESTMEDCLIENT_Gen_i.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 
00023 #define private public
00024 #define protected public
00025 #include "TESTMEDCLIENT_Gen_i.hxx"
00026 #include "MESHClient.hxx"
00027 #include "FIELDClient.hxx"
00028 #include "MEDMEM_Support.hxx"
00029 #include "MEDMEM_Field.hxx"
00030 
00031 #include "MEDMEM_Family.hxx"
00032 #include "FAMILYClient.hxx"
00033 #include "MEDMEM_Field.hxx"
00034 #include "MEDMEM_Array.hxx"
00035 #include "MEDMEM_PointerOf.hxx"
00036 
00037 #include "MemorySpy.hxx"
00038 
00039 using namespace std;
00040 
00041 extern "C"
00042 {
00043   PortableServer::ObjectId *TESTMEDCLIENTEngine_factory(CORBA::ORB_ptr orb,
00044                                                         PortableServer::POA_ptr poa,
00045                                                         PortableServer::ObjectId * contId, 
00046                                                         const char *instanceName, 
00047                                                         const char *interfaceName)
00048   {
00049     TESTMEDCLIENT_Gen_i *ret=new TESTMEDCLIENT_Gen_i(orb,poa,contId,instanceName,interfaceName);
00050     return ret->getId();
00051   }
00052 }
00053 
00054 TESTMEDCLIENT_Gen_i::TESTMEDCLIENT_Gen_i(CORBA::ORB_ptr orb,
00055             PortableServer::POA_ptr poa,
00056             PortableServer::ObjectId * contId, 
00057             const char *instanceName, 
00058                                          const char *interfaceName):Engines_Component_i(orb,poa,contId,instanceName,interfaceName)
00059 {
00060   _thisObj = this ;
00061   _id = _poa->activate_object(_thisObj);
00062 }
00063   
00064 TESTMEDCLIENT_Gen_i::~TESTMEDCLIENT_Gen_i()
00065 {
00066 }
00067   
00068 void TESTMEDCLIENT_Gen_i::go(SALOME_MED::MED_ptr objMed)
00069 {
00070   cerr << "Begin of test 1" << endl;
00071   SALOME_MED::MESH_ptr maillagePtr=objMed->getMeshByName("CUBE_EN_HEXA8_QUAD4");
00072   MESHClient mesh(maillagePtr);
00073   maillagePtr->setProtocol(SALOME::SOCKET_);
00074   mesh.fillCopy();
00075 
00076   long n=mesh.getNumberOfNodes();
00077   long dim=mesh.getMeshDimension();
00078   cout << "Mesh nodes nb :" << n << " dim : " << dim << endl;
00079   const double *tabRet=mesh.getCoordinates(MED_NO_INTERLACE);
00080   for(int k=0;k<n;k++)
00081     {
00082       for(int l=0;l<dim;l++)
00083         cout << *(tabRet++) << " ";
00084       cout << endl;
00085     }
00086   int nbOfElt=mesh.getNumberOfTypes(MED_FACE);
00087   cout << "____" <<  nbOfElt << endl;
00088   SUPPORT* sup1=new SUPPORT(&mesh,"MonSup",MED_FACE);
00089   nbOfElt=sup1->getNumberOfElements(MED_QUAD4);
00090   FIELD<double>* fd=mesh.getArea(sup1);
00091   delete sup1;
00092   int nbOfVal=fd->getNumberOfValues();
00093   int nbOfCpt=fd->getNumberOfComponents();
00094   cout << "nbOfVal " << nbOfVal << " nbOfCpt " << nbOfCpt << endl;
00095   const double *tabAera=fd->getValue(MED_NO_INTERLACE);
00096   for(int m=0;m<nbOfVal;m++)
00097     cout << "Aera " << m << " = " << tabAera[m] << endl;
00098   delete fd;
00099 
00100   const vector<FAMILY*> fams=mesh.getFamilies(MED_FACE);
00101   cout << "Nb Of FACES families :" << fams.size() << " " << mesh.getNumberOfFamilies(MED_FACE)  << endl;
00102   MEDSKYLINEARRAY *numb=fams[0]->getnumber();
00103   cout << "const MEDSKYLINEARRAY *numb" << endl;
00104   cout << "Length of : " << numb->getLength() << endl;
00105   const int *vec2=numb->getValue();
00106   for(int m=0;m<numb->getLength();m++)
00107     {
00108       cout << vec2[m] << " " << endl;
00109     }
00110   const vector<GROUP*>  groups=mesh.getGroups(MED_FACE);
00111   cout << "Nb Of FACES groups :" << groups.size() << endl;
00112   const int * tabConec=mesh.getConnectivity(MED_FULL_INTERLACE,MED_NODAL,MED_FACE,MED_QUAD4);
00113   for(int p=0;p<nbOfElt;p++){
00114     for(int p1=0;p1<4;p1++)
00115       {
00116         cout << tabConec[4*p+p1] << " ";
00117       }
00118     cout << endl;
00119   }
00120   cout << endl;
00121 
00122 
00123   SALOME_MED::string_array* strArray=objMed->getFieldNames();
00124   for(int r=0;r<strArray->length();r++)
00125     cout << (*strArray)[r] << endl;
00126   SALOME_MED::FIELD_var myField=objMed->getField((*strArray)[1],2,-1);
00127   if(myField==SALOME_MED::FIELD::_nil())
00128     cout << "big problem ... " << endl;
00129   SALOME_MED::FIELDDOUBLE_ptr myFieldD=SALOME_MED::FIELDDOUBLE::_narrow(myField);
00130   if(myFieldD==SALOME_MED::FIELDDOUBLE::_nil())
00131     cout << "not fielddouble " << (*strArray)[1] << endl;
00132   FIELDClient<double,SALOME_MED::FIELDDOUBLE_ptr> myFieldDouble(myFieldD);
00133   delete strArray;
00134   const SUPPORT *supField=myFieldDouble.getSupport();
00135   int nbOfValField=supField->getNumberOfElements(MED_NONE);
00136 
00137   const double * values = myFieldDouble.getValue(MED_FULL_INTERLACE);
00138   for(int r2=0;r2<myFieldDouble.getNumberOfComponents()*nbOfValField;r2++)
00139     cout << values[r2] << " ";
00140   cout << endl;
00141 }
00142 
00143 void TESTMEDCLIENT_Gen_i::go2(SALOME_MED::MED_ptr objMed)
00144 {
00145   cerr << "Begin of test 2" << endl;
00146   SALOME_MED::string_array_var strA=objMed->getMeshNames();
00147   cout << strA[0] << endl;
00148   SALOME_MED::MESH_ptr maillagePtr;
00149   MemorySpy spy;
00150   cout << "Mem0 : " << spy.getCurrentMemoryUsage() << endl;
00151   maillagePtr=objMed->getMeshByName("cube_tetra4");
00152   MESHClient* mesh=new MESHClient(maillagePtr);
00153   cout << "Mem1 : " << spy.getCurrentMemoryUsage() << endl;
00154   mesh->fillCopy();
00155   cout << "Mem2 : " << spy.getCurrentMemoryUsage() << endl;
00156   delete mesh;
00157   cout << "Mem3 : " << spy.getCurrentMemoryUsage() << endl;
00158   SALOME_MED::string_array_var strB=objMed->getFieldNames();
00159   cout << "________________" << endl;
00160   cout << "il y a " << strB->length() << " champs" << endl;
00161   for(int i=0;i<strB->length();i++)
00162     cout << strB[i] << endl;
00163   cout << "Field beeing get " << strB[0] << endl;
00164   SALOME_MED::FIELD_var myField=objMed->getField(strB[0],-1,-1);
00165   SALOME_MED::FIELDDOUBLE_ptr myFieldD=SALOME_MED::FIELDDOUBLE::_narrow(myField);
00166   if(myFieldD==SALOME_MED::FIELDDOUBLE::_nil())
00167     cout << "not fielddouble " << strB[0] << endl;
00168   else
00169     cout << "Field " << strB[0] << " is double" << endl;
00170   //myFieldD->setProtocol(SALOME::MPI_);
00171   FIELDClient<double,SALOME_MED::FIELDDOUBLE_ptr> *myFieldDouble=new FIELDClient<double,SALOME_MED::FIELDDOUBLE_ptr>(myFieldD);
00172   cout << "Mem3bis : " << spy.getCurrentMemoryUsage() << endl;
00173   const SUPPORT *supField=myFieldDouble->getSupport();
00174   int nbOfValField=supField->getNumberOfElements(MED_TETRA4);
00175   
00176   cout << "Mem4 : " << spy.getCurrentMemoryUsage() << endl;
00177   const double * values = myFieldDouble->getValue(MED_FULL_INTERLACE);
00178 //   values= myFieldDouble->getValue(MED_FULL_INTERLACE);
00179 //   const  MEDARRAY<double>* valAr=myFieldDouble->getvalue();
00180 //   double* ptOf=valAr->_valuesNo._pointer;
00181 //   double* ptOf2=valAr->_valuesFull._pointer;
00182   cout << "Mem5 : " << spy.getCurrentMemoryUsage() << " -- " << myFieldDouble->getNumberOfComponents() << " " << nbOfValField  << endl;
00183 //   cout << valAr->_ldValues << " " << valAr->_lengthValues << endl;
00184   for(int r2=0;r2<myFieldDouble->getNumberOfComponents()*nbOfValField;r2++)
00185     {
00186 //       for(int r2j=0;r2j<nbOfValField;r2j++)
00187       {
00188 //      cout << ptOf2[r2j*3+r2i] << " " << ptOf[r2i*nbOfValField+r2j] << " | ";
00189               double val = values[r2];
00190               if ( (val < 1.0) || (val > 100.0))
00191                 cout << val << " ";
00192       }
00193     }
00194   delete myFieldDouble;
00195   cout << "Mem6 : " << spy.getCurrentMemoryUsage() << endl;
00196 }