1 #ifndef __ELMER_FOAM_FSI_H__
8 #define __ELMER_FOAM_FSI_H__
9 #ifdef _ELMERFOAMFSI_PARALLEL_
16 namespace ElmerFoamFSI {
54 typedef IRAD::Global::GlobalObj<StackType,int,ProfilerType>
GlobalType;
55 #ifdef _ELMERFOAMFSI_PARALLEL_
56 typedef IRAD::Comm::CommunicatorObject
CommType;
63 typedef IRAD::Global::ParallelGlobalObj<CommType,StackType,int,ProfilerType>
PGlobalType;
77 : IRAD::Util::ComLineObject()
80 : IRAD::Util::ComLineObject(args)
89 AddOption(
'h',
"help");
90 AddOption(
'd',
"debug");
91 AddOption(
'v',
"verbosity",1);
92 AddOption(
'o',
"output",2,
"filename");
94 AddHelp(
"help",
"Prints this long version of help.");
95 AddHelp(
"debug",
"Turns on debugging output.");
96 AddHelp(
"output",
"Specifies the name of the output file.");
97 AddArgument(
"inputfile",1);
98 std::ostringstream Ostr;
99 Ostr <<
"A configuration file with parameters.";
102 AddArgHelp(
"inputfile",Ostr.str());
111 Ostr <<
"Example ElmerFoamFSI program.";
112 _description.assign(Ostr.str());
127 #ifdef _ELMERFOAMFSI_PARALLEL_
128 typedef IRAD::Global::Program<PGlobalType,ComLineType> ParallelProgramType;
209 args_dupe =
new char * [3];
210 args_dupe[0] =
const_cast<char *
>(
"test");
211 args_dupe[1] =
const_cast<char *
>(
"-com-mpi");
213 COM_init(&nargs_dupe,&args_dupe);
220 int retval = SerialProgramType::Initialize();
221 if(!_command_line.GetOption(
"help").empty()){
222 std::ostringstream Ostr;
223 Ostr << _command_line.LongUsage() << std::endl;
228 std::ostringstream Ostr;
229 Ostr << _command_line.ErrorReport() << std::endl
230 << std::endl << _command_line.ShortUsage() << std::endl;
234 if(!_command_line.GetOption(
"debug").empty()){
235 this->SetDebugLevel(2);
236 this->SetDebugStream(std::cout);
242 std::vector<std::string> args(_command_line.GetArgs());
246 std::string sverb(_command_line.GetOption(
"verbosity"));
247 if(sverb.empty() || sverb ==
".true.")
250 std::istringstream Vin(sverb);
261 std::ostringstream Ostr;
262 Ostr <<
"Configuration:" << std::endl
263 <<
"verbosity = " << verblevel << std::endl
264 <<
"config file = " << input_name << std::endl;
266 Ostr <<
"output file = " <<
output_name << std::endl;
281 if(COM_initialized())
286 SetOutStream(std::cout);
296 #ifdef _ELMERFOAMFSI_PARALLEL_
297 class ParallelDriverProgram :
public ParallelProgramType
369 std::string output_name;
371 std::string input_name;
379 int fluidsInitHandle;
383 int fluidsStepHandle;
385 int fluidsFinalizeHandle;
387 int structuresInitHandle;
389 int structuresRunHandle;
391 int structuresFinalizeHandle;
400 ParallelDriverProgram() :
401 ParallelProgramType()
406 ParallelDriverProgram(
int nargs,
char **args) :
407 ParallelProgramType(nargs,args), argc(nargs), argv(args)
412 args_dupe =
new char * [3];
413 args_dupe[0] =
const_cast<char *
>(
"dummy");
414 args_dupe[1] =
const_cast<char *
>(
"-com-mpi");
416 COM_init(&nargs_dupe,&args_dupe);
425 this->_command_line.Copy(comline);
426 this->Init(_command_line.ProgramName(),incomm);
432 virtual int Initialize()
434 int retval = ParallelProgramType::Initialize();
436 if(!_command_line.GetOption(
"help").empty()){
437 std::ostringstream Ostr;
438 Ostr << _command_line.LongUsage() << std::endl;
443 std::ostringstream Ostr;
444 Ostr << _command_line.ErrorReport() << std::endl
445 << std::endl << _command_line.ShortUsage() << std::endl;
450 if(!_command_line.GetOption(
"debug").empty()){
451 this->SetDebugLevel(2);
452 this->SetDebugStream(std::cout);
456 output_name = _command_line.GetOption(
"output");
459 std::vector<std::string> args(_command_line.GetArgs());
460 input_name = args[0];
463 std::string sverb(_command_line.GetOption(
"verbosity"));
464 if(sverb.empty() || sverb ==
".true.")
467 std::istringstream Vin(sverb);
474 SetVerbLevel((
char)verblevel);
478 std::ostringstream Ostr;
479 Ostr <<
"*****************************************************"<< std::endl;
480 Ostr <<
"* Reading the input file *"<< std::endl;
481 Ostr <<
"*****************************************************"<< std::endl;
482 Ostr <<
"* Configuration:" << std::endl
483 <<
"* verbosity = " << verblevel << std::endl;
484 if(!input_name.empty())
485 Ostr <<
"* input file = " << input_name << std::endl;
486 if(!output_name.empty())
487 Ostr <<
"* output file = " << output_name << std::endl;
488 Ostr <<
"*" << std::endl;
489 Ostr <<
"*****************************************************"<< std::endl;
498 int VerbLevel()
const {
return verblevel;};
502 virtual ~ParallelDriverProgram() {
503 if(COM_initialized())
507 SetOutStream(std::cout);
528 template<
typename ProgramType>
535 MyProgram.ErrOut(
"Error in Program Initialization.\n");
541 MyProgram.StdOut(
"Calling RUN.\n");
543 MyProgram.ErrOut(
"Error in Program RUN method.\n");
547 std::ostringstream Ostr;
548 MyProgram.Report(Ostr);
549 MyProgram.StdOut(Ostr.str());
550 MyProgram.StdOut(
"Calling Finalize.\n");
552 if(MyProgram.Finalize()){
553 MyProgram.ErrOut(
"Error in Program Finalization.\n");
557 MyProgram.StdOut(
"All done.\n");
566 #ifdef _ELMERFOAMFSI_PARALLEL_
567 inline double f(
double x)
579 return (4.0 / (1.0 + x*x));
584 typedef ElmerFoamFSI::ParallelDriverProgram PEProgramType;
int structuresInitHandle
Handle/identifier for structures init.
IRAD::Global::GlobalObj< StackType, int, ProfilerType > GlobalType
Convenience type definition for the serial global object.
char ** argv
Object-local copy for argv.
The ComLineObject for the example programs.
int fluidsRunHandle
Handle/identifier for fluids run.
DriverComLine(const char *args[])
int DriverRun()
This function implements the main function executed by the program.
ElmerFoamFSI::SerialDriverProgram DriverProgramType
Convenience definition for serial program type.
std::string input_name
Name of input file.
std::string StackType
Convenience type definition for program stack.
DriverComLine ComLineType
Convenience type definition for the example comline object.
int structuresFinalizeHandle
Handle/identifier for structures finalize.
int fluidsStepHandle
Handle/identifier for fluids step.
std::ofstream Ouf
Outfile stream for output.
int fluidsFinalizeHandle
Handle/identifier for fluids finalize.
virtual ~SerialDriverProgram()
Destructor.
Implementation of the basic parts of the serial program example.
std::string output_name
Name of file for output.
int verblevel
Verbosity level.
IRAD::Profiler::ProfilerObj ProfilerType
Encapsulate example program-specific code constructs.
int argc
Object-local copy for argc.
int structuresRunHandle
Handle/identifier for structures run.
IRAD::Comm::CommunicatorObject CommType
Convenience typedef for CommunicatorObject.
SerialDriverProgram()
Default constructor.
virtual int Initialize()
Initializes native data structures from commandline args.
int Driver(int argc, char *argv[])
Unified driver for the example programs.
int fluidsInitHandle
Handle/identifier for fluids init.
IRAD::Global::ParallelGlobalObj< CommTypeIrad, StackType, int, ProfilerType > PGlobalType
int VerbLevel() const
Returns verbosity level.
IRAD::Global::Program< GlobalType, ComLineType > SerialProgramType
Convenience type definition for the serial program.
SerialDriverProgram(int nargs, char **args)
Constructor designed to take the commandline args.
void Initialize()
This is where the actual options and arguments are described.
std::ifstream Inf
Infile stream for input.