Commits

Peter Brune  committed 8f5bbff

Added src/sys/examples/tests/ex25.c for PetscScalar and PetscReal wrapping.

  • Participants
  • Parent commits a4bea5a

Comments (0)

Files changed (3)

File src/sys/examples/tests/ex25.c

+static char help[] = "Tests wrapping of math.h functions for real, complex, and scalar types \n";
+#include <petscsys.h>
+
+#undef __FUNCT__
+#define __FUNCT__ "main"
+int main(int argc,char **argv)
+{
+  PetscErrorCode ierr;
+
+  PetscInitialize(&argc,&argv,(char*)0,help);
+  {
+    PetscReal a,b,c;
+    a = 0.5;
+    c = 2.0;
+    ierr = PetscPrintf(PETSC_COMM_WORLD,"Real tests:\n");CHKERRQ(ierr);
+    b = PetscSqrtReal(a);
+    ierr = PetscPrintf(PETSC_COMM_WORLD,"sqrt(%f) = %f\n",(double)a,(double)b);CHKERRQ(ierr);
+    b = PetscExpReal(a);
+    ierr = PetscPrintf(PETSC_COMM_WORLD,"exp(%f) = %f\n",(double)a,(double)b);CHKERRQ(ierr);
+    b = PetscLogReal(a);
+    ierr = PetscPrintf(PETSC_COMM_WORLD,"log(%f) = %f\n",(double)a,(double)b);CHKERRQ(ierr);
+    b = PetscLog10Real(a);
+    ierr = PetscPrintf(PETSC_COMM_WORLD,"log10(%f) = %f\n",(double)a,(double)b);CHKERRQ(ierr);
+    b = PetscSinReal(a);
+    ierr = PetscPrintf(PETSC_COMM_WORLD,"sin(%f) = %f\n",(double)a,(double)b);CHKERRQ(ierr);
+    b = PetscCosReal(a);
+    ierr = PetscPrintf(PETSC_COMM_WORLD,"cos(%f) = %f\n",(double)a,(double)b);CHKERRQ(ierr);
+    b = PetscTanReal(a);
+    ierr = PetscPrintf(PETSC_COMM_WORLD,"tan(%f) = %f\n",(double)a,(double)b);CHKERRQ(ierr);
+    b = PetscAsinReal(a);
+    ierr = PetscPrintf(PETSC_COMM_WORLD,"asin(%f) = %f\n",(double)a,(double)b);CHKERRQ(ierr);
+    b = PetscAcosReal(a);
+    ierr = PetscPrintf(PETSC_COMM_WORLD,"acos(%f) = %f\n",(double)a,(double)b);CHKERRQ(ierr);
+    b = PetscAtanReal(a);
+    ierr = PetscPrintf(PETSC_COMM_WORLD,"atan(%f) = %f\n",(double)a,(double)b);CHKERRQ(ierr);
+    b = PetscSinhReal(a);
+    ierr = PetscPrintf(PETSC_COMM_WORLD,"sinh(%f) = %f\n",(double)a,(double)b);CHKERRQ(ierr);
+    b = PetscCoshReal(a);
+    ierr = PetscPrintf(PETSC_COMM_WORLD,"cosh(%f) = %f\n",(double)a,(double)b);CHKERRQ(ierr);
+    b = PetscTanhReal(a);
+    ierr = PetscPrintf(PETSC_COMM_WORLD,"tanh(%f) = %f\n",(double)a,(double)b);CHKERRQ(ierr);
+    b = PetscPowReal(a,c);
+    ierr = PetscPrintf(PETSC_COMM_WORLD,"pow(%f,%f) = %f\n",(double)a,(double)c,(double)b);CHKERRQ(ierr);
+    b = PetscCeilReal(a);
+    ierr = PetscPrintf(PETSC_COMM_WORLD,"ceil(%f) = %f\n",(double)a,(double)b);CHKERRQ(ierr);
+    b = PetscFloorReal(a);
+    ierr = PetscPrintf(PETSC_COMM_WORLD,"floor(%f) = %f\n",(double)a,(double)b);CHKERRQ(ierr);
+    b = PetscFmodReal(a,c);
+    ierr = PetscPrintf(PETSC_COMM_WORLD,"fmod(%f,%f) = %f\n",(double)a,(double)c,(double)b);CHKERRQ(ierr);
+  }
+  ierr = PetscPrintf(PETSC_COMM_WORLD,"Scalar tests:\n");CHKERRQ(ierr);
+  {
+    PetscScalar a,b,c;
+    a = 0.5;
+    c = 2.0;
+    b = PetscSqrtScalar(a);
+    ierr = PetscPrintf(PETSC_COMM_WORLD,"sqrt(%f) = %f\n",(double)PetscRealPart(a),(double)PetscRealPart(b));CHKERRQ(ierr);
+    b = PetscExpScalar(a);
+    ierr = PetscPrintf(PETSC_COMM_WORLD,"exp(%f) = %f\n",(double)PetscRealPart(a),(double)PetscRealPart(b));CHKERRQ(ierr);
+    b = PetscLogScalar(a);
+    ierr = PetscPrintf(PETSC_COMM_WORLD,"log(%f) = %f\n",(double)PetscRealPart(a),(double)PetscRealPart(b));CHKERRQ(ierr);
+    b = PetscPowScalar(a,c);
+    ierr = PetscPrintf(PETSC_COMM_WORLD,"pow(%f,%f) = %f\n",(double)PetscRealPart(a),(double)PetscRealPart(c),(double)PetscRealPart(b));CHKERRQ(ierr);
+    b = PetscSinScalar(a);
+    ierr = PetscPrintf(PETSC_COMM_WORLD,"sin(%f) = %f\n",(double)PetscRealPart(a),(double)PetscRealPart(b));CHKERRQ(ierr);
+    b = PetscCosScalar(a);
+    ierr = PetscPrintf(PETSC_COMM_WORLD,"cos(%f) = %f\n",(double)PetscRealPart(a),(double)PetscRealPart(b));CHKERRQ(ierr);
+    b = PetscTanScalar(a);
+    ierr = PetscPrintf(PETSC_COMM_WORLD,"tan(%f) = %f\n",(double)PetscRealPart(a),(double)PetscRealPart(b));CHKERRQ(ierr);
+    b = PetscSinhScalar(a);
+    ierr = PetscPrintf(PETSC_COMM_WORLD,"sinh(%f) = %f\n",(double)PetscRealPart(a),(double)PetscRealPart(b));CHKERRQ(ierr);
+    b = PetscCoshScalar(a);
+    ierr = PetscPrintf(PETSC_COMM_WORLD,"cosh(%f) = %f\n",(double)PetscRealPart(a),(double)PetscRealPart(b));CHKERRQ(ierr);
+    b = PetscTanhScalar(a);
+    ierr = PetscPrintf(PETSC_COMM_WORLD,"tanh(%f) = %f\n",(double)PetscRealPart(a),(double)PetscRealPart(b));CHKERRQ(ierr);
+  }
+  ierr = PetscFinalize();
+  return 0;
+}

File src/sys/examples/tests/makefile

 ex24: ex24.o chkopts
 	-${CLINKER} -o ex24 ex24.o  ${PETSC_SYS_LIB}
 	${RM} -f ex24.o
+ex25: ex25.o chkopts
+	-${CLINKER} -o ex25 ex25.o  ${PETSC_SYS_LIB}
+	${RM} -f ex25.o
 #----------------------------------------------------------------------------
 runex1:
 	-@${MPIEXEC} -n 1 ./ex1
 	-@${MPIEXEC} -n 1 ./ex23 -options_file_yaml ex23options > ex23.tmp 2>&1;   \
 	   ${DIFF} output/ex23.out ex23.tmp || echo  ${PWD} "\nPossible problem with ex23, diffs above \n========================================="; \
 	   ${RM} -f ex23.tmp
+runex25:
+	-@${MPIEXEC} -n 1 ./ex25 > ex25.tmp 2>&1;   \
+	   ${DIFF} output/ex25.out ex25.tmp || echo  ${PWD} "\nPossible problem with ex25, diffs above \n========================================="; \
+	   ${RM} -f ex25.tmp
 
 
 TESTEXAMPLES_C		       = ex13.PETSc runex13 ex13.rm ex19.PETSc runex19 ex19.rm \
                                  ex20.PETSc runex20 runex20_2 runex20_3 ex20.rm  ex21.PETSc ex21.rm \
-                                 ex22.PETSc runex22 ex22.rm ex24.PETSc ex24.rm
+                                 ex22.PETSc runex22 ex22.rm ex24.PETSc ex24.rm \
+                                 ex25.PETSc runex25 ex25.rm
 TESTEXAMPLES_C_X	       = ex1.PETSc runex1 ex1.rm ex2.PETSc runex2 ex2.rm ex3.PETSc runex3 ex3.rm
 TESTEXAMPLES_FORTRAN	       = ex5f.PETSc ex5f.rm ex6f.PETSc ex6f.rm ex17f.PETSc ex17f.rm
 TESTEXAMPLES_FORTRAN_NOCOMPLEX = ex1f.PETSc runex1f ex1f.rm

File src/sys/examples/tests/output/ex25.out

+Real tests:
+sqrt(0.500000) = 0.707107
+exp(0.500000) = 1.648721
+log(0.500000) = -0.693147
+log10(0.500000) = -0.301030
+sin(0.500000) = 0.479426
+cos(0.500000) = 0.877583
+tan(0.500000) = 0.546302
+asin(0.500000) = 0.523599
+acos(0.500000) = 1.047198
+atan(0.500000) = 0.463648
+sinh(0.500000) = 0.521095
+cosh(0.500000) = 1.127626
+tanh(0.500000) = 0.462117
+pow(0.500000,2.000000) = 0.250000
+ceil(0.500000) = 1.000000
+floor(0.500000) = 0.000000
+fmod(0.500000,2.000000) = 0.500000
+Scalar tests:
+sqrt(0.500000) = 0.707107
+exp(0.500000) = 1.648721
+log(0.500000) = -0.693147
+pow(0.500000,2.000000) = 0.250000
+sin(0.500000) = 0.479426
+cos(0.500000) = 0.877583
+tan(0.500000) = 0.546302
+sinh(0.500000) = 0.521095
+cosh(0.500000) = 1.127626
+tanh(0.500000) = 0.462117