Chaste Commit::1fd4e48e3990e67db148bc1bc4cf6991a0049d0c
NodeVelocityWriter.cpp
1/*
2
3Copyright (c) 2005-2024, University of Oxford.
4All rights reserved.
5
6University of Oxford means the Chancellor, Masters and Scholars of the
7University of Oxford, having an administrative office at Wellington
8Square, Oxford OX1 2JD, UK.
9
10This file is part of Chaste.
11
12Redistribution and use in source and binary forms, with or without
13modification, 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
23THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
27LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
29GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
32OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33
34*/
35
36#include "NodeVelocityWriter.hpp"
37#include "AbstractCellPopulation.hpp"
38#include "MeshBasedCellPopulation.hpp"
39#include "CaBasedCellPopulation.hpp"
40#include "NodeBasedCellPopulation.hpp"
41#include "PottsBasedCellPopulation.hpp"
42#include "VertexBasedCellPopulation.hpp"
43#include "ImmersedBoundaryCellPopulation.hpp"
44
45template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
47 : AbstractCellPopulationWriter<ELEMENT_DIM, SPACE_DIM>("nodevelocities.dat")
48{
49}
50
51template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
53{
54 for (typename AbstractMesh<ELEMENT_DIM, SPACE_DIM>::NodeIterator node_iter = pCellPopulation->rGetMesh().GetNodeIteratorBegin();
55 node_iter != pCellPopulation->rGetMesh().GetNodeIteratorEnd();
56 ++node_iter)
57 {
58 // We should never encounter deleted nodes when calling this method
59 assert(!node_iter->IsDeleted());
60
61 unsigned node_index = node_iter->GetIndex();
62
63 // Check that results should be written for this node
64 bool is_real_node = !(pCellPopulation->IsGhostNode(node_index));
65
66 // We should never encounter nodes associated with dead cells when calling this method
67 if (is_real_node)
68 {
69 assert(!pCellPopulation->GetCellUsingLocationIndex(node_index)->IsDead());
70 }
71
72 if (is_real_node)
73 {
74 // Write this node's index to file
75 *this->mpOutStream << node_index << " ";
76
77 // Write this node's position to file
78 const c_vector<double, SPACE_DIM>& position = node_iter->rGetLocation();
79 for (unsigned i=0; i<SPACE_DIM; i++)
80 {
81 *this->mpOutStream << position[i] << " ";
82 }
83
84 // Write this node's velocity to file
85 double time_step = SimulationTime::Instance()->GetTimeStep();
86 double damping_constant = pCellPopulation->GetDampingConstant(node_index);
87 c_vector<double, SPACE_DIM> velocity = time_step * node_iter->rGetAppliedForce() / damping_constant;
88 for (unsigned i=0; i<SPACE_DIM; i++)
89 {
90 *this->mpOutStream << velocity[i] << " ";
91 }
92 }
93 }
94}
95
96template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
98{
99 EXCEPTION("NodeVelocityWriter cannot be used with a CaBasedCellPopulation");
100}
101
102template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
104{
105 for (typename AbstractMesh<SPACE_DIM, SPACE_DIM>::NodeIterator node_iter = pCellPopulation->rGetMesh().GetNodeIteratorBegin();
106 node_iter != pCellPopulation->rGetMesh().GetNodeIteratorEnd();
107 ++node_iter)
108 {
109 // We should never encounter deleted nodes when calling this method
110 assert(!node_iter->IsDeleted());
111
112 unsigned node_index = node_iter->GetIndex();
113
114 // Check that results should be written for this node
115 bool is_real_node = !(pCellPopulation->IsGhostNode(node_index));
116
117 // We should never encounter nodes associated with dead cells when calling this method
118 if (is_real_node)
119 {
120 assert(!pCellPopulation->GetCellUsingLocationIndex(node_index)->IsDead());
121 }
122
123 if (is_real_node)
124 {
125 // Write this node's index to file
126 *this->mpOutStream << node_index << " ";
127
128 // Write this node's position to file
129 const c_vector<double, SPACE_DIM>& position = node_iter->rGetLocation();
130 for (unsigned i=0; i<SPACE_DIM; i++)
131 {
132 *this->mpOutStream << position[i] << " ";
133 }
134
135 // Write this node's velocity to file
136 double time_step = SimulationTime::Instance()->GetTimeStep();
137 double damping_constant = pCellPopulation->GetDampingConstant(node_index);
138 c_vector<double, SPACE_DIM> velocity = time_step * node_iter->rGetAppliedForce() / damping_constant;
139 for (unsigned i=0; i<SPACE_DIM; i++)
140 {
141 *this->mpOutStream << velocity[i] << " ";
142 }
143 }
144 }
145}
146
147template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
149{
150 EXCEPTION("NodeVelocityWriter cannot be used with a PottsBasedCellPopulation");
151}
152
153template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
155{
156 for (typename AbstractMesh<SPACE_DIM, SPACE_DIM>::NodeIterator node_iter = pCellPopulation->rGetMesh().GetNodeIteratorBegin();
157 node_iter != pCellPopulation->rGetMesh().GetNodeIteratorEnd();
158 ++node_iter)
159 {
160 // We should never encounter deleted nodes when calling this method
161 assert(!node_iter->IsDeleted());
162
163 // Write this node's index to file
164 unsigned node_index = node_iter->GetIndex();
165 *this->mpOutStream << node_index << " ";
166
167 // Write this node's position to file
168 const c_vector<double, SPACE_DIM>& position = node_iter->rGetLocation();
169 for (unsigned i=0; i<SPACE_DIM; i++)
170 {
171 *this->mpOutStream << position[i] << " ";
172 }
173
174 // Write this node's velocity to file
175 double time_step = SimulationTime::Instance()->GetTimeStep();
176 double damping_constant = pCellPopulation->GetDampingConstant(node_index);
177 c_vector<double, SPACE_DIM> velocity = time_step * node_iter->rGetAppliedForce() / damping_constant;
178 for (unsigned i=0; i<SPACE_DIM; i++)
179 {
180 *this->mpOutStream << velocity[i] << " ";
181 }
182 }
183}
184
185template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
187{
188 EXCEPTION("NodeVelocityWriter cannot be used with a ImmersedBoundaryCellPopulation");
189}
190
191// Explicit instantiation
192template class NodeVelocityWriter<1,1>;
193template class NodeVelocityWriter<1,2>;
194template class NodeVelocityWriter<2,2>;
195template class NodeVelocityWriter<1,3>;
196template class NodeVelocityWriter<2,3>;
197template class NodeVelocityWriter<3,3>;
198
200// Declare identifier for the serializer
#define EXCEPTION(message)
#define EXPORT_TEMPLATE_CLASS_ALL_DIMS(CLASS)
virtual CellPtr GetCellUsingLocationIndex(unsigned index)
virtual double GetDampingConstant(unsigned nodeIndex)
NodeIterator GetNodeIteratorEnd()
NodeIterator GetNodeIteratorBegin(bool skipDeletedNodes=true)
double GetDampingConstant(unsigned nodeIndex)
MutableMesh< ELEMENT_DIM, SPACE_DIM > & rGetMesh()
virtual CellPtr GetCellUsingLocationIndex(unsigned index)
NodesOnlyMesh< DIM > & rGetMesh()
virtual void Visit(MeshBasedCellPopulation< ELEMENT_DIM, SPACE_DIM > *pCellPopulation)
double GetTimeStep() const
static SimulationTime * Instance()
double GetDampingConstant(unsigned nodeIndex)
MutableVertexMesh< DIM, DIM > & rGetMesh()