Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GridConversion Namespace Reference

Project-specific namespace. More...

Namespaces

 DriverProgram
 Encapsulate GridConversion-specific code constructs.
 
 ExampleProgram
 Encapsulate example program-specific code constructs.
 
 TestFixture
 Namespace for storing simple test utility fixtures.
 

Classes

class  TestingObject
 Project-specific testing object. More...
 
class  TestComLine
 ComLineObject for GridConversion testing command-line interface. More...
 

Typedefs

typedef IRAD::Util::TestResults TestResults
 Project-specific test results type. More...
 
typedef
IRAD::Comm::CommunicatorObject 
CommType
 Convenience typedef for CommunicatorObject. More...
 

Functions

std::string ExampleFunction (const std::string &instring)
 Example function for GridConversion (this is a brief description). More...
 
double TrapezoidQuadrature (double(*f)(double), double x0, double xn, int n)
 Integrates f with composite trapezoid rule. More...
 
double MidPointQuadrature (double(*f)(double), double x0, double xn, int n)
 Integrates f with composite midpoint rule. More...
 
bool Excluded (const std::string &filename)
 Exclude certain template files from conversion in project creation. More...
 
int MakeProject (int argc, char *argv[])
 Creates a new project from an GridConversion base. More...
 
int ParallelTest (int argc, char *argv[])
 Drives the GridConversion::TestObject. More...
 
int Test (int argc, char *argv[])
 Drives the GridConversion::TestObject. More...
 

Detailed Description

Project-specific namespace.

Every project needs its own namespace. This helps make it much easier to deal with in integrated/composite software packages.

Typedef Documentation

typedef IRAD::Comm::CommunicatorObject CommType

Convenience typedef for CommunicatorObject.

Definition at line 20 of file ParallelTestGridConversion.C.

typedef IRAD::Util::TestResults TestResults

Project-specific test results type.

Test results types can be custom implemented by the project developer. The requirement is that they produce the proper test results output when used with outstreams.

Definition at line 41 of file GridConversionTest.H.

Function Documentation

std::string ExampleFunction ( const std::string &  instring)

Example function for GridConversion (this is a brief description).

Parameters
instringInput string to copy
Returns
A copy of the input string
Bug:
No known bugs.
Note
All of this documentation is generated from the comments in ExampleHeader.H
The first sentence in a doxygen comment block before a code construct is interpreted as the "brief" description.
Warning
This is an example warning.
Todo:
Nothing to do on this example function.

The detailed description for ExampleFunction actually starts above with the constructs describing the input/output, and any notes, warnings, todo, bugs, author, or other information the author would like to put in.

At IR, we like for all code constructs to have a "brief" description -first sentence in this comment block, and then a "detailed" description as needed, but it should at least list the input params and output description. The actual example detailed documentation for this function now follows:

This function returns a copy of the input string. If there were more to say about this, then it can be said here.

Definition at line 31 of file ExampleSourceFile.C.

Referenced by TestingObject< ResultsType >::Test__ExampleFunction().

32  {
33  return(instring);
34  };

Here is the caller graph for this function:

bool GridConversion::Excluded ( const std::string &  filename)

Exclude certain template files from conversion in project creation.

Definition at line 25 of file MakeProject.C.

References x.

Referenced by MakeProject().

26  {
27  std::string::size_type x = filename.find("IR.dox");
28  if(x != std::string::npos)
29  return(true);
30  x = filename.find("MakeProject.dox");
31  if(x != std::string::npos)
32  return(true);
33  x = filename.find("ExistingProject.dox");
34  if(x != std::string::npos)
35  return(true);
36  return(false);
37  }
void int int REAL * x
Definition: read.cpp:74

Here is the caller graph for this function:

int GridConversion::MakeProject ( int  argc,
char *  argv[] 
)

Creates a new project from an GridConversion base.

This program is designed to make a new IllinoisRocstar software project starting from an intallation of the GridConversion project template.

Usage of this program should go like the following:

  1. Get and Install the GridConversion template.

    svn co $IRREPO/GridConversion/trunk GridConversion
    mkdir gridconversion_build
    cd gridconversion_build
    cmake ../GridConversion
    make
    cd ../

  2. Create the new project, <NewProject>, with the "make_project" command.

    gridconversion_build/bin/make_project GridConversion <NewProject>

Note
Be sure to replace <NewProject> with your new project name.

The usage for the make_project command is:

make_project usage:
make_project <template name> <new project> [verb level]
This program will read the project template from the <template name>
directory and create a new "blank" IllinoisRocstar project
named <new name>, in a directory named <new name>.
An optional verblevel of 1 or 2 can be given to make the process
more verbose.

Definition at line 77 of file MakeProject.C.

References CreateDirectory(), Excluded(), FILEEXISTS(), n, v, and x.

Referenced by main().

78  {
79  if(argc < 3){
80  std::cout << "Usage:" << std::endl << std::endl
81  << argv[0] << " <template name> <new name> [verb level]" << std::endl
82  << std::endl
83  << "This program will read the project template from the <template name> "
84  << std::endl
85  << "directory and create a new \"blank\" IllinoisRocstar project"
86  << std::endl
87  << "named <new name>, in a directory named <new name>."
88  << std::endl
89  << "An optional verblevel of 1 or 2 can be given to make the process"
90  << std::endl << "more verbose." << std::endl;
91  return(0);
92  }
93  std::string OriginalName(argv[1]);
94  std::string NewName(argv[2]);
95  int verb = 0;
96  if(argv[3]){
97  verb = 1;
98  int v = atoi(argv[3]);
99  if(v > 0)
100  verb = v;
101  }
102  std::vector<std::string> ProtectedFiles;
103  ProtectedFiles.push_back("AUTHORS");
104  ProtectedFiles.push_back("CTestConfig.cmake");
105  ProtectedFiles.push_back("LICENSE");
106  ProtectedFiles.push_back(".svn");
107  std::vector<std::string> CommonFiles;
108  CommonFiles.push_back("CMakeLists.txt");
109  int syserr = 0;
110  std::string olower(OriginalName);
111  std::string oupper(OriginalName);
112  std::string nlower(NewName);
113  std::string nupper(NewName);
114  std::transform(olower.begin(),olower.end(),olower.begin(),tolower);
115  std::transform(oupper.begin(),oupper.end(),oupper.begin(),toupper);
116  std::transform(nlower.begin(),nlower.end(),nlower.begin(),tolower);
117  std::transform(nupper.begin(),nupper.end(),nupper.begin(),toupper);
118 
119  if(verb)
120  std::cout << "Creating a new project (" << NewName
121  << ") from project template (" << OriginalName
122  << ")." << std::endl << std::endl
123  << "Creating top level project directories...";
124  std::string dirname(NewName);
125  if(!IRAD::Sys::FILEEXISTS(NewName)){
126  if(verb > 1)
127  std::cout << " Creating directory " << dirname << "...";
128  syserr = IRAD::Sys::CreateDirectory(dirname);
129  if(syserr){
130  std::cout << "Unable to create directory " << dirname << "."
131  << std::endl;
132  return(1);
133  }
134  if(verb > 1)
135  std::cout << "done." << std::endl;
136  }
137  dirname += "/branches";
138  if(!IRAD::Sys::FILEEXISTS(dirname)){
139  if(verb > 1)
140  std::cout << " Creating directory " << dirname << "...";
141  syserr = IRAD::Sys::CreateDirectory(dirname);
142  if(syserr){
143  std::cout << "Unable to create directory " << dirname << "."
144  << std::endl;
145  return(1);
146  }
147  if(verb > 1)
148  std::cout << "done." << std::endl;
149  }
150  dirname = NewName+"/tags";
151  if(!IRAD::Sys::FILEEXISTS(dirname)){
152  if(verb > 1)
153  std::cout << " Creating directory " << dirname << "...";
154  syserr = IRAD::Sys::CreateDirectory(dirname);
155  if(syserr){
156  std::cout << "Unable to create directory " << dirname << "."
157  << std::endl;
158  return(1);
159  }
160  if(verb > 1)
161  std::cout << "done." << std::endl;
162  }
163  dirname.assign(NewName+"/examples");
164  if(!IRAD::Sys::FILEEXISTS(dirname)){
165  if(verb > 1)
166  std::cout << " Creating directory " << dirname << "...";
167  syserr = IRAD::Sys::CreateDirectory(dirname);
168  if(syserr){
169  std::cout << "Unable to create directory " << dirname << "."
170  << std::endl;
171  return(1);
172  }
173  if(verb > 1)
174  std::cout << "done." << std::endl;
175  }
176  bool protect_svn = false;
177  dirname = NewName+"/trunk";
178  std::vector<std::string>::iterator pfi = ProtectedFiles.begin();
179  while(pfi != ProtectedFiles.end()){
180  std::string ProtectThisFile(dirname+"/"+*pfi++);
181  std::string ProtectedFile(ProtectThisFile+".backup");
182  if(IRAD::Sys::FILEEXISTS(ProtectThisFile))
183  IRAD::Sys::Rename(ProtectThisFile,ProtectedFile);
184  }
185  pfi = CommonFiles.begin();
186  while(pfi != CommonFiles.end()){
187  std::string ProtectThisFile(dirname+"/"+*pfi++);
188  std::string ProtectedFile(ProtectThisFile+".backup");
189  if(IRAD::Sys::FILEEXISTS(ProtectThisFile))
190  IRAD::Sys::Rename(ProtectThisFile,ProtectedFile);
191  }
192  std::ostringstream ComStr;
193  if(!IRAD::Sys::FILEEXISTS(dirname)){
194  if(verb > 1)
195  std::cout << " Creating directory " << dirname << "...";
196  ComStr << "cp -r " << OriginalName << " " << dirname;
197  } else {
198  if(verb > 1)
199  std::cout << " Making project files from template ...";
200  ComStr << "cp -r " << OriginalName << "/* " << dirname;
201  }
202  IRAD::Sys::InProcess System(ComStr.str());
203  std::string comline;
204  while(std::getline(System,comline)){
205  if(verb > 1)
206  std::cout << comline << std::endl;
207  }
208  if(verb)
209  std::cout << "done." << std::endl;
210  if(verb)
211  std::cout << "Cleaning up ...";
212  ComStr.str("");
213  ComStr << "rm -rf " << dirname << "/.svn";
214  System.Execute(ComStr.str());
215  int n = 0;
216  while(std::getline(System,comline))
217  n++;
218  pfi = ProtectedFiles.begin();
219  while(pfi != ProtectedFiles.end()){
220  std::string ProtectThisFile(dirname+"/"+*pfi++);
221  std::string ProtectedFile(ProtectThisFile+".backup");
222  if(IRAD::Sys::FILEEXISTS(ProtectedFile)){
223  if(IRAD::Sys::FILEEXISTS(ProtectThisFile))
224  IRAD::Sys::Remove(ProtectThisFile);
225  IRAD::Sys::Rename(ProtectedFile,ProtectThisFile);
226  }
227  }
228  pfi = CommonFiles.begin();
229  while(pfi != CommonFiles.end()){
230  std::string ProtectThisFile(dirname+"/"+*pfi++);
231  std::string ProtectedFile(ProtectThisFile+".backup");
232  std::string CommonFileTemplate(ProtectThisFile+".template");
233  if(IRAD::Sys::FILEEXISTS(ProtectedFile)){
234  if(IRAD::Sys::FILEEXISTS(ProtectThisFile))
235  IRAD::Sys::Rename(ProtectThisFile,CommonFileTemplate);
236  IRAD::Sys::Rename(ProtectedFile,ProtectThisFile);
237  }
238  }
239  if(verb)
240  std::cout << "done." << std::endl;
241  if(verb > 1)
242  std::cout << "Done creating new project files."
243  << std::endl;
244  if(verb)
245  std::cout << "Renaming project...";
246  if(IRAD::Sys::ChDir(dirname)){
247  std::cout << "Something went wrong, cannot find new project directory."
248  << std::endl;
249  return(1);
250  }
251  ComStr.str("");
252  ComStr << "grep -i " << OriginalName << " -r * | cut -d \":\" -f 1 | sort | uniq";
253  if(verb > 1)
254  std::cout << " " << ComStr.str() << std::endl;
255  System.Execute(ComStr.str());
256  std::vector<std::string> filenames;
257  if(verb > 1)
258  std::cout << " Files to change:" << std::endl;
259  while(std::getline(System,comline)){
260  if(!Excluded(comline)){
261  filenames.push_back(comline);
262  if(verb > 1)
263  std::cout << " " << comline << std::endl;
264  }
265  }
266  std::vector<std::string>::iterator fni = filenames.begin();
267  if(verb > 1)
268  std::cout << " Processing files....";
269  while(fni != filenames.end()){
270  std::string filename(*fni++);
271  if(verb > 1)
272  std::cout << " File: " << filename << std::endl;
273  ComStr.str("");
274  ComStr << "sed -i 's/" << OriginalName << "/" << NewName << "/g' " << filename;
275  if(verb > 1)
276  std::cout << " " << ComStr.str() << std::endl;
277  System.Execute(ComStr.str());
278  int n = 0;
279  while(std::getline(System,comline))
280  n++;
281  ComStr.str("");
282  ComStr << "sed -i 's/" << oupper << "/" << nupper << "/g' " << filename;
283  if(verb > 1)
284  std::cout << " " << ComStr.str() << std::endl;
285  // std::cout << ComStr.str() << std::endl;
286  System.Execute(ComStr.str());
287  while(std::getline(System,comline))
288  n++;
289  ComStr.str("");
290  ComStr << "sed -i 's/" << olower << "/" << nlower << "/g' " << filename;
291  if(verb > 1)
292  std::cout << " " << ComStr.str() << std::endl;
293  // std::cout << ComStr.str() << std::endl;
294  System.Execute(ComStr.str());
295  while(std::getline(System,comline))
296  n++;
297  }
298  if(verb > 1)
299  std::cout << " Done processing file contents." << std::endl
300  << " Renaming files..." << std::endl;
301  ComStr.str("");
302  // Now the inside of all files is fixed, need to fix filenames
303  ComStr << "find . -name \"*" << OriginalName << "*\"";
304  System.Execute(ComStr.str());
305  std::string::size_type olen = OriginalName.length();
306  std::string::size_type nlen = NewName.length();
307  while(std::getline(System,comline)){
308  if(verb > 1)
309  std::cout << " Renaming " << comline << " to ";
310  std::string newname(comline);
311  std::string::size_type x = newname.find(OriginalName);
312  while(x != std::string::npos){
313  newname.replace(x,olen,NewName);
314  x = newname.find(OriginalName);
315  }
316  ComStr.str("");
317  if(verb > 1)
318  std::cout << newname << std::endl;
319  ComStr << "mv " << comline << " " << newname;
320  // std::cout << ComStr.str() << std::endl;
321  IRAD::Sys::InProcess MV(ComStr.str());
322  }
323  if(verb > 1)
324  std::cout << "done." << std::endl;
325  return(0);
326  }
bool FILEEXISTS(const std::string &fname)
Definition: sepin.C:32
bool Excluded(const std::string &filename)
Exclude certain template files from conversion in project creation.
Definition: MakeProject.C:25
*********************************************************************Illinois Open Source License ****University of Illinois NCSA **Open Source License University of Illinois All rights reserved ****Developed free of to any person **obtaining a copy of this software and associated documentation to deal with the Software without including without limitation the rights to and or **sell copies of the and to permit persons to whom the **Software is furnished to do subject to the following this list of conditions and the following disclaimers ****Redistributions in binary form must reproduce the above **copyright this list of conditions and the following **disclaimers in the documentation and or other materials **provided with the distribution ****Neither the names of the Center for Simulation of Advanced the University of nor the names of its **contributors may be used to endorse or promote products derived **from this Software without specific prior written permission ****THE SOFTWARE IS PROVIDED AS WITHOUT WARRANTY OF ANY **EXPRESS OR INCLUDING BUT NOT LIMITED TO THE WARRANTIES **OF FITNESS FOR A PARTICULAR PURPOSE AND **NONINFRINGEMENT IN NO EVENT SHALL THE CONTRIBUTORS OR **COPYRIGHT HOLDERS BE LIABLE FOR ANY DAMAGES OR OTHER WHETHER IN AN ACTION OF TORT OR **ARISING OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE **USE OR OTHER DEALINGS WITH THE SOFTWARE v
Definition: roccomf90.h:20
void int int REAL * x
Definition: read.cpp:74
const NT & n
int CreateDirectory(const std::string &fname)
Definition: sepin.C:26

Here is the call graph for this function:

Here is the caller graph for this function:

double MidPointQuadrature ( double(*)(double)  f,
double  x0,
double  xn,
int  n 
)

Integrates f with composite midpoint rule.

Parameters
fFunction to integrate takes a double argument, x, and returns a double value
x0The lower integration domain limit.
xnThe upper integration domain limit.
nThe number of intervals into which to break the domain.
Returns
The numerical approximation for $\int_{x_0}^{x_n}{f(x)}{dx}$.

With $h = \frac{(x_n - x_0)}{n}$, and $x_i = x_0 + h(i-\frac{1}{2})$, the integral is calculated as:

$\int_{x_0}^{x_n}{f(x)}{dx} \approx h\sum_{i=1}^{n}f(x_i)$

The error of this method is $O(h^2)$.

Test:
GridConversion::TestingObject::Test__MidPointQuadrature tests this function by sending linear and quadratic test functions.

Definition at line 51 of file ExampleSourceFile.C.

References i, and n.

Referenced by TestingObject< ResultsType >::Test__MidPointQuadrature().

52  {
53  double h = (xn - x0)/(static_cast<double>(n));
54  if(std::fabs(h) < 1e-12) throw 1;
55  double sum = 0.0;
56  for(int i = 1;i <= n;i++)
57  sum += f(x0+((static_cast<double>(i)-.5)*h));
58  return(h*sum);
59  }
blockLoc i
Definition: read.cpp:79
const NT & n

Here is the caller graph for this function:

int GridConversion::ParallelTest ( int  argc,
char *  argv[] 
)

Drives the GridConversion::TestObject.

Parameters
argcnumber of string command line tokens
argvstring command line tokens
Returns
0 if successful, 1 otherwise

Drives the GridConversion::TestObject, which should encapsulate all the tests for the GridConversion namespace (and thus the project).

Command line documentation:

      gridconversion_test [-h] [-v [level] -o <filename> -l <filename> -n <TestName> ] 

      -h,--help
         Print out long version of help and exit.

      -v,--verblevel [level]
         Set the verbosity level. (default = 0)

      -o,--output <filename>
         Set the output file to <filename>. (default = stdout)

      -l,--list <filename>
         Set the list file name to <filename>. (no default). The list file should be a text file with one test name per line.

      -n,--name <TestName>
         Run test by name. (no default)

Definition at line 50 of file ParallelTestGridConversion.C.

References TestComLine::Initialize(), rank, and test().

Referenced by main().

51  {
52 
53  // The default verbosity is 0
54  int verblevel = 0;
55 
56  // This sets everything up with MPI
57  GridConversion::CommType communicator(&argc,&argv);
58  int rank = communicator.Rank();
59  int nproc = communicator.Size();
60  bool do_stdout = !rank;
61 
62  // This line creates the GridConversion::TestComLine object and passes in
63  // the command line arguments as a (const char **).
64  TestComLine comline((const char **)(argv));
65  // The call to comline.Initialize() reads the command line arguments
66  // from the array passed in the previous line.
67  comline.Initialize();
68 
69 
70  // The ProcessOptions() call does detailed examination of the command
71  // line arguments to check for user errors or other problems. This call
72  // will return non-zero if there were errors on the commandline.
73  int clerr = comline.ProcessOptions();
74  // Check if the user just wanted to get the help and exit
75  if(!comline.GetOption("help").empty()){
76  // Print out the "long usage" (i.e. help) message to stdout
77  if(do_stdout){
78  std::cout << comline.LongUsage() << std::endl;
79  if(verblevel > 1)
80  std::cout << "GridConversion::ParallelTest: Exiting test function (success)"
81  << std::endl;
82  }
83  communicator.SetExit(1);
84  }
85  if(communicator.Check())
86  return(0);
87  if(clerr){
88  if(do_stdout){
89  std::cout << comline.ErrorReport() << std::endl
90  << std::endl << comline.ShortUsage() << std::endl;
91  if(verblevel > 2)
92  std::cout << "GridConversion::ParallelTest: Exiting test function (fail)" << std::endl;
93  }
94  communicator.SetExit(1);
95  }
96  if(communicator.Check())
97  return(1);
98 
99  // These outstreams allow the output to file to be set up and separated
100  // from the stdout.
101  std::ofstream Ouf;
102  std::ostream *Out = NULL;
103  if(do_stdout)
104  Out = &std::cout;
105 
106  // The next few lines populate some strings based on the
107  // users input from the commandline.
108  std::string OutFileName(comline.GetOption("output"));
109  std::string TestName(comline.GetOption("name"));
110  std::string ListName(comline.GetOption("list"));
111  std::string sverb(comline.GetOption("verblevel"));
112 
113  // The following block parses and sets the verbosity level
114  if(!sverb.empty()){
115  verblevel = 1;
116  if(sverb != ".true."){
117  std::istringstream Istr(sverb);
118  Istr >> verblevel;
119  if(verblevel < 0)
120  verblevel = 1;
121  }
122  }
123 
124  // This block sets up the output file if the user specified one
125  if(!OutFileName.empty()){
126  if(Out){
127  Ouf.open(OutFileName.c_str());
128  if(!Ouf){
129  std::cout << "GridConversion::ParallelTest> Error: Could not open output file, "
130  << OutFileName << " for test output. Exiting (fail)." << std::endl;
131  communicator.SetExit(1);
132  }
133  Out = &Ouf;
134  }
135  if(communicator.Check())
136  return(1);
137  }
138 
139  if(verblevel > 1 && Out)
140  *Out << "GridConversion::ParallelTest: Entering test function" << std::endl;
141 
142  // Make an instance of the GridConversion testing object, GridConversion::ParallelTestingObject
143  GridConversion::ParallelTestingObject<GridConversion::CommType,GridConversion::TestResults> test(communicator);
144  // Make an instance of the GridConversion results object, GridConversion::TestResults
146 
147  // If the user specified a name, then run only the named test
148  if(!TestName.empty()){
149  // This call runs a test by name
150  test.RunTest(TestName,results);
151  }
152  // Otherwise, if the user specified a list, then read the list and
153  // run the listed tests.
154  else if(!ListName.empty()){
155  std::ifstream ListInf;
156  ListInf.open(ListName.c_str());
157  if(!ListInf){
158  if(Out)
159  *Out << "GridConversion::ParallelTest> Error: Could not open list of tests in file "
160  << ListName << ". Exiting (fail)." << std::endl;
161  communicator.SetExit(1);
162  }
163  if(communicator.Check())
164  return(1);
165  std::string testname;
166  while(std::getline(ListInf,testname))
167  test.RunTest(testname,results);
168  ListInf.close();
169  }
170  else {
171  // This call runs all the tests for the GridConversion namespace.
172  test.Process(results);
173  }
174  if(Out)
175  *Out << results << std::endl;
176 
177  if(Out && Ouf)
178  Ouf.close();
179 
180  if((verblevel > 1) && Out)
181  *Out << "GridConversion::ParallelTest: Exiting test function (success)" << std::endl;
182 
183  return(0);
184  }
IRAD::Util::TestResults TestResults
Project-specific test results type.
IRAD::Comm::CommunicatorObject CommType
Convenience typedef for CommunicatorObject.
void test(void)
Definition: flotsam.C:99
ComLineObject for testing app.
Definition: Test.C:12
static int rank
Definition: advectest.C:66

Here is the call graph for this function:

Here is the caller graph for this function:

int GridConversion::Test ( int  argc,
char *  argv[] 
)

Drives the GridConversion::TestObject.

Parameters
argcnumber of string command line tokens
argvstring command line tokens
Returns
0 if successful, 1 otherwise

Drives the GridConversion::TestObject, which should encapsulate all the tests for the GridConversion namespace (and thus the project).

Command line documentation:

      gridconversion_test [-h] [-v [level] -o <filename> -l <filename> -n <TestName> ] 

      -h,--help
         Print out long version of help and exit.

      -v,--verblevel [level]
         Set the verbosity level. (default = 0)

      -o,--output <filename>
         Set the output file to <filename>. (default = stdout)

      -l,--list <filename>
         Set the list file name to <filename>. (no default). The list file should be a text file with one test name per line.

      -n,--name <TestName>
         Run test by name. (no default)

Definition at line 45 of file TestGridConversion.C.

References TestComLine::Initialize(), TestingObject< ResultsType >::Process(), TestingObject< ResultsType >::RunTest(), and test().

Referenced by main().

46  {
47 
48  // The default verbosity is 0
49  int verblevel = 0;
50 
51  // This line creates the GridConversion::TestComLine object and passes in
52  // the command line arguments as a (const char **).
53  TestComLine comline((const char **)(argv));
54  // The call to comline.Initialize() reads the command line arguments
55  // from the array passed in the previous line.
56  comline.Initialize();
57  // The ProcessOptions() call does detailed examination of the command
58  // line arguments to check for user errors or other problems. This call
59  // will return non-zero if there were errors on the commandline.
60  int clerr = comline.ProcessOptions();
61  // Check if the user just wanted to get the help and exit
62  if(!comline.GetOption("help").empty()){
63  // Print out the "long usage" (i.e. help) message to stdout
64  std::cout << comline.LongUsage() << std::endl;
65  if(verblevel > 2)
66  std::cout << "GridConversion::Test: Exiting test function (success)" << std::endl;
67  return(0);
68  }
69  if(clerr){
70  std::cout << comline.ErrorReport() << std::endl
71  << std::endl << comline.ShortUsage() << std::endl;
72  if(verblevel > 2)
73  std::cout << "GridConversion::Test: Exiting test function (fail)" << std::endl;
74  return(1);
75  }
76  // These outstreams allow the output to file to be set up and separated
77  // from the stdout.
78  std::ofstream Ouf;
79  std::ostream *Out = &std::cout;
80 
81  // The next few lines populate some strings based on the
82  // users input from the commandline.
83  std::string OutFileName(comline.GetOption("output"));
84  std::string TestName(comline.GetOption("name"));
85  std::string ListName(comline.GetOption("list"));
86  std::string sverb(comline.GetOption("verblevel"));
87 
88  // The following block parses and sets the verbosity level
89  if(!sverb.empty()){
90  verblevel = 1;
91  if(sverb != ".true."){
92  std::istringstream Istr(sverb);
93  Istr >> verblevel;
94  if(verblevel < 0)
95  verblevel = 1;
96  }
97  }
98 
99  // This block sets up the output file if the user specified one
100  if(!OutFileName.empty()){
101  Ouf.open(OutFileName.c_str());
102  if(!Ouf){
103  std::cout << "GridConversion::Test> Error: Could not open output file, "
104  << OutFileName << " for test output. Exiting (fail)." << std::endl;
105  return(1);
106  }
107  Out = &Ouf;
108  }
109 
110  if(verblevel > 2)
111  std::cout << "GridConversion::Test: Entering test function" << std::endl;
112 
113  // Make an instance of the GridConversion testing object, GridConversion::TestingObject
115  // Make an instance of the GridConversion results object, GridConversion::TestResults
117 
118  // If the user specified a name, then run only the named test
119  if(!TestName.empty()){
120  // This call runs a test by name
121  test.RunTest(TestName,results);
122  }
123  // Otherwise, if the user specified a list, then read the list and
124  // run the listed tests.
125  else if(!ListName.empty()){
126  std::ifstream ListInf;
127  ListInf.open(ListName.c_str());
128  if(!ListInf){
129  std::cout << "GridConversion::Test> Error: Could not open list of tests in file "
130  << ListName << ". Exiting (fail)." << std::endl;
131  return(1);
132  }
133  std::string testname;
134  while(std::getline(ListInf,testname))
135  test.RunTest(testname,results);
136  ListInf.close();
137  }
138  else {
139  // This call runs all the tests for the GridConversion namespace.
140  test.Process(results);
141  }
142  *Out << results << std::endl;
143 
144  if(Ouf)
145  Ouf.close();
146 
147  if(verblevel > 2)
148  *Out << "GridConversion::Test: Exiting test function (success)" << std::endl;
149 
150  return(0);
151  }
virtual void RunTest(const std::string &name, ResultsType &result)
Runs a test specified by name.
IRAD::Util::TestResults TestResults
Project-specific test results type.
void test(void)
Definition: flotsam.C:99
virtual void Process(ResultsType &result)
Runs all tests implemented by the GridConversion::TestingObject.
ComLineObject for testing app.
Definition: Test.C:12
Project-specific testing object.

Here is the call graph for this function:

Here is the caller graph for this function:

double TrapezoidQuadrature ( double(*)(double)  f,
double  x0,
double  xn,
int  n 
)

Integrates f with composite trapezoid rule.

Parameters
fFunction to integrate takes a double argument, x, and returns a double value
x0The lower integration domain limit.
xnThe upper integration domain limit.
nThe number of intervals into which to break the domain.
Returns
The numerical approximation for $\int_{x_0}^{x_n}{f(x)}{dx}$.

With $h = \frac{(x_n - x_0)}{n}$, and $x_i = x_0 + {i}{h}$, the integral is calculated as:

$\int_{x_0}^{x_n}{f(x)}{dx} \approx \frac{h}{2}\sum_{i=1}^{n}(f(x_{i-1}) + f(x_i))$

The error of this method is $O(h^2)$.

Test:
GridConversion::TestingObject::Test__TrapezoidQuadrature tests this function by sending linear and quadratic test functions.

Definition at line 39 of file ExampleSourceFile.C.

References i, and n.

Referenced by TestingObject< ResultsType >::Test__TrapezoidQuadrature().

40  {
41  double h = (xn - x0)/(static_cast<double>(n));
42  if(std::fabs(h) < 1e-12) throw 1;
43  double sum = .5*(f(x0)+f(xn));
44  for(int i = 1; i < n;i++)
45  sum += f(x0 + i*h);
46  return(h*sum);
47  };
blockLoc i
Definition: read.cpp:79
const NT & n

Here is the caller graph for this function: