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
|
# -*- 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 values of reference.
This module contains the following classes and function:
- FluidStructureInteractionModel
"""
#-------------------------------------------------------------------------------
# Library modules import
#-------------------------------------------------------------------------------
import unittest
#-------------------------------------------------------------------------------
# Application modules import
#-------------------------------------------------------------------------------
from code_saturne.Base.XMLvariables import Model, Variables
from code_saturne.Base.XMLmodel import ModelTest
#-------------------------------------------------------------------------------
# Constants class
#-------------------------------------------------------------------------------
class Constants:
"""
Define class that manages constants
This class is especially useful when we need constant string identifier.
Indeed, if the constant value must be changed, the changes is done at
one place
### example
const = Constants()
# define constant 'a'
const.a = 10
# raise Exception, "Cannot reassign constant a"
const.a = 20
"""
def __getattr__(self, attr):
"""
Get an attributs
"""
try:
return self.__dict__[attr]
except(KeyError):
raise AttributeError('A instance has no attribute %s' % attr)
def __setattr__(self, attr, value):
"""
Set an attributs
"""
if attr in list(self.__dict__.keys()):
raise Exception("Cannot reassign constant %s" % attr)
else:
self.__dict__[attr] = value
#-------------------------------------------------------------------------------
# Constant class
#-------------------------------------------------------------------------------
const = Constants()
const.max_iterations_implicitation = 'max_iterations_implicitation'
const.implicitation_precision = 'implicitation_precision'
const.displacement_prediction_alpha = 'displacement_prediction_alpha'
const.displacement_prediction_beta = 'displacement_prediction_beta'
const.stress_prediction_alpha = 'stress_prediction_alpha'
const.monitor_point_synchronisation = 'monitor_point_synchronisation'
#-------------------------------------------------------------------------------
# Mobil Mesh model class
#-------------------------------------------------------------------------------
class FluidStructureInteractionModel(Model):
"""
Manage the input/output markups in the xml doc about mobil mesh
"""
def __init__(self, case):
"""
Constructor.
"""
self.case = case
self.__node_models = case.xmlGetNode('thermophysical_models')
self.__node_ale = self.__node_models.xmlInitChildNode('ale_method', 'status')
self.__defaults = {}
self.__defaults[const.max_iterations_implicitation] = 1
self.__defaults[const.implicitation_precision] = 1e-05
self.__defaults[const.displacement_prediction_alpha] = 0.5
self.__defaults[const.displacement_prediction_beta] = 0
self.__defaults[const.stress_prediction_alpha] = 2
self.__defaults[const.monitor_point_synchronisation] = 'off'
#------------------------------------------------------------------
# MaxIterations
#------------------------------------------------------------------
@Variables.undoLocal
def setMaxIterations(self, value):
"""
Set value of maximum of iteration if implicitation into xml file.
"""
self.isInt(value)
self.isGreaterOrEqual(value, 1)
self.__node_ale.xmlSetData(const.max_iterations_implicitation, value)
@Variables.noUndo
def getMaxIterations(self):
"""
Get value of maximum of iteration if implicitation from xml file.
"""
return self.__getIntData(const.max_iterations_implicitation,
self.setMaxIterations )
#------------------------------------------------------------------
# Precision
#------------------------------------------------------------------
@Variables.undoLocal
def setPrecision(self, value):
"""
Set value of precision of implicitation into xml file.
"""
self.isGreater(value, 0.0)
self.__node_ale.xmlSetData(const.implicitation_precision, value)
@Variables.noUndo
def getPrecision(self):
"""
Get value of precision of implicitation from xml file.
"""
return self.__getDoubleData(const.implicitation_precision,
self.setPrecision )
#------------------------------------------------------------------
# DisplacementPredictionAlpha
#------------------------------------------------------------------
@Variables.undoLocal
def setDisplacementPredictionAlpha(self, value):
"""
Set value of isplacement prediction alpha into xml file.
"""
self.__node_ale.xmlSetData(const.displacement_prediction_alpha, value)
@Variables.noUndo
def getDisplacementPredictionAlpha(self):
"""
Get value of displacement prediction alpha from xml file.
"""
return self.__getDoubleData(const.displacement_prediction_alpha,
self.setDisplacementPredictionAlpha )
#------------------------------------------------------------------
# DisplacementPredictionBeta
#------------------------------------------------------------------
@Variables.undoLocal
def setDisplacementPredictionBeta(self, value):
"""
Set value of isplacement prediction beta into xml file.
"""
self.__node_ale.xmlSetData(const.displacement_prediction_beta, value)
@Variables.noUndo
def getDisplacementPredictionBeta(self):
"""
Get value of displacement prediction beta from xml file.
"""
return self.__getDoubleData(const.displacement_prediction_beta,
self.setDisplacementPredictionBeta )
#------------------------------------------------------------------
# StressPredictionAlpha
#------------------------------------------------------------------
@Variables.undoLocal
def setStressPredictionAlpha(self, value):
"""
Set value of stress prediction alpha into xml file.
"""
self.__node_ale.xmlSetData(const.stress_prediction_alpha, value)
@Variables.noUndo
def getStressPredictionAlpha(self):
"""
Get value of stress prediction alpha from xml file.
"""
return self.__getDoubleData(const.stress_prediction_alpha,
self.setStressPredictionAlpha )
#------------------------------------------------------------------
# Monitor point synchronisation
#------------------------------------------------------------------
@Variables.undoLocal
def setMonitorPointSynchronisation(self, value):
"""
Set value of monitor point synchronisation into xml file.
"""
self.__setOnOffXML(const.monitor_point_synchronisation, value)
@Variables.noUndo
def getMonitorPointSynchronisation(self):
"""
Get value of monitor point synchronisation from xml file.
"""
return self.__getOnOffXML(const.monitor_point_synchronisation,
self.setMonitorPointSynchronisation)
#------------------------------------------------------------------
# Helper function
#------------------------------------------------------------------
def __getStringData(self, name, setFunction):
"""
Get string value from xml file.
"""
value = self.__node_ale.xmlGetString(name)
return self.__getDefaultDataIfNone(value, name, setFunction)
def __getDoubleData(self, name, setFunction):
"""
Get double value from xml file.
"""
value = self.__node_ale.xmlGetDouble(name)
return self.__getDefaultDataIfNone(value, name, setFunction)
def __getIntData(self, name, setFunction):
"""
Get int value from xml file.
"""
value = self.__node_ale.xmlGetInt(name)
return self.__getDefaultDataIfNone(value, name, setFunction)
def __getDefaultDataIfNone(self, value, name, setFunction):
"""
Get default value if value is none.
"""
if value == None or value == "":
value = self.__defaults[name]
setFunction(value)
return value
def __setOnOffXML(self, name, value):
"""
Set value of 'on'/'off' xml attribute
"""
Model().isInList(value, [ 'on', 'off'])
xmlNode = self.__node_ale.xmlInitNode(name)
xmlNode['status'] = value
def __getOnOffXML(self, name, setFunction):
"""
Get value of 'on'/'off' xml attribut
"""
node = self.__node_ale.xmlInitNode(name, 'status')
value = node['status']
return self.__getDefaultDataIfNone(value, name, setFunction)
def getNodeALE(self):
"""
Return the node ALE
"""
return self.__node_ale
#-------------------------------------------------------------------------------
# FluidStructureInteraction test case
#-------------------------------------------------------------------------------
class FluidStructureInteractionTestCase(ModelTest):
"""
Test case for FluidStructureInteraction
"""
def checkFluidStructureInteractionInstantiation(self):
"""
Check whether the FluidStructureInteraction class could be instantiated
"""
model = None
model = FluidStructureInteractionModel(self.case)
assert model != None, 'Could not instantiate '
def checkGetandSetPrecision(self):
"""Check whether the FluidStructureInteraction class could be set and get precision"""
mdl = FluidStructureInteractionModel(self.case)
mdl.setPrecision(0.001)
doc = """<ale_method status="off">
<implicitation_precision>
0.001
</implicitation_precision>
</ale_method>"""
assert mdl.getNodeALE() == self.xmlNodeFromString(doc), \
'Could not set fluid structure interaction precision'
assert mdl.getPrecision() == 0.001, \
'Could not get fluid structure interaction precision'
def checkGetandSetMaxIterations(self):
"""Check whether the FluidStructureInteraction class could be set and get max iterations"""
mdl = FluidStructureInteractionModel(self.case)
mdl.setMaxIterations(99)
doc = """<ale_method status="off">
<max_iterations_implicitation>
99
</max_iterations_implicitation>
</ale_method>"""
assert mdl.getNodeALE() == self.xmlNodeFromString(doc), \
'Could not set fluid structure interaction max iterations'
assert mdl.getMaxIterations() == 99, \
'Could not get fluid structure interaction max iteration'
def checkGetAndSetAdvancedViewFeatures(self):
"""Check whether the FluidStructureInteraction class could be set and get advanced view features"""
mdl = FluidStructureInteractionModel(self.case)
mdl.setStressPredictionAlpha(42.0)
mdl.setDisplacementPredictionBeta(42.42)
mdl.setDisplacementPredictionAlpha(42.4242)
mdl.setMonitorPointSynchronisation('on')
doc = """<ale_method status="off">
<stress_prediction_alpha>
42
</stress_prediction_alpha>
<displacement_prediction_beta>
42.42
</displacement_prediction_beta>
<displacement_prediction_alpha>
42.4242
</displacement_prediction_alpha>
<monitor_point_synchronisation status="on"/>
</ale_method>"""
assert mdl.getNodeALE() == self.xmlNodeFromString(doc), \
'Could not set fluid structure interaction advanced view features'
assert mdl.getStressPredictionAlpha() == 42.0, \
'Could not get fluid structure interaction stress prediction alpha'
assert mdl.getDisplacementPredictionBeta() == 42.42, \
'Could not get fluid structure interaction displacement prediction beta'
assert mdl.getDisplacementPredictionAlpha() == 42.4242, \
'Could not get fluid structure interaction displacement prediction alpha'
assert mdl.getMonitorPointSynchronisation() == 'on', \
'Could not get fluid structure interaction monitor point synchronisation'
def suite():
"""
Test Suite for FluidStructureInteractionTestCase
"""
testSuite = unittest.makeSuite(FluidStructureInteractionTestCase, "check")
return testSuite
def runTest():
"""
run test
"""
print("FluidStructureInteractionTestCase")
runner = unittest.TextTestRunner()
runner.run(suite())
#-------------------------------------------------------------------------------
# End
#-------------------------------------------------------------------------------
|