VPTissue Reference Manual
ExchangeCoupler.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2011-2016 Universiteit Antwerpen
3  *
4  * Licensed under the EUPL, Version 1.1 or as soon they will be approved by
5  * the European Commission - subsequent versions of the EUPL (the "Licence");
6  * You may not use this work except in compliance with the Licence.
7  * You may obtain a copy of the Licence at: http://ec.europa.eu/idabc/eupl5
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the Licence is distributed on an "AS IS" basis,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the Licence for the specific language governing
13  * permissions and limitations under the Licence.
14  */
20 #include "ExchangeCoupler.h"
21 
22 #include "bio/Cell.h"
23 #include "sim/Sim.h"
24 
25 #include <boost/property_tree/ptree.hpp>
26 #include <unordered_map>
27 
28 using namespace std;
29 using namespace boost::property_tree;
30 
31 namespace SimPT_Sim {
32 
33 ExchangeCoupler::ExchangeCoupler()
34 {
35 }
36 
37 void ExchangeCoupler::Initialize( const ptree& params,
38  const CoreData& from, const CoreData& to)
39 {
40  m_from = from;
41  m_to = to;
42  m_transfer_chemicals = { params.get<unsigned int>("chemical_from"), params.get<unsigned int>("chemical_to")};
43 
44  for (const auto& transfer_cells : params.get_child("transfer_cells_array")) {
45  const auto from = transfer_cells.second.get<unsigned int>("cell_from");
46  const auto to = transfer_cells.second.get<unsigned int>("cell_to");
47  const auto D = transfer_cells.second.get<double>("diffusion");
48  m_transfer_cells.push_back(make_tuple(from, to, D));
49  }
50 }
51 
52 void ExchangeCoupler::Exec()
53 {
54  assert(m_from.m_mesh->GetNumChemicals() >= m_transfer_chemicals.first + 1
55  && "Mesh to transfer chemicals from has too few chemicals");
56  assert(m_to.m_mesh->GetNumChemicals() >= m_transfer_chemicals.second + 1
57  && "Mesh to transfer chemicals to has too few chemicals");
58 
59  const auto& from_cells = m_from.m_mesh->GetCells();
60  const auto& to_cells = m_to.m_mesh->GetCells();
61  auto& from_map = *m_from.m_coupled_sim_transfer_data;
62  auto& to_map = *m_to.m_coupled_sim_transfer_data;
63 
64  for (auto c : m_transfer_cells) {
65  assert((from_cells.size() >= get<0>(c) + 1) && "No cell with from index");
66  assert((to_cells.size() >= get<1>(c) + 1) && "No cell with to index");
67 
68  const Cell& from_cell = *(from_cells[get<0>(c)]);
69  const Cell& to_cell = *(to_cells[get<1>(c)]);
70 
71  double value;
72 
73 
74  // Update to transfer map
75  value= ( from_cell.GetChemical(m_transfer_chemicals.first) ) / (from_cell.GetArea());
76  to_map[get<1>(c)] = make_tuple (value, get<2>(c));
77 
78  // Update from transfer map
79  value= ( to_cell.GetChemical(m_transfer_chemicals.second) ) / (to_cell.GetArea());
80 
81  from_map[get<0>(c)] = make_tuple (value, get<2>(c));
82 
83  }
84 }
85 
86 } // namespace
Core data with mesh, parameters, random engine and time data.
Definition: CoreData.h:38
STL namespace.
A cell contains walls and nodes.
Definition: Cell.h:48
Interface for ExchangeCoupler.
Namespace for the core simulator.
Interface for Cell.
Sim, the actual simulator.
double GetArea() const
Return the area of the cell.
Definition: Cell.cpp:178