protected override void Context()
        {
            base.Context();

            _root = new Container().WithName("Root");
            var length = new Dimension(new BaseDimensionRepresentation {
                LengthExponent = 1
            }, "Length", "cm");
            var molWeight = new Dimension(new BaseDimensionRepresentation {
                AmountExponent = 1, MassExponent = -1
            }, "MW", "mol/g");

            var explicitFormula = new ExplicitFormula().WithFormulaString("exp(MW)").WithDimension(length);

            explicitFormula.AddObjectPath(new FormulaUsablePath(new[] { "Root", "MW" }).WithAlias("MW").WithDimension(molWeight));


            var pksimPara = new Parameter()
                            .WithName(AppConstants.Parameters.RADIUS_SOLUTE)
                            .WithParentContainer(_root)
                            .WithFormula(explicitFormula)
                            .WithDimension(length);

            new Parameter().WithName("MW").WithParentContainer(_root).WithDimension(molWeight).WithFormula(new ConstantFormula(1));
            explicitFormula.ResolveObjectPathsFor(pksimPara);
        }
        public void TestSerializationQuantityWithExplicitFormula()
        {
            Observer x1 = CreateObject <Observer>().WithName("Quentin").WithDimension(DimensionLength);

            x1.ParentContainer = C1;
            x1.IsFixedValue    = false;
            x1.Persistable     = false;
            x1.Formula         = CreateObject <ConstantFormula>().WithDimension(DimensionLength).WithValue(23.4);

            ExplicitFormula f1 = CreateObject <ExplicitFormula>().WithName("Fortunato").WithDimension(DimensionLength);

            f1.AddObjectPath(ObjectPathFactory.CreateAbsoluteFormulaUsablePath(P1));
            f1.AddObjectPath(ObjectPathFactory.CreateRelativeFormulaUsablePath(P, P0));
            f1.AddObjectPath(ObjectPathFactory.CreateRelativeFormulaUsablePath(P, P2).WithAlias("Pitter"));
            f1.ResolveObjectPathsFor(P);
            f1.FormulaString = "Paul + Peter + Pitter";

            P1.Value = 1.0;
            P0.Value = 10.0;
            P2.Value = 2.0;

            x1.Formula = f1;

            IQuantity x2 = SerializeAndDeserialize(x1);

            x2.ParentContainer = C1;
            x2.Formula.ResolveObjectPathsFor(x2);

            AssertForSpecs.AreEqualQuantity(x2, x1);
        }
        protected override void Context()
        {
            base.Context();
            var sim1   = new Container().WithName("Sim1");
            var c1     = new Container().WithName("A").WithParentContainer(sim1);
            var p1     = new Parameter().WithName("B").WithParentContainer(c1);
            var param1 = new Parameter().WithName("C").WithParentContainer(c1);

            var sim2   = new Container().WithName("Sim2");
            var c2     = new Container().WithName("A").WithParentContainer(sim2);
            var p2     = new Parameter().WithName("B").WithParentContainer(c2);
            var param2 = new Parameter().WithName("C").WithParentContainer(c2);

            var formula1 = new ExplicitFormula("A+B");

            formula1.AddObjectPath(new FormulaUsablePath("Sim1", "A", "B").WithAlias("Same"));
            param1.Formula = formula1;
            formula1.ResolveObjectPathsFor(param1);

            var formula2 = new ExplicitFormula("A+B");

            formula2.AddObjectPath(new FormulaUsablePath("Sim2", "A", "B").WithAlias("Same"));
            param2.Formula = formula2;
            formula2.ResolveObjectPathsFor(param2);

            _object1 = param1;
            _object2 = param2;
        }
Beispiel #4
0
        protected override void Because()
        {
            _model = new Model();
            var root = new Container().WithName("ROOT");

            _model.Root = root;
            var subContainer = new Container().WithName("SUB").WithParentContainer(root);
            var p1Formula    = new ExplicitFormula("P3").WithName("p1Formula");

            p1Formula.AddObjectPath(new FormulaUsablePath(ObjectPath.PARENT_CONTAINER, ObjectPath.PARENT_CONTAINER, "P3").WithAlias("P3"));

            var p2Formula = new ExplicitFormula("P3").WithName("p2Formula");

            p2Formula.AddObjectPath(new FormulaUsablePath(ObjectPath.PARENT_CONTAINER, ObjectPath.PARENT_CONTAINER, "P3").WithAlias("P3"));
            var p3RHSFormula = new ExplicitFormula("P2").WithName("p3RHSFormula");

            p3RHSFormula.AddObjectPath(new FormulaUsablePath(ObjectPath.PARENT_CONTAINER, "SUB", "P2").WithAlias("P2"));

            _parameter1 = new Parameter().WithName("P1").WithFormula(p1Formula);
            _parameter2 = new Parameter().WithName("P2").WithFormula(p2Formula);
            _parameter3 = new Parameter().WithName("P3").WithFormula(new ExplicitFormula("1+2"));
            _parameter3.WithRHS(p3RHSFormula);

            root.Add(_parameter3);
            subContainer.Add(_parameter1);
            subContainer.Add(_parameter2);

            p1Formula.ResolveObjectPathsFor(_parameter1);
            p2Formula.ResolveObjectPathsFor(_parameter2);
            p3RHSFormula.ResolveObjectPathsFor(_parameter3);
        }
        protected override void Context()
        {
            base.Context();

            var lengthDimension = new Dimension(new BaseDimensionRepresentation {
                LengthExponent = 1
            }, AppConstants.DimensionNames.LENGTH, "cm");
            var molWeightDimension = new Dimension(new BaseDimensionRepresentation {
                AmountExponent = 1, MassExponent = -1
            }, "MW", "mol/g");
            var areaDimension = new Dimension(new BaseDimensionRepresentation {
                LengthExponent = 2,
            }, AppConstants.DimensionNames.AREA, "cm²");

            var radiusFormula = new ExplicitFormula()
                                .WithFormulaString("0,0333 * (MW * 1E9) ^ 0,4226 * 1E-8")
                                .WithDimension(lengthDimension);

            radiusFormula.AddObjectPath(new FormulaUsablePath("Root", "MW").WithAlias("MW").WithDimension(molWeightDimension));

            var bsaFormula = new ExplicitFormula()
                             .WithFormulaString("MW ^ 0,4226")
                             .WithDimension(areaDimension);

            bsaFormula.AddObjectPath(new FormulaUsablePath("Root", "MW").WithAlias("MW").WithDimension(molWeightDimension));


            var pksimPara = new Parameter()
                            .WithName(AppConstants.Parameters.RADIUS_SOLUTE)
                            .WithFormula(radiusFormula)
                            .WithDimension(lengthDimension);

            var molweight = new Parameter()
                            .WithName("MW")
                            .WithDimension(molWeightDimension)
                            .WithFormula(new ConstantFormula(1));

            var BSA = new Parameter()
                      .WithName(AppConstants.Parameters.BSA)
                      .WithFormula(bsaFormula)
                      .WithDimension(areaDimension);

            _root = new Container {
                pksimPara, molweight, BSA
            }.WithName("Root");

            radiusFormula.ResolveObjectPathsFor(pksimPara);
            bsaFormula.ResolveObjectPathsFor(BSA);
        }
        public void TestSerializationFormulaWithObjectPathsWithObjectReferences()
        {
            ExplicitFormula x1 = CreateObject <ExplicitFormula>().WithName("Fortunato").WithDimension(DimensionLength);

            x1.AddObjectPath(ObjectPathFactory.CreateAbsoluteFormulaUsablePath(P1));
            x1.AddObjectPath(ObjectPathFactory.CreateRelativeFormulaUsablePath(P, P0));
            x1.AddObjectPath(ObjectPathFactory.CreateRelativeFormulaUsablePath(P, P2).WithAlias("Pitter"));
            x1.ResolveObjectPathsFor(P);

            IFormula x2 = SerializeAndDeserialize(x1);

            x2.ResolveObjectPathsFor(P);

            AssertForSpecs.AreEqualFormula(x2, x1);
        }
        public void TestSerializationWithDependencies()
        {
            ExplicitFormula x1 = CreateObject <ExplicitFormula>().WithName("Fortunato").WithDimension(DimensionLength);

            x1.AddObjectPath(ObjectPathFactory.CreateAbsoluteFormulaUsablePath(P1));
            x1.AddObjectPath(ObjectPathFactory.CreateRelativeFormulaUsablePath(P, P0));
            x1.AddObjectPath(ObjectPathFactory.CreateRelativeFormulaUsablePath(P, P2).WithAlias("Pitter"));
            x1.ResolveObjectPathsFor(P);
            x1.FormulaString = "Paul + Peter + Pitter";

            P1.Value = 1.0;
            P0.Value = 10.0;
            P2.Value = 2.0;

            ExplicitFormula x2 = SerializeAndDeserialize(x1);

            x2.ResolveObjectPathsFor(P);

            AssertForSpecs.AreEqualExplicitFormula(x2, x1);
        }