diff --git a/examples/data/material_isotropic.xml b/examples/data/material_isotropic.xml index 518b340e..fe151168 100644 --- a/examples/data/material_isotropic.xml +++ b/examples/data/material_isotropic.xml @@ -7,24 +7,6 @@ Isotropic Test Material - - - - - 182 - Dependent - - - 229 - Dependent - - - 228 - Dependent - - - Appearance - - - Isotropic diff --git a/examples/demo.py b/examples/demo.py index cd51d3ac..19192a14 100644 --- a/examples/demo.py +++ b/examples/demo.py @@ -8,8 +8,8 @@ ElasticityIsotropic, ) from ansys.materials.manager._models.material import Material -from ansys.materials.manager.util.matml.matml_from_material import MatmlWriter from ansys.materials.manager.util.matml.matml_parser import MatmlReader +from ansys.materials.manager.util.matml.writer_matml import WriterMatml # Create a linear elastic material model in pyMaterials-Manager linear_elastic_material = Material( @@ -39,7 +39,7 @@ print(material_string) # Write a MATML file using pyMaterials-Manager -writer = MatmlWriter([linear_elastic_material]) +writer = WriterMatml([linear_elastic_material]) writer.export("linear_elastic_material.xml", indent=True) # Read a MATML file using pyMaterials-Manager diff --git a/examples/manager_example.py b/examples/manager_example.py index 7805d8a5..cb74c4e0 100644 --- a/examples/manager_example.py +++ b/examples/manager_example.py @@ -14,5 +14,6 @@ material_manager = MaterialManager(client=mapdl_client) material_manager.read_from_matml(matml_file_path) +material_manager.write_to_matml("trial.xml") material_manager.write_material("Isotropic Test Material", 1) mapdl_client.exit() diff --git a/examples/trial.py b/examples/trial.py new file mode 100644 index 00000000..1f9c36fd --- /dev/null +++ b/examples/trial.py @@ -0,0 +1,28 @@ +from ansys.dyna.core import Deck +from ansys.units import Quantity + +from ansys.materials.manager._models._material_models.cofficient_of_thermal_expansion_isotropic import ( # noqa: E501 + CoefficientofThermalExpansionIsotropic, +) +from ansys.materials.manager._models._material_models.density import Density +from ansys.materials.manager._models._material_models.elasticity_isotropic import ( # noqa: E501 + ElasticityIsotropic, +) +from ansys.materials.manager._models.material import Material +from ansys.materials.manager.material_manager import MaterialManager + +model_1 = ElasticityIsotropic( + youngs_modulus=Quantity(value=[5], units="Pa"), poissons_ratio=Quantity(value=[0.1], units="") +) +model_2 = Density(density=Quantity(value=[1], units="")) + +model_3 = CoefficientofThermalExpansionIsotropic( + coefficient_of_thermal_expansion=Quantity(value=[1], units="") +) + +elastic_material = Material(name="Elastic Material", models=[model_1, model_2, model_3]) +deck = Deck() +manager = MaterialManager(client=deck) +manager.add_material(elastic_material) +ls_dyna_material = manager.write_material("Elastic Material", 57, client=deck) +print(ls_dyna_material) diff --git a/poetry.lock b/poetry.lock index a0f09c41..85f9d90f 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1,4 +1,4 @@ -# This file is automatically @generated by Poetry 2.2.0 and should not be changed by hand. +# This file is automatically @generated by Poetry 2.2.1 and should not be changed by hand. [[package]] name = "accessible-pygments" @@ -43,6 +43,22 @@ files = [ {file = "annotated_types-0.7.0.tar.gz", hash = "sha256:aff07c09a53a08bc8cfccb9c85b05f1aa9a2a6f23728d790723543408344ce89"}, ] +[[package]] +name = "ansys-api-dyna" +version = "0.4.2" +description = "Autogenerated python gRPC interface package for ansys-api-dyna, built on 07:27:38 on 29 November 2024" +optional = false +python-versions = ">=3.7" +groups = ["dev"] +files = [ + {file = "ansys_api_dyna-0.4.2-py3-none-any.whl", hash = "sha256:85e6c4e950f07f76f04e7b7fcb5354dc787fafeaada2411abe29c051d6f4ea8a"}, + {file = "ansys_api_dyna-0.4.2.tar.gz", hash = "sha256:12f9f85a3a5eeb5c122e52a259a0d96d8764f2494c7c4515249e4843052ab434"}, +] + +[package.dependencies] +grpcio = ">=1.17,<2.0" +protobuf = ">=3.19,<6" + [[package]] name = "ansys-api-fluent" version = "0.3.36" @@ -106,6 +122,66 @@ files = [ grpcio = ">=1.17,<2.0" protobuf = ">=3.19,<6" +[[package]] +name = "ansys-dpf-core" +version = "0.14.1" +description = "Data Processing Framework - Python Core" +optional = false +python-versions = "<4,>=3.9" +groups = ["dev"] +files = [ + {file = "ansys_dpf_core-0.14.1-py3-none-any.whl", hash = "sha256:be188b8a476bc7cd3129ec13c028e996483803d4a15ad3d7e65b4f613c73f840"}, + {file = "ansys_dpf_core-0.14.1-py3-none-manylinux1_x86_64.whl", hash = "sha256:0e8614acd69f91ea7ff200d0d151364c7698e7250c38be06c98f7bbfc7e2dbae"}, + {file = "ansys_dpf_core-0.14.1-py3-none-manylinux_2_17_x86_64.whl", hash = "sha256:965aba04f3971de3228cd3dea1dd814b4084adb070790ace6da0523ff9a04d91"}, + {file = "ansys_dpf_core-0.14.1-py3-none-win_amd64.whl", hash = "sha256:4b58efab6b508e417aa482f06be3670fcce5e416ecde1c8667fe977de53e3d09"}, +] + +[package.dependencies] +grpcio = ">=1.63.0" +importlib-metadata = ">=4.0" +numpy = "*" +packaging = "*" +protobuf = "*" +psutil = "*" +setuptools = "*" +tqdm = "*" + +[package.extras] +graphics = ["imageio", "imageio-ffmpeg", "matplotlib (>=3.2)", "pyvista (>=0.32.0)", "vtk (!=9.4.0)"] +plotting = ["imageio", "imageio-ffmpeg", "matplotlib (>=3.2)", "pyvista (>=0.32.0)", "vtk"] + +[[package]] +name = "ansys-dyna-core" +version = "0.9.0" +description = "Python interface to LS-DYNA Service" +optional = false +python-versions = "<4,>=3.10" +groups = ["dev"] +files = [ + {file = "ansys_dyna_core-0.9.0-py3-none-any.whl", hash = "sha256:29200a3a05505934e5b11caeac7162d9ebfc093d0b4f136764744eddacdfaec3"}, + {file = "ansys_dyna_core-0.9.0.tar.gz", hash = "sha256:b7965537833f5080097939e9a036d30cc7a077d56bd8b57d2c924f9c01f7a71b"}, +] + +[package.dependencies] +ansys-api-dyna = "0.4.2" +ansys-dpf-core = ">=0.7.2" +ansys-tools-path = ">=0.6.0" +appdirs = ">=1.4.4" +chardet = "5.2.0" +hollerith = ">=0.6.0" +numpy = ">=1" +pandas = ">=2.0" +requests = "2.32.4" +transformations = "2025.1.1" + +[package.extras] +all = ["Jinja2", "ansys-platform-instancemanagement (>=1.0,<2.0)", "pyvista (>=0.43.4)"] +codegen = ["Jinja2"] +doc = ["Sphinx (==8.2.1)", "ansys-sphinx-theme (==1.5.3)", "imageio (==2.37.0)", "imageio-ffmpeg (==0.6.0)", "ipython (==8.37.0)", "ipywidgets (==8.1.7)", "joblib (==1.5.1)", "jupyterlab (==4.4.4)", "matplotlib (==3.10.3)", "nbsphinx (==0.9.6)", "numpydoc (==1.9.0)", "pypandoc (==1.15)", "pytest-sphinx (==0.6.3)", "pyvista (==0.45.2)", "recommonmark (==0.7.1)", "scikit-learn (==1.7.0)", "sphinx-autoapi (==3.6.0)", "sphinx-autobuild (==2024.10.3)", "sphinx-autodoc-typehints (==3.1.0)", "sphinx-copybutton (==0.5.2)", "sphinx-design (==0.6.1)", "sphinx-gallery (==0.19.0)", "sphinx-jinja (==2.0.2)", "sphinx-notfound-page (==1.1.0)", "sphinxcontrib-websupport (==2.0.0)"] +graphics = ["pyvista (>=0.43.4)"] +pim = ["ansys-platform-instancemanagement (>=1.0,<2.0)"] +tests = ["ipython (==8.37.0)", "joblib (==1.5.1)", "matplotlib (==3.10.3)", "numpy (==2.2.6)", "openpyxl (==3.1.5)", "pandas (==2.3.0)", "pytest (==8.4.1)", "pytest-cov (==6.2.1)", "pytest-xdist (==3.8.0)", "pyvista (==0.45.2)", "scikit-learn (==1.7.0)"] + [[package]] name = "ansys-fluent-core" version = "0.35.0" @@ -559,6 +635,18 @@ files = [ {file = "cfgv-3.4.0.tar.gz", hash = "sha256:e52591d4c5f5dead8e0f673fb16db7949d2cfb3f7da4582893288f0ded8fe560"}, ] +[[package]] +name = "chardet" +version = "5.2.0" +description = "Universal encoding detector for Python 3" +optional = false +python-versions = ">=3.7" +groups = ["dev"] +files = [ + {file = "chardet-5.2.0-py3-none-any.whl", hash = "sha256:e1cf59446890a00105fe7b7912492ea04b6e6f06d4b742b2c788469e34c82970"}, + {file = "chardet-5.2.0.tar.gz", hash = "sha256:1b3b6ff479a8c414bc3fa2c0852995695c4a026dcd6d0633b2dd092ca39c1cf7"}, +] + [[package]] name = "charset-normalizer" version = "3.4.3" @@ -674,7 +762,7 @@ files = [ {file = "colorama-0.4.6-py2.py3-none-any.whl", hash = "sha256:4f1d9991f5acc0ca119f9d443620b77f9d6b33703e51011c16baf57afb285fc6"}, {file = "colorama-0.4.6.tar.gz", hash = "sha256:08695f5cb7ed6e0531a20572697297273c47b8cae5a63ffc6d6ed5c201be6e44"}, ] -markers = {dev = "platform_system == \"Windows\" or sys_platform == \"win32\"", doc = "sys_platform == \"win32\""} +markers = {dev = "sys_platform == \"win32\" or platform_system == \"Windows\"", doc = "sys_platform == \"win32\""} [[package]] name = "contourpy" @@ -1441,6 +1529,49 @@ googleapis-common-protos = ">=1.5.5" grpcio = ">=1.62.3" protobuf = ">=4.21.6" +[[package]] +name = "hollerith" +version = "0.6.0" +description = "C-extension module for efficient writing of fixed width text" +optional = false +python-versions = ">=3.9" +groups = ["dev"] +files = [ + {file = "hollerith-0.6.0-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:90817935fc8223795f9b40ca6b9f529bffca7d79820f2b66e94e5ac41cbe5797"}, + {file = "hollerith-0.6.0-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:dffceae784ca3e67a8649dee653c42567a75a99a8f914bb0464c8076368e37c8"}, + {file = "hollerith-0.6.0-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:e5bf574534fd1881583d6a68a4d7e95b7a4d8ad0c02e9c7ee506fdedaca67e13"}, + {file = "hollerith-0.6.0-cp310-cp310-musllinux_1_2_i686.whl", hash = "sha256:fd98db01791a65399469182a0c0c61feacbd1a1f7e4a6ceb5398277f7c417c93"}, + {file = "hollerith-0.6.0-cp310-cp310-musllinux_1_2_x86_64.whl", hash = "sha256:7483ccd868e64ae3dd87c5f7159e89c842a440f051226bb24c1f9ce395498483"}, + {file = "hollerith-0.6.0-cp310-cp310-win32.whl", hash = "sha256:81859b2fdc06971e9e3985645abc565e00a1b7c6fb205e8a3d5c105d3ae5c266"}, + {file = "hollerith-0.6.0-cp310-cp310-win_amd64.whl", hash = "sha256:23ba9832a9ea80350f805c19ca1401f4e8d6e06dfcc75b87da45421a5e596e20"}, + {file = "hollerith-0.6.0-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:c721a57d8fd5a685dfc8b36b4321bef90e6252ffdf0ef7fdfe21db4cf92e389d"}, + {file = "hollerith-0.6.0-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:efb789218c21e698c6548decf6b8ed823a4539f3b190218864e10630d074f389"}, + {file = "hollerith-0.6.0-cp311-cp311-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:3c16ff70e7999b31ddcb08b993e790dc01c8edf9f558cf93db3f83fdeeaa93ff"}, + {file = "hollerith-0.6.0-cp311-cp311-musllinux_1_2_i686.whl", hash = "sha256:6bebf2a528418179df588795e783e045d7d40d0257f8afc0475f474c755f9a37"}, + {file = "hollerith-0.6.0-cp311-cp311-musllinux_1_2_x86_64.whl", hash = "sha256:3efd56458223dcdf13fc0292f0187f373588fe8826a86180680f4c223ea0216f"}, + {file = "hollerith-0.6.0-cp311-cp311-win32.whl", hash = "sha256:0beaead362203e01f500d0e2fb9d7f39cf033823593d590748f97bf693941364"}, + {file = "hollerith-0.6.0-cp311-cp311-win_amd64.whl", hash = "sha256:90637506ca2ad86b50dbf84ac4ce8a696b7f3220441b38e6075f7166cccd0947"}, + {file = "hollerith-0.6.0-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:d7d5009f27416f9b6afdc2d32a92628065f8f2cd19f6601dbccea5a49124b83c"}, + {file = "hollerith-0.6.0-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:3d238e5692ce6fc4bb8be445191a8cc6a943c4406c689f729468db1edc10af4b"}, + {file = "hollerith-0.6.0-cp312-cp312-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:0c1c5d181c46a0777183d86532a33d4d89672510f04a012177de838060baee7d"}, + {file = "hollerith-0.6.0-cp312-cp312-musllinux_1_2_i686.whl", hash = "sha256:99c641a0eaf67a881fd309501ef8ddb9b8beffe2a03cd405940c1c7ee15244ce"}, + {file = "hollerith-0.6.0-cp312-cp312-musllinux_1_2_x86_64.whl", hash = "sha256:9a0eebbdc593458f4ddcbfe24328e3513986079a6145fefb622a93816dc60873"}, + {file = "hollerith-0.6.0-cp312-cp312-win32.whl", hash = "sha256:936d7721a33423b4070f022703e733dbfed28796b0ee80431bf50e1159f1325b"}, + {file = "hollerith-0.6.0-cp312-cp312-win_amd64.whl", hash = "sha256:37f7d5127cde391694900bc7fd1106d974101939bc9f9a4a06d7d874a43d533b"}, + {file = "hollerith-0.6.0-cp313-cp313-macosx_11_0_arm64.whl", hash = "sha256:e616326df37b28bb5699c107e9795db88dd08784626ab080e615af98ba7f63d5"}, + {file = "hollerith-0.6.0-cp313-cp313-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:d7b3ff7b0001fb679b1b4a05d6d7a3e8a2a58b8a3dc52572c6809240e0f19b92"}, + {file = "hollerith-0.6.0-cp313-cp313-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:f3e1733fdc02a0f02a1f45993f74fc8fa863dd67b0d59da5b9bec0e1b5ace832"}, + {file = "hollerith-0.6.0-cp313-cp313-musllinux_1_2_i686.whl", hash = "sha256:46087d9a17d8ad75e393dd82ceea23426cab6521e02948d9b7aec215d73f9cf6"}, + {file = "hollerith-0.6.0-cp313-cp313-musllinux_1_2_x86_64.whl", hash = "sha256:ca8d6c4a5a744a78388d6670943d2bfc2fdba26309da1087ef58a8b4c4e50a73"}, + {file = "hollerith-0.6.0-cp313-cp313-win32.whl", hash = "sha256:3051836a3e6d61927dbc2e5aa5384229dad52f4b5abc86ac5e59d6070f94cd24"}, + {file = "hollerith-0.6.0-cp313-cp313-win_amd64.whl", hash = "sha256:5ea789a5a3fdbd0adff5693d41df75c5ced77ef787080787548e27a75afdf74f"}, + {file = "hollerith-0.6.0.tar.gz", hash = "sha256:00fb42ca29e6b37634b93e403b9506f3817a58a5e17b3c7ebe1f89e003dd1603"}, +] + +[package.dependencies] +numpy = ">=1.26.4" +pandas = ">=2.0.3" + [[package]] name = "id" version = "1.5.0" @@ -3166,14 +3297,14 @@ files = [ [[package]] name = "requests" -version = "2.32.5" +version = "2.32.4" description = "Python HTTP for Humans." optional = false -python-versions = ">=3.9" +python-versions = ">=3.8" groups = ["dev", "doc"] files = [ - {file = "requests-2.32.5-py3-none-any.whl", hash = "sha256:2462f94637a34fd532264295e186976db0f5d453d1cdd31473c85a6a161affb6"}, - {file = "requests-2.32.5.tar.gz", hash = "sha256:dbba0bac56e100853db0ea71b82b4dfd5fe2bf6d3754a8893c3af500cec7d7cf"}, + {file = "requests-2.32.4-py3-none-any.whl", hash = "sha256:27babd3cda2a6d50b30443204ee89830707d396671944c998b5975b031ac2b2c"}, + {file = "requests-2.32.4.tar.gz", hash = "sha256:27d0316682c8a29834d3264820024b62a36942083d52caf2f14c0591336d3422"}, ] [package.dependencies] @@ -3823,6 +3954,43 @@ notebook = ["ipywidgets (>=6)"] slack = ["slack-sdk"] telegram = ["requests"] +[[package]] +name = "transformations" +version = "2025.1.1" +description = "Homogeneous Transformation Matrices and Quaternions" +optional = false +python-versions = ">=3.10" +groups = ["dev"] +files = [ + {file = "transformations-2025.1.1-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:5eb808d255c02fba6cfdbc92b7c706432db76b7e55e0cfe921bddad95e1d4285"}, + {file = "transformations-2025.1.1-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:cbc758a858185b38022722ab6f5bb39369b74e69a8e7a861894870269241064f"}, + {file = "transformations-2025.1.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:2ed30be8eed56680dd1405117dfae58f2ebba99cff1333503b8cdac46c85f976"}, + {file = "transformations-2025.1.1-cp310-cp310-win32.whl", hash = "sha256:b50e7bff1d3a776d71b69a3e38c7a776666756011bf5a071739c84b93c481094"}, + {file = "transformations-2025.1.1-cp310-cp310-win_amd64.whl", hash = "sha256:1af88add05b44c752379c4ff0649a17d0853dea65ca20f162661bcc3488ab48c"}, + {file = "transformations-2025.1.1-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:ba5810bbcc403a6fdb0ad55f2d1654ae434ad5e0ed6411c4fd5ee95d3c24a785"}, + {file = "transformations-2025.1.1-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:ee99aee395cbc033e97f3df6c74e6f65e77ea29399e6c2265a4aaada22bc1af3"}, + {file = "transformations-2025.1.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:9ce9fa1663d16126cfd746ca79dfc484db531cd68b1ee99dfd5960f65b82331a"}, + {file = "transformations-2025.1.1-cp311-cp311-win32.whl", hash = "sha256:0480bf56c375070e374994586acfc7366a91a4ec2356e8111394212699a11c0a"}, + {file = "transformations-2025.1.1-cp311-cp311-win_amd64.whl", hash = "sha256:6053d98f6e9d631df2ef467dcd534138c23532b425ca44cc57049197be8a2df0"}, + {file = "transformations-2025.1.1-cp311-cp311-win_arm64.whl", hash = "sha256:609ea776cbd25d81f83be08c6e19576a430b888dfda3f8a9b833c91fee624d23"}, + {file = "transformations-2025.1.1-cp312-cp312-macosx_10_13_x86_64.whl", hash = "sha256:96b9dae9b63d27878422de914630983de937de6699f5e0114c440e2d49bb28df"}, + {file = "transformations-2025.1.1-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:0c0f7b8980053c0e4f93e33a6899adbef85d6473d4b0f004a0addcfd1c310461"}, + {file = "transformations-2025.1.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:c31602afe8480d8b1ec3ef57fad91b655f5aaf13d6913e04a9d16200ebbd0b9d"}, + {file = "transformations-2025.1.1-cp312-cp312-win32.whl", hash = "sha256:fbe073d36a4f5132778aae0f837c9fa1797dc0b5f86e67efacc9be34cf886222"}, + {file = "transformations-2025.1.1-cp312-cp312-win_amd64.whl", hash = "sha256:182c883f06ee9cdaa57b33ecadd694b519e682d5c050026613f260716250fbfc"}, + {file = "transformations-2025.1.1-cp312-cp312-win_arm64.whl", hash = "sha256:90a494108ff1b37ba3505492098170006559aca453b7715ae41983b325f731f4"}, + {file = "transformations-2025.1.1-cp313-cp313-macosx_10_13_x86_64.whl", hash = "sha256:264c71652cb98c35bfa0293fb2e0d3a811a645f3ca4011756321baaa6953b287"}, + {file = "transformations-2025.1.1-cp313-cp313-macosx_11_0_arm64.whl", hash = "sha256:9e68e475256cfe03e3fa360693d6a39495b2b67d86033640504067ce8febf29b"}, + {file = "transformations-2025.1.1-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:abdba200ec5abfac55fab25c5ef399fd65357d296c304f1499c0af6b9442fc8a"}, + {file = "transformations-2025.1.1-cp313-cp313-win32.whl", hash = "sha256:26950745a1d7fcdbdb2f1ba217496a2ac4c1eeb4cacbd0e866fa48e09c9d01ee"}, + {file = "transformations-2025.1.1-cp313-cp313-win_amd64.whl", hash = "sha256:bffdd9c419cd395af9e1de5a642099dfc9ec0cb2b1d9d87c0421271083603e7c"}, + {file = "transformations-2025.1.1-cp313-cp313-win_arm64.whl", hash = "sha256:4a44eec2c7ae4058316ae75fbfd3c3ab8d15489d0bbeb753f6a4392283378d94"}, + {file = "transformations-2025.1.1.tar.gz", hash = "sha256:b8411a456cd506e4b77cdac884b217836125840e2f1400247b5bc02c46d1b333"}, +] + +[package.dependencies] +numpy = "*" + [[package]] name = "twine" version = "6.2.0" @@ -4082,4 +4250,4 @@ type = ["pytest-mypy"] [metadata] lock-version = "2.1" python-versions = ">=3.10,<3.14" -content-hash = "d195125c45ad94973e5427ab4eb8c4b0d0f217cc8e5ae428297e9b283c38b805" +content-hash = "45028828c7fe2151000e6f3b94157ea7bb40165779a7f8d9523f8a729157c108" diff --git a/pyproject.toml b/pyproject.toml index 951c283f..2c311c12 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -46,6 +46,7 @@ pytest-cov = ">=4" pre-commit = ">=3.2.2" pydantic = ">=2.7.0" ansys-units = ">=0.8.dev0" +ansys-dyna-core = ">=0.9.0" [tool.black] line-length = 100 diff --git a/src/ansys/materials/manager/_models/_common/common.py b/src/ansys/materials/manager/_models/_common/common.py index b2e87f76..be68306c 100644 --- a/src/ansys/materials/manager/_models/_common/common.py +++ b/src/ansys/materials/manager/_models/_common/common.py @@ -40,17 +40,30 @@ class QualifierType(str, Enum): class ParameterFieldInfo(FieldInfo): """FieldInfo for dependent parameters in material models.""" - def __init__(self, *, matml_name=None, **kwargs): + def __init__( + self, *, matml_name=None, mapdl_name=None, lsdyna_name=None, fluent_name=None, **kwargs + ): """Initialize the ParameterFieldInfo with a matml_name.""" super().__init__(**kwargs) if self.title is None: self.title = matml_name self.matml_name = matml_name + self.mapdl_name = mapdl_name + self.fluent_name = fluent_name + self.lsdyna_name = lsdyna_name -def ParameterField(*, matml_name=None, **kwargs): +def ParameterField( + *, matml_name=None, mapdl_name=None, lsdyna_name=None, fluent_name=None, **kwargs +): """Create a ParameterField with a specific matml_name.""" - return ParameterFieldInfo(matml_name=matml_name, **kwargs) + return ParameterFieldInfo( + matml_name=matml_name, + mapdl_name=mapdl_name, + lsdyna_name=lsdyna_name, + fluent_name=fluent_name, + **kwargs, + ) def validate_and_initialize_model_qualifiers( diff --git a/src/ansys/materials/manager/_models/_common/material_model.py b/src/ansys/materials/manager/_models/_common/material_model.py index 359fc7ca..1f06b269 100644 --- a/src/ansys/materials/manager/_models/_common/material_model.py +++ b/src/ansys/materials/manager/_models/_common/material_model.py @@ -23,7 +23,6 @@ import abc from pydantic import BaseModel, Field -from pyparsing import Any from ._packages import SupportedPackage # noqa: F401 from .common import ParameterField, validate_parameters @@ -82,26 +81,14 @@ def validate_model(self) -> None: This method should not perform any calls to other processes. """ - model = self.model_dump() - for field_name, field_value in model.items(): - if field_name not in MaterialModel.model_fields.keys(): - if field_value is None: - raise Exception(f"the value of {field_name} cannot be None, please update it.") - validate_parameters(field_name, field_value["value"], self.independent_parameters) - - @abc.abstractmethod - def write_model(self, material_id: int, pyansys_session: Any, **kwargs: dict) -> None: - """ - Write the model to the given PyAnsys session. - - This method should make some effort to validate the model state before writing. - - Parameters - ---------- - material: Material - Material object to associate this model with. - pyansys_session: Any - Supported PyAnsys product session. Only PyMAPDL and PyFluent are - supported currently. - """ - ... + if not self.__class__.__name__ == "Color": + model = self.model_dump() + for field_name, field_value in model.items(): + if field_name not in MaterialModel.model_fields.keys(): + if field_value is None: + raise Exception( + f"the value of {field_name} cannot be None, please update it." + ) + validate_parameters( + field_name, field_value["value"], self.independent_parameters + ) diff --git a/src/ansys/materials/manager/_models/_material_models/cofficient_of_thermal_expansion_isotropic.py b/src/ansys/materials/manager/_models/_material_models/cofficient_of_thermal_expansion_isotropic.py index 4506e0fe..60a8781d 100644 --- a/src/ansys/materials/manager/_models/_material_models/cofficient_of_thermal_expansion_isotropic.py +++ b/src/ansys/materials/manager/_models/_material_models/cofficient_of_thermal_expansion_isotropic.py @@ -20,7 +20,7 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. -from typing import Any, Dict, Literal +from typing import Dict, Literal from ansys.units import Quantity from pydantic import Field, model_validator @@ -29,17 +29,8 @@ MaterialModel, ParameterField, QualifierType, - _MapdlCore, validate_and_initialize_model_qualifiers, ) -from ansys.materials.manager.util.mapdl.mapdl_writer import ( - write_constant_properties, - write_constant_property, - write_interpolation_options, - write_table_values, - write_temperature_reference_value, - write_temperature_table_values, -) class CoefficientofThermalExpansionIsotropic(MaterialModel): @@ -52,6 +43,7 @@ class CoefficientofThermalExpansionIsotropic(MaterialModel): default=None, description="The coefficient of thermal expansion for the material.", matml_name="Coefficient of Thermal Expansion", + mapdl_name=["CTEX", "ALPX"], ) @model_validator(mode="before") @@ -64,74 +56,3 @@ def _initialize_qualifiers(cls, values) -> Dict: values, expected_qualifiers ) return values - - def _write_mapdl(self, material_id: int, reference_temperature: float | None) -> str: - material_string = "" - if reference_temperature: - material_string += write_temperature_reference_value(material_id, reference_temperature) - for qualfier in self.model_qualifiers: - if qualfier.name == "Definition": - if qualfier.value == "Instantaneous": - labels = ["CTEX"] - else: - labels = ["ALPX"] - if not self.independent_parameters: - material_string += write_constant_property( - label=labels[0], - property=self.coefficient_of_thermal_expansion.value, - material_id=material_id, - unit=self.coefficient_of_thermal_expansion.unit, - ) - return material_string - else: - if ( - len(self.independent_parameters) == 1 - and self.independent_parameters[0].name == "Temperature" - ): - if len(self.independent_parameters[0].values.value) == 1: - material_string += write_constant_properties( - labels=labels, - properties=[self.coefficient_of_thermal_expansion.value], - property_units=[self.coefficient_of_thermal_expansion.unit], - material_id=material_id, - ) - return material_string - else: - material_string += write_temperature_table_values( - labels=labels, - dependent_parameters=[self.coefficient_of_thermal_expansion.value], - dependent_parameters_unit=[self.coefficient_of_thermal_expansion.unit], - material_id=material_id, - temperature_parameter=self.independent_parameters[0], - ) - return material_string - else: - if labels[0] == "CTEX": - raise Exception( - "Instantaneus coefficient of expansion is not supported for tb input." - ) - parameters_str, table_str = write_table_values( - label="CTE", - dependent_parameters=[self.coefficient_of_thermal_expansion.value], - material_id=material_id, - independent_parameters=self.independent_parameters, - ) - material_string += parameters_str + "\n" + table_str - - if self.interpolation_options: - interpolation_string += write_interpolation_options( - interpolation_options=self.interpolation_options, - independent_parameters=self.independent_parameters, - ) - material_string += "\n" + interpolation_string - return material_string - - def write_model(self, material_id: int, pyansys_session: Any, **kwargs: dict) -> str: - """Write this model to the specified session.""" - self.validate_model() - if isinstance(pyansys_session, _MapdlCore): - reference_temperature = kwargs.get("reference_temperature", None) - material_string = self._write_mapdl(material_id, reference_temperature) - else: - raise Exception("The session is not supported.") - return material_string diff --git a/src/ansys/materials/manager/_models/_material_models/cofficient_of_thermal_expansion_orthotropic.py b/src/ansys/materials/manager/_models/_material_models/cofficient_of_thermal_expansion_orthotropic.py index 1fa799bf..ca45113f 100644 --- a/src/ansys/materials/manager/_models/_material_models/cofficient_of_thermal_expansion_orthotropic.py +++ b/src/ansys/materials/manager/_models/_material_models/cofficient_of_thermal_expansion_orthotropic.py @@ -20,7 +20,7 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. -from typing import Any, Dict, Literal +from typing import Dict, Literal from ansys.units import Quantity from pydantic import Field, model_validator @@ -29,16 +29,8 @@ MaterialModel, ParameterField, QualifierType, - _MapdlCore, validate_and_initialize_model_qualifiers, ) -from ansys.materials.manager.util.mapdl.mapdl_writer import ( - write_constant_properties, - write_interpolation_options, - write_table_values, - write_temperature_reference_value, - write_temperature_table_values, -) class CoefficientofThermalExpansionOrthotropic(MaterialModel): @@ -51,16 +43,19 @@ class CoefficientofThermalExpansionOrthotropic(MaterialModel): default=None, description="The coefficient of thermal expansion in X direction for the material.", matml_name="Coefficient of Thermal Expansion X direction", + mapdl_name=["CTEX", "ALPX"], ) coefficient_of_thermal_expansion_y: Quantity | None = ParameterField( default=None, description="The coefficient of thermal expansion in Y direction for the material.", matml_name="Coefficient of Thermal Expansion Y direction", + mapdl_name=["CTEY", "ALPY"], ) coefficient_of_thermal_expansion_z: Quantity | None = ParameterField( default=None, description="The coefficient of thermal expansion in Z direction for the material.", matml_name="Coefficient of Thermal Expansion Z direction", + mapdl_name=["CTEZ", "ALPZ"], ) @model_validator(mode="before") @@ -73,86 +68,3 @@ def _initialize_qualifiers(cls, values) -> Dict: values, expected_qualifiers ) return values - - def _write_mapdl(self, material_id: int, reference_temperature: float | None) -> str: - material_string = "" - if reference_temperature: - material_string += write_temperature_reference_value(material_id, reference_temperature) - dependent_parameters = [ - self.coefficient_of_thermal_expansion_x.value, - self.coefficient_of_thermal_expansion_y.value, - self.coefficient_of_thermal_expansion_z.value, - ] - dependent_parameters_units = [ - self.coefficient_of_thermal_expansion_x.unit, - self.coefficient_of_thermal_expansion_y.unit, - self.coefficient_of_thermal_expansion_z.unit, - ] - for qualfier in self.model_qualifiers: - if qualfier.name == "Definition": - if qualfier.value == "Instantaneous": - labels = ["CTEX", "CTEY", "CTEZ"] - else: - labels = ["ALPX", "ALPY", "ALPZ"] - - if not self.independent_parameters: - material_string += write_constant_properties( - labels=labels, - properties=dependent_parameters, - property_units=dependent_parameters_units, - material_id=material_id, - ) - return material_string - else: - if ( - len(self.independent_parameters) == 1 - and self.independent_parameters[0].name == "Temperature" - ): - if len(self.independent_parameters[0].values.value) == 1: - material_string += write_constant_properties( - labels=labels, - properties=dependent_parameters, - property_units=dependent_parameters_units, - material_id=material_id, - ) - return material_string - else: - material_string += write_temperature_table_values( - labels=labels, - dependent_parameters=dependent_parameters, - dependent_parameters_unit=dependent_parameters_units, - material_id=material_id, - temperature_parameter=self.independent_parameters[0], - ) - return material_string - else: - if labels[0] == "CTEX": - raise Exception( - "Instantaneus coefficient of expansion is not supported for tb input." - ) - - parameters_str, table_str = write_table_values( - label="CTE", - dependent_parameters=dependent_parameters, - material_id=material_id, - independent_parameters=self.independent_parameters, - ) - material_string += parameters_str + "\n" + table_str - - if self.interpolation_options: - interpolation_string = write_interpolation_options( - interpolation_options=self.interpolation_options, - independent_parameters=self.independent_parameters, - ) - material_string += "\n" + interpolation_string - return material_string - - def write_model(self, material_id: int, pyansys_session: Any, **kwargs: dict) -> None: - """Write this model to the specified session.""" - self.validate_model() - if isinstance(pyansys_session, _MapdlCore): - reference_temperature = kwargs.get("reference_temperature", None) - material_string = self._write_mapdl(material_id, reference_temperature) - else: - raise Exception("The session is not supported.") - return material_string diff --git a/src/ansys/materials/manager/_models/_material_models/color.py b/src/ansys/materials/manager/_models/_material_models/color.py index cb6b0908..84dae469 100644 --- a/src/ansys/materials/manager/_models/_material_models/color.py +++ b/src/ansys/materials/manager/_models/_material_models/color.py @@ -20,7 +20,7 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. -from typing import Any, Literal +from typing import Literal from pydantic import Field @@ -46,11 +46,3 @@ class Color(MaterialModel): matml_name="Material Property", frozen=True, ) - - def write_model(self, material_id: int, pyansys_session: Any, **kwargs: dict) -> None: - """Write the anisotropic elasticity model to the pyansys session.""" - pass - - def validate_model(self) -> tuple[bool, list[str]]: - """Validate the anisotropic elasticity model.""" - pass diff --git a/src/ansys/materials/manager/_models/_material_models/density.py b/src/ansys/materials/manager/_models/_material_models/density.py index 579a6cb2..ce3f7e3d 100644 --- a/src/ansys/materials/manager/_models/_material_models/density.py +++ b/src/ansys/materials/manager/_models/_material_models/density.py @@ -20,27 +20,12 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. -from typing import Any, Literal, Sequence +from typing import Literal from ansys.units import Quantity from pydantic import Field -from ansys.materials.manager._models._common import ( - MaterialModel, - ParameterField, - SupportedPackage, - _FluentCore, - _MapdlCore, -) -from ansys.materials.manager.util.mapdl import ( - write_constant_property, - write_interpolation_options, - write_table_values, -) -from ansys.materials.manager.util.mapdl.mapdl_writer import ( - write_temperature_reference_value, - write_temperature_table_values, -) +from ansys.materials.manager._models._common import MaterialModel, ParameterField, SupportedPackage class Density(MaterialModel): @@ -51,6 +36,9 @@ class Density(MaterialModel): default=None, description="The density of the material.", matml_name="Density", + mapdl_name="DENS", + fluent_name="density", + lsdyna_name="ro", ) supported_packages: list[SupportedPackage] = Field( default=[SupportedPackage.MAPDL, SupportedPackage.FLUENT], @@ -58,79 +46,3 @@ class Density(MaterialModel): description="The list of supported packages.", frozen=True, ) - - def _write_mapdl(self, material_id: int, reference_temperature: float | None) -> str: - material_string = "" - if reference_temperature: - material_string += write_temperature_reference_value(material_id, reference_temperature) - - if self.independent_parameters is None: - material_string += write_constant_property( - label="DENS", - property=self.density.value, - material_id=material_id, - unit=self.density.unit, - ) - return material_string - elif ( - len(self.independent_parameters) == 1 - and self.independent_parameters[0].name == "Temperature" - ): - if len(self.independent_parameters[0].values.value) == 1: - material_string += write_constant_property( - label="DENS", - property=self.density.value, - material_id=material_id, - unit=self.density.unit, - ) - return material_string - else: - material_string += write_temperature_table_values( - labels=["DENS"], - dependent_parameters=[self.density.value], - dependent_parameters_unit=[self.density.unit], - material_id=material_id, - temperature_parameter=self.independent_parameters[0], - ) - return material_string - else: - parameters_str, table_str = write_table_values( - label="DENS", - dependent_parameters=[self.density.value], - material_id=material_id, - independent_parameters=self.independent_parameters, - ) - material_string += parameters_str + "\n" + table_str - - if self.interpolation_options: - interpolation_string = write_interpolation_options( - interpolation_options=self.interpolation_options, - independent_parameters=self.independent_parameters, - ) - material_string += "\n" + interpolation_string - - return material_string - - def _write_fluent(self) -> dict: - return { - "density": { - "option": "constant", - "value": ( - self.density.value[0] - if isinstance(self.density.value, Sequence) - else self.density.value - ), - } - } - - def write_model(self, material_id: int, pyansys_session: Any, **kwargs: dict) -> str | dict: - """Write this model to the specified session.""" - self.validate_model() - if isinstance(pyansys_session, _MapdlCore): - reference_temperature = kwargs.get("reference_temperature", None) - material = self._write_mapdl(material_id, reference_temperature) - elif isinstance(pyansys_session, _FluentCore): - material = self._write_fluent() - else: - raise Exception("The session is not supported.") - return material diff --git a/src/ansys/materials/manager/_models/_material_models/elasticity_anisotropic.py b/src/ansys/materials/manager/_models/_material_models/elasticity_anisotropic.py index 51d4e6e3..9904c1ad 100644 --- a/src/ansys/materials/manager/_models/_material_models/elasticity_anisotropic.py +++ b/src/ansys/materials/manager/_models/_material_models/elasticity_anisotropic.py @@ -21,7 +21,7 @@ # SOFTWARE. -from typing import Any, Dict, Literal +from typing import Dict, Literal from ansys.units import Quantity import numpy as np @@ -31,13 +31,8 @@ MaterialModel, ParameterField, QualifierType, - _MapdlCore, validate_and_initialize_model_qualifiers, ) -from ansys.materials.manager.util.mapdl.mapdl_writer import ( - write_table_dep_values, - write_temperature_reference_value, -) class ElasticityAnisotropic(MaterialModel): @@ -71,43 +66,6 @@ def _initialize_qualifiers(cls, values) -> Dict: ) return values - def _write_mapdl(self, material_id: int, reference_temperature: float | None) -> str: - material_string = "" - if reference_temperature: - material_string += write_temperature_reference_value(material_id, reference_temperature) - d = np.column_stack( - ( - self.column_1.value, - self.column_2.value, - self.column_3.value, - self.column_4.value, - self.column_5.value, - self.column_6.value, - ) - ) - # extract the lower triangular elements column-wise - dependent_values = [] - for j in range(6): - dependent_values.extend(d[j:, j]) - - material_string += write_table_dep_values( - material_id=material_id, - label="ELASTIC", - dependent_values=dependent_values, - tb_opt="AELS", - ) - return material_string - - def write_model(self, material_id: int, pyansys_session: Any, **kwargs: dict) -> None: - """Write the anisotropic elasticity model to the pyansys session.""" - self.validate_model() - if isinstance(pyansys_session, _MapdlCore): - reference_temperature = kwargs.get("reference_temperature", None) - material_string = self._write_mapdl(material_id, reference_temperature) - else: - raise Exception("The session is not supported.") - return material_string - def validate_model(self) -> None: """Validate anisotropic elasticity.""" if self.independent_parameters: diff --git a/src/ansys/materials/manager/_models/_material_models/elasticity_isotropic.py b/src/ansys/materials/manager/_models/_material_models/elasticity_isotropic.py index 28a5b232..07f46d8c 100644 --- a/src/ansys/materials/manager/_models/_material_models/elasticity_isotropic.py +++ b/src/ansys/materials/manager/_models/_material_models/elasticity_isotropic.py @@ -21,7 +21,7 @@ # SOFTWARE. -from typing import Any, Literal +from typing import Literal from ansys.units import Quantity from pydantic import Field, model_validator @@ -31,19 +31,8 @@ MaterialModel, ParameterField, QualifierType, - _MapdlCore, validate_and_initialize_model_qualifiers, ) -from ansys.materials.manager.util.mapdl import ( - write_constant_property, - write_interpolation_options, - write_table_values, -) -from ansys.materials.manager.util.mapdl.mapdl_writer import ( - write_constant_properties, - write_temperature_reference_value, - write_temperature_table_values, -) class ElasticityIsotropic(MaterialModel): @@ -54,11 +43,15 @@ class ElasticityIsotropic(MaterialModel): default=None, description="The Young's modulus of the material.", matml_name="Young's Modulus", + mapdl_name="EX", + lsdyna_name="e", ) poissons_ratio: Quantity | None = ParameterField( default=None, description="The Poisson's ratio of the material.", matml_name="Poisson's Ratio", + mapdl_name="PRXY", + lsdyna_name="pr", ) @model_validator(mode="before") @@ -68,81 +61,3 @@ def _initialize_qualifiers(cls, values) -> Dict: values, expected_qualifiers ) return values - - def _write_mapdl(self, material_id: int, reference_temperature: float | None) -> str: - material_string = "" - if reference_temperature: - material_string += write_temperature_reference_value(material_id, reference_temperature) - if not self.independent_parameters: - material_string += write_constant_property( - label="EX", - property=self.youngs_modulus.value, - material_id=material_id, - unit=self.youngs_modulus.unit, - ) - material_string += write_constant_property( - label="PRXY", - property=self.poissons_ratio.value, - material_id=material_id, - unit=self.poissons_ratio.unit, - ) - return material_string - else: - if ( - len(self.independent_parameters) == 1 - and self.independent_parameters[0].name == "Temperature" - ): - if len(self.independent_parameters[0].values.value) == 1: - material_string += write_constant_properties( - labels=[ - "EX", - "PRXY", - ], - properties=[self.youngs_modulus.value, self.poissons_ratio.value], - property_units=[self.youngs_modulus.unit, self.poissons_ratio.unit], - material_id=material_id, - ) - return material_string - else: - material_string += write_temperature_table_values( - labels=["EX"], - dependent_parameters=[self.youngs_modulus.value], - dependent_parameters_unit=[self.youngs_modulus.unit], - material_id=material_id, - temperature_parameter=self.independent_parameters[0], - ) - material_string += write_temperature_table_values( - labels=["PRXY"], - dependent_parameters=[self.poissons_ratio.value], - dependent_parameters_unit=[self.poissons_ratio.unit], - material_id=material_id, - temperature_parameter=self.independent_parameters[0], - ) - return material_string - else: - parameters_str, table_str = write_table_values( - label="ELASTIC", - dependent_parameters=[self.youngs_modulus.value, self.poissons_ratio.value], - material_id=material_id, - independent_parameters=self.independent_parameters, - tb_opt="ISOT", - ) - material_string += parameters_str + "\n" + table_str - - if self.interpolation_options: - interpolation_string += write_interpolation_options( - interpolation_options=self.interpolation_options, - independent_parameters=self.independent_parameters, - ) - material_string += "\n" + interpolation_string - return material_string - - def write_model(self, material_id: int, pyansys_session: Any, **kwargs: dict) -> str: - """Write this model to the specified session.""" - self.validate_model() - if isinstance(pyansys_session, _MapdlCore): - reference_temperature = kwargs.get("reference_temperature", None) - material_string = self._write_mapdl(material_id, reference_temperature) - else: - raise Exception("The session is not supported.") - return material_string diff --git a/src/ansys/materials/manager/_models/_material_models/elasticity_orthotropic.py b/src/ansys/materials/manager/_models/_material_models/elasticity_orthotropic.py index 3a406ce0..87b804f1 100644 --- a/src/ansys/materials/manager/_models/_material_models/elasticity_orthotropic.py +++ b/src/ansys/materials/manager/_models/_material_models/elasticity_orthotropic.py @@ -24,22 +24,13 @@ from ansys.units import Quantity from pydantic import Field, model_validator -from pyparsing import Any from ansys.materials.manager._models._common import ( MaterialModel, ParameterField, QualifierType, - _MapdlCore, validate_and_initialize_model_qualifiers, ) -from ansys.materials.manager.util.mapdl.mapdl_writer import ( - write_constant_properties, - write_interpolation_options, - write_table_values, - write_temperature_reference_value, - write_temperature_table_values, -) class ElasticityOrthotropic(MaterialModel): @@ -51,54 +42,72 @@ class ElasticityOrthotropic(MaterialModel): default=None, description="The Young's modulus of the material in the x direction.", matml_name="Young's Modulus X direction", + mapdl_name="EX", + lsdyna_name="ea", ) youngs_modulus_y: Quantity | None = ParameterField( default=None, description="The Young's modulus of the material in the y direction.", matml_name="Young's Modulus Y direction", + mapdl_name="EY", + lsdyna_name="eb", ) youngs_modulus_z: Quantity | None = ParameterField( default=None, description="The Young's modulus of the material in the z direction.", matml_name="Young's Modulus Z direction", + mapdl_name="EZ", + lsdyna_name="ec", ) - poissons_ratio_yz: Quantity | None = ParameterField( - default=None, - description="The Poisson's ratio yz of the material.", - matml_name="Poisson's Ratio YZ", - ) - - poissons_ratio_xz: Quantity | None = ParameterField( - default=None, - description="The Poisson's ratio xz of the material.", - matml_name="Poisson's Ratio XZ", - ) - - poissons_ratio_xy: Quantity | None = ParameterField( + shear_modulus_xy: Quantity | None = ParameterField( default=None, - description="The Poisson's ratio xy of the material.", - matml_name="Poisson's Ratio XY", + description="The shear modulus xy of the material.", + matml_name="Shear Modulus XY", + mapdl_name="GXY", + lsdyna_name="gab", ) shear_modulus_yz: Quantity | None = ParameterField( default=None, description="The shear modulus yz of the material.", matml_name="Shear Modulus YZ", + mapdl_name="GYZ", + lsdyna_name="gbc", ) shear_modulus_xz: Quantity | None = ParameterField( default=None, description="The shear modulus xz of the material.", matml_name="Shear Modulus XZ", + mapdl_name="GXZ", + lsdyna_name="gca", ) - shear_modulus_xy: Quantity | None = ParameterField( + poissons_ratio_xy: Quantity | None = ParameterField( default=None, - description="The shear modulus xy of the material.", - matml_name="Shear Modulus XY", + description="The Poisson's ratio xy of the material.", + matml_name="Poisson's Ratio XY", + mapdl_name="PRXY", + lsdyna_name="prba", + ) + + poissons_ratio_yz: Quantity | None = ParameterField( + default=None, + description="The Poisson's ratio yz of the material.", + matml_name="Poisson's Ratio YZ", + mapdl_name="PRYZ", + lsdyna_name="prcb", + ) + + poissons_ratio_xz: Quantity | None = ParameterField( + default=None, + description="The Poisson's ratio xz of the material.", + matml_name="Poisson's Ratio XZ", + mapdl_name="PRXZ", + lsdyna_name="prca", ) @model_validator(mode="before") @@ -108,89 +117,3 @@ def _initialize_qualifiers(cls, values) -> Dict: values, expected_qualifiers ) return values - - def _write_mapdl(self, material_id: int, reference_temperature: float | None) -> str: - material_string = "" - if reference_temperature: - material_string += write_temperature_reference_value(material_id, reference_temperature) - - dependent_parameters = [ - self.youngs_modulus_x.value, - self.youngs_modulus_y.value, - self.youngs_modulus_z.value, - self.shear_modulus_xy.value, - self.shear_modulus_yz.value, - self.shear_modulus_xz.value, - self.poissons_ratio_xy.value, - self.poissons_ratio_yz.value, - self.poissons_ratio_xz.value, - ] - dependent_parameters_units = [ - self.youngs_modulus_x.unit, - self.youngs_modulus_y.unit, - self.youngs_modulus_z.unit, - self.shear_modulus_xy.unit, - self.shear_modulus_yz.unit, - self.shear_modulus_xz.unit, - self.poissons_ratio_xy.unit, - self.poissons_ratio_yz.unit, - self.poissons_ratio_xz.unit, - ] - if not self.independent_parameters: - material_string += write_constant_properties( - labels=["EX", "EY", "EZ", "GXY", "GYZ", "GXZ", "PRXY", "PRYZ", "PRXZ"], - properties=dependent_parameters, - property_units=dependent_parameters_units, - material_id=material_id, - ) - return material_string - - else: - if ( - len(self.independent_parameters) == 1 - and self.independent_parameters[0].name == "Temperature" - ): - if len(self.independent_parameters[0].values.value) == 1: - material_string += write_constant_properties( - labels=["EX", "EY", "EZ", "GXY", "GYZ", "GXZ", "PRXY", "PRYZ", "PRXZ"], - properties=dependent_parameters, - property_units=dependent_parameters_units, - material_id=material_id, - ) - return material_string - else: - material_string += write_temperature_table_values( - labels=["EX", "EY", "EZ", "GXY", "GYZ", "GXZ", "PRXY", "PRYZ", "PRXZ"], - dependent_parameters=dependent_parameters, - dependent_parameters_unit=dependent_parameters_units, - material_id=material_id, - temperature_parameter=self.independent_parameters[0], - ) - return material_string - else: - parameters_str, table_str = write_table_values( - label="ELASTIC", - dependent_parameters=dependent_parameters, - material_id=material_id, - independent_parameters=self.independent_parameters, - tb_opt="OELM", - ) - material_string += parameters_str + "\n" + table_str - - if self.interpolation_options: - interpolation_string = write_interpolation_options( - interpolation_options=self.interpolation_options, - independent_parameters=self.independent_parameters, - ) - material_string += "\n" + interpolation_string - return material_string - - def write_model(self, material_id: int, pyansys_session: Any, **kwargs: dict) -> str: - """Write this model to the specified session.""" - self.validate_model() - if isinstance(pyansys_session, _MapdlCore): - reference_temperature = kwargs.get("reference_temperature", None) - material_string = self._write_mapdl(material_id, reference_temperature) - else: - raise Exception("The session is not supported.") - return material_string diff --git a/src/ansys/materials/manager/_models/_material_models/fabric_fiber_angle.py b/src/ansys/materials/manager/_models/_material_models/fabric_fiber_angle.py index 101b3140..6ee7c80d 100644 --- a/src/ansys/materials/manager/_models/_material_models/fabric_fiber_angle.py +++ b/src/ansys/materials/manager/_models/_material_models/fabric_fiber_angle.py @@ -20,7 +20,7 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. -from typing import Any, Literal +from typing import Literal from ansys.units import Quantity from pydantic import Field @@ -40,11 +40,3 @@ class FabricFiberAngle(MaterialModel): description="The fabric fiber angle values for the fabric fiber angle model.", matml_name="Fabric Fiber Angle", ) - - def write_model(self, material_id: int, pyansys_session: Any, **kwargs: dict) -> None: - """Write this model to the specified session.""" - pass - - def validate_model(self) -> tuple[bool, list[str]]: - """Validate the model.""" - pass diff --git a/src/ansys/materials/manager/_models/_material_models/fiber_angle.py b/src/ansys/materials/manager/_models/_material_models/fiber_angle.py index 5c688090..8dfa8e96 100644 --- a/src/ansys/materials/manager/_models/_material_models/fiber_angle.py +++ b/src/ansys/materials/manager/_models/_material_models/fiber_angle.py @@ -20,7 +20,7 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. -from typing import Any, Literal +from typing import Literal from pydantic import Field @@ -31,11 +31,3 @@ class FiberAngle(MaterialModel): """Represents a fiber angle material model.""" name: Literal["Fiber Angle"] = Field(default="Fiber Angle", repr=False, frozen=True) - - def write_model(self, material_id: int, pyansys_session: Any, **kwargs: dict) -> None: - """Write this model to the specified session.""" - pass - - def validate_model(self) -> tuple[bool, list[str]]: - """Validate the model.""" - pass diff --git a/src/ansys/materials/manager/_models/_material_models/hill_yield_criterion.py b/src/ansys/materials/manager/_models/_material_models/hill_yield_criterion.py index d436b5ed..570d9200 100644 --- a/src/ansys/materials/manager/_models/_material_models/hill_yield_criterion.py +++ b/src/ansys/materials/manager/_models/_material_models/hill_yield_criterion.py @@ -20,25 +20,17 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. -from typing import Any, Dict, Literal +from typing import Dict, Literal from ansys.units import Quantity -import numpy as np from pydantic import Field, model_validator from ansys.materials.manager._models._common import ( MaterialModel, ParameterField, QualifierType, - _MapdlCore, validate_and_initialize_model_qualifiers, ) -from ansys.materials.manager.util.mapdl.mapdl_writer import ( - write_interpolation_options, - write_table_dep_values, - write_table_value_per_temperature, - write_table_values, -) class HillYieldCriterion(MaterialModel): @@ -151,96 +143,3 @@ def _initialize_qualifiers(cls, values) -> Dict: values, expected_qualifiers ) return values - - def validate_model(self) -> None: - """Validate the model.""" - pass - - def _write_mapdl(self, material_id): - for qualifier in self.model_qualifiers: - if qualifier.name == "Separated Hill Potentials for Plasticity and Creep": - creep = True if qualifier.value == "Yes" else False - - if not creep: - dependent_values = [ - self.yield_stress_ratio_x.value, - self.yield_stress_ratio_y.value, - self.yield_stress_ratio_z.value, - self.yield_stress_ratio_xy.value, - self.yield_stress_ratio_yz.value, - self.yield_stress_ratio_xz.value, - ] - tb_opt = "" - else: - dependent_values = [ - self.yield_stress_ratio_x_for_plasticity.value, - self.yield_stress_ratio_y_for_plasticity.value, - self.yield_stress_ratio_z_for_plasticity.value, - self.yield_stress_ratio_xy_for_plasticity.value, - self.yield_stress_ratio_yz_for_plasticity.value, - self.yield_stress_ratio_xz_for_plasticity.value, - self.yield_stress_ratio_x_for_creep.value, - self.yield_stress_ratio_y_for_creep.value, - self.yield_stress_ratio_z_for_creep.value, - self.yield_stress_ratio_xy_for_creep.value, - self.yield_stress_ratio_yz_for_creep.value, - self.yield_stress_ratio_xz_for_creep.value, - ] - tb_opt = "PC" - - if not self.independent_parameters: - dependent_values = [ - dep_val[0] for dep_val in dependent_values if isinstance(dep_val, np.ndarray) - ] - material_string = write_table_dep_values( - material_id=material_id, - label="HILL", - dependent_values=dependent_values, - tb_opt=tb_opt, - ) - return material_string - elif ( - len(self.independent_parameters) == 1 - and self.independent_parameters[0].name == "Temperature" - ): - if len(self.independent_parameters[0].values.value) == 1: - material_string = write_table_dep_values( - material_id=material_id, - label="HILL", - dependent_values=dependent_values, - tb_opt=tb_opt, - ) - else: - material_string = write_table_value_per_temperature( - label="HILL", - material_id=material_id, - dependent_parameters=dependent_values, - temperature_parameter=self.independent_parameters[0], - tb_opt=tb_opt, - ) - return material_string - else: - parameters_str, table_str = write_table_values( - label="HILL", - dependent_parameters=dependent_values, - material_id=material_id, - independent_parameters=self.independent_parameters, - tb_opt=tb_opt, - ) - material_string = parameters_str + "\n" + table_str - if self.interpolation_options: - interpolation_string = write_interpolation_options( - interpolation_options=self.interpolation_options, - independent_parameters=self.independent_parameters, - ) - material_string += "\n" + interpolation_string - return material_string - - def write_model(self, material_id: int, pyansys_session: Any, **kwargs: dict) -> str: - """Write this model to the specified session.""" - self.validate_model() - if isinstance(pyansys_session, _MapdlCore): - material_string = self._write_mapdl(material_id) - else: - raise Exception("The session is not supported.") - return material_string diff --git a/src/ansys/materials/manager/_models/_material_models/isotropic_hardening.py b/src/ansys/materials/manager/_models/_material_models/isotropic_hardening.py index 257c50aa..439a348c 100644 --- a/src/ansys/materials/manager/_models/_material_models/isotropic_hardening.py +++ b/src/ansys/materials/manager/_models/_material_models/isotropic_hardening.py @@ -21,7 +21,7 @@ # SOFTWARE. from ast import Dict -from typing import Any, Literal +from typing import Literal from ansys.units import Quantity from pydantic import Field, model_validator @@ -30,10 +30,8 @@ MaterialModel, ParameterField, QualifierType, - _MapdlCore, validate_and_initialize_model_qualifiers, ) -from ansys.materials.manager.util.mapdl.mapdl_writer import write_tb_points_for_temperature class IsotropicHardening(MaterialModel): @@ -57,43 +55,6 @@ def _initialize_qualifiers(cls, values) -> Dict: ) return values - def _write_mapdl(self, material_id: int) -> str: - plastic_strain = [ - ind_param.values.value.tolist() - for ind_param in self.independent_parameters - if ind_param.name == "Plastic Strain" - ][0] - temperature = [ - ind_param.values.value.tolist() - for ind_param in self.independent_parameters - if ind_param.name == "Temperature" - ] - table_parameters = [ - plastic_strain, - self.stress.value.tolist(), - ] - if len(self.independent_parameters) == 1: - temperature_parameter = len(table_parameters[0]) * [0] - material_string = write_tb_points_for_temperature( - label="PLASTIC", - table_parameters=table_parameters, - material_id=material_id, - temperature_parameter=temperature_parameter, - tb_opt="MISO", - ) - - elif len(self.independent_parameters) == 2 and len(temperature) == 1: - material_string = write_tb_points_for_temperature( - label="PLASTIC", - table_parameters=table_parameters, - material_id=material_id, - temperature_parameter=temperature[0], - tb_opt="MISO", - ) - else: - raise Exception("Only variable supported at the moment is temperature") - return material_string - def validate_model(self): """Override the validate_model implementation from the baseclass.""" is_plastic_strain = [ @@ -105,12 +66,3 @@ def validate_model(self): "Plastic Strain has not been provided for the isotropic hardening model." ) super().validate_model() - - def write_model(self, material_id: int, pyansys_session: Any, **kwargs: dict) -> str: - """Write this model to the specified session.""" - self.validate_model() - if isinstance(pyansys_session, _MapdlCore): - material_string = self._write_mapdl(material_id) - else: - raise Exception("The session is not supported.") - return material_string diff --git a/src/ansys/materials/manager/_models/_material_models/isotropic_hardening_voce_law.py b/src/ansys/materials/manager/_models/_material_models/isotropic_hardening_voce_law.py index 2e76d6df..915c2343 100644 --- a/src/ansys/materials/manager/_models/_material_models/isotropic_hardening_voce_law.py +++ b/src/ansys/materials/manager/_models/_material_models/isotropic_hardening_voce_law.py @@ -21,7 +21,7 @@ # SOFTWARE. from ast import Dict -from typing import Any, Literal +from typing import Literal from ansys.units import Quantity from pydantic import Field, model_validator @@ -75,11 +75,3 @@ def _initialize_qualifiers(cls, values) -> Dict: values, expected_qualifiers ) return values - - def write_model(self, material_id: int, pyansys_session: Any, **kwargs: dict) -> None: - """Write the isotropic hardening model to the specified session.""" - pass - - def validate_model(self) -> tuple[bool, list[str]]: - """Validate the isotropic hardening model.""" - pass diff --git a/src/ansys/materials/manager/_models/_material_models/kinematic_hardening.py b/src/ansys/materials/manager/_models/_material_models/kinematic_hardening.py index 74993367..7c7e93f6 100644 --- a/src/ansys/materials/manager/_models/_material_models/kinematic_hardening.py +++ b/src/ansys/materials/manager/_models/_material_models/kinematic_hardening.py @@ -21,7 +21,7 @@ # SOFTWARE. from ast import Dict -from typing import Any, Literal +from typing import Literal from ansys.units import Quantity from pydantic import Field, model_validator @@ -107,11 +107,3 @@ def _initialize_qualifiers(cls, values) -> Dict: values, expected_qualifiers ) return values - - def write_model(self, material_id: int, pyansys_session: Any, **kwargs: dict) -> None: - """Write this model to the specified session.""" - pass - - def validate_model(self) -> tuple[bool, list[str]]: - """Validate the model.""" - pass diff --git a/src/ansys/materials/manager/_models/_material_models/larc03_04_constants.py b/src/ansys/materials/manager/_models/_material_models/larc03_04_constants.py index fa0f249d..fe9c3bf0 100644 --- a/src/ansys/materials/manager/_models/_material_models/larc03_04_constants.py +++ b/src/ansys/materials/manager/_models/_material_models/larc03_04_constants.py @@ -20,7 +20,7 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. -from typing import Any, Literal +from typing import Literal from ansys.units import Quantity from pydantic import Field @@ -54,11 +54,3 @@ class LaRc0304Constants(MaterialModel): description="The angle of fracture under compression.", matml_name="Fracture Angle Under Compression", ) - - def write_model(self, material_id: int, pyansys_session: Any, **kwargs: dict) -> None: - """Write the anisotropic elasticity model to the pyansys session.""" - pass - - def validate_model(self) -> tuple[bool, list[str]]: - """Validate the anisotropic elasticity model.""" - pass diff --git a/src/ansys/materials/manager/_models/_material_models/molecular_weight.py b/src/ansys/materials/manager/_models/_material_models/molecular_weight.py index 6e1390da..73de516b 100644 --- a/src/ansys/materials/manager/_models/_material_models/molecular_weight.py +++ b/src/ansys/materials/manager/_models/_material_models/molecular_weight.py @@ -20,7 +20,7 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. -from typing import Literal, Sequence +from typing import Literal from ansys.units import Quantity from pydantic import Field @@ -29,7 +29,6 @@ MaterialModel, ParameterField, SupportedPackage, - _FluentCore, ) @@ -41,6 +40,7 @@ class MolecularWeight(MaterialModel): default=None, description="The molecular weight of the material.", matml_name="Molecular Weight", + fluent_name="molecular_weight", ) supported_packages: list[SupportedPackage] = Field( default=[SupportedPackage.FLUENT], @@ -48,22 +48,3 @@ class MolecularWeight(MaterialModel): description="The list of supported packages", frozen=True, ) - - def _write_fluent(self) -> dict: - return { - "molecular_weight": { - "option": "constant", - "value": ( - self.molecular_weight.value[0] - if isinstance(self.molecular_weight.value, Sequence) - else self.molecular_weight.value - ), - } - } - - def write_model(self, material_id, pyansys_session, **kwargs: dict): - """Write molecular weight model.""" - self.validate_model() - if isinstance(pyansys_session, _FluentCore): - molecular_weight = self._write_fluent() - return molecular_weight diff --git a/src/ansys/materials/manager/_models/_material_models/ply_type.py b/src/ansys/materials/manager/_models/_material_models/ply_type.py index 845c5320..bb757cd0 100644 --- a/src/ansys/materials/manager/_models/_material_models/ply_type.py +++ b/src/ansys/materials/manager/_models/_material_models/ply_type.py @@ -20,7 +20,7 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. -from typing import Any, Literal +from typing import Literal from pydantic import Field @@ -31,11 +31,3 @@ class PlyType(MaterialModel): """Represents a ply type material model.""" name: Literal["Ply Type"] = Field(default="Ply Type", repr=False, frozen=True) - - def write_model(self, material_id: int, pyansys_session: Any, **kwargs: dict) -> None: - """Write this model to the specified session.""" - pass - - def validate_model(self) -> tuple[bool, list[str]]: - """Validate the model.""" - pass diff --git a/src/ansys/materials/manager/_models/_material_models/puck_constants.py b/src/ansys/materials/manager/_models/_material_models/puck_constants.py index d95f785f..be1981d0 100644 --- a/src/ansys/materials/manager/_models/_material_models/puck_constants.py +++ b/src/ansys/materials/manager/_models/_material_models/puck_constants.py @@ -20,7 +20,7 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. -from typing import Any, Literal +from typing import Literal from ansys.units import Quantity from pydantic import Field @@ -52,11 +52,3 @@ class PuckConstants(MaterialModel): description="The tensile inclination in the YZ plane for the Puck constants model.", matml_name="Tensile Inclination YZ", ) - - def write_model(self, material_id: int, pyansys_session: Any, **kwargs: dict) -> None: - """Write this model to the specified session.""" - pass - - def validate_model(self) -> tuple[bool, list[str]]: - """Validate the model.""" - pass diff --git a/src/ansys/materials/manager/_models/_material_models/puck_constants_additional.py b/src/ansys/materials/manager/_models/_material_models/puck_constants_additional.py index 5fdccb50..133a2268 100644 --- a/src/ansys/materials/manager/_models/_material_models/puck_constants_additional.py +++ b/src/ansys/materials/manager/_models/_material_models/puck_constants_additional.py @@ -20,7 +20,7 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. -from typing import Any, Literal +from typing import Literal from ansys.units import Quantity from pydantic import Field @@ -49,11 +49,3 @@ class AdditionalPuckConstants(MaterialModel): description="The degradation parameter M for the additional Puck constants model.", matml_name="Degradation Parameter M", ) - - def write_model(self, material_id: int, pyansys_session: Any, **kwargs: dict) -> None: - """Write this model to the specified session.""" - pass - - def validate_model(self) -> tuple[bool, list[str]]: - """Validate the model.""" - pass diff --git a/src/ansys/materials/manager/_models/_material_models/specific_heat.py b/src/ansys/materials/manager/_models/_material_models/specific_heat.py index 03d9bf38..d7f21f5d 100644 --- a/src/ansys/materials/manager/_models/_material_models/specific_heat.py +++ b/src/ansys/materials/manager/_models/_material_models/specific_heat.py @@ -20,7 +20,7 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. -from typing import Any, Dict, Literal +from typing import Dict, Literal from ansys.units import Quantity from pydantic import Field, model_validator @@ -57,11 +57,3 @@ def _initialize_qualifiers(cls, values) -> Dict: values, expected_qualifiers ) return values - - def write_model(self, material_id: int, pyansys_session: Any, **kwargs: dict) -> None: - """Write the anisotropic elasticity model to the pyansys session.""" - pass - - def validate_model(self) -> tuple[bool, list[str]]: - """Validate the anisotropic elasticity model.""" - pass diff --git a/src/ansys/materials/manager/_models/_material_models/speed_of_sound.py b/src/ansys/materials/manager/_models/_material_models/speed_of_sound.py index 31362a2e..41577f07 100644 --- a/src/ansys/materials/manager/_models/_material_models/speed_of_sound.py +++ b/src/ansys/materials/manager/_models/_material_models/speed_of_sound.py @@ -20,7 +20,7 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. -from typing import Any, Dict, Literal +from typing import Dict, Literal from ansys.units import Quantity from pydantic import Field, model_validator @@ -50,11 +50,3 @@ def _initialize_qualifiers(cls, values) -> Dict: values, expected_qualifiers ) return values - - def write_model(self, material_id: int, pyansys_session: Any, **kwargs: dict) -> None: - """Write the anisotropic elasticity model to the pyansys session.""" - pass - - def validate_model(self) -> tuple[bool, list[str]]: - """Validate the anisotropic elasticity model.""" - pass diff --git a/src/ansys/materials/manager/_models/_material_models/strain_hardening.py b/src/ansys/materials/manager/_models/_material_models/strain_hardening.py index 2951b4bd..616cfe71 100644 --- a/src/ansys/materials/manager/_models/_material_models/strain_hardening.py +++ b/src/ansys/materials/manager/_models/_material_models/strain_hardening.py @@ -20,7 +20,7 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. -from typing import Any, Literal +from typing import Literal from ansys.units import Quantity from pydantic import Field @@ -52,11 +52,3 @@ class StrainHardening(MaterialModel): description="The fourth creep constant for the strain hardening model.", matml_name="Creep Constant 4", ) - - def write_model(self, material_id: int, pyansys_session: Any, **kwargs: dict) -> None: - """Write this model to the specified session.""" - pass - - def validate_model(self) -> tuple[bool, list[str]]: - """Validate the model.""" - pass diff --git a/src/ansys/materials/manager/_models/_material_models/strain_limits_isotropic.py b/src/ansys/materials/manager/_models/_material_models/strain_limits_isotropic.py index 51a1ef0d..d05a4550 100644 --- a/src/ansys/materials/manager/_models/_material_models/strain_limits_isotropic.py +++ b/src/ansys/materials/manager/_models/_material_models/strain_limits_isotropic.py @@ -20,7 +20,7 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. -from typing import Any, Dict, Literal +from typing import Dict, Literal from ansys.units import Quantity from pydantic import Field, model_validator @@ -50,11 +50,3 @@ def _initialize_qualifiers(cls, values) -> Dict: values, expected_qualifiers ) return values - - def write_model(self, material_id: int, pyansys_session: Any, **kwargs: dict) -> None: - """Write this model to the specified session.""" - pass - - def validate_model(self) -> tuple[bool, list[str]]: - """Validate the model.""" - pass diff --git a/src/ansys/materials/manager/_models/_material_models/strain_limits_orthotropic.py b/src/ansys/materials/manager/_models/_material_models/strain_limits_orthotropic.py index f9810375..c55c566f 100644 --- a/src/ansys/materials/manager/_models/_material_models/strain_limits_orthotropic.py +++ b/src/ansys/materials/manager/_models/_material_models/strain_limits_orthotropic.py @@ -20,7 +20,7 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. -from typing import Any, Dict, Literal +from typing import Dict, Literal from ansys.units import Quantity from pydantic import Field, model_validator @@ -90,11 +90,3 @@ def _initialize_qualifiers(cls, values) -> Dict: values, expected_qualifiers ) return values - - def write_model(self, material_id: int, pyansys_session: Any, **kwargs: dict) -> None: - """Write this model to the specified session.""" - pass - - def validate_model(self) -> tuple[bool, list[str]]: - """Validate the model.""" - pass diff --git a/src/ansys/materials/manager/_models/_material_models/stress_limits_orthotropic.py b/src/ansys/materials/manager/_models/_material_models/stress_limits_orthotropic.py index 91054d53..98801778 100644 --- a/src/ansys/materials/manager/_models/_material_models/stress_limits_orthotropic.py +++ b/src/ansys/materials/manager/_models/_material_models/stress_limits_orthotropic.py @@ -20,7 +20,7 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. -from typing import Any, Dict, Literal +from typing import Dict, Literal from ansys.units import Quantity from pydantic import Field, model_validator @@ -90,11 +90,3 @@ def _initialize_qualifiers(cls, values) -> Dict: values, expected_qualifiers ) return values - - def write_model(self, material_id: int, pyansys_session: Any, **kwargs: dict) -> None: - """Write this model to the specified session.""" - pass - - def validate_model(self) -> tuple[bool, list[str]]: - """Validate the model.""" - pass diff --git a/src/ansys/materials/manager/_models/_material_models/thermal_conductivity_isotropic.py b/src/ansys/materials/manager/_models/_material_models/thermal_conductivity_isotropic.py index 4a12dc0a..18a458a7 100644 --- a/src/ansys/materials/manager/_models/_material_models/thermal_conductivity_isotropic.py +++ b/src/ansys/materials/manager/_models/_material_models/thermal_conductivity_isotropic.py @@ -20,7 +20,7 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. -from typing import Any, Dict, Literal +from typing import Dict, Literal from ansys.units import Quantity from pydantic import Field, model_validator @@ -29,17 +29,8 @@ MaterialModel, ParameterField, QualifierType, - _MapdlCore, validate_and_initialize_model_qualifiers, ) -from ansys.materials.manager.util.mapdl.mapdl_writer import ( - write_constant_properties, - write_constant_property, - write_interpolation_options, - write_table_values, - write_temperature_reference_value, - write_temperature_table_values, -) class ThermalConductivityIsotropic(MaterialModel): @@ -52,6 +43,7 @@ class ThermalConductivityIsotropic(MaterialModel): default=None, description="The thermal conductivity of the material.", matml_name="Thermal Conductivity", + mapdl_name="KXX", ) @model_validator(mode="before") @@ -61,66 +53,3 @@ def _initialize_qualifiers(cls, values) -> Dict: values, expected_qualifiers ) return values - - def _write_mapdl(self, material_id: int, reference_temperature: float | None) -> str: - material_string = "" - if reference_temperature: - material_string += write_temperature_reference_value(material_id, reference_temperature) - - if not self.independent_parameters: - material_string += write_constant_property( - label="KXX", - property=self.thermal_conductivity.value, - material_id=material_id, - unit=self.thermal_conductivity.unit, - ) - return material_string - else: - if ( - len(self.independent_parameters) == 1 - and self.independent_parameters[0].name == "Temperature" - ): - if len(self.independent_parameters[0].values.value) == 1: - material_string += write_constant_properties( - labels=["KXX"], - properties=[self.thermal_conductivity.value], - property_units=[self.thermal_conductivity.unit], - material_id=material_id, - ) - return material_string - else: - material_string += write_temperature_table_values( - labels=["KXX"], - dependent_parameters=[self.thermal_conductivity.value], - dependent_parameters_unit=[self.thermal_conductivity.unit], - material_id=material_id, - temperature_parameter=self.independent_parameters[0], - ) - return material_string - else: - parameters_str, table_str = write_table_values( - label="THERM", - dependent_parameters=[self.thermal_conductivity.value], - material_id=material_id, - independent_parameters=self.independent_parameters, - tb_opt="COND", - ) - material_string += parameters_str + "\n" + table_str - - if self.interpolation_options: - interpolation_string += write_interpolation_options( - interpolation_options=self.interpolation_options, - independent_parameters=self.independent_parameters, - ) - material_string += "\n" + interpolation_string - return material_string - - def write_model(self, material_id: int, pyansys_session: Any, **kwargs: dict) -> str: - """Write this model to the specified session.""" - self.validate_model() - if isinstance(pyansys_session, _MapdlCore): - reference_temperature = kwargs.get("reference_temperature", None) - material_string = self._write_mapdl(material_id, reference_temperature) - else: - raise Exception("The session is not supported.") - return material_string diff --git a/src/ansys/materials/manager/_models/_material_models/thermal_conductivity_orthotropic.py b/src/ansys/materials/manager/_models/_material_models/thermal_conductivity_orthotropic.py index 070d55a5..fb4a8ab9 100644 --- a/src/ansys/materials/manager/_models/_material_models/thermal_conductivity_orthotropic.py +++ b/src/ansys/materials/manager/_models/_material_models/thermal_conductivity_orthotropic.py @@ -20,7 +20,7 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. -from typing import Any, Dict, Literal +from typing import Dict, Literal from ansys.units import Quantity from pydantic import Field, model_validator @@ -29,16 +29,8 @@ MaterialModel, ParameterField, QualifierType, - _MapdlCore, validate_and_initialize_model_qualifiers, ) -from ansys.materials.manager.util.mapdl.mapdl_writer import ( - write_constant_properties, - write_interpolation_options, - write_table_values, - write_temperature_reference_value, - write_temperature_table_values, -) class ThermalConductivityOrthotropic(MaterialModel): @@ -51,16 +43,19 @@ class ThermalConductivityOrthotropic(MaterialModel): default=None, description="The thermal conductivity in the X direction of the material.", matml_name="Thermal Conductivity X direction", + mapdl_name="KXX", ) thermal_conductivity_y: Quantity | None = ParameterField( default=None, description="The thermal conductivity in the Y direction of the material.", matml_name="Thermal Conductivity Y direction", + mapdl_name="KYY", ) thermal_conductivity_z: Quantity | None = ParameterField( default=None, description="The thermal conductivity in the Z direction of the material.", matml_name="Thermal Conductivity Z direction", + mapdl_name="KZZ", ) @model_validator(mode="before") @@ -70,77 +65,3 @@ def _initialize_qualifiers(cls, values) -> Dict: values, expected_qualifiers ) return values - - def _write_mapdl(self, material_id: int, reference_temperature: float | None) -> str: - material_string = "" - if reference_temperature: - material_string += write_temperature_reference_value(material_id, reference_temperature) - - dependent_parameters = [ - self.thermal_conductivity_x.value, - self.thermal_conductivity_y.value, - self.thermal_conductivity_z.value, - ] - dependent_parameters_units = [ - self.thermal_conductivity_x.unit, - self.thermal_conductivity_y.unit, - self.thermal_conductivity_z.unit, - ] - - if not self.independent_parameters: - material_string += write_constant_properties( - labels=["KXX", "KYY", "KZZ"], - properties=dependent_parameters, - property_units=dependent_parameters_units, - material_id=material_id, - ) - return material_string - else: - if ( - len(self.independent_parameters) == 1 - and self.independent_parameters[0].name == "Temperature" - ): - if len(self.independent_parameters[0].values.value) == 1: - material_string += write_constant_properties( - labels=["KXX", "KYY", "KZZ"], - properties=dependent_parameters, - property_units=dependent_parameters_units, - material_id=material_id, - ) - return material_string - else: - material_string += write_temperature_table_values( - labels=["KXX", "KYY", "KZZ"], - dependent_parameters=dependent_parameters, - dependent_parameters_unit=dependent_parameters_units, - material_id=material_id, - temperature_parameter=self.independent_parameters[0], - ) - return material_string - else: - parameters_str, table_str = write_table_values( - label="THERM", - dependent_parameters=dependent_parameters, - material_id=material_id, - independent_parameters=self.independent_parameters, - tb_opt="COND", - ) - material_string += parameters_str + "\n" + table_str - - if self.interpolation_options: - interpolation_string = write_interpolation_options( - interpolation_options=self.interpolation_options, - independent_parameters=self.independent_parameters, - ) - material_string += "\n" + interpolation_string - return material_string - - def write_model(self, material_id: int, pyansys_session: Any, **kwargs: dict) -> None: - """Write this model to the specified session.""" - self.validate_model() - if isinstance(pyansys_session, _MapdlCore): - reference_temperature = kwargs.get("reference_temperature", None) - material_string = self._write_mapdl(material_id, reference_temperature) - else: - raise Exception("The session is not supported.") - return material_string diff --git a/src/ansys/materials/manager/_models/_material_models/tsai_wu_constants.py b/src/ansys/materials/manager/_models/_material_models/tsai_wu_constants.py index b59a1b22..60b2fbef 100644 --- a/src/ansys/materials/manager/_models/_material_models/tsai_wu_constants.py +++ b/src/ansys/materials/manager/_models/_material_models/tsai_wu_constants.py @@ -20,7 +20,7 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. -from typing import Any, Literal +from typing import Literal from ansys.units import Quantity from pydantic import Field @@ -47,11 +47,3 @@ class TsaiWuConstants(MaterialModel): description="The coupling coefficient in the YZ plane.", matml_name="Coupling Coefficient YZ", ) - - def write_model(self, material_id: int, pyansys_session: Any, **kwargs: dict) -> None: - """Write the anisotropic elasticity model to the pyansys session.""" - pass - - def validate_model(self) -> tuple[bool, list[str]]: - """Validate the anisotropic elasticity model.""" - pass diff --git a/src/ansys/materials/manager/_models/_material_models/usermat.py b/src/ansys/materials/manager/_models/_material_models/usermat.py index 8e6fd726..28e71438 100644 --- a/src/ansys/materials/manager/_models/_material_models/usermat.py +++ b/src/ansys/materials/manager/_models/_material_models/usermat.py @@ -21,7 +21,7 @@ # SOFTWARE. from ast import Dict -from typing import Any, Literal +from typing import Literal from pydantic import Field, model_validator @@ -52,11 +52,3 @@ def _initialize_qualifiers(cls, values) -> Dict: values, expected_qualifiers ) return values - - def write_model(self, material_id: int, pyansys_session: Any, **kwargs: dict) -> None: - """Write this model to the specified session.""" - pass - - def validate_model(self) -> tuple[bool, list[str]]: - """Validate the model.""" - pass diff --git a/src/ansys/materials/manager/_models/_material_models/viscosity.py b/src/ansys/materials/manager/_models/_material_models/viscosity.py index c9612f34..3d1880ca 100644 --- a/src/ansys/materials/manager/_models/_material_models/viscosity.py +++ b/src/ansys/materials/manager/_models/_material_models/viscosity.py @@ -20,7 +20,7 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. -from typing import Any, Dict, Literal +from typing import Dict, Literal from ansys.units import Quantity from pydantic import Field, model_validator @@ -50,11 +50,3 @@ def _initialize_qualifiers(cls, values) -> Dict: values, expected_qualifiers ) return values - - def write_model(self, material_id: int, pyansys_session: Any, **kwargs: dict) -> None: - """Write the anisotropic elasticity model to the pyansys session.""" - pass - - def validate_model(self) -> tuple[bool, list[str]]: - """Validate the anisotropic elasticity model.""" - pass diff --git a/src/ansys/materials/manager/_models/_material_models/zero_thermal_strain_reference_temperature_isotropic.py b/src/ansys/materials/manager/_models/_material_models/zero_thermal_strain_reference_temperature_isotropic.py index 9f7f424f..1e34f0f1 100644 --- a/src/ansys/materials/manager/_models/_material_models/zero_thermal_strain_reference_temperature_isotropic.py +++ b/src/ansys/materials/manager/_models/_material_models/zero_thermal_strain_reference_temperature_isotropic.py @@ -20,7 +20,7 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. -from typing import Any, Dict, Literal +from typing import Dict, Literal from ansys.units import Quantity from pydantic import Field, model_validator @@ -29,7 +29,6 @@ MaterialModel, ParameterField, QualifierType, - _MapdlCore, validate_and_initialize_model_qualifiers, ) @@ -59,15 +58,3 @@ def _initialize_qualifiers(cls, values) -> Dict: values, expected_qualifiers ) return values - - def _write_mapdl(self, material_id: int): - return f"MPAMOD,{material_id},{self.zero_thermal_strain_reference_temperature.value[0]}\n" - - def write_model(self, material_id: int, pyansys_session: Any, **kwargs: dict) -> None: - """Write this model to the specified session.""" - self.validate_model() - if isinstance(pyansys_session, _MapdlCore): - material_string = self._write_mapdl(material_id) - else: - raise Exception("The session is not supported.") - return material_string diff --git a/src/ansys/materials/manager/_models/_material_models/zero_thermal_strain_reference_temperature_orthotropic.py b/src/ansys/materials/manager/_models/_material_models/zero_thermal_strain_reference_temperature_orthotropic.py index afb9be77..c5c9dae1 100644 --- a/src/ansys/materials/manager/_models/_material_models/zero_thermal_strain_reference_temperature_orthotropic.py +++ b/src/ansys/materials/manager/_models/_material_models/zero_thermal_strain_reference_temperature_orthotropic.py @@ -20,7 +20,7 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. -from typing import Any, Literal +from typing import Literal from ansys.units import Quantity from pydantic import Field, model_validator @@ -30,7 +30,6 @@ MaterialModel, ParameterField, QualifierType, - _MapdlCore, validate_and_initialize_model_qualifiers, ) @@ -60,15 +59,3 @@ def _initialize_qualifiers(cls, values) -> Dict: values, expected_qualifiers ) return values - - def _write_mapdl(self, material_id: int): - return f"MPAMOD,{material_id},{self.zero_thermal_strain_reference_temperature.value[0]}\n" - - def write_model(self, material_id: int, pyansys_session: Any, **kwargs: dict) -> None: - """Write this model to the specified session.""" - self.validate_model() - if isinstance(pyansys_session, _MapdlCore): - material_string = self._write_mapdl(material_id) - else: - raise Exception("The session is not supported.") - return material_string diff --git a/src/ansys/materials/manager/_models/material.py b/src/ansys/materials/manager/_models/material.py index 542d9d94..07200a85 100644 --- a/src/ansys/materials/manager/_models/material.py +++ b/src/ansys/materials/manager/_models/material.py @@ -21,10 +21,10 @@ # SOFTWARE. from collections import Counter -from typing import Any, List +from typing import List import uuid -from ansys.materials.manager._models._common import MaterialModel, _MapdlCore +from ansys.materials.manager._models._common import MaterialModel class Material: @@ -125,12 +125,3 @@ def get_model_by_name(self, model_name: str) -> MaterialModel | None: if model_name.lower() == mat_model.name.lower(): model = mat_model return model - - def write_material(self, pyansys_session: Any, material_id: int, **kwargs: dict): - """Write material to the pyansys session.""" - for model in self.models: - model = model.write_model(material_id, pyansys_session, **kwargs) - if model: - if isinstance(pyansys_session, _MapdlCore): - pyansys_session.prep7() - pyansys_session.input_strings(model) diff --git a/src/ansys/materials/manager/material_manager.py b/src/ansys/materials/manager/material_manager.py index 5e00255d..cfd79174 100644 --- a/src/ansys/materials/manager/material_manager.py +++ b/src/ansys/materials/manager/material_manager.py @@ -24,15 +24,16 @@ """Provides the ``MaterialManager`` class.""" from pathlib import Path -from typing import Any +from typing import Any, Sequence from ansys.materials.manager._models._common import _FluentCore, _MapdlCore from ansys.materials.manager._models._common.material_model import MaterialModel from ansys.materials.manager._models.material import Material from ansys.materials.manager.util.mapdl.mapdl_reader import read_mapdl -from ansys.materials.manager.util.matml.matml_from_material import MatmlWriter from ansys.materials.manager.util.matml.matml_parser import MatmlReader from ansys.materials.manager.util.matml.matml_to_material import convert_matml_materials +from ansys.materials.manager.util.matml.writer_matml import WriterMatml +from ansys.materials.manager.util.writer import get_writer class MaterialManager: @@ -105,9 +106,13 @@ def read_from_matml(self, path: str | Path) -> None: self._add_library(material_dic) print("The materials were correctly read from the provided xml file.") - def write_to_matml(self, path: str | Path) -> None: + def write_to_matml(self, path: str | Path, materials: Sequence[Material] | None = None) -> None: """Write the materials in the library to a MatML file.""" - writer = MatmlWriter(self.materials.values()) + if not materials: + materials = list(self.materials.values()) + writer = get_writer("Matml") + writer.materials = materials + assert isinstance(writer, WriterMatml) writer.export(str(path), indent=True) print(f"{len(self.materials)} materials written to {path}.") @@ -130,7 +135,7 @@ def _add_library(self, material_dic: dict[str, Material]): ) self._materials |= material_dic - def write_material(self, material_name: str, material_id: int | None = None) -> None: + def write_material(self, material_name: str, material_id: int | None = None, **kwargs) -> None: """Write material to the pyansys session.""" material = self._materials.get(material_name, None) if not material: @@ -141,9 +146,10 @@ def write_material(self, material_name: str, material_id: int | None = None) -> if not self.client: print("The pyansys session has not been defined.") return - material.write_material(self._client, material_id) - - material.write_material(self._client, material_id) + writer = get_writer(self.client) + writer.write_material( + material=material, material_id=material_id, client=self.client, **kwargs + ) def read_from_client_session(self) -> None: """Read material from the pyansys client session.""" diff --git a/src/ansys/materials/manager/util/__init__.py b/src/ansys/materials/manager/util/__init__.py index 08bb9516..56467028 100644 --- a/src/ansys/materials/manager/util/__init__.py +++ b/src/ansys/materials/manager/util/__init__.py @@ -19,3 +19,7 @@ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. +from .fluent.writer_fluent import WriterFluent +from .ls_dyna.writer_ls_dyna import WriterLsDyna +from .mapdl.writer_mapdl import WriterMapdl +from .matml.writer_matml import WriterMatml diff --git a/src/ansys/materials/manager/util/common.py b/src/ansys/materials/manager/util/common.py index b2106a7a..ce66e861 100644 --- a/src/ansys/materials/manager/util/common.py +++ b/src/ansys/materials/manager/util/common.py @@ -81,40 +81,6 @@ def _chunk_data(data: Iterable) -> Generator[List, None, None]: piece = list(islice(data_iterator, 6)) -def _chunk_lower_triangular_matrix( - matrix: np.ndarray, -) -> Generator[Iterable[float], None, None]: - """ - Convert a lower-triangular square matrix into a chunked vector. - - This is intended for use with symmetric matrices, where the upper half can be ignored. - - Parameters - ---------- - matrix : np.ndarray - Input square matrix. - - Returns - ------- - Generator[Iterable[float]] - Chunked vector with coefficients in the lower half-matrix. E.g. D11, D12, D22, etc. - - Notes - ----- - If the input matrix is non-symmetric then the upper half-matrix will be lost. - """ - vals = [] - if np.ndim(matrix) != 2: - raise ValueError("Input matrix must be two dimensional.") - size = matrix.shape - if size[0] != size[1]: - raise ValueError("Input matrix must be square.") - for col_index in range(0, matrix.shape[1]): - for row_index in range(col_index, matrix.shape[0]): - vals.append(matrix[row_index][col_index]) - return _chunk_data(vals) - - def fill_upper_triangular_matrix(vector: List[float]) -> np.ndarray: """ Convert a vector of coefficients into a full matrix. diff --git a/src/ansys/materials/manager/util/fluent/__init__.py b/src/ansys/materials/manager/util/fluent/__init__.py new file mode 100644 index 00000000..08bb9516 --- /dev/null +++ b/src/ansys/materials/manager/util/fluent/__init__.py @@ -0,0 +1,21 @@ +# Copyright (C) 2022 - 2025 ANSYS, Inc. and/or its affiliates. +# SPDX-License-Identifier: MIT +# +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. diff --git a/src/ansys/materials/manager/util/fluent/writer_fluent.py b/src/ansys/materials/manager/util/fluent/writer_fluent.py new file mode 100644 index 00000000..212871d9 --- /dev/null +++ b/src/ansys/materials/manager/util/fluent/writer_fluent.py @@ -0,0 +1,58 @@ +# Copyright (C) 2022 - 2025 ANSYS, Inc. and/or its affiliates. +# SPDX-License-Identifier: MIT +# +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. + +from typing import Sequence + +from ansys.materials.manager._models._common.material_model import MaterialModel +from ansys.materials.manager._models.material import Material +from ansys.materials.manager.util.writer import register_writer + + +@register_writer("Solver") +class WriterFluent: + """Class containing the methods for writing into a fluent session.""" + + def _write_material_model(self, model: MaterialModel): + label = [ + field.fluent_name + for field in model.__class__.model_fields.values() + if hasattr(field, "fluent_name") and field.fluent_name + ] + dependant_parameter_names = [ + model_name + for model_name, field in model.__class__.model_fields.items() + if hasattr(field, "fluent_name") and field.fluent_name + ] + dict_model = model.model_dump() + dependent_parameters = [] + for name in dependant_parameter_names: + value = dict_model[name]["value"] + dependent_parameters.append(value.tolist() if isinstance(value, Sequence) else value) + return {label[0]: {"option": "constant", "value": dependent_parameters[0]}} + + def write_material(self, material: Material, material_id: int, **kwargs) -> str: + """Write the material into Fluent.""" + material_model = {} + for model in material.models: + model.validate_model() + material_model.update(self._write_material_model(model)) + return material_model diff --git a/src/ansys/materials/manager/util/ls_dyna/__init__.py b/src/ansys/materials/manager/util/ls_dyna/__init__.py new file mode 100644 index 00000000..08bb9516 --- /dev/null +++ b/src/ansys/materials/manager/util/ls_dyna/__init__.py @@ -0,0 +1,21 @@ +# Copyright (C) 2022 - 2025 ANSYS, Inc. and/or its affiliates. +# SPDX-License-Identifier: MIT +# +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. diff --git a/src/ansys/materials/manager/util/ls_dyna/writer_ls_dyna.py b/src/ansys/materials/manager/util/ls_dyna/writer_ls_dyna.py new file mode 100644 index 00000000..03b0799b --- /dev/null +++ b/src/ansys/materials/manager/util/ls_dyna/writer_ls_dyna.py @@ -0,0 +1,71 @@ +# Copyright (C) 2022 - 2025 ANSYS, Inc. and/or its affiliates. +# SPDX-License-Identifier: MIT +# +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. + +from typing import Sequence + +from ansys.dyna.core.lib.keyword_base import KeywordBase + +from ansys.materials.manager._models._material_models.elasticity_anisotropic import ( + ElasticityAnisotropic, +) +from ansys.materials.manager._models.material import Material +from ansys.materials.manager.util.ls_dyna.writer_ls_dyna_utils import ( + MAT_CARD_REGISTRY, + get_anisotropic_attributes_values, + get_attributes_values, +) +from ansys.materials.manager.util.writer import register_writer + + +@register_writer("Deck") +class WriterLsDyna: + """Class containing the methods for writing into a LS-Dyna session.""" + + def write_material(self, material: Material, material_id: int, **kwargs) -> list[KeywordBase]: + """Write material in the lsdyna deck.""" + models = material.models + instanciated_models = [] + instanciated_models_name = [] + available = {model.__class__.__name__: model for model in models} + class_to_instance = {type(obj): obj for obj in available.values()} + model_classes = set(class_to_instance.keys()) + for required_classes_key, target_cls in MAT_CARD_REGISTRY.items(): + if (target_cls.keyword + target_cls.subkeyword).lower() in instanciated_models_name: + continue + required_classes = set(required_classes_key) + if required_classes.issubset(model_classes): + args = {} + for required_cls in required_classes_key: + instance = class_to_instance.get(required_cls) + if instance is None: + break + if isinstance(instance, ElasticityAnisotropic): + args.update(get_anisotropic_attributes_values(instance)) + else: + args.update(get_attributes_values(instance)) + material_class = target_cls(mid=material_id) + + for key, value in args.items(): + setattr(material_class, key, value[0] if isinstance(value, Sequence) else value) + instanciated_models.append(material_class) + instanciated_models_name.append(material_class.__class__.__name__.lower()) + return instanciated_models diff --git a/src/ansys/materials/manager/util/ls_dyna/writer_ls_dyna_utils.py b/src/ansys/materials/manager/util/ls_dyna/writer_ls_dyna_utils.py new file mode 100644 index 00000000..9c9e9d8f --- /dev/null +++ b/src/ansys/materials/manager/util/ls_dyna/writer_ls_dyna_utils.py @@ -0,0 +1,109 @@ +# Copyright (C) 2022 - 2025 ANSYS, Inc. and/or its affiliates. +# SPDX-License-Identifier: MIT +# +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. + +from ansys.dyna.core import keywords as kwd +import numpy as np + +from ansys.materials.manager._models._common.material_model import MaterialModel # noqa: E501 +from ansys.materials.manager._models._material_models.density import Density +from ansys.materials.manager._models._material_models.elasticity_anisotropic import ( + ElasticityAnisotropic, +) +from ansys.materials.manager._models._material_models.elasticity_isotropic import ( # noqa: E501 + ElasticityIsotropic, +) +from ansys.materials.manager._models._material_models.elasticity_orthotropic import ( + ElasticityOrthotropic, +) + + +def normalize_key(classes: tuple[type]) -> tuple[type]: + """Normalize the mat card registry key.""" + return tuple(sorted(classes, key=lambda cls: cls.__name__)) + + +# most complete needs to go before +MAT_CARD_REGISTRY = { + normalize_key((Density, ElasticityIsotropic)): kwd.Mat001, + normalize_key((ElasticityIsotropic,)): kwd.Mat001, + normalize_key((Density, ElasticityOrthotropic)): kwd.Mat002, + normalize_key((ElasticityOrthotropic,)): kwd.Mat002, + normalize_key((Density, ElasticityAnisotropic)): kwd.Mat002Anis, + normalize_key((ElasticityAnisotropic,)): kwd.Mat002Anis, +} + + +def get_attributes_values(model: MaterialModel) -> dict: + """Get the attribute to the dyna model and values.""" + labels = [ + field.lsdyna_name + for field in model.__class__.model_fields.values() + if hasattr(field, "lsdyna_name") and field.lsdyna_name + ] + dependant_parameter_names = [ + model_name + for model_name, field in model.__class__.model_fields.items() + if hasattr(field, "lsdyna_name") and field.lsdyna_name + ] + dict_model = model.model_dump() + dependent_parameters = [] + for name in dependant_parameter_names: + value = dict_model[name]["value"] + dependent_parameters.append(value.tolist()) + return dict(zip(labels, dependent_parameters)) + + +def get_anisotropic_attributes_values(model: ElasticityAnisotropic): + """Get the attibure to the elasticity anisotropic dyna model.""" + d = np.column_stack( + ( + model.column_1.value, + model.column_2.value, + model.column_3.value, + model.column_4.value, + model.column_5.value, + model.column_6.value, + ) + ).tolist() + return { + "c11": d[0][0], + "c12": d[0][1], + "c22": d[1][1], + "c13": d[0][2], + "c23": d[1][2], + "c33": d[2][2], + "c14": d[0][3], + "c24": d[1][3], + "c34": d[2][3], + "c44": d[3][3], + "c15": d[0][4], + "c25": d[1][4], + "c35": d[2][4], + "c45": d[3][4], + "c55": d[4][4], + "c16": d[0][5], + "c26": d[1][5], + "c36": d[2][5], + "c46": d[3][5], + "c56": d[4][5], + "c66": d[5][5], + } diff --git a/src/ansys/materials/manager/util/mapdl/__init__.py b/src/ansys/materials/manager/util/mapdl/__init__.py index bbc5c40e..84d97cb7 100644 --- a/src/ansys/materials/manager/util/mapdl/__init__.py +++ b/src/ansys/materials/manager/util/mapdl/__init__.py @@ -20,4 +20,8 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. from .mapdl_snippets_strings import * -from .mapdl_writer import write_constant_property, write_interpolation_options, write_table_values +from .writer_mapdl_utils import ( + write_constant_property, + write_interpolation_options, + write_table_values, +) diff --git a/src/ansys/materials/manager/util/mapdl/writer_mapdl.py b/src/ansys/materials/manager/util/mapdl/writer_mapdl.py new file mode 100644 index 00000000..fe9914f6 --- /dev/null +++ b/src/ansys/materials/manager/util/mapdl/writer_mapdl.py @@ -0,0 +1,157 @@ +# Copyright (C) 2022 - 2025 ANSYS, Inc. and/or its affiliates. +# SPDX-License-Identifier: MIT +# +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. +from ansys.materials.manager._models._common import _MapdlCore +from ansys.materials.manager._models._common.material_model import MaterialModel +from ansys.materials.manager._models._material_models.elasticity_anisotropic import ( + ElasticityAnisotropic, +) +from ansys.materials.manager._models._material_models.hill_yield_criterion import HillYieldCriterion +from ansys.materials.manager._models._material_models.isotropic_hardening import IsotropicHardening +from ansys.materials.manager._models._material_models.zero_thermal_strain_reference_temperature_isotropic import ( # noqa: E501 + ZeroThermalStrainReferenceTemperatureIsotropic, +) +from ansys.materials.manager._models._material_models.zero_thermal_strain_reference_temperature_orthotropic import ( # noqa: E501 + ZeroThermalStrainReferenceTemperatureOrthotropic, +) +from ansys.materials.manager._models.material import Material +from ansys.materials.manager.util.mapdl.writer_mapdl_utils import ( + get_labels, + get_table_label, + get_tbopt, + write_anisotropic_elasticity, + write_constant_properties, + write_hill_yield, + write_interpolation_options, + write_isotropic_hardening, + write_table_values, + write_temperature_reference_value, + write_temperature_table_values, +) +from ansys.materials.manager.util.writer import register_writer + + +@register_writer("MapdlGrpc") +class WriterMapdl: + """Class containing the methods for writing into a madpl session.""" + + def _write_material_model( + self, model: MaterialModel, material_id: int, reference_temperature: float | None = None + ): + """Write the material model string.""" + material_string = "" + if reference_temperature: + material_string += write_temperature_reference_value(material_id, reference_temperature) + if isinstance(model, ZeroThermalStrainReferenceTemperatureIsotropic) or isinstance( + model, ZeroThermalStrainReferenceTemperatureOrthotropic + ): + material_string += ( + "" + f"MPAMOD,{material_id},{model.zero_thermal_strain_reference_temperature.value[0]}\n" + ) + elif isinstance(model, ElasticityAnisotropic): + material_string += write_anisotropic_elasticity(model, material_id) + return material_string + elif isinstance(model, IsotropicHardening): + material_string += write_isotropic_hardening(model, material_id) + return material_string + elif isinstance(model, HillYieldCriterion): + material_string += write_hill_yield(model, material_id) + else: + labels = get_labels(model) + dependant_parameter_names = [ + model_name + for model_name, field in model.__class__.model_fields.items() + if hasattr(field, "mapdl_name") and field.mapdl_name + ] + dict_model = model.model_dump() + dependent_parameters = [] + dependent_parameters_units = [] + for name in dependant_parameter_names: + value = dict_model[name]["value"] + units = dict_model[name]["units"] + dependent_parameters.append(value.tolist()) + dependent_parameters_units.append(units) + if not model.independent_parameters: + material_string += write_constant_properties( + labels=labels, + properties=dependent_parameters, + property_units=dependent_parameters_units, + material_id=material_id, + ) + return material_string + else: + if ( + len(model.independent_parameters) == 1 + and model.independent_parameters[0].name.lower() == "temperature" + ): + if len(model.independent_parameters[0].values.value) == 1: + material_string += write_constant_properties( + labels=labels, + properties=dependent_parameters, + property_units=dependent_parameters_units, + material_id=material_id, + ) + return material_string + else: + material_string += write_temperature_table_values( + labels=labels, + dependent_parameters=dependent_parameters, + dependent_parameters_unit=dependent_parameters_units, + material_id=material_id, + temperature_parameter=model.independent_parameters[0], + ) + return material_string + else: + table_label = get_table_label(model.__class__.__name__) + tb_opt = get_tbopt(model.__class__.__name__) + parameters_str, table_str = write_table_values( + label=table_label, + dependent_parameters=dependent_parameters, + material_id=material_id, + independent_parameters=model.independent_parameters, + tb_opt=tb_opt, + ) + material_string += parameters_str + "\n" + table_str + + if model.interpolation_options: + interpolation_string = write_interpolation_options( + interpolation_options=model.interpolation_options, + independent_parameters=model.independent_parameters, + ) + material_string += "\n" + interpolation_string + return material_string + + def write_material(self, material: Material, material_id: int, **kwargs) -> str: + """Write the material into Mapdl.""" + client = kwargs.get("client", None) + if not client or not isinstance(client, _MapdlCore): + raise Exception("client not provided correctly") + reference_temperature = kwargs.get("reference_temperature", None) + material_model_string = "" + for model in material.models: + model.validate_model() + material_model_string += self._write_material_model( + model, material_id, reference_temperature + ) + if material_model_string: + client.prep7() + client.input_strings(material_model_string) diff --git a/src/ansys/materials/manager/util/mapdl/mapdl_writer.py b/src/ansys/materials/manager/util/mapdl/writer_mapdl_utils.py similarity index 65% rename from src/ansys/materials/manager/util/mapdl/mapdl_writer.py rename to src/ansys/materials/manager/util/mapdl/writer_mapdl_utils.py index ddeba4c2..8119fd78 100644 --- a/src/ansys/materials/manager/util/mapdl/mapdl_writer.py +++ b/src/ansys/materials/manager/util/mapdl/writer_mapdl_utils.py @@ -26,6 +26,12 @@ import numpy as np from ansys.materials.manager._models._common import IndependentParameter, InterpolationOptions +from ansys.materials.manager._models._common.material_model import MaterialModel +from ansys.materials.manager._models._material_models.elasticity_anisotropic import ( + ElasticityAnisotropic, +) +from ansys.materials.manager._models._material_models.hill_yield_criterion import HillYieldCriterion +from ansys.materials.manager._models._material_models.isotropic_hardening import IsotropicHardening from .mapdl_snippets_strings import ( CONSTANT_MP_PROPERTY, @@ -49,6 +55,31 @@ USER_DEFINED_TB_FIELDS, ) +TABLE_LABELS = { + "ElasticityIsotropic": "ELASTIC", + "ElasticityOrthotropic": "ELASTIC", + "ElasticityAnisotropic": "ELASTIC", + "CoefficientofThermalExpansionIsotropic": "CTE", + "CoefficientofThermalExpansionOrthotropic": "CTE", + "Density": "DENS", + "ThermalConductivityIsotropic": "THERM", + "ThermalConductivityOrthotropic": "THERM", + "IsotropicHardening": "PLASTIC", + "HillYieldCriterion": "HILL", +} + +TABLE_TBOPT = { + "ElasticityIsotropic": "ISOT", + "ElasticityOrthotropic": "OELM", + "ElasticityAnisotropic": "AELS", + "CoefficientofThermalExpansionIsotropic": None, + "CoefficientofThermalExpansionOrthotropic": None, + "Density": None, + "ThermalConductivityIsotropic": "COND", + "ThermalConductivityOrthotropic": "COND", + "IsotropicHardening": "MISO", +} + def _get_table_constants(idx, values): val1 = values[idx * 6] @@ -457,3 +488,183 @@ def write_temperature_reference_value(material_id: int, temperature: float) -> s MP,REFT,1,21, """ return TEMPERATURE_REFERENCE.format(matid=material_id, temp=temperature) + + +def get_table_label(model_name: str) -> str | None: + """Get table label string.""" + return TABLE_LABELS.get(model_name, None) + + +def get_tbopt(model_name: str) -> str | None: + """Get table tbopt string.""" + return TABLE_TBOPT.get(model_name, None) + + +def get_labels(model: MaterialModel) -> list[str]: + """Get mapdl property label string.""" + if model.name == "Coefficient of Thermal Expansion": + for qualfier in model.model_qualifiers: + if qualfier.name == "Definition": + if qualfier.value == "Instantaneous": + labels = [ + field.mapdl_name[0] + for field in model.__class__.model_fields.values() + if hasattr(field, "mapdl_name") and field.mapdl_name + ] + else: + labels = [ + field.mapdl_name[1] + for field in model.__class__.model_fields.values() + if hasattr(field, "mapdl_name") and field.mapdl_name + ] + else: + labels = [ + field.mapdl_name + for field in model.__class__.model_fields.values() + if hasattr(field, "mapdl_name") and field.mapdl_name + ] + return labels + + +def write_anisotropic_elasticity(model: ElasticityAnisotropic, material_id: int): + """Write anisotropic elasticity.""" + d = np.column_stack( + ( + model.column_1.value, + model.column_2.value, + model.column_3.value, + model.column_4.value, + model.column_5.value, + model.column_6.value, + ) + ) + # extract the lower triangular elements column-wise + dependent_values = [] + for j in range(6): + dependent_values.extend(d[j:, j]) + + material_string = write_table_dep_values( + material_id=material_id, + label=TABLE_LABELS[model.__class__.__name__], + dependent_values=dependent_values, + tb_opt=TABLE_TBOPT[model.__class__.__name__], + ) + return material_string + + +def write_isotropic_hardening(model: IsotropicHardening, material_id: int): + """Write isotropic hardening.""" + plastic_strain = [ + ind_param.values.value.tolist() + for ind_param in model.independent_parameters + if ind_param.name == "Plastic Strain" + ][0] + temperature = [ + ind_param.values.value.tolist() + for ind_param in model.independent_parameters + if ind_param.name == "Temperature" + ] + table_parameters = [ + plastic_strain, + model.stress.value.tolist(), + ] + table_label = TABLE_LABELS[model.__class__.__name__] + table_tbopt = TABLE_TBOPT[model.__class__.__name__] + if len(model.independent_parameters) == 1: + temperature_parameter = len(table_parameters[0]) * [0] + material_string = write_tb_points_for_temperature( + label=table_label, + table_parameters=table_parameters, + material_id=material_id, + temperature_parameter=temperature_parameter, + tb_opt=table_tbopt, + ) + + elif len(model.independent_parameters) == 2 and len(temperature) == 1: + material_string = write_tb_points_for_temperature( + label=table_label, + table_parameters=table_parameters, + material_id=material_id, + temperature_parameter=temperature[0], + tb_opt=table_tbopt, + ) + else: + raise Exception("Only variable supported at the moment is temperature") + return material_string + + +def write_hill_yield(model: HillYieldCriterion, material_id: int): + """Write Hill yield.""" + label = TABLE_LABELS[model.__class__.__name__] + for qualifier in model.model_qualifiers: + if qualifier.name == "Separated Hill Potentials for Plasticity and Creep": + creep = True if qualifier.value == "Yes" else False + + if not creep: + dependent_values = [ + model.yield_stress_ratio_x.value, + model.yield_stress_ratio_y.value, + model.yield_stress_ratio_z.value, + model.yield_stress_ratio_xy.value, + model.yield_stress_ratio_yz.value, + model.yield_stress_ratio_xz.value, + ] + tb_opt = "" + else: + dependent_values = [ + model.yield_stress_ratio_x_for_plasticity.value, + model.yield_stress_ratio_y_for_plasticity.value, + model.yield_stress_ratio_z_for_plasticity.value, + model.yield_stress_ratio_xy_for_plasticity.value, + model.yield_stress_ratio_yz_for_plasticity.value, + model.yield_stress_ratio_xz_for_plasticity.value, + model.yield_stress_ratio_x_for_creep.value, + model.yield_stress_ratio_y_for_creep.value, + model.yield_stress_ratio_z_for_creep.value, + model.yield_stress_ratio_xy_for_creep.value, + model.yield_stress_ratio_yz_for_creep.value, + model.yield_stress_ratio_xz_for_creep.value, + ] + tb_opt = "PC" + + if not model.independent_parameters: + dependent_values = [ + dep_val[0] for dep_val in dependent_values if isinstance(dep_val, np.ndarray) + ] + material_string = write_table_dep_values( + material_id=material_id, + label=label, + dependent_values=dependent_values, + tb_opt=tb_opt, + ) + return material_string + elif ( + len(model.independent_parameters) == 1 + and model.independent_parameters[0].name == "Temperature" + ): + if len(model.independent_parameters[0].values.value) == 1: + material_string = write_table_dep_values( + material_id=material_id, + label=label, + dependent_values=dependent_values, + tb_opt=tb_opt, + ) + else: + material_string = write_table_value_per_temperature( + label=label, + material_id=material_id, + dependent_parameters=dependent_values, + temperature_parameter=model.independent_parameters[0], + tb_opt=tb_opt, + ) + return material_string + else: + parameters_str, table_str = write_table_values( + label=label, + dependent_parameters=dependent_values, + material_id=material_id, + independent_parameters=model.independent_parameters, + tb_opt=tb_opt, + ) + material_string = parameters_str + "\n" + table_str + return material_string diff --git a/src/ansys/materials/manager/util/matml/matml_from_material.py b/src/ansys/materials/manager/util/matml/writer_matml.py similarity index 89% rename from src/ansys/materials/manager/util/matml/matml_from_material.py rename to src/ansys/materials/manager/util/matml/writer_matml.py index 43a15d85..6fa42923 100644 --- a/src/ansys/materials/manager/util/matml/matml_from_material.py +++ b/src/ansys/materials/manager/util/matml/writer_matml.py @@ -20,7 +20,7 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. -"""Provides the ``MatmlWriter`` class.""" +"""Provides the ``WriterMatml`` class.""" import os from typing import BinaryIO, Dict, Optional, Sequence, Union @@ -40,6 +40,7 @@ create_xml_string_value, unit_to_xml, ) +from ansys.materials.manager.util.writer import register_writer from .matml_parser import ( BULKDATA_KEY, @@ -60,13 +61,14 @@ VERSION_DATE = "29.08.2016 15:02:00" -class MatmlWriter: +@register_writer("Matml") +class WriterMatml: """ Exports a list of MAPDL materials to an engineering data XML file. Examples -------- - > writer = MatmlWriter(materials) + > writer = WriterMatml(materials) > writer.export('engineering_data.xml') """ @@ -76,7 +78,7 @@ class MatmlWriter: _metadata_parameters_units: Dict _metadata_property_sets_units: Dict - def __init__(self, materials: Sequence[Material]): + def __init__(self, materials: Sequence[Material] = []): """Construct a Matml writer.""" self._materials = materials self._metadata_property_sets = {} @@ -84,6 +86,15 @@ def __init__(self, materials: Sequence[Material]): self._metadata_parameters_units = {} self._metadata_property_sets_units = {} + @property + def materials(self) -> Sequence[Material]: + """Expose the private field _materials.""" + return self._materials + + @materials.setter + def materials(self, value: Sequence[Material]) -> None: + self._materials = value + def _add_dependent_parameters( self, property_element: ET.Element, models: Dict, parameters: Dict ): @@ -312,12 +323,17 @@ def _add_transfer_ids(self, root: ET.Element) -> None: # add the WB transfer IDs to the XML tree wb_transfer_element = ET.SubElement(root, WBTRANSFER_KEY) materials_element = ET.SubElement(wb_transfer_element, MATERIALS_ELEMENT_KEY) + any_uuid = False for mat in self._materials: - mat_element = ET.SubElement(materials_element, "Material") - name_element = ET.SubElement(mat_element, "Name") - name_element.text = mat.name - transfer_element = ET.SubElement(mat_element, "DataTransferID") - transfer_element.text = mat.guid + if mat.guid is not None: + mat_element = ET.SubElement(materials_element, "Material") + name_element = ET.SubElement(mat_element, "Name") + name_element.text = mat.name + transfer_element = ET.SubElement(mat_element, "DataTransferID") + transfer_element.text = mat.guid + any_uuid = True + if not any_uuid: + root.remove(wb_transfer_element) def _to_etree(self) -> ET.ElementTree: root = ET.Element(ROOT_ELEMENT) @@ -397,3 +413,29 @@ def export( if indent: self._indent(tree) tree.write(path, xml_declaration=xml_declaration) + + def write_material(self, material: Material, material_id: int, **kwargs): + """ + Write a MatML (engineering data XML format) representation of a material to file. + + Parameters + ---------- + material: Material + the materoal to be written. + material_id: int + the material identification number + path: + File path. + indent : Optional[bool] + Whether to add an indent to format the XML output. + Defaults to ``false``. + xml_declaration: Optional[bool] + Whether to add the XML declaration to the output. + """ + path = kwargs("path", None) + if not path: + raise Exception("The path was not provided.") + indent = kwargs.get("indent", False) + xml_declaration = kwargs.get("xml_declaration", False) + self._materials = [material] + self.export(path, indent, xml_declaration) diff --git a/src/ansys/materials/manager/util/writer.py b/src/ansys/materials/manager/util/writer.py new file mode 100644 index 00000000..45f4db20 --- /dev/null +++ b/src/ansys/materials/manager/util/writer.py @@ -0,0 +1,60 @@ +# Copyright (C) 2022 - 2025 ANSYS, Inc. and/or its affiliates. +# SPDX-License-Identifier: MIT +# +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. + +from typing import Protocol, Type + +from pyparsing import Any + +from ansys.materials.manager._models.material import Material + + +class Writer(Protocol): + """Protocol of the Writer.""" + + def write_material(self, material: Material, material_id: int, **kwargs): + """Abstract write material method.""" + ... + + +WRITER_REGISTRY: dict[str, Type[Writer]] = {} + + +def register_writer(name: str): + """Decorate the dynamic registration of the writer registry.""" + + def decorator(cls: Type[Writer]): + WRITER_REGISTRY[name] = cls + return cls + + return decorator + + +def get_writer(client: Any): + """Get the appropriate writer instance.""" + try: + if isinstance(client, str): + cls = WRITER_REGISTRY[client] + else: + cls = WRITER_REGISTRY[client.__class__.__name__] + return cls() + except: + raise Exception("Writer not found.") diff --git a/tests/data/mapdl_coefficient_of_thermal_expansion_isotropic_secant_constant.cdb b/tests/data/mapdl_coefficient_of_thermal_expansion_isotropic_secant_constant.cdb index 2a0a6cff..5662fbae 100644 --- a/tests/data/mapdl_coefficient_of_thermal_expansion_isotropic_secant_constant.cdb +++ b/tests/data/mapdl_coefficient_of_thermal_expansion_isotropic_secant_constant.cdb @@ -1 +1 @@ -MP,ALPX,1,1.,,,, ! C^-1 +MP,ALPX,1,1.0,,,, ! C^-1 diff --git a/tests/data/mapdl_coefficient_of_thermal_expansion_isotropic_secant_constant_ref_temp.cdb b/tests/data/mapdl_coefficient_of_thermal_expansion_isotropic_secant_constant_ref_temp.cdb index d9cff4bc..e10e36d6 100644 --- a/tests/data/mapdl_coefficient_of_thermal_expansion_isotropic_secant_constant_ref_temp.cdb +++ b/tests/data/mapdl_coefficient_of_thermal_expansion_isotropic_secant_constant_ref_temp.cdb @@ -1,2 +1,2 @@ MP,REFT,2,22.0, -MP,ALPX,2,1.,,,, ! C^-1 +MP,ALPX,2,1.0,,,, ! C^-1 diff --git a/tests/data/mapdl_coefficient_of_thermal_expansion_orthotropic_secant_constant.cdb b/tests/data/mapdl_coefficient_of_thermal_expansion_orthotropic_secant_constant.cdb index dd177275..ef9a6ac3 100644 --- a/tests/data/mapdl_coefficient_of_thermal_expansion_orthotropic_secant_constant.cdb +++ b/tests/data/mapdl_coefficient_of_thermal_expansion_orthotropic_secant_constant.cdb @@ -1,3 +1,3 @@ -MP,ALPX,5,1.,,,, ! C^-1 -MP,ALPY,5,2.,,,, ! C^-1 -MP,ALPZ,5,3.,,,, ! C^-1 +MP,ALPX,5,1.0,,,, ! C^-1 +MP,ALPY,5,2.0,,,, ! C^-1 +MP,ALPZ,5,3.0,,,, ! C^-1 diff --git a/tests/data/mapdl_coefficient_of_thermal_expansion_orthotropic_secant_constant_ref_temp.cdb b/tests/data/mapdl_coefficient_of_thermal_expansion_orthotropic_secant_constant_ref_temp.cdb index 48da24c5..295cbb7f 100644 --- a/tests/data/mapdl_coefficient_of_thermal_expansion_orthotropic_secant_constant_ref_temp.cdb +++ b/tests/data/mapdl_coefficient_of_thermal_expansion_orthotropic_secant_constant_ref_temp.cdb @@ -1,4 +1,4 @@ MP,REFT,6,22.0, -MP,ALPX,6,1.,,,, ! C^-1 -MP,ALPY,6,2.,,,, ! C^-1 -MP,ALPZ,6,3.,,,, ! C^-1 +MP,ALPX,6,1.0,,,, ! C^-1 +MP,ALPY,6,2.0,,,, ! C^-1 +MP,ALPZ,6,3.0,,,, ! C^-1 diff --git a/tests/data/mapdl_elasticity_isotropic_variable.cdb b/tests/data/mapdl_elasticity_isotropic_variable.cdb index 63ed25a6..cff6cc9a 100644 --- a/tests/data/mapdl_elasticity_isotropic_variable.cdb +++ b/tests/data/mapdl_elasticity_isotropic_variable.cdb @@ -1,4 +1,3 @@ MPTEMP,1,12.0,21.0,,,, MPDATA,EX,3,1,2000000,1000000,,,, ! Pa -MPTEMP,1,12.0,21.0,,,, MPDATA,PRXY,3,1,0.35,0.3,,,, ! diff --git a/tests/data/mapdl_elasticity_isotropic_variable_reference_temperature.cdb b/tests/data/mapdl_elasticity_isotropic_variable_reference_temperature.cdb index 3ed0da37..df0e7f35 100644 --- a/tests/data/mapdl_elasticity_isotropic_variable_reference_temperature.cdb +++ b/tests/data/mapdl_elasticity_isotropic_variable_reference_temperature.cdb @@ -1,5 +1,4 @@ MP,REFT,3,35.0, MPTEMP,1,12.0,77.0,,,, MPDATA,EX,3,1,2000000,1000000,,,, ! Pa -MPTEMP,1,12.0,77.0,,,, MPDATA,PRXY,3,1,0.35,0.3,,,, ! diff --git a/tests/data/mapdl_thermal_conductivity_isotropic_constant.cdb b/tests/data/mapdl_thermal_conductivity_isotropic_constant.cdb index 24838bf3..b07720a4 100644 --- a/tests/data/mapdl_thermal_conductivity_isotropic_constant.cdb +++ b/tests/data/mapdl_thermal_conductivity_isotropic_constant.cdb @@ -1 +1 @@ -MP,KXX,2,10.,,,, ! W m^-1 C^-1 +MP,KXX,2,10.0,,,, ! W m^-1 C^-1 diff --git a/tests/data/mapdl_thermal_conductivity_isotropic_constant_ref_temp.cdb b/tests/data/mapdl_thermal_conductivity_isotropic_constant_ref_temp.cdb index 11668737..3460d587 100644 --- a/tests/data/mapdl_thermal_conductivity_isotropic_constant_ref_temp.cdb +++ b/tests/data/mapdl_thermal_conductivity_isotropic_constant_ref_temp.cdb @@ -1,2 +1,2 @@ MP,REFT,3,22.0, -MP,KXX,3,10.,,,, ! W m^-1 C^-1 +MP,KXX,3,10.0,,,, ! W m^-1 C^-1 diff --git a/tests/data/mapdl_thermal_conductivity_orthotropic_constant.cdb b/tests/data/mapdl_thermal_conductivity_orthotropic_constant.cdb index b313e8c4..9a60791d 100644 --- a/tests/data/mapdl_thermal_conductivity_orthotropic_constant.cdb +++ b/tests/data/mapdl_thermal_conductivity_orthotropic_constant.cdb @@ -1,3 +1,3 @@ -MP,KXX,4,10.,,,, ! W m^-1 C^-1 -MP,KYY,4,20.,,,, ! W m^-1 C^-1 -MP,KZZ,4,30.,,,, ! W m^-1 C^-1 +MP,KXX,4,10.0,,,, ! W m^-1 C^-1 +MP,KYY,4,20.0,,,, ! W m^-1 C^-1 +MP,KZZ,4,30.0,,,, ! W m^-1 C^-1 diff --git a/tests/data/mapdl_thermal_conductivity_orthotropic_constant_ref_temp.cdb b/tests/data/mapdl_thermal_conductivity_orthotropic_constant_ref_temp.cdb index 5e6b233f..8f9d8732 100644 --- a/tests/data/mapdl_thermal_conductivity_orthotropic_constant_ref_temp.cdb +++ b/tests/data/mapdl_thermal_conductivity_orthotropic_constant_ref_temp.cdb @@ -1,4 +1,4 @@ MP,REFT,5,22.0, -MP,KXX,5,10.,,,, ! W m^-1 C^-1 -MP,KYY,5,20.,,,, ! W m^-1 C^-1 -MP,KZZ,5,30.,,,, ! W m^-1 C^-1 +MP,KXX,5,10.0,,,, ! W m^-1 C^-1 +MP,KYY,5,20.0,,,, ! W m^-1 C^-1 +MP,KZZ,5,30.0,,,, ! W m^-1 C^-1 diff --git a/tests/data/matml_orthotropic_elasticity.txt b/tests/data/matml_orthotropic_elasticity.txt index 0b63b233..66cf1e31 100644 --- a/tests/data/matml_orthotropic_elasticity.txt +++ b/tests/data/matml_orthotropic_elasticity.txt @@ -24,27 +24,27 @@ Dependent - 0.3 + 1000000 Dependent - 0.4 + 2000000 Dependent - 0.2 + 3000000 Dependent - 2000000 + 0.2 Dependent - 3000000 + 0.3 Dependent - 1000000 + 0.4 Dependent diff --git a/tests/data/matml_orthotropic_elasticity_metadata.txt b/tests/data/matml_orthotropic_elasticity_metadata.txt index fa4c604a..658a2295 100644 --- a/tests/data/matml_orthotropic_elasticity_metadata.txt +++ b/tests/data/matml_orthotropic_elasticity_metadata.txt @@ -33,40 +33,40 @@ Young's Modulus Z direction - - Poisson's Ratio YZ - - - - Poisson's Ratio XZ - - - - Poisson's Ratio XY - - Pa - Shear Modulus YZ + Shear Modulus XY - + Pa - Shear Modulus XZ + Shear Modulus YZ - + Pa - Shear Modulus XY + Shear Modulus XZ + + + + Poisson's Ratio XY + + + + Poisson's Ratio YZ + + + + Poisson's Ratio XZ diff --git a/tests/data/matml_orthotropic_elasticity_variable.txt b/tests/data/matml_orthotropic_elasticity_variable.txt index 35e1af83..9acc72e2 100644 --- a/tests/data/matml_orthotropic_elasticity_variable.txt +++ b/tests/data/matml_orthotropic_elasticity_variable.txt @@ -24,27 +24,27 @@ Dependent,Dependent - 0.3, 0.31 + 1000000, 1100000 Dependent,Dependent - 0.4, 0.41 + 2000000, 2100000 Dependent,Dependent - 0.2, 0.21 + 3000000, 3100000 Dependent,Dependent - 2000000, 2100000 + 0.2, 0.21 Dependent,Dependent - 3000000, 3100000 + 0.3, 0.31 Dependent,Dependent - 1000000, 1100000 + 0.4, 0.41 Dependent,Dependent diff --git a/tests/fluent/test_density_fluent.py b/tests/fluent/test_density_fluent.py index ee34405d..8f3806cb 100644 --- a/tests/fluent/test_density_fluent.py +++ b/tests/fluent/test_density_fluent.py @@ -26,12 +26,13 @@ from ansys.materials.manager._models._common import _FluentCore from ansys.materials.manager._models._material_models.density import Density +from ansys.materials.manager.util.fluent.writer_fluent import WriterFluent def test_density_write_fluent(): mock_fluent = MagicMock(spec=_FluentCore) density = Density(density=Quantity(value=1.225, units="kg m^-3")) - model = density.write_model(1, mock_fluent) + model = WriterFluent()._write_material_model(density) mock_fluent.settings.setup.materials.fluid["air"] = model mock_fluent.settings.setup.materials.fluid.__setitem__.assert_called_once() args = mock_fluent.settings.setup.materials.fluid.__setitem__.call_args diff --git a/tests/fluent/test_molecular_weight_fluent.py b/tests/fluent/test_molecular_weight_fluent.py index 97b131db..8d0816f4 100644 --- a/tests/fluent/test_molecular_weight_fluent.py +++ b/tests/fluent/test_molecular_weight_fluent.py @@ -26,12 +26,13 @@ from ansys.materials.manager._models._common import _FluentCore from ansys.materials.manager._models._material_models.molecular_weight import MolecularWeight +from ansys.materials.manager.util.fluent.writer_fluent import WriterFluent def test_molecular_weight_write_fluent(): mock_fluent = MagicMock(spec=_FluentCore) - density = MolecularWeight(molecular_weight=Quantity(value=28.966, units="kg kmol^-1")) - model = density.write_model(1, mock_fluent) + molecular_weight = MolecularWeight(molecular_weight=Quantity(value=28.966, units="kg kmol^-1")) + model = WriterFluent()._write_material_model(molecular_weight) mock_fluent.settings.setup.materials.fluid["air"] = model mock_fluent.settings.setup.materials.fluid.__setitem__.assert_called_once() args = mock_fluent.settings.setup.materials.fluid.__setitem__.call_args diff --git a/tests/ls_dyna/test_elasticity_lsdyna_write.py b/tests/ls_dyna/test_elasticity_lsdyna_write.py new file mode 100644 index 00000000..da224cd0 --- /dev/null +++ b/tests/ls_dyna/test_elasticity_lsdyna_write.py @@ -0,0 +1,330 @@ +# Copyright (C) 2022 - 2025 ANSYS, Inc. and/or its affiliates. +# SPDX-License-Identifier: MIT +# +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. + +from ansys.units import Quantity +import numpy as np + +from ansys.materials.manager._models._material_models.density import Density +from ansys.materials.manager._models._material_models.elasticity_anisotropic import ( + ElasticityAnisotropic, +) +from ansys.materials.manager._models._material_models.elasticity_isotropic import ( + ElasticityIsotropic, +) +from ansys.materials.manager._models._material_models.elasticity_orthotropic import ( + ElasticityOrthotropic, +) +from ansys.materials.manager._models.material import Material +from ansys.materials.manager.util.ls_dyna.writer_ls_dyna import WriterLsDyna + + +def test_write_constant_elasticity_isotropic(): + elasticity = ElasticityIsotropic( + youngs_modulus=Quantity(value=[1000000], units="Pa"), + poissons_ratio=Quantity(value=[0.3], units=""), + ) + + material = Material(name="Linear Elastic", models=[elasticity]) + + material_id = 1 + lsdyna_material = WriterLsDyna().write_material(material, material_id) + assert len(lsdyna_material) == 1 + assert lsdyna_material[0].e == elasticity.youngs_modulus.value[0] + assert lsdyna_material[0].pr == elasticity.poissons_ratio.value[0] + assert lsdyna_material[0].mid == material_id + + +def test_write_constant_elasticity_isotropic_with_density(): + density = Density( + density=Quantity(value=[1.34], units="kg m^-3"), + ) + + elasticity = ElasticityIsotropic( + youngs_modulus=Quantity(value=[1000000], units="Pa"), + poissons_ratio=Quantity(value=[0.3], units=""), + ) + + material = Material(name="Isotropic Elastic", models=[density, elasticity]) + + material_id = 2 + lsdyna_material = WriterLsDyna().write_material(material, material_id) + assert len(lsdyna_material) == 1 + assert lsdyna_material[0].e == elasticity.youngs_modulus.value[0] + assert lsdyna_material[0].pr == elasticity.poissons_ratio.value[0] + assert lsdyna_material[0].ro == density.density.value[0] + assert lsdyna_material[0].mid == material_id + + +def test_write_constant_elasticity_orthotropic(): + elasticity = ElasticityOrthotropic( + youngs_modulus_x=Quantity(value=[1000000], units="Pa"), + youngs_modulus_y=Quantity(value=[2000000], units="Pa"), + youngs_modulus_z=Quantity(value=[3000000], units="Pa"), + shear_modulus_xy=Quantity(value=[100000], units="Pa"), + shear_modulus_yz=Quantity(value=[200000], units="Pa"), + shear_modulus_xz=Quantity(value=[300000], units="Pa"), + poissons_ratio_xy=Quantity(value=[0.1], units=""), + poissons_ratio_yz=Quantity(value=[0.2], units=""), + poissons_ratio_xz=Quantity(value=[0.3], units=""), + ) + + material = Material(name="Orthotropic Elastic", models=[elasticity]) + + material_id = 3 + lsdyna_material = WriterLsDyna().write_material(material, material_id) + assert len(lsdyna_material) == 1 + assert lsdyna_material[0].ea == elasticity.youngs_modulus_x.value[0] + assert lsdyna_material[0].eb == elasticity.youngs_modulus_y.value[0] + assert lsdyna_material[0].ec == elasticity.youngs_modulus_z.value[0] + assert lsdyna_material[0].gab == elasticity.shear_modulus_xy.value[0] + assert lsdyna_material[0].gbc == elasticity.shear_modulus_yz.value[0] + assert lsdyna_material[0].gca == elasticity.shear_modulus_xz.value[0] + assert lsdyna_material[0].prba == elasticity.poissons_ratio_xy.value[0] + assert lsdyna_material[0].prcb == elasticity.poissons_ratio_yz.value[0] + assert lsdyna_material[0].prca == elasticity.poissons_ratio_xz.value[0] + assert lsdyna_material[0].mid == material_id + + +def test_write_constant_elasticity_orthotropic_with_density(): + density = Density( + density=Quantity(value=[1.34], units="kg m^-3"), + ) + + elasticity = ElasticityOrthotropic( + youngs_modulus_x=Quantity(value=[1000000], units="Pa"), + youngs_modulus_y=Quantity(value=[2000000], units="Pa"), + youngs_modulus_z=Quantity(value=[3000000], units="Pa"), + shear_modulus_xy=Quantity(value=[100000], units="Pa"), + shear_modulus_yz=Quantity(value=[200000], units="Pa"), + shear_modulus_xz=Quantity(value=[300000], units="Pa"), + poissons_ratio_xy=Quantity(value=[0.1], units=""), + poissons_ratio_yz=Quantity(value=[0.2], units=""), + poissons_ratio_xz=Quantity(value=[0.3], units=""), + ) + + material = Material(name="Orthotropic Elastic", models=[elasticity, density]) + + material_id = 4 + lsdyna_material = WriterLsDyna().write_material(material, material_id) + assert len(lsdyna_material) == 1 + assert lsdyna_material[0].ro == density.density.value[0] + assert lsdyna_material[0].ea == elasticity.youngs_modulus_x.value[0] + assert lsdyna_material[0].eb == elasticity.youngs_modulus_y.value[0] + assert lsdyna_material[0].ec == elasticity.youngs_modulus_z.value[0] + assert lsdyna_material[0].gab == elasticity.shear_modulus_xy.value[0] + assert lsdyna_material[0].gbc == elasticity.shear_modulus_yz.value[0] + assert lsdyna_material[0].gca == elasticity.shear_modulus_xz.value[0] + assert lsdyna_material[0].prba == elasticity.poissons_ratio_xy.value[0] + assert lsdyna_material[0].prcb == elasticity.poissons_ratio_yz.value[0] + assert lsdyna_material[0].prca == elasticity.poissons_ratio_xz.value[0] + assert lsdyna_material[0].mid == material_id + + +def test_write_constant_elasticity_anisotropic(): + elasticity = ElasticityAnisotropic( + column_1=Quantity( + value=[100000000, 1000000, 2000000, 3000000, 4000000, 5000000], units="Pa" + ), + column_2=Quantity( + value=[7.88860905221012e-31, 150000000, 6000000, 7000000, 8000000, 9000000], + units="Pa", + ), + column_3=Quantity( + value=[ + 7.88860905221012e-31, + 7.88860905221012e-31, + 200000000, + 10000000, + 11000000, + 12000000, + ], + units="Pa", + ), + column_4=Quantity( + value=[ + 7.88860905221012e-31, + 7.88860905221012e-31, + 7.88860905221012e-31, + 50000000, + 13000000, + 14000000, + ], + units="Pa", + ), + column_5=Quantity( + value=[ + 7.88860905221012e-31, + 7.88860905221012e-31, + 7.88860905221012e-31, + 7.88860905221012e-31, + 60000000, + 15000000, + ], + units="Pa", + ), + column_6=Quantity( + value=[ + 7.88860905221012e-31, + 7.88860905221012e-31, + 7.88860905221012e-31, + 7.88860905221012e-31, + 7.88860905221012e-31, + 70000000, + ], + units="Pa", + ), + ) + + material = Material(name="Anisotropic Elastic", models=[elasticity]) + + material_id = 5 + lsdyna_material = WriterLsDyna().write_material(material, material_id) + d = np.column_stack( + ( + elasticity.column_1.value, + elasticity.column_2.value, + elasticity.column_3.value, + elasticity.column_4.value, + elasticity.column_5.value, + elasticity.column_6.value, + ) + ).tolist() + + lsdyna_material[0].c11 == d[0][0] + lsdyna_material[0].c12 == d[0][1] + lsdyna_material[0].c22 == d[1][1] + lsdyna_material[0].c13 == d[0][2] + lsdyna_material[0].c23 == d[1][2] + lsdyna_material[0].c33 == d[2][2] + lsdyna_material[0].c14 == d[0][3] + lsdyna_material[0].c24 == d[1][3] + lsdyna_material[0].c34 == d[2][3] + lsdyna_material[0].c44 == d[3][3] + lsdyna_material[0].c15 == d[0][4] + lsdyna_material[0].c25 == d[1][4] + lsdyna_material[0].c35 == d[2][4] + lsdyna_material[0].c45 == d[3][4] + lsdyna_material[0].c55 == d[4][4] + lsdyna_material[0].c16 == d[0][5] + lsdyna_material[0].c26 == d[1][5] + lsdyna_material[0].c36 == d[2][5] + lsdyna_material[0].c46 == d[3][5] + lsdyna_material[0].c56 == d[4][5] + lsdyna_material[0].c66 == d[5][5] + + +def test_write_constant_elasticity_anisotropic_with_density(): + + density = Density( + density=Quantity(value=[1.34], units="kg m^-3"), + ) + + elasticity = ElasticityAnisotropic( + column_1=Quantity( + value=[100000000, 1000000, 2000000, 3000000, 4000000, 5000000], units="Pa" + ), + column_2=Quantity( + value=[7.88860905221012e-31, 150000000, 6000000, 7000000, 8000000, 9000000], + units="Pa", + ), + column_3=Quantity( + value=[ + 7.88860905221012e-31, + 7.88860905221012e-31, + 200000000, + 10000000, + 11000000, + 12000000, + ], + units="Pa", + ), + column_4=Quantity( + value=[ + 7.88860905221012e-31, + 7.88860905221012e-31, + 7.88860905221012e-31, + 50000000, + 13000000, + 14000000, + ], + units="Pa", + ), + column_5=Quantity( + value=[ + 7.88860905221012e-31, + 7.88860905221012e-31, + 7.88860905221012e-31, + 7.88860905221012e-31, + 60000000, + 15000000, + ], + units="Pa", + ), + column_6=Quantity( + value=[ + 7.88860905221012e-31, + 7.88860905221012e-31, + 7.88860905221012e-31, + 7.88860905221012e-31, + 7.88860905221012e-31, + 70000000, + ], + units="Pa", + ), + ) + + material = Material(name="Anisotropic Elastic", models=[elasticity, density]) + + material_id = 5 + lsdyna_material = WriterLsDyna().write_material(material, material_id) + d = np.column_stack( + ( + elasticity.column_1.value, + elasticity.column_2.value, + elasticity.column_3.value, + elasticity.column_4.value, + elasticity.column_5.value, + elasticity.column_6.value, + ) + ).tolist() + assert lsdyna_material[0].ro == density.density.value[0] + assert lsdyna_material[0].c11 == d[0][0] + assert lsdyna_material[0].c12 == d[0][1] + assert lsdyna_material[0].c22 == d[1][1] + assert lsdyna_material[0].c13 == d[0][2] + assert lsdyna_material[0].c23 == d[1][2] + assert lsdyna_material[0].c33 == d[2][2] + assert lsdyna_material[0].c14 == d[0][3] + assert lsdyna_material[0].c24 == d[1][3] + assert lsdyna_material[0].c34 == d[2][3] + assert lsdyna_material[0].c44 == d[3][3] + assert lsdyna_material[0].c15 == d[0][4] + assert lsdyna_material[0].c25 == d[1][4] + assert lsdyna_material[0].c35 == d[2][4] + assert lsdyna_material[0].c45 == d[3][4] + assert lsdyna_material[0].c55 == d[4][4] + assert lsdyna_material[0].c16 == d[0][5] + assert lsdyna_material[0].c26 == d[1][5] + assert lsdyna_material[0].c36 == d[2][5] + assert lsdyna_material[0].c46 == d[3][5] + assert lsdyna_material[0].c56 == d[4][5] + assert lsdyna_material[0].c66 == d[5][5] diff --git a/tests/mapdl/test_coefficient_of_thermal_expansion_mapdl_write.py b/tests/mapdl/test_coefficient_of_thermal_expansion_mapdl_write.py index ef023e8e..4b5f5f79 100644 --- a/tests/mapdl/test_coefficient_of_thermal_expansion_mapdl_write.py +++ b/tests/mapdl/test_coefficient_of_thermal_expansion_mapdl_write.py @@ -21,11 +21,9 @@ # SOFTWARE. from pathlib import Path -from unittest.mock import MagicMock from ansys.units import Quantity -from ansys.materials.manager._models._common import _MapdlCore from ansys.materials.manager._models._common.independent_parameter import IndependentParameter from ansys.materials.manager._models._common.model_qualifier import ModelQualifier from ansys.materials.manager._models._material_models.cofficient_of_thermal_expansion_isotropic import ( # noqa: E501 @@ -34,6 +32,7 @@ from ansys.materials.manager._models._material_models.cofficient_of_thermal_expansion_orthotropic import ( # noqa: E501 CoefficientofThermalExpansionOrthotropic, ) +from ansys.materials.manager.util.mapdl.writer_mapdl import WriterMapdl DIR_PATH = Path(__file__).resolve().parent COEFFICIENT_OF_THERMAL_EXPANSION_SECANT_ISOTROPIC_CONSTANT = DIR_PATH.joinpath( @@ -71,26 +70,23 @@ def test_coefficient_of_thermal_expansion_coefficient_isotropic_secant_constant(): - thermal_conductivity = CoefficientofThermalExpansionIsotropic( + thermal_expansion = CoefficientofThermalExpansionIsotropic( model_qualifiers=[ModelQualifier(name="Definition", value="Secant")], coefficient_of_thermal_expansion=Quantity(value=[1.0], units="C^-1"), ) - mock_mapdl = MagicMock(spec=_MapdlCore) - material_string = thermal_conductivity.write_model(material_id=1, pyansys_session=mock_mapdl) + material_string = WriterMapdl()._write_material_model(thermal_expansion, 1) with open(COEFFICIENT_OF_THERMAL_EXPANSION_SECANT_ISOTROPIC_CONSTANT, "r") as file: data = file.read() assert data == material_string def test_coefficient_of_thermal_expansion_coefficient_isotropic_secant_ref_temperature(): - thermal_conductivity = CoefficientofThermalExpansionIsotropic( + thermal_expansion = CoefficientofThermalExpansionIsotropic( model_qualifiers=[ModelQualifier(name="Definition", value="Secant")], coefficient_of_thermal_expansion=Quantity(value=[1.0], units="C^-1"), ) - - mock_mapdl = MagicMock(spec=_MapdlCore) - material_string = thermal_conductivity.write_model( - material_id=2, pyansys_session=mock_mapdl, reference_temperature=22.0 + material_string = WriterMapdl()._write_material_model( + thermal_expansion, 2, reference_temperature=22.0 ) with open(COEFFICIENT_OF_THERMAL_EXPANSION_SECANT_ISOTROPIC_CONSTANT_REF_TEMP, "r") as file: data = file.read() @@ -98,7 +94,7 @@ def test_coefficient_of_thermal_expansion_coefficient_isotropic_secant_ref_tempe def test_coefficient_of_thermal_expansion_coefficient_isotropic_secant_variable(): - thermal_conductivity = CoefficientofThermalExpansionIsotropic( + thermal_expansion = CoefficientofThermalExpansionIsotropic( model_qualifiers=[ModelQualifier(name="Definition", value="Secant")], coefficient_of_thermal_expansion=Quantity(value=[1.0, 1.1, 1.2], units="C^-1"), independent_parameters=[ @@ -109,10 +105,8 @@ def test_coefficient_of_thermal_expansion_coefficient_isotropic_secant_variable( ) ], ) - - mock_mapdl = MagicMock(spec=_MapdlCore) - material_string = thermal_conductivity.write_model( - material_id=3, pyansys_session=mock_mapdl, reference_temperature=22.0 + material_string = WriterMapdl()._write_material_model( + thermal_expansion, 3, reference_temperature=22.0 ) with open(COEFFICIENT_OF_THERMAL_EXPANSION_SECANT_ISOTROPIC_VARIABLE, "r") as file: data = file.read() @@ -120,7 +114,7 @@ def test_coefficient_of_thermal_expansion_coefficient_isotropic_secant_variable( def test_coefficient_of_thermal_expansion_coefficient_isotropic_secant_variable_a11_a22(): - thermal_conductivity = CoefficientofThermalExpansionIsotropic( + thermal_expansion = CoefficientofThermalExpansionIsotropic( model_qualifiers=[ModelQualifier(name="Definition", value="Secant")], coefficient_of_thermal_expansion=Quantity( value=[ @@ -168,38 +162,34 @@ def test_coefficient_of_thermal_expansion_coefficient_isotropic_secant_variable_ ), ], ) - - mock_mapdl = MagicMock(spec=_MapdlCore) - material_string = thermal_conductivity.write_model(material_id=4, pyansys_session=mock_mapdl) + material_string = WriterMapdl()._write_material_model(thermal_expansion, 4) with open(COEFFICIENT_OF_THERMAL_EXPANSION_SECANT_ISOTROPIC_VARIABLE_A11_A22, "r") as file: data = file.read() assert data == material_string def test_coefficient_of_thermal_expansion_coefficient_orthotropic_secant_constant(): - thermal_conductivity = CoefficientofThermalExpansionOrthotropic( + thermal_expansion = CoefficientofThermalExpansionOrthotropic( model_qualifiers=[ModelQualifier(name="Definition", value="Secant")], coefficient_of_thermal_expansion_x=Quantity(value=[1.0], units="C^-1"), coefficient_of_thermal_expansion_y=Quantity(value=[2.0], units="C^-1"), coefficient_of_thermal_expansion_z=Quantity(value=[3.0], units="C^-1"), ) - mock_mapdl = MagicMock(spec=_MapdlCore) - material_string = thermal_conductivity.write_model(material_id=5, pyansys_session=mock_mapdl) + material_string = WriterMapdl()._write_material_model(thermal_expansion, 5) with open(COEFFICIENT_OF_THERMAL_EXPANSION_SECANT_ORTHOTROPIC_CONSTANT, "r") as file: data = file.read() assert data == material_string def test_coefficient_of_thermal_expansion_coefficient_orthotropic_secant_constant_ref_temp(): - thermal_conductivity = CoefficientofThermalExpansionOrthotropic( + thermal_expansion = CoefficientofThermalExpansionOrthotropic( model_qualifiers=[ModelQualifier(name="Definition", value="Secant")], coefficient_of_thermal_expansion_x=Quantity(value=[1.0], units="C^-1"), coefficient_of_thermal_expansion_y=Quantity(value=[2.0], units="C^-1"), coefficient_of_thermal_expansion_z=Quantity(value=[3.0], units="C^-1"), ) - mock_mapdl = MagicMock(spec=_MapdlCore) - material_string = thermal_conductivity.write_model( - material_id=6, pyansys_session=mock_mapdl, reference_temperature=22.0 + material_string = WriterMapdl()._write_material_model( + thermal_expansion, 6, reference_temperature=22.0 ) with open(COEFFICIENT_OF_THERMAL_EXPANSION_SECANT_ORTHOTROPIC_CONSTANT_REF_TEMP, "r") as file: data = file.read() @@ -207,7 +197,7 @@ def test_coefficient_of_thermal_expansion_coefficient_orthotropic_secant_constan def test_coefficient_of_thermal_expansion_coefficient_orthotropic_secant_variable(): - thermal_conductivity = CoefficientofThermalExpansionOrthotropic( + thermal_expansion = CoefficientofThermalExpansionOrthotropic( model_qualifiers=[ModelQualifier(name="Definition", value="Secant")], coefficient_of_thermal_expansion_x=Quantity(value=[1.0, 1.1, 1.2], units="C^-1"), coefficient_of_thermal_expansion_y=Quantity(value=[2.0, 2.1, 2.2], units="C^-1"), @@ -220,9 +210,8 @@ def test_coefficient_of_thermal_expansion_coefficient_orthotropic_secant_variabl ) ], ) - mock_mapdl = MagicMock(spec=_MapdlCore) - material_string = thermal_conductivity.write_model( - material_id=7, pyansys_session=mock_mapdl, reference_temperature=22.0 + material_string = WriterMapdl()._write_material_model( + thermal_expansion, 7, reference_temperature=22.0 ) with open(COEFFICIENT_OF_THERMAL_EXPANSION_SECANT_ORTHOTROPIC_VARIABLE, "r") as file: data = file.read() @@ -230,7 +219,7 @@ def test_coefficient_of_thermal_expansion_coefficient_orthotropic_secant_variabl def test_coefficient_of_thermal_expansion_coefficient_orthotropic_secant_variable_a11_a22(): - thermal_conductivity = CoefficientofThermalExpansionOrthotropic( + thermal_expansion = CoefficientofThermalExpansionOrthotropic( model_qualifiers=[ModelQualifier(name="Definition", value="Secant")], coefficient_of_thermal_expansion_x=Quantity( value=[ @@ -324,8 +313,7 @@ def test_coefficient_of_thermal_expansion_coefficient_orthotropic_secant_variabl ), ], ) - mock_mapdl = MagicMock(spec=_MapdlCore) - material_string = thermal_conductivity.write_model(material_id=7, pyansys_session=mock_mapdl) + material_string = WriterMapdl()._write_material_model(thermal_expansion, 7) with open(COEFFICIENT_OF_THERMAL_EXPANSION_SECANT_ORTHOTROPIC_VARIABLE_A11_A22, "r") as file: data = file.read() assert data == material_string diff --git a/tests/mapdl/test_density_mapdl_write.py b/tests/mapdl/test_density_mapdl_write.py index 0e4fcd7d..27bc2cf6 100644 --- a/tests/mapdl/test_density_mapdl_write.py +++ b/tests/mapdl/test_density_mapdl_write.py @@ -21,14 +21,13 @@ # SOFTWARE. from pathlib import Path -from unittest.mock import MagicMock from ansys.units import Quantity -from ansys.materials.manager._models._common import _MapdlCore from ansys.materials.manager._models._common.independent_parameter import IndependentParameter from ansys.materials.manager._models._common.interpolation_options import InterpolationOptions from ansys.materials.manager._models._material_models.density import Density +from ansys.materials.manager.util.mapdl.writer_mapdl import WriterMapdl DIR_PATH = Path(__file__).resolve().parent CONSTANT_DENSITY = DIR_PATH.joinpath("..", "data", "mapdl_density_constant.cdb") @@ -45,8 +44,8 @@ def test_density_constant_no_temp(): density = Density( density=Quantity(value=[1.34], units="kg m^-3"), ) - mock_mapdl = MagicMock(spec=_MapdlCore) - material_string = density.write_model(material_id=1, pyansys_session=mock_mapdl) + + material_string = WriterMapdl()._write_material_model(density, 1) with open(CONSTANT_DENSITY, "r") as file: data = file.read() assert data == material_string @@ -59,8 +58,7 @@ def test_density_single_temp(): IndependentParameter(name="Temperature", values=Quantity(value=[22], units="C")) ], ) - mock_mapdl = MagicMock(spec=_MapdlCore) - material_string = density.write_model(material_id=1, pyansys_session=mock_mapdl) + material_string = WriterMapdl()._write_material_model(density, 1) with open(CONSTANT_DENSITY, "r") as file: data = file.read() assert data == material_string @@ -73,8 +71,7 @@ def test_density_temp_1(): IndependentParameter(name="Temperature", values=Quantity(value=[22, 40], units="C")) ], ) - mock_mapdl = MagicMock(spec=_MapdlCore) - material_string = density.write_model(material_id=1, pyansys_session=mock_mapdl) + material_string = WriterMapdl()._write_material_model(density, 1) with open(VARIABLE_DENSITY_TEMP_1, "r") as file: data = file.read() assert data == material_string @@ -89,8 +86,8 @@ def test_density_temp_2(): ) ], ) - mock_mapdl = MagicMock(spec=_MapdlCore) - material_string = density.write_model(material_id=1, pyansys_session=mock_mapdl) + + material_string = WriterMapdl()._write_material_model(density, 1) with open(VARIABLE_DENSITY_TEMP_2, "r") as file: data = file.read() assert data == material_string @@ -110,8 +107,8 @@ def test_density_a11_a22(): ), ], ) - mock_mapdl = MagicMock(spec=_MapdlCore) - material_string = density.write_model(material_id=1, pyansys_session=mock_mapdl) + + material_string = WriterMapdl()._write_material_model(density, 1) with open(VARIABLE_DENSITY_A11_A22, "r") as file: data = file.read() assert data == material_string @@ -165,8 +162,8 @@ def test_density_temp_a11_a22(): ), ], ) - mock_mapdl = MagicMock(spec=_MapdlCore) - material_string = density.write_model(material_id=1, pyansys_session=mock_mapdl) + + material_string = WriterMapdl()._write_material_model(density, 1) with open(VARIABLE_DENSITY_TEMP_A11_A22, "r") as file: data = file.read() assert data == material_string @@ -235,8 +232,8 @@ def test_temp_a11_a22_interpolation(): cached=False, ), ) - mock_mapdl = MagicMock(spec=_MapdlCore) - material_string = density.write_model(material_id=1, pyansys_session=mock_mapdl) + + material_string = WriterMapdl()._write_material_model(density, 1) with open(VARIABLE_DENSITY_TEMP_A11_A22_INTERP, "r") as file: data = file.read() assert data == material_string diff --git a/tests/mapdl/test_elasticity_mapdl_write.py b/tests/mapdl/test_elasticity_mapdl_write.py index d50f3303..fb8217a3 100644 --- a/tests/mapdl/test_elasticity_mapdl_write.py +++ b/tests/mapdl/test_elasticity_mapdl_write.py @@ -21,14 +21,12 @@ # SOFTWARE. from pathlib import Path -from unittest.mock import MagicMock from ansys.units import Quantity from ansys.materials.manager._models._common import ( IndependentParameter, InterpolationOptions, - _MapdlCore, ) from ansys.materials.manager._models._material_models import ElasticityIsotropic from ansys.materials.manager._models._material_models.elasticity_anisotropic import ( @@ -37,6 +35,7 @@ from ansys.materials.manager._models._material_models.elasticity_orthotropic import ( ElasticityOrthotropic, ) +from ansys.materials.manager.util.mapdl.writer_mapdl import WriterMapdl DIR_PATH = Path(__file__).resolve().parent ELASTICITY_ISOTROPIC_CONSTANT = DIR_PATH.joinpath( @@ -73,8 +72,7 @@ def test_elasticity_isotropic_constant(): youngs_modulus=Quantity(value=[1000000], units="Pa"), poissons_ratio=Quantity(value=[0.3], units=""), ) - mock_mapdl = MagicMock(spec=_MapdlCore) - material_string = elasticity.write_model(material_id=2, pyansys_session=mock_mapdl) + material_string = WriterMapdl()._write_material_model(elasticity, 2) with open(ELASTICITY_ISOTROPIC_CONSTANT, "r") as file: data = file.read() assert data == material_string @@ -85,10 +83,7 @@ def test_elasticity_isotropic_constant_temperature(): youngs_modulus=Quantity(value=[1000000], units="Pa"), poissons_ratio=Quantity(value=[0.3], units=""), ) - mock_mapdl = MagicMock(spec=_MapdlCore) - material_string = elasticity.write_model( - material_id=2, pyansys_session=mock_mapdl, reference_temperature=22.0 - ) + material_string = WriterMapdl()._write_material_model(elasticity, 2, 22.0) with open(ELASTICITY_ISOTROPIC_CONSTANT_REFERENCE_TEMPERATURE, "r") as file: data = file.read() assert data == material_string @@ -105,8 +100,7 @@ def test_elasticity_isotropic_variable(): ) ], ) - mock_mapdl = MagicMock(spec=_MapdlCore) - material_string = elasticity.write_model(material_id=3, pyansys_session=mock_mapdl) + material_string = WriterMapdl()._write_material_model(elasticity, 3) with open(ELASTICITY_ISOTROPIC_VARIABLE_TEMP, "r") as file: data = file.read() assert data == material_string @@ -123,10 +117,7 @@ def test_elasticity_isotropic_variable_reference_temperature(): ) ], ) - mock_mapdl = MagicMock(spec=_MapdlCore) - material_string = elasticity.write_model( - material_id=3, pyansys_session=mock_mapdl, reference_temperature=35.0 - ) + material_string = WriterMapdl()._write_material_model(elasticity, 3, 35.0) print(material_string) with open(ELASTICITY_ISOTROPIC_VARIABLE_TEMP_REFERENCE_TEMP, "r") as file: data = file.read() @@ -145,8 +136,7 @@ def test_elasticity_orthotropic_constant(): shear_modulus_yz=Quantity(value=[2000000], units="Pa"), shear_modulus_xz=Quantity(value=[3000000], units="Pa"), ) - mock_mapdl = MagicMock(spec=_MapdlCore) - material_string = elasticity.write_model(material_id=1, pyansys_session=mock_mapdl) + material_string = WriterMapdl()._write_material_model(elasticity, 1) with open(ELASTICITY_ORTHOTROPIC_CONSTANT, "r") as file: data = file.read() assert data == material_string @@ -170,8 +160,7 @@ def test_elasticity_orthotropic_variable_temp(): ) ], ) - mock_mapdl = MagicMock(spec=_MapdlCore) - material_string = elasticity.write_model(material_id=1, pyansys_session=mock_mapdl) + material_string = WriterMapdl()._write_material_model(elasticity, 1) with open(ELASTICITY_ORTHOTROPIC_VARIABLE, "r") as file: data = file.read() assert data == material_string @@ -385,10 +374,7 @@ def test_elasticity_orthotropic_variable_temp_a11_a22(): extrapolation_type="Projection to the Convex Hull", ), ) - mock_mapdl = MagicMock(spec=_MapdlCore) - material_string = elasticity.write_model( - material_id=1, pyansys_session=mock_mapdl, reference_temperature=22.0 - ) + material_string = WriterMapdl()._write_material_model(elasticity, 1, 22.0) with open(ELASTICITY_ORTHOTROPIC_VARIABLE_TEMP_A11_A22, "r") as file: data = file.read() assert data == material_string @@ -429,9 +415,7 @@ def test_elasticity_orthotropic_variable_a11_a22(): ), ], ) - mock_mapdl = MagicMock(spec=_MapdlCore) - material_string = elasticity.write_model(material_id=1, pyansys_session=mock_mapdl) - print(material_string) + material_string = WriterMapdl()._write_material_model(elasticity, 1) with open(ELASTICITY_ORTHOTROPIC_VARIABLE_A11_A22, "r") as file: data = file.read() assert data == material_string @@ -492,8 +476,7 @@ def test_elasticity_anisotropic_constant(): ), ) - mock_mapdl = MagicMock(spec=_MapdlCore) - material_string = elasticity.write_model(material_id=1, pyansys_session=mock_mapdl) + material_string = WriterMapdl()._write_material_model(elasticity, 1) with open(ELASTICITY_ANISOTROPIC_CONSTANT, "r") as file: data = file.read() assert data == material_string diff --git a/tests/mapdl/test_hill_yield_mapdl_write.py b/tests/mapdl/test_hill_yield_mapdl_write.py index 64e561e0..54fdfc26 100644 --- a/tests/mapdl/test_hill_yield_mapdl_write.py +++ b/tests/mapdl/test_hill_yield_mapdl_write.py @@ -21,15 +21,14 @@ # SOFTWARE. from pathlib import Path -from unittest.mock import MagicMock from ansys.units import Quantity -from ansys.materials.manager._models._common import _MapdlCore from ansys.materials.manager._models._common.independent_parameter import IndependentParameter from ansys.materials.manager._models._common.interpolation_options import InterpolationOptions from ansys.materials.manager._models._common.model_qualifier import ModelQualifier from ansys.materials.manager._models._material_models import HillYieldCriterion +from ansys.materials.manager.util.mapdl.writer_mapdl import WriterMapdl DIR_PATH = Path(__file__).resolve().parent HILL_CONSTANT = DIR_PATH.joinpath("..", "data", "mapdl_hill_constant.cdb") @@ -48,9 +47,7 @@ def test_hill_constant(): yield_stress_ratio_yz=Quantity(value=[0.23], units=""), yield_stress_ratio_z=Quantity(value=[0.5], units=""), ) - - mock_mapdl = MagicMock(spec=_MapdlCore) - material_string = hill.write_model(material_id=2, pyansys_session=mock_mapdl) + material_string = WriterMapdl()._write_material_model(hill, 2) with open(HILL_CONSTANT, "r") as file: data = file.read() assert data == material_string @@ -70,8 +67,7 @@ def test_hill_variable_temp(): ) ], ) - mock_mapdl = MagicMock(spec=_MapdlCore) - material_string = hill.write_model(material_id=2, pyansys_session=mock_mapdl) + material_string = WriterMapdl()._write_material_model(hill, 2) with open(HILL_VARIABLE_TEMP, "r") as file: data = file.read() assert data == material_string @@ -145,8 +141,7 @@ def test_hill_variable_a11_a22(): ], interpolation_options=InterpolationOptions(algorithm_type="Linear Multivariate"), ) - mock_mapdl = MagicMock(spec=_MapdlCore) - material_string = hill.write_model(material_id=2, pyansys_session=mock_mapdl) + material_string = WriterMapdl()._write_material_model(hill, 2) with open(HILL_VARIABLE_A11_A22, "r") as file: data = file.read() assert data == material_string @@ -170,9 +165,7 @@ def hill_creep_constant(): yield_stress_ratio_yz_for_creep=Quantity(value=[2.4], units=""), yield_stress_ratio_z_for_creep=Quantity(value=[2.5], units=""), ) - - mock_mapdl = MagicMock(spec=_MapdlCore) - material_string = hill.write_model(material_id=2, pyansys_session=mock_mapdl) + material_string = WriterMapdl()._write_material_model(hill, 2) with open(HILL_CREEP_CONSTANT, "r") as file: data = file.read() assert data == material_string @@ -199,9 +192,7 @@ def test_hill_creep_variable_temp(): IndependentParameter(name="Temperature", values=Quantity(value=[34, 78], units="C")) ], ) - - mock_mapdl = MagicMock(spec=_MapdlCore) - material_string = hill.write_model(material_id=2, pyansys_session=mock_mapdl) + material_string = WriterMapdl()._write_material_model(hill, 2) with open(HILL_CREEP_VARIABLE_TEMP, "r") as file: data = file.read() assert data == material_string diff --git a/tests/mapdl/test_isotropic_hardening_mapdl_write.py b/tests/mapdl/test_isotropic_hardening_mapdl_write.py index e8f0ed4b..45ed0bd0 100644 --- a/tests/mapdl/test_isotropic_hardening_mapdl_write.py +++ b/tests/mapdl/test_isotropic_hardening_mapdl_write.py @@ -21,13 +21,12 @@ # SOFTWARE. from pathlib import Path -from unittest.mock import MagicMock from ansys.units import Quantity -from ansys.materials.manager._models._common import _MapdlCore from ansys.materials.manager._models._common.independent_parameter import IndependentParameter from ansys.materials.manager._models._material_models import IsotropicHardening +from ansys.materials.manager.util.mapdl.writer_mapdl import WriterMapdl DIR_PATH = Path(__file__).resolve().parent ISOTROPIC_HARDENING_MULTILINEAR_CONSTANT = DIR_PATH.joinpath( @@ -119,8 +118,7 @@ def test_isotropic_hardening_multilinear_constant(): ], ) - mock_mapdl = MagicMock(spec=_MapdlCore) - material_string = isotropic_hardening.write_model(material_id=2, pyansys_session=mock_mapdl) + material_string = WriterMapdl()._write_material_model(isotropic_hardening, 2) with open(ISOTROPIC_HARDENING_MULTILINEAR_CONSTANT, "r") as file: data = file.read() assert data == material_string @@ -519,8 +517,7 @@ def test_isotropic_hardening_multilinear_variable(): ], ) - mock_mapdl = MagicMock(spec=_MapdlCore) - material_string = isotropic_hardening.write_model(material_id=2, pyansys_session=mock_mapdl) + material_string = WriterMapdl()._write_material_model(isotropic_hardening, 2) with open(ISOTROPIC_HARDENING_MULTILINEAR_VARIABLE, "r") as file: data = file.read() assert data == material_string diff --git a/tests/mapdl/test_thermal_conductivity_mapdl_write.py b/tests/mapdl/test_thermal_conductivity_mapdl_write.py index cb82ad1e..fdc488f8 100644 --- a/tests/mapdl/test_thermal_conductivity_mapdl_write.py +++ b/tests/mapdl/test_thermal_conductivity_mapdl_write.py @@ -21,11 +21,9 @@ # SOFTWARE. from pathlib import Path -from unittest.mock import MagicMock from ansys.units import Quantity -from ansys.materials.manager._models._common import _MapdlCore from ansys.materials.manager._models._common.independent_parameter import IndependentParameter from ansys.materials.manager._models._material_models.thermal_conductivity_isotropic import ( ThermalConductivityIsotropic, @@ -33,6 +31,7 @@ from ansys.materials.manager._models._material_models.thermal_conductivity_orthotropic import ( ThermalConductivityOrthotropic, ) +from ansys.materials.manager.util.mapdl.writer_mapdl import WriterMapdl DIR_PATH = Path(__file__).resolve().parent THERMAL_CONDUCTIVITY_ISOTROPIC_CONSTANT = DIR_PATH.joinpath( @@ -62,8 +61,7 @@ def test_thermal_conductivity_isotropic_constant(): thermal_conductivity = ThermalConductivityIsotropic( thermal_conductivity=Quantity(value=[10.0], units="W m^-1 C^-1") ) - mock_mapdl = MagicMock(spec=_MapdlCore) - material_string = thermal_conductivity.write_model(material_id=2, pyansys_session=mock_mapdl) + material_string = WriterMapdl()._write_material_model(thermal_conductivity, 2) with open(THERMAL_CONDUCTIVITY_ISOTROPIC_CONSTANT, "r") as file: data = file.read() assert data == material_string @@ -73,9 +71,8 @@ def test_thermal_conductivity_isotropic_constant_temperature(): thermal_conductivity = ThermalConductivityIsotropic( thermal_conductivity=Quantity(value=[10.0], units="W m^-1 C^-1"), ) - mock_mapdl = MagicMock(spec=_MapdlCore) - material_string = thermal_conductivity.write_model( - material_id=3, pyansys_session=mock_mapdl, reference_temperature=22.0 + material_string = WriterMapdl()._write_material_model( + thermal_conductivity, 3, reference_temperature=22.0 ) with open(THERMAL_CONDUCTIVITY_ISOTROPIC_CONSTANT_REFERENCE_TEMPERATURE, "r") as file: data = file.read() @@ -93,10 +90,8 @@ def test_thermal_conductivity_isotropic_variable(): ) ], ) - - mock_mapdl = MagicMock(spec=_MapdlCore) - material_string = thermal_conductivity.write_model( - material_id=1, pyansys_session=mock_mapdl, reference_temperature=22.0 + material_string = WriterMapdl()._write_material_model( + thermal_conductivity, 1, reference_temperature=22.0 ) with open(THERMAL_CONDUCTIVITY_ISOTROPIC_VARIABLE_TEMP, "r") as file: data = file.read() @@ -109,9 +104,7 @@ def test_thermal_conductivity_orthotropic_constant(): thermal_conductivity_y=Quantity(value=[20.0], units="W m^-1 C^-1"), thermal_conductivity_z=Quantity(value=[30.0], units="W m^-1 C^-1"), ) - - mock_mapdl = MagicMock(spec=_MapdlCore) - material_string = thermal_conductivity.write_model(material_id=4, pyansys_session=mock_mapdl) + material_string = WriterMapdl()._write_material_model(thermal_conductivity, 4) with open(THERMAL_CONDUCTIVITY_ORTHOTROPIC_CONSTANT, "r") as file: data = file.read() assert data == material_string @@ -131,9 +124,8 @@ def test_thermal_conductivity_orthotropic_constant_reference_temperature(): ], ) - mock_mapdl = MagicMock(spec=_MapdlCore) - material_string = thermal_conductivity.write_model( - material_id=5, pyansys_session=mock_mapdl, reference_temperature=22.0 + material_string = WriterMapdl()._write_material_model( + thermal_conductivity, 5, reference_temperature=22.0 ) with open(THERMAL_CONDUCTIVITY_ORTHOTROPIC_CONSTANT_REFERENCE_TEMPERATURE, "r") as file: data = file.read() @@ -153,10 +145,8 @@ def test_thermal_conductivity_orthotropic_variable_temperature(): ) ], ) - - mock_mapdl = MagicMock(spec=_MapdlCore) - material_string = thermal_conductivity.write_model( - material_id=6, pyansys_session=mock_mapdl, reference_temperature=22.0 + material_string = WriterMapdl()._write_material_model( + thermal_conductivity, 6, reference_temperature=22.0 ) with open(THERMAL_CONDUCTIVITY_ORTHOTROPIC_VARIABLE_TEMP, "r") as file: data = file.read() @@ -257,9 +247,7 @@ def test_thermal_conductivity_orthotropic_variable_a11_a22(): ), ], ) - - mock_mapdl = MagicMock(spec=_MapdlCore) - material_string = thermal_conductivity.write_model(material_id=7, pyansys_session=mock_mapdl) + material_string = WriterMapdl()._write_material_model(thermal_conductivity, 7) with open(THERMAL_CONDUCTIVITY_ORTHOTROPIC_VARIABLE_A11_A22, "r") as file: data = file.read() assert data == material_string diff --git a/tests/matml/test_density_matml.py b/tests/matml/test_density_matml.py index 91ffa7e6..4c40366d 100644 --- a/tests/matml/test_density_matml.py +++ b/tests/matml/test_density_matml.py @@ -28,7 +28,7 @@ from ansys.materials.manager._models._common import IndependentParameter from ansys.materials.manager._models._material_models import Density from ansys.materials.manager._models.material import Material -from ansys.materials.manager.util.matml.matml_from_material import MatmlWriter +from ansys.materials.manager.util.matml.writer_matml import WriterMatml DIR_PATH = Path(__file__).resolve().parent XML_FILE_PATH = DIR_PATH.joinpath("..", "data", "matml_unittest_density.xml") @@ -87,7 +87,7 @@ def test_write_material_with_constant_density(): ) ] - writer = MatmlWriter(materials) + writer = WriterMatml(materials) tree = writer._to_etree() material_string, metadata_string = get_material_and_metadata_from_xml(tree) print(metadata_string) @@ -116,7 +116,7 @@ def test_write_model_with_variable_density(): ) ] - writer = MatmlWriter(materials) + writer = WriterMatml(materials) tree = writer._to_etree() material_string, metadata_string = get_material_and_metadata_from_xml(tree) with open(DENSITY_VARIABLE, "r") as file: diff --git a/tests/matml/test_elasticity_matml.py b/tests/matml/test_elasticity_matml.py index d57cb9d6..a72c7de9 100644 --- a/tests/matml/test_elasticity_matml.py +++ b/tests/matml/test_elasticity_matml.py @@ -36,7 +36,7 @@ ElasticityOrthotropic, ) from ansys.materials.manager._models.material import Material -from ansys.materials.manager.util.matml.matml_from_material import MatmlWriter +from ansys.materials.manager.util.matml.writer_matml import WriterMatml DIR_PATH = Path(__file__).resolve().parent XML_FILE_PATH = DIR_PATH.joinpath("..", "data", "matml_unittest_elasticity.xml") @@ -278,7 +278,7 @@ def test_write_constant_elastic_isotropic_material(): ) ] - writer = MatmlWriter(materials) + writer = WriterMatml(materials) tree = writer._to_etree() material_string, metadata_string = get_material_and_metadata_from_xml(tree) with open(ISOTROPIC_ELASTICITY, "r") as file: @@ -298,12 +298,12 @@ def test_write_constant_elastic_orthotropic_material(): youngs_modulus_x=Quantity(value=[1000000], units="Pa"), youngs_modulus_y=Quantity(value=[1500000], units="Pa"), youngs_modulus_z=Quantity(value=[2000000], units="Pa"), - poissons_ratio_xy=Quantity(value=[0.2], units=""), - poissons_ratio_yz=Quantity(value=[0.3], units=""), - poissons_ratio_xz=Quantity(value=[0.4], units=""), shear_modulus_xy=Quantity(value=[1000000], units="Pa"), shear_modulus_yz=Quantity(value=[2000000], units="Pa"), shear_modulus_xz=Quantity(value=[3000000], units="Pa"), + poissons_ratio_xy=Quantity(value=[0.2], units=""), + poissons_ratio_yz=Quantity(value=[0.3], units=""), + poissons_ratio_xz=Quantity(value=[0.4], units=""), independent_parameters=[ IndependentParameter( name="Temperature", @@ -323,7 +323,7 @@ def test_write_constant_elastic_orthotropic_material(): ) ] - writer = MatmlWriter(materials) + writer = WriterMatml(materials) tree = writer._to_etree() material_string, metadata_string = get_material_and_metadata_from_xml(tree) with open(ORTHOTROPIC_ELASTICITY, "r") as file: @@ -396,7 +396,7 @@ def test_write_constant_elastic_anisotropic_material(): ) ] - writer = MatmlWriter(materials) + writer = WriterMatml(materials) tree = writer._to_etree() material_string, metadata_string = get_material_and_metadata_from_xml(tree) with open(ANISOTROPIC_ELASTICITY, "r") as file: @@ -434,7 +434,7 @@ def test_write_variable_elastic_isotropic_material(): ) ] - writer = MatmlWriter(materials) + writer = WriterMatml(materials) tree = writer._to_etree() material_string, metadata_string = get_material_and_metadata_from_xml(tree) with open(ISOTROPIC_ELASTICITY_VARIABLE, "r") as file: @@ -454,12 +454,12 @@ def test_write_variable_elastic_orthotropic_material(): youngs_modulus_x=Quantity(value=[1000000, 11000000], units="Pa"), youngs_modulus_y=Quantity(value=[1500000, 15100000], units="Pa"), youngs_modulus_z=Quantity(value=[2000000, 21000000], units="Pa"), - poissons_ratio_xy=Quantity(value=[0.2, 0.21], units=""), - poissons_ratio_yz=Quantity(value=[0.3, 0.31], units=""), - poissons_ratio_xz=Quantity(value=[0.4, 0.41], units=""), shear_modulus_xy=Quantity(value=[1000000, 1100000], units="Pa"), shear_modulus_yz=Quantity(value=[2000000, 2100000], units="Pa"), shear_modulus_xz=Quantity(value=[3000000, 3100000], units="Pa"), + poissons_ratio_xy=Quantity(value=[0.2, 0.21], units=""), + poissons_ratio_yz=Quantity(value=[0.3, 0.31], units=""), + poissons_ratio_xz=Quantity(value=[0.4, 0.41], units=""), independent_parameters=[ IndependentParameter( name="Temperature", @@ -478,7 +478,7 @@ def test_write_variable_elastic_orthotropic_material(): ], ) ] - writer = MatmlWriter(materials) + writer = WriterMatml(materials) tree = writer._to_etree() material_string, metadata_string = get_material_and_metadata_from_xml(tree) with open(ORTHOTROPIC_ELASTICITY_VARIABLE, "r") as file: diff --git a/tests/matml/test_fabric_fiber_angle_matml.py b/tests/matml/test_fabric_fiber_angle_matml.py index 7b6291b5..7f91cd3b 100644 --- a/tests/matml/test_fabric_fiber_angle_matml.py +++ b/tests/matml/test_fabric_fiber_angle_matml.py @@ -33,7 +33,7 @@ from ansys.materials.manager._models._material_models.fabric_fiber_angle import FabricFiberAngle from ansys.materials.manager._models._material_models.ply_type import PlyType from ansys.materials.manager._models.material import Material -from ansys.materials.manager.util.matml.matml_from_material import MatmlWriter +from ansys.materials.manager.util.matml.writer_matml import WriterMatml DIR_PATH = Path(__file__).resolve().parent XML_FILE_PATH = DIR_PATH.joinpath("..", "data", "matml_unittest_fabric_fiber_angle.xml") @@ -169,7 +169,7 @@ def test_write_constant_fabric_fiber_angle_0_deg(): ], ) ] - writer = MatmlWriter(materials) + writer = WriterMatml(materials) tree = writer._to_etree() material_string, metadata_string = get_material_and_metadata_from_xml(tree) with open(FABRIC_FIBER_ANGLE, "r") as file: @@ -220,7 +220,7 @@ def test_write_variable_fabric_fiber_angle(): ], ) ] - writer = MatmlWriter(materials) + writer = WriterMatml(materials) tree = writer._to_etree() material_string, metadata_string = get_material_and_metadata_from_xml(tree) with open(FABRIC_FIBER_ANGLE_VARIABLE, "r") as file: @@ -245,7 +245,7 @@ def test_write_ply_type(): ], ) ] - writer = MatmlWriter(materials) + writer = WriterMatml(materials) tree = writer._to_etree() material_string, metadata_string = get_material_and_metadata_from_xml(tree) with open(PLY_TYPE, "r") as file: diff --git a/tests/matml/test_hill_yield_matml.py b/tests/matml/test_hill_yield_matml.py index 4da3db03..a7b62caa 100644 --- a/tests/matml/test_hill_yield_matml.py +++ b/tests/matml/test_hill_yield_matml.py @@ -34,7 +34,7 @@ from ansys.materials.manager._models._material_models.kinematic_hardening import KinematicHardening from ansys.materials.manager._models._material_models.strain_hardening import StrainHardening from ansys.materials.manager._models.material import Material -from ansys.materials.manager.util.matml.matml_from_material import MatmlWriter +from ansys.materials.manager.util.matml.writer_matml import WriterMatml DIR_PATH = Path(__file__).resolve().parent NO_CREEP_XML_FILE_PATH = DIR_PATH.joinpath("..", "data", "matml_unittest_hill_yield.xml") @@ -388,7 +388,7 @@ def test_write_constant_hill_yield_no_creep(): ) ] - writer = MatmlWriter(materials) + writer = WriterMatml(materials) tree = writer._to_etree() material_string, metadata_string = get_material_and_metadata_from_xml(tree) with open(HILL_YIELD, "r") as file: @@ -429,7 +429,7 @@ def test_write_variable_hill_yield_no_creep(): ], ) ] - writer = MatmlWriter(materials) + writer = WriterMatml(materials) tree = writer._to_etree() material_string, metadata_string = get_material_and_metadata_from_xml(tree) with open(HILL_YIELD_VARIABLE, "r") as file: @@ -482,7 +482,7 @@ def test_write_constant_hill_yield_creep(): ) ] - writer = MatmlWriter(materials) + writer = WriterMatml(materials) tree = writer._to_etree() material_string, metadata_string = get_material_and_metadata_from_xml(tree) with open(HILL_YIELD_CREEP, "r") as file: @@ -513,7 +513,7 @@ def test_write_kinematic_hardening(): ) ] - writer = MatmlWriter(materials) + writer = WriterMatml(materials) tree = writer._to_etree() material_string, metadata_string = get_material_and_metadata_from_xml(tree) with open(KINEMATIC_HARDENING, "r") as file: @@ -551,7 +551,7 @@ def test_write_strain_hardening(): ) ] - writer = MatmlWriter(materials) + writer = WriterMatml(materials) tree = writer._to_etree() material_string, metadata_string = get_material_and_metadata_from_xml(tree) with open(STRAIN_HARDENING, "r") as file: diff --git a/tests/matml/test_isotropic_hardening_matml.py b/tests/matml/test_isotropic_hardening_matml.py index 62ae9d3b..963d6a74 100644 --- a/tests/matml/test_isotropic_hardening_matml.py +++ b/tests/matml/test_isotropic_hardening_matml.py @@ -31,7 +31,7 @@ IsotropicHardeningVoceLaw, ) from ansys.materials.manager._models.material import Material -from ansys.materials.manager.util.matml.matml_from_material import MatmlWriter +from ansys.materials.manager.util.matml.writer_matml import WriterMatml DIR_PATH = Path(__file__).resolve().parent VOCE_XML_FILE_PATH = DIR_PATH.joinpath("..", "data", "matml_unittest_voce_isotropic_hardening.xml") @@ -517,7 +517,7 @@ def test_write_constant_multilinear_isotropic_hardening(): ) ] - writer = MatmlWriter(materials) + writer = WriterMatml(materials) tree = writer._to_etree() material_string, metadata_string = get_material_and_metadata_from_xml(tree) with open(ISOTROPIC_HARDENING_MULTILINEAR, "r") as file: @@ -580,7 +580,7 @@ def test_write_variable_mutilinear_isotropic_hardening(): ) ] - writer = MatmlWriter(materials) + writer = WriterMatml(materials) tree = writer._to_etree() material_string, metadata_string = get_material_and_metadata_from_xml(tree) with open(ISOTROPIC_HARDENING_MULTILINEAR_VARIABLE, "r") as file: @@ -612,7 +612,7 @@ def test_write_constant_voce_isotropic_hardening(): ) ] - writer = MatmlWriter(materials) + writer = WriterMatml(materials) tree = writer._to_etree() material_string, metadata_string = get_material_and_metadata_from_xml(tree) with open(ISOTROPIC_HARDENING_VOCE, "r") as file: @@ -649,7 +649,7 @@ def test_read_variable_voce_isotropic_hardening(): ) ] - writer = MatmlWriter(materials) + writer = WriterMatml(materials) tree = writer._to_etree() material_string, metadata_string = get_material_and_metadata_from_xml(tree) with open(ISOTROPIC_HARDENING_VOCE_VARIABLE, "r") as file: diff --git a/tests/matml/test_larc_matml.py b/tests/matml/test_larc_matml.py index 45c54081..21cb0844 100644 --- a/tests/matml/test_larc_matml.py +++ b/tests/matml/test_larc_matml.py @@ -28,7 +28,7 @@ from ansys.materials.manager._models._common import IndependentParameter from ansys.materials.manager._models._material_models.larc03_04_constants import LaRc0304Constants from ansys.materials.manager._models.material import Material -from ansys.materials.manager.util.matml.matml_from_material import MatmlWriter +from ansys.materials.manager.util.matml.writer_matml import WriterMatml DIR_PATH = Path(__file__).resolve().parent XML_FILE_PATH = DIR_PATH.joinpath("..", "data", "matml_unittest_larc.xml") @@ -94,7 +94,7 @@ def test_write_constant_larc(): ) ] - writer = MatmlWriter(materials) + writer = WriterMatml(materials) tree = writer._to_etree() material_string, metadata_string = get_material_and_metadata_from_xml(tree) with open(LARC, "r") as file: @@ -125,7 +125,7 @@ def test_write_variable_larc(): ) ] - writer = MatmlWriter(materials) + writer = WriterMatml(materials) tree = writer._to_etree() material_string, metadata_string = get_material_and_metadata_from_xml(tree) with open(LARC_VARIABLE, "r") as file: diff --git a/tests/matml/test_puck_and_additional_puck_matml.py b/tests/matml/test_puck_and_additional_puck_matml.py index 2c88cf3b..9bb5b73e 100644 --- a/tests/matml/test_puck_and_additional_puck_matml.py +++ b/tests/matml/test_puck_and_additional_puck_matml.py @@ -35,7 +35,7 @@ StressLimitsOrthotropic, ) from ansys.materials.manager._models.material import Material -from ansys.materials.manager.util.matml.matml_from_material import MatmlWriter +from ansys.materials.manager.util.matml.writer_matml import WriterMatml DIR_PATH = Path(__file__).resolve().parent XML_FILE_PATH = DIR_PATH.joinpath("..", "data", "matml_unittest_puck_for_woven.xml") @@ -174,7 +174,7 @@ def test_write_fiber_angle(): ], ) ] - writer = MatmlWriter(materials) + writer = WriterMatml(materials) tree = writer._to_etree() material_string, metadata_string = get_material_and_metadata_from_xml(tree) with open(FIBER_ANGLE, "r") as file: @@ -208,7 +208,7 @@ def test_write_puck_constants(): ) ] - writer = MatmlWriter(materials) + writer = WriterMatml(materials) tree = writer._to_etree() material_string, metadata_string = get_material_and_metadata_from_xml(tree) with open(PUCK, "r") as file: @@ -241,7 +241,7 @@ def test_write_puck_additional_constants(): ) ] - writer = MatmlWriter(materials) + writer = WriterMatml(materials) tree = writer._to_etree() material_string, metadata_string = get_material_and_metadata_from_xml(tree) with open(PUCK_ADDITIONAL, "r") as file: @@ -272,7 +272,7 @@ def test_write_stress_limits(): ) ] - writer = MatmlWriter(materials) + writer = WriterMatml(materials) tree = writer._to_etree() material_string, metadata_string = get_material_and_metadata_from_xml(tree) with open(STRESS_LIMITS_ORTHOTROPIC, "r") as file: diff --git a/tests/matml/test_specific_heat_matml.py b/tests/matml/test_specific_heat_matml.py index 01cf6019..5cf069a2 100644 --- a/tests/matml/test_specific_heat_matml.py +++ b/tests/matml/test_specific_heat_matml.py @@ -28,7 +28,7 @@ from ansys.materials.manager._models._common import IndependentParameter, ModelQualifier from ansys.materials.manager._models._material_models.specific_heat import SpecificHeat from ansys.materials.manager._models.material import Material -from ansys.materials.manager.util.matml.matml_from_material import MatmlWriter +from ansys.materials.manager.util.matml.writer_matml import WriterMatml DIR_PATH = Path(__file__).resolve().parent XML_FILE_PATH = DIR_PATH.joinpath("..", "data", "matml_unittest_specific_heat.xml") @@ -167,7 +167,7 @@ def test_write_constant_specific_heat_volume(): ) ] - writer = MatmlWriter(materials) + writer = WriterMatml(materials) tree = writer._to_etree() material_string, metadata_string = get_material_and_metadata_from_xml(tree) with open(SPECIFIC_HEAT_VOLUME, "r", encoding="utf8") as file: @@ -204,7 +204,7 @@ def test_write_variable_specific_heat_volume(): ) ] - writer = MatmlWriter(materials) + writer = WriterMatml(materials) tree = writer._to_etree() material_string, metadata_string = get_material_and_metadata_from_xml(tree) with open(SPECIFIC_HEAT_VOLUME_VARIABLE, "r", encoding="utf8") as file: @@ -241,7 +241,7 @@ def test_write_constant_specific_heat_pressure(): ) ] - writer = MatmlWriter(materials) + writer = WriterMatml(materials) tree = writer._to_etree() material_string, metadata_string = get_material_and_metadata_from_xml(tree) with open(SPECIFIC_HEAT_PRESSURE, "r", encoding="utf8") as file: @@ -278,7 +278,7 @@ def test_write_variable_specific_heat_pressure(): ) ] - writer = MatmlWriter(materials) + writer = WriterMatml(materials) tree = writer._to_etree() material_string, metadata_string = get_material_and_metadata_from_xml(tree) with open(SPECIFIC_HEAT_PRESSURE_VARIABLE, "r", encoding="utf8") as file: diff --git a/tests/matml/test_speed_of_sound_matml.py b/tests/matml/test_speed_of_sound_matml.py index 7b05eb77..be06910e 100644 --- a/tests/matml/test_speed_of_sound_matml.py +++ b/tests/matml/test_speed_of_sound_matml.py @@ -28,7 +28,7 @@ from ansys.materials.manager._models._common import IndependentParameter from ansys.materials.manager._models._material_models.speed_of_sound import SpeedofSound from ansys.materials.manager._models.material import Material -from ansys.materials.manager.util.matml.matml_from_material import MatmlWriter +from ansys.materials.manager.util.matml.writer_matml import WriterMatml DIR_PATH = Path(__file__).resolve().parent XML_FILE_PATH = DIR_PATH.joinpath("..", "data", "matml_unittest_speed_of_sound.xml") @@ -96,7 +96,7 @@ def test_write_constant_speed_of_sound(): ) ] - writer = MatmlWriter(materials) + writer = WriterMatml(materials) tree = writer._to_etree() material_string, metadata_string = get_material_and_metadata_from_xml(tree) with open(SPEED_OF_SOUND, "r", encoding="utf8") as file: @@ -128,7 +128,7 @@ def test_write_variable_speed_of_sound(): ) ] - writer = MatmlWriter(materials) + writer = WriterMatml(materials) tree = writer._to_etree() material_string, metadata_string = get_material_and_metadata_from_xml(tree) with open(SPEED_OF_SOUND_VARIABLE, "r", encoding="utf8") as file: diff --git a/tests/matml/test_strain_limits_matml.py b/tests/matml/test_strain_limits_matml.py index 39cbd9be..35143df8 100644 --- a/tests/matml/test_strain_limits_matml.py +++ b/tests/matml/test_strain_limits_matml.py @@ -33,7 +33,7 @@ StrainLimitsOrthotropic, ) from ansys.materials.manager._models.material import Material -from ansys.materials.manager.util.matml.matml_from_material import MatmlWriter +from ansys.materials.manager.util.matml.writer_matml import WriterMatml DIR_PATH = Path(__file__).resolve().parent XML_FILE_PATH = DIR_PATH.joinpath("..", "data", "matml_unittest_strain_limit.xml") @@ -202,7 +202,7 @@ def test_write_constant_strain_limits_orthotropic(): ) ] - writer = MatmlWriter(materials) + writer = WriterMatml(materials) tree = writer._to_etree() material_string, metadata_string = get_material_and_metadata_from_xml(tree) with open(STRAIN_LIMITS_ORTHOTROPIC, "r", encoding="utf8") as file: @@ -230,7 +230,7 @@ def test_write_constant_strain_limits_isotropic(): ], ) ] - writer = MatmlWriter(materials) + writer = WriterMatml(materials) tree = writer._to_etree() material_string, metadata_string = get_material_and_metadata_from_xml(tree) with open(STRAIN_LIMITS_ISOTROPIC, "r", encoding="utf8") as file: @@ -257,7 +257,7 @@ def test_write_variable_strain_limits_isotropic(): ], ) ] - writer = MatmlWriter(materials) + writer = WriterMatml(materials) tree = writer._to_etree() material_string, metadata_string = get_material_and_metadata_from_xml(tree) with open(STRAIN_LIMITS_ISOTROPIC_VARIABLE, "r", encoding="utf8") as file: @@ -297,7 +297,7 @@ def test_write_variable_strain_limits_orthotropic(): ) ] - writer = MatmlWriter(materials) + writer = WriterMatml(materials) tree = writer._to_etree() material_string, metadata_string = get_material_and_metadata_from_xml(tree) with open(STRAIN_LIMITS_ORTHOTROPIC_VARIABLE, "r", encoding="utf8") as file: @@ -308,7 +308,7 @@ def test_write_variable_strain_limits_orthotropic(): assert data == metadata_string -# writer = MatmlWriter(materials) +# writer = WriterMatml(materials) # tree = writer._to_etree() # material_string, metadata_string = get_material_and_metadata_from_xml(tree) # path = r"D:\AnsysDev\pymaterials-manager\tests\data" diff --git a/tests/matml/test_thermal_conductivity_matml.py b/tests/matml/test_thermal_conductivity_matml.py index a58d77bb..0e914328 100644 --- a/tests/matml/test_thermal_conductivity_matml.py +++ b/tests/matml/test_thermal_conductivity_matml.py @@ -33,7 +33,7 @@ ThermalConductivityOrthotropic, ) from ansys.materials.manager._models.material import Material -from ansys.materials.manager.util.matml.matml_from_material import MatmlWriter +from ansys.materials.manager.util.matml.writer_matml import WriterMatml DIR_PATH = Path(__file__).resolve().parent XML_FILE_PATH = DIR_PATH.joinpath("..", "data", "matml_unittest_thermal_conductivity.xml") @@ -109,7 +109,7 @@ def test_write_thermal_conductivity_isotropic(): ) ] - writer = MatmlWriter(materials) + writer = WriterMatml(materials) tree = writer._to_etree() material_string, metadata_string = get_material_and_metadata_from_xml(tree) with open(THERMAL_CONDUCTIVITY_ISOTROPIC, "r") as file: @@ -140,7 +140,7 @@ def test_write_thermal_conductivity_orthotropic(): ) ] - writer = MatmlWriter(materials) + writer = WriterMatml(materials) tree = writer._to_etree() material_string, metadata_string = get_material_and_metadata_from_xml(tree) with open(THERMAL_CONDUCTIVITY_ORTHOTROPIC, "r") as file: diff --git a/tests/matml/test_thermal_expansion_coefficients_matml.py b/tests/matml/test_thermal_expansion_coefficients_matml.py index b5ed4e80..21eff8fd 100644 --- a/tests/matml/test_thermal_expansion_coefficients_matml.py +++ b/tests/matml/test_thermal_expansion_coefficients_matml.py @@ -39,7 +39,7 @@ ZeroThermalStrainReferenceTemperatureOrthotropic, ) from ansys.materials.manager._models.material import Material -from ansys.materials.manager.util.matml.matml_from_material import MatmlWriter +from ansys.materials.manager.util.matml.writer_matml import WriterMatml DIR_PATH = Path(__file__).resolve().parent INSTANTANEOUS_XML_FILE_PATH = DIR_PATH.joinpath( @@ -328,7 +328,7 @@ def test_write_constant_cte_isotropic(): ) ] - writer = MatmlWriter(materials) + writer = WriterMatml(materials) tree = writer._to_etree() material_string, metadata_string = get_material_and_metadata_from_xml(tree) with open(CTE_ISOTROPIC, "r") as file: @@ -370,7 +370,7 @@ def test_write_constant_cte_orthotropic(): ) ] - writer = MatmlWriter(materials) + writer = WriterMatml(materials) tree = writer._to_etree() material_string, metadata_string = get_material_and_metadata_from_xml(tree) with open(CTE_ORTHOTROPIC, "r") as file: @@ -410,7 +410,7 @@ def test_write_variable_cte_isotropic(): ) ] - writer = MatmlWriter(materials) + writer = WriterMatml(materials) tree = writer._to_etree() material_string, metadata_string = get_material_and_metadata_from_xml(tree) with open(CTE_ISOTROPIC_VARIABLE, "r") as file: @@ -458,7 +458,7 @@ def test_write_variable_cte_orthotropic(): ) ] - writer = MatmlWriter(materials) + writer = WriterMatml(materials) tree = writer._to_etree() material_string, metadata_string = get_material_and_metadata_from_xml(tree) with open(CTE_ORTHOTROPIC_VARIABLE, "r") as file: diff --git a/tests/matml/test_tsai_wu_matml.py b/tests/matml/test_tsai_wu_matml.py index f5052415..facc5a28 100644 --- a/tests/matml/test_tsai_wu_matml.py +++ b/tests/matml/test_tsai_wu_matml.py @@ -28,7 +28,7 @@ from ansys.materials.manager._models._common import IndependentParameter from ansys.materials.manager._models._material_models.tsai_wu_constants import TsaiWuConstants from ansys.materials.manager._models.material import Material -from ansys.materials.manager.util.matml.matml_from_material import MatmlWriter +from ansys.materials.manager.util.matml.writer_matml import WriterMatml DIR_PATH = Path(__file__).resolve().parent XML_FILE_PATH = DIR_PATH.joinpath("..", "data", "matml_unittest_tsai_wu.xml") @@ -89,7 +89,7 @@ def test_write_constant_tsai_wu(): ) ] - writer = MatmlWriter(materials) + writer = WriterMatml(materials) tree = writer._to_etree() material_string, metadata_string = get_material_and_metadata_from_xml(tree) with open(TSAI_WU, "r") as file: @@ -120,7 +120,7 @@ def test_write_variable_tsai_wu(): ) ] - writer = MatmlWriter(materials) + writer = WriterMatml(materials) tree = writer._to_etree() material_string, metadata_string = get_material_and_metadata_from_xml(tree) with open(TSAI_WU_VARIABLE, "r") as file: diff --git a/tests/matml/test_user_mat_matml.py b/tests/matml/test_user_mat_matml.py index 0355415c..3df2781f 100644 --- a/tests/matml/test_user_mat_matml.py +++ b/tests/matml/test_user_mat_matml.py @@ -28,7 +28,7 @@ from ansys.materials.manager._models._common import IndependentParameter, UserParameter from ansys.materials.manager._models._material_models.usermat import ModelCoefficients from ansys.materials.manager._models.material import Material -from ansys.materials.manager.util.matml.matml_from_material import MatmlWriter +from ansys.materials.manager.util.matml.writer_matml import WriterMatml DIR_PATH = Path(__file__).resolve().parent XML_FILE_PATH = DIR_PATH.joinpath("..", "data", "matml_unittest_usermat.xml") @@ -103,7 +103,7 @@ def test_write_constant_usermat(): ) ] - writer = MatmlWriter(materials) + writer = WriterMatml(materials) tree = writer._to_etree() material_string, metadata_string = get_material_and_metadata_from_xml(tree) with open(USER_MAT, "r", encoding="utf8") as file: @@ -143,7 +143,7 @@ def test_write_variable_usermat(): ) ] - writer = MatmlWriter(materials) + writer = WriterMatml(materials) tree = writer._to_etree() material_string, metadata_string = get_material_and_metadata_from_xml(tree) with open(USER_MAT_VARIABLE, "r") as file: diff --git a/tests/matml/test_viscosity_matml.py b/tests/matml/test_viscosity_matml.py index 3793569f..5d67d8b9 100644 --- a/tests/matml/test_viscosity_matml.py +++ b/tests/matml/test_viscosity_matml.py @@ -28,7 +28,7 @@ from ansys.materials.manager._models._common import IndependentParameter from ansys.materials.manager._models._material_models.viscosity import Viscosity from ansys.materials.manager._models.material import Material -from ansys.materials.manager.util.matml.matml_from_material import MatmlWriter +from ansys.materials.manager.util.matml.writer_matml import WriterMatml DIR_PATH = Path(__file__).resolve().parent XML_FILE_PATH = DIR_PATH.joinpath("..", "data", "matml_unittest_viscosity.xml") @@ -93,7 +93,7 @@ def test_write_constant_viscosity(): ) ] - writer = MatmlWriter(materials) + writer = WriterMatml(materials) tree = writer._to_etree() material_string, metadata_string = get_material_and_metadata_from_xml(tree) with open(VISCOSITY, "r") as file: @@ -122,7 +122,7 @@ def test_write_variable_viscosity(): ) ] - writer = MatmlWriter(materials) + writer = WriterMatml(materials) tree = writer._to_etree() material_string, metadata_string = get_material_and_metadata_from_xml(tree) with open(VISCOSITY_VARIABLE, "r") as file: