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 "RegularGridWriter.hpp" 45 #include "AbstractRegularGridDiscreteContinuumSolver.hpp" 47 template<
unsigned DIM>
56 template<
unsigned DIM>
62 template<
unsigned DIM>
67 EXCEPTION(
"A regular grid has not been set.");
72 template<
unsigned DIM>
80 std::vector<units::quantity<unit::concentration> > sampled_solution(samplePoints.size(), 0.0*this->
mReferenceConcentration);
83 vtkSmartPointer<vtkPolyData> p_polydata = vtkSmartPointer<vtkPolyData>::New();
84 vtkSmartPointer<vtkPoints> p_points = vtkSmartPointer<vtkPoints>::New();
85 p_points->SetNumberOfPoints(samplePoints.size());
86 for(
unsigned idx=0; idx< samplePoints.size(); idx++)
88 c_vector<double, DIM> location = samplePoints[idx].GetLocation(this->
mpRegularGrid->GetReferenceLengthScale());
91 p_points->SetPoint(idx, location[0], location[1], location[2]);
95 p_points->SetPoint(idx, location[0], location[1], 0.0);
98 p_polydata->SetPoints(p_points);
100 vtkSmartPointer<vtkProbeFilter> p_probe_filter = vtkSmartPointer<vtkProbeFilter>::New();
101 #if VTK_MAJOR_VERSION <= 5 102 p_probe_filter->SetInput(p_polydata);
105 p_probe_filter->SetInputData(p_polydata);
108 p_probe_filter->Update();
109 vtkSmartPointer<vtkPointData> p_point_data = p_probe_filter->GetOutput()->GetPointData();
111 unsigned num_points = p_point_data->GetArray(this->
mLabel.c_str())->GetNumberOfTuples();
112 for(
unsigned idx=0; idx<num_points; idx++)
116 return sampled_solution;
119 template<
unsigned DIM>
132 template<
unsigned DIM>
138 template<
unsigned DIM>
146 std::vector<double> sampled_solution(rSamplePoints.size(), 0.0);
149 vtkSmartPointer<vtkPolyData> p_polydata = vtkSmartPointer<vtkPolyData>::New();
150 vtkSmartPointer<vtkPoints> p_points = vtkSmartPointer<vtkPoints>::New();
151 p_points->SetNumberOfPoints(rSamplePoints.size());
152 for(
unsigned idx=0; idx< rSamplePoints.size(); idx++)
154 c_vector<double, DIM> location = rSamplePoints[idx].GetLocation(this->
mpRegularGrid->GetReferenceLengthScale());
157 p_points->SetPoint(idx, location[0], location[1], location[2]);
161 p_points->SetPoint(idx, location[0], location[1], 0.0);
164 p_polydata->SetPoints(p_points);
166 vtkSmartPointer<vtkProbeFilter> p_probe_filter = vtkSmartPointer<vtkProbeFilter>::New();
167 #if VTK_MAJOR_VERSION <= 5 168 p_probe_filter->SetInput(p_polydata);
171 p_probe_filter->SetInputData(p_polydata);
174 p_probe_filter->Update();
175 vtkSmartPointer<vtkPointData> p_point_data = p_probe_filter->GetOutput()->GetPointData();
177 unsigned num_points = p_point_data->GetArray(this->
mLabel.c_str())->GetNumberOfTuples();
178 for(
unsigned idx=0; idx<num_points; idx++)
180 sampled_solution[idx] = p_point_data->GetArray(this->
mLabel.c_str())->GetTuple1(idx);
182 return sampled_solution;
185 template<
unsigned DIM>
198 template<
unsigned DIM>
201 return this->
GetSolution(pMesh->GetNodeLocationsAsPoints());
204 template<
unsigned DIM>
214 template<
unsigned DIM>
220 template<
unsigned DIM>
225 EXCEPTION(
"Regular grid DiscreteContinuum solvers need a grid before Setup can be called.");
246 this->
mpVtkSolution->SetOrigin(origin[0], origin[1], origin[2]);
256 template<
unsigned DIM>
264 vtkSmartPointer<vtkDoubleArray> pPointData = vtkSmartPointer<vtkDoubleArray>::New();
265 pPointData->SetNumberOfComponents(1);
266 pPointData->SetNumberOfTuples(data.size());
267 pPointData->SetName(this->
GetLabel().c_str());
268 for (
unsigned i = 0; i < data.size(); i++)
270 pPointData->SetValue(i, data[i]);
275 this->
mSolution = std::vector<double>(data.size(), 0.0);
276 for (
unsigned i = 0; i < data.size(); i++)
282 for (
unsigned i = 0; i < data.size(); i++)
288 template<
unsigned DIM>
296 vtkSmartPointer<vtkDoubleArray> pPointData = vtkSmartPointer<vtkDoubleArray>::New();
297 pPointData->SetNumberOfComponents(1);
298 pPointData->SetNumberOfTuples(data.size());
299 pPointData->SetName((this->
GetLabel()).c_str());
300 for (
unsigned i = 0; i < data.size(); i++)
308 for (
unsigned i = 0; i < data.size(); i++)
314 template<
unsigned DIM>
324 EXCEPTION(
"The DiscreteContinuum solver needs a cell population for this operation.");
328 std::vector<std::vector<CellPtr> > point_cell_map = this->
mpRegularGrid->GetPointCellMap();
329 for(
unsigned idx=0; idx<point_cell_map.size(); idx++)
331 for(
unsigned jdx=0; jdx<point_cell_map[idx].size(); jdx++)
338 template<
unsigned DIM>
344 template<
unsigned DIM>
354 EXCEPTION(
"An output file handler has not been set for the DiscreteContinuum solver.");
virtual vtkSmartPointer< vtkImageData > GetVtkSolution()
virtual std::vector< units::quantity< unit::concentration > > GetConcentrations()
virtual ~AbstractRegularGridDiscreteContinuumSolver()
void SetFilename(const std::string &rFilename)
boost::shared_ptr< RegularGrid< DIM > > mpRegularGrid
boost::shared_ptr< OutputFileHandler > mpOutputFileHandler
AbstractCellPopulation< DIM > * mpCellPopulation
boost::shared_ptr< RegularGrid< DIM > > GetGrid()
std::vector< units::quantity< unit::concentration > > mConcentrations
virtual std::vector< double > GetSolution()
AbstractRegularGridDiscreteContinuumSolver()
vtkSmartPointer< vtkImageData > mpVtkSolution
virtual void UpdateCellData()
const std::string & GetLabel()
virtual void UpdateSolution(std::vector< double > &rData)
bool CellPopulationIsSet()
units::quantity< unit::concentration > mReferenceConcentration
std::vector< double > mSolution
void SetImage(vtkSmartPointer< vtkImageData > pImage)
units::quantity< unit::concentration > mCellPopulationReferenceConcentration
void SetGrid(boost::shared_ptr< RegularGrid< DIM > > pRegularGrid)
units::quantity< unit::length > mCellPopulationReferenceLength