2
This file is part of Code_Saturne, a general-purpose CFD tool.
4
Copyright (C) 1998-2011 EDF S.A.
6
This program is free software; you can redistribute it and/or modify it under
7
the terms of the GNU General Public License as published by the Free Software
8
Foundation; either version 2 of the License, or (at your option) any later
11
This program is distributed in the hope that it will be useful, but WITHOUT
12
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
16
You should have received a copy of the GNU General Public License along with
17
this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
18
Street, Fifth Floor, Boston, MA 02110-1301, USA.
21
/*----------------------------------------------------------------------------*/
23
#include "FSI_MILIEU.hxx"
27
#include <Calcium.hxx>
28
#include <CalciumException.hxx>
31
#include <SALOME_NamingService.hxx>
32
#include <Utils_SALOME_Exception.hxx>
36
typedef void (*sighandler_t)(int);
37
sighandler_t setsig(int sig, sighandler_t handler)
39
struct sigaction context, ocontext;
40
context.sa_handler = handler;
41
sigemptyset(&context.sa_mask);
43
if (sigaction(sig, &context, &ocontext) == -1)
45
return ocontext.sa_handler;
48
static void AttachDebugger()
55
size = backtrace (array, size);
56
strings = backtrace_symbols (array, size);
57
for (i = 0; i < size; i++)
58
_what=_what+strings[i]+ '\n';
61
std::cerr << pthread_self() << std::endl;
62
std::cerr << _what << std::endl;
64
if(getenv ("DEBUGGER"))
66
std::stringstream exec;
68
exec << "$DEBUGGER " << "None " << getpid() << "&";
70
exec << "$DEBUGGER SALOME_Container " << getpid() << "&";
72
std::cerr << exec.str() << std::endl;
73
system(exec.str().c_str());
78
static void THandler(int theSigId)
80
std::cerr << "SIGSEGV: " << std::endl;
82
//to exit or not to exit
86
static void terminateHandler(void)
88
std::cerr << "Terminate: not managed exception !" << std::endl;
90
throw SALOME_Exception("Terminate: not managed exception !");
93
static void unexpectedHandler(void)
95
std::cerr << "Unexpected: unexpected exception !" << std::endl;
97
throw SALOME_Exception("Unexpected: unexpected exception !");
103
#define F_FUNC(lname,uname) __stdcall uname
104
#define F_CALL(lname,uname) uname
105
#define STR_PSTR(str) char *str, int _(Len,str)
106
#define STR_PLEN(str)
107
#define STR_PTR(str) str
108
#define STR_LEN(str) _(Len,str)
109
#define STR_CPTR(str) str,strlen(str)
110
#define STR_CLEN(str)
112
#define F_FUNC(lname,uname) _(lname,_) /* Fortran function name */
113
#define F_CALL(lname,uname) _(lname,_) /* Fortran function call */
114
#define STR_PSTR(str) char *str /* fortran string arg pointer */
115
#define STR_PLEN(str) , int _(Len,str) /* fortran string arg length */
116
#define STR_PTR(str) str /* fortran string pointer */
117
#define STR_LEN(str) _(Len,str) /* fortran string length */
118
#define STR_CPTR(str) str /* fortran string calling arg pointer */
119
#define STR_CLEN(str) , strlen(str) /* fortran string calling arg length */
123
#include <runmilieu.h>
129
extern "C" void cp_exit(int err);
131
extern "C" void F_FUNC(cpexit,CPEXIT)(int *err)
141
//! Constructor for component "FSI_MILIEU" instance
145
FSI_MILIEU_i::FSI_MILIEU_i(CORBA::ORB_ptr orb,
146
PortableServer::POA_ptr poa,
147
PortableServer::ObjectId * contId,
148
const char *instanceName,
149
const char *interfaceName)
150
: Superv_Component_i(orb, poa, contId, instanceName, interfaceName)
153
setsig(SIGSEGV,&THandler);
154
set_terminate(&terminateHandler);
155
set_unexpected(&unexpectedHandler);
158
_id = _poa->activate_object(_thisObj);
161
FSI_MILIEU_i::FSI_MILIEU_i(CORBA::ORB_ptr orb,
162
PortableServer::POA_ptr poa,
163
Engines::Container_ptr container,
164
const char *instanceName,
165
const char *interfaceName)
166
: Superv_Component_i(orb, poa, container, instanceName, interfaceName)
169
setsig(SIGSEGV,&THandler);
170
set_terminate(&terminateHandler);
171
set_unexpected(&unexpectedHandler);
174
_id = _poa->activate_object(_thisObj);
177
//! Destructor for component "FSI_MILIEU" instance
178
FSI_MILIEU_i::~FSI_MILIEU_i()
182
void FSI_MILIEU_i::destroy()
186
if(!CORBA::is_nil(_orb))
189
Engines_Component_i::destroy();
193
//! Register datastream ports for a component service given its name
195
* \param service_name : service name
196
* \return true if port registering succeeded, false if not
199
FSI_MILIEU_i::init_service(const char * service_name) {
200
CORBA::Boolean rtn = false;
201
string s_name(service_name);
203
if (s_name == "inter_run")
207
//initialization CALCIUM ports IN
208
create_calcium_port(this,(char *)"ALMAXI",(char *)"CALCIUM_double",(char *)"IN",(char *)"I");
209
create_calcium_port(this,(char *)"DTSAT",(char *)"CALCIUM_double",(char *)"IN",(char *)"I");
210
create_calcium_port(this,(char *)"DTAST",(char *)"CALCIUM_double",(char *)"IN",(char *)"I");
211
create_calcium_port(this,(char *)"DEPAST",(char *)"CALCIUM_double",(char *)"IN",(char *)"I");
212
create_calcium_port(this,(char *)"VITAST",(char *)"CALCIUM_double",(char *)"IN",(char *)"I");
213
create_calcium_port(this,(char *)"FORSAT",(char *)"CALCIUM_double",(char *)"IN",(char *)"I");
214
create_calcium_port(this,(char *)"DONGEO",(char *)"CALCIUM_integer",(char *)"IN",(char *)"I");
215
create_calcium_port(this,(char *)"ICV",(char *)"CALCIUM_integer",(char *)"IN",(char *)"I");
216
//initialization CALCIUM ports OUT
217
create_calcium_port(this,(char *)"DTCALC",(char *)"CALCIUM_double",(char *)"OUT",(char *)"I");
218
create_calcium_port(this,(char *)"EPSILO",(char *)"CALCIUM_double",(char *)"OUT",(char *)"I");
219
create_calcium_port(this,(char *)"TTINIT",(char *)"CALCIUM_double",(char *)"OUT",(char *)"I");
220
create_calcium_port(this,(char *)"PDTREF",(char *)"CALCIUM_double",(char *)"OUT",(char *)"I");
221
create_calcium_port(this,(char *)"DEPSAT",(char *)"CALCIUM_double",(char *)"OUT",(char *)"I");
222
create_calcium_port(this,(char *)"FORAST",(char *)"CALCIUM_double",(char *)"OUT",(char *)"I");
223
create_calcium_port(this,(char *)"NBPDTM",(char *)"CALCIUM_integer",(char *)"OUT",(char *)"I");
224
create_calcium_port(this,(char *)"NBSSIT",(char *)"CALCIUM_integer",(char *)"OUT",(char *)"I");
225
create_calcium_port(this,(char *)"ISYNCP",(char *)"CALCIUM_integer",(char *)"OUT",(char *)"I");
226
create_calcium_port(this,(char *)"NTCHRO",(char *)"CALCIUM_integer",(char *)"OUT",(char *)"I");
227
create_calcium_port(this,(char *)"ICVEXT",(char *)"CALCIUM_integer",(char *)"OUT",(char *)"I");
228
create_calcium_port(this,(char *)"ICVAST",(char *)"CALCIUM_integer",(char *)"OUT",(char *)"I");
229
create_calcium_port(this,(char *)"NB_DYN",(char *)"CALCIUM_integer",(char *)"OUT",(char *)"I");
230
create_calcium_port(this,(char *)"NB_FOR",(char *)"CALCIUM_integer",(char *)"OUT",(char *)"I");
232
catch(const PortAlreadyDefined& ex)
234
std::cerr << "FSI_MILIEU: " << ex.what() << std::endl;
235
//Ports already created : we use them
239
std::cerr << "FSI_MILIEU: unknown exception" << std::endl;
248
void FSI_MILIEU_i::inter_run(CORBA::Long NBPDTM,CORBA::Long NBSSIT,CORBA::Long ISYNCP,CORBA::Long NTCHR,CORBA::Double DTREF,CORBA::Double TTINIT,CORBA::Double EPSILO)
250
beginService("FSI_MILIEU_i::inter_run");
251
Superv_Component_i * component = dynamic_cast<Superv_Component_i*>(this);
252
//char nom_instance[INSTANCE_LEN];
253
//int info = cp_cd(component,nom_instance);
257
inter_cs_ast_set_nbpdtm(NBPDTM);
258
inter_cs_ast_set_nbssit(NBSSIT);
259
inter_cs_ast_set_isyncp(ISYNCP);
260
inter_cs_ast_set_ntchr(NTCHR);
261
inter_cs_ast_set_dtref(DTREF);
262
inter_cs_ast_set_ttinit(TTINIT);
263
inter_cs_ast_set_epsilo(EPSILO);
264
runmilieu(component);
266
//cp_fin(component,CP_ARRET);
268
catch ( const CalciumException & ex)
270
std::cerr << ex.what() << std::endl;
271
//cp_fin(component,CP_ARRET);
272
SALOME::ExceptionStruct es;
273
es.text=CORBA::string_dup(ex.what());
274
es.type=SALOME::INTERNAL_ERROR;
275
throw SALOME::SALOME_Exception(es);
277
catch ( const SALOME_Exception & ex)
279
//cp_fin(component,CP_ARRET);
280
SALOME::ExceptionStruct es;
281
es.text=CORBA::string_dup(ex.what());
282
es.type=SALOME::INTERNAL_ERROR;
283
throw SALOME::SALOME_Exception(es);
285
catch ( const SALOME::SALOME_Exception & ex)
287
//cp_fin(component,CP_ARRET);
290
catch ( const std::exception& ex)
292
//std::cerr << typeid(ex).name() << std::endl;
293
SALOME::ExceptionStruct es;
294
es.text=CORBA::string_dup(ex.what());
295
es.type=SALOME::INTERNAL_ERROR;
296
throw SALOME::SALOME_Exception(es);
300
std::cerr << "unknown exception" << std::endl;
304
//cp_fin(component,CP_ARRET);
305
SALOME::ExceptionStruct es;
306
es.text=CORBA::string_dup(" unknown exception");
307
es.type=SALOME::INTERNAL_ERROR;
308
throw SALOME::SALOME_Exception(es);
310
endService("FSI_MILIEU_i::inter_run");
317
PortableServer::ObjectId * FSI_MILIEUEngine_factory( CORBA::ORB_ptr orb,
318
PortableServer::POA_ptr poa,
319
PortableServer::ObjectId * contId,
320
const char *instanceName,
321
const char *interfaceName)
323
MESSAGE("PortableServer::ObjectId * FSI_MILIEUEngine_factory()");
324
FSI_MILIEU_i * myEngine = new FSI_MILIEU_i(orb, poa, contId, instanceName, interfaceName);
325
return myEngine->getId() ;
331
CORBA::ORB_var orb = CORBA::ORB_init( argc , &argv ) ;
332
PortableServer::POAManager_var pman;
333
CORBA::Object_var obj;
336
SALOME_NamingService * salomens = new SALOME_NamingService(orb);
337
obj = orb->resolve_initial_references("RootPOA");
338
PortableServer::POA_var poa = PortableServer::POA::_narrow(obj);
339
PortableServer::POAManager_var pman = poa->the_POAManager();
340
std::string containerName(getenv("SALOME_CONTAINERNAME"));
341
std::string instanceName(getenv("SALOME_INSTANCE"));
342
obj=orb->string_to_object(getenv("SALOME_CONTAINER"));
343
Engines::Container_var container = Engines::Container::_narrow(obj);
344
FSI_MILIEU_i * myEngine = new FSI_MILIEU_i(orb, poa, container, instanceName.c_str(), "FSI_MILIEU");
346
obj=myEngine->POA_FSI_ORB::FSI_MILIEU::_this();
347
Engines::EngineComponent_var component = Engines::EngineComponent::_narrow(obj);
348
string component_registerName = containerName + "/" + instanceName;
349
salomens->Register(component,component_registerName.c_str());
353
catch(CORBA::Exception&)
355
std::cerr << "Caught CORBA::Exception."<< std::endl;
357
catch(std::exception& exc)
359
std::cerr << "Caught std::exception - "<<exc.what() << std::endl;
363
std::cerr << "Caught unknown exception." << std::endl;
367
void F_FUNC(yacsinit,YACSINIT)()