xref: /libCEED/tests/t530-operator-f.f90 (revision 15910d16b955338d1102d4e730fc58bca8f202b9)
11d102b48SJeremy L Thompson!-----------------------------------------------------------------------
21d102b48SJeremy L Thompson      subroutine setup(ctx,q,u1,u2,u3,u4,u5,u6,u7,u8,u9,u10,u11,u12,u13,u14,&
31d102b48SJeremy L Thompson&           u15,u16,v1,v2,v3,v4,v5,v6,v7,v8,v9,v10,v11,v12,v13,v14,v15,v16,ierr)
41d102b48SJeremy L Thompson      real*8 ctx
51d102b48SJeremy L Thompson      real*8 u1(1)
61d102b48SJeremy L Thompson      real*8 u2(1)
71d102b48SJeremy L Thompson      real*8 v1(1)
81d102b48SJeremy L Thompson      integer q,ierr
91d102b48SJeremy L Thompson
101d102b48SJeremy L Thompson      do i=1,q
111d102b48SJeremy L Thompson        v1(i)=u1(i)*(u2(i+q*0)*u2(i+q*3)-u2(i+q*1)*u2(i+q*2))
121d102b48SJeremy L Thompson      enddo
131d102b48SJeremy L Thompson
141d102b48SJeremy L Thompson      ierr=0
151d102b48SJeremy L Thompson      end
161d102b48SJeremy L Thompson!-----------------------------------------------------------------------
171d102b48SJeremy L Thompson      subroutine mass(ctx,q,u1,u2,u3,u4,u5,u6,u7,u8,u9,u10,u11,u12,u13,u14,&
181d102b48SJeremy L Thompson&           u15,u16,v1,v2,v3,v4,v5,v6,v7,v8,v9,v10,v11,v12,v13,v14,v15,v16,ierr)
191d102b48SJeremy L Thompson      real*8 ctx
201d102b48SJeremy L Thompson      real*8 u1(1)
211d102b48SJeremy L Thompson      real*8 u2(1)
221d102b48SJeremy L Thompson      real*8 v1(1)
231d102b48SJeremy L Thompson      integer q,ierr
241d102b48SJeremy L Thompson
251d102b48SJeremy L Thompson      do i=1,q
261d102b48SJeremy L Thompson        v1(i)=u2(i)*u1(i)
271d102b48SJeremy L Thompson      enddo
281d102b48SJeremy L Thompson
291d102b48SJeremy L Thompson      ierr=0
301d102b48SJeremy L Thompson      end
311d102b48SJeremy L Thompson!-----------------------------------------------------------------------
321d102b48SJeremy L Thompson      program test
331d102b48SJeremy L Thompson
341d102b48SJeremy L Thompson      include 'ceedf.h'
351d102b48SJeremy L Thompson
361d102b48SJeremy L Thompson      integer ceed,err,i,j,k
3761dbc9d2Sjeremylt      integer imode
3861dbc9d2Sjeremylt      parameter(imode=ceed_noninterlaced)
39*15910d16Sjeremylt      integer stridesu(3)
40*15910d16Sjeremylt      integer erestrictx,erestrictu,erestrictui,erestrictlini
411d102b48SJeremy L Thompson      integer bx,bu
421d102b48SJeremy L Thompson      integer qf_setup,qf_mass
431d102b48SJeremy L Thompson      integer op_setup,op_mass
441d102b48SJeremy L Thompson      integer qdata,x,a,u,v
451d102b48SJeremy L Thompson      integer nelem,p,q,d
461d102b48SJeremy L Thompson      integer row,col,offset
471d102b48SJeremy L Thompson      parameter(nelem=6)
481d102b48SJeremy L Thompson      parameter(p=3)
491d102b48SJeremy L Thompson      parameter(q=4)
501d102b48SJeremy L Thompson      parameter(d=2)
511d102b48SJeremy L Thompson      integer ndofs,nqpts,nx,ny
521d102b48SJeremy L Thompson      parameter(nx=3)
531d102b48SJeremy L Thompson      parameter(ny=2)
541d102b48SJeremy L Thompson      parameter(ndofs=(nx*2+1)*(ny*2+1))
551d102b48SJeremy L Thompson      parameter(nqpts=nelem*q*q)
561d102b48SJeremy L Thompson      integer indx(nelem*p*p)
571d102b48SJeremy L Thompson      real*8 arrx(d*ndofs),aa(nqpts),qq(nqpts),vv(ndofs)
581d102b48SJeremy L Thompson      integer*8 xoffset,aoffset,qoffset,voffset
591d102b48SJeremy L Thompson      real*8 total
601d102b48SJeremy L Thompson
611d102b48SJeremy L Thompson      character arg*32
621d102b48SJeremy L Thompson
631d102b48SJeremy L Thompson      external setup,mass
641d102b48SJeremy L Thompson
651d102b48SJeremy L Thompson      call getarg(1,arg)
661d102b48SJeremy L Thompson
671d102b48SJeremy L Thompson      call ceedinit(trim(arg)//char(0),ceed,err)
681d102b48SJeremy L Thompson
691d102b48SJeremy L Thompson! DoF Coordinates
701d102b48SJeremy L Thompson      do i=0,nx*2
711d102b48SJeremy L Thompson        do j=0,ny*2
721d102b48SJeremy L Thompson          arrx(i+j*(nx*2+1)+0*ndofs+1)=1.d0*i/(2*nx)
731d102b48SJeremy L Thompson          arrx(i+j*(nx*2+1)+1*ndofs+1)=1.d0*j/(2*ny)
741d102b48SJeremy L Thompson        enddo
751d102b48SJeremy L Thompson      enddo
761d102b48SJeremy L Thompson      call ceedvectorcreate(ceed,d*ndofs,x,err)
771d102b48SJeremy L Thompson      xoffset=0
781d102b48SJeremy L Thompson      call ceedvectorsetarray(x,ceed_mem_host,ceed_use_pointer,arrx,xoffset,err)
791d102b48SJeremy L Thompson
801d102b48SJeremy L Thompson! Qdata Vector
811d102b48SJeremy L Thompson      call ceedvectorcreate(ceed,nqpts,qdata,err)
821d102b48SJeremy L Thompson
831d102b48SJeremy L Thompson! Element Setup
841d102b48SJeremy L Thompson      do i=0,nelem-1
851d102b48SJeremy L Thompson        col=mod(i,nx)
861d102b48SJeremy L Thompson        row=i/nx
871d102b48SJeremy L Thompson        offset=col*(p-1)+row*(nx*2+1)*(p-1)
881d102b48SJeremy L Thompson        do j=0,p-1
891d102b48SJeremy L Thompson          do k=0,p-1
901d102b48SJeremy L Thompson            indx(p*(p*i+k)+j+1)=offset+k*(nx*2+1)+j
911d102b48SJeremy L Thompson          enddo
921d102b48SJeremy L Thompson        enddo
931d102b48SJeremy L Thompson      enddo
941d102b48SJeremy L Thompson
951d102b48SJeremy L Thompson! Restrictions
9661dbc9d2Sjeremylt      call ceedelemrestrictioncreate(ceed,imode,nelem,p*p,ndofs,d,&
971d102b48SJeremy L Thompson     & ceed_mem_host,ceed_use_pointer,indx,erestrictx,err)
981d102b48SJeremy L Thompson
9961dbc9d2Sjeremylt      call ceedelemrestrictioncreate(ceed,imode,nelem,p*p,ndofs,1,&
1001d102b48SJeremy L Thompson     & ceed_mem_host,ceed_use_pointer,indx,erestrictu,err)
1017509a596Sjeremylt      stridesu=[1,q*q,q*q]
1027509a596Sjeremylt      call ceedelemrestrictioncreatestrided(ceed,nelem,q*q,nqpts,&
1037509a596Sjeremylt     & 1,stridesu,erestrictui,err)
1041d102b48SJeremy L Thompson
1051d102b48SJeremy L Thompson! Bases
1061d102b48SJeremy L Thompson      call ceedbasiscreatetensorh1lagrange(ceed,d,d,p,q,ceed_gauss,&
1071d102b48SJeremy L Thompson     & bx,err)
1081d102b48SJeremy L Thompson      call ceedbasiscreatetensorh1lagrange(ceed,d,1,p,q,ceed_gauss,&
1091d102b48SJeremy L Thompson     & bu,err)
1101d102b48SJeremy L Thompson
1111d102b48SJeremy L Thompson! QFunctions
1121d102b48SJeremy L Thompson! -- Setup
1131d102b48SJeremy L Thompson      call ceedqfunctioncreateinterior(ceed,1,setup,&
1141d102b48SJeremy L Thompson     &SOURCE_DIR&
115a05f9790Sjeremylt     &//'t510-operator.h:setup'//char(0),qf_setup,err)
1161d102b48SJeremy L Thompson      call ceedqfunctionaddinput(qf_setup,'_weight',1,ceed_eval_weight,err)
1171d102b48SJeremy L Thompson      call ceedqfunctionaddinput(qf_setup,'dx',d*d,ceed_eval_grad,err)
1181d102b48SJeremy L Thompson      call ceedqfunctionaddoutput(qf_setup,'rho',1,ceed_eval_none,err)
1191d102b48SJeremy L Thompson! -- Mass
1201d102b48SJeremy L Thompson      call ceedqfunctioncreateinterior(ceed,1,mass,&
1211d102b48SJeremy L Thompson     &SOURCE_DIR&
122a05f9790Sjeremylt     &//'t510-operator.h:mass'//char(0),qf_mass,err)
1231d102b48SJeremy L Thompson      call ceedqfunctionaddinput(qf_mass,'rho',1,ceed_eval_none,err)
1241d102b48SJeremy L Thompson      call ceedqfunctionaddinput(qf_mass,'u',1,ceed_eval_interp,err)
1251d102b48SJeremy L Thompson      call ceedqfunctionaddoutput(qf_mass,'v',1,ceed_eval_interp,err)
1261d102b48SJeremy L Thompson
1271d102b48SJeremy L Thompson! Operators
1281d102b48SJeremy L Thompson! -- Setup
129442e7f0bSjeremylt      call ceedoperatorcreate(ceed,qf_setup,ceed_qfunction_none,&
130442e7f0bSjeremylt     & ceed_qfunction_none,op_setup,err)
131*15910d16Sjeremylt      call ceedoperatorsetfield(op_setup,'_weight',ceed_elemrestriction_none,&
132a8d32208Sjeremylt     & bx,ceed_vector_none,err)
1331d102b48SJeremy L Thompson      call ceedoperatorsetfield(op_setup,'dx',erestrictx,&
134a8d32208Sjeremylt     & bx,ceed_vector_active,err)
1351d102b48SJeremy L Thompson      call ceedoperatorsetfield(op_setup,'rho',erestrictui,&
136a8d32208Sjeremylt     & ceed_basis_collocated,ceed_vector_active,err)
1371d102b48SJeremy L Thompson! -- Mass
138442e7f0bSjeremylt      call ceedoperatorcreate(ceed,qf_mass,ceed_qfunction_none,&
139442e7f0bSjeremylt     & ceed_qfunction_none,op_mass,err)
1401d102b48SJeremy L Thompson      call ceedoperatorsetfield(op_mass,'rho',erestrictui,&
141a8d32208Sjeremylt     & ceed_basis_collocated,qdata,err)
1421d102b48SJeremy L Thompson      call ceedoperatorsetfield(op_mass,'u',erestrictu,&
143a8d32208Sjeremylt     & bu,ceed_vector_active,err)
1441d102b48SJeremy L Thompson      call ceedoperatorsetfield(op_mass,'v',erestrictu,&
145a8d32208Sjeremylt     & bu,ceed_vector_active,err)
1461d102b48SJeremy L Thompson
1471d102b48SJeremy L Thompson! Apply Setup Operator
1481d102b48SJeremy L Thompson      call ceedoperatorapply(op_setup,x,qdata,ceed_request_immediate,err)
1491d102b48SJeremy L Thompson
1501d102b48SJeremy L Thompson! Assemble QFunction
1511d102b48SJeremy L Thompson      call ceedoperatorassemblelinearqfunction(op_mass,a,erestrictlini,&
1521d102b48SJeremy L Thompson     & ceed_request_immediate,err)
1531d102b48SJeremy L Thompson
1541d102b48SJeremy L Thompson! Check Output
1551d102b48SJeremy L Thompson      call ceedvectorgetarrayread(a,ceed_mem_host,aa,aoffset,err)
1561d102b48SJeremy L Thompson      call ceedvectorgetarrayread(qdata,ceed_mem_host,qq,qoffset,err)
1571d102b48SJeremy L Thompson      do i=1,nqpts
1581d102b48SJeremy L Thompson        if (abs(qq(qoffset+i)-aa(aoffset+i))>1.0d-9) then
1591d102b48SJeremy L Thompson! LCOV_EXCL_START
1601d102b48SJeremy L Thompson          write(*,*) 'Error: A[',i,'] = ',aa(aoffset+i),' != ',&
1611d102b48SJeremy L Thompson     &      qq(qoffset+i)
1621d102b48SJeremy L Thompson! LCOV_EXCL_STOP
1631d102b48SJeremy L Thompson        endif
1641d102b48SJeremy L Thompson      enddo
1651d102b48SJeremy L Thompson      call ceedvectorrestorearrayread(a,aa,aoffset,err)
1661d102b48SJeremy L Thompson      call ceedvectorrestorearrayread(qdata,qq,qoffset,err)
1671d102b48SJeremy L Thompson
1681d102b48SJeremy L Thompson! Apply original Mass Operator
1691d102b48SJeremy L Thompson      call ceedvectorcreate(ceed,ndofs,u,err)
1701d102b48SJeremy L Thompson      call ceedvectorsetvalue(u,1.d0,err)
1711d102b48SJeremy L Thompson      call ceedvectorcreate(ceed,ndofs,v,err)
1721d102b48SJeremy L Thompson      call ceedvectorsetvalue(v,0.d0,err)
1731d102b48SJeremy L Thompson      call ceedoperatorapply(op_mass,u,v,ceed_request_immediate,err)
1741d102b48SJeremy L Thompson
1751d102b48SJeremy L Thompson! Check Output
1761d102b48SJeremy L Thompson      call ceedvectorgetarrayread(v,ceed_mem_host,vv,voffset,err)
1771d102b48SJeremy L Thompson      total=0.
1781d102b48SJeremy L Thompson      do i=1,ndofs
1791d102b48SJeremy L Thompson        total=total+vv(voffset+i)
1801d102b48SJeremy L Thompson      enddo
1811d102b48SJeremy L Thompson      if (abs(total-1.)>1.0d-14) then
1821d102b48SJeremy L Thompson! LCOV_EXCL_START
1831d102b48SJeremy L Thompson        write(*,*) 'Error: True operator computed area = ',total,' != 1.0'
1841d102b48SJeremy L Thompson! LCOV_EXCL_STOP
1851d102b48SJeremy L Thompson      endif
1861d102b48SJeremy L Thompson      call ceedvectorrestorearrayread(v,vv,voffset,err)
1871d102b48SJeremy L Thompson
1881d102b48SJeremy L Thompson! Switch to new qdata
1891d102b48SJeremy L Thompson      call ceedvectorgetarrayread(a,ceed_mem_host,aa,aoffset,err)
1901d102b48SJeremy L Thompson      call ceedvectorsetarray(qdata,ceed_mem_host,ceed_copy_values,aa,&
1911d102b48SJeremy L Thompson     & aoffset,err)
1921d102b48SJeremy L Thompson      call ceedvectorrestorearrayread(a,aa,aoffset,err)
1931d102b48SJeremy L Thompson
1941d102b48SJeremy L Thompson! Apply new Mass Operator
1951d102b48SJeremy L Thompson      call ceedvectorsetvalue(v,0.d0,err)
1961d102b48SJeremy L Thompson      call ceedoperatorapply(op_mass,u,v,ceed_request_immediate,err)
1971d102b48SJeremy L Thompson
1981d102b48SJeremy L Thompson! Check Output
1991d102b48SJeremy L Thompson      call ceedvectorgetarrayread(v,ceed_mem_host,vv,voffset,err)
2001d102b48SJeremy L Thompson      total=0.
2011d102b48SJeremy L Thompson      do i=1,ndofs
2021d102b48SJeremy L Thompson        total=total+vv(voffset+i)
2031d102b48SJeremy L Thompson      enddo
2041d102b48SJeremy L Thompson      if (abs(total-1.)>1.0d-10) then
2051d102b48SJeremy L Thompson! LCOV_EXCL_START
2061d102b48SJeremy L Thompson        write(*,*) 'Error: Assembled operator computed area = ',total,' != 1.0'
2071d102b48SJeremy L Thompson! LCOV_EXCL_STOP
2081d102b48SJeremy L Thompson      endif
2091d102b48SJeremy L Thompson      call ceedvectorrestorearrayread(v,vv,voffset,err)
2101d102b48SJeremy L Thompson
2111d102b48SJeremy L Thompson! Cleanup
2121d102b48SJeremy L Thompson      call ceedqfunctiondestroy(qf_setup,err)
2131d102b48SJeremy L Thompson      call ceedqfunctiondestroy(qf_mass,err)
2141d102b48SJeremy L Thompson      call ceedoperatordestroy(op_setup,err)
2151d102b48SJeremy L Thompson      call ceedoperatordestroy(op_mass,err)
2161d102b48SJeremy L Thompson      call ceedelemrestrictiondestroy(erestrictu,err)
2171d102b48SJeremy L Thompson      call ceedelemrestrictiondestroy(erestrictx,err)
2181d102b48SJeremy L Thompson      call ceedelemrestrictiondestroy(erestrictui,err)
2191d102b48SJeremy L Thompson      call ceedelemrestrictiondestroy(erestrictlini,err)
2201d102b48SJeremy L Thompson      call ceedbasisdestroy(bu,err)
2211d102b48SJeremy L Thompson      call ceedbasisdestroy(bx,err)
2221d102b48SJeremy L Thompson      call ceedvectordestroy(x,err)
2231d102b48SJeremy L Thompson      call ceedvectordestroy(a,err)
2241d102b48SJeremy L Thompson      call ceedvectordestroy(u,err)
2251d102b48SJeremy L Thompson      call ceedvectordestroy(v,err)
2261d102b48SJeremy L Thompson      call ceedvectordestroy(qdata,err)
2271d102b48SJeremy L Thompson      call ceeddestroy(ceed,err)
2281d102b48SJeremy L Thompson      end
2291d102b48SJeremy L Thompson!-----------------------------------------------------------------------
230