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 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452
|
# -*- coding: utf-8 -*-
#-------------------------------------------------------------------------------
# This file is part of Code_Saturne, a general-purpose CFD tool.
#
# 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 lagrangian two phase flow modelling management.
This module contains the following classes and function:
- LagrangianStatisticsModel
- LagrangianStatisticsTestCase
"""
#-------------------------------------------------------------------------------
# Library modules import
#-------------------------------------------------------------------------------
import sys, unittest, logging
#-------------------------------------------------------------------------------
# Application modules import
#-------------------------------------------------------------------------------
from code_saturne.Base.Common import *
import code_saturne.Base.Toolbox as Tool
from code_saturne.Base.XMLvariables import Model, Variables
from code_saturne.Pages.LagrangianModel import LagrangianModel
#-------------------------------------------------------------------------------
# log config
#-------------------------------------------------------------------------------
logging.basicConfig()
log = logging.getLogger("LagrangianStatisticsModel")
log.setLevel(Tool.GuiParam.DEBUG)
#-------------------------------------------------------------------------------
# lagrangian model class
#-------------------------------------------------------------------------------
class LagrangianStatisticsModel(Model):
"""
Manage the input/output markups in the xml doc about Lagrangian module.
"""
def __init__(self, case):
"""
Constructor.
"""
self.case = case
self.node_lagr = self.case.root().xmlInitNode('lagrangian', 'model')
self.node_stat = self.node_lagr.xmlInitChildNode('statistics')
def _defaultLagrangianStatisticsValues(self):
"""
Return a dictionnary which contains default values.
"""
default = {}
default['restart'] = "off"
default['statistics_groups_of_particles'] = 0
default['volume_statistics'] = "off"
default['iteration_start'] = 1
default['iteration_steady_start'] = default['iteration_start']
default['threshold'] = 0.
for v in self._defaultVariablesNamesVolume():
default[v] = v
default['boundary_statistics'] = "off"
for v in self.getVariablesNamesBoundary():
default[v] = v
default['listing_printing'] = "off"
default['postprocessing_recording'] = "off"
return default
def _defaultVariablesNamesVolume(self):
names = self.getVariablesNamesVolume()
volume_names = []
for name in names:
if name == "Part_statis_weight":
volume_names.append(name)
else:
volume_names.append(name)
volume_names.append("var_" + name)
return volume_names
@Variables.noUndo
def getVariablesNamesVolume(self):
names = ["Part_vol_frac", "Part_velocity",
"Part_resid_time", "Part_statis_weight"]
return names
@Variables.noUndo
def getVariablesNamesBoundary(self):
names = ["Part_bndy_mass_flux","Part_impact_number",
"Part_impact_angle", "Part_impact_velocity"]
if LagrangianModel(self.case).getCoalFouling() == 'on':
names = ["Part_bndy_mass_flux" ,"Part_impact_number",
"Part_impact_angle" , "Part_impact_velocity",
"Part_fouled_impact_number", "Part_fouled_mass_flux",
"Part_fouled_diam" , "Part_fouled_Xck"]
return names
@Variables.undoLocal
def setRestartStatisticsStatus(self, status):
"""
Update the restart status markup from the XML document.
"""
self.isOnOff(status)
node_restart = self.node_stat.xmlInitChildNode('restart', 'status')
node_restart['status'] = status
@Variables.noUndo
def getRestartStatisticsStatus(self):
"""
Return status of restart file.
"""
node_restart = self.node_stat.xmlInitChildNode('restart', 'status')
status = node_restart['status']
if not status:
status = self._defaultLagrangianStatisticsValues()['restart']
self.setRestartStatisticsStatus(status)
return status
@Variables.undoLocal
def setGroupOfParticlesValue(self, value):
"""
Update the value of group of particles.
"""
self.isInt(value)
self.isGreaterOrEqual(value, 0)
self.node_stat.xmlSetData('statistics_groups_of_particles', value)
@Variables.noUndo
def getGroupOfParticlesValue(self):
"""
Return the value of group of particles.
"""
npart = self.node_stat.xmlGetInt('statistics_groups_of_particles')
if npart == None:
npart = self._defaultLagrangianStatisticsValues()['statistics_groups_of_particles']
self.setGroupOfParticlesValue(npart)
return npart
# Volume functions
# ----------------
@Variables.undoLocal
def setVolumeStatisticsStatus(self, status):
"""
"""
self.isOnOff(status)
self.node_volume['status'] = status
@Variables.noUndo
def getVolumeStatisticsStatus(self):
"""
"""
self.node_volume = self.node_stat.xmlInitChildNode('volume', 'status')
status = self.node_volume['status']
if not status:
status = self._defaultLagrangianStatisticsValues()['volume_statistics']
self.setVolumeStatisticsStatus(status)
return status
@Variables.undoLocal
def setIterationStart(self, value):
"""
Update the iteration value for start of statistics calculation.
"""
self.isInt(value)
self.isGreaterOrEqual(value, 0)
self.node_stat.xmlSetData('iteration_start', value)
@Variables.noUndo
def getIterationStart(self):
"""
Return the iteration value for start of volume statistics calculation.
"""
value = self.node_stat.xmlGetInt('iteration_start')
if value == None:
value = self._defaultLagrangianStatisticsValues()['iteration_start']
self.setIterationStart(value)
return value
@Variables.undoLocal
def setIterSteadyStart(self, value):
"""
Update the iteration value for start of steady statistics calculation.
"""
self.isInt(value)
self.isGreaterOrEqual(value,0)
self.node_stat.xmlSetData('iteration_steady_start', value)
@Variables.noUndo
def getIterSteadyStart(self):
"""
Return the iteration value for start of steady statistics calculation.
"""
value = self.node_stat.xmlGetInt('iteration_steady_start')
if value == None:
value = self._defaultLagrangianStatisticsValues()['iteration_steady_start']
self.setIterSteadyStart(value)
return value
@Variables.undoLocal
def setThresholdValue(self, value):
"""
Update the limit statistical weight value.
"""
self.isFloat(value)
self.isGreaterOrEqual(value, 0)
self.node_stat.xmlSetData('threshold', value)
@Variables.noUndo
def getThresholdValue(self):
"""
Return the limit statistical weight value.
"""
value = self.node_stat.xmlGetDouble('threshold')
if not value:
value = self._defaultLagrangianStatisticsValues()['threshold']
self.setThresholdValue(value)
return value
@Variables.noUndo
def getPostprocessingVolStatusFromName(self, name):
node = self.node_volume.xmlInitChildNode('property', name=name)
node2 = node.xmlGetChildNode('postprocessing_recording', 'status')
if not node2:
return "on"
else:
return "off"
@Variables.undoLocal
def setPostprocessingVolStatusFromName(self, name, status):
self.isOnOff(status)
node = self.node_volume.xmlInitChildNode('property', name=name)
node2 = node.xmlInitChildNode('postprocessing_recording', 'status')
if status == "on":
node.xmlRemoveChild('postprocessing_recording')
elif status == "off":
node2['status'] = status
# Boundary functions
# ------------------
@Variables.undoLocal
def setBoundaryStatisticsStatus(self, status):
"""
"""
self.isOnOff(status)
self.node_boundary['status'] = status
@Variables.noUndo
def getBoundaryStatisticsStatus(self):
"""
"""
self.node_boundary = self.node_stat.xmlInitChildNode('boundary', 'status')
status = self.node_boundary['status']
if not status:
status = self._defaultLagrangianStatisticsValues()['boundary_statistics']
self.setBoundaryStatisticsStatus(status)
return status
@Variables.noUndo
def getPropertyLabelFromNameBoundary(self, name):
node = self.node_boundary.xmlInitChildNode('property', name=name)
label = node['label']
if not label:
label = self._defaultLagrangianStatisticsValues()[name]
self.setPropertyLabelFromNameBoundary(label, label)
return label
@Variables.undoLocal
def setPropertyLabelFromNameBoundary(self, name, label):
node = self.node_boundary.xmlInitChildNode('property', name=name)
node['label'] = label
@Variables.noUndo
def getListingPrintingStatusFromName(self, name):
node = self.node_boundary.xmlInitChildNode('property', name=name)
node2 = node.xmlGetChildNode('listing_printing', 'status')
if not node2:
return "on"
else:
return "off" # node2['status']
@Variables.undoLocal
def setListingPrintingStatusFromName(self, name, status):
self.isOnOff(status)
node = self.node_boundary.xmlInitChildNode('property', name=name)
node2 = node.xmlInitChildNode('listing_printing', 'status')
if status == "on":
node.xmlRemoveChild('listing_printing')
elif status == "off":
node2['status'] = status
@Variables.noUndo
def getPostprocessingStatusFromName(self, name):
node = self.node_boundary.xmlInitChildNode('property', name=name)
node2 = node.xmlGetChildNode('postprocessing_recording', 'status')
if not node2:
return "on"
else:
return "off" # node2['status']
@Variables.undoLocal
def setPostprocessingStatusFromName(self, name, status):
self.isOnOff(status)
node = self.node_boundary.xmlInitChildNode('property', name=name)
node2 = node.xmlInitChildNode('postprocessing_recording', 'status')
if status == "on":
node.xmlRemoveChild('postprocessing_recording')
elif status == "off":
node2['status'] = status
#-------------------------------------------------------------------------------
# LagrangianStatistics test case
#-------------------------------------------------------------------------------
class LagrangianStatisticsTestCase(unittest.TestCase):
"""
"""
def setUp(self):
"""
This method is executed before all "check" methods.
"""
from code_saturne.Base.XMLengine import Case
from code_saturne.Base.XMLinitialize import XMLinit
self.case = Case()
XMLinit(self.case).initialize()
def tearDown(self):
"""
This method is executed after all "check" methods.
"""
del self.case
def checkLagrangianStatisticsInstantiation(self):
"""
Check whether the LagrangianStatisticsModel class could be instantiated
"""
model = None
model = LagrangianStatisticsModel(self.case)
assert model != None, 'Could not instantiate LagrangianStatisticsModel'
def checkLagrangianStatisticsDefaultValues(self):
"""
Check the default values
"""
model = LagrangianStatisticsModel(self.case)
doc = """"""
assert model.node_output == self.xmlNodeFromString(doc),\
'Could not get default values for model'
# def checkGetandSetLagrangianStatisticsModel(self):
# """
# Check whether the LagrangianStatisticsModel could be set/get
# """
# mdl = LagrangianStatisticsModel(self.case)
# lagrangianStatus = mdl.lagrangianStatus()
# assert lagrangianStatus == ('off','one_way','two_way','frozen')
# for name in lagrangianStatus:
# mdl.setLagrangianStatisticsModel(name)
# name2 = mdl.getLagrangianStatisticsModel()
# assert name == name2 ,\
# 'Could not use the get/setLagrangianStatisticsModel method for model name %s '%name
def checkSetandGetRestart(self):
"""
Check whether the restart method could be set and get
"""
mdl = LagrangianStatisticsModel(self.case)
# default
status = mdl.getRestart()
assert status == 'off' ,\
'Could not get default values for restart status'
mdl.setRestart('on')
doc = """
"""
assert mdl.node_output == self.xmlNodeFromString(doc) ,\
'Could not set values for restart status'
def suite():
testSuite = unittest.makeSuite(LagrangianStatisticsTestCase, "check")
return testSuite
def runTest():
print("LagrangianStatisticsTestCase TODO*********.")
runner = unittest.TextTestRunner()
runner.run(suite())
#-------------------------------------------------------------------------------
# End
#-------------------------------------------------------------------------------
|