www.mooseframework.org
Functions
PetscDMMoose.h File Reference

Go to the source code of this file.

Functions

PetscErrorCode DMMooseRegisterAll ()
 
PetscErrorCode DMCreateMoose (MPI_Comm, NonlinearSystemBase &, DM *)
 
PetscErrorCode DMMooseReset (DM)
 
PetscErrorCode DMMooseSetNonlinearSystem (DM, NonlinearSystemBase &)
 
PetscErrorCode DMMooseGetNonlinearSystem (DM, NonlinearSystemBase *&)
 
PetscErrorCode DMMooseGetBlocks (DM, std::vector< std::string > &)
 
PetscErrorCode DMMooseGetVariables (DM, std::vector< std::string > &)
 
PetscErrorCode DMMooseGetSides (DM, std::set< std::string > &)
 
PetscErrorCode DMMooseGetUnSides (DM, std::set< std::string > &)
 
PetscErrorCode DMMooseGetContacts (DM, std::vector< std::pair< std::string, std::string >> &, std::vector< bool > &)
 
PetscErrorCode DMMooseGetUnContacts (DM, std::vector< std::pair< std::string, std::string >> &, std::vector< bool > &)
 
PetscErrorCode DMMooseSetBlocks (DM, const std::vector< std::string > &)
 
PetscErrorCode DMMooseSetVariables (DM, const std::vector< std::string > &)
 
PetscErrorCode DMMooseSetSides (DM, const std::set< std::string > &)
 
PetscErrorCode DMMooseSetUnSides (DM, const std::set< std::string > &)
 
PetscErrorCode DMMooseSetContacts (DM, const std::vector< std::pair< std::string, std::string >> &, const std::vector< bool > &)
 
PetscErrorCode DMMooseSetUnContacts (DM, const std::vector< std::pair< std::string, std::string >> &, const std::vector< bool > &)
 
PetscErrorCode DMMooseSetSplitNames (DM, const std::vector< std::string > &)
 
PetscErrorCode DMMooseGetSplitNames (DM, const std::vector< std::string > &)
 
PetscErrorCode DMMooseSetSplitVars (DM, const std::string &, const std::set< std::string > &)
 
PetscErrorCode DMMooseGetSplitVars (DM, const std::string &, std::set< std::string > &)
 
PetscErrorCode DMMooseSetSplitBlocks (DM, const std::string &, const std::set< std::string > &)
 
PetscErrorCode DMMooseGetSplitBlocks (DM, const std::string &, std::set< std::string > &)
 
PetscErrorCode DMMooseSetSplitSides (DM, const std::string &, const std::set< std::string > &)
 
PetscErrorCode DMMooseGetSplitSides (DM, const std::string &, std::set< std::string > &)
 
PetscErrorCode SNESUpdateDMMoose (SNES snes, PetscInt iteration)
 

Function Documentation

PetscErrorCode DMCreateMoose ( MPI_Comm  ,
NonlinearSystemBase ,
DM *   
)

Definition at line 2477 of file PetscDMMoose.C.

Referenced by DMCreateFieldDecomposition_Moose(), and Moose::PetscSupport::petscSetupDM().

2478 {
2479  PetscErrorCode ierr;
2480 
2482  ierr = DMCreate(comm, dm);
2483  CHKERRQ(ierr);
2484  ierr = DMSetType(*dm, DMMOOSE);
2485  CHKERRQ(ierr);
2486  ierr = DMMooseSetNonlinearSystem(*dm, nl);
2487  CHKERRQ(ierr);
2489 }
PetscFunctionBegin
PetscErrorCode DMMooseSetNonlinearSystem(DM dm, NonlinearSystemBase &nl)
Definition: PetscDMMoose.C:250
NonlinearSystemBase * nl
PetscFunctionReturn(0)
CHKERRQ(ierr)
MPI_Comm comm
ierr
PetscErrorCode DMMooseGetBlocks ( DM  ,
std::vector< std::string > &   
)

Definition at line 202 of file PetscDMMoose.C.

203 {
204  PetscErrorCode ierr;
205  PetscBool ismoose;
206 
208  PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
209  ierr = PetscObjectTypeCompare((PetscObject)dm, DMMOOSE, &ismoose);
210  CHKERRQ(ierr);
211  if (!ismoose)
212  SETERRQ2(((PetscObject)dm)->comm,
213  PETSC_ERR_ARG_WRONG,
214  "Got DM oftype %s, not of type %s",
215  ((PetscObject)dm)->type_name,
216  DMMOOSE);
217  DM_Moose * dmm = (DM_Moose *)dm->data;
218  for (const auto & it : *(dmm->_block_ids))
219  block_names.push_back(it.first);
221 }
DM_Moose * dmm
PetscBool ismoose
PetscFunctionBegin
PetscFunctionReturn(0)
CHKERRQ(ierr)
MPI_Comm comm
std::map< std::string, subdomain_id_type > * _block_ids
Definition: PetscDMMoose.C:56
ierr
PetscErrorCode DMMooseGetContacts ( DM  ,
std::vector< std::pair< std::string, std::string >> &  ,
std::vector< bool > &   
)
PetscErrorCode DMMooseGetNonlinearSystem ( DM  ,
NonlinearSystemBase *&   
)

Definition at line 467 of file PetscDMMoose.C.

Referenced by DMMooseFunction(), and DMVariableBounds_Moose().

468 {
469  PetscErrorCode ierr;
470  PetscBool ismoose;
471 
473  PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
474  ierr = PetscObjectTypeCompare((PetscObject)dm, DMMOOSE, &ismoose);
475  CHKERRQ(ierr);
476  if (!ismoose)
477  SETERRQ2(((PetscObject)dm)->comm,
478  PETSC_ERR_ARG_WRONG,
479  "Got DM oftype %s, not of type %s",
480  ((PetscObject)dm)->type_name,
481  DMMOOSE);
482  DM_Moose * dmm = (DM_Moose *)(dm->data);
483  nl = dmm->_nl;
485 }
DM_Moose * dmm
PetscBool ismoose
PetscFunctionBegin
NonlinearSystemBase * nl
PetscFunctionReturn(0)
CHKERRQ(ierr)
NonlinearSystemBase * _nl
Definition: PetscDMMoose.C:50
MPI_Comm comm
ierr
PetscErrorCode DMMooseGetSides ( DM  ,
std::set< std::string > &   
)
PetscErrorCode DMMooseGetSplitBlocks ( DM  ,
const std::string &  ,
std::set< std::string > &   
)
PetscErrorCode DMMooseGetSplitNames ( DM  ,
const std::vector< std::string > &   
)
PetscErrorCode DMMooseGetSplitSides ( DM  ,
const std::string &  ,
std::set< std::string > &   
)
PetscErrorCode DMMooseGetSplitVars ( DM  ,
const std::string &  ,
std::set< std::string > &   
)
PetscErrorCode DMMooseGetUnContacts ( DM  ,
std::vector< std::pair< std::string, std::string >> &  ,
std::vector< bool > &   
)
PetscErrorCode DMMooseGetUnSides ( DM  ,
std::set< std::string > &   
)
PetscErrorCode DMMooseGetVariables ( DM  ,
std::vector< std::string > &   
)

Definition at line 226 of file PetscDMMoose.C.

227 {
228  PetscErrorCode ierr;
229  PetscBool ismoose;
230 
232  PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
233  ierr = PetscObjectTypeCompare((PetscObject)dm, DMMOOSE, &ismoose);
234  CHKERRQ(ierr);
235  if (!ismoose)
236  SETERRQ2(((PetscObject)dm)->comm,
237  PETSC_ERR_ARG_WRONG,
238  "Got DM oftype %s, not of type %s",
239  ((PetscObject)dm)->type_name,
240  DMMOOSE);
241  DM_Moose * dmm = (DM_Moose *)(dm->data);
242  for (const auto & it : *(dmm->_var_ids))
243  var_names.push_back(it.first);
245 }
DM_Moose * dmm
PetscBool ismoose
PetscFunctionBegin
std::map< std::string, unsigned int > * _var_ids
Definition: PetscDMMoose.C:52
PetscFunctionReturn(0)
CHKERRQ(ierr)
MPI_Comm comm
ierr
PetscErrorCode DMMooseRegisterAll ( )

Definition at line 2611 of file PetscDMMoose.C.

Referenced by Moose::PetscSupport::petscSetupDM().

2612 {
2613  static PetscBool DMMooseRegisterAllCalled = PETSC_FALSE;
2614  PetscErrorCode ierr;
2615 
2617  if (!DMMooseRegisterAllCalled)
2618  {
2619 #if PETSC_VERSION_LESS_THAN(3, 4, 0)
2620  ierr = DMRegister(DMMOOSE, PETSC_NULL, "DMCreate_Moose", DMCreate_Moose);
2621  CHKERRQ(ierr);
2622 #else
2623  ierr = DMRegister(DMMOOSE, DMCreate_Moose);
2624  CHKERRQ(ierr);
2625 #endif
2626  DMMooseRegisterAllCalled = PETSC_TRUE;
2627  }
2629 }
PetscFunctionBegin
PetscFunctionReturn(0)
CHKERRQ(ierr)
PetscErrorCode DMCreate_Moose(DM dm)
ierr
PetscErrorCode DMMooseReset ( DM  )

Definition at line 1958 of file PetscDMMoose.C.

Referenced by SNESUpdateDMMoose().

1959 {
1960  PetscErrorCode ierr;
1961  DM_Moose * dmm = (DM_Moose *)(dm->data);
1962  PetscBool ismoose;
1963 
1965  ierr = PetscObjectTypeCompare((PetscObject)dm, DMMOOSE, &ismoose);
1966  CHKERRQ(ierr);
1967  if (!ismoose)
1969  if (!dmm->_nl)
1970  SETERRQ(PETSC_COMM_WORLD, PETSC_ERR_ARG_WRONGSTATE, "No Moose system set for DM_Moose");
1971  ierr = ISDestroy(&dmm->_embedding);
1972  CHKERRQ(ierr);
1973  for (auto & it : *(dmm->_splits))
1974  {
1975  DM_Moose::SplitInfo & split = it.second;
1976  ierr = ISDestroy(&split._rembedding);
1977  CHKERRQ(ierr);
1978  if (split._dm)
1979  {
1980  ierr = DMMooseReset(split._dm);
1981  CHKERRQ(ierr);
1982  }
1983  }
1984  dm->setupcalled = PETSC_FALSE;
1986 }
DM_Moose * dmm
PetscBool ismoose
PetscFunctionBegin
PetscErrorCode DMMooseReset(DM dm)
PETSC_ERR_ARG_WRONGSTATE
IS _embedding
Definition: PetscDMMoose.C:89
std::map< std::string, SplitInfo > * _splits
Definition: PetscDMMoose.C:88
PetscFunctionReturn(0)
CHKERRQ(ierr)
NonlinearSystemBase * _nl
Definition: PetscDMMoose.C:50
ierr
PetscErrorCode DMMooseSetBlocks ( DM  ,
const std::vector< std::string > &   
)
PetscErrorCode DMMooseSetContacts ( DM  ,
const std::vector< std::pair< std::string, std::string >> &  ,
const std::vector< bool > &   
)
PetscErrorCode DMMooseSetNonlinearSystem ( DM  ,
NonlinearSystemBase  
)

Definition at line 250 of file PetscDMMoose.C.

Referenced by DMCreateMoose().

251 {
252  PetscErrorCode ierr;
253  PetscBool ismoose;
254 
256  PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
257  ierr = PetscObjectTypeCompare((PetscObject)dm, DMMOOSE, &ismoose);
258  CHKERRQ(ierr);
259  if (!ismoose)
260  SETERRQ2(((PetscObject)dm)->comm,
261  PETSC_ERR_ARG_WRONG,
262  "Got DM oftype %s, not of type %s",
263  ((PetscObject)dm)->type_name,
264  DMMOOSE);
265  if (dm->setupcalled)
266  SETERRQ(((PetscObject)dm)->comm,
268  "Cannot reset the NonlinearSystem after DM has been set up.");
269  DM_Moose * dmm = (DM_Moose *)(dm->data);
270  dmm->_nl = &nl;
272 }
DM_Moose * dmm
PetscBool ismoose
PetscFunctionBegin
PETSC_ERR_ARG_WRONGSTATE
NonlinearSystemBase * nl
PetscFunctionReturn(0)
CHKERRQ(ierr)
NonlinearSystemBase * _nl
Definition: PetscDMMoose.C:50
MPI_Comm comm
ierr
PetscErrorCode DMMooseSetSides ( DM  ,
const std::set< std::string > &   
)

Definition at line 331 of file PetscDMMoose.C.

Referenced by DMSetFromOptions_Moose().

332 {
333  PetscErrorCode ierr;
334  DM_Moose * dmm = (DM_Moose *)dm->data;
335  PetscBool ismoose;
336 
338  PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
339  ierr = PetscObjectTypeCompare((PetscObject)dm, DMMOOSE, &ismoose);
340  CHKERRQ(ierr);
341  if (!ismoose)
342  SETERRQ2(PETSC_COMM_SELF,
343  PETSC_ERR_ARG_WRONG,
344  "Got DM oftype %s, not of type %s",
345  ((PetscObject)dm)->type_name,
346  DMMOOSE);
347  if (dm->setupcalled)
348  SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_WRONGSTATE, "Not for an already setup DM");
349  if (dmm->_sides)
350  delete dmm->_sides;
351  dmm->_sides = new std::set<std::string>(sides);
353 }
DM_Moose * dmm
PetscBool ismoose
PetscFunctionBegin
PETSC_ERR_ARG_WRONGSTATE
std::set< std::string > * _sides
Definition: PetscDMMoose.C:59
PetscFunctionReturn(0)
CHKERRQ(ierr)
ierr
PetscErrorCode DMMooseSetSplitBlocks ( DM  ,
const std::string &  ,
const std::set< std::string > &   
)
PetscErrorCode DMMooseSetSplitNames ( DM  ,
const std::vector< std::string > &   
)

Definition at line 490 of file PetscDMMoose.C.

Referenced by DMSetFromOptions_Moose().

491 {
492  PetscErrorCode ierr;
493  PetscBool ismoose;
494 
496  PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
497  ierr = PetscObjectTypeCompare((PetscObject)dm, DMMOOSE, &ismoose);
498  CHKERRQ(ierr);
499  if (!ismoose)
500  SETERRQ2(((PetscObject)dm)->comm,
501  PETSC_ERR_ARG_WRONG,
502  "Got DM oftype %s, not of type %s",
503  ((PetscObject)dm)->type_name,
504  DMMOOSE);
505  DM_Moose * dmm = (DM_Moose *)(dm->data);
506 
507  if (dmm->_splits)
508  {
509  for (auto & it : *(dmm->_splits))
510  {
511  ierr = DMDestroy(&(it.second._dm));
512  CHKERRQ(ierr);
513  ierr = ISDestroy(&(it.second._rembedding));
514  CHKERRQ(ierr);
515  }
516  delete dmm->_splits;
517  dmm->_splits = PETSC_NULL;
518  }
519  if (dmm->_splitlocs)
520  {
521  delete dmm->_splitlocs;
522  dmm->_splitlocs = PETSC_NULL;
523  }
524  dmm->_splits = new std::map<std::string, DM_Moose::SplitInfo>();
525  dmm->_splitlocs = new std::multimap<std::string, unsigned int>();
526  for (unsigned int i = 0; i < split_names.size(); ++i)
527  {
528  DM_Moose::SplitInfo info;
529  info._dm = PETSC_NULL;
530  info._rembedding = PETSC_NULL;
531  std::string name = split_names[i];
532  (*dmm->_splits)[name] = info;
533  dmm->_splitlocs->insert(std::make_pair(name, i));
534  }
536 }
DM_Moose * dmm
PetscBool ismoose
PetscFunctionBegin
std::map< std::string, SplitInfo > * _splits
Definition: PetscDMMoose.C:88
PetscFunctionReturn(0)
CHKERRQ(ierr)
MPI_Comm comm
ierr
std::multimap< std::string, unsigned int > * _splitlocs
Definition: PetscDMMoose.C:82
PetscErrorCode DMMooseSetSplitSides ( DM  ,
const std::string &  ,
const std::set< std::string > &   
)
PetscErrorCode DMMooseSetSplitVars ( DM  ,
const std::string &  ,
const std::set< std::string > &   
)
PetscErrorCode DMMooseSetUnContacts ( DM  ,
const std::vector< std::pair< std::string, std::string >> &  ,
const std::vector< bool > &   
)
PetscErrorCode DMMooseSetUnSides ( DM  ,
const std::set< std::string > &   
)

Definition at line 358 of file PetscDMMoose.C.

Referenced by DMSetFromOptions_Moose().

359 {
360  PetscErrorCode ierr;
361  DM_Moose * dmm = (DM_Moose *)dm->data;
362  PetscBool ismoose;
363 
365  PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
366  ierr = PetscObjectTypeCompare((PetscObject)dm, DMMOOSE, &ismoose);
367  CHKERRQ(ierr);
368  if (!ismoose)
369  SETERRQ2(PETSC_COMM_SELF,
370  PETSC_ERR_ARG_WRONG,
371  "Got DM oftype %s, not of type %s",
372  ((PetscObject)dm)->type_name,
373  DMMOOSE);
374  if (dm->setupcalled)
375  SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_WRONGSTATE, "Not for an already setup DM");
376  if (dmm->_sides)
377  delete dmm->_sides;
378  dmm->_unsides = new std::set<std::string>(unsides);
380 }
DM_Moose * dmm
PetscBool ismoose
PetscFunctionBegin
PETSC_ERR_ARG_WRONGSTATE
std::set< std::string > * _sides
Definition: PetscDMMoose.C:59
PetscFunctionReturn(0)
CHKERRQ(ierr)
std::set< std::string > * _unsides
Definition: PetscDMMoose.C:62
ierr
PetscErrorCode DMMooseSetVariables ( DM  ,
const std::vector< std::string > &   
)
PetscErrorCode SNESUpdateDMMoose ( SNES  snes,
PetscInt  iteration 
)

Definition at line 2557 of file PetscDMMoose.C.

2558 {
2559  /* This is called any time the structure of the problem changes in a way that affects the Jacobian
2560  sparsity pattern.
2561  For example, this may happen when NodeFaceConstraints change Jacobian's sparsity pattern based
2562  on newly-detected Penetration.
2563  In that case certain preconditioners (e.g., PCASM) will not work, unless we tell them that the
2564  sparsity pattern has changed.
2565  For now we are rebuilding the whole KSP, when necessary.
2566  */
2567  PetscErrorCode ierr;
2568  DM dm;
2569  KSP ksp;
2570  const char * prefix;
2571  MPI_Comm comm;
2572  PC pc;
2573 
2575  if (iteration)
2576  {
2577  /* TODO: limit this only to situations when displaced (un)contact splits are present, as is
2578  * DisplacedProblem(). */
2579  ierr = SNESGetDM(snes, &dm);
2580  CHKERRQ(ierr);
2581  ierr = DMMooseReset(dm);
2582  CHKERRQ(ierr);
2583  ierr = DMSetUp(dm);
2584  CHKERRQ(ierr);
2585  ierr = SNESGetKSP(snes, &ksp);
2586  CHKERRQ(ierr);
2587  /* Should we rebuild the whole KSP? */
2588  ierr = PetscObjectGetOptionsPrefix((PetscObject)ksp, &prefix);
2589  CHKERRQ(ierr);
2590  ierr = PetscObjectGetComm((PetscObject)ksp, &comm);
2591  CHKERRQ(ierr);
2592  ierr = PCCreate(comm, &pc);
2593  CHKERRQ(ierr);
2594  ierr = PCSetDM(pc, dm);
2595  CHKERRQ(ierr);
2596  ierr = PCSetOptionsPrefix(pc, prefix);
2597  CHKERRQ(ierr);
2598  ierr = PCSetFromOptions(pc);
2599  CHKERRQ(ierr);
2600  ierr = KSPSetPC(ksp, pc);
2601  CHKERRQ(ierr);
2602  ierr = PCDestroy(&pc);
2603  CHKERRQ(ierr);
2604  }
2606 }
PetscFunctionBegin
PetscErrorCode DMMooseReset(DM dm)
static PetscErrorCode Vec Mat Mat pc
PetscFunctionReturn(0)
CHKERRQ(ierr)
MPI_Comm comm
ierr