Back to index

salome-med  6.5.0
MEDCouplingFieldOverTimeClient.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-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 "MEDCouplingFieldOverTimeClient.hxx"
00021 #include "MEDCouplingMultiFieldsClient.hxx"
00022 #include "MEDCouplingFieldTemplate.hxx"
00023 #include "MEDCouplingDefinitionTime.hxx"
00024 #include "MEDCouplingMeshClient.hxx"
00025 #include "DataArrayDoubleClient.hxx"
00026 #include "MEDCouplingMemArray.hxx"
00027 #include "MEDCouplingMesh.hxx"
00028 
00029 #include <vector>
00030 
00031 using namespace ParaMEDMEM;
00032 
00033 MEDCouplingFieldOverTimeClient::MEDCouplingFieldOverTimeClient(SALOME_MED::MEDCouplingFieldOverTimeCorbaInterface_ptr field):_df(0)
00034 {
00035   _field_ptr=SALOME_MED::MEDCouplingFieldOverTimeCorbaInterface::_duplicate(field);
00036   _field_ptr->Register();
00037 }
00038 
00039 MEDCouplingFieldOverTimeClient::~MEDCouplingFieldOverTimeClient()
00040 {
00041   _field_ptr->UnRegister();
00042   delete _df;
00043 }
00044 
00045 MEDCouplingFieldOverTimeClient *MEDCouplingFieldOverTimeClient::New(SALOME_MED::MEDCouplingFieldOverTimeCorbaInterface_ptr fieldPtr)
00046 {
00047   MEDCouplingFieldOverTimeClient *ret=new MEDCouplingFieldOverTimeClient(fieldPtr);
00048   MEDCouplingMultiFieldsClient::BuildFullMultiFieldsCorbaFetch(ret,fieldPtr);
00049   return ret;
00050 }
00051 
00052 void MEDCouplingFieldOverTimeClient::retrieveFieldTemplates()
00053 {
00054   SALOME_TYPES::ListOfLong *tinyL=0;
00055   SALOME_TYPES::ListOfDouble *tinyD=0;
00056   SALOME_TYPES::ListOfString *tinyS=0;
00057   //
00058   CORBA::Long nbOfArrays;
00059   CORBA::Long nbOfFields;
00060   CORBA::Long nbOfMeshes=_field_ptr->getMainTinyInfo(tinyL,tinyD,nbOfArrays,nbOfFields);
00061   int tinyLgth=tinyL->length();
00062   std::vector<int> mainI(tinyLgth);
00063   for(int i=0;i<tinyLgth;i++)
00064     mainI[i]=(*tinyL)[i];
00065   delete tinyL; tinyL=0;
00066   tinyLgth=tinyD->length();
00067   std::vector<double> mainD(tinyLgth);
00068   for(int i=0;i<tinyLgth;i++)
00069     mainD[i]=(*tinyD)[i];
00070   delete tinyD; tinyD=0;
00071   //
00072   std::vector<MEDCouplingMesh *> cppms(nbOfMeshes);
00073   //
00074   std::vector<DataArrayDouble *> cppdas(nbOfArrays);
00075   //
00076   std::vector<MEDCouplingFieldTemplate *> fts(nbOfFields);
00077   for(CORBA::Long i=0;i<nbOfFields;i++)
00078     {
00079       _field_ptr->getTinyInfo(i,tinyL,tinyD,tinyS);
00080       int tinyLgth=tinyL->length();
00081       std::vector<int> tinyLV(tinyLgth);
00082       for(int j=0;j<tinyLgth;j++)
00083         tinyLV[j]=(*tinyL)[j];
00084       delete tinyL; tinyL=0;
00085       //
00086       tinyLgth=tinyD->length();
00087       std::vector<double> tinyLD(tinyLgth);
00088       for(int j=0;j<tinyLgth;j++)
00089         tinyLD[j]=(*tinyD)[j];
00090       delete tinyD; tinyD=0;
00091       //
00092       tinyLgth=tinyS->length();
00093       std::vector<std::string> tinyLS(tinyLgth);
00094       for(int j=0;j<tinyLgth;j++)
00095         tinyLS[j]=(*tinyS)[j];
00096       delete tinyS; tinyS=0;
00097       TypeOfField type=(TypeOfField) tinyLV[0];
00098       MEDCouplingFieldTemplate *f1=MEDCouplingFieldTemplate::New(type);
00099       //
00100       DataArrayInt *array0;
00101       f1->resizeForUnserialization(tinyLV,array0);
00102       if(array0)
00103         {
00104           _field_ptr->getSerialisationData(i,tinyL);
00105           tinyLgth=tinyL->length();
00106           int *ptr=array0->getPointer();
00107           for(int j=0;j<tinyLgth;j++)
00108             ptr[j]=(*tinyL)[j];
00109           delete tinyL; tinyL=0;
00110         }
00111       f1->finishUnserialization(tinyLV,tinyLD,tinyLS);
00112       fts[i]=f1;
00113     }
00114   //last step
00115   finishUnserialization(mainI,mainD,fts,cppms,cppdas);
00116   // clean-up
00117   for(std::vector<MEDCouplingFieldTemplate *>::iterator it=fts.begin();it!=fts.end();it++)
00118     (*it)->decrRef();
00119 }
00120 
00121 std::vector<double> MEDCouplingFieldOverTimeClient::getTimeSteps() const
00122 {
00123   fetchDefTimeIfNeeded();
00124   return _df->getHotSpotsTime();
00125 }
00126 
00127 void MEDCouplingFieldOverTimeClient::fetchDefTimeIfNeeded() const
00128 {
00129   if(!_df)
00130     {
00131       SALOME_TYPES::ListOfLong *tinyL=0;
00132       SALOME_TYPES::ListOfDouble *tinyD=0;
00133       _field_ptr->getTinyInfoAboutTimeDefinition(tinyL,tinyD);
00134       int tinyLgth=tinyL->length();
00135       std::vector<int> mainI(tinyLgth);
00136       for(int i=0;i<tinyLgth;i++)
00137         mainI[i]=(*tinyL)[i];
00138       delete tinyL; tinyL=0;
00139       tinyLgth=tinyD->length();
00140       std::vector<double> mainD(tinyLgth);
00141       for(int i=0;i<tinyLgth;i++)
00142         mainD[i]=(*tinyD)[i];
00143       delete tinyD; tinyD=0;
00144       //
00145       _df=new MEDCouplingDefinitionTime;
00146       _df->unserialize(mainI,mainD);
00147     }
00148 }