1# -*- coding: utf-8 -*-
2
3#-------------------------------------------------------------------------------
4
5# This file is part of Code_Saturne, a general-purpose CFD tool.
6#
7# Copyright (C) 1998-2021 EDF S.A.
8#
9# This program is free software; you can redistribute it and/or modify it under
10# the terms of the GNU General Public License as published by the Free Software
11# Foundation; either version 2 of the License, or (at your option) any later
12# version.
13#
14# This program is distributed in the hope that it will be useful, but WITHOUT
15# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16# FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
17# details.
18#
19# You should have received a copy of the GNU General Public License along with
20# this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
21# Street, Fifth Floor, Boston, MA 02110-1301, USA.
22
23#-------------------------------------------------------------------------------
24
25"""
26This modules defines properties for internal coupling.
27"""
28
29#-------------------------------------------------------------------------------
30# Library modules import
31#-------------------------------------------------------------------------------
32
33import os, sys, unittest
34
35#-------------------------------------------------------------------------------
36# Application modules import
37#-------------------------------------------------------------------------------
38
39
40from code_saturne.model.Common import *
41from code_saturne.model.XMLvariables import Variables, Model
42from code_saturne.model.XMLmodel import XMLmodel, ModelTest
43
44from code_saturne.model.ThermalScalarModel import ThermalScalarModel
45from code_saturne.model.DefineUserScalarsModel import DefineUserScalarsModel
46from code_saturne.model.NotebookModel import NotebookModel
47
48class InternalCouplingModel(Variables, Model):
49    """
50    Class to manipulate internal coupling parameters in xml file.
51    """
52
53    def __init__(self, case):
54        """Constructor"""
55        self.case = case
56
57        n = self.case.xmlGetNode("thermophysical_models")
58        self.node = n.xmlGetChildNode("internal_coupling")
59        if not self.node:
60            self.node = n.xmlInitChildNode("internal_coupling")
61
62        self.node_zones = self.node.xmlInitChildNode("solid_zones")
63        self.node_scals = self.node.xmlInitChildNode("coupled_scalars")
64
65
66    def addZone(self, zone_name):
67        """Add a coupled zone"""
68
69        self.node_zones.xmlInitChildNode("zone", name=zone_name)
70
71
72    def removeZone(self, zone_name):
73        """Remove a zone from the coupled list"""
74
75        n = self.node_zones.xmlGetChildNode("zone", name=zone_name)
76        if n:
77            n.xmlRemoveNode()
78
79
80    def getZonesList(self):
81        """Get list of coupled zones."""
82
83        lst = []
84        for n in self.node_zones.xmlGetChildNodeList("zone"):
85            lst.append(n['name'])
86
87        return lst
88
89
90    def addScalar(self, scalar_name):
91        """Add a coupled scalar"""
92
93        self.node_scals.xmlInitChildNode("scalar", name=scalar_name)
94
95
96    def removeScalar(self, scalar_name):
97        """Remove a scalar from the coupled list"""
98        n = self.node_scals.xmlGetChildNode("scalar", name=scalar_name)
99        if n:
100            n.xmlRemoveNode()
101
102
103    def getScalarsList(self):
104        """Get list of coupled scalars."""
105
106        lst = []
107        for n in self.node_scals.xmlGetChildNodeList("scalar"):
108            lst.append(n['name'])
109
110        return lst
111
112
113    def isScalarCoupled(self, scalar_name):
114        """Check if a scalar is coupled."""
115
116        retval = False
117        if scalar_name in self.getScalarsList():
118            retval = True
119
120        return retval
121
122    def getListOfAvailableScalars(self):
123        """Get list of scalars which may be coupled"""
124
125        lst = []
126
127        thm = ThermalScalarModel(self.case)
128        thermal = thm.getThermalScalarName()
129        if thermal and thermal != "":
130            lst.append(thermal)
131
132        scm = DefineUserScalarsModel(self.case)
133        for scalar in scm.getUserScalarNameList():
134            lst.append(scalar)
135
136        return lst
137