/// <inheritdoc/> void IFrequencyBehavior.Load() { var omega = ComplexState.Laplace.Imaginary; var gdpr = ModelParameters.DrainConductance * Parameters.Area; var gspr = ModelParameters.SourceConductance * Parameters.Area; var gm = Gm; var gds = Gds; var ggs = Ggs; var xgs = CapGs * omega; var ggd = Ggd; var xgd = CapGd * omega; ComplexElements.Add( gdpr, new Complex(ggd + ggs, xgd + xgs), gspr, new Complex(gdpr + gds + ggd, xgd), new Complex(gspr + gds + gm + ggs, xgs), -gdpr, -new Complex(ggd, xgd), -new Complex(ggs, xgs), -gspr, -gdpr, new Complex(-ggd + gm, -xgd), (-gds - gm), -new Complex(ggs + gm, xgs), -gspr, -gds); }
//public static bool IsComplexType(Type type) //{ // return ComplexElements.ContainsKey(type); //} public static ElementSequence GetComplexElementForType(Type type, string name, int position = 0) { ElementSequence seq = null; if (ComplexElements.ContainsKey(type)) { seq = ComplexElements[type]; if (seq != null) { seq.Name = name; seq.Position = position; return(seq); } } seq = new ElementSequence(name, position); foreach (var property in type.GetProperties(BindingFlags.Instance | BindingFlags.Public)) { Type elementType = null; IElement elementObj = null; string elementName = null; int? elementPosition = null; IElement lengthElement = null; //check if an ad-hoc attribute has been set.. if (Attribute.IsDefined(property, typeof(ElementTypeAttribute))) { var attribute = Attribute.GetCustomAttribute(property, typeof(ElementTypeAttribute)) as ElementTypeAttribute; elementPosition = attribute.BufferPosition; elementName = attribute.ElementName; elementType = attribute.ElementType; if (attribute.IsArray && !String.IsNullOrWhiteSpace(attribute.ArrayLengthProperty)) { lengthElement = seq.Elements.Where(e => e.Name == attribute.ArrayLengthProperty).First(); //throws if the LengthElement is not been defined yet.. } //create element, just basic elements can be specified through attributes.. if (elementType != null) { elementObj = GetDefaultInstanceOfElementType(elementType, elementName ?? property.Name, elementPosition ?? 0); } } //get the rigth element.. if (elementObj == null) { elementObj = GetElementForPropertyType(property.PropertyType, elementName ?? property.Name, elementPosition ?? 0, lengthElement); } if (elementObj == null) { throw new Exception("No IElement<> supports type: " + property.PropertyType.Name); } seq.Elements.Add(elementObj); } //cache it for further use.. //ComplexElements[type] = seq; //TODO: Commentato. Una cache statica non va bene perché è tutto multithread e a volte asincrono quindi si accavallano i valori negli elementi.. //TODO: Implementare un metodo di clonazione e tenere in cache un prototipo da clonare ogni volta arriva una richiesta per lo stesso tipo.. return(seq); }