/// <summary> /// Set parameters which will be varied into SimModel /// </summary> /// <param name="simulation">SimModel simulation</param> private void setVariableParameters(ISimulation simulation) { var parameterPathsToBeVaried = _populationDataSplitter.ParameterPathsToBeVaried(); var allParameters = simulation.ParameterProperties; var parametersToBeVaried = allParameters.Where(p => parameterPathsToBeVaried.Contains(p.Path)); simulation.VariableParameters = parametersToBeVaried.ToList(); }
private void setVariableParameters(ISimulation simulation) { var allParameters = simulation.ParameterProperties; var parametersToBeVaried = allParameters.Where(p => _variableParameterPaths.Contains(p.Path)).ToList(); parametersToBeVaried.Each(p => p.CalculateSensitivity = _calculateSensitivities); simulation.VariableParameters = parametersToBeVaried; }
public void InitializeWith(IModelCoreSimulation modelCoreSimulation, IReadOnlyList <string> variableParameterPaths, bool calculateSensitivities = false, string simulationResultsName = null) { _modelCoreSimulation = modelCoreSimulation; _variableParameterPaths = variableParameterPaths; _simulationResultsName = simulationResultsName; _calculateSensitivities = calculateSensitivities; _simModelSimulation = createAndFinalizeSimulation(); _simModelSimulation.CheckForNegativeValues = false; _allVariableParameters = _simModelSimulation.VariableParameters; }
/// <summary> /// Get Results from SimModel /// </summary> /// <param name="simulation">SimModel simulation</param> /// <param name="individualId">Individual id</param> private IndividualResults individualResultsFrom(SimModelNET.ISimulation simulation, int individualId) { var results = new IndividualResults { IndividualId = individualId }; var simulationTimes = simulation.SimulationTimes; var simulationTimesLength = simulationTimes.Length; foreach (var result in simulation.AllValues) { //Add quantity name and remove simulation name var quantityPath = _objectPathFactory.CreateObjectPathFrom(result.Path.ToPathArray()); quantityPath.Remove(_simulationName); results.Add(quantityValuesFor(quantityPath.ToString(), result, simulationTimesLength)); } results.Time = quantityValuesFor(Constants.TIME, simulation.SimulationTimes); return(results); }
/// <summary> /// Perform single simulation run /// </summary> /// <param name="simulation">SimModel simulation (loaded and finalized)</param> /// <param name="coreIndex">0..NumberOfCores-1</param> /// <param name="cancellationToken">Token used to cancel the action if required</param> private void simulate(SimModelNET.ISimulation simulation, int coreIndex, CancellationToken cancellationToken) { var allIndividuals = _populationDataSplitter.GetIndividualIdsFor(coreIndex); var variableParameters = simulation.VariableParameters; var initialValues = simulation.VariableSpecies; foreach (var individualId in allIndividuals) { cancellationToken.ThrowIfCancellationRequested(); //get row indices for the simulations on current core _populationDataSplitter.UpdateParametersAndInitialValuesForIndividual(individualId, variableParameters, initialValues); //set new parameter values into SimModel simulation.SetParameterValues(variableParameters); //set new initial values into SimModel simulation.SetSpeciesProperties(initialValues); try { simulation.RunSimulation(); _populationRunResults.Add(individualResultsFrom(simulation, individualId)); } catch (Exception ex) { _populationRunResults.AddFailure(individualId, ex.FullMessage()); } finally { var warnings = simulation.SolverWarnings; _populationRunResults.AddWarnings(individualId, warnings); //Could lead to a wrong progress if two threads are accessing the value at the same time SimulationProgress(this, new PopulationSimulationProgressEventArgs(++_numberOfProcessedSimulations, _numberOfSimulationsToRun)); } } }
public DataRepository CreateRepository(IModelCoreSimulation simulation, SimModelNET.ISimulation simModelSimulation, string repositoryName = null) { var repository = new DataRepository().WithName(repositoryName ?? _dataNamingService.GetNewRepositoryName()); var allPersitableQuantities = new Cache <string, IQuantity>(q => _objectPathFactory.CreateAbsoluteObjectPath(q).ToString(), x => null); allPersitableQuantities.AddRange(simulation.Model.Root.GetAllChildren <IQuantity>(x => x.Persistable)); var time = createTimeGrid(simModelSimulation.SimulationTimes); foreach (var quantityValue in simModelSimulation.AllValues) { var quantity = allPersitableQuantities[quantityValue.Path]; if (quantity == null) { continue; } repository.Add(createColumn(time, quantity, quantityValue, quantityValue.Path.ToPathArray(), simulation)); } return(repository); }
/// <summary> /// Performs any actions necessary to make the simulation run ready /// </summary> protected void FinalizeSimulation(ISimulation simModelSimulation) { simModelSimulation.FinalizeSimulation(); }