1 // Copyright (C) 2007-2008 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
19 #include "MEDCouplingFieldDouble.hxx"
20 #include "MEDCouplingMesh.hxx"
24 using namespace ParaMEDMEM;
26 MEDCouplingFieldDouble *MEDCouplingFieldDouble::New(TypeOfField type)
28 return new MEDCouplingFieldDouble(type);
31 MEDCouplingFieldDouble::MEDCouplingFieldDouble(TypeOfField type):MEDCouplingField(type),_array(0)
35 MEDCouplingFieldDouble::~MEDCouplingFieldDouble()
41 void MEDCouplingFieldDouble::checkCoherency() const throw(INTERP_KERNEL::Exception)
44 throw INTERP_KERNEL::Exception("Field invalid because no mesh specified !");
46 throw INTERP_KERNEL::Exception("Field invalid because no values set !");
49 if(_mesh->getNumberOfCells()!=_array->getNumberOfTuples())
51 std::ostringstream message;
52 message << "Field on cells invalid because there are " << _mesh->getNumberOfCells();
53 message << " cells in mesh and " << _array->getNumberOfTuples() << " tuples in field !";
54 throw INTERP_KERNEL::Exception(message.str().c_str());
57 else if(_type==ON_NODES)
59 if(_mesh->getNumberOfNodes()!=_array->getNumberOfTuples())
61 std::ostringstream message;
62 message << "Field on nodes invalid because there are " << _mesh->getNumberOfNodes();
63 message << " cells in mesh and " << _array->getNumberOfTuples() << " tuples in field !";
64 throw INTERP_KERNEL::Exception(message.str().c_str());
68 throw INTERP_KERNEL::Exception("Field of undifined type !!!");
71 void MEDCouplingFieldDouble::applyLin(double a, double b, int compoId)
73 double *ptr=_array->getPointer();
75 int nbOfComp=_array->getNumberOfComponents();
76 int nbOfTuple=_array->getNumberOfTuples();
77 for(int i=0;i<nbOfTuple;i++,ptr+=nbOfComp)
81 int MEDCouplingFieldDouble::getNumberOfComponents() const
83 return _array->getNumberOfComponents();
86 int MEDCouplingFieldDouble::getNumberOfTuples() const throw(INTERP_KERNEL::Exception)
89 throw INTERP_KERNEL::Exception("Impossible to retrieve number of tuples because no mesh specified !");
91 return _mesh->getNumberOfCells();
92 else if(_type==ON_NODES)
93 return _mesh->getNumberOfNodes();
95 throw INTERP_KERNEL::Exception("Impossible to retrieve number of tuples because type of entity not implemented yet !");
98 void MEDCouplingFieldDouble::updateTime()
100 MEDCouplingField::updateTime();
102 updateTimeWith(*_array);
105 void MEDCouplingFieldDouble::setArray(DataArrayDouble *array)