File: FansModel.py

package info (click to toggle)
code-saturne 7.0.2%2Brepack-1~exp1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 62,868 kB
  • sloc: ansic: 395,271; f90: 100,755; python: 86,746; cpp: 6,227; makefile: 4,247; xml: 2,389; sh: 1,091; javascript: 69
file content (235 lines) | stat: -rw-r--r-- 6,564 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
# -*- coding: utf-8 -*-

#-------------------------------------------------------------------------------

# This file is part of Code_Saturne, a general-purpose CFD tool.
#
# Copyright (C) 1998-2021 EDF S.A.
#
# This program is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free Software
# Foundation; either version 2 of the License, or (at your option) any later
# version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
# details.
#
# You should have received a copy of the GNU General Public License along with
# this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
# Street, Fifth Floor, Boston, MA 02110-1301, USA.

#-------------------------------------------------------------------------------

"""
This module defines the XML calls for preprocessor execution
This module contains the following classes and function:
- FansModel
"""

#-------------------------------------------------------------------------------
# Library modules import
#-------------------------------------------------------------------------------

import sys, unittest
import os, sys, types

#-------------------------------------------------------------------------------
# Application modules import
#-------------------------------------------------------------------------------

from code_saturne.model.XMLvariables import Variables, Model
from code_saturne.model.XMLmodel import XMLmodel, ModelTest

#-------------------------------------------------------------------------------
# Class Fans Model
#-------------------------------------------------------------------------------

class FansModel(Variables, Model):

    """
    This class manages the fan objects in the XML file
    """

    def __init__(self, case):
        """
        Constuctor.
        """
        #
        # XML file parameters
        self.case = case
        node_model = self.case.xmlInitNode('thermophysical_models')
        self.node_model_fans = node_model.xmlInitNode('fans')


    def defaultValues(self):
        """
        Return a dictionary with default values
        """
        defvalue = {}
        defvalue['inlet_axis_x']   = 0.
        defvalue['inlet_axis_y']   = 0.
        defvalue['inlet_axis_z']   = 0.
        defvalue['outlet_axis_x']  = 0.1
        defvalue['outlet_axis_y']  = 0.
        defvalue['outlet_axis_z']  = 0.
        defvalue['fan_radius']     = 0.7
        defvalue['blades_radius']  = 0.5
        defvalue['hub_radius']     = 0.1
        defvalue['axial_torque']   = 0.01
        defvalue['curve_coeffs_x'] = 0.6
        defvalue['curve_coeffs_y'] = -0.1
        defvalue['curve_coeffs_z'] = -0.05
        defvalue['mesh_dimension'] = 3

        return defvalue


    @Variables.undoGlobal
    def addFan(self):
        """
        """
        nb = len(self.getFanList())
        node = self.node_model_fans.xmlAddChild('fan', fan_id = nb)


    @Variables.undoGlobal
    def delFan(self, idx):
        """
        """
        self.isInt(idx)
        lst = self.getFanList()
        n = lst[idx]
        for node in lst:
            nodeid = int(node['fan_id'])
            if nodeid > int(idx):
                node['fan_id'] = str(nodeid-1)
        n.xmlRemoveNode()


    @Variables.noUndo
    def getFanList(self):
        """
        """
        listNode = self.node_model_fans.xmlGetNodeList('fan')

        return listNode


    @Variables.noUndo
    def getFanProperty(self, idx, prop):
        """
        """
        self.isInt(idx)
        node = self.node_model_fans.xmlGetNode('fan', fan_id = idx)
        n = node.xmlGetNode(prop)
        if not n or n == "None":
            value = self.defaultValues()[prop]
            self.setFanProperty(idx, prop, value)
        value = node.xmlGetDouble(prop)

        return value


    @Variables.undoLocal
    def setFanProperty(self, idx, prop, val):
        """
        """
        self.isInt(idx)
        node = self.node_model_fans.xmlGetNode('fan', fan_id = idx)
        node.xmlSetData(prop, val)


    @Variables.noUndo
    def getFanMeshDimension(self, idx):
        """
        """
        self.isInt(idx)
        node = self.node_model_fans.xmlGetNode('fan', fan_id = idx)
        n = node.xmlGetNode('mesh_dimension')
        if not n or n == "None":
            value = self.defaultValues()['mesh_dimension']
            self.setFanMeshDimension(idx, value)
        value = node.xmlGetInt('mesh_dimension')

        return value


    @Variables.undoLocal
    def setFanMeshDimension(self, idx, val):
        """
        """
        self.isInt(idx)
        node = self.node_model_fans.xmlGetNode('fan', fan_id = idx)
        node.xmlSetData('mesh_dimension', val)


class FansStatus(Variables, Model):

    """
    This class checks for fan objects in the XML file
    """

    def __init__(self, case):
        """
        Constuctor.
        """
        self.case = case


    def getFanCount(self):
        """
        Returns info on fans: -1 if node is not present, count if present
        """
        count = -1

        node_model = self.case.xmlGetNode('thermophysical_models')
        if node_model:
            node_fans = node_model.xmlGetNode('fans')
            if node_fans:
                count =len(node_fans.xmlGetNodeList('fan'))

        return count


    def initFans(self):
        """
        Ensures a fans node is present
        """
        node_model = self.case.xmlInitNode('thermophysical_models')
        node_model.xmlInitNode('fans')


    def cleanFans(self):
        """
        Removes fan node if empty
        """
        count = -1
        node_model = self.case.xmlGetNode('thermophysical_models')
        if node_model:
            node_fans = node_model.xmlGetNode('fans')
            if node_fans:
                count =len(node_fans.xmlGetNodeList('fan'))

        if count == 0:
            node_fans.xmlRemoveNode()


#-------------------------------------------------------------------------------
# Fans test case
#-------------------------------------------------------------------------------

class FansTestCase(ModelTest):
    """
    """

def suite():
    testSuite = unittest.makeSuite(FansTestCase, "check")
    return testSuite


def runTest():
    print("FansTestCase")
    runner = unittest.TextTestRunner()
    runner.run(suite())