Ejemplo n.º 1
0
void
ComputeResidualThread::onBoundary(const Elem *elem, unsigned int side, BoundaryID bnd_id)
{

  std::vector<IntegratedBC *> bcs = _sys._bcs[_tid].activeIntegrated(bnd_id);
  if (bcs.size() > 0)
  {
    _fe_problem.reinitElemFace(elem, side, bnd_id, _tid);

    unsigned int subdomain = elem->subdomain_id();
    if (subdomain != _subdomain)
      _fe_problem.subdomainSetupSide(subdomain, _tid);

    _fe_problem.reinitMaterialsFace(elem->subdomain_id(), _tid);
    _fe_problem.reinitMaterialsBoundary(bnd_id, _tid);

    // Set the active boundary id so that BoundaryRestrictable::_boundary_id is correct
    _fe_problem.setCurrentBoundaryID(bnd_id);

    for (std::vector<IntegratedBC *>::iterator it = bcs.begin(); it != bcs.end(); ++it)
    {
      IntegratedBC * bc = (*it);
      if (bc->shouldApply())
        bc->computeResidual();
    }
    _fe_problem.swapBackMaterialsFace(_tid);

    // Set active boundary id to invalid
    _fe_problem.setCurrentBoundaryID(Moose::INVALID_BOUNDARY_ID);
  }
}
Ejemplo n.º 2
0
void
ComputeResidualThread::subdomainChanged()
{
  _fe_problem.subdomainSetup(_subdomain, _tid);
  _sys._kernels[_tid].updateActiveKernels(_subdomain);
  if (_sys._doing_dg)
    _sys._dg_kernels[_tid].updateActiveDGKernels(_fe_problem.time(), _fe_problem.dt());

  std::set<MooseVariable *> needed_moose_vars;
  const std::vector<KernelBase *> & kernels = _sys._kernels[_tid].active();
  for (std::vector<KernelBase *>::const_iterator it = kernels.begin(); it != kernels.end(); ++it)
  {
    const std::set<MooseVariable *> & mv_deps = (*it)->getMooseVariableDependencies();
    needed_moose_vars.insert(mv_deps.begin(), mv_deps.end());
  }

  // Boundary Condition Dependencies
  const std::set<unsigned int> & subdomain_boundary_ids = _mesh.getSubdomainBoundaryIds(_subdomain);
  for (std::set<unsigned int>::const_iterator id_it = subdomain_boundary_ids.begin();
      id_it != subdomain_boundary_ids.end();
      ++id_it)
  {
    std::vector<IntegratedBC *> bcs = _sys._bcs[_tid].activeIntegrated(*id_it);
    if (bcs.size() > 0)
    {
      for (std::vector<IntegratedBC *>::iterator it = bcs.begin(); it != bcs.end(); ++it)
      {
        IntegratedBC * bc = (*it);
        if (bc->shouldApply())
        {
          const std::set<MooseVariable *> & mv_deps = bc->getMooseVariableDependencies();
          needed_moose_vars.insert(mv_deps.begin(), mv_deps.end());
        }
      }
    }
  }

  // DG Kernel dependencies
  {
    std::vector<DGKernel *> dgks = _sys._dg_kernels[_tid].active();
    for (std::vector<DGKernel *>::iterator it = dgks.begin(); it != dgks.end(); ++it)
    {
      const std::set<MooseVariable *> & mv_deps = (*it)->getMooseVariableDependencies();
      needed_moose_vars.insert(mv_deps.begin(), mv_deps.end());
    }
  }

  _fe_problem.setActiveElementalMooseVariables(needed_moose_vars, _tid);
  _fe_problem.prepareMaterials(_subdomain, _tid);
}
Ejemplo n.º 3
0
void
ComputeJacobianBlockThread::operator() (const ConstElemRange & range, bool bypass_threading/*=false*/)
{
  ParallelUniqueId puid;
  _tid = bypass_threading ? 0 : puid.id;

  unsigned int subdomain = std::numeric_limits<unsigned int>::max();

  const DofMap & dof_map = _precond_system.get_dof_map();
  std::vector<unsigned int> dof_indices;

  ConstElemRange::const_iterator range_end = range.end();
  for (ConstElemRange::const_iterator el = range.begin() ; el != range_end; ++el)
  {
    const Elem* elem = *el;
    unsigned int cur_subdomain = elem->subdomain_id();

    dof_map.dof_indices(elem, dof_indices);
    if (dof_indices.size())
    {
      _fe_problem.prepare(elem, _ivar, _jvar, dof_indices, _tid);
      _fe_problem.reinitElem(elem, _tid);

      if (cur_subdomain != subdomain)
      {
        subdomain = cur_subdomain;
        _fe_problem.subdomainSetup(subdomain, _tid);
        _nl._kernels[_tid].updateActiveKernels(cur_subdomain);
      }

      _fe_problem.reinitMaterials(cur_subdomain, _tid);

      //Kernels
      std::vector<KernelBase *> kernels = _nl._kernels[_tid].active();
      for (std::vector<KernelBase *>::const_iterator it = kernels.begin(); it != kernels.end(); it++)
      {
        KernelBase * kernel = *it;
        if (kernel->variable().index() == _ivar)
        {
          kernel->subProblem().prepareShapes(_jvar, _tid);
          kernel->computeOffDiagJacobian(_jvar);
        }
      }

      _fe_problem.swapBackMaterials(_tid);

      for (unsigned int side = 0; side < elem->n_sides(); side++)
      {
        std::vector<BoundaryID> boundary_ids = _mesh.boundaryIDs(elem, side);

        if (boundary_ids.size() > 0)
        {
          for (std::vector<BoundaryID>::iterator it = boundary_ids.begin(); it != boundary_ids.end(); ++it)
          {
            BoundaryID bnd_id = *it;

            std::vector<IntegratedBC *> bcs = _nl._bcs[_tid].activeIntegrated(bnd_id);
            if (bcs.size() > 0)
            {
              _fe_problem.prepareFace(elem, _tid);
              _fe_problem.reinitElemFace(elem, side, bnd_id, _tid);
              _fe_problem.reinitMaterialsFace(elem->subdomain_id(), _tid);
              _fe_problem.reinitMaterialsBoundary(bnd_id, _tid);

              for (std::vector<IntegratedBC *>::iterator it = bcs.begin(); it != bcs.end(); ++it)
              {
                IntegratedBC * bc = *it;
                if (bc->variable().index() == _ivar)
                {
                  if (bc->shouldApply())
                  {
                    bc->subProblem().prepareFaceShapes(_jvar, _tid);
                    bc->computeJacobianBlock(_jvar);
                  }
                }
              }

              _fe_problem.swapBackMaterialsFace(_tid);
            }
          }
        }

        if (elem->neighbor(side) != NULL)
        {
          // on internal edge
          // Pointer to the neighbor we are currently working on.
          const Elem * neighbor = elem->neighbor(side);

          // Get the global id of the element and the neighbor
          const unsigned int elem_id = elem->id();
          const unsigned int neighbor_id = neighbor->id();

          if ((neighbor->active() && (neighbor->level() == elem->level()) && (elem_id < neighbor_id)) || (neighbor->level() < elem->level()))
          {
            std::vector<DGKernel *> dgks = _nl._dg_kernels[_tid].active();
            if (dgks.size() > 0)
            {
              _fe_problem.prepareFace(elem, _tid);
              _fe_problem.reinitNeighbor(elem, side, _tid);

              _fe_problem.reinitMaterialsFace(elem->subdomain_id(), _tid);
              _fe_problem.reinitMaterialsNeighbor(neighbor->subdomain_id(), _tid);

              for (std::vector<DGKernel *>::iterator it = dgks.begin(); it != dgks.end(); ++it)
              {
                DGKernel * dg = *it;
                if (dg->variable().index() == _ivar)
                {
                  dg->subProblem().prepareFaceShapes(_jvar, _tid);
                  dg->subProblem().prepareNeighborShapes(_jvar, _tid);
                  dg->computeOffDiagJacobian(_jvar);
                }
              }

              _fe_problem.swapBackMaterialsFace(_tid);
              _fe_problem.swapBackMaterialsNeighbor(_tid);

              std::vector<unsigned int> neighbor_dof_indices;
              dof_map.dof_indices(neighbor, neighbor_dof_indices);
              {
                Threads::spin_mutex::scoped_lock lock(Threads::spin_mtx);
                _fe_problem.addJacobianNeighbor(_jacobian, _ivar, _jvar, dof_map, dof_indices, neighbor_dof_indices, _tid);
              }
            }
          }
        }
      }

      {
        Threads::spin_mutex::scoped_lock lock(Threads::spin_mtx);
        _fe_problem.addJacobianBlock(_jacobian, _ivar, _jvar, dof_map, dof_indices, _tid);
      }
    }
  }
}
Ejemplo n.º 4
0
void
ComputeFullJacobianThread::computeFaceJacobian(BoundaryID bnd_id)
{
  std::vector<std::pair<MooseVariable *, MooseVariable *> > & ce = _fe_problem.couplingEntries(_tid);
  for (std::vector<std::pair<MooseVariable *, MooseVariable *> >::iterator it = ce.begin(); it != ce.end(); ++it)
  {
    MooseVariable & ivar = *(*it).first;
    MooseVariable & jvar = *(*it).second;
    if (ivar.activeOnSubdomain(_subdomain) && jvar.activeOnSubdomain(_subdomain))
    {
      // only if there are dofs for j-variable (if it is subdomain restricted var, there may not be any)
      std::vector<IntegratedBC *> bcs = _sys._bcs[_tid].getBCs(bnd_id);
      for (std::vector<IntegratedBC *>::iterator jt = bcs.begin(); jt != bcs.end(); ++jt)
      {
        IntegratedBC * bc = *jt;
        if (bc->shouldApply() && bc->variable().index() == ivar.index() && bc->isImplicit())
        {
          bc->subProblem().prepareFaceShapes(jvar.index(), _tid);
          bc->computeJacobianBlock(jvar.index());
        }
      }
    }
  }

  const std::vector<MooseVariableScalar *> & scalar_vars = _sys.getScalarVariables(_tid);
  if (scalar_vars.size() > 0)
  {
    // go over nl-variables (non-scalar)
    const std::vector<MooseVariable *> & vars = _sys.getVariables(_tid);
    for (std::vector<MooseVariable *>::const_iterator it = vars.begin(); it != vars.end(); it++)
    {
      MooseVariable & ivar = *(*it);
      if (ivar.activeOnSubdomain(_subdomain) > 0)
      {
        // for each variable get the list of active kernels
        std::vector<IntegratedBC *> bcs = _sys._bcs[_tid].activeIntegrated(bnd_id);
        for (std::vector<IntegratedBC *>::iterator kt = bcs.begin(); kt != bcs.end(); ++kt)
        {
          IntegratedBC * bc = *kt;
          if (bc->variable().index() == ivar.index() && bc->isImplicit())
          {
            // now, get the list of coupled scalar vars and compute their off-diag jacobians
            const std::vector<MooseVariableScalar *> coupled_scalar_vars = bc->getCoupledMooseScalarVars();
            for (std::vector<MooseVariableScalar *>::const_iterator jt = coupled_scalar_vars.begin(); jt != coupled_scalar_vars.end(); jt++)
            {
              MooseVariableScalar & jvar = *(*jt);
              // Do: dvar / dscalar_var
              if (_sys.hasScalarVariable(jvar.name()))              // want to process only nl-variables (not aux ones)
                bc->computeJacobianBlockScalar(jvar.index());
            }
          }
        }
      }
    }
  }
}