示例#1
0
void
ComputeDiracThread::onElement(const Elem * elem)
{
  bool has_dirac_kernels_on_elem = _fe_problem.reinitDirac(elem, _tid);
  std::set<MooseVariable *> needed_moose_vars;

  if (has_dirac_kernels_on_elem)
  {
    // Only call reinitMaterials() if one or more DiracKernels has
    // actually called getMaterialProperty().  Loop over all the
    // DiracKernels and check whether this is the case.
    bool need_reinit_materials = false;
    {
      std::vector<DiracKernel *>::const_iterator
        dirac_kernel_it = _sys.getDiracKernelWarehouse(_tid).all().begin(),
        dirac_kernel_end = _sys.getDiracKernelWarehouse(_tid).all().end();

      for (; dirac_kernel_it != dirac_kernel_end; ++dirac_kernel_it)
      {
        // If any of the DiracKernels have had getMaterialProperty()
        // called, we need to reinit Materials.
        if ((*dirac_kernel_it)->getMaterialPropertyCalled())
        {
          need_reinit_materials = true;
          break;
        }
      }
    }

    if (need_reinit_materials)
      _fe_problem.reinitMaterials(_subdomain, _tid, /*swap_stateful=*/false);

    std::vector<DiracKernel *>::const_iterator
      dirac_kernel_it = _sys.getDiracKernelWarehouse(_tid).all().begin(),
      dirac_kernel_end = _sys.getDiracKernelWarehouse(_tid).all().end();

    for (; dirac_kernel_it != dirac_kernel_end; ++dirac_kernel_it)
    {
      DiracKernel * dirac_kernel = *dirac_kernel_it;

      if (dirac_kernel->hasPointsOnElem(elem))
      {
        if (_jacobian == NULL)
          dirac_kernel->computeResidual();
        else
        {
          // Get a list of coupled variables from the FEProblem
          std::vector<std::pair<MooseVariable *, MooseVariable *> > & coupling_entries = _fe_problem.couplingEntries(_tid);

          // Loop over the list of coupled variable pairs
          {
            std::vector<std::pair<MooseVariable *, MooseVariable *> >::iterator
              var_pair_iter = coupling_entries.begin(),
              var_pair_end = coupling_entries.end();

            for (; var_pair_iter != var_pair_end; ++var_pair_iter)
            {
              MooseVariable * ivariable = var_pair_iter->first;
              MooseVariable * jvariable = var_pair_iter->second;

              // The same check that is in ComputeFullJacobianThread::computeJacobian().
              // We only want to call computeOffDiagJacobian() if both
              // variables are active on this subdomain...
              if (ivariable->activeOnSubdomain(_subdomain) && jvariable->activeOnSubdomain(_subdomain))
              {
                // FIXME: do we need to prepareShapes for ivariable->number?
                dirac_kernel->subProblem().prepareShapes(jvariable->number(), _tid);
                dirac_kernel->computeOffDiagJacobian(jvariable->number());
              }
            }
          }
        }
      }
    }

    // Note that we do not call swapBackMaterials() here as they were
    // never swapped in the first place.  This avoids messing up
    // stored values of stateful material properties.
  }
}
示例#2
0
void
ComputeDiracThread::onElement(const Elem * elem)
{
  bool has_dirac_kernels_on_elem = _fe_problem.reinitDirac(elem, _tid);
  std::set<MooseVariable *> needed_moose_vars;
  const std::vector<MooseSharedPointer<DiracKernel> > & dkernels = _dirac_kernels.getActiveObjects(_tid);

  if (has_dirac_kernels_on_elem)
  {
    // Only call reinitMaterials() if one or more DiracKernels has
    // actually called getMaterialProperty().  Loop over all the
    // DiracKernels and check whether this is the case.
    bool need_reinit_materials = false;
    {
      for (std::vector<MooseSharedPointer<DiracKernel> >::const_iterator it = dkernels.begin(); it != dkernels.end(); ++it)
      {
        // If any of the DiracKernels have had getMaterialProperty()
        // called, we need to reinit Materials.
        if ((*it)->getMaterialPropertyCalled())
        {
          need_reinit_materials = true;
          break;
        }
      }
    }

    if (need_reinit_materials)
      _fe_problem.reinitMaterials(_subdomain, _tid, /*swap_stateful=*/false);

    for (std::vector<MooseSharedPointer<DiracKernel> >::const_iterator it = dkernels.begin(); it != dkernels.end(); ++it)
    {
      MooseSharedPointer<DiracKernel> dirac_kernel = *it;

      if (dirac_kernel->hasPointsOnElem(elem))
      {
        if (_jacobian == NULL)
          dirac_kernel->computeResidual();
        else
        {
          // Get a list of coupled variables from the SubProblem
          std::vector<std::pair<MooseVariable *, MooseVariable *> > & coupling_entries =
            dirac_kernel->subProblem().assembly(_tid).couplingEntries();

          // Loop over the list of coupled variable pairs
          {
            std::vector<std::pair<MooseVariable *, MooseVariable *> >::iterator
              var_pair_iter = coupling_entries.begin(),
              var_pair_end = coupling_entries.end();

            for (; var_pair_iter != var_pair_end; ++var_pair_iter)
            {
              MooseVariable * ivariable = var_pair_iter->first;
              MooseVariable * jvariable = var_pair_iter->second;

              // A variant of the check that is in
              // ComputeFullJacobianThread::computeJacobian().  We
              // only want to call computeOffDiagJacobian() if both
              // variables are active on this subdomain, and the
              // off-diagonal variable actually has dofs.
              if (dirac_kernel->variable().number() == ivariable->number()
                  && ivariable->activeOnSubdomain(_subdomain)
                  && jvariable->activeOnSubdomain(_subdomain)
                  && (jvariable->numberOfDofs() > 0))
              {
                dirac_kernel->subProblem().prepareShapes(jvariable->number(), _tid);
                dirac_kernel->computeOffDiagJacobian(jvariable->number());
              }
            }
          }
        }
      }
    }

    // Note that we do not call swapBackMaterials() here as they were
    // never swapped in the first place.  This avoids messing up
    // stored values of stateful material properties.
  }
}