Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Convert protobuf Point to python Vector. #3239

Merged
merged 6 commits into from
Sep 2, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
28 changes: 28 additions & 0 deletions src/ansys/fluent/core/services/datamodel_se.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

from ansys.api.fluent.v0 import datamodel_se_pb2 as DataModelProtoModule
from ansys.api.fluent.v0 import datamodel_se_pb2_grpc as DataModelGrpcModule
from ansys.api.fluent.v0.common_api_pb2 import Point
from ansys.api.fluent.v0.variant_pb2 import Variant
import ansys.fluent.core as pyfluent
from ansys.fluent.core.data_model_cache import DataModelCache, NameKey
Expand Down Expand Up @@ -329,6 +330,33 @@ def _convert_variant_to_value(var: Variant) -> _TValue:
return val


class Vector:
"""Wrap Fluent's Point type into a Python class."""

def __init__(self, point: Point):
"""__init__ of Vector class."""
self._val = point

@property
def x(self) -> float:
"""Returns vector point x."""
return self._val.x

@property
def y(self) -> float:
"""Returns vector point y."""
return self._val.y

@property
def z(self) -> float:
"""Returns vector point z."""
return self._val.z

def __call__(self):
"""Returns vector as [x, y, z]."""
return [self.x, self.y, self.z]


class EventSubscription:
"""EventSubscription class for any datamodel event."""

Expand Down
12 changes: 6 additions & 6 deletions src/ansys/fluent/core/services/reduction.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from ansys.api.fluent.v0 import reduction_pb2 as ReductionProtoModule
from ansys.api.fluent.v0 import reduction_pb2_grpc as ReductionGrpcModule
from ansys.fluent.core.services.datamodel_se import _convert_variant_to_value
from ansys.fluent.core.services.datamodel_se import Vector, _convert_variant_to_value
from ansys.fluent.core.services.interceptors import (
BatchInterceptor,
ErrorStateInterceptor,
Expand Down Expand Up @@ -300,7 +300,7 @@ def centroid(self, locations, ctxt=None) -> Any:
request = ReductionProtoModule.CentroidRequest()
request.locations.extend(self._get_location_string(locations, ctxt))
response = self.service.centroid(request)
return response.value
return Vector(response.value)
prmukherj marked this conversation as resolved.
Show resolved Hide resolved

def count(self, locations, ctxt=None) -> Any:
"""Get count."""
Expand All @@ -322,7 +322,7 @@ def force(self, locations, ctxt=None) -> Any:
request = ReductionProtoModule.ForceRequest()
request.locations.extend(self._get_location_string(locations, ctxt))
response = self.service.force(request)
return response.value
return Vector(response.value)

def mass_average(self, expression, locations, ctxt=None) -> Any:
"""Get mass average."""
Expand Down Expand Up @@ -385,14 +385,14 @@ def pressure_force(self, locations, ctxt=None) -> Any:
request = ReductionProtoModule.PressureForceRequest()
request.locations.extend(self._get_location_string(locations, ctxt))
response = self.service.pressure_force(request)
return response.value
return Vector(response.value)

def viscous_force(self, locations, ctxt=None) -> Any:
"""Get viscous force."""
request = ReductionProtoModule.ViscousForceRequest()
request.locations.extend(self._get_location_string(locations, ctxt))
response = self.service.viscous_force(request)
return response.value
return Vector(response.value)

def volume(self, locations, ctxt=None) -> Any:
"""Get volume."""
Expand Down Expand Up @@ -423,7 +423,7 @@ def moment(self, expression, locations, ctxt=None) -> Any:
request.expression = expression
request.locations.extend(self._get_location_string(locations, ctxt))
response = self.service.moment(request)
return response.value
return Vector(response.value)

def sum(self, expression, locations, weight, ctxt=None) -> Any:
"""Get sum."""
Expand Down
Loading