/usr/lib/python2.7/dist-packages/code_saturne/Pages/OutputSurfacicVariablesModel.py is in code-saturne-data 4.3.3+repack-1build1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 | # -*- coding: utf-8 -*-
#-------------------------------------------------------------------------------
# This file is part of Code_Saturne, a general-purpose CFD tool.
#
# Copyright (C) 1998-2016 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 contains the following classes and function:
- OutputVariableModel
- OutputVariableModelTestCase
"""
#-------------------------------------------------------------------------------
# Library modules import
#-------------------------------------------------------------------------------
import string, unittest
#-------------------------------------------------------------------------------
# Application modules import
#-------------------------------------------------------------------------------
from code_saturne.Base.Common import *
import code_saturne.Base.Toolbox as Tool
from code_saturne.Base.XMLmodel import ModelTest
from code_saturne.Base.XMLvariables import Model, Variables
from code_saturne.Pages.ThermalScalarModel import ThermalScalarModel
from code_saturne.Pages.ThermalRadiationModel import ThermalRadiationModel
#-------------------------------------------------------------------------------
# Output model class
#-------------------------------------------------------------------------------
class OutputSurfacicVariablesModel(Model):
def __init__(self, case):
"""
Constuctor
"""
self.case = case
self.node_models = self.case.xmlGetNode('thermophysical_models')
self.listNodeSurface = (self._getListOfVelocityPressureSurfacicProperties(),
self._getThermalScalarSurfacicProperties(),
self._getThermalRadiativeSurfacicProperties())
self.dicoLabelName = {}
self.list_name = []
self._updateDicoLabelName()
def _defaultValues(self):
"""
Return in a dictionnary which contains default values
"""
default = {}
default['status'] = "on"
return default
def _getListOfVelocityPressureSurfacicProperties(self):
"""
Private method: return node of yplus, stress
"""
nodeList = []
self.node_veloce = self.node_models.xmlInitNode('velocity_pressure')
for node in self.node_veloce.xmlGetNodeList('property'):
if node['support']:
nodeList.append(node)
return nodeList
def _getThermalScalarSurfacicProperties(self):
"""
Private method: return list of volumic properties for thermal radiation
"""
nodeList = []
self.node_therm = self.node_models.xmlGetNode('thermal_scalar')
for node in self.node_therm.xmlGetChildNodeList('property'):
if node['support']:
nodeList.append(node)
return nodeList
def _getThermalRadiativeSurfacicProperties(self):
"""
Private method: return list of volumic properties for thermal radiation
"""
nodeList = []
self.node_ray = self.node_models.xmlGetNode('radiative_transfer')
if ThermalRadiationModel(self.case).getRadiativeModel() != "off":
for node in self.node_ray.xmlGetChildNodeList('property'):
if node['support']:
nodeList.append(node)
return nodeList
def _updateDicoLabelName(self):
"""
Private method: update dictionaries of labels for all properties .....
"""
for nodeList in self.listNodeSurface:
for node in nodeList:
name = node['name']
if not name:
name = node['label']
if not node['label']:
msg = "xml node named "+ name +" has no label"
raise ValueError(msg)
self.dicoLabelName[name] = node['label']
self.list_name.append(name)
def getLabelsList(self):
"""
Return list of labels for all properties .....Only for the View
"""
lst = []
for nodeList in self.listNodeSurface:
for node in nodeList:
lst.append(node['label'])
return lst
@Variables.undoLocal
def setPropertyLabel(self, old_label, new_label):
"""
Replace old_label by new_label for node with name and old_label. Only for the View
"""
self.isInList(old_label, self.getLabelsList())
if old_label != new_label:
self.isNotInList(new_label, self.getLabelsList())
for nodeList in self.listNodeSurface:
for node in nodeList:
if node['label'] == old_label:
node['label'] = new_label
self._updateDicoLabelName()
@Variables.noUndo
def getPostProcessing(self, label):
""" Return status of post processing for node withn label 'label'"""
self.isInList(label, self.getLabelsList())
status = self._defaultValues()['status']
for nodeList in self.listNodeSurface:
for node in nodeList:
if node['label'] == label:
node_post = node.xmlGetChildNode('postprocessing_recording', 'status')
if node_post:
status = node_post['status']
return status
@Variables.undoLocal
def setPostProcessing(self, label, status):
""" Put status of post processing for node with label 'label'"""
self.isOnOff(status)
self.isInList(label, self.getLabelsList())
for nodeList in self.listNodeSurface:
for node in nodeList:
if node['label'] == label:
if status == 'off':
node.xmlInitChildNode('postprocessing_recording')['status'] = status
else:
if node.xmlGetChildNode('postprocessing_recording'):
node.xmlRemoveChild('postprocessing_recording')
#-------------------------------------------------------------------------------
# OutputVariableModel test case
#-------------------------------------------------------------------------------
class OutputSurfacicVariablesTestCase(ModelTest):
"""
"""
def checkOutputSurfacicVariablesInstantiation(self):
"""
Check whether the OutputSurfacicVariables Model class could be instantiated
"""
model = None
model = OutputSurfacicVariablesModel(self.case)
assert model != None, 'Could not instantiate OutputSurfacicVariablesModel'
def checkSetPropertyLabel(self):
"""
Check whether the OutputSurfacicVariablesModel class could be set a label
of property
"""
model = OutputSurfacicVariablesModel(self.case)
model.setPropertyLabel('Yplus', 'toto')
node = model.node_models.xmlInitNode('velocity_pressure')
doc = '''<velocity_pressure>
<variable label="Pressure" name="pressure"/>
<variable label="VelocitU" name="velocity_U"/>
<variable label="VelocitV" name="velocity_V"/>
<variable label="VelocitW" name="velocity_W"/>
<property label="total_pressure" name="total_pressure"/>
<property label="toto" name="yplus" support="boundary"/>
<property label="Stress" name="stress" support="boundary"/>
</velocity_pressure>'''
assert node == self.xmlNodeFromString(doc),\
'Could not set label of property in output surfacic variables model'
def checkSetandGetPostProcessing(self):
"""
Check whether the OutputSurfacicVariablesModel class could be set and
get status for post processing of named property
"""
from code_saturne.Pages.ThermalRadiationModel import ThermalRadiationModel
ThermalRadiationModel(self.case).setRadiativeModel('dom')
del ThermalRadiationModel
model = OutputSurfacicVariablesModel(self.case)
model.setPostProcessing('Flux_convectif','off')
doc = '''<property label="Flux_convectif" name="flux_convectif" support="boundary">
<postprocessing_recording status="off"/>
</property>'''
assert model.getPostProcessing('Flux_convectif') == 'off',\
'Could not get status for post processing of named property'
def suite():
testSuite = unittest.makeSuite(OutputSurfacicVariablesTestCase, "check")
return testSuite
def runTest():
print("OutputSurfacicVariablesTestCase")
runner = unittest.TextTestRunner()
runner.run(suite())
#-------------------------------------------------------------------------------
# End
#-------------------------------------------------------------------------------
|