<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">#!/usr/bin/env python

'''
-------------------
Copyright (c) 2015 Computational Biomechanics (CoBi) Core, Department of
Biomedical Engineering, Cleveland Clinic

Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to permit
persons to whom the Software is furnished to do so, subject to the
following conditions:

The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
USE OR OTHER DEALINGS IN THE SOFTWARE.
-------------------

WRITTEN BY:
-----------
Craig Bennetts, MS
Computational Biomodeling (CoBi) Core
Department of Biomedical Engineering
Lerner Research Institute
Cleveland Clinic
Cleveland, OH
bennect2@ccf.org


DESCRIPTION:
------------
Reads a batch of FEBio .log files and creates text files that rank the simulations
according to a set of desired FEBio simulation results.


LEGEND:
-------
&lt;...&gt; = variable argument

USAGE:
------
./plot_FEBio_sim_time.py &lt;FEBio_TIME.txt&gt; &amp;


ASSUMPTION:
-----------
- FEBio .log files are in simulation batch folders (generated by SLURM_FEBio_BATCH.py),
  with the following format:
  	sim_&lt;param#.1&gt;_..._&lt;param#.N&gt;
- script should be run in the parent folder of the batch simulation subfolders
  =&gt; input argument should include subfolders, e.g.:
     sim_*/*.log
- simulations will be identified by the subfolder name in output files


INPUT FILE:
-----------

&lt;FEBio_TIME.txt&gt;

	each line has a single converged time value (for an FEBio simulation)
 
'''


import sys
import matplotlib.pyplot as plt

def USAGE(argv):

	print
	print 'USAGE: ' + argv[0] + ' &lt;FEBio_TIME.txt&gt; &amp;'
	print


def plot_FEBio_sim_time(argv):

	# CHECK SCRIPT USAGE
	if len(argv)!=2:
		USAGE(argv)
		sys.exit(1)

	#log_filenames = argv[1:]
	sim_time_filename = argv[1]

	# READ LOG FILE
	SimTimeFile = open(sim_time_filename,'r')
	SimTimeLines = SimTimeFile.readlines()
	SimTimeFile.close()

	# assumes TIME.txt file does not include t=0.0
	t = [0.0]
	dt = [0.0]

	for line in SimTimeLines:
		t.append( float(line) )
		#if len(t)&gt;1:
		dt.append( t[-1] - t[-2] )
		#else:
		#	dt.append( 0.0 )

	plt.plot( t, dt, '.-')
	plt.xlabel('t')
	plt.ylabel('dt')
	plt.gca().set_aspect('equal', adjustable='box')
	#plt.xlim(0.0, t[-1])
	#plt.ylim(0.0, t[-1])
	plt.show()

# END OF plot_FEBio_sim_time()


# Default calls SLURM_FEBio_BATCH() if this script is not called as a function
if __name__ == "__main__":
	plot_FEBio_sim_time(sys.argv)</pre></body></html>