1 // Copyright (C) 2007-2012 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.
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
20 #include "MEDCouplingFieldOverTime.hxx"
21 #include "MEDCouplingMesh.hxx"
25 using namespace ParaMEDMEM;
27 MEDCouplingFieldOverTime *MEDCouplingFieldOverTime::New(const std::vector<MEDCouplingFieldDouble *>& fs) throw(INTERP_KERNEL::Exception)
29 return new MEDCouplingFieldOverTime(fs);
32 double MEDCouplingFieldOverTime::getTimeTolerance() const throw(INTERP_KERNEL::Exception)
34 std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> >::const_iterator it=_fs.begin();
36 throw INTERP_KERNEL::Exception("MEDCouplingFieldOverTime::getTimeTolerance : empty set !");
37 for(;it!=_fs.end();it++)
38 if((const MEDCouplingFieldDouble *)(*it)!=0)
39 return (*it)->getTimeTolerance();
40 throw INTERP_KERNEL::Exception("MEDCouplingFieldOverTime::getTimeTolerance : only empty fields in this !");
43 void MEDCouplingFieldOverTime::checkCoherency() const throw(INTERP_KERNEL::Exception)
45 MEDCouplingMultiFields::checkCoherency();
46 std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> >::const_iterator it=_fs.begin();
47 for(;it!=_fs.end();it++)
48 if((*it)->getTimeDiscretization()==NO_TIME)
50 std::ostringstream oss; oss << "MEDCouplingFieldOverTime::checkCoherency : At rank #" << std::distance(_fs.begin(),it) << " the field has no time !";
51 throw INTERP_KERNEL::Exception(oss.str().c_str());
56 const MEDCouplingFieldDouble& ref=*(*(it++));
58 double reft=ref.getEndTime(tt1,tt2);
59 double eps=getTimeTolerance();
61 for(;it!=_fs.end();it++,id++)
63 if(!ref.getMesh()->areCompatibleForMerge((*it)->getMesh()))
65 std::ostringstream oss; oss << "Field slice at rank #" << id << " is not compatible with the first !";
66 throw INTERP_KERNEL::Exception(oss.str().c_str());
68 double curt=(*it)->getStartTime(tt1,tt2);
70 throw INTERP_KERNEL::Exception("MEDCouplingFieldOverTime::checkCoherency : fields are NOT sorted properly in ascending time !");
71 reft=(*it)->getEndTime(tt1,tt2);
75 std::string MEDCouplingFieldOverTime::simpleRepr() const
77 std::ostringstream ret;
78 ret << "MEDCouplingFieldOverTime with name : \"" << getName() << "\"\n";
79 ret << "Description of MEDCouplingFieldOverTime is : \"" << getDescription() << "\"\n";
80 ret << "Number of discretization : " << _fs.size() << "\n";
81 ret << "Number of different meshes : ";
82 std::vector<MEDCouplingMesh *> ms;
83 std::vector<int> refms;
86 ms=getDifferentMeshes(refms);
87 ret << ms.size() << "\n";
89 catch(INTERP_KERNEL::Exception& e)
90 { ret << "Current instance is INVALID !\n"; }
93 MEDCouplingDefinitionTime dt=getDefinitionTimeZone();
96 catch(INTERP_KERNEL::Exception& e)
97 { ret << "Definition zone is INVALID !\n"; }
101 bool MEDCouplingFieldOverTime::isEqual(const MEDCouplingMultiFields *other, double meshPrec, double valsPrec) const
103 if(!MEDCouplingMultiFields::isEqual(other,meshPrec,valsPrec))
105 const MEDCouplingFieldOverTime *otherC=dynamic_cast<const MEDCouplingFieldOverTime *>(other);
112 bool MEDCouplingFieldOverTime::isEqualWithoutConsideringStr(const MEDCouplingMultiFields *other, double meshPrec, double valsPrec) const
114 if(!MEDCouplingMultiFields::isEqualWithoutConsideringStr(other,meshPrec,valsPrec))
116 const MEDCouplingFieldOverTime *otherC=dynamic_cast<const MEDCouplingFieldOverTime *>(other);
123 std::vector<MEDCouplingMesh *> MEDCouplingFieldOverTime::getMeshes() const throw(INTERP_KERNEL::Exception)
126 return MEDCouplingMultiFields::getMeshes();
129 std::vector<MEDCouplingMesh *> MEDCouplingFieldOverTime::getDifferentMeshes(std::vector<int>& refs) const throw(INTERP_KERNEL::Exception)
132 return MEDCouplingMultiFields::getDifferentMeshes(refs);
135 std::vector<DataArrayDouble *> MEDCouplingFieldOverTime::getArrays() const throw(INTERP_KERNEL::Exception)
138 return MEDCouplingMultiFields::getArrays();
141 std::vector<DataArrayDouble *> MEDCouplingFieldOverTime::getDifferentArrays(std::vector< std::vector<int> >& refs) const throw(INTERP_KERNEL::Exception)
144 return MEDCouplingMultiFields::getDifferentArrays(refs);
147 MEDCouplingDefinitionTime MEDCouplingFieldOverTime::getDefinitionTimeZone() const
149 std::vector< std::vector<int> > tmp;
150 getDifferentArrays(tmp);
151 std::vector<const MEDCouplingFieldDouble *> tmp2(_fs.begin(),_fs.end());
152 std::vector<int> tmp3;
153 getDifferentMeshes(tmp3);
154 return MEDCouplingDefinitionTime(tmp2,tmp3,tmp);
157 MEDCouplingFieldOverTime::MEDCouplingFieldOverTime(const std::vector<MEDCouplingFieldDouble *>& fs) throw(INTERP_KERNEL::Exception):MEDCouplingMultiFields(fs)
162 MEDCouplingFieldOverTime::MEDCouplingFieldOverTime()