Skip to content

Commit 2973736

Browse files
committed
Add usage explanations; fix crystal position
1 parent d71a1f5 commit 2973736

File tree

6 files changed

+41
-29
lines changed

6 files changed

+41
-29
lines changed

README.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@ Several types of inclusions can be defined:
1919

2020
Crystalpy supports unit tests with nosetests.
2121

22+
Usage
23+
=====
24+
25+
* Define the geometry of your crystal in mesh.py
26+
* Run `python mesh.py`
27+
2228
Versions
2329
========
2430

@@ -31,3 +37,4 @@ Versions
3137
* v. 2.4: Add unit tests; fix periodicity conditions
3238
* v. 2.5: Add support for physical points; fix 2D crystal generation
3339
* v. 2.6: Add support for physical lines; fix 2D image generation
40+
* v. 2.7: Add usage explanations; fix crystal position

generator.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
from __future__ import division
55
import pysvg
6-
from pysvg.builders import *
6+
from pysvg.builders import StyleBuilder
77
from pysvg.core import *
88
from pysvg.structure import *
99
from pysvg.shape import *
@@ -754,14 +754,19 @@ def __init__(self,
754754
el_size_value = Value(el_size_name, type.el_size)
755755
type.el_size = el_size_value
756756

757+
dim_crystal_x = (nb_x - 1) * space_x
758+
dim_crystal_y = (nb_y - 1) * space_y
759+
crystal_base_x = pos_x - dim_crystal_x / 2
760+
crystal_base_y = pos_y - dim_crystal_y / 2
761+
757762
for i in range(nb_x):
758763
for j in range(nb_y):
759764
if crystal_shape == 'hexa' and j % 2 == 1:
760-
x = pos_x + i * space_x + space_x / 2
761-
y = pos_y + j * space_y
765+
x = crystal_base_x + i * space_x + space_x / 2
766+
y = crystal_base_y + j * space_y
762767
else:
763-
x = pos_x + i * space_x
764-
y = pos_y + j * space_y
768+
x = crystal_base_x + i * space_x
769+
y = crystal_base_y + j * space_y
765770
type_id = 0 if inclusion_map is None else inclusion_map[j][i]
766771
type = inclusion_types[type_id]
767772
if type is not None:

mesh.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@
5454
'nb_y': 2,
5555
'space_x': 250,
5656
'space_y': 250,
57-
'pos_x': -125,
58-
'pos_y': -125,
57+
'pos_x': 0,
58+
'pos_y': 0,
5959
'crystal_shape': 'square',
6060
'el_size_bulk': 25,
6161
'bulk_tag': 'mat1',

tests/test_image_2d.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ def test_square_mesh_2d(self):
3333
'nb_y': 2,
3434
'space_x': 250,
3535
'space_y': 250,
36-
'pos_x': -125,
37-
'pos_y': -125,
36+
'pos_x': 0,
37+
'pos_y': 0,
3838
'crystal_shape': 'square',
3939
'el_size_bulk': 25,
4040
'bulk_tag': 'mat1',
@@ -47,7 +47,7 @@ def test_square_mesh_2d(self):
4747
<rect style="stroke-width:1.5; " height="100" width="150" stroke="black" y="-175.0" x="-200.0" fill="grey" />
4848
<rect style="stroke-width:1.5; " height="100" width="150" stroke="black" y="75.0" x="-200.0" fill="grey" />
4949
<rect style="stroke-width:1.5; " height="100" width="150" stroke="black" y="-175.0" x="50.0" fill="grey" />
50-
<ellipse style="stroke-width:1.5; " rx="75.0" ry="50.0" stroke="black" cy="125" cx="125" fill="lightgrey" />
50+
<ellipse style="stroke-width:1.5; " rx="75.0" ry="50.0" stroke="black" cy="125.0" cx="125.0" fill="lightgrey" />
5151
</svg>
5252
"""
5353
self.image_equal_string(simple_2d, expected)

tests/test_mesh_2d.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ def test_square_mesh_2d(self):
3939
'nb_y': 2,
4040
'space_x': 250,
4141
'space_y': 250,
42-
'pos_x': -125,
43-
'pos_y': -125,
42+
'pos_x': 0,
43+
'pos_y': 0,
4444
'crystal_shape': 'square',
4545
'el_size_bulk': 25,
4646
'bulk_tag': 'mat1',
@@ -72,11 +72,11 @@ def test_square_mesh_2d(self):
7272
Point(17) = {50.0, -175.0, 0, size_1};
7373
Point(18) = {200.0, -75.0, 0, size_1};
7474
Point(19) = {200.0, -175.0, 0, size_1};
75-
Point(20) = {125, 125, 0, size_2};
76-
Point(21) = {50.0, 125, 0, size_2};
77-
Point(22) = {200.0, 125, 0, size_2};
78-
Point(23) = {125, 175.0, 0, size_2};
79-
Point(24) = {125, 75.0, 0, size_2};
75+
Point(20) = {125.0, 125.0, 0, size_2};
76+
Point(21) = {50.0, 125.0, 0, size_2};
77+
Point(22) = {200.0, 125.0, 0, size_2};
78+
Point(23) = {125.0, 175.0, 0, size_2};
79+
Point(24) = {125.0, 75.0, 0, size_2};
8080
Point(25) = {-250.0, 250.0, 0, size_bulk};
8181
Point(26) = {-250.0, -250.0, 0, size_bulk};
8282
Point(27) = {250.0, 250.0, 0, size_bulk};

tests/test_mesh_3d.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ def test_square_mesh_3d(self):
3838
'nb_y': 2,
3939
'space_x': 250,
4040
'space_y': 250,
41-
'pos_x': -125,
42-
'pos_y': -125,
41+
'pos_x': 0,
42+
'pos_y': 0,
4343
'crystal_shape': 'square',
4444
'el_size_bulk': 25,
4545
'bulk_tag': 'mat1',
@@ -81,16 +81,16 @@ def test_square_mesh_3d(self):
8181
Point(27) = {50.0, -175.0, -150, size_1};
8282
Point(28) = {200.0, -75.0, -150, size_1};
8383
Point(29) = {200.0, -175.0, -150, size_1};
84-
Point(30) = {125, 125, 0, size_2};
85-
Point(31) = {50.0, 125, 0, size_2};
86-
Point(32) = {200.0, 125, 0, size_2};
87-
Point(33) = {125, 175.0, 0, size_2};
88-
Point(34) = {125, 75.0, 0, size_2};
89-
Point(35) = {125, 125, 300, size_2};
90-
Point(36) = {50.0, 125, 300, size_2};
91-
Point(37) = {200.0, 125, 300, size_2};
92-
Point(38) = {125, 175.0, 300, size_2};
93-
Point(39) = {125, 75.0, 300, size_2};
84+
Point(30) = {125.0, 125.0, 0, size_2};
85+
Point(31) = {50.0, 125.0, 0, size_2};
86+
Point(32) = {200.0, 125.0, 0, size_2};
87+
Point(33) = {125.0, 175.0, 0, size_2};
88+
Point(34) = {125.0, 75.0, 0, size_2};
89+
Point(35) = {125.0, 125.0, 300, size_2};
90+
Point(36) = {50.0, 125.0, 300, size_2};
91+
Point(37) = {200.0, 125.0, 300, size_2};
92+
Point(38) = {125.0, 175.0, 300, size_2};
93+
Point(39) = {125.0, 75.0, 300, size_2};
9494
Point(40) = {-250.0, 250.0, 0, size_bulk};
9595
Point(41) = {-250.0, -250.0, 0, size_bulk};
9696
Point(42) = {250.0, 250.0, 0, size_bulk};

0 commit comments

Comments
 (0)