Example #1
0
        public void InitGasConnector(Model cm)
        {
            // find the two gascompartment names which this connector connects
            string[] comps = compartments.Split("_");
            comp1_name = comps[0];
            comp2_name = comps[1];

            // store reference to the model
            currentModel = cm;

            // find the gas compartments which are connected by this connector
            foreach (GasCompartment comp in currentModel.modelDefinition.gas_compartments)
            {
                if (comp.name == comp1_name)
                {
                    comp1 = comp;
                }
                if (comp.name == comp2_name)
                {
                    comp2 = comp;
                }
            }

            currentModel.modelInterface.StatusMessage = $"Initialized gas compartment connector {name} by connecting {comp1.name} to {comp2.name}";
        }
        public void InitializeExchanger(Model cm)
        {
            string[] comps = compartments.Split("_");
            comp_blood_name = comps[0];
            comp_gas_name   = comps[1];

            currentModel = cm;

            foreach (BloodCompartment blood_comp in currentModel.modelDefinition.blood_compartments)
            {
                if (blood_comp.name == comp_blood_name)
                {
                    comp_blood = blood_comp;
                }
            }

            foreach (GasCompartment gas_comp in currentModel.modelDefinition.gas_compartments)
            {
                if (gas_comp.name == comp_gas_name)
                {
                    comp_gas = gas_comp;
                }
            }



            currentModel.modelInterface.StatusMessage = $"Initialized gas exchange unit {name} : {comp_blood.name} to {comp_gas.name}";
        }
        public void InitializeDiffusor(Model cm)
        {
            string[] comps = compartments.Split("_");
            comp1_name = comps[0];
            comp2_name = comps[1];

            currentModel = cm;

            foreach (BloodCompartment blood_comp in currentModel.modelDefinition.blood_compartments)
            {
                if (blood_comp.name == comp1_name)
                {
                    comp1_blood = blood_comp;
                }
                if (blood_comp.name == comp2_name)
                {
                    comp2_blood = blood_comp;
                }
            }

            foreach (GasCompartment gas_comp in currentModel.modelDefinition.gas_compartments)
            {
                if (gas_comp.name == comp1_name)
                {
                    comp1_gas = gas_comp;
                }
                if (gas_comp.name == comp2_name)
                {
                    comp2_gas = gas_comp;
                }
            }

            currentModel.modelInterface.StatusMessage = $"Initialized diffusor {name} : compartment {comp1_name} to compartment {comp2_name}";
        }
        public void GasIn(double dvol, GasCompartment compFrom)
        {
            if (has_fixed_composition == 0)
            {
                // change the volume
                vol_current += dvol;
                if (vol_current < 0)
                {
                    vol_current = 0.01;
                }

                // convert the concentrations
                double vol_current_l = vol_current / 1000.0;
                double dvol_l        = dvol / 1000.0;

                // change the gas concentrations
                double dtotal = dvol_l * (compFrom.ctotal - ctotal);
                ctotal = ((ctotal * vol_current_l) + dtotal) / vol_current_l;

                double dco2 = dvol_l * (compFrom.co2 - co2);
                co2 = ((co2 * vol_current_l) + dco2) / vol_current_l;

                double dcco2 = dvol_l * (compFrom.cco2 - cco2);
                cco2 = ((cco2 * vol_current_l) + dcco2) / vol_current_l;

                double dcn2 = dvol_l * (compFrom.cn2 - cn2);
                cn2 = ((cn2 * vol_current_l) + dcn2) / vol_current_l;

                double dcother = dvol_l * (compFrom.cother - cother);
                cother = ((cother * vol_current_l) + dcother) / vol_current_l;

                // update the composition
                fo2    = co2 / ctotal;
                fco2   = cco2 / ctotal;
                fn2    = cn2 / ctotal;
                fother = cother / ctotal;

                po2    = fo2 * (pres_current - (pres_current * fh2o));
                pco2   = fco2 * (pres_current - (pres_current * fh2o));
                pn2    = fn2 * (pres_current - (pres_current * fh2o));
                pother = fother * (pres_current - (pres_current * fh2o));
            }
            else
            {
                CalculateComposition();
            }
        }