Skip to content

Commit 864954a

Browse files
committed
Minor updates so that compatible with python3
1 parent 0fca20c commit 864954a

File tree

2 files changed

+36
-32
lines changed

2 files changed

+36
-32
lines changed
Binary file not shown.

n88/documentation/faim/9.0/doc/manual/html/index.html

Lines changed: 36 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -7932,7 +7932,7 @@ <h4 id="_preliminaries_first_lines_of_python">7.5.2. Preliminaries: first lines
79327932
</div>
79337933
<div class="listingblock">
79347934
<div class="content">
7935-
<pre>script_version = 3</pre>
7935+
<pre>script_version = 4</pre>
79367936
</div>
79377937
</div>
79387938
<div class="paragraph">
@@ -8010,7 +8010,7 @@ <h4 id="_reading_the_input_file">7.5.3. Reading the input file</h4>
80108010
</div>
80118011
<div class="listingblock">
80128012
<div class="content">
8013-
<pre>print "Reading", args.input_file
8013+
<pre>print(f"Reading, {args.input_file}")
80148014
reader = vtk.vtkXMLImageDataReader()
80158015
reader.SetFileName(args.input_file)
80168016
reader.Update()
@@ -8054,10 +8054,10 @@ <h4 id="_reading_the_input_file">7.5.3. Reading the input file</h4>
80548054
<div class="listingblock">
80558055
<div class="content">
80568056
<pre>if not image:
8057-
print "No image data read."
8057+
print("No image data read.")
80588058
sys.exit(1)
80598059

8060-
print "Read image with dimensions", image.GetDimensions()</pre>
8060+
print(f"Read image with point dimensions: {image.GetDimensions()}")</pre>
80618061
</div>
80628062
</div>
80638063
<div class="paragraph">
@@ -8110,7 +8110,7 @@ <h4 id="_ensuring_connectivity">7.5.4. Ensuring connectivity</h4>
81108110
</div>
81118111
<div class="listingblock">
81128112
<div class="content">
8113-
<pre>print "Applying connectivity filter."
8113+
<pre>print("Applying connectivity filter.")
81148114
connectivity_filter = vtkbone.vtkboneImageConnectivityFilter()
81158115
connectivity_filter.SetExtractionModeToLargestRegion()
81168116
connectivity_filter.SetInputData(image)
@@ -8163,8 +8163,7 @@ <h4 id="_generating_a_mesh_2">7.5.5. Generating a mesh</h4>
81638163
geometry_generator.Update()
81648164
geometry = geometry_generator.GetOutput()
81658165

8166-
print "Generated %d elements and %d nodes." % \
8167-
(geometry.GetNumberOfCells(), geometry.GetNumberOfPoints())</pre>
8166+
print(f"Generated {geometry.GetNumberOfCells()} elements and {geometry.GetNumberOfPoints()} nodes.")</pre>
81688167
</div>
81698168
</div>
81708169
<div class="paragraph">
@@ -8203,7 +8202,7 @@ <h4 id="_generating_a_mesh_2">7.5.5. Generating a mesh</h4>
82038202
<div class="content">
82048203
<pre>writer = vtk.vtkXMLUnstructuredGridWriter()
82058204
geometry_file = "geometry.vtu"
8206-
print "Writing geometry to", geometry_file
8205+
print(f"Writing geometry to {geometry_file}")
82078206
writer.SetFileName(geometry_file)
82088207
writer.SetInputData(geometry)
82098208
writer.Write()</pre>
@@ -8224,7 +8223,7 @@ <h4 id="_defining_materials_and_creating_a_material_table">7.5.6. Defining mater
82248223
</div>
82258224
<div class="listingblock">
82268225
<div class="content">
8227-
<pre>print "Creating a linear isotropic material."
8226+
<pre>print("Creating a linear isotropic material.")
82288227
material = vtkbone.vtkboneLinearIsotropicMaterial()
82298228
material.SetName("linear_iso_material") <img src="./images/icons/callouts/1.png" alt="1">
82308229
material.SetYoungsModulus(6829) <img src="./images/icons/callouts/2.png" alt="2">
@@ -8268,7 +8267,7 @@ <h4 id="_defining_materials_and_creating_a_material_table">7.5.6. Defining mater
82688267
mt_generator.SetMaterialIdList(image.GetCellData().GetScalars()) <img src="./images/icons/callouts/1.png" alt="1">
82698268
mt_generator.Update()
82708269
material_table = mt_generator.GetOutput()
8271-
print "Generated material table with %d entries." % material_table.GetNumberOfMaterials()</pre>
8270+
print(f"Generated material table with {material_table.GetNumberOfMaterials()} entries.")</pre>
82728271
</div>
82738272
</div>
82748273
<div class="colist arabic">
@@ -8294,7 +8293,7 @@ <h4 id="_applying_a_compression_test">7.5.7. Applying a compression test</h4>
82948293
<div class="content">
82958294
<pre># Apply a compression test (uniaxial)
82968295

8297-
print "Applying a uniaxial compression test."
8296+
print("Applying a uniaxial compression test.")
82988297
generator = vtkbone.vtkboneApplyCompressionTest()
82998298
generator.SetInputData(0, geometry) <img src="./images/icons/callouts/1.png" alt="1">
83008299
generator.SetInputData(1, material_table) <img src="./images/icons/callouts/2.png" alt="2">
@@ -8333,7 +8332,7 @@ <h4 id="_writing_an_n88model_file">7.5.8. Writing an n88model file</h4>
83338332
# Remove directory, so file ends up in current directory.
83348333
output_file = os.path.split(output_file)[1]
83358334

8336-
print "Writing n88model file:", output_file
8335+
print(f"Writing n88model file: {output_file}")
83378336
writer = vtkbone.vtkboneN88ModelWriter()
83388337
writer.SetInputData(model)
83398338
writer.SetFileName(output_file)
@@ -8390,7 +8389,7 @@ <h4 id="_modifying_the_file_history_and_log">7.5.9. Modifying the file history a
83908389
</div>
83918390
<div class="listingblock">
83928391
<div class="content">
8393-
<pre>model.AppendHistory("Created by apply_compression.py version %s ." % script_version)</pre>
8392+
<pre>model.AppendHistory(f"Created by cube_compression.py version {script_version}.")</pre>
83948393
</div>
83958394
</div>
83968395
<div class="paragraph">
@@ -8672,7 +8671,7 @@ <h4 id="_generating_the_image_data">7.6.3. Generating the image data</h4>
86728671
<div class="content">
86738672
<pre># Optional: write out image data to examine it
86748673

8675-
print ("Writing geometry file: beam_image.vti")
8674+
print("Writing geometry file: beam_image.vti")
86768675
writer = vtk.vtkXMLImageDataWriter()
86778676
writer.SetInputData(image)
86788677
writer.SetFileName("beam_image.vti")
@@ -8762,7 +8761,7 @@ <h4 id="_generating_a_base_model_without_boundary_conditions">7.6.4. Generating
87628761
<div class="content">
87638762
<pre># Write an n88model file
87648763

8765-
print "Writing n88model file:", args.output_file
8764+
print(f"Writing n88model file: {args.output_file}")
87668765
writer = vtkbone.vtkboneN88ModelWriter()
87678766
writer.SetInputData(model)
87688767
writer.SetFileName(args.output_file)
@@ -9149,13 +9148,14 @@ <h4 id="_documenting_the_model_in_the_file_log">7.6.9. Documenting the model in
91499148
<div class="content">
91509149
<pre># Update history and log
91519150

9152-
model.AppendHistory("Created by create_cantilever.py version %s ." % script_version)
9151+
model.AppendHistory(f"Created by create_cantilever.py version {script_version} .")
91539152

91549153
model.AppendLog(
9155-
"""create_cantilever.py
9156-
Cantilever beam model with applied force on far face of %s .
9157-
Using vtkbone version %s .
9158-
""" % (args.applied_force, vtkbone.vtkboneVersion.GetVTKBONEVersion()))</pre>
9154+
f"""create_cantilever.py
9155+
Cantilever beam model with applied force on far face edge of {args.applied_force} .
9156+
Using vtkbone version {vtkbone.vtkboneVersion.GetvtkboneVersion()} .
9157+
"""
9158+
)</pre>
91599159
</div>
91609160
</div>
91619161
<div class="paragraph">
@@ -9744,7 +9744,7 @@ <h4 id="_incremental_loading_and_hysteresis">7.7.7. Incremental loading and hyst
97449744

97459745
# Read existing model (including possible solution)
97469746

9747-
print "Reading n88model file:", args.input_file
9747+
print(f"Reading n88model file: {args.input_file}")
97489748
reader = vtkbone.vtkboneN88ModelReader()
97499749
reader.SetFileName (args.input_file)
97509750
reader.Update()
@@ -9781,17 +9781,18 @@ <h4 id="_incremental_loading_and_hysteresis">7.7.7. Incremental loading and hyst
97819781
<div class="content">
97829782
<pre># Update history and log
97839783

9784-
model.AppendHistory("Modified modify_force.py version %s ." % script_version)
9784+
model.AppendHistory(f"Modified modify_force.py version {script_version} .")
97859785

97869786
model.AppendLog(
97879787
"""modify_force.py
9788-
Changed applied force on far face edge to %s .
9789-
Using VTKBONE version %s .
9790-
""" % (args.applied_force, vtkbone.vtkboneVersion.GetVTKBONEVersion()))
9788+
Changed applied force on far face edge to {args.applied_force} .
9789+
Using vtkbone version {vtkbone.vtkboneVersion.GetvtkboneVersion()} .
9790+
"""
9791+
)
97919792

97929793
# Write an n88model file
97939794

9794-
print "Writing n88model file:", args.output_file
9795+
print(f"Writing n88model file: {args.output_file}")
97959796
writer = vtkbone.vtkboneN88ModelWriter()
97969797
writer.SetInputData(model)
97979798
writer.SetFileName(args.output_file)
@@ -10220,9 +10221,10 @@ <h4 id="_preliminaries_first_lines_of_python_2">7.8.2. Preliminaries: first line
1022010221
The first argument is printed with a time stamp.
1022110222
Subsequent arguments are printed one to a line without a timestamp.
1022210223
"""
10223-
print "%8.2f %s" % (time.time()-start_time, msg)
10224+
print(f"{(time.time()-start_time):8.2f} {msg}")
1022410225
for line in additionalLines:
10225-
print " " * 9 + line
10226+
print(" "*9 + line)
10227+
1022610228
start_time = time.time()</pre>
1022710229
</div>
1022810230
</div>
@@ -10288,7 +10290,7 @@ <h4 id="_using_a_configuration_file_to_store_parameters">7.8.3. Using a configur
1028810290
<p>A bit of code to get the configuration file name from the command line.</p>
1028910291
</li>
1029010292
<li>
10291-
<p>One line to execute the configuration file as Python code.</p>
10293+
<p>A few lines to execute the configuration file as Python code.</p>
1029210294
</li>
1029310295
<li>
1029410296
<p>Some lines to print out all the values that we expected to read in. This is very good practice so when you run it, you can verify that everything is as you expect.</p>
@@ -10301,14 +10303,16 @@ <h4 id="_using_a_configuration_file_to_store_parameters">7.8.3. Using a configur
1030110303
<div class="listingblock">
1030210304
<div class="content">
1030310305
<pre>if len(sys.argv) != 2:
10304-
print "Usage: python screwpullout.py example.conf"
10306+
print("Usage: python screwpullout.py example.conf")
1030510307
sys.exit(1)
1030610308
config_file = sys.argv[1]
1030710309

1030810310
# Read in configuration file.
1030910311
message("Reading configuration file " + config_file)
1031010312
# Here we are actually executing it as python code.
10311-
execfile(config_file)
10313+
with open(config_file) as f:
10314+
code = compile(f.read(), config_file, 'exec')
10315+
exec(code)
1031210316

1031310317
# Print out values that we read in. This also has the effect of causing
1031410318
# this script to die if configuration values are missing (which is a good thing).
@@ -17598,7 +17602,7 @@ <h2 id="_colophon">Colophon</h2>
1759817602
</div>
1759917603
<div id="footer">
1760017604
<div id="footer-text">
17601-
Last updated 2020-04-30 21:19:16 -0600
17605+
Last updated 2021-06-18 12:47:47 -0600
1760217606
</div>
1760317607
</div>
1760417608
<script type="text/x-mathjax-config">

0 commit comments

Comments
 (0)