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
|
# -*- 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 atmospheric flows modelling management.
This module contains the following classes and function:
- AtmosphericFlowsModel
"""
#-------------------------------------------------------------------------------
# Library modules import
#-------------------------------------------------------------------------------
import unittest
#-------------------------------------------------------------------------------
# Application modules import
#-------------------------------------------------------------------------------
from code_saturne.Base.XMLvariables import Model, Variables
from code_saturne.Base.XMLmodel import ModelTest
from code_saturne.Pages.ThermalScalarModel import ThermalScalarModel
from code_saturne.Pages.FluidCharacteristicsModel import FluidCharacteristicsModel
from code_saturne.Pages.NumericalParamGlobalModel import NumericalParamGlobalModel
#-------------------------------------------------------------------------------
# Atmospheric flows model class
#-------------------------------------------------------------------------------
class AtmosphericFlowsModel(Model):
"""
Model for atmospheric flows
"""
off = 'off'
constant = 'constant'
dry = 'dry'
humid = 'humid'
read_meteo_data = 'read_meteo_data'
model = 'model'
status = 'status'
def __init__(self, case):
"""
Constructor.
"""
self.case = case
self.__fluidProp = FluidCharacteristicsModel(self.case)
models = case.xmlGetNode('thermophysical_models')
self.__node_atmos = models.xmlInitChildNode('atmospheric_flows')
self.__atmosphericModel = (AtmosphericFlowsModel.off,
AtmosphericFlowsModel.constant,
AtmosphericFlowsModel.dry,
AtmosphericFlowsModel.humid)
self.__default = {}
self.__default[self.model] = AtmosphericFlowsModel.off
self.__default[self.read_meteo_data] = AtmosphericFlowsModel.off
self.__default['meteo_data'] = "meteo"
@Variables.undoLocal
def setAtmosphericFlowsModel(self, model):
"""
Update the atmospheric flows model markup from the XML document.
"""
self.isInList(model, self.__atmosphericModel)
self.__node_atmos[self.model] = model
self.__updateScalarAndProperty()
if (model == "humid" or model == "dry"):
NumericalParamGlobalModel(self.case).setHydrostaticPressure("on")
NumericalParamGlobalModel(self.case).setWallPressureExtrapolation("extrapolation")
if (model == "dry"):
ThermalScalarModel(self.case).setThermalModel('potential_temperature')
else:
ThermalScalarModel(self.case).setThermalModel('liquid_potential_temperature')
else:
ThermalScalarModel(self.case).setThermalModel('off')
NumericalParamGlobalModel(self.case).setHydrostaticPressure("off")
NumericalParamGlobalModel(self.case).setWallPressureExtrapolation("neumann")
@Variables.noUndo
def getAtmosphericFlowsModel(self):
"""
Return the current atmospherics flows model.
"""
model = self.__node_atmos[self.model]
if model not in self.__atmosphericModel:
model = self.__default[self.model]
self.setAtmosphericFlowsModel(model)
return model
@Variables.noUndo
def getMeteoDataStatus(self):
"""
Return if reading meteo data status is 'on' or 'off'.
"""
node = self.__node_atmos.xmlInitChildNode(self.read_meteo_data)
if not node[self.status]:
status = self.__default[self.read_meteo_data]
self.setMeteoDataStatus(status)
return node[self.status]
@Variables.undoLocal
def setMeteoDataStatus(self, status):
"""
Set meteo data status to 'on' / 'off'.
"""
self.isOnOff(status)
self.__node_atmos.xmlInitChildNode(self.read_meteo_data)[self.status] = status
if status == 'off':
for tag in ['read_meteo_data', 'meteo_automatic']:
for node in self.case.xmlGetNodeList(tag):
node['status'] = "off"
@Variables.noUndo
def getMeteoDataFileName(self):
"""
Return the name of the meteo data file.
"""
f = self.__node_atmos.xmlGetString('meteo_data')
if f == None:
f = self.__default['meteo_data']
self.setMeteoDataFile(f)
return f
@Variables.undoLocal
def setMeteoDataFileName(self, tag):
"""
Set the name of the meteo data file.
"""
self.__node_atmos.xmlSetData('meteo_data', tag)
def __updateScalarAndProperty(self):
"""
Update scalars and properties depending on model
"""
model = self.getAtmosphericFlowsModel()
node = self.__node_atmos
# Update only if getMeteoDataStatus is not off
if model != AtmosphericFlowsModel.off:
if model == AtmosphericFlowsModel.dry:
self.__removeScalar(node, 'total_water')
self.__removeScalar(node, 'number_of_droplets')
self.__removeProperty(node, 'liquid_water')
self.__setProperty(node, 'RealTemp', 'real_temperature')
if self.__fluidProp.getPropertyMode('density') == 'constant':
self.__fluidProp.setPropertyMode('density', 'variable')
elif model == AtmosphericFlowsModel.humid:
self.__setScalar(node, 'TotWater', 'total_water', 'model')
self.__setScalar(node, 'TotDrop', 'number_of_droplets', 'model')
self.__setProperty(node, 'RealTemp', 'real_temperature')
self.__setProperty(node, 'LiqWater', 'liquid_water')
if self.__fluidProp.getPropertyMode('density') == 'constant':
self.__fluidProp.setPropertyMode('density', 'variable')
elif model == AtmosphericFlowsModel.constant:
self.__removeScalar(node, 'total_water')
self.__removeScalar(node, 'number_of_droplets')
self.__removeProperty(node, 'liquid_water')
FluidCharacteristicsModel(self.case).setPropertyMode('density', 'constant')
else:
self.__removeScalar(node, 'total_water')
self.__removeScalar(node, 'number_of_droplets')
self.__removeProperty(node, 'liquid_water')
def atmosphericFlowsNode(self):
"""
Get the atmospheric flows node
"""
return self.__node_atmos
def __setScalar(self, parentNode, labelStr, nameStr, typeStr ):
"""
Create xml scalar
"""
scalar = parentNode.xmlInitChildNode('variable', name = nameStr)
scalar['label'] = labelStr
scalar['type'] = typeStr
def __setProperty(self, parentNode, labelStr, nameStr):
"""
Create xml property
"""
prop = parentNode.xmlInitChildNode('property', name = nameStr)
prop['label'] = labelStr
def __removeScalar(self, parentNode, nameStr):
"""
Delete scalar
"""
parentNode.xmlRemoveChild('variable', name = nameStr)
def __removeProperty(self, parentNode, nameStr):
"""
Delete property
"""
parentNode.xmlRemoveChild('property', name = nameStr)
#-------------------------------------------------------------------------------
# AtmosphericFlowsModel test case
#-------------------------------------------------------------------------------
class AtmosphericFlowsTestCase(ModelTest):
"""
Test case for AtmosphericFlows
"""
def checkAtmosphericFlowsInstantiation(self):
"""
Check whether the AtmosphericFlowsModel class could be instantiated
"""
model = None
model = AtmosphericFlowsModel(self.case)
assert model != None, 'Could not instantiate '
def checkGetandSetAtmosphericFlowsModel(self):
"""Check whether the AtmosphericFlowsModel class could be set and get the model"""
mdl = AtmosphericFlowsModel(self.case)
mdl.setAtmosphericFlowsModel(AtmosphericFlowsModel.dry)
doc = """<atmospheric_flows model="dry">
<read_meteo_data status="off"/>
</atmospheric_flows>"""
assert mdl.atmosphericFlowsNode() == self.xmlNodeFromString(doc), \
'Could not set atmospheric flows model'
assert mdl.getAtmosphericFlowsModel() == AtmosphericFlowsModel.dry, \
'Could not get atmospheric flows model'
def checkGetandSetMeteoDataStatus(self):
"""Check whether the AtmosphericFlowsModel class could be set and get the meteo data status"""
mdl = AtmosphericFlowsModel(self.case)
mdl.setAtmosphericFlowsModel(AtmosphericFlowsModel.constant)
mdl.setMeteoDataStatus('on')
doc = """<atmospheric_flows model="constant">
<read_meteo_data status="on"/>
</atmospheric_flows>"""
assert mdl.atmosphericFlowsNode() == self.xmlNodeFromString(doc), \
'Could not set meteo data status'
assert mdl.getMeteoDataStatus() == 'on', \
'Could not get meteo data status'
def checkDryModel(self):
"""
Check whether the AtmosphericFlowsModel class could set the correct
properties and scalar for dry model
"""
mdl = AtmosphericFlowsModel(self.case)
mdl.setAtmosphericFlowsModel(AtmosphericFlowsModel.dry)
mdl.setMeteoDataStatus('on')
doc = """<atmospheric_flows model="dry">
<read_meteo_data status="on">
<property label="Real temp" name="real_temperature"/>
</read_meteo_data>
</atmospheric_flows>
"""
assert mdl.atmosphericFlowsNode() == self.xmlNodeFromString(doc), \
'Could not set scalars and properties for dry model'
def checkHumidModel(self):
"""
Check whether the AtmosphericFlowsModel class could set the correct
properties and scalar for humid model
"""
mdl = AtmosphericFlowsModel(self.case)
mdl.setAtmosphericFlowsModel(AtmosphericFlowsModel.humid)
mdl.setMeteoDataStatus('on')
doc = """<atmospheric_flows model="humid">
<read_meteo_data status="on">
<variable label="total water" name="total_water" type="model"/>
<variable label="number of droplets" name="number_of_droplets" type="model"/>
<property label="Real temp" name="real_temperature"/>
<property label="Liquid water" name="liquid_water"/>
</read_meteo_data>
</atmospheric_flows>"""
assert mdl.atmosphericFlowsNode() == self.xmlNodeFromString(doc), \
'Could not set scalars and properties for humid model'
def suite():
"""
Test Suite for AtmosphericFlows
"""
testSuite = unittest.makeSuite(AtmosphericFlowsTestCase, "check")
return testSuite
def runTest():
"""
run test
"""
print("AtmosphericFlowsTestCase")
runner = unittest.TextTestRunner()
runner.run(suite())
#-------------------------------------------------------------------------------
# End
#-------------------------------------------------------------------------------
|