Salome HOME
Some factorization before integration of ParaMEDMEM into medcoupling python module
[tools/medcoupling.git] / src / MEDCoupling / MEDCouplingFieldTemplate.cxx
index e15615a902561b23492f5ad23c2cc4066a52c90d..a9871a43dba95729246d7dfff5fd40a3fcbb8659 100644 (file)
@@ -1,9 +1,9 @@
-// Copyright (C) 2007-2012  CEA/DEN, EDF R&D
+// Copyright (C) 2007-2016  CEA/DEN, EDF R&D
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
 // License as published by the Free Software Foundation; either
-// version 2.1 of the License.
+// version 2.1 of the License, or (at your option) any later version.
 //
 // This library is distributed in the hope that it will be useful,
 // but WITHOUT ANY WARRANTY; without even the implied warranty of
 
 #include "MEDCouplingFieldTemplate.hxx"
 #include "MEDCouplingMesh.hxx"
+#include "MEDCouplingFieldInt.hxx"
+#include "MEDCouplingFieldFloat.hxx"
 #include "MEDCouplingFieldDouble.hxx"
 #include "MEDCouplingFieldDiscretization.hxx"
 
 #include <sstream>
 
-using namespace ParaMEDMEM;
+using namespace MEDCoupling;
 
-MEDCouplingFieldTemplate *MEDCouplingFieldTemplate::New(const MEDCouplingFieldDouble& f) throw(INTERP_KERNEL::Exception)
+MEDCouplingFieldTemplate *MEDCouplingFieldTemplate::New(const MEDCouplingFieldDouble& f)
 {
-  return new MEDCouplingFieldTemplate(f);
+  return new MEDCouplingFieldTemplate(f,true);
+}
+
+MEDCouplingFieldTemplate *MEDCouplingFieldTemplate::New(const MEDCouplingFieldFloat& f)
+{
+  return new MEDCouplingFieldTemplate(f,true);
+}
+
+MEDCouplingFieldTemplate *MEDCouplingFieldTemplate::New(const MEDCouplingFieldInt& f)
+{
+  return new MEDCouplingFieldTemplate(f,true);
+}
+
+MEDCouplingFieldTemplate *MEDCouplingFieldTemplate::NewWithoutCheck(const MEDCouplingFieldDouble& f)
+{
+  return new MEDCouplingFieldTemplate(f,false);
+}
+
+MEDCouplingFieldTemplate *MEDCouplingFieldTemplate::NewWithoutCheck(const MEDCouplingFieldFloat& f)
+{
+  return new MEDCouplingFieldTemplate(f,false);
+}
+
+MEDCouplingFieldTemplate *MEDCouplingFieldTemplate::NewWithoutCheck(const MEDCouplingFieldInt& f)
+{
+  return new MEDCouplingFieldTemplate(f,false);
+}
+
+bool MEDCouplingFieldTemplate::isEqualIfNotWhy(const MEDCouplingFieldTemplate *other, double meshPrec, std::string& reason) const
+{
+  return isEqualIfNotWhyProtected(other,meshPrec,reason);
+}
+
+bool MEDCouplingFieldTemplate::isEqual(const MEDCouplingFieldTemplate *other, double meshPrec) const
+{
+  std::string tmp;
+  return isEqualIfNotWhyProtected(other,meshPrec,tmp);
+}
+
+bool MEDCouplingFieldTemplate::isEqualWithoutConsideringStr(const MEDCouplingFieldTemplate *other, double meshPrec) const
+{
+  return isEqualWithoutConsideringStrProtected(other,meshPrec);
 }
 
 /*!
@@ -40,20 +83,39 @@ MEDCouplingFieldTemplate *MEDCouplingFieldTemplate::New(TypeOfField type)
   return new MEDCouplingFieldTemplate(type);
 }
 
-MEDCouplingFieldTemplate::MEDCouplingFieldTemplate(const MEDCouplingFieldDouble& f) throw(INTERP_KERNEL::Exception):MEDCouplingField(f,false) 
+MEDCouplingFieldTemplate::MEDCouplingFieldTemplate(const MEDCouplingFieldDouble& f, bool isChecked):MEDCouplingField(f,false) 
+{
+  forceTimeOfThis(f);
+  if(isChecked)
+    checkConsistencyLight();
+}
+
+MEDCouplingFieldTemplate::MEDCouplingFieldTemplate(const MEDCouplingFieldFloat& f, bool isChecked):MEDCouplingField(f,false) 
 {
   forceTimeOfThis(f);
-  checkCoherency();
+  if(isChecked)
+    checkConsistencyLight();
+}
+
+MEDCouplingFieldTemplate::MEDCouplingFieldTemplate(const MEDCouplingFieldInt& f, bool isChecked):MEDCouplingField(f,false) 
+{
+  forceTimeOfThis(f);
+  if(isChecked)
+    checkConsistencyLight();
 }
 
 MEDCouplingFieldTemplate::MEDCouplingFieldTemplate(TypeOfField type):MEDCouplingField(type)
 {
 }
 
-void MEDCouplingFieldTemplate::checkCoherency() const throw(INTERP_KERNEL::Exception)
+MEDCouplingFieldTemplate::MEDCouplingFieldTemplate(const MEDCouplingFieldTemplate& other, bool deepCopy):MEDCouplingField(other,deepCopy)
+{
+}
+
+void MEDCouplingFieldTemplate::checkConsistencyLight() const
 {
   if(_mesh==0)
-    throw INTERP_KERNEL::Exception("MEDCouplingFieldTemplate::checkCoherency : Empty mesh !");
+    throw INTERP_KERNEL::Exception("MEDCouplingFieldTemplate::checkConsistencyLight : Empty mesh !");
 }
 
 std::string MEDCouplingFieldTemplate::simpleRepr() const
@@ -61,8 +123,11 @@ std::string MEDCouplingFieldTemplate::simpleRepr() const
   std::ostringstream ret;
   ret << "FieldTemplate with name : \"" << getName() << "\"\n";
   ret << "Description of field is : \"" << getDescription() << "\"\n";
-  ret << "FieldTemplate space discretization is : " << _type->getStringRepr() << "\n";
-  ret << "FieldTemplate nature of field is : " << MEDCouplingNatureOfField::GetRepr(_nature) << "\n";
+  if(_type)
+    { ret << "FieldTemplate space discretization is : " << _type->getStringRepr() << "\n"; }
+  else
+    { ret << "FieldTemplate has no spatial discretization !\n"; }
+  ret << "FieldTemplate nature of field is : \"" << MEDCouplingNatureOfField::GetReprNoThrow(_nature) << "\"\n";
   if(_mesh)
     ret << "Mesh support information :\n__________________________\n" << _mesh->simpleRepr();
   else
@@ -77,6 +142,8 @@ std::string MEDCouplingFieldTemplate::advancedRepr() const
 
 void MEDCouplingFieldTemplate::getTinySerializationIntInformation(std::vector<int>& tinyInfo) const
 {
+  if(!((const MEDCouplingFieldDiscretization *)_type))
+    throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform getTinySerializationIntInformation !");
   tinyInfo.clear();
   tinyInfo.push_back((int)_type->getEnum());
   tinyInfo.push_back((int)_nature);
@@ -88,6 +155,8 @@ void MEDCouplingFieldTemplate::getTinySerializationIntInformation(std::vector<in
 
 void MEDCouplingFieldTemplate::getTinySerializationDbleInformation(std::vector<double>& tinyInfo) const
 {
+  if(!((const MEDCouplingFieldDiscretization *)_type))
+    throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform getTinySerializationDbleInformation !");
   tinyInfo.clear();
   _type->getTinySerializationDbleInformation(tinyInfo);
 }
@@ -101,6 +170,8 @@ void MEDCouplingFieldTemplate::getTinySerializationStrInformation(std::vector<st
 
 void MEDCouplingFieldTemplate::resizeForUnserialization(const std::vector<int>& tinyInfoI, DataArrayInt *&dataInt)
 {
+  if(!((const MEDCouplingFieldDiscretization *)_type))
+    throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform resizeForUnserialization !");
   dataInt=0;
   std::vector<int> tinyInfoITmp(tinyInfoI.begin()+2,tinyInfoI.end());
   _type->resizeForUnserialization(tinyInfoITmp,dataInt);
@@ -108,6 +179,8 @@ void MEDCouplingFieldTemplate::resizeForUnserialization(const std::vector<int>&
 
 void MEDCouplingFieldTemplate::finishUnserialization(const std::vector<int>& tinyInfoI, const std::vector<double>& tinyInfoD, const std::vector<std::string>& tinyInfoS)
 {
+  if(!((const MEDCouplingFieldDiscretization *)_type))
+    throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform finishUnserialization !");
   _nature=(NatureOfField)tinyInfoI[1];
   _type->finishUnserialization(tinyInfoD);
   _name=tinyInfoS[0];
@@ -119,3 +192,36 @@ void MEDCouplingFieldTemplate::serialize(DataArrayInt *&dataInt) const
   _type->getSerializationIntArray(dataInt);
 }
 
+void MEDCouplingFieldTemplate::reprQuickOverview(std::ostream& stream) const
+{
+  stream << "MEDCouplingFieldTemplate C++ instance at " << this << ". Name : \"" << _name << "\"." << std::endl;
+  const char *nat=0;
+  try
+  {
+      nat=MEDCouplingNatureOfField::GetRepr(_nature);
+      stream << "Nature of field template : " << nat << ".\n";
+  }
+  catch(INTERP_KERNEL::Exception& /*e*/)
+  {  }
+  const MEDCouplingFieldDiscretization *fd(_type);
+  if(!fd)
+    stream << "No spatial discretization set !";
+  else
+    fd->reprQuickOverview(stream);
+  stream << std::endl;
+  if(!_mesh)
+    stream << "\nNo mesh support defined !";
+  else
+    {
+      std::ostringstream oss;
+      _mesh->reprQuickOverview(oss);
+      std::string tmp(oss.str());
+      stream << "\nMesh info : " << tmp.substr(0,tmp.find('\n'));
+    }
+}
+
+MCAuto<MEDCouplingFieldTemplate> MEDCouplingFieldTemplate::clone(bool recDeepCpy) const
+{
+  MCAuto<MEDCouplingFieldTemplate> ret(new MEDCouplingFieldTemplate(*this,recDeepCpy));
+  return ret;
+}