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


C++ GenericMatrix::ident方法代码示例

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


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

示例1: apply

//-----------------------------------------------------------------------------
void NewDirichletBC::apply(GenericMatrix& A, GenericVector& b,
                const GenericVector* x, const DofMap& dof_map, const ufc::form& form)
{
  bool reassemble = dolfin_get("PDE reassemble matrix");
  std::cout << "newdirichlet: " << reassemble << std::endl;

  // FIXME: How do we reuse the dof map for u?

  if (method == topological)
    message("Applying Dirichlet boundary conditions to linear system.");
  /*
  else if (method == geometrical)
    message("Applying Dirichlet boundary conditions to linear system (geometrical approach).");
  else
    message("Applying Dirichlet boundary conditions to linear system (pointwise approach).");
  */
  // Make sure we have the facet - cell connectivity
  const uint D = _mesh.topology().dim();
  if (method == topological)
    _mesh.init(D - 1, D);

  // Create local data for application of boundary conditions
  BoundaryCondition::LocalData data(form, _mesh, dof_map, sub_system);
  
  // A map to hold the mapping from boundary dofs to boundary values
  std::map<uint, real> boundary_values;

  if (method == pointwise)
  {
    Progress p("Applying Dirichlet boundary conditions", _mesh.size(D));
    for (CellIterator cell(_mesh); !cell.end(); ++cell)
    {
      computeBCPointwise(boundary_values, *cell, data);
      p++;
    }
  }
  else
  {
    // Iterate over the facets of the mesh
    Progress p("Applying Dirichlet boundary conditions", _mesh.size(D - 1));
    for (FacetIterator facet(_mesh); !facet.end(); ++facet)
    {
      // Skip facets not inside the sub domain
      if ((*sub_domains)(*facet) != sub_domain)
      {
        p++;
        continue;
      }

      // Chose strategy
      if (method == topological)
        computeBCTopological(boundary_values, *facet, data);
      else
        computeBCGeometrical(boundary_values, *facet, data);
    
      // Update process
      p++;
    }
  }

  // Copy boundary value data to arrays
  uint* dofs = new uint[boundary_values.size()];
  real* values = new real[boundary_values.size()];
  std::map<uint, real>::const_iterator boundary_value;
  uint i = 0;
  for (boundary_value = boundary_values.begin(); boundary_value != boundary_values.end(); ++boundary_value)
  {
    dofs[i]     = boundary_value->first;
    values[i++] = boundary_value->second;
  }

  // Modify boundary values for nonlinear problems
  if (x)
  {
    real* x_values = new real[boundary_values.size()];
    x->get(x_values, boundary_values.size(), dofs);
    for (uint i = 0; i < boundary_values.size(); i++)
      values[i] -= x_values[i];
    delete[] x_values;
  }
  
  // Modify RHS vector (b[i] = value)
  b.set(values, boundary_values.size(), dofs);

  if(reassemble)
  {
    // Modify linear system (A_ii = 1)
    A.ident(boundary_values.size(), dofs);
  }

  // Clear temporary arrays
  delete [] dofs;
  delete [] values;

  // Finalise changes to b
  b.apply();
}
开发者ID:njansson,项目名称:unicorn-hpc,代码行数:98,代码来源:NewDirichletBC.cpp


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