Commit 59a4d9c2 authored by Baptiste Durand's avatar Baptiste Durand

New unit test for periodic boundary condition

parent 353c43fb
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
sodipodi:docname="illustration_periodicity_from_vectors.svg"
inkscape:version="1.0 (4035a4fb49, 2020-05-01)"
id="svg8"
version="1.1"
viewBox="0 0 210 297"
height="297mm"
width="210mm">
<defs
id="defs2" />
<sodipodi:namedview
inkscape:window-maximized="1"
inkscape:window-y="-8"
inkscape:window-x="1912"
inkscape:window-height="1177"
inkscape:window-width="1856"
inkscape:snap-grids="true"
showgrid="true"
inkscape:document-rotation="0"
inkscape:current-layer="layer1"
inkscape:document-units="mm"
inkscape:cy="707.39884"
inkscape:cx="252.5438"
inkscape:zoom="15.839192"
inkscape:pageshadow="2"
inkscape:pageopacity="0.0"
borderopacity="1.0"
bordercolor="#666666"
pagecolor="#ffffff"
id="base">
<inkscape:grid
id="grid833"
type="xygrid" />
</sodipodi:namedview>
<metadata
id="metadata5">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title></dc:title>
</cc:Work>
</rdf:RDF>
</metadata>
<g
id="layer1"
inkscape:groupmode="layer"
inkscape:label="Layer 1">
<path
id="path835"
d="m 60.854166,189.17708 h 5.291666 l 2.645834,-5.29167 h -5.291667 l -2.645833,5.29167"
style="fill:none;stroke:#000000;stroke-width:0.264583px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" />
<path
id="path845"
d="M 66.145832,189.17708 H 60.854166 L 63.5,183.88542"
style="fill:none;stroke:#00ff00;stroke-width:0.264583px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" />
<path
id="path847"
d="M 68.791666,183.88541 H 63.499999"
style="fill:none;stroke:#ff0000;stroke-width:0.264583px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" />
<path
id="path849"
d="m 66.145832,189.17708 2.645834,-5.29167"
style="fill:none;stroke:#ff0000;stroke-width:0.264583px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" />
<text
id="text853"
y="190.02094"
x="60.071751"
style="font-style:normal;font-weight:normal;font-size:0.705556px;line-height:1.25;font-family:sans-serif;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.264583"
xml:space="preserve"><tspan
style="font-size:0.705556px;stroke-width:0.264583"
y="190.02094"
x="60.071751"
id="tspan851"
sodipodi:role="line">0,0</tspan></text>
<text
xml:space="preserve"
style="font-style:normal;font-weight:normal;font-size:0.705556px;line-height:1.25;font-family:sans-serif;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.264583"
x="62.922821"
y="190.03496"
id="text853-2"><tspan
sodipodi:role="line"
id="tspan851-0"
x="62.922821"
y="190.03496"
style="font-size:0.705556px;stroke-width:0.264583">2,0</tspan></text>
<text
xml:space="preserve"
style="font-style:normal;font-weight:normal;font-size:0.705556px;line-height:1.25;font-family:sans-serif;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.264583"
x="65.718994"
y="190.08507"
id="text853-7"><tspan
sodipodi:role="line"
id="tspan851-2"
x="65.718994"
y="190.08507"
style="font-size:0.705556px;stroke-width:0.264583">4,0</tspan></text>
<text
xml:space="preserve"
style="font-style:normal;font-weight:normal;font-size:0.705556px;line-height:1.25;font-family:sans-serif;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.264583"
x="60.071751"
y="186.84593"
id="text853-9"><tspan
sodipodi:role="line"
id="tspan851-20"
x="60.071751"
y="186.84593"
style="font-size:0.705556px;stroke-width:0.264583">1,2</tspan></text>
<text
xml:space="preserve"
style="font-style:normal;font-weight:normal;font-size:0.705556px;line-height:1.25;font-family:sans-serif;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.264583"
x="61.659252"
y="184.46469"
id="text853-0"><tspan
sodipodi:role="line"
id="tspan851-9"
x="61.659252"
y="184.46469"
style="font-size:0.705556px;stroke-width:0.264583">2,4</tspan></text>
<text
xml:space="preserve"
style="font-style:normal;font-weight:normal;font-size:0.705556px;line-height:1.25;font-family:sans-serif;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.264583"
x="69.332169"
y="184.2001"
id="text853-28"><tspan
sodipodi:role="line"
id="tspan851-3"
x="69.332169"
y="184.2001"
style="font-size:0.705556px;stroke-width:0.264583">6,4</tspan></text>
<text
xml:space="preserve"
style="font-style:normal;font-weight:normal;font-size:0.705556px;line-height:1.25;font-family:sans-serif;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.264583"
x="68.538414"
y="186.58136"
id="text853-5"><tspan
sodipodi:role="line"
id="tspan851-4"
x="68.538414"
y="186.58136"
style="font-size:0.705556px;stroke-width:0.264583">5,2</tspan></text>
<text
xml:space="preserve"
style="font-style:normal;font-weight:normal;font-size:0.705556px;line-height:1.25;font-family:sans-serif;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.264583"
x="65.363419"
y="183.67093"
id="text853-6"><tspan
sodipodi:role="line"
id="tspan851-1"
x="65.363419"
y="183.67093"
style="font-size:0.705556px;stroke-width:0.264583">4,4</tspan></text>
</g>
</svg>
......@@ -12,8 +12,8 @@ from pytest import approx
logger = logging.getLogger("Test_periodicity")
logger.setLevel(logging.DEBUG)
formatter = logging.Formatter(
'%(asctime)s :: %(levelname)s :: %(name)s :: %(message)s',
"%H:%M:%S")
"%(asctime)s :: %(levelname)s :: %(name)s :: %(message)s", "%H:%M:%S"
)
stream_handler = logging.StreamHandler()
stream_handler.setLevel(logging.DEBUG)
stream_handler.setFormatter(formatter)
......@@ -22,19 +22,37 @@ logger.addHandler(stream_handler)
def test_pbc_from_vectors():
per_vect = np.array([[4.0, 0.0], [0.0, 8.0]])
pbc = periodicity.PeriodicDomain.pbc_dual_base(per_vect, 'XY')
pbc = periodicity.PeriodicDomain.pbc_dual_base(per_vect, "XY")
test_points = [
(0., 0.), (4., 0.), (4., 8.), (0., 8.),
(2., 0.), (4., 4.), (2., 8.), (0., 4.),
(0.0, 0.0),
(4.0, 0.0),
(4.0, 8.0),
(0.0, 8.0),
(2.0, 0.0),
(4.0, 4.0),
(2.0, 8.0),
(0.0, 4.0),
]
test_points = [np.array(coord) for coord in test_points]
inside_results = [
True, False, False, False,
True, False, False, True,
True,
False,
False,
False,
True,
False,
False,
True,
]
map_results = [
(39996, 79992), (0., 0.), (0., 0.), (0., 0.),
(39996, 79992), (0., 4.), (2., 0.), (39996, 79992),
(39996, 79992),
(0.0, 0.0),
(0.0, 0.0),
(0.0, 0.0),
(39996, 79992),
(0.0, 4.0),
(2.0, 0.0),
(39996, 79992),
]
map_results = [np.array(coord) for coord in map_results]
for point, result in zip(test_points, inside_results):
......@@ -48,4 +66,48 @@ def test_pbc_from_vectors():
assert y == approx(map_pt)
test_pbc_from_vectors()
def test_pbc_from_vectors_parallelogram():
per_vect = np.array([[4.0, 2.0], [0.0, 4.0]])
pbc = periodicity.PeriodicDomain.pbc_dual_base(per_vect, "XY")
test_points = [
(0, 0),
(2, 0),
(4, 0),
(1, 2),
(5, 2),
(2, 4),
(4, 4),
(6, 4),
]
test_points = [np.array(coord, np.float64) for coord in test_points]
inside_results = [
True,
True,
False,
True,
False,
False,
False,
False,
]
for point, result in zip(test_points, inside_results):
logger.debug(f"Point : {point}, master : {pbc.inside(point, True)}")
assert pbc.inside(point, on_boundary=True) == result
map_results = [
(59994, 39996),
(59994, 39996),
(0, 0),
(59994, 39996),
(1, 2),
(0, 0),
(2, 0),
(0, 0),
]
map_results = [np.array(coord, np.float64) for coord in map_results]
y = np.zeros(2)
for point, map_pt in zip(test_points, map_results):
pbc.map(point, y)
logger.debug(f"Point : {point}, map pt : {y}, expected : {map_pt}")
assert y == approx(map_pt)
# * OK, test réussi
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment