Actual source code: pipeInterface.c

petsc-3.9.0 2018-04-07
Report Typos and Errors
  1: #include "pipe.h"

  3: /* Subroutines for Pipe                                  */
  4: /* -------------------------------------------------------*/

  6: /*
  7:    PipeCreate - Create Pipe object.

  9:    Input Parameters:
 10:    comm - MPI communicator
 11:    
 12:    Output Parameter:
 13: .  pipe - location to put the PIPE context
 14: */
 15: PetscErrorCode PipeCreate(MPI_Comm comm,Pipe *pipe)
 16: {

 20:   PetscNew(pipe);
 21:   (*pipe)->comm = comm;
 22:   return(0);
 23: }

 25: /*
 26:    PipeDestroy - Destroy Pipe object.

 28:    Input Parameters:
 29:    pipe - Reference to pipe intended to be destroyed.
 30: */
 31: PetscErrorCode PipeDestroy(Pipe *pipe)
 32: {

 36:   if (!*pipe) return(0);
 37: 
 38:   VecDestroy(&(*pipe)->x);
 39:   DMDestroy(&(*pipe)->da);
 40:   PetscFree(*pipe);
 41:   return(0);
 42: }

 44: /*
 45:    PipeSetParameters - Set parameters for Pipe context

 47:    Input Parameter:
 48: +  pipe - PIPE object
 49: .  length - 
 50: .  nnodes -
 51: .  D - 
 52: .  a -
 53: -  fric -
 54: */
 55: PetscErrorCode PipeSetParameters(Pipe pipe,PetscReal length,PetscInt nnodes,PetscReal D,PetscReal a,PetscReal fric)
 56: {
 58:   pipe->length = length;
 59:   pipe->nnodes = nnodes;
 60:   pipe->D      = D;
 61:   pipe->a      = a;
 62:   pipe->fric   = fric;
 63:   return(0);
 64: }

 66: /*
 67:     PipeSetUp - Set up pipe based on set parameters.
 68: */
 69: PetscErrorCode PipeSetUp(Pipe pipe)
 70: {
 71:   DMDALocalInfo  info;
 73:   MPI_Comm       comm = pipe->comm;
 74: 
 76:   DMDACreate1d(comm, DM_BOUNDARY_GHOSTED, pipe->nnodes, 2, 1, NULL, &pipe->da);
 77:   DMSetFromOptions(pipe->da);
 78:   DMSetUp(pipe->da);
 79:   DMDASetFieldName(pipe->da, 0, "Q");
 80:   DMDASetFieldName(pipe->da, 1, "H");
 81:   DMDASetUniformCoordinates(pipe->da, 0, pipe->length, 0, 0, 0, 0);
 82:   DMCreateGlobalVector(pipe->da, &(pipe->x));

 84:   DMDAGetLocalInfo(pipe->da, &info);

 86:   pipe->rad = pipe->D / 2;
 87:   pipe->A   = PETSC_PI*pipe->rad*pipe->rad;
 88:   pipe->R   = pipe->fric / (2*pipe->D*pipe->A);
 89:   return(0);
 90: }