[asl] 55/177: Fixing parameters handling
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 f8b2f596861ec646fb57fe8ada1ef5a9852bdd44
Author: Avtech Scientific <AvtechScientific at users.noreply.github.com>
Date: Sat Jun 27 23:06:19 2015 +0300
Fixing parameters handling
---
examples/flow/locomotive_in_tunnel.cc | 74 +++++++++++++++---------------
examples/flow/locomotive_stability.cc | 24 +++++-----
examples/flow/multicomponent_flow.cc | 24 +++++-----
examples/levelSet/levelSetFacetedGrowth.cc | 17 +++----
src/utilities/aslParametersManager.cxx | 52 ++++++++++-----------
src/utilities/aslParametersManager.h | 29 ++++++------
6 files changed, 113 insertions(+), 107 deletions(-)
diff --git a/examples/flow/locomotive_in_tunnel.cc b/examples/flow/locomotive_in_tunnel.cc
index 062ba21..a6ef8b1 100644
--- a/examples/flow/locomotive_in_tunnel.cc
+++ b/examples/flow/locomotive_in_tunnel.cc
@@ -25,8 +25,7 @@
\example locomotive_in_tunnel.cc
*/
-#include <utilities/aslUValue.h>
-#include <math/aslVectors.h>
+#include <utilities/aslParametersManager.h>
#include <math/aslTemplates.h>
#include <aslGeomInc.h>
#include <math/aslPositionFunction.h>
@@ -35,19 +34,18 @@
#include <writers/aslVTKFormatWriters.h>
#include <num/aslLBGK.h>
#include <num/aslLBGKBC.h>
-#include "utilities/aslTimer.h"
-#include "acl/aclUtilities.h"
+#include <utilities/aslTimer.h>
#include <readers/aslVTKFormatReaders.h>
-
-typedef float FlT;
+// typedef to switch to double precision
//typedef double FlT;
-typedef asl::UValue<double> Param;
+typedef float FlT;
using asl::AVec;
using asl::makeAVec;
+// Generate geometry of the tunnel
asl::SPDistanceFunction generateTunnel(asl::Block & bl)
{
@@ -70,30 +68,32 @@ asl::SPDistanceFunction generateTunnel(asl::Block & bl)
}
-int main()
+int main(int argc, char* argv[])
{
- Param dx(0.08);
- Param dt(1.);
- Param nu(.001);
+ asl::ApplicationParametersManager appParamsManager("locomotive_in_tunnel",
+ "1.0",
+ "locomotive_in_tunnel.ini");
+ asl::Parameter<FlT> dx(0.08, "dx", "space step");
+ asl::Parameter<FlT> dt(1., "dt", "time step");
+ asl::Parameter<FlT> nu(.001, "nu", "viscosity");
- AVec<int> size(makeAVec(40., 10., 15.)*(1./dx.v()));
- asl::Block bl(size,dx.v(),makeAVec(-30., 8.58, 1.53));
+ AVec<int> size(makeAVec(40., 10., 15.) * (1. / dx.v()));
+ asl::Block bl(size, dx.v(), makeAVec(-30., 8.58, 1.53));
- Param nuNum(nu.v()*dt.v()/dx.v()/dx.v());
+ asl::UValue<FlT> nuNum(nu.v() * dt.v() / dx.v() / dx.v());
std::cout << "Flow: Data initialization...";
-
- auto object(asl::readSurface("locomotive.stl", bl));
+ auto locomotive(asl::readSurface("locomotive.stl", bl));
- asl::Block block(object->getInternalBlock());
+ asl::Block block(locomotive->getInternalBlock());
auto tunnelMap(asl::generateDataContainerACL_SP<FlT>(block, 1, 1u));
asl::initData(tunnelMap, generateTunnel(block));
auto forceField(asl::generateDataContainerACL_SP<FlT>(block, 3, 1u));
- asl::initData(forceField, makeAVec(0.,0.,0.));
+ asl::initData(forceField, makeAVec(0., 0., 0.));
std::cout << "Finished" << endl;
@@ -105,9 +105,9 @@ int main()
lbgk->init();
asl::SPLBGKUtilities lbgkUtil(new asl::LBGKUtilities(lbgk));
- lbgkUtil->initF(acl::generateVEConstant(.1,.0,.0));
+ lbgkUtil->initF(acl::generateVEConstant(.1, .0, .0));
- auto vfTunnel(asl::generatePFConstant(makeAVec(0.1,0.,0.)));
+ auto vfTunnel(asl::generatePFConstant(makeAVec(0.1, 0., 0.)));
std::vector<asl::SPNumMethod> bc;
std::vector<asl::SPNumMethod> bcV;
@@ -115,24 +115,26 @@ int main()
bc.push_back(generateBCVelocity(lbgk, vfTunnel, tunnelMap));
bcV.push_back(generateBCVelocityVel(lbgk, vfTunnel, tunnelMap));
// bcV.push_back(generateBCNoSlipRho(lbgk, tunnelMap));
- bc.push_back(generateBCNoSlip(lbgk, object));
- bcV.push_back(generateBCNoSlipVel(lbgk, object));
-// bcV.push_back(generateBCNoSlipRho(lbgk, object));
- bc.push_back(generateBCConstantPressureVelocity(lbgk, 1., makeAVec(0.1,0.,0.), {asl::X0, asl::XE}));
+ bc.push_back(generateBCNoSlip(lbgk, locomotive));
+ bcV.push_back(generateBCNoSlipVel(lbgk, locomotive));
+// bcV.push_back(generateBCNoSlipRho(lbgk, locomotive));
+ bc.push_back(generateBCConstantPressureVelocity(lbgk, 1.,
+ makeAVec(0.1, 0., 0.),
+ {asl::X0, asl::XE}));
initAll(bc);
initAll(bcV);
- auto computeForce(generateComputeSurfaceForce(lbgk, forceField, object));
+ auto computeForce(generateComputeSurfaceForce(lbgk, forceField, locomotive));
computeForce->init();
- std::cout<<"Finished"<<endl;
- std::cout<<"Computing...";
+ std::cout << "Finished" << endl;
+ std::cout << "Computing...";
asl::Timer timer;
asl::WriterVTKXML writer("locomotive_in_tunnel");
- writer.addScalars("map", *object);
+ writer.addScalars("map", *locomotive);
writer.addScalars("tunnel", *tunnelMap);
writer.addScalars("rho", *lbgk->getRho());
writer.addVector("v", *lbgk->getVelocity());
@@ -151,7 +153,7 @@ int main()
executeAll(bc);
if(!(i%1000))
{
- cout<<i<<endl;
+ cout << i << endl;
executeAll(bcV);
computeForce->execute();
writer.write();
@@ -159,15 +161,15 @@ int main()
}
timer.stop();
- std::cout<<"Finished"<<endl;
+ std::cout << "Finished" << endl;
cout << "time=" << timer.getTime() << "; clockTime="
- << timer.getClockTime() << "; load="
- << timer.getProcessorLoad() * 100 << "%" << endl;
+ << 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;
-}
+}
\ No newline at end of file
diff --git a/examples/flow/locomotive_stability.cc b/examples/flow/locomotive_stability.cc
index 0d52dae..f9b8e12 100644
--- a/examples/flow/locomotive_stability.cc
+++ b/examples/flow/locomotive_stability.cc
@@ -80,7 +80,7 @@ int main()
Param nuNum(nu.v()*dt.v()/dx.v()/dx.v());
- std::cout<<"Flow: Data initialization...";
+ std::cout << "Flow: Data initialization...";
auto object(asl::readSurface("locomotive.stl", dx.v(), .5,1.,0.,1.,2.,4.));
@@ -90,9 +90,9 @@ int main()
auto forceField(asl::generateDataContainerACL_SP<FlT>(block, 3, 1u));
asl::initData(forceField, makeAVec(0.,0.,0.));
- std::cout<<"Finished"<<endl;
+ std::cout << "Finished" << endl;
- std::cout<<"Flow: Numerics initialization...";
+ std::cout << "Flow: Numerics initialization...";
asl::SPLBGK lbgk(new asl::LBGK(block,
acl::generateVEConstant(FlT(nu.v())),
@@ -124,8 +124,8 @@ int main()
computeForce->init();
- std::cout<<"Finished"<<endl;
- std::cout<<"Computing...";
+ std::cout << "Finished" << endl;
+ std::cout << "Computing...";
asl::WriterVTKXML writer("locomotive_stability");
writer.addScalars("train", *object);
@@ -148,7 +148,7 @@ int main()
executeAll(bc);
if(!(i%1000))
{
- cout<<i<<endl;
+ cout << i << endl;
executeAll(bcV);
computeForce->execute();
writer.write();
@@ -156,15 +156,15 @@ int main()
}
timer.stop();
- std::cout<<"Finished"<<endl;
+ std::cout << "Finished" << endl;
cout << "time=" << timer.getTime() << "; clockTime="
- << timer.getClockTime() << "; load="
- << timer.getProcessorLoad() * 100 << "%" << endl;
+ << 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/flow/multicomponent_flow.cc b/examples/flow/multicomponent_flow.cc
index bbb4667..198157c 100644
--- a/examples/flow/multicomponent_flow.cc
+++ b/examples/flow/multicomponent_flow.cc
@@ -33,14 +33,13 @@
#include <writers/aslVTKFormatWriters.h>
#include <num/aslLBGK.h>
#include <num/aslLBGKBC.h>
-#include "utilities/aslTimer.h"
+#include <utilities/aslTimer.h>
#include <num/aslFDAdvectionDiffusion.h>
#include <num/aslBasicBC.h>
-
-typedef float FlT;
+// typedef to switch to double precision
//typedef double FlT;
-typedef asl::UValue<double> Param;
+typedef float FlT;
using asl::AVec;
using asl::makeAVec;
@@ -125,21 +124,24 @@ void Parameters::init()
updateNumValues();
}
-// generate geometry of the mixer
+// Generate geometry of the mixer (cross-coupled pipes)
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());
- mixerGeometry = generateDFCylinderInf(params.tubeD.v() / 2., orientation, center);
+ mixerGeometry = generateDFCylinderInf(params.tubeD.v() / 2., orientation,
+ center);
orientation[1] = 1.0;
orientation[2] = 0.0;
center[2] = params.pumpD.v() * 1.5;
- mixerGeometry = mixerGeometry | generateDFCylinderInf(params.pumpD.v() / 2., orientation, center);
+ mixerGeometry = mixerGeometry | generateDFCylinderInf(params.pumpD.v() / 2.,
+ orientation, center);
- return asl::normalize(-(mixerGeometry) | asl::generateDFInBlock(block, 0), params.dx.v());
+ return asl::normalize(-(mixerGeometry) | asl::generateDFInBlock(block, 0),
+ params.dx.v());
}
int main(int argc, char *argv[])
@@ -241,7 +243,7 @@ int main(int argc, char *argv[])
if(!(i%100))
{
timer.stop();
- cout<<i<<"/10000; expected left time: "<< timer.getLeftTime(double(i)/10000.) <<endl;
+ cout << i << "/10000; expected left time: " << timer.getLeftTime(double(i)/10000.) << endl;
executeAll(bcV);
writer.write();
timer.resume();
@@ -252,8 +254,8 @@ int main(int argc, char *argv[])
std::cout << "Finished" << endl;
cout << "time=" << timer.getTime() << "; clockTime="
- << timer.getClockTime() << "; load="
- << timer.getProcessorLoad() * 100 << "%" << endl;
+ << timer.getClockTime() << "; load="
+ << timer.getProcessorLoad() * 100 << "%" << endl;
std::cout << "Output...";
std::cout << "Finished" << endl;
diff --git a/examples/levelSet/levelSetFacetedGrowth.cc b/examples/levelSet/levelSetFacetedGrowth.cc
index 961e553..7e03556 100644
--- a/examples/levelSet/levelSetFacetedGrowth.cc
+++ b/examples/levelSet/levelSetFacetedGrowth.cc
@@ -47,27 +47,28 @@ acl::TypeID type(acl::typeToTypeID<FlT>());
int main(int argc, char* argv[])
{
- asl::ApplicationParametersManager appParamsManager("levelSetFacetedGrowth", "1.0",
+ asl::ApplicationParametersManager appParamsManager("levelSetFacetedGrowth",
+ "1.0",
"levelSetFacetedGrowth.ini");
asl::Parameter<asl::AVec<int>> size("size", "size");
asl::Parameter<FlT> dx("dx", "dx");
asl::Parameter<FlT> dt("dt", "dt");
- asl::Parameter<FlT> superS("superS", "super satuation");
- asl::Parameter<FlT> radius("radius", "initial radius");
+ asl::Parameter<FlT> superS("superS", "Super saturation");
+ asl::Parameter<FlT> radius("radius", "Initial radius");
asl::Parameter<FlT> betaSt("beta_step", "Kinetic coefficient for step");
asl::Parameter<FlT> betaDisl("beta_dislocation", "Kinetic coefficient for dislocation");
asl::Parameter<FlT> betaRough("beta_rough", "Kinetic coefficient for rough region");
asl::Parameter<map<string, asl::AVec<FlT>>> cr_directions_p("cr_direction_*",
- "crystallographic directions");
+ "Crystallographic directions");
asl::Parameter<cl_uint> nIterations("nIterations", "Number of iterations");
asl::Parameter<cl_uint> nItOut("nItOut", "Number of iterations for output");
appParamsManager.load(argc, argv);
- std::cout<<"LevelSet: Data initialization...";
+ std::cout << "LevelSet: Data initialization...";
asl::Block block(size.v(), dx.v());
auto levelSet(asl::generateDataContainerACL_SP<FlT>(block, 1, 1u));
@@ -111,11 +112,11 @@ 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;
+ << timer.getClockTime() << "; load="
+ << timer.getProcessorLoad() * 100 << "%" << endl;
std::cout << "Output...";
std::cout << "Finished" << endl;
diff --git a/src/utilities/aslParametersManager.cxx b/src/utilities/aslParametersManager.cxx
index 5032a97..b100338 100644
--- a/src/utilities/aslParametersManager.cxx
+++ b/src/utilities/aslParametersManager.cxx
@@ -208,8 +208,8 @@ namespace asl
ParametersManager * ParametersManager::current(NULL);
ParametersManager::ParametersManager():
- configurationOptions("Configuration options"),
- parametersFileStr("# Parameters file with initial default values (where available).\n"),
+ parametersOptions("Parameters options"),
+ parametersFileStr("# Parameters file\n"),
folder(""),
folderWithSlash("")
{
@@ -265,10 +265,10 @@ namespace asl
string key,
string description)
{
- configurationOptions.add_options()
+ parametersOptions.add_options()
(key.c_str(), value<T>(¶meter.v())->required(), description.c_str());
- // Add the option to the default parameters file
+ // Add the parameter to the default parameters file
parametersFileStr += "\n# " + description + "\n" + key + " = \n";
}
@@ -277,9 +277,9 @@ namespace asl
string key,
string description)
{
- configurationOptions.add_options()
+ parametersOptions.add_options()
(key.c_str(), value<T>()->required(), description.c_str());
- // Add the option to the default parameters file
+ // Add the parameter to the default parameters file
parametersFileStr += "\n# " + description + "; substite '*' by any suffix to provide a set of related parameters\n"
+ key + " = \n";
}
@@ -290,11 +290,11 @@ namespace asl
string key,
string description)
{
- configurationOptions.add_options()
+ parametersOptions.add_options()
(key.c_str(), value<T>(¶meter.v())->default_value(defaultValue),
description.c_str());
- // Add the option to the default parameters file
+ // Add the parameter to the default parameters file
parametersFileStr += "\n# " + description + "\n"
+ key + " = " + numToStr(defaultValue) + "\n";
}
@@ -317,17 +317,17 @@ namespace asl
}
- void ParametersManager::load(string configFile)
+ void ParametersManager::load(string paramFile)
{
variables_map vm;
try
{
- ifstream ifs(configFile);
+ ifstream ifs(paramFile);
if (!ifs)
- errorMessage("Can not open configuration file: " + configFile);
+ errorMessage("Can not open parameters file: " + paramFile);
- parsed_options parsed = parse_config_file(ifs, configurationOptions,
+ parsed_options parsed = parse_config_file(ifs, parametersOptions,
true);
store(parsed, vm);
notify(vm);
@@ -365,12 +365,12 @@ namespace asl
ApplicationParametersManager::ApplicationParametersManager(string applicationName_,
string applicationVersion_,
- string configFileName_):
+ string paramFileName_):
platform(acl::getPlatformVendor(acl::hardware.defaultQueue)),
device(acl::getDeviceName(acl::hardware.defaultQueue)),
applicationName(applicationName_),
applicationVersion(applicationVersion_),
- configFileName(configFileName_)
+ paramFileName(paramFileName_)
{
enable();
// Prepend informative header
@@ -394,21 +394,21 @@ namespace asl
options_description genericOptions("Generic options");
genericOptions.add_options()
- ("help,h", "display this help and exit")
- ("version,v", "display version and exit")
- ("devices,d", "display all available devices and exit")
+ ("help,h", "Display this help and exit")
+ ("version,v", "Display version and exit")
+ ("devices,d", "Display all available devices and exit")
("folder,f", value<string>()->default_value("Default"),
- string("path to the working folder that contains configuration file - " + configFileName).c_str())
+ string("Path to the working folder that contains parameters file - " + paramFileName).c_str())
("parameters,p", value<string>(),
- string("generate default configuration file " + configFileName + ", write it to the provided path and ext").c_str())
- ("check,c", "check configuration for consistency and exit");
+ string("Generate default parameters file " + paramFileName + ", write it to the provided path and exit").c_str())
+ ("check,c", "Check parameters for consistency and exit");
positional_options_description positional;
options_description allOptions;
positional.add("folder", 1);
- allOptions.add(genericOptions).add(configurationOptions);
+ allOptions.add(genericOptions).add(parametersOptions);
try
{
@@ -448,9 +448,9 @@ namespace asl
// and then cut all possible slashes at the end
p = p.parent_path();
p /= "/";
- p /= configFileName;
+ p /= paramFileName;
- cout << "Writing default configuration file to: "
+ cout << "Writing default parameters file to: "
<< p.string() << endl;
writeParametersFile(p.string());
@@ -465,13 +465,13 @@ namespace asl
folder = p.string();
p /= "/";
folderWithSlash = p.string();
- p /= configFileName;
+ p /= paramFileName;
ifstream ifs(p.string());
if (!ifs)
{
// Only warn, since all options might have default values, or required values
- // provided through the command line - so no configuration file is required
- warningMessage("ParametersManager::load() - can not open configuration file: " + p.string());
+ // provided through the command line - so no parameters file is required
+ warningMessage("ParametersManager::load() - can not open parameters file: " + p.string());
}
parsed_options parsed = parse_config_file(ifs, allOptions, true);
diff --git a/src/utilities/aslParametersManager.h b/src/utilities/aslParametersManager.h
index 87f4dd0..4ac5808 100644
--- a/src/utilities/aslParametersManager.h
+++ b/src/utilities/aslParametersManager.h
@@ -35,20 +35,21 @@ namespace asl
class PrefixStore;
/// This class stores parameter's value and the information
- /// needed to extract it from command line and/or configuration file
+ /// needed to extract it from command line and/or parameters file
/// \ingroup LDI
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.
+ /// parameters file. If no default value is specified, then the
+ /// parameter is required to be specified in the parameters file
+ /// or command line.
Parameter(std::string key_,
std::string description_,
std::string units_ = "");
- /// \p key is the parameter's identification key in the configuration file
- /// If a default value is specified, then the parameter
- /// is not required to be specified in the configuration file.
+ /// \p key is the parameter's identification key in the parameters file
+ /// If a default value is specified, then the parameter is not
+ /// required to be specified in the parameters file or command line.
Parameter(T defaultValue,
std::string key_,
std::string description_,
@@ -67,7 +68,7 @@ namespace asl
/** 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!
+ It has to be declared before declaring all the parameters it will manage!
\ingroup Utilities */
class ParametersManager
{
@@ -95,15 +96,15 @@ namespace asl
void addPrefix(const std::string prefix,
std::shared_ptr<std::map<std::string, T>> destinationMap);
/// Loads all previously declared parameters
- /// from configuration file \p configFile
- void load(std::string configFile);
+ /// from parameters file \p paramFile
+ void load(std::string paramFile);
std::string getFolder();
std::string getFolderWithSlash();
static ParametersManager * current;
protected:
- boost::program_options::options_description configurationOptions;
+ boost::program_options::options_description parametersOptions;
std::string folder;
std::string folderWithSlash;
/// Accomodates prefixes (defined by attached "*" wildcard)
@@ -123,17 +124,17 @@ namespace asl
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!
+ It has to be declared before declaring all the parameters it will manage!
\ingroup Utilities */
class ApplicationParametersManager: public ParametersManager
{
public:
ApplicationParametersManager(std::string applicationName_,
std::string applicationVersion_,
- std::string configFileName_ = "parameters.ini");
+ std::string paramFileName_ = "parameters.ini");
/** Loads all previously declared parameters from command line
- and/or configuration file (provided through command line) */
+ and/or parameters file (provided through command line) */
void load(int argc, char* argv[]);
private:
@@ -141,7 +142,7 @@ namespace asl
UValue<std::string> device;
std::string applicationName;
std::string applicationVersion;
- std::string configFileName;
+ std::string paramFileName;
};
--
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