Salome HOME
Merge from V6_main_20120808 08Aug12
[modules/med.git] / src / MEDCoupling / MEDCouplingFieldTemplate.cxx
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
20 #include "MEDCouplingFieldTemplate.hxx"
21 #include "MEDCouplingMesh.hxx"
22 #include "MEDCouplingFieldDouble.hxx"
23 #include "MEDCouplingFieldDiscretization.hxx"
24
25 #include <sstream>
26
27 using namespace ParaMEDMEM;
28
29 MEDCouplingFieldTemplate *MEDCouplingFieldTemplate::New(const MEDCouplingFieldDouble *f) throw(INTERP_KERNEL::Exception)
30 {
31   return new MEDCouplingFieldTemplate(f);
32 }
33
34 /*!
35  * The user should \b not use this method. Only useful for CORBA serialization/unserialization.
36  */
37 MEDCouplingFieldTemplate *MEDCouplingFieldTemplate::New(TypeOfField type)
38 {
39   return new MEDCouplingFieldTemplate(type);
40 }
41
42 MEDCouplingFieldTemplate::MEDCouplingFieldTemplate(const MEDCouplingFieldDouble *f) throw(INTERP_KERNEL::Exception):MEDCouplingField(*f) 
43 {
44   checkCoherency();
45 }
46
47 MEDCouplingFieldTemplate::MEDCouplingFieldTemplate(TypeOfField type):MEDCouplingField(type)
48 {
49 }
50
51 void MEDCouplingFieldTemplate::checkCoherency() const throw(INTERP_KERNEL::Exception)
52 {
53   if(_mesh==0)
54     throw INTERP_KERNEL::Exception("MEDCouplingFieldTemplate::checkCoherency : Empty mesh !");
55 }
56
57 std::string MEDCouplingFieldTemplate::simpleRepr() const
58 {
59   std::ostringstream ret;
60   ret << "FieldTemplate with name : \"" << getName() << "\"\n";
61   ret << "Description of field is : \"" << getDescription() << "\"\n";
62   ret << "FieldTemplate space discretization is : " << _type->getStringRepr() << "\n";
63   ret << "FieldTemplate nature of field is : " << MEDCouplingNatureOfField::getRepr(_nature) << "\n";
64   if(_mesh)
65     ret << "Mesh support information :\n__________________________\n" << _mesh->simpleRepr();
66   else
67     ret << "Mesh support information : No mesh set !\n";
68   return ret.str();
69 }
70
71 std::string MEDCouplingFieldTemplate::advancedRepr() const
72 {
73   return simpleRepr();
74 }
75
76 void MEDCouplingFieldTemplate::getTinySerializationIntInformation(std::vector<int>& tinyInfo) const
77 {
78   tinyInfo.clear();
79   tinyInfo.push_back((int)_type->getEnum());
80   tinyInfo.push_back((int)_nature);
81   std::vector<int> tinyInfo2;
82   _type->getTinySerializationIntInformation(tinyInfo2);
83   tinyInfo.insert(tinyInfo.end(),tinyInfo2.begin(),tinyInfo2.end());
84   tinyInfo.push_back((int)tinyInfo2.size());
85 }
86
87 void MEDCouplingFieldTemplate::getTinySerializationDbleInformation(std::vector<double>& tinyInfo) const
88 {
89   tinyInfo.clear();
90   _type->getTinySerializationDbleInformation(tinyInfo);
91 }
92
93 void MEDCouplingFieldTemplate::getTinySerializationStrInformation(std::vector<std::string>& tinyInfo) const
94 {
95   tinyInfo.clear();
96   tinyInfo.push_back(_name);
97   tinyInfo.push_back(_desc);
98 }
99
100 void MEDCouplingFieldTemplate::resizeForUnserialization(const std::vector<int>& tinyInfoI, DataArrayInt *&dataInt)
101 {
102   dataInt=0;
103   std::vector<int> tinyInfoITmp(tinyInfoI.begin()+2,tinyInfoI.end());
104   _type->resizeForUnserialization(tinyInfoITmp,dataInt);
105 }
106
107 void MEDCouplingFieldTemplate::finishUnserialization(const std::vector<int>& tinyInfoI, const std::vector<double>& tinyInfoD, const std::vector<std::string>& tinyInfoS)
108 {
109   _nature=(NatureOfField)tinyInfoI[1];
110   _type->finishUnserialization(tinyInfoD);
111   _name=tinyInfoS[0];
112   _desc=tinyInfoS[1];
113 }
114
115 void MEDCouplingFieldTemplate::serialize(DataArrayInt *&dataInt) const
116 {
117   _type->getSerializationIntArray(dataInt);
118 }
119