28 #include <boost/property_tree/ptree.hpp>
40 TransportEquations::TransportEquations(
const CoreData& cd)
45 void TransportEquations::GetDerivatives(vector<double>& derivs)
const
48 derivs.assign(m_equation_count, 0.0);
54 for (
auto c : m_mesh->GetCells()) {
55 m_cell_chemistry(c, &(derivs[i]));
56 i += m_effective_nchem;
60 for (
auto w : m_mesh->GetWalls()) {
61 m_wall_chemistry(w, &(derivs[i]), &(derivs[i + m_effective_nchem]));
64 double* dchem_c1 = &(derivs[w->GetC1()->GetIndex() * m_effective_nchem]);
65 double* dchem_c2 = &(derivs[w->GetC2()->GetIndex() * m_effective_nchem]);
72 if (w->GetC1()->GetIndex() < 0) {
75 if (w->GetC2()->GetIndex() < 0) {
78 m_cell2cell_transport(w, dchem_c1, dchem_c2);
79 i += 2 * m_effective_nchem;
83 int TransportEquations::GetEquationCount()
const
85 return m_equation_count;
88 void TransportEquations::GetVariables(vector<double> &values)
const
94 for (
auto const& cell : m_mesh->GetCells()) {
95 for (
size_t ch = 0; ch < static_cast<size_t>(m_effective_nchem); ch++) {
96 values[i + ch] = cell->GetChemical(ch);
98 i += m_effective_nchem;
102 for (
auto const& wall : m_mesh->GetWalls()) {
103 for (
size_t ch = 0; ch < static_cast<size_t>(m_effective_nchem); ch++) {
104 values[i + ch] = wall->GetTransporters1(ch);
106 i += m_effective_nchem;
108 for (
size_t ch = 0; ch < static_cast<size_t>(m_effective_nchem); ch++) {
109 values[i + ch] = wall->GetTransporters2(ch);
111 i += m_effective_nchem;
115 void TransportEquations::Initialize(
const CoreData& cd)
117 assert(cd.
Check() &&
"CoreData not ok.");
119 m_mesh = m_cd.m_mesh.get();
121 const auto model_group = m_cd.m_parameters->get<
string>(
"model.group",
"");
122 const auto factory = ComponentFactoryProxy::Create(model_group);
123 m_cell_chemistry = factory->CreateCellChemistry(m_cd);
124 m_cell2cell_transport = factory->CreateCellToCellTransport(m_cd);
125 m_wall_chemistry = factory->CreateWallChemistry(m_cd);
127 const unsigned int mesh_cc = m_mesh->GetNumChemicals();
128 const unsigned int model_cc = m_cd.m_parameters->get<
unsigned int>(
"model.cell_chemical_count");
129 if ((mesh_cc == 0) || (model_cc == 0) || (mesh_cc == model_cc)) {
130 m_effective_nchem = min(mesh_cc, model_cc);
133 ss <<
"TransportEquations::Initialize>: mismatch in chemical counts: ";
134 ss <<
"mesh: " << mesh_cc <<
" , model: " << model_cc;
135 throw runtime_error(ss.str());
138 m_equation_count = (2 * m_mesh->GetWalls().size() + m_mesh->GetCells().size()) * m_effective_nchem;
141 void TransportEquations::SetVariables(
const vector<double>& values)
const
147 for (
auto cell : m_mesh->GetCells()) {
148 for (
size_t ch = 0; ch < static_cast<size_t>(m_effective_nchem); ch++) {
149 cell->SetChemical(ch, values[i + ch]);
151 i += m_effective_nchem;
155 for (
const auto& wall : m_mesh->GetWalls()) {
156 for (
size_t ch = 0; ch < static_cast<size_t>(m_effective_nchem); ch++) {
157 wall->SetTransporters1(ch, values[i + ch]);
159 i += m_effective_nchem;
161 for (
size_t ch = 0; ch < static_cast<size_t>(m_effective_nchem); ch++) {
162 wall->SetTransporters2(ch, values[i + ch]);
164 i += m_effective_nchem;
Core data with mesh, parameters, random engine and time data.
Core data used during model execution.
Namespace for miscellaneous utilities.
Namespace for the core simulator.
Proxy for dealing with the factories.
Equations for diffusion and transport.
bool Check() const
Verify all pointers non-null.