31 #include <vtkDoubleArray.h> 32 #include <vtkPointData.h> 33 #include <vtkPolyData.h> 42 COM_EXTERN_MODULE(SurfX)
43 COM_EXTERN_MODULE(SimOut)
52 const std::vector<int> &arrayIds,
53 const std::vector<std::string> &newnames) {
59 MPI_Comm comm = MPI_COMM_WORLD;
61 COM_LOAD_MODULE_STATIC_DYNAMIC(SurfX,
"RFC");
63 RFC_clear = COM_get_function_handle(
"RFC.clear_overlay");
64 RFC_read = COM_get_function_handle(
"RFC.read_overlay");
65 RFC_write = COM_get_function_handle(
"RFC.write_overlay");
66 RFC_overlay = COM_get_function_handle(
"RFC.overlay");
67 RFC_transfer = COM_get_function_handle(
"RFC.least_squares_transfer");
68 RFC_interp = COM_get_function_handle(
"RFC.interpolate");
73 std::vector<double> sourceCoords;
74 std::vector<int> sourceElems;
79 COM_new_window(
"sourceWindow");
82 COM_set_size(
"sourceWindow.nc", 1, sourceCoords.size() / 3);
83 COM_set_array(
"sourceWindow.nc", 1, &sourceCoords[0], 3);
85 COM_set_size(
"sourceWindow.:t3:", 1, sourceElems.size() / 3);
86 COM_set_array(
"sourceWindow.:t3:", 1, &sourceElems[0], 3);
89 COM_new_dataitem(
"sourceWindow.soln",
'n', COM_DOUBLE, 1,
"");
91 COM_window_init_done(
"sourceWindow");
95 std::vector<double> targetCoords;
96 std::vector<int> targetElems;
99 COM_new_window(
"targetWindow");
101 COM_set_size(
"targetWindow.nc", 1, targetCoords.size() / 3);
102 COM_set_array(
"targetWindow.nc", 1, &targetCoords[0], 3);
104 COM_set_size(
"targetWindow.:t3:", 1, targetElems.size() / 3);
105 COM_set_array(
"targetWindow.:t3:", 1, &targetElems[0], 3);
108 std::vector<double> targetData(targetCoords.size(), -1.);
109 COM_new_dataitem(
"targetWindow.soln",
'n', COM_DOUBLE, 1,
"m/s");
110 COM_resize_array(
"targetWindow.soln");
112 COM_window_init_done(
"targetWindow");
115 int srcMesh = COM_get_dataitem_handle(
"sourceWindow.mesh");
116 int tgtMesh = COM_get_dataitem_handle(
"targetWindow.mesh");
117 COM_call_function(
RFC_overlay, &srcMesh, &tgtMesh);
121 int srcData = COM_get_dataitem_handle(
"sourceWindow.soln");
122 int tgtData = COM_get_dataitem_handle(
"targetWindow.soln");
125 std::vector<double> sourceData(sourceCoords.size());
127 for (
const int &arrayId : arrayIds) {
128 vtkSmartPointer<vtkDataArray> sourceArray =
129 sourceDataSet->GetPointData()->GetArray(arrayId);
132 targetPointValues->SetName(sourceArray->GetName());
133 targetPointValues->SetNumberOfComponents(
134 sourceArray->GetNumberOfComponents());
136 for (
int componentId = 0;
137 componentId < sourceArray->GetNumberOfComponents(); ++componentId) {
138 auto sourcePointValues = vtkDoubleArray::SafeDownCast(
139 sourceDataSet->GetPointData()->GetArray(arrayId));
141 for (
int srcNodeId = 0; srcNodeId < sourceCoords.size() / 3;
143 sourceData[srcNodeId] =
144 sourcePointValues->GetComponent(srcNodeId, componentId);
147 COM_set_array(
"sourceWindow.soln", 1, &sourceData[0]);
156 COM_get_array(
"targetWindow.soln", 1, &addr);
157 data = (
double *)addr;
159 for (
int trgNodeId = 0; trgNodeId < targetCoords.size() / 3;
161 targetPointValues->InsertComponent(trgNodeId, componentId,
166 targetDataSet->GetPointData()->AddArray(targetPointValues);
178 COM_init(NULL, NULL);
179 COM_set_profiling(1);
182 MPI_Comm comm = MPI_COMM_WORLD;
184 COM_LOAD_MODULE_STATIC_DYNAMIC(SurfX,
"RFC");
186 RFC_write = COM_get_function_handle(
"RFC.write_overlay");
187 RFC_overlay = COM_get_function_handle(
"RFC.overlay");
192 std::vector<double> sourceCoords;
193 std::vector<int> sourceElems;
197 COM_new_window(
"sourceWindow");
200 COM_set_size(
"sourceWindow.nc", 1, sourceCoords.size() / 3);
201 COM_set_array(
"sourceWindow.nc", 1, &sourceCoords[0], 3);
203 COM_set_size(
"sourceWindow.:t3:", 1, sourceElems.size() / 3);
204 COM_set_array(
"sourceWindow.:t3:", 1, &sourceElems[0], 3);
207 COM_new_dataitem(
"sourceWindow.soln",
'n', COM_DOUBLE, 1,
"");
209 COM_window_init_done(
"sourceWindow");
212 std::vector<double> targetCoords;
213 std::vector<int> targetElems;
216 COM_new_window(
"targetWindow");
218 COM_set_size(
"targetWindow.nc", 1, targetCoords.size() / 3);
219 COM_set_array(
"targetWindow.nc", 1, &targetCoords[0], 3);
221 COM_set_size(
"targetWindow.:t3:", 1, targetElems.size() / 3);
222 COM_set_array(
"targetWindow.:t3:", 1, &targetElems[0], 3);
225 std::vector<double> targetData(targetCoords.size(), -1.);
226 COM_new_dataitem(
"targetWindow.soln",
'n', COM_DOUBLE, 1,
"m/s");
227 COM_resize_array(
"targetWindow.soln");
229 COM_window_init_done(
"targetWindow");
231 int srcMesh = COM_get_dataitem_handle(
"sourceWindow.mesh");
232 int tgtMesh = COM_get_dataitem_handle(
"targetWindow.mesh");
233 COM_call_function(
RFC_overlay, &srcMesh, &tgtMesh);
235 COM_call_function(
RFC_write, &srcMesh, &tgtMesh,
"srcMesh",
"tgtMesh",
"CGNS");
243 vtkDataSet *
data, std::vector<double> &coords, std::vector<int> &
elems) {
244 for (
int ptId = 0; ptId < data->GetNumberOfPoints(); ++ptId) {
247 data->GetPoint(ptId, x);
249 coords.push_back(x[0]);
250 coords.push_back(x[1]);
251 coords.push_back(x[2]);
254 for (
int cellId = 0; cellId < data->GetNumberOfCells(); ++cellId) {
255 if (data->GetCellType(cellId) != VTK_TRIANGLE)
258 vtkCell *cell = data->GetCell(cellId);
260 elems.push_back(cell->GetPointId(0) + 1);
261 elems.push_back(cell->GetPointId(1) + 1);
262 elems.push_back(cell->GetPointId(2) + 1);
data_type data
Edge/face with sorted point ids (a, b, c, ...) is located at some index i in data[b], with data[b][i].first == [a, c] (for edges, third point id treated as -1).
A brief description of meshBase.
geoMeshBase * New(MeshType meshType)
Create a new mesh object.
void extractDataFromVTK(vtkDataSet *data, std::vector< double > &coords, std::vector< int > &elems)
vtkSmartPointer< vtkDataSet > getDataSet() const
get this meshes' dataSet
std::map< std::string, std::vector< Elem > > elems
If the ELEMENT keyword line contains ELSET=name, then the element is stored in elems[name], otherwise, stored in elems[std::string{}].
int transferPointData(const std::vector< int > &arrayIDs=std::vector< int >(), const std::vector< std::string > &newnames=std::vector< std::string >())
Transfer point data with given ids from source to target.