NEMoSys  0.63.0
A modular, extensible resource with robust automated mesh generation, mesh quality analysis, adaptive mesh refinement, and data transfer between arbitrary meshes.
srvBase.C
Go to the documentation of this file.
1 /*******************************************************************************
2 * Promesh *
3 * Copyright (C) 2022, IllinoisRocstar LLC. All rights reserved. *
4 * *
5 * Promesh is the property of IllinoisRocstar LLC. *
6 * *
7 * IllinoisRocstar LLC *
8 * Champaign, IL *
9 * www.illinoisrocstar.com *
10 * promesh@illinoisrocstar.com *
11 *******************************************************************************/
12 /*******************************************************************************
13 * This file is part of Promesh *
14 * *
15 * This version of Promesh is free software: you can redistribute it and/or *
16 * modify it under the terms of the GNU Lesser General Public License as *
17 * published by the Free Software Foundation, either version 3 of the License, *
18 * or (at your option) any later version. *
19 * *
20 * Promesh is distributed in the hope that it will be useful, but WITHOUT ANY *
21 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS *
22 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more *
23 * details. *
24 * *
25 * You should have received a copy of the GNU Lesser General Public License *
26 * along with this program. If not, see <https://www.gnu.org/licenses/>. *
27 * *
28 *******************************************************************************/
29 #include "Services/srvBase.H"
30 
31 #include <vtkInformationExecutivePortKey.h>
32 #include <vtkInformation.h>
33 #include <vtkInformationVector.h>
34 #include <vtkStreamingDemandDrivenPipeline.h>
35 
36 #include "Mesh/vtkGeoMesh.H"
37 #include "Mesh/oshGeoMesh.H"
38 #include "Mesh/exoGeoMesh.H"
39 #include "Mesh/inpGeoMesh.H"
40 
41 #ifdef HAVE_CFMSH
42 # include "Mesh/foamGeoMesh.H"
43 #endif
44 
45 #ifdef HAVE_GMSH
46 # include "Mesh/gmshGeoMesh.H"
47 #endif
48 
49 #ifdef HAVE_OCC
50 # include "Mesh/smeshGeoMesh.H"
51 #endif
52 
53 /* TODO:
54  * nemInformation
55  * https://gitlab.kitware.com/vtk/vtk/-/blob/master/Common/ExecutionModel/vtkAlgorithm.cxx
56  * RequestData
57  * https://gitlab.kitware.com/vtk/vtk/-/blob/master/Filters/Geometry/vtkGeometryFilter.cxx#L131-140
58  * https://vtk.org/doc/nightly/html/classvtkAlgorithm.html
59  */
60 
61 namespace NEM {
62 namespace SRV {
63 
65  std::cout << "srvBase constructed" << std::endl;
66 }
67 
69  std::cout << "srvBase destructed" << std::endl;
70 }
71 
72 int srvBase::ProcessRequest(vtkInformation *request,
73  vtkInformationVector **inputVector,
74  vtkInformationVector *outputVector) {
75  // Create an output object of the correct type.
76  if (request->Has(vtkDemandDrivenPipeline::REQUEST_DATA_OBJECT())) {
77  return this->RequestDataObject(request, inputVector, outputVector);
78  }
79 
80  // generate the data
81  if (request->Has(vtkDemandDrivenPipeline::REQUEST_DATA())) {
82  return this->RequestData(request, inputVector, outputVector);
83  }
84 
85  if (request->Has(vtkStreamingDemandDrivenPipeline::REQUEST_UPDATE_EXTENT())) {
86  return this->RequestUpdateExtent(request, inputVector, outputVector);
87  }
88 
89  // execute information
90  if (request->Has(vtkDemandDrivenPipeline::REQUEST_INFORMATION())) {
91  return this->RequestInformation(request, inputVector, outputVector);
92  }
93 
94  return this->Superclass::ProcessRequest(request, inputVector, outputVector);
95 }
96 
97 int srvBase::RequestInformation(vtkInformation *request,
98  vtkInformationVector **inputVector,
99  vtkInformationVector *outputVector) {
100  // do nothing let subclasses handle it
101  return 1;
102 }
103 
105 
107  return NEM::MSH::geoMeshBase::SafeDownCast(this->GetOutputDataObject(port));
108 }
109 
110 int srvBase::RequestDataObject(vtkInformation *request,
111  vtkInformationVector **inputVector,
112  vtkInformationVector *outputVector) {
113  for (int i = 0; i < outputVector->GetNumberOfInformationObjects(); ++i) {
114  auto outInfo = outputVector->GetInformationObject(i);
115  auto outAlgInfo = this->GetOutputPortInformation(i);
116  if (!outAlgInfo->Has(vtkDataObject::DATA_TYPE_NAME())) {
117  return 0;
118  }
119  std::string typeName = outAlgInfo->Get(vtkDataObject::DATA_TYPE_NAME());
120  MSH::geoMeshBase *output = nullptr;
121  if (typeName == "vtkGeoMesh") {
122  output = MSH::vtkGeoMesh::New();
123  } else if (typeName == "gmshGeoMesh") {
124 #ifdef HAVE_GMSH
125  output = MSH::gmshGeoMesh::New();
126 #endif
127  } else if (typeName == "oshGeoMesh") {
128  output = MSH::oshGeoMesh::New();
129  } else if (typeName == "exoGeoMesh") {
130  output = MSH::exoGeoMesh::New();
131  } else if (typeName == "inpGeoMesh") {
132  output = MSH::inpGeoMesh::New();
133  } else if (typeName == "foamGeoMesh") {
134 #ifdef HAVE_CFMSH
135  output = MSH::foamGeoMesh::New();
136 #endif
137  } else if (typeName == "smeshGeoMesh") {
138 #ifdef HAVE_OCC
139  output = MSH::smeshGeoMesh::New();
140 #endif
141  } else if (typeName == "geoMeshBase") {
142  if (i < this->GetNumberOfInputPorts() &&
143  inputVector[i]->GetNumberOfInformationObjects() > 0) {
144  auto inObj = inputVector[i]
145  ->GetInformationObject(0)
146  ->Get(vtkDataObject::DATA_OBJECT());
147  if (inObj) {
148  output = MSH::geoMeshBase::SafeDownCast(inObj->NewInstance());
149  }
150  }
151  }
152  if (!output) {
153  return 0;
154  }
155  outInfo->Set(vtkDataObject::DATA_OBJECT(), output);
156  output->FastDelete();
157  this->GetOutputPortInformation(i)->Set(
158  vtkDataObject::DATA_EXTENT_TYPE(), output->GetExtentType());
159  }
160  return 1;
161 }
162 
163 int srvBase::RequestUpdateExtent(vtkInformation *request,
164  vtkInformationVector **inputVector,
165  vtkInformationVector *outputVector) {
166  int numInputPorts = this->GetNumberOfInputPorts();
167  for (int i = 0; i < numInputPorts; i++) {
168  int numInputConnections = this->GetNumberOfInputConnections(i);
169  for (int j = 0; j < numInputConnections; j++) {
170  vtkInformation *inputInfo = inputVector[i]->GetInformationObject(j);
171  inputInfo->Set(vtkStreamingDemandDrivenPipeline::EXACT_EXTENT(), 1);
172  }
173  }
174  return 1;
175 }
176 
177 } // namespace SRV
178 } // namespace NEM
static smeshGeoMesh * New()
static inpGeoMesh * New()
static exoGeoMesh * New()
virtual int RequestDataObject(vtkInformation *request, vtkInformationVector **inputVector, vtkInformationVector *outputVector)
This is called by the superclass.
Definition: srvBase.C:110
~srvBase() override
Definition: srvBase.C:68
virtual int RequestInformation(vtkInformation *request, vtkInformationVector **inputVector, vtkInformationVector *outputVector)
Definition: srvBase.C:97
virtual int RequestData(vtkInformation *request, vtkInformationVector **inputVector, vtkInformationVector *outputVector)=0
This is called by the superclass.
static foamGeoMesh * New()
vtkAbstractTypeMacro(srvBase, vtkAlgorithm) public NEM::MSH::geoMeshBase * GetOutput()
Get the output GeoMeshBase for a port on this algorithm.
Definition: srvBase.C:104
static vtkGeoMesh * New()
virtual int RequestUpdateExtent(vtkInformation *request, vtkInformationVector **inputVector, vtkInformationVector *outputVector)
This is called by the superclass.
Definition: srvBase.C:163
abstract class to specify geometry and mesh data
Definition: geoMeshBase.H:102
static oshGeoMesh * New()
static gmshGeoMesh * New()