e4d_vars.F90 coverage: 100.00 %func 36.64 %block
1) module vars
2)
3) implicit none
4) #include "petsc/finclude/petscsys.h"
5) #include "petsc/finclude/petscvec.h"
6) #include "petsc/finclude/petscvec.h90"
7) #include "petsc/finclude/petscmat.h"
8) #include "petsc/finclude/petscmat.h90"
9) #include "petsc/finclude/petscviewer.h"
10) #include "petsc/finclude/petscviewer.h90"
11) #include "petsc/finclude/petscksp.h"
12) #include "petsc/finclude/petscksp.h90"
13)
14) integer, dimension(:), allocatable :: e4d_ranks,pf_e4d_ranks
15) integer :: mpi_comm_grp,mpi_e4d_grp,mpi_pfe4d_grp,i
16) integer :: my_wrank,my_pfe4d_rank,n_pfe4drank !!my mpi rank
17) integer :: tn_rank !!number of processes
18)
19)
20) character*40 :: mshfile !!file containing the mesh options
21) character*40 :: efile !!survey configuration file
22) character*40 :: mapfile
23) character*40 :: sigfile !!baseline conductivity file
24) character*40 :: list_file !!conductivity list file
25) character*40 :: csrv_file !!survey file
26) character*40 :: ccond_file !!conductivity file
27) character*40 :: log_file !!e4d_log file
28)
29) integer :: my_rank !!my mpi rank
30) integer :: ierr !!generall error
31) integer :: n_rank !!number of processes
32) integer :: E4D_COMM !!E4D_COMMUNICATOR
33) integer :: PFE4D_MASTER_COMM !!PF to E4D MASTER COMMUNICATOR
34) integer :: ne,tne !!num my electrodes, total electrodes
35) integer :: nsig !!number of elements, sigma values
36) integer :: nm !!number of measurements
37) integer :: nnodes !!number of nodes
38) integer :: nelem !!number of elements (same as nsig)
39) integer :: nfaces !!number of faces
40) integer :: nvals !!number of non-zeros in coupling mat
41) integer :: my_ne !!number of electrodes I'm assigned
42) integer :: nmy_drows !!number of data in my assembly vector
43) integer :: nmap
44) integer :: ntime !!number of e4d simulation times
45)
46) integer :: pfnx !!number of pf cells in x dim
47) integer :: pfny !!number of pf cells in y dim
48) integer :: pfnz !!number of pf cells in z dim
49)
50) real :: gw_sig !!groundwater electrical conductivity
51) real :: sw_sig !!surface water electrical condctivity
52) real :: FF !!formation factor
53) real :: Cbeg,Cend,etm !!timing variables
54) real*8 :: e4d_time, pf_time
55)
56) integer, dimension(:,:), allocatable :: map_inds
57) integer, dimension(:,:), allocatable :: s_conf !!abmn survey configuration
58) integer, dimension(:,:), allocatable :: eind !!electrode assignments
59) integer, dimension(:,:), allocatable :: jind !!element map assignments
60) integer, dimension(:), allocatable :: nbounds,zones !!node boundaries and element zones
61) integer, dimension(:,:), allocatable :: elements !!elements connections
62) integer, dimension(:,:), allocatable :: faces !!face connections
63) integer, dimension(:), allocatable :: e_nods !!indices of electrode nodes
64) integer, dimension(:), allocatable :: rows,cols
65) integer, dimension(:), allocatable :: trows,tcols
66) integer, dimension(:), allocatable :: A_map !!coupling matrix mapping vector
67) integer, dimension(:), allocatable :: S_map !!Sigma mapping vector
68) integer, dimension(:), allocatable :: my_drows !!rows of my data assemble vector
69)
70) real, dimension(:,:), allocatable :: e_pos
71) real, dimension(:,:), allocatable :: nodes !!node positions
72) real, dimension(:,:), allocatable :: poles !!pole solutions
73) real, dimension(:), allocatable :: pf_porosity !!pflotran porosity
74) real, dimension(:), allocatable :: pf_tracer !!pflotran tracer solution
75) real, dimension(:), allocatable :: pf_saturation !!pflotran saturation solution
76) real, dimension(:), allocatable :: pf_saturation_0 !!pflotran saturation solution at time 0
77) real, dimension(:), allocatable :: pf_temperature !!pflotran temperature
78) real, dimension(:), allocatable :: sigma !!element conductivities
79) real, dimension(:), allocatable :: dpred !!simulated data vector
80) real, dimension(:), allocatable :: dobs !!observed data
81) real, dimension(:), allocatable :: sd !!observed data standard deviations
82) real, dimension(:), allocatable :: my_dvals !!values in my data assembly vector
83) real, dimension(:), allocatable :: map
84) real, dimension(:), allocatable :: base_sigma !!baseline element conductivity
85) real, dimension(:), allocatable :: ffac !!formation factor
86)
87) real, dimension(:), allocatable :: pfxcb !!pf cell boundaries in x
88) real, dimension(:), allocatable :: pfycb !!pf cell boundaries in y
89) real, dimension(:), allocatable :: pfzcb !!pf cell boundaries in z
90)
91)
92)
93) PetscInt, dimension(:), allocatable :: d_nnz !!petsc prealloc vec (diag blocks)
94) PetscReal, dimension(:), allocatable :: delA
95) Mat :: A,Ai
96) PetscErrorCode :: perr
97) MatType :: tp
98) PetscInt :: prn(1),pcn(1)
99) PetscReal :: val(1)
100) PetscInt :: d_nz,o_nz
101) Vec :: psol
102) Vec :: X
103) Vec :: B
104) KSP :: KS,KSi
105) PC :: P
106) logical :: nzero_flag=.true.
107) PetscScalar, pointer :: vloc(:)
108) Vec :: pflotran_tracer_vec_mpi
109) Vec :: pflotran_tracer_vec_seq
110) Vec :: pflotran_saturation_vec_mpi
111) Vec :: pflotran_saturation_vec_seq
112) Vec :: pflotran_temperature_vec_mpi
113) Vec :: pflotran_temperature_vec_seq
114) VecScatter :: pflotran_scatter
115) PetscInt :: pflotran_vec_size
116) character(len=32) :: pflotran_group_prefix
117)
118) contains
119) !_________________________________________________________________
120) subroutine elog(com,i1,i2)
121) implicit none
122) integer :: com,i1,i2
123) logical :: exst
124) integer :: d1,d2,d3
125) real :: v1,v2,v3
126)
127) select case (com)
128)
129) case(0)
130) inquire(file='e4d.inp',exist=exst)
131) if (.not. exst) then
132) open(13,file=trim(log_file),status='old',action='write', &
133) position='append')
134) write(13,*) 'Cannot find the input file e4d.inp'
135) write(*,*) 'Aborting E4D'
136) i2=-1
137) close(13)
138) return
139) else
140) open(13,file=trim(log_file),status='old',action='write',position='append')
141) write(13,*) 'INITIALIZING E4D: FOUND e4d.inp'
142) close(13)
143) i2=0
144) end if
145)
146) case(1)
147) open(13,file=trim(log_file),status='old',action='write', &
148) position='append')
149) if (i1 .ne. 0) then
150) write(13,*) "There was a problem reading the mesh file name in e4d.inp"
151) write(13,*) "Aborting E4D"
152) i2=-1
153) else
154) i2=0
155) write(13,*) "The specified mesh file is: ",trim(mshfile)
156) inquire(file=trim(mshfile),exist=exst)
157) if (.not. exst) then
158) write(13,*) "Cannot find the mesh file: ",trim(mshfile)
159) write(*,*) "Aborting E4D"
160) i2=-1
161) end if
162) end if
163) close(13)
164) return
165)
166) case(2)
167) open(13,file=trim(log_file),status='old',action='write', &
168) position='append')
169) if (i1 .ne. 0) then
170) write(13,*) "There was a problem reading the survey file name in e4d.inp"
171) write(13,*) "Aborting E4D"
172) i2=-1
173) else
174) i2=0
175) write(13,*) "The specified survey file is: ",trim(efile)
176) inquire(file=trim(efile),exist=exst)
177) if (.not. exst) then
178) write(13,*) "Cannot find the survey file: ",trim(efile)
179) write(*,*) "Aborting E4D"
180) i2=-1
181) end if
182) end if
183) close(13)
184) return
185)
186) case(3)
187) open(13,file=trim(log_file),status='old',action='write', &
188) position='append')
189) if (i1 .ne. 0) then
190) write(13,*) "There was a problem reading the conductivity list file name in e4d.inp"
191) write(13,*) "Aborting E4D"
192) i2=-1
193) else
194) i2=0
195) write(13,*) "The specified conductivity list file is: ",trim(sigfile)
196) inquire(file=trim(sigfile),exist=exst)
197) if (.not. exst) then
198) write(13,*) "Cannot find the survey file: ",trim(sigfile)
199) write(*,*) "Aborting E4D"
200) i2=-1
201) end if
202) end if
203) close(13)
204) return
205)
206) case(4)
207) open(13,file=trim(log_file),status='old',action='write', &
208) position='append')
209) if (i1 .ne. 0) then
210) write(13,*) "There was a problem reading the map file name in e4d.inp"
211) write(13,*) "Aborting E4D"
212) i2=-1
213) else
214) i2=0
215) write(13,*) "The specified conductivity list file is: ",trim(mapfile)
216) inquire(file=trim(mapfile),exist=exst)
217) if (.not. exst) then
218) write(13,*) "Cannot find the survey file: ",trim(mapfile)
219) write(*,*) "Aborting E4D"
220) i2=-1
221) end if
222) end if
223) close(13)
224) return
225)
226) case(5)
227) open(13,file=trim(log_file),status='old',action='write', &
228) position='append')
229) if (i1 .ne. 0) then
230) write(13,*) "There was a problem reading the number of electrodes in: ",trim(efile)
231) write(*,*) "Aborting E4D"
232) else
233) write(13,*) "Number of electrodes: ",ne
234) end if
235) close(13)
236) return
237)
238) case(6)
239) open(13,file=trim(log_file),status='old',action='write',position='append')
240) write(13,*) "There was a problem reading the parameters for electrode: ",i1
241) write(*,*) "Aborting E4D"
242) close(13)
243) return
244)
245) case(7)
246) open(13,file=trim(log_file),status='old',action='write',position='append')
247) write(13,*) "E4D internal mesh translation file: ",mshfile(1:i1)//".trn"
248) inquire(file=mshfile(1:i1)//".trn",exist=exst)
249) if (.not. exst) then
250) write(13,*) "Cannot find the mesh translation file: ",mshfile(1:i1)//".trn"
251) write(*,*) "Aborting E4D"
252) i2=-1
253) else
254) i2=0
255) end if
256) close(13)
257) return
258)
259) case(8)
260) open(13,file=trim(log_file),status='old',action='write',position='append')
261) write(13,*) "There was a problem reading the internal mesh translation values"
262) write(13,*) "Aborting E4D"
263) close(13)
264) return
265)
266) case(9)
267) open(13,file=trim(log_file),status='old',action='write', &
268) position='append')
269) if (i1 .ne. 0) then
270) write(13,*) "There was a problem reading the number of measurements"
271) write(13,*) "in the survey file: ",trim(efile)
272) write(13,*) "Aborting E4D"
273) i2=-1
274) else
275) i2=0
276) write(13,*) "The number of measurements per survey is: ",nm
277) end if
278) close(13)
279) return
280)
281) case(10)
282) open(13,file=trim(log_file),status='old',action='write',position='append')
283) write(13,*) 'There wase a problem reading measurement number :',i1
284) write(13,*) 'Aborting E4D'
285) close(13)
286) return
287)
288) case(11)
289) open(13,file=trim(log_file),status='old',action='write', &
290) position='append')
291) if (i1 .ne. 0) then
292) write(13,*) 'There was a problem reading the first line of the '
293) write(13,*) 'conductivity file :',trim(sigfile)
294) write(13,*) 'The first line of the conductivity file must contain the '
295) write(13,*) 'following parameters: '
296) write(13,*) 'Number_of_values Formation_Factor Cond_surface_water Cond_groundwater'
297) write(13,*) 'Aborting E4D'
298)
299) else
300) write(13,*) 'Number of conductivity values: ',i2
301) write(13,*) 'Formation Factor: ',FF
302) write(13,*) 'Surface water conductivity: ',sw_sig
303) write(13,*) 'Groundwater conductivity: ',gw_sig
304)
305) end if
306) close(13)
307) return
308)
309) case(12)
310) open(13,file=trim(log_file),status='old',action='write',position='append')
311) write(13,*) 'There was a problem reading the conductivity for element: ',i1
312) write(13,*) 'Aborting E4D'
313) close(13)
314) return
315)
316) case(13)
317) open(13,file=trim(log_file),status='old',action='write', &
318) position='append')
319) if (i1 .ne. 0) then
320) write(13,*) 'There was a problem reading the number of mapping values'
321) write(13,*) 'in the mapping file: ',trim(mapfile)
322) write(13,*) 'Aborting E4D'
323) i2=-1
324) else
325) write(13,*) "Number of mapping values: ",nmap
326) i2=0
327) end if
328) close(13)
329) return
330)
331) case(14)
332) open(13,file=trim(log_file),status='old',action='write',position='append')
333) write(13,*) "There was a problem reading mapping value: ",i1
334) write(13,*) "Aborting E4D"
335) close(13)
336) return
337)
338) case(15)
339) open(13,file=trim(log_file),status='old',action='write',position='append')
340) inquire(file=mshfile(1:i1)//'.node',exist=exst)
341) if (.not. exst) then
342) write(13,*) 'Could not find the mesh node file: ',mshfile(1:i1)//'.node'
343) write(13,*) 'Aborting E4D'
344) i2=-1
345) else
346) write(13,*) "E4D mesh node file: ",mshfile(1:i1)//'.node'
347) i2=0
348) end if
349) close(13)
350) return
351)
352) case(16)
353) open(13,file=trim(log_file),status='old',action='write',position='append')
354) write(13,*) 'There was a problem reading the first line of the node file.'
355) write(13,*) 'Aborting E4D'
356) close(13)
357) return
358)
359) case(17)
360) open(13,file=trim(log_file),status='old',action='write',position='append')
361) write(13,*) 'There was a problem reading node number: ',i1
362) write(13,*) 'Aborting E4D'
363) close(13)
364) return
365)
366) case(18)
367) open(13,file=trim(log_file),status='old',action='write',position='append')
368) inquire(file=mshfile(1:i1)//'.ele',exist=exst)
369) if (.not. exst) then
370) write(13,*) 'Could not find the mesh node file: ',mshfile(1:i1)//'.ele'
371) write(13,*) 'Aborting E4D'
372) i2=-1
373) else
374) write(13,*) "E4D mesh node file: ",mshfile(1:i1)//'.ele'
375) i2=0
376) end if
377) close(13)
378) return
379)
380) case(19)
381) open(13,file=trim(log_file),status='old',action='write',position='append')
382) write(13,*) 'There was a problem reading the first line of the element file.'
383) write(13,*) 'Aborting E4D'
384) close(13)
385) return
386)
387) case(20)
388) open(13,file=trim(log_file),status='old',action='write',position='append')
389) write(13,*) 'There was a problem reading element number: ',i1
390) write(13,*) 'Aborting E4D'
391) close(13)
392) return
393)
394) case(21)
395) open(13,file=trim(log_file),status='old',action='write',position='append')
396) write(13,*)
397) write(13,*) 'Done setting up forward run ......'
398) write(13,*) ' Number of nodes: ',nnodes
399) write(13,*) ' Number of elements: ',nelem
400) !write(13,*) ' Minimum initial conductivity: ',minval(base_sigma)
401) !write(13,*) ' Maximum intitial conductivity ',maxval(base_sigma)
402) close(13)
403)
404) case(22)
405) open(13,file=trim(log_file),status='old',action='write',position='append')
406) write(13,*)
407) write(13,*) 'mcomm = ',i1
408) write(13,*) 'waiting for pflotran solution'
409) close(13)
410)
411) case(23)
412) open(13,file=trim(log_file),status='old',action='write', &
413) position='append')
414) if (i1 .ne. 0) then
415) write(13,*) "There was a problem reading the list file name in e4d.inp"
416) write(13,*) "Aborting E4D"
417) i2=-1
418) else
419) i2=0
420) write(13,*) "The specified conductivity list file is: ",trim(list_file)
421) inquire(file=trim(list_file),exist=exst)
422) if (.not. exst) then
423) write(13,*) "Cannot find the list file: ",trim(list_file)
424) write(*,*) "Aborting E4D"
425) i2=-1
426) end if
427) end if
428) close(13)
429) return
430)
431) case(24)
432) open(13,file=trim(log_file),status='old',action='write', &
433) position='append')
434) if (i1 .ne. 0) then
435) write(13,*) 'There was a problem reading the first line of the list file.'
436) write(13,*) 'The first line of the list file must contain the following: '
437) write(13,*) 'Number_of_E4D_times FF sw_conductivity gw_conductivity'
438) write(13,*) 'Aborting E4D'
439) i2=-1
440) else
441) write(13,*) "Number of E4D Times: ",ntime
442) write(13,*) "Formation Factor: ",FF
443) write(13,*) "Surface Water Conductivity ", sw_sig
444) write(13,*) "Groundwater Conductivty ",gw_sig
445) i2=0
446) end if
447) close(13)
448) return
449)
450) case(25)
451) open(13,file=trim(log_file),status='old',action='write', &
452) position='append')
453) if (i1 .ne. 0) then
454) write(13,*) "There was a problem reading list file line: ",i2
455) write(13,*) "Each list file line must contain the following: "
456) write(13,*) "E4D_time Survey_file_name Conductivity_file_name"
457) write(13,*) "Aborting E4D"
458) else
459) write(13,"(I5,F12.0,A42,A42)") i2,e4d_time,csrv_file,ccond_file
460) end if
461) close(13)
462) return
463)
464) case(26)
465) open(13,file=trim(log_file),status='old',action='write',position='append')
466) inquire(file=trim(csrv_file),exist=exst)
467) if (.not. exst) then
468) write(13,*) 'Cannot open the file: ',csrv_file
469) write(13,*) 'which is listed on line: ',i2
470) write(13,*) 'of the list file: ',list_file
471) write(13,*) 'Aborting E4D'
472) i2=-1
473) close(13)
474) return
475) end if
476) inquire(file=trim(ccond_file),exist=exst)
477) if (.not. exst) then
478) write(13,*) 'Cannot open the file: ',ccond_file
479) write(13,*) 'which is listed on line: ',i2
480) write(13,*) 'of the list file: ',list_file
481) write(13,*) 'Aborting E4D'
482) i2=-1
483) close(13)
484) return
485) end if
486) i2=0
487) close(13)
488) return
489)
490) case(27)
491) open(13,file=trim(log_file),status='old',action='write', &
492) position='append')
493) if (i1 .ne. 0) then
494) write(13,*) 'There was a problem reading the number of electrodes in: ',trim(csrv_file)
495) write(13,*) 'Aborting E4D'
496) i1=-1
497) elseif (i2 .ne. ne) then
498) write(13,*) 'The number of electrodes in file: ',trim(csrv_file)
499) write(13,*) 'is: ',i2
500) write(13,*) 'The number of electrodes in the baseline survey file is: ',ne
501) write(13,*) 'Each survey geometry must be equivalent.'
502) write(13,*) 'Aborting E4D'
503) i1=-1
504) end if
505) close(13)
506) return
507)
508) case(28)
509) open(13,file=trim(log_file),status='old',action='write',position='append')
510) write(13,*) 'There was a problem reading electrode number: ',i1
511) write(13,*) 'in file: ',trim(csrv_file)
512) write(13,*) 'Make sure the electrodes are specified exactly as in the baseline survey file.'
513) write(13,*) 'Aborting E4D'
514) close(13)
515) return
516)
517) case(29)
518) open(13,file=trim(log_file),status='old',action='write', &
519) position='append')
520) if (i1 .ne. 0) then
521) write(13,*) 'There was a problem reading the number of electrodes in: ',trim(csrv_file)
522) write(13,*) 'Aborting E4D'
523) i1=-1
524) elseif (i2 .ne. nm) then
525) write(13,*) 'The number of measurements in file: ',trim(csrv_file)
526) write(13,*) 'is: ',i2
527) write(13,*) 'The number of measurements in the baseline survey file is: ',nm
528) write(13,*) 'Each survey geometry must be equivalent.'
529) write(13,*) 'Aborting E4D'
530) i1=-1
531) end if
532) close(13)
533) return
534)
535) case(30)
536) open(13,file=trim(log_file),status='old',action='write',position='append')
537) write(13,*) 'There was a problem reading measurement number: ',i1
538) write(13,*) 'in file: ',trim(csrv_file)
539) write(13,*) 'Make sure the a,b,m,n is specified exactly as in the baseline survey file.'
540) write(13,*) 'Aborting E4D'
541) close(13)
542) return
543)
544) case(31)
545) open(13,file=trim(log_file),status='old',action='write',position='append')
546) write(13,*) 'There was a problem reading the number of conductivity values in: ',trim(ccond_file)
547) write(13,*) 'Aborting E4D'
548) close(13)
549) return
550)
551)
552) case(32)
553) open(13,file=trim(log_file),status='old',action='write',position='append')
554) write(13,*) 'The number of conductivity values specified in: ',trim(ccond_file)
555) write(13,*) 'is: ',i1
556) write(13,*) 'The number of conductivity values specifed in the elment file is'
557) write(13,*) 'is: ',i2
558) write(13,*) 'Aborting E4D'
559) close(13)
560) return
561)
562) case(33)
563) open(13,file=trim(log_file),status='old',action='write',position='append')
564) write(13,*) 'There was a problem reading conductivity value: ',i1
565) write(13,*) 'in file: ',trim(ccond_file)
566) write(13,*) 'Aborting E4D'
567) close(13)
568) return
569)
570) case(34)
571) open(13,file=trim(log_file),status='old',action='write',position='append')
572) write(13,*) 'The number of elements in the element file is: ',i2
573) write(13,*) 'The number of values in the conductivity files is: ',i1
574) write(13,*) 'Aborting E4D'
575) close(13)
576) return
577)
578) case(35)
579) open(13,file=trim(log_file),status='old',action='write',position='append')
580) write(13,*) "Executing E4D Simulation for Time: ",e4d_time
581) close(13)
582)
583) case(36)
584) open(13,file=trim(log_file),status='old',action='write',position='append')
585) write(13,*) "Received Time: ",pf_time, " from PFLOTRAN"
586) close(13)
587)
588)
589) case(37)
590) inquire(file='pf_mesh.txt',exist=exst)
591) if(.not.exst) then
592) open(13,file=trim(log_file),status='old',action='write',position='append')
593) write(*,*) "E4D couldn't find the pflotran mesh description file pf_mesh.txt"
594) write(*,*) "E4D is aborting ..."
595) write(13,*) "E4D couldn't find the pflotran mesh description file pf_mesh.txt"
596) write(13,*) "Aborting ..."
597) i1=-1
598) close(13)
599) return
600) else
601) i1=0
602) return
603) end if
604)
605) end select
606)
607)
608)
609) end subroutine elog
610) !_________________________________________________________________
611)
612) end module vars