Nektar++
Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Member Functions | Private Attributes | List of all members
Nektar::SolverUtils::CouplingFile Class Reference

#include <CouplingFile.h>

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

Public Member Functions

SOLVER_UTILS_EXPORT CouplingFile (MultiRegions::ExpListSharedPtr field)
 
SOLVER_UTILS_EXPORT ~CouplingFile () override
 
- Public Member Functions inherited from Nektar::SolverUtils::Coupling
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)
 

Static Public Member Functions

static SOLVER_UTILS_EXPORT CouplingSharedPtr create (MultiRegions::ExpListSharedPtr field)
 Creates an instance of this class. More...
 

Static Public Attributes

static std::string className
 

Protected Member Functions

SOLVER_UTILS_EXPORT void v_Init () override
 
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) override
 
SOLVER_UTILS_EXPORT void v_Receive (const int step, const NekDouble time, Array< OneD, Array< OneD, NekDouble > > &field, std::vector< std::string > &varNames) override
 
- Protected Member Functions inherited from Nektar::SolverUtils::Coupling
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)
 

Private Attributes

int m_lastSend
 
int m_lastReceive
 
SessionFunctionSharedPtr m_inputFunction
 

Additional Inherited Members

- Public Types inherited from Nektar::SolverUtils::Coupling
typedef std::map< std::string, std::string > CouplingConfigMap
 
- Protected Attributes inherited from Nektar::SolverUtils::Coupling
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 45 of file CouplingFile.h.

Constructor & Destructor Documentation

◆ CouplingFile()

Nektar::SolverUtils::CouplingFile::CouplingFile ( MultiRegions::ExpListSharedPtr  field)

Definition at line 51 of file CouplingFile.cpp.

52 : Coupling(field), m_lastSend(-1E6), m_lastReceive(-1E6)
53{
54 m_config["RECEIVEFUNCTION"] = "CouplingIn";
55 m_config["SENDFILENAME"] = "CouplingOut_%14.8E.pts";
56}
CouplingConfigMap m_config
Definition: Coupling.h:109
SOLVER_UTILS_EXPORT Coupling(MultiRegions::ExpListSharedPtr field)
Definition: Coupling.cpp:48

References Nektar::SolverUtils::Coupling::m_config.

◆ ~CouplingFile()

Nektar::SolverUtils::CouplingFile::~CouplingFile ( )
override

Definition at line 58 of file CouplingFile.cpp.

59{
60}

Member Function Documentation

◆ create()

static SOLVER_UTILS_EXPORT CouplingSharedPtr Nektar::SolverUtils::CouplingFile::create ( MultiRegions::ExpListSharedPtr  field)
inlinestatic

Creates an instance of this class.

Definition at line 52 of file CouplingFile.h.

54 {
57 p->Init();
58 return p;
59 }
static std::shared_ptr< DataType > AllocateSharedPtr(const Args &...args)
Allocate a shared pointer from the memory pool.
SOLVER_UTILS_EXPORT typedef std::shared_ptr< Coupling > CouplingSharedPtr
Definition: Coupling.h:45

References Nektar::MemoryManager< DataType >::AllocateSharedPtr(), Nektar::SolverUtils::CouplingSharedPtr, FilterPython_Function::field, and CellMLToNektar.cellml_metadata::p.

◆ v_Init()

void Nektar::SolverUtils::CouplingFile::v_Init ( )
overrideprotectedvirtual

◆ v_Receive()

void Nektar::SolverUtils::CouplingFile::v_Receive ( const int  step,
const NekDouble  time,
Array< OneD, Array< OneD, NekDouble > > &  field,
std::vector< std::string > &  varNames 
)
overrideprotectedvirtual

Implements Nektar::SolverUtils::Coupling.

Definition at line 135 of file CouplingFile.cpp.

138{
139 if (m_nRecvVars < 1 || m_recvSteps < 1)
140 {
141 return;
142 }
143
144 if (step < m_lastReceive + m_recvSteps)
145 {
146 return;
147 }
148 m_lastReceive = step;
149
150 if (m_evalField->GetComm()->GetRank() == 0 &&
151 m_evalField->GetSession()->DefinesCmdLineArgument("verbose"))
152 {
153 cout << "receiving fields at i = " << step << ", t = " << time << endl;
154 }
155
156 string filename = m_evalField->GetSession()->GetFunctionFilename(
157 m_config["RECEIVEFUNCTION"], m_recvFieldNames[0]);
158
159#if (defined _WIN32 && _MSC_VER < 1900)
160 // We need this to make sure boost::format has always
161 // two digits in the exponents of Scientific notation.
162 unsigned int old_exponent_format;
163 old_exponent_format = _set_output_format(_TWO_DIGIT_EXPONENT);
164 filename = boost::str(boost::format(filename) % time);
165 _set_output_format(old_exponent_format);
166#else
167 filename = boost::str(boost::format(filename) % time);
168#endif
169
170 int exists = 0;
171 while (!exists)
172 {
173 exists = fs::exists(filename);
174 m_evalField->GetComm()->AllReduce(exists, LibUtilities::ReduceMin);
175 }
176
177 Array<OneD, Array<OneD, NekDouble>> recvFields(m_nRecvVars);
178 m_inputFunction->Evaluate(m_recvFieldNames, recvFields, time);
179
180 vector<int> recvVarsToVars =
182 ASSERTL1(m_nRecvVars == recvVarsToVars.size(), "field size mismatch");
183 for (int i = 0; i < recvVarsToVars.size(); ++i)
184 {
185 Vmath::Vcopy(recvFields[i].size(), recvFields[i], 1,
186 field[recvVarsToVars[i]], 1);
187 }
188}
#define ASSERTL1(condition, msg)
Assert Level 1 – Debugging which is used whether in FULLDEBUG or DEBUG compilation mode....
Definition: ErrorUtil.hpp:242
std::vector< std::string > m_recvFieldNames
Definition: Coupling.h:118
SOLVER_UTILS_EXPORT std::vector< int > GenerateVariableMapping(std::vector< std::string > &vars, std::vector< std::string > &transVars)
Definition: Coupling.cpp:132
void Vcopy(int n, const T *x, const int incx, T *y, const int incy)
Definition: Vmath.hpp:825

References ASSERTL1, FilterPython_Function::field, CellMLToNektar.pycml::format, Nektar::SolverUtils::Coupling::GenerateVariableMapping(), Nektar::SolverUtils::Coupling::m_config, Nektar::SolverUtils::Coupling::m_evalField, m_inputFunction, m_lastReceive, Nektar::SolverUtils::Coupling::m_nRecvVars, Nektar::SolverUtils::Coupling::m_recvFieldNames, Nektar::SolverUtils::Coupling::m_recvSteps, Nektar::LibUtilities::ReduceMin, and Vmath::Vcopy().

◆ v_Send()

void Nektar::SolverUtils::CouplingFile::v_Send ( const int  step,
const NekDouble  time,
const Array< OneD, const Array< OneD, NekDouble > > &  field,
std::vector< std::string > &  varNames 
)
overrideprotectedvirtual

Implements Nektar::SolverUtils::Coupling.

Definition at line 74 of file CouplingFile.cpp.

78{
79 if (m_nSendVars < 1 || m_sendSteps < 1)
80 {
81 return;
82 }
83
84 if (step < m_lastSend + m_sendSteps)
85 {
86 return;
87 }
88 m_lastSend = step;
89
90 if (m_evalField->GetComm()->GetRank() == 0 &&
91 m_evalField->GetSession()->DefinesCmdLineArgument("verbose"))
92 {
93 cout << "sending fields at i = " << step << ", t = " << time << endl;
94 }
95
96 vector<int> sendVarsToVars =
98
99#if (defined _WIN32 && _MSC_VER < 1900)
100 // We need this to make sure boost::format has always
101 // two digits in the exponents of Scientific notation.
102 unsigned int old_exponent_format;
103 old_exponent_format = _set_output_format(_TWO_DIGIT_EXPONENT);
104 std::string filename =
105 boost::str(boost::format(m_config["SENDFILENAME"]) % time);
106 _set_output_format(old_exponent_format);
107#else
108 std::string filename =
109 boost::str(boost::format(m_config["SENDFILENAME"]) % time);
110#endif
111
112 Array<OneD, Array<OneD, NekDouble>> pts(m_nSendVars + 3);
113 for (int i = 0; i < 3; ++i)
114 {
115 pts[i] = Array<OneD, NekDouble>(m_evalField->GetTotPoints(), 0.0);
116 }
117 m_evalField->GetCoords(pts[0], pts[1], pts[2]);
118
119 for (int i = 0; i < m_nSendVars; ++i)
120 {
121 pts[3 + i] = field[sendVarsToVars[i]];
122 }
123
124 LibUtilities::PtsIO ptsIO(m_evalField->GetSession()->GetComm());
127 3, m_sendFieldNames, pts);
128 // we first write to a temp file and rename this to make sure the
129 // receiver doesnt try to read it before we finished writing
130 string tmpFn = filename + ".tmp";
131 ptsIO.Write(tmpFn, sPts);
132 fs::rename(tmpFn, filename);
133}
std::vector< std::string > m_sendFieldNames
Definition: Coupling.h:114
std::shared_ptr< PtsField > PtsFieldSharedPtr
Definition: PtsField.h:184

References Nektar::MemoryManager< DataType >::AllocateSharedPtr(), FilterPython_Function::field, CellMLToNektar.pycml::format, Nektar::SolverUtils::Coupling::GenerateVariableMapping(), Nektar::SolverUtils::Coupling::m_config, Nektar::SolverUtils::Coupling::m_evalField, m_lastSend, Nektar::SolverUtils::Coupling::m_nSendVars, Nektar::SolverUtils::Coupling::m_sendFieldNames, Nektar::SolverUtils::Coupling::m_sendSteps, and Nektar::LibUtilities::PtsIO::Write().

Member Data Documentation

◆ className

std::string Nektar::SolverUtils::CouplingFile::className
static
Initial value:
=
GetCouplingFactory().RegisterCreatorFunction("File", CouplingFile::create,
"File Coupling")
static SOLVER_UTILS_EXPORT CouplingSharedPtr create(MultiRegions::ExpListSharedPtr field)
Creates an instance of this class.
Definition: CouplingFile.h:52
CouplingFactory & GetCouplingFactory()
Declaration of the Coupling factory singleton.
Definition: Coupling.cpp:42

Definition at line 49 of file CouplingFile.h.

◆ m_inputFunction

SessionFunctionSharedPtr Nektar::SolverUtils::CouplingFile::m_inputFunction
private

Definition at line 82 of file CouplingFile.h.

Referenced by v_Init(), and v_Receive().

◆ m_lastReceive

int Nektar::SolverUtils::CouplingFile::m_lastReceive
private

Definition at line 80 of file CouplingFile.h.

Referenced by v_Receive().

◆ m_lastSend

int Nektar::SolverUtils::CouplingFile::m_lastSend
private

Definition at line 79 of file CouplingFile.h.

Referenced by v_Send().