-
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
minor work on refactor tests and use pytest instead of unittest
- Loading branch information
krande
committed
Oct 25, 2021
1 parent
13e53d6
commit 284354b
Showing
10 changed files
with
160 additions
and
241 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,42 @@ | ||
import unittest | ||
|
||
from common import dummy_display | ||
|
||
from ada import Assembly, Part, Pipe, Section | ||
from ada.config import Settings | ||
|
||
test_folder = Settings.test_dir / "pipes" | ||
|
||
|
||
class PipeIO(unittest.TestCase): | ||
def test_pipe_straight(self): | ||
a = Assembly("MyTest") | ||
|
||
p = Part("MyPart") | ||
a.add_part(p) | ||
z = 3.2 | ||
y0 = -200e-3 | ||
pipe1 = Pipe("Pipe1", [(0, y0, 0), (0, y0, z)], Section("PSec", "PIPE", r=0.10, wt=5e-3)) | ||
p.add_pipe(pipe1) | ||
a.to_ifc(test_folder / "pipe_straight.ifc") | ||
dummy_display(a) | ||
|
||
def test_pipe_bend(self): | ||
a = Assembly("MyTest") | ||
p = a.add_part(Part("MyPart")) | ||
|
||
z = 3.2 | ||
y0 = -200e-3 | ||
x0 = -y0 | ||
|
||
pipe1 = Pipe( | ||
"Pipe1", | ||
[ | ||
(0, y0, z), | ||
(5 + x0, y0, z), | ||
(5 + x0, y0 + 5, z), | ||
(10, y0 + 5, z + 2), | ||
(10, y0 + 5, z + 10), | ||
], | ||
Section("PSec", "PIPE", r=0.10, wt=5e-3), | ||
) | ||
p.add_pipe(pipe1) | ||
a.to_ifc(test_folder / "pipe_bend.ifc") | ||
a.to_stp(test_folder / "pipe_bend.stp") | ||
dummy_display(a) | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() | ||
test_dir = Settings.test_dir / "pipes" | ||
|
||
|
||
def test_pipe_straight(): | ||
a = Assembly("MyTest") | ||
|
||
p = Part("MyPart") | ||
a.add_part(p) | ||
z = 3.2 | ||
y0 = -200e-3 | ||
pipe1 = Pipe("Pipe1", [(0, y0, 0), (0, y0, z)], Section("PSec", "PIPE", r=0.10, wt=5e-3)) | ||
p.add_pipe(pipe1) | ||
a.to_ifc(test_dir / "pipe_straight.ifc") | ||
dummy_display(a) | ||
|
||
|
||
def test_pipe_bend(): | ||
|
||
z = 3.2 | ||
y0 = -200e-3 | ||
x0 = -y0 | ||
|
||
pipe1 = Pipe( | ||
"Pipe1", | ||
[ | ||
(0, y0, z), | ||
(5 + x0, y0, z), | ||
(5 + x0, y0 + 5, z), | ||
(10, y0 + 5, z + 2), | ||
(10, y0 + 5, z + 10), | ||
], | ||
Section("PSec", "PIPE", r=0.10, wt=5e-3), | ||
) | ||
a = Assembly("MyTest") / (Part("MyPart") / pipe1) | ||
a.to_ifc(test_dir / "pipe_bend.ifc") | ||
a.to_stp(test_dir / "pipe_bend.stp") | ||
dummy_display(a) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,22 @@ | ||
import unittest | ||
|
||
from common import build_test_beam_fem, example_files | ||
|
||
from ada import Assembly | ||
from ada.fem import FemSet, Load, StepImplicit | ||
|
||
|
||
class TestCalculix(unittest.TestCase): | ||
def test_read_C3D20(self): | ||
a = Assembly() | ||
a.read_fem(example_files / "fem_files/calculix/contact2e.inp") | ||
beams = list(a.parts.values())[0] | ||
vol = beams.fem.nodes.vol_cog | ||
assert vol == (0.49999999627471, 1.2499999925494, 3.9999999701977) | ||
def test_read_C3D20(): | ||
a = Assembly() | ||
a.read_fem(example_files / "fem_files/calculix/contact2e.inp") | ||
beams = list(a.parts.values())[0] | ||
vol = beams.fem.nodes.vol_cog | ||
assert vol == (0.49999999627471, 1.2499999925494, 3.9999999701977) | ||
|
||
|
||
def test_write_test_model(self): | ||
a = build_test_beam_fem("shell") | ||
fs = a.fem.add_set(FemSet("Eall", [el for el in a.get_by_name("MyPart").fem.elements.elements], "elset")) | ||
my_step = StepImplicit("static", total_time=1, max_incr=1, init_incr=1, nl_geom=True) | ||
my_step.add_load(Load("Gravity", "gravity", -9.81, fem_set=fs)) | ||
a.fem.add_step(my_step) | ||
def test_write_test_model(): | ||
a = build_test_beam_fem("shell") | ||
fs = a.fem.add_set(FemSet("Eall", [el for el in a.get_by_name("MyPart").fem.elements.elements], "elset")) | ||
my_step = StepImplicit("static", total_time=1, max_incr=1, init_incr=1, nl_geom=True) | ||
my_step.add_load(Load("Gravity", "gravity", -9.81, fem_set=fs)) | ||
a.fem.add_step(my_step) | ||
|
||
a.to_fem("my_calculix", fem_format="calculix", overwrite=True) # , execute=True, exit_on_complete=False) | ||
a.to_fem("my_calculix", fem_format="calculix", overwrite=True) # , execute=True, exit_on_complete=False) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,86 +1,67 @@ | ||
import unittest | ||
from common import compare_fem_objects, example_files | ||
|
||
from common import build_test_beam_fem, compare_fem_objects, example_files | ||
|
||
from ada import Assembly | ||
import ada | ||
from ada.config import Settings | ||
from ada.param_models.fem_models import beam_ex1 | ||
|
||
|
||
class TestCodeAster(unittest.TestCase): | ||
def test_read_write_cylinder(self): | ||
|
||
name = "cylinder" | ||
def test_read_write_cylinder(): | ||
|
||
a = Assembly() | ||
a.read_fem(example_files / "fem_files/meshes/med/cylinder.med", "code_aster", name="cylinder_rewritten") | ||
a.to_fem(name, "code_aster", overwrite=True) | ||
name = "cylinder" | ||
|
||
b = Assembly() | ||
b.read_fem((Settings.scratch_dir / name / name).with_suffix(".med"), fem_format="code_aster") | ||
a = ada.from_fem(example_files / "fem_files/meshes/med/cylinder.med", "code_aster", name="cylinder_rewritten") | ||
a.to_fem(name, "code_aster", overwrite=True) | ||
|
||
p_a = a.parts["cylinder_rewritten"] | ||
p_b = b.parts["cylinder"] | ||
b = ada.from_fem((Settings.scratch_dir / name / name).with_suffix(".med"), fem_format="code_aster") | ||
|
||
compare_fem_objects(p_a.fem, p_b.fem, self) | ||
p_a = a.parts["cylinder_rewritten"] | ||
p_b = b.parts["cylinder"] | ||
|
||
def test_read_write_box(self): | ||
compare_fem_objects(p_a.fem, p_b.fem) | ||
|
||
name = "box" | ||
|
||
a = Assembly() | ||
a.read_fem(example_files / "fem_files/meshes/med/box.med", "code_aster", name="box") | ||
a.to_fem(name, "code_aster", overwrite=True) | ||
def test_read_write_box(): | ||
|
||
b = Assembly() | ||
b.read_fem((Settings.scratch_dir / name / name).with_suffix(".med"), fem_format="code_aster") | ||
name = "box" | ||
|
||
p_a = a.parts["box"] | ||
p_b = b.parts["box"] | ||
a = ada.from_fem(example_files / "fem_files/meshes/med/box.med", "code_aster", name="box") | ||
a.to_fem(name, "code_aster", overwrite=True) | ||
|
||
compare_fem_objects(p_a.fem, p_b.fem, self) | ||
b = ada.from_fem((Settings.scratch_dir / name / name).with_suffix(".med"), fem_format="code_aster") | ||
|
||
def test_read_write_portal_frame(self): | ||
p_a = a.parts["box"] | ||
p_b = b.parts["box"] | ||
|
||
name = "portal" | ||
compare_fem_objects(p_a.fem, p_b.fem) | ||
|
||
a = Assembly() | ||
a.read_fem(example_files / "fem_files/code_aster/portal_01.med", "code_aster", name=name) | ||
a.to_fem(name, "code_aster", overwrite=True) | ||
|
||
b = Assembly() | ||
b.read_fem((Settings.scratch_dir / name / name).with_suffix(".med"), fem_format="code_aster") | ||
def test_read_write_portal_frame(): | ||
|
||
p_a = a.parts[name] | ||
p_b = b.parts[name] | ||
name = "portal" | ||
|
||
compare_fem_objects(p_a.fem, p_b.fem, self) | ||
a = ada.from_fem(example_files / "fem_files/code_aster/portal_01.med", "code_aster", name=name) | ||
a.to_fem(name, "code_aster", overwrite=True) | ||
|
||
def test_write_cantilever(self): | ||
b = ada.from_fem((Settings.scratch_dir / name / name).with_suffix(".med"), fem_format="code_aster") | ||
|
||
name = "cantilever_code_aster" | ||
p_a = a.parts[name] | ||
p_b = b.parts[name] | ||
|
||
a = beam_ex1() | ||
compare_fem_objects(p_a.fem, p_b.fem) | ||
|
||
a.to_fem(name, fem_format="code_aster", overwrite=True) | ||
dest_file = (Settings.scratch_dir / name / name).with_suffix(".med") | ||
|
||
b = Assembly() | ||
b.read_fem(dest_file, fem_format="code_aster") | ||
def test_write_cantilever(): | ||
|
||
p_a = a.parts["MyPart"] | ||
p_b = b.parts["cantilever_code_aster"] | ||
name = "cantilever_code_aster" | ||
|
||
compare_fem_objects(p_a.fem, p_b.fem, self) | ||
a = beam_ex1() | ||
|
||
def test_write_bm(self): | ||
a = build_test_beam_fem("line") | ||
a.to_fem("my_code_aster_bm", fem_format="code_aster", overwrite=True) | ||
a.to_fem(name, fem_format="code_aster", overwrite=True) | ||
dest_file = (Settings.scratch_dir / name / name).with_suffix(".med") | ||
|
||
def test_write_bm_shell(self): | ||
a = build_test_beam_fem("shell") | ||
a.to_fem("my_code_aster_bm_shell", fem_format="code_aster", overwrite=True) | ||
b = ada.from_fem(dest_file, fem_format="code_aster") | ||
|
||
p_a = a.parts["MyPart"] | ||
p_b = b.parts["cantilever_code_aster"] | ||
|
||
if __name__ == "__main__": | ||
unittest.main() | ||
compare_fem_objects(p_a.fem, p_b.fem) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,28 @@ | ||
import unittest | ||
|
||
from common import example_files | ||
|
||
from ada import Assembly | ||
import ada | ||
|
||
|
||
def test_read_write_code_aster_to_xdmf(): | ||
a = ada.from_fem(example_files / "fem_files/meshes/med/box.med", fem_converter="meshio") | ||
a.to_fem("box_analysis_xdmf", fem_format="xdmf", fem_converter="meshio", overwrite=True) | ||
|
||
|
||
class TestMeshio(unittest.TestCase): | ||
def test_read_write_code_aster_to_xdmf(self): | ||
a = Assembly("meshio_from_ca", "temp") | ||
a.read_fem(example_files / "fem_files/meshes/med/box.med", fem_converter="meshio") | ||
a.to_fem("box_analysis_xdmf", fem_format="xdmf", fem_converter="meshio", overwrite=True) | ||
def test_read_write_code_aster_to_abaqus(): | ||
a = ada.from_fem(example_files / "fem_files/meshes/med/box.med", fem_converter="meshio") | ||
a.to_fem("box_analysis_abaqus", fem_format="abaqus", fem_converter="meshio", overwrite=True) | ||
|
||
def test_read_write_code_aster_to_abaqus(self): | ||
a = Assembly("meshio_from_ca", "temp") | ||
a.read_fem(example_files / "fem_files/meshes/med/box.med", fem_converter="meshio") | ||
a.to_fem("box_analysis_abaqus", fem_format="abaqus", fem_converter="meshio", overwrite=True) | ||
|
||
def test_read_C3D20(self): | ||
a = Assembly("my_assembly", "temp") | ||
a.read_fem(example_files / "fem_files/calculix/contact2e.inp", fem_converter="meshio") | ||
def test_read_C3D20(): | ||
a = ada.from_fem(example_files / "fem_files/calculix/contact2e.inp", fem_converter="meshio") | ||
print(a) | ||
|
||
def test_read_abaqus(self): | ||
b = Assembly("my_assembly", "temp") | ||
b.read_fem(example_files / "fem_files/meshes/abaqus/element_elset.inp", fem_converter="meshio") | ||
|
||
def test_read_code_aster(self): | ||
a = Assembly("meshio_from_ca", "temp") | ||
a.read_fem(example_files / "fem_files/meshes/med/box.med", fem_converter="meshio") | ||
def test_read_abaqus(): | ||
b = ada.from_fem(example_files / "fem_files/meshes/abaqus/element_elset.inp", fem_converter="meshio") | ||
print(b) | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() | ||
def test_read_code_aster(): | ||
a = ada.from_fem(example_files / "fem_files/meshes/med/box.med", fem_converter="meshio") | ||
print(a) |
Oops, something went wrong.