|
1 | 1 | import argparse
|
2 | 2 | import os
|
| 3 | + |
| 4 | +#GEOS |
3 | 5 | from geos.pygeos_tools.utilities.input import XML
|
4 | 6 | from geos.pygeos_tools.utilities.acquisition_library.EquispacedAcquisition import EQUISPACEDAcquisition
|
5 | 7 | from geos.pygeos_tools.utilities.solvers import AcousticSolver
|
6 | 8 | from geos.pygeos_tools.utilities.output import SeismicTraceOutput
|
7 |
| -from mpi4py import MPI |
8 | 9 |
|
| 10 | +import mpi4py |
| 11 | +mpi4py.rc.initialize = True |
| 12 | +from mpi4py import MPI |
9 | 13 |
|
10 | 14 | def parse_args():
|
11 | 15 | """Get arguments
|
12 | 16 |
|
13 | 17 | Returns:
|
14 | 18 | argument '--xml': Input xml file for GEOSX
|
15 | 19 | """
|
16 |
| - parser = argparse.ArgumentParser( description="Modeling acquisition example - Acoustic" ) |
17 |
| - parser.add_argument( '--xml', type=str, required=True, help="Input xml file for GEOS" ) |
18 |
| - parser.add_argument( '--soutdir', required=False, type=str, default="./", help="Path to seismogram output dir" ) |
19 |
| - parser.add_argument( '--soutn', required=False, type=str, default="seismo", help="Name of output seismograms" ) |
20 |
| - parser.add_argument( '--param_file', |
21 |
| - type=str, |
22 |
| - required=False, |
23 |
| - default="identity", |
24 |
| - dest="pfile", |
25 |
| - help="Optional file containing modelling parameters" ) |
26 |
| - |
27 |
| - args, _ = parser.parse_known_args() |
| 20 | + parser = argparse.ArgumentParser(description="Modeling acquisition example - Acoustic") |
| 21 | + parser.add_argument('--xml', type=str, required=True, |
| 22 | + help="Input xml file for GEOS") |
| 23 | + parser.add_argument('--soutdir', required=False, type=str, default="./", |
| 24 | + help="Path to seismogram output dir") |
| 25 | + parser.add_argument('--soutn', required=False, type=str, default="seismo", |
| 26 | + help="Name of output seismograms") |
| 27 | + parser.add_argument('--param_file', type=str, required=False, default="identity", dest="pfile", help="Optional file containing modelling parameters") |
| 28 | + |
| 29 | + args ,_ = parser.parse_known_args() |
28 | 30 | return args
|
29 | 31 |
|
30 |
| - |
31 |
| -def parse_workflow_parameters( pfile ): |
32 |
| - with open( pfile, "r" ) as f: |
| 32 | +def parse_workflow_parameters(pfile): |
| 33 | + with open(pfile, "r") as f: |
33 | 34 | hdrStr = f.read()
|
34 | 35 |
|
35 | 36 | hdrList = []
|
36 |
| - for fl in hdrStr.split( '\n' ): |
37 |
| - l = fl.split( "#" )[ 0 ] |
| 37 | + for fl in hdrStr.split('\n'): |
| 38 | + l = fl.split("#")[0] |
38 | 39 | if l:
|
39 | 40 | # add "--" to facilitate parsing that follows
|
40 | 41 | l = "--" + l
|
41 |
| - hdrList += l.split( "=" ) |
42 |
| - |
43 |
| - parser = argparse.ArgumentParser( "Modelling workflow parser" ) |
44 |
| - parser.add_argument( "--mintime", dest="mintime", default=None, type=float, help="Min time for the simulation" ) |
45 |
| - parser.add_argument( "--maxtime", dest="maxtime", default=None, type=float, help="Max time for the simulation" ) |
46 |
| - parser.add_argument( "--dt", dest="dt", default=None, type=float, help="Time step of simulation" ) |
47 |
| - parser.add_argument( "--dtSeismo", dest="dtSeismo", default=None, type=float, help="Time step for " ) |
48 |
| - parser.add_argument( "--sourceType", dest="sourceType", type=str, help="Source type" ) |
49 |
| - parser.add_argument( "--sourceFreq", dest="sourceFreq", type=float, help="Ricker source central frequency" ) |
50 |
| - |
51 |
| - args, _ = parser.parse_known_args( hdrList ) |
| 42 | + hdrList += l.split("=") |
| 43 | + |
| 44 | + parser = argparse.ArgumentParser("Modelling workflow parser") |
| 45 | + parser.add_argument("--mintime", dest="mintime", |
| 46 | + default=None, type=float, |
| 47 | + help="Min time for the simulation") |
| 48 | + parser.add_argument("--maxtime", dest="maxtime", |
| 49 | + default=None, type=float, |
| 50 | + help="Max time for the simulation") |
| 51 | + parser.add_argument("--dt", dest="dt", |
| 52 | + default=None, type=float, |
| 53 | + help="Time step of simulation") |
| 54 | + parser.add_argument("--dtSeismo", dest="dtSeismo", |
| 55 | + default=None, type=float, |
| 56 | + help="Time step for ") |
| 57 | + parser.add_argument("--sourceType", dest="sourceType", |
| 58 | + type=str, |
| 59 | + help="Source type") |
| 60 | + parser.add_argument("--sourceFreq", dest="sourceFreq", |
| 61 | + type=float, |
| 62 | + help="Ricker source central frequency") |
| 63 | + |
| 64 | + args, _ = parser.parse_known_args(hdrList) |
52 | 65 | return args
|
53 | 66 |
|
54 | 67 |
|
55 | 68 | def main():
|
| 69 | + |
| 70 | + if MPI.Is_initialized(): |
| 71 | + print("MPI initialized") |
| 72 | + else: |
| 73 | + print("MPI not initialized. Initializing...") |
| 74 | + MPI.Init() |
| 75 | + |
56 | 76 | comm = MPI.COMM_WORLD
|
57 | 77 | rank = comm.Get_rank()
|
58 |
| - |
| 78 | + |
59 | 79 | args = parse_args()
|
60 | 80 | xmlfile = args.xml
|
61 | 81 |
|
62 |
| - xml = XML( xmlfile ) |
| 82 | + xml = XML(xmlfile) |
63 | 83 |
|
64 |
| - wf_args = parse_workflow_parameters( args.pfile ) |
| 84 | + wf_args = parse_workflow_parameters(args.pfile) |
65 | 85 |
|
66 |
| - # Time Parameters |
| 86 | + #Time Parameters |
67 | 87 | minTime = wf_args.mintime
|
68 | 88 | maxTime = wf_args.maxtime
|
69 | 89 | dt = wf_args.dt
|
70 | 90 | dtSeismo = wf_args.dtSeismo
|
71 | 91 |
|
72 |
| - # Output parameters |
| 92 | + #Output parameters |
73 | 93 | outdirseis = args.soutdir
|
74 |
| - os.makedirs( outdirseis, exist_ok=True ) |
| 94 | + os.makedirs(outdirseis, exist_ok=True) |
75 | 95 | outseisname = args.soutn
|
76 |
| - |
77 |
| - # Source parameters |
| 96 | + |
| 97 | + #Source parameters |
78 | 98 | sourceType = wf_args.sourceType
|
79 | 99 | sourceFreq = wf_args.sourceFreq
|
80 |
| - |
| 100 | + |
| 101 | + |
81 | 102 | # Read acquisition
|
82 | 103 | if rank == 0:
|
83 |
| - # acquisition = Acquisition(xml) |
84 |
| - acquisition = EQUISPACEDAcquisition( xml=xml, |
85 |
| - startFirstSourceLine=[ 305.01, 305.01, 5.01 ], |
86 |
| - endFirstSourceLine=[ 325.01, 305.01, 5.01 ], |
87 |
| - startLastSourceLine=[ 305.01, 325.01, 5.01 ], |
88 |
| - endLastSourceLine=[ 325.01, 325.01, 5.01 ], |
89 |
| - numberOfSourceLines=2, |
90 |
| - sourcesPerLine=2, |
91 |
| - startFirstReceiversLine=[ 121.02, 255.02, 58.01 ], |
92 |
| - endFirstReceiversLine=[ 471.02, 255.02, 58.01 ], |
93 |
| - startLastReceiversLine=[ 121.02, 255.02, 58.01 ], |
94 |
| - endLastReceiversLine=[ 471.02, 255.02, 58.01 ], |
95 |
| - numberOfReceiverLines=1, |
96 |
| - receiversPerLine=8 ) |
| 104 | + #acquisition = Acquisition(xml) |
| 105 | + acquisition = EQUISPACEDAcquisition(xml=xml, |
| 106 | + startFirstSourceLine=[305.01,305.01,5.01], |
| 107 | + endFirstSourceLine=[325.01,305.01,5.01], |
| 108 | + startLastSourceLine=[305.01,325.01,5.01], |
| 109 | + endLastSourceLine=[325.01,325.01,5.01], |
| 110 | + numberOfSourceLines=2, |
| 111 | + sourcesPerLine=2, |
| 112 | + startFirstReceiversLine=[121.02,255.02,58.01], |
| 113 | + endFirstReceiversLine=[471.02,255.02,58.01], |
| 114 | + startLastReceiversLine=[121.02,255.02,58.01], |
| 115 | + endLastReceiversLine=[471.02,255.02,58.01], |
| 116 | + numberOfReceiverLines=1, |
| 117 | + receiversPerLine=8) |
97 | 118 |
|
98 | 119 | else:
|
99 | 120 | acquisition = None
|
100 |
| - acquisition = comm.bcast( acquisition, root=0 ) |
| 121 | + acquisition = comm.bcast(acquisition, root=0) |
101 | 122 |
|
102 |
| - solver = AcousticSolver( dt, minTime, maxTime, dtSeismo, sourceType, sourceFreq ) |
| 123 | + solver = AcousticSolver(dt, |
| 124 | + minTime, |
| 125 | + maxTime, |
| 126 | + dtSeismo, |
| 127 | + sourceType, |
| 128 | + sourceFreq) |
103 | 129 |
|
104 |
| - for ishot, shot in enumerate( acquisition.shots ): |
| 130 | + for ishot, shot in enumerate(acquisition.shots): |
105 | 131 | xmlshot = shot.xml
|
106 | 132 | rank = comm.Get_rank()
|
107 |
| - |
108 |
| - solver.initialize( rank, xmlshot ) |
| 133 | + |
| 134 | + solver.initialize(rank, xmlshot) |
109 | 135 | solver.applyInitialConditions()
|
110 | 136 |
|
111 |
| - solver.updateSourceAndReceivers( shot.getSourceCoords(), shot.getReceiverCoords() ) |
112 |
| - solver.updateVtkOutputsName( directory=f"Shot{shot.id}" ) |
113 |
| - |
| 137 | + solver.updateSourceAndReceivers(shot.getSourceCoords(), shot.getReceiverCoords()) |
| 138 | + solver.updateVtkOutputsName(directory=f"Shot{shot.id}") |
| 139 | + |
114 | 140 | t = 0
|
115 |
| - cycle = 0 |
116 |
| - while t < solver.maxTime: |
117 |
| - if rank == 0 and cycle % 100 == 0: |
118 |
| - print( f"time = {t:.3f}s, dt = {solver.dt:.4f}, iter = {cycle+1}" ) |
119 |
| - solver.execute( t ) |
120 |
| - if cycle % 50 == 0: |
121 |
| - solver.outputVtk( t ) |
| 141 | + cycle = 0 |
| 142 | + while t < solver.maxTime : |
| 143 | + if rank == 0 and cycle%100 == 0: |
| 144 | + print(f"time = {t:.3f}s, dt = {solver.dt:.4f}, iter = {cycle+1}") |
| 145 | + solver.execute(t) |
| 146 | + if cycle%50 == 0: |
| 147 | + solver.outputVtk(t) |
122 | 148 | t += solver.dt
|
123 | 149 | cycle += 1
|
124 |
| - |
| 150 | + |
125 | 151 | shot.flag = "Done"
|
126 |
| - if rank == 0: |
127 |
| - print( f"Shot {shot.id} done" ) |
128 |
| - print( "Gathering and exporting seismos" ) |
| 152 | + if rank == 0 : |
| 153 | + print(f"Shot {shot.id} done") |
| 154 | + print("Gathering and exporting seismos") |
129 | 155 |
|
130 | 156 | seismos = solver.getPressureAtReceivers()
|
131 |
| - |
| 157 | + |
132 | 158 | directory = outdirseis
|
133 | 159 | filename = f"{outseisname}_{shot.id}"
|
134 |
| - |
135 |
| - SeismicTraceOutput( seismos, format="SEP" ).export( directory=directory, |
136 |
| - rootname=filename, |
137 |
| - receiverCoords=shot.getReceiverCoords(), |
138 |
| - sourceCoords=shot.getSourceCoords()[ 0 ], |
139 |
| - dt=solver.dtSeismo ) |
140 |
| - |
| 160 | + |
| 161 | + SeismicTraceOutput(seismos, format="SEP").export(directory=directory, rootname=filename, receiverCoords=shot.getReceiverCoords(), sourceCoords=shot.getSourceCoords()[0], dt=solver.dtSeismo) |
| 162 | + |
141 | 163 | solver.resetWaveField()
|
142 | 164 |
|
143 |
| - |
144 | 165 | if __name__ == "__main__":
|
145 | 166 | main()
|
0 commit comments