std::vector<unsigned int> PolycrystalICTools::assignPointsToVariables(const std::vector<Point> & centerpoints, const Real op_num, const MooseMesh & mesh, const MooseVariable & var) { Real grain_num = centerpoints.size(); std::vector<unsigned int> assigned_op(grain_num); std::vector<int> min_op_ind(op_num); std::vector<Real> min_op_dist(op_num); // Assign grains to specific order parameters in a way that maximizes the distance for (unsigned int grain = 0; grain < grain_num; grain++) { // Determine the distance to the closest center assigned to each order parameter if (grain >= op_num) { // We can set the array to the distances to the grains 0..op_num-1 (see assignment in the else // case) for (unsigned int i = 0; i < op_num; ++i) { min_op_dist[i] = mesh.minPeriodicDistance(var.number(), centerpoints[grain], centerpoints[i]); min_op_ind[assigned_op[i]] = i; } // Now check if any of the extra grains are even closer for (unsigned int i = op_num; i < grain; ++i) { Real dist = mesh.minPeriodicDistance(var.number(), centerpoints[grain], centerpoints[i]); if (min_op_dist[assigned_op[i]] > dist) { min_op_dist[assigned_op[i]] = dist; min_op_ind[assigned_op[i]] = i; } } } else { assigned_op[grain] = grain; continue; } // Assign the current center point to the order parameter that is furthest away. unsigned int mx_ind = 0; for (unsigned int i = 1; i < op_num; ++i) // Find index of max if (min_op_dist[mx_ind] < min_op_dist[i]) mx_ind = i; assigned_op[grain] = mx_ind; } return assigned_op; }
std::set<SubdomainID> BlockRestrictable::variableSubdomainIDs(const InputParameters & parameters) const { // This method may be called before initializing the object. It doesn't use // any information from the class state. // Return an empty set if _sys is not defined if (!parameters.isParamValid("_sys")) return std::set<SubdomainID>(); // Get the SystemBase and the thread id SystemBase* sys = parameters.get<SystemBase *>("_sys"); THREAD_ID tid = parameters.get<THREAD_ID>("_tid"); // Pointer to MooseVariable MooseVariable * var = NULL; // Get the variable based on the type if (parameters.have_parameter<NonlinearVariableName>("variable")) var = &_blk_feproblem->getVariable(tid, parameters.get<NonlinearVariableName>("variable")); else if (parameters.have_parameter<AuxVariableName>("variable")) var = &_blk_feproblem->getVariable(tid, parameters.get<AuxVariableName>("variable")); else mooseError("Unknown variable."); // Return the block ids for the variable return sys->getSubdomainsForVar(var->number()); }
unsigned int Coupleable::coupled(const std::string & var_name, unsigned int comp) { if (!isCoupled(var_name)) return _optional_var_index[var_name]; MooseVariable * var = getVar(var_name, comp); switch (var->kind()) { case Moose::VAR_NONLINEAR: return var->number(); case Moose::VAR_AUXILIARY: return std::numeric_limits<unsigned int>::max() - var->number(); } mooseError("Unknown variable kind. Corrupted binary?"); }
unsigned int PolycrystalICTools::assignPointToGrain(const Point & p, const std::vector<Point> & centerpoints, const MooseMesh & mesh, const MooseVariable & var, const Real maxsize) { unsigned int grain_num = centerpoints.size(); Real min_distance = maxsize; unsigned int min_index = grain_num; // Loops through all of the grain centers and finds the center that is closest to the point p for (unsigned int grain = 0; grain < grain_num; grain++) { Real distance = mesh.minPeriodicDistance(var.number(), centerpoints[grain], p); if (min_distance > distance) { min_distance = distance; min_index = grain; } } if (min_index >= grain_num) mooseError("ERROR in PolycrystalVoronoiVoidIC: didn't find minimum values in grain_value_calc"); return min_index; }
void MultiAppCopyTransfer::transferDofObject(libMesh::DofObject * to_object, libMesh::DofObject * from_object, MooseVariable & to_var, MooseVariable & from_var) { if (to_object->n_dofs(to_var.sys().number(), to_var.number()) > 0) // If this variable has dofs at this node for (unsigned int comp = 0; comp < to_object->n_comp(to_var.sys().number(), to_var.number()); ++comp) { dof_id_type dof = to_object->dof_number(to_var.sys().number(), to_var.number(), comp); dof_id_type from_dof = from_object->dof_number(from_var.sys().number(), from_var.number(), comp); Real from_value = from_var.sys().solution()(from_dof); to_var.sys().solution().set(dof, from_value); } }
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. } }
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. } }