/[escript]/trunk/escript/src/Data.h
ViewVC logotype

Diff of /trunk/escript/src/Data.h

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1802 by jfenwick, Tue Sep 23 01:03:29 2008 UTC revision 1803 by jfenwick, Wed Sep 24 06:20:29 2008 UTC
# Line 396  class Data { Line 396  class Data {
396    
397    /**    /**
398       \brief       \brief
399       Return true if this Data is empty.       Return true if this Data holds an instance of DataEmpty. This is _not_ the same as asking if the object
400    contains datapoints.
401    */    */
402    ESCRIPT_DLL_API    ESCRIPT_DLL_API
403    bool    bool
# Line 1694  Data::algorithm(BinaryFunction operation Line 1695  Data::algorithm(BinaryFunction operation
1695      DataConstant* leftC=dynamic_cast<DataConstant*>(m_data.get());      DataConstant* leftC=dynamic_cast<DataConstant*>(m_data.get());
1696      EsysAssert((leftC!=0), "Programming error - casting to DataConstant.");      EsysAssert((leftC!=0), "Programming error - casting to DataConstant.");
1697      return escript::algorithm(*leftC,operation,initial_value);      return escript::algorithm(*leftC,operation,initial_value);
1698      } else if (isEmpty()) {
1699        throw DataException("Error - Operations not permitted on instances of DataEmpty.");
1700    }    }
1701    return 0;    return 0;
1702  }  }
# Line 1711  inline Line 1714  inline
1714  Data  Data
1715  Data::dp_algorithm(BinaryFunction operation, double initial_value) const  Data::dp_algorithm(BinaryFunction operation, double initial_value) const
1716  {  {
1717    if (isExpanded()) {    if (isEmpty()) {
1718        throw DataException("Error - Operations not permitted on instances of DataEmpty.");
1719      }
1720      else if (isExpanded()) {
1721      Data result(0,DataTypes::ShapeType(),getFunctionSpace(),isExpanded());      Data result(0,DataTypes::ShapeType(),getFunctionSpace(),isExpanded());
1722      DataExpanded* dataE=dynamic_cast<DataExpanded*>(m_data.get());      DataExpanded* dataE=dynamic_cast<DataExpanded*>(m_data.get());
1723      DataExpanded* resultE=dynamic_cast<DataExpanded*>(result.m_data.get());      DataExpanded* resultE=dynamic_cast<DataExpanded*>(result.m_data.get());
# Line 1719  Data::dp_algorithm(BinaryFunction operat Line 1725  Data::dp_algorithm(BinaryFunction operat
1725      EsysAssert((resultE!=0), "Programming error - casting result to DataExpanded.");      EsysAssert((resultE!=0), "Programming error - casting result to DataExpanded.");
1726      escript::dp_algorithm(*dataE,*resultE,operation,initial_value);      escript::dp_algorithm(*dataE,*resultE,operation,initial_value);
1727      return result;      return result;
1728    } else if (isTagged()) {    }
1729      else if (isTagged()) {
1730      DataTagged* dataT=dynamic_cast<DataTagged*>(m_data.get());      DataTagged* dataT=dynamic_cast<DataTagged*>(m_data.get());
1731      EsysAssert((dataT!=0), "Programming error - casting data to DataTagged.");      EsysAssert((dataT!=0), "Programming error - casting data to DataTagged.");
   
 //     DataTypes::ShapeType viewShape;  
 //     DataTypes::ValueType viewData(1);  
 //     viewData[0]=0;  
 //     DataArrayView defaultValue(viewData,viewShape);  
 //     DataTagged::TagListType keys;  
 //     DataTagged::ValueListType values;  
 //     DataTagged::DataMapType::const_iterator i;  
 //     for (i=dataT->getTagLookup().begin();i!=dataT->getTagLookup().end();i++) {  
 //       keys.push_back(i->first);  
 //       values.push_back(defaultValue);  
 //     }  
 //     Data result(keys,values,defaultValue,getFunctionSpace());  
 //     DataTagged* resultT=dynamic_cast<DataTagged*>(result.m_data.get());  
 //     EsysAssert((resultT!=0), "Programming error - casting result to DataTagged.");  
   
   
   
   
1732      DataTypes::ValueType defval(1);      DataTypes::ValueType defval(1);
1733      defval[0]=0;      defval[0]=0;
1734      DataTagged* resultT=new DataTagged(getFunctionSpace(), DataTypes::scalarShape, defval, dataT);      DataTagged* resultT=new DataTagged(getFunctionSpace(), DataTypes::scalarShape, defval, dataT);
1735      escript::dp_algorithm(*dataT,*resultT,operation,initial_value);      escript::dp_algorithm(*dataT,*resultT,operation,initial_value);
1736      return Data(resultT);   // note: the Data object now owns the resultT pointer      return Data(resultT);   // note: the Data object now owns the resultT pointer
1737      }
1738    } else if (isConstant()) {    else if (isConstant()) {
1739      Data result(0,DataTypes::ShapeType(),getFunctionSpace(),isExpanded());      Data result(0,DataTypes::ShapeType(),getFunctionSpace(),isExpanded());
1740      DataConstant* dataC=dynamic_cast<DataConstant*>(m_data.get());      DataConstant* dataC=dynamic_cast<DataConstant*>(m_data.get());
1741      DataConstant* resultC=dynamic_cast<DataConstant*>(result.m_data.get());      DataConstant* resultC=dynamic_cast<DataConstant*>(result.m_data.get());
# Line 1774  C_TensorBinaryOperation(Data const &arg_ Line 1762  C_TensorBinaryOperation(Data const &arg_
1762                          Data const &arg_1,                          Data const &arg_1,
1763                          BinaryFunction operation)                          BinaryFunction operation)
1764  {  {
1765      if (arg_0.isEmpty() || arg_1.isEmpty())
1766      {
1767         throw DataException("Error - Operations not permitted on instances of DataEmpty.");
1768      }
1769    // Interpolate if necessary and find an appropriate function space    // Interpolate if necessary and find an appropriate function space
1770    Data arg_0_Z, arg_1_Z;    Data arg_0_Z, arg_1_Z;
1771    if (arg_0.getFunctionSpace()!=arg_1.getFunctionSpace()) {    if (arg_0.getFunctionSpace()!=arg_1.getFunctionSpace()) {
# Line 2683  Data Line 2675  Data
2675  C_TensorUnaryOperation(Data const &arg_0,  C_TensorUnaryOperation(Data const &arg_0,
2676                         UnaryFunction operation)                         UnaryFunction operation)
2677  {  {
2678      if (arg_0.isEmpty())  // do this before we attempt to interpolate
2679      {
2680         throw DataException("Error - Operations not permitted on instances of DataEmpty.");
2681      }
2682    
2683    // Interpolate if necessary and find an appropriate function space    // Interpolate if necessary and find an appropriate function space
2684    Data arg_0_Z = Data(arg_0);    Data arg_0_Z = Data(arg_0);
2685    
# Line 2761  C_TensorUnaryOperation(Data const &arg_0 Line 2758  C_TensorUnaryOperation(Data const &arg_0
2758          tensor_unary_operation(size0, ptr_0, ptr_2, operation);          tensor_unary_operation(size0, ptr_0, ptr_2, operation);
2759        }        }
2760      }      }
   
2761    }    }
2762    else {    else {
2763      throw DataException("Error - C_TensorUnaryOperation: unknown combination of inputs");      throw DataException("Error - C_TensorUnaryOperation: unknown combination of inputs");

Legend:
Removed from v.1802  
changed lines
  Added in v.1803

  ViewVC Help
Powered by ViewVC 1.1.26