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 #ifndef ABSTRACTMESH_HPP_
00030 #define ABSTRACTMESH_HPP_
00031
00032 #include <boost/serialization/access.hpp>
00033 #include <boost/serialization/is_abstract.hpp>
00034
00035 #include <vector>
00036 #include <string>
00037 #include <cassert>
00038
00039 #include "Node.hpp"
00040 #include "DistributedVectorFactory.hpp"
00041
00045 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00046 class AbstractMesh
00047 {
00048 private:
00057 virtual unsigned SolveNodeMapping(unsigned index) const = 0;
00058
00060 friend class boost::serialization::access;
00067 template<class Archive>
00068 void serialize(Archive & archive, const unsigned int version)
00069 {
00070 archive & mMeshChangesDuringSimulation;
00071 }
00072
00073 protected:
00074
00076 std::vector<Node<SPACE_DIM> *> mNodes;
00077
00079 std::vector<Node<SPACE_DIM> *> mBoundaryNodes;
00080
00082 DistributedVectorFactory *mpDistributedVectorFactory;
00083
00085 std::vector<unsigned> mNodesPermutation;
00086
00091 std::string mMeshFileBaseName;
00092
00096 bool mMeshChangesDuringSimulation;
00097
00098 public:
00099
00101
00103
00105 typedef typename std::vector<Node<SPACE_DIM> *>::const_iterator BoundaryNodeIterator;
00106
00108 class NodeIterator;
00109
00115 inline NodeIterator GetNodeIteratorBegin(bool skipDeletedNodes=true);
00116
00120 inline NodeIterator GetNodeIteratorEnd();
00121
00123
00125
00129 AbstractMesh();
00130
00134 virtual ~AbstractMesh();
00135
00141 virtual unsigned GetNumNodes() const;
00142
00146 unsigned GetNumBoundaryNodes() const;
00147
00151 unsigned GetNumAllNodes() const;
00152
00159 Node<SPACE_DIM>* GetNode(unsigned index) const;
00160
00166 virtual void ReadNodesPerProcessorFile(const std::string& rNodesPerProcessorFile);
00167
00171 DistributedVectorFactory * GetDistributedVectorFactory();
00172
00177 virtual void PermuteNodes();
00178
00182 BoundaryNodeIterator GetBoundaryNodeIteratorBegin() const;
00183
00188 BoundaryNodeIterator GetBoundaryNodeIteratorEnd() const;
00189
00193 std::string GetMeshFileBaseName() const;
00194
00198 const std::vector<unsigned>& rGetNodePermutation() const;
00199
00210 virtual c_vector<double, SPACE_DIM> GetVectorFromAtoB(const c_vector<double, SPACE_DIM>& rLocationA,
00211 const c_vector<double, SPACE_DIM>& rLocationB);
00212
00224 double GetDistanceBetweenNodes(unsigned indexA, unsigned indexB);
00225
00234 virtual double GetWidth(const unsigned& rDimension) const;
00235
00242 c_vector<double,2> GetWidthExtremes(const unsigned& rDimension) const;
00243
00251 void Scale(const double xFactor=1.0, const double yFactor=1.0, const double zFactor=1.0);
00252
00257 virtual void RefreshMesh();
00258
00262 bool IsMeshChanging() const;
00263
00265
00267
00271 class NodeIterator
00272 {
00273 public:
00279 inline Node<SPACE_DIM>& operator*();
00280
00284 inline Node<SPACE_DIM>* operator->();
00285
00291 inline bool operator!=(const AbstractMesh<ELEMENT_DIM, SPACE_DIM>::NodeIterator& rOther);
00292
00296 inline NodeIterator& operator++();
00297
00308 NodeIterator(AbstractMesh<ELEMENT_DIM, SPACE_DIM>& rMesh,
00309 typename std::vector<Node<SPACE_DIM> *>::iterator nodeIter,
00310 bool skipDeletedNodes=true);
00311 private:
00313 AbstractMesh& mrMesh;
00314
00316 typename std::vector<Node<SPACE_DIM> *>::iterator mNodeIter;
00317
00319 bool mSkipDeletedNodes;
00320
00324 inline bool IsAtEnd();
00325
00329 inline bool IsAllowedNode();
00330 };
00331
00332
00333 };
00334
00335 namespace boost
00336 {
00337 namespace serialization
00338 {
00344 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00345 struct is_abstract<AbstractMesh<ELEMENT_DIM, SPACE_DIM> >
00346 {
00348 typedef mpl::bool_<true> type;
00350 BOOST_STATIC_CONSTANT(bool, value=true);
00351 };
00352 }
00353 }
00354
00356
00358
00359 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00360 typename AbstractMesh<ELEMENT_DIM, SPACE_DIM>::NodeIterator AbstractMesh<ELEMENT_DIM, SPACE_DIM>::GetNodeIteratorBegin(
00361 bool skipDeletedNodes)
00362 {
00363 return NodeIterator(*this, mNodes.begin(), skipDeletedNodes);
00364 }
00365
00366 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00367 typename AbstractMesh<ELEMENT_DIM, SPACE_DIM>::NodeIterator AbstractMesh<ELEMENT_DIM, SPACE_DIM>::GetNodeIteratorEnd()
00368 {
00369 return NodeIterator(*this, mNodes.end());
00370 }
00371
00372 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00373 Node<SPACE_DIM>& AbstractMesh<ELEMENT_DIM, SPACE_DIM>::NodeIterator::operator*()
00374 {
00375 assert(!IsAtEnd());
00376 return **mNodeIter;
00377 }
00378
00379 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00380 Node<SPACE_DIM>* AbstractMesh<ELEMENT_DIM, SPACE_DIM>::NodeIterator::operator->()
00381 {
00382 assert(!IsAtEnd());
00383 return *mNodeIter;
00384 }
00385
00386 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00387 bool AbstractMesh<ELEMENT_DIM, SPACE_DIM>::NodeIterator::operator!=(const AbstractMesh<ELEMENT_DIM, SPACE_DIM>::NodeIterator& rOther)
00388 {
00389 return mNodeIter != rOther.mNodeIter;
00390 }
00391
00392 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00393 typename AbstractMesh<ELEMENT_DIM, SPACE_DIM>::NodeIterator& AbstractMesh<ELEMENT_DIM, SPACE_DIM>::NodeIterator::operator++()
00394 {
00395 do
00396 {
00397 ++mNodeIter;
00398 }
00399 while (!IsAtEnd() && !IsAllowedNode());
00400
00401 return (*this);
00402 }
00403
00404 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00405 AbstractMesh<ELEMENT_DIM, SPACE_DIM>::NodeIterator::NodeIterator(
00406 AbstractMesh<ELEMENT_DIM, SPACE_DIM>& rMesh,
00407 typename std::vector<Node<SPACE_DIM> *>::iterator nodeIter,
00408 bool skipDeletedNodes)
00409 : mrMesh(rMesh),
00410 mNodeIter(nodeIter),
00411 mSkipDeletedNodes(skipDeletedNodes)
00412 {
00413 if (mrMesh.mNodes.size() == 0)
00414 {
00415
00416 mNodeIter = mrMesh.mNodes.end();
00417 }
00418 else
00419 {
00420
00421 if (mNodeIter == mrMesh.mNodes.begin() && !IsAllowedNode())
00422 {
00423 ++(*this);
00424 }
00425 }
00426 }
00427
00428 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00429 bool AbstractMesh<ELEMENT_DIM, SPACE_DIM>::NodeIterator::IsAtEnd()
00430 {
00431 return mNodeIter == mrMesh.mNodes.end();
00432 }
00433
00434 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00435 bool AbstractMesh<ELEMENT_DIM, SPACE_DIM>::NodeIterator::IsAllowedNode()
00436 {
00437 return !(mSkipDeletedNodes && (*this)->IsDeleted());
00438 }
00439
00440
00441 #endif