Nektar++
Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
Nektar::SolverUtils::Coupling Class Referenceabstract

#include <Coupling.h>

Inheritance diagram for Nektar::SolverUtils::Coupling:
[legend]

Public Types

typedef std::map< std::string, std::string > CouplingConfigMap
 

Public Member Functions

virtual SOLVER_UTILS_EXPORT ~Coupling ()
 
SOLVER_UTILS_EXPORT void Init ()
 
SOLVER_UTILS_EXPORT const std::map< std::string, std::string > GetConfig ()
 
SOLVER_UTILS_EXPORT std::vector< std::string > GetSendFieldNames ()
 
SOLVER_UTILS_EXPORT std::vector< std::string > GetRecvFieldNames ()
 
SOLVER_UTILS_EXPORT void Finalize ()
 
SOLVER_UTILS_EXPORT void Send (const int step, const NekDouble time, const Array< OneD, const Array< OneD, NekDouble > > &field, std::vector< std::string > &varNames)
 
SOLVER_UTILS_EXPORT void Receive (const int step, const NekDouble time, Array< OneD, Array< OneD, NekDouble > > &field, std::vector< std::string > &varNames)
 

Protected Member Functions

SOLVER_UTILS_EXPORT Coupling (MultiRegions::ExpListSharedPtr field)
 
virtual SOLVER_UTILS_EXPORT void v_Init ()
 
virtual SOLVER_UTILS_EXPORT void v_Send (const int step, const NekDouble time, const Array< OneD, const Array< OneD, NekDouble > > &field, std::vector< std::string > &varNames)=0
 
virtual SOLVER_UTILS_EXPORT void v_Receive (const int step, const NekDouble time, Array< OneD, Array< OneD, NekDouble > > &field, std::vector< std::string > &varNames)=0
 
virtual SOLVER_UTILS_EXPORT void v_Finalize ()
 
SOLVER_UTILS_EXPORT std::vector< int > GenerateVariableMapping (std::vector< std::string > &vars, std::vector< std::string > &transVars)
 

Protected Attributes

std::string m_couplingName
 
CouplingConfigMap m_config
 
MultiRegions::ExpListSharedPtr m_evalField
 
int m_nSendVars
 
std::vector< std::string > m_sendFieldNames
 
int m_sendSteps
 
int m_nRecvVars
 
std::vector< std::string > m_recvFieldNames
 
int m_recvSteps
 

Detailed Description

Definition at line 57 of file Coupling.h.

Member Typedef Documentation

◆ CouplingConfigMap

typedef std::map<std::string, std::string> Nektar::SolverUtils::Coupling::CouplingConfigMap

Definition at line 61 of file Coupling.h.

Constructor & Destructor Documentation

◆ ~Coupling()

virtual SOLVER_UTILS_EXPORT Nektar::SolverUtils::Coupling::~Coupling ( )
inlinevirtual

Definition at line 63 of file Coupling.h.

64  {
65  }

◆ Coupling()

Nektar::SolverUtils::Coupling::Coupling ( MultiRegions::ExpListSharedPtr  field)
protected

Definition at line 50 of file Coupling.cpp.

References m_config.

51  : m_couplingName(""), m_evalField(field), m_nSendVars(0), m_sendSteps(0),
53 {
54  m_config["RECEIVESTEPS"] = "0";
55  m_config["RECEIVEVARIABLES"] = "";
56 
57  m_config["SENDSTEPS"] = "0";
58  m_config["SENDVARIABLES"] = "";
59 }
CouplingConfigMap m_config
Definition: Coupling.h:113
MultiRegions::ExpListSharedPtr m_evalField
Definition: Coupling.h:115

Member Function Documentation

◆ Finalize()

SOLVER_UTILS_EXPORT void Nektar::SolverUtils::Coupling::Finalize ( )
inline

Definition at line 87 of file Coupling.h.

References v_Finalize().

88  {
89  v_Finalize();
90  }
virtual SOLVER_UTILS_EXPORT void v_Finalize()
Definition: Coupling.h:141

◆ GenerateVariableMapping()

vector< int > Nektar::SolverUtils::Coupling::GenerateVariableMapping ( std::vector< std::string > &  vars,
std::vector< std::string > &  transVars 
)
protected

Definition at line 135 of file Coupling.cpp.

References ASSERTL0, and Nektar::StdRegions::find().

Referenced by v_Finalize(), Nektar::SolverUtils::CouplingFile::v_Receive(), Nektar::SolverUtils::CouplingCwipi::v_Receive(), Nektar::SolverUtils::CouplingFile::v_Send(), and Nektar::SolverUtils::CouplingCwipi::v_Send().

137 {
138  vector<int> transToVars;
139  Array<OneD, Array<OneD, NekDouble> > sendField(transVars.size());
140  for (int i = 0; i < transVars.size(); ++i)
141  {
142  auto it2 = find(vars.begin(), vars.end(), transVars[i]);
143  ASSERTL0(it2 != vars.end(),
144  "send variable " + transVars[i] + " not found");
145  int id = distance(vars.begin(), it2);
146 
147  transToVars.push_back(id);
148  }
149 
150  return transToVars;
151 }
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:216
InputIterator find(InputIterator first, InputIterator last, InputIterator startingpoint, const EqualityComparable &value)
Definition: StdRegions.hpp:358

◆ GetConfig()

SOLVER_UTILS_EXPORT const std::map<std::string, std::string> Nektar::SolverUtils::Coupling::GetConfig ( )
inline

Definition at line 72 of file Coupling.h.

References m_config.

73  {
74  return m_config;
75  }
CouplingConfigMap m_config
Definition: Coupling.h:113

◆ GetRecvFieldNames()

SOLVER_UTILS_EXPORT std::vector<std::string> Nektar::SolverUtils::Coupling::GetRecvFieldNames ( )
inline

Definition at line 82 of file Coupling.h.

References m_recvFieldNames.

83  {
84  return m_recvFieldNames;
85  }
std::vector< std::string > m_recvFieldNames
Definition: Coupling.h:122

◆ GetSendFieldNames()

SOLVER_UTILS_EXPORT std::vector<std::string> Nektar::SolverUtils::Coupling::GetSendFieldNames ( )
inline

Definition at line 77 of file Coupling.h.

References m_sendFieldNames.

78  {
79  return m_sendFieldNames;
80  }
std::vector< std::string > m_sendFieldNames
Definition: Coupling.h:118

◆ Init()

SOLVER_UTILS_EXPORT void Nektar::SolverUtils::Coupling::Init ( )
inline

Definition at line 67 of file Coupling.h.

References v_Init().

68  {
69  v_Init();
70  }
virtual SOLVER_UTILS_EXPORT void v_Init()
Definition: Coupling.cpp:61

◆ Receive()

SOLVER_UTILS_EXPORT void Nektar::SolverUtils::Coupling::Receive ( const int  step,
const NekDouble  time,
Array< OneD, Array< OneD, NekDouble > > &  field,
std::vector< std::string > &  varNames 
)
inline

Definition at line 101 of file Coupling.h.

References v_Receive().

106  {
107  v_Receive(step, time, field, varNames);
108  }
virtual SOLVER_UTILS_EXPORT void v_Receive(const int step, const NekDouble time, Array< OneD, Array< OneD, NekDouble > > &field, std::vector< std::string > &varNames)=0

◆ Send()

SOLVER_UTILS_EXPORT void Nektar::SolverUtils::Coupling::Send ( const int  step,
const NekDouble  time,
const Array< OneD, const Array< OneD, NekDouble > > &  field,
std::vector< std::string > &  varNames 
)
inline

Definition at line 92 of file Coupling.h.

References v_Send().

97  {
98  v_Send(step, time, field, varNames);
99  }
virtual SOLVER_UTILS_EXPORT void v_Send(const int step, const NekDouble time, const Array< OneD, const Array< OneD, NekDouble > > &field, std::vector< std::string > &varNames)=0

◆ v_Finalize()

virtual SOLVER_UTILS_EXPORT void Nektar::SolverUtils::Coupling::v_Finalize ( void  )
inlineprotectedvirtual

Reimplemented in Nektar::SolverUtils::CouplingCwipi.

Definition at line 141 of file Coupling.h.

References GenerateVariableMapping(), and SOLVER_UTILS_EXPORT.

Referenced by Finalize().

142  {
143  }

◆ v_Init()

void Nektar::SolverUtils::Coupling::v_Init ( )
protectedvirtual

Reimplemented in Nektar::SolverUtils::CouplingCwipi, and Nektar::SolverUtils::CouplingFile.

Definition at line 61 of file Coupling.cpp.

References ASSERTL0, Nektar::ParseUtils::GenerateVector(), m_config, m_couplingName, m_evalField, m_nRecvVars, m_nSendVars, m_recvFieldNames, m_recvSteps, m_sendFieldNames, and m_sendSteps.

Referenced by Init(), Nektar::SolverUtils::CouplingFile::v_Init(), and Nektar::SolverUtils::CouplingCwipi::v_Init().

62 {
63  LibUtilities::SessionReaderSharedPtr session = m_evalField->GetSession();
64 
65  TiXmlElement *vCoupling = session->GetElement("Nektar/Coupling");
66  ASSERTL0(vCoupling, "Invalid Coupling config");
67 
68  vCoupling->QueryStringAttribute("NAME", &m_couplingName);
69  ASSERTL0(m_couplingName.size(), "No Coupling NAME attribute set");
70 
71  TiXmlElement *element = vCoupling->FirstChildElement("I");
72  while (element)
73  {
74  std::stringstream tagcontent;
75  tagcontent << *element;
76  // read the property name
77  ASSERTL0(element->Attribute("PROPERTY"),
78  "Missing PROPERTY attribute in Coupling section "
79  "XML element: \n\t'" +
80  tagcontent.str() + "'");
81  std::string property = element->Attribute("PROPERTY");
82  ASSERTL0(!property.empty(),
83  "PROPERTY attribute must be non-empty in XML "
84  "element: \n\t'" +
85  tagcontent.str() + "'");
86 
87  // make sure that solver property is capitalised
88  std::string propertyUpper = boost::to_upper_copy(property);
89 
90  CouplingConfigMap::const_iterator x = m_config.find(propertyUpper);
91  ASSERTL0(x != m_config.end(),
92  "Invalid PROPERTY attribute in Coupling section "
93  "XML element: \n\t'" +
94  tagcontent.str() + "'");
95 
96  // read the value
97  ASSERTL0(element->Attribute("VALUE"),
98  "Missing VALUE attribute in Coupling section "
99  "XML element: \n\t'" +
100  tagcontent.str() + "'");
101  std::string value = element->Attribute("VALUE");
102  ASSERTL0(!value.empty(),
103  "VALUE attribute must be non-empty in XML "
104  "element: \n\t'" +
105  tagcontent.str() + "'");
106 
107  // Set Variable
108  m_config[propertyUpper] = value;
109 
110  element = element->NextSiblingElement("I");
111  }
112 
113  // mangle config into variables. This is ugly
114  ParseUtils::GenerateVector(m_config["RECEIVEVARIABLES"], m_recvFieldNames);
115  m_nRecvVars = m_recvFieldNames.size();
116 
117  ParseUtils::GenerateVector(m_config["SENDVARIABLES"], m_sendFieldNames);
118  m_nSendVars = m_sendFieldNames.size();
119 
120  m_recvSteps = boost::lexical_cast<int>(m_config["RECEIVESTEPS"]);
121  m_sendSteps = boost::lexical_cast<int>(m_config["SENDSTEPS"]);
122 
123  if (session->GetComm()->GetRank() == 0 &&
124  session->DefinesCmdLineArgument("verbose") && m_config.size() > 0)
125  {
126  cout << "Coupling Config:" << endl;
127  CouplingConfigMap::iterator x;
128  for (x = m_config.begin(); x != m_config.end(); ++x)
129  {
130  cout << "\t" << x->first << " = '" << x->second << "'" << endl;
131  }
132  }
133 }
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:216
CouplingConfigMap m_config
Definition: Coupling.h:113
std::vector< std::string > m_recvFieldNames
Definition: Coupling.h:122
std::vector< std::string > m_sendFieldNames
Definition: Coupling.h:118
static bool GenerateVector(const std::string &str, std::vector< T > &out)
Takes a comma-separated string and converts it to entries in a vector.
Definition: ParseUtils.cpp:135
MultiRegions::ExpListSharedPtr m_evalField
Definition: Coupling.h:115
std::shared_ptr< SessionReader > SessionReaderSharedPtr

◆ v_Receive()

virtual SOLVER_UTILS_EXPORT void Nektar::SolverUtils::Coupling::v_Receive ( const int  step,
const NekDouble  time,
Array< OneD, Array< OneD, NekDouble > > &  field,
std::vector< std::string > &  varNames 
)
protectedpure virtual

◆ v_Send()

virtual SOLVER_UTILS_EXPORT void Nektar::SolverUtils::Coupling::v_Send ( const int  step,
const NekDouble  time,
const Array< OneD, const Array< OneD, NekDouble > > &  field,
std::vector< std::string > &  varNames 
)
protectedpure virtual

Member Data Documentation

◆ m_config

CouplingConfigMap Nektar::SolverUtils::Coupling::m_config
protected

◆ m_couplingName

std::string Nektar::SolverUtils::Coupling::m_couplingName
protected

◆ m_evalField

MultiRegions::ExpListSharedPtr Nektar::SolverUtils::Coupling::m_evalField
protected

◆ m_nRecvVars

int Nektar::SolverUtils::Coupling::m_nRecvVars
protected

◆ m_nSendVars

int Nektar::SolverUtils::Coupling::m_nSendVars
protected

◆ m_recvFieldNames

std::vector<std::string> Nektar::SolverUtils::Coupling::m_recvFieldNames
protected

◆ m_recvSteps

int Nektar::SolverUtils::Coupling::m_recvSteps
protected

◆ m_sendFieldNames

std::vector<std::string> Nektar::SolverUtils::Coupling::m_sendFieldNames
protected

◆ m_sendSteps

int Nektar::SolverUtils::Coupling::m_sendSteps
protected