/// <summary>
        /// Transforms the generic <paramref name="soilProfile"/> into a piping specific
        /// soil profile of type <see cref="PipingSoilProfile"/>.
        /// </summary>
        /// <param name="soilProfile">The soil profile to use in the transformation.</param>
        /// <returns>A new <see cref="PipingSoilProfile"/> based on the given data.</returns>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="soilProfile"/> is <c>null</c>.</exception>
        /// <exception cref="ImportedDataTransformException">Thrown when transformation would not result
        /// in a valid transformed instance.</exception>
        public static PipingSoilProfile Transform(ISoilProfile soilProfile)
        {
            if (soilProfile == null)
            {
                throw new ArgumentNullException(nameof(soilProfile));
            }

            var soilProfile1D = soilProfile as SoilProfile1D;

            if (soilProfile1D != null)
            {
                return(CreatePipingSoilProfile(soilProfile1D));
            }

            var soilProfile2D = soilProfile as SoilProfile2D;

            if (soilProfile2D != null)
            {
                return(CreatePipingSoilProfile(soilProfile2D));
            }

            string errorMessage = string.Format(RiskeerCommonIOResources.SoilProfileTransformer_Cannot_tranform_Type_0_Only_types_Type_1_and_Type_2_are_supported,
                                                soilProfile.GetType().Name,
                                                nameof(SoilProfile1D),
                                                nameof(SoilProfile2D));

            throw new ImportedDataTransformException(errorMessage);
        }
        /// <summary>
        /// Creates a new instance of <see cref="StochasticSoilProfile"/>.
        /// </summary>
        /// <param name="probability">Probability of the stochastic soil profile.</param>
        /// <param name="soilProfile">The soil profile.</param>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="soilProfile"/> is <c>null</c>.</exception>
        public StochasticSoilProfile(double probability, ISoilProfile soilProfile)
        {
            if (soilProfile == null)
            {
                throw new ArgumentNullException(nameof(soilProfile));
            }

            Probability = probability;
            SoilProfile = soilProfile;
        }
        /// <summary>
        /// Transforms all generic <see cref="ISoilProfile"/> into <see cref="PipingSoilProfile"/>.
        /// </summary>
        /// <param name="soilProfile">The soil profile to use in the transformation.</param>
        /// <returns>The transformed piping soil profile.</returns>
        /// <exception cref="ImportedDataTransformException">Thrown when transformation would
        /// not result in a valid transformed instance.</exception>
        private PipingSoilProfile GetTransformedPipingSoilProfile(ISoilProfile soilProfile)
        {
            PipingSoilProfile pipingSoilProfile;

            if (soilProfiles.ContainsKey(soilProfile))
            {
                pipingSoilProfile = soilProfiles[soilProfile];
            }
            else
            {
                pipingSoilProfile = PipingSoilProfileTransformer.Transform(soilProfile);
                soilProfiles.Add(soilProfile, pipingSoilProfile);
            }

            return(pipingSoilProfile);
        }
Exemple #4
0
        /// <summary>
        /// Gets a collection of <see cref="StochasticSoilProfile"/> that contain unique <see cref="ISoilProfile"/>
        /// and sums the probabilities when there are multiple occurrences.
        /// </summary>
        /// <param name="stochasticSoilProfiles">The collection of <see cref="StochasticSoilProfile"/>
        /// to validate.</param>
        /// <param name="soilModelName">The name of the soil model.</param>
        /// <returns>A collection of unique <see cref="StochasticSoilProfile"/> to transform.</returns>
        /// <exception cref="ArgumentNullException">Thrown when any parameter is <c>null</c>.</exception>
        public static IEnumerable <StochasticSoilProfile> GetUniqueStochasticSoilProfiles(IEnumerable <StochasticSoilProfile> stochasticSoilProfiles,
                                                                                          string soilModelName)
        {
            if (stochasticSoilProfiles == null)
            {
                throw new ArgumentNullException(nameof(stochasticSoilProfiles));
            }

            if (soilModelName == null)
            {
                throw new ArgumentNullException(nameof(soilModelName));
            }

            var uniqueStochasticSoilProfiles = new Dictionary <ISoilProfile, StochasticSoilProfile>();

            foreach (StochasticSoilProfile stochasticSoilProfile in stochasticSoilProfiles)
            {
                ISoilProfile soilProfile = stochasticSoilProfile.SoilProfile;
                if (uniqueStochasticSoilProfiles.ContainsKey(soilProfile))
                {
                    StochasticSoilProfile currentStochasticSoilProfile = uniqueStochasticSoilProfiles[soilProfile];

                    double newProbability = currentStochasticSoilProfile.Probability + stochasticSoilProfile.Probability;
                    uniqueStochasticSoilProfiles[soilProfile] = new StochasticSoilProfile(newProbability, soilProfile);

                    log.Warn(string.Format(Resources.StochasticSoilProfileHelper_GetUniqueStochasticSoilProfiles_StochasticSoilProfile_0_has_multiple_occurences_in_SoilModel_1_Probability_Summed,
                                           currentStochasticSoilProfile.SoilProfile.Name,
                                           soilModelName));
                }
                else
                {
                    uniqueStochasticSoilProfiles.Add(soilProfile, stochasticSoilProfile);
                }
            }

            return(uniqueStochasticSoilProfiles.Values.ToArray());
        }
Exemple #5
0
 /// <summary>
 /// Creates a <see cref="StochasticSoilProfile"/> with a valid probability.
 /// </summary>
 /// <param name="soilProfile">The soil profile.</param>
 /// <returns>A <see cref="StochasticSoilProfile"/> with the specified <paramref name="soilProfile"/>.</returns>
 /// <exception cref="ArgumentNullException">Thrown when <paramref name="soilProfile"/> is <c>null</c>.</exception>
 public static StochasticSoilProfile CreateStochasticSoilProfileWithValidProbability(ISoilProfile soilProfile)
 {
     return(new StochasticSoilProfile(0.5, soilProfile));
 }
        /// <summary>
        /// Transforms all generic <see cref="ISoilProfile"/> into <see cref="IMacroStabilityInwardsSoilProfile{T}"/>.
        /// </summary>
        /// <param name="soilProfile">The soil profile to use in the transformation.</param>
        /// <returns>The transformed soil profile.</returns>
        /// <exception cref="ImportedDataTransformException">Thrown when transformation would
        /// not result in a valid transformed instance.</exception>
        private IMacroStabilityInwardsSoilProfile <IMacroStabilityInwardsSoilLayer> GetTransformedSoilProfile(ISoilProfile soilProfile)
        {
            IMacroStabilityInwardsSoilProfile <IMacroStabilityInwardsSoilLayer> macroStabilityInwardsSoilProfile;

            if (soilProfiles.ContainsKey(soilProfile))
            {
                macroStabilityInwardsSoilProfile = soilProfiles[soilProfile];
            }
            else
            {
                macroStabilityInwardsSoilProfile = MacroStabilityInwardsSoilProfileTransformer.Transform(soilProfile);
                soilProfiles.Add(soilProfile, macroStabilityInwardsSoilProfile);
            }

            return(macroStabilityInwardsSoilProfile);
        }
        public void Transform_ValidStochasticSoilModelWithSameProfileProbabilityExceedingValidRange_ThrowsImportedDataException(ISoilProfile profile)
        {
            // Setup
            StochasticSoilModel soilModel = PipingStochasticSoilModelTestFactory.CreatePipingStochasticSoilModelWithGeometry(new[]
            {
                new StochasticSoilProfile(0.9, profile),
                new StochasticSoilProfile(0.9, profile)
            });

            var transformer = new PipingStochasticSoilModelTransformer();

            // Call
            TestDelegate call = () => transformer.Transform(soilModel);

            // Assert
            var          exception       = Assert.Throws <ImportedDataTransformException>(call);
            const string expectedMessage = "Het aandeel van de ondergrondschematisatie in het stochastische ondergrondmodel " +
                                           "moet in het bereik [0,0, 1,0] liggen.";

            StringAssert.StartsWith(expectedMessage, exception.Message);
        }
Exemple #8
0
        public void Transform_ValidStochasticSoilModelWithSameProfileInTwoStochasticSoilProfilesAndSumOfProbabilitiesInvalid_ThrowsImportedDataException(ISoilProfile soilProfile)
        {
            // Setup
            var stochasticSoilProfiles = new[]
            {
                new StochasticSoilProfile(0.9, soilProfile),
                new StochasticSoilProfile(0.9, soilProfile)
            };
            StochasticSoilModel soilModel = MacroStabilityInwardsStochasticSoilModelTestFactory.CreateMacroStabilityInwardsStochasticSoilModelWithGeometry(stochasticSoilProfiles);

            var transformer = new MacroStabilityInwardsStochasticSoilModelTransformer();

            // Call
            TestDelegate call = () => transformer.Transform(soilModel);

            // Assert
            var          exception       = Assert.Throws <ImportedDataTransformException>(call);
            const string expectedMessage = "Het aandeel van de ondergrondschematisatie in het stochastische ondergrondmodel " +
                                           "moet in het bereik [0,0, 1,0] liggen.";

            StringAssert.StartsWith(expectedMessage, exception.Message);
        }
Exemple #9
0
        public void Transform_ValidStochasticSoilModelWithSameProfileInTwoStochasticSoilProfiles_ReturnsExpectedMacroStabilityInwardsStochasticSoilModel(ISoilProfile soilProfile)
        {
            // Setup
            const string        soilModelName = "name";
            const double        originalProfileOneProbability = 0.2;
            const double        originalProfileTwoProbability = 0.7;
            StochasticSoilModel soilModel =
                MacroStabilityInwardsStochasticSoilModelTestFactory.CreateMacroStabilityInwardsStochasticSoilModelWithGeometry(soilModelName, new[]
            {
                new StochasticSoilProfile(originalProfileOneProbability, soilProfile),
                new StochasticSoilProfile(originalProfileTwoProbability, soilProfile)
            });

            var transformer = new MacroStabilityInwardsStochasticSoilModelTransformer();
            MacroStabilityInwardsStochasticSoilModel transformed = null;

            // Call
            Action call = () => transformed = transformer.Transform(soilModel);

            // Assert
            string expectedMessage = $"Ondergrondschematisatie '{soilProfile.Name}' is meerdere keren gevonden in ondergrondmodel '{soilModelName}'. " +
                                     "Kansen van voorkomen worden opgeteld.";

            TestHelper.AssertLogMessageWithLevelIsGenerated(call, Tuple.Create(expectedMessage, LogLevelConstant.Warn));

            MacroStabilityInwardsStochasticSoilProfile[] transformedStochasticSoilProfiles = transformed.StochasticSoilProfiles.ToArray();
            Assert.AreEqual(1, transformedStochasticSoilProfiles.Length);
            const double expectedProbability = originalProfileOneProbability + originalProfileTwoProbability;

            Assert.AreEqual(expectedProbability, transformedStochasticSoilProfiles[0].Probability, 1e-6);
        }