Skip to content

Commit e9abd8c

Browse files
feat: Pass cycleNumber to execute/output/collect calls (#89)
* Pass cycleNumber to execute/output/collect calls * Update OBL examples for better comparison * Update example doc --------- Co-authored-by: alexbenedicto <[email protected]>
1 parent f45f362 commit e9abd8c

File tree

11 files changed

+72
-40
lines changed

11 files changed

+72
-40
lines changed

docs/pygeos_tools_docs/example.rst

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,12 +117,12 @@ This block contains a ``forceDt`` attribute that will be used later to choose as
117117
118118
The "outputs" event triggers the output of the vtk files. The attribute "timeFrequency" has the same value as "forceDt"
119119
so we can use the same timestep for the solver and the outputs.
120-
To start, we will set the time to 0.0 and trigger one output of the vtk files.
120+
To start, we will set the time to 0.0 and the cycle number to 0.
121121

122122
.. code-block:: python
123123
124124
time = 0.0
125-
solver.outputVtk( time )
125+
cycle = 0
126126
127127
128128
------------------------------------------------------------------
@@ -135,9 +135,12 @@ Once done, the simulation is ended by calling the ``cleanup`` method.
135135
.. code-block:: python
136136
137137
while time < solver.maxTime:
138-
solver.execute( time )
139-
solver.outputVtk( time )
138+
solver.outputVtk( time, cycle )
139+
solver.execute( time, cycle )
140140
time += solver.dt
141+
cycle += 1
142+
143+
solver.outputVtk( time, cycle )
141144
solver.cleanup( time )
142145
143146

pygeos-tools/examples/reactiveCompositionalMultiphaseOBL_modeling/2ph_comp/input_file_adaptive.xml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@
1616
newtonTol="0.0001"
1717
newtonMaxIter="25"/>
1818
<LinearSolverParameters
19-
directParallel="0"/>
19+
solverType="fgmres"
20+
preconditionerType="mgr"
21+
krylovTol="1.0e-5"/>
2022
</ReactiveCompositionalMultiphaseOBL>
2123
</Solvers>
2224

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/1d_setup.xml

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@
1818
newtonTol="0.0001"
1919
newtonMaxIter="25"/>
2020
<LinearSolverParameters
21-
directParallel="0"/>
21+
solverType="fgmres"
22+
preconditionerType="mgr"
23+
krylovTol="1.0e-5"/>
2224
</ReactiveCompositionalMultiphaseOBL>
2325
</Solvers>
2426

@@ -101,23 +103,23 @@
101103
objectPath="ElementRegions/Region1"
102104
fieldName="globalCompFraction"
103105
component="0"
104-
scale="0.7"/>
106+
scale="0.276839"/>
105107
<FieldSpecification
106108
name="Region1InitCa"
107109
initialCondition="1"
108110
setNames="{ all }"
109111
objectPath="ElementRegions/Region1"
110112
fieldName="globalCompFraction"
111113
component="1"
112-
scale="0.0"/>
114+
scale="1e-11"/>
113115
<FieldSpecification
114116
name="Region1InitC"
115117
initialCondition="1"
116118
setNames="{ all }"
117119
objectPath="ElementRegions/Region1"
118120
fieldName="globalCompFraction"
119121
component="2"
120-
scale="0.0"/>
122+
scale="1e-11"/>
121123
<FieldSpecification
122124
name="Region1InitO"
123125
initialCondition="1"
@@ -139,7 +141,7 @@
139141
name="inj1Pressure"
140142
objectPath="ElementRegions/Region1"
141143
fieldName="pressure"
142-
scale="10010000.0"
144+
scale="10005000.0"
143145
setNames="{ inj1 }"/>
144146
<FieldSpecification
145147
name="inj1Calcite"
@@ -219,21 +221,21 @@
219221
objectPath="ElementRegions/Region1"
220222
fieldName="globalCompFraction"
221223
component="0"
222-
scale="0.7"/>
224+
scale="0.276839"/>
223225
<FieldSpecification
224226
name="prd1Ca"
225227
setNames="{ prd1 }"
226228
objectPath="ElementRegions/Region1"
227229
fieldName="globalCompFraction"
228230
component="1"
229-
scale="0.0"/>
231+
scale="1e-11"/>
230232
<FieldSpecification
231233
name="prd1C"
232234
setNames="{ prd1 }"
233235
objectPath="ElementRegions/Region1"
234236
fieldName="globalCompFraction"
235237
component="2"
236-
scale="0.0"/>
238+
scale="1e-11"/>
237239
<FieldSpecification
238240
name="prd1O"
239241
setNames="{ prd1 }"

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

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ def run_darts_model( domain: str, xml_name: str, darts_model=None ):
5151
cycle: int = 0
5252
solver.setDt( 8.64 )
5353

54-
solver.outputVtk( time )
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)