当前位置: 首页>>代码示例>>C++>>正文


C++ SparseMatrix::Set方法代码示例

本文整理汇总了C++中SparseMatrix::Set方法的典型用法代码示例。如果您正苦于以下问题:C++ SparseMatrix::Set方法的具体用法?C++ SparseMatrix::Set怎么用?C++ SparseMatrix::Set使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SparseMatrix的用法示例。


在下文中一共展示了SparseMatrix::Set方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: I

SparseMatrix* FiniteElementSpace::NC_GlobalRestrictionMatrix
(FiniteElementSpace* cfes, NCMesh* ncmesh)
{
   Array<int> rows, cols, rs, cs;
   LinearFECollection linfec;

   NCMesh::FineTransform* transforms = ncmesh->GetFineTransforms();

   SparseMatrix* R = new SparseMatrix(cfes->GetVSize(), this->GetVSize());

   // we mark each fine DOF the first time its column is set so that slave node
   // values don't get represented twice in R
   Array<int> mark(this->GetNDofs());
   mark = 0;

   // loop over the fine elements, get interpolations of the coarse elements
   for (int k = 0; k < mesh->GetNE(); k++)
   {
      mesh->SetState(Mesh::TWO_LEVEL_COARSE);
      cfes->GetElementDofs(transforms[k].coarse_index, rows);

      mesh->SetState(Mesh::TWO_LEVEL_FINE);
      this->GetElementDofs(k, cols);

      if (!transforms[k].IsIdentity())
      {
         int geom = mesh->GetElementBaseGeometry(k);
         const FiniteElement *fe = fec->FiniteElementForGeometry(geom);

         IsoparametricTransformation trans;
         trans.SetFE(linfec.FiniteElementForGeometry(geom));
         trans.GetPointMat() = transforms[k].point_matrix;

         DenseMatrix I(fe->GetDof());
         fe->GetLocalInterpolation(trans, I);
         // TODO: use std::unordered_map to cache I matrices (point_matrix as key)

         // make sure we don't set any column of R more than once
         for (int i = 0; i < I.Height(); i++)
         {
            int col = cols[i];
            if (col < 0)
               col = -1 - col;
            if (mark[col]++)
               I.SetRow(i, 0); // zero the i-th row of I
         }

         cfes->DofsToVDofs(rows);
         this->DofsToVDofs(cols);
         SetVDofSubMatrixTranspose(*R, rows, cols, I, vdim);
      }
      else // optimization: insert identity for elements that were not refined
      {
         MFEM_ASSERT(rows.Size() == cols.Size(), "");
         for (int i = 0; i < rows.Size(); i++)
         {
            int col = cols[i];
            if (col < 0)
               col = -1 - col;
            if (!mark[col]++)
               for (int vd = 0; vd < vdim; vd++)
                  R->Set(cfes->DofToVDof(rows[i], vd),
                         this->DofToVDof(cols[i], vd), 1.0);
         }
      }
   }

   delete [] transforms;
   return R;
}
开发者ID:YPCC,项目名称:mfem,代码行数:70,代码来源:fespace.cpp


注:本文中的SparseMatrix::Set方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。