petscdmlibmesh.h File Reference

Go to the source code of this file.

Functions

PetscErrorCode DMCreateLibMesh (MPI_Comm, libMesh::NonlinearImplicitSystem &, DM *)
 
PetscErrorCode DMLibMeshSetSystem (DM, libMesh::NonlinearImplicitSystem &)
 
PetscErrorCode DMLibMeshGetSystem (DM, libMesh::NonlinearImplicitSystem *&)
 
PetscErrorCode DMLibMeshGetBlocks (DM, PetscInt *, char ***)
 
PetscErrorCode DMLibMeshGetVariables (DM, PetscInt *, char ***)
 
PetscErrorCode DMLibMeshCreateFieldDecompositionDM (DM, PetscInt, PetscInt *, const char ***, DM *)
 
PetscErrorCode DMLibMeshCreateDomainDecompositionDM (DM, PetscInt, PetscInt *, const char ***, DM *)
 

Function Documentation

PetscErrorCode DMCreateLibMesh ( MPI_Comm  ,
libMesh::NonlinearImplicitSystem ,
DM *   
)

Definition at line 1094 of file petscdmlibmesh.C.

References CHKERRQ(), DMLibMeshSetSystem(), libMesh::ierr, PetscFunctionBegin, and PetscFunctionReturn().

Referenced by libMesh::PetscDMNonlinearSolver< T >::init().

1095 {
1098  ierr = DMCreate(comm, dm); CHKERRQ(ierr);
1099  ierr = DMSetType(*dm, DMLIBMESH); CHKERRQ(ierr);
1100  ierr = DMLibMeshSetSystem(*dm, sys); CHKERRQ(ierr);
1102 }
PetscErrorCode DMLibMeshCreateDomainDecompositionDM ( DM  ,
PetscInt  ,
PetscInt ,
const char ***  ,
DM *   
)
PetscErrorCode DMLibMeshCreateFieldDecompositionDM ( DM  ,
PetscInt  ,
PetscInt ,
const char ***  ,
DM *   
)
PetscErrorCode DMLibMeshGetBlocks ( DM  ,
PetscInt ,
char ***   
)

Definition at line 45 of file petscdmlibmesh.C.

References DM_libMesh::blockids, CHKERRQ(), libMesh::comm, dlm, libMesh::ierr, PetscBool, PetscFunctionBegin, and PetscFunctionReturn().

46 {
48  PetscInt i;
50  PetscValidHeaderSpecific(dm,DM_CLASSID,1);
51  PetscBool islibmesh;
52  ierr = PetscObjectTypeCompare((PetscObject)dm, DMLIBMESH,&islibmesh);
53  if(!islibmesh) SETERRQ2(((PetscObject)dm)->comm, PETSC_ERR_ARG_WRONG, "Got DM oftype %s, not of type %s", ((PetscObject)dm)->type_name, DMLIBMESH);
54  DM_libMesh *dlm = (DM_libMesh *)(dm->data);
55  PetscValidPointer(n,2);
56  *n = dlm->blockids->size();
57  if(!blocknames) PetscFunctionReturn(0);
58  ierr = PetscMalloc(*n*sizeof(char*), blocknames); CHKERRQ(ierr);
59  i = 0;
60  for(std::map<std::string, unsigned int>::const_iterator it = dlm->blockids->begin(); it != dlm->blockids->end(); ++it){
61  ierr = PetscStrallocpy(it->first.c_str(), *blocknames+i); CHKERRQ(ierr);
62  ++i;
63  }
65 }
PetscErrorCode DMLibMeshGetSystem ( DM  ,
libMesh::NonlinearImplicitSystem *&   
)

Definition at line 205 of file petscdmlibmesh.C.

References CHKERRQ(), libMesh::comm, dlm, libMesh::ierr, PetscBool, PetscFunctionBegin, PetscFunctionReturn(), and DM_libMesh::sys.

Referenced by DMlibMeshFunction(), DMlibMeshJacobian(), and DMVariableBounds_libMesh().

206 {
209  PetscValidHeaderSpecific(dm,DM_CLASSID,1);
210  PetscBool islibmesh;
211  ierr = PetscObjectTypeCompare((PetscObject)dm, DMLIBMESH,&islibmesh); CHKERRQ(ierr);
212  if(!islibmesh) SETERRQ2(((PetscObject)dm)->comm, PETSC_ERR_ARG_WRONG, "Got DM oftype %s, not of type %s", ((PetscObject)dm)->type_name, DMLIBMESH);
213  DM_libMesh *dlm = (DM_libMesh *)(dm->data);
214  sys = dlm->sys;
216 }
PetscErrorCode DMLibMeshGetVariables ( DM  ,
PetscInt ,
char ***   
)

Definition at line 69 of file petscdmlibmesh.C.

References CHKERRQ(), libMesh::comm, dlm, libMesh::ierr, PetscBool, PetscFunctionBegin, PetscFunctionReturn(), and DM_libMesh::varids.

70 {
73  PetscValidHeaderSpecific(dm,DM_CLASSID,1);
74  PetscBool islibmesh;
75  PetscInt i;
76  ierr = PetscObjectTypeCompare((PetscObject)dm, DMLIBMESH,&islibmesh);
77  if(!islibmesh) SETERRQ2(((PetscObject)dm)->comm, PETSC_ERR_ARG_WRONG, "Got DM oftype %s, not of type %s", ((PetscObject)dm)->type_name, DMLIBMESH);
78  DM_libMesh *dlm = (DM_libMesh *)(dm->data);
79  PetscValidPointer(n,2);
80  *n = dlm->varids->size();
81  if(!varnames) PetscFunctionReturn(0);
82  ierr = PetscMalloc(*n*sizeof(char*), varnames); CHKERRQ(ierr);
83  i = 0;
84  for(std::map<std::string, unsigned int>::const_iterator it = dlm->varids->begin(); it != dlm->varids->end(); ++it){
85  ierr = PetscStrallocpy(it->first.c_str(), *varnames+i); CHKERRQ(ierr);
86  ++i;
87  }
89 }
PetscErrorCode DMLibMeshSetSystem ( DM  ,
libMesh::NonlinearImplicitSystem  
)

Definition at line 142 of file petscdmlibmesh.C.

References libMesh::MeshBase::active_elements_begin(), libMesh::MeshBase::active_elements_end(), DM_libMesh::blockids, DM_libMesh::blocknames, CHKERRQ(), libMesh::ParallelObject::comm(), libMesh::comm, dlm, DMLibMeshSetUpName_Private(), end, libMesh::System::get_dof_map(), libMesh::System::get_mesh(), libMesh::ierr, libMesh::libmesh_parallel_only(), mesh, libMesh::DofMap::n_variables(), libMesh::Variable::name(), PETSC_ERR_ARG_WRONGSTATE, PetscBool, PetscFunctionBegin, PetscFunctionReturn(), libMesh::MeshBase::subdomain_name(), DM_libMesh::sys, libMesh::DofMap::variable(), DM_libMesh::varids, and DM_libMesh::varnames.

Referenced by DMCreateLibMesh().

143 {
144  const Parallel::Communicator &comm(sys.comm());
145 
148  PetscValidHeaderSpecific(dm,DM_CLASSID,1);
149  PetscBool islibmesh;
150  ierr = PetscObjectTypeCompare((PetscObject)dm, DMLIBMESH,&islibmesh);
151  if(!islibmesh) SETERRQ2(((PetscObject)dm)->comm, PETSC_ERR_ARG_WRONG, "Got DM oftype %s, not of type %s", ((PetscObject)dm)->type_name, DMLIBMESH);
152 
153  if(dm->setupcalled) SETERRQ(((PetscObject)dm)->comm, PETSC_ERR_ARG_WRONGSTATE, "Cannot reset the libMesh system after DM has been set up.");
154  DM_libMesh *dlm = (DM_libMesh *)(dm->data);
155  dlm->sys =&sys;
156  /* Initially populate the sets of active blockids and varids using all of the
157  existing blocks/variables (only variables are supported at the moment). */
158  DofMap& dofmap = dlm->sys->get_dof_map();
159  dlm->varids->clear();
160  dlm->varnames->clear();
161  for(unsigned int v = 0; v < dofmap.n_variables(); ++v) {
162  std::string vname = dofmap.variable(v).name();
163  dlm->varids->insert(std::pair<std::string,unsigned int>(vname,v));
164  dlm->varnames->insert(std::pair<unsigned int,std::string>(v,vname));
165  }
166  const MeshBase& mesh = dlm->sys->get_mesh();
167  dlm->blockids->clear();
168  dlm->blocknames->clear();
169  std::set<subdomain_id_type> blocks;
170  /* The following effectively is a verbatim copy of MeshBase::n_subdomains(). */
171  // This requires an inspection on every processor
172  libmesh_parallel_only(mesh.comm());
175  for (; el!=end; ++el)
176  blocks.insert((*el)->subdomain_id());
177  // Some subdomains may only live on other processors
178  comm.set_union(blocks);
179 
180  std::set<subdomain_id_type>::iterator bit = blocks.begin();
181  std::set<subdomain_id_type>::iterator bend = blocks.end();
182  if(bit == bend) SETERRQ(((PetscObject)dm)->comm, PETSC_ERR_PLIB, "No mesh blocks found.");
183 
184  for(; bit != bend; ++bit) {
185  subdomain_id_type bid = *bit;
186  std::string bname = mesh.subdomain_name(bid);
187  if(!bname.length()) {
188  /* Block names are currently implemented for Exodus II meshes
189  only, so we might have to make up our own block names and
190  maintain our own mapping of block ids to names.
191  */
192  std::ostringstream ss;
193  ss << "dm" << bid;
194  bname = ss.str();
195  }
196  dlm->blockids->insert(std::pair<std::string,unsigned int>(bname,bid));
197  dlm->blocknames->insert(std::pair<unsigned int,std::string>(bid,bname));
198  }
199  ierr = DMLibMeshSetUpName_Private(dm); CHKERRQ(ierr);
201 }

Site Created By: libMesh Developers
Last modified: February 07 2014 16:57:08 UTC

Hosted By:
SourceForge.net Logo