1 // Copyright (C) 2007-2023 CEA, EDF
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 (EDF R&D)
21 #include "MEDCouplingFieldTemplate.hxx"
22 #include "MEDCouplingMesh.hxx"
23 #include "MEDCouplingFieldInt32.hxx"
24 #include "MEDCouplingFieldInt64.hxx"
25 #include "MEDCouplingFieldFloat.hxx"
26 #include "MEDCouplingFieldDouble.hxx"
27 #include "MEDCouplingFieldDiscretization.hxx"
31 using namespace MEDCoupling;
33 MEDCouplingFieldTemplate *MEDCouplingFieldTemplate::New(const MEDCouplingFieldDouble& f)
35 return new MEDCouplingFieldTemplate(f,true);
38 MEDCouplingFieldTemplate *MEDCouplingFieldTemplate::New(const MEDCouplingFieldFloat& f)
40 return new MEDCouplingFieldTemplate(f,true);
43 MEDCouplingFieldTemplate *MEDCouplingFieldTemplate::New(const MEDCouplingFieldInt32& f)
45 return new MEDCouplingFieldTemplate(f,true);
48 MEDCouplingFieldTemplate *MEDCouplingFieldTemplate::New(const MEDCouplingFieldInt64& f)
50 return new MEDCouplingFieldTemplate(f,true);
53 MEDCouplingFieldTemplate *MEDCouplingFieldTemplate::NewWithoutCheck(const MEDCouplingFieldDouble& f)
55 return new MEDCouplingFieldTemplate(f,false);
58 MEDCouplingFieldTemplate *MEDCouplingFieldTemplate::NewWithoutCheck(const MEDCouplingFieldFloat& f)
60 return new MEDCouplingFieldTemplate(f,false);
63 MEDCouplingFieldTemplate *MEDCouplingFieldTemplate::NewWithoutCheck(const MEDCouplingFieldInt32& f)
65 return new MEDCouplingFieldTemplate(f,false);
68 MEDCouplingFieldTemplate *MEDCouplingFieldTemplate::NewWithoutCheck(const MEDCouplingFieldInt64& f)
70 return new MEDCouplingFieldTemplate(f,false);
73 bool MEDCouplingFieldTemplate::isEqualIfNotWhy(const MEDCouplingFieldTemplate *other, double meshPrec, std::string& reason) const
75 return isEqualIfNotWhyProtected(other,meshPrec,reason);
78 bool MEDCouplingFieldTemplate::isEqual(const MEDCouplingFieldTemplate *other, double meshPrec) const
81 return isEqualIfNotWhyProtected(other,meshPrec,tmp);
84 bool MEDCouplingFieldTemplate::isEqualWithoutConsideringStr(const MEDCouplingFieldTemplate *other, double meshPrec) const
86 return isEqualWithoutConsideringStrProtected(other,meshPrec);
90 * The user should \b not use this method. Only useful for CORBA serialization/unserialization.
92 MEDCouplingFieldTemplate *MEDCouplingFieldTemplate::New(TypeOfField type)
94 return new MEDCouplingFieldTemplate(type);
97 MEDCouplingFieldTemplate::MEDCouplingFieldTemplate(const MEDCouplingFieldDouble& f, bool isChecked):MEDCouplingField(f,false)
101 checkConsistencyLight();
104 MEDCouplingFieldTemplate::MEDCouplingFieldTemplate(const MEDCouplingFieldFloat& f, bool isChecked):MEDCouplingField(f,false)
108 checkConsistencyLight();
111 MEDCouplingFieldTemplate::MEDCouplingFieldTemplate(const MEDCouplingFieldInt32& f, bool isChecked):MEDCouplingField(f,false)
115 checkConsistencyLight();
118 MEDCouplingFieldTemplate::MEDCouplingFieldTemplate(const MEDCouplingFieldInt64& f, bool isChecked):MEDCouplingField(f,false)
122 checkConsistencyLight();
125 MEDCouplingFieldTemplate::MEDCouplingFieldTemplate(TypeOfField type):MEDCouplingField(type)
129 MEDCouplingFieldTemplate::MEDCouplingFieldTemplate(const MEDCouplingFieldTemplate& other, bool deepCopy):MEDCouplingField(other,deepCopy)
133 void MEDCouplingFieldTemplate::checkConsistencyLight() const
136 throw INTERP_KERNEL::Exception("MEDCouplingFieldTemplate::checkConsistencyLight : Empty mesh !");
139 std::string MEDCouplingFieldTemplate::simpleRepr() const
141 std::ostringstream ret;
142 ret << "FieldTemplate with name : \"" << getName() << "\"\n";
143 ret << "Description of field is : \"" << getDescription() << "\"\n";
145 { ret << "FieldTemplate space discretization is : " << _type->getStringRepr() << "\n"; }
147 { ret << "FieldTemplate has no spatial discretization !\n"; }
148 ret << "FieldTemplate nature of field is : \"" << MEDCouplingNatureOfField::GetReprNoThrow(_nature) << "\"\n";
150 ret << "Mesh support information :\n__________________________\n" << _mesh->simpleRepr();
152 ret << "Mesh support information : No mesh set !\n";
156 std::string MEDCouplingFieldTemplate::advancedRepr() const
161 void MEDCouplingFieldTemplate::getTinySerializationIntInformation(std::vector<mcIdType>& tinyInfo) const
163 if(!((const MEDCouplingFieldDiscretization *)_type))
164 throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform getTinySerializationIntInformation !");
166 tinyInfo.push_back(ToIdType(_type->getEnum()));
167 tinyInfo.push_back(ToIdType(_nature));
168 std::vector<mcIdType> tinyInfo2;
169 _type->getTinySerializationIntInformation(tinyInfo2);
170 tinyInfo.insert(tinyInfo.end(),tinyInfo2.begin(),tinyInfo2.end());
171 tinyInfo.push_back(ToIdType(tinyInfo2.size()));
174 void MEDCouplingFieldTemplate::getTinySerializationDbleInformation(std::vector<double>& tinyInfo) const
176 if(!((const MEDCouplingFieldDiscretization *)_type))
177 throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform getTinySerializationDbleInformation !");
179 _type->getTinySerializationDbleInformation(tinyInfo);
182 void MEDCouplingFieldTemplate::getTinySerializationStrInformation(std::vector<std::string>& tinyInfo) const
185 tinyInfo.push_back(_name);
186 tinyInfo.push_back(_desc);
189 void MEDCouplingFieldTemplate::resizeForUnserialization(const std::vector<mcIdType>& tinyInfoI, DataArrayIdType *&dataInt)
191 if(!((const MEDCouplingFieldDiscretization *)_type))
192 throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform resizeForUnserialization !");
194 std::vector<mcIdType> tinyInfoITmp(tinyInfoI.begin()+2,tinyInfoI.end());
195 _type->resizeForUnserialization(tinyInfoITmp,dataInt);
198 void MEDCouplingFieldTemplate::finishUnserialization(const std::vector<mcIdType>& tinyInfoI, const std::vector<double>& tinyInfoD, const std::vector<std::string>& tinyInfoS)
200 if(!((const MEDCouplingFieldDiscretization *)_type))
201 throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform finishUnserialization !");
202 _nature=(NatureOfField)tinyInfoI[1];
203 _type->finishUnserialization(tinyInfoD);
208 void MEDCouplingFieldTemplate::serialize(DataArrayIdType *&dataInt) const
210 _type->getSerializationIntArray(dataInt);
213 void MEDCouplingFieldTemplate::reprQuickOverview(std::ostream& stream) const
215 stream << "MEDCouplingFieldTemplate C++ instance at " << this << ". Name : \"" << _name << "\"." << std::endl;
219 nat=MEDCouplingNatureOfField::GetRepr(_nature);
220 stream << "Nature of field template : " << nat << ".\n";
222 catch(INTERP_KERNEL::Exception& /*e*/)
224 const MEDCouplingFieldDiscretization *fd(_type);
226 stream << "No spatial discretization set !";
228 fd->reprQuickOverview(stream);
231 stream << "\nNo mesh support defined !";
234 std::ostringstream oss;
235 _mesh->reprQuickOverview(oss);
236 std::string tmp(oss.str());
237 stream << "\nMesh info : " << tmp.substr(0,tmp.find('\n'));
241 MCAuto<MEDCouplingFieldTemplate> MEDCouplingFieldTemplate::clone(bool recDeepCpy) const
243 MCAuto<MEDCouplingFieldTemplate> ret(new MEDCouplingFieldTemplate(*this,recDeepCpy));