46#include <boost/format.hpp>
47#include <boost/functional/hash.hpp>
61 const int entities_dim,
const int n_local_vertex,
62 [[maybe_unused]]
const int n_local_element,
63 [[maybe_unused]]
const int n_local_polyhedra,
const int n_distant_point,
64 [[maybe_unused]]
const double local_coordinates[],
65 [[maybe_unused]]
const int local_connectivity_index[],
66 [[maybe_unused]]
const int local_connectivity[],
67 [[maybe_unused]]
const int local_polyhedra_face_index[],
68 [[maybe_unused]]
const int local_polyhedra_cell_to_face_connectivity[],
69 [[maybe_unused]]
const int local_polyhedra_face_connectivity_index[],
70 [[maybe_unused]]
const int local_polyhedra_face_connectivity[],
71 const double distant_points_coordinates[],
72 [[maybe_unused]]
const int distant_points_location[],
73 [[maybe_unused]]
const float distant_points_distance[],
74 [[maybe_unused]]
const int distant_points_barycentric_coordinates_index[],
75 [[maybe_unused]]
const double distant_points_barycentric_coordinates[],
76 const int stride, [[maybe_unused]]
const cwipi_solver_type_t solver_type,
77 [[maybe_unused]]
const void *local_field,
void *distant_field)
82 for (
int i = 0; i < n_distant_point; ++i)
85 for (
int j = 0; j < 3; ++j)
87 distCoords[i][j] = distant_points_coordinates[3 * i + j];
91 std::stringstream sst;
92 sst << entities_dim <<
"," << n_local_vertex <<
"," << stride;
95 ASSERTL0(interpField.size() == stride,
"size mismatch");
96 ASSERTL0(interpField[0].size() == n_distant_point,
"size mismatch");
98 for (
int i = 0; i < n_distant_point; i++)
100 for (
int j = 0; j < stride; ++j)
102 ((
double *)distant_field)[i * stride + j] = interpField[j][i];
108 :
Coupling(
field), m_sendHandle(-1), m_recvHandle(-1), m_lastSend(-1E6),
109 m_lastReceive(-1E6), m_points(nullptr), m_coords(nullptr),
110 m_connecIdx(nullptr), m_connec(nullptr), m_rValsInterl(nullptr),
111 m_sValsInterl(nullptr)
120 m_config[
"SENDMETHOD"] =
"EVALUATE";
130 cwipi_add_local_int_control_parameter(
"nSendVars",
m_nSendVars);
131 cwipi_add_local_int_control_parameter(
"nRecvVars",
m_nRecvVars);
132 cwipi_add_local_string_control_parameter(
133 "recvFieldNames",
m_config[
"RECEIVEVARIABLES"].c_str());
134 cwipi_add_local_string_control_parameter(
"sendFieldNames",
145 cwipi_add_local_int_control_parameter(
"receiveTag",
m_recvTag);
156 cwipi_solver_type_t solver_type = CWIPI_SOLVER_CELL_VERTEX;
158 cwipi_create_coupling(
159 m_couplingName.c_str(), CWIPI_COUPLING_PARALLEL_WITH_PARTITIONING,
162 cwipi_synchronize_control_parameter(
m_config[
"REMOTENAME"].c_str());
165 m_evalField->GetSession()->DefinesCmdLineArgument(
"verbose"))
167 cwipi_dump_application_properties();
170 m_sendTag = cwipi_get_distant_int_control_parameter(
171 m_config[
"REMOTENAME"].c_str(),
"receiveTag");
173 if (cwipi_has_int_parameter(
m_config[
"REMOTENAME"].c_str(),
"nRecvVars"))
175 int remoteNRecvVars = cwipi_get_distant_int_control_parameter(
176 m_config[
"REMOTENAME"].c_str(),
"nRecvVars");
178 "Number of local send vars different to remote received vars");
181 if (cwipi_has_int_parameter(
m_config[
"REMOTENAME"].c_str(),
"nSendVars"))
183 int remoteNSendVars = cwipi_get_distant_int_control_parameter(
184 m_config[
"REMOTENAME"].c_str(),
"nSendVars");
186 "Number of local receive vars different to remote sent vars");
197 m_evalField->GetSession()->DefinesCmdLineArgument(
"verbose"))
199 cout <<
"locating..." << endl;
226 ASSERTL0(session->DefinesElement(
"Nektar/Coupling"),
227 "No Coupling config found");
229 m_config[
"LOCALNAME"] = session->GetCmdLineArgument<std::string>(
"cwipi");
231 TiXmlElement *vCoupling = session->GetElement(
"Nektar/Coupling");
232 ASSERTL0(vCoupling,
"Invalid Coupling config");
239 int oversamp = boost::lexical_cast<int>(
m_config[
"OVERSAMPLE"]);
243 recvGraph->SetExpansionInfoToPointOrder(
244 oversamp +
m_evalField->GetExp(0)->GetNumPoints(0));
248 m_evalField->GetSession(), recvGraph,
"DefaultVar");
264 m_recvField->GetCoords(coords[0], coords[1], coords[2]);
271 m_points[3 * i + 0] = double(coords[0][i]);
275 m_points[3 * i + 1] = double(coords[1][i]);
284 m_points[3 * i + 2] = double(coords[2][i]);
311 std::stringstream sst;
316 std::placeholders::_2);
325 int nOutPts = distCoords.size();
328 for (
int i = 0; i < nOutPts; ++i)
335 elmtid =
m_evalField->GetExpIndex(distCoords[i], Lcoords, tol);
354 "no element found for (" +
355 boost::lexical_cast<string>(distCoords[i][0]) +
", " +
356 boost::lexical_cast<string>(distCoords[i][1]) +
", " +
357 boost::lexical_cast<string>(distCoords[i][2]) +
")");
366 ASSERTL0(!(boost::math::isnan)(value),
"new value is not a number");
367 interpField[f][i] = value;
374 const double *distCoords =
379 for (
int i = 0; i < 3; ++i)
383 m_evalField->GetCoords(local[0], local[1], local[2]);
388 for (
int i = 0; i < 3; ++i)
391 for (
int j = 0; j < nPts; ++j)
393 dist[i][j] = distCoords[3 * j + i];
400 if (boost::to_upper_copy(
m_config[
"SENDMETHOD"]) ==
"SHEPARD")
424 seggeom = graph->GetAllSegGeoms();
428 trigeom = graph->GetAllTriGeoms();
429 quadgeom = graph->GetAllQuadGeoms();
433 tetgeom = graph->GetAllTetGeoms();
434 pyrgeom = graph->GetAllPyrGeoms();
435 prismgeom = graph->GetAllPrismGeoms();
436 hexgeom = graph->GetAllHexGeoms();
439 int nVerts = graph->GetNvertices();
440 int nElts = seggeom.size() + trigeom.size() + quadgeom.size() +
441 tetgeom.size() + pyrgeom.size() + prismgeom.size() +
445 m_coords = (
double *)malloc(
sizeof(
double) * 3 * nVerts);
447 int tmp = 2 * seggeom.size() + 3 * trigeom.size() + 4 * quadgeom.size() +
448 4 * tetgeom.size() + 5 * pyrgeom.size() + 6 * prismgeom.size() +
450 m_connec = (
int *)malloc(
sizeof(
int) * tmp);
452 m_connecIdx = (
int *)malloc(
sizeof(
int) * (nElts + 1));
504 int kNverts = T::mapped_type::element_type::kNverts;
507 for (
auto it = geom.begin(); it != geom.end(); it++)
510 for (
int j = 0; j < kNverts; ++j)
512 vert = it->second->GetVertex(j);
513 vertID = vert->GetVid();
519 vert->GetCoords(x[0], x[1], x[2]);
520 m_coords[3 * coordsPos + 0] = double(x[0]);
521 m_coords[3 * coordsPos + 1] = double(x[1]);
522 m_coords[3 * coordsPos + 2] = double(x[2]);
549 if (boost::to_upper_copy(
m_config[
"SENDMETHOD"]) ==
"NEARESTNEIGHBOUR" ||
550 boost::to_upper_copy(
m_config[
"SENDMETHOD"]) ==
"SHEPARD")
574 vector<string> &varNames)
587 vector<int> sendVarsToVars =
590 for (
int i = 0; i < sendVarsToVars.size(); ++i)
596 m_evalField->GetSession()->DefinesCmdLineArgument(
"verbose"))
598 cout <<
"sending fields at i = " << step <<
", t = " << time
606 strcpy(sendFN,
"dummyName");
613 m_evalField->GetSession()->DefinesCmdLineArgument(
"verbose"))
615 cout <<
"Send total time: " << timer1.
TimePerTest(1) << endl;
636 m_evalField->GetSession()->DefinesCmdLineArgument(
"verbose"))
638 cout <<
"Send waiting time: " << timer1.
TimePerTest(1) << endl;
654 strcpy(recFN,
"dummyName");
661 m_evalField->GetSession()->DefinesCmdLineArgument(
"verbose"))
663 cout <<
"Receive start time: " << timer1.
TimePerTest(1) << endl;
669 vector<string> &varNames)
677 vector<int> recvVarsToVars =
680 for (
int i = 0; i < recvVarsToVars.size(); ++i)
682 recvFields[i] =
field[recvVarsToVars[i]];
713 1, recvFields[i], 1);
732 m_evalField->GetSession()->DefinesCmdLineArgument(
"verbose"))
734 cout <<
"waiting for receive at i = " << step <<
", t = " << time
755 int nNotLoc = cwipi_get_n_not_located_points(
m_couplingName.c_str());
759 cout <<
"WARNING: relocating " << nNotLoc <<
" of " <<
m_nPoints
760 <<
" points" << endl;
765 for (
int i = 0; i < nNotLoc; ++i)
767 notLoc[i] = tmp[i] - 1;
770 if (boost::to_upper_copy(
m_config[
"NOTLOCMETHOD"]) ==
"KEEP")
781 for (
int i = 0, locPos = 0, intPos = 0; i <
m_nPoints; ++i)
783 if (locPos < nNotLoc && notLoc[locPos] == i)
798 if (boost::to_upper_copy(
m_config[
"NOTLOCMETHOD"]) ==
"EXTRAPOLATE")
800 int doExtrapolate = 0;
807 if (doExtrapolate > 0)
847 varcoeffs[varcoefftypes[j]] = Velocity[j];
858 m_recvField->LinearAdvectionDiffusionReactionSolve(
859 forcing, tmpC,
factors, varcoeffs, varfactors);
884 m_evalField->GetSession()->DefinesCmdLineArgument(
"verbose"))
886 cout <<
"Receive total time: " << timer1.
TimePerTest(1) <<
", ";
887 cout <<
"Receive waiting time: " << timer2.
TimePerTest(1) << endl;
901 int nNotLoc = notLoc.size();
902 int nranks =
m_evalField->GetSession()->GetComm()->GetSize();
906 m_evalField->GetSession()->GetComm()->AllGather(thisNLoc, sizeMap);
910 for (
int i = 1; i < nranks; ++i)
912 offsetMap[i] = offsetMap[i - 1] + sizeMap[i - 1];
914 int totNLoc = offsetMap[nranks - 1] + sizeMap[nranks - 1];
917 for (
int i = 0; i < 3; ++i)
921 m_recvField->GetCoords(allVals[0], allVals[1], allVals[2]);
934 allVals[3 + i] = rVals[i];
938 for (
int i = 0; i < totvars; ++i)
944 int offset = offsetMap[
m_evalField->GetSession()->GetComm()->GetRank()];
945 for (
int i = 0, intPos = 0, locPos = 0; i <
m_nPoints; ++i)
947 if (locPos < nNotLoc && notLoc[locPos] == i)
954 for (
int k = 0; k < totvars; ++k)
956 locatedVals[k][offset + intPos] = allVals[k][i];
964 for (
int i = 0; i < totvars; ++i)
966 m_evalField->GetSession()->GetComm()->AllGatherv(locatedVals[i],
978 for (
int j = 0; j < totvars; ++j)
981 for (
int i = 0; i < nNotLoc; ++i)
983 notLocVals[j][i] = allVals[j][notLoc[i]];
995 std::vector<MultiRegions::ExpListSharedPtr>>>::
1002 for (
int j = 3; j < totvars; ++j)
1004 for (
int i = 0; i < nNotLoc; ++i)
1006 allVals[j][notLoc[i]] = notLocVals[j][i];
1013 m_evalField->GetSession()->DefinesCmdLineArgument(
"verbose"))
1015 cout <<
"ExtrapolateFields total time: " << timer1.
TimePerTest(1);
1016 cout <<
" (AllGathervI: " << timer2.
TimePerTest(1) <<
")" << endl;
1026#if (defined _WIN32 && _MSC_VER < 1900)
1029 unsigned int old_exponent_format;
1030 old_exponent_format = _set_output_format(_TWO_DIGIT_EXPONENT);
1032 _set_output_format(old_exponent_format);
1034 std::string filename =
1039 for (
int i = 0; i < 3; ++i)
1054 csvIO.
Write(filename, rvPts);
1058 m_evalField->GetSession()->DefinesCmdLineArgument(
"verbose"))
1060 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....
A class that contains algorithms for interpolation between pts fields, expansions and different meshe...
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.
General purpose memory allocation routines with the ability to allocate from thread specific memory p...
static std::shared_ptr< DataType > AllocateSharedPtr(const Args &...args)
Allocate a shared pointer from the memory pool.
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::string className
Array< OneD, Array< OneD, NekDouble > > m_oldFields
SOLVER_UTILS_EXPORT void v_Receive(const int step, const NekDouble time, Array< OneD, Array< OneD, NekDouble > > &field, std::vector< std::string > &varNames) override
void AddElementsToMesh(T geom, int &coordsPos, int &connecPos, int &conidxPos)
Array< OneD, Array< OneD, NekDouble > > m_sendField
SOLVER_UTILS_EXPORT CouplingCwipi(MultiRegions::ExpListSharedPtr field)
SOLVER_UTILS_EXPORT void v_Init() override
void ExtrapolateFields(Array< OneD, Array< OneD, NekDouble > > &rVals, Array< OneD, int > ¬Loc)
std::shared_ptr< FieldUtils::Interpolator< std::vector< MultiRegions::ExpListSharedPtr > > > m_sendInterpolator
void EvaluateFields(Array< OneD, Array< OneD, NekDouble > > interpField, Array< OneD, Array< OneD, NekDouble > > distCoords)
SOLVER_UTILS_EXPORT void v_Finalize() override
SOLVER_UTILS_EXPORT ~CouplingCwipi() override
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 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 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::shared_ptr< FieldUtils::Interpolator< std::vector< MultiRegions::ExpListSharedPtr > > > m_extrapInterpolator
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, SpatialDomains::MeshGraphSharedPtr partitionedGraph=nullptr)
std::shared_ptr< SessionReader > SessionReaderSharedPtr
std::shared_ptr< PtsField > PtsFieldSharedPtr
static VarFactorsMap NullVarFactorsMap
std::shared_ptr< ExpList > ExpListSharedPtr
Shared pointer to an ExpList object.
std::map< StdRegions::ConstFactorType, Array< OneD, NekDouble > > VarFactorsMap
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
std::map< ConstFactorType, NekDouble > ConstFactorMap
std::map< StdRegions::VarCoeffType, VarCoeffEntry > VarCoeffMap
StdRegions::ConstFactorMap factors
void Svtsvtp(int n, const T alpha, const T *x, int incx, const T beta, const T *y, int incy, T *z, int incz)
Svtsvtp (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)