/** \brief Rebuild this inverse from an Tpetra::Operator<ST,LO,GO,NT>  passed
  * in this to object.
  *
  * Rebuild this inverse from an Tpetra::Operator<ST,LO,GO,NT>  passed
  * in this to object.  If <code>buildInverseOperator</code> has not been called
  * the inverse operator will be built instead. Otherwise efforts are taken
  * to only rebuild what is neccessary. Also, that this Tpetra::Operator<ST,LO,GO,NT>
  * may be an EpetraOperatorWrapper object, so the block Thyra components
  * can be extracted.
  *
  * \param[in] A The Epetra source operator. (Should be a EpetraOperatorWrapper!)
  */
void InverseFactoryOperator::rebuildInverseOperator(const Teuchos::RCP<const Tpetra::Operator<ST,LO,GO,NT> > & A)
{
    Teko_DEBUG_SCOPE("InverseFactoryOperator::rebuildPreconditioner",10);

    // if the inverse hasn't been built yet, rebuild from scratch
    if(not firstBuildComplete_) {
        buildInverseOperator(A,false);
        return;
    }

    RCP<const Thyra::LinearOpBase<ST> > thyraA = extractLinearOp(A);
    Teko::rebuildInverse(*inverseFactory_,thyraA,invOperator_);

    if(setConstFwdOp_)
        fwdOp_.initialize(A);

    SetOperator(invOperator_,false);

    setConstFwdOp_ = true;

    TEUCHOS_ASSERT(getForwardOp()!=Teuchos::null);
    TEUCHOS_ASSERT(invOperator_!=Teuchos::null);
    TEUCHOS_ASSERT(getThyraOp()!=Teuchos::null);
    TEUCHOS_ASSERT(firstBuildComplete_==true);
}
/** \brief Build this inverse operator from an Tpetra::Operator<ST,LO,GO,NT>
  * passed in to this object.
  *
  * Build this inverse opeerator from an Tpetra::Operator<ST,LO,GO,NT>
  * passed in to this object. If this Tpetra::Operator<ST,LO,GO,NT>
  * is an EpetraOperatorWrapper object then the block Thyra components
  * are extracted.
  *
  * \param[in] A The Epetra source operator.
  * \param[in] clear If true, than any previous state saved by the operator
  *                  is discarded.
  */
void InverseFactoryOperator::buildInverseOperator(const Teuchos::RCP<const Tpetra::Operator<ST,LO,GO,NT> > & A,bool clear)
{
    Teko_DEBUG_SCOPE("InverseFactoryOperator::buildInverseOperator",10);

    // extract EpetraOperatorWrapper (throw on failure) and corresponding thyra operator
    RCP<const Thyra::LinearOpBase<ST> > thyraA = extractLinearOp(A);

    // set the mapping strategy
    SetMapStrategy(rcp(new InverseMappingStrategy(extractMappingStrategy(A))));

    initInverse(clear);

    // actually build the inverse operator
    invOperator_ = Teko::buildInverse(*inverseFactory_,thyraA);

    SetOperator(invOperator_,false);

    firstBuildComplete_ = true;

    if(setConstFwdOp_)
        fwdOp_ = A;

    setConstFwdOp_ = true;

    TEUCHOS_ASSERT(invOperator_!=Teuchos::null);
    TEUCHOS_ASSERT(getForwardOp()!=Teuchos::null);
    TEUCHOS_ASSERT(getThyraOp()!=Teuchos::null);
    TEUCHOS_ASSERT(getMapStrategy()!=Teuchos::null);
    TEUCHOS_ASSERT(firstBuildComplete_==true);
}
Ejemplo n.º 3
0
void Driver::Event_Fallthrough(const EV::Event& event) {
    int accepted = 0;
    event.SetReturnPointer(&accepted);
	if(!(_activeOp && DispatchSingleEvent(_activeOp, event))) {
        if(_activeOp != _defaultOp) {
            GEN::Pointer<EV::Event> ftevent(event.Clone());
            ftevent->SetFallthrough(true);
            if(DispatchSingleEvent(_defaultOp, *ftevent)) {
                // default operator becomes active, implicit rebuild
                SetOperator(_defaultOp, false, NULL);
                // next, we have to resend the event without fallthrough flag
                accepted = 0;
                DispatchSingleEvent(_activeOp, event);
            }
        }
    }
    if(!accepted) {
        // forward event
        W::world.Send(event);
    }
    RebuildMeshes();
    SignalCompletion();
}
static nsresult
InitOperators(void)
{
  // Load the property file containing the Operator Dictionary
  nsresult rv;
  nsCOMPtr<nsIPersistentProperties> mathfontProp;
  rv = NS_LoadPersistentPropertiesFromURISpec(
         getter_AddRefs(mathfontProp),
         NS_LITERAL_CSTRING("resource://gre/res/fonts/mathfont.properties"));

  if (NS_FAILED(rv)) return rv;

  // Parse the Operator Dictionary in two passes.
  // The first pass is to count the number of operators; the second pass is to
  // allocate the necessary space for them and to add them in the hash table.
  for (int32_t pass = 1; pass <= 2; pass++) {
    OperatorData dummyData;
    OperatorData* operatorData = &dummyData;
    nsCOMPtr<nsISimpleEnumerator> iterator;
    if (NS_SUCCEEDED(mathfontProp->Enumerate(getter_AddRefs(iterator)))) {
      bool more;
      uint32_t index = 0;
      nsAutoCString name;
      nsAutoString attributes;
      while ((NS_SUCCEEDED(iterator->HasMoreElements(&more))) && more) {
        nsCOMPtr<nsISupports> supports;
        nsCOMPtr<nsIPropertyElement> element;
        if (NS_SUCCEEDED(iterator->GetNext(getter_AddRefs(supports)))) {
          element = do_QueryInterface(supports);
          if (NS_SUCCEEDED(element->GetKey(name)) &&
              NS_SUCCEEDED(element->GetValue(attributes))) {
            // expected key: operator.\uNNNN.{infix,postfix,prefix}
            if ((21 <= name.Length()) && (0 == name.Find("operator.\\u"))) {
              name.Cut(0, 9); // 9 is the length of "operator.";
              int32_t len = name.Length();
              nsOperatorFlags form = 0;
              if (kNotFound != name.RFind(".infix")) {
                form = NS_MATHML_OPERATOR_FORM_INFIX;
                len -= 6;  // 6 is the length of ".infix";
              }
              else if (kNotFound != name.RFind(".postfix")) {
                form = NS_MATHML_OPERATOR_FORM_POSTFIX;
                len -= 8; // 8 is the length of ".postfix";
              }
              else if (kNotFound != name.RFind(".prefix")) {
                form = NS_MATHML_OPERATOR_FORM_PREFIX;
                len -= 7; // 7 is the length of ".prefix";
              }
              else continue; // input is not applicable
              name.SetLength(len);
              if (2 == pass) { // allocate space and start the storage
                if (!gOperatorArray) {
                  if (0 == gOperatorCount) return NS_ERROR_UNEXPECTED;
                  gOperatorArray = new OperatorData[gOperatorCount];
                  if (!gOperatorArray) return NS_ERROR_OUT_OF_MEMORY;
                }
                operatorData = &gOperatorArray[index];
              }
              else {
                form = 0; // to quickly return from SetOperator() at pass 1
              }
              // See if the operator should be retained
              if (SetOperator(operatorData, form, name, attributes)) {
                index++;
                if (1 == pass) gOperatorCount = index;
              }
            }
          }
        }
      }
    }
  }
  return NS_OK;
}
Ejemplo n.º 5
0
void
ALOperator::BuildALOperator()
{
   TEUCHOS_ASSERT(blockedMapping_ != Teuchos::null);

   // Get an Epetra_CrsMatrix.
   const Teuchos::RCP<const Epetra_CrsMatrix> crsContent
      = Teuchos::rcp_dynamic_cast<const Epetra_CrsMatrix>(fullContent_);

   // Ask the strategy to build the Thyra operator for you.
   if(blockedOperator_ == Teuchos::null)
   {
      blockedOperator_
         = blockedMapping_->buildBlockedThyraOp(crsContent, label_);
   }
   else
   {
      const Teuchos::RCP<Thyra::BlockedLinearOpBase<double> > blkOp
            = Teuchos::rcp_dynamic_cast<Thyra::BlockedLinearOpBase<double> >
            (blockedOperator_, true);
      blockedMapping_->rebuildBlockedThyraOp(crsContent, blkOp);
   }

   // Extract blocks.
   const Teuchos::RCP<Thyra::BlockedLinearOpBase<double> > blkOp
      = Teuchos::rcp_dynamic_cast<Thyra::BlockedLinearOpBase<double> >
      (blockedOperator_, true);
   numBlockRows_ = blkOp->productRange()->numBlocks();
   Teuchos::RCP<const Thyra::LinearOpBase<double> > blockedOpBlocks[4][4];
   for(int i = 0; i <= dim_; i++)
   {
      for(int j = 0; j <= dim_; j++)
      {
         blockedOpBlocks[i][j] = blkOp->getBlock(i, j);
      }
   }

   // Pressure mass matrix.
   if(pressureMassMatrix_ != Teuchos::null)
   {
      invPressureMassMatrix_ = getInvDiagonalOp(pressureMassMatrix_);
   }
   // We need the size of the sub-block to build the identity matrix.
   else
   {
      std::cout << "Pressure mass matrix is null. Use identity." << std::endl;
      pressureMassMatrix_
            = Thyra::identity<double>(blockedOpBlocks[dim_][0]->range());
      invPressureMassMatrix_
            = Thyra::identity<double>(blockedOpBlocks[dim_][0]->range());
   }

   // Build the AL operator.
   Teuchos::RCP<Thyra::DefaultBlockedLinearOp<double> > alOperator_
      = Thyra::defaultBlockedLinearOp<double>();
   alOperator_->beginBlockFill(dim_ + 1, dim_ + 1);

   // Set blocks for the velocity parts and gradient.
   for(int i = 0; i < dim_; i++)
   {
      for(int j = 0; j < dim_; j++)
      {
         // build the blocks and place it the right location
         alOperator_->setBlock(i, j,
               Thyra::add(blockedOpBlocks[i][j],
               Thyra::scale(gamma_,
               Thyra::multiply(blockedOpBlocks[i][dim_],
               invPressureMassMatrix_, blockedOpBlocks[dim_][j]))));
      } // end for j
   } // end for i

   // Last row. Divergence and (possible) stabilization matrix.
   for(int j = 0; j <= dim_; j++)
   {
      alOperator_->setBlock(dim_, j, blockedOpBlocks[dim_][j]);
   }

   // Last column. Gradient.
   for(int i = 0; i < dim_; i++)
   {
      alOperator_->setBlock(i, dim_,
            Thyra::add(blockedOpBlocks[i][dim_],
            Thyra::scale(gamma_,
            Thyra::multiply(blockedOpBlocks[i][dim_],
            invPressureMassMatrix_,blockedOpBlocks[dim_][dim_]))));
   }

   alOperator_->endBlockFill();

   // Set whatever is returned.
   SetOperator(alOperator_, false);

   // Set operator for augmenting the right-hand side.
   Teuchos::RCP<Thyra::DefaultBlockedLinearOp<double> > alOpRhs_
         = Thyra::defaultBlockedLinearOp<double>();
   alOpRhs_->beginBlockFill(dim_ + 1, dim_ + 1);

   // Identity matrices on the main diagonal.
   for(int i = 0; i < dim_; i++)
   {
      // build the blocks and place it the right location
      alOpRhs_->setBlock(i, i,
            Thyra::identity<double>(blockedOpBlocks[0][0]->range()));
   } // end for i
   alOpRhs_->setBlock(dim_, dim_,
         Thyra::identity<double>(blockedOpBlocks[dim_][dim_]->range()));

   // Last column.
   for(int i = 0; i < dim_; i++)
   {
      alOpRhs_->setBlock(i, dim_,
            Thyra::scale(gamma_,
            Thyra::multiply(blockedOpBlocks[i][dim_], invPressureMassMatrix_)));
   }

   alOpRhs_->endBlockFill();

   alOperatorRhs_ = alOpRhs_;

   // reorder if necessary
   if(reorderManager_ != Teuchos::null)
      Reorder(*reorderManager_);
}
Ejemplo n.º 6
0
 UMFPackSolver(SparseMatrix &A, bool _use_long_ints = false)
    : use_long_ints(_use_long_ints) { Init(); SetOperator(A); }
Ejemplo n.º 7
0
void Driver::Event_SetOperator(const SetOperatorEvent& event) {
    SetOperator(event.m_op, event.m_force, event.m_args);
    SignalCompletion();
}