36 #define _BACKWARD_BACKWARD_WARNING_H 1 //Cut out the vtk deprecated warning for now (gcc4.3) 37 #include <vtkDoubleArray.h> 38 #include <vtkPointData.h> 39 #include <vtkPolyData.h> 40 #include <vtkProbeFilter.h> 41 #include <vtkImageData.h> 42 #include <vtkSmartPointer.h> 43 #include "AbstractUnstructuredGridDiscreteContinuumSolver.hpp" 45 template<
unsigned DIM>
54 template<
unsigned DIM>
60 template<
unsigned DIM>
65 EXCEPTION(
"A mesh has not been set.");
70 template<
unsigned DIM>
78 std::vector<c_vector<double, DIM> > centroids =
mpMesh->GetElementCentroids();
79 std::vector<units::quantity<unit::concentration> > sampled_solution(centroids.size(), 0.0*this->
mReferenceConcentration);
82 vtkSmartPointer<vtkPolyData> p_polydata = vtkSmartPointer<vtkPolyData>::New();
83 vtkSmartPointer<vtkPoints> p_points = vtkSmartPointer<vtkPoints>::New();
84 p_points->SetNumberOfPoints(centroids.size());
85 for(
unsigned idx=0; idx< centroids.size(); idx++)
89 p_points->SetPoint(idx, centroids[idx][0], centroids[idx][1], centroids[idx][2]);
93 p_points->SetPoint(idx, centroids[idx][0], centroids[idx][1], 0.0);
96 p_polydata->SetPoints(p_points);
98 vtkSmartPointer<vtkProbeFilter> p_probe_filter = vtkSmartPointer<vtkProbeFilter>::New();
99 #if VTK_MAJOR_VERSION <= 5 100 p_probe_filter->SetInput(p_polydata);
103 p_probe_filter->SetInputData(p_polydata);
106 p_probe_filter->Update();
107 vtkSmartPointer<vtkPointData> p_point_data = p_probe_filter->GetOutput()->GetPointData();
109 unsigned num_points = p_point_data->GetArray(this->
mLabel.c_str())->GetNumberOfTuples();
110 for(
unsigned idx=0; idx<num_points; idx++)
114 return sampled_solution;
117 template<
unsigned DIM>
125 std::vector<units::quantity<unit::concentration> > sampled_solution(samplePoints.size(), 0.0*this->
mReferenceConcentration);
128 vtkSmartPointer<vtkPolyData> p_polydata = vtkSmartPointer<vtkPolyData>::New();
129 vtkSmartPointer<vtkPoints> p_points = vtkSmartPointer<vtkPoints>::New();
131 p_points->SetNumberOfPoints(samplePoints.size());
132 for(
unsigned idx=0; idx< samplePoints.size(); idx++)
134 c_vector<double, DIM> location = samplePoints[idx].GetLocation(this->
mpMesh->GetReferenceLengthScale());
137 p_points->SetPoint(idx, location[0], location[1], location[2]);
141 p_points->SetPoint(idx, location[0], location[1], 0.0);
144 p_polydata->SetPoints(p_points);
146 vtkSmartPointer<vtkProbeFilter> p_probe_filter = vtkSmartPointer<vtkProbeFilter>::New();
147 #if VTK_MAJOR_VERSION <= 5 148 p_probe_filter->SetInput(p_polydata);
151 p_probe_filter->SetInputData(p_polydata);
154 p_probe_filter->Update();
155 vtkSmartPointer<vtkPointData> p_point_data = p_probe_filter->GetOutput()->GetPointData();
157 unsigned num_points = p_point_data->GetArray(this->
mLabel.c_str())->GetNumberOfTuples();
158 for(
unsigned idx=0; idx<num_points; idx++)
162 return sampled_solution;
165 template<
unsigned DIM>
171 template<
unsigned DIM>
184 template<
unsigned DIM>
192 std::vector<double> sampled_solution(rSamplePoints.size(), 0.0);
195 vtkSmartPointer<vtkPolyData> p_polydata = vtkSmartPointer<vtkPolyData>::New();
196 vtkSmartPointer<vtkPoints> p_points = vtkSmartPointer<vtkPoints>::New();
197 p_points->SetNumberOfPoints(rSamplePoints.size());
198 for(
unsigned idx=0; idx< rSamplePoints.size(); idx++)
200 c_vector<double, DIM> location = rSamplePoints[idx].GetLocation(this->
mpMesh->GetReferenceLengthScale());
203 p_points->SetPoint(idx, location[0], location[1], location[2]);
207 p_points->SetPoint(idx, location[0], location[1], 0.0);
210 p_polydata->SetPoints(p_points);
212 vtkSmartPointer<vtkProbeFilter> p_probe_filter = vtkSmartPointer<vtkProbeFilter>::New();
213 #if VTK_MAJOR_VERSION <= 5 214 p_probe_filter->SetInput(p_polydata);
217 p_probe_filter->SetInputData(p_polydata);
220 p_probe_filter->Update();
221 vtkSmartPointer<vtkPointData> p_point_data = p_probe_filter->GetOutput()->GetPointData();
223 unsigned num_points = p_point_data->GetArray(this->
mLabel.c_str())->GetNumberOfTuples();
224 for(
unsigned idx=0; idx<num_points; idx++)
226 sampled_solution[idx] = p_point_data->GetArray(this->
mLabel.c_str())->GetTuple1(idx);
228 return sampled_solution;
231 template<
unsigned DIM>
237 template<
unsigned DIM>
246 return this->
GetSolution(pMesh->GetNodeLocationsAsPoints());
250 template<
unsigned DIM>
260 template<
unsigned DIM>
266 template<
unsigned DIM>
271 EXCEPTION(
"Mesh needed before Setup can be called.");
277 unsigned num_nodes = this->
mpMesh->GetNodeLocationsAsPoints().size();
278 this->
mSolution = std::vector<double>(0.0, num_nodes);
286 template<
unsigned DIM>
294 vtkSmartPointer<vtkDoubleArray> pPointData = vtkSmartPointer<vtkDoubleArray>::New();
295 pPointData->SetNumberOfComponents(1);
296 pPointData->SetNumberOfTuples(data.size());
297 pPointData->SetName(this->
GetLabel().c_str());
298 for (
unsigned i = 0; i < data.size(); i++)
300 pPointData->SetValue(i, data[i]);
305 this->
mSolution = std::vector<double>(data.size(), 0.0);
306 for (
unsigned i = 0; i < data.size(); i++)
312 template<
unsigned DIM>
320 vtkSmartPointer<vtkDoubleArray> pPointData = vtkSmartPointer<vtkDoubleArray>::New();
321 pPointData->SetNumberOfComponents(1);
322 pPointData->SetNumberOfTuples(data.size());
323 pPointData->SetName(this->
GetLabel().c_str());
324 for (
unsigned i = 0; i < data.size(); i++)
326 pPointData->SetValue(i, data[i]);
331 template<
unsigned DIM>
339 vtkSmartPointer<vtkDoubleArray> pPointData = vtkSmartPointer<vtkDoubleArray>::New();
340 pPointData->SetNumberOfComponents(1);
341 pPointData->SetNumberOfTuples(data.size());
342 pPointData->SetName(this->
GetLabel().c_str());
343 for (
unsigned i = 0; i < data.size(); i++)
351 for (
unsigned i = 0; i < data.size(); i++)
357 template<
unsigned DIM>
367 EXCEPTION(
"The DiscreteContinuum solver needs a cell population for this operation.");
382 template<
unsigned DIM>
388 template<
unsigned DIM>
398 EXCEPTION(
"An output file handler has not been set for the DiscreteContinuum solver.");
401 if(PetscTools::AmMaster())
403 vtkSmartPointer<vtkXMLUnstructuredGridWriter> p_writer1 = vtkSmartPointer<vtkXMLUnstructuredGridWriter>::New();
410 p_writer1->SetFileName((this->
mpOutputFileHandler->GetOutputDirectoryFullPath() +
"/solution.vtu").c_str());
412 #if VTK_MAJOR_VERSION <= 5 virtual ~AbstractUnstructuredGridDiscreteContinuumSolver()
virtual std::vector< units::quantity< unit::concentration > > GetConcentrations()
void SetMesh(boost::shared_ptr< DiscreteContinuumMesh< DIM, DIM > > pMesh)
virtual std::vector< units::quantity< unit::concentration > > GetConcentrationsAtCentroids()
virtual void UpdateCellData()
bool mHasUnstructuredGrid
AbstractUnstructuredGridDiscreteContinuumSolver()
boost::shared_ptr< OutputFileHandler > mpOutputFileHandler
virtual vtkSmartPointer< vtkUnstructuredGrid > GetVtkSolution()
std::vector< units::quantity< unit::concentration > > mConcentrations
virtual void UpdateSolution(const std::vector< double > &rData)
virtual std::vector< double > GetSolution()
boost::shared_ptr< DiscreteContinuumMesh< DIM > > GetMesh()
const std::string & GetLabel()
boost::shared_ptr< VesselNetwork< DIM > > mpNetwork
bool CellPopulationIsSet()
units::quantity< unit::concentration > mReferenceConcentration
boost::shared_ptr< DiscreteContinuumMesh< DIM, DIM > > mpMesh
std::vector< double > mSolution
virtual void UpdateElementSolution(const std::vector< double > &rData)
vtkSmartPointer< vtkUnstructuredGrid > mpVtkSolution