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

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

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

revision 1811 by ksteube, Thu Sep 25 23:11:13 2008 UTC revision 1859 by gross, Wed Oct 8 03:03:37 2008 UTC
# Line 469  Data::setToZero() Line 469  Data::setToZero()
469    throw DataException("Error - Data can not be set to zero.");    throw DataException("Error - Data can not be set to zero.");
470  }  }
471    
472    // void
473    // Data::copyWithMask(const Data& other,
474    //                    const Data& mask)
475    // {
476    //   if (other.isEmpty() || mask.isEmpty())
477    //   {
478    //  throw DataException("Error - copyWithMask not permitted using instances of DataEmpty.");
479    //   }
480    //   Data mask1;
481    //   Data mask2;
482    //   mask1 = mask.wherePositive();
483    //
484    //   mask2.copy(mask1);
485    //   mask1 *= other;
486    //
487    //   mask2 *= *this;
488    //   mask2 = *this - mask2;
489    //   *this = mask1 + mask2;
490    // }
491    
492  void  void
493  Data::copyWithMask(const Data& other,  Data::copyWithMask(const Data& other,
494                     const Data& mask)                     const Data& mask)
495  {  {
496      // 1. Interpolate if required so all Datas use the same FS as this
497      // 2. Tag or Expand so that all Data's are the same type
498      // 3. Iterate over the data vectors copying values where mask is >0
499    if (other.isEmpty() || mask.isEmpty())    if (other.isEmpty() || mask.isEmpty())
500    {    {
501      throw DataException("Error - copyWithMask not permitted using instances of DataEmpty.");      throw DataException("Error - copyWithMask not permitted using instances of DataEmpty.");
502    }    }
503    Data mask1;    Data other2(other);
504    Data mask2;    Data mask2(mask);
505      FunctionSpace myFS=getFunctionSpace();
506    mask1 = mask.wherePositive();    FunctionSpace oFS=other2.getFunctionSpace();
507    mask2.copy(mask1);    FunctionSpace mFS=mask2.getFunctionSpace();
508      if (oFS!=myFS)
509      {
510         if (other2.probeInterpolation(myFS))
511         {
512        other2=other2.interpolate(myFS);
513         }
514         else
515         {
516        throw DataException("Error - copyWithMask: other FunctionSpace is not compatible with this one.");
517         }
518      }
519      if (mFS!=myFS)
520      {
521         if (mask2.probeInterpolation(myFS))
522         {
523        mask2=mask2.interpolate(myFS);
524         }
525         else
526         {
527        throw DataException("Error - copyWithMask: mask FunctionSpace is not compatible with this one.");
528         }
529      }
530                // Ensure that all args have the same type
531      if (this->isExpanded() || mask2.isExpanded() || other2.isExpanded())
532      {
533        this->expand();
534        other2.expand();
535        mask2.expand();
536      }
537      else if (this->isTagged() || mask2.isTagged() || other2.isTagged())
538      {
539        this->tag();
540        other2.tag();
541        mask2.tag();
542      }
543      else if (this->isConstant() && mask2.isConstant() && other2.isConstant())
544      {
545      }
546      else
547      {
548        throw DataException("Error - Unknown DataAbstract passed to copyWithMask.");
549      }
550      // Now we iterate over the elements
551      DataVector& self=m_data->getVector();
552      const DataVector& ovec=other2.m_data->getVector();
553      const DataVector& mvec=mask2.m_data->getVector();
554      if ((self.size()!=ovec.size()) || (self.size()!=mvec.size()))
555      {
556        throw DataException("Error - size mismatch in arguments to copyWithMask.");
557      }
558      size_t num_points=self.size();
559      long i;
560      #pragma omp parallel for private(i) schedule(static)
561      for (i=0;i<num_points;++i)
562      {
563        if (mvec[i]>0)
564        {
565           self[i]=ovec[i];
566        }
567      }
568    }
569    
   mask1 *= other;  
   mask2 *= *this;  
   mask2 = *this - mask2;  
570    
   *this = mask1 + mask2;  
 }  
571    
572  bool  bool
573  Data::isExpanded() const  Data::isExpanded() const
# Line 778  Data::setValueOfDataPointToPyObject(int Line 857  Data::setValueOfDataPointToPyObject(int
857      // this will throw if the value cannot be represented      // this will throw if the value cannot be represented
858      boost::python::numeric::array num_array(py_object);      boost::python::numeric::array num_array(py_object);
859      setValueOfDataPointToArray(dataPointNo,num_array);      setValueOfDataPointToArray(dataPointNo,num_array);
   
   
860  }  }
861    
862  void  void
# Line 801  Data::setValueOfDataPointToArray(int dat Line 878  Data::setValueOfDataPointToArray(int dat
878    }    }
879    //    //
880    // make sure data is expanded:    // make sure data is expanded:
881      //
882    if (!isExpanded()) {    if (!isExpanded()) {
883      expand();      expand();
884    }    }

Legend:
Removed from v.1811  
changed lines
  Added in v.1859

  ViewVC Help
Powered by ViewVC 1.1.26