Salome HOME
TypeInstance and basestring
[tools/eficas.git] / boundary_conditions / generator_boundary_conditions.py
1 #  Copyright (C) 2012-2013 EDF
2 #
3 #  This file is part of SALOME HYDRO module.
4 #
5 #  SALOME HYDRO module is free software: you can redistribute it and/or modify
6 #  it under the terms of the GNU General Public License as published by
7 #  the Free Software Foundation, either version 3 of the License, or
8 #  (at your option) any later version.
9 #
10 #  SALOME HYDRO module is distributed in the hope that it will be useful,
11 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
12 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 #  GNU General Public License for more details.
14 #
15 #  You should have received a copy of the GNU General Public License
16 #  along with SALOME HYDRO module.  If not, see <http://www.gnu.org/licenses/>.
17
18 import os
19 from generator.generator_python import PythonGenerator
20
21 def entryPoint():
22   return {'name': 'boundary_conditions',
23           'factory': BoundaryConditionsGenerator}
24
25 class BoundaryConditionsGenerator(PythonGenerator):
26   """
27   This generator creates files containing associations between groups and
28   boundary conditions (.bcd files, for Boundary Conditions Definition).
29   Those files contain one line per group, each line containing four fields
30   separated by spaces: LIHBOR LIUBOR LIVBOR GROUP.
31   LIHBOR, LIUBOR and LIVBOR are integer values, GROUP is a string (the name of
32   the group).
33   
34   Example:
35   
36   
37   """
38
39   def gener(self, obj, format = 'brut', config = None):
40     self.group_list = []
41     self.text = PythonGenerator.gener(self, obj, format)
42     return self.text
43   
44   def generPROC_ETAPE(self, obj):
45     group_dict = {}
46     for keyword in obj.mc_liste:
47       group_dict[keyword.nom] = keyword.valeur
48     self.group_list.append(group_dict)
49     return PythonGenerator.generPROC_ETAPE(self, obj)
50
51   def writeDefault(self, basefilename):
52     output_filename = os.path.splitext(basefilename)[0] + ".bcd"
53     f = open(output_filename, 'w')
54     f.write("%d\n" % len(self.group_list))
55     for group_dict in self.group_list:
56       f.write("%(LIHBOR)d %(LIUBOR)d %(LIVBOR)d %(GROUP)s\n" % group_dict)
57     f.close()