Commit 6f9767e7 authored by Dave Moxey's avatar Dave Moxey
Browse files

Add some logic to define filename variable transformations

parent 66154758
...@@ -1217,6 +1217,48 @@ namespace Nektar ...@@ -1217,6 +1217,48 @@ namespace Nektar
} }
/**
*
*/
std::string SessionReader::GetFunctionFilenameVariable(
const std::string &pName,
const std::string &pVariable,
const int pDomain) const
{
FunctionMap::const_iterator it1;
FunctionVariableMap::const_iterator it2, it3;
std::string vName = boost::to_upper_copy(pName);
it1 = m_functions.find(vName);
ASSERTL0 (it1 != m_functions.end(),
std::string("Function '") + pName
+ std::string("' not found."));
// Check for specific and wildcard definitions
pair<std::string,int> key(pVariable,pDomain);
pair<std::string,int> defkey("*",pDomain);
bool specific = (it2 = it1->second.find(key)) !=
it1->second.end();
bool wildcard = (it3 = it1->second.find(defkey)) !=
it1->second.end();
// Check function is defined somewhere
ASSERTL0(specific || wildcard,
"No such variable " + pVariable
+ " in domain " + boost::lexical_cast<string>(pDomain)
+ " defined for function " + pName
+ " in session file.");
// If not specific, must be wildcard
if (!specific)
{
it2 = it3;
}
return it2->second.m_fileVariable;
}
/** /**
* *
*/ */
...@@ -2368,6 +2410,7 @@ namespace Nektar ...@@ -2368,6 +2410,7 @@ namespace Nektar
} }
// Parse list of variables // Parse list of variables
std::vector<std::string> varSplit;
std::vector<unsigned int> domainList; std::vector<unsigned int> domainList;
ParseUtils::GenerateSeqVector(domainStr.c_str(), domainList); ParseUtils::GenerateSeqVector(domainStr.c_str(), domainList);
...@@ -2418,8 +2461,32 @@ namespace Nektar ...@@ -2418,8 +2461,32 @@ namespace Nektar
"attribute of function '" + functionStr "attribute of function '" + functionStr
+ "'."); + "'.");
std::vector<std::string> fSplit;
boost::split(fSplit, filenameStr, boost::is_any_of(":"));
ASSERTL0(fSplit.size() == 1 || fSplit.size() == 2,
"Incorrect filename specification in function "
+ functionStr + "'. "
"Specify variables inside file as: "
"filename:var1,var2");
// set the filename // set the filename
funcDef.m_filename = filenameStr; funcDef.m_filename = fSplit[0];
if (fSplit.size() == 2)
{
ASSERTL0(variableList[0] != "*",
"Filename variable mapping not valid "
"when using * as a variable inside "
"function '" + functionStr + "'.");
boost::split(
varSplit, fSplit[1], boost::is_any_of(","));
ASSERTL0(varSplit.size() == variableList.size(),
"Filename variables should contain the "
"same number of variables defined in "
"VAR in function " + functionStr + "'.");
}
} }
// Nothing else supported so throw an error // Nothing else supported so throw an error
...@@ -2450,8 +2517,17 @@ namespace Nektar ...@@ -2450,8 +2517,17 @@ namespace Nektar
+ boost::lexical_cast<std::string>(domainList[j]) + boost::lexical_cast<std::string>(domainList[j])
+ "' in function '" + functionStr + "'. " + "' in function '" + functionStr + "'. "
"Expression has already been defined."); "Expression has already been defined.");
functionVarMap[key] = funcDef; if (varSplit.size() > 0)
{
FunctionVariableDefinition funcDef2 = funcDef;
funcDef2.m_fileVariable = varSplit[i];
functionVarMap[key] = funcDef2;
}
else
{
functionVarMap[key] = funcDef;
}
} }
} }
......
...@@ -108,6 +108,7 @@ namespace Nektar ...@@ -108,6 +108,7 @@ namespace Nektar
enum FunctionType m_type; enum FunctionType m_type;
std::string m_filename; std::string m_filename;
EquationSharedPtr m_expression; EquationSharedPtr m_expression;
std::string m_fileVariable;
}; };
typedef std::map<std::pair<std::string,int>, FunctionVariableDefinition> typedef std::map<std::pair<std::string,int>, FunctionVariableDefinition>
...@@ -366,6 +367,12 @@ namespace Nektar ...@@ -366,6 +367,12 @@ namespace Nektar
const std::string &name, const std::string &name,
const unsigned int &var, const unsigned int &var,
const int pDomain = 0) const; const int pDomain = 0) const;
/// Returns the filename variable to be loaded for a given variable
/// index.
LIB_UTILITIES_EXPORT std::string GetFunctionFilenameVariable(
const std::string &name,
const std::string &variable,
const int pDomain = 0) const;
/// Returns the instance of AnalyticExpressionEvaluator specific to /// Returns the instance of AnalyticExpressionEvaluator specific to
/// this session. /// this session.
......
...@@ -773,20 +773,28 @@ namespace Nektar ...@@ -773,20 +773,28 @@ namespace Nektar
ffunc->Evaluate(x0,x1,x2,pTime,pArray); ffunc->Evaluate(x0,x1,x2,pTime,pArray);
} }
else if (vType == LibUtilities::eFunctionTypeFile || vType == LibUtilities::eFunctionTypeTransientFile) else if (vType == LibUtilities::eFunctionTypeFile ||
vType == LibUtilities::eFunctionTypeTransientFile)
{ {
std::string filename std::string filename = m_session->GetFunctionFilename(
= m_session->GetFunctionFilename(pFunctionName, pFieldName,domain); pFunctionName, pFieldName, domain);
std::string fileVar = m_session->GetFunctionFilenameVariable(
pFunctionName, pFieldName, domain);
if (fileVar.length() == 0)
{
fileVar = pFieldName;
}
std::vector<LibUtilities::FieldDefinitionsSharedPtr> FieldDef; std::vector<LibUtilities::FieldDefinitionsSharedPtr> FieldDef;
std::vector<std::vector<NekDouble> > FieldData; std::vector<std::vector<NekDouble> > FieldData;
Array<OneD, NekDouble> vCoeffs(m_fields[0]->GetNcoeffs()); Array<OneD, NekDouble> vCoeffs(m_fields[0]->GetNcoeffs());
Vmath::Zero(vCoeffs.num_elements(),vCoeffs,1); Vmath::Zero(vCoeffs.num_elements(),vCoeffs,1);
int numexp = m_fields[0]->GetExpSize(); int numexp = m_fields[0]->GetExpSize();
Array<OneD,int> ElementGIDs(numexp); Array<OneD,int> ElementGIDs(numexp);
// Define list of global element ids
// Define list of global element ids
for(int i = 0; i < numexp; ++i) for(int i = 0; i < numexp; ++i)
{ {
ElementGIDs[i] = m_fields[0]->GetExp(i)->GetGeom()->GetGlobalID(); ElementGIDs[i] = m_fields[0]->GetExp(i)->GetGeom()->GetGlobalID();
...@@ -801,29 +809,29 @@ namespace Nektar ...@@ -801,29 +809,29 @@ namespace Nektar
catch (...) catch (...)
{ {
ASSERTL0(false, "Invalid Filename in function \"" ASSERTL0(false, "Invalid Filename in function \""
+ pFunctionName + "\", variable \"" + pFieldName + "\"") + pFunctionName + "\", variable \"" + fileVar + "\"")
} }
} }
m_fld->Import(filename,FieldDef,FieldData, m_fld->Import(filename, FieldDef, FieldData,
LibUtilities::NullFieldMetaDataMap, LibUtilities::NullFieldMetaDataMap,
ElementGIDs); ElementGIDs);
int idx = -1; int idx = -1;
// Loop over all the expansions // Loop over all the expansions
for (int i = 0; i < FieldDef.size(); ++i) for (int i = 0; i < FieldDef.size(); ++i)
{ {
// Find the index of the required field in the // Find the index of the required field in the
// expansion segment // expansion segment
for(int j = 0; j < FieldDef[i]->m_fields.size(); ++j) for(int j = 0; j < FieldDef[i]->m_fields.size(); ++j)
{ {
if (FieldDef[i]->m_fields[j] == pFieldName) if (FieldDef[i]->m_fields[j] == fileVar)
{ {
idx = j; idx = j;
} }
} }
if (idx >= 0) if (idx >= 0)
{ {
m_fields[0]->ExtractDataToCoeffs( m_fields[0]->ExtractDataToCoeffs(
...@@ -832,11 +840,10 @@ namespace Nektar ...@@ -832,11 +840,10 @@ namespace Nektar
} }
else else
{ {
cout << "Field " + pFieldName + " not found." << endl; cout << "Field " + fileVar + " not found." << endl;
} }
} }
m_fields[0]->BwdTrans_IterPerExp(vCoeffs, pArray); m_fields[0]->BwdTrans_IterPerExp(vCoeffs, pArray);
} }
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment