Nektar++
Coupling.cpp
Go to the documentation of this file.
1////////////////////////////////////////////////////////////////////////////////
2//
3// File: Coupling.cpp
4//
5// For more information, please see: http://www.nektar.info/
6//
7// The MIT License
8//
9// Copyright (c) 2017 Kilian Lackhove
10//
11// Permission is hereby granted, free of charge, to any person obtaining a
12// copy of this software and associated documentation files (the "Software"),
13// to deal in the Software without restriction, including without limitation
14// the rights to use, copy, modify, merge, publish, distribute, sublicense,
15// and/or sell copies of the Software, and to permit persons to whom the
16// Software is furnished to do so, subject to the following conditions:
17//
18// The above copyright notice and this permission notice shall be included
19// in all copies or substantial portions of the Software.
20//
21// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
22// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
24// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
26// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
27// DEALINGS IN THE SOFTWARE.
28//
29// Description: Coupling
30//
31////////////////////////////////////////////////////////////////////////////////
32
33#include "Coupling.h"
34
36
37namespace Nektar::SolverUtils
38{
39
40using namespace std;
41
43{
44 static CouplingFactory instance;
45 return instance;
46}
47
49 : m_couplingName(""), m_evalField(field), m_nSendVars(0), m_sendSteps(0),
50 m_nRecvVars(0), m_recvSteps(0)
51{
52 m_config["RECEIVESTEPS"] = "0";
53 m_config["RECEIVEVARIABLES"] = "";
54
55 m_config["SENDSTEPS"] = "0";
56 m_config["SENDVARIABLES"] = "";
57}
58
60{
62
63 TiXmlElement *vCoupling = session->GetElement("Nektar/Coupling");
64 ASSERTL0(vCoupling, "Invalid Coupling config");
65
66 vCoupling->QueryStringAttribute("NAME", &m_couplingName);
67 ASSERTL0(m_couplingName.size(), "No Coupling NAME attribute set");
68
69 TiXmlElement *element = vCoupling->FirstChildElement("I");
70 while (element)
71 {
72 std::stringstream tagcontent;
73 tagcontent << *element;
74 // read the property name
75 ASSERTL0(element->Attribute("PROPERTY"),
76 "Missing PROPERTY attribute in Coupling section "
77 "XML element: \n\t'" +
78 tagcontent.str() + "'");
79 std::string property = element->Attribute("PROPERTY");
80 ASSERTL0(!property.empty(),
81 "PROPERTY attribute must be non-empty in XML "
82 "element: \n\t'" +
83 tagcontent.str() + "'");
84
85 // make sure that solver property is capitalised
86 std::string propertyUpper = boost::to_upper_copy(property);
87
88 CouplingConfigMap::const_iterator x = m_config.find(propertyUpper);
89 ASSERTL0(x != m_config.end(),
90 "Invalid PROPERTY attribute in Coupling section "
91 "XML element: \n\t'" +
92 tagcontent.str() + "'");
93
94 // read the value
95 ASSERTL0(element->Attribute("VALUE"),
96 "Missing VALUE attribute in Coupling section "
97 "XML element: \n\t'" +
98 tagcontent.str() + "'");
99 std::string value = element->Attribute("VALUE");
100 ASSERTL0(!value.empty(), "VALUE attribute must be non-empty in XML "
101 "element: \n\t'" +
102 tagcontent.str() + "'");
103
104 // Set Variable
105 m_config[propertyUpper] = value;
106
107 element = element->NextSiblingElement("I");
108 }
109
110 // mangle config into variables. This is ugly
113
116
117 m_recvSteps = boost::lexical_cast<int>(m_config["RECEIVESTEPS"]);
118 m_sendSteps = boost::lexical_cast<int>(m_config["SENDSTEPS"]);
119
120 if (session->GetComm()->GetRank() == 0 &&
121 session->DefinesCmdLineArgument("verbose") && m_config.size() > 0)
122 {
123 cout << "Coupling Config:" << endl;
124 CouplingConfigMap::iterator x;
125 for (x = m_config.begin(); x != m_config.end(); ++x)
126 {
127 cout << "\t" << x->first << " = '" << x->second << "'" << endl;
128 }
129 }
130}
131
132vector<int> Coupling::GenerateVariableMapping(vector<string> &vars,
133 vector<string> &transVars)
134{
135 vector<int> transToVars;
136 Array<OneD, Array<OneD, NekDouble>> sendField(transVars.size());
137 for (int i = 0; i < transVars.size(); ++i)
138 {
139 auto it2 = find(vars.begin(), vars.end(), transVars[i]);
140 ASSERTL0(it2 != vars.end(),
141 "send variable " + transVars[i] + " not found");
142 int id = distance(vars.begin(), it2);
143
144 transToVars.push_back(id);
145 }
146
147 return transToVars;
148}
149} // namespace Nektar::SolverUtils
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:208
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:130
virtual SOLVER_UTILS_EXPORT void v_Init()
Definition: Coupling.cpp:59
MultiRegions::ExpListSharedPtr m_evalField
Definition: Coupling.h:111
std::vector< std::string > m_sendFieldNames
Definition: Coupling.h:114
CouplingConfigMap m_config
Definition: Coupling.h:109
std::vector< std::string > m_recvFieldNames
Definition: Coupling.h:118
SOLVER_UTILS_EXPORT Coupling(MultiRegions::ExpListSharedPtr field)
Definition: Coupling.cpp:48
SOLVER_UTILS_EXPORT std::vector< int > GenerateVariableMapping(std::vector< std::string > &vars, std::vector< std::string > &transVars)
Definition: Coupling.cpp:132
std::shared_ptr< SessionReader > SessionReaderSharedPtr
std::shared_ptr< ExpList > ExpListSharedPtr
Shared pointer to an ExpList object.
SOLVER_UTILS_EXPORT typedef LibUtilities::NekFactory< std::string, Coupling, MultiRegions::ExpListSharedPtr > CouplingFactory
Declaration of the Coupling factory.
Definition: Coupling.h:50
CouplingFactory & GetCouplingFactory()
Declaration of the Coupling factory singleton.
Definition: Coupling.cpp:42
InputIterator find(InputIterator first, InputIterator last, InputIterator startingpoint, const EqualityComparable &value)
Definition: StdRegions.hpp:475
STL namespace.