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 1146 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().

1147 {
1148  PetscErrorCode ierr;
1149  DM_libMesh * dlm;
1150 
1151  PetscFunctionBegin;
1152  PetscValidHeaderSpecific(dm,DM_CLASSID,1);
1153 #if PETSC_RELEASE_LESS_THAN(3,5,0)
1154  ierr = PetscNewLog(dm,DM_libMesh,&dlm);CHKERRQ(ierr);
1155 #else
1156  ierr = PetscNewLog(dm,&dlm);CHKERRQ(ierr);
1157 #endif
1158  dm->data = dlm;
1159 
1160  /* DMlibMesh impl */
1161  dlm->varids = new(std::map<std::string, unsigned int>);
1162  dlm->blockids = new(std::map<std::string, unsigned int>);
1163  dlm->varnames = new(std::map<unsigned int, std::string>);
1164  dlm->blocknames = new(std::map<unsigned int, std::string>);
1165  dlm->decomposition = PETSC_NULL;
1166  dlm->decomposition_type = DMLIBMESH_NO_DECOMPOSITION;
1167 
1168  /* DM API */
1169  dm->ops->createglobalvector = DMCreateGlobalVector_libMesh;
1170  dm->ops->createlocalvector = 0; // DMCreateLocalVector_libMesh;
1171  dm->ops->getcoloring = 0; // DMGetColoring_libMesh;
1172  dm->ops->creatematrix = DMCreateMatrix_libMesh;
1173  dm->ops->createinterpolation= 0; // DMCreateInterpolation_libMesh;
1174 
1175  dm->ops->refine = 0; // DMRefine_libMesh;
1176  dm->ops->coarsen = 0; // DMCoarsen_libMesh;
1177  dm->ops->getinjection = 0; // DMGetInjection_libMesh;
1178  dm->ops->getaggregates = 0; // DMGetAggregates_libMesh;
1179 
1180 #if PETSC_RELEASE_LESS_THAN(3,3,1)
1181  dm->ops->createfielddecompositiondm = DMCreateFieldDecompositionDM_libMesh;
1182  dm->ops->createdomaindecompositiondm = DMCreateDomainDecompositionDM_libMesh;
1183 #endif
1184  dm->ops->createfielddecomposition = DMCreateFieldDecomposition_libMesh;
1185  dm->ops->createdomaindecomposition = DMCreateDomainDecomposition_libMesh;
1186 
1187  dm->ops->destroy = DMDestroy_libMesh;
1188  dm->ops->view = DMView_libMesh;
1189  dm->ops->setfromoptions = 0; // DMSetFromOptions_libMesh;
1190  dm->ops->setup = DMSetUp_libMesh;
1191 
1192  /* DMlibMesh API */
1193 #if PETSC_RELEASE_LESS_THAN(3,4,0)
1194  ierr = PetscObjectComposeFunction((PetscObject)dm,"DMlibMeshSetSystem_C",PETSC_NULL,(PetscVoidFunction)DMlibMeshSetSystem_libMesh);CHKERRQ(ierr);
1195  ierr = PetscObjectComposeFunction((PetscObject)dm,"DMlibMeshGetSystem_C",PETSC_NULL,(PetscVoidFunction)DMlibMeshGetSystem_libMesh);CHKERRQ(ierr);
1196 #else
1197  ierr = PetscObjectComposeFunction((PetscObject)dm,"DMlibMeshSetSystem_C",DMlibMeshSetSystem_libMesh);CHKERRQ(ierr);
1198  ierr = PetscObjectComposeFunction((PetscObject)dm,"DMlibMeshGetSystem_C",DMlibMeshGetSystem_libMesh);CHKERRQ(ierr);
1199 #endif
1200 
1202 }
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 355 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().

356 {
357  PetscFunctionBegin;
358  PetscErrorCode ierr;
359  DM_libMesh * dlm = (DM_libMesh *)(dm->data);
361  IS emb;
362  if(dlm->decomposition_type != DMLIBMESH_DOMAIN_DECOMPOSITION) PetscFunctionReturn(0);
363  *len = dlm->decomposition->size();
364  if(namelist) {ierr = PetscMalloc(*len*sizeof(char *), namelist); CHKERRQ(ierr);}
365  if(innerislist) {ierr = PetscMalloc(*len*sizeof(IS), innerislist); CHKERRQ(ierr);}
366  if(outerislist) *outerislist = PETSC_NULL; /* FIX: allow mesh-based overlap. */
367  if(dmlist) {ierr = PetscMalloc(*len*sizeof(DM), dmlist); CHKERRQ(ierr);}
368  for(unsigned int d = 0; d < dlm->decomposition->size(); ++d) {
369  std::set<numeric_index_type> dindices;
370  std::string dname;
371  std::map<std::string, unsigned int> dblockids;
372  std::map<unsigned int,std::string> dblocknames;
373  unsigned int dbcount = 0;
374  for(std::set<unsigned int>::const_iterator bit = (*dlm->decomposition)[d].begin(); bit != (*dlm->decomposition)[d].end(); ++bit){
375  unsigned int b = *bit;
376  std::string bname = (*dlm->blocknames)[b];
377  dblockids.insert(std::pair<std::string, unsigned int>(bname,b));
378  dblocknames.insert(std::pair<unsigned int,std::string>(b,bname));
379  if(!dbcount) dname = bname;
380  else dname += "_" + bname;
381  ++dbcount;
382  if(!innerislist) continue;
385  for ( ; el != end_el; ++el) {
386  const Elem * elem = *el;
387  std::vector<numeric_index_type> evindices;
388  /* Iterate only over this DM's variables. */
389  for(std::map<std::string, unsigned int>::const_iterator vit = dlm->varids->begin(); vit != dlm->varids->end(); ++vit) {
390  unsigned int v = vit->second;
391  // Get the degree of freedom indices for the given variable off the current element.
392  sys->get_dof_map().dof_indices(elem, evindices, v);
393  for(unsigned int i = 0; i < evindices.size(); ++i) {
394  numeric_index_type dof = evindices[i];
395  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 */
396  dindices.insert(dof);
397  }
398  }
399  }
400  }
401  if(namelist) {
402  ierr = PetscStrallocpy(dname.c_str(),(*namelist)+d); CHKERRQ(ierr);
403  }
404  if(innerislist) {
405  PetscInt * darray;
406  IS dis;
407  ierr = PetscMalloc(sizeof(PetscInt)*dindices.size(), &darray); CHKERRQ(ierr);
408  numeric_index_type i = 0;
409  for(std::set<numeric_index_type>::const_iterator it = dindices.begin(); it != dindices.end(); ++it) {
410  darray[i] = *it;
411  ++i;
412  }
413  ierr = ISCreateGeneral(((PetscObject)dm)->comm, dindices.size(),darray, PETSC_OWN_POINTER, &dis); CHKERRQ(ierr);
414  if(dlm->embedding) {
415  /* Create a relative embedding into the parent's index space. */
416 #if PETSC_RELEASE_LESS_THAN(3,3,1)
417  ierr = ISMapFactorRight(dis,dlm->embedding, PETSC_TRUE, &emb); CHKERRQ(ierr);
418 #else
419  ierr = ISEmbed(dis,dlm->embedding, PETSC_TRUE, &emb); CHKERRQ(ierr);
420 #endif
421  PetscInt elen, dlen;
422  ierr = ISGetLocalSize(emb, &elen); CHKERRQ(ierr);
423  ierr = ISGetLocalSize(dis, &dlen); CHKERRQ(ierr);
424  if(elen != dlen) SETERRQ1(((PetscObject)dm)->comm, PETSC_ERR_PLIB, "Failed to embed field %D", d);
425  ierr = ISDestroy(&dis); CHKERRQ(ierr);
426  dis = emb;
427  }
428  else {
429  emb = dis;
430  }
431  if(innerislist) {
432  ierr = PetscObjectReference((PetscObject)dis); CHKERRQ(ierr);
433  (*innerislist)[d] = dis;
434  }
435  ierr = ISDestroy(&dis); CHKERRQ(ierr);
436  }
437  if(dmlist) {
438  DM ddm;
439  ierr = DMCreate(((PetscObject)dm)->comm, &ddm); CHKERRQ(ierr);
440  ierr = DMSetType(ddm, DMLIBMESH); CHKERRQ(ierr);
441  DM_libMesh * ddlm = (DM_libMesh *)(ddm->data);
442  ddlm->sys = dlm->sys;
443  /* copy over the varids and varnames */
444  *ddlm->varids = *dlm->varids;
445  *ddlm->varnames = *dlm->varnames;
446  /* set the blocks from the d-th part of the decomposition. */
447  *ddlm->blockids = dblockids;
448  *ddlm->blocknames = dblocknames;
449  ierr = PetscObjectReference((PetscObject)emb); CHKERRQ(ierr);
450  ddlm->embedding = emb;
451  ddlm->embedding_type = DMLIBMESH_DOMAIN_EMBEDDING;
452 
453  ierr = DMlibMeshSetUpName_Private(ddm); CHKERRQ(ierr);
454  ierr = DMSetFromOptions(ddm); CHKERRQ(ierr);
455  (*dmlist)[d] = ddm;
456  }
457  }
459 }
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:531
std::vector< std::set< unsigned int > > * decomposition
dof_id_type end_dof(const processor_id_type proc) const
Definition: dof_map.h:569
virtual element_iterator active_local_subdomain_elements_begin(subdomain_id_type subdomain_id)=0
const MeshBase & get_mesh() const
Definition: system.h:2003
const DofMap & get_dof_map() const
Definition: system.h:2019
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:2022
static PetscErrorCode DMCreateDomainDecompositionDM_libMesh ( DM  dm,
const char *  ddesc,
DM *  ddm 
)
static

Definition at line 742 of file petscdmlibmeshimpl.C.

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

Referenced by DMCreate_libMesh().

743 {
744  PetscFunctionBegin;
745  PetscErrorCode ierr;
746  PetscInt dtype, dcount;
747  PetscInt * dsizes;
748  char *** dlists;
749  PetscFunctionBegin;
750  *ddm = PETSC_NULL;
751  ierr = DMlibMeshParseDecompositionDescriptor_Private(dm,ddesc,&dtype,&dcount,&dsizes,&dlists); CHKERRQ(ierr);
752  if(dtype == DMLIBMESH_DOMAIN_DECOMPOSITION) {
753  ierr = DMlibMeshCreateDomainDecompositionDM(dm,dcount,dsizes,dlists,ddm); CHKERRQ(ierr);
754  }
755  else SETERRQ1(((PetscObject)dm)->comm, PETSC_ERR_PLIB, "Uexpected unknown decomposition type for domain decomposition descriptor %s", ddesc);
757 }
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 249 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().

250 {
251  PetscFunctionBegin;
252  PetscErrorCode ierr;
253  DM_libMesh * dlm = (DM_libMesh *)(dm->data);
255  IS emb;
256  if(dlm->decomposition_type != DMLIBMESH_FIELD_DECOMPOSITION) PetscFunctionReturn(0);
257 
258  *len = dlm->decomposition->size();
259  if(namelist) {ierr = PetscMalloc(*len*sizeof(char *), namelist); CHKERRQ(ierr);}
260  if(islist) {ierr = PetscMalloc(*len*sizeof(IS), islist); CHKERRQ(ierr);}
261  if(dmlist) {ierr = PetscMalloc(*len*sizeof(DM), dmlist); CHKERRQ(ierr);}
262  DofMap & dofmap = dlm->sys->get_dof_map();
263  for(unsigned int d = 0; d < dlm->decomposition->size(); ++d) {
264  std::set<numeric_index_type> dindices;
265  std::string dname;
266  std::map<std::string, unsigned int> dvarids;
267  std::map<unsigned int, std::string> dvarnames;
268  unsigned int dvcount = 0;
269  for(std::set<unsigned int>::const_iterator dvit = (*dlm->decomposition)[d].begin(); dvit != (*dlm->decomposition)[d].end(); ++dvit){
270  unsigned int v = *dvit;
271  std::string vname = (*dlm->varnames)[v];
272  dvarids.insert(std::pair<std::string, unsigned int>(vname,v));
273  dvarnames.insert(std::pair<unsigned int,std::string>(v,vname));
274  if(!dvcount) dname = vname;
275  else dname += "_" + vname;
276  ++dvcount;
277  if(!islist) continue;
278  /* Iterate only over this DM's blocks. */
279  for(std::map<std::string, unsigned int>::const_iterator bit = dlm->blockids->begin(); bit != dlm->blockids->end(); ++bit) {
280  unsigned int b = bit->second;
283  for ( ; el != end_el; ++el) {
284  const Elem * elem = *el;
285  //unsigned int e_subdomain = elem->subdomain_id();
286  std::vector<numeric_index_type> evindices;
287  // Get the degree of freedom indices for the given variable off the current element.
288  dofmap.dof_indices(elem, evindices, v);
289  for(unsigned int i = 0; i < evindices.size(); ++i) {
290  numeric_index_type dof = evindices[i];
291  if(dof >= dofmap.first_dof() && dof < dofmap.end_dof()) /* might want to use variable_first/last_local_dof instead */
292  dindices.insert(dof);
293  }
294  }
295  }
296  }
297  if(namelist) {
298  ierr = PetscStrallocpy(dname.c_str(),(*namelist)+d); CHKERRQ(ierr);
299  }
300  if(islist) {
301  IS dis;
302  PetscInt * darray;
303  ierr = PetscMalloc(sizeof(PetscInt)*dindices.size(), &darray); CHKERRQ(ierr);
304  numeric_index_type i = 0;
305  for(std::set<numeric_index_type>::const_iterator it = dindices.begin(); it != dindices.end(); ++it) {
306  darray[i] = *it;
307  ++i;
308  }
309  ierr = ISCreateGeneral(((PetscObject)dm)->comm, dindices.size(),darray, PETSC_OWN_POINTER, &dis); CHKERRQ(ierr);
310  if(dlm->embedding) {
311  /* Create a relative embedding into the parent's index space. */
312 #if PETSC_RELEASE_LESS_THAN(3,3,1)
313  ierr = ISMapFactorRight(dis,dlm->embedding, PETSC_TRUE, &emb); CHKERRQ(ierr);
314 #else
315  ierr = ISEmbed(dis,dlm->embedding, PETSC_TRUE, &emb); CHKERRQ(ierr);
316 #endif
317  PetscInt elen, dlen;
318  ierr = ISGetLocalSize(emb, &elen); CHKERRQ(ierr);
319  ierr = ISGetLocalSize(dis, &dlen); CHKERRQ(ierr);
320  if(elen != dlen) SETERRQ1(((PetscObject)dm)->comm, PETSC_ERR_PLIB, "Failed to embed subdomain %D", d);
321  ierr = ISDestroy(&dis); CHKERRQ(ierr);
322  dis = emb;
323  }
324  else {
325  emb = dis;
326  }
327  (*islist)[d] = dis;
328  }
329  if(dmlist) {
330  DM ddm;
331  ierr = DMCreate(((PetscObject)dm)->comm, &ddm); CHKERRQ(ierr);
332  ierr = DMSetType(ddm, DMLIBMESH); CHKERRQ(ierr);
333  DM_libMesh * ddlm = (DM_libMesh *)(ddm->data);
334  ddlm->sys = dlm->sys;
335  /* copy over the block ids and names */
336  *ddlm->blockids = *dlm->blockids;
337  *ddlm->blocknames = *dlm->blocknames;
338  /* set the vars from the d-th part of the decomposition. */
339  *ddlm->varids = dvarids;
340  *ddlm->varnames = dvarnames;
341  ierr = PetscObjectReference((PetscObject)emb); CHKERRQ(ierr);
342  ddlm->embedding = emb;
343  ddlm->embedding_type = DMLIBMESH_FIELD_EMBEDDING;
344 
345  ierr = DMlibMeshSetUpName_Private(ddm); CHKERRQ(ierr);
346  ierr = DMSetFromOptions(ddm); CHKERRQ(ierr);
347  (*dmlist)[d] = ddm;
348  }
349  }
351 }
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:531
std::vector< std::set< unsigned int > > * decomposition
dof_id_type end_dof(const processor_id_type proc) const
Definition: dof_map.h:569
virtual element_iterator active_local_subdomain_elements_begin(subdomain_id_type subdomain_id)=0
const MeshBase & get_mesh() const
Definition: system.h:2003
const DofMap & get_dof_map() const
Definition: system.h:2019
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:2022
static PetscErrorCode DMCreateFieldDecompositionDM_libMesh ( DM  dm,
const char *  ddesc,
DM *  ddm 
)
static

Definition at line 723 of file petscdmlibmeshimpl.C.

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

Referenced by DMCreate_libMesh().

724 {
725  PetscFunctionBegin;
726  PetscErrorCode ierr;
727  PetscInt dtype, dcount;
728  PetscInt * dsizes;
729  char *** dlists;
730  PetscFunctionBegin;
731  *ddm = PETSC_NULL;
732  ierr = DMlibMeshParseDecompositionDescriptor_Private(dm,ddesc,&dtype,&dcount,&dsizes,&dlists); CHKERRQ(ierr);
733  if(dtype == DMLIBMESH_FIELD_DECOMPOSITION){
734  ierr = DMlibMeshCreateFieldDecompositionDM(dm,dcount,dsizes,dlists,ddm); CHKERRQ(ierr);
735  }
736  else SETERRQ1(((PetscObject)dm)->comm, PETSC_ERR_PLIB, "Uexpected unknown decomposition type for field decomposition descriptor %s", ddesc);
738 }
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 956 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().

957 {
958  PetscFunctionBegin;
959  PetscErrorCode ierr;
960  DM_libMesh * dlm = (DM_libMesh *)(dm->data);
961  PetscBool eq;
962 
963  ierr = PetscObjectTypeCompare((PetscObject)dm, DMLIBMESH, &eq); CHKERRQ(ierr);
964 
965  if (!eq)
966  SETERRQ2(((PetscObject)dm)->comm, PETSC_ERR_ARG_WRONG, "DM of type %s, not of type %s", ((PetscObject)dm)->type, DMLIBMESH);
967 
968  if (!dlm->sys)
969  SETERRQ(PETSC_COMM_WORLD, PETSC_ERR_ARG_WRONGSTATE, "No libMesh system set for DM_libMesh");
970 
971  NumericVector<Number> * nv = (dlm->sys->solution).get();
972  PetscVector<Number> * pv = dynamic_cast<PetscVector<Number> *>(nv);
973  Vec v = pv->vec();
974  /* Unfortunately, currently this does not produce a ghosted vector, so nonlinear subproblem solves aren't going to be easily available.
975  Should work fine for getting vectors out for linear subproblem solvers. */
976  if(dlm->embedding) {
977  PetscInt n;
978  ierr = VecCreate(((PetscObject)v)->comm, x); CHKERRQ(ierr);
979  ierr = ISGetLocalSize(dlm->embedding, &n); CHKERRQ(ierr);
980  ierr = VecSetSizes(*x,n,PETSC_DETERMINE); CHKERRQ(ierr);
981  ierr = VecSetType(*x,((PetscObject)v)->type_name); CHKERRQ(ierr);
982  ierr = VecSetFromOptions(*x); CHKERRQ(ierr);
983  ierr = VecSetUp(*x); CHKERRQ(ierr);
984  }
985  else {
986  ierr = VecDuplicate(v,x); CHKERRQ(ierr);
987  }
988  ierr = PetscObjectCompose((PetscObject)*x,"DM",(PetscObject)dm); CHKERRQ(ierr);
990 }
NonlinearImplicitSystem * sys
NumericVector interface to PETSc Vec.
Definition: petsc_vector.h:64
PetscBool eq
PetscErrorCode Vec x
UniquePtr< NumericVector< Number > > solution
Definition: system.h:1512
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 1127 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().

1128 {
1129  DM_libMesh * dlm = (DM_libMesh *)(dm->data);
1130  PetscErrorCode ierr;
1131  PetscFunctionBegin;
1132  delete dlm->varids;
1133  delete dlm->varnames;
1134  delete dlm->blockids;
1135  delete dlm->blocknames;
1136  delete dlm->decomposition;
1137  ierr = ISDestroy(&dlm->embedding); CHKERRQ(ierr);
1138  ierr = PetscFree(dm->data); CHKERRQ(ierr);
1139 
1141 }
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 517 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().

518 {
519  PetscErrorCode ierr;
520  PetscBool islibmesh;
521  PetscFunctionBegin;
522  PetscValidHeaderSpecific(dm,DM_CLASSID,1);
523  ierr = PetscObjectTypeCompare((PetscObject)dm, DMLIBMESH,&islibmesh);
524  if(!islibmesh) SETERRQ2(((PetscObject)dm)->comm, PETSC_ERR_ARG_WRONG, "Got DM oftype %s, not of type %s", ((PetscObject)dm)->type_name, DMLIBMESH);
525  if(dnumber < 0) SETERRQ1(((PetscObject)dm)->comm, PETSC_ERR_ARG_WRONG, "Negative number %D of decomposition parts", dnumber);
526  PetscValidPointer(ddm,5);
527  DM_libMesh * dlm = (DM_libMesh *)(dm->data);
528  ierr = DMCreate(((PetscObject)dm)->comm, ddm); CHKERRQ(ierr);
529  ierr = DMSetType(*ddm, DMLIBMESH); CHKERRQ(ierr);
530  DM_libMesh * ddlm = (DM_libMesh *)((*ddm)->data);
531  ddlm->sys = dlm->sys;
532  ddlm->varids = dlm->varids;
533  ddlm->varnames = dlm->varnames;
534  ddlm->blockids = dlm->blockids;
535  ddlm->blocknames = dlm->blocknames;
536  ddlm->decomposition = new(std::vector<std::set<unsigned int> >);
537  ddlm->decomposition_type = DMLIBMESH_DOMAIN_DECOMPOSITION;
538  if(dnumber) {
539  for(PetscInt d = 0; d < dnumber; ++d) {
540  if(dsizes[d] < 0) SETERRQ2(((PetscObject)dm)->comm, PETSC_ERR_ARG_WRONG, "Negative size %D of decomposition part %D", dsizes[d],d);
541  ddlm->decomposition->push_back(std::set<unsigned int>());
542  for(PetscInt b = 0; b < dsizes[d]; ++b) {
543  std::string bname(dblocklists[d][b]);
544  std::map<std::string, unsigned int>::const_iterator bit = dlm->blockids->find(bname);
545  if(bit == dlm->blockids->end())
546  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]);
547  unsigned int bid = bit->second;
548  (*ddlm->decomposition)[d].insert(bid);
549  }
550  }
551  }
552  else { /* Empty splits indicate default: split all blocks with one per split. */
553  PetscInt d = 0;
554  for(std::map<std::string, unsigned int>::const_iterator bit = ddlm->blockids->begin(); bit != ddlm->blockids->end(); ++bit) {
555  ddlm->decomposition->push_back(std::set<unsigned int>());
556  unsigned int bid = bit->second;
557  std::string bname = bit->first;
558  (*ddlm->decomposition)[d].insert(bid);
559  ++d;
560  }
561  }
562  ierr = DMlibMeshSetUpName_Private(*ddm); CHKERRQ(ierr);
563  ierr = DMSetFromOptions(*ddm); CHKERRQ(ierr);
564  ierr = DMSetUp(*ddm); CHKERRQ(ierr);
566 }
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 464 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().

465 {
466  PetscErrorCode ierr;
467  PetscBool islibmesh;
468  PetscFunctionBegin;
469  PetscValidHeaderSpecific(dm,DM_CLASSID,1);
470  ierr = PetscObjectTypeCompare((PetscObject)dm, DMLIBMESH,&islibmesh);
471  if(!islibmesh) SETERRQ2(((PetscObject)dm)->comm, PETSC_ERR_ARG_WRONG, "Got DM oftype %s, not of type %s", ((PetscObject)dm)->type_name, DMLIBMESH);
472  if(dnumber < 0) SETERRQ1(((PetscObject)dm)->comm, PETSC_ERR_ARG_WRONG, "Negative number %D of decomposition parts", dnumber);
473  PetscValidPointer(ddm,5);
474  DM_libMesh * dlm = (DM_libMesh *)(dm->data);
475  ierr = DMCreate(((PetscObject)dm)->comm, ddm); CHKERRQ(ierr);
476  ierr = DMSetType(*ddm, DMLIBMESH); CHKERRQ(ierr);
477  DM_libMesh * ddlm = (DM_libMesh *)((*ddm)->data);
478  ddlm->sys = dlm->sys;
479  ddlm->varids = dlm->varids;
480  ddlm->varnames = dlm->varnames;
481  ddlm->blockids = dlm->blockids;
482  ddlm->blocknames = dlm->blocknames;
483  ddlm->decomposition = new(std::vector<std::set<unsigned int> >);
484  ddlm->decomposition_type = DMLIBMESH_FIELD_DECOMPOSITION;
485  if(dnumber) {
486  for(PetscInt d = 0; d < dnumber; ++d) {
487  if(dsizes[d] < 0) SETERRQ2(((PetscObject)dm)->comm, PETSC_ERR_ARG_WRONG, "Negative size %D of decomposition part %D", dsizes[d],d);
488  ddlm->decomposition->push_back(std::set<unsigned int>());
489  for(PetscInt v = 0; v < dsizes[d]; ++v) {
490  std::string vname(dvarlists[d][v]);
491  std::map<std::string, unsigned int>::const_iterator vit = dlm->varids->find(vname);
492  if(vit == dlm->varids->end())
493  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]);
494  unsigned int vid = vit->second;
495  (*ddlm->decomposition)[d].insert(vid);
496  }
497  }
498  }
499  else { /* Empty splits indicate default: split all variables with one per split. */
500  PetscInt d = 0;
501  for(std::map<std::string, unsigned int>::const_iterator vit = ddlm->varids->begin(); vit != ddlm->varids->end(); ++vit) {
502  ddlm->decomposition->push_back(std::set<unsigned int>());
503  unsigned int vid = vit->second;
504  std::string vname = vit->first;
505  (*ddlm->decomposition)[d].insert(vid);
506  ++d;
507  }
508  }
509  ierr = DMlibMeshSetUpName_Private(*ddm); CHKERRQ(ierr);
510  ierr = DMSetFromOptions(*ddm); CHKERRQ(ierr);
511  ierr = DMSetUp(*ddm); CHKERRQ(ierr);
513 }
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 764 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().

765 {
766  PetscErrorCode ierr;
767  PetscFunctionBegin;
768  libmesh_assert(x);
769  libmesh_assert(r);
770 
772  ierr = DMlibMeshGetSystem(dm, _sys);CHKERRQ(ierr);
773  NonlinearImplicitSystem & sys = *_sys;
774  PetscVector<Number> & X_sys = *libmesh_cast_ptr<PetscVector<Number> * >(sys.solution.get());
775  PetscVector<Number> & R_sys = *libmesh_cast_ptr<PetscVector<Number> * >(sys.rhs);
776  PetscVector<Number> X_global(x, _sys->comm()), R(r, _sys->comm());
777 
778  // Use the systems update() to get a good local version of the parallel solution
779  X_global.swap(X_sys);
780  R.swap(R_sys);
781 
783  _sys->update();
784 
785  // Swap back
786  X_global.swap(X_sys);
787  R.swap(R_sys);
788  R.zero();
789 
790  // if the user has provided both function pointers and objects only the pointer
791  // will be used, so catch that as an error
792  if (_sys->nonlinear_solver->residual && _sys->nonlinear_solver->residual_object)
793  libmesh_error_msg("ERROR: cannot specifiy both a function and object to compute the Residual!");
794 
795  if (_sys->nonlinear_solver->matvec && _sys->nonlinear_solver->residual_and_jacobian_object)
796  libmesh_error_msg("ERROR: cannot specifiy both a function and object to compute the combined Residual & Jacobian!");
797 
798  if (_sys->nonlinear_solver->residual != libmesh_nullptr)
799  _sys->nonlinear_solver->residual(*(_sys->current_local_solution.get()), R, *_sys);
800 
801  else if (_sys->nonlinear_solver->residual_object != libmesh_nullptr)
802  _sys->nonlinear_solver->residual_object->residual(*(_sys->current_local_solution.get()), R, *_sys);
803 
804  else if (_sys->nonlinear_solver->matvec != libmesh_nullptr)
805  _sys->nonlinear_solver->matvec(*(_sys->current_local_solution.get()), &R, libmesh_nullptr, *_sys);
806 
807  else if (_sys->nonlinear_solver->residual_and_jacobian_object != libmesh_nullptr)
808  _sys->nonlinear_solver->residual_and_jacobian_object->residual_and_jacobian(*(_sys->current_local_solution.get()), &R, libmesh_nullptr, *_sys);
809 
810  else
811  libmesh_error_msg("Error! Unable to compute residual and/or Jacobian!");
812 
813  R.close();
814  X_global.close();
816 }
NumericVector interface to PETSc Vec.
Definition: petsc_vector.h:64
ImplicitSystem & sys
UniquePtr< NumericVector< Number > > current_local_solution
Definition: system.h:1524
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:2019
Used for solving nonlinear implicit systems of equations.
UniquePtr< NumericVector< Number > > solution
Definition: system.h:1512
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 151 of file petscdmlibmeshimpl.C.

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

152 {
153  PetscErrorCode ierr;
154  PetscInt i;
155  PetscFunctionBegin;
156  PetscValidHeaderSpecific(dm,DM_CLASSID,1);
157  PetscBool islibmesh;
158  ierr = PetscObjectTypeCompare((PetscObject)dm, DMLIBMESH,&islibmesh);
159  if(!islibmesh) SETERRQ2(((PetscObject)dm)->comm, PETSC_ERR_ARG_WRONG, "Got DM oftype %s, not of type %s", ((PetscObject)dm)->type_name, DMLIBMESH);
160  DM_libMesh * dlm = (DM_libMesh *)(dm->data);
161  PetscValidPointer(n,2);
162  *n = dlm->blockids->size();
163  if(!blocknames) PetscFunctionReturn(0);
164  ierr = PetscMalloc(*n*sizeof(char *), blocknames); CHKERRQ(ierr);
165  i = 0;
166  for(std::map<std::string, unsigned int>::const_iterator it = dlm->blockids->begin(); it != dlm->blockids->end(); ++it){
167  ierr = PetscStrallocpy(it->first.c_str(), *blocknames+i); CHKERRQ(ierr);
168  ++i;
169  }
171 }
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 134 of file petscdmlibmeshimpl.C.

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

Referenced by DMCreate_libMesh().

135 {
136  PetscErrorCode ierr;
137 
138  PetscFunctionBegin;
139  PetscValidHeaderSpecific(dm,DM_CLASSID,1);
140  PetscBool islibmesh;
141  ierr = PetscObjectTypeCompare((PetscObject)dm, DMLIBMESH,&islibmesh);CHKERRQ(ierr);
142  if(!islibmesh) SETERRQ2(((PetscObject)dm)->comm, PETSC_ERR_ARG_WRONG, "Got DM oftype %s, not of type %s", ((PetscObject)dm)->type_name, DMLIBMESH);
143  DM_libMesh * dlm = (DM_libMesh *)(dm->data);
144  sys = dlm->sys;
146 }
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 175 of file petscdmlibmeshimpl.C.

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

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

References DMlibMeshSetUpName_Private(), and PetscFunctionReturn().

59 {
60  PetscFunctionBegin;
61 
63 }
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 834 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().

841 {
842  PetscErrorCode ierr;
843  PetscFunctionBegin;
845  ierr = DMlibMeshGetSystem(dm, _sys); CHKERRQ(ierr);
846  NonlinearImplicitSystem & sys = *_sys;
847 
848  PetscMatrix<Number> the_pc(pc,sys.comm());
849  PetscMatrix<Number> Jac(jac,sys.comm());
850  PetscVector<Number> & X_sys = *libmesh_cast_ptr<PetscVector<Number> *>(sys.solution.get());
851  PetscMatrix<Number> & Jac_sys = *libmesh_cast_ptr<PetscMatrix<Number> *>(sys.matrix);
852  PetscVector<Number> X_global(x, sys.comm());
853 
854  // Set the dof maps
855  the_pc.attach_dof_map(sys.get_dof_map());
856  Jac.attach_dof_map(sys.get_dof_map());
857 
858  // Use the systems update() to get a good local version of the parallel solution
859  X_global.swap(X_sys);
860  Jac.swap(Jac_sys);
861 
863  sys.update();
864 
865  X_global.swap(X_sys);
866  Jac.swap(Jac_sys);
867 
868  the_pc.zero();
869 
870  // if the user has provided both function pointers and objects only the pointer
871  // will be used, so catch that as an error
872  if (sys.nonlinear_solver->jacobian && sys.nonlinear_solver->jacobian_object)
873  libmesh_error_msg("ERROR: cannot specifiy both a function and object to compute the Jacobian!");
874 
875  if (sys.nonlinear_solver->matvec && sys.nonlinear_solver->residual_and_jacobian_object)
876  libmesh_error_msg("ERROR: cannot specifiy both a function and object to compute the combined Residual & Jacobian!");
877 
878  if (sys.nonlinear_solver->jacobian != libmesh_nullptr)
879  sys.nonlinear_solver->jacobian(*(sys.current_local_solution.get()), the_pc, sys);
880 
881  else if (sys.nonlinear_solver->jacobian_object != libmesh_nullptr)
882  sys.nonlinear_solver->jacobian_object->jacobian(*(sys.current_local_solution.get()), the_pc, sys);
883 
884  else if (sys.nonlinear_solver->matvec != libmesh_nullptr)
885  sys.nonlinear_solver->matvec(*(sys.current_local_solution.get()), libmesh_nullptr, &the_pc, sys);
886 
887  else if (sys.nonlinear_solver->residual_and_jacobian_object != libmesh_nullptr)
888  sys.nonlinear_solver->residual_and_jacobian_object->residual_and_jacobian(*(sys.current_local_solution.get()), libmesh_nullptr, &the_pc, sys);
889 
890  else
891  libmesh_error_msg("Error! Unable to compute residual and/or Jacobian!");
892 
893  the_pc.close();
894  Jac.close();
895  X_global.close();
896 #if PETSC_RELEASE_LESS_THAN(3,5,0)
897  *msflag = SAME_NONZERO_PATTERN;
898 #endif
900 }
NumericVector interface to PETSc Vec.
Definition: petsc_vector.h:64
ImplicitSystem & sys
UniquePtr< NumericVector< Number > > current_local_solution
Definition: system.h:1524
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:2019
Used for solving nonlinear implicit systems of equations.
UniquePtr< NumericVector< Number > > solution
Definition: system.h:1512
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 579 of file petscdmlibmeshimpl.C.

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

Referenced by DMCreateDomainDecompositionDM_libMesh(), and DMCreateFieldDecompositionDM_libMesh().

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

72 {
73  const Parallel::Communicator & comm = sys.comm();
74 
75  PetscErrorCode ierr;
76  PetscFunctionBegin;
77  PetscValidHeaderSpecific(dm,DM_CLASSID,1);
78  PetscBool islibmesh;
79  ierr = PetscObjectTypeCompare((PetscObject)dm, DMLIBMESH,&islibmesh);
80  if(!islibmesh) SETERRQ2(((PetscObject)dm)->comm, PETSC_ERR_ARG_WRONG, "Got DM oftype %s, not of type %s", ((PetscObject)dm)->type_name, DMLIBMESH);
81 
82  if(dm->setupcalled) SETERRQ(((PetscObject)dm)->comm, PETSC_ERR_ARG_WRONGSTATE, "Cannot reset the libMesh system after DM has been set up.");
83  DM_libMesh * dlm = (DM_libMesh *)(dm->data);
84  dlm->sys =&sys;
85  /* Initially populate the sets of active blockids and varids using all of the
86  existing blocks/variables (only variables are supported at the moment). */
87  DofMap & dofmap = dlm->sys->get_dof_map();
88  dlm->varids->clear();
89  dlm->varnames->clear();
90  for(unsigned int v = 0; v < dofmap.n_variables(); ++v) {
91  std::string vname = dofmap.variable(v).name();
92  dlm->varids->insert(std::pair<std::string,unsigned int>(vname,v));
93  dlm->varnames->insert(std::pair<unsigned int,std::string>(v,vname));
94  }
95  const MeshBase & mesh = dlm->sys->get_mesh();
96  dlm->blockids->clear();
97  dlm->blocknames->clear();
98  std::set<subdomain_id_type> blocks;
99  /* The following effectively is a verbatim copy of MeshBase::n_subdomains(). */
100  // This requires an inspection on every processor
101  libmesh_parallel_only(mesh.comm());
104  for (; el!=end; ++el)
105  blocks.insert((*el)->subdomain_id());
106  // Some subdomains may only live on other processors
107  comm.set_union(blocks);
108 
109  std::set<subdomain_id_type>::iterator bit = blocks.begin();
110  std::set<subdomain_id_type>::iterator bend = blocks.end();
111  if(bit == bend) SETERRQ(((PetscObject)dm)->comm, PETSC_ERR_PLIB, "No mesh blocks found.");
112 
113  for(; bit != bend; ++bit) {
114  subdomain_id_type bid = *bit;
115  std::string bname = mesh.subdomain_name(bid);
116  if(!bname.length()) {
117  /* Block names are currently implemented for Exodus II meshes
118  only, so we might have to make up our own block names and
119  maintain our own mapping of block ids to names.
120  */
121  std::ostringstream ss;
122  ss << "dm" << bid;
123  bname = ss.str();
124  }
125  dlm->blockids->insert(std::pair<std::string,unsigned int>(bname,bid));
126  dlm->blocknames->insert(std::pair<unsigned int,std::string>(bid,bname));
127  }
128  ierr = DMlibMeshSetUpName_Private(dm); CHKERRQ(ierr);
130 }
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:1638
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:2003
const DofMap & get_dof_map() const
Definition: system.h:2019
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:573
virtual element_iterator active_elements_begin()=0
virtual element_iterator active_elements_end()=0
unsigned int n_variables() const
Definition: dof_map.h:473
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 199 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().

200 {
201  DM_libMesh * dlm = (DM_libMesh *)dm->data;
202  PetscErrorCode ierr;
203  PetscFunctionBegin;
204  std::string name = dlm->sys->name();
205  std::map<unsigned int, std::string> * dnames = PETSC_NULL, * enames = PETSC_NULL;
206  if(dlm->decomposition_type == DMLIBMESH_FIELD_DECOMPOSITION) {
207  name += ":dec:var:";
208  dnames = dlm->varnames;
209  }
210  if(dlm->decomposition_type == DMLIBMESH_DOMAIN_DECOMPOSITION) {
211  name += ":dec:block:";
212  dnames = dlm->blocknames;
213  }
214  if(dnames) {
215  for(unsigned int d = 0; d < dlm->decomposition->size(); ++d) {
216  for(std::set<unsigned int>::iterator dit = (*dlm->decomposition)[d].begin(); dit != (*dlm->decomposition)[d].end(); ++dit) {
217  unsigned int id = *dit;
218  if(dit != (*dlm->decomposition)[d].begin())
219  name += ",";
220  name += (*dnames)[id];
221  }
222  name += ";";
223  }
224  }
225  if(dlm->embedding_type == DMLIBMESH_FIELD_EMBEDDING) {
226  name += ":emb:var:";
227  enames = dlm->varnames;
228  }
229  if(dlm->embedding_type == DMLIBMESH_DOMAIN_EMBEDDING) {
230  name += ":emb:block:";
231  enames = dlm->blocknames;
232  }
233  if(enames) {
234  for(std::map<unsigned int, std::string>::iterator eit = enames->begin(); eit != enames->end(); ++eit) {
235  std::string ename = eit->second;
236  if(eit != enames->begin())
237  name += ",";
238  name += ename;
239  }
240  name += ";";
241  }
242  ierr = PetscObjectSetName((PetscObject)dm, name.c_str()); CHKERRQ(ierr);
244 }
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:1987
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 1083 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().

1084 {
1085  PetscFunctionBegin;
1086  PetscErrorCode ierr;
1087  DM_libMesh * dlm = (DM_libMesh *)(dm->data);
1088  PetscBool eq;
1089 
1090  ierr = PetscObjectTypeCompare((PetscObject)dm, DMLIBMESH, &eq); CHKERRQ(ierr);
1091 
1092  if (!eq)
1093  SETERRQ2(((PetscObject)dm)->comm, PETSC_ERR_ARG_WRONG, "DM of type %s, not of type %s", ((PetscObject)dm)->type, DMLIBMESH);
1094 
1095  if (!dlm->sys)
1096  SETERRQ(PETSC_COMM_WORLD, PETSC_ERR_ARG_WRONGSTATE, "No libMesh system set for DM_libMesh");
1097  /*
1098  Do not evaluate function, Jacobian or bounds for an embedded DM -- the subproblem might not have enough information for that.
1099  */
1100  if(!dlm->embedding) {
1101 #if PETSC_RELEASE_LESS_THAN(3,3,1)
1102  ierr = DMSetFunction(dm, DMlibMeshFunction); CHKERRQ(ierr);
1103  ierr = DMSetJacobian(dm, DMlibMeshJacobian); CHKERRQ(ierr);
1104 #else
1105  ierr = DMSNESSetFunction(dm, SNESFunction_DMlibMesh, (void *)dm); CHKERRQ(ierr);
1106  ierr = DMSNESSetJacobian(dm, SNESJacobian_DMlibMesh, (void *)dm); CHKERRQ(ierr);
1107 #endif
1108  if (dlm->sys->nonlinear_solver->bounds || dlm->sys->nonlinear_solver->bounds_object)
1109  ierr = DMSetVariableBounds(dm, DMVariableBounds_libMesh); CHKERRQ(ierr);
1110  }
1111  else {
1112  /*
1113  Fow now we don't implement even these, although a linear "Dirichlet" subproblem is well-defined.
1114  Creating the submatrix, however, might require extracting the submatrix preallocation from an unassembled matrix.
1115  */
1116  dm->ops->createglobalvector = 0;
1117  dm->ops->creatematrix = 0;
1118  }
1120 }
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 927 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().

928 {
929  PetscErrorCode ierr;
931  ierr = DMlibMeshGetSystem(dm, _sys); CHKERRQ(ierr);
932  NonlinearImplicitSystem & sys = *_sys;
933  PetscVector<Number> XL(xl, sys.comm());
934  PetscVector<Number> XU(xu, sys.comm());
935  PetscFunctionBegin;
936 #if PETSC_VERSION_LESS_THAN(3,5,0) && PETSC_VERSION_RELEASE
937  ierr = VecSet(xl, SNES_VI_NINF);CHKERRQ(ierr);
938  ierr = VecSet(xu, SNES_VI_INF);CHKERRQ(ierr);
939 #else
940  ierr = VecSet(xl, PETSC_NINFINITY);CHKERRQ(ierr);
941  ierr = VecSet(xu, PETSC_INFINITY);CHKERRQ(ierr);
942 #endif
943  if (sys.nonlinear_solver->bounds != libmesh_nullptr)
944  sys.nonlinear_solver->bounds(XL,XU,sys);
945  else if (sys.nonlinear_solver->bounds_object != libmesh_nullptr)
946  sys.nonlinear_solver->bounds_object->bounds(XL,XU, sys);
947  else
948  SETERRQ(((PetscObject)dm)->comm, PETSC_ERR_ARG_WRONG, "No bounds calculation in this libMesh object");
949 
951 }
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 1024 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().

1025 {
1026  PetscErrorCode ierr;
1027  PetscBool isascii;
1028  const char * name, * prefix;
1029  DM_libMesh * dlm = (DM_libMesh *)dm->data;
1030  PetscFunctionBegin;
1031  ierr = PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERASCII,&isascii); CHKERRQ(ierr);
1032  if(isascii) {
1033  ierr = PetscObjectGetName((PetscObject)dm, &name); CHKERRQ(ierr);
1034  ierr = PetscObjectGetOptionsPrefix((PetscObject)dm, &prefix); CHKERRQ(ierr);
1035  ierr = PetscViewerASCIIPrintf(viewer, "DM libMesh with name %s and prefix %s\n", name, prefix); CHKERRQ(ierr);
1036  ierr = PetscViewerASCIIPrintf(viewer, "blocks:", name, prefix); CHKERRQ(ierr);
1037  std::map<std::string,unsigned int>::iterator bit = dlm->blockids->begin();
1038  std::map<std::string,unsigned int>::const_iterator bend = dlm->blockids->end();
1039  for(; bit != bend; ++bit) {
1040  ierr = PetscViewerASCIIPrintf(viewer, "(%s,%D) ", bit->first.c_str(), bit->second); CHKERRQ(ierr);
1041  }
1042  ierr = PetscViewerASCIIPrintf(viewer, "\n"); CHKERRQ(ierr);
1043  ierr = PetscViewerASCIIPrintf(viewer, "variables:", name, prefix); CHKERRQ(ierr);
1044  std::map<std::string,unsigned int>::iterator vit = dlm->varids->begin();
1045  std::map<std::string,unsigned int>::const_iterator vend = dlm->varids->end();
1046  for(; vit != vend; ++vit) {
1047  ierr = PetscViewerASCIIPrintf(viewer, "(%s,%D) ", vit->first.c_str(), vit->second); CHKERRQ(ierr);
1048  }
1049  ierr = PetscViewerASCIIPrintf(viewer, "\n"); CHKERRQ(ierr);
1050  if(dlm->decomposition_type == DMLIBMESH_NO_DECOMPOSITION) {
1051  ierr = PetscViewerASCIIPrintf(viewer, "No decomposition\n"); CHKERRQ(ierr);
1052  }
1053  else {
1054  if(dlm->decomposition_type == DMLIBMESH_FIELD_DECOMPOSITION) {
1055  ierr = PetscViewerASCIIPrintf(viewer, "Field decomposition by variable: "); CHKERRQ(ierr);
1056  }
1057  else if(dlm->decomposition_type == DMLIBMESH_DOMAIN_DECOMPOSITION) {
1058  ierr = PetscViewerASCIIPrintf(viewer, "Domain decomposition by block: "); CHKERRQ(ierr);
1059  }
1060  else SETERRQ1(((PetscObject)dm)->comm, PETSC_ERR_PLIB, "Unexpected decomposition type: %D", dlm->decomposition_type);
1061  /* FIX: decompositions might have different sizes and components on different ranks. */
1062  for(unsigned int d = 0; d < dlm->decomposition->size(); ++d) {
1063  std::set<unsigned int>::iterator dbegin = (*dlm->decomposition)[d].begin();
1064  std::set<unsigned int>::iterator dit = (*dlm->decomposition)[d].begin();
1065  std::set<unsigned int>::iterator dend = (*dlm->decomposition)[d].end();
1066  for(; dit != dend; ++dit) {
1067  if(dit != dbegin) {
1068  ierr = PetscViewerASCIIPrintf(viewer, ","); CHKERRQ(ierr);
1069  }
1070  ierr = PetscViewerASCIIPrintf(viewer, "%D", *dit); CHKERRQ(ierr);
1071  }
1072  ierr = PetscViewerASCIIPrintf(viewer, ";"); CHKERRQ(ierr);
1073  }
1074  ierr = PetscViewerASCIIPrintf(viewer, "\n"); CHKERRQ(ierr);
1075  }
1076  }
1077 
1079 }
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 821 of file petscdmlibmeshimpl.C.

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

Referenced by DMSetUp_libMesh().

822 {
823  DM dm = (DM)ctx;
824  PetscErrorCode ierr;
825  PetscFunctionBegin;
826  ierr = DMlibMeshFunction(dm,x,r);CHKERRQ(ierr);
828 }
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 905 of file petscdmlibmeshimpl.C.

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

Referenced by DMSetUp_libMesh().

912 {
913  DM dm = (DM)ctx;
914  PetscErrorCode ierr;
915  PetscFunctionBegin;
916 #if PETSC_RELEASE_LESS_THAN(3,5,0)
917  ierr = DMlibMeshJacobian(dm,x,*jac,*pc,flag); CHKERRQ(ierr);
918 #else
919  ierr = DMlibMeshJacobian(dm,x,jac,pc); CHKERRQ(ierr);
920 #endif
922 }
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 1014 of file petscdmlibmeshimpl.C.

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

Definition at line 1004 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::SlepcEigenSolver< T >::init(), libMesh::PetscPreconditioner< 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