libMesh
Classes | Functions | Variables
petscdmlibmeshimpl.C File Reference

Go to the source code of this file.

Classes

struct  DM_libMesh
 
struct  DMVec_libMesh
 
struct  token
 

Functions

PetscErrorCode DMlibMeshGetVec_Private (DM, const char *, Vec *)
 
PetscErrorCode DMlibMeshSetUpName_Private (DM dm)
 
PetscErrorCode DMlibMeshSetSystem_libMesh (DM dm, NonlinearImplicitSystem &sys)
 
PetscErrorCode DMlibMeshGetSystem_libMesh (DM dm, NonlinearImplicitSystem *&sys)
 
PetscErrorCode DMlibMeshGetBlocks (DM dm, PetscInt *n, char ***blocknames)
 
PetscErrorCode DMlibMeshGetVariables (DM dm, PetscInt *n, char ***varnames)
 
static PetscErrorCode DMCreateFieldDecomposition_libMesh (DM dm, PetscInt *len, char ***namelist, IS **islist, DM **dmlist)
 
static PetscErrorCode DMCreateDomainDecomposition_libMesh (DM dm, PetscInt *len, char ***namelist, IS **innerislist, IS **outerislist, DM **dmlist)
 
PetscErrorCode DMlibMeshCreateFieldDecompositionDM (DM dm, PetscInt dnumber, PetscInt *dsizes, char ***dvarlists, DM *ddm)
 
PetscErrorCode DMlibMeshCreateDomainDecompositionDM (DM dm, PetscInt dnumber, PetscInt *dsizes, char ***dblocklists, DM *ddm)
 
static PetscErrorCode DMlibMeshParseDecompositionDescriptor_Private (DM dm, const char *ddesc, PetscInt *dtype, PetscInt *dcount, PetscInt **dsizes, char ****dlists)
 
static PetscErrorCode DMCreateFieldDecompositionDM_libMesh (DM dm, const char *ddesc, DM *ddm)
 
static PetscErrorCode DMCreateDomainDecompositionDM_libMesh (DM dm, const char *ddesc, DM *ddm)
 
static PetscErrorCode DMlibMeshFunction (DM dm, Vec x, Vec r)
 
static PetscErrorCode SNESFunction_DMlibMesh (SNES, Vec x, Vec r, void *ctx)
 
static PetscErrorCode DMlibMeshJacobian (#if PETSC_RELEASE_LESS_THAN(3, 5, 0) DM dm, Vec x, Mat jac, Mat pc, MatStructure *msflag#else DM dm, Vec x, Mat jac, Mat pc#endif)
 
static PetscErrorCode SNESJacobian_DMlibMesh (#if PETSC_RELEASE_LESS_THAN(3, 5, 0) SNES, Vec x, Mat *jac, Mat *pc, MatStructure *flag, void *ctx#else SNES, Vec x, Mat jac, Mat pc, void *ctx#endif)
 
static PetscErrorCode DMVariableBounds_libMesh (DM dm, Vec xl, Vec xu)
 
static PetscErrorCode DMCreateGlobalVector_libMesh (DM dm, Vec *x)
 
static PetscErrorCode DMCreateMatrix_libMesh (DM dm, const MatType, Mat *A) static PetscErrorCode DMCreateMatrix_libMesh(DM dm
 
 CHKERRQ (ierr)
 
 if (!eq) SETERRQ2(((PetscObject) dm) -> comm, PETSC_ERR_ARG_WRONG,"DM of type %s, not of type %s",((PetscObject) dm) ->type, DMLIBMESH)
 
 if (!dlm->sys) SETERRQ(PETSC_COMM_WORLD
 
 PetscFunctionReturn (0)
 
static PetscErrorCode DMView_libMesh (DM dm, PetscViewer viewer)
 
static PetscErrorCode DMSetUp_libMesh (DM dm)
 
static PetscErrorCode DMDestroy_libMesh (DM dm)
 
PetscErrorCode DMCreate_libMesh (DM dm)
 

Variables

static PetscErrorCode Mat * A
 
PetscErrorCode ierr = PetscObjectTypeCompare((PetscObject)dm, DMLIBMESH, &eq)
 
DM_libMeshdlm = (DM_libMesh *)(dm->data)
 
PetscBool eq
 
 PETSC_ERR_ARG_WRONGSTATE
 
No libMesh system set for DM_libMesh
 

Function Documentation

CHKERRQ ( ierr  )
PetscErrorCode DMCreate_libMesh ( DM  dm)

Definition at line 1162 of file petscdmlibmeshimpl.C.

References DM_libMesh::blockids, DM_libMesh::blocknames, CHKERRQ(), DM_libMesh::decomposition, DM_libMesh::decomposition_type, dlm, DMCreateDomainDecomposition_libMesh(), DMCreateDomainDecompositionDM_libMesh(), DMCreateFieldDecomposition_libMesh(), DMCreateFieldDecompositionDM_libMesh(), DMCreateGlobalVector_libMesh(), DMCreateMatrix_libMesh(), DMDestroy_libMesh(), DMlibMeshGetSystem_libMesh(), DMlibMeshSetSystem_libMesh(), DMSetUp_libMesh(), DMView_libMesh(), ierr, PetscFunctionReturn(), DM_libMesh::varids, and DM_libMesh::varnames.

Referenced by libMesh::LibMeshInit::LibMeshInit().

1163 {
1164  PetscErrorCode ierr;
1165  DM_libMesh * dlm;
1166 
1167  PetscFunctionBegin;
1168  PetscValidHeaderSpecific(dm,DM_CLASSID,1);
1169 #if PETSC_RELEASE_LESS_THAN(3,5,0)
1170  ierr = PetscNewLog(dm,DM_libMesh,&dlm);CHKERRQ(ierr);
1171 #else
1172  ierr = PetscNewLog(dm,&dlm);CHKERRQ(ierr);
1173 #endif
1174  dm->data = dlm;
1175 
1176  /* DMlibMesh impl */
1177  dlm->varids = new(std::map<std::string, unsigned int>);
1178  dlm->blockids = new(std::map<std::string, unsigned int>);
1179  dlm->varnames = new(std::map<unsigned int, std::string>);
1180  dlm->blocknames = new(std::map<unsigned int, std::string>);
1181  dlm->decomposition = PETSC_NULL;
1182  dlm->decomposition_type = DMLIBMESH_NO_DECOMPOSITION;
1183 
1184  /* DM API */
1185  dm->ops->createglobalvector = DMCreateGlobalVector_libMesh;
1186  dm->ops->createlocalvector = 0; // DMCreateLocalVector_libMesh;
1187  dm->ops->getcoloring = 0; // DMGetColoring_libMesh;
1188  dm->ops->creatematrix = DMCreateMatrix_libMesh;
1189  dm->ops->createinterpolation= 0; // DMCreateInterpolation_libMesh;
1190 
1191  dm->ops->refine = 0; // DMRefine_libMesh;
1192  dm->ops->coarsen = 0; // DMCoarsen_libMesh;
1193  dm->ops->getinjection = 0; // DMGetInjection_libMesh;
1194  dm->ops->getaggregates = 0; // DMGetAggregates_libMesh;
1195 
1196 #if PETSC_RELEASE_LESS_THAN(3,3,1)
1197  dm->ops->createfielddecompositiondm = DMCreateFieldDecompositionDM_libMesh;
1198  dm->ops->createdomaindecompositiondm = DMCreateDomainDecompositionDM_libMesh;
1199 #endif
1200  dm->ops->createfielddecomposition = DMCreateFieldDecomposition_libMesh;
1201  dm->ops->createdomaindecomposition = DMCreateDomainDecomposition_libMesh;
1202 
1203  dm->ops->destroy = DMDestroy_libMesh;
1204  dm->ops->view = DMView_libMesh;
1205  dm->ops->setfromoptions = 0; // DMSetFromOptions_libMesh;
1206  dm->ops->setup = DMSetUp_libMesh;
1207 
1208  /* DMlibMesh API */
1209 #if PETSC_RELEASE_LESS_THAN(3,4,0)
1210  ierr = PetscObjectComposeFunction((PetscObject)dm,"DMlibMeshSetSystem_C",PETSC_NULL,(PetscVoidFunction)DMlibMeshSetSystem_libMesh);CHKERRQ(ierr);
1211  ierr = PetscObjectComposeFunction((PetscObject)dm,"DMlibMeshGetSystem_C",PETSC_NULL,(PetscVoidFunction)DMlibMeshGetSystem_libMesh);CHKERRQ(ierr);
1212 #else
1213  ierr = PetscObjectComposeFunction((PetscObject)dm,"DMlibMeshSetSystem_C",DMlibMeshSetSystem_libMesh);CHKERRQ(ierr);
1214  ierr = PetscObjectComposeFunction((PetscObject)dm,"DMlibMeshGetSystem_C",DMlibMeshGetSystem_libMesh);CHKERRQ(ierr);
1215 #endif
1216 
1218 }
static PetscErrorCode DMCreateDomainDecomposition_libMesh(DM dm, PetscInt *len, char ***namelist, IS **innerislist, IS **outerislist, DM **dmlist)
static PetscErrorCode DMCreateGlobalVector_libMesh(DM dm, Vec *x)
static PetscErrorCode DMCreateDomainDecompositionDM_libMesh(DM dm, const char *ddesc, DM *ddm)
std::map< std::string, unsigned int > * blockids
PetscErrorCode DMlibMeshSetSystem_libMesh(DM dm, NonlinearImplicitSystem &sys)
std::map< std::string, unsigned int > * varids
static PetscErrorCode DMCreateFieldDecomposition_libMesh(DM dm, PetscInt *len, char ***namelist, IS **islist, DM **dmlist)
std::vector< std::set< unsigned int > > * decomposition
static PetscErrorCode DMSetUp_libMesh(DM dm)
static PetscErrorCode DMCreateMatrix_libMesh(DM dm, const MatType, Mat *A) static PetscErrorCode DMCreateMatrix_libMesh(DM dm
PetscErrorCode DMlibMeshGetSystem_libMesh(DM dm, NonlinearImplicitSystem *&sys)
std::map< unsigned int, std::string > * varnames
std::map< unsigned int, std::string > * blocknames
static PetscErrorCode DMCreateFieldDecompositionDM_libMesh(DM dm, const char *ddesc, DM *ddm)
PetscErrorCode ierr
DM_libMesh * dlm
PetscFunctionReturn(0)
CHKERRQ(ierr)
static PetscErrorCode DMView_libMesh(DM dm, PetscViewer viewer)
unsigned int decomposition_type
static PetscErrorCode DMDestroy_libMesh(DM dm)
static PetscErrorCode DMCreateDomainDecomposition_libMesh ( DM  dm,
PetscInt *  len,
char ***  namelist,
IS **  innerislist,
IS **  outerislist,
DM **  dmlist 
)
static

Definition at line 371 of file petscdmlibmeshimpl.C.

References libMesh::MeshBase::active_local_subdomain_elements_begin(), libMesh::MeshBase::active_local_subdomain_elements_end(), DM_libMesh::blockids, DM_libMesh::blocknames, CHKERRQ(), DM_libMesh::decomposition, DM_libMesh::decomposition_type, dlm, DMlibMeshSetUpName_Private(), libMesh::DofMap::dof_indices(), DM_libMesh::embedding, DM_libMesh::embedding_type, end, libMesh::DofMap::end_dof(), libMesh::DofMap::first_dof(), libMesh::System::get_dof_map(), libMesh::System::get_mesh(), ierr, PETSC_OWN_POINTER, PetscFunctionReturn(), DM_libMesh::sys, libMesh::sys, DM_libMesh::varids, and DM_libMesh::varnames.

Referenced by DMCreate_libMesh().

372 {
373  PetscFunctionBegin;
374  PetscErrorCode ierr;
375  DM_libMesh * dlm = (DM_libMesh *)(dm->data);
377  IS emb;
378  if (dlm->decomposition_type != DMLIBMESH_DOMAIN_DECOMPOSITION) PetscFunctionReturn(0);
379  *len = dlm->decomposition->size();
380  if (namelist) {ierr = PetscMalloc(*len*sizeof(char *), namelist); CHKERRQ(ierr);}
381  if (innerislist) {ierr = PetscMalloc(*len*sizeof(IS), innerislist); CHKERRQ(ierr);}
382  if (outerislist) *outerislist = PETSC_NULL; /* FIX: allow mesh-based overlap. */
383  if (dmlist) {ierr = PetscMalloc(*len*sizeof(DM), dmlist); CHKERRQ(ierr);}
384  for (unsigned int d = 0; d < dlm->decomposition->size(); ++d) {
385  std::set<numeric_index_type> dindices;
386  std::string dname;
387  std::map<std::string, unsigned int> dblockids;
388  std::map<unsigned int,std::string> dblocknames;
389  unsigned int dbcount = 0;
390  for (std::set<unsigned int>::const_iterator bit = (*dlm->decomposition)[d].begin(); bit != (*dlm->decomposition)[d].end(); ++bit){
391  unsigned int b = *bit;
392  std::string bname = (*dlm->blocknames)[b];
393  dblockids.insert(std::pair<std::string, unsigned int>(bname,b));
394  dblocknames.insert(std::pair<unsigned int,std::string>(b,bname));
395  if (!dbcount) dname = bname;
396  else dname += "_" + bname;
397  ++dbcount;
398  if (!innerislist) continue;
401  for ( ; el != end_el; ++el) {
402  const Elem * elem = *el;
403  std::vector<numeric_index_type> evindices;
404  /* Iterate only over this DM's variables. */
405  for (std::map<std::string, unsigned int>::const_iterator vit = dlm->varids->begin(); vit != dlm->varids->end(); ++vit) {
406  unsigned int v = vit->second;
407  // Get the degree of freedom indices for the given variable off the current element.
408  sys->get_dof_map().dof_indices(elem, evindices, v);
409  for (unsigned int i = 0; i < evindices.size(); ++i) {
410  numeric_index_type dof = evindices[i];
411  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 */
412  dindices.insert(dof);
413  }
414  }
415  }
416  }
417  if (namelist) {
418  ierr = PetscStrallocpy(dname.c_str(),(*namelist)+d); CHKERRQ(ierr);
419  }
420  if (innerislist) {
421  PetscInt * darray;
422  IS dis;
423  ierr = PetscMalloc(sizeof(PetscInt)*dindices.size(), &darray); CHKERRQ(ierr);
424  numeric_index_type i = 0;
425  for (std::set<numeric_index_type>::const_iterator it = dindices.begin(); it != dindices.end(); ++it) {
426  darray[i] = *it;
427  ++i;
428  }
429  ierr = ISCreateGeneral(((PetscObject)dm)->comm, dindices.size(),darray, PETSC_OWN_POINTER, &dis); CHKERRQ(ierr);
430  if (dlm->embedding) {
431  /* Create a relative embedding into the parent's index space. */
432 #if PETSC_RELEASE_LESS_THAN(3,3,1)
433  ierr = ISMapFactorRight(dis,dlm->embedding, PETSC_TRUE, &emb); CHKERRQ(ierr);
434 #else
435  ierr = ISEmbed(dis,dlm->embedding, PETSC_TRUE, &emb); CHKERRQ(ierr);
436 #endif
437  PetscInt elen, dlen;
438  ierr = ISGetLocalSize(emb, &elen); CHKERRQ(ierr);
439  ierr = ISGetLocalSize(dis, &dlen); CHKERRQ(ierr);
440  if (elen != dlen) SETERRQ1(((PetscObject)dm)->comm, PETSC_ERR_PLIB, "Failed to embed field %D", d);
441  ierr = ISDestroy(&dis); CHKERRQ(ierr);
442  dis = emb;
443  }
444  else {
445  emb = dis;
446  }
447  if (innerislist) {
448  ierr = PetscObjectReference((PetscObject)dis); CHKERRQ(ierr);
449  (*innerislist)[d] = dis;
450  }
451  ierr = ISDestroy(&dis); CHKERRQ(ierr);
452  }
453  if (dmlist) {
454  DM ddm;
455  ierr = DMCreate(((PetscObject)dm)->comm, &ddm); CHKERRQ(ierr);
456  ierr = DMSetType(ddm, DMLIBMESH); CHKERRQ(ierr);
457  DM_libMesh * ddlm = (DM_libMesh *)(ddm->data);
458  ddlm->sys = dlm->sys;
459  /* copy over the varids and varnames */
460  *ddlm->varids = *dlm->varids;
461  *ddlm->varnames = *dlm->varnames;
462  /* set the blocks from the d-th part of the decomposition. */
463  *ddlm->blockids = dblockids;
464  *ddlm->blocknames = dblocknames;
465  ierr = PetscObjectReference((PetscObject)emb); CHKERRQ(ierr);
466  ddlm->embedding = emb;
467  ddlm->embedding_type = DMLIBMESH_DOMAIN_EMBEDDING;
468 
469  ierr = DMlibMeshSetUpName_Private(ddm); CHKERRQ(ierr);
470  ierr = DMSetFromOptions(ddm); CHKERRQ(ierr);
471  (*dmlist)[d] = ddm;
472  }
473  }
475 }
NonlinearImplicitSystem * sys
PetscErrorCode DMlibMeshSetUpName_Private(DM dm)
The definition of the const_element_iterator struct.
Definition: mesh_base.h:1494
ImplicitSystem & sys
unsigned int embedding_type
std::map< std::string, unsigned int > * blockids
std::map< std::string, unsigned int > * varids
This is the base class from which all geometric element types are derived.
Definition: elem.h:89
IterBase * end
Also have a polymorphic pointer to the end object, this prevents iterating past the end...
virtual element_iterator active_local_subdomain_elements_end(subdomain_id_type subdomain_id)=0
dof_id_type first_dof(const processor_id_type proc) const
Definition: dof_map.h:535
std::vector< std::set< unsigned int > > * decomposition
dof_id_type end_dof(const processor_id_type proc) const
Definition: dof_map.h:577
virtual element_iterator active_local_subdomain_elements_begin(subdomain_id_type subdomain_id)=0
const MeshBase & get_mesh() const
Definition: system.h:2014
const DofMap & get_dof_map() const
Definition: system.h:2030
dof_id_type numeric_index_type
Definition: id_types.h:92
std::map< unsigned int, std::string > * varnames
This class provides a specific system class.
std::map< unsigned int, std::string > * blocknames
PetscErrorCode ierr
DM_libMesh * dlm
PetscFunctionReturn(0)
CHKERRQ(ierr)
unsigned int decomposition_type
void dof_indices(const Elem *const elem, std::vector< dof_id_type > &di) const
Fills the vector di with the global degree of freedom indices for the element.
Definition: dof_map.C:1917
static PetscErrorCode DMCreateDomainDecompositionDM_libMesh ( DM  dm,
const char *  ddesc,
DM *  ddm 
)
static

Definition at line 758 of file petscdmlibmeshimpl.C.

References CHKERRQ(), DMlibMeshCreateDomainDecompositionDM(), DMlibMeshParseDecompositionDescriptor_Private(), ierr, and PetscFunctionReturn().

Referenced by DMCreate_libMesh().

759 {
760  PetscFunctionBegin;
761  PetscErrorCode ierr;
762  PetscInt dtype, dcount;
763  PetscInt * dsizes;
764  char *** dlists;
765  PetscFunctionBegin;
766  *ddm = PETSC_NULL;
767  ierr = DMlibMeshParseDecompositionDescriptor_Private(dm,ddesc,&dtype,&dcount,&dsizes,&dlists); CHKERRQ(ierr);
768  if (dtype == DMLIBMESH_DOMAIN_DECOMPOSITION) {
769  ierr = DMlibMeshCreateDomainDecompositionDM(dm,dcount,dsizes,dlists,ddm); CHKERRQ(ierr);
770  }
771  else SETERRQ1(((PetscObject)dm)->comm, PETSC_ERR_PLIB, "Unexpected unknown decomposition type for domain decomposition descriptor %s", ddesc);
773 }
static PetscErrorCode DMlibMeshParseDecompositionDescriptor_Private(DM dm, const char *ddesc, PetscInt *dtype, PetscInt *dcount, PetscInt **dsizes, char ****dlists)
PetscErrorCode ierr
PetscErrorCode DMlibMeshCreateDomainDecompositionDM(DM dm, PetscInt dnumber, PetscInt *dsizes, char ***dblocklists, DM *ddm)
PetscFunctionReturn(0)
CHKERRQ(ierr)
static PetscErrorCode DMCreateFieldDecomposition_libMesh ( DM  dm,
PetscInt *  len,
char ***  namelist,
IS **  islist,
DM **  dmlist 
)
static

Definition at line 265 of file petscdmlibmeshimpl.C.

References libMesh::MeshBase::active_local_subdomain_elements_begin(), libMesh::MeshBase::active_local_subdomain_elements_end(), DM_libMesh::blockids, DM_libMesh::blocknames, CHKERRQ(), DM_libMesh::decomposition, DM_libMesh::decomposition_type, dlm, DMlibMeshSetUpName_Private(), libMesh::DofMap::dof_indices(), DM_libMesh::embedding, DM_libMesh::embedding_type, end, libMesh::DofMap::end_dof(), libMesh::DofMap::first_dof(), libMesh::System::get_dof_map(), libMesh::System::get_mesh(), ierr, PETSC_OWN_POINTER, PetscFunctionReturn(), DM_libMesh::sys, libMesh::sys, DM_libMesh::varids, and DM_libMesh::varnames.

Referenced by DMCreate_libMesh().

266 {
267  PetscFunctionBegin;
268  PetscErrorCode ierr;
269  DM_libMesh * dlm = (DM_libMesh *)(dm->data);
271  IS emb;
272  if (dlm->decomposition_type != DMLIBMESH_FIELD_DECOMPOSITION) PetscFunctionReturn(0);
273 
274  *len = dlm->decomposition->size();
275  if (namelist) {ierr = PetscMalloc(*len*sizeof(char *), namelist); CHKERRQ(ierr);}
276  if (islist) {ierr = PetscMalloc(*len*sizeof(IS), islist); CHKERRQ(ierr);}
277  if (dmlist) {ierr = PetscMalloc(*len*sizeof(DM), dmlist); CHKERRQ(ierr);}
278  DofMap & dofmap = dlm->sys->get_dof_map();
279  for (unsigned int d = 0; d < dlm->decomposition->size(); ++d) {
280  std::set<numeric_index_type> dindices;
281  std::string dname;
282  std::map<std::string, unsigned int> dvarids;
283  std::map<unsigned int, std::string> dvarnames;
284  unsigned int dvcount = 0;
285  for (std::set<unsigned int>::const_iterator dvit = (*dlm->decomposition)[d].begin(); dvit != (*dlm->decomposition)[d].end(); ++dvit){
286  unsigned int v = *dvit;
287  std::string vname = (*dlm->varnames)[v];
288  dvarids.insert(std::pair<std::string, unsigned int>(vname,v));
289  dvarnames.insert(std::pair<unsigned int,std::string>(v,vname));
290  if (!dvcount) dname = vname;
291  else dname += "_" + vname;
292  ++dvcount;
293  if (!islist) continue;
294  /* Iterate only over this DM's blocks. */
295  for (std::map<std::string, unsigned int>::const_iterator bit = dlm->blockids->begin(); bit != dlm->blockids->end(); ++bit) {
296  unsigned int b = bit->second;
299  for ( ; el != end_el; ++el) {
300  const Elem * elem = *el;
301  //unsigned int e_subdomain = elem->subdomain_id();
302  std::vector<numeric_index_type> evindices;
303  // Get the degree of freedom indices for the given variable off the current element.
304  dofmap.dof_indices(elem, evindices, v);
305  for (unsigned int i = 0; i < evindices.size(); ++i) {
306  numeric_index_type dof = evindices[i];
307  if (dof >= dofmap.first_dof() && dof < dofmap.end_dof()) /* might want to use variable_first/last_local_dof instead */
308  dindices.insert(dof);
309  }
310  }
311  }
312  }
313  if (namelist) {
314  ierr = PetscStrallocpy(dname.c_str(),(*namelist)+d); CHKERRQ(ierr);
315  }
316  if (islist) {
317  IS dis;
318  PetscInt * darray;
319  ierr = PetscMalloc(sizeof(PetscInt)*dindices.size(), &darray); CHKERRQ(ierr);
320  numeric_index_type i = 0;
321  for (std::set<numeric_index_type>::const_iterator it = dindices.begin(); it != dindices.end(); ++it) {
322  darray[i] = *it;
323  ++i;
324  }
325  ierr = ISCreateGeneral(((PetscObject)dm)->comm, dindices.size(),darray, PETSC_OWN_POINTER, &dis); CHKERRQ(ierr);
326  if (dlm->embedding) {
327  /* Create a relative embedding into the parent's index space. */
328 #if PETSC_RELEASE_LESS_THAN(3,3,1)
329  ierr = ISMapFactorRight(dis,dlm->embedding, PETSC_TRUE, &emb); CHKERRQ(ierr);
330 #else
331  ierr = ISEmbed(dis,dlm->embedding, PETSC_TRUE, &emb); CHKERRQ(ierr);
332 #endif
333  PetscInt elen, dlen;
334  ierr = ISGetLocalSize(emb, &elen); CHKERRQ(ierr);
335  ierr = ISGetLocalSize(dis, &dlen); CHKERRQ(ierr);
336  if (elen != dlen) SETERRQ1(((PetscObject)dm)->comm, PETSC_ERR_PLIB, "Failed to embed subdomain %D", d);
337  ierr = ISDestroy(&dis); CHKERRQ(ierr);
338  dis = emb;
339  }
340  else {
341  emb = dis;
342  }
343  (*islist)[d] = dis;
344  }
345  if (dmlist) {
346  DM ddm;
347  ierr = DMCreate(((PetscObject)dm)->comm, &ddm); CHKERRQ(ierr);
348  ierr = DMSetType(ddm, DMLIBMESH); CHKERRQ(ierr);
349  DM_libMesh * ddlm = (DM_libMesh *)(ddm->data);
350  ddlm->sys = dlm->sys;
351  /* copy over the block ids and names */
352  *ddlm->blockids = *dlm->blockids;
353  *ddlm->blocknames = *dlm->blocknames;
354  /* set the vars from the d-th part of the decomposition. */
355  *ddlm->varids = dvarids;
356  *ddlm->varnames = dvarnames;
357  ierr = PetscObjectReference((PetscObject)emb); CHKERRQ(ierr);
358  ddlm->embedding = emb;
359  ddlm->embedding_type = DMLIBMESH_FIELD_EMBEDDING;
360 
361  ierr = DMlibMeshSetUpName_Private(ddm); CHKERRQ(ierr);
362  ierr = DMSetFromOptions(ddm); CHKERRQ(ierr);
363  (*dmlist)[d] = ddm;
364  }
365  }
367 }
NonlinearImplicitSystem * sys
PetscErrorCode DMlibMeshSetUpName_Private(DM dm)
The definition of the const_element_iterator struct.
Definition: mesh_base.h:1494
ImplicitSystem & sys
unsigned int embedding_type
std::map< std::string, unsigned int > * blockids
std::map< std::string, unsigned int > * varids
This is the base class from which all geometric element types are derived.
Definition: elem.h:89
IterBase * end
Also have a polymorphic pointer to the end object, this prevents iterating past the end...
virtual element_iterator active_local_subdomain_elements_end(subdomain_id_type subdomain_id)=0
This class handles the numbering of degrees of freedom on a mesh.
Definition: dof_map.h:167
dof_id_type first_dof(const processor_id_type proc) const
Definition: dof_map.h:535
std::vector< std::set< unsigned int > > * decomposition
dof_id_type end_dof(const processor_id_type proc) const
Definition: dof_map.h:577
virtual element_iterator active_local_subdomain_elements_begin(subdomain_id_type subdomain_id)=0
const MeshBase & get_mesh() const
Definition: system.h:2014
const DofMap & get_dof_map() const
Definition: system.h:2030
dof_id_type numeric_index_type
Definition: id_types.h:92
std::map< unsigned int, std::string > * varnames
This class provides a specific system class.
std::map< unsigned int, std::string > * blocknames
PetscErrorCode ierr
DM_libMesh * dlm
PetscFunctionReturn(0)
CHKERRQ(ierr)
unsigned int decomposition_type
void dof_indices(const Elem *const elem, std::vector< dof_id_type > &di) const
Fills the vector di with the global degree of freedom indices for the element.
Definition: dof_map.C:1917
static PetscErrorCode DMCreateFieldDecompositionDM_libMesh ( DM  dm,
const char *  ddesc,
DM *  ddm 
)
static

Definition at line 739 of file petscdmlibmeshimpl.C.

References CHKERRQ(), DMlibMeshCreateFieldDecompositionDM(), DMlibMeshParseDecompositionDescriptor_Private(), ierr, and PetscFunctionReturn().

Referenced by DMCreate_libMesh().

740 {
741  PetscFunctionBegin;
742  PetscErrorCode ierr;
743  PetscInt dtype, dcount;
744  PetscInt * dsizes;
745  char *** dlists;
746  PetscFunctionBegin;
747  *ddm = PETSC_NULL;
748  ierr = DMlibMeshParseDecompositionDescriptor_Private(dm,ddesc,&dtype,&dcount,&dsizes,&dlists); CHKERRQ(ierr);
749  if (dtype == DMLIBMESH_FIELD_DECOMPOSITION){
750  ierr = DMlibMeshCreateFieldDecompositionDM(dm,dcount,dsizes,dlists,ddm); CHKERRQ(ierr);
751  }
752  else SETERRQ1(((PetscObject)dm)->comm, PETSC_ERR_PLIB, "Unexpected unknown decomposition type for field decomposition descriptor %s", ddesc);
754 }
PetscErrorCode DMlibMeshCreateFieldDecompositionDM(DM dm, PetscInt dnumber, PetscInt *dsizes, char ***dvarlists, DM *ddm)
static PetscErrorCode DMlibMeshParseDecompositionDescriptor_Private(DM dm, const char *ddesc, PetscInt *dtype, PetscInt *dcount, PetscInt **dsizes, char ****dlists)
PetscErrorCode ierr
PetscFunctionReturn(0)
CHKERRQ(ierr)
static PetscErrorCode DMCreateGlobalVector_libMesh ( DM  dm,
Vec *  x 
)
static

Definition at line 972 of file petscdmlibmeshimpl.C.

References A, CHKERRQ(), dlm, DMCreateMatrix_libMesh(), DM_libMesh::embedding, eq, ierr, PETSC_ERR_ARG_WRONGSTATE, PetscFunctionReturn(), libMesh::System::solution, and DM_libMesh::sys.

Referenced by DMCreate_libMesh().

973 {
974  PetscFunctionBegin;
975  PetscErrorCode ierr;
976  DM_libMesh * dlm = (DM_libMesh *)(dm->data);
977  PetscBool eq;
978 
979  ierr = PetscObjectTypeCompare((PetscObject)dm, DMLIBMESH, &eq); CHKERRQ(ierr);
980 
981  if (!eq)
982  SETERRQ2(((PetscObject)dm)->comm, PETSC_ERR_ARG_WRONG, "DM of type %s, not of type %s", ((PetscObject)dm)->type, DMLIBMESH);
983 
984  if (!dlm->sys)
985  SETERRQ(PETSC_COMM_WORLD, PETSC_ERR_ARG_WRONGSTATE, "No libMesh system set for DM_libMesh");
986 
987  NumericVector<Number> * nv = (dlm->sys->solution).get();
988  PetscVector<Number> * pv = dynamic_cast<PetscVector<Number> *>(nv);
989  Vec v = pv->vec();
990  /* Unfortunately, currently this does not produce a ghosted vector, so nonlinear subproblem solves aren't going to be easily available.
991  Should work fine for getting vectors out for linear subproblem solvers. */
992  if (dlm->embedding) {
993  PetscInt n;
994  ierr = VecCreate(((PetscObject)v)->comm, x); CHKERRQ(ierr);
995  ierr = ISGetLocalSize(dlm->embedding, &n); CHKERRQ(ierr);
996  ierr = VecSetSizes(*x,n,PETSC_DETERMINE); CHKERRQ(ierr);
997  ierr = VecSetType(*x,((PetscObject)v)->type_name); CHKERRQ(ierr);
998  ierr = VecSetFromOptions(*x); CHKERRQ(ierr);
999  ierr = VecSetUp(*x); CHKERRQ(ierr);
1000  }
1001  else {
1002  ierr = VecDuplicate(v,x); CHKERRQ(ierr);
1003  }
1004  ierr = PetscObjectCompose((PetscObject)*x,"DM",(PetscObject)dm); CHKERRQ(ierr);
1006 }
NonlinearImplicitSystem * sys
PetscBool eq
PetscErrorCode Vec x
UniquePtr< NumericVector< Number > > solution
Data structure to hold solution values.
Definition: system.h:1523
PetscTruth PetscBool
Definition: petsc_macro.h:64
PetscErrorCode ierr
DM_libMesh * dlm
PetscFunctionReturn(0)
CHKERRQ(ierr)
PETSC_ERR_ARG_WRONGSTATE
static PetscErrorCode DMCreateMatrix_libMesh ( DM  dm,
const MatType  ,
Mat *  A 
)
static
static PetscErrorCode DMDestroy_libMesh ( DM  dm)
static

Definition at line 1143 of file petscdmlibmeshimpl.C.

References DM_libMesh::blockids, DM_libMesh::blocknames, CHKERRQ(), DM_libMesh::decomposition, DM_libMesh::embedding, ierr, PetscFunctionReturn(), DM_libMesh::varids, and DM_libMesh::varnames.

Referenced by DMCreate_libMesh().

1144 {
1145  DM_libMesh * dlm = (DM_libMesh *)(dm->data);
1146  PetscErrorCode ierr;
1147  PetscFunctionBegin;
1148  delete dlm->varids;
1149  delete dlm->varnames;
1150  delete dlm->blockids;
1151  delete dlm->blocknames;
1152  delete dlm->decomposition;
1153  ierr = ISDestroy(&dlm->embedding); CHKERRQ(ierr);
1154  ierr = PetscFree(dm->data); CHKERRQ(ierr);
1155 
1157 }
std::map< std::string, unsigned int > * blockids
std::map< std::string, unsigned int > * varids
std::vector< std::set< unsigned int > > * decomposition
std::map< unsigned int, std::string > * varnames
std::map< unsigned int, std::string > * blocknames
PetscErrorCode ierr
DM_libMesh * dlm
PetscFunctionReturn(0)
CHKERRQ(ierr)
PetscErrorCode DMlibMeshCreateDomainDecompositionDM ( DM  dm,
PetscInt  dnumber,
PetscInt *  dsizes,
char ***  dblocklists,
DM *  ddm 
)

Definition at line 533 of file petscdmlibmeshimpl.C.

References DM_libMesh::blockids, DM_libMesh::blocknames, CHKERRQ(), DM_libMesh::decomposition, DM_libMesh::decomposition_type, dlm, DMlibMeshSetUpName_Private(), ierr, PetscFunctionReturn(), DM_libMesh::sys, DM_libMesh::varids, and DM_libMesh::varnames.

Referenced by DMCreateDomainDecompositionDM_libMesh().

534 {
535  PetscErrorCode ierr;
536  PetscBool islibmesh;
537  PetscFunctionBegin;
538  PetscValidHeaderSpecific(dm,DM_CLASSID,1);
539  ierr = PetscObjectTypeCompare((PetscObject)dm, DMLIBMESH,&islibmesh);
540  if (!islibmesh) SETERRQ2(((PetscObject)dm)->comm, PETSC_ERR_ARG_WRONG, "Got DM of type %s, not of type %s", ((PetscObject)dm)->type_name, DMLIBMESH);
541  if (dnumber < 0) SETERRQ1(((PetscObject)dm)->comm, PETSC_ERR_ARG_WRONG, "Negative number %D of decomposition parts", dnumber);
542  PetscValidPointer(ddm,5);
543  DM_libMesh * dlm = (DM_libMesh *)(dm->data);
544  ierr = DMCreate(((PetscObject)dm)->comm, ddm); CHKERRQ(ierr);
545  ierr = DMSetType(*ddm, DMLIBMESH); CHKERRQ(ierr);
546  DM_libMesh * ddlm = (DM_libMesh *)((*ddm)->data);
547  ddlm->sys = dlm->sys;
548  ddlm->varids = dlm->varids;
549  ddlm->varnames = dlm->varnames;
550  ddlm->blockids = dlm->blockids;
551  ddlm->blocknames = dlm->blocknames;
552  ddlm->decomposition = new(std::vector<std::set<unsigned int>>);
553  ddlm->decomposition_type = DMLIBMESH_DOMAIN_DECOMPOSITION;
554  if (dnumber) {
555  for (PetscInt d = 0; d < dnumber; ++d) {
556  if (dsizes[d] < 0) SETERRQ2(((PetscObject)dm)->comm, PETSC_ERR_ARG_WRONG, "Negative size %D of decomposition part %D", dsizes[d],d);
557  ddlm->decomposition->push_back(std::set<unsigned int>());
558  for (PetscInt b = 0; b < dsizes[d]; ++b) {
559  std::string bname(dblocklists[d][b]);
560  std::map<std::string, unsigned int>::const_iterator bit = dlm->blockids->find(bname);
561  if (bit == dlm->blockids->end())
562  SETERRQ3(((PetscObject)dm)->comm, PETSC_ERR_ARG_WRONG, "Block %D on the %D-th list with name %s is not owned by this DM", b, d, dblocklists[d][b]);
563  unsigned int bid = bit->second;
564  (*ddlm->decomposition)[d].insert(bid);
565  }
566  }
567  }
568  else { /* Empty splits indicate default: split all blocks with one per split. */
569  PetscInt d = 0;
570  for (std::map<std::string, unsigned int>::const_iterator bit = ddlm->blockids->begin(); bit != ddlm->blockids->end(); ++bit) {
571  ddlm->decomposition->push_back(std::set<unsigned int>());
572  unsigned int bid = bit->second;
573  std::string bname = bit->first;
574  (*ddlm->decomposition)[d].insert(bid);
575  ++d;
576  }
577  }
578  ierr = DMlibMeshSetUpName_Private(*ddm); CHKERRQ(ierr);
579  ierr = DMSetFromOptions(*ddm); CHKERRQ(ierr);
580  ierr = DMSetUp(*ddm); CHKERRQ(ierr);
582 }
NonlinearImplicitSystem * sys
PetscErrorCode DMlibMeshSetUpName_Private(DM dm)
std::map< std::string, unsigned int > * blockids
std::map< std::string, unsigned int > * varids
std::vector< std::set< unsigned int > > * decomposition
std::map< unsigned int, std::string > * varnames
std::map< unsigned int, std::string > * blocknames
PetscTruth PetscBool
Definition: petsc_macro.h:64
PetscErrorCode ierr
DM_libMesh * dlm
PetscFunctionReturn(0)
CHKERRQ(ierr)
unsigned int decomposition_type
PetscErrorCode DMlibMeshCreateFieldDecompositionDM ( DM  dm,
PetscInt  dnumber,
PetscInt *  dsizes,
char ***  dvarlists,
DM *  ddm 
)

Definition at line 480 of file petscdmlibmeshimpl.C.

References DM_libMesh::blockids, DM_libMesh::blocknames, CHKERRQ(), DM_libMesh::decomposition, DM_libMesh::decomposition_type, dlm, DMlibMeshSetUpName_Private(), ierr, PetscFunctionReturn(), DM_libMesh::sys, DM_libMesh::varids, and DM_libMesh::varnames.

Referenced by DMCreateFieldDecompositionDM_libMesh().

481 {
482  PetscErrorCode ierr;
483  PetscBool islibmesh;
484  PetscFunctionBegin;
485  PetscValidHeaderSpecific(dm,DM_CLASSID,1);
486  ierr = PetscObjectTypeCompare((PetscObject)dm, DMLIBMESH,&islibmesh);
487  if (!islibmesh) SETERRQ2(((PetscObject)dm)->comm, PETSC_ERR_ARG_WRONG, "Got DM of type %s, not of type %s", ((PetscObject)dm)->type_name, DMLIBMESH);
488  if (dnumber < 0) SETERRQ1(((PetscObject)dm)->comm, PETSC_ERR_ARG_WRONG, "Negative number %D of decomposition parts", dnumber);
489  PetscValidPointer(ddm,5);
490  DM_libMesh * dlm = (DM_libMesh *)(dm->data);
491  ierr = DMCreate(((PetscObject)dm)->comm, ddm); CHKERRQ(ierr);
492  ierr = DMSetType(*ddm, DMLIBMESH); CHKERRQ(ierr);
493  DM_libMesh * ddlm = (DM_libMesh *)((*ddm)->data);
494  ddlm->sys = dlm->sys;
495  ddlm->varids = dlm->varids;
496  ddlm->varnames = dlm->varnames;
497  ddlm->blockids = dlm->blockids;
498  ddlm->blocknames = dlm->blocknames;
499  ddlm->decomposition = new(std::vector<std::set<unsigned int>>);
500  ddlm->decomposition_type = DMLIBMESH_FIELD_DECOMPOSITION;
501  if (dnumber) {
502  for (PetscInt d = 0; d < dnumber; ++d) {
503  if (dsizes[d] < 0) SETERRQ2(((PetscObject)dm)->comm, PETSC_ERR_ARG_WRONG, "Negative size %D of decomposition part %D", dsizes[d],d);
504  ddlm->decomposition->push_back(std::set<unsigned int>());
505  for (PetscInt v = 0; v < dsizes[d]; ++v) {
506  std::string vname(dvarlists[d][v]);
507  std::map<std::string, unsigned int>::const_iterator vit = dlm->varids->find(vname);
508  if (vit == dlm->varids->end())
509  SETERRQ3(((PetscObject)dm)->comm, PETSC_ERR_ARG_WRONG, "Variable %D on the %D-th list with name %s is not owned by this DM", v, d, dvarlists[d][v]);
510  unsigned int vid = vit->second;
511  (*ddlm->decomposition)[d].insert(vid);
512  }
513  }
514  }
515  else { /* Empty splits indicate default: split all variables with one per split. */
516  PetscInt d = 0;
517  for (std::map<std::string, unsigned int>::const_iterator vit = ddlm->varids->begin(); vit != ddlm->varids->end(); ++vit) {
518  ddlm->decomposition->push_back(std::set<unsigned int>());
519  unsigned int vid = vit->second;
520  std::string vname = vit->first;
521  (*ddlm->decomposition)[d].insert(vid);
522  ++d;
523  }
524  }
525  ierr = DMlibMeshSetUpName_Private(*ddm); CHKERRQ(ierr);
526  ierr = DMSetFromOptions(*ddm); CHKERRQ(ierr);
527  ierr = DMSetUp(*ddm); CHKERRQ(ierr);
529 }
NonlinearImplicitSystem * sys
PetscErrorCode DMlibMeshSetUpName_Private(DM dm)
std::map< std::string, unsigned int > * blockids
std::map< std::string, unsigned int > * varids
std::vector< std::set< unsigned int > > * decomposition
std::map< unsigned int, std::string > * varnames
std::map< unsigned int, std::string > * blocknames
PetscTruth PetscBool
Definition: petsc_macro.h:64
PetscErrorCode ierr
DM_libMesh * dlm
PetscFunctionReturn(0)
CHKERRQ(ierr)
unsigned int decomposition_type
static PetscErrorCode DMlibMeshFunction ( DM  dm,
Vec  x,
Vec  r 
)
static

Definition at line 780 of file petscdmlibmeshimpl.C.

References CHKERRQ(), libMesh::ParallelObject::comm(), libMesh::System::current_local_solution, DMlibMeshGetSystem(), libMesh::DofMap::enforce_constraints_exactly(), libMesh::System::get_dof_map(), ierr, libMesh::libmesh_assert(), libmesh_nullptr, libMesh::NonlinearImplicitSystem::nonlinear_solver, PetscFunctionReturn(), libMesh::ExplicitSystem::rhs, libMesh::System::solution, libMesh::sys, and libMesh::System::update().

Referenced by DMSetUp_libMesh(), and SNESFunction_DMlibMesh().

781 {
782  PetscErrorCode ierr;
783  PetscFunctionBegin;
784  libmesh_assert(x);
785  libmesh_assert(r);
786 
788  ierr = DMlibMeshGetSystem(dm, _sys);CHKERRQ(ierr);
789  NonlinearImplicitSystem & sys = *_sys;
790  PetscVector<Number> & X_sys = *libmesh_cast_ptr<PetscVector<Number> *>(sys.solution.get());
791  PetscVector<Number> & R_sys = *libmesh_cast_ptr<PetscVector<Number> *>(sys.rhs);
792  PetscVector<Number> X_global(x, _sys->comm()), R(r, _sys->comm());
793 
794  // Use the systems update() to get a good local version of the parallel solution
795  X_global.swap(X_sys);
796  R.swap(R_sys);
797 
799  _sys->update();
800 
801  // Swap back
802  X_global.swap(X_sys);
803  R.swap(R_sys);
804  R.zero();
805 
806  // if the user has provided both function pointers and objects only the pointer
807  // will be used, so catch that as an error
808  if (_sys->nonlinear_solver->residual && _sys->nonlinear_solver->residual_object)
809  libmesh_error_msg("ERROR: cannot specify both a function and object to compute the Residual!");
810 
811  if (_sys->nonlinear_solver->matvec && _sys->nonlinear_solver->residual_and_jacobian_object)
812  libmesh_error_msg("ERROR: cannot specify both a function and object to compute the combined Residual & Jacobian!");
813 
814  if (_sys->nonlinear_solver->residual != libmesh_nullptr)
815  _sys->nonlinear_solver->residual(*(_sys->current_local_solution.get()), R, *_sys);
816 
817  else if (_sys->nonlinear_solver->residual_object != libmesh_nullptr)
818  _sys->nonlinear_solver->residual_object->residual(*(_sys->current_local_solution.get()), R, *_sys);
819 
820  else if (_sys->nonlinear_solver->matvec != libmesh_nullptr)
821  _sys->nonlinear_solver->matvec(*(_sys->current_local_solution.get()), &R, libmesh_nullptr, *_sys);
822 
823  else if (_sys->nonlinear_solver->residual_and_jacobian_object != libmesh_nullptr)
824  _sys->nonlinear_solver->residual_and_jacobian_object->residual_and_jacobian(*(_sys->current_local_solution.get()), &R, libmesh_nullptr, *_sys);
825 
826  else
827  libmesh_error_msg("Error! Unable to compute residual and/or Jacobian!");
828 
829  R.close();
830  X_global.close();
832 }
ImplicitSystem & sys
UniquePtr< NumericVector< Number > > current_local_solution
All the values I need to compute my contribution to the simulation at hand.
Definition: system.h:1535
const class libmesh_nullptr_t libmesh_nullptr
NumericVector< Number > * rhs
The system matrix.
PETSC_EXTERN PetscErrorCode DMlibMeshGetSystem(DM, libMesh::NonlinearImplicitSystem *&)
libmesh_assert(j)
UniquePtr< NonlinearSolver< Number > > nonlinear_solver
The NonlinearSolver defines the default interface used to solve the nonlinear_implicit system...
PetscErrorCode Vec x
const DofMap & get_dof_map() const
Definition: system.h:2030
This class provides a specific system class.
UniquePtr< NumericVector< Number > > solution
Data structure to hold solution values.
Definition: system.h:1523
void enforce_constraints_exactly(const System &system, NumericVector< Number > *v=libmesh_nullptr, bool homogeneous=false) const
Constrains the numeric vector v, which represents a solution defined on the mesh. ...
Definition: dof_map.h:1816
virtual void update()
Update the local values to reflect the solution on neighboring processors.
Definition: system.C:425
PetscErrorCode ierr
const Parallel::Communicator & comm() const
PetscFunctionReturn(0)
CHKERRQ(ierr)
PetscErrorCode DMlibMeshGetBlocks ( DM  dm,
PetscInt *  n,
char ***  blocknames 
)

Definition at line 167 of file petscdmlibmeshimpl.C.

References DM_libMesh::blockids, CHKERRQ(), dlm, ierr, and PetscFunctionReturn().

168 {
169  PetscErrorCode ierr;
170  PetscInt i;
171  PetscFunctionBegin;
172  PetscValidHeaderSpecific(dm,DM_CLASSID,1);
173  PetscBool islibmesh;
174  ierr = PetscObjectTypeCompare((PetscObject)dm, DMLIBMESH,&islibmesh);
175  if (!islibmesh) SETERRQ2(((PetscObject)dm)->comm, PETSC_ERR_ARG_WRONG, "Got DM of type %s, not of type %s", ((PetscObject)dm)->type_name, DMLIBMESH);
176  DM_libMesh * dlm = (DM_libMesh *)(dm->data);
177  PetscValidPointer(n,2);
178  *n = dlm->blockids->size();
179  if (!blocknames) PetscFunctionReturn(0);
180  ierr = PetscMalloc(*n*sizeof(char *), blocknames); CHKERRQ(ierr);
181  i = 0;
182  for (std::map<std::string, unsigned int>::const_iterator it = dlm->blockids->begin(); it != dlm->blockids->end(); ++it){
183  ierr = PetscStrallocpy(it->first.c_str(), *blocknames+i); CHKERRQ(ierr);
184  ++i;
185  }
187 }
std::map< std::string, unsigned int > * blockids
PetscTruth PetscBool
Definition: petsc_macro.h:64
PetscErrorCode ierr
DM_libMesh * dlm
PetscFunctionReturn(0)
CHKERRQ(ierr)
PetscErrorCode DMlibMeshGetSystem_libMesh ( DM  dm,
NonlinearImplicitSystem *&  sys 
)

Definition at line 150 of file petscdmlibmeshimpl.C.

References CHKERRQ(), dlm, ierr, PetscFunctionReturn(), and DM_libMesh::sys.

Referenced by DMCreate_libMesh().

151 {
152  PetscErrorCode ierr;
153 
154  PetscFunctionBegin;
155  PetscValidHeaderSpecific(dm,DM_CLASSID,1);
156  PetscBool islibmesh;
157  ierr = PetscObjectTypeCompare((PetscObject)dm, DMLIBMESH,&islibmesh);CHKERRQ(ierr);
158  if (!islibmesh) SETERRQ2(((PetscObject)dm)->comm, PETSC_ERR_ARG_WRONG, "Got DM of type %s, not of type %s", ((PetscObject)dm)->type_name, DMLIBMESH);
159  DM_libMesh * dlm = (DM_libMesh *)(dm->data);
160  sys = dlm->sys;
162 }
NonlinearImplicitSystem * sys
PetscTruth PetscBool
Definition: petsc_macro.h:64
PetscErrorCode ierr
DM_libMesh * dlm
PetscFunctionReturn(0)
CHKERRQ(ierr)
PetscErrorCode DMlibMeshGetVariables ( DM  dm,
PetscInt *  n,
char ***  varnames 
)

Definition at line 191 of file petscdmlibmeshimpl.C.

References CHKERRQ(), dlm, ierr, PetscFunctionReturn(), and DM_libMesh::varids.

192 {
193  PetscErrorCode ierr;
194  PetscFunctionBegin;
195  PetscValidHeaderSpecific(dm,DM_CLASSID,1);
196  PetscBool islibmesh;
197  PetscInt i;
198  ierr = PetscObjectTypeCompare((PetscObject)dm, DMLIBMESH,&islibmesh);
199  if (!islibmesh) SETERRQ2(((PetscObject)dm)->comm, PETSC_ERR_ARG_WRONG, "Got DM of type %s, not of type %s", ((PetscObject)dm)->type_name, DMLIBMESH);
200  DM_libMesh * dlm = (DM_libMesh *)(dm->data);
201  PetscValidPointer(n,2);
202  *n = dlm->varids->size();
203  if (!varnames) PetscFunctionReturn(0);
204  ierr = PetscMalloc(*n*sizeof(char *), varnames); CHKERRQ(ierr);
205  i = 0;
206  for (std::map<std::string, unsigned int>::const_iterator it = dlm->varids->begin(); it != dlm->varids->end(); ++it){
207  ierr = PetscStrallocpy(it->first.c_str(), *varnames+i); CHKERRQ(ierr);
208  ++i;
209  }
211 }
std::map< std::string, unsigned int > * varids
PetscTruth PetscBool
Definition: petsc_macro.h:64
PetscErrorCode ierr
DM_libMesh * dlm
PetscFunctionReturn(0)
CHKERRQ(ierr)
PetscErrorCode DMlibMeshGetVec_Private ( DM  ,
const char *  ,
Vec *   
)

Definition at line 76 of file petscdmlibmeshimpl.C.

References DMlibMeshSetUpName_Private(), and PetscFunctionReturn().

77 {
78  PetscFunctionBegin;
79 
81 }
PetscFunctionReturn(0)
static PetscErrorCode DMlibMeshJacobian ( #if PETSC_RELEASE_LESS_THAN(3, 5, 0) DM  dm,
Vec  x,
Mat  jac,
Mat  pc,
MatStructure *msflag#else DM  dm,
Vec  x,
Mat  jac,
Mat pc#  endif 
)
static

Definition at line 850 of file petscdmlibmeshimpl.C.

References CHKERRQ(), libMesh::ParallelObject::comm(), libMesh::System::current_local_solution, DMlibMeshGetSystem(), libMesh::DofMap::enforce_constraints_exactly(), libMesh::System::get_dof_map(), ierr, libmesh_nullptr, libMesh::ImplicitSystem::matrix, libMesh::NonlinearImplicitSystem::nonlinear_solver, PetscFunctionReturn(), libMesh::System::solution, libMesh::sys, and libMesh::System::update().

Referenced by DMSetUp_libMesh(), and SNESJacobian_DMlibMesh().

857 {
858  PetscErrorCode ierr;
859  PetscFunctionBegin;
861  ierr = DMlibMeshGetSystem(dm, _sys); CHKERRQ(ierr);
862  NonlinearImplicitSystem & sys = *_sys;
863 
864  PetscMatrix<Number> the_pc(pc,sys.comm());
865  PetscMatrix<Number> Jac(jac,sys.comm());
866  PetscVector<Number> & X_sys = *libmesh_cast_ptr<PetscVector<Number> *>(sys.solution.get());
867  PetscMatrix<Number> & Jac_sys = *libmesh_cast_ptr<PetscMatrix<Number> *>(sys.matrix);
868  PetscVector<Number> X_global(x, sys.comm());
869 
870  // Set the dof maps
871  the_pc.attach_dof_map(sys.get_dof_map());
872  Jac.attach_dof_map(sys.get_dof_map());
873 
874  // Use the systems update() to get a good local version of the parallel solution
875  X_global.swap(X_sys);
876  Jac.swap(Jac_sys);
877 
879  sys.update();
880 
881  X_global.swap(X_sys);
882  Jac.swap(Jac_sys);
883 
884  the_pc.zero();
885 
886  // if the user has provided both function pointers and objects only the pointer
887  // will be used, so catch that as an error
888  if (sys.nonlinear_solver->jacobian && sys.nonlinear_solver->jacobian_object)
889  libmesh_error_msg("ERROR: cannot specify both a function and object to compute the Jacobian!");
890 
891  if (sys.nonlinear_solver->matvec && sys.nonlinear_solver->residual_and_jacobian_object)
892  libmesh_error_msg("ERROR: cannot specify both a function and object to compute the combined Residual & Jacobian!");
893 
894  if (sys.nonlinear_solver->jacobian != libmesh_nullptr)
895  sys.nonlinear_solver->jacobian(*(sys.current_local_solution.get()), the_pc, sys);
896 
897  else if (sys.nonlinear_solver->jacobian_object != libmesh_nullptr)
898  sys.nonlinear_solver->jacobian_object->jacobian(*(sys.current_local_solution.get()), the_pc, sys);
899 
900  else if (sys.nonlinear_solver->matvec != libmesh_nullptr)
901  sys.nonlinear_solver->matvec(*(sys.current_local_solution.get()), libmesh_nullptr, &the_pc, sys);
902 
903  else if (sys.nonlinear_solver->residual_and_jacobian_object != libmesh_nullptr)
904  sys.nonlinear_solver->residual_and_jacobian_object->residual_and_jacobian(*(sys.current_local_solution.get()), libmesh_nullptr, &the_pc, sys);
905 
906  else
907  libmesh_error_msg("Error! Unable to compute residual and/or Jacobian!");
908 
909  the_pc.close();
910  Jac.close();
911  X_global.close();
912 #if PETSC_RELEASE_LESS_THAN(3,5,0)
913  *msflag = SAME_NONZERO_PATTERN;
914 #endif
916 }
ImplicitSystem & sys
UniquePtr< NumericVector< Number > > current_local_solution
All the values I need to compute my contribution to the simulation at hand.
Definition: system.h:1535
const class libmesh_nullptr_t libmesh_nullptr
PETSC_EXTERN PetscErrorCode DMlibMeshGetSystem(DM, libMesh::NonlinearImplicitSystem *&)
PetscErrorCode Vec Mat Mat pc
UniquePtr< NonlinearSolver< Number > > nonlinear_solver
The NonlinearSolver defines the default interface used to solve the nonlinear_implicit system...
PetscErrorCode Vec x
const DofMap & get_dof_map() const
Definition: system.h:2030
This class provides a specific system class.
UniquePtr< NumericVector< Number > > solution
Data structure to hold solution values.
Definition: system.h:1523
void enforce_constraints_exactly(const System &system, NumericVector< Number > *v=libmesh_nullptr, bool homogeneous=false) const
Constrains the numeric vector v, which represents a solution defined on the mesh. ...
Definition: dof_map.h:1816
virtual void update()
Update the local values to reflect the solution on neighboring processors.
Definition: system.C:425
PetscErrorCode ierr
const Parallel::Communicator & comm() const
SparseMatrix< Number > * matrix
The system matrix.
PetscFunctionReturn(0)
CHKERRQ(ierr)
static PetscErrorCode DMlibMeshParseDecompositionDescriptor_Private ( DM  dm,
const char *  ddesc,
PetscInt *  dtype,
PetscInt *  dcount,
PetscInt **  dsizes,
char ****  dlists 
)
static

Definition at line 595 of file petscdmlibmeshimpl.C.

References CHKERRQ(), eq, ierr, token::next, PetscFunctionReturn(), and token::s.

Referenced by DMCreateDomainDecompositionDM_libMesh(), and DMCreateFieldDecompositionDM_libMesh().

596 {
597  PetscFunctionBegin;
598  PetscErrorCode ierr;
599  PetscBool eq;
600  char * s0;
601  char * s;
602  char * ss;
603  struct token * llfirst = PETSC_NULL;
604  struct token * lllast = PETSC_NULL;
605  struct token * tok;
606  PetscInt stcount = 0, brcount = 0, d, i;
607  size_t len0, count;
608 
609  /*
610  Parse the decomposition descriptor.
611  Decomposition names could be of one of two forms:
612  var:v1,v2;v3,v4;v4,v5;
613  block:b1,b2;b3,b4;b4,b5;
614  resulting in an overlapping decomposition that groups
615  variables (v1,v2), (v3,v4), (v4,v5) or
616  blocks (b1,b2), (b3,b4), (b4,b5).
617  */
618  /* Copy the descriptor so that we can manipulate it in place. */
619  ierr = PetscStrallocpy(ddesc,&s0); CHKERRQ(ierr);
620  ierr = PetscStrlen(s0, &len0) ; CHKERRQ(ierr);
621  ierr = PetscStrstr(s0,":",&ss); CHKERRQ(ierr);
622  if (!ss) {
623  ss = s0+len0;
624  }
625  else {
626  *ss = 0;
627  }
628  ierr = PetscStrcmp(s0,"var",&eq); CHKERRQ(ierr);
629  if (eq) {
630  *dtype=DMLIBMESH_FIELD_DECOMPOSITION;
631  }
632  else {
633  ierr = PetscStrcmp(s0,"block",&eq);CHKERRQ(ierr);
634  if (!eq)
635  SETERRQ1(((PetscObject)dm)->comm, PETSC_ERR_ARG_WRONG, "Could not determine decomposition type from descriptor: %s\n", ddesc); CHKERRQ(ierr);
636  *dtype=DMLIBMESH_DOMAIN_DECOMPOSITION;
637  }
638  ierr = PetscStrlen(s0,&count); CHKERRQ(ierr);
639  while (count < len0) {
640  struct token * st;
641  struct token * br;
642  ++ss; ++count;
643  s=ss;
644  while (*ss && *ss != ',' && *ss != ';') {
645  ++ss; ++count;
646  }
647  st = PETSC_NULL; br = PETSC_NULL;
648  if (*ss) {
649  /*
650  Found a separator, or a break.
651  Add an appropriate token to the list.
652  A token separator ',' produces no token.
653  */
654  if (*ss == ';') {
655  /* Create a break token: a token with a null string. */
656 #if PETSC_RELEASE_LESS_THAN(3,5,0)
657  ierr = PetscNew(struct token,&br);CHKERRQ(ierr);
658 #else
659  ierr = PetscNew(&br);CHKERRQ(ierr);
660 #endif
661  }
662  *ss = 0;
663  if (s != ss) {
664  /* A nonempty string. */
665 #if PETSC_RELEASE_LESS_THAN(3,5,0)
666  ierr = PetscNew(struct token, &st);CHKERRQ(ierr);
667 #else
668  ierr = PetscNew(&st);CHKERRQ(ierr);
669 #endif
670  st->s = s; /* The string will be properly copied below. */
671  }
672  /* Add the new tokens to the list. */
673  if (st) {
674  if (!lllast) {
675  llfirst = lllast = st;
676  }
677  else {
678  lllast->next = st; lllast = st;
679  }
680  }
681  if (br) {
682  if (!lllast) {
683  llfirst = lllast = br;
684  }
685  else {
686  lllast->next = br; lllast = br;
687  }
688  }
689  }
690  }
691  /* The result of parsing is in the linked list ll. */
692  /* Count up the strings and the breaks. */
693  tok = llfirst;
694  while (tok) {
695  if (tok->s)
696  ++stcount;
697  else
698  ++brcount;
699  tok = tok->next;
700  }
701  /* Allocate the space for the output. */
702  *dcount = brcount;
703  ierr = PetscMalloc(*dcount*sizeof(PetscInt), dsizes); CHKERRQ(ierr);
704  ierr = PetscMalloc(*dcount*sizeof(char **), dlists); CHKERRQ(ierr);
705  for (d = 0; d < *dcount; ++d) (*dsizes)[d] = 0;
706  tok = llfirst; d = 0;
707  while (tok) {
708  if (tok->s)
709  ++(*dsizes)[d];
710  else
711  ++d;
712  tok = tok->next;
713  }
714  for (d = 0; d < *dcount; ++d) {
715  ierr = PetscMalloc(sizeof(char **)*(*dsizes)[d], (* dlists)+d); CHKERRQ(ierr);
716  }
717  /* Now copy strings and destroy tokens. */
718  tok = llfirst; d = 0; i = 0;
719  while (tok) {
720  if (tok->s) {
721  ierr = PetscStrallocpy(tok->s, (*dlists)[d]+i); CHKERRQ(ierr);
722  ++i;
723  }
724  else {
725  ++d;
726  i = 0;
727  }
728  llfirst = tok;
729  tok = tok->next;
730  ierr = PetscFree(llfirst); CHKERRQ(ierr);
731  }
732  /* Deallocate workspace. */
733  ierr = PetscFree(s0); CHKERRQ(ierr);
735 }
const char * s
PetscBool eq
struct token * next
PetscTruth PetscBool
Definition: petsc_macro.h:64
PetscErrorCode ierr
PetscFunctionReturn(0)
CHKERRQ(ierr)
PetscErrorCode DMlibMeshSetSystem_libMesh ( DM  dm,
NonlinearImplicitSystem sys 
)

Definition at line 89 of file petscdmlibmeshimpl.C.

References libMesh::MeshBase::active_element_ptr_range(), DM_libMesh::blockids, DM_libMesh::blocknames, CHKERRQ(), libMesh::ParallelObject::comm(), dlm, DMlibMeshSetUpName_Private(), libMesh::System::get_dof_map(), libMesh::System::get_mesh(), ierr, mesh, libMesh::DofMap::n_variables(), libMesh::Variable::name(), PETSC_ERR_ARG_WRONGSTATE, PetscFunctionReturn(), libMesh::Parallel::Communicator::set_union(), libMesh::MeshBase::subdomain_name(), DM_libMesh::sys, libMesh::sys, libMesh::DofMap::variable(), DM_libMesh::varids, and DM_libMesh::varnames.

Referenced by DMCreate_libMesh().

90 {
91  const Parallel::Communicator & comm = sys.comm();
92 
93  PetscErrorCode ierr;
94  PetscFunctionBegin;
95  PetscValidHeaderSpecific(dm,DM_CLASSID,1);
96  PetscBool islibmesh;
97  ierr = PetscObjectTypeCompare((PetscObject)dm, DMLIBMESH,&islibmesh);
98  if (!islibmesh) SETERRQ2(((PetscObject)dm)->comm, PETSC_ERR_ARG_WRONG, "Got DM of type %s, not of type %s", ((PetscObject)dm)->type_name, DMLIBMESH);
99 
100  if (dm->setupcalled) SETERRQ(((PetscObject)dm)->comm, PETSC_ERR_ARG_WRONGSTATE, "Cannot reset the libMesh system after DM has been set up.");
101  DM_libMesh * dlm = (DM_libMesh *)(dm->data);
102  dlm->sys =&sys;
103  /* Initially populate the sets of active blockids and varids using all of the
104  existing blocks/variables (only variables are supported at the moment). */
105  DofMap & dofmap = dlm->sys->get_dof_map();
106  dlm->varids->clear();
107  dlm->varnames->clear();
108  for (unsigned int v = 0; v < dofmap.n_variables(); ++v) {
109  std::string vname = dofmap.variable(v).name();
110  dlm->varids->insert(std::pair<std::string,unsigned int>(vname,v));
111  dlm->varnames->insert(std::pair<unsigned int,std::string>(v,vname));
112  }
113  const MeshBase & mesh = dlm->sys->get_mesh();
114  dlm->blockids->clear();
115  dlm->blocknames->clear();
116  std::set<subdomain_id_type> blocks;
117  /* The following effectively is a verbatim copy of MeshBase::n_subdomains(). */
118  // This requires an inspection on every processor
119  libmesh_parallel_only(mesh.comm());
120  for (const auto & elem : mesh.active_element_ptr_range())
121  blocks.insert(elem->subdomain_id());
122  // Some subdomains may only live on other processors
123  comm.set_union(blocks);
124 
125  std::set<subdomain_id_type>::iterator bit = blocks.begin();
126  std::set<subdomain_id_type>::iterator bend = blocks.end();
127  if (bit == bend) SETERRQ(((PetscObject)dm)->comm, PETSC_ERR_PLIB, "No mesh blocks found.");
128 
129  for (; bit != bend; ++bit) {
130  subdomain_id_type bid = *bit;
131  std::string bname = mesh.subdomain_name(bid);
132  if (!bname.length()) {
133  /* Block names are currently implemented for Exodus II meshes
134  only, so we might have to make up our own block names and
135  maintain our own mapping of block ids to names.
136  */
137  std::ostringstream ss;
138  ss << "dm" << bid;
139  bname = ss.str();
140  }
141  dlm->blockids->insert(std::pair<std::string,unsigned int>(bname,bid));
142  dlm->blocknames->insert(std::pair<unsigned int,std::string>(bid,bname));
143  }
144  ierr = DMlibMeshSetUpName_Private(dm); CHKERRQ(ierr);
146 }
NonlinearImplicitSystem * sys
Encapsulates the MPI_Comm object.
Definition: parallel.h:657
const std::string & name() const
Definition: variable.h:100
PetscErrorCode DMlibMeshSetUpName_Private(DM dm)
ImplicitSystem & sys
std::map< std::string, unsigned int > * blockids
std::map< std::string, unsigned int > * varids
MeshBase & mesh
virtual SimpleRange< element_iterator > active_element_ptr_range()=0
const Variable & variable(const unsigned int c) const
Definition: dof_map.h:1667
This is the MeshBase class.
Definition: mesh_base.h:68
This class handles the numbering of degrees of freedom on a mesh.
Definition: dof_map.h:167
const MeshBase & get_mesh() const
Definition: system.h:2014
const DofMap & get_dof_map() const
Definition: system.h:2030
std::map< unsigned int, std::string > * varnames
std::map< unsigned int, std::string > * blocknames
std::string & subdomain_name(subdomain_id_type id)
Definition: mesh_base.C:576
unsigned int n_variables() const
Definition: dof_map.h:477
PetscTruth PetscBool
Definition: petsc_macro.h:64
PetscErrorCode ierr
const Parallel::Communicator & comm() const
DM_libMesh * dlm
PetscFunctionReturn(0)
CHKERRQ(ierr)
PETSC_ERR_ARG_WRONGSTATE
void set_union(T &data, const unsigned int root_id) const
Take a container of local variables on each processor, and collect their union over all processors...
PetscErrorCode DMlibMeshSetUpName_Private ( DM  dm)

Definition at line 215 of file petscdmlibmeshimpl.C.

References DM_libMesh::blocknames, CHKERRQ(), DM_libMesh::decomposition, DM_libMesh::decomposition_type, dlm, DM_libMesh::embedding_type, end, ierr, libMesh::Quality::name(), libMesh::System::name(), PetscFunctionReturn(), DM_libMesh::sys, and DM_libMesh::varnames.

Referenced by DMCreateDomainDecomposition_libMesh(), DMCreateFieldDecomposition_libMesh(), DMlibMeshCreateDomainDecompositionDM(), DMlibMeshCreateFieldDecompositionDM(), DMlibMeshGetVec_Private(), and DMlibMeshSetSystem_libMesh().

216 {
217  DM_libMesh * dlm = (DM_libMesh *)dm->data;
218  PetscErrorCode ierr;
219  PetscFunctionBegin;
220  std::string name = dlm->sys->name();
221  std::map<unsigned int, std::string> * dnames = PETSC_NULL, * enames = PETSC_NULL;
222  if (dlm->decomposition_type == DMLIBMESH_FIELD_DECOMPOSITION) {
223  name += ":dec:var:";
224  dnames = dlm->varnames;
225  }
226  if (dlm->decomposition_type == DMLIBMESH_DOMAIN_DECOMPOSITION) {
227  name += ":dec:block:";
228  dnames = dlm->blocknames;
229  }
230  if (dnames) {
231  for (unsigned int d = 0; d < dlm->decomposition->size(); ++d) {
232  for (std::set<unsigned int>::iterator dit = (*dlm->decomposition)[d].begin(); dit != (*dlm->decomposition)[d].end(); ++dit) {
233  unsigned int id = *dit;
234  if (dit != (*dlm->decomposition)[d].begin())
235  name += ",";
236  name += (*dnames)[id];
237  }
238  name += ";";
239  }
240  }
241  if (dlm->embedding_type == DMLIBMESH_FIELD_EMBEDDING) {
242  name += ":emb:var:";
243  enames = dlm->varnames;
244  }
245  if (dlm->embedding_type == DMLIBMESH_DOMAIN_EMBEDDING) {
246  name += ":emb:block:";
247  enames = dlm->blocknames;
248  }
249  if (enames) {
250  for (std::map<unsigned int, std::string>::iterator eit = enames->begin(); eit != enames->end(); ++eit) {
251  std::string ename = eit->second;
252  if (eit != enames->begin())
253  name += ",";
254  name += ename;
255  }
256  name += ";";
257  }
258  ierr = PetscObjectSetName((PetscObject)dm, name.c_str()); CHKERRQ(ierr);
260 }
std::string name(const ElemQuality q)
This function returns a string containing some name for q.
Definition: elem_quality.C:39
NonlinearImplicitSystem * sys
unsigned int embedding_type
IterBase * end
Also have a polymorphic pointer to the end object, this prevents iterating past the end...
const std::string & name() const
Definition: system.h:1998
std::vector< std::set< unsigned int > > * decomposition
std::map< unsigned int, std::string > * varnames
std::map< unsigned int, std::string > * blocknames
PetscErrorCode ierr
DM_libMesh * dlm
PetscFunctionReturn(0)
CHKERRQ(ierr)
unsigned int decomposition_type
static PetscErrorCode DMSetUp_libMesh ( DM  dm)
static

Definition at line 1099 of file petscdmlibmeshimpl.C.

References CHKERRQ(), DMlibMeshFunction(), DMlibMeshJacobian(), DMVariableBounds_libMesh(), DM_libMesh::embedding, eq, ierr, libMesh::NonlinearImplicitSystem::nonlinear_solver, PETSC_ERR_ARG_WRONGSTATE, PetscFunctionReturn(), SNESFunction_DMlibMesh(), SNESJacobian_DMlibMesh(), and DM_libMesh::sys.

Referenced by DMCreate_libMesh().

1100 {
1101  PetscFunctionBegin;
1102  PetscErrorCode ierr;
1103  DM_libMesh * dlm = (DM_libMesh *)(dm->data);
1104  PetscBool eq;
1105 
1106  ierr = PetscObjectTypeCompare((PetscObject)dm, DMLIBMESH, &eq); CHKERRQ(ierr);
1107 
1108  if (!eq)
1109  SETERRQ2(((PetscObject)dm)->comm, PETSC_ERR_ARG_WRONG, "DM of type %s, not of type %s", ((PetscObject)dm)->type, DMLIBMESH);
1110 
1111  if (!dlm->sys)
1112  SETERRQ(PETSC_COMM_WORLD, PETSC_ERR_ARG_WRONGSTATE, "No libMesh system set for DM_libMesh");
1113  /*
1114  Do not evaluate function, Jacobian or bounds for an embedded DM -- the subproblem might not have enough information for that.
1115  */
1116  if (!dlm->embedding) {
1117 #if PETSC_RELEASE_LESS_THAN(3,3,1)
1118  ierr = DMSetFunction(dm, DMlibMeshFunction); CHKERRQ(ierr);
1119  ierr = DMSetJacobian(dm, DMlibMeshJacobian); CHKERRQ(ierr);
1120 #else
1121  ierr = DMSNESSetFunction(dm, SNESFunction_DMlibMesh, (void *)dm); CHKERRQ(ierr);
1122  ierr = DMSNESSetJacobian(dm, SNESJacobian_DMlibMesh, (void *)dm); CHKERRQ(ierr);
1123 #endif
1124  if (dlm->sys->nonlinear_solver->bounds || dlm->sys->nonlinear_solver->bounds_object)
1125  ierr = DMSetVariableBounds(dm, DMVariableBounds_libMesh); CHKERRQ(ierr);
1126  }
1127  else {
1128  /*
1129  Fow now we don't implement even these, although a linear "Dirichlet" subproblem is well-defined.
1130  Creating the submatrix, however, might require extracting the submatrix preallocation from an unassembled matrix.
1131  */
1132  dm->ops->createglobalvector = 0;
1133  dm->ops->creatematrix = 0;
1134  }
1136 }
static PetscErrorCode SNESFunction_DMlibMesh(SNES, Vec x, Vec r, void *ctx)
static PetscErrorCode DMVariableBounds_libMesh(DM dm, Vec xl, Vec xu)
NonlinearImplicitSystem * sys
PetscBool eq
UniquePtr< NonlinearSolver< Number > > nonlinear_solver
The NonlinearSolver defines the default interface used to solve the nonlinear_implicit system...
static PetscErrorCode DMlibMeshFunction(DM dm, Vec x, Vec r)
PetscTruth PetscBool
Definition: petsc_macro.h:64
PetscErrorCode ierr
static PetscErrorCode SNESJacobian_DMlibMesh(#if PETSC_RELEASE_LESS_THAN(3, 5, 0) SNES, Vec x, Mat *jac, Mat *pc, MatStructure *flag, void *ctx#else SNES, Vec x, Mat jac, Mat pc, void *ctx#endif)
DM_libMesh * dlm
PetscFunctionReturn(0)
CHKERRQ(ierr)
PETSC_ERR_ARG_WRONGSTATE
static PetscErrorCode DMlibMeshJacobian(#if PETSC_RELEASE_LESS_THAN(3, 5, 0) DM dm, Vec x, Mat jac, Mat pc, MatStructure *msflag#else DM dm, Vec x, Mat jac, Mat pc#endif)
static PetscErrorCode DMVariableBounds_libMesh ( DM  dm,
Vec  xl,
Vec  xu 
)
static

Definition at line 943 of file petscdmlibmeshimpl.C.

References CHKERRQ(), libMesh::ParallelObject::comm(), DMlibMeshGetSystem(), ierr, libmesh_nullptr, libMesh::NonlinearImplicitSystem::nonlinear_solver, PetscFunctionReturn(), and libMesh::sys.

Referenced by DMSetUp_libMesh().

944 {
945  PetscErrorCode ierr;
947  ierr = DMlibMeshGetSystem(dm, _sys); CHKERRQ(ierr);
948  NonlinearImplicitSystem & sys = *_sys;
949  PetscVector<Number> XL(xl, sys.comm());
950  PetscVector<Number> XU(xu, sys.comm());
951  PetscFunctionBegin;
952 #if PETSC_VERSION_LESS_THAN(3,5,0) && PETSC_VERSION_RELEASE
953  ierr = VecSet(xl, SNES_VI_NINF);CHKERRQ(ierr);
954  ierr = VecSet(xu, SNES_VI_INF);CHKERRQ(ierr);
955 #else
956  ierr = VecSet(xl, PETSC_NINFINITY);CHKERRQ(ierr);
957  ierr = VecSet(xu, PETSC_INFINITY);CHKERRQ(ierr);
958 #endif
959  if (sys.nonlinear_solver->bounds != libmesh_nullptr)
960  sys.nonlinear_solver->bounds(XL,XU,sys);
961  else if (sys.nonlinear_solver->bounds_object != libmesh_nullptr)
962  sys.nonlinear_solver->bounds_object->bounds(XL,XU, sys);
963  else
964  SETERRQ(((PetscObject)dm)->comm, PETSC_ERR_ARG_WRONG, "No bounds calculation in this libMesh object");
965 
967 }
ImplicitSystem & sys
const class libmesh_nullptr_t libmesh_nullptr
PETSC_EXTERN PetscErrorCode DMlibMeshGetSystem(DM, libMesh::NonlinearImplicitSystem *&)
UniquePtr< NonlinearSolver< Number > > nonlinear_solver
The NonlinearSolver defines the default interface used to solve the nonlinear_implicit system...
This class provides a specific system class.
PetscErrorCode ierr
const Parallel::Communicator & comm() const
PetscFunctionReturn(0)
CHKERRQ(ierr)
static PetscErrorCode DMView_libMesh ( DM  dm,
PetscViewer  viewer 
)
static

Definition at line 1040 of file petscdmlibmeshimpl.C.

References DM_libMesh::blockids, CHKERRQ(), DM_libMesh::decomposition, DM_libMesh::decomposition_type, end, ierr, libMesh::Quality::name(), PetscFunctionReturn(), and DM_libMesh::varids.

Referenced by DMCreate_libMesh().

1041 {
1042  PetscErrorCode ierr;
1043  PetscBool isascii;
1044  const char * name, * prefix;
1045  DM_libMesh * dlm = (DM_libMesh *)dm->data;
1046  PetscFunctionBegin;
1047  ierr = PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERASCII,&isascii); CHKERRQ(ierr);
1048  if (isascii) {
1049  ierr = PetscObjectGetName((PetscObject)dm, &name); CHKERRQ(ierr);
1050  ierr = PetscObjectGetOptionsPrefix((PetscObject)dm, &prefix); CHKERRQ(ierr);
1051  ierr = PetscViewerASCIIPrintf(viewer, "DM libMesh with name %s and prefix %s\n", name, prefix); CHKERRQ(ierr);
1052  ierr = PetscViewerASCIIPrintf(viewer, "blocks:", name, prefix); CHKERRQ(ierr);
1053  std::map<std::string,unsigned int>::iterator bit = dlm->blockids->begin();
1054  std::map<std::string,unsigned int>::const_iterator bend = dlm->blockids->end();
1055  for (; bit != bend; ++bit) {
1056  ierr = PetscViewerASCIIPrintf(viewer, "(%s,%D) ", bit->first.c_str(), bit->second); CHKERRQ(ierr);
1057  }
1058  ierr = PetscViewerASCIIPrintf(viewer, "\n"); CHKERRQ(ierr);
1059  ierr = PetscViewerASCIIPrintf(viewer, "variables:", name, prefix); CHKERRQ(ierr);
1060  std::map<std::string,unsigned int>::iterator vit = dlm->varids->begin();
1061  std::map<std::string,unsigned int>::const_iterator vend = dlm->varids->end();
1062  for (; vit != vend; ++vit) {
1063  ierr = PetscViewerASCIIPrintf(viewer, "(%s,%D) ", vit->first.c_str(), vit->second); CHKERRQ(ierr);
1064  }
1065  ierr = PetscViewerASCIIPrintf(viewer, "\n"); CHKERRQ(ierr);
1066  if (dlm->decomposition_type == DMLIBMESH_NO_DECOMPOSITION) {
1067  ierr = PetscViewerASCIIPrintf(viewer, "No decomposition\n"); CHKERRQ(ierr);
1068  }
1069  else {
1070  if (dlm->decomposition_type == DMLIBMESH_FIELD_DECOMPOSITION) {
1071  ierr = PetscViewerASCIIPrintf(viewer, "Field decomposition by variable: "); CHKERRQ(ierr);
1072  }
1073  else if (dlm->decomposition_type == DMLIBMESH_DOMAIN_DECOMPOSITION) {
1074  ierr = PetscViewerASCIIPrintf(viewer, "Domain decomposition by block: "); CHKERRQ(ierr);
1075  }
1076  else SETERRQ1(((PetscObject)dm)->comm, PETSC_ERR_PLIB, "Unexpected decomposition type: %D", dlm->decomposition_type);
1077  /* FIX: decompositions might have different sizes and components on different ranks. */
1078  for (unsigned int d = 0; d < dlm->decomposition->size(); ++d) {
1079  std::set<unsigned int>::iterator dbegin = (*dlm->decomposition)[d].begin();
1080  std::set<unsigned int>::iterator dit = (*dlm->decomposition)[d].begin();
1081  std::set<unsigned int>::iterator dend = (*dlm->decomposition)[d].end();
1082  for (; dit != dend; ++dit) {
1083  if (dit != dbegin) {
1084  ierr = PetscViewerASCIIPrintf(viewer, ","); CHKERRQ(ierr);
1085  }
1086  ierr = PetscViewerASCIIPrintf(viewer, "%D", *dit); CHKERRQ(ierr);
1087  }
1088  ierr = PetscViewerASCIIPrintf(viewer, ";"); CHKERRQ(ierr);
1089  }
1090  ierr = PetscViewerASCIIPrintf(viewer, "\n"); CHKERRQ(ierr);
1091  }
1092  }
1093 
1095 }
std::string name(const ElemQuality q)
This function returns a string containing some name for q.
Definition: elem_quality.C:39
std::map< std::string, unsigned int > * blockids
std::map< std::string, unsigned int > * varids
IterBase * end
Also have a polymorphic pointer to the end object, this prevents iterating past the end...
std::vector< std::set< unsigned int > > * decomposition
PetscTruth PetscBool
Definition: petsc_macro.h:64
PetscErrorCode ierr
DM_libMesh * dlm
PetscFunctionReturn(0)
CHKERRQ(ierr)
unsigned int decomposition_type
if ( eq) -> comm, PETSC_ERR_ARG_WRONG,"DM of type %s, not of type %s",((PetscObject) dm) ->type, DMLIBMESH)

Referenced by init_cd().

if ( !dlm->  sys)
PetscFunctionReturn ( )
static PetscErrorCode SNESFunction_DMlibMesh ( SNES  ,
Vec  x,
Vec  r,
void *  ctx 
)
static

Definition at line 837 of file petscdmlibmeshimpl.C.

References CHKERRQ(), DMlibMeshFunction(), ierr, and PetscFunctionReturn().

Referenced by DMSetUp_libMesh().

838 {
839  DM dm = (DM)ctx;
840  PetscErrorCode ierr;
841  PetscFunctionBegin;
842  ierr = DMlibMeshFunction(dm,x,r);CHKERRQ(ierr);
844 }
PetscErrorCode Vec x
static PetscErrorCode DMlibMeshFunction(DM dm, Vec x, Vec r)
PetscErrorCode Vec Mat Mat void * ctx
PetscErrorCode ierr
PetscFunctionReturn(0)
CHKERRQ(ierr)
static PetscErrorCode SNESJacobian_DMlibMesh ( #if PETSC_RELEASE_LESS_THAN(3, 5, 0)  SNES,
Vec  x,
Mat *  jac,
Mat *  pc,
MatStructure *  flag,
void *ctx#else  SNES,
Vec  x,
Mat  jac,
Mat  pc,
void *ctx#  endif 
)
static

Definition at line 921 of file petscdmlibmeshimpl.C.

References CHKERRQ(), libMesh::ctx, DMlibMeshJacobian(), ierr, and PetscFunctionReturn().

Referenced by DMSetUp_libMesh().

928 {
929  DM dm = (DM)ctx;
930  PetscErrorCode ierr;
931  PetscFunctionBegin;
932 #if PETSC_RELEASE_LESS_THAN(3,5,0)
933  ierr = DMlibMeshJacobian(dm,x,*jac,*pc,flag); CHKERRQ(ierr);
934 #else
935  ierr = DMlibMeshJacobian(dm,x,jac,pc); CHKERRQ(ierr);
936 #endif
938 }
PetscErrorCode Vec Mat Mat pc
PetscErrorCode Vec x
PetscErrorCode Vec Mat Mat void * ctx
PetscErrorCode ierr
PetscFunctionReturn(0)
CHKERRQ(ierr)
static PetscErrorCode DMlibMeshJacobian(#if PETSC_RELEASE_LESS_THAN(3, 5, 0) DM dm, Vec x, Mat jac, Mat pc, MatStructure *msflag#else DM dm, Vec x, Mat jac, Mat pc#endif)

Variable Documentation

* A
DM_libMesh* dlm = (DM_libMesh *)(dm->data)
No libMesh system set for DM_libMesh

Definition at line 1030 of file petscdmlibmeshimpl.C.

ierr = PetscObjectTypeCompare((PetscObject)dm, DMLIBMESH, &eq)

Definition at line 1020 of file petscdmlibmeshimpl.C.

Referenced by libMesh::__libmesh_petsc_diff_solver_monitor(), libMesh::__libmesh_petsc_preconditioner_apply(), libMesh::__libmesh_petsc_preconditioner_setup(), libMesh::__libmesh_petsc_snes_jacobian(), libMesh::__libmesh_petsc_snes_postcheck(), libMesh::__libmesh_petsc_snes_residual(), libMesh::__libmesh_tao_equality_constraints(), libMesh::__libmesh_tao_equality_constraints_jacobian(), libMesh::__libmesh_tao_gradient(), libMesh::__libmesh_tao_hessian(), libMesh::__libmesh_tao_inequality_constraints(), libMesh::__libmesh_tao_inequality_constraints_jacobian(), libMesh::__libmesh_tao_objective(), libMesh::PetscLinearSolver< T >::_create_complement_is(), libMesh::PetscLinearSolver< T >::_petsc_shell_matrix_get_diagonal(), libMesh::SlepcEigenSolver< T >::_petsc_shell_matrix_get_diagonal(), libMesh::PetscLinearSolver< T >::_petsc_shell_matrix_mult(), libMesh::SlepcEigenSolver< T >::_petsc_shell_matrix_mult(), libMesh::PetscLinearSolver< T >::_petsc_shell_matrix_mult_add(), libMesh::PetscLinearSolver< T >::_restrict_solve_to_is_local_size(), libMesh::SlepcEigenSolver< T >::_solve_generalized_helper(), libMesh::SlepcEigenSolver< T >::_solve_standard_helper(), libMesh::PetscLinearSolver< T >::adjoint_solve(), libMesh::PetscPreconditioner< T >::apply(), libMesh::SlepcEigenSolver< T >::attach_deflation_space(), libMesh::PetscNonlinearSolver< T >::build_mat_null_space(), libMesh::SlepcEigenSolver< T >::clear(), libMesh::PetscPreconditioner< T >::clear(), libMesh::TaoOptimizationSolver< T >::clear(), libMesh::PetscDiffSolver::clear(), libMesh::PetscNonlinearSolver< T >::clear(), libMesh::PetscLinearSolver< T >::clear(), PetscSolverConfiguration::configure_solver(), DMCreate_libMesh(), DMCreateDomainDecomposition_libMesh(), DMCreateDomainDecompositionDM_libMesh(), DMCreateFieldDecomposition_libMesh(), DMCreateFieldDecompositionDM_libMesh(), DMCreateGlobalVector_libMesh(), DMDestroy_libMesh(), DMlibMeshCreateDomainDecompositionDM(), DMlibMeshCreateFieldDecompositionDM(), DMlibMeshFunction(), DMlibMeshGetBlocks(), DMlibMeshGetSystem(), DMlibMeshGetSystem_libMesh(), DMlibMeshGetVariables(), DMlibMeshJacobian(), DMlibMeshParseDecompositionDescriptor_Private(), DMlibMeshSetSystem(), DMlibMeshSetSystem_libMesh(), DMlibMeshSetUpName_Private(), DMSetUp_libMesh(), DMVariableBounds_libMesh(), DMView_libMesh(), libMesh::TaoOptimizationSolver< T >::get_converged_reason(), libMesh::PetscNonlinearSolver< T >::get_converged_reason(), libMesh::TaoOptimizationSolver< T >::get_dual_variables(), libMesh::SlepcEigenSolver< T >::get_eigenpair(), libMesh::SlepcEigenSolver< T >::get_eigenvalue(), libMesh::PetscLinearSolver< T >::get_initial_residual(), libMesh::SlepcEigenSolver< T >::get_relative_error(), libMesh::PetscLinearSolver< T >::get_residual_history(), libMesh::PetscDiffSolver::init(), libMesh::SlepcEigenSolver< T >::init(), libMesh::PetscPreconditioner< T >::init(), libMesh::TaoOptimizationSolver< T >::init(), libMesh::PetscNonlinearSolver< T >::init(), libMesh::PetscLinearSolver< T >::init(), libMesh::LibMeshInit::LibMeshInit(), libMesh::GMVIO::read(), libMesh::PetscDiffSolver::reinit(), libMesh::PetscLinearSolver< T >::restrict_solve_to(), libMesh::SlepcEigenSolver< T >::set_initial_space(), libMesh::PetscPreconditioner< T >::set_petsc_preconditioner_type(), libMesh::PetscLinearSolver< T >::set_petsc_solver_type(), libMesh::SlepcEigenSolver< T >::set_slepc_position_of_spectrum(), libMesh::SlepcEigenSolver< T >::set_slepc_problem_type(), libMesh::SlepcEigenSolver< T >::set_slepc_solver_type(), SNESFunction_DMlibMesh(), SNESJacobian_DMlibMesh(), libMesh::PetscDiffSolver::solve(), libMesh::TaoOptimizationSolver< T >::solve(), libMesh::PetscNonlinearSolver< T >::solve(), libMesh::NloptOptimizationSolver< T >::solve(), libMesh::PetscLinearSolver< T >::solve(), libMesh::SlepcEigenSolver< T >::solve_generalized(), libMesh::SlepcEigenSolver< T >::solve_standard(), and libMesh::TecplotIO::write_binary().

PETSC_ERR_ARG_WRONGSTATE