Salome HOME
aab9a45f1e5091a25616ca5d74f6b183541acce3
[tools/medcoupling.git] / src / MEDCoupling / MEDCouplingFieldInt.cxx
1 // Copyright (C) 2007-2016  CEA/DEN, EDF R&D
2 //
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.
7 //
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.
12 //
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
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19 // Author : Yann Pora (EDF R&D)
20
21 #include "MEDCouplingFieldInt.hxx"
22 #include "MEDCouplingFieldTemplate.hxx"
23 #include "MEDCouplingMesh.hxx"
24
25 using namespace MEDCoupling;
26
27 MEDCouplingFieldInt *MEDCouplingFieldInt::New(TypeOfField type, TypeOfTimeDiscretization td)
28 {
29   return new MEDCouplingFieldInt(type,td);
30 }
31
32 MEDCouplingFieldInt *MEDCouplingFieldInt::New(const MEDCouplingFieldTemplate& ft, TypeOfTimeDiscretization td)
33 {
34   return new MEDCouplingFieldInt(ft,td);
35 }
36
37 void MEDCouplingFieldInt::checkConsistencyLight() const
38 {
39   MEDCouplingField::checkConsistencyLight();
40   _time_discr->checkConsistencyLight();
41   _type->checkCoherencyBetween(_mesh,getArray());
42 }
43
44 std::string MEDCouplingFieldInt::simpleRepr() const
45 {
46   std::ostringstream ret;
47   ret << "FieldInt with name : \"" << getName() << "\"\n";
48   ret << "Description of field is : \"" << getDescription() << "\"\n";
49   if(_type)
50     { ret << "FieldInt space discretization is : " << _type->getStringRepr() << "\n"; }
51   else
52     { ret << "FieldInt has no spatial discretization !\n"; }
53   if(_time_discr)
54     { ret << "FieldInt time discretization is : " << _time_discr->getStringRepr() << "\n"; }
55   else
56     { ret << "FieldInt has no time discretization !\n"; }
57   ret << "FieldInt nature of field is : \"" << MEDCouplingNatureOfField::GetReprNoThrow(_nature) << "\"\n";
58   if(getArray())
59     {
60       if(getArray()->isAllocated())
61         {
62           int nbOfCompo=getArray()->getNumberOfComponents();
63           ret << "FieldInt default array has " << nbOfCompo << " components and " << getArray()->getNumberOfTuples() << " tuples.\n";
64           ret << "FieldInt default array has following info on components : ";
65           for(int i=0;i<nbOfCompo;i++)
66             ret << "\"" << getArray()->getInfoOnComponent(i) << "\" ";
67           ret << "\n";
68         }
69       else
70         {
71           ret << "Array set but not allocated !\n";
72         }
73     }
74   if(_mesh)
75     ret << "Mesh support information :\n__________________________\n" << _mesh->simpleRepr();
76   else
77     ret << "Mesh support information : No mesh set !\n";
78   return ret.str();
79 }
80
81 void MEDCouplingFieldInt::reprQuickOverview(std::ostream& stream) const
82 {
83 }
84
85 void MEDCouplingFieldInt::setTimeUnit(const std::string& unit)
86 {
87   _time_discr->setTimeUnit(unit);
88 }
89
90 std::string MEDCouplingFieldInt::getTimeUnit() const
91 {
92   return _time_discr->getTimeUnit();
93 }
94
95 void MEDCouplingFieldInt::setTime(double val, int iteration, int order) 
96
97   _time_discr->setTime(val,iteration,order); 
98 }
99
100 double MEDCouplingFieldInt::getTime(int& iteration, int& order) const
101 {
102   return _time_discr->getTime(iteration,order);
103 }
104
105 void MEDCouplingFieldInt::setArray(DataArrayInt *array)
106 {
107   _time_discr->setArray(array,this);
108 }
109
110 const DataArrayInt *MEDCouplingFieldInt::getArray() const
111 {
112   return _time_discr->getArray();
113 }
114
115 DataArrayInt *MEDCouplingFieldInt::getArray()
116 {
117   return _time_discr->getArray();
118 }
119
120 MEDCouplingFieldInt::MEDCouplingFieldInt(TypeOfField type, TypeOfTimeDiscretization td):MEDCouplingField(type),_time_discr(MEDCouplingTimeDiscretizationInt::New(td))
121 {
122 }
123
124 MEDCouplingFieldInt::MEDCouplingFieldInt(const MEDCouplingFieldInt& other, bool deepCopy):MEDCouplingField(other,deepCopy),_time_discr(dynamic_cast<MEDCouplingTimeDiscretizationInt *>(other._time_discr->performCopyOrIncrRef(deepCopy)))
125 {
126 }
127
128 MEDCouplingFieldInt::MEDCouplingFieldInt(NatureOfField n, MEDCouplingTimeDiscretizationInt *td, MEDCouplingFieldDiscretization *type):MEDCouplingField(type,n),_time_discr(td)
129 {
130 }
131
132 MEDCouplingFieldInt::~MEDCouplingFieldInt()
133 {
134   delete _time_discr;
135 }
136
137 /*!
138  * ** WARINING : This method do not deeply copy neither mesh nor spatial discretization. Only a shallow copy (reference) is done for mesh and spatial discretization ! **
139  */
140 MEDCouplingFieldInt::MEDCouplingFieldInt(const MEDCouplingFieldTemplate& ft, TypeOfTimeDiscretization td):MEDCouplingField(ft,false),_time_discr(MEDCouplingTimeDiscretizationInt::New(td))
141 {
142 }