projects/biogears/src/engine/Systems/Tissue.cpp
void Tissue::CalculatePulmonaryCapillarySubstanceTransfer()
{
  SEPatient& Patient = m_data.GetPatient();
  const BioGearsConfiguration& Configuration = m_data.GetConfiguration();

  double AlveoliSurfaceArea_cm2 = Patient.GetAlveoliSurfaceArea(AreaUnit::cm2);
  double PulmonaryCapillaryCoverage = Configuration.GetStandardPulmonaryCapillaryCoverage();
  double DiffusionSurfaceArea_cm2 = AlveoliSurfaceArea_cm2 * PulmonaryCapillaryCoverage;
  double RightLungRatio = Patient.GetRightLungRatio().GetValue();

  double StandardDiffusingCapacityOfOxygen_mLPersPermmHg = (DiffusionSurfaceArea_cm2 * Configuration.GetStandardOxygenDiffusionCoefficient(AreaPerTimePressureUnit::cm2_Per_s_mmHg)) / Configuration.GetStandardDiffusionDistance(LengthUnit::cm);
  double DiffusingCapacityPerSide_mLPerSPermmHg = StandardDiffusingCapacityOfOxygen_mLPersPermmHg;

  for (SESubstance* sub : m_data.GetSubstances().GetActiveGases()) {
    sub->GetAlveolarTransfer().SetValue(0, VolumePerTimeUnit::mL_Per_s);
    sub->GetDiffusingCapacity().SetValue(0, VolumePerTimePressureUnit::mL_Per_s_mmHg);

    //Left Side Alveoli Transfer
    DiffusingCapacityPerSide_mLPerSPermmHg = StandardDiffusingCapacityOfOxygen_mLPersPermmHg * (1 - RightLungRatio);
    AlveolarPartialPressureGradientDiffusion(*m_LeftAlveoli, *m_LeftPulmonaryCapillaries, *sub, DiffusingCapacityPerSide_mLPerSPermmHg, m_Dt_s);

    //Right Side Alveoli Transfer
    DiffusingCapacityPerSide_mLPerSPermmHg = StandardDiffusingCapacityOfOxygen_mLPersPermmHg * RightLungRatio;
    AlveolarPartialPressureGradientDiffusion(*m_RightAlveoli, *m_RightPulmonaryCapillaries, *sub, DiffusingCapacityPerSide_mLPerSPermmHg, m_Dt_s);

    if (m_LeftAlveoli->GetSubstanceQuantity(*sub)->GetVolume(VolumeUnit::mL) < 0.0 || m_LeftPulmonaryCapillaries->GetSubstanceQuantity(*sub)->GetMass(MassUnit::ug) < 0.0 || m_RightAlveoli->GetSubstanceQuantity(*sub)->GetVolume(VolumeUnit::mL) < 0.0 || m_RightPulmonaryCapillaries->GetSubstanceQuantity(*sub)->GetMass(MassUnit::ug) < 0.0) {
      Fatal("Diffusion mass cannot be negative");
    }
  }
  m_LeftAlveoli->Balance(BalanceGasBy::Volume);
  m_RightAlveoli->Balance(BalanceGasBy::Volume);
}
//--------------------------------------------------------------------------------------------------
/// \brief
/// Generic substance alveoli transfer calculations
///
/// \param  vSubstances
/// Alveoli transfer is completed for each substance in the input vector of substances.
///
/// \details
/// The mass transferred between the alveoli and the capillaries is calculated for all substances in the
/// input vector. The concentration gradient between the alveoli and the capillaries, the substance-specific
/// alveoli transfer factor, the pulmonary capillary flow, the time step, and the patient-specific alveoli
/// transfer factor are used to calculate the mass transfer. The mass in both the alveoli and the
/// capillaries is then updated. This represents gases moving from the respiratory to the cardiovascular
/// systems and vice versa.
//--------------------------------------------------------------------------------------------------
\brief
Generic substance alveoli transfer calculations

\param  vSubstances
Alveoli transfer is completed for each substance in the input vector of substances.

\details
The mass transferred between the alveoli and the capillaries is calculated for all substances in the
input vector. The concentration gradient between the alveoli and the capillaries, the substance-specific
alveoli transfer factor, the pulmonary capillary flow, the time step, and the patient-specific alveoli
transfer factor are used to calculate the mass transfer. The mass in both the alveoli and the
capillaries is then updated. This represents gases moving from the respiratory to the cardiovascular
systems and vice versa.
\ brief Generic substance alveoli transfer calculations \ param vSubstances Alveoli transfer is completed for each substance in the input vector of substances . \ details The mass transferred between the alveoli and the capillaries is calculated for all substances in the input vector . The concentration gradient between the alveoli and the capillaries the substance - specific alveoli transfer factor the pulmonary capillary flow the time step and the patient - specific alveoli transfer factor are used to calculate the mass transfer . The mass in both the alveoli and the capillaries is then updated . This represents gases moving from the respiratory to the cardiovascular systems and vice versa .
void Tissue::CalculatePulmonaryCapillarySubstanceTransfer()
{
  SEPatient& Patient = m_data.GetPatient();
  const BioGearsConfiguration& Configuration = m_data.GetConfiguration();
  double AlveoliSurfaceArea_cm2 = Patient.GetAlveoliSurfaceArea(AreaUnit::cm2);
  double PulmonaryCapillaryCoverage = Configuration.GetStandardPulmonaryCapillaryCoverage();
  double DiffusionSurfaceArea_cm2 = AlveoliSurfaceArea_cm2 * PulmonaryCapillaryCoverage;
  double RightLungRatio = Patient.GetRightLungRatio().GetValue();
  double StandardDiffusingCapacityOfOxygen_mLPersPermmHg = (DiffusionSurfaceArea_cm2 * Configuration.GetStandardOxygenDiffusionCoefficient(AreaPerTimePressureUnit::cm2_Per_s_mmHg)) / Configuration.GetStandardDiffusionDistance(LengthUnit::cm);
  double DiffusingCapacityPerSide_mLPerSPermmHg = StandardDiffusingCapacityOfOxygen_mLPersPermmHg;
  for (SESubstance* sub : m_data.GetSubstances().GetActiveGases()) {
    sub->GetAlveolarTransfer().SetValue(0, VolumePerTimeUnit::mL_Per_s);
    sub->GetDiffusingCapacity().SetValue(0, VolumePerTimePressureUnit::mL_Per_s_mmHg);
    DiffusingCapacityPerSide_mLPerSPermmHg = StandardDiffusingCapacityOfOxygen_mLPersPermmHg * (1 - RightLungRatio);
    AlveolarPartialPressureGradientDiffusion(*m_LeftAlveoli, *m_LeftPulmonaryCapillaries, *sub, DiffusingCapacityPerSide_mLPerSPermmHg, m_Dt_s);
    DiffusingCapacityPerSide_mLPerSPermmHg = StandardDiffusingCapacityOfOxygen_mLPersPermmHg * RightLungRatio;
    AlveolarPartialPressureGradientDiffusion(*m_RightAlveoli, *m_RightPulmonaryCapillaries, *sub, DiffusingCapacityPerSide_mLPerSPermmHg, m_Dt_s);
    if (m_LeftAlveoli->GetSubstanceQuantity(*sub)->GetVolume(VolumeUnit::mL) < 0.0 || m_LeftPulmonaryCapillaries->GetSubstanceQuantity(*sub)->GetMass(MassUnit::ug) < 0.0 || m_RightAlveoli->GetSubstanceQuantity(*sub)->GetVolume(VolumeUnit::mL) < 0.0 || m_RightPulmonaryCapillaries->GetSubstanceQuantity(*sub)->GetMass(MassUnit::ug) < 0.0) {
      Fatal("Diffusion mass cannot be negative");
    }
  }
  m_LeftAlveoli->Balance(BalanceGasBy::Volume);
  m_RightAlveoli->Balance(BalanceGasBy::Volume);
}
void Tissue :: CalculatePulmonaryCapillarySubstanceTransfer ( ) { SEPatient & Patient = m_data . GetPatient ( ) ; const BioGearsConfiguration & Configuration = m_data . GetConfiguration ( ) ; double AlveoliSurfaceArea_cm2 = Patient . GetAlveoliSurfaceArea ( AreaUnit :: cm2 ) ; double PulmonaryCapillaryCoverage = Configuration . GetStandardPulmonaryCapillaryCoverage ( ) ; double DiffusionSurfaceArea_cm2 = AlveoliSurfaceArea_cm2 * PulmonaryCapillaryCoverage ; double RightLungRatio = Patient . GetRightLungRatio ( ) . GetValue ( ) ; double StandardDiffusingCapacityOfOxygen_mLPersPermmHg = ( DiffusionSurfaceArea_cm2 * Configuration . GetStandardOxygenDiffusionCoefficient ( AreaPerTimePressureUnit :: cm2_Per_s_mmHg ) ) / Configuration . GetStandardDiffusionDistance ( LengthUnit :: cm ) ; double DiffusingCapacityPerSide_mLPerSPermmHg = StandardDiffusingCapacityOfOxygen_mLPersPermmHg ; for ( SESubstance * sub : m_data . GetSubstances ( ) . GetActiveGases ( ) ) { sub -> GetAlveolarTransfer ( ) . SetValue ( 0 , VolumePerTimeUnit :: mL_Per_s ) ; sub -> GetDiffusingCapacity ( ) . SetValue ( 0 , VolumePerTimePressureUnit :: mL_Per_s_mmHg ) ; DiffusingCapacityPerSide_mLPerSPermmHg = StandardDiffusingCapacityOfOxygen_mLPersPermmHg * ( 1 - RightLungRatio ) ; AlveolarPartialPressureGradientDiffusion ( * m_LeftAlveoli , * m_LeftPulmonaryCapillaries , * sub , DiffusingCapacityPerSide_mLPerSPermmHg , m_Dt_s ) ; DiffusingCapacityPerSide_mLPerSPermmHg = StandardDiffusingCapacityOfOxygen_mLPersPermmHg * RightLungRatio ; AlveolarPartialPressureGradientDiffusion ( * m_RightAlveoli , * m_RightPulmonaryCapillaries , * sub , DiffusingCapacityPerSide_mLPerSPermmHg , m_Dt_s ) ; if ( m_LeftAlveoli -> GetSubstanceQuantity ( * sub ) -> GetVolume ( VolumeUnit :: mL ) < 0.0 || m_LeftPulmonaryCapillaries -> GetSubstanceQuantity ( * sub ) -> GetMass ( MassUnit :: ug ) < 0.0 || m_RightAlveoli -> GetSubstanceQuantity ( * sub ) -> GetVolume ( VolumeUnit :: mL ) < 0.0 || m_RightPulmonaryCapillaries -> GetSubstanceQuantity ( * sub ) -> GetMass ( MassUnit :: ug ) < 0.0 ) { Fatal ( " " ) ; } } m_LeftAlveoli -> Balance ( BalanceGasBy :: Volume ) ; m_RightAlveoli -> Balance ( BalanceGasBy :: Volume ) ; }
\brief
Generic substance alveoli transfer calculations
\ brief Generic substance alveoli transfer calculations
//Left Side Alveoli Transfer //Right Side Alveoli Transfer