File: InternalCouplingModel.py

package info (click to toggle)
code-saturne 7.0.2%2Brepack-1~exp1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 62,868 kB
  • sloc: ansic: 395,271; f90: 100,755; python: 86,746; cpp: 6,227; makefile: 4,247; xml: 2,389; sh: 1,091; javascript: 69
file content (136 lines) | stat: -rw-r--r-- 4,145 bytes parent folder | download
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
# -*- coding: utf-8 -*-

#-------------------------------------------------------------------------------

# This file is part of Code_Saturne, a general-purpose CFD tool.
#
# Copyright (C) 1998-2021 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 modules defines properties for internal coupling.
"""

#-------------------------------------------------------------------------------
# Library modules import
#-------------------------------------------------------------------------------

import os, sys, unittest

#-------------------------------------------------------------------------------
# Application modules import
#-------------------------------------------------------------------------------


from code_saturne.model.Common import *
from code_saturne.model.XMLvariables import Variables, Model
from code_saturne.model.XMLmodel import XMLmodel, ModelTest

from code_saturne.model.ThermalScalarModel import ThermalScalarModel
from code_saturne.model.DefineUserScalarsModel import DefineUserScalarsModel
from code_saturne.model.NotebookModel import NotebookModel

class InternalCouplingModel(Variables, Model):
    """
    Class to manipulate internal coupling parameters in xml file.
    """

    def __init__(self, case):
        """Constructor"""
        self.case = case

        n = self.case.xmlGetNode("thermophysical_models")
        self.node = n.xmlGetChildNode("internal_coupling")
        if not self.node:
            self.node = n.xmlInitChildNode("internal_coupling")

        self.node_zones = self.node.xmlInitChildNode("solid_zones")
        self.node_scals = self.node.xmlInitChildNode("coupled_scalars")


    def addZone(self, zone_name):
        """Add a coupled zone"""

        self.node_zones.xmlInitChildNode("zone", name=zone_name)


    def removeZone(self, zone_name):
        """Remove a zone from the coupled list"""

        n = self.node_zones.xmlGetChildNode("zone", name=zone_name)
        if n:
            n.xmlRemoveNode()


    def getZonesList(self):
        """Get list of coupled zones."""

        lst = []
        for n in self.node_zones.xmlGetChildNodeList("zone"):
            lst.append(n['name'])

        return lst


    def addScalar(self, scalar_name):
        """Add a coupled scalar"""

        self.node_scals.xmlInitChildNode("scalar", name=scalar_name)


    def removeScalar(self, scalar_name):
        """Remove a scalar from the coupled list"""
        n = self.node_scals.xmlGetChildNode("scalar", name=scalar_name)
        if n:
            n.xmlRemoveNode()


    def getScalarsList(self):
        """Get list of coupled scalars."""

        lst = []
        for n in self.node_scals.xmlGetChildNodeList("scalar"):
            lst.append(n['name'])

        return lst


    def isScalarCoupled(self, scalar_name):
        """Check if a scalar is coupled."""

        retval = False
        if scalar_name in self.getScalarsList():
            retval = True

        return retval

    def getListOfAvailableScalars(self):
        """Get list of scalars which may be coupled"""

        lst = []

        thm = ThermalScalarModel(self.case)
        thermal = thm.getThermalScalarName()
        if thermal and thermal != "":
            lst.append(thermal)

        scm = DefineUserScalarsModel(self.case)
        for scalar in scm.getUserScalarNameList():
            lst.append(scalar)

        return lst