|
| 1 | +# Copyright (C) 2020 - 2025 ANSYS, Inc. and/or its affiliates. |
| 2 | +# SPDX-License-Identifier: MIT |
| 3 | +# |
| 4 | +# |
| 5 | +# Permission is hereby granted, free of charge, to any person obtaining a copy |
| 6 | +# of this software and associated documentation files (the "Software"), to deal |
| 7 | +# in the Software without restriction, including without limitation the rights |
| 8 | +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 9 | +# copies of the Software, and to permit persons to whom the Software is |
| 10 | +# furnished to do so, subject to the following conditions: |
| 11 | +# |
| 12 | +# The above copyright notice and this permission notice shall be included in all |
| 13 | +# copies or substantial portions of the Software. |
| 14 | +# |
| 15 | +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 16 | +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 17 | +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 18 | +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 19 | +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 20 | +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 21 | +# SOFTWARE. |
| 22 | + |
| 23 | +from ansys.dpf.core import Field |
| 24 | +from ansys.dpf.core.changelog import Changelog |
| 25 | +from ansys.dpf.core.custom_operator import CustomOperatorBase, record_operator |
| 26 | +from ansys.dpf.core.operator_specification import ( |
| 27 | + CustomSpecification, |
| 28 | + PinSpecification, |
| 29 | + SpecificationProperties, |
| 30 | +) |
| 31 | + |
| 32 | + |
| 33 | +class AddFloatToFieldData(CustomOperatorBase): |
| 34 | + def run(self): |
| 35 | + field = self.get_input(0, Field) |
| 36 | + to_add = self.get_input(1, float) |
| 37 | + data = field.data |
| 38 | + data += to_add |
| 39 | + self.set_output(0, field) |
| 40 | + self.set_succeeded() |
| 41 | + |
| 42 | + @property |
| 43 | + def specification(self): |
| 44 | + spec = CustomSpecification() |
| 45 | + spec.description = "Add a custom value to all the data of an input Field" |
| 46 | + spec.inputs = { |
| 47 | + 0: PinSpecification("field", [Field], "Field on which float value is added."), |
| 48 | + 1: PinSpecification("to_add", [float], "Data to add."), |
| 49 | + } |
| 50 | + spec.outputs = { |
| 51 | + 0: PinSpecification("field", [Field], "Field on which the float value is added.") |
| 52 | + } |
| 53 | + spec.properties = SpecificationProperties("custom add to field", "math") |
| 54 | + spec.set_changelog(changelog=Changelog().major_bump("Major bump").expect_version("1.0.0")) |
| 55 | + return spec |
| 56 | + |
| 57 | + @property |
| 58 | + def name(self): |
| 59 | + return "custom_add_to_field" |
| 60 | + |
| 61 | + |
| 62 | +def load_operators(*args): |
| 63 | + record_operator(AddFloatToFieldData, *args) |
0 commit comments