43 Wall::Wall(
unsigned int index,
Node* n1,
Node* n2,
Cell* c1,
Cell* c2,
unsigned int num_chem)
45 m_c1(c1), m_c2(c2), m_n1(n1), m_n2(n2), m_wall_index(index), m_length(0.0), m_length_dirty(true)
47 assert( (n1 !=
nullptr) &&
"Wall::Wall> Attempting to build a node with nullptr cell!" );
48 assert( (n2 !=
nullptr) &&
"Wall::Wall> Attempting to build a node with nullptr cell!" );
49 assert( (c1 !=
nullptr) &&
"Wall::Wall> Attempting to build a wall with nullptr cell!" );
50 assert( (c2 !=
nullptr) &&
"Wall::Wall> Attempting to build a wall with nullptr cell!" );
51 assert( (c1 != c2) &&
"Wall::Wall> Attempting to build a wall between identical cells!" );
53 std::array<double, 3> ref{{1., 0., 0.}};
54 std::array<double, 3> tot1 = *n1;
55 std::array<double, 3> tot2 = *n2;
56 std::array<double, 3> tot3 = tot1 - tot2;
57 double t2 = SignedAngle(tot3, ref);
58 if ( ( t2 > (-
pi() * 3 / 4) && t2 <= (-
pi() / 4) ) || ( t2 > (
pi() / 4) && t2 <= (
pi() * 3 / 4) ) )
66 void Wall::CalculateLength()
const
68 const auto& nodes = m_c1->
GetNodes();
69 const auto n_begin = nodes.begin();
70 const auto n_end = nodes.end();
74 assert(from != m_c1->
GetNodes().end() &&
"N1 wall endpoint not in cell C1!");
75 assert(to != m_c1->
GetNodes().end() &&
"N2 wall endpoint not in cell C1!");
79 m_length += Norm(**from - **
std::next(from));
80 }
while (++from != to);
83 vector<Edge> Wall::GetEdges()
const
86 const auto& nodes = GetC1()->
GetNodes();
87 const auto cit_start = find(nodes.begin(), nodes.end(), GetN1());
88 const auto cit_stop = find(nodes.begin(), nodes.end(), GetN2());
93 }
while(++cit != cit_stop);
101 m_length_dirty =
false;
106 array<double, 3> Wall::GetInfluxVector(
Cell* c)
const
108 assert( (m_c1 == c || m_c2 == c) &&
"Wall::GetWallVector called with wrong cell!" );
109 const double sign = ( c == m_c1 ? 1.0 : -1.0 );
110 return sign * Orthogonalize(Normalize(*m_n2 - *m_n1));
113 array<double, 3> Wall::GetWallVector(
Cell* c)
const
115 assert( (m_c1 == c || m_c2 ==c) &&
"Wall::GetWallVector called with wrong cell!" );
116 const double sign = ( c == m_c1 ? 1.0 : -1.0 );
117 return sign * (*m_n2 - *m_n1);
127 return GetN1()->IsSam() || GetN2()->IsSam();
134 const auto& nodes = GetC1()->
GetNodes();
135 const auto cit_start = find(nodes.begin(), nodes.end(), GetN1());
136 const auto cit_stop = find(nodes.begin(), nodes.end(), GetN2());
140 status = (
Edge(*cit, *
next(cit)) == edge);
141 }
while(!status && ++cit != cit_stop);
150 const auto& nodes = GetC1()->
GetNodes();
151 const auto cit_start = find(nodes.begin(), nodes.end(), GetN1());
152 const auto cit_stop = find(nodes.begin(), nodes.end(), GetN2());
156 status = (*cit == node);
157 }
while(!status && cit++ != cit_stop);
162 bool Wall::IsIntersectingWithDivisionPlane(
const array<double, 3>& p1,
const array<double, 3>& p2)
const
164 const double x1 = (*m_n1)[0];
165 const double y1 = (*m_n1)[1];
166 const double x2 = (*m_n2)[0];
167 const double y2 = (*m_n2)[1];
168 const double x3 = p1[0];
169 const double y3 = p1[1];
170 const double x4 = p2[0];
171 const double y4 = p2[1];
172 const double ua = ((x4 - x3) * (y1 - y3) - (y4 - y3) * (x1 - x3))
173 / ((y4 - y3) * (x2 - x1) - (x4 - x3) * (y2 - y1));
176 return (ua >= 0. && ua <= 1.) ?
true :
false;
180 ostream& Wall::Print(ostream& os)
const
182 os <<
"Wall: " << GetIndex() <<
" "<<
"{ " << m_n1->GetIndex() <<
"->" << m_n2->GetIndex()
187 void Wall::ReadPtree(boost::property_tree::ptree
const& wall_pt)
189 WallAttributes::ReadPtree(wall_pt.get_child(
"attributes"));
195 ret.put(
"id", GetIndex());
198 ret.put(
"n1", m_n1->GetIndex());
199 ret.put(
"n2", m_n2->GetIndex());
206 ostream& operator<<(ostream& os,
const Wall& w)
bool IsAtBoundary() const
Checks whether a wall is at the boundary of the mesh.
A cell contains walls and nodes.
bool IncludesNode(const Node *node) const
Checks whether edge is part of this wall.
Namespace for miscellaneous utilities.
bool IncludesEdge(const Edge &edge) const
Checks whether edge is part of this wall.
Interface for NodeAttributes.
Namespace for the core simulator.
An Edge connects two nodes and is ambidextrous.
Namespace for container related classes.
Interface for WallAttributes.
const std::vector< Node * > & GetNodes() const
Access the nodes of cell's polygon.
Attributes associated with a wall.
ConstCircularIterator class and helper functions.
int GetIndex() const
Return the index.
virtual boost::property_tree::ptree ToPtree() const
Convert the wall to a ptree.
double GetLength() const
Returns (and calculates, if length marked as dirty) the length along all nodes.
Extending std with arithmetic for std::array.
CircularIterator< T > next(CircularIterator< T > i)
Helper yields the position the iterator would have if moved forward (in circular fashion) by 1 positi...
ConstCircularIterator< typename T::const_iterator > make_const_circular(const T &c)
Helper produces const circular iterator whose range corresponds to the begin and end iterators of a c...
CircularIterator class and helper functions.
constexpr double pi()
Math constant pi.
A cell wall, runs between cell corner points and consists of wall elements.
virtual boost::property_tree::ptree ToPtree() const
Convert the wall attributes to a ptree.
bool IsSam() const
True if the Wall adheres to the SAM (shoot apical meristem)