Skip to content

Commit

Permalink
Merge pull request #11 from chenle02/Tetris_Domino
Browse files Browse the repository at this point in the history
Complete the first version of the doc
  • Loading branch information
chenle02 committed Dec 2, 2023
2 parents 6480e33 + 8da0a59 commit 805f414
Show file tree
Hide file tree
Showing 15 changed files with 313 additions and 70 deletions.
132 changes: 103 additions & 29 deletions Ballistic_decomposition/Ian_edits/tetris_complete.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,30 +12,43 @@

import numpy as np
import random
import os
import sys
import argparse
# from RD_CLI import Interface_width

# Add the directory containing RD_CLI.py to the Python path
# script_dir = os.path.dirname(os.path.realpath(__file__))
# parent_dir = os.path.dirname(script_dir)
# sys.path.append(parent_dir)


def Tetris_Choice():
"""
Randomly selects a Tetris piece and its orientation.
There are 7 tetris pieces:
* 0 is the square
* 1 is the line
* 2 is the L
* 3 is J
* 4 is the T
* 5 is the S
* 6 is the Z
There are 4 orientations for each piece:
* 0 is the original orientation
* 1 is the 90 degree rotation
* 2 is the 180 degree rotation
* 3 is the 270 degree rotation
There are 7 Tetris pieces:
- 0 : the square;
- 1 : the line;
- 2 : the L;
- 3 : J;
- 4 : the T;
- 5 : the S;
- 6 : the Z.
There are 4 orientations for each piece:
- 0 is the original orientation;
- 1 is the 90 degree rotation;
- 2 is the 180 degree rotation;
- 3 is the 270 degree rotation.
Returns:
numpy.ndarray: A 2-element array:
* the first element is the piece type (0-6)
* the second element is the orientation (0-3).
the first element is the piece type (0-6);
the second element is the orientation (0-3).
To-do:
- add input file to specify the probability of each piece.
"""
choice = np.random.randint(1, [7, 4])
return choice
Expand Down Expand Up @@ -64,13 +77,24 @@ def ffnz(matrix, height, column):


def Tetris_RD(width, height, steps):
"""
This function simulates the Tetris Decomposition model on a substrate.
Args:
width (int): The width of the substrate.
height (int): The height of the matrix.
steps (int): The steps to simulate.
Returns:
string : Filename of the output file.
"""
i = 0
substrate = np.zeros((height, width))
topmost = height - 1
while i < steps:
choice = Tetris_Choice()

# Square Piece
# 0. Square Piece
if choice[0] == 0 and (choice[1] == 0 or choice[1] == 1): # Square, check right boundary
position = random.randint(0, width - 1)
if position != (width - 1):
Expand Down Expand Up @@ -100,6 +124,7 @@ def Tetris_RD(width, height, steps):
else:
continue

# 1. Line Piece
if choice[0] == 1 and (choice[1] == 0 or choice[1] == 2): # Vertical, check ceiling case
position = random.randint(0, width - 1)
landing_row = ffnz(substrate, height, position) - 1
Expand All @@ -112,6 +137,7 @@ def Tetris_RD(width, height, steps):
else:
break

# 2. L Piece
if choice[0] == 1 and choice[1] == 1: # Line with right pivot, check left boundary
position = random.randint(0, width - 1)
if position - 3 >= 0:
Expand Down Expand Up @@ -139,7 +165,7 @@ def Tetris_RD(width, height, steps):
else:
continue

# L Case
# L Case
if choice[0] == 2 and choice[1] == 0: # L case upright, check right boundary
position = random.randint(0, width - 1)
if position + 1 <= width - 1:
Expand Down Expand Up @@ -236,6 +262,7 @@ def Tetris_RD(width, height, steps):
else:
continue

# 3. J Piece
if choice[0] == 3 and choice[1] == 0: # J case upright, check left boundary
position = random.randint(0, width - 1)
# position = 6
Expand Down Expand Up @@ -288,6 +315,7 @@ def Tetris_RD(width, height, steps):
continue
else:
continue

if choice[0] == 3 and choice[1] == 2: # J case long part on the left, check right boundary
position = random.randint(0, width - 1)
if position != width - 1:
Expand Down Expand Up @@ -316,6 +344,7 @@ def Tetris_RD(width, height, steps):
i += 1
else:
continue

if choice[0] == 3 and choice[1] == 3: # J case long part on the bottom, check right boundary
position = random.randint(0, width - 1)
# position = 7
Expand All @@ -335,8 +364,7 @@ def Tetris_RD(width, height, steps):
else:
continue

# T case

# 4. T Piece
if choice[0] == 4 and choice[1] == 0: # T case long part on top, check left and right boundaries
position = random.randint(0, width - 1)
# position = 7
Expand Down Expand Up @@ -371,6 +399,7 @@ def Tetris_RD(width, height, steps):
continue
else:
continue

if choice[0] == 4 and choice[1] == 1: # T case long part on the left, check right boundary
position = random.randint(0, width - 1)
# position = 7
Expand Down Expand Up @@ -398,6 +427,7 @@ def Tetris_RD(width, height, steps):
i += 1
else:
continue

if choice[0] == 4 and choice[1] == 2: # T case long part on the bottom, check left and right boundaries
position = random.randint(0, width - 1)
# position = 4
Expand All @@ -416,6 +446,7 @@ def Tetris_RD(width, height, steps):
break
else:
continue

if choice[0] == 4 and choice[1] == 3: # T case long part on the right, check left boundary
position = random.randint(0, width - 1)
# position = 7
Expand Down Expand Up @@ -449,8 +480,7 @@ def Tetris_RD(width, height, steps):
landing_row = min(landing_row_right, landing_row_left)
continue


# S Case
# 5. S Piece
if choice[0] == 5 and (choice[1] == 0 or choice[1] == 2): # S case laying down, check left and right boundary
position = random.randint(0, width - 1)
if position + 1 <= width - 1 and position - 1 >= 0: # Check left and right bdy
Expand Down Expand Up @@ -530,8 +560,8 @@ def Tetris_RD(width, height, steps):
i += 1
else:
continue
# Z Case

# 6. Z Case
if choice[0] == 6 and (choice[1] == 0 or choice[1] == 2): # Z case laying down, check left and right boundary
position = random.randint(0, width - 1)
if position + 1 <= width - 1 and position - 1 >= 0: # Check left and right bdy
Expand Down Expand Up @@ -635,12 +665,56 @@ def Tetris_RD(width, height, steps):
return outputfile


height_str = input('What is the height?')
width_str = input('What is the width?')
steps_str = input('How many blocks?')
height = int(height_str)
width = int(width_str)
steps = int(steps_str)

def main():
"""
To use the script from terminal, the following options are expected:
-w, --width : Width of the substrate (default: 100)
-e, --height : Maximum height of the substrate (default: 60)
-s, --steps : Number of particles to drop (default: 5000)
It returns:
1. A text file representing the substrate state.
Example:
``ptyhon3 tetris_complete.py -w 100 -e 60 -s 5000``
In this example, the script will simulate Tetris Decomposition on a substrate of size 100x60 for 5000 steps. And the simulation movie will be generated.
"""

parser = argparse.ArgumentParser(description="""
Simulate Random Deposition on a substrate.
Outputs: 1. Substrate_WIDTHxHEIGHT_Particles=STEPS_[Relaxed/BD].txt
A text file for the substrate.
2. Statistical figures, loglog plot for the interface width and the estimated slope.
Author: Ian Ruau and Mauricio Mountes
Date: 2023-12-01
""", formatter_class=argparse.RawTextHelpFormatter)
parser.add_argument("-w", "--width", type=int, default=100, help="Width of the substrate (default: 100)")
parser.add_argument("-e", "--height", type=int, default=60, help="Maximum height of the substrate (default: 60)")
parser.add_argument("-s", "--steps", type=int, default=5000, help="Number of particles to drop (default: 5000)")
args = parser.parse_args()

Outputfile = Tetris_RD(args.width, args.height, args.steps)
# print("Computing the interface width...")
# interface_width(Outputfile)


Tetris_RD(width, height, steps)
if __name__ == "__main__":
main()
# height_str = input('What is the height?')
# width_str = input('What is the width?')
# steps_str = input('How many blocks?')
# height = int(height_str)
# width = int(width_str)
# steps = int(steps_str)
# Tetris_RD(width, height, steps)
38 changes: 22 additions & 16 deletions Ballistic_decomposition/RD_CLI.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,19 +325,25 @@ def main():
To use the script from terminal, the following options are expected:
-w, --width : Width of the substrate (default: 100)
-e, --height : Maximum height of the substrate (default: 60)
-s, --steps : Number of particles to drop (default: 5000)
--relax : Enable surface relaxation (default: False)
--BD : Enable ballistic decomposition (default: False)
-m, --movie : Generate an mp4 movie of the simulation (default: False)
-w, --width : Width of the substrate (default: 100)
-e, --height : Maximum height of the substrate (default: 60)
-s, --steps : Number of particles to drop (default: 5000)
-r, --relax : Enable surface relaxation (default: False)
-b, --BD : Enable ballistic decomposition (default: False)
-m, --movie : Generate an mp4 movie of the simulation (default: False)
It returns:
1. A text file representing the substrate state.
2. Statistical figures, including a log-log plot for the interface width and the estimated slope.
3. (Optional) An mp4 movie of the simulation process.
By Le Chen (le.chen@auburn.edu, chenle02@gmail.com), 2023-10-22
1. A text file representing the substrate state.
2. Statistical figures, including a log-log plot for the interface width and the estimated slope.
3. (Optional) An mp4 movie of the simulation process.
Example:
``ptyhon3 RD_CLI.py -w 100 -e 60 -s 5000 --BD --movie``
In this example, the script will simulate Ballistic Decomposition on a substrate of size 100x60 for 5000 steps. And the simulation movie will be generated.
"""

parser = argparse.ArgumentParser(description="""
Expand All @@ -352,12 +358,12 @@ def main():
""", formatter_class=argparse.RawTextHelpFormatter)
parser.add_argument("-w", "--width", type=int, default=100, help="Width of the substrate (default: 100)")
parser.add_argument("-e", "--height", type=int, default=60, help="Maximum height of the substrate (default: 60)")
parser.add_argument("-s", "--steps", type=int, default=5000, help="Number of particles to drop (default: 5000)")
parser.add_argument("--relax", action="store_true", help="Surface Relaxation: go to the nearest lowest neighbor (default: False)")
parser.add_argument("--BD", action="store_true", help="Ballistic decomposition (default: False)")
parser.add_argument("-m", "--movie", action="store_true", help="Generate the mp4 movie (default: False)")
parser.add_argument("-w", "--width", type=int, default=100, help="Width of the substrate (default: 100)")
parser.add_argument("-e", "--height", type=int, default=60, help="Maximum height of the substrate (default: 60)")
parser.add_argument("-s", "--steps", type=int, default=5000, help="Number of particles to drop (default: 5000)")
parser.add_argument("-r", "--relax", action="store_true", help="Surface Relaxation: go to the nearest lowest neighbor (default: False)")
parser.add_argument("-b", "--BD", action="store_true", help="Ballistic decomposition (default: False)")
parser.add_argument("-m", "--movie", action="store_true", help="Generate the mp4 movie (default: False)")
args = parser.parse_args()

Outputfile = ""
Expand Down
4 changes: 1 addition & 3 deletions Ballistic_decomposition/Visualize_RD.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,10 @@ def main():
Example:
``python3 Visualize_RD.py -f path/to/substrate.txt -t "Simulation Title" -r 10 --envelop --average --play``
``python3 Visualize_RD.py -f path/to/substrate.txt -t "Simulation Title" -r 10 --envelop --average --play``
This command will run the script on 'substrate.txt', set a title, use a frame rate of 10 fps,
and display both the top envelope and average height in the visualization.
By Le Chen (le.chen@auburn.edu, chenle02@gmail.com), 2023-10-22
"""

parser = argparse.ArgumentParser(description="""
Expand Down
2 changes: 1 addition & 1 deletion Build_Docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import os
import sys
sys.path.insert(0, os.path.abspath('../../Ballistic_decomposition/'))

sys.path.insert(0, os.path.abspath('../../Ballistic_decomposition/Ian_edits/'))

# -- Project information -----------------------------------------------------

Expand Down
1 change: 1 addition & 0 deletions Build_Docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Welcome to Surface Growth Models with Tetris Growth's documentation!

doc_rst/RD_CLI
doc_rst/Visualize_RD
doc_rst/tetris_complete


Indices and tables
Expand Down
1 change: 1 addition & 0 deletions docs/html/_sources/index.rst.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Welcome to Surface Growth Models with Tetris Growth's documentation!

doc_rst/RD_CLI
doc_rst/Visualize_RD
doc_rst/tetris_complete


Indices and tables
Expand Down
28 changes: 13 additions & 15 deletions docs/html/doc_rst/RD_CLI.html
Original file line number Diff line number Diff line change
Expand Up @@ -179,33 +179,31 @@ <h3>Navigation</h3>
<dt><kbd><span class="option">-w</span>, <span class="option">--width</span></kbd></dt>
<dd><p>: Width of the substrate (default: 100)</p>
</dd>
</dl>
<p>-e, –height : Maximum height of the substrate (default: 60)
-s, –steps : Number of particles to drop (default: 5000)</p>
<blockquote>
<div><dl class="option-list">
<dt><kbd><span class="option">--relax</span></kbd></dt>
<dt><kbd><span class="option">-e</span>, <span class="option">--height</span></kbd></dt>
<dd><p>: Maximum height of the substrate (default: 60)</p>
</dd>
<dt><kbd><span class="option">-s</span>, <span class="option">--steps</span></kbd></dt>
<dd><p>: Number of particles to drop (default: 5000)</p>
</dd>
<dt><kbd><span class="option">-r</span>, <span class="option">--relax</span></kbd></dt>
<dd><p>: Enable surface relaxation (default: False)</p>
</dd>
<dt><kbd><span class="option">--BD</span></kbd></dt>
<dt><kbd><span class="option">-b</span>, <span class="option">--BD</span></kbd></dt>
<dd><p>: Enable ballistic decomposition (default: False)</p>
</dd>
</dl>
</div></blockquote>
<dl class="option-list">
<dt><kbd><span class="option">-m</span>, <span class="option">--movie</span></kbd></dt>
<dd><p>: Generate an mp4 movie of the simulation (default: False)</p>
</dd>
</dl>
<dl class="simple">
<dt>It returns:</dt><dd><ol class="arabic simple">
<p>It returns:</p>
<ol class="arabic simple">
<li><p>A text file representing the substrate state.</p></li>
<li><p>Statistical figures, including a log-log plot for the interface width and the estimated slope.</p></li>
<li><p>(Optional) An mp4 movie of the simulation process.</p></li>
</ol>
</dd>
</dl>
<p>By Le Chen (<a class="reference external" href="mailto:le&#46;chen&#37;&#52;&#48;auburn&#46;edu">le<span>&#46;</span>chen<span>&#64;</span>auburn<span>&#46;</span>edu</a>, <a class="reference external" href="mailto:chenle02&#37;&#52;&#48;gmail&#46;com">chenle02<span>&#64;</span>gmail<span>&#46;</span>com</a>), 2023-10-22</p>
<p class="rubric">Example</p>
<p><code class="docutils literal notranslate"><span class="pre">ptyhon3</span> <span class="pre">RD_CLI.py</span> <span class="pre">-w</span> <span class="pre">100</span> <span class="pre">-e</span> <span class="pre">60</span> <span class="pre">-s</span> <span class="pre">5000</span> <span class="pre">--BD</span> <span class="pre">--movie</span></code></p>
<p>In this example, the script will simulate Ballistic Decomposition on a substrate of size 100x60 for 5000 steps. And the simulation movie will be generated.</p>
</dd></dl>

</section>
Expand Down
Loading

0 comments on commit 805f414

Please sign in to comment.