# DMSwarmProjectFields
Project a set of swarm fields onto the cell DM 
## Synopsis
```
#include "petscdmswarm.h"   
PETSC_EXTERN PetscErrorCode DMSwarmProjectFields(DM dm, PetscInt nfields, const char *fieldnames[], Vec **fields, PetscBool reuse)
```
Collective on dm


## Input parameters

- ***dm -*** the DMSwarm
- ***nfields -*** the number of swarm fields to project
- ***fieldnames -*** the textual names of the swarm fields to project
- ***fields -*** an array of Vec's of length nfields
- ***reuse -*** flag indicating whether the array and contents of fields should be re-used or internally allocated


Currently, the only available projection method consists of
phi_i = \sum_{p=0}^{np} N_i(x_p) phi_p dJ / \sum_{p=0}^{np} N_i(x_p) dJ
where phi_p is the swarm field at point p,
N_i() is the cell DM basis function at vertex i,
dJ is the determinant of the cell Jacobian and
phi_i is the projected vertex value of the field phi.




## Notes

If reuse = PETSC_FALSE, this function will allocate the array of Vec's, and each individual Vec.
The user is responsible for destroying both the array and the individual Vec objects.

Only swarm fields registered with data type = PETSC_REAL can be projected onto the cell DM.

Only swarm fields of block size = 1 can currently be projected.

The only projection methods currently only support the DA (2D) and PLEX (triangles 2D).


## See Also
 `DMSwarmSetType()`, `DMSwarmSetCellDM()`, `DMSwarmType`

## Level
beginner

## Location
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/dm/impls/swarm/swarmpic.c.html#DMSwarmProjectFields">src/dm/impls/swarm/swarmpic.c</A>

## Examples
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/dm/tutorials/ex21.c.html">src/dm/tutorials/ex21.c.html</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/ksp/ksp/tutorials/ex70.c.html">src/ksp/ksp/tutorials/ex70.c.html</A><BR>


---
[Edit on GitLab](https://gitlab.com/petsc/petsc/-/edit/release/src/dm/impls/swarm/swarmpic.c)


[Index of all DMSwarm routines](index.md)  
[Table of Contents for all manual pages](/docs/manualpages/index.md)  
[Index of all manual pages](/docs/manualpages/singleindex.md)  
