xref: /libCEED/tests/t533-operator-f.f90 (revision a05f97901b895e32eec0b6702c716da036e3d97e)
1b7ec98d8SJeremy L Thompson!-----------------------------------------------------------------------
2b7ec98d8SJeremy L Thompson      subroutine setup(ctx,q,u1,u2,u3,u4,u5,u6,u7,u8,u9,u10,u11,u12,u13,u14,&
3b7ec98d8SJeremy L Thompson&           u15,u16,v1,v2,v3,v4,v5,v6,v7,v8,v9,v10,v11,v12,v13,v14,v15,v16,ierr)
4b7ec98d8SJeremy L Thompson      real*8 ctx
5b7ec98d8SJeremy L Thompson      real*8 u1(1)
6b7ec98d8SJeremy L Thompson      real*8 u2(1)
7b7ec98d8SJeremy L Thompson      real*8 v1(1)
8b7ec98d8SJeremy L Thompson      integer q,ierr
9b7ec98d8SJeremy L Thompson
10b7ec98d8SJeremy L Thompson      do i=1,q
11b7ec98d8SJeremy L Thompson        v1(i)=u1(i)*(u2(i+q*0)*u2(i+q*3)-u2(i+q*1)*u2(i+q*2))
12b7ec98d8SJeremy L Thompson      enddo
13b7ec98d8SJeremy L Thompson
14b7ec98d8SJeremy L Thompson      ierr=0
15b7ec98d8SJeremy L Thompson      end
16b7ec98d8SJeremy L Thompson!-----------------------------------------------------------------------
17b7ec98d8SJeremy L Thompson      subroutine mass(ctx,q,u1,u2,u3,u4,u5,u6,u7,u8,u9,u10,u11,u12,u13,u14,&
18b7ec98d8SJeremy L Thompson&           u15,u16,v1,v2,v3,v4,v5,v6,v7,v8,v9,v10,v11,v12,v13,v14,v15,v16,ierr)
19b7ec98d8SJeremy L Thompson      real*8 ctx
20b7ec98d8SJeremy L Thompson      real*8 u1(1)
21b7ec98d8SJeremy L Thompson      real*8 u2(1)
22b7ec98d8SJeremy L Thompson      real*8 v1(1)
23b7ec98d8SJeremy L Thompson      integer q,ierr
24b7ec98d8SJeremy L Thompson
25b7ec98d8SJeremy L Thompson      do i=1,q
26b7ec98d8SJeremy L Thompson        v1(i)=u2(i)*u1(i)
27b7ec98d8SJeremy L Thompson      enddo
28b7ec98d8SJeremy L Thompson
29b7ec98d8SJeremy L Thompson      ierr=0
30b7ec98d8SJeremy L Thompson      end
31b7ec98d8SJeremy L Thompson!-----------------------------------------------------------------------
32b7ec98d8SJeremy L Thompson      program test
33b7ec98d8SJeremy L Thompson
34b7ec98d8SJeremy L Thompson      include 'ceedf.h'
35b7ec98d8SJeremy L Thompson
36b7ec98d8SJeremy L Thompson      integer ceed,err,i,j,k
37b7ec98d8SJeremy L Thompson      integer erestrictx,erestrictu,erestrictxi,erestrictui
38b7ec98d8SJeremy L Thompson      integer bx,bu
39b7ec98d8SJeremy L Thompson      integer qf_setup,qf_mass
40b7ec98d8SJeremy L Thompson      integer op_setup,op_mass
41b7ec98d8SJeremy L Thompson      integer qdata,x,a,u,v
42b7ec98d8SJeremy L Thompson      integer nelem,p,q,d
43b7ec98d8SJeremy L Thompson      integer row,col,offset
44b7ec98d8SJeremy L Thompson      parameter(nelem=6)
45b7ec98d8SJeremy L Thompson      parameter(p=3)
46b7ec98d8SJeremy L Thompson      parameter(q=4)
47b7ec98d8SJeremy L Thompson      parameter(d=2)
48b7ec98d8SJeremy L Thompson      integer ndofs,nqpts,nx,ny
49b7ec98d8SJeremy L Thompson      parameter(nx=3)
50b7ec98d8SJeremy L Thompson      parameter(ny=2)
51b7ec98d8SJeremy L Thompson      parameter(ndofs=(nx*2+1)*(ny*2+1))
52b7ec98d8SJeremy L Thompson      parameter(nqpts=nelem*q*q)
53b7ec98d8SJeremy L Thompson      integer indx(nelem*p*p)
54b7ec98d8SJeremy L Thompson      real*8 arrx(d*ndofs),aa(nqpts),uu(ndofs),vv(ndofs),atrue(ndofs)
55b7ec98d8SJeremy L Thompson      integer*8 xoffset,aoffset,uoffset,voffset
56b7ec98d8SJeremy L Thompson
57b7ec98d8SJeremy L Thompson      character arg*32
58b7ec98d8SJeremy L Thompson
59b7ec98d8SJeremy L Thompson      external setup,mass
60b7ec98d8SJeremy L Thompson
61b7ec98d8SJeremy L Thompson      call getarg(1,arg)
62b7ec98d8SJeremy L Thompson
63b7ec98d8SJeremy L Thompson      call ceedinit(trim(arg)//char(0),ceed,err)
64b7ec98d8SJeremy L Thompson
65b7ec98d8SJeremy L Thompson! DoF Coordinates
66b7ec98d8SJeremy L Thompson      do i=0,nx*2
67b7ec98d8SJeremy L Thompson        do j=0,ny*2
68b7ec98d8SJeremy L Thompson          arrx(i+j*(nx*2+1)+0*ndofs+1)=1.d0*i/(2*nx)
69b7ec98d8SJeremy L Thompson          arrx(i+j*(nx*2+1)+1*ndofs+1)=1.d0*j/(2*ny)
70b7ec98d8SJeremy L Thompson        enddo
71b7ec98d8SJeremy L Thompson      enddo
72b7ec98d8SJeremy L Thompson      call ceedvectorcreate(ceed,d*ndofs,x,err)
73b7ec98d8SJeremy L Thompson      xoffset=0
74b7ec98d8SJeremy L Thompson      call ceedvectorsetarray(x,ceed_mem_host,ceed_use_pointer,arrx,xoffset,err)
75b7ec98d8SJeremy L Thompson
76b7ec98d8SJeremy L Thompson! Qdata Vector
77b7ec98d8SJeremy L Thompson      call ceedvectorcreate(ceed,nqpts,qdata,err)
78b7ec98d8SJeremy L Thompson
79b7ec98d8SJeremy L Thompson! Element Setup
80b7ec98d8SJeremy L Thompson      do i=0,nelem-1
81b7ec98d8SJeremy L Thompson        col=mod(i,nx)
82b7ec98d8SJeremy L Thompson        row=i/nx
83b7ec98d8SJeremy L Thompson        offset=col*(p-1)+row*(nx*2+1)*(p-1)
84b7ec98d8SJeremy L Thompson        do j=0,p-1
85b7ec98d8SJeremy L Thompson          do k=0,p-1
86b7ec98d8SJeremy L Thompson            indx(p*(p*i+k)+j+1)=offset+k*(nx*2+1)+j
87b7ec98d8SJeremy L Thompson          enddo
88b7ec98d8SJeremy L Thompson        enddo
89b7ec98d8SJeremy L Thompson      enddo
90b7ec98d8SJeremy L Thompson
91b7ec98d8SJeremy L Thompson! Restrictions
92b7ec98d8SJeremy L Thompson      call ceedelemrestrictioncreate(ceed,nelem,p*p,ndofs,d,&
93b7ec98d8SJeremy L Thompson     & ceed_mem_host,ceed_use_pointer,indx,erestrictx,err)
94b7ec98d8SJeremy L Thompson      call ceedelemrestrictioncreateidentity(ceed,nelem,p*p,&
95b7ec98d8SJeremy L Thompson     & nelem*p*p,d,erestrictxi,err)
96b7ec98d8SJeremy L Thompson
97b7ec98d8SJeremy L Thompson      call ceedelemrestrictioncreate(ceed,nelem,p*p,ndofs,1,&
98b7ec98d8SJeremy L Thompson     & ceed_mem_host,ceed_use_pointer,indx,erestrictu,err)
99b7ec98d8SJeremy L Thompson      call ceedelemrestrictioncreateidentity(ceed,nelem,q*q,nqpts,&
100b7ec98d8SJeremy L Thompson     & 1,erestrictui,err)
101b7ec98d8SJeremy L Thompson
102b7ec98d8SJeremy L Thompson! Bases
103b7ec98d8SJeremy L Thompson      call ceedbasiscreatetensorh1lagrange(ceed,d,d,p,q,ceed_gauss,&
104b7ec98d8SJeremy L Thompson     & bx,err)
105b7ec98d8SJeremy L Thompson      call ceedbasiscreatetensorh1lagrange(ceed,d,1,p,q,ceed_gauss,&
106b7ec98d8SJeremy L Thompson     & bu,err)
107b7ec98d8SJeremy L Thompson
108b7ec98d8SJeremy L Thompson! QFunctions
109b7ec98d8SJeremy L Thompson! -- Setup
110b7ec98d8SJeremy L Thompson      call ceedqfunctioncreateinterior(ceed,1,setup,&
111b7ec98d8SJeremy L Thompson     &SOURCE_DIR&
112*a05f9790Sjeremylt     &//'t510-operator.h:setup'//char(0),qf_setup,err)
113b7ec98d8SJeremy L Thompson      call ceedqfunctionaddinput(qf_setup,'_weight',1,ceed_eval_weight,err)
114b7ec98d8SJeremy L Thompson      call ceedqfunctionaddinput(qf_setup,'dx',d*d,ceed_eval_grad,err)
115b7ec98d8SJeremy L Thompson      call ceedqfunctionaddoutput(qf_setup,'rho',1,ceed_eval_none,err)
116b7ec98d8SJeremy L Thompson! -- Mass
117b7ec98d8SJeremy L Thompson      call ceedqfunctioncreateinterior(ceed,1,mass,&
118b7ec98d8SJeremy L Thompson     &SOURCE_DIR&
119*a05f9790Sjeremylt     &//'t510-operator.h:mass'//char(0),qf_mass,err)
120b7ec98d8SJeremy L Thompson      call ceedqfunctionaddinput(qf_mass,'rho',1,ceed_eval_none,err)
121b7ec98d8SJeremy L Thompson      call ceedqfunctionaddinput(qf_mass,'u',1,ceed_eval_interp,err)
122b7ec98d8SJeremy L Thompson      call ceedqfunctionaddoutput(qf_mass,'v',1,ceed_eval_interp,err)
123b7ec98d8SJeremy L Thompson
124b7ec98d8SJeremy L Thompson! Operators
125b7ec98d8SJeremy L Thompson! -- Setup
126b7ec98d8SJeremy L Thompson      call ceedoperatorcreate(ceed,qf_setup,ceed_null,ceed_null,op_setup,&
127b7ec98d8SJeremy L Thompson     & err)
128b7ec98d8SJeremy L Thompson      call ceedoperatorsetfield(op_setup,'_weight',erestrictxi,&
129b7ec98d8SJeremy L Thompson     & ceed_notranspose,bx,ceed_vector_none,err)
130b7ec98d8SJeremy L Thompson      call ceedoperatorsetfield(op_setup,'dx',erestrictx,&
131b7ec98d8SJeremy L Thompson     & ceed_notranspose,bx,ceed_vector_active,err)
132b7ec98d8SJeremy L Thompson      call ceedoperatorsetfield(op_setup,'rho',erestrictui,&
133b7ec98d8SJeremy L Thompson     & ceed_notranspose,ceed_basis_collocated,ceed_vector_active,err)
134b7ec98d8SJeremy L Thompson! -- Mass
135b7ec98d8SJeremy L Thompson      call ceedoperatorcreate(ceed,qf_mass,ceed_null,ceed_null,op_mass,&
136b7ec98d8SJeremy L Thompson     & err)
137b7ec98d8SJeremy L Thompson      call ceedoperatorsetfield(op_mass,'rho',erestrictui,&
138b7ec98d8SJeremy L Thompson     & ceed_notranspose,ceed_basis_collocated,qdata,err)
139b7ec98d8SJeremy L Thompson      call ceedoperatorsetfield(op_mass,'u',erestrictu,&
140b7ec98d8SJeremy L Thompson     & ceed_notranspose,bu,ceed_vector_active,err)
141b7ec98d8SJeremy L Thompson      call ceedoperatorsetfield(op_mass,'v',erestrictu,&
142b7ec98d8SJeremy L Thompson     & ceed_notranspose,bu,ceed_vector_active,err)
143b7ec98d8SJeremy L Thompson
144b7ec98d8SJeremy L Thompson! Apply Setup Operator
145b7ec98d8SJeremy L Thompson      call ceedoperatorapply(op_setup,x,qdata,ceed_request_immediate,err)
146b7ec98d8SJeremy L Thompson
147b7ec98d8SJeremy L Thompson! Assemble Diagonal
148b7ec98d8SJeremy L Thompson      call ceedoperatorassemblelineardiagonal(op_mass,a,&
149b7ec98d8SJeremy L Thompson     & ceed_request_immediate,err)
150b7ec98d8SJeremy L Thompson
151b7ec98d8SJeremy L Thompson! Manually assemble diagonal
152b7ec98d8SJeremy L Thompson      call ceedvectorcreate(ceed,ndofs,u,err)
153b7ec98d8SJeremy L Thompson      call ceedvectorsetvalue(u,0.d0,err)
154b7ec98d8SJeremy L Thompson      call ceedvectorcreate(ceed,ndofs,v,err)
155b7ec98d8SJeremy L Thompson      do i=1,ndofs
156b7ec98d8SJeremy L Thompson        call ceedvectorgetarray(u,ceed_mem_host,uu,uoffset,err)
157b7ec98d8SJeremy L Thompson        uu(i+uoffset)=1.d0
158b7ec98d8SJeremy L Thompson        if (i>1) then
159b7ec98d8SJeremy L Thompson          uu(i-1+uoffset)=0.d0
160b7ec98d8SJeremy L Thompson        endif
161b7ec98d8SJeremy L Thompson        call ceedvectorrestorearray(u,uu,uoffset,err)
162b7ec98d8SJeremy L Thompson
163b7ec98d8SJeremy L Thompson        call ceedoperatorapply(op_mass,u,v,ceed_request_immediate,err)
164b7ec98d8SJeremy L Thompson
165b7ec98d8SJeremy L Thompson        call ceedvectorgetarrayread(v,ceed_mem_host,vv,voffset,err)
166b7ec98d8SJeremy L Thompson        atrue(i)=vv(voffset+i)
167b7ec98d8SJeremy L Thompson        call ceedvectorrestorearrayread(v,vv,voffset,err)
168b7ec98d8SJeremy L Thompson      enddo
169b7ec98d8SJeremy L Thompson
170b7ec98d8SJeremy L Thompson! Check Output
171b7ec98d8SJeremy L Thompson      call ceedvectorgetarrayread(a,ceed_mem_host,aa,aoffset,err)
172b7ec98d8SJeremy L Thompson      do i=1,ndofs
173b7ec98d8SJeremy L Thompson        if (abs(aa(aoffset+i)-atrue(i))>1.0d-14) then
174b7ec98d8SJeremy L Thompson! LCOV_EXCL_START
175b7ec98d8SJeremy L Thompson          write(*,*) '[',i,'] Error in assembly: ',aa(aoffset+i),' != ',&
176b7ec98d8SJeremy L Thompson     &      atrue(i)
177b7ec98d8SJeremy L Thompson! LCOV_EXCL_STOP
178b7ec98d8SJeremy L Thompson        endif
179b7ec98d8SJeremy L Thompson      enddo
180b7ec98d8SJeremy L Thompson      call ceedvectorrestorearrayread(a,aa,aoffset,err)
181b7ec98d8SJeremy L Thompson
182b7ec98d8SJeremy L Thompson! Cleanup
183b7ec98d8SJeremy L Thompson      call ceedqfunctiondestroy(qf_setup,err)
184b7ec98d8SJeremy L Thompson      call ceedqfunctiondestroy(qf_mass,err)
185b7ec98d8SJeremy L Thompson      call ceedoperatordestroy(op_setup,err)
186b7ec98d8SJeremy L Thompson      call ceedoperatordestroy(op_mass,err)
187b7ec98d8SJeremy L Thompson      call ceedelemrestrictiondestroy(erestrictu,err)
188b7ec98d8SJeremy L Thompson      call ceedelemrestrictiondestroy(erestrictx,err)
189b7ec98d8SJeremy L Thompson      call ceedelemrestrictiondestroy(erestrictui,err)
190b7ec98d8SJeremy L Thompson      call ceedelemrestrictiondestroy(erestrictxi,err)
191b7ec98d8SJeremy L Thompson      call ceedbasisdestroy(bu,err)
192b7ec98d8SJeremy L Thompson      call ceedbasisdestroy(bx,err)
193b7ec98d8SJeremy L Thompson      call ceedvectordestroy(x,err)
194b7ec98d8SJeremy L Thompson      call ceedvectordestroy(a,err)
195b7ec98d8SJeremy L Thompson      call ceedvectordestroy(u,err)
196b7ec98d8SJeremy L Thompson      call ceedvectordestroy(v,err)
197b7ec98d8SJeremy L Thompson      call ceedvectordestroy(qdata,err)
198b7ec98d8SJeremy L Thompson      call ceeddestroy(ceed,err)
199b7ec98d8SJeremy L Thompson      end
200b7ec98d8SJeremy L Thompson!-----------------------------------------------------------------------
201