Skip to content

Commit

Permalink
tests - refactor t301,302 to not use output
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremylt committed Aug 2, 2021
1 parent 1c55e7a commit 35778b5
Show file tree
Hide file tree
Showing 10 changed files with 172 additions and 162 deletions.
5 changes: 2 additions & 3 deletions interface/ceed-basis.c
Original file line number Diff line number Diff line change
Expand Up @@ -551,10 +551,9 @@ int CeedBasisCreateTensorH1Lagrange(Ceed ceed, CeedInt dim, CeedInt num_comp,
c1 = c2;
}
}
// // Pass to CeedBasisCreateTensorH1
// Pass to CeedBasisCreateTensorH1
ierr = CeedBasisCreateTensorH1(ceed, dim, num_comp, P, Q, interp_1d, grad_1d,
q_ref_1d,
q_weight_1d, basis); CeedChk(ierr);
q_ref_1d, q_weight_1d, basis); CeedChk(ierr);
cleanup:
ierr2 = CeedFree(&interp_1d); CeedChk(ierr2);
ierr2 = CeedFree(&grad_1d); CeedChk(ierr2);
Expand Down
29 changes: 29 additions & 0 deletions interface/ceed-fortran.c
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,15 @@ void fCeedQRFactorization(int *ceed, CeedScalar *mat, CeedScalar *tau, int *m,
*err = CeedQRFactorization(Ceed_dict[*ceed], mat, tau, *m, *n);
}

#define fCeedHouseholderApplyQ \
FORTRAN_NAME(ceedhouseholderapplyq, CEEDHOUSEHOLDERAPPLYQ)
void fCeedHouseholderApplyQ(CeedScalar *A, CeedScalar *Q, CeedScalar *tau,
int *t_mode,
int *m, int *n, int *k, int *row, int *col, int *err) {
*err = CeedHouseholderApplyQ(A, Q, tau, (CeedTransposeMode)*t_mode, *m, *n, *k,
*row, *col);
}

#define fCeedSymmetricSchurDecomposition \
FORTRAN_NAME(ceedsymmetricschurdecomposition, CEEDSYMMETRICSCHURDECOMPOSITION)
void fCeedSymmetricSchurDecomposition(int *ceed, CeedScalar *mat,
Expand Down Expand Up @@ -607,6 +616,26 @@ void fCeedBasisGetInterp1D(int *basis, CeedScalar *interp_1d, int64_t *offset,
*offset = interp1d_ - interp_1d;
}

#define fCeedBasisGetGrad1D \
FORTRAN_NAME(ceedbasisgetgrad1d, CEEDBASISGETGRAD1D)
void fCeedBasisGetGrad1D(int *basis, CeedScalar *grad_1d, int64_t *offset,
int *err) {
const CeedScalar *grad1d_;
CeedBasis basis_ = CeedBasis_dict[*basis];
*err = CeedBasisGetGrad1D(basis_, &grad1d_);
*offset = grad1d_ - grad_1d;
}

#define fCeedBasisGetQRef \
FORTRAN_NAME(ceedbasisgetqref, CEEDBASISGETQREF)
void fCeedBasisGetQRef(int *basis, CeedScalar *q_ref, int64_t *offset,
int *err) {
const CeedScalar *qref_;
CeedBasis basis_ = CeedBasis_dict[*basis];
*err = CeedBasisGetQRef(basis_, &qref_);
*offset = qref_ - q_ref;
}

#define fCeedBasisDestroy FORTRAN_NAME(ceedbasisdestroy,CEEDBASISDESTROY)
void fCeedBasisDestroy(int *basis, int *err) {
if (*basis == FORTRAN_NULL) return;
Expand Down
15 changes: 0 additions & 15 deletions tests/output/t301-basis-f.out

This file was deleted.

15 changes: 0 additions & 15 deletions tests/output/t301-basis.out

This file was deleted.

14 changes: 0 additions & 14 deletions tests/output/t302-basis-f.out

This file was deleted.

14 changes: 0 additions & 14 deletions tests/output/t302-basis.out

This file was deleted.

45 changes: 23 additions & 22 deletions tests/t301-basis-f.f90
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,37 @@
program test
implicit none
include 'ceed/fortran.h'

integer ceed,err,i
real*8 qr(12), tau(3)

integer ceed,err,i,j
real*8 a(12),qr(12),a_qr(12),tau(3)
character arg*32


A = (/ 1, -1, 4, 1, 4, -2, 1, 4, 2, 1, -1, 0 /)
qr = (/ 1, -1, 4, 1, 4, -2, 1, 4, 2, 1, -1, 0 /)

a_qr = (/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 /)

call getarg(1,arg)

call ceedinit(trim(arg)//char(0),ceed,err)
call ceedqrfactorization(ceed,qr,tau,4,3,err);
do i=1,12
if (abs(qr(i))<1.0D-14) then
! LCOV_EXCL_START
qr(i) = 0
! LCOV_EXCL_STOP
endif
write(*,'(A,F12.8)') '',qr(i)
enddo
call ceedqrfactorization(ceed,qr,tau,4,3,err)
do i=1,3
if (abs(tau(i))<1.0D-14) then
do j=i,3
a_qr((i-1)*3+j)=qr((i-1)*3+j)
enddo
enddo
call ceedhouseholderapplyq(a_qr,qr,tau,ceed_notranspose,4,3,3,3,1,err)

do i=1,12
if (abs(a(i)-a_qr(i))>1.0D-14) then
! LCOV_EXCL_START
tau(i) = 0
write(*,*) 'Error in QR factorization a_qr(',i,') = ',a_qr(i),&
& ' != a(',i,') = ',a(i)
! LCOV_EXCL_STOP
endif
write(*,'(A,F12.8)') '',tau(i)
endif
enddo

call ceeddestroy(ceed,err)

end
!-----------------------------------------------------------------------
28 changes: 18 additions & 10 deletions tests/t301-basis.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,31 @@
/// Test QR Factorization
/// \test Test QR Factorization
#include <ceed.h>
#include <ceed/backend.h>
#include <math.h>

int main(int argc, char **argv) {
Ceed ceed;
CeedScalar qr[12] = {1, -1, 4, 1, 4, -2, 1, 4, 2, 1, -1, 0};
CeedScalar tau[3];
CeedScalar A[12] = {1, -1, 4, 1, 4, -2, 1, 4, 2, 1, -1, 0};
CeedScalar qr[12] = {1, -1, 4, 1, 4, -2, 1, 4, 2, 1, -1, 0};
CeedScalar A_qr[12] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
CeedScalar tau[4];

CeedInit(argv[1], &ceed);

CeedQRFactorization(ceed, qr, tau, 4, 3);
for (int i=0; i<12; i++) {
if (qr[i] <= 1E-14 && qr[i] >= -1E-14) qr[i] = 0;
fprintf(stdout, "%12.8f\n", qr[i]);
}
for (int i=0; i<3; i++) {
if (tau[i] <= 1E-14 && tau[i] >= -1E-14) tau[i] = 0;
fprintf(stdout, "%12.8f\n", tau[i]);
}
for (CeedInt i=0; i<3; i++)
for (CeedInt j=i; j<3; j++)
A_qr[i*3+j] = qr[i*3+j];
CeedHouseholderApplyQ(A_qr, qr, tau, CEED_NOTRANSPOSE, 4, 3, 3, 3, 1);

for (CeedInt i=0; i<12; i++)
if (fabs(A_qr[i] - A[i]) > 10*CEED_EPSILON)
// LCOV_EXCL_START
printf("Error in QR factorization A_qr[%d] = %f != A[%d] = %f\n",
i, A_qr[i], i, A[i]);
// LCOV_EXCL_STOP

CeedDestroy(&ceed);
return 0;
}
99 changes: 58 additions & 41 deletions tests/t302-basis-f.f90
Original file line number Diff line number Diff line change
Expand Up @@ -2,68 +2,85 @@
program test
implicit none
include 'ceed/fortran.h'

integer ceed,err,i,j
integer b
real*8 collograd1d(16), collograd1d2(36)

integer b,p
parameter(p=4)
real*8 collograd1d(36),x2(6)
real*8 grad1d(16),qref(6)
integer*8 gradoffset,qoffset
real*8 sum

character arg*32

call getarg(1,arg)

call ceedinit(trim(arg)//char(0),ceed,err)

! Already collocated, GetCollocatedGrad will return grad1d
call ceedbasiscreatetensorh1lagrange(ceed,1,1,4,4,ceed_gauss_lobatto,b,&
call ceedbasiscreatetensorh1lagrange(ceed,1,1,p,p,ceed_gauss_lobatto,b,&
& err)
call ceedbasisgetcollocatedgrad(b,collograd1d,err)
do i=1,16
if (abs(collograd1d(i))<1.0D-14) then
collograd1d(i) = 0
endif
enddo
do i=0,3
write(*,'(A,I1,A,F12.8,F12.8,F12.8,F12.8,F12.8,F12.8)')&
& 'collograd[',i,']:',(collograd1d(j+4*i),j=1,4)
call flush(6)
call ceedbasisgetgrad1d(b,grad1d,gradoffset,err)
do i=0,p-1
do j=1,p
if (abs(collograd1d(j+p*i)-grad1d(j+p*i+gradoffset))>1.0D-13) then
! LCOV_EXCL_START
write(*,*) 'Error in collocated gradient ',collograd1d(j+p*i),' != ',&
& grad1d(j+p*i+gradoffset)
! LCOV_EXCL_STOP
endif
enddo
enddo
call ceedbasisdestroy(b,err)

! Q = P, not already collocated
call ceedbasiscreatetensorh1lagrange(ceed,1,1,4,4,ceed_gauss,b,err)
call ceedbasiscreatetensorh1lagrange(ceed,1,1,p,p,ceed_gauss,b,err)
call ceedbasisgetcollocatedgrad(b,collograd1d,err)
do i=1,16
if (abs(collograd1d(i))<1.0D-14) then

call ceedbasisgetqref(b,qref,qoffset,err)
do i=1,p
x2(i)=qref(i+qoffset)*qref(i+qoffset)
enddo

do i=0,p-1
sum=0
do j=1,p
sum=sum+collograd1d(j+p*i)*x2(j)
enddo
if (abs(sum-2*qref(i+1+qoffset))>1.0D-13) then
! LCOV_EXCL_START
collograd1d(i) = 0
write(*,*) 'Error in collocated gradient ',sum,' != ',&
& 2*qref(i+1+qoffset)
! LCOV_EXCL_STOP
endif
enddo
do i=0,3
write(*,'(A,I1,A,F12.8,F12.8,F12.8,F12.8,F12.8,F12.8)')&
& 'collograd[',i,']:',(collograd1d(j+4*i),j=1,4)
call flush(6)
enddo
call ceedbasisdestroy(b,err)

! Q = P + 2, not already collocated
call ceedbasiscreatetensorh1lagrange(ceed,1,1,4,6,ceed_gauss,b,err)
call ceedbasisgetcollocatedgrad(b,collograd1d2,err)
do i=1,36
if (abs(collograd1d2(i))<1.0D-14) then
call ceedbasiscreatetensorh1lagrange(ceed,1,1,p,p+2,ceed_gauss,b,err)
call ceedbasisgetcollocatedgrad(b,collograd1d,err)

call ceedbasisgetqref(b,qref,qoffset,err)
do i=1,p+2
x2(i)=qref(i+qoffset)*qref(i+qoffset)
enddo

do i=0,p+1
sum=0
do j=1,p+2
sum=sum+collograd1d(j+(p+2)*i)*x2(j)
enddo
if (abs(sum-2*qref(i+1+qoffset))>1.0D-13) then
! LCOV_EXCL_START
collograd1d2(i) = 0
write(*,*) 'Error in collocated gradient ',sum,' != ',&
& 2*qref(i+1+qoffset)
! LCOV_EXCL_STOP
endif
enddo
do i=0,5
write(*,'(A,I1,A,F12.8,F12.8,F12.8,F12.8,F12.8,F12.8)')&
& 'collograd[',i,']:',(collograd1d2(j+6*i),j=1,6)
call flush(6)
enddo
call ceedbasisdestroy(b,err)

call ceeddestroy(ceed,err)

end
!-----------------------------------------------------------------------
!-----------------------------------------------------------------------
Loading

0 comments on commit 35778b5

Please sign in to comment.