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

PetscErrorCode DMCreate_libMesh ( DM  dm)

Definition at line 1164 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().

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

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

Definition at line 760 of file petscdmlibmeshimpl.C.

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

Referenced by DMCreate_libMesh().

761 {
762  PetscFunctionBegin;
763  PetscErrorCode ierr;
764  PetscInt dtype, dcount;
765  PetscInt * dsizes;
766  char *** dlists;
767  PetscFunctionBegin;
768  *ddm = PETSC_NULL;
769  ierr = DMlibMeshParseDecompositionDescriptor_Private(dm,ddesc,&dtype,&dcount,&dsizes,&dlists); CHKERRQ(ierr);
770  if (dtype == DMLIBMESH_DOMAIN_DECOMPOSITION) {
771  ierr = DMlibMeshCreateDomainDecompositionDM(dm,dcount,dsizes,dlists,ddm); CHKERRQ(ierr);
772  }
773  else SETERRQ1(((PetscObject)dm)->comm, PETSC_ERR_PLIB, "Uexpected unknown decomposition type for domain decomposition descriptor %s", ddesc);
775 }
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 267 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().

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

Definition at line 741 of file petscdmlibmeshimpl.C.

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

Referenced by DMCreate_libMesh().

742 {
743  PetscFunctionBegin;
744  PetscErrorCode ierr;
745  PetscInt dtype, dcount;
746  PetscInt * dsizes;
747  char *** dlists;
748  PetscFunctionBegin;
749  *ddm = PETSC_NULL;
750  ierr = DMlibMeshParseDecompositionDescriptor_Private(dm,ddesc,&dtype,&dcount,&dsizes,&dlists); CHKERRQ(ierr);
751  if (dtype == DMLIBMESH_FIELD_DECOMPOSITION){
752  ierr = DMlibMeshCreateFieldDecompositionDM(dm,dcount,dsizes,dlists,ddm); CHKERRQ(ierr);
753  }
754  else SETERRQ1(((PetscObject)dm)->comm, PETSC_ERR_PLIB, "Uexpected unknown decomposition type for field decomposition descriptor %s", ddesc);
756 }
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 974 of file petscdmlibmeshimpl.C.

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

Referenced by DMCreate_libMesh().

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

1146 {
1147  DM_libMesh * dlm = (DM_libMesh *)(dm->data);
1148  PetscErrorCode ierr;
1149  PetscFunctionBegin;
1150  delete dlm->varids;
1151  delete dlm->varnames;
1152  delete dlm->blockids;
1153  delete dlm->blocknames;
1154  delete dlm->decomposition;
1155  ierr = ISDestroy(&dlm->embedding); CHKERRQ(ierr);
1156  ierr = PetscFree(dm->data); CHKERRQ(ierr);
1157 
1159 }
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 535 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().

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

483 {
484  PetscErrorCode ierr;
485  PetscBool islibmesh;
486  PetscFunctionBegin;
487  PetscValidHeaderSpecific(dm,DM_CLASSID,1);
488  ierr = PetscObjectTypeCompare((PetscObject)dm, DMLIBMESH,&islibmesh);
489  if (!islibmesh) SETERRQ2(((PetscObject)dm)->comm, PETSC_ERR_ARG_WRONG, "Got DM oftype %s, not of type %s", ((PetscObject)dm)->type_name, DMLIBMESH);
490  if (dnumber < 0) SETERRQ1(((PetscObject)dm)->comm, PETSC_ERR_ARG_WRONG, "Negative number %D of decomposition parts", dnumber);
491  PetscValidPointer(ddm,5);
492  DM_libMesh * dlm = (DM_libMesh *)(dm->data);
493  ierr = DMCreate(((PetscObject)dm)->comm, ddm); CHKERRQ(ierr);
494  ierr = DMSetType(*ddm, DMLIBMESH); CHKERRQ(ierr);
495  DM_libMesh * ddlm = (DM_libMesh *)((*ddm)->data);
496  ddlm->sys = dlm->sys;
497  ddlm->varids = dlm->varids;
498  ddlm->varnames = dlm->varnames;
499  ddlm->blockids = dlm->blockids;
500  ddlm->blocknames = dlm->blocknames;
501  ddlm->decomposition = new(std::vector<std::set<unsigned int> >);
502  ddlm->decomposition_type = DMLIBMESH_FIELD_DECOMPOSITION;
503  if (dnumber) {
504  for (PetscInt d = 0; d < dnumber; ++d) {
505  if (dsizes[d] < 0) SETERRQ2(((PetscObject)dm)->comm, PETSC_ERR_ARG_WRONG, "Negative size %D of decomposition part %D", dsizes[d],d);
506  ddlm->decomposition->push_back(std::set<unsigned int>());
507  for (PetscInt v = 0; v < dsizes[d]; ++v) {
508  std::string vname(dvarlists[d][v]);
509  std::map<std::string, unsigned int>::const_iterator vit = dlm->varids->find(vname);
510  if (vit == dlm->varids->end())
511  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]);
512  unsigned int vid = vit->second;
513  (*ddlm->decomposition)[d].insert(vid);
514  }
515  }
516  }
517  else { /* Empty splits indicate default: split all variables with one per split. */
518  PetscInt d = 0;
519  for (std::map<std::string, unsigned int>::const_iterator vit = ddlm->varids->begin(); vit != ddlm->varids->end(); ++vit) {
520  ddlm->decomposition->push_back(std::set<unsigned int>());
521  unsigned int vid = vit->second;
522  std::string vname = vit->first;
523  (*ddlm->decomposition)[d].insert(vid);
524  ++d;
525  }
526  }
527  ierr = DMlibMeshSetUpName_Private(*ddm); CHKERRQ(ierr);
528  ierr = DMSetFromOptions(*ddm); CHKERRQ(ierr);
529  ierr = DMSetUp(*ddm); CHKERRQ(ierr);
531 }
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 782 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::PetscVector< T >::swap(), libMesh::sys, and libMesh::System::update().

Referenced by DMSetUp_libMesh(), and SNESFunction_DMlibMesh().

783 {
784  PetscErrorCode ierr;
785  PetscFunctionBegin;
786  libmesh_assert(x);
787  libmesh_assert(r);
788 
790  ierr = DMlibMeshGetSystem(dm, _sys);CHKERRQ(ierr);
791  NonlinearImplicitSystem & sys = *_sys;
792  PetscVector<Number> & X_sys = *libmesh_cast_ptr<PetscVector<Number> * >(sys.solution.get());
793  PetscVector<Number> & R_sys = *libmesh_cast_ptr<PetscVector<Number> * >(sys.rhs);
794  PetscVector<Number> X_global(x, _sys->comm()), R(r, _sys->comm());
795 
796  // Use the systems update() to get a good local version of the parallel solution
797  X_global.swap(X_sys);
798  R.swap(R_sys);
799 
801  _sys->update();
802 
803  // Swap back
804  X_global.swap(X_sys);
805  R.swap(R_sys);
806  R.zero();
807 
808  // if the user has provided both function pointers and objects only the pointer
809  // will be used, so catch that as an error
810  if (_sys->nonlinear_solver->residual && _sys->nonlinear_solver->residual_object)
811  libmesh_error_msg("ERROR: cannot specifiy both a function and object to compute the Residual!");
812 
813  if (_sys->nonlinear_solver->matvec && _sys->nonlinear_solver->residual_and_jacobian_object)
814  libmesh_error_msg("ERROR: cannot specifiy both a function and object to compute the combined Residual & Jacobian!");
815 
816  if (_sys->nonlinear_solver->residual != libmesh_nullptr)
817  _sys->nonlinear_solver->residual(*(_sys->current_local_solution.get()), R, *_sys);
818 
819  else if (_sys->nonlinear_solver->residual_object != libmesh_nullptr)
820  _sys->nonlinear_solver->residual_object->residual(*(_sys->current_local_solution.get()), R, *_sys);
821 
822  else if (_sys->nonlinear_solver->matvec != libmesh_nullptr)
823  _sys->nonlinear_solver->matvec(*(_sys->current_local_solution.get()), &R, libmesh_nullptr, *_sys);
824 
825  else if (_sys->nonlinear_solver->residual_and_jacobian_object != libmesh_nullptr)
826  _sys->nonlinear_solver->residual_and_jacobian_object->residual_and_jacobian(*(_sys->current_local_solution.get()), &R, libmesh_nullptr, *_sys);
827 
828  else
829  libmesh_error_msg("Error! Unable to compute residual and/or Jacobian!");
830 
831  R.close();
832  X_global.close();
834 }
NumericVector interface to PETSc Vec.
Definition: petsc_vector.h:64
ImplicitSystem & sys
UniquePtr< NumericVector< Number > > current_local_solution
Definition: system.h:1533
const class libmesh_nullptr_t libmesh_nullptr
NumericVector< Number > * rhs
libmesh_assert(j)
UniquePtr< NonlinearSolver< Number > > nonlinear_solver
PetscErrorCode Vec x
const DofMap & get_dof_map() const
Definition: system.h:2028
Used for solving nonlinear implicit systems of equations.
UniquePtr< NumericVector< Number > > solution
Definition: system.h:1521
void enforce_constraints_exactly(const System &system, NumericVector< Number > *v=libmesh_nullptr, bool homogeneous=false) const
virtual void update()
Definition: system.C:420
PetscErrorCode ierr
const Parallel::Communicator & comm() const
PetscErrorCode DMlibMeshGetSystem(DM dm, libMesh::NonlinearImplicitSystem *&sys)
virtual void swap(NumericVector< T > &v) libmesh_override
PetscFunctionReturn(0)
CHKERRQ(ierr)
PetscErrorCode DMlibMeshGetBlocks ( DM  dm,
PetscInt *  n,
char ***  blocknames 
)

Definition at line 169 of file petscdmlibmeshimpl.C.

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

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

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

Referenced by DMCreate_libMesh().

153 {
154  PetscErrorCode ierr;
155 
156  PetscFunctionBegin;
157  PetscValidHeaderSpecific(dm,DM_CLASSID,1);
158  PetscBool islibmesh;
159  ierr = PetscObjectTypeCompare((PetscObject)dm, DMLIBMESH,&islibmesh);CHKERRQ(ierr);
160  if (!islibmesh) SETERRQ2(((PetscObject)dm)->comm, PETSC_ERR_ARG_WRONG, "Got DM oftype %s, not of type %s", ((PetscObject)dm)->type_name, DMLIBMESH);
161  DM_libMesh * dlm = (DM_libMesh *)(dm->data);
162  sys = dlm->sys;
164 }
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 193 of file petscdmlibmeshimpl.C.

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

194 {
195  PetscErrorCode ierr;
196  PetscFunctionBegin;
197  PetscValidHeaderSpecific(dm,DM_CLASSID,1);
198  PetscBool islibmesh;
199  PetscInt i;
200  ierr = PetscObjectTypeCompare((PetscObject)dm, DMLIBMESH,&islibmesh);
201  if (!islibmesh) SETERRQ2(((PetscObject)dm)->comm, PETSC_ERR_ARG_WRONG, "Got DM oftype %s, not of type %s", ((PetscObject)dm)->type_name, DMLIBMESH);
202  DM_libMesh * dlm = (DM_libMesh *)(dm->data);
203  PetscValidPointer(n,2);
204  *n = dlm->varids->size();
205  if (!varnames) PetscFunctionReturn(0);
206  ierr = PetscMalloc(*n*sizeof(char *), varnames); CHKERRQ(ierr);
207  i = 0;
208  for (std::map<std::string, unsigned int>::const_iterator it = dlm->varids->begin(); it != dlm->varids->end(); ++it){
209  ierr = PetscStrallocpy(it->first.c_str(), *varnames+i); CHKERRQ(ierr);
210  ++i;
211  }
213 }
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 852 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::PetscVector< T >::swap(), libMesh::sys, and libMesh::System::update().

Referenced by DMSetUp_libMesh(), and SNESJacobian_DMlibMesh().

859 {
860  PetscErrorCode ierr;
861  PetscFunctionBegin;
863  ierr = DMlibMeshGetSystem(dm, _sys); CHKERRQ(ierr);
864  NonlinearImplicitSystem & sys = *_sys;
865 
866  PetscMatrix<Number> the_pc(pc,sys.comm());
867  PetscMatrix<Number> Jac(jac,sys.comm());
868  PetscVector<Number> & X_sys = *libmesh_cast_ptr<PetscVector<Number> *>(sys.solution.get());
869  PetscMatrix<Number> & Jac_sys = *libmesh_cast_ptr<PetscMatrix<Number> *>(sys.matrix);
870  PetscVector<Number> X_global(x, sys.comm());
871 
872  // Set the dof maps
873  the_pc.attach_dof_map(sys.get_dof_map());
874  Jac.attach_dof_map(sys.get_dof_map());
875 
876  // Use the systems update() to get a good local version of the parallel solution
877  X_global.swap(X_sys);
878  Jac.swap(Jac_sys);
879 
881  sys.update();
882 
883  X_global.swap(X_sys);
884  Jac.swap(Jac_sys);
885 
886  the_pc.zero();
887 
888  // if the user has provided both function pointers and objects only the pointer
889  // will be used, so catch that as an error
890  if (sys.nonlinear_solver->jacobian && sys.nonlinear_solver->jacobian_object)
891  libmesh_error_msg("ERROR: cannot specifiy both a function and object to compute the Jacobian!");
892 
893  if (sys.nonlinear_solver->matvec && sys.nonlinear_solver->residual_and_jacobian_object)
894  libmesh_error_msg("ERROR: cannot specifiy both a function and object to compute the combined Residual & Jacobian!");
895 
896  if (sys.nonlinear_solver->jacobian != libmesh_nullptr)
897  sys.nonlinear_solver->jacobian(*(sys.current_local_solution.get()), the_pc, sys);
898 
899  else if (sys.nonlinear_solver->jacobian_object != libmesh_nullptr)
900  sys.nonlinear_solver->jacobian_object->jacobian(*(sys.current_local_solution.get()), the_pc, sys);
901 
902  else if (sys.nonlinear_solver->matvec != libmesh_nullptr)
903  sys.nonlinear_solver->matvec(*(sys.current_local_solution.get()), libmesh_nullptr, &the_pc, sys);
904 
905  else if (sys.nonlinear_solver->residual_and_jacobian_object != libmesh_nullptr)
906  sys.nonlinear_solver->residual_and_jacobian_object->residual_and_jacobian(*(sys.current_local_solution.get()), libmesh_nullptr, &the_pc, sys);
907 
908  else
909  libmesh_error_msg("Error! Unable to compute residual and/or Jacobian!");
910 
911  the_pc.close();
912  Jac.close();
913  X_global.close();
914 #if PETSC_RELEASE_LESS_THAN(3,5,0)
915  *msflag = SAME_NONZERO_PATTERN;
916 #endif
918 }
NumericVector interface to PETSc Vec.
Definition: petsc_vector.h:64
ImplicitSystem & sys
UniquePtr< NumericVector< Number > > current_local_solution
Definition: system.h:1533
const class libmesh_nullptr_t libmesh_nullptr
PetscErrorCode Vec Mat Mat pc
UniquePtr< NonlinearSolver< Number > > nonlinear_solver
PetscErrorCode Vec x
const DofMap & get_dof_map() const
Definition: system.h:2028
Used for solving nonlinear implicit systems of equations.
UniquePtr< NumericVector< Number > > solution
Definition: system.h:1521
void enforce_constraints_exactly(const System &system, NumericVector< Number > *v=libmesh_nullptr, bool homogeneous=false) const
virtual void update()
Definition: system.C:420
PetscErrorCode ierr
const Parallel::Communicator & comm() const
SparseMatrix< Number > * matrix
SparseMatrix interface to PETSc Mat.
PetscErrorCode DMlibMeshGetSystem(DM dm, libMesh::NonlinearImplicitSystem *&sys)
virtual void swap(NumericVector< T > &v) libmesh_override
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 597 of file petscdmlibmeshimpl.C.

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

Referenced by DMCreateDomainDecompositionDM_libMesh(), and DMCreateFieldDecompositionDM_libMesh().

598 {
599  PetscFunctionBegin;
600  PetscErrorCode ierr;
601  PetscBool eq;
602  char * s0;
603  char * s;
604  char * ss;
605  struct token * llfirst = PETSC_NULL;
606  struct token * lllast = PETSC_NULL;
607  struct token * tok;
608  PetscInt stcount = 0, brcount = 0, d, i;
609  size_t len0, count;
610 
611  /*
612  Parse the decomposition descriptor.
613  Decomposition names could be of one of two forms:
614  var:v1,v2;v3,v4;v4,v5;
615  block:b1,b2;b3,b4;b4,b5;
616  resulting in an overlapping decomposition that groups
617  variables (v1,v2), (v3,v4), (v4,v5) or
618  blocks (b1,b2), (b3,b4), (b4,b5).
619  */
620  /* Copy the descriptor so that we can manipulate it in place. */
621  ierr = PetscStrallocpy(ddesc,&s0); CHKERRQ(ierr);
622  ierr = PetscStrlen(s0, &len0) ; CHKERRQ(ierr);
623  ierr = PetscStrstr(s0,":",&ss); CHKERRQ(ierr);
624  if (!ss) {
625  ss = s0+len0;
626  }
627  else {
628  *ss = 0;
629  }
630  ierr = PetscStrcmp(s0,"var",&eq); CHKERRQ(ierr);
631  if (eq) {
632  *dtype=DMLIBMESH_FIELD_DECOMPOSITION;
633  }
634  else {
635  ierr = PetscStrcmp(s0,"block",&eq);CHKERRQ(ierr);
636  if (!eq)
637  SETERRQ1(((PetscObject)dm)->comm, PETSC_ERR_ARG_WRONG, "Could not determine decomposition type from descriptor: %s\n", ddesc); CHKERRQ(ierr);
638  *dtype=DMLIBMESH_DOMAIN_DECOMPOSITION;
639  }
640  ierr = PetscStrlen(s0,&count); CHKERRQ(ierr);
641  while (count < len0) {
642  struct token * st;
643  struct token * br;
644  ++ss; ++count;
645  s=ss;
646  while (*ss && *ss != ',' && *ss != ';') {
647  ++ss; ++count;
648  }
649  st = PETSC_NULL; br = PETSC_NULL;
650  if (*ss) {
651  /*
652  Found a separator, or a break.
653  Add an appropriate token to the list.
654  A token separator ',' produces no token.
655  */
656  if (*ss == ';') {
657  /* Create a break token: a token with a null string. */
658 #if PETSC_RELEASE_LESS_THAN(3,5,0)
659  ierr = PetscNew(struct token,&br);CHKERRQ(ierr);
660 #else
661  ierr = PetscNew(&br);CHKERRQ(ierr);
662 #endif
663  }
664  *ss = 0;
665  if (s != ss) {
666  /* A nonempty string. */
667 #if PETSC_RELEASE_LESS_THAN(3,5,0)
668  ierr = PetscNew(struct token, &st);CHKERRQ(ierr);
669 #else
670  ierr = PetscNew(&st);CHKERRQ(ierr);
671 #endif
672  st->s = s; /* The string will be properly copied below. */
673  }
674  /* Add the new tokens to the list. */
675  if (st) {
676  if (!lllast) {
677  llfirst = lllast = st;
678  }
679  else {
680  lllast->next = st; lllast = st;
681  }
682  }
683  if (br) {
684  if (!lllast) {
685  llfirst = lllast = br;
686  }
687  else {
688  lllast->next = br; lllast = br;
689  }
690  }
691  }
692  }
693  /* The result of parsing is in the linked list ll. */
694  /* Count up the strings and the breaks. */
695  tok = llfirst;
696  while (tok) {
697  if (tok->s)
698  ++stcount;
699  else
700  ++brcount;
701  tok = tok->next;
702  }
703  /* Allocate the space for the output. */
704  *dcount = brcount;
705  ierr = PetscMalloc(*dcount*sizeof(PetscInt), dsizes); CHKERRQ(ierr);
706  ierr = PetscMalloc(*dcount*sizeof(char **), dlists); CHKERRQ(ierr);
707  for (d = 0; d < *dcount; ++d) (*dsizes)[d] = 0;
708  tok = llfirst; d = 0;
709  while (tok) {
710  if (tok->s)
711  ++(*dsizes)[d];
712  else
713  ++d;
714  tok = tok->next;
715  }
716  for (d = 0; d < *dcount; ++d) {
717  ierr = PetscMalloc(sizeof(char **)*(*dsizes)[d], (* dlists)+d); CHKERRQ(ierr);
718  }
719  /* Now copy strings and destroy tokens. */
720  tok = llfirst; d = 0; i = 0;
721  while (tok) {
722  if (tok->s) {
723  ierr = PetscStrallocpy(tok->s, (*dlists)[d]+i); CHKERRQ(ierr);
724  ++i;
725  }
726  else {
727  ++d;
728  i = 0;
729  }
730  llfirst = tok;
731  tok = tok->next;
732  ierr = PetscFree(llfirst); CHKERRQ(ierr);
733  }
734  /* Deallocate workspace. */
735  ierr = PetscFree(s0); CHKERRQ(ierr);
737 }
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_elements_begin(), libMesh::MeshBase::active_elements_end(), DM_libMesh::blockids, DM_libMesh::blocknames, CHKERRQ(), libMesh::ParallelObject::comm(), dlm, DMlibMeshSetUpName_Private(), end, 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 oftype %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());
122  for (; el!=end; ++el)
123  blocks.insert((*el)->subdomain_id());
124  // Some subdomains may only live on other processors
125  comm.set_union(blocks);
126 
127  std::set<subdomain_id_type>::iterator bit = blocks.begin();
128  std::set<subdomain_id_type>::iterator bend = blocks.end();
129  if (bit == bend) SETERRQ(((PetscObject)dm)->comm, PETSC_ERR_PLIB, "No mesh blocks found.");
130 
131  for (; bit != bend; ++bit) {
132  subdomain_id_type bid = *bit;
133  std::string bname = mesh.subdomain_name(bid);
134  if (!bname.length()) {
135  /* Block names are currently implemented for Exodus II meshes
136  only, so we might have to make up our own block names and
137  maintain our own mapping of block ids to names.
138  */
139  std::ostringstream ss;
140  ss << "dm" << bid;
141  bname = ss.str();
142  }
143  dlm->blockids->insert(std::pair<std::string,unsigned int>(bname,bid));
144  dlm->blocknames->insert(std::pair<unsigned int,std::string>(bid,bname));
145  }
146  ierr = DMlibMeshSetUpName_Private(dm); CHKERRQ(ierr);
148 }
NonlinearImplicitSystem * sys
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
IterBase * end
const Variable & variable(const unsigned int c) const
Definition: dof_map.h:1646
Base class for Mesh.
Definition: mesh_base.h:67
Manages the degrees of freedom (DOFs) in a simulation.
Definition: dof_map.h:167
const MeshBase & get_mesh() const
Definition: system.h:2012
const DofMap & get_dof_map() const
Definition: system.h:2028
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:571
virtual element_iterator active_elements_begin()=0
virtual element_iterator active_elements_end()=0
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
PetscErrorCode DMlibMeshSetUpName_Private ( DM  dm)

Definition at line 217 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().

218 {
219  DM_libMesh * dlm = (DM_libMesh *)dm->data;
220  PetscErrorCode ierr;
221  PetscFunctionBegin;
222  std::string name = dlm->sys->name();
223  std::map<unsigned int, std::string> * dnames = PETSC_NULL, * enames = PETSC_NULL;
224  if (dlm->decomposition_type == DMLIBMESH_FIELD_DECOMPOSITION) {
225  name += ":dec:var:";
226  dnames = dlm->varnames;
227  }
228  if (dlm->decomposition_type == DMLIBMESH_DOMAIN_DECOMPOSITION) {
229  name += ":dec:block:";
230  dnames = dlm->blocknames;
231  }
232  if (dnames) {
233  for (unsigned int d = 0; d < dlm->decomposition->size(); ++d) {
234  for (std::set<unsigned int>::iterator dit = (*dlm->decomposition)[d].begin(); dit != (*dlm->decomposition)[d].end(); ++dit) {
235  unsigned int id = *dit;
236  if (dit != (*dlm->decomposition)[d].begin())
237  name += ",";
238  name += (*dnames)[id];
239  }
240  name += ";";
241  }
242  }
243  if (dlm->embedding_type == DMLIBMESH_FIELD_EMBEDDING) {
244  name += ":emb:var:";
245  enames = dlm->varnames;
246  }
247  if (dlm->embedding_type == DMLIBMESH_DOMAIN_EMBEDDING) {
248  name += ":emb:block:";
249  enames = dlm->blocknames;
250  }
251  if (enames) {
252  for (std::map<unsigned int, std::string>::iterator eit = enames->begin(); eit != enames->end(); ++eit) {
253  std::string ename = eit->second;
254  if (eit != enames->begin())
255  name += ",";
256  name += ename;
257  }
258  name += ";";
259  }
260  ierr = PetscObjectSetName((PetscObject)dm, name.c_str()); CHKERRQ(ierr);
262 }
std::string name(const ElemQuality q)
Definition: elem_quality.C:39
NonlinearImplicitSystem * sys
unsigned int embedding_type
IterBase * end
const std::string & name() const
Definition: system.h:1996
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 1101 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().

1102 {
1103  PetscFunctionBegin;
1104  PetscErrorCode ierr;
1105  DM_libMesh * dlm = (DM_libMesh *)(dm->data);
1106  PetscBool eq;
1107 
1108  ierr = PetscObjectTypeCompare((PetscObject)dm, DMLIBMESH, &eq); CHKERRQ(ierr);
1109 
1110  if (!eq)
1111  SETERRQ2(((PetscObject)dm)->comm, PETSC_ERR_ARG_WRONG, "DM of type %s, not of type %s", ((PetscObject)dm)->type, DMLIBMESH);
1112 
1113  if (!dlm->sys)
1114  SETERRQ(PETSC_COMM_WORLD, PETSC_ERR_ARG_WRONGSTATE, "No libMesh system set for DM_libMesh");
1115  /*
1116  Do not evaluate function, Jacobian or bounds for an embedded DM -- the subproblem might not have enough information for that.
1117  */
1118  if (!dlm->embedding) {
1119 #if PETSC_RELEASE_LESS_THAN(3,3,1)
1120  ierr = DMSetFunction(dm, DMlibMeshFunction); CHKERRQ(ierr);
1121  ierr = DMSetJacobian(dm, DMlibMeshJacobian); CHKERRQ(ierr);
1122 #else
1123  ierr = DMSNESSetFunction(dm, SNESFunction_DMlibMesh, (void *)dm); CHKERRQ(ierr);
1124  ierr = DMSNESSetJacobian(dm, SNESJacobian_DMlibMesh, (void *)dm); CHKERRQ(ierr);
1125 #endif
1126  if (dlm->sys->nonlinear_solver->bounds || dlm->sys->nonlinear_solver->bounds_object)
1127  ierr = DMSetVariableBounds(dm, DMVariableBounds_libMesh); CHKERRQ(ierr);
1128  }
1129  else {
1130  /*
1131  Fow now we don't implement even these, although a linear "Dirichlet" subproblem is well-defined.
1132  Creating the submatrix, however, might require extracting the submatrix preallocation from an unassembled matrix.
1133  */
1134  dm->ops->createglobalvector = 0;
1135  dm->ops->creatematrix = 0;
1136  }
1138 }
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
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 945 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().

946 {
947  PetscErrorCode ierr;
949  ierr = DMlibMeshGetSystem(dm, _sys); CHKERRQ(ierr);
950  NonlinearImplicitSystem & sys = *_sys;
951  PetscVector<Number> XL(xl, sys.comm());
952  PetscVector<Number> XU(xu, sys.comm());
953  PetscFunctionBegin;
954 #if PETSC_VERSION_LESS_THAN(3,5,0) && PETSC_VERSION_RELEASE
955  ierr = VecSet(xl, SNES_VI_NINF);CHKERRQ(ierr);
956  ierr = VecSet(xu, SNES_VI_INF);CHKERRQ(ierr);
957 #else
958  ierr = VecSet(xl, PETSC_NINFINITY);CHKERRQ(ierr);
959  ierr = VecSet(xu, PETSC_INFINITY);CHKERRQ(ierr);
960 #endif
961  if (sys.nonlinear_solver->bounds != libmesh_nullptr)
962  sys.nonlinear_solver->bounds(XL,XU,sys);
963  else if (sys.nonlinear_solver->bounds_object != libmesh_nullptr)
964  sys.nonlinear_solver->bounds_object->bounds(XL,XU, sys);
965  else
966  SETERRQ(((PetscObject)dm)->comm, PETSC_ERR_ARG_WRONG, "No bounds calculation in this libMesh object");
967 
969 }
NumericVector interface to PETSc Vec.
Definition: petsc_vector.h:64
ImplicitSystem & sys
const class libmesh_nullptr_t libmesh_nullptr
UniquePtr< NonlinearSolver< Number > > nonlinear_solver
Used for solving nonlinear implicit systems of equations.
PetscErrorCode ierr
const Parallel::Communicator & comm() const
PetscErrorCode DMlibMeshGetSystem(DM dm, libMesh::NonlinearImplicitSystem *&sys)
PetscFunctionReturn(0)
CHKERRQ(ierr)
static PetscErrorCode DMView_libMesh ( DM  dm,
PetscViewer  viewer 
)
static

Definition at line 1042 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().

1043 {
1044  PetscErrorCode ierr;
1045  PetscBool isascii;
1046  const char * name, * prefix;
1047  DM_libMesh * dlm = (DM_libMesh *)dm->data;
1048  PetscFunctionBegin;
1049  ierr = PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERASCII,&isascii); CHKERRQ(ierr);
1050  if (isascii) {
1051  ierr = PetscObjectGetName((PetscObject)dm, &name); CHKERRQ(ierr);
1052  ierr = PetscObjectGetOptionsPrefix((PetscObject)dm, &prefix); CHKERRQ(ierr);
1053  ierr = PetscViewerASCIIPrintf(viewer, "DM libMesh with name %s and prefix %s\n", name, prefix); CHKERRQ(ierr);
1054  ierr = PetscViewerASCIIPrintf(viewer, "blocks:", name, prefix); CHKERRQ(ierr);
1055  std::map<std::string,unsigned int>::iterator bit = dlm->blockids->begin();
1056  std::map<std::string,unsigned int>::const_iterator bend = dlm->blockids->end();
1057  for (; bit != bend; ++bit) {
1058  ierr = PetscViewerASCIIPrintf(viewer, "(%s,%D) ", bit->first.c_str(), bit->second); CHKERRQ(ierr);
1059  }
1060  ierr = PetscViewerASCIIPrintf(viewer, "\n"); CHKERRQ(ierr);
1061  ierr = PetscViewerASCIIPrintf(viewer, "variables:", name, prefix); CHKERRQ(ierr);
1062  std::map<std::string,unsigned int>::iterator vit = dlm->varids->begin();
1063  std::map<std::string,unsigned int>::const_iterator vend = dlm->varids->end();
1064  for (; vit != vend; ++vit) {
1065  ierr = PetscViewerASCIIPrintf(viewer, "(%s,%D) ", vit->first.c_str(), vit->second); CHKERRQ(ierr);
1066  }
1067  ierr = PetscViewerASCIIPrintf(viewer, "\n"); CHKERRQ(ierr);
1068  if (dlm->decomposition_type == DMLIBMESH_NO_DECOMPOSITION) {
1069  ierr = PetscViewerASCIIPrintf(viewer, "No decomposition\n"); CHKERRQ(ierr);
1070  }
1071  else {
1072  if (dlm->decomposition_type == DMLIBMESH_FIELD_DECOMPOSITION) {
1073  ierr = PetscViewerASCIIPrintf(viewer, "Field decomposition by variable: "); CHKERRQ(ierr);
1074  }
1075  else if (dlm->decomposition_type == DMLIBMESH_DOMAIN_DECOMPOSITION) {
1076  ierr = PetscViewerASCIIPrintf(viewer, "Domain decomposition by block: "); CHKERRQ(ierr);
1077  }
1078  else SETERRQ1(((PetscObject)dm)->comm, PETSC_ERR_PLIB, "Unexpected decomposition type: %D", dlm->decomposition_type);
1079  /* FIX: decompositions might have different sizes and components on different ranks. */
1080  for (unsigned int d = 0; d < dlm->decomposition->size(); ++d) {
1081  std::set<unsigned int>::iterator dbegin = (*dlm->decomposition)[d].begin();
1082  std::set<unsigned int>::iterator dit = (*dlm->decomposition)[d].begin();
1083  std::set<unsigned int>::iterator dend = (*dlm->decomposition)[d].end();
1084  for (; dit != dend; ++dit) {
1085  if (dit != dbegin) {
1086  ierr = PetscViewerASCIIPrintf(viewer, ","); CHKERRQ(ierr);
1087  }
1088  ierr = PetscViewerASCIIPrintf(viewer, "%D", *dit); CHKERRQ(ierr);
1089  }
1090  ierr = PetscViewerASCIIPrintf(viewer, ";"); CHKERRQ(ierr);
1091  }
1092  ierr = PetscViewerASCIIPrintf(viewer, "\n"); CHKERRQ(ierr);
1093  }
1094  }
1095 
1097 }
std::string name(const ElemQuality q)
Definition: elem_quality.C:39
std::map< std::string, unsigned int > * blockids
std::map< std::string, unsigned int > * varids
IterBase * 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)
if ( !dlm->  sys)
static PetscErrorCode SNESFunction_DMlibMesh ( SNES  ,
Vec  x,
Vec  r,
void *  ctx 
)
static

Definition at line 839 of file petscdmlibmeshimpl.C.

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

Referenced by DMSetUp_libMesh().

840 {
841  DM dm = (DM)ctx;
842  PetscErrorCode ierr;
843  PetscFunctionBegin;
844  ierr = DMlibMeshFunction(dm,x,r);CHKERRQ(ierr);
846 }
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 923 of file petscdmlibmeshimpl.C.

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

Referenced by DMSetUp_libMesh().

930 {
931  DM dm = (DM)ctx;
932  PetscErrorCode ierr;
933  PetscFunctionBegin;
934 #if PETSC_RELEASE_LESS_THAN(3,5,0)
935  ierr = DMlibMeshJacobian(dm,x,*jac,*pc,flag); CHKERRQ(ierr);
936 #else
937  ierr = DMlibMeshJacobian(dm,x,jac,pc); CHKERRQ(ierr);
938 #endif
940 }
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

No libMesh system set for DM_libMesh

Definition at line 1032 of file petscdmlibmeshimpl.C.

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

Definition at line 1022 of file petscdmlibmeshimpl.C.

Referenced by libMesh::__libmesh_petsc_diff_solver_monitor(), __libmesh_petsc_preconditioner_apply(), __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::PetscVector< T >::_get_array(), libMesh::PetscMatrix< T >::_get_submatrix(), 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::PetscVector< T >::_restore_array(), libMesh::PetscLinearSolver< T >::_restrict_solve_to_is_local_size(), libMesh::SlepcEigenSolver< T >::_solve_generalized_helper(), libMesh::SlepcEigenSolver< T >::_solve_standard_helper(), libMesh::PetscVector< T >::abs(), libMesh::PetscMatrix< T >::add(), libMesh::PetscVector< T >::add(), libMesh::PetscMatrix< T >::add_block_matrix(), libMesh::PetscMatrix< T >::add_matrix(), libMesh::PetscVector< T >::add_vector(), libMesh::PetscVector< T >::add_vector_conjugate_transpose(), libMesh::PetscVector< T >::add_vector_transpose(), 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(), libMesh::PetscVector< T >::clear(), libMesh::PetscMatrix< T >::clear(), libMesh::PetscVector< T >::close(), libMesh::PetscMatrix< T >::close(), libMesh::PetscMatrix< T >::closed(), libMesh::PetscVector< T >::conjugate(), libMesh::PetscVector< T >::create_subvector(), 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::PetscVector< T >::dot(), libMesh::PetscVector< T >::first_local_index(), libMesh::TaoOptimizationSolver< T >::get_converged_reason(), libMesh::PetscNonlinearSolver< T >::get_converged_reason(), libMesh::PetscMatrix< T >::get_diagonal(), 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::PetscMatrix< T >::get_transpose(), libMesh::PetscVector< T >::indefinite_dot(), libMesh::PetscDiffSolver::init(), libMesh::PetscPreconditioner< T >::init(), libMesh::SlepcEigenSolver< T >::init(), libMesh::TaoOptimizationSolver< T >::init(), libMesh::PetscNonlinearSolver< T >::init(), libMesh::PetscLinearSolver< T >::init(), libMesh::PetscMatrix< T >::init(), libMesh::PetscVector< T >::init(), libMesh::PetscVector< T >::insert(), libMesh::PetscVector< T >::l1_norm(), libMesh::PetscMatrix< T >::l1_norm(), libMesh::PetscVector< T >::l2_norm(), libMesh::PetscVector< T >::last_local_index(), libMesh::LibMeshInit::LibMeshInit(), libMesh::PetscVector< T >::linfty_norm(), libMesh::PetscMatrix< T >::linfty_norm(), libMesh::PetscVector< T >::local_size(), libMesh::PetscVector< T >::localize(), libMesh::PetscVector< T >::localize_to_one(), libMesh::PetscMatrix< T >::m(), libMesh::PetscVector< T >::map_global_to_local_index(), libMesh::PetscVector< T >::max(), libMesh::PetscVector< T >::min(), libMesh::PetscMatrix< T >::n(), libMesh::PetscMatrix< T >::operator()(), libMesh::PetscVector< T >::operator/=(), libMesh::PetscVector< T >::operator=(), libMesh::PetscVector< T >::PetscVector(), libMesh::PetscVector< T >::pointwise_mult(), libMesh::PetscMatrix< T >::print_matlab(), libMesh::PetscVector< T >::print_matlab(), libMesh::PetscMatrix< T >::print_personal(), libMesh::GMVIO::read(), libMesh::PetscVector< T >::reciprocal(), libMesh::PetscDiffSolver::reinit(), libMesh::PetscLinearSolver< T >::restrict_solve_to(), libMesh::PetscMatrix< T >::row_start(), libMesh::PetscMatrix< T >::row_stop(), libMesh::PetscVector< T >::scale(), libMesh::PetscMatrix< T >::set(), libMesh::PetscVector< T >::set(), 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(), libMesh::PetscVector< T >::size(), 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(), libMesh::PetscVector< T >::sum(), libMesh::TecplotIO::write_binary(), libMesh::PetscVector< T >::zero(), libMesh::PetscMatrix< T >::zero(), and libMesh::PetscMatrix< T >::zero_rows().

PETSC_ERR_ARG_WRONGSTATE