Added: class SIMargsBase which replaces SIM::AppXMLInputBase residing in

Apps/Common/AppCommn.[Ch]. The latter files therefore removed.
The new class handles parsing of command-line arguments in addition.
This commit is contained in:
Knut Morten Okstad
2018-01-09 16:55:38 +01:00
parent 09485d65d5
commit cefc896412
5 changed files with 104 additions and 74 deletions

View File

@@ -1,36 +0,0 @@
// $Id$
//==============================================================================
//!
//! \file AppCommon.C
//!
//! \date Nov 06 2012
//!
//! \author Arne Morten Kvarving / SINTEF
//!
//! \brief Common helper templates for applications.
//!
//==============================================================================
#include "AppCommon.h"
#include "Utilities.h"
#include "IFEM.h"
#include "tinyxml.h"
bool SIM::AppXMLInputBase::parse (const TiXmlElement* elem)
{
if (strcasecmp(elem->Value(),"geometry"))
return true;
if (!utl::getAttribute(elem,"dimension",dim))
utl::getAttribute(elem,"dim",dim);
std::string type;
const TiXmlElement* child = elem->FirstChildElement();
for (; child; child = child->NextSiblingElement())
if (!strcasecmp(child->Value(),"patchfile"))
if (utl::getAttribute(child,"type",type) && type == "lrspline")
IFEM::getOptions().discretization = ASM::LRSpline;
return true;
}

View File

@@ -1,38 +0,0 @@
// $Id$
//==============================================================================
//!
//! \file AppCommon.h
//!
//! \date Nov 06 2012
//!
//! \author Arne Morten Kvarving / SINTEF
//!
//! \brief Common helper templates for applications.
//!
//==============================================================================
#ifndef _APP_COMMON_H_
#define _APP_COMMON_H_
#include "XMLInputBase.h"
namespace SIM
{
//! \brief Base class for input file pre-parsing in applications.
class AppXMLInputBase : public XMLInputBase
{
public:
//! \brief Default constructor.
AppXMLInputBase() : dim(3) {}
protected:
//! \brief Parses a data section from an XML element.
virtual bool parse(const TiXmlElement* elem);
public:
int dim; //!< Dimensionality of simulation
};
}
#endif

50
src/SIM/SIMargsBase.C Normal file
View File

@@ -0,0 +1,50 @@
// $Id$
//==============================================================================
//!
//! \file SIMargsBase.C
//!
//! \date Jul 15 2016
//!
//! \author Arne Morten Kvarving / SINTEF
//!
//! \brief Base class for pre-parsing of XML input files for simulators.
//!
//==============================================================================
#include "SIMargsBase.h"
#include "Utilities.h"
#include "IFEM.h"
#include "tinyxml.h"
#include <cstring>
bool SIMargsBase::parseArg (const char* argv)
{
if (!strncmp(argv,"-adap",5))
adap = true;
else if (!strcmp(argv,"-1D"))
dim = 1;
else if (!strcmp(argv,"-2D"))
dim = 2;
else if (!strcmp(argv,"-3D"))
dim = 3;
else
return false;
return true;
}
bool SIMargsBase::parse (const TiXmlElement* elem)
{
if (!strcasecmp(elem->Value(),context))
utl::getAttribute(elem,"adaptive",adap);
if (strcasecmp(elem->Value(),"geometry"))
return true;
if (!utl::getAttribute(elem,"dimension",dim))
utl::getAttribute(elem,"dim",dim);
return IFEM::getOptions().parseDiscretizationTag(elem);
}

45
src/SIM/SIMargsBase.h Normal file
View File

@@ -0,0 +1,45 @@
// $Id$
//==============================================================================
//!
//! \file SIMargsBase.h
//!
//! \date Jul 15 2016
//!
//! \author Arne Morten Kvarving / SINTEF
//!
//! \brief Base class for pre-parsing of XML input files for simulators.
//!
//==============================================================================
#ifndef _SIM_ARGS_BASE_H_
#define _SIM_ARGS_BASE_H_
#include "XMLInputBase.h"
/*!
\brief Base class for input file pre-parsing in applications.
*/
class SIMargsBase : public XMLInputBase
{
public:
//! \brief The constructor initializes the default parameter values.
explicit SIMargsBase(const char* ctx) : context(ctx), dim(3), adap(false) {}
//! \brief Parses a command-line argument.
virtual bool parseArg(const char* argv);
protected:
//! \brief Parses a data section from an XML element.
virtual bool parse(const TiXmlElement* elem);
private:
const char* context; //!< Application-specific context tag
public:
int dim; //!< Dimensionality of simulation
bool adap; //!< If \e true, run an adaptive simulator
};
#endif

View File

@@ -111,6 +111,15 @@ bool SIMoptions::parseDiscretizationTag (const TiXmlElement* elem)
}
}
else if (!strcasecmp(elem->Value(),"geometry")) {
std::string type;
const TiXmlElement* child = elem->FirstChildElement();
for (; child; child = child->NextSiblingElement())
if (!strcasecmp(child->Value(),"patchfile"))
if (utl::getAttribute(child,"type",type) && type == "lrspline")
discretization = ASM::LRSpline;
}
else if (!strcasecmp(elem->Value(),"nGauss") && elem->FirstChild()) {
std::string value(elem->FirstChild()->Value());
char* cval = strtok(const_cast<char*>(value.c_str())," ");