File: FansModel.py

package info (click to toggle)
code-saturne 5.3.2%2Brepack-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 76,868 kB
  • sloc: ansic: 338,582; f90: 118,487; python: 65,227; makefile: 4,429; cpp: 3,826; xml: 3,078; sh: 1,205; lex: 170; yacc: 100
file content (178 lines) | stat: -rw-r--r-- 5,203 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
# Copyright (C) 1998-2018 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.Base.XMLvariables import Variables, Model
from code_saturne.Base.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
        self.node_model      = self.case.xmlInitNode('thermophysical_models')
        self.node_model_fans = self.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)


#-------------------------------------------------------------------------------
# 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())