private IFormulaUsablePath generatePathFromDTO(IObjectBaseDTO dto) { if (dto.IsAnImplementationOf <DummyParameterDTO>()) { var dummy = dto.DowncastTo <DummyParameterDTO>(); var parent = getExistingParentContainerFromDTO(dto); var path = _objectPathFactory.CreateAbsoluteObjectPath(parent) .AndAdd(dummy.ModelParentName) .AndAdd(dummy.Name); return(formulatUsablePathFrom(path, getDimensionForDummyParameter(dummy))); } if (dto.IsAnImplementationOf <IDummyContainer>()) { var parent = dto.DowncastTo <IDummyContainer>().StructureParent; var path = _objectPathFactory.CreateAbsoluteObjectPath(parent).AndAdd(dto.Name); return(formulatUsablePathFrom(path, getDimensionFor(dto))); } var selectedEntity = _context.Get <IEntity>(dto.Id); if (selectedEntity.IsAnImplementationOf <IUsingFormula>()) { var usingFormula = selectedEntity.DowncastTo <IUsingFormula>(); var path = _objectPathFactory.CreateAbsoluteObjectPath(usingFormula); return(formulatUsablePathFrom(path, usingFormula.Dimension)); } return(null); }
private IEnumerable <IParameterStartValue> getMoleculePropertiesParameterValues(IContainer moleculeProperties, IMoleculeBuilder moleculeBuilder) { foreach (var parameter in moleculeProperties.GetChildren <IParameter>(parameterValueShouldBeSet)) { var path = _objectPathFactory.CreateAbsoluteObjectPath(parameter); path.Replace(Constants.MOLECULE_PROPERTIES, moleculeBuilder.Name); yield return(CreateParameterStartValue(path, parameter)); } }
public TransportDTO MapFrom(ITransport transport) { var dto = Map <TransportDTO>(transport); dto.Molecule = transport.SourceAmount.Name; dto.Source = _pathFactory.CreateAbsoluteObjectPath(transport.SourceAmount.ParentContainer).PathAsString; dto.Target = _pathFactory.CreateAbsoluteObjectPath(transport.TargetAmount.ParentContainer).PathAsString; dto.Rate = transport.Formula.ToString(); dto.Dimension = transport.Dimension; return(dto); }
public DataTable ExportParametersToTable(IEnumerable <IParameter> parametersToExport, Action <DataTable> tableConfigurationAction = null, Action <IParameter, DataRow> rowConfigurationAction = null) { var dataTable = new DataTable(); var colPath = dataTable.AddColumn(Constants.ParameterExport.PARAMETER_PATH); var colValue = dataTable.AddColumn <double>(Constants.ParameterExport.VALUE); var colFormula = dataTable.AddColumn(Constants.ParameterExport.FORMULA); var colRHSFormula = dataTable.AddColumn(Constants.ParameterExport.RHS_FORMULA); tableConfigurationAction?.Invoke(dataTable); foreach (var parameter in parametersToExport) { var row = dataTable.NewRow(); row[colPath] = _objectPathFactory.CreateAbsoluteObjectPath(parameter); try { row[colValue] = parameter.Value; } catch (Exception) { row[colValue] = double.NaN; } row[colFormula] = formulaStringFrom(parameter.Formula); row[colRHSFormula] = formulaStringFrom(parameter.RHSFormula); rowConfigurationAction?.Invoke(parameter, row); dataTable.Rows.Add(row); } return(dataTable); }
private IContainer resolveReference(IModel model, IContainer neighborBuilderContainer) { var objectPathInBuilder = _objectPathFactory.CreateAbsoluteObjectPath(neighborBuilderContainer); var objectPathInModel = _keywordReplacerTask.CreateModelPathFor(objectPathInBuilder, model.Root); return(objectPathInModel.Resolve <IContainer>(model.Root)); }
public void Visit(IUsingFormula entityUsingFormula) { try { Visit(entityUsingFormula as IEntity); if (!_checkDimensions) { return; } var formula = entityUsingFormula.Formula; if (formula.IsConstant()) { return; //do not need to check constants } var displayPath = _objectPathFactory.CreateAbsoluteObjectPath(entityUsingFormula).PathAsString; if (entityUsingFormula.Dimension == null) { addWarning(entityUsingFormula, AppConstants.Validation.NoDimensionSet(displayPath)); return; } checkFormula(entityUsingFormula, displayPath); checkRHSFormula(entityUsingFormula as IParameter, displayPath); } catch (Exception exception) { addNotification(NotificationType.Error, entityUsingFormula, exception.Message); } }
/// <summary> /// Returns molecules which will be created in both neighbours of the neighbourhood /// </summary> private IEnumerable <string> moleculeNamesFor(INeighborhoodBuilder neighborhoodBuilder, ICache <string, IList <string> > moleculesStartValuesForFloatingMolecules) { var pathToFirstNeighbor = _objectPathFactory.CreateAbsoluteObjectPath(neighborhoodBuilder.FirstNeighbor).ToString(); var pathToSecondNeighbor = _objectPathFactory.CreateAbsoluteObjectPath(neighborhoodBuilder.SecondNeighbor).ToString(); // check if both neighbours has at least 1 molecule (if not - return empty list) if (!moleculesStartValuesForFloatingMolecules.Contains(pathToFirstNeighbor) || !moleculesStartValuesForFloatingMolecules.Contains(pathToSecondNeighbor)) { return(new List <string>()); } return(moleculesStartValuesForFloatingMolecules[pathToFirstNeighbor] .Intersect(moleculesStartValuesForFloatingMolecules[pathToSecondNeighbor]).ToList()); }
private void mapQuantity(IQuantity quantity, QuantityExport quantityExport) { quantityExport.Id = idFor(quantity); quantityExport.EntityId = quantity.Id; quantityExport.Name = quantity.Name; quantityExport.Persistable = quantity.Persistable; //path is required also in optimized mode! //otherwise results-DataRepository will contain invalid quantity infos quantityExport.Path = _objectPathFactory.CreateAbsoluteObjectPath(quantity).PathAsString; if (_exportMode == SimModelExportMode.Full && quantity.Dimension != null) { quantityExport.Unit = quantity.Dimension.BaseUnit.Name; } if (quantity.IsFixedValue || quantity.Formula.IsConstant()) { quantityExport.Value = quantity.Value; } else { quantityExport.FormulaId = mapFormula(quantity, quantity.Formula).Id; } }
public virtual void Init(IEntity localReferencePoint, IEnumerable <IObjectBase> contextSpecificEntitiesToAddToReferenceTree, IUsingFormula editedObject) { if (localReferencePoint != null) { _refObject = localReferencePoint; } _view.Show(contextSpecificEntitiesToAddToReferenceTree.MapAllUsing(_referenceMapper)); addInitialObjects(); if (_refObject != null) { _view.Localisation = _objectPathFactory.CreateAbsoluteObjectPath(_refObject).PathAsString; selectInView(_refObject); } _editedObject = editedObject; }
/// <summary> /// Creates the path from parameter dummy. /// </summary> /// <param name="objectBaseDTO">The dummy parameter dto.</param> /// <param name="shouldCreateAbsolutePaths">if set to <c>true</c> creates absolute paths otherwise creates reltive paths.</param> /// <param name="refObject"> /// The reference object the user chosen (may the concrete object that uses the reference or a /// existing parent of it). /// </param> /// <param name="editedObject"></param> /// <returns> The path that could be uses in the model to reference the object</returns> public virtual ReferenceDTO CreatePathFromParameterDummy(IObjectBaseDTO objectBaseDTO, bool shouldCreateAbsolutePaths, IEntity refObject, IUsingFormula editedObject) { if (IsMoleculeReference(objectBaseDTO)) { return(createMoleculeReference()); } var dtoDummyParameter = (DummyParameterDTO)objectBaseDTO; var parameterToUse = _context.Get <IParameter>(dtoDummyParameter.ParameterToUse.Id); ReferenceDTO dtoReference; if (parameterToUse.IsAtMolecule()) { dtoReference = new ReferenceDTO(); IObjectPath tmpPath; //global molecule parameters we always reference absolute if (shouldCreateAbsolutePaths || !parameterToUse.BuildMode.Equals(ParameterBuildMode.Local)) { tmpPath = _objectPathFactory.CreateAbsoluteObjectPath(dtoDummyParameter.Parent); } else { if (refObject != dtoDummyParameter.Parent) { tmpPath = _objectPathFactory.CreateRelativeObjectPath(refObject, dtoDummyParameter.Parent); } else { tmpPath = new ObjectPath(); } tmpPath = AdjustReferences(parameterToUse, tmpPath); } dtoReference.Path = _objectPathFactory.CreateFormulaUsablePathFrom(tmpPath) .WithAlias(_aliasCreator.CreateAliasFrom(parameterToUse.Name)) .WithDimension(parameterToUse.Dimension); dtoReference.Path.Add(parameterToUse.Name); } else { dtoReference = CreatePathsFromEntity(parameterToUse, shouldCreateAbsolutePaths, refObject, editedObject); } dtoReference.Path.Replace(Constants.MOLECULE_PROPERTIES, dtoDummyParameter.ModelParentName); dtoReference.BuildMode = parameterToUse.BuildMode; return(dtoReference); }
protected void CheckFormulaIn(IUsingFormula entity, IFormula formulaToCheck, ResolveErrorBehavior resolveErrorBehavior) { var entityAbsolutePath = _objectPathFactory.CreateAbsoluteObjectPath(entity).ToPathString(); var builder = _buildConfiguration.BuilderFor(entity); var objectWithError = builder ?? entity; var entityType = _objectTypeResolver.TypeFor(entity); if (formulaToCheck.IsBlackBox()) { addNotificationType(NotificationType.Error, objectWithError, Validation.FormulaIsBlackBoxIn(entity.Name, entityAbsolutePath)); return; } foreach (var objectPath in formulaToCheck.ObjectPaths) { CheckPath(entity, objectPath, resolveErrorBehavior); } }
private DataTable tableFor(IEnumerable <INeighborhoodBuilder> neighborhoodBuilders) { var dataTable = new DataTable(Constants.NEIGHBORHOODS); dataTable.Columns.Add(Constants.FIRST_NEIGHBOR, typeof(string)); dataTable.Columns.Add(Constants.SECOND_NEIGHBOR, typeof(string)); dataTable.BeginLoadData(); foreach (var neighborhood in neighborhoodBuilders) { var newRow = dataTable.NewRow(); newRow[Constants.FIRST_NEIGHBOR] = _objectPathFactory.CreateAbsoluteObjectPath(neighborhood.FirstNeighbor).PathAsString; newRow[Constants.SECOND_NEIGHBOR] = _objectPathFactory.CreateAbsoluteObjectPath(neighborhood.SecondNeighbor).PathAsString; dataTable.Rows.Add(newRow); } dataTable.EndLoadData(); return(dataTable); }
private void addMoleculesFrom(IMoleculeStartValuesBuildingBlock moleculesStartValuesBuildingBlock, IEntity container, IEnumerable <IMoleculeBuilder> molecules) { foreach (var molecule in molecules) { var moleculeStartValue = CreateMoleculeStartValue(_objectPathFactory.CreateAbsoluteObjectPath(container), molecule.Name, molecule.Dimension, molecule.DisplayUnit); setMoleculeStartValue(molecule, moleculeStartValue); setMoleculeStartValueFormula(molecule.DefaultStartFormula, moleculeStartValue, moleculesStartValuesBuildingBlock); moleculesStartValuesBuildingBlock.Add(moleculeStartValue); } }
public string FullPathFor(IObjectBase objectBase, bool addSimulationName = false) { var entity = objectBase as IEntity; if (entity != null) { return(_objectPathFactory.CreateAbsoluteObjectPath(entity).PathAsString); } return(objectBase.Name); }
private Cache <IObjectPath, IContainer> createReactionContainerCache(IModel model) { var cache = new Cache <IObjectPath, IContainer>(); var reactionContainer = model.Root.GetAllChildren <IContainer>(x => x.Children.Any(child => child.IsAnImplementationOf <IReaction>())); reactionContainer.Each(cont => cache.Add(_objectPathFactory.CreateAbsoluteObjectPath(cont), cont)); return(cache); }
public void ReplaceIn(ITransport realization, IContainer rootContainer, string moleculeName, INeighborhood neighborhood, string transportName, string transporterName) { var keywordReplacer = new KeywordReplacerCollection(); addCommonModelReplacersTo(keywordReplacer, rootContainer); addMoleculeReplacersTo(keywordReplacer, moleculeName); addCommonNeighborhoodReplacersTo(keywordReplacer, neighborhood); keywordReplacer.AddReplacement(new KeywordWithPathReplacer(ObjectPathKeywords.SOURCE, _objectPathFactory.CreateAbsoluteObjectPath(realization.SourceAmount.ParentContainer))); keywordReplacer.AddReplacement(new KeywordWithPathReplacer(ObjectPathKeywords.TARGET, _objectPathFactory.CreateAbsoluteObjectPath(realization.TargetAmount.ParentContainer))); keywordReplacer.AddReplacement(new KeywordWithPathReplacer(ObjectPathKeywords.REALIZATION, new ObjectPath(transportName, realization.Name))); keywordReplacer.AddReplacement(new SimpleKeywordReplacer(ObjectPathKeywords.TRANSPORT, transportName)); keywordReplacer.AddReplacement(new SimpleKeywordReplacer(ObjectPathKeywords.TRANSPORTER, transporterName)); keywordReplacer.ReplaceIn(realization); replaceInContainer(realization, rootContainer); //replaceInContainer only replaces standard keywords. Transport specific keywords need to be replaced in all children explicitely var transportContainer = realization.ParentContainer ?? realization; transportContainer.GetAllChildren <IUsingFormula>().Each(keywordReplacer.ReplaceIn); }
protected void CheckFormulaIn(IUsingFormula entity, IFormula formulaToCheck, ResolveErrorBehavior resolveErrorBehavior) { var entityAbsolutePath = _objectPathFactory.CreateAbsoluteObjectPath(entity).ToPathString(); var builder = _buildConfiguration.BuilderFor(entity); var objectWithError = builder ?? entity; // Dynamic formula may contain object path that will be resolved per instance. It cannot be checked here if (formulaToCheck.IsDynamic()) { return; } if (formulaToCheck.IsBlackBox()) { addNotificationType(NotificationType.Error, objectWithError, Validation.FormulaIsBlackBoxIn(entity.Name, entityAbsolutePath)); return; } foreach (var objectPath in formulaToCheck.ObjectPaths) { CheckPath(entity, objectPath, resolveErrorBehavior); } }
private IEnumerable <IObjectPath> moleculesInvolvedInExpression(ISpatialStructure spatialStructure, IndividualMolecule molecule, IReadOnlyList <CompoundProperties> compoundPropertiesList) { foreach (var expressionContainer in _expressionContainersRetriever.AllContainersFor(spatialStructure, molecule)) { var containerPath = _objectPathFactory.CreateAbsoluteObjectPath(expressionContainer); foreach (var compoundProperties in compoundPropertiesList) { foreach (var moleculeName in compoundProperties.Processes.AllInducedMoleculeNames(molecule)) { yield return(containerPath.Clone <IObjectPath>().AndAdd(moleculeName)); } } } }
private void checkCircularReferencesIn(IUsingFormula usingFormula, IBuildConfiguration buildConfiguration, ValidationResult validationResult) { var references = _entityReferenceCache[usingFormula]; if (!references.Contains(usingFormula)) { return; } var entityAbsolutePath = _objectPathFactory.CreateAbsoluteObjectPath(usingFormula).ToPathString(); var builder = buildConfiguration.BuilderFor(usingFormula); var objectWithError = builder ?? usingFormula; var entityType = _objectTypeResolver.TypeFor(usingFormula); var allReferencesName = references.Distinct().AllNames(); validationResult.AddMessage(NotificationType.Error, objectWithError, Validation.CircularReferenceFoundInFormula(usingFormula.Name, entityType, entityAbsolutePath, allReferencesName)); }
public SearchResultDTO MapFrom(SearchResult searchResult) { var dto = new SearchResultDTO(); var foundObject = searchResult.FoundObject; dto.Object = foundObject; if (foundObject.IsAnImplementationOf <IEntity>()) { dto.Path = _objectPathFactory.CreateAbsoluteObjectPath((IEntity)foundObject).ToString(); } else { dto.Path = foundObject.Name; } dto.TypeName = _objectTypeResolver.TypeFor(foundObject); dto.ProjectItem = searchResult.ProjectItem; dto.ProjectItemName = $"{_objectTypeResolver.TypeFor(searchResult.ProjectItem)}: {searchResult.ProjectItem.Name}"; return(dto); }
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); }
public virtual IObjectPath ObjectPathFor(IEntity entity, bool addSimulationName = false) { var objectPath = _objectPathFactory.CreateAbsoluteObjectPath(entity); return(convertedPath(objectPath, entity.RootContainer, addSimulationName)); }
private void reportFor(IContainer container) { if (container.IsAnImplementationOf <INeighborhood>()) { return; } if (container.IsAnImplementationOf <ITransport>()) { return; } if (container.IsAnImplementationOf <IReaction>()) { return; } if (container.IsAnImplementationOf <IParameter>()) { return; } if (container.IsAnImplementationOf <IMoleculeAmount>()) { return; } if (container.Name.Equals(Constants.MOLECULE_PROPERTIES) || container.ParentContainer.Name.Equals(Constants.MOLECULE_PROPERTIES)) { return; } _report.AppendFormat("Container: {0}", _objectPathFactory.CreateAbsoluteObjectPath(container)); _report.AppendLine(); _report.AppendFormat("\tType: {0}", container.ContainerType); _report.AppendLine(); _report.AppendFormat("\tMode: {0}", container.Mode); _report.AppendLine(); _report.AppendFormat("\tTags: "); bool firstEntry = true; foreach (var tag in container.Tags) { if (firstEntry) { firstEntry = false; } else { _report.Append("|"); } _report.Append(tag.Value); } _report.AppendLine(); reportDescription(container); _report.AppendLine(); }
protected override void Context() { var entityPathFactory = new EntityPathResolverForSpecs(); _objectPathFactory = new ObjectPathFactory(new AliasCreator()); _simulation = A.Fake <IModelCoreSimulation>().WithName("Sim"); _simModelManager = A.Fake <ISimModelManager>(); _containerTask = A.Fake <IContainerTask>(); _options = new ScaleDivisorOptions(); _moleculeAmountCache = new PathCache <IMoleculeAmount>(entityPathFactory); var rootContainer = new ARootContainer().WithName(_simulation.Name) .WithContainerType(ContainerType.Simulation); _simulation.Model.Root = rootContainer; _moleculeAmount1 = new MoleculeAmount().WithName("M1"); _moleculeAmount2 = new MoleculeAmount().WithName("M2"); rootContainer.Add(_moleculeAmount1); rootContainer.Add(_moleculeAmount2); _moleculeAmountCache.Add(_moleculeAmount1); _moleculeAmountCache.Add(_moleculeAmount2); _molecule1Path = entityPathFactory.PathFor(_moleculeAmount1); _molecule2Path = entityPathFactory.PathFor(_moleculeAmount2); _originalResults = new DataRepository(); _simulation.Results = _originalResults; var baseGrid = new BaseGrid("Time", Constants.Dimension.NO_DIMENSION) { Values = new[] { 0f, 1f, 2f, 3f } }; _originalDataColumn = new DataColumn("M1", Constants.Dimension.NO_DIMENSION, baseGrid) { Values = new[] { 0f, 10f, 20f, 30f } }; _originalDataColumn.QuantityInfo.Path = _objectPathFactory.CreateAbsoluteObjectPath(_moleculeAmount1); _originalResults.Add(_originalDataColumn); A.CallTo(_containerTask).WithReturnType <PathCache <IMoleculeAmount> >().Returns(_moleculeAmountCache); var simResults = new DataRepository(); var baseGrid2 = new BaseGrid("Time", Constants.Dimension.NO_DIMENSION) { Values = new[] { 0f, 1f, 2f, 3f } }; var res1 = new DataColumn("M1", Constants.Dimension.NO_DIMENSION, baseGrid2) { Values = new[] { 0f, 10f, 20f, 30f } }; res1.QuantityInfo.Path = _objectPathFactory.CreateAbsoluteObjectPath(_moleculeAmount1); simResults.Add(res1); var res2 = new DataColumn("M2", Constants.Dimension.NO_DIMENSION, baseGrid2) { Values = new[] { 0f, 11f, 12f, 13f } }; res2.QuantityInfo.Path = _objectPathFactory.CreateAbsoluteObjectPath(_moleculeAmount2); simResults.Add(res2); var simulationRunResults = new SimulationRunResults(true, Enumerable.Empty <ISolverWarning>(), simResults); A.CallTo(() => _simModelManager.RunSimulation(_simulation)).Returns(simulationRunResults); sut = new ScaleDivisorCalculator(_simModelManager, _containerTask, _objectPathFactory); }
private PathElements displayPathFor(IQuantity quantity) { return(displayPathForQuantity(quantity.RootContainer, _objectPathFactory.CreateAbsoluteObjectPath(quantity))); }
private void addHelpParametersFor(ICoreCalculationMethod calculationMethod, IList <IMoleculeBuilder> allMoleculesUsingMethod) { foreach (var helpParameter in calculationMethod.AllHelpParameters()) { var containerDescriptor = calculationMethod.DescriptorFor(helpParameter); foreach (var molecule in allMoleculesUsingMethod) { foreach (var container in allMoleculeContainersFor(containerDescriptor, molecule)) { var exisitingParameter = container.GetSingleChildByName <IParameter>(helpParameter.Name); //does not exist yet if (exisitingParameter == null) { var parameter = _parameterMapper.MapFrom(helpParameter, _buildConfiguration); container.Add(parameter); replaceKeyWordsIn(parameter, molecule.Name); } else if (!formulasAreTheSameForParameter(exisitingParameter, helpParameter.Formula, molecule.Name)) { throw new OSPSuiteException(Error.HelpParameterAlreadyDefinedWithAnotherFormula(calculationMethod.Name, _objectPathFactory.CreateAbsoluteObjectPath(helpParameter).ToString())); } } } } }
private IObjectPath proteinPathFor(IndividualMolecule molecule, IContainer expressionContainer) { return(_objectPathFactory.CreateAbsoluteObjectPath(expressionContainer).AndAdd(molecule.Name)); }