www.mooseframework.org
Public Member Functions | Protected Attributes | List of all members
PETScDMDAMesh Class Reference

Generate a parallel (distributed) mesh from PETSc DMDA. More...

#include <PETScDMDAMesh.h>

Inheritance diagram for PETScDMDAMesh:
[legend]

Public Member Functions

 PETScDMDAMesh (const InputParameters &parameters)
 
 PETScDMDAMesh (const PETScDMDAMesh &)=default
 
 ~PETScDMDAMesh ()
 
PETScDMDAMeshoperator= (const PETScDMDAMesh &other_mesh)=delete
 
virtual std::unique_ptr< MooseMesh > safeClone () const override
 
virtual void buildMesh () override
 
virtual Real getMinInDimension (unsigned int component) const override
 
virtual Real getMaxInDimension (unsigned int component) const override
 

Protected Attributes

MooseEnum _dim
 The dimension of the mesh. More...
 
dof_id_type _nx
 Number of elements in x, y, z direction. More...
 
dof_id_type _ny
 
dof_id_type _nz
 
Real _xmin
 The min/max values for x,y,z component. More...
 
Real _xmax
 
Real _ymin
 
Real _ymax
 
Real _zmin
 
Real _zmax
 
ElemType _elem_type
 The type of element to build. More...
 
bool _need_to_destroy_dmda
 If DMDA is created on the fly, we should destroy it. More...
 
DM _dmda
 Mesh object. More...
 

Detailed Description

Generate a parallel (distributed) mesh from PETSc DMDA.

DMDA could be passed in from an application such as ExternalPetscSolverApp or created on the fly. Note that this mesh object does not have one layer of ghost elements. It is designed for holding the solution from an external PETSc application. And then the solution can be coupled to other MOOSE-based applications using the existing MultiApp transfers.

Definition at line 27 of file PETScDMDAMesh.h.

Constructor & Destructor Documentation

◆ PETScDMDAMesh() [1/2]

PETScDMDAMesh::PETScDMDAMesh ( const InputParameters &  parameters)

Definition at line 72 of file PETScDMDAMesh.C.

73  : MooseMesh(parameters),
74  _dim(getParam<MooseEnum>("dim")),
75  _nx(getParam<dof_id_type>("nx")),
76  _ny(getParam<dof_id_type>("ny")),
77  _nz(getParam<dof_id_type>("nz")),
78  _xmin(getParam<Real>("xmin")),
79  _xmax(getParam<Real>("xmax")),
80  _ymin(getParam<Real>("ymin")),
81  _ymax(getParam<Real>("ymax")),
82  _zmin(getParam<Real>("zmin")),
83  _zmax(getParam<Real>("zmax"))
84 {
85  // All generated meshes are regular orthogonal meshes
86  _regular_orthogonal_mesh = true;
87 
88  // We support 2D mesh only at this point. If you need 3D or 1D
89  // Please contact MOOSE developers
90  if (_dim != 2)
91  mooseError("Support 2 dimensional mesh only");
92 
93 #if LIBMESH_HAVE_PETSC
94  // If we are going to couple PETSc external solver,
95  // take a DA from PETSc
96  ExternalPetscSolverApp * petsc_app = dynamic_cast<ExternalPetscSolverApp *>(&_app);
97  if (petsc_app)
98  {
99  TS & ts = petsc_app->getExternalPETScTS();
100  // Retrieve mesh from TS
101  TSGetDM(ts, &_dmda);
102  _need_to_destroy_dmda = false;
103  }
104  // This mesh object can be used independently for any MOOSE apps.
105  // We create one from scratch
106  else
107  {
108  DMDACreate2d(_communicator.get(),
109  DM_BOUNDARY_NONE,
110  DM_BOUNDARY_NONE,
111  DMDA_STENCIL_BOX,
112  _nx,
113  _ny,
114  PETSC_DECIDE,
115  PETSC_DECIDE,
116  1,
117  1,
118  NULL,
119  NULL,
120  &_dmda);
121  // Let DMDA take PETSc options
122  DMSetFromOptions(_dmda);
123  // Finalize mesh setup
124  DMSetUp(_dmda);
125  _need_to_destroy_dmda = true;
126  }
127 #else
128  mooseError("You need PETSc installed to use PETScDMDAMesh");
129 #endif
130 }

◆ PETScDMDAMesh() [2/2]

PETScDMDAMesh::PETScDMDAMesh ( const PETScDMDAMesh )
default

◆ ~PETScDMDAMesh()

PETScDMDAMesh::~PETScDMDAMesh ( )
inline

Definition at line 34 of file PETScDMDAMesh.h.

35  {
37  DMDestroy(&_dmda);
38  }

Member Function Documentation

◆ buildMesh()

void PETScDMDAMesh::buildMesh ( )
overridevirtual

Definition at line 517 of file PETScDMDAMesh.C.

518 {
519  // Reference to the libmesh mesh
520  MeshBase & mesh = getMesh();
521 
522  MooseEnum elem_type_enum = getParam<MooseEnum>("elem_type");
523 
524  if (!isParamValid("elem_type"))
525  {
526  // Switching on MooseEnum
527  switch (_dim)
528  {
529  case 2:
530  elem_type_enum = "QUAD4";
531  break;
532 
533  default:
534  mooseError("Does not support dimension ", _dim, "yet");
535  }
536  }
537 
538  _elem_type = Utility::string_to_enum<ElemType>(elem_type_enum);
539 
540  mesh.set_mesh_dimension(_dim);
541  mesh.set_spatial_dimension(_dim);
542 
543  // Switching on MooseEnum
544  switch (_dim)
545  {
546 #if LIBMESH_HAVE_PETSC
547  case 2:
548  build_cube_Quad4(dynamic_cast<UnstructuredMesh &>(getMesh()), _dmda, _elem_type);
549  break;
550 #endif
551  default:
552  mooseError("Does not support dimension ", _dim, "yet");
553  }
554 }

◆ getMaxInDimension()

Real PETScDMDAMesh::getMaxInDimension ( unsigned int  component) const
overridevirtual

Definition at line 149 of file PETScDMDAMesh.C.

150 {
151  switch (component)
152  {
153  case 0:
154  return _xmax;
155  case 1:
156  return _dim > 1 ? _ymax : 0;
157  case 2:
158  return _dim > 2 ? _zmax : 0;
159  default:
160  mooseError("Invalid component");
161  }
162 }

◆ getMinInDimension()

Real PETScDMDAMesh::getMinInDimension ( unsigned int  component) const
overridevirtual

Definition at line 133 of file PETScDMDAMesh.C.

134 {
135  switch (component)
136  {
137  case 0:
138  return _xmin;
139  case 1:
140  return _dim > 1 ? _ymin : 0;
141  case 2:
142  return _dim > 2 ? _zmin : 0;
143  default:
144  mooseError("Invalid component");
145  }
146 }

◆ operator=()

PETScDMDAMesh& PETScDMDAMesh::operator= ( const PETScDMDAMesh other_mesh)
delete

◆ safeClone()

std::unique_ptr< MooseMesh > PETScDMDAMesh::safeClone ( ) const
overridevirtual

Definition at line 165 of file PETScDMDAMesh.C.

166 {
167  return libmesh_make_unique<PETScDMDAMesh>(*this);
168 }

Member Data Documentation

◆ _dim

MooseEnum PETScDMDAMesh::_dim
protected

The dimension of the mesh.

Definition at line 51 of file PETScDMDAMesh.h.

Referenced by buildMesh(), getMaxInDimension(), getMinInDimension(), and PETScDMDAMesh().

◆ _dmda

DM PETScDMDAMesh::_dmda
protected

Mesh object.

Definition at line 66 of file PETScDMDAMesh.h.

Referenced by buildMesh(), PETScDMDAMesh(), and ~PETScDMDAMesh().

◆ _elem_type

ElemType PETScDMDAMesh::_elem_type
protected

The type of element to build.

Definition at line 60 of file PETScDMDAMesh.h.

Referenced by buildMesh().

◆ _need_to_destroy_dmda

bool PETScDMDAMesh::_need_to_destroy_dmda
protected

If DMDA is created on the fly, we should destroy it.

Definition at line 63 of file PETScDMDAMesh.h.

Referenced by PETScDMDAMesh(), and ~PETScDMDAMesh().

◆ _nx

dof_id_type PETScDMDAMesh::_nx
protected

Number of elements in x, y, z direction.

Definition at line 54 of file PETScDMDAMesh.h.

Referenced by PETScDMDAMesh().

◆ _ny

dof_id_type PETScDMDAMesh::_ny
protected

Definition at line 54 of file PETScDMDAMesh.h.

Referenced by PETScDMDAMesh().

◆ _nz

dof_id_type PETScDMDAMesh::_nz
protected

Definition at line 54 of file PETScDMDAMesh.h.

◆ _xmax

Real PETScDMDAMesh::_xmax
protected

Definition at line 57 of file PETScDMDAMesh.h.

Referenced by getMaxInDimension().

◆ _xmin

Real PETScDMDAMesh::_xmin
protected

The min/max values for x,y,z component.

Definition at line 57 of file PETScDMDAMesh.h.

Referenced by getMinInDimension().

◆ _ymax

Real PETScDMDAMesh::_ymax
protected

Definition at line 57 of file PETScDMDAMesh.h.

Referenced by getMaxInDimension().

◆ _ymin

Real PETScDMDAMesh::_ymin
protected

Definition at line 57 of file PETScDMDAMesh.h.

Referenced by getMinInDimension().

◆ _zmax

Real PETScDMDAMesh::_zmax
protected

Definition at line 57 of file PETScDMDAMesh.h.

Referenced by getMaxInDimension().

◆ _zmin

Real PETScDMDAMesh::_zmin
protected

Definition at line 57 of file PETScDMDAMesh.h.

Referenced by getMinInDimension().


The documentation for this class was generated from the following files:
PETScDMDAMesh::_ymin
Real _ymin
Definition: PETScDMDAMesh.h:57
PETScDMDAMesh::_zmax
Real _zmax
Definition: PETScDMDAMesh.h:57
PETScDMDAMesh::_xmin
Real _xmin
The min/max values for x,y,z component.
Definition: PETScDMDAMesh.h:57
PETScDMDAMesh::_nz
dof_id_type _nz
Definition: PETScDMDAMesh.h:54
PETScDMDAMesh::_zmin
Real _zmin
Definition: PETScDMDAMesh.h:57
build_cube_Quad4
void build_cube_Quad4(UnstructuredMesh &mesh, DM da, const ElemType type)
Definition: PETScDMDAMesh.C:435
PETScDMDAMesh::_ny
dof_id_type _ny
Definition: PETScDMDAMesh.h:54
PETScDMDAMesh::_xmax
Real _xmax
Definition: PETScDMDAMesh.h:57
MaterialTensorCalculatorTools::component
Real component(const SymmTensor &symm_tensor, unsigned int index)
Definition: MaterialTensorCalculatorTools.C:16
PETScDMDAMesh::_dmda
DM _dmda
Mesh object.
Definition: PETScDMDAMesh.h:66
PETScDMDAMesh::_nx
dof_id_type _nx
Number of elements in x, y, z direction.
Definition: PETScDMDAMesh.h:54
ExternalPetscSolverApp
This is a demo used to demonstrate how to couple an external app through the MOOSE wrapper APP.
Definition: ExternalPetscSolverApp.h:25
PETScDMDAMesh::_need_to_destroy_dmda
bool _need_to_destroy_dmda
If DMDA is created on the fly, we should destroy it.
Definition: PETScDMDAMesh.h:63
PETScDMDAMesh::_elem_type
ElemType _elem_type
The type of element to build.
Definition: PETScDMDAMesh.h:60
PETScDMDAMesh::_dim
MooseEnum _dim
The dimension of the mesh.
Definition: PETScDMDAMesh.h:51
PETScDMDAMesh::_ymax
Real _ymax
Definition: PETScDMDAMesh.h:57
ExternalPetscSolverApp::getExternalPETScTS
TS & getExternalPETScTS()
Return a time-stepping (TS) component that holds all the ingredients of applicaiton.
Definition: ExternalPetscSolverApp.h:38