Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions ansys/fluent/core/services/datamodel_se.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
from ansys.api.fluent.v0 import datamodel_se_pb2_grpc as DataModelGrpcModule
from ansys.fluent.core.services.error_handler import catch_grpc_error
from ansys.fluent.core.services.interceptors import TracingInterceptor
from ansys.fluent.core.utils.async_execution import asynchronous

Path = List[Tuple[str, str]]

Expand Down Expand Up @@ -550,7 +549,6 @@ def __init__(
else:
self.path = path

@asynchronous
def __call__(self, *args, **kwds) -> Any:
"""Executes the command.

Expand Down
2 changes: 0 additions & 2 deletions ansys/fluent/core/services/datamodel_tui.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from ansys.api.fluent.v0 import datamodel_tui_pb2_grpc as DataModelGrpcModule
from ansys.fluent.core.services.error_handler import catch_grpc_error
from ansys.fluent.core.services.interceptors import TracingInterceptor
from ansys.fluent.core.utils.async_execution import asynchronous

Path = List[Tuple[str, str]]

Expand Down Expand Up @@ -220,7 +219,6 @@ def set_state(self, value: Any) -> None:
_convert_value_to_gvalue(value, request.state)
self._service.set_state(request)

@asynchronous
def _execute_command(
self, request: DataModelProtoModule.ExecuteCommandRequest
) -> Any:
Expand Down
23 changes: 22 additions & 1 deletion ansys/fluent/core/utils/async_execution.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,28 @@


def asynchronous(f):
"""Use for decorating functions to execute asynchronously."""
"""Use for decorating functions to execute asynchronously. The decorated
function returns a `future`_ object. Calling `result()`_ on the future
object synchronizes the function execution.
Examples
--------
>>> # asynchronous execution using @asynchronous decorator
>>> @asynchronous
... def asynchronous_solve(session, number_of_iterations):
... session.tui.solver.solve.iterate(number_of_iterations)
>>> asynchronous_solve(session1, 100)
>>> # using the asynchronous function directly
>>> asynchronous(session2.tui.solver.solve.iterate)(100)
>>> # synchronous execution of above 2 calls
>>> asynchronous_solve(session1, 100).result()
>>> asynchronous(session2.tui.solver.solve.iterate)(100).result()
.. _Future: https://docs.python.org/3/library/asyncio-future.html#future-object # noqa: E501
.. _result(): https://docs.python.org/3/library/asyncio-future.html#asyncio.Future.result # noqa: E501
"""

@functools.wraps(f)
def func(*args, **kwargs):
Expand Down
18 changes: 9 additions & 9 deletions examples/00-fluent/mixing_elbow_settings_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -397,17 +397,17 @@
"3",
"quit",
)
s.tui.solver.solve.convergence_conditions("frequency", "3", "quit").result()
s.tui.solver.solve.convergence_conditions("frequency", "3", "quit")

###############################################################################

# Initialize the flow field using the Hybrid Initialization
s.tui.solver.solve.initialize.hyb_initialization().result()
s.tui.solver.solve.initialize.hyb_initialization()

###############################################################################

# Solve for 150 Iterations.
s.tui.solver.solve.iterate(150).result()
s.tui.solver.solve.iterate(150)

###############################################################################

Expand Down Expand Up @@ -479,7 +479,7 @@
# surface outlet. Name: z=0_outlet
s.tui.solver.surface.iso_surface(
"z-coordinate", "z=0_outlet", "outlet", "()", "()", "0", "()"
).result()
)

# Create Contour on the iso-surface
root.results.graphics.contour["contour-z_0_outlet"] = {}
Expand All @@ -491,7 +491,7 @@
# root.results.graphics.contour["contour-z_0_outlet"].display()

###############################################################################
# s.tui.solver.file.write_case_data("mixing_elbow1_set.cas.h5").result()
# s.tui.solver.file.write_case_data("mixing_elbow1_set.cas.h5")

# Display and save an XY plot of the temperature profile across the centerline
# of the outlet for the initial solution
Expand All @@ -505,8 +505,8 @@
"z=0_outlet",
"()",
"quit",
).result()
# s.tui.solver.display.objects.display("xy-outlet-temp").result()
)
# s.tui.solver.display.objects.display("xy-outlet-temp")
# s.tui.solver.plot.plot(
# "yes",
# "temp-1.xy",
Expand All @@ -520,11 +520,11 @@
# "0",
# "z=0_outlet",
# "()",
# ).result()
# )

###############################################################################

# Write final case and data.
# s.tui.solver.file.write_case_data('mixing_elbow2_set.cas.h5').result()
# s.tui.solver.file.write_case_data('mixing_elbow2_set.cas.h5')

###############################################################################
76 changes: 38 additions & 38 deletions examples/00-fluent/mixing_elbow_tui_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@
###############################################################################

# Check the mesh in Meshing mode
s.tui.meshing.mesh.check_mesh().result()
s.tui.meshing.mesh.check_mesh()

###############################################################################

Expand All @@ -177,7 +177,7 @@
# mode, you can now switch to solver mode to complete the setup of the
# simulation. We have just checked the mesh, so select Yes to switch to
# solution mode.
s.tui.meshing.switch_to_solution_mode("yes").result()
s.tui.meshing.switch_to_solution_mode("yes")

###############################################################################

Expand All @@ -187,7 +187,7 @@
# mesh features that are checked. Any errors in the mesh will be reported at
# this time. Ensure that the minimum volume is not negative, since Ansys Fluent
# cannot begin a calculation when this is the case.
s.tui.solver.mesh.check().result()
s.tui.solver.mesh.check()

###############################################################################

Expand All @@ -197,17 +197,17 @@
# to change any other units in this problem. If you want a different working
# unit for length, other than inches (for example, millimeters), make the
# appropriate change.
s.tui.solver.define.units("length", "in").result()
s.tui.solver.define.units("length", "in")

###############################################################################

# Enable heat transfer by activating the energy equation.
s.tui.solver.define.models.energy("yes", ", ", ", ", ", ", ", ").result()
s.tui.solver.define.models.energy("yes", ", ", ", ", ", ", ", ")

###############################################################################

# Create a new material called water-liquid.
s.tui.solver.define.materials.copy("fluid", "water-liquid").result()
s.tui.solver.define.materials.copy("fluid", "water-liquid")

###############################################################################

Expand Down Expand Up @@ -237,7 +237,7 @@
"no",
"no",
"no",
).result()
)

###############################################################################

Expand All @@ -249,19 +249,19 @@

s.tui.solver.define.boundary_conditions.set.velocity_inlet(
"cold-inlet", [], "vmag", "no", 0.4, "quit"
).result()
)
s.tui.solver.define.boundary_conditions.set.velocity_inlet(
"cold-inlet", [], "ke-spec", "no", "no", "no", "yes", "quit"
).result()
)
s.tui.solver.define.boundary_conditions.set.velocity_inlet(
"cold-inlet", [], "turb-intensity", 5, "quit"
).result()
)
s.tui.solver.define.boundary_conditions.set.velocity_inlet(
"cold-inlet", [], "turb-hydraulic-diam", 4, "quit"
).result()
)
s.tui.solver.define.boundary_conditions.set.velocity_inlet(
"cold-inlet", [], "temperature", "no", 293.15, "quit"
).result()
)

###############################################################################

Expand All @@ -271,19 +271,19 @@

s.tui.solver.define.boundary_conditions.set.velocity_inlet(
"hot-inlet", [], "vmag", "no", 1.2, "quit"
).result()
)
s.tui.solver.define.boundary_conditions.set.velocity_inlet(
"hot-inlet", [], "ke-spec", "no", "no", "no", "yes", "quit"
).result()
)
s.tui.solver.define.boundary_conditions.set.velocity_inlet(
"hot-inlet", [], "turb-intensity", 5, "quit"
).result()
)
s.tui.solver.define.boundary_conditions.set.velocity_inlet(
"hot-inlet", [], "turb-hydraulic-diam", 1, "quit"
).result()
)
s.tui.solver.define.boundary_conditions.set.velocity_inlet(
"hot-inlet", [], "temperature", "no", 313.15, "quit"
).result()
)

###############################################################################

Expand All @@ -293,10 +293,10 @@

s.tui.solver.define.boundary_conditions.set.pressure_outlet(
"outlet", [], "turb-intensity", 5, "quit"
).result()
)
s.tui.solver.define.boundary_conditions.set.pressure_outlet(
"outlet", [], "turb-viscosity-ratio", 4, "quit"
).result()
)

###############################################################################

Expand All @@ -316,7 +316,7 @@
"outlet",
"()",
"quit",
).result()
)

###############################################################################

Expand All @@ -342,7 +342,7 @@
# "run-index",
# "0",
# "quit",
# ).result()
# )

###############################################################################

Expand Down Expand Up @@ -381,23 +381,23 @@
"frequency",
"3",
"quit",
).result()
s.tui.solver.solve.convergence_conditions("frequency", "3", "quit").result()
)
s.tui.solver.solve.convergence_conditions("frequency", "3", "quit")

###############################################################################

# Initialize the flow field using the Hybrid Initialization
s.tui.solver.solve.initialize.hyb_initialization().result()
s.tui.solver.solve.initialize.hyb_initialization()

###############################################################################

# Save the case file (mixing_elbow1.cas.h5).
# s.tui.solver.file.write_case('mixing_elbow1.cas.h5').result()
# s.tui.solver.file.write_case('mixing_elbow1.cas.h5')

###############################################################################

# Solve for 150 Iterations.
s.tui.solver.solve.iterate(150).result()
s.tui.solver.solve.iterate(150)

###############################################################################

Expand All @@ -410,7 +410,7 @@
###############################################################################

# Save the data file (mixing_elbow1.dat.h5).
# s.tui.solver.file.write_data('mixing_elbow1.dat.h5').result()
# s.tui.solver.file.write_data('mixing_elbow1.dat.h5')

###############################################################################

Expand All @@ -435,8 +435,8 @@
"coloring",
"banded",
"quit",
).result()
# s.tui.solver.display.objects.display("contour-vel").result()
)
# s.tui.solver.display.objects.display("contour-vel")

###############################################################################

Expand All @@ -461,7 +461,7 @@
"smooth",
"quit",
)
# s.tui.solver.display.objects.display("contour-temp").result()
# s.tui.solver.display.objects.display("contour-temp")

###############################################################################

Expand All @@ -485,19 +485,19 @@
"skip",
"2",
"quit",
).result()
# s.tui.solver.display.objects.display("vector-vel").result()
)
# s.tui.solver.display.objects.display("vector-vel")

###############################################################################

# Create an iso-surface representing the intersection of the plane z=0 and the
# surface outlet. Name: z=0_outlet
s.tui.solver.surface.iso_surface(
"z-coordinate", "z=0_outlet", "outlet", "()", "()", "0", "()"
).result()
)

###############################################################################
# s.tui.solver.file.write_case_data("mixing_elbow1_tui.cas.h5").result()
# s.tui.solver.file.write_case_data("mixing_elbow1_tui.cas.h5")

# Display and save an XY plot of the temperature profile across the centerline
# of the outlet for the initial solution
Expand All @@ -510,8 +510,8 @@
"z=0_outlet",
"()",
"quit",
).result()
# s.tui.solver.display.objects.display("xy-outlet-temp").result()
)
# s.tui.solver.display.objects.display("xy-outlet-temp")
# s.tui.solver.plot.plot(
# "yes",
# "temp-1.xy",
Expand All @@ -525,11 +525,11 @@
# "0",
# "z=0_outlet",
# "()",
# ).result()
# )

###############################################################################

# Write final case and data.
# s.tui.solver.file.write_case_data("mixing_elbow2_tui.cas.h5").result()
# s.tui.solver.file.write_case_data("mixing_elbow2_tui.cas.h5")

###############################################################################