예제 #1
0
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
QVector<DataArrayPath> DataContainer::getAllDataArrayPaths()
{

  QVector<DataArrayPath> paths;
  for(QMap<QString, AttributeMatrix::Pointer>::iterator iter = m_AttributeMatrices.begin(); iter != m_AttributeMatrices.end(); ++iter)
  {
    AttributeMatrix::Pointer am = iter.value();
    QString amName = am->getName();
    QList<QString> aaNames = am->getAttributeArrayNames();

    foreach(QString aaName, aaNames)
    {
      DataArrayPath dap(getName(), amName, aaName);
      paths.push_back(dap);
    }
  }
Teuchos::RCP< Epetra_MultiVector > *
convertPythonToEpetraMultiVector(PyObject * pyobj)
{
  // SWIG initialization
  static swig_type_info * swig_EMV_ptr =
    SWIG_TypeQuery("Teuchos::RCP< Epetra_MultiVector >*");
  static swig_type_info * swig_DMDV_ptr =
    SWIG_TypeQuery("Teuchos::RCP< Domi::MDVector<double> >*");
  //
  // Get the default communicator
  const Teuchos::RCP< const Teuchos::Comm<int> > comm =
    Teuchos::DefaultComm<int>::getComm();
  //
  // Result objects
  void *argp = 0;
  Teuchos::RCP< Epetra_MultiVector > * result = 0;
  Teuchos::RCP< Epetra_MultiVector > emv_rcp;
  Teuchos::RCP< Domi::MDVector<double> > dmdv_rcp;
  int newmem = 0;
  //
  // Check if the Python object is a wrapped Epetra_MultiVector
  int res = SWIG_ConvertPtrAndOwn(pyobj, &argp, swig_EMV_ptr, 0, &newmem);
  if (SWIG_IsOK(res))
  {
    result =
        reinterpret_cast< Teuchos::RCP< Epetra_MultiVector > * >(argp);
    return result;
  }

#ifdef HAVE_DOMI
  //
  // Check if the Python object is a wrapped Domi::MDVector<double>
  newmem = 0;
  res = SWIG_ConvertPtrAndOwn(pyobj, &argp, swig_DMDV_ptr, 0, &newmem);
  if (SWIG_IsOK(res))
  {
    if (newmem & SWIG_CAST_NEW_MEMORY)
    {
      dmdv_rcp =
        *reinterpret_cast< Teuchos::RCP< Domi::MDVector<double> > * >(argp);
      delete reinterpret_cast< Teuchos::RCP< Domi::MDVector<double> > * >(argp);
      //** result = &(dmdv_rcp->getEpetraMultiVectorView());
    }
    else
    {
      dmdv_rcp =
        *reinterpret_cast< Teuchos::RCP< Domi::MDVector<double> > * >(argp);
      //** result = &(dmdv_rcp->getEpetraMultiVectorView());
    }
    return result;
  }
  //
  // Check if the Python object supports the DistArray Protocol
  if (PyObject_HasAttrString(pyobj, "__distarray__"))
  {
    DistArrayProtocol dap(pyobj);
    dmdv_rcp = convertToMDVector<double>(comm, dap);
    //** result = &(dmdv_rcp->getEpetraMultiVectorView());
    return result;
  }
#endif

  //
  // Check if the environment is serial, and if so, check if the
  // Python object is a NumPy array
  if (comm->getSize() == 1)
  {
    if (PyArray_Check(pyobj))
    {
      //** result = new Teuchos::RCP< Epetra_NumPyMultiVector >(
      //**           new Epetra_NumPyMultiVector(pyobj));
      return result;
    }
  }
  //
  // If we get to this point, then none of our known converters will
  // work, so it is time to throw an exception.
  PyErr_Format(PyExc_TypeError, "Could not convert argument of type '%s' to "
               "an Epetra_MultiVector",
               PyString_AsString(PyObject_Str(PyObject_Type(pyobj))));
  throw PythonException();
}