Actual source code: ad_utils.c

      1: #define PETSC_DLL

      3: #include "petsc.h"
      4: #include "petscis.h"

      6: #if defined(PETSC_HAVE_STDLIB_H)
      7: #include <stdlib.h>
      8: #endif

     12: #include "ad_deriv.h"

     14: void PetscADSetValueAndColor(DERIV_TYPE *vars,int n,ISColoringValue *colors,double *values)
     15: {
     16:   int       i,j;
     17:   PetscReal *d;

     19:   for (i=0; i<n; i++) {
     20:     DERIV_val(vars[i]) = values[i];
     21:     d = (PetscReal*)DERIV_grad(vars[i]);
     22:     for (j=0; j<ad_GRAD_MAX; j++) {
     23:       d[j] = 0.0;
     24:     }
     25:     d[colors[i]] = 1.0;
     26:   }
     27: }

     29: void PetscADResetIndep(void)
     30: {
     31:   ad_AD_ResetIndep();
     32: }

     34: void PetscADSetValArray(DERIV_TYPE *var,int size,double *values)
     35: {
     36:   ad_AD_SetValArray(var,size,values);
     37: }

     39: void PetscADSetIndepVector(DERIV_TYPE *var, int size,double *values)
     40: {
     41:   ad_AD_SetIndepVector(var, size, values);
     42: }

     44: void PetscADSetIndepArrayColored(DERIV_TYPE *var,int size,int *coloring)
     45: {
     46:   ad_AD_SetIndepArrayColored(var,size,coloring);
     47: }

     49: int PetscADIncrementTotalGradSize(int num)
     50: {
     51:   ad_AD_IncrementTotalGradSize(num);
     52:   return(0);
     53: }

     55: void PetscADSetIndepDone(void)
     56: {
     57:   ad_AD_SetIndepDone();
     58: }

     60: /* Note that we pass a pointer to DERIV_TYPE, then dereference to match ad_AD_ExtractGrad format */
     61: void PetscADExtractGrad(double *grad, DERIV_TYPE *deriv)
     62: {
     63:   ad_AD_ExtractGrad(grad,*deriv);
     64: }

     66: int PetscADGetDerivTypeSize(void)
     67: {
     68:   return sizeof(DERIV_TYPE);
     69: }

     71: double *PetscADGetGradArray(DERIV_TYPE *deriv)
     72: {
     73:   return deriv->grad;
     74: }

     76: void PETSC_DLLEXPORT ad_AD_Init(int  arg0) {
     77:     ad_AD_GradInit(arg0);

     79: }
     80: void PETSC_DLLEXPORT ad_AD_Final() {
     81:     ad_AD_GradFinal();

     83: }

     85: void   admf_AD_Init(int  arg0) {
     86:     ad_AD_GradInit(arg0);

     88: }
     89: void   admf_AD_Final() {
     90:     ad_AD_GradFinal();

     92: }