[cig-commits] [commit] python-removal: Initial checkin of the Python to C config file conversion tool. Cookbooks 1-8, and Cookbook10 have been converted and the C versions of the config files are located in the corresponding examples/Cookbook directory (83b32f9)

cig_noreply at geodynamics.org cig_noreply at geodynamics.org
Wed Feb 5 15:23:49 PST 2014


Repository : ssh://geoshell/citcoms

On branch  : python-removal
Link       : https://github.com/geodynamics/citcoms/compare/0000000000000000000000000000000000000000...83b32f9d7148e41d8dd964910ff8cc5a995d7f8f

>---------------------------------------------------------------

commit 83b32f9d7148e41d8dd964910ff8cc5a995d7f8f
Author: Rajesh Kommu <rajesh.kommu at gmail.com>
Date:   Wed Feb 5 15:18:38 2014 -0800

    Initial checkin of the Python to C config file conversion tool. Cookbooks 1-8,
    and Cookbook10 have been converted and the C versions of the config files are
    located in the corresponding examples/Cookbook directory


>---------------------------------------------------------------

83b32f9d7148e41d8dd964910ff8cc5a995d7f8f
 .gitignore                     |  90 ++++----
 Py2C/Makefile                  |   5 +
 Py2C/Py2C.cpp                  | 477 +++++++++++++++++++++++++++++++++++++++++
 Py2C/Py2C.hpp                  |  62 ++++++
 Py2C/Py2CMain.cpp              |  13 ++
 examples/Cookbook1/cookbook1   |  33 +++
 examples/Cookbook10/cookbook10 |  60 ++++++
 examples/Cookbook2/cookbook2   |  39 ++++
 examples/Cookbook3/cookbook3   |  43 ++++
 examples/Cookbook4/cookbook4   |  46 ++++
 examples/Cookbook5/cookbook5   |  59 +++++
 examples/Cookbook6/cookbook6   |  70 ++++++
 examples/Cookbook7/cookbook7   |  56 +++++
 examples/Cookbook8/cookbook8   |  94 ++++++++
 examples/example0              |  30 +++
 examples/example1              |  32 +++
 16 files changed, 1172 insertions(+), 37 deletions(-)

diff --git a/.gitignore b/.gitignore
index c1de314..18f7a3c 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,39 +1,55 @@
-# ignore svn externals
-.svn
-
-# ignore object files and static libraries
+# Compiled Object files
+*.slo
+*.lo
 *.o
-lib*.a
-
-# ignore files generated by autoreconf
-configure
-aclocal.m4
-autom4te.cache
-aux-config
-libtool
-Makefile
-Makefile.in
-config.log
-config.status
-config.h.in
-config.h
-stamp-h1
-.deps
-*.net
-
-
-# ignore python eggs
-CitcomS.egg-info
-pyconfig
-python/*
-*.egg
-
-# ignore files generated by make
-archimedes/__init__.pyc
-bin/CitcomSFull
-bin/CitcomSRegional
-bin/citcoms
-bin/mpipycitcoms
-bin/pycitcoms
-visual/project_geoid
+*.hi
+
+# Compiled Dynamic libraries
+*.so
+*.dylib
+
+# Compiled Static libraries
+*.lai
+*.la
+*.a
+
+# Binary files
+*.exe
+
+# AESON files
+*.aes
+
+# LaTex stuff
+*.vrb
+*.aux
+*.log
+*.toc
+*.bbl 
+*.out
+*.blg
+*.snm
+*.nav
+
+# Archives
+*.zip
+*.tar
+*.gz
+*.bz2
+*.tgz
+
+# VTK stuff
+*.pvd
+*.vtu
+
+# directories
+.metadata/
+.project/
+.classpath/
+.settings/
+
+# android stuff / eclipse stuff
+*.class
+*.jar
+*.project
+*.classpath
 
diff --git a/Py2C/Makefile b/Py2C/Makefile
new file mode 100644
index 0000000..a6517a7
--- /dev/null
+++ b/Py2C/Makefile
@@ -0,0 +1,5 @@
+Py2C.exe : Py2CMain.cpp Py2C.cpp
+	g++ -std=c++11 -o Py2C.exe Py2CMain.cpp Py2C.cpp
+
+clean:
+	rm -f *.exe *.o
diff --git a/Py2C/Py2C.cpp b/Py2C/Py2C.cpp
new file mode 100644
index 0000000..f97bd8e
--- /dev/null
+++ b/Py2C/Py2C.cpp
@@ -0,0 +1,477 @@
+#include "Py2C.hpp"
+
+namespace
+{
+  int pow2(int n)
+  {
+    if(n == 0)
+      return 1;
+    else
+      return 2*pow2(n-1);
+  }
+}
+
+Parameter::Parameter() 
+  : value("INVALID"), section("INVALID"), isDefault(false), cRequired(false) 
+{
+}
+
+Parameter::Parameter(const char* val, const char* sec, bool cReq, bool isDef) 
+  : value(val), section(sec), isDefault(isDef),cRequired(cReq)
+{
+}
+
+Py2CConverter::Py2CConverter(const char* pycfgfile, const char* ccfgfile)
+  : fin(pycfgfile), fout(ccfgfile)
+{
+  initialize_parameters();
+}
+  
+Py2CConverter::~Py2CConverter()
+{
+  fin.close();
+  fout.close();
+}
+  
+void Py2CConverter::convert()
+{
+  load();
+  check_and_fix_errors();
+  save();
+}
+
+void Py2CConverter::initialize_parameters()
+{
+  // CitcomS
+  // minstep is called steps in the Python version
+  parameters["minstep"] =  {"1", "CitcomS"};
+  parameters["maxstep"] = {"1000", "CitcomS"};
+  parameters["maxtotstep"] = {"1000000", "CitcomS"};
+  parameters["cpu_limits_in_seconds"] = {"360000000", "CitcomS", true};
+
+  parameters["solver"] = {"regional", "CitcomS"};
+  
+  // CitcomS.controller
+  // storage_spacing is called monitoringFrequency in the Python versions
+  parameters["storage_spacing"] = {"100", "CitcomS.controller"};
+  parameters["checkpointFrequency"] = {"100", "CitcomS.controller"};
+  
+  // CitcomS.solver
+  parameters["datadir"] = {"\".\"", "CitcomS.solver"};
+  parameters["datafile"] = {"\"regtest\"", "CitcomS.solver"};
+  parameters["datadir_old"] = {"\".\"", "CitcomS.solver"};
+  parameters["datafile_old"] = {"\"regtest\"", "CitcomS.solver"};
+  parameters["rayleigh"] = {"100000", "CitcomS.solver",true};
+  parameters["dissipation_number"] = {"0.0", "CitcomS.solver"};
+  parameters["gruneisen"] = {"0.0", "CitcomS.solver"};
+  parameters["surfaceT"] = {"0.1", "CitcomS.solver"};
+  parameters["Q0"] = {"0", "CitcomS.solver"};
+  parameters["stokes_flow_only"] = {"off", "CitcomS.solver"};
+  parameters["verbose"] = {"off", "CitcomS.solver"};
+  parameters["see_convergence"] = {"on", "CitcomS.solver"};
+
+  // CitcomS.solver.mesher
+  parameters["nproc_surf"] = {"1", "CitcomS.solver.mesher"};
+  parameters["nprocx"] = {"1","CitcomS.solver.mesher"};
+  parameters["nprocy"] = {"1","CitcomS.solver.mesher"};
+  parameters["nprocz"] = {"1","CitcomS.solver.mesher"};
+  parameters["coor"] = {"0","CitcomS.solver.mesher"};
+  parameters["coor_file"] = {"\"coor.dat\"","CitcomS.solver.mesher"};
+  parameters["coor_refine"] = {"0.1,0.15,0.1,0.2","CitcomS.solver.mesher"};
+  parameters["nodex"] = {"9","CitcomS.solver.mesher",true};
+  parameters["nodey"] = {"9","CitcomS.solver.mesher",true};
+  parameters["nodez"] = {"9","CitcomS.solver.mesher",true};
+  parameters["levels"] = {"1","CitcomS.solver.mesher"};
+  parameters["mgunitx"] = {"8", "CitcomS.solver.mesher"};
+  parameters["mgunity"] = {"8", "CitcomS.solver.mesher"};
+  parameters["mgunitz"] = {"8", "CitcomS.solver.mesher"};
+  parameters["radius_outer"] = {"1","CitcomS.solver.mesher"};
+  parameters["radius_inner"] = {"0.55","CitcomS.solver.mesher"};
+  parameters["theta_min"] = {"1.0708","CitcomS.solver.mesher",true};
+  parameters["theta_max"] = {"2.0708","CitcomS.solver.mesher",true};
+  parameters["fi_min"] = {"0","CitcomS.solver.mesher",true};
+  parameters["fi_max"] = {"1","CitcomS.solver.mesher",true};
+
+  // CitcomS.solver.tsolver
+  parameters["ADV"] = {"on","CitcomS.solver.tsolver"};
+  parameters["filter_temp"] = {"off","CitcomS.solver.tsolver"};
+  parameters["monitor_max_T"] = {"on","CitcomS.solver.tsolver"};
+  parameters["finetunedt"] = {"0.9","CitcomS.solver.tsolver"};
+  parameters["fixed_timestep"] = {"0.0","CitcomS.solver.tsolver"};
+  parameters["input_diffusivity"] = {"1","CitcomS.solver.tsolver"};
+  parameters["adv_gamma"] = {"0.5","CitcomS.solver.tsolver"};
+  parameters["adv_sub_iterations"] = {"2","CitcomS.solver.tsolver"};
+  
+  // CitcomS.solver.vsolver
+  parameters["Solver"] = {"cgrad","CitcomS.solver.vsolver"};
+  parameters["node_assemble"] = {"on","CitcomS.solver.vsolver"};
+  parameters["precond"] = {"on","CitcomS.solver.vsolver"};
+  parameters["accuracy"] = {"1.0e-4","CitcomS.solver.vsolver"};
+  parameters["uzawa"] = {"cg","CitcomS.solver.vsolver"};
+  parameters["compress_iter_maxstep"] = {"100","CitcomS.solver.vsolver"};
+  parameters["mg_cycle"] = {"1","CitcomS.solver.vsolver"};
+  parameters["down_heavy"] = {"3","CitcomS.solver.vsolver"};
+  parameters["up_heavy"] = {"3","CitcomS.solver.vsolver"};
+  parameters["vlowstep"] = {"1000","CitcomS.solver.vsolver"};
+  parameters["vhighstep"] = {"3","CitcomS.solver.vsolver"};
+  parameters["max_mg_cycles"] = {"50","CitcomS.solver.vsolver"};
+  parameters["piterations"] = {"1000","CitcomS.solver.vsolver"};
+  parameters["aug_lagr"] = {"on","CitcomS.solver.vsolver"};
+  parameters["aug_number"] = {"2000","CitcomS.solver.vsolver"};
+  parameters["remove_rigid_rotation"] = {"on","CitcomS.solver.vsolver"};
+  parameters["remove_angular_momentum"] = {"on","CitcomS.solver.vsolver"};
+
+  // CitcomS.solver.bc
+  parameters["side_sbcs"] = {"off","CitcomS.solver.bc"};
+  parameters["pseudo_free_surf"] = {"off","CitcomS.solver.bc"};
+  parameters["topvbc"] = {"0","CitcomS.solver.bc"};
+  parameters["topvbxval"] = {"0","CitcomS.solver.bc"};
+  parameters["topvbyval"] = {"0","CitcomS.solver.bc"};
+  parameters["botvbc"] = {"0","CitcomS.solver.bc"};
+  parameters["botvbxval"] = {"0","CitcomS.solver.bc"};
+  parameters["botvbyval"] = {"0","CitcomS.solver.bc"};
+  parameters["toptbc"] = {"1","CitcomS.solver.bc"};
+  parameters["toptbcval"] = {"0","CitcomS.solver.bc"};
+  parameters["bottbc"] = {"1","CitcomS.solver.bc"};
+  parameters["bottbcval"] = {"1","CitcomS.solver.bc"};
+  parameters["temperature_bound_adj"] = {"off","CitcomS.solver.bc"};
+  parameters["depth_bound_adj"] = {"0.157","CitcomS.solver.bc"};
+  parameters["width_bound_adj"] = {"0.08727","CitcomS.solver.bc"};
+
+  // CitcomS.solver.const
+  parameters["radius"] = {"6.371e+06", "CitcomS.solver.const"};
+  parameters["density"] = {"3340.0", "CitcomS.solver.const"};
+  parameters["thermdiff"] = {"1e-06", "CitcomS.solver.const"};
+  parameters["gravacc"] = {"9.81", "CitcomS.solver.const"};
+  parameters["thermexp"] = {"3e-05", "CitcomS.solver.const"};
+  parameters["refvisc"] = {"1e+21", "CitcomS.solver.const"};
+  parameters["cp"] = {"1200", "CitcomS.solver.const"};
+  parameters["density_above"] = {"1030.0", "CitcomS.solver.const"};
+  parameters["density_below"] = {"6600.0", "CitcomS.solver.const"};
+  parameters["z_lith"] = {"0.014", "CitcomS.solver.const"};
+  parameters["z_410"] = {"0.06435", "CitcomS.solver.const"};
+  parameters["z_lmantle"] = {"0.105", "CitcomS.solver.const"};
+  parameters["z_cmb"] = {"0.439", "CitcomS.solver.const"};
+
+  // CitcomS.solver.ic
+  parameters["restart"] = {"off", "CitcomS.solver.ic"};
+  parameters["post_p"] = {"off", "CitcomS.solver.ic"};
+  parameters["solution_cycles_init"] = {"0", "CitcomS.solver.ic"};
+  parameters["zero_elapsed_time"] = {"on", "CitcomS.solver.ic"};
+  parameters["tic_method"] = {"0", "CitcomS.solver.ic"};
+  parameters["num_perturbations"] = {"1", "CitcomS.solver.ic",true};
+  parameters["perturbl"] = {"1", "CitcomS.solver.ic",true};
+  parameters["perturbm"] = {"1", "CitcomS.solver.ic",true};
+  parameters["perturblayer"] = {"5", "CitcomS.solver.ic",true};
+  parameters["perturbmag"] = {"0.05", "CitcomS.solver.ic",true};
+  parameters["half_space_age"] = {"40", "CitcomS.solver.ic"};
+  parameters["mantle_temp"] = {"1.0", "CitcomS.solver.ic"};
+  parameters["blob_center"] = {"[-999,-999,-999]", "CitcomS.solver.ic"};
+  parameters["blob_radius"] = {"0.063", "CitcomS.solver.ic"};
+  parameters["blob_dT"] = {"0.18", "CitcomS.solver.ic"};
+
+  // CitcomS.solver.output
+  parameters["output_format"] = {"\"ascii\"", "CitcomS.solver.output"};
+  parameters["output_optional"] = {"\"surf,botm,tracer\"", "CitcomS.solver.output"};
+  parameters["output_ll_max"] = {"20", "CitcomS.solver.output"};
+  parameters["self_gravitation"] = {"off", "CitcomS.solver.output"};
+  parameters["use_cbf_topo"] = {"off", "CitcomS.solver.output"};
+  parameters["cb_block_size"] = {"1048576", "CitcomS.solver.output"};
+  parameters["cb_buffer_size"] = {"4194304", "CitcomS.solver.output"};
+  parameters["sieve_buf_size"] = {"1048576", "CitcomS.solver.output"};
+  parameters["output_alignment"] = {"262144", "CitcomS.solver.output"};
+  parameters["output_alignment_threshold"] = {"524288", "CitcomS.solver.output"};
+  parameters["cache_mdc_nelmts"] = {"10330", "CitcomS.solver.output"};
+  parameters["cache_rdcc_nelmts"] = {"521", "CitcomS.solver.output"};
+  parameters["cache_rdcc_nbytes"] = {"1048576", "CitcomS.solver.output"};
+
+  // CitcomS.solver.param
+  parameters["reference_state"] = {"1", "CitcomS.solver.param"};
+  parameters["refstate_file"] = {"\"refstate.dat\"", "CitcomS.solver.param"};
+  parameters["mineral_physics_model"] = {"3", "CitcomS.solver.param"};
+  parameters["file_vbcs"] = {"off", "CitcomS.solver.param"};
+  parameters["vel_bound_file"] = {"\"bevel.dat\"", "CitcomS.solver.param"};
+  parameters["mat_control"] = {"off", "CitcomS.solver.param"};
+  parameters["mat_file"] = {"\"mat.dat\"", "CitcomS.solver.param"};
+  parameters["lith_age"] = {"off", "CitcomS.solver.param"};
+  parameters["lith_age_file"] = {"\"age.dat\"", "CitcomS.solver.param"};
+  parameters["lith_age_time"] = {"off", "CitcomS.solver.param"};
+  parameters["lith_age_depth"] = {"0.0314", "CitcomS.solver.param"};
+  parameters["start_age"] = {"40", "CitcomS.solver.param"};
+  parameters["reset_startage"] = {"off", "CitcomS.solver.param"};
+
+  // CitcomS.solver.phase
+  parameters["Ra_410"] = {"0", "CitcomS.solver.phase"};
+  parameters["clapeyron410"] = {"0.0235", "CitcomS.solver.phase"};
+  parameters["transT410"] = {"0.78", "CitcomS.solver.phase"};
+  parameters["width410"] = {"0.0058", "CitcomS.solver.phase"};
+  parameters["Ra_670"] = {"0", "CitcomS.solver.phase"};
+  parameters["clapeyron670"] = {"-0.0235", "CitcomS.solver.phase"};
+  parameters["transT670"] = {"0.78", "CitcomS.solver.phase"};
+  parameters["width670"] = {"0.0058", "CitcomS.solver.phase"};
+  parameters["Ra_cmb"] = {"0", "CitcomS.solver.phase"};
+  parameters["clapeyroncmb"] = {"-0.0235", "CitcomS.solver.phase"};
+  parameters["transTcmb"] = {"0.875", "CitcomS.solver.phase"};
+  parameters["widthcmb"] = {"0.0058", "CitcomS.solver.phase"};
+
+  // CitcomS.solver.tracer
+  parameters["tracer"] = {"off", "Citcoms.Solver.tracer"};
+  parameters["tracer_ic_method"] = {"0", "Citcoms.Solver.tracer"};
+  parameters["tracers_per_element"] = {"10", "Citcoms.Solver.tracer"};
+  parameters["tracer_file"] = {"\"tracer.dat\"", "Citcoms.Solver.tracer"};
+  parameters["tracer_flavors"] = {"0", "Citcoms.Solver.tracer"};
+  parameters["ic_method_for_flavors"] = {"0", "Citcoms.Solver.tracer"};
+  parameters["z_interface"] = {"0.7", "Citcoms.Solver.tracer"};
+  parameters["itracer_warnings"] = {"on", "Citcoms.Solver.tracer"};
+  parameters["regular_grid_deltheta"] = {"1.0", "Citcoms.Solver.tracer"};
+  parameters["regular_grid_delphi"] = {"1.0", "Citcoms.Solver.tracer"};
+  parameters["chemical_buoyancy"] = {"on", "Citcoms.Solver.tracer"};
+  parameters["buoy_type"] = {"1", "Citcoms.Solver.tracer"};
+  parameters["buoyancy_ratio"] = {"1.0", "Citcoms.Solver.tracer"};
+  parameters["tracer_enriched"] = {"off", "Citcoms.Solver.tracer"};
+  parameters["Q0_enriched"] = {"0.0", "Citcoms.Solver.tracer"};
+
+  // CitcomS.solver.visc
+  parameters["Viscosity"] = {"\"system\"", "CitcomS.solver.visc"};
+  parameters["visc_smooth_method"] = {"3", "CitcomS.solver.visc"};
+  parameters["VISC_UPDATE"] = {"on", "CitcomS.solver.visc"};
+  parameters["num_mat"] = {"4", "CitcomS.solver.visc",true};
+  parameters["visc0"] = {"1,1,1,1", "CitcomS.solver.visc"};
+  parameters["TDEPV"] = {"off", "CitcomS.solver.visc"};
+  parameters["rheol"] = {"3", "CitcomS.solver.visc"};
+  parameters["viscE"] = {"1,1,1,1", "CitcomS.solver.visc"};
+  parameters["viscT"] = {"1,1,1,1", "CitcomS.solver.visc"};
+  parameters["viscZ"] = {"1,1,1,1", "CitcomS.solver.visc"};
+  parameters["SDEPV"] = {"off", "CitcomS.solver.visc"};
+  parameters["sdepv_misfit"] = {"0.001", "CitcomS.solver.visc"};
+  parameters["sdepv_expt"] = {"1,1,1,1", "CitcomS.solver.visc"};
+  parameters["PDEPV"] = {"off", "CitcomS.solver.visc"};
+  parameters["pdepv_a"] = {"1e20,1e20,1e20,1e20", "CitcomS.solver.visc"};
+  parameters["pdepv_b"] = {"0,0,0,0", "CitcomS.solver.visc"};
+  parameters["pdepv_y"] = {"1e20,1e20,1e20,1e20", "CitcomS.solver.visc"};
+  parameters["pdepv_eff"] = {"on", "CitcomS.solver.visc"};
+  parameters["pdepv_offset"] = {"0", "CitcomS.solver.visc"};
+  parameters["CDEPV"] = {"off", "CitcomS.solver.visc"};
+  parameters["cdepv_ff"] = {"1,1", "CitcomS.solver.visc"};
+  parameters["low_visc_channel"] = {"0", "CitcomS.solver.visc"};
+  parameters["low_visc_wedge"] = {"0", "CitcomS.solver.visc"};
+  parameters["lv_min_radius"] = {"0.9764", "CitcomS.solver.visc"};
+  parameters["lv_max_radius"] = {"0.9921", "CitcomS.solver.visc"};
+  parameters["lv_channel_thickness"] = {"0.0047", "CitcomS.solver.visc"};
+  parameters["lv_reduction"] = {"0.5", "CitcomS.solver.visc"};
+  parameters["VMIN"] = {"off", "CitcomS.solver.visc"};
+  parameters["visc_min"] = {"0.001", "CitcomS.solver.visc"};
+  parameters["VMAX"] = {"off", "CitcomS.solver.visc"};
+  parameters["visc_max"] = {"1000", "CitcomS.solver.visc"};
+}
+
+void Py2CConverter::load()
+{
+  std::string cfgline;
+  while(std::getline(fin, cfgline))
+  {
+    if(cfgline.length() == 0)
+    {
+      // blank line, do nothing
+    }
+    else if(cfgline[0] == '#')
+    {
+      // comment line, do nothing
+    }
+    else if(cfgline[0] == '[')
+    {
+      size_t pos = cfgline.find_first_of(']');
+      assert(pos != std::string::npos); // [ without a closing ] is malformed
+      section_names.insert(cfgline.substr(1,pos-1));
+    }
+    else
+    {
+      size_t pos = cfgline.find_first_of(';');
+      if(pos != std::string::npos)
+	cfgline = cfgline.substr(0,pos);
+      std::string name, value;
+      pos = cfgline.find_first_of('=');
+      assert(pos != std::string::npos); // parameter line without = is malformed
+      name = cfgline.substr(0,pos);
+      value = cfgline.substr(pos+1);
+
+      // trim any leading and trailing whitespaces from name and value
+      name.erase(std::remove_if(name.begin(), name.end(), ::isspace), 
+		 name.end());
+      value.erase(std::remove_if(value.begin(), value.end(), ::isspace), 
+		  value.end());
+
+      // parse the name value pair, and record any unknown parameters
+      if(!parse(name, value))
+      {
+	std::ostringstream ostr;
+	ostr << "# unknown parameter " << name << " with value " << value;
+	log_messages.push_back(ostr.str());
+      }
+    }
+  }
+}
+
+bool Py2CConverter::parse(const std::string& name, const std::string& value)
+{
+  std::string namecopy = name;
+
+  // Parameters that are named differently in C and Python config files
+  if(namecopy == "steps")
+    namecopy = "minstep";
+  else if(namecopy == "monitoringFrequency")
+    namecopy = "storage_spacing";
+
+  if(parameters.find(namecopy) == parameters.end())
+  {
+    return false;
+  }
+
+  Parameter& prm(parameters[namecopy]);
+  prm.value = value;
+  prm.isDefault = false;
+  return true;
+}
+
+void Py2CConverter::check_and_fix_errors()
+{
+  // Do the error checking/corrections that the Python version does automatically
+
+  // for the full spherical model, nproc_surf must be 12, for regional it must be 1
+  // for the full spherical model, nprocx=nprocy, mgunitx=mgunity
+  if(parameters["solver"].value == "full")
+  {
+    if(std::stoi(parameters["nproc_surf"].value) != 12)
+    {
+      log_messages.push_back("# WARNING: incorrect value for nproc_surf found; "
+			     "setting it to 12");
+      parameters["nproc_surf"].value = "12";
+      parameters["nproc_surf"].isDefault = false;
+    }
+    if(parameters["nprocx"].value != parameters["nprocy"].value)
+    {
+      log_messages.push_back("# WARNING: for solver=full, need nprocx=nprocy. "
+			     "changing value of nprocy to be equal to nprocx.");
+      parameters["nprocy"].value = parameters["nprocx"].value;
+      parameters["nprocx"].isDefault = false;
+      parameters["nprocy"].isDefault = false;
+    }
+    if(parameters["mgunitx"].value != parameters["mgunity"].value)
+    {
+      log_messages.push_back("# WARNING: for solver=full, need mgunitx=mgunity. "
+			     "changing value of mgunity to be equal to mgunitx.");
+      parameters["mgunity"].value = parameters["mgunitx"].value;
+      parameters["mgunitx"].isDefault = false;
+      parameters["mgunity"].isDefault = false;
+    }
+  }
+  else if(parameters["solver"].value == "regional")
+  {
+    if(std::stoi(parameters["nproc_surf"].value) != 1)
+    {
+      log_messages.push_back("# WARNING: incorrect value for nproc_surf found; "
+			     "setting it to 1");
+      parameters["nproc_surf"].value = "1";
+      parameters["nproc_surf"].isDefault = false;
+    }
+  }
+
+  // if Solver=multigrid, then Equation 6.7 needs to be satisfied.
+  // nodex = 1 + nprocx * mgunitx * 2^(levels-1)
+  if(parameters["Solver"].value == "multigrid")
+  {
+    int nprocx, nprocy, nprocz, nodex, nodey, nodez;
+    int mgunitx, mgunity, mgunitz, levels;
+    nprocx = std::stoi(parameters["nprocx"].value); 
+    nprocy = std::stoi(parameters["nprocy"].value);
+    nprocz = std::stoi(parameters["nprocz"].value);
+    nodex = std::stoi(parameters["nodex"].value); 
+    nodey = std::stoi(parameters["nodey"].value);
+    nodez = std::stoi(parameters["nodez"].value);
+    mgunitx = std::stoi(parameters["mgunitx"].value); 
+    mgunity = std::stoi(parameters["mgunity"].value);
+    mgunitz = std::stoi(parameters["mgunitz"].value);
+    levels = std::stoi(parameters["levels"].value);
+
+    if(nodex != (1+nprocx*mgunitx*pow2(levels-1)))
+    {
+      log_messages.push_back("# WARNING: changing mgunitx value to satisfy eqn 6.7");
+      parameters["mgunitx"].value = 
+	std::to_string((nodex - 1)/(nprocx*pow2(levels-1)));
+      parameters["mgunitx"].isDefault = false;
+    }
+    if(nodey != (1+nprocy*mgunity*pow2(levels-1)))
+    {
+      log_messages.push_back("# WARNING: changing mgunity value to satisfy eqn 6.7");
+      parameters["mgunity"].value = 
+	std::to_string((nodey - 1)/(nprocy*pow2(levels-1)));
+      parameters["mgunity"].isDefault = false;
+    }
+    if(nodez != (1+nprocz*mgunitz*pow2(levels-1)))
+    {
+      log_messages.push_back("# WARNING: changing mgunitz value to satisfy eqn 6.7");
+      parameters["mgunitz"].value = 
+	std::to_string((nodez - 1)/(nprocz*pow2(levels-1)));
+      parameters["mgunitz"].isDefault = false;
+    }
+  }
+}
+
+void Py2CConverter::save()
+{
+
+  for(const auto& secname : {std::string("CitcomS"), 
+	std::string("CitcomS.controller"), std::string("CitcomS.solver"),
+	std::string("CitcomS.solver.mesher"), std::string("CitcomS.solver.tsolver"),
+	std::string("CitcomS.solver.vsolver"), std::string("CitcomS.solver.bc"),
+	std::string("CitcomS.solver.const"), std::string("CitcomS.solver.ic"),
+	std::string("CitcomS.solver.output"), std::string("CitcomS.solver.param"),
+	std::string("CitcomS.solver.phase"), std::string("CitcomS.solver.tracer"),
+	std::string("CitcomS.solver.visc")})
+  {
+
+    // check if atleast one parameter in this section has been changed from its
+    // default value
+    if(section_names.count(secname) > 0)
+    {
+      fout << "# " << secname << std::endl;
+      for(auto p = parameters.begin(); p != parameters.end(); ++p)
+      {
+	if((p->second.section == secname) && 
+	   ((!p->second.isDefault)||(p->second.cRequired)))
+	{
+	  fout << p->first << "=" << p->second.value << std::endl;
+	}
+      }
+      fout << std::endl;
+    }
+    else
+    {
+      // check if there are any cRequired parameters in this section or any 
+      // parameters that have been changed from their default values
+      std::vector<std::string> namevals;
+      namevals.push_back(secname);
+      for(auto p = parameters.begin(); p != parameters.end(); ++p)
+      {
+	if((p->second.section == secname) && 
+	   ((p->second.cRequired)||(!p->second.isDefault)))
+	{
+	  namevals.push_back(p->first + "=" + p->second.value);
+	}
+      }
+      if(namevals.size() > 1)
+      {
+	fout << "# " << namevals[0] << std::endl;
+	for(size_t ndx=1; ndx < namevals.size(); ++ndx)
+	{
+	  fout << namevals[ndx] << std::endl;
+	}
+	fout << std::endl;
+      }
+    }
+  }
+
+  // write out all the log messages at the end of the config file
+  for(const auto& msg : log_messages)
+    fout << msg << std::endl;
+}
diff --git a/Py2C/Py2C.hpp b/Py2C/Py2C.hpp
new file mode 100644
index 0000000..0786911
--- /dev/null
+++ b/Py2C/Py2C.hpp
@@ -0,0 +1,62 @@
+#ifndef __citcoms__py2c__hpp__
+#define __citcoms__py2c__hpp__
+//------------------------------------------------------------------------------
+// Py2C.cpp : convert Python based CitcomS config files to C-based versions
+//
+// parsing rules for .cfg files
+// [0] Blank lines are ignored
+// [1] If line starts with a #, ignore the rest of the line
+// [2] If line starts with [, look for the closing ] and everything in between 
+//     is the name of a section.
+// [3] If a line contains a ';', ignore everything after the ';'
+// [4] Parse name = value pairs
+//------------------------------------------------------------------------------
+#include <algorithm>
+#include <cassert>
+#include <cstdlib>
+#include <fstream>
+#include <iostream>
+#include <iterator>
+#include <list>
+#include <locale>
+#include <map>
+#include <set>
+#include <sstream>
+#include <string>
+#include <vector>
+
+struct Parameter
+{
+  Parameter();
+  Parameter(const char* val, const char* sec, bool cReq=false,bool isDef=true); 
+
+  std::string value;      // string representation of the Parameter value
+  bool isDefault;         // true if the value has not been set from the .cfg file
+  bool cRequired;         // values whose presence is mandatory in C config files
+  std::string section;    // the section in which this Parameter is to be listed
+};
+
+
+class Py2CConverter
+{
+public:
+  Py2CConverter(const char* pycfgfile, const char* ccfgfile);
+  ~Py2CConverter();
+  
+  void convert();
+private:
+  void initialize_parameters();
+  bool parse(const std::string& name, const std::string& value);
+  void check_and_fix_errors();
+  void save();
+  void load();
+  
+  std::map<std::string, Parameter> parameters;
+  std::set<std::string> section_names;
+  std::list<std::string> log_messages;
+  
+  std::ifstream fin;
+  std::ofstream fout;
+};
+
+#endif // __citcoms__py2c__hpp__
diff --git a/Py2C/Py2CMain.cpp b/Py2C/Py2CMain.cpp
new file mode 100644
index 0000000..10a9b5e
--- /dev/null
+++ b/Py2C/Py2CMain.cpp
@@ -0,0 +1,13 @@
+#include "Py2C.hpp"
+
+int main(int argc, char* argv[])
+{
+  if( argc != 3)
+  {
+    std::cerr << "Usage: Py2C infile outfile" << std::endl;
+    exit(-1);
+  }
+
+  Py2CConverter py2c(argv[1], argv[2]);
+  py2c.convert();
+}
diff --git a/examples/Cookbook1/cookbook1 b/examples/Cookbook1/cookbook1
new file mode 100644
index 0000000..c92143f
--- /dev/null
+++ b/examples/Cookbook1/cookbook1
@@ -0,0 +1,33 @@
+# CitcomS
+cpu_limits_in_seconds=360000000
+minstep=100
+solver=full
+
+# CitcomS.controller
+storage_spacing=25
+
+# CitcomS.solver
+datafile=cookbook1
+rayleigh=100000
+
+# CitcomS.solver.mesher
+fi_max=1
+fi_min=0
+nodex=9
+nodey=9
+nodez=9
+nproc_surf=12
+theta_max=2.0708
+theta_min=1.0708
+
+# CitcomS.solver.ic
+num_perturbations=1
+perturbl=3
+perturblayer=5
+perturbm=2
+perturbmag=0.05
+
+# CitcomS.solver.visc
+num_mat=4
+
+# WARNING: incorrect value for nproc_surf found; setting it to 12
diff --git a/examples/Cookbook10/cookbook10 b/examples/Cookbook10/cookbook10
new file mode 100644
index 0000000..70531a1
--- /dev/null
+++ b/examples/Cookbook10/cookbook10
@@ -0,0 +1,60 @@
+# CitcomS
+cpu_limits_in_seconds=360000000
+minstep=15
+solver=full
+
+# CitcomS.controller
+storage_spacing=5
+
+# CitcomS.solver
+datadir=output
+datafile=cookbook10
+rayleigh=1e9
+
+# CitcomS.solver.mesher
+fi_max=1
+fi_min=0
+nodex=9
+nodey=9
+nodez=9
+nproc_surf=12
+radius_inner=0.546
+theta_max=2.0708
+theta_min=1.0708
+
+# CitcomS.solver.vsolver
+Solver=cgrad
+accuracy=1e-04
+piterations=1000
+vlowstep=1000
+
+# CitcomS.solver.ic
+num_perturbations=1
+perturbl=3
+perturblayer=5
+perturbm=2
+perturbmag=0.05
+
+# CitcomS.solver.output
+output_optional=tracer,comp_nd,seismic
+
+# CitcomS.solver.param
+mineral_physics_model=3
+
+# CitcomS.solver.tracer
+
+# CitcomS.solver.visc
+TDEPV=on
+VISC_UPDATE=on
+VMAX=on
+VMIN=on
+num_mat=4
+rheol=4
+visc0=1,1,1,1
+viscE=0.2,0.2,0.2,0.2
+viscT=0,0,0,0
+viscZ=0,0,0,0
+visc_max=100.0
+visc_min=1.0
+
+# WARNING: incorrect value for nproc_surf found; setting it to 12
diff --git a/examples/Cookbook2/cookbook2 b/examples/Cookbook2/cookbook2
new file mode 100644
index 0000000..6937679
--- /dev/null
+++ b/examples/Cookbook2/cookbook2
@@ -0,0 +1,39 @@
+# CitcomS
+cpu_limits_in_seconds=360000000
+minstep=60
+
+# CitcomS.controller
+storage_spacing=30
+
+# CitcomS.solver
+datafile=cookbook2
+rayleigh=100000
+
+# CitcomS.solver.mesher
+fi_max=0.7854
+fi_min=0.0
+nodex=17
+nodey=17
+nodez=9
+nprocx=2
+nprocy=2
+radius_inner=0.55
+radius_outer=1.0
+theta_max=1.5708
+theta_min=0.7854
+
+# CitcomS.solver.bc
+topvbc=1
+topvbxval=100
+topvbyval=0
+
+# CitcomS.solver.ic
+num_perturbations=1
+perturbl=1
+perturblayer=5
+perturbm=1
+perturbmag=0.0
+
+# CitcomS.solver.visc
+num_mat=4
+
diff --git a/examples/Cookbook3/cookbook3 b/examples/Cookbook3/cookbook3
new file mode 100644
index 0000000..58b6acb
--- /dev/null
+++ b/examples/Cookbook3/cookbook3
@@ -0,0 +1,43 @@
+# CitcomS
+cpu_limits_in_seconds=360000000
+minstep=200
+
+# CitcomS.controller
+storage_spacing=25
+
+# CitcomS.solver
+datafile=cookbook3
+rayleigh=1e6
+
+# CitcomS.solver.mesher
+fi_max=1
+fi_min=0
+nodex=17
+nodey=17
+nodez=9
+nprocx=2
+nprocy=2
+theta_max=2.0708
+theta_min=1.0708
+
+# CitcomS.solver.ic
+num_perturbations=1
+perturbl=1
+perturblayer=5
+perturbm=1
+perturbmag=0.05
+
+# CitcomS.solver.visc
+TDEPV=on
+VISC_UPDATE=on
+VMAX=on
+VMIN=on
+num_mat=4
+rheol=4
+visc0=1,1,1,1
+viscE=0.2,0.2,0.2,0.2
+viscT=0,0,0,0
+viscZ=0,0,0,0
+visc_max=100.0
+visc_min=1.0
+
diff --git a/examples/Cookbook4/cookbook4 b/examples/Cookbook4/cookbook4
new file mode 100644
index 0000000..e0a63a3
--- /dev/null
+++ b/examples/Cookbook4/cookbook4
@@ -0,0 +1,46 @@
+# CitcomS
+cpu_limits_in_seconds=360000000
+minstep=250
+
+# CitcomS.controller
+storage_spacing=50
+
+# CitcomS.solver
+datafile=cookbook4
+rayleigh=1e6
+
+# CitcomS.solver.mesher
+coor=1
+coor_file=coor.dat
+fi_max=1
+fi_min=0
+nodex=33
+nodey=17
+nodez=17
+nprocx=1
+nprocy=1
+nprocz=1
+theta_max=2.0708
+theta_min=1.0708
+
+# CitcomS.solver.ic
+num_perturbations=1
+perturbl=1
+perturblayer=10
+perturbm=0
+perturbmag=0.05
+
+# CitcomS.solver.visc
+TDEPV=on
+VISC_UPDATE=on
+VMAX=on
+VMIN=on
+num_mat=4
+rheol=4
+visc0=1,1,1,1
+viscE=0.2,0.2,0.2,0.2
+viscT=0,0,0,0
+viscZ=0,0,0,0
+visc_max=100.0
+visc_min=1.0
+
diff --git a/examples/Cookbook5/cookbook5 b/examples/Cookbook5/cookbook5
new file mode 100644
index 0000000..40fc210
--- /dev/null
+++ b/examples/Cookbook5/cookbook5
@@ -0,0 +1,59 @@
+# CitcomS
+cpu_limits_in_seconds=360000000
+minstep=1100
+
+# CitcomS.controller
+storage_spacing=100
+
+# CitcomS.solver
+datadir_old=./ic
+datafile=cookbook5
+datafile_old=cookbook5
+rayleigh=4.07e+08
+
+# CitcomS.solver.mesher
+coor=1
+coor_file=./coor.dat
+fi_max=1
+fi_min=0
+nodex=17
+nodey=65
+nodez=33
+nprocx=1
+nprocy=2
+nprocz=1
+theta_max=2.0708
+theta_min=1.0708
+
+# CitcomS.solver.tsolver
+finetunedt=0.75
+monitor_max_T=on
+
+# CitcomS.solver.bc
+topvbc=1
+
+# CitcomS.solver.ic
+num_perturbations=1
+perturbl=1
+perturblayer=5
+perturbm=1
+perturbmag=0.05
+solution_cycles_init=0
+tic_method=-1
+
+# CitcomS.solver.param
+file_vbcs=on
+start_age=55
+vel_bound_file=./velocity/bvel.dat
+
+# CitcomS.solver.visc
+TDEPV=on
+VMAX=on
+VMIN=on
+num_mat=4
+visc0=100,0.003,1,2
+viscE=24,24,24,24
+viscT=0.182,0.182,0.182,0.182
+visc_max=100.0
+visc_min=0.01
+
diff --git a/examples/Cookbook6/cookbook6 b/examples/Cookbook6/cookbook6
new file mode 100644
index 0000000..4c20781
--- /dev/null
+++ b/examples/Cookbook6/cookbook6
@@ -0,0 +1,70 @@
+# CitcomS
+cpu_limits_in_seconds=360000000
+minstep=100
+
+# CitcomS.controller
+storage_spacing=10
+
+# CitcomS.solver
+datafile=cookbook6
+rayleigh=4.312616e+08
+
+# CitcomS.solver.mesher
+coor=1
+coor_file=./coord.dat
+fi_max=1
+fi_min=0
+nodex=61
+nodey=61
+nodez=25
+nprocx=2
+nprocy=2
+nprocz=1
+theta_max=2.0708
+theta_min=1.0708
+
+# CitcomS.solver.tsolver
+fixed_timestep=7.77e-10
+
+# CitcomS.solver.vsolver
+accuracy=1e-5
+piterations=100000
+precond=on
+vlowstep=100000
+
+# CitcomS.solver.bc
+bottbcval=0.82
+pseudo_free_surf=on
+topvbc=2
+
+# CitcomS.solver.const
+density=3270.0
+gravacc=10.0
+radius=6.371e+06
+refvisc=1.0e+21
+thermdiff=1.0e-06
+thermexp=3.0e-05
+
+# CitcomS.solver.ic
+blob_center=1.570800e+00,1.570800e+00,9.246600e-01
+blob_dT=0.18
+blob_radius=6.278334e-02
+half_space_age=2500.0
+mantle_temp=0.82
+num_perturbations=1
+perturbl=1
+perturblayer=5
+perturbm=1
+perturbmag=0.05
+tic_method=2
+
+# CitcomS.solver.param
+start_age=60
+
+# CitcomS.solver.visc
+TDEPV=on
+num_mat=4
+visc0=1,1,1,1
+viscE=9.50614,9.50614,9.50614,9.50614
+viscT=1.02126,1.02126,1.02126,1.02126
+
diff --git a/examples/Cookbook7/cookbook7 b/examples/Cookbook7/cookbook7
new file mode 100644
index 0000000..dcc7488
--- /dev/null
+++ b/examples/Cookbook7/cookbook7
@@ -0,0 +1,56 @@
+# CitcomS
+cpu_limits_in_seconds=360000000
+minstep=15
+solver=full
+
+# CitcomS.controller
+storage_spacing=5
+
+# CitcomS.solver
+datadir=output
+datafile=cookbook7
+rayleigh=1e7
+
+# CitcomS.solver.mesher
+fi_max=1
+fi_min=0
+nodex=9
+nodey=9
+nodez=9
+nproc_surf=12
+theta_max=2.0708
+theta_min=1.0708
+
+# CitcomS.solver.vsolver
+Solver=cgrad
+accuracy=1e-04
+piterations=1000
+vlowstep=1000
+
+# CitcomS.solver.ic
+num_perturbations=1
+perturbl=3
+perturblayer=5
+perturbm=2
+perturbmag=0.05
+
+# CitcomS.solver.output
+output_optional=tracer,comp_nd
+
+# CitcomS.solver.tracer
+
+# CitcomS.solver.visc
+TDEPV=on
+VISC_UPDATE=on
+VMAX=on
+VMIN=on
+num_mat=4
+rheol=4
+visc0=1,1,1,1
+viscE=0.2,0.2,0.2,0.2
+viscT=0,0,0,0
+viscZ=0,0,0,0
+visc_max=100.0
+visc_min=1.0
+
+# WARNING: incorrect value for nproc_surf found; setting it to 12
diff --git a/examples/Cookbook8/cookbook8 b/examples/Cookbook8/cookbook8
new file mode 100644
index 0000000..3df5ab2
--- /dev/null
+++ b/examples/Cookbook8/cookbook8
@@ -0,0 +1,94 @@
+# CitcomS
+cpu_limits_in_seconds=360000000
+minstep=10000
+solver=full
+
+# CitcomS.controller
+checkpointFrequency=1000
+storage_spacing=1000
+
+# CitcomS.solver
+datadir=output
+datadir_old=restart
+datafile=cookbook8
+datafile_old=cookbook8
+dissipation_number=0.5
+gruneisen=1.25
+rayleigh=7.68175583e4
+surfaceT=0.1
+
+# CitcomS.solver.mesher
+coor=1
+coor_file=coord.dat
+fi_max=1
+fi_min=0
+levels=5
+mgunitx=2
+mgunity=2
+mgunitz=2
+nodex=33
+nodey=33
+nodez=33
+nproc_surf=12
+theta_max=2.0708
+theta_min=1.0708
+
+# CitcomS.solver.tsolver
+finetunedt=0.75
+
+# CitcomS.solver.vsolver
+Solver=multigrid
+accuracy=0.001
+aug_lagr=on
+aug_number=2.0e3
+compress_iter_maxstep=100
+down_heavy=2
+max_mg_cycles=50
+mg_cycle=1
+piterations=375
+precond=on
+remove_angular_momentum=on
+remove_rigid_rotation=off
+up_heavy=2
+uzawa=cg
+vhighstep=2
+vlowstep=20
+
+# CitcomS.solver.ic
+num_perturbations=1
+perturbl=3
+perturblayer=17
+perturbm=2
+perturbmag=0.01
+restart=off
+solution_cycles_init=9000
+tic_method=3
+
+# CitcomS.solver.output
+output_ll_max=20
+output_optional=geoid,surf,botm
+self_gravitation=on
+use_cbf_topo=on
+
+# CitcomS.solver.param
+reference_state=1
+refstate_file=ref.dat
+
+# CitcomS.solver.visc
+TDEPV=on
+VISC_UPDATE=on
+VMAX=on
+VMIN=on
+num_mat=4
+rheol=1
+visc0=1,1,1,1
+viscE=2.99573,2.99573,2.99573,2.99573
+viscT=0.5,0.5,0.5,0.5
+visc_max=1e+06
+visc_min=0.001
+visc_smooth_method=1
+
+# WARNING: incorrect value for nproc_surf found; setting it to 12
+# WARNING: changing mgunitx value to satisfy eqn 6.7
+# WARNING: changing mgunity value to satisfy eqn 6.7
+# WARNING: changing mgunitz value to satisfy eqn 6.7
diff --git a/examples/example0 b/examples/example0
new file mode 100644
index 0000000..228901f
--- /dev/null
+++ b/examples/example0
@@ -0,0 +1,30 @@
+# CitcomS
+cpu_limits_in_seconds=360000000
+minstep=5
+
+# CitcomS.controller
+storage_spacing=1
+
+# CitcomS.solver
+datafile=example0
+rayleigh=100000
+
+# CitcomS.solver.mesher
+fi_max=1
+fi_min=0
+nodex=17
+nodey=17
+nodez=9
+theta_max=2.0708
+theta_min=1.0708
+
+# CitcomS.solver.ic
+num_perturbations=1
+perturbl=1
+perturblayer=5
+perturbm=1
+perturbmag=0.05
+
+# CitcomS.solver.visc
+num_mat=4
+
diff --git a/examples/example1 b/examples/example1
new file mode 100644
index 0000000..240b23c
--- /dev/null
+++ b/examples/example1
@@ -0,0 +1,32 @@
+# CitcomS
+cpu_limits_in_seconds=360000000
+minstep=70
+
+# CitcomS.controller
+storage_spacing=10
+
+# CitcomS.solver
+datafile=example1
+rayleigh=100000
+
+# CitcomS.solver.mesher
+fi_max=1
+fi_min=0
+nodex=17
+nodey=17
+nodez=9
+nprocx=2
+nprocy=2
+theta_max=2.0708
+theta_min=1.0708
+
+# CitcomS.solver.ic
+num_perturbations=1
+perturbl=1
+perturblayer=5
+perturbm=1
+perturbmag=0.05
+
+# CitcomS.solver.visc
+num_mat=4
+



More information about the CIG-COMMITS mailing list