xref: /libCEED/tests/t533-operator-f.f90 (revision d9b786505a4dfcb66b2fcd9e3b61dd507168515d)
1b7ec98d8SJeremy L Thompson!-----------------------------------------------------------------------
2752c3701SJeremy L Thompson!
3752c3701SJeremy L Thompson! Header with QFunctions
4752c3701SJeremy L Thompson!
5752c3701SJeremy L Thompson      include 't510-operator-f.h'
6b7ec98d8SJeremy L Thompson!-----------------------------------------------------------------------
7b7ec98d8SJeremy L Thompson      program test
81f9a83abSJed Brown      implicit none
9ec3da8bcSJed Brown      include 'ceed/fortran.h'
10b7ec98d8SJeremy L Thompson
11b7ec98d8SJeremy L Thompson      integer ceed,err,i,j,k
1215910d16Sjeremylt      integer stridesu(3)
1315910d16Sjeremylt      integer erestrictx,erestrictu,erestrictui
14b7ec98d8SJeremy L Thompson      integer bx,bu
15b7ec98d8SJeremy L Thompson      integer qf_setup,qf_mass
16b7ec98d8SJeremy L Thompson      integer op_setup,op_mass
17b7ec98d8SJeremy L Thompson      integer qdata,x,a,u,v
18b7ec98d8SJeremy L Thompson      integer nelem,p,q,d
19b7ec98d8SJeremy L Thompson      integer row,col,offset
20b7ec98d8SJeremy L Thompson      parameter(nelem=6)
21b7ec98d8SJeremy L Thompson      parameter(p=3)
22b7ec98d8SJeremy L Thompson      parameter(q=4)
23b7ec98d8SJeremy L Thompson      parameter(d=2)
24b7ec98d8SJeremy L Thompson      integer ndofs,nqpts,nx,ny
25b7ec98d8SJeremy L Thompson      parameter(nx=3)
26b7ec98d8SJeremy L Thompson      parameter(ny=2)
27b7ec98d8SJeremy L Thompson      parameter(ndofs=(nx*2+1)*(ny*2+1))
28b7ec98d8SJeremy L Thompson      parameter(nqpts=nelem*q*q)
29b7ec98d8SJeremy L Thompson      integer indx(nelem*p*p)
30b7ec98d8SJeremy L Thompson      real*8 arrx(d*ndofs),aa(nqpts),uu(ndofs),vv(ndofs),atrue(ndofs)
31b7ec98d8SJeremy L Thompson      integer*8 xoffset,aoffset,uoffset,voffset
32b7ec98d8SJeremy L Thompson
33b7ec98d8SJeremy L Thompson      character arg*32
34b7ec98d8SJeremy L Thompson
35b7ec98d8SJeremy L Thompson      external setup,mass
36b7ec98d8SJeremy L Thompson
37b7ec98d8SJeremy L Thompson      call getarg(1,arg)
38b7ec98d8SJeremy L Thompson
39b7ec98d8SJeremy L Thompson      call ceedinit(trim(arg)//char(0),ceed,err)
40b7ec98d8SJeremy L Thompson
41b7ec98d8SJeremy L Thompson! DoF Coordinates
42b7ec98d8SJeremy L Thompson      do i=0,nx*2
43b7ec98d8SJeremy L Thompson        do j=0,ny*2
44b7ec98d8SJeremy L Thompson          arrx(i+j*(nx*2+1)+0*ndofs+1)=1.d0*i/(2*nx)
45b7ec98d8SJeremy L Thompson          arrx(i+j*(nx*2+1)+1*ndofs+1)=1.d0*j/(2*ny)
46b7ec98d8SJeremy L Thompson        enddo
47b7ec98d8SJeremy L Thompson      enddo
48b7ec98d8SJeremy L Thompson      call ceedvectorcreate(ceed,d*ndofs,x,err)
49b7ec98d8SJeremy L Thompson      xoffset=0
50b7ec98d8SJeremy L Thompson      call ceedvectorsetarray(x,ceed_mem_host,ceed_use_pointer,arrx,xoffset,err)
51b7ec98d8SJeremy L Thompson
52b7ec98d8SJeremy L Thompson! Qdata Vector
53b7ec98d8SJeremy L Thompson      call ceedvectorcreate(ceed,nqpts,qdata,err)
54b7ec98d8SJeremy L Thompson
55b7ec98d8SJeremy L Thompson! Element Setup
56b7ec98d8SJeremy L Thompson      do i=0,nelem-1
57b7ec98d8SJeremy L Thompson        col=mod(i,nx)
58b7ec98d8SJeremy L Thompson        row=i/nx
59b7ec98d8SJeremy L Thompson        offset=col*(p-1)+row*(nx*2+1)*(p-1)
60b7ec98d8SJeremy L Thompson        do j=0,p-1
61b7ec98d8SJeremy L Thompson          do k=0,p-1
62b7ec98d8SJeremy L Thompson            indx(p*(p*i+k)+j+1)=offset+k*(nx*2+1)+j
63b7ec98d8SJeremy L Thompson          enddo
64b7ec98d8SJeremy L Thompson        enddo
65b7ec98d8SJeremy L Thompson      enddo
66b7ec98d8SJeremy L Thompson
67b7ec98d8SJeremy L Thompson! Restrictions
68d979a051Sjeremylt      call ceedelemrestrictioncreate(ceed,nelem,p*p,d,ndofs,d*ndofs,&
69b7ec98d8SJeremy L Thompson     & ceed_mem_host,ceed_use_pointer,indx,erestrictx,err)
70b7ec98d8SJeremy L Thompson
71d979a051Sjeremylt      call ceedelemrestrictioncreate(ceed,nelem,p*p,1,1,ndofs,&
72b7ec98d8SJeremy L Thompson     & ceed_mem_host,ceed_use_pointer,indx,erestrictu,err)
737509a596Sjeremylt      stridesu=[1,q*q,q*q]
74d979a051Sjeremylt      call ceedelemrestrictioncreatestrided(ceed,nelem,q*q,1,nqpts,&
75d979a051Sjeremylt     & stridesu,erestrictui,err)
76b7ec98d8SJeremy L Thompson
77b7ec98d8SJeremy L Thompson! Bases
78b7ec98d8SJeremy L Thompson      call ceedbasiscreatetensorh1lagrange(ceed,d,d,p,q,ceed_gauss,&
79b7ec98d8SJeremy L Thompson     & bx,err)
80b7ec98d8SJeremy L Thompson      call ceedbasiscreatetensorh1lagrange(ceed,d,1,p,q,ceed_gauss,&
81b7ec98d8SJeremy L Thompson     & bu,err)
82b7ec98d8SJeremy L Thompson
83b7ec98d8SJeremy L Thompson! QFunctions
84b7ec98d8SJeremy L Thompson! -- Setup
85b7ec98d8SJeremy L Thompson      call ceedqfunctioncreateinterior(ceed,1,setup,&
86b7ec98d8SJeremy L Thompson     &SOURCE_DIR&
87a05f9790Sjeremylt     &//'t510-operator.h:setup'//char(0),qf_setup,err)
88a61c78d6SJeremy L Thompson      call ceedqfunctionaddinput(qf_setup,'weight',1,ceed_eval_weight,err)
89b7ec98d8SJeremy L Thompson      call ceedqfunctionaddinput(qf_setup,'dx',d*d,ceed_eval_grad,err)
90b7ec98d8SJeremy L Thompson      call ceedqfunctionaddoutput(qf_setup,'rho',1,ceed_eval_none,err)
91b7ec98d8SJeremy L Thompson! -- Mass
92b7ec98d8SJeremy L Thompson      call ceedqfunctioncreateinterior(ceed,1,mass,&
93b7ec98d8SJeremy L Thompson     &SOURCE_DIR&
94a05f9790Sjeremylt     &//'t510-operator.h:mass'//char(0),qf_mass,err)
95b7ec98d8SJeremy L Thompson      call ceedqfunctionaddinput(qf_mass,'rho',1,ceed_eval_none,err)
96b7ec98d8SJeremy L Thompson      call ceedqfunctionaddinput(qf_mass,'u',1,ceed_eval_interp,err)
97b7ec98d8SJeremy L Thompson      call ceedqfunctionaddoutput(qf_mass,'v',1,ceed_eval_interp,err)
98b7ec98d8SJeremy L Thompson
99b7ec98d8SJeremy L Thompson! Operators
100b7ec98d8SJeremy L Thompson! -- Setup
101442e7f0bSjeremylt      call ceedoperatorcreate(ceed,qf_setup,ceed_qfunction_none,&
102442e7f0bSjeremylt     & ceed_qfunction_none,op_setup,err)
103a61c78d6SJeremy L Thompson      call ceedoperatorsetfield(op_setup,'weight',ceed_elemrestriction_none,&
104a8d32208Sjeremylt     & bx,ceed_vector_none,err)
105b7ec98d8SJeremy L Thompson      call ceedoperatorsetfield(op_setup,'dx',erestrictx,&
106a8d32208Sjeremylt     & bx,ceed_vector_active,err)
107b7ec98d8SJeremy L Thompson      call ceedoperatorsetfield(op_setup,'rho',erestrictui,&
108*356036faSJeremy L Thompson     ceed_basis_none,ceed_vector_active,err)
109b7ec98d8SJeremy L Thompson! -- Mass
110442e7f0bSjeremylt      call ceedoperatorcreate(ceed,qf_mass,ceed_qfunction_none,&
111442e7f0bSjeremylt     & ceed_qfunction_none,op_mass,err)
112b7ec98d8SJeremy L Thompson      call ceedoperatorsetfield(op_mass,'rho',erestrictui,&
113*356036faSJeremy L Thompson     ceed_basis_none,qdata,err)
114b7ec98d8SJeremy L Thompson      call ceedoperatorsetfield(op_mass,'u',erestrictu,&
115a8d32208Sjeremylt     & bu,ceed_vector_active,err)
116b7ec98d8SJeremy L Thompson      call ceedoperatorsetfield(op_mass,'v',erestrictu,&
117a8d32208Sjeremylt     & bu,ceed_vector_active,err)
118b7ec98d8SJeremy L Thompson
119b7ec98d8SJeremy L Thompson! Apply Setup Operator
120b7ec98d8SJeremy L Thompson      call ceedoperatorapply(op_setup,x,qdata,ceed_request_immediate,err)
121b7ec98d8SJeremy L Thompson
122b7ec98d8SJeremy L Thompson! Assemble Diagonal
1232bba3ffaSJeremy L Thompson      call ceedvectorcreate(ceed,ndofs,a,err)
12480ac2e43SJeremy L Thompson      call ceedoperatorlinearassemblediagonal(op_mass,a,&
125b7ec98d8SJeremy L Thompson     & ceed_request_immediate,err)
126b7ec98d8SJeremy L Thompson
127b7ec98d8SJeremy L Thompson! Manually assemble diagonal
128b7ec98d8SJeremy L Thompson      call ceedvectorcreate(ceed,ndofs,u,err)
129b7ec98d8SJeremy L Thompson      call ceedvectorsetvalue(u,0.d0,err)
130b7ec98d8SJeremy L Thompson      call ceedvectorcreate(ceed,ndofs,v,err)
131b7ec98d8SJeremy L Thompson      do i=1,ndofs
132b7ec98d8SJeremy L Thompson        call ceedvectorgetarray(u,ceed_mem_host,uu,uoffset,err)
133b7ec98d8SJeremy L Thompson        uu(i+uoffset)=1.d0
134b7ec98d8SJeremy L Thompson        if (i>1) then
135b7ec98d8SJeremy L Thompson          uu(i-1+uoffset)=0.d0
136b7ec98d8SJeremy L Thompson        endif
137b7ec98d8SJeremy L Thompson        call ceedvectorrestorearray(u,uu,uoffset,err)
138b7ec98d8SJeremy L Thompson
139b7ec98d8SJeremy L Thompson        call ceedoperatorapply(op_mass,u,v,ceed_request_immediate,err)
140b7ec98d8SJeremy L Thompson
141b7ec98d8SJeremy L Thompson        call ceedvectorgetarrayread(v,ceed_mem_host,vv,voffset,err)
142b7ec98d8SJeremy L Thompson        atrue(i)=vv(voffset+i)
143b7ec98d8SJeremy L Thompson        call ceedvectorrestorearrayread(v,vv,voffset,err)
144b7ec98d8SJeremy L Thompson      enddo
145b7ec98d8SJeremy L Thompson
146b7ec98d8SJeremy L Thompson! Check Output
147b7ec98d8SJeremy L Thompson      call ceedvectorgetarrayread(a,ceed_mem_host,aa,aoffset,err)
148b7ec98d8SJeremy L Thompson      do i=1,ndofs
149b7ec98d8SJeremy L Thompson        if (abs(aa(aoffset+i)-atrue(i))>1.0d-14) then
150b7ec98d8SJeremy L Thompson! LCOV_EXCL_START
151b7ec98d8SJeremy L Thompson          write(*,*) '[',i,'] Error in assembly: ',aa(aoffset+i),' != ',&
152b7ec98d8SJeremy L Thompson     &      atrue(i)
153b7ec98d8SJeremy L Thompson! LCOV_EXCL_STOP
154b7ec98d8SJeremy L Thompson        endif
155b7ec98d8SJeremy L Thompson      enddo
156b7ec98d8SJeremy L Thompson      call ceedvectorrestorearrayread(a,aa,aoffset,err)
157b7ec98d8SJeremy L Thompson
158b7ec98d8SJeremy L Thompson! Cleanup
159b7ec98d8SJeremy L Thompson      call ceedqfunctiondestroy(qf_setup,err)
160b7ec98d8SJeremy L Thompson      call ceedqfunctiondestroy(qf_mass,err)
161b7ec98d8SJeremy L Thompson      call ceedoperatordestroy(op_setup,err)
162b7ec98d8SJeremy L Thompson      call ceedoperatordestroy(op_mass,err)
163b7ec98d8SJeremy L Thompson      call ceedelemrestrictiondestroy(erestrictu,err)
164b7ec98d8SJeremy L Thompson      call ceedelemrestrictiondestroy(erestrictx,err)
165b7ec98d8SJeremy L Thompson      call ceedelemrestrictiondestroy(erestrictui,err)
166b7ec98d8SJeremy L Thompson      call ceedbasisdestroy(bu,err)
167b7ec98d8SJeremy L Thompson      call ceedbasisdestroy(bx,err)
168b7ec98d8SJeremy L Thompson      call ceedvectordestroy(x,err)
169b7ec98d8SJeremy L Thompson      call ceedvectordestroy(a,err)
170b7ec98d8SJeremy L Thompson      call ceedvectordestroy(u,err)
171b7ec98d8SJeremy L Thompson      call ceedvectordestroy(v,err)
172b7ec98d8SJeremy L Thompson      call ceedvectordestroy(qdata,err)
173b7ec98d8SJeremy L Thompson      call ceeddestroy(ceed,err)
174b7ec98d8SJeremy L Thompson      end
175b7ec98d8SJeremy L Thompson!-----------------------------------------------------------------------
176