Skip to content

Commit

Permalink
Merge pull request #46 from jrleeman/savedata
Browse files Browse the repository at this point in the history
Add Text File Output
  • Loading branch information
jrleeman committed Dec 1, 2019
2 parents 40f43f6 + edc92e0 commit dd2d33d
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 1 deletion.
30 changes: 30 additions & 0 deletions environment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Create full conda environment for development, including some useful tools
name: rsfmodel
channels:
- conda-forge/label/testing
- conda-forge
dependencies:
- python>=3.6
- numpy
- scipy
- matplotlib
- sphinx
- sphinx-gallery
- sphinx_rtd_theme
- pytest>=2.4
- pytest-cov
- pytest-flake8
- pytest-mpl
- pytest-runner
- flake8-builtins!=1.4.0
- flake8-comprehensions
- flake8-copyright
- flake8-docstrings
- flake8-import-order
- flake8-mutable
- flake8-pep3101
- flake8-print
- flake8-quotes
- pep8-naming
- doc8
- recommonmark
3 changes: 3 additions & 0 deletions examples/velocity_step_two_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@
# Run the model!
model.solve()

# Save the model output
model.savetxt('model_output.txt')

# Make the 2D phase plot
plot.phasePlot(model)

Expand Down
36 changes: 36 additions & 0 deletions rsfmodel/rsf.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,42 @@ def __init__(self):
"slider_velocity", "friction",
"states", "slider_displacement"])


def savetxt(self, fname, line_ending='\n'):
""" Save the output of the model to a csv file.
"""
with open(fname, 'w') as f:
# Model Properties
f.write(f'mu0 = {self.mu0}{line_ending}')
f.write(f'a = {self.a}{line_ending}')
f.write(f'vref = {self.vref}{line_ending}')
f.write(f'k = {self.k}{line_ending}')
for i, state in enumerate(self.state_relations):
f.write(f'State {i + 1}{line_ending}')
f.write(str(state))

# Header
f.write('Time,Loadpoint_Displacement,Slider_Velocity,Friction,')
f.write(f'Slider_Displacement')
for i, state in enumerate(self.state_relations):
f.write(f',State_{i + 1}')
f.write(line_ending)

# Data
i = 0
for row in zip(self.results.time,
self.results.loadpoint_displacement,
self.results.slider_velocity,
self.results.friction,
self.results.slider_displacement):
t, lp_disp, s_vel, fric, s_disp = row
f.write(f'{t},{lp_disp},{s_vel},{fric},{s_disp}')
for state in self.state_relations:
f.write(f',{state.state[i]}')
f.write(f'{line_ending}')
i += 1


def _integrationStep(self, w, t, system):
""" Do the calculation for a time-step
Expand Down
25 changes: 25 additions & 0 deletions rsfmodel/staterelations.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ class DieterichState(StateRelation):
results and constitutive equations." Journal of Geophysical
Research: Solid Earth (19782012) 84.B5 (1979): 2161-2168.
"""
def __str__(self):
s = 'Dieterich State Relation\n'
s += f'b = {self.b}\n'
s += f'Dc = {self.Dc}\n'
return s

def set_steady_state(self, system):
self.state = self.Dc/system.vref

Expand All @@ -65,6 +71,12 @@ class RuinaState(StateRelation):
.. [#Ruina1983] Ruina, Andy. "Slip instability and state variable friction laws."
J. geophys. Res 88.10 (1983): 359-10.
"""
def __str__(self):
s = 'Ruina State Relation\n'
s += f'b = {self.b}\n'
s += f'Dc = {self.Dc}\n'
return s

def set_steady_state(self, system):
self.state = self.Dc/system.vref

Expand All @@ -85,6 +97,12 @@ class PrzState(StateRelation):
"Self-healing slip pulse on a frictional surface."
Journal of the Mechanics and Physics of Solids 43.9 (1995): 1461-1495.
"""
def __str__(self):
s = 'PRZ State Relation\n'
s += f'b = {self.b}\n'
s += f'Dc = {self.Dc}\n'
return s

def set_steady_state(self, system):
self.state = 2 * self.Dc / system.v
self.prz_vref = system.vref/(2*self.Dc)
Expand Down Expand Up @@ -117,6 +135,13 @@ class NagataState(StateRelation):
evolution laws separately with laboratory data," Journal of Geophysical
Research: Solid Earth, vol 117, 2012.
"""
def __str__(self):
s = 'Nagata State Relation\n'
s += f'b = {self.b}\n'
s += f'c = {self.c}\n'
s += f'Dc = {self.Dc}\n'
return s

def __init__(self):
StateRelation.__init__(self)
self.c = None
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
'url': 'http://github.com/jrleeman/rsfmodel',
'download_url': 'http://github.com/jrleeman/rsfmodel',
'author_email': '[email protected]',
'version': '0.1',
'version': '0.2',
'install_requires': ['nose'],
'packages': ['rsfmodel'],
'scripts': [],
Expand Down

0 comments on commit dd2d33d

Please sign in to comment.