DMGetApplicationContext — PETSc 3.23.0 documentation

Skip to main content
`Ctrl`+`K`

# DMGetApplicationContext

Gets a user context from a `DM` object provided with `DMSetApplicationContext()`

## Synopsis

    #include "petscdm.h"
    #include "petscdmlabel.h"
    #include "petscds.h"
    PetscErrorCode DMGetApplicationContext(DM dm, PeCtx ctx)

Not Collective

## Input Parameter

- dm - the `DM` object

## Output Parameter

- ctx - a pointer to the user context

## Note

A user context is a way to pass problem specific information that is accessible whenever the `DM` is available

## Fortran Notes

This only works when the context is a Fortran derived type (it cannot be a `PetscObject`) and you must write a Fortran interface definition for this function that tells the Fortran compiler the derived data type that is returned as the `ctx` argument. For example,

      Interface DMGetApplicationContext
        Subroutine DMGetApplicationContext(dm,ctx,ierr)
      #include <petsc/finclude/petscdm.h>
          use petscdm
          DM dm
          type(tUsertype), pointer :: ctx
          PetscErrorCode ierr
        End Subroutine
      End Interface DMGetApplicationContext

The prototpye for `ctx` must be

      type(tUsertype), pointer :: ctx

## See Also

DM Basics, `DM`, `DMView()`, `DMCreateGlobalVector()`, `DMCreateInterpolation()`, `DMCreateColoring()`, `DMCreateMatrix()`, `DMCreateMassMatrix()`

## Level

intermediate

## Location

src/dm/interface/dm.c

## Examples

src/snes/tutorials/ex18.c
src/dm/tutorials/swarm_ex3.c
src/snes/tutorials/ex27.c
src/ksp/ksp/tutorials/ex73.c
src/snes/tutorials/ex30.c
src/snes/tutorials/ex22.c
src/snes/tutorials/ex5.c
src/snes/tutorials/ex48.c
src/ksp/ksp/tutorials/ex28.c
src/snes/tutorials/ex55.c

Index of all DM routines
Table of Contents for all manual pages
Index of all manual pages