~ubuntu-branches/ubuntu/precise/code-saturne/precise

« back to all changes in this revision

Viewing changes to salome/fsi_coupling/src/FSI_ASTER/FSI_ASTER_module.py.in

  • Committer: Package Import Robot
  • Author(s): Sylvestre Ledru
  • Date: 2011-11-24 00:00:08 UTC
  • mfrom: (6.1.9 sid)
  • Revision ID: package-import@ubuntu.com-20111124000008-2vo99e38267942q5
Tags: 2.1.0-3
Install a missing file

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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-2011 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
import sys,traceback,os
 
26
import string
 
27
import FSI_ORB__POA
 
28
import calcium
 
29
import dsccalcium
 
30
import SALOME
 
31
import linecache
 
32
 
 
33
# Trick so that one doesn't have to set the PYTHONPATH variable
 
34
cspath = '@pkgpythondir@'
 
35
if os.path.isdir(cspath) and not cspath in sys.path:
 
36
    sys.path.insert(0, cspath)
 
37
 
 
38
import ConfigParser
 
39
from cs_package import package
 
40
 
 
41
config = ConfigParser.ConfigParser()
 
42
pkg = package()
 
43
config.read([pkg.get_configfile(), os.path.expanduser('~/.' + pkg.configfile)])
 
44
 
 
45
# Code_Aster installation directory
 
46
if not config.has_option('install', 'aster'):
 
47
  sys.stderr.write("Cannot locate Code_Aster installation.\n")
 
48
  sys.exit(1)
 
49
else:
 
50
  aster_dir = config.get('install', 'aster')
 
51
 
 
52
# Code_Aster Python library files
 
53
aster_path = os.path.join(aster_dir, 'bibpyt')
 
54
 
 
55
sys.path.insert(0, aster_path)
 
56
 
 
57
from Execution.E_SUPERV import SUPERV
 
58
 
 
59
 
 
60
try:
 
61
  import numpy
 
62
except:
 
63
  numpy=None
 
64
 
 
65
#DEFS
 
66
 
 
67
#ENDDEF
 
68
 
 
69
class ExecutionError(Exception):
 
70
  '''General exception during execution'''
 
71
 
 
72
class FSI_ASTER(FSI_ORB__POA.FSI_ASTER,dsccalcium.PyDSCComponent,SUPERV):
 
73
  '''
 
74
     To be identified as a SALOME component this Python class
 
75
     must have the same name as the component, inherit omniorb
 
76
     class FSI_ORB__POA.FSI_ASTER and DSC class dsccalcium.PyDSCComponent
 
77
     that implements DSC API.
 
78
  '''
 
79
  def __init__ ( self, orb, poa, contID, containerName, instanceName, interfaceName ):
 
80
    self.init=0
 
81
    dsccalcium.PyDSCComponent.__init__(self, orb, poa,contID,containerName,instanceName,interfaceName)
 
82
 
 
83
  def init_service(self,service):
 
84
    if service == "op0117":
 
85
       #initialization CALCIUM ports IN
 
86
       calcium.create_calcium_port(self.proxy,"NB_FOR","CALCIUM_integer","IN","I")
 
87
       calcium.create_calcium_port(self.proxy,"NB_DYN","CALCIUM_integer","IN","I")
 
88
       calcium.create_calcium_port(self.proxy,"COONOD","CALCIUM_double","IN","I")
 
89
       calcium.create_calcium_port(self.proxy,"COOFAC","CALCIUM_double","IN","I")
 
90
       calcium.create_calcium_port(self.proxy,"COLNOD","CALCIUM_integer","IN","I")
 
91
       calcium.create_calcium_port(self.proxy,"COLFAC","CALCIUM_integer","IN","I")
 
92
       calcium.create_calcium_port(self.proxy,"FORAST","CALCIUM_double","IN","I")
 
93
       calcium.create_calcium_port(self.proxy,"NBPDTM","CALCIUM_integer","IN","I")
 
94
       calcium.create_calcium_port(self.proxy,"NBSSIT","CALCIUM_integer","IN","I")
 
95
       calcium.create_calcium_port(self.proxy,"EPSILO","CALCIUM_double","IN","I")
 
96
       calcium.create_calcium_port(self.proxy,"ICVAST","CALCIUM_integer","IN","I")
 
97
       calcium.create_calcium_port(self.proxy,"ISYNCP","CALCIUM_integer","IN","I")
 
98
       calcium.create_calcium_port(self.proxy,"NTCHRO","CALCIUM_integer","IN","I")
 
99
       calcium.create_calcium_port(self.proxy,"TTINIT","CALCIUM_double","IN","I")
 
100
       calcium.create_calcium_port(self.proxy,"PDTREF","CALCIUM_double","IN","I")
 
101
       calcium.create_calcium_port(self.proxy,"DTCALC","CALCIUM_double","IN","I")
 
102
       #initialization CALCIUM ports OUT
 
103
       calcium.create_calcium_port(self.proxy,"DEPAST","CALCIUM_double","OUT","I")
 
104
       calcium.create_calcium_port(self.proxy,"VITAST","CALCIUM_double","OUT","I")
 
105
       calcium.create_calcium_port(self.proxy,"DTAST","CALCIUM_double","OUT","I")
 
106
       return True
 
107
    return False
 
108
 
 
109
  def interpstring(self,text,args):
 
110
    try:
 
111
      self.jdc.g_context.update(args)
 
112
      CONTEXT.set_current_step(self.jdc)
 
113
      linecache.cache['<string>']=0,None,string.split(text,'\n'),'<string>'
 
114
      exec text in self.jdc.const_context,self.jdc.g_context
 
115
      CONTEXT.unset_current_step()
 
116
    except EOFError:
 
117
      CONTEXT.unset_current_step()
 
118
    except:
 
119
      CONTEXT.unset_current_step()
 
120
      raise
 
121
 
 
122
 
 
123
  def op0117(self,jdc):
 
124
    self.beginService("FSI_ASTER.op0117")
 
125
    try:
 
126
      args={"jdc":jdc,"component":self.proxy.ptr()}
 
127
      if not args.has_key("jdc"):
 
128
        fcomm=open("jdc",'r')
 
129
        jdc=fcomm.read()
 
130
        fcomm.close()
 
131
        #args["jdc"]=jdc
 
132
      if not self.init:
 
133
        self.init=1
 
134
        fcomm=open("fort.1",'w')
 
135
        fcomm.write(jdc)
 
136
        fcomm.close()
 
137
        ier=self.main(args)
 
138
        if ier != 0:
 
139
          raise ExecutionError("Error in initial execution")
 
140
      else:
 
141
        self.interpstring(jdc,args)
 
142
 
 
143
      self.endService("FSI_ASTER.op0117")
 
144
      j=self.jdc
 
145
      return
 
146
    except:
 
147
      exc_typ,exc_val,exc_fr=sys.exc_info()
 
148
      l=traceback.format_exception(exc_typ,exc_val,exc_fr)
 
149
      self.endService("FSI_ASTER.op0117")
 
150
      sys.stdout.flush()
 
151
      sys.stderr.flush()
 
152
      raise SALOME.SALOME_Exception(SALOME.ExceptionStruct(SALOME.BAD_PARAM,"".join(l),"FSI_ASTER.py",0))
 
153
 
 
154
 
 
155
  def destroy(self):
 
156
     self._orb.shutdown(0)