projects/biogears/src/engine/Controller/BioGearsSubstances.cpp
void BioGearsSubstances::CalculateGenericClearance(double VolumeCleared_mL, SETissueCompartment& tissue, SESubstance& sub, SEScalarMass* cleared)
{
  SELiquidSubstanceQuantity* subQ = m_data.GetCompartments().GetIntracellularFluid(tissue).GetSubstanceQuantity(sub);
  if (subQ == nullptr)
    throw CommonDataModelException("No Substance Quantity found for substance " + sub.GetName());
  //GetMass and Concentration from the compartment
  double mass_ug = subQ->GetMass(MassUnit::ug);
  double concentration_ug_Per_mL;
  SEScalarMassPerVolume concentration;
  if (sub.HasPK()) {
    GeneralMath::CalculateConcentration(subQ->GetMass(), tissue.GetMatrixVolume(), concentration, m_Logger);
    concentration_ug_Per_mL = concentration.GetValue(MassPerVolumeUnit::ug_Per_mL);
  } else {
    concentration_ug_Per_mL = subQ->GetConcentration(MassPerVolumeUnit::ug_Per_mL);
  }

  //Calculate Mass Cleared
  double MassCleared_ug = VolumeCleared_mL * concentration_ug_Per_mL;
  //Ensure mass does not become negative
  mass_ug -= MassCleared_ug;
  if (mass_ug < 0) {
    mass_ug = 0;
  }

  MassCleared_ug = subQ->GetMass(MassUnit::ug) - mass_ug;
  subQ->GetMass().SetValue(mass_ug, MassUnit::ug);
  subQ->Balance(BalanceLiquidBy::Mass);
  subQ->GetMassCleared().IncrementValue(MassCleared_ug, MassUnit::ug);
  if (cleared != nullptr)
    cleared->SetValue(MassCleared_ug, MassUnit::ug);
}
/// --------------------------------------------------------------------------------------------------
/// \brief
/// Calculates the substance mass cleared for a tissue compartment based on a volume
///
/// \param VolumeCleared_mL: the volume of fluid cleared of a substance by some process
/// \param tissue: a tissue compartment
/// \param sub: a substance
/// \param cleared: mass cleared
///
/// \details
/// The volume cleared, the compartment, and the substance are provided to clear the mass of the substance
/// from the node. This generic methodology can be used by other systems to calculate the mass cleared.
//--------------------------------------------------------------------------------------------------
\brief
Calculates the substance mass cleared for a tissue compartment based on a volume

\param VolumeCleared_mL: the volume of fluid cleared of a substance by some process
\param tissue: a tissue compartment
\param sub: a substance
\param cleared: mass cleared

\details
The volume cleared, the compartment, and the substance are provided to clear the mass of the substance
from the node. This generic methodology can be used by other systems to calculate the mass cleared.
\ brief Calculates the substance mass cleared for a tissue compartment based on a volume \ param VolumeCleared_mL : the volume of fluid cleared of a substance by some process \ param tissue : a tissue compartment \ param sub : a substance \ param cleared : mass cleared \ details The volume cleared the compartment and the substance are provided to clear the mass of the substance from the node . This generic methodology can be used by other systems to calculate the mass cleared .
void BioGearsSubstances::CalculateGenericClearance(double VolumeCleared_mL, SETissueCompartment& tissue, SESubstance& sub, SEScalarMass* cleared)
{
  SELiquidSubstanceQuantity* subQ = m_data.GetCompartments().GetIntracellularFluid(tissue).GetSubstanceQuantity(sub);
  if (subQ == nullptr)
    throw CommonDataModelException("No Substance Quantity found for substance " + sub.GetName());
  double mass_ug = subQ->GetMass(MassUnit::ug);
  double concentration_ug_Per_mL;
  SEScalarMassPerVolume concentration;
  if (sub.HasPK()) {
    GeneralMath::CalculateConcentration(subQ->GetMass(), tissue.GetMatrixVolume(), concentration, m_Logger);
    concentration_ug_Per_mL = concentration.GetValue(MassPerVolumeUnit::ug_Per_mL);
  } else {
    concentration_ug_Per_mL = subQ->GetConcentration(MassPerVolumeUnit::ug_Per_mL);
  }
  double MassCleared_ug = VolumeCleared_mL * concentration_ug_Per_mL;
  mass_ug -= MassCleared_ug;
  if (mass_ug < 0) {
    mass_ug = 0;
  }
  MassCleared_ug = subQ->GetMass(MassUnit::ug) - mass_ug;
  subQ->GetMass().SetValue(mass_ug, MassUnit::ug);
  subQ->Balance(BalanceLiquidBy::Mass);
  subQ->GetMassCleared().IncrementValue(MassCleared_ug, MassUnit::ug);
  if (cleared != nullptr)
    cleared->SetValue(MassCleared_ug, MassUnit::ug);
}
void BioGearsSubstances :: CalculateGenericClearance ( double VolumeCleared_mL , SETissueCompartment & tissue , SESubstance & sub , SEScalarMass * cleared ) { SELiquidSubstanceQuantity * subQ = m_data . GetCompartments ( ) . GetIntracellularFluid ( tissue ) . GetSubstanceQuantity ( sub ) ; if ( subQ == nullptr ) throw CommonDataModelException ( " " + sub . GetName ( ) ) ; double mass_ug = subQ -> GetMass ( MassUnit :: ug ) ; double concentration_ug_Per_mL ; SEScalarMassPerVolume concentration ; if ( sub . HasPK ( ) ) { GeneralMath :: CalculateConcentration ( subQ -> GetMass ( ) , tissue . GetMatrixVolume ( ) , concentration , m_Logger ) ; concentration_ug_Per_mL = concentration . GetValue ( MassPerVolumeUnit :: ug_Per_mL ) ; } else { concentration_ug_Per_mL = subQ -> GetConcentration ( MassPerVolumeUnit :: ug_Per_mL ) ; } double MassCleared_ug = VolumeCleared_mL * concentration_ug_Per_mL ; mass_ug -= MassCleared_ug ; if ( mass_ug < 0 ) { mass_ug = 0 ; } MassCleared_ug = subQ -> GetMass ( MassUnit :: ug ) - mass_ug ; subQ -> GetMass ( ) . SetValue ( mass_ug , MassUnit :: ug ) ; subQ -> Balance ( BalanceLiquidBy :: Mass ) ; subQ -> GetMassCleared ( ) . IncrementValue ( MassCleared_ug , MassUnit :: ug ) ; if ( cleared != nullptr ) cleared -> SetValue ( MassCleared_ug , MassUnit :: ug ) ; }
\brief
Calculates the substance mass cleared for a tissue compartment based on a volume
\ brief Calculates the substance mass cleared for a tissue compartment based on a volume
//GetMass and Concentration from the compartment //Calculate Mass Cleared //Ensure mass does not become negative