-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
936 implement the class infectionstate of the lct model more efficien…
…tly (#941) - LctInfectionState is now a class template and has only static members (variables and functions). More computation is now done at compile time. - LctInfectionState can be used by various LCT models (not just SECIR models). Co-authored-by: reneSchm <[email protected]>
- Loading branch information
1 parent
c484b89
commit afd4982
Showing
11 changed files
with
476 additions
and
625 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
/* | ||
* Copyright (C) 2020-2024 MEmilio | ||
* | ||
* Authors: Lena Ploetzke | ||
* | ||
* Contact: Martin J. Kuehn <[email protected]> | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
#ifndef MIO_EPI_LCT_INFECTION_STATE_H | ||
#define MIO_EPI_LCT_INFECTION_STATE_H | ||
|
||
#include <array> | ||
|
||
namespace mio | ||
{ | ||
/** | ||
* @brief Provides the functionality to be able to work with subcompartments in an LCT model. | ||
* | ||
* @tparam InfectionStates An enum class that defines the basic infection states. | ||
* @tparam Ns Number of subcompartments for each infection state defined in InfectionState. | ||
* The number of given template arguments must be equal to the entry Count from InfectionState. | ||
*/ | ||
template <class InfectionStates, unsigned int... Ns> | ||
class LctInfectionState | ||
{ | ||
public: | ||
using InfectionState = InfectionStates; | ||
static_assert((unsigned int)InfectionState::Count == sizeof...(Ns), | ||
"The number of integers provided as template parameters must be " | ||
"the same as the entry Count of InfectionState."); | ||
|
||
static_assert(((Ns > 0) && ...), "The number of subcompartments must be at least 1."); | ||
|
||
/** | ||
* @brief Gets the number of subcompartments in an infection state. | ||
* | ||
* @tparam State: Infection state for which the number of subcompartments should be returned. | ||
* @return Number of subcompartments for State. | ||
*/ | ||
template <InfectionState State> | ||
static constexpr unsigned int get_num_subcompartments() | ||
{ | ||
static_assert(State < InfectionState::Count, "State must be a a valid InfectionState."); | ||
return m_subcompartment_numbers[(int)State]; | ||
} | ||
|
||
/** | ||
* @brief Gets the index of the first subcompartment of an infection state. | ||
* | ||
* In a simulation, the number of individuals in the subcompartments are stored in vectors. | ||
* Accordingly, the index of the first subcompartment of State in such a vector is returned. | ||
* @tparam State: Infection state for which the index should be returned. | ||
* @return Index of the first subcompartment for a vector with one entry per subcompartment. | ||
*/ | ||
template <InfectionState State> | ||
static constexpr unsigned int get_first_index() | ||
{ | ||
static_assert(State < InfectionState::Count, "State must be a a valid InfectionState."); | ||
unsigned int index = 0; | ||
for (int i = 0; i < (int)(State); i++) { | ||
index = index + m_subcompartment_numbers[i]; | ||
} | ||
return index; | ||
} | ||
|
||
static constexpr unsigned int Count{(... + Ns)}; | ||
|
||
private: | ||
static constexpr const std::array<unsigned int, sizeof...(Ns)> m_subcompartment_numbers{ | ||
Ns...}; ///< Vector which defines the number of subcompartments for each infection state of InfectionState. | ||
}; | ||
|
||
} // namespace mio | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.