47 #include <boost/core/ignore_unused.hpp> 48 #include <boost/format.hpp> 49 #include <boost/functional/hash.hpp> 65 const int entities_dim,
66 const int n_local_vertex,
67 const int n_local_element,
68 const int n_local_polyhedra,
69 const int n_distant_point,
70 const double local_coordinates[],
71 const int local_connectivity_index[],
72 const int local_connectivity[],
73 const int local_polyhedra_face_index[],
74 const int local_polyhedra_cell_to_face_connectivity[],
75 const int local_polyhedra_face_connectivity_index[],
76 const int local_polyhedra_face_connectivity[],
77 const double distant_points_coordinates[],
78 const int distant_points_location[],
79 const float distant_points_distance[],
80 const int distant_points_barycentric_coordinates_index[],
81 const double distant_points_barycentric_coordinates[],
83 const cwipi_solver_type_t solver_type,
84 const void *local_field,
87 boost::ignore_unused(n_local_element, n_local_polyhedra, local_coordinates,
88 local_connectivity_index, local_connectivity,
89 local_polyhedra_face_index,
90 local_polyhedra_cell_to_face_connectivity,
91 local_polyhedra_face_connectivity_index,
92 local_polyhedra_face_connectivity,
93 distant_points_location,
94 distant_points_distance,
95 distant_points_barycentric_coordinates_index,
96 distant_points_barycentric_coordinates,
103 for (
int i = 0; i < n_distant_point; ++i)
106 for (
int j = 0; j < 3; ++j)
108 distCoords[i][j] = distant_points_coordinates[3 * i + j];
112 std::stringstream sst;
113 sst << entities_dim <<
"," << n_local_vertex <<
"," << stride;
116 ASSERTL0(interpField.num_elements() == stride,
"size mismatch");
117 ASSERTL0(interpField[0].num_elements() == n_distant_point,
"size mismatch");
119 for (
int i = 0; i < n_distant_point; i++)
121 for (
int j = 0; j < stride; ++j)
123 ((
double *)distant_field)[i * stride + j] = interpField[j][i];
129 :
Coupling(field), m_sendHandle(-1), m_recvHandle(-1), m_lastSend(-1E6),
130 m_lastReceive(-1E6), m_points(NULL), m_coords(NULL), m_connecIdx(NULL),
131 m_connec(NULL), m_rValsInterl(NULL), m_sValsInterl(NULL)
140 m_config[
"SENDMETHOD"] =
"EVALUATE";
150 cwipi_add_local_int_control_parameter(
"nSendVars",
m_nSendVars);
151 cwipi_add_local_int_control_parameter(
"nRecvVars",
m_nRecvVars);
152 cwipi_add_local_string_control_parameter(
153 "recvFieldNames",
m_config[
"RECEIVEVARIABLES"].c_str());
154 cwipi_add_local_string_control_parameter(
"sendFieldNames",
163 cwipi_add_local_int_control_parameter(
"receiveTag",
m_recvTag);
174 cwipi_solver_type_t solver_type = CWIPI_SOLVER_CELL_VERTEX;
177 CWIPI_COUPLING_PARALLEL_WITH_PARTITIONING,
186 cwipi_synchronize_control_parameter(
m_config[
"REMOTENAME"].c_str());
189 m_evalField->GetSession()->DefinesCmdLineArgument(
"verbose"))
191 cwipi_dump_application_properties();
194 m_sendTag = cwipi_get_distant_int_control_parameter(
195 m_config[
"REMOTENAME"].c_str(),
"receiveTag");
197 if (cwipi_has_int_parameter(
m_config[
"REMOTENAME"].c_str(),
"nRecvVars"))
199 int remoteNRecvVars = cwipi_get_distant_int_control_parameter(
200 m_config[
"REMOTENAME"].c_str(),
"nRecvVars");
202 "Number of local send vars different to remote received vars");
205 if (cwipi_has_int_parameter(
m_config[
"REMOTENAME"].c_str(),
"nSendVars"))
207 int remoteNSendVars = cwipi_get_distant_int_control_parameter(
208 m_config[
"REMOTENAME"].c_str(),
"nSendVars");
210 "Number of local receive vars different to remote sent vars");
221 m_evalField->GetSession()->DefinesCmdLineArgument(
"verbose"))
223 cout <<
"locating..." << endl;
250 ASSERTL0(session->DefinesElement(
"Nektar/Coupling"),
251 "No Coupling config found");
253 m_config[
"LOCALNAME"] = session->GetCmdLineArgument<std::string>(
"cwipi");
255 TiXmlElement *vCoupling = session->GetElement(
"Nektar/Coupling");
256 ASSERTL0(vCoupling,
"Invalid Coupling config");
263 int oversamp = boost::lexical_cast<
int>(
m_config[
"OVERSAMPLE"]);
267 recvGraph->SetExpansionsToPointOrder(
268 oversamp +
m_evalField->GetExp(0)->GetNumPoints(0));
277 m_evalField->GetSession(), recvGraph,
"DefaultVar");
301 ASSERTL0(
false,
"Expansion dimension not recognised");
320 m_recvField->GetCoords(coords[0], coords[1], coords[2]);
327 m_points[3 * i + 0] = double(coords[0][i]);
331 m_points[3 * i + 1] = double(coords[1][i]);
340 m_points[3 * i + 2] = double(coords[2][i]);
351 ASSERTL1(m_rValsInterl != NULL,
"malloc failed for m_rValsInterl");
367 std::stringstream sst;
372 std::placeholders::_1,
373 std::placeholders::_2);
382 int nOutPts = distCoords.num_elements();
385 for (
int i = 0; i < nOutPts; ++i)
392 elmtid =
m_evalField->GetExpIndex(distCoords[i], Lcoords, tol);
395 if (tol > 2 * NekConstants::kNekZeroTol)
399 if (Lcoords[j] < -1 - 0.75 * NekConstants::kNekZeroTol)
403 if (Lcoords[j] > 1 + 0.75 * NekConstants::kNekZeroTol)
411 "no element found for (" +
412 boost::lexical_cast<string>(distCoords[i][0]) +
", " +
413 boost::lexical_cast<string>(distCoords[i][1]) +
", " +
414 boost::lexical_cast<string>(distCoords[i][2]) +
")");
423 ASSERTL0(!(boost::math::isnan)(value),
"new value is not a number");
424 interpField[f][i] = value;
431 const double *distCoords =
436 for (
int i = 0; i < 3; ++i)
440 m_evalField->GetCoords(local[0], local[1], local[2]);
445 for (
int i = 0; i < 3; ++i)
448 for (
int j = 0; j < nPts; ++j)
450 dist[i][j] = distCoords[3 * j + i];
457 if (boost::to_upper_copy(
m_config[
"SENDMETHOD"]) ==
"SHEPARD")
481 seggeom = graph->GetAllSegGeoms();
485 trigeom = graph->GetAllTriGeoms();
486 quadgeom = graph->GetAllQuadGeoms();
490 tetgeom = graph->GetAllTetGeoms();
491 pyrgeom = graph->GetAllPyrGeoms();
492 prismgeom = graph->GetAllPrismGeoms();
493 hexgeom = graph->GetAllHexGeoms();
496 int nVerts = graph->GetNvertices();
497 int nElts = seggeom.size() + trigeom.size() + quadgeom.size() +
498 tetgeom.size() + pyrgeom.size() + prismgeom.size() +
502 m_coords = (
double *)malloc(
sizeof(
double) * 3 * nVerts);
504 int tmp = 2 * seggeom.size() + 3 * trigeom.size() + 4 * quadgeom.size() +
505 4 * tetgeom.size() + 5 * pyrgeom.size() + 6 * prismgeom.size() +
507 m_connec = (
int *)malloc(
sizeof(
int) * tmp);
509 m_connecIdx = (
int *)malloc(
sizeof(
int) * (nElts + 1));
552 template <
typename T>
563 int kNverts = T::mapped_type::element_type::kNverts;
566 for (
auto it = geom.begin(); it != geom.end(); it++)
569 for (
int j = 0; j < kNverts; ++j)
571 vert = it->second->GetVertex(j);
572 vertID = vert->GetVid();
578 vert->GetCoords(x[0], x[1], x[2]);
579 m_coords[3 * coordsPos + 0] = double(x[0]);
580 m_coords[3 * coordsPos + 1] = double(x[1]);
581 m_coords[3 * coordsPos + 2] = double(x[2]);
608 if (boost::to_upper_copy(
m_config[
"SENDMETHOD"]) ==
"NEARESTNEIGHBOUR" ||
609 boost::to_upper_copy(
m_config[
"SENDMETHOD"]) ==
"SHEPARD")
634 vector<string> &varNames)
647 vector<int> sendVarsToVars =
650 for (
int i = 0; i < sendVarsToVars.size(); ++i)
656 m_evalField->GetSession()->DefinesCmdLineArgument(
"verbose"))
658 cout <<
"sending fields at i = " << step <<
", t = " << time
666 strcpy(sendFN,
"dummyName");
680 m_evalField->GetSession()->DefinesCmdLineArgument(
"verbose"))
682 cout <<
"Send total time: " << timer1.
TimePerTest(1) << endl;
703 m_evalField->GetSession()->DefinesCmdLineArgument(
"verbose"))
705 cout <<
"Send waiting time: " << timer1.
TimePerTest(1) << endl;
721 strcpy(recFN,
"dummyName");
735 m_evalField->GetSession()->DefinesCmdLineArgument(
"verbose"))
737 cout <<
"Receive start time: " << timer1.
TimePerTest(1) << endl;
744 vector<string> &varNames)
752 vector<int> recvVarsToVars =
755 for (
int i = 0; i < recvVarsToVars.size(); ++i)
757 recvFields[i] = field[recvVarsToVars[i]];
815 m_evalField->GetSession()->DefinesCmdLineArgument(
"verbose"))
817 cout <<
"waiting for receive at i = " << step <<
", t = " << time
838 int nNotLoc = cwipi_get_n_not_located_points(
m_couplingName.c_str());
842 cout <<
"WARNING: relocating " << nNotLoc <<
" of " <<
m_nPoints 843 <<
" points" << endl;
848 for (
int i = 0; i < nNotLoc; ++i)
850 notLoc[i] = tmp[i] - 1;
853 if (boost::to_upper_copy(
m_config[
"NOTLOCMETHOD"]) ==
"KEEP")
864 for (
int i = 0, locPos = 0, intPos = 0; i <
m_nPoints; ++i)
866 if (locPos < nNotLoc && notLoc[locPos] == i)
881 if (boost::to_upper_copy(
m_config[
"NOTLOCMETHOD"]) ==
"EXTRAPOLATE")
883 int doExtrapolate = 0;
890 if (doExtrapolate > 0)
923 m_recvField->LinearAdvectionDiffusionReactionSolve(
949 m_evalField->GetSession()->DefinesCmdLineArgument(
"verbose"))
951 cout <<
"Receive total time: " << timer1.
TimePerTest(1) <<
", ";
952 cout <<
"Receive waiting time: " << timer2.
TimePerTest(1) << endl;
966 int nNotLoc = notLoc.num_elements();
967 int nranks =
m_evalField->GetSession()->GetComm()->GetSize();
971 m_evalField->GetSession()->GetComm()->AllGather(thisNLoc, sizeMap);
975 for (
int i = 1; i < nranks; ++i)
977 offsetMap[i] = offsetMap[i - 1] + sizeMap[i - 1];
979 int totNLoc = offsetMap[nranks - 1] + sizeMap[nranks - 1];
982 for (
int i = 0; i < 3; ++i)
986 m_recvField->GetCoords(allVals[0], allVals[1], allVals[2]);
999 allVals[3 + i] = rVals[i];
1003 for (
int i = 0; i < totvars; ++i)
1009 int offset = offsetMap[
m_evalField->GetSession()->GetComm()->GetRank()];
1010 for (
int i = 0, intPos = 0, locPos = 0; i <
m_nPoints; ++i)
1012 if (locPos < nNotLoc && notLoc[locPos] == i)
1019 for (
int k = 0; k < totvars; ++k)
1021 locatedVals[k][offset + intPos] = allVals[k][i];
1029 for (
int i = 0; i < totvars; ++i)
1032 locatedVals[i], sizeMap, offsetMap);
1043 for (
int j = 0; j < totvars; ++j)
1046 for (
int i = 0; i < nNotLoc; ++i)
1048 notLocVals[j][i] = allVals[j][notLoc[i]];
1067 for (
int j = 3; j < totvars; ++j)
1069 for (
int i = 0; i < nNotLoc; ++i)
1071 allVals[j][notLoc[i]] = notLocVals[j][i];
1078 m_evalField->GetSession()->DefinesCmdLineArgument(
"verbose"))
1080 cout <<
"ExtrapolateFields total time: " << timer1.
TimePerTest(1);
1081 cout <<
" (AllGathervI: " << timer2.
TimePerTest(1) <<
")" << endl;
1091 #if (defined _WIN32 && _MSC_VER < 1900) 1094 unsigned int old_exponent_format;
1095 old_exponent_format = _set_output_format(_TWO_DIGIT_EXPONENT);
1097 _set_output_format(old_exponent_format);
1099 std::string filename =
1104 for (
int i = 0; i < 3; ++i)
1119 csvIO.Write(filename, rvPts);
1123 m_evalField->GetSession()->DefinesCmdLineArgument(
"verbose"))
1125 cout <<
"DumpRawFields total time: " << timer1.
TimePerTest(1) << endl;
static std::string className
#define ASSERTL0(condition, msg)
void ReceiveCwipi(const int step, const NekDouble time, Array< OneD, Array< OneD, NekDouble > > &field)
std::shared_ptr< MeshGraph > MeshGraphSharedPtr
CouplingConfigMap m_config
std::shared_ptr< ExpList > ExpListSharedPtr
Shared pointer to an ExpList object.
Array< OneD, Array< OneD, NekDouble > > m_newFields
NekDouble TimePerTest(unsigned int n)
Returns amount of seconds per iteration in a test with n iterations.
static CouplingSharedPtr create(MultiRegions::ExpListSharedPtr field)
Creates an instance of this class.
std::vector< std::string > m_recvFieldNames
static std::map< std::string, SendCallbackType > SendCallbackMap
std::map< int, int > m_vertMap
SOLVER_UTILS_EXPORT CouplingCwipi(MultiRegions::ExpListSharedPtr field)
FieldUtils::InterpolatorSharedPtr m_sendInterpolator
virtual SOLVER_UTILS_EXPORT void v_Init()
std::map< int, PrismGeomSharedPtr > PrismGeomMap
void AddElementsToMesh(T geom, int &coordsPos, int &connecPos, int &conidxPos)
std::map< int, PyrGeomSharedPtr > PyrGeomMap
void ExtrapolateFields(Array< OneD, Array< OneD, NekDouble > > &rVals, Array< OneD, int > ¬Loc)
std::map< int, TetGeomSharedPtr > TetGeomMap
virtual SOLVER_UTILS_EXPORT ~CouplingCwipi()
void EvaluateFields(Array< OneD, Array< OneD, NekDouble > > interpField, Array< OneD, Array< OneD, NekDouble > > distCoords)
std::map< int, TriGeomSharedPtr > TriGeomMap
SOLVER_UTILS_EXPORT std::vector< int > GenerateVariableMapping(std::vector< std::string > &vars, std::vector< std::string > &transVars)
std::shared_ptr< PtsField > PtsFieldSharedPtr
static const NekDouble kNekZeroTol
void Smul(int n, const T alpha, const T *x, const int incx, T *y, const int incy)
Scalar multiply y = alpha*y.
Array< OneD, Array< OneD, NekDouble > > m_oldFields
std::vector< std::string > m_sendFieldNames
std::string m_couplingName
std::map< int, SegGeomSharedPtr > SegGeomMap
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)
static std::shared_ptr< DataType > AllocateSharedPtr(const Args &...args)
Allocate a shared pointer from the memory pool.
FieldUtils::InterpolatorSharedPtr m_extrapInterpolator
std::shared_ptr< PointGeom > PointGeomSharedPtr
void SetupSendInterpolation()
MultiRegions::ExpListSharedPtr m_recvField
virtual SOLVER_UTILS_EXPORT void v_Finalize()
std::map< int, QuadGeomSharedPtr > QuadGeomMap
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)
MultiRegions::ExpListSharedPtr m_evalField
virtual SOLVER_UTILS_EXPORT void v_Init()
virtual SOLVER_UTILS_EXPORT void v_Receive(const int step, const NekDouble time, Array< OneD, Array< OneD, NekDouble > > &field, std::vector< std::string > &varNames)
Array< OneD, Array< OneD, NekDouble > > m_sendField
void ReadConfig(LibUtilities::SessionReaderSharedPtr session)
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):
SOLVER_UTILS_EXPORT void SendCallback(Array< OneD, Array< OneD, NekDouble > > &interpField, Array< OneD, Array< OneD, NekDouble > > &distCoords)
CouplingFactory & GetCouplingFactory()
Declaration of the Coupling factory singleton.
void DumpRawFields(const NekDouble time, Array< OneD, Array< OneD, NekDouble > > rVals)
void Zero(int n, T *x, const int incx)
Zero vector.
#define ASSERTL1(condition, msg)
Assert Level 1 – Debugging which is used whether in FULLDEBUG or DEBUG compilation mode...
void Vcopy(int n, const T *x, const int incx, T *y, const int incy)
std::map< int, HexGeomSharedPtr > HexGeomMap
std::shared_ptr< SessionReader > SessionReaderSharedPtr
static MeshGraphSharedPtr Read(const LibUtilities::SessionReaderSharedPtr pSession, DomainRangeShPtr rng=NullDomainRangeShPtr, bool fillGraph=true)