Commit 3a91a6e9 authored by Chris Cantwell's avatar Chris Cantwell
Browse files

Tidy up formatting and structure of code.

parent 95467528
......@@ -73,9 +73,9 @@ namespace Nektar
return 0;
}
/**
*
*
*/
bool CommSerial::v_TreatAsRankZero(void)
{
......
......@@ -71,7 +71,7 @@ namespace Nektar
LIB_UTILITIES_EXPORT virtual void v_Finalise();
LIB_UTILITIES_EXPORT virtual int v_GetRank();
LIB_UTILITIES_EXPORT virtual bool v_TreatAsRankZero(void);
LIB_UTILITIES_EXPORT virtual void v_Block();
LIB_UTILITIES_EXPORT virtual void v_Send(int pProc, Array<OneD, NekDouble>& pData);
LIB_UTILITIES_EXPORT virtual void v_Send(int pProc, Array<OneD, int>& pData);
......
......@@ -136,7 +136,8 @@ namespace Nektar
SetCoeffPhys();
if(variable.compare("DefaultVar") != 0) // do not set up BCs if default variable
// Do not set up BCs if default variable
if(variable.compare("DefaultVar") != 0)
{
SetupBoundaryConditions(HomoBasis,lhom,bcs,variable);
}
......
......@@ -180,7 +180,8 @@ namespace Nektar
m_trace(NullExpListSharedPtr)
{
// Set up boundary conditions for this variable.
if(variable.compare("DefaultVar") != 0) // do not set up BCs if default variable
// Do not set up BCs if default variable
if(variable.compare("DefaultVar") != 0)
{
SpatialDomains::BoundaryConditions bcs(m_session, graph2D);
GenerateBoundaryConditionExpansion(graph2D, bcs, variable);
......
......@@ -146,7 +146,8 @@ namespace Nektar
SetCoeffPhys();
if(variable.compare("DefaultVar") != 0) // do not set up BCs if default variable
// Do not set up BCs if default variable
if(variable.compare("DefaultVar") != 0)
{
SetupBoundaryConditions(HomoBasis, lhom, bcs, variable);
}
......
......@@ -1433,13 +1433,13 @@ namespace Nektar
{
ncnt_low++;
}
if(xval > m_domainRange->xmax)
{
ncnt_up++;
}
}
// check for all verts to be less or greater than
// range so that if element spans thin range then
// it is still included
......@@ -1461,13 +1461,13 @@ namespace Nektar
{
ncnt_low++;
}
if(yval > m_domainRange->ymax)
{
ncnt_up++;
}
}
// check for all verts to be less or greater than
// range so that if element spans thin range then
// it is still included
......@@ -1488,7 +1488,7 @@ namespace Nektar
for(int i = 0; i < nverts; ++i)
{
NekDouble zval = (*geom.GetVertex(i))[2];
if(zval < m_domainRange->zmin)
{
ncnt_low++;
......@@ -1535,7 +1535,7 @@ namespace Nektar
{
ncnt_low++;
}
if(xval > m_domainRange->xmax)
{
ncnt_up++;
......@@ -1562,13 +1562,13 @@ namespace Nektar
{
ncnt_low++;
}
if(yval > m_domainRange->ymax)
{
ncnt_up++;
}
}
}
// check for all verts to be less or greater than
// range so that if element spans thin range then
// it is still included
......@@ -1577,7 +1577,7 @@ namespace Nektar
returnval = false;
}
}
if(m_domainRange->doZrange)
{
int ncnt_low = 0;
......@@ -1585,7 +1585,7 @@ namespace Nektar
for(int i = 0; i < nverts; ++i)
{
NekDouble zval = (*geom.GetVertex(i))[2];
if(zval < m_domainRange->zmin)
{
ncnt_low++;
......@@ -1596,7 +1596,7 @@ namespace Nektar
ncnt_up++;
}
}
// check for all verts to be less or greater than
// range so that if element spans thin range then
// it is still included
......@@ -1606,7 +1606,7 @@ namespace Nektar
}
}
}
return returnval;
}
......
......@@ -46,39 +46,47 @@ int main(int argc, char* argv[])
{
po::options_description desc("Available options");
desc.add_options()
("help,h", "Produce this help message.")
("modules-list,l", "Print the list of available modules.")
("output-points,n",po::value<int>(),
"Output at p equipspaced points (for .dat, .vtk).")
("error,e", "write error of fields for regression checking")
("range,r",po::value<string>(),
"define output range i.e. (-r xmin,xmax,ymin,ymax,zmin,zmax) in which any vertex is contained .")
("nprocs",po::value<int>(),
"used to define nprocs if running serial problem to mimic parallel run.")
("procid",po::value<int>(),
"process as single procid of a partition of size nproc (-nproc must be specified).")
("modules-opt,p", po::value<string>(),
"Print options for a module.")
("module,m", po::value<vector<string> >(),
"Specify modules which are to be used.")
("useSessionVariables", "Use variables defined in session for output")
("verbose,v", "Enable verbose mode.");
("help,h",
"Produce this help message.")
("modules-list,l",
"Print the list of available modules.")
("output-points,n", po::value<int>(),
"Output at p equipspaced points (for .dat, .vtk).")
("error,e",
"Write error of fields for regression checking")
("range,r", po::value<string>(),
"Define output range i.e. (-r xmin,xmax,ymin,ymax,zmin,zmax) "
"in which any vertex is contained.")
("nprocs", po::value<int>(),
"Used to define nprocs if running serial problem to mimic "
"parallel run.")
("procid", po::value<int>(),
"Process as single procid of a partition of size nproc "
"(-nproc must be specified).")
("modules-opt,p", po::value<string>(),
"Print options for a module.")
("module,m", po::value<vector<string> >(),
"Specify modules which are to be used.")
("useSessionVariables",
"Use variables defined in session for output")
("verbose,v",
"Enable verbose mode.");
po::options_description hidden("Hidden options");
hidden.add_options()
("input-file", po::value<vector<string> >(), "Input filename");
po::options_description cmdline_options;
cmdline_options.add(hidden).add(desc);
po::options_description visible("Allowed options");
visible.add(desc);
po::positional_options_description p;
p.add("input-file", -1);
po::variables_map vm;
try
{
po::store(po::command_line_parser(argc, argv).
......@@ -98,28 +106,28 @@ int main(int argc, char* argv[])
GetModuleFactory().PrintAvailableClasses(std::cerr);
return 1;
}
if (vm.count("modules-opt"))
{
vector<string> tmp1;
boost::split(tmp1, vm["modules-opt"].as<string>(),
boost::is_any_of(":"));
if (tmp1.size() != 2)
{
cerr << "ERROR: To specify a module, use one of in, out or proc "
<< "together with the filename; for example in:vtk." << endl;
return 1;
}
if (tmp1[0] != "in" && tmp1[0] != "out" && tmp1[0] != "proc")
{
cerr << "ERROR: Invalid module type " << tmp1[0] << endl;
return 1;
}
ModuleType t;
if (tmp1[0] == "in")
{
t = eInputModule;
......@@ -132,7 +140,7 @@ int main(int argc, char* argv[])
{
t = eProcessModule;
}
FieldSharedPtr f = boost::shared_ptr<Field>(new Field());
ModuleSharedPtr mod = GetModuleFactory().CreateInstance(
ModuleKey(t, tmp1[1]), f);
......@@ -140,30 +148,30 @@ int main(int argc, char* argv[])
mod->PrintConfig();
return 1;
}
if (vm.count("help") || vm.count("input-file") != 1) {
cerr << "Usage: FieldConvert [options] inputfile.ext1 outputfile.ext2"
<< endl;
cout << desc;
cout << endl;
cout << "Example Usage: \n" << endl;
cout << "\t FieldConvert -m vorticity file.xml file.fld file_vort.fld " << endl;
cout << "(This will add vorticity to file file.fld and put it in a new file file_vort.fld) " << endl;
cout << "\t FieldConvert -m vorticity file.xml file.fld file_vort.fld "
<< endl;
cout << "(This will add vorticity to file file.fld and put it in a "
"new file file_vort.fld) " << endl;
cout << endl;
cout << "\t FieldConvert file.xml file_vort.fld file_vort.dat " << endl;
cout << "(process file_vort.fld and make a tecplot output file_vort.dat) " << endl;
cout << "(process file_vort.fld and make a tecplot output "
"file_vort.dat) " << endl;
return 1;
}
ASSERTL0(vm.count("input-file"),
"Must specify input(s) and/or output file.");
vector<string> inout = vm["input-file"].as<vector<string> >();
if (inout.size() < 1)
{
cerr << "ERROR: You must specify input(s) and/or output file." << endl;
return 1;
}
/*
* Process list of modules. Each element of the vector of module strings can
* be in the following form:
......@@ -173,44 +181,38 @@ int main(int argc, char* argv[])
* where the only required argument is 'modname', specifing the name of the
* module to load.
*/
FieldSharedPtr f = boost::shared_ptr<Field>(new Field());
if (LibUtilities::GetCommFactory().ModuleExists("ParallelMPI"))
{
if(vm.count("procid"))
{
int nprocs, rank;
int nprocs;
int rank = vm["procid"].as<int>();
ASSERTL0(vm.count("nprocs"),
"Must specify --nprocs when using --procid option");
nprocs = vm["nprocs"].as<int>();
rank = vm["procid"].as<int>();
if(vm.count("nprocs"))
{
nprocs = vm["nprocs"].as<int>();
}
else
{
ASSERTL0(false,"Must specify --nprocs when using --procid option");
}
LibUtilities::CommSharedPtr vComm = boost::shared_ptr<FieldConvertComm>(new FieldConvertComm(argc, argv, nprocs,rank));
f->m_comm = vComm;
f->m_comm = boost::shared_ptr<FieldConvertComm>(
new FieldConvertComm(argc, argv, nprocs,rank));
}
else
{
f->m_comm = LibUtilities::GetCommFactory().CreateInstance(
"ParallelMPI", argc, argv);
"ParallelMPI", argc, argv);
}
}
else
{
f->m_comm = LibUtilities::GetCommFactory().CreateInstance("Serial", argc, argv);
f->m_comm = LibUtilities::GetCommFactory().CreateInstance(
"Serial", argc, argv);
}
vector<ModuleSharedPtr> modules;
vector<string> modcmds;
if (vm.count("verbose"))
{
f->m_verbose = true;
......@@ -220,14 +222,14 @@ int main(int argc, char* argv[])
{
modcmds = vm["module"].as<vector<string> >();
}
// Add input and output modules to beginning and end of this vector.
modcmds.insert(modcmds.begin(), inout.begin(), inout.end()-1);
modcmds.push_back(*(inout.end()-1));
int nInput = inout.size()-1;
InputModuleSharedPtr inputModule;
for (int i = 0; i < modcmds.size(); ++i)
{
// First split each command by the colon separator.
......@@ -236,11 +238,11 @@ int main(int argc, char* argv[])
int offset = 1;
boost::split(tmp1, modcmds[i], boost::is_any_of(":"));
if (i < nInput || i == modcmds.size() - 1)
{
module.first = (i < nInput ? eInputModule : eOutputModule);
// If no colon detected, automatically detect mesh type from
// file extension. Otherwise override and use tmp1[1] as the
// module to load. This also allows us to pass options to
......@@ -252,14 +254,14 @@ int main(int argc, char* argv[])
{
int dot = tmp1[0].find_last_of('.') + 1;
string ext = tmp1[0].substr(dot, tmp1[0].length() - dot);
if(ext == "gz")
{
string tmp2 = tmp1[0].substr(0,dot-1);
dot = tmp2.find_last_of('.') + 1;
ext = tmp1[0].substr(dot,tmp1[0].length()-dot);
}
module.second = ext;
tmp1.push_back(string(i < nInput ? "infile=" : "outfile=")
+tmp1[0]);
......@@ -277,25 +279,24 @@ int main(int argc, char* argv[])
module.first = eProcessModule;
module.second = tmp1[0];
}
// Create module.
ModuleSharedPtr mod;
mod = GetModuleFactory().CreateInstance(module, f);
modules.push_back(mod);
if (i < nInput)
{
inputModule = boost::dynamic_pointer_cast<InputModule>(mod);
inputModule->AddFile(module.second, tmp1[0]);
}
// Set options for this module.
for (int j = offset; j < tmp1.size(); ++j)
{
vector<string> tmp2;
boost::split(tmp2, tmp1[j], boost::is_any_of("="));
if (tmp2.size() == 1)
{
mod->RegisterConfig(tmp2[0], "1");
......@@ -311,7 +312,7 @@ int main(int argc, char* argv[])
abort();
}
}
// Ensure configuration options have been set.
mod->SetDefaults();
}
......
......@@ -43,111 +43,109 @@ using namespace std;
namespace Nektar
{
namespace Utilities
namespace Utilities
{
ModuleKey InputPts::m_className[5] = {
GetModuleFactory().RegisterCreatorFunction(
ModuleKey(eInputModule, "pts"), InputPts::create, "Reads Pts file."),
GetModuleFactory().RegisterCreatorFunction(
ModuleKey(eInputModule, "pts.gz"), InputPts::create, "Reads Pts file."),
};
/**
* @brief Set up InputPts object.
*
*/
InputPts::InputPts(FieldSharedPtr f) : InputModule(f)
{
m_allowedFiles.insert("pts");
f->m_fieldPts = MemoryManager<FieldPts>::AllocateSharedPtr();
}
InputPts::~InputPts()
{
}
/**
*
*/
void InputPts::Process(po::variables_map &vm)
{
if(m_f->m_verbose)
{
ModuleKey InputPts::m_className[5] = {
GetModuleFactory().RegisterCreatorFunction(
ModuleKey(eInputModule, "pts"), InputPts::create,
"Reads Pts file."),
GetModuleFactory().RegisterCreatorFunction(
ModuleKey(eInputModule, "pts.gz"), InputPts::create,
"Reads Pts file."),
};
/**
* @brief Set up InputPts object.
*
*/
InputPts::InputPts(FieldSharedPtr f) : InputModule(f)
{
m_allowedFiles.insert("pts");
f->m_fieldPts = MemoryManager<FieldPts>::AllocateSharedPtr();
}
InputPts::~InputPts()
cout << "Processing input pts file" << endl;
}
string pts_ending = "pts";
TiXmlDocument docInput;
ASSERTL0(!docInput.LoadFile((m_f->m_inputfiles["pts"][0]).c_str()),
"Unable to open file '" + m_f->m_inputfiles["pts"][0] + "'.");
TiXmlElement *nektar = docInput.FirstChildElement("NEKTAR");
TiXmlElement *points = nektar->FirstChildElement("POINTS");
int dim;
int err = points->QueryIntAttribute("DIM", &dim);
ASSERTL0(err == TIXML_SUCCESS, "Unable to read attribute DIM.");
int nfields;
std::string fields = points->Attribute("FIELDS");
bool valid = ParseUtils::GenerateOrderedStringVector(
fields.c_str(),m_f->m_fieldPts->m_fields);
ASSERTL0(valid,"Unable to process list of field variable in "
" FIELDS attribute: "+ fields);
nfields = m_f->m_fieldPts->m_nFields = m_f->m_fieldPts->m_fields.size();
int totvars = dim + nfields;
m_f->m_fieldPts->m_ptsDim = dim;
m_f->m_fieldPts->m_nFields = nfields;
m_f->m_fieldPts->m_pts = Array<OneD, Array<OneD, NekDouble> >(totvars);
TiXmlNode *pointsBody = points->FirstChild();
std::istringstream pointsDataStrm(pointsBody->ToText()->Value());
vector<NekDouble> pts;
NekDouble in_pts;
try
{
while(!pointsDataStrm.fail())
{
pointsDataStrm >> in_pts;
pts.push_back(in_pts);
}
}
catch(...)
{
ASSERTL0(false, "Unable to read Points data.");
}
int npts = pts.size()/totvars;
/**
*
*/
void InputPts::Process(po::variables_map &vm)
if(m_f->m_verbose)
{
cout << " Read " << npts << " points of dimension " << dim << " and "
<< nfields << " field variables" << endl;
}
for(int i = 0; i < totvars; ++i)
{
m_f->m_fieldPts->m_pts[i] = Array<OneD, NekDouble>(npts);
}
for(int i = 0; i < npts; ++i)
{
for(int j = 0; j < totvars; ++j)
{
if(m_f->m_verbose)
{
cout << "Processing input pts file" << endl;
}
string pts_ending = "pts";
TiXmlDocument docInput;
if (!docInput.LoadFile((m_f->m_inputfiles["pts"][0]).c_str()))
{
std::cerr << "Unable to open file '" << m_f->m_inputfiles["pts"][0] << "'." << std::endl;
exit(1);
}
TiXmlElement *nektar = docInput.FirstChildElement("NEKTAR");
TiXmlElement *points = nektar->FirstChildElement("POINTS");
int dim;
int err = points->QueryIntAttribute("DIM", &dim);