1 // Copyright (C) 2007-2016 CEA/DEN, EDF R&D
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 // Author : Anthony Geay (CEA/DEN)
21 #include "MEDCouplingFieldTemplate.hxx"
22 #include "MEDCouplingMesh.hxx"
23 #include "MEDCouplingFieldInt.hxx"
24 #include "MEDCouplingFieldFloat.hxx"
25 #include "MEDCouplingFieldDouble.hxx"
26 #include "MEDCouplingFieldDiscretization.hxx"
30 using namespace MEDCoupling;
32 MEDCouplingFieldTemplate *MEDCouplingFieldTemplate::New(const MEDCouplingFieldDouble& f)
34 return new MEDCouplingFieldTemplate(f,true);
37 MEDCouplingFieldTemplate *MEDCouplingFieldTemplate::New(const MEDCouplingFieldFloat& f)
39 return new MEDCouplingFieldTemplate(f,true);
42 MEDCouplingFieldTemplate *MEDCouplingFieldTemplate::New(const MEDCouplingFieldInt& f)
44 return new MEDCouplingFieldTemplate(f,true);
47 MEDCouplingFieldTemplate *MEDCouplingFieldTemplate::NewWithoutCheck(const MEDCouplingFieldDouble& f)
49 return new MEDCouplingFieldTemplate(f,false);
52 MEDCouplingFieldTemplate *MEDCouplingFieldTemplate::NewWithoutCheck(const MEDCouplingFieldFloat& f)
54 return new MEDCouplingFieldTemplate(f,false);
57 MEDCouplingFieldTemplate *MEDCouplingFieldTemplate::NewWithoutCheck(const MEDCouplingFieldInt& f)
59 return new MEDCouplingFieldTemplate(f,false);
63 * The user should \b not use this method. Only useful for CORBA serialization/unserialization.
65 MEDCouplingFieldTemplate *MEDCouplingFieldTemplate::New(TypeOfField type)
67 return new MEDCouplingFieldTemplate(type);
70 MEDCouplingFieldTemplate::MEDCouplingFieldTemplate(const MEDCouplingFieldDouble& f, bool isChecked):MEDCouplingField(f,false)
74 checkConsistencyLight();
77 MEDCouplingFieldTemplate::MEDCouplingFieldTemplate(const MEDCouplingFieldFloat& f, bool isChecked):MEDCouplingField(f,false)
81 checkConsistencyLight();
84 MEDCouplingFieldTemplate::MEDCouplingFieldTemplate(const MEDCouplingFieldInt& f, bool isChecked):MEDCouplingField(f,false)
88 checkConsistencyLight();
91 MEDCouplingFieldTemplate::MEDCouplingFieldTemplate(TypeOfField type):MEDCouplingField(type)
95 MEDCouplingFieldTemplate::MEDCouplingFieldTemplate(const MEDCouplingFieldTemplate& other, bool deepCopy):MEDCouplingField(other,deepCopy)
99 void MEDCouplingFieldTemplate::checkConsistencyLight() const
102 throw INTERP_KERNEL::Exception("MEDCouplingFieldTemplate::checkConsistencyLight : Empty mesh !");
105 std::string MEDCouplingFieldTemplate::simpleRepr() const
107 std::ostringstream ret;
108 ret << "FieldTemplate with name : \"" << getName() << "\"\n";
109 ret << "Description of field is : \"" << getDescription() << "\"\n";
111 { ret << "FieldTemplate space discretization is : " << _type->getStringRepr() << "\n"; }
113 { ret << "FieldTemplate has no spatial discretization !\n"; }
114 ret << "FieldTemplate nature of field is : \"" << MEDCouplingNatureOfField::GetReprNoThrow(_nature) << "\"\n";
116 ret << "Mesh support information :\n__________________________\n" << _mesh->simpleRepr();
118 ret << "Mesh support information : No mesh set !\n";
122 std::string MEDCouplingFieldTemplate::advancedRepr() const
127 void MEDCouplingFieldTemplate::getTinySerializationIntInformation(std::vector<int>& tinyInfo) const
129 if(!((const MEDCouplingFieldDiscretization *)_type))
130 throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform getTinySerializationIntInformation !");
132 tinyInfo.push_back((int)_type->getEnum());
133 tinyInfo.push_back((int)_nature);
134 std::vector<int> tinyInfo2;
135 _type->getTinySerializationIntInformation(tinyInfo2);
136 tinyInfo.insert(tinyInfo.end(),tinyInfo2.begin(),tinyInfo2.end());
137 tinyInfo.push_back((int)tinyInfo2.size());
140 void MEDCouplingFieldTemplate::getTinySerializationDbleInformation(std::vector<double>& tinyInfo) const
142 if(!((const MEDCouplingFieldDiscretization *)_type))
143 throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform getTinySerializationDbleInformation !");
145 _type->getTinySerializationDbleInformation(tinyInfo);
148 void MEDCouplingFieldTemplate::getTinySerializationStrInformation(std::vector<std::string>& tinyInfo) const
151 tinyInfo.push_back(_name);
152 tinyInfo.push_back(_desc);
155 void MEDCouplingFieldTemplate::resizeForUnserialization(const std::vector<int>& tinyInfoI, DataArrayInt *&dataInt)
157 if(!((const MEDCouplingFieldDiscretization *)_type))
158 throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform resizeForUnserialization !");
160 std::vector<int> tinyInfoITmp(tinyInfoI.begin()+2,tinyInfoI.end());
161 _type->resizeForUnserialization(tinyInfoITmp,dataInt);
164 void MEDCouplingFieldTemplate::finishUnserialization(const std::vector<int>& tinyInfoI, const std::vector<double>& tinyInfoD, const std::vector<std::string>& tinyInfoS)
166 if(!((const MEDCouplingFieldDiscretization *)_type))
167 throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform finishUnserialization !");
168 _nature=(NatureOfField)tinyInfoI[1];
169 _type->finishUnserialization(tinyInfoD);
174 void MEDCouplingFieldTemplate::serialize(DataArrayInt *&dataInt) const
176 _type->getSerializationIntArray(dataInt);
179 void MEDCouplingFieldTemplate::reprQuickOverview(std::ostream& stream) const
181 stream << "MEDCouplingFieldTemplate C++ instance at " << this << ". Name : \"" << _name << "\"." << std::endl;
185 nat=MEDCouplingNatureOfField::GetRepr(_nature);
186 stream << "Nature of field template : " << nat << ".\n";
188 catch(INTERP_KERNEL::Exception& /*e*/)
190 const MEDCouplingFieldDiscretization *fd(_type);
192 stream << "No spatial discretization set !";
194 fd->reprQuickOverview(stream);
197 stream << "\nNo mesh support defined !";
200 std::ostringstream oss;
201 _mesh->reprQuickOverview(oss);
202 std::string tmp(oss.str());
203 stream << "\nMesh info : " << tmp.substr(0,tmp.find('\n'));
207 MCAuto<MEDCouplingFieldTemplate> MEDCouplingFieldTemplate::clone(bool recDeepCpy) const
209 MCAuto<MEDCouplingFieldTemplate> ret(new MEDCouplingFieldTemplate(*this,recDeepCpy));