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);
37 MEDCouplingFieldTemplate *MEDCouplingFieldTemplate::New(const MEDCouplingFieldFloat& f)
39 return new MEDCouplingFieldTemplate(f);
42 MEDCouplingFieldTemplate *MEDCouplingFieldTemplate::New(const MEDCouplingFieldInt& f)
44 return new MEDCouplingFieldTemplate(f);
48 * The user should \b not use this method. Only useful for CORBA serialization/unserialization.
50 MEDCouplingFieldTemplate *MEDCouplingFieldTemplate::New(TypeOfField type)
52 return new MEDCouplingFieldTemplate(type);
55 MEDCouplingFieldTemplate::MEDCouplingFieldTemplate(const MEDCouplingFieldDouble& f):MEDCouplingField(f,false)
58 checkConsistencyLight();
61 MEDCouplingFieldTemplate::MEDCouplingFieldTemplate(const MEDCouplingFieldFloat& f):MEDCouplingField(f,false)
64 checkConsistencyLight();
67 MEDCouplingFieldTemplate::MEDCouplingFieldTemplate(const MEDCouplingFieldInt& f):MEDCouplingField(f,false)
70 checkConsistencyLight();
73 MEDCouplingFieldTemplate::MEDCouplingFieldTemplate(TypeOfField type):MEDCouplingField(type)
77 void MEDCouplingFieldTemplate::checkConsistencyLight() const
80 throw INTERP_KERNEL::Exception("MEDCouplingFieldTemplate::checkConsistencyLight : Empty mesh !");
83 std::string MEDCouplingFieldTemplate::simpleRepr() const
85 std::ostringstream ret;
86 ret << "FieldTemplate with name : \"" << getName() << "\"\n";
87 ret << "Description of field is : \"" << getDescription() << "\"\n";
89 { ret << "FieldTemplate space discretization is : " << _type->getStringRepr() << "\n"; }
91 { ret << "FieldTemplate has no spatial discretization !\n"; }
92 ret << "FieldTemplate nature of field is : \"" << MEDCouplingNatureOfField::GetReprNoThrow(_nature) << "\"\n";
94 ret << "Mesh support information :\n__________________________\n" << _mesh->simpleRepr();
96 ret << "Mesh support information : No mesh set !\n";
100 std::string MEDCouplingFieldTemplate::advancedRepr() const
105 void MEDCouplingFieldTemplate::getTinySerializationIntInformation(std::vector<int>& tinyInfo) const
107 if(!((const MEDCouplingFieldDiscretization *)_type))
108 throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform getTinySerializationIntInformation !");
110 tinyInfo.push_back((int)_type->getEnum());
111 tinyInfo.push_back((int)_nature);
112 std::vector<int> tinyInfo2;
113 _type->getTinySerializationIntInformation(tinyInfo2);
114 tinyInfo.insert(tinyInfo.end(),tinyInfo2.begin(),tinyInfo2.end());
115 tinyInfo.push_back((int)tinyInfo2.size());
118 void MEDCouplingFieldTemplate::getTinySerializationDbleInformation(std::vector<double>& tinyInfo) const
120 if(!((const MEDCouplingFieldDiscretization *)_type))
121 throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform getTinySerializationDbleInformation !");
123 _type->getTinySerializationDbleInformation(tinyInfo);
126 void MEDCouplingFieldTemplate::getTinySerializationStrInformation(std::vector<std::string>& tinyInfo) const
129 tinyInfo.push_back(_name);
130 tinyInfo.push_back(_desc);
133 void MEDCouplingFieldTemplate::resizeForUnserialization(const std::vector<int>& tinyInfoI, DataArrayInt *&dataInt)
135 if(!((const MEDCouplingFieldDiscretization *)_type))
136 throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform resizeForUnserialization !");
138 std::vector<int> tinyInfoITmp(tinyInfoI.begin()+2,tinyInfoI.end());
139 _type->resizeForUnserialization(tinyInfoITmp,dataInt);
142 void MEDCouplingFieldTemplate::finishUnserialization(const std::vector<int>& tinyInfoI, const std::vector<double>& tinyInfoD, const std::vector<std::string>& tinyInfoS)
144 if(!((const MEDCouplingFieldDiscretization *)_type))
145 throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform finishUnserialization !");
146 _nature=(NatureOfField)tinyInfoI[1];
147 _type->finishUnserialization(tinyInfoD);
152 void MEDCouplingFieldTemplate::serialize(DataArrayInt *&dataInt) const
154 _type->getSerializationIntArray(dataInt);
157 void MEDCouplingFieldTemplate::reprQuickOverview(std::ostream& stream) const
159 stream << "MEDCouplingFieldTemplate C++ instance at " << this << ". Name : \"" << _name << "\"." << std::endl;
163 nat=MEDCouplingNatureOfField::GetRepr(_nature);
164 stream << "Nature of field template : " << nat << ".\n";
166 catch(INTERP_KERNEL::Exception& /*e*/)
168 const MEDCouplingFieldDiscretization *fd(_type);
170 stream << "No spatial discretization set !";
172 fd->reprQuickOverview(stream);
175 stream << "\nNo mesh support defined !";
178 std::ostringstream oss;
179 _mesh->reprQuickOverview(oss);
180 std::string tmp(oss.str());
181 stream << "\nMesh info : " << tmp.substr(0,tmp.find('\n'));