Skip to content
Snippets Groups Projects
Commit d915d974 authored by Ankang Gao's avatar Ankang Gao
Browse files

update

parent 48fa0ffb
No related branches found
No related tags found
No related merge requests found
////////////////////////////////////////////////////////////////////////////////
//
// File: ProcessMRF.cpp
//
// For more information, please see: http://www.nektar.info/
//
// The MIT License
//
// Copyright (c) 2006 Division of Applied Mathematics, Brown University (USA),
// Department of Aeronautics, Imperial College London (UK), and Scientific
// Computing and Imaging Institute, University of Utah (USA).
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
// Description: Add transformed coordinates to field
//
////////////////////////////////////////////////////////////////////////////////
#include <iostream>
#include <string>
using namespace std;
#include "ProcessMRF.h"
#include <LibUtilities/BasicUtils/ParseUtils.h>
#include <LibUtilities/BasicUtils/SharedArray.hpp>
namespace Nektar::FieldUtils
{
ModuleKey ProcessMRF::className = GetModuleFactory().RegisterCreatorFunction(
ModuleKey(eProcessModule, "MRF"), ProcessMRF::create,
"Add transformed coordinates to output file.");
ProcessMRF::ProcessMRF(FieldSharedPtr f) : ProcessModule(f)
{
m_config["vectors"] = ConfigOption(false, "NotSet", "Select variables");
}
ProcessMRF::~ProcessMRF()
{
}
void ProcessMRF::v_Process(po::variables_map &vm)
{
m_f->SetUpExp(vm);
// Skip in case of empty partition
if (m_f->m_exp[0]->GetNumElmts() == 0)
{
return;
}
// Determine dimensions
m_spacedim = m_f->m_graph->GetMeshDimension() + m_f->m_numHomogeneousDir;
ReadMRFData();
// transform coordinates
int nfields = m_f->m_variables.size();
int addfields = m_spacedim;
int npoints = m_f->m_exp[0]->GetNpoints();
string fieldNames[3] = {"xCoord", "yCoord", "zCoord"};
for (int i = 0; i < addfields; ++i)
{
m_f->m_variables.push_back(fieldNames[i]);
}
m_f->m_exp.resize(nfields + addfields);
std::vector<Array<OneD, NekDouble>> coords(m_spacedim);
for (int i = 0; i < m_spacedim; ++i)
{
coords[i] = Array<OneD, NekDouble>(npoints);
}
if (m_spacedim == 1)
{
m_f->m_exp[0]->GetCoords(coords[0]);
}
else if (m_spacedim == 2)
{
m_f->m_exp[0]->GetCoords(coords[0], coords[1]);
}
else
{
m_f->m_exp[0]->GetCoords(coords[0], coords[1], coords[2]);
}
for (int i = 0; i < m_spacedim; ++i)
{
Vmath::Sadd(npoints, -m_pivot[i], coords[i], 1, coords[i], 1);
}
TransformVector(coords);
for (int i = 0; i < m_spacedim; ++i)
{
Vmath::Sadd(npoints, m_pivot[i] + m_origin[i], coords[i], 1, coords[i],
1);
}
// Add new information to m_f
for (int i = 0; i < addfields; ++i)
{
m_f->m_exp[nfields + i] = m_f->AppendExpList(m_f->m_numHomogeneousDir);
Vmath::Vcopy(npoints, coords[i], 1,
m_f->m_exp[nfields + i]->UpdatePhys(), 1);
m_f->m_exp[nfields + i]->FwdTransLocalElmt(
coords[i], m_f->m_exp[nfields + i]->UpdateCoeffs());
}
// tranform vectors
std::vector<Array<OneD, NekDouble>> data(m_spacedim);
std::vector<int> vars;
if (m_config["vectors"].as<string>().compare("NotSet"))
{
ParseUtils::GenerateVariableVector(m_config["vectors"].as<string>(),
m_f->m_variables, vars);
}
ASSERTL0(vars.size() % m_spacedim == 0,
"The number of vector variables is not divisible by the space "
"dimension.");
for (int i = 0; i < vars.size() / m_spacedim; ++i)
{
for (int d = 0; d < m_spacedim; ++d)
{
data[d] = m_f->m_exp[vars[m_spacedim * i + d]]->UpdatePhys();
}
TransformVector(data);
for (int d = 0; d < m_spacedim; ++d)
{
int nv = vars[m_spacedim * i + d];
m_f->m_exp[nv]->FwdTransLocalElmt(data[d],
m_f->m_exp[nv]->UpdateCoeffs());
}
}
}
void ProcessMRF::ReadMRFData()
{
std::vector<std::string> strOrigin = {"X", "Y", "Z"};
std::vector<std::string> strTheta = {"Theta_x", "Theta_y", "Theta_z"};
std::vector<std::string> strPivot = {"X0", "Y0", "Z0"};
m_origin.resize(3, 0.);
m_theta.resize(3, 0.);
m_pivot.resize(3, 0.);
for (size_t i = 0; i < strOrigin.size(); ++i)
{
if (m_f->m_fieldMetaDataMap.count(strOrigin[i]))
{
m_origin[i] = boost::lexical_cast<NekDouble>(
m_f->m_fieldMetaDataMap[strOrigin[i]]);
}
}
for (size_t i = 0; i < strTheta.size(); ++i)
{
if (m_f->m_fieldMetaDataMap.count(strTheta[i]))
{
m_theta[i] = boost::lexical_cast<NekDouble>(
m_f->m_fieldMetaDataMap[strTheta[i]]);
}
}
for (size_t i = 0; i < strPivot.size(); ++i)
{
if (m_f->m_fieldMetaDataMap.count(strPivot[i]))
{
m_pivot[i] = boost::lexical_cast<NekDouble>(
m_f->m_fieldMetaDataMap[strPivot[i]]);
}
}
}
void ProcessMRF::TransformVector(std::vector<Array<OneD, NekDouble>> &data)
{
if (data.size() < m_spacedim)
{
NEKERROR(ErrorUtil::efatal,
"data size is small than the space dimension.");
}
int npoint = data[0].size();
int dim = 2;
NekDouble sz = sin(m_theta[2]), cz = cos(m_theta[2]);
Array<OneD, Array<OneD, NekDouble>> tmp(dim);
for (int i = 0; i < dim; ++i)
{
tmp[i] = Array<OneD, NekDouble>(npoint);
}
Vmath::Svtsvtp(npoint, cz, tmp[0], 1, -sz, tmp[1], 1, data[0], 1);
Vmath::Svtsvtp(npoint, sz, tmp[0], 1, cz, tmp[1], 1, data[1], 1);
}
} // namespace Nektar::FieldUtils
////////////////////////////////////////////////////////////////////////////////
//
// File: ProcessMRF.h
//
// For more information, please see: http://www.nektar.info/
//
// The MIT License
//
// Copyright (c) 2006 Division of Applied Mathematics, Brown University (USA),
// Department of Aeronautics, Imperial College London (UK), and Scientific
// Computing and Imaging Institute, University of Utah (USA).
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
// Description: Add transformed coordinates to field
//
////////////////////////////////////////////////////////////////////////////////
#ifndef FIELDUTILS_ProcessMRF
#define FIELDUTILS_ProcessMRF
#include "../Module.h"
#include <GlobalMapping/Mapping.h>
namespace Nektar::FieldUtils
{
/**
* @brief This processing module scales the input fld file
*
*/
class ProcessMRF : public ProcessModule
{
public:
/// Creates an instance of this class
static std::shared_ptr<Module> create(FieldSharedPtr f)
{
return MemoryManager<ProcessMRF>::AllocateSharedPtr(f);
}
static ModuleKey className;
ProcessMRF(FieldSharedPtr f);
~ProcessMRF() override;
protected:
/// Write mesh to output file.
void v_Process(po::variables_map &vm) override;
std::string v_GetModuleName() override
{
return "ProcessMRF";
}
std::string v_GetModuleDescription() override
{
return "Applying mapping to field";
}
ModulePriority v_GetModulePriority() override
{
return eModifyExp;
}
void ReadMRFData();
void TransformVector(std::vector<Array<OneD, NekDouble>> &data);
private:
NekInt m_spacedim;
std::vector<NekDouble> m_origin;
std::vector<NekDouble> m_theta;
std::vector<NekDouble> m_pivot;
};
} // namespace Nektar::FieldUtils
#endif
...@@ -168,6 +168,23 @@ LIB_UTILITIES_EXPORT bool ParseUtils::GenerateVector( ...@@ -168,6 +168,23 @@ LIB_UTILITIES_EXPORT bool ParseUtils::GenerateVector(
bool ParseUtils::GenerateVariableSet(const std::string &str, bool ParseUtils::GenerateVariableSet(const std::string &str,
const std::vector<std::string> &variables, const std::vector<std::string> &variables,
std::set<int> &out) std::set<int> &out)
{
std::vector<int> tempvect;
GenerateVariableVector(str, variables, tempvect);
out.clear();
for (auto i : tempvect)
{
out.insert(i);
}
return true;
}
/**
*
*/
bool ParseUtils::GenerateVariableVector(
const std::string &str, const std::vector<std::string> &variables,
std::vector<int> &out)
{ {
out.clear(); out.clear();
std::vector<std::string> vars; std::vector<std::string> vars;
...@@ -191,7 +208,7 @@ bool ParseUtils::GenerateVariableSet(const std::string &str, ...@@ -191,7 +208,7 @@ bool ParseUtils::GenerateVariableSet(const std::string &str,
} }
else else
{ {
out.insert(v); out.push_back(v);
} }
} }
return true; return true;
......
...@@ -125,6 +125,10 @@ public: ...@@ -125,6 +125,10 @@ public:
LIB_UTILITIES_EXPORT static bool GenerateVariableSet( LIB_UTILITIES_EXPORT static bool GenerateVariableSet(
const std::string &str, const std::vector<std::string> &variables, const std::string &str, const std::vector<std::string> &variables,
std::set<int> &out); std::set<int> &out);
LIB_UTILITIES_EXPORT static bool GenerateVariableVector(
const std::string &str, const std::vector<std::string> &variables,
std::vector<int> &out);
}; };
} // namespace Nektar } // namespace Nektar
......
...@@ -94,8 +94,7 @@ int main(int argc, char *argv[]) ...@@ -94,8 +94,7 @@ int main(int argc, char *argv[])
"Specify modules which are to be used.") "Specify modules which are to be used.")
("use-session-variables", "Use variables defined in session for output") ("use-session-variables", "Use variables defined in session for output")
("use-session-expansion", "Use expansion defined in session.") ("use-session-expansion", "Use expansion defined in session.")
("verbose,v", "Enable verbose mode.") ("verbose,v", "Enable verbose mode.");
("MRF", "Transform coordinates for moving reference frame.");
// clang-format on // clang-format on
po::options_description hidden("Hidden options"); po::options_description hidden("Hidden options");
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment