Skip to content

Commit

Permalink
CFX pressure data mapping to structural 11 blade model in PyMAPDL. (#…
Browse files Browse the repository at this point in the history
…1931)

* CFX pressure data mapping to structural 11 blade model in PyMAPDL.

* Adding function to download extra files

* Reformating

* reformatting again

* Small fixes

* Adding unit tests.

* Fixing inventory

* Skipping coverage for now. A follow up PR will come.

* fixing function name

---------

Co-authored-by: German <28149841+germa89@users.noreply.github.com>
Co-authored-by: German <germanmartinezayuso@gmail.com>
  • Loading branch information
3 people authored Mar 23, 2023
1 parent 4b7ceb2 commit 592a8d3
Show file tree
Hide file tree
Showing 4 changed files with 160 additions and 2 deletions.
123 changes: 123 additions & 0 deletions examples/00-mapdl-examples/slashmap_cfx_mapping.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
"""
.. _ref_cfx_mapping:
=============================================
CFX pressure data mapping to structural blade
=============================================
The objective of this test is to demonstrate CFX pressure data mapping to
structural 11 blade model in PyMAPDL.
Description
===========
The 11 blade model along with a fictitious disk is modeled. CFX generated
pressure data is used as input.
The test uses a CFX exported pressure data to map. Pressure file
correspond to a certain vibrating blade mode (vibrating mode 1
approximately 534 Hz)and to a certain pressure mode (pressure mode 1
also the same 534 Hz mode). However, due to lack of data for another
mode this same file will be assumed to represent other mode
combinations (vib mode 2 press mode 2) (vib mode 1 press mode 2)
(vib mode 2 press mode 1).
"""

from datetime import datetime

from ansys.mapdl.core import launch_mapdl
from ansys.mapdl.core.examples import download_cfx_mapping_example_data

###############################################################################
# Downloading files
# =================
#
files_path = download_cfx_mapping_example_data()

db_file_path = files_path["model"]
pressure_file_path = files_path["data"]

###############################################################################
# Launch MAPDL service
# ====================
#

mapdl = launch_mapdl()

mapdl.title(
"Verify Pressure Data Mapping exported from CFX on Structural 11 Blade Model"
)

###############################################################################
# Upload files to the instance
# ============================
#
# Uploading files
mapdl.upload(db_file_path)
mapdl.upload(pressure_file_path)


###############################################################################
# Pressure mapping
# ================
#
# Resume the database from the example mapping file
mapdl.resume("ExampleMapping", "db")
mapdl.esel("s", "type", "", 1)
mapdl.cm("BladeElem", "elem")

# Write CDB file
mapdl.allsel()
mapdl.cdwrite("all", "baseModel", "cdb")
mapdl.finish()

# Start the mapping processor and record the start time
start_time = datetime.now()
mapdl.slashmap() # mapdl.slashmap(**kwargs); Enters the mapping processor.
print("Enter the Mapping Processor")

# Specifies the target nodes for mapping pressures onto surface effect elements.
mapdl.run("target,pressure_faces")

# Specifies the file type and pressure type for the subsequent import of source points and pressures.
mapdl.ftype(filetype="cfxtbr", prestype="1")
# Read the CFX exported file containing pressure data Blade 2, Export Surface 1
mapdl.read(fname="11_blades_mode_1_ND_0.csv")

# Perform the pressure mapping from source points to target surface elements.
# Interpolation is done on a surface (default).
print(mapdl.map(kdim="2", kout="1"))

###############################################################################
# Plot mapping
# ============
#
# Plot the geometries and mappings
mapdl.show("png,rev")
mapdl.plgeom(item="BOTH") # Plot both target and source geometries (default).
mapdl.plmap(item="target")
mapdl.plmap(item="target", imagkey="1")
mapdl.plmap(item="source")
mapdl.plmap(item="source", imagkey="1")
mapdl.plmap(item="both")
mapdl.plmap(item="both", imagkey="1")

# Close the plot and write the mapped data to a file
mapdl.show("close")
mapdl.writemap("mappedHI.dat")

# Print the mapping completion message and duration
print("Mapping Completed")
end_time = datetime.now()
c = end_time - start_time
seconds = c.total_seconds()
print("\nDuration in seconds for Mapping is : ", seconds)

mapdl.eplot()

###############################################################################
# Stop MAPDL
#
mapdl.finish()
mapdl.exit()
2 changes: 1 addition & 1 deletion src/ansys/mapdl/core/examples/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from .downloads import *
from .downloads import _download_rotor_tech_demo_plot
from .downloads import _download_rotor_tech_demo_plot, download_cfx_mapping_example_data
from .examples import *
from .verif_files import vmfiles
27 changes: 27 additions & 0 deletions src/ansys/mapdl/core/examples/downloads.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,3 +131,30 @@ def download_manifold_example_data() -> dict:
filename="manifold_cht-final_temp.csv", directory=files_dir
)[0],
}


def download_cfx_mapping_example_data() -> dict: # pragma: no cover
"""Download the CFX mapping data and return the
download paths into a dictionary domain id->path.
Examples files are downloaded to a persistent cache to avoid
re-downloading the same file twice.
Returns
-------
dict[str:str]
Path to the example files.
Examples
--------
>>> from ansys.mapdl.core.examples import download_cfx_mapping_example_data
>>> paths = download_cfx_mapping_example_data()
>>> paths
{data: 'C:\\Users\\user\\AppData\\Local\\ansys_mapdl_core\\ansys_mapdl_core\\examples\\11_blades_mode_1_ND_0.csv',
model: 'C:\\Users\\user\\AppData\\Local\\ansys_mapdl_core\\ansys_mapdl_core\\examples\\ExampleMapping.db'}
"""

files_dir = "pymapdl/cfx_mapping"
return {
"data": _download_file(
filename="11_blades_mode_1_ND_0.csv", directory=files_dir
)[0],
"model": _download_file(filename="ExampleMapping.db", directory=files_dir)[0],
}
10 changes: 9 additions & 1 deletion tests/test_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@
import pytest

from ansys.mapdl.core import examples
from ansys.mapdl.core.examples.downloads import _download_file, download_example_data
from ansys.mapdl.core.examples.downloads import (
_download_file,
download_cfx_mapping_example_data,
download_example_data,
)


def test_load_verif():
Expand Down Expand Up @@ -33,3 +37,7 @@ def test_failed_download():
filename = "non_existing_file"
with pytest.raises(RuntimeError):
_download_file(filename, directory=None)


def test_download_cfx_mapping_example_data():
assert download_cfx_mapping_example_data() is not None

0 comments on commit 592a8d3

Please sign in to comment.