4
4
5
5
from ansys import dpf
6
6
from ansys .grpc .dpf import field_pb2 , field_pb2_grpc , base_pb2 , field_definition_pb2 , field_definition_pb2_grpc
7
- from ansys .dpf .core .common import natures , types , locations
8
- from ansys .dpf .core import operators , plotting , scoping , meshed_region , time_freq_support
9
-
7
+ from ansys .dpf .core .common import natures , types , locations , ShellLayers
8
+ from ansys .dpf .core import operators_helper , scoping , meshed_region , time_freq_support
9
+ from ansys . dpf . core . plotter import Plotter
10
10
11
11
class Field :
12
12
"""Class representing evaluated data from a ``ansys.dpf.core.Operator``.
@@ -74,9 +74,10 @@ def __init__(self, nentities=0,
74
74
raise TypeError (f'Cannot create a field from a "{ type (field )} " object' )
75
75
76
76
self ._field_definition = self ._load_field_definition ()
77
-
77
+
78
78
# add dynamic methods
79
79
self ._update_dynamic_methods ()
80
+
80
81
81
82
@property
82
83
def size (self ):
@@ -98,38 +99,12 @@ def elementary_data_shape(self):
98
99
return (1 , self .component_count )
99
100
else :
100
101
return self .component_count
101
-
102
+
102
103
def _update_dynamic_methods (self ):
103
104
"""Add or remove dynamic methods to this instance based on the
104
105
field type"""
105
106
if self .location in [locations .elemental_nodal , locations .elemental ]:
106
107
self .to_nodal = self .__to_nodal
107
-
108
- # specify plot method based on field type
109
- if self .location == locations .elemental :
110
- self .plot = self .__plot_elemental
111
- elif self .location in [locations .nodal , locations .elemental_nodal ]:
112
- self .plot = self .__plot_nodal
113
- self .plot = self .__plot_lines
114
-
115
-
116
- @wraps (plotting .plot_lines )
117
- def __plot_lines (self , * args , ** kwargs ):
118
- """Wraps plotting.plot_lines"""
119
- return plotting .plot_lines (self , * args , ** kwargs )
120
-
121
- @wraps (plotting .plot_nodal )
122
- def __plot_nodal (self , comp = None , ** kwargs ):
123
- """wraps plotting.plot_nodal"""
124
- return plotting .plot_nodal (self , comp , ** kwargs )
125
-
126
- @wraps (plotting .plot_elemental )
127
- def __plot_elemental (self , comp = None , ** kwargs ):
128
- """wraps plotting.plot_elemental
129
-
130
- Should be only available when type == locations.elemental
131
- """
132
- return plotting .plot_elemental (self , comp , ** kwargs )
133
108
134
109
@property
135
110
def location (self ):
@@ -142,12 +117,46 @@ def location(self):
142
117
if self ._field_definition :
143
118
return self ._field_definition .location
144
119
120
+ @property
121
+ def shell_layers (self ):
122
+ """Return the field shell layers.
123
+
124
+ Returns
125
+ -------
126
+ Enum
127
+ dpf.core.common.ShellLayers enum value
128
+ """
129
+ if self ._field_definition :
130
+ return self ._field_definition .shell_layers
131
+
145
132
def __to_nodal (self ):
146
133
"""create a to_nodal operator and evaluates it"""
147
134
op = dpf .core .Operator ("to_nodal" )
148
135
op .inputs .connect (self )
149
136
return op .outputs .field ()
150
137
138
+ def plot (self , notebook = None , shell_layers = None ):
139
+ """Plot the field/fields container on mesh support if exists.
140
+
141
+ Warning
142
+ -------
143
+ Regarding the interactions with the GRPc server, this can be slower than:
144
+ >>> mesh = model.metadata.meshed_region
145
+ >>> mesh.plot(field)
146
+ Better use the previous lines.
147
+
148
+ Parameters
149
+ ----------
150
+ notebook (default: True)
151
+ bool, that specifies if the plotting is in the notebook (2D) or not (3D)
152
+
153
+ shell_layers : core.ShellLayers, optional
154
+ Enum used to set the shell layers if the model to plot
155
+ contains shell elements.
156
+ """
157
+ pl = Plotter (self .meshed_region )
158
+ pl .plot_contour (self , notebook , shell_layers )
159
+
151
160
def resize (self , nentities , datasize ):
152
161
"""allocate memory
153
162
@@ -392,12 +401,12 @@ def component_count(self):
392
401
393
402
def __add__ (self , field_b ):
394
403
"""Adds two fields together"""
395
- return dpf .core .operators .add (self , field_b )
404
+ return dpf .core .operators_helper .add (self , field_b )
396
405
397
406
def __pow__ (self , value ):
398
407
if value != 2 :
399
408
raise ValueError ('DPF only the value is "2" suppported' )
400
- return dpf .core .operators .sqr (self )
409
+ return dpf .core .operators_helper .sqr (self )
401
410
402
411
def _del_data (self ):
403
412
pass
@@ -442,9 +451,9 @@ def __len__(self):
442
451
return self .size
443
452
444
453
445
- @wraps (operators .min_max )
454
+ @wraps (operators_helper .min_max )
446
455
def _min_max (self ):
447
- return operators .min_max (self )
456
+ return operators_helper .min_max (self )
448
457
449
458
def min (self ):
450
459
"""Component-wise minimum over this field
@@ -487,6 +496,11 @@ def location(self):
487
496
@property
488
497
def unit (self ):
489
498
return self ._stub .List (self ._messageDefinition ).unit .symbol
499
+
500
+ @property
501
+ def shell_layers (self ):
502
+ enum_val = self ._stub .List (self ._messageDefinition ).shell_layers
503
+ return ShellLayers (enum_val )
490
504
491
505
def __del__ (self ):
492
506
try :
0 commit comments