Skip to content

Commit 41b780b

Browse files
committed
Pass cycleNumber to execute/output/collect calls
1 parent 7bccab6 commit 41b780b

File tree

8 files changed

+53
-28
lines changed

8 files changed

+53
-28
lines changed

pygeos-tools/examples/reactiveCompositionalMultiphaseOBL_modeling/2ph_comp/main.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ def run_darts_model( xml_name: str, darts_model=None ):
9898
cycle: int = 0
9999

100100
solver.setDt( 86400.0 )
101-
solver.outputVtk( time )
101+
102102
while time < solver.maxTime:
103103
if time < 604800:
104104
solver.setDt( 86400.0 )
@@ -108,10 +108,14 @@ def run_darts_model( xml_name: str, darts_model=None ):
108108
if rank == 0:
109109
if solver.dt is not None:
110110
print( f"time = {time:.3f}s, dt = {solver.getDt():.4f}, iter = {cycle + 1}" )
111-
solver.execute( time )
111+
112+
solver.outputVtk( time, cycle )
113+
solver.execute( time, cycle )
114+
112115
time += solver.getDt()
113-
solver.outputVtk( time )
114116
cycle += 1
117+
118+
solver.outputVtk( time, cycle )
115119
solver.cleanup( time )
116120

117121

pygeos-tools/examples/reactiveCompositionalMultiphaseOBL_modeling/carbonated_water/main.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,7 @@ def run_darts_model( domain: str, xml_name: str, darts_model=None ):
5050
time: float = 0
5151
cycle: int = 0
5252
solver.setDt( 8.64 )
53-
54-
solver.outputVtk( time )
53+
5554
while time < solver.maxTime:
5655
# choose new timestep
5756
if domain == '1D':
@@ -84,16 +83,20 @@ def run_darts_model( domain: str, xml_name: str, darts_model=None ):
8483
solver.setDt( 100.0 )
8584
if rank == 0:
8685
print( f"time = {time:.3f}s, dt = {solver.getDt():.4f}, step = {cycle + 1}" )
87-
# run simulation
88-
solver.execute( time )
89-
time += solver.getDt()
86+
9087
if cycle % 5 == 0:
91-
solver.outputVtk( time )
88+
solver.outputVtk( time, cycle )
89+
90+
solver.execute( time, cycle )
91+
92+
time += solver.getDt()
9293
cycle += 1
94+
95+
solver.outputVtk( time, cycle )
9396
solver.cleanup( time )
9497

9598

9699
if __name__ == "__main__":
97100
darts_model = Model()
98-
# run_darts_model( domain='1D', xml_name="1d_setup.xml", darts_model=darts_model )
99-
run_darts_model( domain='2D', xml_name="2d_setup.xml", darts_model=darts_model )
101+
run_darts_model( domain='1D', xml_name="1d_setup.xml", darts_model=darts_model )
102+
# run_darts_model( domain='2D', xml_name="2d_setup.xml", darts_model=darts_model )

pygeos-tools/examples/solvers/acoustic_modeling.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,12 +149,17 @@ def main():
149149
while time < solver.maxTime:
150150
if rank == 0 and cycle % 100 == 0:
151151
print( f"time = {time:.3f}s, dt= {solver.dt:.4f}, iter = {cycle + 1}" )
152-
solver.execute( time )
152+
153153
if cycle % 50 == 0:
154-
solver.outputVtk( time )
154+
solver.outputVtk( time, cycle )
155+
156+
solver.execute( time, cycle )
157+
155158
time += solver.dt
156159
cycle += 1
157160

161+
solver.outputVtk( time, cycle )
162+
158163
shot.flag = "Done"
159164
if rank == 0:
160165
print( f"Shot {shot.id} done" )

pygeos-tools/examples/solvers/elastic_modeling.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,17 @@ def main():
8282
while t < solver.maxTime:
8383
if rank == 0 and cycle % 100 == 0:
8484
print( f"time = {t:.3f}s, dt = {solver.dt:.4f}, iter = {cycle + 1}" )
85-
solver.execute( t )
85+
8686
if cycle % 100 == 0:
87-
solver.outputVtk( t )
87+
solver.outputVtk( t, cycle )
88+
89+
solver.execute( t, cycle )
90+
8891
t += solver.dt
8992
cycle += 1
9093

94+
solver.outputVtk( t, cycle )
95+
9196
shot.flag = "Done"
9297
if rank == 0:
9398
print( f"Shot {shot.id} done" )

pygeos-tools/examples/solvers/geomechanics_modeling.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,16 @@ def main():
5353
time: float = 0.0
5454
cycle: int = 0
5555

56-
solver.outputVtk( time )
5756
while time < solver.maxTime:
5857
if rank == 0:
5958
if solver.dt is not None:
6059
print( f"time = {time:.3f}s, dt = {solver.dt:.4f}, iter = {cycle + 1}" )
61-
solver.execute( time )
62-
solver.outputVtk( time )
60+
solver.outputVtk( time, cycle )
61+
solver.execute( time, cycle )
6362
time += solver.dt
6463
cycle += 1
64+
65+
solver.outputVtk( time, cycle )
6566
solver.cleanup( time )
6667

6768

pygeos-tools/examples/solvers/reservoir_modeling.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,17 +53,18 @@ def main():
5353
time: float = 0.0
5454
cycle: int = 0
5555

56-
solver.outputVtk( time )
5756
while time < solver.maxTime:
5857
if rank == 0:
5958
if solver.dt is not None:
6059
print( f"time = {time:.3f}s, dt = {solver.dt:.4f}, iter = {cycle + 1}" )
61-
solver.execute( time )
62-
solver.outputVtk( time )
60+
solver.outputVtk( time, cycle )
61+
solver.execute( time, cycle )
6362
pressure = solver.getPressures()
6463
print( pressure )
6564
time += solver.dt
6665
cycle += 1
66+
67+
solver.outputVtk( time, cycle )
6768
solver.cleanup( time )
6869

6970

pygeos-tools/src/geos/pygeos_tools/solvers/Solver.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -701,34 +701,38 @@ def cleanup( self: Self, time: float ) -> None:
701701
self.solver.cleanup( time )
702702

703703
@required_attributes( "solver" )
704-
def execute( self: Self, time: float ) -> None:
704+
def execute( self: Self, time: float, cycleNumber: int ) -> None:
705705
"""
706706
Do one solver iteration
707707
708708
Parameters
709709
----------
710710
time : float
711711
Current time of simulation
712+
cycleNumber : int
713+
Current cycle number
712714
"""
713-
self.solver.execute( time, self.dt )
715+
self.solver.execute( time, self.dt, cycleNumber )
714716

715717
@required_attributes( "solver" )
716718
def reinitSolver( self: Self ) -> None:
717719
"""Reinitialize Solver"""
718720
self.solver.reinit()
719721

720722
@required_attributes( "vtkOutputs" )
721-
def outputVtk( self: Self, time: float ) -> None:
723+
def outputVtk( self: Self, time: float, cycleNumber: int ) -> None:
722724
"""
723725
Trigger the VTK output
724726
725727
Parameters
726728
----------
727729
time : float
728730
Current time of simulation
731+
cycleNumber : int
732+
Current cycle number
729733
"""
730734
for vtkOutput in self.vtkOutputs:
731-
vtkOutput.output( time, self.dt )
735+
vtkOutput.output( time, self.dt, cycleNumber )
732736

733737
"""
734738
Update methods when initializing or reinitializing the solver

pygeos-tools/src/geos/pygeos_tools/solvers/WaveSolver.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -393,14 +393,16 @@ def filterSource( self: Self, fmax: Union[ str, float ] ) -> None:
393393
self.setGeosWrapperValueByTargetKey( "Events/minTime", self.minTimeSim )
394394
self.sourceValue = np.real( y[ max( i1 - d, 0 ):min( i4 + d, n ), : ] )
395395

396-
def outputWaveField( self: Self, time: float ) -> None:
396+
def outputWaveField( self: Self, time: float, cycleNumber: int ) -> None:
397397
"""
398398
Trigger the wavefield output
399399
400400
Parameters
401401
----------
402402
time : float
403403
Current time of simulation
404+
cycleNumber : int
405+
Current cycle number
404406
"""
405-
self.collections[ 0 ].collect( time, self.dt )
406-
self.hdf5Outputs[ 0 ].output( time, self.dt )
407+
self.collections[ 0 ].collect( time, self.dt, cycleNumber )
408+
self.hdf5Outputs[ 0 ].output( time, self.dt, cycleNumber )

0 commit comments

Comments
 (0)