Chaste  Release::2017.1
ChemotacticForce.cpp
1 /*
2 
3 Copyright (c) 2005-2017, 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 "ChemotacticForce.hpp"
37 
38 #include "CellwiseDataGradient.hpp"
39 #include "CellLabel.hpp"
40 
41 template<unsigned DIM>
43  : AbstractForce<DIM>()
44 {
45 }
46 
47 template<unsigned DIM>
49 {
50 }
51 
52 template<unsigned DIM>
53 double ChemotacticForce<DIM>::GetChemotacticForceMagnitude(const double concentration, const double concentrationGradientMagnitude)
54 {
55  return concentration; // temporary force law - can be changed to something realistic
56  // without tests failing
57 }
58 
59 template<unsigned DIM>
61 {
62  CellwiseDataGradient<DIM> gradients;
63  gradients.SetupGradients(rCellPopulation, "nutrient");
64 
65  for (typename AbstractCellPopulation<DIM>::Iterator cell_iter = rCellPopulation.Begin();
66  cell_iter != rCellPopulation.End();
67  ++cell_iter)
68  {
69  // Only labelled cells move chemotactically
70  if (cell_iter->template HasCellProperty<CellLabel>())
71  {
72  unsigned node_global_index = rCellPopulation.GetLocationIndexUsingCell(*cell_iter);
73 
74  c_vector<double,DIM>& r_gradient = gradients.rGetGradient(node_global_index);
75  double nutrient_concentration = cell_iter->GetCellData()->GetItem("nutrient");
76  double magnitude_of_gradient = norm_2(r_gradient);
77 
78  double force_magnitude = GetChemotacticForceMagnitude(nutrient_concentration, magnitude_of_gradient);
79 
80  // force += chi * gradC/|gradC|
81  if (magnitude_of_gradient > 0)
82  {
83  c_vector<double,DIM> force = (force_magnitude/magnitude_of_gradient)*r_gradient;
84  rCellPopulation.GetNode(node_global_index)->AddAppliedForceContribution(force);
85  }
86  // else Fc=0
87  }
88  }
89 }
90 
91 template<unsigned DIM>
92 void ChemotacticForce<DIM>::OutputForceParameters(out_stream& rParamsFile)
93 {
94  // No parameters to include
95 
96  // Call method on direct parent class
98 }
99 
100 // Explicit instantiation
101 template class ChemotacticForce<1>;
102 template class ChemotacticForce<2>;
103 template class ChemotacticForce<3>;
104 
105 // Serialization for Boost >= 1.36
virtual Node< SPACE_DIM > * GetNode(unsigned index)=0
void OutputForceParameters(out_stream &rParamsFile)
unsigned GetLocationIndexUsingCell(CellPtr pCell)
void AddForceContribution(AbstractCellPopulation< DIM > &rCellPopulation)
void SetupGradients(AbstractCellPopulation< DIM > &rCellPopulation, const std::string &rItemName)
#define EXPORT_TEMPLATE_CLASS_SAME_DIMS(CLASS)
c_vector< double, DIM > & rGetGradient(unsigned nodeIndex)
double GetChemotacticForceMagnitude(const double concentration, const double concentrationGradientMagnitude)
virtual void OutputForceParameters(out_stream &rParamsFile)=0