[asl] 57/177: Fixing ApplicationParametersManager

Ghislain Vaillant ghisvail-guest at moszumanska.debian.org
Thu Aug 27 09:22:40 UTC 2015


This is an automated email from the git hooks/post-receive script.

ghisvail-guest pushed a commit to branch master
in repository asl.

commit aa6ff37205eeb661abfda7ee17b743b87ece0f43
Author: Avtech Scientific <AvtechScientific at users.noreply.github.com>
Date:   Tue Jun 30 15:16:54 2015 +0300

    Fixing ApplicationParametersManager
---
 README.md                                  | 19 +++------
 examples/flow/locomotive_in_tunnel.cc      | 10 ++---
 examples/input_data/Media_Files_LICENSE.md |  4 ++
 src/utilities/aslParametersManager.cxx     | 64 ++++++++++++++++++++----------
 4 files changed, 58 insertions(+), 39 deletions(-)

diff --git a/README.md b/README.md
index 73521bd..5dc0535 100644
--- a/README.md
+++ b/README.md
@@ -25,25 +25,18 @@ ASL is distributed under the free GNU Affero General Public License (AGPLv3) wit
 
 ### Running an example
 
-1. Go to tests: `cd test/testPhysics/flow/locomotive_in_tunnel`
-2. Copy sample ASL configuration file: `cp ../../../../../ASL/test/input_data/asl.ini .`
-3. Copy the .stl input file: `cp ../../../../../ASL/test/input_data/locomotive.stl .`
-4. Run: `./locomotive_in_tunnel`
-5. Post-processing: [step by step example](https://github.com/AvtechScientific/ASL/wiki/User-Guide#post-processing).
+1. Go to tests: `cd examples/flow/locomotive_in_tunnel`
+2. Copy the .stl input file: `cp ../../../../ASL/examples/input_data/locomotive.stl .`
+3. Run: `./locomotive_in_tunnel`
+4. Post-processing: [step by step example](https://github.com/AvtechScientific/ASL/wiki/User-Guide#post-processing).
 
 ### Writing your own code using ASL
 
-1. Take a look on examples, e.g. `test/testPhysics/flow/locomotive_in_tunnel.cc`
-2. To build your program using `cmake` see e.g. `test/testPhysics/flow/CMakeLists.txt`
+1. Take a look on examples, e.g. `examples/flow/locomotive_in_tunnel.cc`
+2. To build your program using `cmake` see e.g. `examples/flow/CMakeLists.txt`
 3. To build your program with tools others than `cmake` run `make VERBOSE=1` and/or consult `CMakeCache.txt` to get better understanding of the compiler flags, library paths and dependencies involved. The output of `make install` shows the location of installed public include headers and libraries (by default: `/usr/local/include/asl-X.Y.Z` and `/usr/local/lib`).
 
 
-## Media files
-
-Some examples require input files (like `asl.ini` or .stl) that can be found in `test/input_data`.
-All .stl files were obtained from [GrabCAD](https://grabcad.com/) and are subject to their [Terms of Service](https://grabcad.com/terms); the rest of files, and specifically the images in `src/pics` are part of the ASL project and are covered by its license (see above) except where stated otherwise (`cmake/Modules`).
-
-
 ## Further information
 
 For more information, please visit <http://asl.org.il>.
diff --git a/examples/flow/locomotive_in_tunnel.cc b/examples/flow/locomotive_in_tunnel.cc
index a61342a..c25055e 100644
--- a/examples/flow/locomotive_in_tunnel.cc
+++ b/examples/flow/locomotive_in_tunnel.cc
@@ -74,16 +74,16 @@ int main(int argc, char* argv[])
 	                                                   "1.0");
 	asl::Parameter<FlT> dx(0.08, "dx", "space step", "m");
 	asl::Parameter<FlT> dt(1., "dt", "time step", "s");
-	asl::Parameter<FlT> nu(.001, "nu", "viscosity");
+	asl::Parameter<FlT> nu(.001, "nu", "viscosity", "Pa*s");
 
 	appParamsManager.load(argc, argv);
-cout << "getDir(): " << appParamsManager.getDir() << endl;
+
 	AVec<int> size(makeAVec(40., 10., 15.) * (1. / dx.v()));
 	asl::Block bl(size, dx.v(), makeAVec(-30., 8.58, 1.53));
 	
 	asl::UValue<FlT> nuNum(nu.v() * dt.v() / dx.v() / dx.v());
 	
-	std::cout << "Data initialization...";
+	std::cout << "Data initialization... ";
 
 	auto locomotive(asl::readSurface("locomotive.stl", bl));
 	
@@ -97,7 +97,7 @@ cout << "getDir(): " << appParamsManager.getDir() << endl;
 	
 	std::cout << "Finished" << endl;
 	
-	std::cout << "Numerics initialization...";
+	std::cout << "Numerics initialization... ";
 
 	asl::SPLBGK lbgk(new asl::LBGKTurbulence(block, 
 	                                         acl::generateVEConstant(FlT(nu.v())),  
@@ -130,7 +130,7 @@ cout << "getDir(): " << appParamsManager.getDir() << endl;
 	
 
 	std::cout << "Finished" << endl;
-	std::cout << "Computing...";
+	std::cout << "Computing... ";
 	asl::Timer timer;
 
 	asl::WriterVTKXML writer(appParamsManager.getDir() + "locomotive_in_tunnel");
diff --git a/examples/input_data/Media_Files_LICENSE.md b/examples/input_data/Media_Files_LICENSE.md
new file mode 100644
index 0000000..0cded78
--- /dev/null
+++ b/examples/input_data/Media_Files_LICENSE.md
@@ -0,0 +1,4 @@
+# Media files
+
+Some examples require input files (like .vti or .stl) that can be found in `examples/input_data`.
+All .stl files were originally obtained from [GrabCAD](https://grabcad.com/) and are subject to their [Terms of Service](https://grabcad.com/terms); the rest of files, and specifically the images in `src/pics` are part of the ASL project and are covered by its license (see above) except where stated otherwise (`cmake/Modules`).
diff --git a/src/utilities/aslParametersManager.cxx b/src/utilities/aslParametersManager.cxx
index 568c710..0b94983 100644
--- a/src/utilities/aslParametersManager.cxx
+++ b/src/utilities/aslParametersManager.cxx
@@ -333,7 +333,7 @@ namespace asl
 		try
 		{
 			ifstream ifs(paramFile);
-			if (!ifs)
+			if (!ifs.good())
 				errorMessage("Can not open parameters file: " + paramFile);
 
 			parsed_options parsed = parse_config_file(ifs, parametersOptions,
@@ -358,7 +358,7 @@ namespace asl
 	void ParametersManager::writeParametersFile(const std::string fileName)
 	{
 		ofstream fo(fileName);
-		if (!fo)
+		if (!fo.good())
 			errorMessage("ParametersManager::writeParametersFile() - can not open file: " + fileName);
 
 		fo << parametersFileStr;
@@ -391,6 +391,8 @@ namespace asl
 	void ApplicationParametersManager::load(int argc, char * argv[])
 	{
 		variables_map vm;
+		// Set default parameters file path
+		path p("./");
 
 		options_description genericOptions("Generic options");
 
@@ -400,7 +402,7 @@ namespace asl
 			("devices,d", "Display all available devices and exit")
 			("parameters,p", value<string>(), "Path to the parameters file")
 			("generate,g", value<string>(),
-			 "Generate default parameters file and exit")
+			 "Generate default parameters file, write it and exit")
 			("check,c", "Check parameters for consistency and exit");
 
 		positional_options_description positional;
@@ -442,34 +444,53 @@ namespace asl
 
 			if (vm.count("generate"))
 			{
-				path p(vm["generate"].as<string>());
+				path gp(vm["generate"].as<string>());
 				cout << "Writing default parameters file to: "
-					 << p.string() << endl;
+					 << gp.string() << endl;
 
-				writeParametersFile(p.string());
+				writeParametersFile(gp.string());
 				exit(0);
 			}
 
-			path p(vm["parameters"].as<string>());
-			ifstream ifs(p.string());
-			if (!ifs)
+			if (vm.count("parameters"))
 			{
-				// Only warn, since all options might have default values, or required values
-				// provided through the command line - so not always a parameters file is required
-				warningMessage("ParametersManager::load() - can not open parameters file: " + p.string());
+				p = vm["parameters"].as<string>();
+				if (is_directory(p))
+				{
+					// Only warn, since all options might have default values, or required values
+					// provided through the command line - so no configuration file is required
+					warningMessage("ApplicationParametersManager::load() - no parameters file provided, " + p.string() + " is a directory");
+				}
+				else
+				{
+					ifstream ifs(p.string());
+					if (ifs.good())
+					{
+						parsed_options parsed = parse_config_file(ifs, allOptions, true);
+						store(parsed, vm);
+						// Get directory, cutting file name
+						p = p.parent_path();
+					}
+					else
+					{
+						warningMessage("ApplicationParametersManager::load() - can not open configuration file: " + p.string());
+						// Get directory, cutting file name, after using p for warning
+						p = p.parent_path();
+					}
+				}
+			}
+			else
+			{
+					warningMessage("ApplicationParametersManager::load() - no parameters file provided");
 			}
 
-			// Get absolute path
-			p = absolute(p);
-			// Get directory
-			p = p.parent_path();
+			// Generate `parametersFileDirectory`
+			// Get absolute, canonical (no symbolic links, . or ..) path first
+			p = canonical(p);
 			// Append slash
 			p /= "/";
 			parametersFileDirectory = p.string(); 
-			
 
-			parsed_options parsed = parse_config_file(ifs, allOptions, true);
-			store(parsed, vm);
 			// Run error notification only after obtaining
 			// all options and dealing with "--help"
 			notify(vm);
@@ -477,7 +498,8 @@ namespace asl
 			populateMaps(vm);
 
 			// Set hardware default queue as required through provided options
-			acl::hardware.setDefaultQueue(vm["platform"].as<string>(), vm["device"].as<string>());
+			acl::hardware.setDefaultQueue(vm["platform"].as<string>(),
+			                              vm["device"].as<string>());
 
 			// Place it after(!) notify(vm);
 			if (vm.count("check"))
@@ -490,7 +512,7 @@ namespace asl
 		}
 		catch(exception& e)
 		{
-			errorMessage(string("ParametersManager::load() - ") + e.what());
+			errorMessage(string("ApplicationParametersManager::load() - ") + e.what());
 		}
 	}
 		 

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/asl.git



More information about the debian-science-commits mailing list