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 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437
|
# -*- coding: utf-8 -*-
#-------------------------------------------------------------------------------
# This file is part of Code_Saturne, a general-purpose CFD tool.
#
# Copyright (C) 1998-2019 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:
- TurboMachineryModel
"""
#-------------------------------------------------------------------------------
# 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 ModelTest
#-------------------------------------------------------------------------------
# Class TurboMachinery Model
#-------------------------------------------------------------------------------
class TurboMachineryModel(Variables, Model):
"""
This class manages the turbomachinery objects in the XML file
"""
def __init__(self, case):
"""
Constuctor.
"""
#
# XML file parameters
self.case = case
self.node_therm = self.case.xmlGetNode('thermophysical_models')
self.node_turbo = self.node_therm.xmlInitNode('turbomachinery')
self.node_join = self.node_turbo.xmlInitNode('joining')
def defaultValues(self):
"""
Return a dictionary with default values
"""
defvalue = {}
defvalue['selector'] = "all[]"
defvalue['fraction'] = 0.1
defvalue['plane'] = 25.0
defvalue['verbosity'] = 0
defvalue['visualization'] = 0
defvalue['angle'] = 0.01
defvalue['model'] = 'off'
defvalue['velocity'] = 1.
defvalue['invariant'] = 0.
defvalue['axis'] = 0.
return defvalue
def _getJoinNode(self, join_id):
"""
Get node for a given joining
"""
node = None
listNode = self.node_join.xmlGetNodeList('face_joining')
if join_id < len(listNode):
node = listNode[join_id]
return node
def _updateJoinSelectionNumbers(self):
"""
Update names of join selection
"""
listNode = self.node_join.xmlGetNodeList('face_joining')
i = 0
for node in listNode:
i = i + 1
if int(node['name']) > i:
node['name'] = str(i)
def _addJoinSelect(self, node, select):
"""
Private method: Add faces to node join with dictionary select.
"""
for sel, txt in [ (select['selector'], 'selector'),
(select['fraction'], 'fraction'),
(select['plane'], 'plane'),
(select['verbosity'], 'verbosity'),
(select['visualization'], 'visualization')]:
if sel:
node.xmlSetData(txt, sel)
else:
node.xmlRemoveChild(txt)
def _getFaces(self, node):
"""
Private method: Return values found for joining for a given node
"""
default = {}
default['selector'] =""
default['fraction'] = ""
default['plane'] = ""
default['verbosity'] = ""
default['visualization'] = ""
if node:
default['selector'] = node.xmlGetString('selector')
default['fraction'] = node.xmlGetString('fraction')
default['plane'] = node.xmlGetString('plane')
default['verbosity'] = node.xmlGetString('verbosity')
default['visualization'] = node.xmlGetString('visualization')
if not default['selector']:
default['selector'] = self.defaultValues()['selector']
if not default['fraction']:
default['fraction'] = self.defaultValues()['fraction']
if not default['plane']:
default['plane'] = self.defaultValues()['plane']
if not default['verbosity']:
default['verbosity'] = self.defaultValues()['verbosity']
if not default['visualization']:
default['visualization'] = self.defaultValues()['visualization']
else:
default = {}
return default
def _removeJoinChildren(self, node):
"""
Private method: Remove all child nodes of node for one selection
"""
for tag in ('selector',
'fraction',
'plane',
'verbosity',
'visualization',):
node.xmlRemoveChild(tag)
@Variables.noUndo
def getJoinSelectionsCount(self):
"""
Public method.
@return: number of join faces selections
@rtype: C{int}
"""
return len(self.node_join.xmlGetNodeList('face_joining'))
@Variables.undoGlobal
def addJoinFaces(self, select):
"""
Add faces selection for face joining.
Select is a dictionary with 'selector', 'fraction', 'plane', 'verbosity', 'visualization'
"""
nb = self.getJoinSelectionsCount()
name = str(nb +1)
node = self.node_join.xmlAddChild('face_joining', name=name)
self._addJoinSelect(node, select)
@Variables.noUndo
def getJoinFaces(self, join_id):
"""
Return faces selection named 'number' for face joining .
"""
node = self._getJoinNode(join_id)
return self._getFaces(node)
@Variables.undoGlobal
def replaceJoinFaces(self, join_id, select):
"""
Replace values of faces selection named 'number' for face joining, by select
"""
node = self._getJoinNode(join_id)
self._removeJoinChildren(node)
self._addJoinSelect(node, select)
@Variables.undoGlobal
def deleteJoinFaces(self, join_id):
"""
Delete faces selection named 'number' for face joining
"""
node = self._getJoinNode(join_id)
node.xmlRemoveNode()
if join_id < self.getJoinSelectionsCount():
self._updateJoinSelectionNumbers()
@Variables.undoGlobal
def setTurboMachineryModel(self, model) :
"""
Put model for turbo machinery
"""
self.isInList(model, ('off', 'frozen', 'transient',
'frozen_coupled', 'transient_coupled'))
self.node_turbo.xmlSetAttribute(model = model)
if model == 'off':
for node in self.getRotorList():
node.xmlRemoveNode()
else :
if len(self.getRotorList()) == 0:
self.addRotor()
@Variables.noUndo
def getTurboMachineryModel(self) :
"""
Get model for turbo machinery
"""
model = self.node_turbo['model']
if model == None :
model = self.defaultValues()['model']
self.setTurboMachineryModel(model)
return model
@Variables.undoGlobal
def addRotor(self):
"""
Add a rotor
"""
rotor_id = 0
if self.getRotorList() != None:
rotor_id = len(self.getRotorList())
self.node_turbo.xmlInitNode('rotor', rotor_id = rotor_id)
self.getRotorVelocity(rotor_id)
self.getRotorCriteria(rotor_id)
@Variables.undoGlobal
def delRotor(self, rotor_id):
"""
Suppress a rotor
"""
lst = self.getRotorList()
n = lst[rotor_id]
for node in lst:
nodeid = int(node['rotor_id'])
if nodeid > int(rotor_id):
node['rotor_id'] = str(nodeid-1)
n.xmlRemoveNode()
def _getRotorNode(self, rotor_id):
"""
Get node for a given rotor
"""
if rotor_id < len(self.getRotorList()):
node = self.getRotorList()[rotor_id]
return node
def getRotorList(self):
"""
Get rotor list
"""
listNode = self.node_turbo.xmlGetNodeList('rotor')
return listNode
@Variables.noUndo
def getRotorVelocity(self, rotor_id):
"""
return values for rotor velocity
"""
node = self.node_turbo.xmlGetNode('rotor', rotor_id = rotor_id)
n = node.xmlGetNode('velocity')
if not n or n == "None":
vel = self.defaultValues()['velocity']
self.setRotorVelocity(rotor_id, vel)
n = node.xmlGetNode('velocity')
vel = n.xmlGetDouble('value')
return vel
@Variables.undoLocal
def setRotorVelocity(self, rotor_id, velocity):
"""
Put values for rotor velocity
"""
self.isFloat(velocity)
node = self.node_turbo.xmlGetNode('rotor', rotor_id = rotor_id)
n = node.xmlInitChildNode('velocity', status="constant")
n.xmlSetData('value', velocity)
@Variables.noUndo
def getRotorCriteria(self, rotor_id):
"""
return values for rotor criteria
"""
node = self.node_turbo.xmlGetNode('rotor', rotor_id = rotor_id)
n = node.xmlGetNode('criteria')
if not n or n == "None":
crit = self.defaultValues()['selector']
self.setRotorCriteria(rotor_id, crit)
n = node.xmlGetNode('criteria')
criteria = str(n.xmlGetTextNode())
return criteria
@Variables.undoLocal
def setRotorCriteria(self, rotor_id, criteria):
"""
Put values for rotor criteria
"""
node = self.node_turbo.xmlGetNode('rotor', rotor_id = rotor_id)
node.xmlSetData('criteria', criteria)
@Variables.noUndo
def getRotationDirection(self, rotor_id):
"""
Get values for director vector rotation for periodic translation
"""
node = self._getRotorNode(rotor_id)
n = node.xmlInitChildNode('rotation')
rx = n.xmlGetString('axis_x')
if not rx:
rx = self.defaultValues()['axis']
ry = n.xmlGetString('axis_y')
if not ry:
ry = self.defaultValues()['axis']
rz = n.xmlGetString('axis_z')
if not rz:
rz = self.defaultValues()['axis']
return rx, ry, rz
@Variables.undoLocal
def setRotationVector(self, rotor_id, dir, valcoor):
"""
Put values for director vector rotation for periodic translation
"""
self.isFloat(valcoor)
self.isInList(dir, ("axis_x", "axis_y", "axis_z"))
node = self._getRotorNode(rotor_id)
n = node.xmlGetChildNode('rotation')
n.xmlSetData(dir,valcoor)
@Variables.noUndo
def getRotationCenter(self, rotor_id):
"""
Get coordinates of center of rotation for periodic transformation
"""
node = self._getRotorNode(rotor_id)
n = node.xmlInitChildNode('rotation')
px = n.xmlGetString('invariant_x')
if not px:
px = self.defaultValues()['invariant']
py = n.xmlGetString('invariant_y')
if not py:
py = self.defaultValues()['invariant']
pz = n.xmlGetString('invariant_z')
if not pz:
pz = self.defaultValues()['invariant']
return px, py, pz
@Variables.undoGlobal
def setRotationCenter(self, rotor_id, pos, val):
"""
Put coordinates of center of rotation for periodic transformation
"""
self.isFloat(val)
self.isInList(pos, ('invariant_x', 'invariant_y', 'invariant_z'))
node = self._getRotorNode(rotor_id)
n = node.xmlGetChildNode('rotation')
n.xmlSetData(pos, val)
#-------------------------------------------------------------------------------
# TurboMachinery test case
#-------------------------------------------------------------------------------
class TurboMachineryTestCase(ModelTest):
"""
"""
def suite():
testSuite = unittest.makeSuite(TurboMachineryTestCase, "check")
return testSuite
def runTest():
print("TurboMachineryTestCase")
runner = unittest.TextTestRunner()
runner.run(suite())
|