xref: /libCEED/tests/t530-operator-f.f90 (revision 7509a596beda7c1d002d2274a17375b09541fdb6)
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*7509a596Sjeremylt      integer stridesx(3),stridesu(3)
401d102b48SJeremy L Thompson      integer erestrictx,erestrictu,erestrictxi,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)
98*7509a596Sjeremylt      stridesx=[1,p*p,p*p*d]
99*7509a596Sjeremylt      call ceedelemrestrictioncreatestrided(ceed,nelem,p*p,&
100*7509a596Sjeremylt     & nelem*p*p,d,stridesx,erestrictxi,err)
1011d102b48SJeremy L Thompson
10261dbc9d2Sjeremylt      call ceedelemrestrictioncreate(ceed,imode,nelem,p*p,ndofs,1,&
1031d102b48SJeremy L Thompson     & ceed_mem_host,ceed_use_pointer,indx,erestrictu,err)
104*7509a596Sjeremylt      stridesu=[1,q*q,q*q]
105*7509a596Sjeremylt      call ceedelemrestrictioncreatestrided(ceed,nelem,q*q,nqpts,&
106*7509a596Sjeremylt     & 1,stridesu,erestrictui,err)
1071d102b48SJeremy L Thompson
1081d102b48SJeremy L Thompson! Bases
1091d102b48SJeremy L Thompson      call ceedbasiscreatetensorh1lagrange(ceed,d,d,p,q,ceed_gauss,&
1101d102b48SJeremy L Thompson     & bx,err)
1111d102b48SJeremy L Thompson      call ceedbasiscreatetensorh1lagrange(ceed,d,1,p,q,ceed_gauss,&
1121d102b48SJeremy L Thompson     & bu,err)
1131d102b48SJeremy L Thompson
1141d102b48SJeremy L Thompson! QFunctions
1151d102b48SJeremy L Thompson! -- Setup
1161d102b48SJeremy L Thompson      call ceedqfunctioncreateinterior(ceed,1,setup,&
1171d102b48SJeremy L Thompson     &SOURCE_DIR&
118a05f9790Sjeremylt     &//'t510-operator.h:setup'//char(0),qf_setup,err)
1191d102b48SJeremy L Thompson      call ceedqfunctionaddinput(qf_setup,'_weight',1,ceed_eval_weight,err)
1201d102b48SJeremy L Thompson      call ceedqfunctionaddinput(qf_setup,'dx',d*d,ceed_eval_grad,err)
1211d102b48SJeremy L Thompson      call ceedqfunctionaddoutput(qf_setup,'rho',1,ceed_eval_none,err)
1221d102b48SJeremy L Thompson! -- Mass
1231d102b48SJeremy L Thompson      call ceedqfunctioncreateinterior(ceed,1,mass,&
1241d102b48SJeremy L Thompson     &SOURCE_DIR&
125a05f9790Sjeremylt     &//'t510-operator.h:mass'//char(0),qf_mass,err)
1261d102b48SJeremy L Thompson      call ceedqfunctionaddinput(qf_mass,'rho',1,ceed_eval_none,err)
1271d102b48SJeremy L Thompson      call ceedqfunctionaddinput(qf_mass,'u',1,ceed_eval_interp,err)
1281d102b48SJeremy L Thompson      call ceedqfunctionaddoutput(qf_mass,'v',1,ceed_eval_interp,err)
1291d102b48SJeremy L Thompson
1301d102b48SJeremy L Thompson! Operators
1311d102b48SJeremy L Thompson! -- Setup
132442e7f0bSjeremylt      call ceedoperatorcreate(ceed,qf_setup,ceed_qfunction_none,&
133442e7f0bSjeremylt     & ceed_qfunction_none,op_setup,err)
1341d102b48SJeremy L Thompson      call ceedoperatorsetfield(op_setup,'_weight',erestrictxi,&
135a8d32208Sjeremylt     & bx,ceed_vector_none,err)
1361d102b48SJeremy L Thompson      call ceedoperatorsetfield(op_setup,'dx',erestrictx,&
137a8d32208Sjeremylt     & bx,ceed_vector_active,err)
1381d102b48SJeremy L Thompson      call ceedoperatorsetfield(op_setup,'rho',erestrictui,&
139a8d32208Sjeremylt     & ceed_basis_collocated,ceed_vector_active,err)
1401d102b48SJeremy L Thompson! -- Mass
141442e7f0bSjeremylt      call ceedoperatorcreate(ceed,qf_mass,ceed_qfunction_none,&
142442e7f0bSjeremylt     & ceed_qfunction_none,op_mass,err)
1431d102b48SJeremy L Thompson      call ceedoperatorsetfield(op_mass,'rho',erestrictui,&
144a8d32208Sjeremylt     & ceed_basis_collocated,qdata,err)
1451d102b48SJeremy L Thompson      call ceedoperatorsetfield(op_mass,'u',erestrictu,&
146a8d32208Sjeremylt     & bu,ceed_vector_active,err)
1471d102b48SJeremy L Thompson      call ceedoperatorsetfield(op_mass,'v',erestrictu,&
148a8d32208Sjeremylt     & bu,ceed_vector_active,err)
1491d102b48SJeremy L Thompson
1501d102b48SJeremy L Thompson! Apply Setup Operator
1511d102b48SJeremy L Thompson      call ceedoperatorapply(op_setup,x,qdata,ceed_request_immediate,err)
1521d102b48SJeremy L Thompson
1531d102b48SJeremy L Thompson! Assemble QFunction
1541d102b48SJeremy L Thompson      call ceedoperatorassemblelinearqfunction(op_mass,a,erestrictlini,&
1551d102b48SJeremy L Thompson     & ceed_request_immediate,err)
1561d102b48SJeremy L Thompson
1571d102b48SJeremy L Thompson! Check Output
1581d102b48SJeremy L Thompson      call ceedvectorgetarrayread(a,ceed_mem_host,aa,aoffset,err)
1591d102b48SJeremy L Thompson      call ceedvectorgetarrayread(qdata,ceed_mem_host,qq,qoffset,err)
1601d102b48SJeremy L Thompson      do i=1,nqpts
1611d102b48SJeremy L Thompson        if (abs(qq(qoffset+i)-aa(aoffset+i))>1.0d-9) then
1621d102b48SJeremy L Thompson! LCOV_EXCL_START
1631d102b48SJeremy L Thompson          write(*,*) 'Error: A[',i,'] = ',aa(aoffset+i),' != ',&
1641d102b48SJeremy L Thompson     &      qq(qoffset+i)
1651d102b48SJeremy L Thompson! LCOV_EXCL_STOP
1661d102b48SJeremy L Thompson        endif
1671d102b48SJeremy L Thompson      enddo
1681d102b48SJeremy L Thompson      call ceedvectorrestorearrayread(a,aa,aoffset,err)
1691d102b48SJeremy L Thompson      call ceedvectorrestorearrayread(qdata,qq,qoffset,err)
1701d102b48SJeremy L Thompson
1711d102b48SJeremy L Thompson! Apply original Mass Operator
1721d102b48SJeremy L Thompson      call ceedvectorcreate(ceed,ndofs,u,err)
1731d102b48SJeremy L Thompson      call ceedvectorsetvalue(u,1.d0,err)
1741d102b48SJeremy L Thompson      call ceedvectorcreate(ceed,ndofs,v,err)
1751d102b48SJeremy L Thompson      call ceedvectorsetvalue(v,0.d0,err)
1761d102b48SJeremy L Thompson      call ceedoperatorapply(op_mass,u,v,ceed_request_immediate,err)
1771d102b48SJeremy L Thompson
1781d102b48SJeremy L Thompson! Check Output
1791d102b48SJeremy L Thompson      call ceedvectorgetarrayread(v,ceed_mem_host,vv,voffset,err)
1801d102b48SJeremy L Thompson      total=0.
1811d102b48SJeremy L Thompson      do i=1,ndofs
1821d102b48SJeremy L Thompson        total=total+vv(voffset+i)
1831d102b48SJeremy L Thompson      enddo
1841d102b48SJeremy L Thompson      if (abs(total-1.)>1.0d-14) then
1851d102b48SJeremy L Thompson! LCOV_EXCL_START
1861d102b48SJeremy L Thompson        write(*,*) 'Error: True operator computed area = ',total,' != 1.0'
1871d102b48SJeremy L Thompson! LCOV_EXCL_STOP
1881d102b48SJeremy L Thompson      endif
1891d102b48SJeremy L Thompson      call ceedvectorrestorearrayread(v,vv,voffset,err)
1901d102b48SJeremy L Thompson
1911d102b48SJeremy L Thompson! Switch to new qdata
1921d102b48SJeremy L Thompson      call ceedvectorgetarrayread(a,ceed_mem_host,aa,aoffset,err)
1931d102b48SJeremy L Thompson      call ceedvectorsetarray(qdata,ceed_mem_host,ceed_copy_values,aa,&
1941d102b48SJeremy L Thompson     & aoffset,err)
1951d102b48SJeremy L Thompson      call ceedvectorrestorearrayread(a,aa,aoffset,err)
1961d102b48SJeremy L Thompson
1971d102b48SJeremy L Thompson! Apply new Mass Operator
1981d102b48SJeremy L Thompson      call ceedvectorsetvalue(v,0.d0,err)
1991d102b48SJeremy L Thompson      call ceedoperatorapply(op_mass,u,v,ceed_request_immediate,err)
2001d102b48SJeremy L Thompson
2011d102b48SJeremy L Thompson! Check Output
2021d102b48SJeremy L Thompson      call ceedvectorgetarrayread(v,ceed_mem_host,vv,voffset,err)
2031d102b48SJeremy L Thompson      total=0.
2041d102b48SJeremy L Thompson      do i=1,ndofs
2051d102b48SJeremy L Thompson        total=total+vv(voffset+i)
2061d102b48SJeremy L Thompson      enddo
2071d102b48SJeremy L Thompson      if (abs(total-1.)>1.0d-10) then
2081d102b48SJeremy L Thompson! LCOV_EXCL_START
2091d102b48SJeremy L Thompson        write(*,*) 'Error: Assembled operator computed area = ',total,' != 1.0'
2101d102b48SJeremy L Thompson! LCOV_EXCL_STOP
2111d102b48SJeremy L Thompson      endif
2121d102b48SJeremy L Thompson      call ceedvectorrestorearrayread(v,vv,voffset,err)
2131d102b48SJeremy L Thompson
2141d102b48SJeremy L Thompson! Cleanup
2151d102b48SJeremy L Thompson      call ceedqfunctiondestroy(qf_setup,err)
2161d102b48SJeremy L Thompson      call ceedqfunctiondestroy(qf_mass,err)
2171d102b48SJeremy L Thompson      call ceedoperatordestroy(op_setup,err)
2181d102b48SJeremy L Thompson      call ceedoperatordestroy(op_mass,err)
2191d102b48SJeremy L Thompson      call ceedelemrestrictiondestroy(erestrictu,err)
2201d102b48SJeremy L Thompson      call ceedelemrestrictiondestroy(erestrictx,err)
2211d102b48SJeremy L Thompson      call ceedelemrestrictiondestroy(erestrictui,err)
2221d102b48SJeremy L Thompson      call ceedelemrestrictiondestroy(erestrictxi,err)
2231d102b48SJeremy L Thompson      call ceedelemrestrictiondestroy(erestrictlini,err)
2241d102b48SJeremy L Thompson      call ceedbasisdestroy(bu,err)
2251d102b48SJeremy L Thompson      call ceedbasisdestroy(bx,err)
2261d102b48SJeremy L Thompson      call ceedvectordestroy(x,err)
2271d102b48SJeremy L Thompson      call ceedvectordestroy(a,err)
2281d102b48SJeremy L Thompson      call ceedvectordestroy(u,err)
2291d102b48SJeremy L Thompson      call ceedvectordestroy(v,err)
2301d102b48SJeremy L Thompson      call ceedvectordestroy(qdata,err)
2311d102b48SJeremy L Thompson      call ceeddestroy(ceed,err)
2321d102b48SJeremy L Thompson      end
2331d102b48SJeremy L Thompson!-----------------------------------------------------------------------
234