Esempio n. 1
0
        public void SetNotesTest_Success()
        {
            var scriptBuilder = ScriptBuilder.Create("Test", "Desc", "Tag1", "Tag2");
            var script        = scriptBuilder.SetNotes("Note").Build();

            Assert.That(script.Notes, Is.EqualTo("Note"));
        }
Esempio n. 2
0
        public void SetAuthorTest_Success()
        {
            var scriptBuilder = ScriptBuilder.Create("Test", "Desc", "Tag1", "Tag2");
            var script        = scriptBuilder.SetAuthor("Author").Build();

            Assert.That(script.Author, Is.EqualTo("Author"));
        }
Esempio n. 3
0
        public void SetDocumentTest_Success()
        {
            var scriptBuilder = ScriptBuilder.Create("Test", "Desc", "Tag1", "Tag2");
            var script        = scriptBuilder.SetDocument("Document").Build();

            Assert.That(script.AccordingTo, Is.EqualTo("Document"));
        }
Esempio n. 4
0
        public void SetDescriptionTest_Success()
        {
            var scriptBuilder = ScriptBuilder.Create("Test", "Desc", "Tag1", "Tag2");
            var script        = scriptBuilder.SetDescription("NewDesc").Build();

            Assert.That(script.Description, Is.EqualTo("NewDesc"));
        }
Esempio n. 5
0
        public void SetGroupNameTest_Success()
        {
            var scriptBuilder = ScriptBuilder.Create("Test", "Desc", "Tag1", "Tag2");
            var script        = scriptBuilder.SetGroupName("GroupName").Build();

            Assert.That(script.GroupName, Is.EqualTo("GroupName"));
        }
Esempio n. 6
0
        public void AppendParameterTest_Success()
        {
            var scriptBuilder = ScriptBuilder.Create("Test", "Desc", "Tag1", "Tag2");
            var parameter     = Mock.Of <IParameter>();

            var script = scriptBuilder.AppendParameter(parameter).Build();

            Assert.That(script.Parameters.Count, Is.EqualTo(1));
        }
Esempio n. 7
0
        public void ConstructorTest_Success()
        {
            var script = ScriptBuilder.Create("Test", "Desc", "Tag1", "Tag2").Build();

            Assert.That(script.Name, Is.EqualTo("Test"));
            Assert.That(script.Description, Is.EqualTo("Desc"));
            CollectionAssert.Contains(script.Tags, "Tag1");
            CollectionAssert.Contains(script.Tags, "Tag2");
        }
Esempio n. 8
0
        public void AppendTagsTest_Success()
        {
            var scriptBuilder = ScriptBuilder.Create("Test", "Desc", "Tag1", "Tag2");
            var script        = scriptBuilder.AppendTags("Tag3", "Tag4").Build();

            CollectionAssert.Contains(script.Tags, "Tag1");
            CollectionAssert.Contains(script.Tags, "Tag2");
            CollectionAssert.Contains(script.Tags, "Tag3");
            CollectionAssert.Contains(script.Tags, "Tag4");
        }
Esempio n. 9
0
        private object CalculateScript(SI.Script scriptData, FunctionArgs functionArgs, IParameterRepository parameterRepository)
        {
            var script = ScriptBuilder.Create(
                scriptData.Name,
                scriptData.Description,
                new string[0])
                         .Build();

            script.Parameters = GetParameters(scriptData, parameterRepository).ToList();

            var calculationEngine = new CalculationEngine(script);

            IDictionary <string, object> parameterValues = GetParametersValues(functionArgs);

            calculationEngine.Calculate(parameterValues);
            IncludeParameterValues(script, parameterValues);

            SetPrefixes(functionArgs, script);

            return(true);
        }
        public void NewlyCreatedScriptTest_Success()
        {
            var scriptBuilder = ScriptBuilder.Create(name: "Mean compresive strength of concrete at 28 days",
                                                     description: "Calculate mean compressive strength of concrete at 28 days. Base on [PN-EN-1992-1-1:2002 Table 3.1].",
                                                     "Eurocode 1992", "Concrete", "Materials", "Strength", "Compressive");

            scriptBuilder.SetDocument("PN-EN-1992-1-1:2002")
            .SetAuthor("Konrad Kania")
            .SetGroupName("Eurocode 2")
            .AppendParameter(new Parameter()
            {
                Number = 1,
                Name   = "f_ck_",
                VisibilityValidator = "[f_ck_]>0",
                Description         = "Characteristic compressive cylinder strength of concrete at 28 days.",
                ValueType           = ValueTypes.Number,
                Context             = ParameterOptions.Editable | ParameterOptions.Visible,
                Unit = "MPa"
            })
            .AppendParameter(new Parameter()
            {
                Number = 2,
                Name   = "f_cm_",
                VisibilityValidator = "[f_cm_]>0",
                Description         = "Mean compressive strength at 28 days.",
                Value     = "[f_ck_]+8",
                ValueType = ValueTypes.Number,
                Context   = ParameterOptions.Calculation | ParameterOptions.Visible,
                Unit      = "MPa"
            });

            var script = scriptBuilder.Build();

            var calculationEngine = new CalculationEngine(script);

            calculationEngine.CalculateFromText("[f_ck_]=30");

            Assert.That(38, Is.EqualTo(script.GetParameterByName("f_cm_").Value));
        }
Esempio n. 11
0
        public void MomentOfInteriaScriptTest_Success()
        {
            var scriptBuilder = ScriptBuilder.Create(name: "Moment of interia for rectangle",
                                                     description: "Calculate moment of interia for rectangle",
                                                     "Section", "Moment of interia", "Rectangle");

            scriptBuilder.AppendParameter(new Parameter()
            {
                Number    = 1,
                Name      = "b",
                ValueType = ValueTypes.Number,
                Context   = ParameterOptions.Editable | ParameterOptions.Visible
            })
            .AppendParameter(new Parameter()
            {
                Number    = 2,
                Name      = "h",
                ValueType = ValueTypes.Number,
                Context   = ParameterOptions.Editable | ParameterOptions.Visible
            });

            scriptBuilder.AppendParameter(new Parameter()
            {
                Number    = 3,
                Name      = "I",
                Value     = "[b]*Pow([h],3)/12",
                ValueType = ValueTypes.Number,
                Context   = ParameterOptions.Calculation | ParameterOptions.Visible
            });

            var script            = scriptBuilder.Build();
            var calculationEngine = new CalculationEngine(script);

            calculationEngine.CalculateFromText("[b]=50,[h]=70");

            Assert.That(1429166.667, Is.EqualTo(script.GetParameterByName("I").Value).Within(0.001));
        }
Esempio n. 12
0
        public void CreationTest_Success()
        {
            var scriptBuilder = ScriptBuilder.Create(name: "Steel tension",
                                                     description: "Calculate tension resistance. Base on [PN-EN-1993-1-1:2005 6.2.3.(2)a)].",
                                                     "Eurocode 1993", "Steel", "Tension", "Resistance");

            scriptBuilder.SetAuthor("Konrad Kania");
            scriptBuilder.SetDocument("PN-EN-1993-1-1:2005");
            scriptBuilder.SetGroupName("Eurocode 3");
            scriptBuilder.SetNotes("Net area not included.");

            scriptBuilder
            .AppendParameter(new Parameter()
            {
                Number      = 1,
                Name        = "N_Ed_",
                Description = "Normal design force at calculated position.",
                ValueType   = ValueTypes.Number,
                Context     = ParameterOptions.Editable | ParameterOptions.Visible,
                Unit        = "kN"
            })
            .AppendParameter(new Parameter()
            {
                Number      = 2,
                Name        = "A",
                Description = "Area of the section.",
                ValueType   = ValueTypes.Number,
                Context     = ParameterOptions.Editable | ParameterOptions.Visible,
                Unit        = "cm^2^"
            })
            .AppendParameter(new Parameter()
            {
                Number       = 3,
                Name         = "f_y_",
                Description  = "Yield strength.",
                ValueType    = ValueTypes.Number,
                ValueOptions = new List <ValueOption>()
                {
                    new ValueOption(235),
                    new ValueOption(275),
                    new ValueOption(355),
                    new ValueOption(420),
                    new ValueOption(440),
                    new ValueOption(460),
                    new ValueOption(null),
                },
                Context = ParameterOptions.Editable | ParameterOptions.Visible,
                Unit    = "MPa"
            })
            .AppendParameter(new Parameter()
            {
                Number      = 4,
                Name        = "γ_M0_",
                Description = "Partial safety factor.",
                Value       = 1.0,
                ValueType   = ValueTypes.Number,
                Context     = ParameterOptions.StaticData,
                Unit        = ""
            })
            .AppendParameter(new Parameter()
            {
                Number      = 5,
                Name        = "N_pl,Rd_",
                Value       = "[A]*[f_y_]/[γ_M0_]/10",
                Description = "Design plastic resistance of the gross cross-section.",
                ValueType   = ValueTypes.Number,
                Context     = ParameterOptions.Calculation | ParameterOptions.Visible,
                Unit        = "kN"
            });

            scriptBuilder.AppendParameter(new Parameter()
            {
                Number      = 27,
                Name        = "Resistance",
                Value       = "[N_Ed_]/[N_pl,Rd_]*100",
                Description = "Resistance of the element loaded with normal force.",
                ValueType   = ValueTypes.Number,
                Context     = ParameterOptions.Calculation | ParameterOptions.Visible,
                Unit        = "%"
            });

            var script = scriptBuilder.Build();

            var calculationEngine = new CalculationEngine(script);

            calculationEngine.CalculateFromText("[A]=60|[f_y_]=235|[N_Ed_]=1400");

            Assert.That(script.GetParameterByName("N_pl,Rd_").Value, Is.EqualTo(1410).Within(0.000001));
            Assert.That(script.GetParameterByName("Resistance").Value, Is.EqualTo(99.29078).Within(0.000001));
        }
Esempio n. 13
0
        public void NewlyCreatedScriptTest_Success()
        {
            var scriptBuilder = ScriptBuilder.Create(name: "Compressive strength of concrete at an age",
                                                     description: "Calculate compressive strength of concrete at an age. Base on [PN-EN-1992-1-1:2002 3.1.2].",
                                                     "Eurocode 1992", "Concrete", "Materials", "Strength", "Time", "Compressive");

            var cementTypes = new List <ValueOption>
            {
                new ValueOption(value: "CEM 42,5R",
                                description: "Rapid hardening high strength cements (R)."),
                new ValueOption(value: "CEM 52,5N",
                                description: "Rapid hardening high strength cements (R)."),
                new ValueOption(value: "CEM 52,5R",
                                description: "Rapid hardening high strength cements (R)."),
                new ValueOption(value: "CEM 32,5R",
                                description: "Normal and rapid hardening cements (N)."),
                new ValueOption(value: "CEM 42,5",
                                description: "Normal and rapid hardening cements (N)."),
                new ValueOption(value: "CEM 32,5N",
                                description: "Slow hardening cements (S).")
            };

            scriptBuilder.AppendParameter(new Parameter()
            {
                Number = 1,
                Name   = "f_ck_",
                VisibilityValidator = "[f_ck_]>0",
                Description         = "Characteristic compressive cylinder strength of concrete at 28 days.",
                ValueType           = ValueTypes.Number,
                Context             = ParameterOptions.Editable | ParameterOptions.Visible,
                Unit = "MPa"
            })
            .AppendParameter(new Parameter()
            {
                Number = 2,
                Name   = "f_cm_",
                VisibilityValidator = "[f_cm_]>0",
                Description         = "Mean compressive strength at 28 days.",
                ValueType           = ValueTypes.Number,
                Context             = ParameterOptions.Editable | ParameterOptions.Visible,
                Unit = "MPa",
            })
            .AppendParameter(new Parameter()
            {
                Number       = 3,
                Name         = "cement_type_",
                Description  = "Type of cement.",
                ValueOptions = cementTypes,
                ValueType    = ValueTypes.Text,
                Context      = ParameterOptions.Editable | ParameterOptions.Visible,
                Unit         = "-"
            })
            .AppendParameter(new Parameter()
            {
                Number = 4,
                Name   = "t",
                VisibilityValidator = "[t]>3",
                Description         = "Age of the concrete in days.",
                ValueType           = ValueTypes.Number,
                Context             = ParameterOptions.Editable | ParameterOptions.Visible,
                Unit = "day"
            });

            scriptBuilder.AppendParameter(new Parameter()
            {
                Number = 10,
                Name   = "s",
                Value  = "if(in([cement_type_],'CEM 42,5R','CEM 52,5N', 'CEM 52,5R') == true,0.2," +
                         "if(in([cement_type_],'CEM 32,5R','CEM 42,5') == true,0.25," +
                         "if(in([cement_type_],'CEM 32,5N') == true,0.38, ERROR('Invalid cement type.'))))",
                Description = "Coefficient which depends on the type of cement.",
                ValueType   = ValueTypes.Number,
                Context     = ParameterOptions.Calculation | ParameterOptions.Visible,
                Unit        = "-"
            });

            scriptBuilder.AppendParameter(new Parameter()
            {
                Number      = 11,
                Name        = "β_cc_(t)",
                Value       = "Exp([s]*(1-Sqrt(28/[t])))",
                Description = "Coefficient which depends on the age of the concrete t.",
                ValueType   = ValueTypes.Number,
                Context     = ParameterOptions.Calculation | ParameterOptions.Visible,
                Unit        = "-"
            });

            scriptBuilder.AppendParameter(new Parameter()
            {
                Number      = 12,
                Name        = "f_cm_(t)",
                Value       = "[β_cc_(t)]*[f_cm_]",
                Description = "Mean concrete compressive strength at an age of t days.",
                ValueType   = ValueTypes.Number,
                Context     = ParameterOptions.Calculation | ParameterOptions.Visible,
                Unit        = "MPa"
            });

            scriptBuilder.AppendParameter(new Parameter()
            {
                Number      = 13,
                Name        = "f_ck_(t)",
                Value       = "if([t]>=28,[f_ck_],if([t]>3,[f_cm_(t)]-8,ERROR('Not even 3 days.')))",
                Description = "Concrete compressive strength at time t.",
                ValueType   = ValueTypes.Number,
                Context     = ParameterOptions.Calculation | ParameterOptions.Visible,
                Unit        = "MPa"
            });

            var script = scriptBuilder.Build();

            var calculationEngine = new CalculationEngine(script);

            calculationEngine.CalculateFromText("[f_ck_]=30|[f_cm_]=38|[cement_type_]=CEM 42,5R|[t]=5");

            Assert.That(0.2, Is.EqualTo(script.GetParameterByName("s").Value).Within(0.000001));
            Assert.That(0.760874, Is.EqualTo(script.GetParameterByName("β_cc_(t)").Value).Within(0.000001));
            Assert.That(28.913244, Is.EqualTo(script.GetParameterByName("f_cm_(t)").Value).Within(0.000001));
            Assert.That(20.913244, Is.EqualTo(script.GetParameterByName("f_ck_(t)").Value).Within(0.000001));
        }
Esempio n. 14
0
        public void NewlyCreatedScriptTest_Success()
        {
            var scriptBuilder = ScriptBuilder.Create(name: "Shear resistance without shear reinforcement",
                                                     description: "Calculate shear resistance without shear reinforcement. Base on [PN-EN-1992-1-1:2002 6.2.2].",
                                                     "Eurocode 1992", "Concrete", "Shear", "Resistance");

            scriptBuilder
            .AppendParameter(new Parameter()
            {
                Number      = 1,
                Name        = "V_Ed_",
                Description = "Shear force at calculated position.",
                ValueType   = ValueTypes.Number,
                Context     = ParameterOptions.Editable | ParameterOptions.Visible,
                Unit        = "kN"
            })
            .AppendParameter(new Parameter()
            {
                Number      = 2,
                Name        = "f_ck_",
                Description = "Mean compressive strength at 28 days.",
                ValueType   = ValueTypes.Number,
                Context     = ParameterOptions.Editable | ParameterOptions.Visible,
                Unit        = "MPa"
            })
            .AppendParameter(new Parameter()
            {
                Number      = 4,
                Name        = "b_w_",
                Description = "Section width.",
                ValueType   = ValueTypes.Number,
                Context     = ParameterOptions.Editable | ParameterOptions.Visible,
                Unit        = "mm"
            })
            .AppendParameter(new Parameter()
            {
                Number      = 5,
                Name        = "d",
                Description = "Effective depth of a cross-section.",
                ValueType   = ValueTypes.Number,
                Context     = ParameterOptions.Editable | ParameterOptions.Visible,
                Unit        = "mm"
            })
            .AppendParameter(new Parameter()
            {
                Number      = 6,
                Name        = "A_sl_",
                Description = "Area of the tensile reinforcement, which extends ≥ (lbd + d) beyond the section considered.",
                ValueType   = ValueTypes.Number,
                Context     = ParameterOptions.Editable | ParameterOptions.Visible,
                Unit        = "cm^2^"
            })
            .AppendParameter(new Parameter()
            {
                Number      = 7,
                Name        = "N_Ed_",
                Description = "Axial force in the cross-section due to loading or prestressing in newtons (NEd>0 for compression)." +
                              " The influence of imposed deformations on NEd may be ignored.",
                Value     = 0,
                ValueType = ValueTypes.Number,
                Context   = ParameterOptions.Editable | ParameterOptions.Visible,
                Unit      = "N"
            })
            .AppendParameter(new Parameter()
            {
                Number      = 8,
                Name        = "A_c_",
                Description = "Area of concrete cross section [mm2].",
                ValueType   = ValueTypes.Number,
                Context     = ParameterOptions.Editable | ParameterOptions.Visible,
                Unit        = "mm^2^"
            })
            .AppendParameter(new Parameter()
            {
                Number      = 10,
                Name        = "k_1_",
                Value       = 0.15,
                Description = "Coefficient",
                ValueType   = ValueTypes.Number,
                Context     = ParameterOptions.StaticData,
                Unit        = "-"
            })
            .AppendParameter(new Parameter()
            {
                Number      = 11,
                Name        = "γ_c_",
                Value       = 1.4,
                Description = "Partial factors for concrete.",
                ValueType   = ValueTypes.Number,
                Context     = ParameterOptions.StaticData,
                Unit        = "-"
            });

            scriptBuilder.AppendParameter(new Parameter()
            {
                Number      = 20,
                Name        = "C_Rd,c_",
                Value       = "0.18/[γ_c_]",
                Description = "Coefficient.",
                ValueType   = ValueTypes.Number,
                Context     = ParameterOptions.Calculation | ParameterOptions.Visible,
                Unit        = "-"
            });

            scriptBuilder.AppendParameter(new Parameter()
            {
                Number      = 21,
                Name        = "k",
                Value       = "Min(1+Sqrt(200/[d]),2)",
                Description = "Coefficient.",
                ValueType   = ValueTypes.Number,
                Context     = ParameterOptions.Calculation | ParameterOptions.Visible,
                Unit        = "-"
            });

            scriptBuilder.AppendParameter(new Parameter()
            {
                Number      = 22,
                Name        = "ρ_l_",
                Value       = "Min(0.02,[A_sl_]/([b_w_]*[d]))",
                Description = "Reinforcement ratio for longitudinal reinforcement.",
                ValueType   = ValueTypes.Number,
                Context     = ParameterOptions.Calculation | ParameterOptions.Visible,
                Unit        = "-"
            });

            scriptBuilder.AppendParameter(new Parameter()
            {
                Number      = 23,
                Name        = "f_cd_",
                Value       = "[f_ck_]/[γ_c_]",
                Description = "Design value of concrete compressive strength.",
                ValueType   = ValueTypes.Number,
                Context     = ParameterOptions.Calculation | ParameterOptions.Visible,
                Unit        = "MPa"
            });

            scriptBuilder.AppendParameter(new Parameter()
            {
                Number      = 24,
                Name        = "σ_cp_",
                Value       = "Min([N_Ed_]/[A_c_],0.2*[f_cd_])",
                Description = "Compressive stress in the concrete from axial load or prestressing.",
                ValueType   = ValueTypes.Number,
                Context     = ParameterOptions.Calculation | ParameterOptions.Visible,
                Unit        = "MPa"
            });

            scriptBuilder.AppendParameter(new Parameter()
            {
                Number      = 25,
                Name        = "v_min_",
                Value       = "0.035*Pow([k],3/2)*Pow([f_ck_],1/2)",
                Description = "Coefficient.",
                ValueType   = ValueTypes.Number,
                Context     = ParameterOptions.Calculation | ParameterOptions.Visible,
                Unit        = "MPa"
            });

            scriptBuilder.AppendParameter(new Parameter()
            {
                Number = 26,
                Name   = "V_Rd,c_",
                Value  = "Max(([v_min_]+[k_1_]*[σ _cp_])*[b_w_]*[d]," +
                         "([C_Rd,c_]*[k]*Pow(100*[ρ_l_]*[f_ck_],1/3)+[k_1_]*[σ _cp_])*[b_w_]*[d])" +
                         "/1000",
                Description = "Design value for the shear resistance.",
                ValueType   = ValueTypes.Number,
                Context     = ParameterOptions.Calculation | ParameterOptions.Visible,
                Unit        = "kN"
            });

            scriptBuilder.AppendParameter(new Parameter()
            {
                Number      = 27,
                Name        = "Resistance",
                Value       = "[V_Ed_]/[V_Rd,c_]*100",
                Description = "Resistance of the element without shear reinforcement.",
                ValueType   = ValueTypes.Number,
                Context     = ParameterOptions.Calculation | ParameterOptions.Visible,
                Unit        = "%"
            });

            var script = scriptBuilder.Build();

            var calculationEngine = new CalculationEngine(script);

            calculationEngine.CalculateFromText("[V_Ed_]=100|[f_ck_]=30|[b_w_]=240|[d]=461|[A_sl_]=339|[N_Ed_]=100|[A_c_]=150000");

            Assert.That(0.128571, Is.EqualTo(script.GetParameterByName("C_Rd,c_").Value).Within(0.000001));
            Assert.That(1.658664, Is.EqualTo(script.GetParameterByName("k").Value).Within(0.000001));
            Assert.That(0.003063, Is.EqualTo(script.GetParameterByName("ρ_l_").Value).Within(0.000001));
            Assert.That(21.428571, Is.EqualTo(script.GetParameterByName("f_cd_").Value).Within(0.000001));
            Assert.That(0.000666, Is.EqualTo(script.GetParameterByName("σ_cp_").Value).Within(0.000001));
            Assert.That(0.409512, Is.EqualTo(script.GetParameterByName("v_min_").Value).Within(0.000001));
            Assert.That(49.436619, Is.EqualTo(script.GetParameterByName("V_Rd,c_").Value).Within(0.000001));
            Assert.That(202.279, Is.EqualTo(script.GetParameterByName("Resistance").Value).Within(0.001));
        }