Salome HOME
Minor doc: isIota()
[tools/medcoupling.git] / src / MEDCoupling / MEDCouplingFieldTemplate.cxx
1 // Copyright (C) 2007-2016  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, or (at your option) any later version.
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 "MEDCouplingFieldInt.hxx"
24 #include "MEDCouplingFieldDouble.hxx"
25 #include "MEDCouplingFieldDiscretization.hxx"
26
27 #include <sstream>
28
29 using namespace MEDCoupling;
30
31 MEDCouplingFieldTemplate *MEDCouplingFieldTemplate::New(const MEDCouplingFieldDouble& f)
32 {
33   return new MEDCouplingFieldTemplate(f);
34 }
35
36 MEDCouplingFieldTemplate *MEDCouplingFieldTemplate::New(const MEDCouplingFieldInt& f)
37 {
38   return new MEDCouplingFieldTemplate(f);
39 }
40
41 /*!
42  * The user should \b not use this method. Only useful for CORBA serialization/unserialization.
43  */
44 MEDCouplingFieldTemplate *MEDCouplingFieldTemplate::New(TypeOfField type)
45 {
46   return new MEDCouplingFieldTemplate(type);
47 }
48
49 MEDCouplingFieldTemplate::MEDCouplingFieldTemplate(const MEDCouplingFieldDouble& f):MEDCouplingField(f,false) 
50 {
51   forceTimeOfThis(f);
52   checkConsistencyLight();
53 }
54
55 MEDCouplingFieldTemplate::MEDCouplingFieldTemplate(const MEDCouplingFieldInt& f):MEDCouplingField(f,false) 
56 {
57   forceTimeOfThis(f);
58   checkConsistencyLight();
59 }
60
61 MEDCouplingFieldTemplate::MEDCouplingFieldTemplate(TypeOfField type):MEDCouplingField(type)
62 {
63 }
64
65 void MEDCouplingFieldTemplate::checkConsistencyLight() const
66 {
67   if(_mesh==0)
68     throw INTERP_KERNEL::Exception("MEDCouplingFieldTemplate::checkConsistencyLight : Empty mesh !");
69 }
70
71 std::string MEDCouplingFieldTemplate::simpleRepr() const
72 {
73   std::ostringstream ret;
74   ret << "FieldTemplate with name : \"" << getName() << "\"\n";
75   ret << "Description of field is : \"" << getDescription() << "\"\n";
76   if(_type)
77     { ret << "FieldTemplate space discretization is : " << _type->getStringRepr() << "\n"; }
78   else
79     { ret << "FieldTemplate has no spatial discretization !\n"; }
80   ret << "FieldTemplate nature of field is : \"" << MEDCouplingNatureOfField::GetReprNoThrow(_nature) << "\"\n";
81   if(_mesh)
82     ret << "Mesh support information :\n__________________________\n" << _mesh->simpleRepr();
83   else
84     ret << "Mesh support information : No mesh set !\n";
85   return ret.str();
86 }
87
88 std::string MEDCouplingFieldTemplate::advancedRepr() const
89 {
90   return simpleRepr();
91 }
92
93 void MEDCouplingFieldTemplate::getTinySerializationIntInformation(std::vector<int>& tinyInfo) const
94 {
95   if(!((const MEDCouplingFieldDiscretization *)_type))
96     throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform getTinySerializationIntInformation !");
97   tinyInfo.clear();
98   tinyInfo.push_back((int)_type->getEnum());
99   tinyInfo.push_back((int)_nature);
100   std::vector<int> tinyInfo2;
101   _type->getTinySerializationIntInformation(tinyInfo2);
102   tinyInfo.insert(tinyInfo.end(),tinyInfo2.begin(),tinyInfo2.end());
103   tinyInfo.push_back((int)tinyInfo2.size());
104 }
105
106 void MEDCouplingFieldTemplate::getTinySerializationDbleInformation(std::vector<double>& tinyInfo) const
107 {
108   if(!((const MEDCouplingFieldDiscretization *)_type))
109     throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform getTinySerializationDbleInformation !");
110   tinyInfo.clear();
111   _type->getTinySerializationDbleInformation(tinyInfo);
112 }
113
114 void MEDCouplingFieldTemplate::getTinySerializationStrInformation(std::vector<std::string>& tinyInfo) const
115 {
116   tinyInfo.clear();
117   tinyInfo.push_back(_name);
118   tinyInfo.push_back(_desc);
119 }
120
121 void MEDCouplingFieldTemplate::resizeForUnserialization(const std::vector<int>& tinyInfoI, DataArrayInt *&dataInt)
122 {
123   if(!((const MEDCouplingFieldDiscretization *)_type))
124     throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform resizeForUnserialization !");
125   dataInt=0;
126   std::vector<int> tinyInfoITmp(tinyInfoI.begin()+2,tinyInfoI.end());
127   _type->resizeForUnserialization(tinyInfoITmp,dataInt);
128 }
129
130 void MEDCouplingFieldTemplate::finishUnserialization(const std::vector<int>& tinyInfoI, const std::vector<double>& tinyInfoD, const std::vector<std::string>& tinyInfoS)
131 {
132   if(!((const MEDCouplingFieldDiscretization *)_type))
133     throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform finishUnserialization !");
134   _nature=(NatureOfField)tinyInfoI[1];
135   _type->finishUnserialization(tinyInfoD);
136   _name=tinyInfoS[0];
137   _desc=tinyInfoS[1];
138 }
139
140 void MEDCouplingFieldTemplate::serialize(DataArrayInt *&dataInt) const
141 {
142   _type->getSerializationIntArray(dataInt);
143 }
144
145 void MEDCouplingFieldTemplate::reprQuickOverview(std::ostream& stream) const
146 {
147   stream << "MEDCouplingFieldTemplate C++ instance at " << this << ". Name : \"" << _name << "\"." << std::endl;
148   const char *nat=0;
149   try
150   {
151       nat=MEDCouplingNatureOfField::GetRepr(_nature);
152       stream << "Nature of field template : " << nat << ".\n";
153   }
154   catch(INTERP_KERNEL::Exception& /*e*/)
155   {  }
156   const MEDCouplingFieldDiscretization *fd(_type);
157   if(!fd)
158     stream << "No spatial discretization set !";
159   else
160     fd->reprQuickOverview(stream);
161   stream << std::endl;
162   if(!_mesh)
163     stream << "\nNo mesh support defined !";
164   else
165     {
166       std::ostringstream oss;
167       _mesh->reprQuickOverview(oss);
168       std::string tmp(oss.str());
169       stream << "\nMesh info : " << tmp.substr(0,tmp.find('\n'));
170     }
171 }