45 #include <boost/core/ignore_unused.hpp> 
   46 #include <boost/format.hpp> 
   47 #include <boost/functional/hash.hpp> 
   63     const int entities_dim,
 
   64     const int n_local_vertex,
 
   65     const int n_local_element,
 
   66     const int n_local_polyhedra,
 
   67     const int n_distant_point,
 
   68     const double local_coordinates[],
 
   69     const int local_connectivity_index[],
 
   70     const int local_connectivity[],
 
   71     const int local_polyhedra_face_index[],
 
   72     const int local_polyhedra_cell_to_face_connectivity[],
 
   73     const int local_polyhedra_face_connectivity_index[],
 
   74     const int local_polyhedra_face_connectivity[],
 
   75     const double distant_points_coordinates[],
 
   76     const int distant_points_location[],
 
   77     const float distant_points_distance[],
 
   78     const int distant_points_barycentric_coordinates_index[],
 
   79     const double distant_points_barycentric_coordinates[],
 
   81     const cwipi_solver_type_t solver_type,
 
   82     const void *local_field,
 
   85     boost::ignore_unused(n_local_element, n_local_polyhedra, local_coordinates,
 
   86                          local_connectivity_index, local_connectivity,
 
   87                          local_polyhedra_face_index,
 
   88                          local_polyhedra_cell_to_face_connectivity,
 
   89                          local_polyhedra_face_connectivity_index,
 
   90                          local_polyhedra_face_connectivity,
 
   91                          distant_points_location,
 
   92                          distant_points_distance,
 
   93                          distant_points_barycentric_coordinates_index,
 
   94                          distant_points_barycentric_coordinates,
 
  101     for (
int i = 0; i < n_distant_point; ++i)
 
  104         for (
int j = 0; j < 3; ++j)
 
  106             distCoords[i][j] = distant_points_coordinates[3 * i + j];
 
  110     std::stringstream sst;
 
  111     sst << entities_dim << 
"," << n_local_vertex << 
"," << stride;
 
  114     ASSERTL0(interpField.size() == stride, 
"size mismatch");
 
  115     ASSERTL0(interpField[0].size() == n_distant_point, 
"size mismatch");
 
  117     for (
int i = 0; i < n_distant_point; i++)
 
  119         for (
int j = 0; j < stride; ++j)
 
  121             ((
double *)distant_field)[i * stride + j] = interpField[j][i];
 
  127     : 
Coupling(field), m_sendHandle(-1), m_recvHandle(-1), m_lastSend(-1E6),
 
  128       m_lastReceive(-1E6), m_points(NULL), m_coords(NULL), m_connecIdx(NULL),
 
  129       m_connec(NULL), m_rValsInterl(NULL), m_sValsInterl(NULL)
 
  138     m_config[
"SENDMETHOD"]   = 
"EVALUATE";
 
  148     cwipi_add_local_int_control_parameter(
"nSendVars", 
m_nSendVars);
 
  149     cwipi_add_local_int_control_parameter(
"nRecvVars", 
m_nRecvVars);
 
  150     cwipi_add_local_string_control_parameter(
 
  151         "recvFieldNames", 
m_config[
"RECEIVEVARIABLES"].c_str());
 
  152     cwipi_add_local_string_control_parameter(
"sendFieldNames",
 
  161     cwipi_add_local_int_control_parameter(
"receiveTag", 
m_recvTag);
 
  172     cwipi_solver_type_t solver_type = CWIPI_SOLVER_CELL_VERTEX;
 
  175                           CWIPI_COUPLING_PARALLEL_WITH_PARTITIONING,
 
  184     cwipi_synchronize_control_parameter(
m_config[
"REMOTENAME"].c_str());
 
  187         m_evalField->GetSession()->DefinesCmdLineArgument(
"verbose"))
 
  189         cwipi_dump_application_properties();
 
  192     m_sendTag = cwipi_get_distant_int_control_parameter(
 
  193         m_config[
"REMOTENAME"].c_str(), 
"receiveTag");
 
  195     if (cwipi_has_int_parameter(
m_config[
"REMOTENAME"].c_str(), 
"nRecvVars"))
 
  197         int remoteNRecvVars = cwipi_get_distant_int_control_parameter(
 
  198             m_config[
"REMOTENAME"].c_str(), 
"nRecvVars");
 
  200                  "Number of local send vars different to remote received vars");
 
  203     if (cwipi_has_int_parameter(
m_config[
"REMOTENAME"].c_str(), 
"nSendVars"))
 
  205         int remoteNSendVars = cwipi_get_distant_int_control_parameter(
 
  206             m_config[
"REMOTENAME"].c_str(), 
"nSendVars");
 
  208                  "Number of local receive vars different to remote sent vars");
 
  219         m_evalField->GetSession()->DefinesCmdLineArgument(
"verbose"))
 
  221         cout << 
"locating..." << endl;
 
  248     ASSERTL0(session->DefinesElement(
"Nektar/Coupling"),
 
  249              "No Coupling config found");
 
  251     m_config[
"LOCALNAME"] = session->GetCmdLineArgument<std::string>(
"cwipi");
 
  253     TiXmlElement *vCoupling = session->GetElement(
"Nektar/Coupling");
 
  254     ASSERTL0(vCoupling, 
"Invalid Coupling config");
 
  261     int oversamp = boost::lexical_cast<int>(
m_config[
"OVERSAMPLE"]);
 
  265     recvGraph->SetExpansionInfoToPointOrder(
 
  266         oversamp + 
m_evalField->GetExp(0)->GetNumPoints(0));
 
  271            m_evalField->GetSession(), recvGraph, 
"DefaultVar");
 
  287     m_recvField->GetCoords(coords[0], coords[1], coords[2]);
 
  294         m_points[3 * i + 0] = double(coords[0][i]);
 
  298             m_points[3 * i + 1] = double(coords[1][i]);
 
  307             m_points[3 * i + 2] = double(coords[2][i]);
 
  334     std::stringstream sst;
 
  339                                            std::placeholders::_1,
 
  340                                            std::placeholders::_2);
 
  349     int nOutPts = distCoords.size();
 
  352     for (
int i = 0; i < nOutPts; ++i)
 
  359             elmtid = 
m_evalField->GetExpIndex(distCoords[i], Lcoords, tol);
 
  378                  "no element found for (" +
 
  379                      boost::lexical_cast<string>(distCoords[i][0]) + 
", " +
 
  380                      boost::lexical_cast<string>(distCoords[i][1]) + 
", " +
 
  381                      boost::lexical_cast<string>(distCoords[i][2]) + 
")");
 
  390             ASSERTL0(!(boost::math::isnan)(value), 
"new value is not a number");
 
  391             interpField[f][i] = value;
 
  398     const double *distCoords =
 
  403     for (
int i = 0; i < 3; ++i)
 
  407     m_evalField->GetCoords(local[0], local[1], local[2]);
 
  412     for (
int i = 0; i < 3; ++i)
 
  415         for (
int j = 0; j < nPts; ++j)
 
  417             dist[i][j] = distCoords[3 * j + i];
 
  424     if (boost::to_upper_copy(
m_config[
"SENDMETHOD"]) == 
"SHEPARD")
 
  448         seggeom = graph->GetAllSegGeoms();
 
  452         trigeom  = graph->GetAllTriGeoms();
 
  453         quadgeom = graph->GetAllQuadGeoms();
 
  457         tetgeom   = graph->GetAllTetGeoms();
 
  458         pyrgeom   = graph->GetAllPyrGeoms();
 
  459         prismgeom = graph->GetAllPrismGeoms();
 
  460         hexgeom   = graph->GetAllHexGeoms();
 
  463     int nVerts = graph->GetNvertices();
 
  464     int nElts  = seggeom.size() + trigeom.size() + quadgeom.size() +
 
  465                 tetgeom.size() + pyrgeom.size() + prismgeom.size() +
 
  469     m_coords = (
double *)malloc(
sizeof(
double) * 3 * nVerts);
 
  471     int tmp = 2 * seggeom.size() + 3 * trigeom.size() + 4 * quadgeom.size() +
 
  472               4 * tetgeom.size() + 5 * pyrgeom.size() + 6 * prismgeom.size() +
 
  474     m_connec = (
int *)malloc(
sizeof(
int) * tmp);
 
  476     m_connecIdx = (
int *)malloc(
sizeof(
int) * (nElts + 1));
 
  519 template <
typename T>
 
  530     int kNverts = T::mapped_type::element_type::kNverts;
 
  533     for (
auto it = geom.begin(); it != geom.end(); it++)
 
  536         for (
int j = 0; j < kNverts; ++j)
 
  538             vert   = it->second->GetVertex(j);
 
  539             vertID = vert->GetVid();
 
  545                 vert->GetCoords(x[0], x[1], x[2]);
 
  546                 m_coords[3 * coordsPos + 0] = double(x[0]);
 
  547                 m_coords[3 * coordsPos + 1] = double(x[1]);
 
  548                 m_coords[3 * coordsPos + 2] = double(x[2]);
 
  575     if (boost::to_upper_copy(
m_config[
"SENDMETHOD"]) == 
"NEARESTNEIGHBOUR" ||
 
  576         boost::to_upper_copy(
m_config[
"SENDMETHOD"]) == 
"SHEPARD")
 
  601     vector<string> &varNames)
 
  614         vector<int> sendVarsToVars =
 
  617         for (
int i = 0; i < sendVarsToVars.size(); ++i)
 
  623             m_evalField->GetSession()->DefinesCmdLineArgument(
"verbose"))
 
  625             cout << 
"sending fields at i = " << step << 
", t = " << time
 
  633         strcpy(sendFN, 
"dummyName");
 
  647             m_evalField->GetSession()->DefinesCmdLineArgument(
"verbose"))
 
  649             cout << 
"Send total time: " << timer1.
TimePerTest(1) << endl;
 
  670         m_evalField->GetSession()->DefinesCmdLineArgument(
"verbose"))
 
  672         cout << 
"Send waiting time: " << timer1.
TimePerTest(1) << endl;
 
  688     strcpy(recFN, 
"dummyName");
 
  702         m_evalField->GetSession()->DefinesCmdLineArgument(
"verbose"))
 
  704         cout << 
"Receive start time: " << timer1.
TimePerTest(1) << endl;
 
  711                               vector<string> &varNames)
 
  719     vector<int> recvVarsToVars =
 
  722     for (
int i = 0; i < recvVarsToVars.size(); ++i)
 
  724         recvFields[i] = field[recvVarsToVars[i]];
 
  782             m_evalField->GetSession()->DefinesCmdLineArgument(
"verbose"))
 
  784             cout << 
"waiting for receive at i = " << step << 
", t = " << time
 
  805         int nNotLoc = cwipi_get_n_not_located_points(
m_couplingName.c_str());
 
  809             cout << 
"WARNING: relocating " << nNotLoc << 
" of " << 
m_nPoints 
  810                  << 
" points" << endl;
 
  815             for (
int i = 0; i < nNotLoc; ++i)
 
  817                 notLoc[i] = tmp[i] - 1;
 
  820             if (boost::to_upper_copy(
m_config[
"NOTLOCMETHOD"]) == 
"KEEP")
 
  831         for (
int i = 0, locPos = 0, intPos = 0; i < 
m_nPoints; ++i)
 
  833             if (locPos < nNotLoc && notLoc[locPos] == i)
 
  848         if (boost::to_upper_copy(
m_config[
"NOTLOCMETHOD"]) == 
"EXTRAPOLATE")
 
  850             int doExtrapolate = 0;
 
  857             if (doExtrapolate > 0)
 
  890                 m_recvField->LinearAdvectionDiffusionReactionSolve(
 
  916             m_evalField->GetSession()->DefinesCmdLineArgument(
"verbose"))
 
  918             cout << 
"Receive total time: " << timer1.
TimePerTest(1) << 
", ";
 
  919             cout << 
"Receive waiting time: " << timer2.
TimePerTest(1) << endl;
 
  933     int nNotLoc = notLoc.size();
 
  934     int nranks  = 
m_evalField->GetSession()->GetComm()->GetSize();
 
  938     m_evalField->GetSession()->GetComm()->AllGather(thisNLoc, sizeMap);
 
  942     for (
int i = 1; i < nranks; ++i)
 
  944         offsetMap[i] = offsetMap[i - 1] + sizeMap[i - 1];
 
  946     int totNLoc = offsetMap[nranks - 1] + sizeMap[nranks - 1];
 
  949     for (
int i = 0; i < 3; ++i)
 
  953     m_recvField->GetCoords(allVals[0], allVals[1], allVals[2]);
 
  966         allVals[3 + i] = rVals[i];
 
  970     for (
int i = 0; i < totvars; ++i)
 
  976     int offset = offsetMap[
m_evalField->GetSession()->GetComm()->GetRank()];
 
  977     for (
int i = 0, intPos = 0, locPos = 0; i < 
m_nPoints; ++i)
 
  979         if (locPos < nNotLoc && notLoc[locPos] == i)
 
  986             for (
int k = 0; k < totvars; ++k)
 
  988                 locatedVals[k][offset + intPos] = allVals[k][i];
 
  996     for (
int i = 0; i < totvars; ++i)
 
  999             locatedVals[i], sizeMap, offsetMap);
 
 1010         for (
int j = 0; j < totvars; ++j)
 
 1013             for (
int i = 0; i < nNotLoc; ++i)
 
 1015                 notLocVals[j][i] = allVals[j][notLoc[i]];
 
 1034         for (
int j = 3; j < totvars; ++j)
 
 1036             for (
int i = 0; i < nNotLoc; ++i)
 
 1038                 allVals[j][notLoc[i]] = notLocVals[j][i];
 
 1045         m_evalField->GetSession()->DefinesCmdLineArgument(
"verbose"))
 
 1047         cout << 
"ExtrapolateFields total time: " << timer1.
TimePerTest(1);
 
 1048         cout << 
" (AllGathervI: " << timer2.
TimePerTest(1) << 
")" << endl;
 
 1058 #if (defined _WIN32 && _MSC_VER < 1900) 
 1061     unsigned int old_exponent_format;
 
 1062     old_exponent_format = _set_output_format(_TWO_DIGIT_EXPONENT);
 
 1064     _set_output_format(old_exponent_format);
 
 1066     std::string filename =
 
 1071     for (
int i = 0; i < 3; ++i)
 
 1086     csvIO.
Write(filename, rvPts);
 
 1090         m_evalField->GetSession()->DefinesCmdLineArgument(
"verbose"))
 
 1092         cout << 
"DumpRawFields total time: " << timer1.
TimePerTest(1) << endl;
 
#define ASSERTL0(condition, msg)
 
#define ASSERTL1(condition, msg)
Assert Level 1 – Debugging which is used whether in FULLDEBUG or DEBUG compilation mode....
 
void Write(const std::string &outFile, const PtsFieldSharedPtr &ptsField, const bool backup=false)
Save a pts field to a file.
 
NekDouble TimePerTest(unsigned int n)
Returns amount of seconds per iteration in a test with n iterations.
 
static std::shared_ptr< DataType > AllocateSharedPtr(const Args &...args)
Allocate a shared pointer from the memory pool.
 
virtual SOLVER_UTILS_EXPORT void v_Receive(const int step, const NekDouble time, Array< OneD, Array< OneD, NekDouble > > &field, std::vector< std::string > &varNames)
 
static SOLVER_UTILS_EXPORT void InterpCallback(const int entities_dim, const int n_local_vertex, const int n_local_element, const int n_local_polhyedra, const int n_distant_point, const double local_coordinates[], const int local_connectivity_index[], const int local_connectivity[], const int local_polyhedra_face_index[], const int local_polyhedra_cell_to_face_connectivity[], const int local_polyhedra_face_connectivity_index[], const int local_polyhedra_face_connectivity[], const double distant_points_coordinates[], const int distant_points_location[], const float distant_points_distance[], const int distant_points_barycentric_coordinates_index[], const double distant_points_barycentric_coordinates[], const int stride, const cwipi_solver_type_t solver_type, const void *local_field, void *distant_field)
 
virtual SOLVER_UTILS_EXPORT void v_Finalize()
 
static std::string className
 
Array< OneD, Array< OneD, NekDouble > > m_oldFields
 
FieldUtils::InterpolatorSharedPtr m_extrapInterpolator
 
FieldUtils::InterpolatorSharedPtr m_sendInterpolator
 
void AddElementsToMesh(T geom, int &coordsPos, int &connecPos, int &conidxPos)
 
Array< OneD, Array< OneD, NekDouble > > m_sendField
 
virtual SOLVER_UTILS_EXPORT ~CouplingCwipi()
 
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)
 
SOLVER_UTILS_EXPORT CouplingCwipi(MultiRegions::ExpListSharedPtr field)
 
void ExtrapolateFields(Array< OneD, Array< OneD, NekDouble > > &rVals, Array< OneD, int > ¬Loc)
 
virtual SOLVER_UTILS_EXPORT void v_Init()
 
void EvaluateFields(Array< OneD, Array< OneD, NekDouble > > interpField, Array< OneD, Array< OneD, NekDouble > > distCoords)
 
static CouplingSharedPtr create(MultiRegions::ExpListSharedPtr field)
Creates an instance of this class.
 
Array< OneD, Array< OneD, NekDouble > > m_newFields
 
void SetupSendInterpolation()
 
SOLVER_UTILS_EXPORT void SendCallback(Array< OneD, Array< OneD, NekDouble > > &interpField, Array< OneD, Array< OneD, NekDouble > > &distCoords)
 
void ReadConfig(LibUtilities::SessionReaderSharedPtr session)
 
void ReceiveCwipi(const int step, const NekDouble time, Array< OneD, Array< OneD, NekDouble > > &field)
 
std::map< int, int > m_vertMap
 
void DumpRawFields(const NekDouble time, Array< OneD, Array< OneD, NekDouble > > rVals)
 
MultiRegions::ExpListSharedPtr m_recvField
 
virtual SOLVER_UTILS_EXPORT void v_Init()
 
MultiRegions::ExpListSharedPtr m_evalField
 
std::string m_couplingName
 
std::vector< std::string > m_sendFieldNames
 
CouplingConfigMap m_config
 
std::vector< std::string > m_recvFieldNames
 
SOLVER_UTILS_EXPORT std::vector< int > GenerateVariableMapping(std::vector< std::string > &vars, std::vector< std::string > &transVars)
 
static MeshGraphSharedPtr Read(const LibUtilities::SessionReaderSharedPtr pSession, LibUtilities::DomainRangeShPtr rng=LibUtilities::NullDomainRangeShPtr, bool fillGraph=true)
 
std::shared_ptr< SessionReader > SessionReaderSharedPtr
 
std::shared_ptr< PtsField > PtsFieldSharedPtr
 
std::shared_ptr< ExpList > ExpListSharedPtr
Shared pointer to an ExpList object.
 
static const NekDouble kNekZeroTol
 
static std::map< std::string, SendCallbackType > SendCallbackMap
 
CouplingFactory & GetCouplingFactory()
Declaration of the Coupling factory singleton.
 
std::map< int, TriGeomSharedPtr > TriGeomMap
 
std::map< int, PyrGeomSharedPtr > PyrGeomMap
 
std::map< int, QuadGeomSharedPtr > QuadGeomMap
 
std::map< int, SegGeomSharedPtr > SegGeomMap
 
std::map< int, TetGeomSharedPtr > TetGeomMap
 
std::shared_ptr< MeshGraph > MeshGraphSharedPtr
 
std::map< int, PrismGeomSharedPtr > PrismGeomMap
 
std::shared_ptr< PointGeom > PointGeomSharedPtr
 
std::map< int, HexGeomSharedPtr > HexGeomMap
 
The above copyright notice and this permission notice shall be included.
 
void Svtsvtp(int n, const T alpha, const T *x, int incx, const T beta, const T *y, int incy, T *z, int incz)
vvtvvtp (scalar times vector plus scalar times vector):
 
void Smul(int n, const T alpha, const T *x, const int incx, T *y, const int incy)
Scalar multiply y = alpha*x.
 
void Zero(int n, T *x, const int incx)
Zero vector.
 
void Vcopy(int n, const T *x, const int incx, T *y, const int incy)