36 #include "HeartGeometryInformation.hpp"
41 #include "OutputFileHandler.hpp"
46 template<
unsigned SPACE_DIM>
49 template<
unsigned SPACE_DIM>
52 template<
unsigned SPACE_DIM>
54 const std::string& rEpiFile,
55 const std::string& rEndoFile,
71 template<
unsigned SPACE_DIM>
73 const std::string& rEpiFile,
74 const std::string& rLVFile,
75 const std::string& rRVFile,
93 EXCEPTION(
"At least one of left ventricle or right ventricle files is required");
108 template<
unsigned SPACE_DIM>
112 std::ifstream heterogeneity_file;
113 heterogeneity_file.open(nodeHeterogeneityFileName.c_str());
115 if (!(heterogeneity_file.is_open()))
117 heterogeneity_file.close();
118 EXCEPTION(
"Could not open heterogeneities file (" << nodeHeterogeneityFileName <<
")");
121 while(!heterogeneity_file.eof())
125 heterogeneity_file >> value;
128 if( (heterogeneity_file.fail() && !heterogeneity_file.eof()) || value < 0 || value > 2)
130 heterogeneity_file.close();
131 EXCEPTION(
"A value in the heterogeneities file (" << nodeHeterogeneityFileName
132 <<
") is out of range (or not an integer). It should be epi = 0, mid = 1, endo = 2");
135 if(!heterogeneity_file.eof())
139 mLayerForEachNode.push_back(EPI);
143 mLayerForEachNode.push_back(MID);
148 mLayerForEachNode.push_back(ENDO);
153 heterogeneity_file.close();
156 template<
unsigned SPACE_DIM>
158 const std::string& rLineFromFile,
159 std::set<unsigned>& rSurfaceNodeIndexSet,
160 unsigned offset)
const
162 std::stringstream line_stream(rLineFromFile);
163 while (!line_stream.eof())
168 if (item == 0 && offset != 0)
170 EXCEPTION(
"Error when reading surface file. It was assumed not to be indexed from zero, but zero appeared in the list.");
172 rSurfaceNodeIndexSet.insert(item-offset);
177 template<
unsigned SPACE_DIM>
179 const std::string& rSurfaceFileName,
180 std::vector<unsigned>& rSurfaceNodes,
181 bool indexFromZero)
const
184 std::ifstream file_stream;
186 if (indexFromZero ==
false)
191 file_stream.open(rSurfaceFileName.c_str());
192 if (!file_stream.is_open())
194 EXCEPTION(
"Wrong surface definition file name " + rSurfaceFileName);
198 std::set<unsigned> surface_original_node_index_set;
202 getline(file_stream, line);
205 ProcessLine(line, surface_original_node_index_set, offset);
207 getline(file_stream, line);
209 while(!file_stream.eof());
213 rSurfaceNodes.reserve(surface_original_node_index_set.size());
215 if (mpMesh->rGetNodePermutation().empty())
218 for(std::set<unsigned>::iterator node_index_it=surface_original_node_index_set.begin();
219 node_index_it != surface_original_node_index_set.end();
222 rSurfaceNodes.push_back(*node_index_it);
228 for(std::set<unsigned>::iterator node_index_it=surface_original_node_index_set.begin();
229 node_index_it != surface_original_node_index_set.end();
232 rSurfaceNodes.push_back(mpMesh->rGetNodePermutation()[*node_index_it]);
239 template<
unsigned SPACE_DIM>
243 if (mDistMapRightVentricle[nodeIndex] >= mDistMapEpicardium[nodeIndex] &&
244 mDistMapRightVentricle[nodeIndex] >= mDistMapLeftVentricle[nodeIndex])
246 return LEFT_VENTRICLE_WALL;
249 if (mDistMapLeftVentricle[nodeIndex] >= mDistMapEpicardium[nodeIndex] &&
250 mDistMapLeftVentricle[nodeIndex] >= mDistMapRightVentricle[nodeIndex])
252 return RIGHT_VENTRICLE_WALL;
255 if (mDistMapEpicardium[nodeIndex] >= mDistMapLeftVentricle[nodeIndex] &&
256 mDistMapEpicardium[nodeIndex] >= mDistMapRightVentricle[nodeIndex])
258 if (mDistMapLeftVentricle[nodeIndex]
259 < LEFT_SEPTUM_SIZE*(mDistMapLeftVentricle[nodeIndex] + mDistMapRightVentricle[nodeIndex]))
272 template<
unsigned SPACE_DIM>
276 if ( mNumberOfSurfacesProvided == 3)
281 case LEFT_VENTRICLE_WALL:
282 case LEFT_VENTRICLE_SURFACE:
283 return mDistMapLeftVentricle[nodeIndex];
286 case RIGHT_VENTRICLE_WALL:
287 case RIGHT_VENTRICLE_SURFACE:
288 return mDistMapRightVentricle[nodeIndex];
292 return mDistMapLeftVentricle[nodeIndex];
296 return mDistMapRightVentricle[nodeIndex] ;
300 #define COVERAGE_IGNORE
301 std::cerr <<
"Wrong distances node: " << nodeIndex <<
"\t"
302 <<
"Epi " << mDistMapEpicardium[nodeIndex] <<
"\t"
303 <<
"RV " << mDistMapRightVentricle[nodeIndex] <<
"\t"
304 <<
"LV " << mDistMapLeftVentricle[nodeIndex]
310 #undef COVERAGE_IGNORE
319 return mDistMapEndocardium[nodeIndex];
327 template<
unsigned SPACE_DIM>
330 return mDistMapEpicardium[nodeIndex];
333 template<
unsigned SPACE_DIM>
337 double dist_endo = GetDistanceToEndo(nodeIndex);
338 double dist_epi = GetDistanceToEpi(nodeIndex);
339 assert( (dist_endo + dist_epi) != 0 );
344 double relative_position = dist_endo / (dist_endo + dist_epi);
345 return relative_position;
348 template<
unsigned SPACE_DIM>
351 if (epiFraction+endoFraction>1)
353 EXCEPTION(
"The sum of fractions of epicardial and endocardial layers must be lesser than 1");
356 if ((endoFraction<0) || (epiFraction<0))
358 EXCEPTION(
"A fraction of a layer must be positive");
361 mLayerForEachNode.resize(mpMesh->GetNumNodes());
362 for(
unsigned i=0; i<mpMesh->GetNumNodes(); i++)
364 double position = CalculateRelativeWallPosition(i);
365 if (position<endoFraction)
367 mLayerForEachNode[i] = ENDO;
369 else if (position<(1-epiFraction))
371 mLayerForEachNode[i] = MID;
375 mLayerForEachNode[i] = EPI;
381 template<
unsigned SPACE_DIM>
389 assert(mLayerForEachNode.size()>0);
390 for(
unsigned i=0; i<mpMesh->GetNumNodes(); i++)
392 if(mLayerForEachNode[i]==EPI)
396 else if(mLayerForEachNode[i]==MID)
412 template<
unsigned SPACE_DIM>
414 const std::vector<unsigned>& rSurfaceNodes)
417 assert(rSurfaceNodes.size()>0);
419 c_vector<double, SPACE_DIM> my_minimum_point = scalar_vector<double>(SPACE_DIM, DBL_MAX);
421 c_vector<double, SPACE_DIM> my_maximum_point=-my_minimum_point;
424 for (
unsigned surface_index=0; surface_index<rSurfaceNodes.size(); surface_index++)
426 unsigned global_index=rSurfaceNodes[surface_index];
427 if (mpMesh->GetDistributedVectorFactory()->IsGlobalIndexLocal(global_index) )
429 c_vector<double, SPACE_DIM> position = mpMesh->GetNode(global_index)->rGetLocation();
431 for (
unsigned i=0; i<SPACE_DIM; i++)
433 if (position[i] < my_minimum_point[i])
435 my_minimum_point[i] = position[i];
437 if (position[i] > my_maximum_point[i])
439 my_maximum_point[i] = position[i];
446 c_vector<double, SPACE_DIM> global_minimum_point;
447 c_vector<double, SPACE_DIM> global_maximum_point;
448 MPI_Allreduce(&my_minimum_point[0], &global_minimum_point[0], SPACE_DIM, MPI_DOUBLE, MPI_MIN, PETSC_COMM_WORLD);
449 MPI_Allreduce(&my_maximum_point[0], &global_maximum_point[0], SPACE_DIM, MPI_DOUBLE, MPI_MAX, PETSC_COMM_WORLD);
#define EXCEPTION(message)
out_stream OpenOutputFile(const std::string &rFileName, std::ios_base::openmode mode=std::ios::out|std::ios::trunc) const
void ComputeDistanceMap(const std::vector< unsigned > &rSourceNodeIndices, std::vector< double > &rNodeDistances)