ParallelCellsGenerator.hpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036 #ifndef PARALLELCELLSGENERATOR_HPP_
00037 #define PARALLELCELLSGENERATOR_HPP_
00038
00039 #include <vector>
00040 #include "Cell.hpp"
00041 #include "WildTypeCellMutationState.hpp"
00042 #include "AbstractCellProperty.hpp"
00043 #include "NodesOnlyMesh.hpp"
00044
00049 template<class CELL_CYCLE_MODEL, unsigned DIM>
00050 class ParallelCellsGenerator
00051 {
00052 friend class TestParallelCellsGenerator;
00053
00054 private:
00055
00062 c_vector<double, 2*DIM> GetArchiveBoundingBox(std::string archivePath);
00063
00064 public:
00065
00073 void GenerateParallelCells( std::string archivePath,
00074 std::vector<CellPtr>& cells,
00075 NodesOnlyMesh<DIM>& mesh,
00076 boost::shared_ptr<AbstractCellProperty> pCellProliferativeType=boost::shared_ptr<AbstractCellProperty>());
00077
00078 };
00079
00080
00081 template<class CELL_CYCLE_MODEL, unsigned DIM>
00082 void ParallelCellsGenerator<CELL_CYCLE_MODEL, DIM>::GenerateParallelCells(std::string archivePath, std::vector<CellPtr>& cells, NodesOnlyMesh<DIM>& mesh, boost::shared_ptr<AbstractCellProperty> pCellProliferativeType)
00083 {
00084
00085 c_vector<double, 2*DIM> base_bounding_box = GetArchiveBoundingBox(archivePath);
00086
00087
00088 for (unsigned i=0; i<DIM; i++)
00089 {
00090 base_bounding_box[2*i] -= 1e-14;
00091 base_bounding_box[2*i + 1] += 1e-14;
00092 }
00093
00094
00095 mesh.SetInitialBoxCollection(base_bounding_box, mesh.GetMaximumInteractionDistance());
00096
00097 unsigned node_index = 0;
00098
00099 std::ifstream infile(archivePath.c_str(), std::ios::in);
00100
00101 std::string line;
00102 std::getline(infile, line);
00103
00104 while (std::getline(infile, line))
00105 {
00106
00107 std::istringstream iss(line);
00108
00109
00110 c_vector<double, DIM> location;
00111 for (unsigned k=0; k<DIM; k++)
00112 {
00113 iss >> location[k];
00114 }
00115
00116
00117 if (mesh.IsOwned(location))
00118 {
00119
00120 Node<DIM>* p_node = new Node<DIM>(node_index, location);
00121 mesh.AddNode(p_node);
00122
00123
00124 CELL_CYCLE_MODEL* p_cell_cycle_model = new CELL_CYCLE_MODEL;
00125 p_cell_cycle_model->SetDimension(DIM);
00126
00127
00128 boost::shared_ptr<AbstractCellProperty> p_state(CellPropertyRegistry::Instance()->Get<WildTypeCellMutationState>());
00129 CellPtr p_cell(new Cell(p_state, p_cell_cycle_model));
00130 p_cell->SetCellProliferativeType(pCellProliferativeType);
00131 cells.push_back(p_cell);
00132
00133 node_index++;
00134 }
00135 }
00136
00137 infile.close();
00138
00139
00140 NodeMap map(mesh.GetMaximumNodeIndex()+1);
00141 mesh.ReMesh(map);
00142 }
00143
00144 template<class CELL_CYCLE_MODEL, unsigned DIM>
00145 c_vector<double, 2*DIM> ParallelCellsGenerator<CELL_CYCLE_MODEL, DIM>::GetArchiveBoundingBox(std::string archivePath)
00146 {
00147 c_vector<double, 2*DIM> bounding_box;
00148 for (unsigned i=0; i<DIM; i++)
00149 {
00150 bounding_box[2*i] = DBL_MAX;
00151 bounding_box[2*i + 1] = -DBL_MAX;
00152 }
00153
00154 std::ifstream infile(archivePath.c_str());
00155
00156 std::string line;
00157 std::getline(infile, line);
00158
00159 std::istringstream iss(line);
00160
00161
00162 unsigned num_lines;
00163 unsigned file_dimension;
00164
00165 iss >> num_lines >> file_dimension;
00166
00167 if (file_dimension != DIM)
00168 {
00169 EXCEPTION("Space dimension of ParallelCellsGenerator and archive file do not match");
00170 }
00171
00172 while (std::getline(infile, line))
00173 {
00174 std::stringstream new_iss(line);
00175 for (unsigned i=0; i<DIM; i++)
00176 {
00177 double point;
00178 new_iss >> point;
00179 bounding_box[2*i] = (point < bounding_box[2*i]) ? point : bounding_box[2*i];
00180 bounding_box[2*i+1] = (point > bounding_box[2*i+1]) ? point : bounding_box[2*i+1];
00181 }
00182 }
00183
00184 infile.close();
00185
00186 return bounding_box;
00187 }
00188 #endif