Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
implicit_soln.f90
Go to the documentation of this file.
1 !*********************************************************************
2 !* Illinois Open Source License *
3 !* *
4 !* University of Illinois/NCSA *
5 !* Open Source License *
6 !* *
7 !* Copyright@2008, University of Illinois. All rights reserved. *
8 !* *
9 !* Developed by: *
10 !* *
11 !* Center for Simulation of Advanced Rockets *
12 !* *
13 !* University of Illinois *
14 !* *
15 !* www.csar.uiuc.edu *
16 !* *
17 !* Permission is hereby granted, free of charge, to any person *
18 !* obtaining a copy of this software and associated documentation *
19 !* files (the "Software"), to deal with the Software without *
20 !* restriction, including without limitation the rights to use, *
21 !* copy, modify, merge, publish, distribute, sublicense, and/or *
22 !* sell copies of the Software, and to permit persons to whom the *
23 !* Software is furnished to do so, subject to the following *
24 !* conditions: *
25 !* *
26 !* *
27 !* @ Redistributions of source code must retain the above copyright *
28 !* notice, this list of conditions and the following disclaimers. *
29 !* *
30 !* @ Redistributions in binary form must reproduce the above *
31 !* copyright notice, this list of conditions and the following *
32 !* disclaimers in the documentation and/or other materials *
33 !* provided with the distribution. *
34 !* *
35 !* @ Neither the names of the Center for Simulation of Advanced *
36 !* Rockets, the University of Illinois, nor the names of its *
37 !* contributors may be used to endorse or promote products derived *
38 !* from this Software without specific prior written permission. *
39 !* *
40 !* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, *
41 !* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES *
42 !* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND *
43 !* NONINFRINGEMENT. IN NO EVENT SHALL THE CONTRIBUTORS OR *
44 !* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
45 !* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, *
46 !* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE *
47 !* USE OR OTHER DEALINGS WITH THE SOFTWARE. *
48 !*********************************************************************
49 !* Please acknowledge The University of Illinois Center for *
50 !* Simulation of Advanced Rockets in works and publications *
51 !* resulting from this software or its derivatives. *
52 !*********************************************************************
53 SUBROUTINE implicit_soln(delt,t,fext_in,global)
54 
55  USE implicit_global
56  USE comp_row_global
57  USE precision
59 
60  IMPLICIT NONE
61 
62  include 'mpif.h'
63 
64 ! Input
65  TYPE(rocfrac_global) :: global
66  REAL(kind=wp) :: delt, t
67  REAL(kind=wp), DIMENSION(1:3*global%NumNp) :: fext_in
68 ! Internal
69  INTEGER :: bs95debug
70  INTEGER :: i, j, k, m, n, p, counter, ii
71  INTEGER :: newnrows_meff, newnstart_meff, newndim
72  REAL(kind=wp) :: contol, alphaimp, deltaimp
73  REAL(kind=wp), DIMENSION(1:3*LNumNp) :: pbar, fint, fext, v, a, d
74  REAL(kind=wp), ALLOCATABLE, DIMENSION(:) :: newpbar, newa
75  REAL(kind=wp), ALLOCATABLE, DIMENSION(:) :: bufsnd, ftemp
76  REAL(wp) :: per1, delay
77 
78 
79 ! Initialize
80  fint(:) = 0.0
81  contol = 1.0e-09
82  alphaimp = 0.25
83  deltaimp = 0.5
84  IF ( global%debug_state ) THEN
85  bs95debug = 1
86  ELSE
87  bs95debug = 0
88  END IF
89 
90 
91 ! Assemble the vectors
92  DO i = 1, global%NumNp
93  IF ( nodeproc(i) == myid ) THEN
94  DO j = 1, 3
95  k = 3*local2global(i) - nstart_km + 1 + j - 3
96  m = 3*i + j - 3
97  fext( k ) = fext_in( m )
98  d( k ) = global%Disp( m )
99  v( k ) = global%VeloHalf( m )
100  a( k ) = global%Accel( m )
101  END DO
102  END IF
103  END DO
104 
105 
106 !
107 ! If this is the first timestep, initialize the acceleration array
108 !
109  IF ( initaccel .EQV. .true. ) THEN
110 
111  initaccel = .false.
112 
113  ! Use applied forces and mass matrix
114  ! i.e. solve {F} - [K]*{disp} = [M]*{a} for {a}
115 
116  IF(myid==0) print*,'CALCULATING INITIAL ACCELERATION'
117 
118  ! Construct the imposed external force vector
119  ALLOCATE(fext_imp(1:3*lnumnp))
120  fext_imp(:) = 0.0
121  counter = 0
122  DO m = 1, gnumnp
123  DO i = 1, global%NumNp
124  IF (local2global(i) == m) THEN
125  DO j = 1, 3
126  IF (nodeproc(i) == myid) THEN
127  counter = counter + 1
128  IF(node_flag(i,j) == 7) THEN ! Imposed force
129  fext_imp(counter) = boundary_value(i,j)
130 
131  ENDIF
132  ENDIF
133  ENDDO
134  ENDIF
135  ENDDO
136  ENDDO
137 
138  ! Construct the internal force vector
139  CALL get_fint(3*gnumnp,nrows_km,nnz_k,nstart_km,rp_k,cval_k,aval_k,d,fint)
140 
141  ALLOCATE(ftemp(1:3*lnumnp))
142  ftemp(1:3*lnumnp) = 0.0
143 
144  ! Construct the effective force vector
145  DO i = 1, 3*lnumnp
146  ftemp(i) = fext(i) + fext_imp(i) - fint(i)
147  ENDDO
148 
149  ! Remove rows that are constrained by displacement BC's
150  counter = 0
151  DO m = 1, gnumnp
152  DO i = 1, global%NumNp
153  IF (local2global(i) == m) THEN
154  IF (nodeproc(i) == myid) THEN
155  DO j = 1, 3
156  counter = counter + 1
157  IF(node_flag(i,j) == 8) THEN ! Imposed constant nodal displacement
158  DO n = rp_m(counter)+1,rp_m(counter+1)
159  IF (cval_m(n)+1 /= counter+nstart_km-1) THEN
160  aval_m(n) = 0.0
161  ELSE
162  aval_m(n) = 1.0
163  ENDIF
164  ENDDO
165  ENDIF
166  ENDDO
167  ENDIF
168  ENDIF
169  ENDDO
170  ENDDO
171  counter = 0
172  DO m = 1, gnumnp
173  DO i = 1, global%NumNp
174  IF (local2global(i) == m) THEN
175  IF (nodeproc(i)==myid) THEN
176  DO j = 1, 3
177  counter = counter + 1
178  IF(node_flag(i,j) == 8) THEN ! Imposed constant nodal displacement
179  ftemp(counter) = 0.0 ! If constant displacement, acceleration = 0
180  ENDIF
181  ENDDO
182  ENDIF
183  ENDIF
184  ENDDO
185  ENDDO
186 
187  ! Solve using BlockSolve95 functions
188  a(:) = 0.0 ! Initial guess
189  CALL bs95setup(3*gnumnp,nnz_m,nstart_km-1,nrows_km,rp_m,cval_m,aval_m,1,bs95debug)
190  CALL bs95solve(3*lnumnp,ftemp,a,contol,bs95debug)
191  CALL bs95free(bs95debug)
192  DEALLOCATE(ftemp)
193 
194  ! Make sure initial conditions conform to BC's
195  CALL implicit_bc_enforce(global%NumNp,lnumnp,d,a,v,node_flag,boundary_value,0,myid)
196 
197  ! Create the effective mass matrix
198  IF(myid==0) print*,'FORMING EFFECTIVE MASS MATRIX'
199  CALL comp_row_add(3*lnumnp,3*gnumnp,nrows_km,nrows_km,nnz_k,nnz_m,1, &
200  rp_k,cval_k,alphaimp*delt*delt*aval_k,1,rp_m,cval_m,aval_m)
201  ALLOCATE(rp_meff(nrows_km+1),cval_meff(nnz_temp),aval_meff(nnz_temp))
202  nnz_meff = nnz_temp
203  nstart_meff = nstart_km
204  nrows_meff = nrows_km
205  rp_meff = rp_temp
206  cval_meff = cval_temp
207  aval_meff = aval_temp
208  DEALLOCATE(rp_temp,cval_temp,aval_temp)
209 
210  ! Remove rows that are constrained by displacement BC's
211  CALL removebcs_meff(3*gnumnp,nrows_meff,nnz_meff,nstart_meff,rp_meff,cval_meff,aval_meff, &
212  newnrows_meff,newnstart_meff,newndim,global)
213  DEALLOCATE(rp_meff,cval_meff,aval_meff)
214  nrows_meff = newnrows_meff
215  nstart_meff = newnstart_meff
216  ALLOCATE(rp_meff(nrows_meff+1),cval_meff(nnz_temp),aval_meff(nnz_temp))
217  nnz_meff = nnz_temp
218  rp_meff = rp_temp
219  cval_meff = cval_temp
220  aval_meff = aval_temp
221  DEALLOCATE(rp_temp,cval_temp,aval_temp)
222 
223  ! Set up the new system to be solved
224  CALL bs95setup(newndim,nnz_meff,nstart_meff-1,nrows_meff,rp_meff,cval_meff,aval_meff,1, &
225  bs95debug)
226 
227  END IF
228 
229 
230 !!$! DEBUG
231 !!$
232 !!$ IF ( t == 0.0 ) THEN
233 !!$
234 !!$ OPEN(30,FILE='m_'//global%MyIdChr//'.m',FORM='formatted')
235 !!$ counter = 0
236 !!$ DO i = 1, nrows_km
237 !!$ DO j = rp_m(i)+1, rp_m(i+1)
238 !!$ counter = counter + 1
239 !!$ m = cval_m(counter)+1
240 !!$ WRITE(30,*) 'M(', i+nstart_km-1, ',', m, ') = ',aval_m(counter), ';'
241 !!$ ENDDO
242 !!$ ENDDO
243 !!$ CLOSE(30)
244 !!$
245 !!$ OPEN(30,FILE='k_'//global%MyIdChr//'.m',FORM='formatted')
246 !!$ counter = 0
247 !!$ DO i = 1, nrows_km
248 !!$ DO j = rp_k(i)+1, rp_k(i+1)
249 !!$ counter = counter + 1
250 !!$ m = cval_k(counter)+1
251 !!$ WRITE(30,*) 'K(', i+nstart_km-1, ',', m, ') = ',aval_k(counter), ';'
252 !!$ ENDDO
253 !!$ ENDDO
254 !!$ CLOSE(30)
255 !!$
256 !!$ OPEN(30,FILE='meff_'//global%MyIdChr//'.m',FORM='formatted')
257 !!$ counter = 0
258 !!$ DO i = 1, nrows_meff
259 !!$ DO j = rp_meff(i)+1, rp_meff(i+1)
260 !!$ counter = counter + 1
261 !!$ m = cval_meff(counter)+1
262 !!$ WRITE(30,*) 'Meff(', i+nstart_meff-1, ',', m, ') = ',aval_meff(counter), ';'
263 !!$ ENDDO
264 !!$ ENDDO
265 !!$ CLOSE(30)
266 !!$
267 !!$ END IF
268 !!$
269 !!$! END DEBUG
270 
271 
272 
273  IF(myid==0) print*,'CALCULATING NEW DISPLACEMENT VECTOR'
274 
275 
276 ! Calculate displacement and velocity predictors:
277 ! ~ . ..
278 ! x = x + Dt * x + 1/2 * Dt^2 * (1-2*beta) * x
279 ! k+1 k k k
280 !
281 ! ~. . ..
282 ! x = x + Dt * (1-gamma) * x
283 ! k+1 k k
284 !
285 
286  DO i = 1, 3*lnumnp
287  d(i) = d(i) + delt * v(i) + 0.5*delt*delt * (1.0 - 2.0*alphaimp) * a(i)
288  v(i) = v(i) + delt * (1.0 - deltaimp) * a(i)
289  ENDDO
290 
291 
292 ! Calculate effective loads at time t + Dt:
293 !
294 ! _ .
295 ! P = P - C x - I
296 ! k+1 k+1 k
297 !
298 ! where I is the internal force vector
299 !
300 
301  ! Get the internal force vector
302  fint(:) = 0.0
303  CALL get_fint(3*gnumnp,nrows_km,nnz_k,nstart_km,rp_k,cval_k,aval_k,d,fint)
304 
305  ! Construct the load vector
306  !per1 = 359.1592 ! beambending2
307  !delay = 0.0
308  !print*,'constructing load vector for beambending2 model'
309  per1 = 0.03237 ! agard (Yates SOLID 1 flutter)
310  delay = 0.0 * per1
311  print*,'constructing load vector for YATES SOLID 1 model in flutter'
312  !per1 = 100.0
313  !delay = 0.0
314  !print*,'constructing load vector for orthotropic test cases'
315  DO i = 1,3*lnumnp
316  ! IF ( ( t > delay ) .AND. ( t < per1 + delay ) ) THEN
317  ! pbar(i) = fext_imp(i)*SIN(3.14159*(t-delay)/per1) + fext(i) - fint(i)
318  ! !pbar(i) = fext(i) + (0.5 - 0.5*COS(3.14159/per1*(t-delay)))*fext_imp(i) - fint(i)
319  ! ELSE
320  ! pbar(i) = fext(i) - fint(i)
321  ! !pbar(i) = fext(i) + fext_imp(i) - fint(i)
322  ! END IF
323  pbar(i) = fext(i) + fext_imp(i) - fint(i)
324  ENDDO
325 
326  print*,myid,'MAXIMUM FORCING TERM:',maxval(pbar(:) - fext(:) + fint(:))
327 
328  ! Allocate shortened arrays
329  ALLOCATE(newpbar(1:nrows_meff))
330  ALLOCATE(newa(1:nrows_meff))
331  newpbar(:) = 0.0
332  newa(:) = 0.0
333 
334  ! Remove rows that are constrained by displacement BC's
335  CALL removebcs_pbar(nstart_km,3*lnumnp,pbar,nrows_meff,newpbar)
336 
337 
338 !
339 ! Solve for acceleration at time t + Dt
340 ! _ _
341 ! M a = P
342 ! k+1 k+1
343 !
344 
345  ! Solve using BlockSolve95 functions
346  CALL bs95solve(nrows_meff,newpbar,newa,contol,bs95debug)
347 
348  ! Put newa back into a
349  CALL removebcs_newa(nstart_km,3*lnumnp,a,nrows_meff,newa)
350 
351  ! Deallocate shortened arrays
352  DEALLOCATE(newpbar)
353  DEALLOCATE(newa)
354 
355 
356 ! Calculate displacement and velocity correctors:
357 ! ~ ..
358 ! x = x + beta * Dt^2 * x
359 ! k+1 k+1 k+1
360 !
361 ! . ~. ..
362 ! x = x + gamma * Dt * x
363 ! k+1 k+1 k+1
364 !
365 
366  DO i = 1, 3*lnumnp
367  d(i) = d(i) + alphaimp*delt*delt*a(i)
368  v(i) = v(i) + deltaimp*delt*a(i)
369  ENDDO
370 
371 
372 !
373 ! 4. Apply boundary conditions
374 !
375  CALL implicit_bc_enforce(global%NumNp,lnumnp,d,v,a,node_flag,boundary_value,t,myid)
376 
377 
378  IF(myid==0) print*,'ASSEMBLING NEW DISPLACEMENT VECTOR'
379 
380 
381 !
382 ! Put the vectors back into their Rocfrac equivalent vectors
383 !
384 
385  DO i = 1, global%NumNp
386  IF ( nodeproc(i) == myid ) THEN
387  DO j = 1, 3
388  k = 3*local2global(i) - nstart_km + 1 + j - 3
389  m = 3*i + j - 3
390  global%Disp( m ) = d( k )
391  global%VeloHalf( m ) = v( k )
392  global%Accel( m ) = a( k )
393  END DO
394  END IF
395  END DO
396 
397 
398 !
399 ! Communicate variables to other processors and assemble
400 !
401 
402  IF (nprocs > 1) THEN
403 
404 ! clear the status and request vars
405  CALL mpi_barrier(rocstar_communicator,ierr)
406  ALLOCATE(req_rcv(1:nprocs))
407  ALLOCATE(req_snd(1:nprocs))
408  ALLOCATE(stat_snd(1:mpi_status_size,1:nprocs))
409  ALLOCATE(stat_rcv(1:mpi_status_size,1:nprocs))
410  DO i = 1, nprocs
411  req_rcv(i) = 0
412  req_snd(i) = 0
413  DO j = 1, mpi_status_size
414  stat_rcv(1,i) = 0
415  stat_snd(j,i) = 0
416  ENDDO
417  ENDDO
418 
419 ! receive from other procs
420  CALL mpi_barrier(rocstar_communicator,ierr)
421  ALLOCATE(frmproc(1:numcommprocsfrom2))
422  DO i = 1, numcommprocsfrom2
423  ALLOCATE(frmproc(i)%rcvbuf(1:10*numcommnodesfrom2(i)))
424  CALL mpi_irecv(frmproc(i)%rcvbuf(1),10*numcommnodesfrom2(i), &
425  mpi_double_precision,commprocsfrom2(i),10,rocstar_communicator, &
426  req_rcv(i),ierr)
427  ENDDO
428 
429 ! send to other procs
430  DO i = 1, numcommprocs2
431  ALLOCATE(bufsnd(1:10*numcommnodes2(i)))
432  counter = 0
433  DO j = 1, numcommnodes2(i)
434  counter = counter + 1
435  bufsnd(counter) = 1.0 * commnodes2(i,j)
436  k = global2local(commnodes2(i,j))
437  DO p = 1, 3
438  counter = counter + 1
439  bufsnd(counter) = global%Disp( k * 3 - 3 + p )
440  ENDDO
441  DO p = 1, 3
442  counter = counter + 1
443  bufsnd(counter) = global%VeloHalf( k * 3 - 3 + p )
444  ENDDO
445  DO p = 1, 3
446  counter = counter + 1
447  bufsnd(counter) = global%Accel( k * 3 - 3 + p )
448  ENDDO
449  ENDDO
450  CALL mpi_send(bufsnd(:),10*numcommnodes2(i),mpi_double_precision, &
451  commprocs2(i),10,rocstar_communicator,ierr)
452  DEALLOCATE(bufsnd)
453  ENDDO
454  CALL mpi_waitall(nprocs,req_rcv,stat_rcv,ierr)
455 
456 ! deallocate status and request vars
457  DEALLOCATE(req_rcv)
458  DEALLOCATE(req_snd)
459  DEALLOCATE(stat_snd)
460  DEALLOCATE(stat_rcv)
461 
462 ! assemble into Rocfrac nodal variable vectors
463  DO i = 1, numcommprocsfrom2
464  counter = 0
465  DO j = 1, numcommnodesfrom2(i)
466  counter = counter + 1
467  k = global2local( int( frmproc(i)%rcvbuf(counter) ) ) ! local index of node
468  DO p = 1, 3
469  counter = counter + 1
470  global%Disp( 3*k - 3 + p ) = frmproc(i)%rcvbuf(counter)
471  END DO
472  DO p = 1, 3
473  counter = counter + 1
474  global%VeloHalf( 3*k - 3 + p ) = frmproc(i)%rcvbuf(counter)
475  END DO
476  DO p = 1, 3
477  counter = counter + 1
478  global%Accel( 3*k - 3 + p ) = frmproc(i)%rcvbuf(counter)
479  END DO
480  END DO
481  END DO
482 
483 ! clear the receive buffer
484  DEALLOCATE(frmproc)
485 
486  ENDIF
487 
488 
489 END SUBROUTINE implicit_soln
490 
FT m(int i, int j) const
subroutine removebcs_newa(nstart, ndim, a, newndim, newa)
Definition: removeBCs.f90:373
const NT & d
j indices k indices k
Definition: Indexing.h:6
subroutine comp_row_add(ndim, gndim, nrows1, nrows2, nnz1, nnz2, nstart1, rp1, cval1, aval1, nstart2, rp2, cval2, aval2)
subroutine removebcs_meff(ndim, nrows, nnz, nstart, rp1, cval, aval, newnrows, newnstart, newndim, global)
Definition: removeBCs.f90:84
*********************************************************************Illinois Open Source License ****University of Illinois NCSA **Open Source License University of Illinois All rights reserved ****Developed free of to any person **obtaining a copy of this software and associated documentation to deal with the Software without including without limitation the rights to and or **sell copies of the and to permit persons to whom the **Software is furnished to do subject to the following this list of conditions and the following disclaimers ****Redistributions in binary form must reproduce the above **copyright this list of conditions and the following **disclaimers in the documentation and or other materials **provided with the distribution ****Neither the names of the Center for Simulation of Advanced the University of nor the names of its **contributors may be used to endorse or promote products derived **from this Software without specific prior written permission ****THE SOFTWARE IS PROVIDED AS WITHOUT WARRANTY OF ANY **EXPRESS OR INCLUDING BUT NOT LIMITED TO THE WARRANTIES **OF FITNESS FOR A PARTICULAR PURPOSE AND **NONINFRINGEMENT IN NO EVENT SHALL THE CONTRIBUTORS OR **COPYRIGHT HOLDERS BE LIABLE FOR ANY DAMAGES OR OTHER WHETHER IN AN ACTION OF TORT OR **ARISING OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE **USE OR OTHER DEALINGS WITH THE SOFTWARE v
Definition: roccomf90.h:20
subroutine implicit_soln(delt, t, fext_in, global)
subroutine implicit_bc_enforce(NumNp, LocNumNp, disp, v, a, node_flag, boundary_value, t, myid)
blockLoc i
Definition: read.cpp:79
subroutine get_fint(ndim, nrows, nnz, nstart, rp_k, cval_k, aval_k, dispin, fint)
Definition: get_fint.f90:82
const NT & n
subroutine removebcs_pbar(nstart, ndim, pbar, newndim, newpbar)
Definition: removeBCs.f90:304
virtual std::ostream & print(std::ostream &os) const
j indices j
Definition: Indexing.h:6
RT a() const
Definition: Line_2.h:140