POD application. This application computes the POD basis using the setup specified through an xml dictionary. To print the usage: ./POD_application_example_00001 –help
.
POD application. This application computes the POD basis using the setup specified through an xml dictionary. To print the usage: ./POD_application_example_00001 –help
#if BITPIT_ENABLE_MPI
#include <mpi.h>
#endif
#include "pod.hpp"
using namespace bitpit;
enum class Verbose{
QUIET=0 ,
NORMAL=1 ,
FULL=2
};
}
*this = other;
}
return *this;
}
};
if(argc <2) {
std::cout<<"Error. Not enough arguments found launching the application"<<std::endl;
std::cout<<"Please run application_example_00001 --help for a brief guide on how to use it"<<std::endl;
exit(1);
}
std::unordered_set<std::string> input;
for(int i=1; i<argc; ++i){
std::string temp = argv[i];
}
if(input.count("--help")>0){
std::cout<<"++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"<<std::endl;
std::cout<<""<<std::endl;
std::cout<<" Brief application_example_00001 helper, version 1.0"<<std::endl;
std::cout<<""<<std::endl;
std::cout<<""<<std::endl;
std::cout<<" This is the executable command for running POD instructions from XML Control Dictionaries"<<std::endl;
std::cout<<" The command needs mandatorily a XML dictionary to run. It can return execution info on "<<std::endl;
std::cout<<" both console(screen) and external log file. As further debug info, it can plot optional "<<std::endl;
std::cout<<" results of its execution. "<<std::endl;
std::cout<<" "<<std::endl;
std::cout<<" The full list of options for running the application are: "<<std::endl;
std::cout<<" "<<std::endl;
std::cout<<" "<<std::endl;
std::cout<<" "<<std::endl;
std::cout<<" --help : print this helper "<<std::endl;
std::cout<<" "<<std::endl;
std::cout<<" --dict=<dictionary name> : full path to the target xml dictionary. Mandatory. "<<std::endl;
std::cout<<" "<<std::endl;
std::cout<<" --vconsole=<quiet/normal/full> : print info on the execution on console(screen). "<<std::endl;
std::cout<<" full is meant for full debug message verbosity, normal for "<<std::endl;
std::cout<<" a medium verbosity, quiet shut off messaging on console. "<<std::endl;
std::cout<<" Default verbosity is medium. "<<std::endl;
std::cout<<" "<<std::endl;
std::cout<<" --vlog=<quiet/normal/full> : print info on the execution external file bitpit.log. "<<std::endl;
std::cout<<" full is meant for full debug message verbosity, normal for "<<std::endl;
std::cout<<" a medium verbosity, quiet shut off messaging on file. "<<std::endl;
std::cout<<" Default verbosity is full. "<<std::endl;
std::cout<<" "<<std::endl;
std::cout<<" "<<std::endl;
std::cout<<" "<<std::endl;
std::cout<<" For any problem, bug and malfunction please contact bitpit developers. "<<std::endl;
std::cout<<"++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"<<std::endl;
exit(1);
}
std::unordered_map<int, std::string> keymap;
keymap[0] = "dict=";
keymap[1] = "vlog=";
keymap[2] = "vconsole=";
std::map<int, std::string> final_map;
for(const auto &val: input){
std::size_t pos = std::string::npos;
int counter=0;
while (pos == std::string::npos && counter <3){
pos = val.find(keymap[counter]);
++counter;
}
if(pos != std::string::npos) final_map[counter-1] =val.substr(pos+keymap[counter-1].size());
}
if(final_map.count(0) < 1) {
std::cout<<"Error. Not valid xml dictionary found launching the application"<<std::endl;
std::cout<<"Please run application_example_00001 --help for a brief guide on how to use it"<<std::endl;
exit(1);
}
if(final_map.count(1)){
int check = -1 + int(final_map[1]==
"quiet") + 2*int(final_map[1]==
"normal") + 3*int(final_map[1]==
"full");
if(check == -1)
check = 2;
}
if(final_map.count(2)){
int check = -1 + int(final_map[2]==
"quiet") + 2*int(final_map[2]==
"normal") + 3*int(final_map[2]==
"full");
if(check == -1)
check = 1;
}
return result;
}
std::string input = slotXML.
get(
"Directory");
std::string temp = ".";
if(!input.empty())
else
}
std::string input = slotXML.
get(
"Name");
std::string temp = "pod";
if(!input.empty())
else
}
std::string input = slotXML.
get(
"MemoryMode");
if(input =="MEMORY_LIGHT")
else
}
std::string input = slotXML.
get(
"RunMode");
if(input =="RESTORE")
else
}
std::string input = slotXML.
get(
"WriteMode");
if(input =="NONE")
else if(input =="DEBUG")
else
}
std::string input = slotXML.
get(
"ReconstructionMode");
if(input =="MINIMIZATION")
else
}
std::string input = slotXML.
get(
"ErrorMode");
if(input =="SINGLE")
else if(input =="COMBINED")
else
}
std::string input = slotXML.
get(
"StaticMesh");
bool value = false;
if(!input.empty()){
std::stringstream ss(input);
ss >> value;
}
}
std::string input = slotXML.
get(
"MeshType");
if(input =="VOLOCTREE")
else
}
else{
}
std::string meshDir = slotXML.
get(
"MeshDirectory");
if(!meshDir.empty()){
std::string meshName = slotXML.
get(
"MeshName");
if(!meshName.empty()){
podInst.
setMesh(meshDir, meshName);
}
}
}
}
std::string input = slotXML.
get(
"Mean");
bool value = false;
if(!input.empty()){
std::stringstream ss(input);
ss >> value;
}
}
std::string input = slotXML.
get(
"Modes");
std::size_t temp = std::numeric_limits<std::size_t>::max();
if(!input.empty()){
std::stringstream ss(input);
ss>>temp;
}
}
std::string input = slotXML.
get(
"Energy");
double temp = 100;
if(!input.empty()){
std::stringstream ss(input);
ss>>temp;
}
}
std::string input = slotXML.
get(
"ErrorThreshold");
double temp = 0;
if(!input.empty()){
std::stringstream ss(input);
ss>>temp;
}
}
std::vector<std::string> tempsf;
std::vector<std::array<std::string,3>> tempvf;
if(slotXML.
hasOption(
"targetErrorScalarFields")){
std::string input = slotXML.
get(
"targetErrorScalarFields");
if(!input.empty()){
std::stringstream ss(input);
ss>>tempsf;
}
}
if(slotXML.
hasOption(
"targetErrorVectorFields")){
std::string input = slotXML.
get(
"targetErrorVectorFields");
if(!input.empty()){
std::stringstream ss(input);
ss>>tempvf;
}
}
log::cout().setDefaultSeverity(bitpit::log::LEVEL_INFO);
log::cout()<< "Finished reading XML dictionary"<<std::endl;
{
std::vector<std::string> emode(2, "restore");
emode[1] = "compute";
std::vector<std::string> mmode(2, "normal");
emode[1] = "light";
std::vector<std::string> wmode(3, "dump");
wmode[1] = "debug";
wmode[2] = "none";
std::vector<std::string> rmode(2, "projection");
wmode[1] = "minimization";
std::vector<std::string> errmode(3, "combined");
wmode[1] = "single";
wmode[2] = "none";
log::cout()<<
"Resume of arguments in "<< podInst.
getName() <<
" : " << std::endl;
log::cout()<<
"execution mode: "<<emode[
static_cast<int>(podInst.
getRunMode())]<<std::endl;
log::cout()<<
"memory mode: "<<mmode[
static_cast<int>(podInst.
getMemoryMode())]<<std::endl;
log::cout()<<
"write mode: "<<wmode[
static_cast<int>(podInst.
getWriteMode())]<<std::endl;
log::cout()<<
"reconstruction mode: "<<rmode[
static_cast<int>(podInst.
getReconstructionMode())]<<std::endl;
log::cout()<<
"error mode: "<<errmode[
static_cast<int>(podInst.
getErrorMode())]<<std::endl;
log::cout()<<
"number of modes: "<<podInst.
getModeCount()<<std::endl;
log::cout()<< " "<<std::endl;
log::cout()<< " "<<std::endl;
}
}
std::vector<bool> controls;
controls.resize(3,false);
std::string input = slotXML.
get(
"doPODbasis");
bool temp=true;
if(!input.empty()){
std::stringstream ss(input);
ss>>temp;
}
controls[0]=temp;
}
else
controls[0]=true;
std::string input = slotXML.
get(
"doLeave1out");
bool temp=false;
if(!input.empty()){
std::stringstream ss(input);
ss>>temp;
}
controls[1]=temp;
}
std::string input = slotXML.
get(
"doBoundingBox");
bool temp=false;
if(!input.empty()){
std::stringstream ss(input);
ss>>temp;
}
controls[2]=temp;
}
return controls;
}
std::vector<bool> read_Dictionary(
POD & podInst) {
std::vector<bool> exeFlags;
exeFlags.resize(3,false);
log::cout().setDefaultSeverity(bitpit::log::LEVEL_INFO);
log::cout()<< "Currently reading XML dictionary"<<std::endl;
if(config::root.hasSection("POD")){
read_podXML(podXML, podInst);
log::cout() <<
"...Instantiated pod: "<< podInst.
getName() << std::endl;
}else{
log::cout().setDefaultSeverity(bitpit::log::LEVEL_INFO);
log::cout()<<"No POD section available in the XML dictionary"<<std::endl;
}
if(config::root.hasSection("Database")){
for(auto & sect : blockXML.getSections()){
std::string name = ".";
std::string path = ".";
std::size_t ns, first = 0;
std::size_t stride = 1;
name = sect.second->
get(
"Case");
path = sect.second->get("Directory");
std::string nss = sect.second->get("NSnapshots");
std::stringstream ss(nss);
ss >> ns;
if(sect.second->hasOption("Stride")){
std::string sstride = sect.second->get("Stride");
std::stringstream ssstride(sstride);
ssstride >> stride;
}
if(sect.second->hasOption("FirstSnapshot")){
std::string sfirst = sect.second->get("FirstSnapshot");
std::stringstream ssfirst(sfirst);
ssfirst >> first;
}
for (std::size_t i = first; i < ns; i+=stride){
snap.
name = name +
"." + std::to_string(i);
}
}
}else{
log::cout().setDefaultSeverity(bitpit::log::LEVEL_INFO);
log::cout()<<"No Database section available in the XML dictionary"<<std::endl;
}
if(config::root.hasSection("Reconstruction")){
for(auto & sect : blockXML.getSections()){
std::string name = ".";
std::string path = ".";
std::size_t ns, first = 0;
std::size_t stride = 1;
name = sect.second->
get(
"Case");
path = sect.second->get("Directory");
std::string nss = sect.second->get("NSnapshots");
std::stringstream ss(nss);
ss >> ns;
if(sect.second->hasOption("Stride")){
std::string sstride = sect.second->get("Stride");
std::stringstream ssstride(sstride);
ssstride >> stride;
}
if(sect.second->hasOption("FirstSnapshot")){
std::string sfirst = sect.second->get("FirstSnapshot");
std::stringstream ssfirst(sfirst);
ssfirst >> first;
}
for (std::size_t i = first; i < ns; i+=stride){
snap.
name = name +
"." + std::to_string(i);
}
}
}
if(config::root.hasSection("Leave1out")){
for(auto & sect : blockXML.getSections()){
std::string name = ".";
std::string path = ".";
std::size_t ns, first = 0;
std::size_t stride = 1;
name = sect.second->
get(
"Case");
path = sect.second->get("Directory");
std::string nss = sect.second->get("NSnapshots");
std::stringstream ss(nss);
ss >> ns;
if(sect.second->hasOption("Stride")){
std::string sstride = sect.second->get("Stride");
std::stringstream ssstride(sstride);
ssstride >> stride;
}
if(sect.second->hasOption("FirstSnapshot")){
std::string sfirst = sect.second->get("FirstSnapshot");
std::stringstream ssfirst(sfirst);
ssfirst >> first;
}
for (std::size_t i = first; i < ns; i+=stride){
snap.
name = name +
"." + std::to_string(i);
}
}
}
if(config::root.hasSection("JobControls")){
exeFlags=read_jobControlsXML(jobXML, podInst);
}else
exeFlags[0]=true;
log::cout().setDefaultSeverity(bitpit::log::LEVEL_INFO);
log::cout()<< "Finished reading XML dictionary"<<std::endl;
return exeFlags;
}
std::string log = "bitpit";
switch(
int(
info.vconsole)){
case 1 :
break;
case 2 :
break;
case 0 :
break;
default:
break;
}
case 1 :
break;
case 2 :
break;
case 0 :
break;
default:
break;
}
log::cout().setDefaultSeverity(bitpit::log::LEVEL_INFO);
{
std::vector<std::string> verb(3, "quiet");
verb[1] = "normal";
verb[2] = "full";
log::cout()<< "Resume of arguments:"<<std::endl;
log::cout()<<
"dictionary: "<<
info.dictName<<std::endl;
log::cout()<<
"console verbosity: "<<verb[
static_cast<int>(
info.vconsole)]<<std::endl;
log::cout()<<
"log file verbosity: "<<verb[
static_cast<int>(
info.vlog)]<<std::endl;
log::cout()<< " "<<std::endl;
log::cout()<< " "<<std::endl;
}
std::vector<bool> exes;
exes=read_Dictionary(podInst);
log::cout().setDefaultSeverity(bitpit::log::LEVEL_INFO);
log::cout()<<"Execution of pod... ";
if (exes[1])
if (exes[2])
if (exes[0])
log::cout().setDefaultSeverity(bitpit::log::LEVEL_INFO);
log::cout()<<"...execution of pod done"<<std::endl;
}
int main( int argc, char *argv[] ) {
#if BITPIT_ENABLE_MPI
MPI_Init(&argc, &argv);
{
#endif
try{
podcore(info);
}
catch(std::exception & e){
std::cout<<"application_example_00001 exited with an error of type : "<<e.what()<<std::endl;
return 1;
}
#if BITPIT_ENABLE_MPI
}
MPI_Finalize();
#endif
return 0;
}
const std::string & get(const std::string &key) const
Section & getSection(const std::string &key)
bool hasOption(const std::string &key) const
void setDefaultSeverity(log::Level severity)
The POD (Proper Orthogonal Decomposition) class provides an interface for defining POD object.
void setErrorThreshold(double threshold)
std::size_t getModeCount()
void setRunMode(RunMode mode)
void setTargetErrorFields(std::vector< std::string > &namesf, std::vector< std::array< std::string, 3 > > &namevf)
void setMeshType(MeshType type)
void setStaticMesh(bool flag)
void setMemoryMode(MemoryMode mode)
double getErrorThreshold()
void setDirectory(const std::string &directory)
const std::string & getName()
ReconstructionMode getReconstructionMode()
void evalErrorBoundingBox()
MemoryMode getMemoryMode()
void setUseMean(bool flag)
void addReconstructionSnapshot(const std::string &directory, const std::string &name)
void removeLeave1outSnapshot(const std::string &directory, const std::string &name)
void setWriteMode(WriteMode mode)
void setReconstructionMode(ReconstructionMode mode)
void setEnergyLevel(double energy)
void setModeCount(std::size_t nmodes)
void setName(const std::string &name)
void setErrorMode(ErrorMode mode)
void setMesh(const std::string &directory, const std::string &name)
void addSnapshot(const std::string &directory, const std::string &name)
#define BITPIT_UNUSED(variable)
std::string & trim(std::string &s)
void reset(const std::string &rootName)
void read(const std::string &filename, bool append)
unsigned int check(std::ifstream &, std::vector< std::vector< int > > &)
Logger & cout(log::Level defaultSeverity, log::Visibility defaultVisibility)
Logger & setFileVerbosity(Logger &logger, const log::Level &threshold)
Logger & info(log::Visibility defaultVisibility)
Logger & setConsoleVerbosity(Logger &logger, const log::Level &threshold)
database of essential information absorbed from the custom arguments
InfoBitpodPP & operator=(const InfoBitpodPP &other)
The SnapFile structure is used to store the file names inside POD classes.