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