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
38{
39namespace SolverUtils
40{
41
42using namespace std;
43
45{
46 static CouplingFactory instance;
47 return instance;
48}
49
51 : m_couplingName(""), m_evalField(field), m_nSendVars(0), m_sendSteps(0),
52 m_nRecvVars(0), m_recvSteps(0)
53{
54 m_config["RECEIVESTEPS"] = "0";
55 m_config["RECEIVEVARIABLES"] = "";
56
57 m_config["SENDSTEPS"] = "0";
58 m_config["SENDVARIABLES"] = "";
59}
60
62{
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(), "VALUE attribute must be non-empty in XML "
103 "element: \n\t'" +
104 tagcontent.str() + "'");
105
106 // Set Variable
107 m_config[propertyUpper] = value;
108
109 element = element->NextSiblingElement("I");
110 }
111
112 // mangle config into variables. This is ugly
115
118
119 m_recvSteps = boost::lexical_cast<int>(m_config["RECEIVESTEPS"]);
120 m_sendSteps = boost::lexical_cast<int>(m_config["SENDSTEPS"]);
121
122 if (session->GetComm()->GetRank() == 0 &&
123 session->DefinesCmdLineArgument("verbose") && m_config.size() > 0)
124 {
125 cout << "Coupling Config:" << endl;
126 CouplingConfigMap::iterator x;
127 for (x = m_config.begin(); x != m_config.end(); ++x)
128 {
129 cout << "\t" << x->first << " = '" << x->second << "'" << endl;
130 }
131 }
132}
133
134vector<int> Coupling::GenerateVariableMapping(vector<string> &vars,
135 vector<string> &transVars)
136{
137 vector<int> transToVars;
138 Array<OneD, Array<OneD, NekDouble>> sendField(transVars.size());
139 for (int i = 0; i < transVars.size(); ++i)
140 {
141 auto it2 = find(vars.begin(), vars.end(), transVars[i]);
142 ASSERTL0(it2 != vars.end(),
143 "send variable " + transVars[i] + " not found");
144 int id = distance(vars.begin(), it2);
145
146 transToVars.push_back(id);
147 }
148
149 return transToVars;
150}
151} // namespace SolverUtils
152} // namespace Nektar
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:215
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:131
virtual SOLVER_UTILS_EXPORT void v_Init()
Definition: Coupling.cpp:61
MultiRegions::ExpListSharedPtr m_evalField
Definition: Coupling.h:113
std::vector< std::string > m_sendFieldNames
Definition: Coupling.h:116
CouplingConfigMap m_config
Definition: Coupling.h:111
std::vector< std::string > m_recvFieldNames
Definition: Coupling.h:120
SOLVER_UTILS_EXPORT Coupling(MultiRegions::ExpListSharedPtr field)
Definition: Coupling.cpp:50
SOLVER_UTILS_EXPORT std::vector< int > GenerateVariableMapping(std::vector< std::string > &vars, std::vector< std::string > &transVars)
Definition: Coupling.cpp:134
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:52
CouplingFactory & GetCouplingFactory()
Declaration of the Coupling factory singleton.
Definition: Coupling.cpp:44
InputIterator find(InputIterator first, InputIterator last, InputIterator startingpoint, const EqualityComparable &value)
Definition: StdRegions.hpp:453
The above copyright notice and this permission notice shall be included.
Definition: CoupledSolver.h:2