1 // Copyright (C) 2007-2019 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);
62 bool MEDCouplingFieldTemplate::isEqualIfNotWhy(const MEDCouplingFieldTemplate *other, double meshPrec, std::string& reason) const
64 return isEqualIfNotWhyProtected(other,meshPrec,reason);
67 bool MEDCouplingFieldTemplate::isEqual(const MEDCouplingFieldTemplate *other, double meshPrec) const
70 return isEqualIfNotWhyProtected(other,meshPrec,tmp);
73 bool MEDCouplingFieldTemplate::isEqualWithoutConsideringStr(const MEDCouplingFieldTemplate *other, double meshPrec) const
75 return isEqualWithoutConsideringStrProtected(other,meshPrec);
79 * The user should \b not use this method. Only useful for CORBA serialization/unserialization.
81 MEDCouplingFieldTemplate *MEDCouplingFieldTemplate::New(TypeOfField type)
83 return new MEDCouplingFieldTemplate(type);
86 MEDCouplingFieldTemplate::MEDCouplingFieldTemplate(const MEDCouplingFieldDouble& f, bool isChecked):MEDCouplingField(f,false)
90 checkConsistencyLight();
93 MEDCouplingFieldTemplate::MEDCouplingFieldTemplate(const MEDCouplingFieldFloat& f, bool isChecked):MEDCouplingField(f,false)
97 checkConsistencyLight();
100 MEDCouplingFieldTemplate::MEDCouplingFieldTemplate(const MEDCouplingFieldInt& f, bool isChecked):MEDCouplingField(f,false)
104 checkConsistencyLight();
107 MEDCouplingFieldTemplate::MEDCouplingFieldTemplate(TypeOfField type):MEDCouplingField(type)
111 MEDCouplingFieldTemplate::MEDCouplingFieldTemplate(const MEDCouplingFieldTemplate& other, bool deepCopy):MEDCouplingField(other,deepCopy)
115 void MEDCouplingFieldTemplate::checkConsistencyLight() const
118 throw INTERP_KERNEL::Exception("MEDCouplingFieldTemplate::checkConsistencyLight : Empty mesh !");
121 std::string MEDCouplingFieldTemplate::simpleRepr() const
123 std::ostringstream ret;
124 ret << "FieldTemplate with name : \"" << getName() << "\"\n";
125 ret << "Description of field is : \"" << getDescription() << "\"\n";
127 { ret << "FieldTemplate space discretization is : " << _type->getStringRepr() << "\n"; }
129 { ret << "FieldTemplate has no spatial discretization !\n"; }
130 ret << "FieldTemplate nature of field is : \"" << MEDCouplingNatureOfField::GetReprNoThrow(_nature) << "\"\n";
132 ret << "Mesh support information :\n__________________________\n" << _mesh->simpleRepr();
134 ret << "Mesh support information : No mesh set !\n";
138 std::string MEDCouplingFieldTemplate::advancedRepr() const
143 void MEDCouplingFieldTemplate::getTinySerializationIntInformation(std::vector<mcIdType>& tinyInfo) const
145 if(!((const MEDCouplingFieldDiscretization *)_type))
146 throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform getTinySerializationIntInformation !");
148 tinyInfo.push_back(ToIdType(_type->getEnum()));
149 tinyInfo.push_back(ToIdType(_nature));
150 std::vector<mcIdType> tinyInfo2;
151 _type->getTinySerializationIntInformation(tinyInfo2);
152 tinyInfo.insert(tinyInfo.end(),tinyInfo2.begin(),tinyInfo2.end());
153 tinyInfo.push_back(ToIdType(tinyInfo2.size()));
156 void MEDCouplingFieldTemplate::getTinySerializationDbleInformation(std::vector<double>& tinyInfo) const
158 if(!((const MEDCouplingFieldDiscretization *)_type))
159 throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform getTinySerializationDbleInformation !");
161 _type->getTinySerializationDbleInformation(tinyInfo);
164 void MEDCouplingFieldTemplate::getTinySerializationStrInformation(std::vector<std::string>& tinyInfo) const
167 tinyInfo.push_back(_name);
168 tinyInfo.push_back(_desc);
171 void MEDCouplingFieldTemplate::resizeForUnserialization(const std::vector<mcIdType>& tinyInfoI, DataArrayIdType *&dataInt)
173 if(!((const MEDCouplingFieldDiscretization *)_type))
174 throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform resizeForUnserialization !");
176 std::vector<mcIdType> tinyInfoITmp(tinyInfoI.begin()+2,tinyInfoI.end());
177 _type->resizeForUnserialization(tinyInfoITmp,dataInt);
180 void MEDCouplingFieldTemplate::finishUnserialization(const std::vector<mcIdType>& tinyInfoI, const std::vector<double>& tinyInfoD, const std::vector<std::string>& tinyInfoS)
182 if(!((const MEDCouplingFieldDiscretization *)_type))
183 throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform finishUnserialization !");
184 _nature=(NatureOfField)tinyInfoI[1];
185 _type->finishUnserialization(tinyInfoD);
190 void MEDCouplingFieldTemplate::serialize(DataArrayIdType *&dataInt) const
192 _type->getSerializationIntArray(dataInt);
195 void MEDCouplingFieldTemplate::reprQuickOverview(std::ostream& stream) const
197 stream << "MEDCouplingFieldTemplate C++ instance at " << this << ". Name : \"" << _name << "\"." << std::endl;
201 nat=MEDCouplingNatureOfField::GetRepr(_nature);
202 stream << "Nature of field template : " << nat << ".\n";
204 catch(INTERP_KERNEL::Exception& /*e*/)
206 const MEDCouplingFieldDiscretization *fd(_type);
208 stream << "No spatial discretization set !";
210 fd->reprQuickOverview(stream);
213 stream << "\nNo mesh support defined !";
216 std::ostringstream oss;
217 _mesh->reprQuickOverview(oss);
218 std::string tmp(oss.str());
219 stream << "\nMesh info : " << tmp.substr(0,tmp.find('\n'));
223 MCAuto<MEDCouplingFieldTemplate> MEDCouplingFieldTemplate::clone(bool recDeepCpy) const
225 MCAuto<MEDCouplingFieldTemplate> ret(new MEDCouplingFieldTemplate(*this,recDeepCpy));