public IFiniteElementMaterial GetMaterial(NEUTopology topology)
        {
            switch (topology)
            {
            case NEUTopology.Brick8:
            case NEUTopology.Brick20:
            case NEUTopology.Tetra4:
            case NEUTopology.Tetra10:
            case NEUTopology.Wedge6:
            case NEUTopology.Wedge15:
            case NEUTopology.Line2:
            case NEUTopology.Line3:
                return(new ElasticMaterial3D()
                {
                    YoungModulus = Es[0],
                    PoissonRatio = Nus[0]
                });

            default:
                return(new ElasticMaterial()
                {
                    YoungModulus = Es[0],
                    PoissonRatio = Nus[0]
                });
            }
        }
        public void ExtractData(NEUModel model, IList <string> lines)
        {
            int index = 2;

            while (index < lines.Count - 1)
            {
                var            idLine     = lines[index].Split(',');
                int            id         = Int32.Parse(idLine[0]);
                int            propertyId = Int32.Parse(idLine[2]);
                NEUElementType typeId     = (NEUElementType)Int32.Parse(idLine[3]);
                NEUTopology    topologyId = (NEUTopology)Int32.Parse(idLine[4]);

                var element = new Tuple <IList <int>, int, NEUElementType, NEUTopology>(
                    lines[index + 1].Split(',').Take(10).Concat(lines[index + 2].Split(',').Take(10)).Select(x => Int32.Parse(x)).Where(x => x != 0).ToList <int>(),
                    propertyId, typeId, topologyId);
                model.Elements.Add(id, element);

                int extraLines = 0;
                var listLine   = lines[index + 6].Split(',').Take(16);
                int extraLists = listLine.Skip(12).Select(x => x != "0").Count(x => x);
                for (int i = 0; i < extraLists; i++)
                {
                    while (!lines[index + 7 + extraLines].StartsWith("-1"))
                    {
                        extraLines++;
                    }
                }
                index += extraLines + 7;
            }
        }
        private static Model GetModelFromNEUModel(NEUModel neuModel, bool includeRotationsWhenEmbedding)
        {
            var model = new Model();

            foreach (var node in neuModel.Nodes)
            {
                model.NodesDictionary.Add(node.Key, node.Value);
            }
            foreach (var constraint in neuModel.Constraints)
            {
                model.NodesDictionary[constraint.Item1].Constraints.Add(constraint.Item2);
            }

            foreach (var neuElement in neuModel.Elements)
            {
                var            neuNodes       = neuElement.Value.Item1;
                int            propertyId     = neuElement.Value.Item2;
                NEUElementType neuElementType = neuElement.Value.Item3;
                NEUTopology    neuTopology    = neuElement.Value.Item4;
                var            property       = neuModel.Properties[propertyId];
                var            material       = neuModel.Materials[property.MaterialID].GetMaterial(neuTopology);
                IFiniteElement elementType;
                switch (neuElementType)
                {
                case NEUElementType.Solid1:
                    elementType = new Hexa8((IFiniteElementMaterial3D)material);
                    break;

                case NEUElementType.Solid2:
                    elementType = new Hexa8((IFiniteElementMaterial3D)material);
                    //elementType = new Hexa20((IFiniteElementMaterial3D)material);
                    break;

                case NEUElementType.Bar:
                case NEUElementType.Beam:
                case NEUElementType.Beam82:
                    var beamProperty = (NEUBeamProperty)property;
                    elementType = new Beam3D(material)
                    {
                        SectionArea          = beamProperty.Area,
                        MomentOfInertiaZ     = beamProperty.I1,
                        MomentOfInertiaY     = beamProperty.I2,
                        MomentOfInertiaPolar = beamProperty.J
                    };
                    break;

                default:
                    throw new ArgumentException("Unsupported element type.");
                }

                var element = new Element()
                {
                    ElementType = elementType, ID = neuElement.Key
                };
                for (int i = 0; i < neuNodes.Count; i++)
                {
                    element.AddNode(model.NodesDictionary[neuNodes[i]]);
                }
                //element.AddNodes(model.NodesDictionary.Where(x =>
                //    {
                //        return neuNodes.IndexOf(x.Key) >= 0;
                //    }).Select(x => x.Value).ToList<Node>());
                model.ElementsDictionary.Add(neuElement.Key, element);
            }

            var dofTypeTranslations = new Dictionary <DOFType, DOFType>()
            {
                { DOFType.X, DOFType.RotX },
                { DOFType.Y, DOFType.RotY },
                { DOFType.Z, DOFType.RotZ }
            };

            foreach (var load in neuModel.Loads)
            {
                switch (load.Item2)
                {
                case NEULoadType.NodalForce:
                    model.Loads.Add(new Load()
                    {
                        Node = model.NodesDictionary[load.Item3], Amount = load.Item5, DOF = load.Item4
                    });
                    break;

                case NEULoadType.NodalMoment:
                    model.Loads.Add(new Load()
                    {
                        Node = model.NodesDictionary[load.Item3], Amount = load.Item5, DOF = dofTypeTranslations[load.Item4]
                    });
                    break;

                default:
                    throw new NotImplementedException("Load type not implemented.");
                }
            }

            var hostGroups     = neuModel.Groups.Where(x => x.Value.Item1.ToUpper().StartsWith(NEUMeshGenerator.hostGroupPrefix)).Select(x => x.Value).OrderBy(x => x.Item1).ToArray();
            var embeddedGroups = neuModel.Groups.Where(x => x.Value.Item1.ToUpper().StartsWith(NEUMeshGenerator.embeddedGroupPrefix)).Select(x => x.Value).OrderBy(x => x.Item1).ToArray();
            var groupSize      = hostGroups.Length;

            if (groupSize != embeddedGroups.Length)
            {
                throw new ArgumentException("Number of host groups is not equalt to number of embedded groups. Check group names.");
            }
            for (int i = 0; i < groupSize; i++)
            {
                var hostName     = hostGroups[i].Item1.Substring(NEUMeshGenerator.hostGroupPrefix.Length);
                var embeddedName = embeddedGroups[i].Item1.Substring(NEUMeshGenerator.embeddedGroupPrefix.Length);
                if (hostName != embeddedName)
                {
                    throw new ArgumentException(String.Format("Current host/embedded pair name does not match ({0} - {1}).", hostName, embeddedName));
                }

                var hostElements     = model.ElementsDictionary.Where(x => hostGroups[i].Item2.Any(id => id == x.Key)).Select(x => x.Value);
                var embeddedElements = model.ElementsDictionary.Where(x => embeddedGroups[i].Item2.Any(id => id == x.Key)).Select(x => x.Value);
                var embeddedGrouping = new EmbeddedGrouping(model, hostElements, embeddedElements, includeRotationsWhenEmbedding);
            }

            var subdomain = new Subdomain()
            {
                ID = 1
            };

            foreach (var element in model.Elements)
            {
                subdomain.ElementsDictionary.Add(element.ID, element);
            }
            model.SubdomainsDictionary.Add(1, subdomain);

            return(model);
        }
 public IFiniteElementMaterial GetMaterial(NEUTopology topology)
 {
     throw new NotImplementedException();
 }