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