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
41{
42 static CouplingFactory instance;
43 return instance;
44}
45
47 : m_couplingName(""), m_evalField(field), m_nSendVars(0), m_sendSteps(0),
48 m_nRecvVars(0), m_recvSteps(0)
49{
50 m_config["RECEIVESTEPS"] = "0";
51 m_config["RECEIVEVARIABLES"] = "";
52
53 m_config["SENDSTEPS"] = "0";
54 m_config["SENDVARIABLES"] = "";
55}
56
58{
60
61 TiXmlElement *vCoupling = session->GetElement("Nektar/Coupling");
62 ASSERTL0(vCoupling, "Invalid Coupling config");
63
64 vCoupling->QueryStringAttribute("NAME", &m_couplingName);
65 ASSERTL0(m_couplingName.size(), "No Coupling NAME attribute set");
66
67 TiXmlElement *element = vCoupling->FirstChildElement("I");
68 while (element)
69 {
70 std::stringstream tagcontent;
71 tagcontent << *element;
72 // read the property name
73 ASSERTL0(element->Attribute("PROPERTY"),
74 "Missing PROPERTY attribute in Coupling section "
75 "XML element: \n\t'" +
76 tagcontent.str() + "'");
77 std::string property = element->Attribute("PROPERTY");
78 ASSERTL0(!property.empty(),
79 "PROPERTY attribute must be non-empty in XML "
80 "element: \n\t'" +
81 tagcontent.str() + "'");
82
83 // make sure that solver property is capitalised
84 std::string propertyUpper = boost::to_upper_copy(property);
85
86 CouplingConfigMap::const_iterator x = m_config.find(propertyUpper);
87 ASSERTL0(x != m_config.end(),
88 "Invalid PROPERTY attribute in Coupling section "
89 "XML element: \n\t'" +
90 tagcontent.str() + "'");
91
92 // read the value
93 ASSERTL0(element->Attribute("VALUE"),
94 "Missing VALUE attribute in Coupling section "
95 "XML element: \n\t'" +
96 tagcontent.str() + "'");
97 std::string value = element->Attribute("VALUE");
98 ASSERTL0(!value.empty(), "VALUE attribute must be non-empty in XML "
99 "element: \n\t'" +
100 tagcontent.str() + "'");
101
102 // Set Variable
103 m_config[propertyUpper] = value;
104
105 element = element->NextSiblingElement("I");
106 }
107
108 // mangle config into variables. This is ugly
111
114
115 m_recvSteps = std::stoi(m_config["RECEIVESTEPS"]);
116 m_sendSteps = std::stoi(m_config["SENDSTEPS"]);
117
118 if (session->GetComm()->GetRank() == 0 &&
119 session->DefinesCmdLineArgument("verbose") && m_config.size() > 0)
120 {
121 std::cout << "Coupling Config:" << std::endl;
122 CouplingConfigMap::iterator x;
123 for (x = m_config.begin(); x != m_config.end(); ++x)
124 {
125 std::cout << "\t" << x->first << " = '" << x->second << "'"
126 << std::endl;
127 }
128 }
129}
130
132 std::vector<std::string> &vars, std::vector<std::string> &transVars)
133{
134 std::vector<int> transToVars;
135 Array<OneD, Array<OneD, NekDouble>> sendField(transVars.size());
136 for (int i = 0; i < transVars.size(); ++i)
137 {
138 auto it2 = find(vars.begin(), vars.end(), transVars[i]);
139 ASSERTL0(it2 != vars.end(),
140 "send variable " + transVars[i] + " not found");
141 int id = distance(vars.begin(), it2);
142
143 transToVars.push_back(id);
144 }
145
146 return transToVars;
147}
148} // 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:57
MultiRegions::ExpListSharedPtr m_evalField
Definition: Coupling.h:107
std::vector< std::string > m_sendFieldNames
Definition: Coupling.h:110
CouplingConfigMap m_config
Definition: Coupling.h:105
std::vector< std::string > m_recvFieldNames
Definition: Coupling.h:114
SOLVER_UTILS_EXPORT Coupling(MultiRegions::ExpListSharedPtr field)
Definition: Coupling.cpp:46
SOLVER_UTILS_EXPORT std::vector< int > GenerateVariableMapping(std::vector< std::string > &vars, std::vector< std::string > &transVars)
Definition: Coupling.cpp:131
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:40
InputIterator find(InputIterator first, InputIterator last, InputIterator startingpoint, const EqualityComparable &value)
Definition: StdRegions.hpp:475