[cig-commits] commit 1912 by buerg to /var/svn/dealii/aspect
dealii.demon at gmail.com
dealii.demon at gmail.com
Mon Sep 23 10:01:59 PDT 2013
Revision 1912
Insert r1786.
U trunk/aspire/source/main.cc
http://www.dealii.org/websvn/revision.php?repname=Aspect+Repository&path=%2F&rev=1912&peg=1912
Diff:
Modified: trunk/aspire/source/main.cc
===================================================================
--- trunk/aspire/source/main.cc 2013-09-23 16:51:09 UTC (rev 1911)
+++ trunk/aspire/source/main.cc 2013-09-23 17:01:47 UTC (rev 1912)
@@ -25,7 +25,65 @@
#include <deal.II/base/utilities.h>
#include <deal.II/base/mpi.h>
-
+// extract the dimension in which to run ASPECT from the
+// parameter file. this is something that we need to do
+// before processing the parameter file since we need to
+// know whether to use the dim=2 or dim=3 instantiation
+// of the main classes
+unsigned int
+get_dimension(const std::string ¶meter_filename)
+{
+ using namespace dealii;
+
+ unsigned int dim = 2;
+
+ std::ifstream x_file(parameter_filename.c_str());
+ while (x_file)
+ {
+ // get one line and strip spaces at the front and back
+ std::string line;
+ std::getline(x_file, line);
+ while ((line.size() > 0) && (line[0] == ' ' || line[0] == ' '))
+ line.erase(0, 1);
+ while ((line.size() > 0)
+ && (line[line.size() - 1] == ' ' || line[line.size() - 1] == ' '))
+ line.erase(line.size() - 1, std::string::npos);
+ // now see whether the line starts with 'set' followed by multiple spaces
+ // if now, try next line
+ if (line.size() < 4)
+ continue;
+
+ if ((line[0] != 's') || (line[1] != 'e') || (line[2] != 't')
+ || !(line[3] == ' ' || line[3] == ' '))
+ continue;
+
+ line.erase(0, 4);
+ while ((line.size() > 0) && (line[0] == ' ' || line[0] == ' '))
+ line.erase(0, 1);
+ // now see whether the next word is "Dimension"
+ if (line.size() < 4)
+ continue;
+
+ if (line.find("Dimension") != 0)
+ continue;
+
+ line.erase(0, 9);
+ while ((line.size() > 0) && (line[0] == ' ' || line[0] == ' '))
+ line.erase(0, 1);
+ // we'd expect an equals size here
+ if ((line.size() < 1) || (line[0] != '='))
+ continue;
+
+ line.erase(0, 1);
+ while ((line.size() > 0) && (line[0] == ' ' || line[0] == ' '))
+ line.erase(0, 1);
+ // the rest should now be an integer
+ dim = Utilities::string_to_int(line);
+ }
+
+ return dim;
+}
+
int main (int argc, char *argv[])
{
using namespace dealii;
@@ -56,54 +114,8 @@
// try to determine the dimension we want to work in. the default
// is 2, but if we find a line of the kind "set Dimension = ..."
// then the last such line wins
- unsigned int dim = 2;
- {
- std::ifstream x_file(parameter_filename.c_str());
- while (x_file)
- {
- // get one line and strip spaces at the front and back
- std::string line;
- std::getline(x_file, line);
- while ((line.size() > 0) && (line[0] == ' ' || line[0] == ' '))
- line.erase(0, 1);
- while ((line.size() > 0)
- && (line[line.size() - 1] == ' '
- || line[line.size() - 1] == ' '))
- line.erase(line.size() - 1, std::string::npos);
+ const unsigned int dim = get_dimension(parameter_filename);
- // now see whether the line starts with 'set' followed by multiple spaces
- // if now, try next line
- if (line.size() < 4)
- continue;
- if ((line[0] != 's') || (line[1] != 'e') || (line[2] != 't')
- || !(line[3] == ' ' || line[3] == ' '))
- continue;
-
- line.erase(0, 4);
- while ((line.size() > 0) && (line[0] == ' ' || line[0] == ' '))
- line.erase(0, 1);
-
- // now see whether the next word is "Dimension"
- if (line.size() < 4)
- continue;
- if (line.find("Dimension") != 0)
- continue;
- line.erase(0, 9);
- while ((line.size() > 0) && (line[0] == ' ' || line[0] == ' '))
- line.erase(0, 1);
-
- // we'd expect an equals size here
- if ((line.size() < 1) || (line[0] != '='))
- continue;
- line.erase(0, 1);
- while ((line.size() > 0) && (line[0] == ' ' || line[0] == ' '))
- line.erase(0, 1);
-
- // the rest should now be an integer
- dim = Utilities::string_to_int(line);
- }
- }
-
// now switch between the templates that code for 2d or 3d. it
// would be nicer if we didn't have to duplicate code, but the
// following needs to be known at compile time whereas the dimensionality
More information about the CIG-COMMITS
mailing list