本文整理汇总了C++中NonlinearImplicitSystem::get_dof_map方法的典型用法代码示例。如果您正苦于以下问题:C++ NonlinearImplicitSystem::get_dof_map方法的具体用法?C++ NonlinearImplicitSystem::get_dof_map怎么用?C++ NonlinearImplicitSystem::get_dof_map使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NonlinearImplicitSystem
的用法示例。
在下文中一共展示了NonlinearImplicitSystem::get_dof_map方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: jacobian
// This function computes the Jacobian K(x)
void LaplaceYoung::jacobian (const NumericVector<Number> &soln,
SparseMatrix<Number> &jacobian,
NonlinearImplicitSystem &system)
{
// Get a constant reference to the mesh object.
const MeshBase& mesh = es.get_mesh();
// The dimension that we are running
const unsigned int dim = mesh.mesh_dimension();
// A reference to the \p DofMap object for this system. The \p DofMap
// object handles the index translation from node and element numbers
// to degree of freedom numbers. We will talk more about the \p DofMap
// in future examples.
const DofMap& dof_map = system.get_dof_map();
// Get a constant reference to the Finite Element type
// for the first (and only) variable in the system.
FEType fe_type = dof_map.variable_type(0);
// Build a Finite Element object of the specified type. Since the
// \p FEBase::build() member dynamically creates memory we will
// store the object as an \p AutoPtr<FEBase>. This can be thought
// of as a pointer that will clean up after itself.
AutoPtr<FEBase> fe (FEBase::build(dim, fe_type));
// A 5th order Gauss quadrature rule for numerical integration.
QGauss qrule (dim, FIFTH);
// Tell the finite element object to use our quadrature rule.
fe->attach_quadrature_rule (&qrule);
// Here we define some references to cell-specific data that
// will be used to assemble the linear system.
// We begin with the element Jacobian * quadrature weight at each
// integration point.
const std::vector<Real>& JxW = fe->get_JxW();
// The element shape functions evaluated at the quadrature points.
const std::vector<std::vector<Real> >& phi = fe->get_phi();
// The element shape function gradients evaluated at the quadrature
// points.
const std::vector<std::vector<RealGradient> >& dphi = fe->get_dphi();
// Define data structures to contain the Jacobian element matrix.
// Following basic finite element terminology we will denote these
// "Ke". More detail is in example 3.
DenseMatrix<Number> Ke;
// This vector will hold the degree of freedom indices for
// the element. These define where in the global system
// the element degrees of freedom get mapped.
std::vector<dof_id_type> dof_indices;
// Now we will loop over all the active elements in the mesh which
// are local to this processor.
// We will compute the element Jacobian contribution.
MeshBase::const_element_iterator el = mesh.active_local_elements_begin();
const MeshBase::const_element_iterator end_el = mesh.active_local_elements_end();
for ( ; el != end_el; ++el)
{
// Store a pointer to the element we are currently
// working on. This allows for nicer syntax later.
const Elem* elem = *el;
// Get the degree of freedom indices for the
// current element. These define where in the global
// matrix and right-hand-side this element will
// contribute to.
dof_map.dof_indices (elem, dof_indices);
// Compute the element-specific data for the current
// element. This involves computing the location of the
// quadrature points (q_point) and the shape functions
// (phi, dphi) for the current element.
fe->reinit (elem);
// Zero the element Jacobian before
// summing them. We use the resize member here because
// the number of degrees of freedom might have changed from
// the last element. Note that this will be the case if the
// element type is different (i.e. the last element was a
// triangle, now we are on a quadrilateral).
Ke.resize (dof_indices.size(),
dof_indices.size());
// Now we will build the element Jacobian. This involves
// a double loop to integrate the test funcions (i) against
// the trial functions (j). Note that the Jacobian depends
// on the current solution x, which we access using the soln
// vector.
//
for (unsigned int qp=0; qp<qrule.n_points(); qp++)
{
Gradient grad_u;
for (unsigned int i=0; i<phi.size(); i++)
//.........这里部分代码省略.........
示例2: DMCreateDomainDecomposition_libMesh
static PetscErrorCode DMCreateDomainDecomposition_libMesh(DM dm, PetscInt *len, char ***namelist, IS **innerislist, IS **outerislist, DM **dmlist)
{
PetscFunctionBegin;
PetscErrorCode ierr;
DM_libMesh *dlm = (DM_libMesh *)(dm->data);
NonlinearImplicitSystem *sys = dlm->sys;
IS emb;
if(dlm->decomposition_type != DMLIBMESH_DOMAIN_DECOMPOSITION) PetscFunctionReturn(0);
*len = dlm->decomposition->size();
if(namelist) {ierr = PetscMalloc(*len*sizeof(char*), namelist); CHKERRQ(ierr);}
if(innerislist) {ierr = PetscMalloc(*len*sizeof(IS), innerislist); CHKERRQ(ierr);}
if(outerislist) *outerislist = PETSC_NULL; /* FIX: allow mesh-based overlap. */
if(dmlist) {ierr = PetscMalloc(*len*sizeof(DM), dmlist); CHKERRQ(ierr);}
for(unsigned int d = 0; d < dlm->decomposition->size(); ++d) {
std::set<unsigned int> dindices;
std::string dname;
std::map<std::string, unsigned int> dblockids;
std::map<unsigned int,std::string> dblocknames;
unsigned int dbcount = 0;
for(std::set<unsigned int>::const_iterator bit = (*dlm->decomposition)[d].begin(); bit != (*dlm->decomposition)[d].end(); ++bit){
unsigned int b = *bit;
std::string bname = (*dlm->blocknames)[b];
dblockids.insert(std::pair<std::string, unsigned int>(bname,b));
dblocknames.insert(std::pair<unsigned int,std::string>(b,bname));
if(!dbcount) dname = bname;
else dname += "_" + bname;
++dbcount;
if(!innerislist) continue;
MeshBase::const_element_iterator el = sys->get_mesh().active_local_subdomain_elements_begin(b);
const MeshBase::const_element_iterator end_el = sys->get_mesh().active_local_subdomain_elements_end(b);
for ( ; el != end_el; ++el) {
const Elem* elem = *el;
std::vector<unsigned int> evindices;
/* Iterate only over this DM's variables. */
for(std::map<std::string, unsigned int>::const_iterator vit = dlm->varids->begin(); vit != dlm->varids->end(); ++vit) {
unsigned int v = vit->second;
// Get the degree of freedom indices for the given variable off the current element.
sys->get_dof_map().dof_indices(elem, evindices, v);
for(unsigned int i = 0; i < evindices.size(); ++i) {
unsigned int dof = evindices[i];
if(dof >= sys->get_dof_map().first_dof() && dof < sys->get_dof_map().end_dof()) /* might want to use variable_first/last_local_dof instead */
dindices.insert(dof);
}
}
}
}
if(namelist) {
ierr = PetscStrallocpy(dname.c_str(),(*namelist)+d); CHKERRQ(ierr);
}
if(innerislist) {
PetscInt *darray;
IS dis;
ierr = PetscMalloc(sizeof(PetscInt)*dindices.size(), &darray); CHKERRQ(ierr);
unsigned int i = 0;
for(std::set<unsigned int>::const_iterator it = dindices.begin(); it != dindices.end(); ++it) {
darray[i] = *it;
++i;
}
ierr = ISCreateGeneral(((PetscObject)dm)->comm, dindices.size(),darray, PETSC_OWN_POINTER, &dis); CHKERRQ(ierr);
if(dlm->embedding) {
/* Create a relative embedding into the parent's index space. */
ierr = ISMapFactorRight(dis,dlm->embedding, PETSC_TRUE, &emb); CHKERRQ(ierr);
PetscInt elen, dlen;
ierr = ISGetLocalSize(emb, &elen); CHKERRQ(ierr);
ierr = ISGetLocalSize(dis, &dlen); CHKERRQ(ierr);
if(elen != dlen) SETERRQ1(((PetscObject)dm)->comm, PETSC_ERR_PLIB, "Failed to embed field %D", d);
ierr = ISDestroy(&dis); CHKERRQ(ierr);
dis = emb;
}
else {
emb = dis;
}
if(innerislist) {
ierr = PetscObjectReference((PetscObject)dis); CHKERRQ(ierr);
(*innerislist)[d] = dis;
}
ierr = ISDestroy(&dis); CHKERRQ(ierr);
}
if(dmlist) {
DM ddm;
ierr = DMCreate(((PetscObject)dm)->comm, &ddm); CHKERRQ(ierr);
ierr = DMSetType(ddm, DMLIBMESH); CHKERRQ(ierr);
DM_libMesh *ddlm = (DM_libMesh*)(ddm->data);
ddlm->sys = dlm->sys;
/* copy over the varids and varnames */
*ddlm->varids = *dlm->varids;
*ddlm->varnames = *dlm->varnames;
/* set the blocks from the d-th part of the decomposition. */
*ddlm->blockids = dblockids;
*ddlm->blocknames = dblocknames;
ierr = PetscObjectReference((PetscObject)emb); CHKERRQ(ierr);
ddlm->embedding = emb;
ddlm->embedding_type = DMLIBMESH_DOMAIN_EMBEDDING;
ierr = DMLibMeshSetUpName_Private(ddm); CHKERRQ(ierr);
ierr = DMSetFromOptions(ddm); CHKERRQ(ierr);
(*dmlist)[d] = ddm;
}
}
PetscFunctionReturn(0);
//.........这里部分代码省略.........
示例3: residual
// Here we compute the residual R(x) = K(x)*x - f. The current solution
// x is passed in the soln vector
void LaplaceYoung::residual (const NumericVector<Number> &soln,
NumericVector<Number> &residual,
NonlinearImplicitSystem &system)
{
// Get a constant reference to the mesh object.
const MeshBase& mesh = es.get_mesh();
// The dimension that we are running
const unsigned int dim = mesh.mesh_dimension();
libmesh_assert_equal_to (dim, 2);
// A reference to the \p DofMap object for this system. The \p DofMap
// object handles the index translation from node and element numbers
// to degree of freedom numbers. We will talk more about the \p DofMap
// in future examples.
const DofMap& dof_map = system.get_dof_map();
// Get a constant reference to the Finite Element type
// for the first (and only) variable in the system.
FEType fe_type = dof_map.variable_type(0);
// Build a Finite Element object of the specified type. Since the
// \p FEBase::build() member dynamically creates memory we will
// store the object as an \p AutoPtr<FEBase>. This can be thought
// of as a pointer that will clean up after itself.
AutoPtr<FEBase> fe (FEBase::build(dim, fe_type));
// A 5th order Gauss quadrature rule for numerical integration.
QGauss qrule (dim, FIFTH);
// Tell the finite element object to use our quadrature rule.
fe->attach_quadrature_rule (&qrule);
// Declare a special finite element object for
// boundary integration.
AutoPtr<FEBase> fe_face (FEBase::build(dim, fe_type));
// Boundary integration requires one quadraure rule,
// with dimensionality one less than the dimensionality
// of the element.
QGauss qface(dim-1, FIFTH);
// Tell the finte element object to use our
// quadrature rule.
fe_face->attach_quadrature_rule (&qface);
// Here we define some references to cell-specific data that
// will be used to assemble the linear system.
// We begin with the element Jacobian * quadrature weight at each
// integration point.
const std::vector<Real>& JxW = fe->get_JxW();
// The element shape functions evaluated at the quadrature points.
const std::vector<std::vector<Real> >& phi = fe->get_phi();
// The element shape function gradients evaluated at the quadrature
// points.
const std::vector<std::vector<RealGradient> >& dphi = fe->get_dphi();
// Define data structures to contain the resdual contributions
DenseVector<Number> Re;
// This vector will hold the degree of freedom indices for
// the element. These define where in the global system
// the element degrees of freedom get mapped.
std::vector<dof_id_type> dof_indices;
// Now we will loop over all the active elements in the mesh which
// are local to this processor.
// We will compute the element residual.
residual.zero();
MeshBase::const_element_iterator el = mesh.active_local_elements_begin();
const MeshBase::const_element_iterator end_el = mesh.active_local_elements_end();
for ( ; el != end_el; ++el)
{
// Store a pointer to the element we are currently
// working on. This allows for nicer syntax later.
const Elem* elem = *el;
// Get the degree of freedom indices for the
// current element. These define where in the global
// matrix and right-hand-side this element will
// contribute to.
dof_map.dof_indices (elem, dof_indices);
// Compute the element-specific data for the current
// element. This involves computing the location of the
// quadrature points (q_point) and the shape functions
// (phi, dphi) for the current element.
fe->reinit (elem);
// We use the resize member here because
// the number of degrees of freedom might have changed from
// the last element. Note that this will be the case if the
// element type is different (i.e. the last element was a
// triangle, now we are on a quadrilateral).
//.........这里部分代码省略.........