ansys / pyfluent

Pythonic interface to Ansys Fluent
https://fluent.docs.pyansys.com
MIT License
274 stars 40 forks source link

Difference in Dict returned from v222 and v231 makes trouble! #1920

Closed RebelYoung closed 1 year ago

RebelYoung commented 1 year ago

🔍 Before submitting the issue

🐞 Description of the bug

The dict or structure returned from solver.boundary_conditions command differs between v222 and v231. example:

ss.bc.mass_flow_outlet['inlet']()
# product_version='22.2.0'
{'frame_of_reference': 'Relative to Adjacent Cell Zone',
 'flow_spec': 'Mass Flow Rate',
 'mass_flow': {'option': 'constant', 'constant': 7},
 't0': {'option': 'constant', 'constant': 300},
 'gauge_pressure': {'option': 'constant', 'constant': 0},
 'ke_spec': 'Intermittency, Intensity and Viscosity Ratio',
 'intermit': {'option': 'constant', 'constant': 1},
 'turb_intensity': 0.05,
 'turb_viscosity_ratio': 10}

# product_version='23.1.0'
{'frame_of_reference': 'Relative to Adjacent Cell Zone',
 'flow_spec': 'Mass Flow Rate',
 'mass_flow': {'option': 'value', 'value': 7},
 't0': {'option': 'value', 'value': 300},
 'gauge_pressure': {'option': 'value', 'value': 0},
 'ke_spec': 'Intermittency, Intensity and Viscosity Ratio',
 'intermit': {'option': 'value', 'value': 1},
 'turb_intensity': 0.05,
 'turb_viscosity_ratio': 10}

It makes my class function invalid like:

    def set_mass_flow_outlet(self,
            flux,
            bc_name:str,
            t_total=300,
            p_static=0,
            ):
        self.bc.mass_flow_outlet[bc_name].mass_flow.constant=flux
        self.bc.mass_flow_outlet[bc_name].t0.constant=t_total
        self.bc.mass_flow_outlet[bc_name].supersonic_or_initial_gauge_pressure.constant=p_static
        self.bc.mass_flow_outlet[bc_name]()

I must change all code .constant into .value, Or program many duplicated code for two version just for this command. I hope keeping the structure between different product_version.

Another one,

        # in v23r1,the type returnd from compute function is a list[dict[str:list[float]]]
        # in v222, dict[str:list[float]]
        # 231: [{'drag_coef': [-0.02313975528399801, 0]}] 222:{'drag_coef': [-0.02313975528399801, 0]} 
        if self.product_version == '22.2.0':
            D_coef = self.solver.solution.report_definitions.compute(
                report_defs=["drag_coef"])['drag_coef'][0]
        elif self.product_version == '23.1.0':
            D_coef = self.solver.solution.report_definitions.compute(
                report_defs=["drag_coef"])[0]['drag_coef'][0]

📝 Steps to reproduce

as below

💻 Which operating system are you using?

Windows

📀 Which ANSYS version are you using?

2022r2 and 2023r1

🐍 Which Python version are you using?

3.8

📦 Installed packages

aiofiles==22.1.0
aiohttp==3.8.4
aiosignal==1.3.1
aiosqlite==0.18.0
ansys-api-fluent==0.3.11
ansys-api-platform-instancemanagement==1.0.0b3
ansys-fluent-core==0.13.0
ansys-fluent-visualization==0.7.1
ansys-platform-instancemanagement==1.0.3
anyio==3.6.2
appdirs==1.4.4
argon2-cffi==21.3.0
argon2-cffi-bindings==21.2.0
arrow==1.2.3
asttokens @ file:///home/conda/feedstock_root/build_artifacts/asttokens_1670263926556/work
async-timeout==4.0.2
attrs==22.2.0
Babel==2.12.1
backcall @ file:///home/conda/feedstock_root/build_artifacts/backcall_1592338393461/work
backports.functools-lru-cache @ file:///home/conda/feedstock_root/build_artifacts/backports.functools_lru_cache_1618230623929/work
beautifulsoup4==4.11.2
bleach==6.0.0
certifi==2022.12.7
cffi==1.15.1
charset-normalizer==3.0.1
colorama @ file:///home/conda/feedstock_root/build_artifacts/colorama_1666700638685/work
comm==0.1.3
contourpy==1.0.7
cycler==0.11.0
debugpy==1.6.7
decorator @ file:///home/conda/feedstock_root/build_artifacts/decorator_1641555617451/work
seanpearsonuk commented 1 year ago

@RebelYoung Apologies, but the library is still beta (v0) and the solver settings API is brand new and the least stable aspect. Unfortunately during this period there are inevitably some disruptions. We will soon be moving into a phase where user code is better protected by a built-in compatibility mechanism.

RebelYoung commented 1 year ago

@RebelYoung Apologies, but the library is still beta (v0) and the solver settings API is brand new and the least stable aspect. Unfortunately during this period there are inevitably some disruptions. We will soon be moving into a phase where user code is better protected by a built-in compatibility mechanism.

Ok, I have found the values in the new data type:

            """
            # before v0.13.0
            t = field_data.get_scalar_field_data(
                surface_name=AN, field_name=f)[id]
            """
            # for v0.17.0
            t0 = field_data.get_scalar_field_data(
                surface_name=AN, field_name=f)
            t = np.zeros(t0.size)
            for i in range(t0.size):
                t[i] = t0.data[i].scalar_data

it means, a dict as {id:np.array} is detect from {id:list[scalardata]}.