1 // Copyright (C) 2007-2014 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 "MEDCouplingFieldOverTime.hxx"
22 #include "MEDCouplingMesh.hxx"
26 using namespace ParaMEDMEM;
28 MEDCouplingFieldOverTime *MEDCouplingFieldOverTime::New(const std::vector<MEDCouplingFieldDouble *>& fs)
30 return new MEDCouplingFieldOverTime(fs);
33 double MEDCouplingFieldOverTime::getTimeTolerance() const
35 std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> >::const_iterator it=_fs.begin();
37 throw INTERP_KERNEL::Exception("MEDCouplingFieldOverTime::getTimeTolerance : empty set !");
38 for(;it!=_fs.end();it++)
39 if((const MEDCouplingFieldDouble *)(*it)!=0)
40 return (*it)->getTimeTolerance();
41 throw INTERP_KERNEL::Exception("MEDCouplingFieldOverTime::getTimeTolerance : only empty fields in this !");
44 void MEDCouplingFieldOverTime::checkCoherency() const
46 MEDCouplingMultiFields::checkCoherency();
47 std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> >::const_iterator it=_fs.begin();
48 for(;it!=_fs.end();it++)
49 if((*it)->getTimeDiscretization()==NO_TIME)
51 std::ostringstream oss; oss << "MEDCouplingFieldOverTime::checkCoherency : At rank #" << std::distance(_fs.begin(),it) << " the field has no time !";
52 throw INTERP_KERNEL::Exception(oss.str().c_str());
57 const MEDCouplingFieldDouble& ref=*(*(it++));
59 double reft=ref.getEndTime(tt1,tt2);
60 double eps=getTimeTolerance();
62 for(;it!=_fs.end();it++,id++)
64 if(!ref.getMesh()->areCompatibleForMerge((*it)->getMesh()))
66 std::ostringstream oss; oss << "Field slice at rank #" << id << " is not compatible with the first !";
67 throw INTERP_KERNEL::Exception(oss.str().c_str());
69 double curt=(*it)->getStartTime(tt1,tt2);
71 throw INTERP_KERNEL::Exception("MEDCouplingFieldOverTime::checkCoherency : fields are NOT sorted properly in ascending time !");
72 reft=(*it)->getEndTime(tt1,tt2);
76 std::string MEDCouplingFieldOverTime::simpleRepr() const
78 std::ostringstream ret;
79 ret << "MEDCouplingFieldOverTime with name : \"" << getName() << "\"\n";
80 ret << "Description of MEDCouplingFieldOverTime is : \"" << getDescription() << "\"\n";
81 ret << "Number of discretization : " << _fs.size() << "\n";
82 ret << "Number of different meshes : ";
83 std::vector<MEDCouplingMesh *> ms;
84 std::vector<int> refms;
87 ms=getDifferentMeshes(refms);
88 ret << ms.size() << "\n";
90 catch(INTERP_KERNEL::Exception& /*e*/)
91 { ret << "Current instance is INVALID !\n"; }
94 MEDCouplingDefinitionTime dt=getDefinitionTimeZone();
97 catch(INTERP_KERNEL::Exception& /*e*/)
98 { ret << "Definition zone is INVALID !\n"; }
102 bool MEDCouplingFieldOverTime::isEqual(const MEDCouplingMultiFields *other, double meshPrec, double valsPrec) const
104 if(!MEDCouplingMultiFields::isEqual(other,meshPrec,valsPrec))
106 const MEDCouplingFieldOverTime *otherC=dynamic_cast<const MEDCouplingFieldOverTime *>(other);
113 bool MEDCouplingFieldOverTime::isEqualWithoutConsideringStr(const MEDCouplingMultiFields *other, double meshPrec, double valsPrec) const
115 if(!MEDCouplingMultiFields::isEqualWithoutConsideringStr(other,meshPrec,valsPrec))
117 const MEDCouplingFieldOverTime *otherC=dynamic_cast<const MEDCouplingFieldOverTime *>(other);
124 std::vector<MEDCouplingMesh *> MEDCouplingFieldOverTime::getMeshes() const
127 return MEDCouplingMultiFields::getMeshes();
130 std::vector<MEDCouplingMesh *> MEDCouplingFieldOverTime::getDifferentMeshes(std::vector<int>& refs) const
133 return MEDCouplingMultiFields::getDifferentMeshes(refs);
136 std::vector<DataArrayDouble *> MEDCouplingFieldOverTime::getArrays() const
139 return MEDCouplingMultiFields::getArrays();
142 std::vector<DataArrayDouble *> MEDCouplingFieldOverTime::getDifferentArrays(std::vector< std::vector<int> >& refs) const
145 return MEDCouplingMultiFields::getDifferentArrays(refs);
148 MEDCouplingDefinitionTime MEDCouplingFieldOverTime::getDefinitionTimeZone() const
150 std::vector< std::vector<int> > tmp;
151 getDifferentArrays(tmp);
152 std::vector<const MEDCouplingFieldDouble *> tmp2(_fs.begin(),_fs.end());
153 std::vector<int> tmp3;
154 getDifferentMeshes(tmp3);
155 return MEDCouplingDefinitionTime(tmp2,tmp3,tmp);
158 MEDCouplingFieldOverTime::MEDCouplingFieldOverTime(const std::vector<MEDCouplingFieldDouble *>& fs):MEDCouplingMultiFields(fs)
163 MEDCouplingFieldOverTime::MEDCouplingFieldOverTime()