23 #ifndef __MESH_VALUE_COLLECTION_H 24 #define __MESH_VALUE_COLLECTION_H 29 #include <dolfin/common/NoDeleter.h> 30 #include <dolfin/common/Variable.h> 31 #include <dolfin/log/log.h> 34 #include "MeshEntity.h" 35 #include "MeshFunction.h" 50 class MeshValueCollection :
public Variable
112 void init(std::shared_ptr<const Mesh>
mesh, std::size_t
dim);
120 void init(std::size_t dim);
126 std::size_t
dim()
const;
132 std::shared_ptr<const Mesh>
mesh()
const;
144 std::size_t
size()
const;
159 bool set_value(std::size_t cell_index, std::size_t local_entity,
172 bool set_value(std::size_t entity_index,
const T& value);
184 T
get_value(std::size_t cell_index, std::size_t local_entity);
190 std::map<std::pair<std::size_t, std::size_t>, T>&
values();
196 const std::map<std::pair<std::size_t, std::size_t>, T>&
values()
const;
208 std::string
str(
bool verbose)
const;
213 std::shared_ptr<const Mesh> _mesh;
219 std::map<std::pair<std::size_t, std::size_t>, T> _values;
226 template <
typename T>
228 :
Variable(
"m",
"unnamed MeshValueCollection"), _dim(-1)
233 template <
typename T>
235 mesh) : _mesh(mesh), _dim(-1)
240 template <
typename T>
243 :
Variable(
"m",
"unnamed MeshValueCollection"), _mesh(mesh), _dim(dim)
248 template <
typename T>
251 :
Variable(
"m",
"unnamed MeshValueCollection"), _mesh(mesh_function.
mesh()),
252 _dim(mesh_function.
dim())
254 dolfin_assert(_mesh);
255 const std::size_t D = _mesh->topology().dim();
260 for (std::size_t cell_index = 0; cell_index < mesh_function.
size();
263 const std::pair<std::size_t, std::size_t> key(cell_index, 0);
264 _values.insert({key, mesh_function[cell_index]});
269 _mesh->init(_dim, D);
271 dolfin_assert(!connectivity.
empty());
272 for (std::size_t entity_index = 0; entity_index < mesh_function.
size();
276 dolfin_assert(connectivity.
size(entity_index) > 0);
277 const MeshEntity entity(*_mesh, _dim, entity_index);
278 for (std::size_t i = 0; i < entity.num_entities(D) ; ++i)
281 const Cell cell(*_mesh, connectivity(entity_index)[i]);
284 const std::size_t local_entity = cell.
index(entity);
287 const std::pair<std::size_t, std::size_t> key(cell.
index(),
289 _values.insert({key, mesh_function[entity_index]});
295 template <
typename T>
297 const std::string filename)
298 :
Variable(
"m",
"unnamed MeshValueCollection"),
299 _mesh(mesh), _dim(-1)
303 dolfin_assert(_dim > -1);
306 template <
typename T>
310 _mesh = mesh_function.
mesh();
311 _dim = mesh_function.
dim();
313 dolfin_assert(_mesh);
314 const std::size_t D = _mesh->topology().dim();
321 for (std::size_t cell_index = 0; cell_index < mesh_function.
size();
324 const std::pair<std::size_t, std::size_t> key(cell_index, 0);
325 _values.insert({key, mesh_function[cell_index]});
330 _mesh->init(_dim, D);
332 dolfin_assert(!connectivity.
empty());
333 for (std::size_t entity_index = 0; entity_index < mesh_function.
size();
337 dolfin_assert(connectivity.
size(entity_index) > 0);
338 const MeshEntity entity(*_mesh, _dim, entity_index);
339 for (std::size_t i = 0; i < entity.num_entities(D) ; ++i)
342 const Cell cell(*_mesh, connectivity(entity_index)[i]);
345 const std::size_t local_entity = cell.
index(entity);
348 const std::pair<std::size_t, std::size_t> key(cell.
index(),
350 _values.insert({key, mesh_function[entity_index]});
358 template <
typename T>
361 mesh_value_collection)
363 _mesh = mesh_value_collection._mesh;
364 _dim = mesh_value_collection.dim();
365 _values = mesh_value_collection.values();
370 template <
typename T>
380 template <
typename T>
383 dolfin_assert(_mesh);
384 dolfin_assert(_dim < 0);
388 template <
typename T>
391 dolfin_assert(_dim >= 0);
395 template <
typename T>
398 return _values.empty();
401 template <
typename T>
404 return _values.size();
407 template <
typename T>
410 dolfin_assert(_mesh);
414 template <
typename T>
416 std::size_t local_entity,
419 dolfin_assert(_dim >= 0);
424 "A mesh has not been associated with this MeshValueCollection");
427 const std::pair<std::size_t, std::size_t> pos(cell_index, local_entity);
428 std::pair<typename std::map<std::pair<std::size_t, std::size_t>, T>::iterator,
bool>
429 it = _values.insert({pos, value});
434 it.first->second = value;
439 template <
typename T>
447 "A mesh has not been associated with this MeshValueCollection");
450 dolfin_assert(_dim >= 0);
453 const std::size_t D = _mesh->topology().dim();
457 const std::pair<std::size_t, std::size_t> pos(entity_index, 0);
458 std::pair<
typename std::map<std::pair<std::size_t,
459 std::size_t>, T>::iterator,
bool> it;
460 it = _values.insert({pos, value});
465 it.first->second = value;
471 _mesh->init(_dim, D);
475 dolfin_assert(!connectivity.
empty());
476 dolfin_assert(connectivity.
size(entity_index) > 0);
477 const MeshEntity entity(*_mesh, _dim, entity_index);
478 const Cell cell(*_mesh, connectivity(entity_index)[0]);
481 const std::size_t local_entity = cell.
index(entity);
484 const std::pair<std::size_t, std::size_t> pos(cell.
index(), local_entity);
485 std::pair<
typename std::map<std::pair<std::size_t,
486 std::size_t>, T>::iterator,
bool> it;
487 it = _values.insert({pos, value});
492 it.first->second = value;
497 template <
typename T>
499 std::size_t local_entity)
501 dolfin_assert(_dim >= 0);
503 const std::pair<std::size_t, std::size_t> pos(cell_index, local_entity);
504 const typename std::map<std::pair<std::size_t,
505 std::size_t>, T>::const_iterator
506 it = _values.find(pos);
508 if (it == _values.end())
512 "No value stored for cell index: %d and local index: %d",
513 cell_index, local_entity);
519 template <
typename T>
520 std::map<std::pair<std::size_t, std::size_t>, T>&
526 template <
typename T>
527 const std::map<std::pair<std::size_t, std::size_t>, T>&
533 template <
typename T>
539 template <
typename T>
545 s <<
str(
false) << std::endl << std::endl;
546 warning(
"Verbose output of MeshValueCollection must be implemented manually.");
550 s <<
"<MeshValueCollection of topological dimension " <<
dim()
551 <<
" containing " <<
size() <<
" values>";
std::map< std::pair< std::size_t, std::size_t >, T > & values()
Definition: MeshValueCollection.h:521
Common base class for DOLFIN variables.
Definition: Variable.h:35
std::size_t index() const
Definition: MeshEntity.h:113
std::string str(bool verbose) const
Definition: MeshValueCollection.h:540
void warning(std::string msg,...)
Print warning.
Definition: log.cpp:115
void clear()
Clear all values.
Definition: MeshValueCollection.h:534
std::size_t size() const
Return total number of connections.
Definition: MeshConnectivity.h:60
std::size_t dim() const
Definition: MeshFunction.h:498
std::shared_ptr< const Mesh > mesh() const
Definition: MeshValueCollection.h:408
std::size_t size() const
Definition: MeshValueCollection.h:402
Definition: MeshConnectivity.h:39
A Cell is a MeshEntity of topological codimension 0.
Definition: Cell.h:42
bool empty() const
Definition: MeshValueCollection.h:396
T get_value(std::size_t cell_index, std::size_t local_entity)
Definition: MeshValueCollection.h:498
bool set_value(std::size_t cell_index, std::size_t local_entity, const T &value)
Definition: MeshValueCollection.h:415
std::size_t dim() const
Definition: MeshValueCollection.h:389
void init(std::shared_ptr< const Mesh > mesh, std::size_t dim)
Definition: MeshValueCollection.h:371
bool empty() const
Return true if the total number of connections is equal to zero.
Definition: MeshConnectivity.h:56
MeshValueCollection< T > & operator=(const MeshFunction< T > &mesh_function)
Definition: MeshValueCollection.h:308
Definition: GenericFile.h:38
MeshValueCollection()
Definition: MeshValueCollection.h:227
Definition: MeshEntity.h:42
void dolfin_error(std::string location, std::string task, std::string reason,...)
Definition: log.cpp:129
std::shared_ptr< const Mesh > mesh() const
Definition: MeshFunction.h:491
std::size_t size() const
Definition: MeshFunction.h:510
~MeshValueCollection()
Destructor.
Definition: MeshValueCollection.h:89