-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
70 changed files
with
808 additions
and
690 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,32 @@ | ||
namespace OSPSuite.Core.Domain.Builder | ||
{ | ||
public class ModelConfiguration | ||
internal class ModelConfiguration | ||
{ | ||
public SimulationBuilder SimulationBuilder { get; } | ||
public IModel Model { get; } | ||
public SimulationConfiguration SimulationConfiguration { get; } | ||
|
||
public ModelConfiguration(IModel model, SimulationConfiguration simulationConfiguration) | ||
public ModelConfiguration(IModel model, SimulationConfiguration simulationConfiguration, SimulationBuilder simulationBuilder) | ||
{ | ||
Model = model; | ||
SimulationConfiguration = simulationConfiguration; | ||
SimulationBuilder = simulationBuilder; | ||
} | ||
|
||
public bool ShouldValidate => SimulationConfiguration.ShouldValidate; | ||
|
||
public void Deconstruct(out IModel model, out SimulationConfiguration simulationConfiguration) | ||
public void Deconstruct(out IModel model, out SimulationConfiguration simulationConfiguration, out SimulationBuilder simulationBuilder) | ||
{ | ||
model = Model; | ||
simulationConfiguration = SimulationConfiguration; | ||
simulationBuilder = SimulationBuilder; | ||
} | ||
|
||
|
||
public void Deconstruct(out IModel model, out SimulationBuilder simulationBuilder) | ||
{ | ||
model = Model; | ||
simulationBuilder = SimulationBuilder; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using OSPSuite.Utility.Collections; | ||
|
||
namespace OSPSuite.Core.Domain.Builder | ||
{ | ||
public class SimulationBuilder | ||
{ | ||
private readonly SimulationConfiguration _simulationConfiguration; | ||
|
||
private readonly ObjectBaseCache<ITransportBuilder> _passiveTransports = new ObjectBaseCache<ITransportBuilder>(); | ||
private readonly ObjectBaseCache<IReactionBuilder> _reactions = new ObjectBaseCache<IReactionBuilder>(); | ||
private readonly ObjectBaseCache<IEventGroupBuilder> _eventGroups = new ObjectBaseCache<IEventGroupBuilder>(); | ||
private readonly ObjectBaseCache<IObserverBuilder> _observers = new ObjectBaseCache<IObserverBuilder>(); | ||
private readonly ObjectBaseCache<IMoleculeBuilder> _molecules = new ObjectBaseCache<IMoleculeBuilder>(); | ||
private readonly StartValueCache<ParameterStartValue> _parameterStartValues = new StartValueCache<ParameterStartValue>(); | ||
private readonly StartValueCache<MoleculeStartValue> _moleculeStartValues = new StartValueCache<MoleculeStartValue>(); | ||
|
||
private readonly Cache<IObjectBase, IObjectBase> _builderCache = new Cache<IObjectBase, IObjectBase>(onMissingKey: x => null); | ||
|
||
public SimulationBuilder(SimulationConfiguration simulationConfiguration) | ||
{ | ||
_simulationConfiguration = simulationConfiguration; | ||
performMerge(); | ||
} | ||
|
||
internal IObjectBase BuilderFor(IObjectBase modelObject) => _builderCache[modelObject]; | ||
|
||
internal void AddBuilderReference(IObjectBase modelObject, IObjectBase builder) | ||
{ | ||
_builderCache[modelObject] = builder; | ||
} | ||
|
||
private IReadOnlyList<T> all<T>(Func<Module, T> propAccess) where T : IBuildingBlock => | ||
_simulationConfiguration.ModuleConfigurations.Select(x => propAccess(x.Module)).Where(x => x != null).ToList(); | ||
|
||
private IEnumerable<T> allBuilder<T>(Func<Module, IBuildingBlock<T>> propAccess) where T : IBuilder => | ||
all(propAccess).SelectMany(x => x); | ||
|
||
private IEnumerable<T> allStartValueBuilder<T>(Func<ModuleConfiguration, IBuildingBlock<T>> propAccess) where T : IStartValue => | ||
_simulationConfiguration.ModuleConfigurations.Select(propAccess).Where(x => x != null).SelectMany(x => x); | ||
|
||
internal IEnumerable<IMoleculeBuilder> AllPresentMolecules() | ||
{ | ||
var moleculeNames = _moleculeStartValues | ||
.Where(moleculeStartValue => moleculeStartValue.IsPresent) | ||
.Select(moleculeStartValue => moleculeStartValue.MoleculeName) | ||
.Distinct(); | ||
|
||
|
||
return moleculeNames.Select(x => _molecules[x]).Where(m => m != null); | ||
} | ||
|
||
internal IEnumerable<MoleculeStartValue> AllPresentMoleculeValues() => | ||
AllPresentMoleculeValuesFor(_molecules.Select(x => x.Name)); | ||
|
||
internal IEnumerable<MoleculeStartValue> AllPresentMoleculeValuesFor(IEnumerable<string> moleculeNames) | ||
{ | ||
return _moleculeStartValues | ||
.Where(msv => moleculeNames.Contains(msv.MoleculeName)) | ||
.Where(msv => msv.IsPresent); | ||
} | ||
|
||
internal IEnumerable<IMoleculeBuilder> AllFloatingMolecules() => Molecules.Where(x => x.IsFloating); | ||
|
||
internal IReadOnlyList<string> AllPresentMoleculeNames() => AllPresentMoleculeNames(x => true); | ||
|
||
//Uses toArray so that the marshaling to R works out of the box (array vs list) | ||
internal IReadOnlyList<string> AllPresentMoleculeNames(Func<IMoleculeBuilder, bool> query) => | ||
AllPresentMolecules().Where(query).Select(x => x.Name).ToArray(); | ||
|
||
internal IReadOnlyList<string> AllPresentFloatingMoleculeNames() => | ||
AllPresentMoleculeNames(m => m.IsFloating); | ||
|
||
internal IReadOnlyList<string> AllPresentStationaryMoleculeNames() => | ||
AllPresentMoleculeNames(m => !m.IsFloating); | ||
|
||
internal IReadOnlyList<string> AllPresentXenobioticFloatingMoleculeNames() => | ||
AllPresentMoleculeNames(m => m.IsFloating && m.IsXenobiotic); | ||
|
||
internal IReadOnlyList<string> AllPresentEndogenousStationaryMoleculeNames() => | ||
AllPresentMoleculeNames(m => !m.IsFloating && !m.IsXenobiotic); | ||
|
||
internal IReadOnlyList<string> AllPresentEndogenousMoleculeNames() => AllPresentMoleculeNames(m => !m.IsXenobiotic); | ||
|
||
private void performMerge() | ||
{ | ||
_passiveTransports.AddRange(allBuilder(x => x.PassiveTransports)); | ||
_reactions.AddRange(allBuilder(x => x.Reactions)); | ||
_eventGroups.AddRange(allBuilder(x => x.EventGroups)); | ||
_observers.AddRange(allBuilder(x => x.Observers)); | ||
_molecules.AddRange(allBuilder(x => x.Molecules)); | ||
_parameterStartValues.AddRange(allStartValueBuilder(x => x.SelectedParameterStartValues)); | ||
_moleculeStartValues.AddRange(allStartValueBuilder(x => x.SelectedMoleculeStartValues)); | ||
} | ||
|
||
internal IReadOnlyList<ISpatialStructure> SpatialStructures => all(x => x.SpatialStructure); | ||
internal IReadOnlyCollection<ITransportBuilder> PassiveTransports => _passiveTransports; | ||
internal IReadOnlyCollection<IReactionBuilder> Reactions => _reactions; | ||
internal IReadOnlyCollection<IEventGroupBuilder> EventGroups => _eventGroups; | ||
internal IReadOnlyCollection<IObserverBuilder> Observers => _observers; | ||
internal IReadOnlyCollection<IMoleculeBuilder> Molecules => _molecules; | ||
internal IReadOnlyCollection<ParameterStartValue> ParameterStartValues => _parameterStartValues; | ||
internal IReadOnlyCollection<MoleculeStartValue> MoleculeStartValues => _moleculeStartValues; | ||
|
||
internal IMoleculeBuilder MoleculeByName(string name) => _molecules[name]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.