[asl] 52/177: refactoring ParametersManager
Ghislain Vaillant
ghisvail-guest at moszumanska.debian.org
Thu Aug 27 09:22:39 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 432502c97c0be809b836cf835196d2f134fc22e4
Author: Avtech Scientific <AvtechScientific at users.noreply.github.com>
Date: Fri Jun 26 13:14:21 2015 +0300
refactoring ParametersManager
---
examples/flow/multicomponent_flow.cc | 55 +++++-----
examples/input_data/axial-compressor.stl | Bin 32248484 -> 0 bytes
src/acl/Kernels/aclKernel.h | 2 +-
src/utilities/aslGlobalSpace.h | 4 +-
src/utilities/aslParametersManager.cxx | 180 +++++++++++++++++--------------
src/utilities/aslParametersManager.h | 53 ++++++---
6 files changed, 163 insertions(+), 131 deletions(-)
diff --git a/examples/flow/multicomponent_flow.cc b/examples/flow/multicomponent_flow.cc
index 78c7dee..bbb4667 100644
--- a/examples/flow/multicomponent_flow.cc
+++ b/examples/flow/multicomponent_flow.cc
@@ -51,7 +51,7 @@ class Parameters
void init();
public:
- asl::ParametersManager parametersManager;
+ asl::ApplicationParametersManager appParamsManager;
string folder;
asl::Block::DV size;
@@ -74,15 +74,14 @@ class Parameters
asl::Parameter<double> component3InVel;
- void load(int argc, char * argv[],
- string programName,
- string programVersion);
+ void load(int argc, char * argv[]);
Parameters();
void updateNumValues();
};
Parameters::Parameters():
+ appParamsManager("multicomponent_flow", "0.1", "multicomponent_flow.ini"),
size(3),
dx(0.0005, "dx", "space step"),
dt(1., "dt", "time step"),
@@ -100,12 +99,10 @@ Parameters::Parameters():
}
-void Parameters::load(int argc, char * argv[],
- string programName,
- string programVersion)
+void Parameters::load(int argc, char * argv[])
{
- parametersManager.load(argc, argv, programName, programVersion);
- folder = parametersManager.getFolderWithSlash();
+ appParamsManager.load(argc, argv);
+ folder = appParamsManager.getFolderWithSlash();
init();
}
@@ -133,13 +130,13 @@ asl::SPDistanceFunction generateMixer(asl::Block & block, Parameters ¶ms)
{
asl::SPDistanceFunction mixerGeometry;
asl::AVec<double> orientation(asl::makeAVec(0., 0., 1.));
- asl::AVec<double> center(asl::AVec<double>(params.size)*.5*params.dx.v());
+ asl::AVec<double> center(asl::AVec<double>(params.size) * .5 * params.dx.v());
mixerGeometry = generateDFCylinderInf(params.tubeD.v() / 2., orientation, center);
orientation[1] = 1.0;
orientation[2] = 0.0;
- center[2]=params.pumpD.v() * 1.5;
+ center[2] = params.pumpD.v() * 1.5;
mixerGeometry = mixerGeometry | generateDFCylinderInf(params.pumpD.v() / 2., orientation, center);
return asl::normalize(-(mixerGeometry) | asl::generateDFInBlock(block, 0), params.dx.v());
@@ -148,9 +145,9 @@ asl::SPDistanceFunction generateMixer(asl::Block & block, Parameters ¶ms)
int main(int argc, char *argv[])
{
Parameters params;
- params.load(argc, argv, "multicomponent_flow", "0.1");
+ params.load(argc, argv);
- std::cout<<"Flow: Data initialization...";
+ std::cout << "Flow: Data initialization...";
asl::Block block(params.size, params.dx.v());
@@ -163,9 +160,9 @@ int main(int argc, char *argv[])
asl::initData(component3Frac, 0);
- std::cout<<"Finished"<<endl;
+ std::cout << "Finished" << endl;
- std::cout<<"Flow: Numerics initialization...";
+ std::cout << "Flow: Numerics initialization...";
auto templ(&asl::d3q15());
@@ -178,9 +175,11 @@ int main(int argc, char *argv[])
lbgkUtil->initF(acl::generateVEConstant(.0, .0, .0));
auto flowVel(lbgk->getVelocity());
- auto nmcomponent1(asl::generateFDAdvectionDiffusion(component1Frac, 0.01, flowVel, templ, true));
+ auto nmcomponent1(asl::generateFDAdvectionDiffusion(component1Frac, 0.01,
+ flowVel, templ, true));
nmcomponent1->init();
- auto nmcomponent3(asl::generateFDAdvectionDiffusion(component3Frac, 0.01, flowVel, templ));
+ auto nmcomponent3(asl::generateFDAdvectionDiffusion(component3Frac, 0.01,
+ flowVel, templ));
nmcomponent3->init();
std::vector<asl::SPNumMethod> bc;
@@ -188,15 +187,15 @@ int main(int argc, char *argv[])
std::vector<asl::SPNumMethod> bcDif;
bc.push_back(generateBCNoSlip(lbgk, mcfMapMem));
- bc.push_back(generateBCConstantPressure(lbgk,1.,{asl::ZE}));
+ bc.push_back(generateBCConstantPressure(lbgk, 1., {asl::ZE}));
bc.push_back(generateBCConstantPressureVelocity(lbgk, 1.,
- makeAVec(0.,0.,params.component2InVel.v()),
+ makeAVec(0., 0., params.component2InVel.v()),
{asl::Z0}));
bc.push_back(generateBCConstantPressureVelocity(lbgk, 1.,
- makeAVec(0.,-params.component1InVel.v(),0.),
+ makeAVec(0., -params.component1InVel.v(), 0.),
{asl::YE}));
- bc.push_back(generateBCConstantPressureVelocity(lbgk,1.,
- makeAVec(0.,params.component3InVel.v(),0.),
+ bc.push_back(generateBCConstantPressureVelocity(lbgk, 1.,
+ makeAVec(0., params.component3InVel.v(), 0.),
{asl::Y0}));
bcDif.push_back(generateBCNoSlipVel(lbgk, mcfMapMem));
@@ -213,8 +212,8 @@ int main(int argc, char *argv[])
initAll(bcDif);
initAll(bcV);
- std::cout<<"Finished"<<endl;
- std::cout<<"Computing..."<<endl;
+ std::cout << "Finished" << endl;
+ std::cout << "Computing..." << endl;
asl::Timer timer;
asl::WriterVTKXML writer("multicomponent_flow");
@@ -250,15 +249,15 @@ int main(int argc, char *argv[])
}
timer.stop();
- std::cout<<"Finished"<<endl;
+ std::cout << "Finished" << endl;
cout << "time=" << timer.getTime() << "; clockTime="
<< timer.getClockTime() << "; load="
<< timer.getProcessorLoad() * 100 << "%" << endl;
- std::cout<<"Output...";
- std::cout<<"Finished"<<endl;
- std::cout<<"Ok"<<endl;
+ std::cout << "Output...";
+ std::cout << "Finished" << endl;
+ std::cout << "Ok" << endl;
return 0;
}
diff --git a/examples/input_data/axial-compressor.stl b/examples/input_data/axial-compressor.stl
deleted file mode 100644
index 88f9ef7..0000000
Binary files a/examples/input_data/axial-compressor.stl and /dev/null differ
diff --git a/src/acl/Kernels/aclKernel.h b/src/acl/Kernels/aclKernel.h
index d808395..295fe1b 100644
--- a/src/acl/Kernels/aclKernel.h
+++ b/src/acl/Kernels/aclKernel.h
@@ -67,7 +67,7 @@ namespace acl
explicit Kernel(const KernelConfiguration kernelConfig_ = KERNEL_BASIC);
/// Prepares kernel for launch.
/// Should always be called before compute() after all expressions are added.
- /// Generates kernel source, builds kernel and set its arguments.
+ /// Generates kernel source, builds kernel and sets its arguments.
void setup();
void compute();
void setGroupsNumber(unsigned int n);
diff --git a/src/utilities/aslGlobalSpace.h b/src/utilities/aslGlobalSpace.h
index 01fb242..be15af9 100644
--- a/src/utilities/aslGlobalSpace.h
+++ b/src/utilities/aslGlobalSpace.h
@@ -30,7 +30,7 @@ namespace asl{
//The class describes global discrete space
/**
It is used for correct positioning of the objects and
- sychronisation of processes in time
+ synchronization of processes in time
*/
class GlobalSpace {
public:
@@ -49,4 +49,4 @@ namespace asl{
} //namespace acl
-#endif // ASLTIMESTAMP_H
+#endif // ASLGLOBALSPACE_H
diff --git a/src/utilities/aslParametersManager.cxx b/src/utilities/aslParametersManager.cxx
index e9e3145..48b356e 100644
--- a/src/utilities/aslParametersManager.cxx
+++ b/src/utilities/aslParametersManager.cxx
@@ -209,20 +209,11 @@ namespace asl
ParametersManager::ParametersManager():
configurationOptions("Configuration options"),
- parametersFileStr(""),
- platform(""),
- device(""),
+ parametersFileStr("# Parameters file with initial default values (where available).\n"),
folder(""),
- folderWithSlash(""),
- programName(""),
- programVersion("")
+ folderWithSlash("")
{
enable();
- // Add platform and device parameters with default values
- add(platform, acl::getPlatformVendor(acl::hardware.defaultQueue),
- "platform", "Default computation platform");
- add(device, acl::getDeviceName(acl::hardware.defaultQueue),
- "device", "Default computation device");
}
@@ -283,13 +274,14 @@ namespace asl
template<typename T> void ParametersManager::add(UValue<map<string, T>> parameter,
- string key,
- string description)
+ string key,
+ string description)
{
configurationOptions.add_options()
(key.c_str(), value<T>()->required(), description.c_str());
// Add the option to the default parameters file
- parametersFileStr += "\n# " + description + "\n" + key + " = \n";
+ parametersFileStr += "\n# " + description + "; substite '*' by any suffix to provide a set of related parameters\n"
+ + key + " = \n";
}
@@ -325,13 +317,90 @@ namespace asl
}
- void ParametersManager::load(int argc, char * argv[],
- string programName_,
- string programVersion_)
+ void ParametersManager::load(string configFile)
+ {
+ variables_map vm;
+
+ try
+ {
+ ifstream ifs(configFile);
+ if (!ifs)
+ errorMessage("Can not open configuration file: " + configFile);
+
+ parsed_options parsed = parse_config_file(ifs, configurationOptions,
+ true);
+ store(parsed, vm);
+ notify(vm);
+ populateMaps(vm);
+ }
+ catch(exception& e)
+ {
+ errorMessage(string("ParametersManager::load() - ") + e.what());
+ }
+ }
+
+
+ string ParametersManager::getFolder()
+ {
+ return folder;
+ }
+
+
+ string ParametersManager::getFolderWithSlash()
+ {
+ return folderWithSlash;
+ }
+
+
+ void ParametersManager::writeParametersFile(const std::string fileName)
+ {
+ ofstream fo(fileName);
+ if (!fo)
+ errorMessage("ParametersManager::writeParametersFile() - can not open file: " + fileName);
+
+ fo << parametersFileStr;
+ fo.close();
+ }
+
+
+/////////////////////////////////////////////////////// copied bellow...
+
+
+ ApplicationParametersManager::ApplicationParametersManager(string applicationName_,
+ string applicationVersion_,
+ string configFileName_):
+//??? ParametersManager(),
+ platform(acl::getPlatformVendor(acl::hardware.defaultQueue)),
+ device(acl::getDeviceName(acl::hardware.defaultQueue)),
+ applicationName(applicationName_),
+ applicationVersion(applicationVersion_),
+ configFileName(configFileName_)
+ {
+ enable();
+ // Prepend informative header
+ parametersFileStr += "# Generated by " + applicationName + " version " + applicationVersion + "\n\n"
+ + "# Get the list of all available computation devices by running:\n"
+ + "# `" + applicationName + " -d`\n";
+
+ /* Add platform and device parameters already initialized
+ with their default values */
+ add(platform, platform.v(),
+ "platform", "Default computation platform");
+ add(device, device.v(),
+ "device", "Default computation device");
+ }
+
+
+ ApplicationParametersManager::~ApplicationParametersManager()
{
- programName = programName_;
- programVersion = programVersion_;
+ // Deactivates this instance of ApplicationParametersManager
+ if (current == this)
+ current = NULL;
+ }
+
+ void ApplicationParametersManager::load(int argc, char * argv[])
+ {
variables_map vm;
options_description genericOptions("Generic options");
@@ -341,9 +410,9 @@ namespace asl
("version,v", "display version and exit")
("devices,d", "display all available devices and exit")
("folder,f", value<string>()->default_value("Default"),
- "path to the working folder that contains configuration file - parameters.ini")
+ string("path to the working folder that contains configuration file - " + configFileName).c_str())
("parameters,p", value<string>(),
- "generate default configuration file parameters.ini, write it to the provided path and exit")
+ string("generate default configuration file " + configFileName + ", write it to the provided path and ext").c_str())
("check,c", "check configuration for consistency and exit");
positional_options_description positional;
@@ -359,7 +428,7 @@ namespace asl
if (vm.count("help"))
{
- cout << "Usage: " + programName + " [WORKING_FOLDER] [OPTION]...\n"
+ cout << "Usage: " + applicationName + " [WORKING_FOLDER] [OPTION]...\n"
<< allOptions
<< endl;
exit(0);
@@ -367,14 +436,14 @@ namespace asl
if (vm.count("version"))
{
- cout << programName + " " + programVersion
+ cout << applicationName + " " + applicationVersion
<< endl;
exit(0);
}
if (vm.count("devices"))
{
- cout << programName + " " + programVersion + "\n\n"
+ cout << applicationName + " " + applicationVersion + "\n\n"
<< "Default computation device:\n"
<< acl::hardware.getDefaultDeviceInfo() << "\n\n"
<< "List of all available platforms and their devices:\n"
@@ -391,7 +460,7 @@ namespace asl
// and then cut all possible slashes at the end
p = p.parent_path();
p /= "/";
- p /= "parameters.ini";
+ p /= configFileName;
cout << "Writing default configuration file to: "
<< p.string() << endl;
@@ -408,7 +477,7 @@ namespace asl
folder = p.string();
p /= "/";
folderWithSlash = p.string();
- p /= "parameters.ini";
+ p /= configFileName;
ifstream ifs(p.string());
if (!ifs)
{
@@ -431,7 +500,7 @@ namespace asl
// Place it after(!) notify(vm);
if (vm.count("check"))
{
- cout << programName + " " + programVersion + "\n"
+ cout << applicationName + " " + applicationVersion + "\n"
<< "Consistency check - successful."
<< endl;
exit(0);
@@ -442,60 +511,5 @@ namespace asl
errorMessage(string("ParametersManager::load() - ") + e.what());
}
}
-
-
- void ParametersManager::load(string configFile)
- {
- variables_map vm;
-
- try
- {
- ifstream ifs(configFile);
- if (!ifs)
- errorMessage("Can not open configuration file: " + configFile);
-
- parsed_options parsed = parse_config_file(ifs, configurationOptions,
- true);
- store(parsed, vm);
- notify(vm);
- populateMaps(vm);
- // No need to set hardware default queue, because this
- // member functions is not called on program launch and deals with
- // parameters others than `platform` and `device`.
- }
- catch(exception& e)
- {
- errorMessage(string("ParametersManager::load() - ") + e.what());
- }
- }
-
-
- string ParametersManager::getFolder()
- {
- return folder;
- }
-
-
- string ParametersManager::getFolderWithSlash()
- {
- return folderWithSlash;
- }
-
-
- void ParametersManager::writeParametersFile(const std::string fileName)
- {
- ofstream fo(fileName);
- if (!fo)
- errorMessage("ParametersManager::writeParametersFile() - can not open file: " + fileName);
-
- // Prepend informative header
- parametersFileStr = "# Parameters file with default values (where available).\n# Generated by "
- + programName + " version " + programVersion + "\n\n"
- + "# Get the list of all available computation devices by running:\n"
- + "# `" + programName + " -d`\n" + parametersFileStr;
-
- fo << parametersFileStr;
- fo.close();
- }
-
+
} //namespace asl
diff --git a/src/utilities/aslParametersManager.h b/src/utilities/aslParametersManager.h
index 36f1ad1..f5490b7 100644
--- a/src/utilities/aslParametersManager.h
+++ b/src/utilities/aslParametersManager.h
@@ -40,9 +40,9 @@ namespace asl
template <typename T> class Parameter
{
public:
- /// \p key is the parameter's identification key in the configuration file
- /// If no default value is specified, then the parameter
- /// is required to be specified in the configuration file.
+ /// \p key is the parameter's identification key in the
+ /// configuration file. If no default value is specified, then the
+ /// parameter is required to be specified in the configuration file.
Parameter(std::string key_,
std::string description_,
std::string units_ = "");
@@ -65,8 +65,10 @@ namespace asl
};
- /// This class automatically accomodates newly created Parameters
- /// and then loads them
+ /** This class automatically accomodates newly created Parameters and then
+ can load them from a parameters file.
+ It has to be declared before declaring all the parameters it has to manage!
+ \ingroup Utilities */
class ParametersManager
{
public:
@@ -92,13 +94,6 @@ namespace asl
template <typename T>
void addPrefix(const std::string prefix,
std::shared_ptr<std::map<std::string, T>> destinationMap);
-
- /// Loads all previously declared parameters
- /// from command line and/or configuration file (provided
- /// through command line)
- void load(int argc, char* argv[],
- std::string programName_ = "program_name",
- std::string programVersion_ = "1.0");
/// Loads all previously declared parameters
/// from configuration file \p configFile
void load(std::string configFile);
@@ -107,14 +102,10 @@ namespace asl
static ParametersManager * current;
- private:
+ protected:
boost::program_options::options_description configurationOptions;
- UValue<std::string> platform;
- UValue<std::string> device;
std::string folder;
std::string folderWithSlash;
- std::string programName;
- std::string programVersion;
/// Accomodates prefixes (defined by attached "*" wildcard)
/// using PrefixStore class
std::vector<std::shared_ptr<PrefixStore>> prefixes;
@@ -128,6 +119,34 @@ namespace asl
};
+ /** This class inherits ParametersManager class and thus also automatically
+ accomodates newly created Parameters and then can load them from
+ a parameters file and/or command line. It silently includes two parameters -
+ `platform` and `device` that determine the hardware application will run on.
+ It has to be declared before declaring all the parameters it has to manage!
+ \ingroup Utilities */
+ class ApplicationParametersManager: public ParametersManager
+ {
+ public:
+ ApplicationParametersManager(std::string applicationName_,
+ std::string applicationVersion_,
+ std::string configFileName_ = "parameters.ini");
+ // ToDo: do we need the destructor? it is the same as in the base class
+ ~ApplicationParametersManager();
+
+ /** Loads all previously declared parameters from command line
+ and/or configuration file (provided through command line) */
+ void load(int argc, char* argv[]);
+
+ private:
+ UValue<std::string> platform;
+ UValue<std::string> device;
+ std::string applicationName;
+ std::string applicationVersion;
+ std::string configFileName;
+
+ };
+
//-------------------------- Implementation --------------------------
--
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