Chaste  Release::3.4
Cylindrical2dNodesOnlyMesh.cpp
1 /*
2 
3 Copyright (c) 2005-2016, University of Oxford.
4 All rights reserved.
5 
6 University of Oxford means the Chancellor, Masters and Scholars of the
7 University of Oxford, having an administrative office at Wellington
8 Square, Oxford OX1 2JD, UK.
9 
10 This file is part of Chaste.
11 
12 Redistribution and use in source and binary forms, with or without
13 modification, are permitted provided that the following conditions are met:
14  * Redistributions of source code must retain the above copyright notice,
15  this list of conditions and the following disclaimer.
16  * Redistributions in binary form must reproduce the above copyright notice,
17  this list of conditions and the following disclaimer in the documentation
18  and/or other materials provided with the distribution.
19  * Neither the name of the University of Oxford nor the names of its
20  contributors may be used to endorse or promote products derived from this
21  software without specific prior written permission.
22 
23 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
27 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
29 GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
32 OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 
34 */
35 
36 #include <map>
37 #include "Cylindrical2dNodesOnlyMesh.hpp"
38 
40  : NodesOnlyMesh<2>(),
41  mWidth(width)
42 {
43  assert(width > 0.0);
44 }
45 
46 void Cylindrical2dNodesOnlyMesh::SetUpBoxCollection(double cutOffLength, c_vector<double, 2*2> domainSize, int numLocalRows, bool isPeriodic)
47 {
48  if (cutOffLength < mWidth)
49  {
50  EXCEPTION("Need to specify a cut off length larger than the width with Cylindrical2dNodesOnlyMeshes.");
51  }
52 
53  NodesOnlyMesh<2>::SetUpBoxCollection(cutOffLength, domainSize, PETSC_DECIDE, true); // Only difference is that this "true" makes the boxes periodic.
54 
55  this->AddNodesToBoxes();
56 }
57 
58 double Cylindrical2dNodesOnlyMesh::GetWidth(const unsigned& rDimension) const
59 {
60  double width = 0.0;
61  assert(rDimension==0 || rDimension==1);
62  if (rDimension==0)
63  {
64  width = mWidth;
65  }
66  else
67  {
68  width = MutableMesh<2,2>::GetWidth(rDimension);
69  }
70  return width;
71 }
72 
73 
74 void Cylindrical2dNodesOnlyMesh::SetNode(unsigned nodeIndex, ChastePoint<2> point, bool concreteMove)
75 {
76  // concreteMove should always be false for NodesOnlyMesh as no elements to check
77  assert(!concreteMove);
78 
79  double x_coord = point.rGetLocation()[0];
80 
81  // Perform a periodic movement if necessary
82  if (x_coord >= mWidth)
83  {
84  // Move point to the left
85  point.SetCoordinate(0, x_coord - mWidth);
86  }
87  else if (x_coord < 0.0)
88  {
89  // Move point to the right
90  point.SetCoordinate(0, x_coord + mWidth);
91  }
92 
93  // Update the node's location
94  this->GetNode(nodeIndex)->SetPoint(point);
95 }
96 
98 {
99  // Call method on parent class
100  unsigned node_index = NodesOnlyMesh<2>::AddNode(pNewNode);
101 
102  // If necessary move it to be back on the cylinder
103  ChastePoint<2> new_node_point = pNewNode->GetPoint();
104  SetNode(node_index, new_node_point);
105 
106  return node_index;
107 
108 }
109 
110 c_vector<double, 2> Cylindrical2dNodesOnlyMesh::GetVectorFromAtoB(const c_vector<double, 2>& rLocation1, const c_vector<double, 2>& rLocation2)
111 {
112  c_vector<double, 2> vector = rLocation2 - rLocation1;
113  vector[0] = fmod(vector[0], mWidth);
114 
115  /*
116  * Handle the cylindrical condition here: if the points are more
117  * than halfway around the cylinder apart, measure the other way.
118  */
119  if (vector[0] > 0.5*mWidth)
120  {
121  vector[0] -= mWidth;
122  }
123  else if (vector[0] < -0.5*mWidth)
124  {
125  vector[0] += mWidth;
126  }
127  return vector;
128 }
129 
130 // Serialization for Boost >= 1.36
void SetNode(unsigned nodeIndex, ChastePoint< 2 > point, bool concreteMove=false)
Definition: Node.hpp:58
c_vector< double, DIM > & rGetLocation()
Definition: ChastePoint.cpp:76
unsigned AddNode(Node< 2 > *pNewNode)
Node< SPACE_DIM > * GetNode(unsigned index) const
#define EXCEPTION(message)
Definition: Exception.hpp:143
virtual void SetUpBoxCollection(double cutOffLength, c_vector< double, 2 *2 > domainSize, int numLocalRows=PETSC_DECIDE, bool isPeriodic=true)
void SetUpBoxCollection(const std::vector< Node< SPACE_DIM > * > &rNodes)
void SetCoordinate(unsigned i, double value)
unsigned AddNode(Node< SPACE_DIM > *pNewNode)
ChastePoint< SPACE_DIM > GetPoint() const
Definition: Node.cpp:134
virtual double GetWidth(const unsigned &rDimension) const
double GetWidth(const unsigned &rDimension) const
#define CHASTE_CLASS_EXPORT(T)
c_vector< double, 2 > GetVectorFromAtoB(const c_vector< double, 2 > &rLocation1, const c_vector< double, 2 > &rLocation2)