9 #include "ExampleProgram.H"
10 #include "ExampleHeader.H"
14 namespace ElmerFoamFSI {
16 namespace ExampleProgram {
18 int ParallelProgram::Run()
26 int myid = _communicator.Rank();
27 int nproc = _communicator.Size();
28 bool use_file = !output_name.empty();
36 std::ostringstream RepStr;
38 RepStr <<
"Running on " << nproc <<
" processors." << std::endl;
40 _communicator.Barrier();
42 StdOut(
"All procesors ready.\n");
45 if(use_file && !myid){
46 Ouf.open(output_name.c_str(),std::ios::app);
50 std::ostringstream Ostr;
51 Ostr <<
"Error: Unable to open output file, " << output_name <<
".";
58 _communicator.SetExit(1);
64 if(_communicator.Check()){
72 double PIVAL = 3.141592653589793238462643383;
77 FunctionEntry(
"Broadcast");
78 _communicator.BroadCast(ndiv,0);
79 FunctionExit(
"Broadcast");
84 int nper = ndiv/nproc;
85 int nvol = nper*nproc;
86 int leftover = ndiv - nvol;
91 for(
int i = 0; i < myid;i++){
100 if(myid == 0) myn = ndiv;
107 double h = 1.0/(
static_cast<double>(ndiv));
108 double a = h*mystart;
109 double b = a + h*myn;
112 FunctionEntry(
"TrapezoidMethod");
116 FunctionEntry(
"TrapezoidQuadrature");
118 FunctionExit(
"TrapezoidQuadrature");
120 StdOut(
"Numerical limits of ElmerFoamFSI::TrapezoidQuadrature exceeded.");
127 FunctionEntry(
"Reduce");
128 _communicator.Reduce(my_tpi, tpi,IRAD::Comm::DTDOUBLE, IRAD::Comm::SUMOP, 0);
129 FunctionExit(
"Reduce");
130 FunctionExit(
"TrapezoidMethod");
133 FunctionEntry(
"MidPointMethod");
134 double my_mppi = 0.0;
137 FunctionEntry(
"MidPointQuadrature");
139 FunctionExit(
"MidPointQuadrature");
141 StdOut(
"Numerical limits of ElmerFoamFSI::MidPointQuadrature exceeded.");
148 FunctionEntry(
"Reduce");
149 _communicator.Reduce(my_mppi, mppi,IRAD::Comm::DTDOUBLE, IRAD::Comm::SUMOP, 0);
150 FunctionExit(
"Reduce");
151 FunctionExit(
"MidPointMethod");
157 Ouf << ndiv <<
" " << std::setprecision(16) << tpi <<
" "
158 << std::setprecision(4) << std::fabs(tpi-PIVAL) <<
" "
159 << std::setprecision(16) << mppi <<
" "
160 << std::setprecision(4) << std::fabs(mppi-PIVAL) <<
" "
165 std::ostringstream Ostr;
166 Ostr <<
"With " << ndiv <<
" divisions, PI was calculated:" << std::endl
167 <<
"MidPointQuadrature: "
168 << std::setprecision(16) << mppi <<
"\t\t"
169 << std::setprecision(4) << std::fabs(mppi - PIVAL) << std::endl
170 <<
"TrapezoidQuadrature: "
171 << std::setprecision(16) << tpi <<
"\t\t"
172 << std::setprecision(4) << std::fabs(tpi - PIVAL) << std::endl;
double MidPointQuadrature(double(*f)(double), double x0, double xn, int n)
Integrates f with composite midpoint rule.
double TrapezoidQuadrature(double(*f)(double), double x0, double xn, int n)
Integrates f with composite trapezoid rule.