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 readonly DOFType[] directions = new DOFType[] { DOFType.X, DOFType.Y, DOFType.Z, DOFType.RotX, DOFType.RotY, DOFType.RotZ }; public void ExtractData(NEUModel model, IList <string> lines) { int index = 2; while (index < lines.Count - 1) { var splitLine = lines[index].Split(','); int groupId = Int32.Parse(splitLine[0]); bool needsEvaluation = splitLine[1] != "0"; string groupName = lines[index + 1]; if (needsEvaluation && (groupName.ToUpper().StartsWith(NEUMeshGenerator.hostGroupPrefix) || groupName.ToUpper().StartsWith(NEUMeshGenerator.embeddedGroupPrefix))) { throw new ArgumentException(String.Format("Group {0} needs evaluation. Run FEMAP to evaluate group, save and reload.", groupId)); } index += 24; // Rule types while (!lines[index].StartsWith("-1")) { index++; // Entries in rule type while (!lines[index].StartsWith("-1")) { index++; } index++; } index++; // Skip line for max number of entity lists index++; while (!lines[index].StartsWith("-1")) { splitLine = lines[index].Split(','); NEUEntityListType listType = (NEUEntityListType)Int32.Parse(splitLine[0]); if (listType != NEUEntityListType.Element) { throw new ArgumentException("Entity list type not elemental."); } index++; List <int> ids = new List <int>(); while (!lines[index].StartsWith("-1")) { splitLine = lines[index].Split(','); ids.Add(Int32.Parse(splitLine[0])); index++; } index++; model.Groups.Add(groupId, new Tuple <string, List <int> >(groupName, ids)); } index++; } }
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]); NEUMaterialType typeId = (NEUMaterialType)Int32.Parse(idLine[3]); INEUMaterial material = materialObjects.ContainsKey(typeId) ? materialObjects[typeId].BuildFromBlock(lines.ToList <string>().GetRange(index + 9, 2)) : new NEUGeneralMaterial(); model.Materials.Add(id, material); index += 43; } }
public static Model ReadFile(string fileName, bool includeRotationsWhenEmbedding = false) { var model = new NEUModel(); var fileLines = File.ReadAllLines(fileName); var block = new List <string>(); IEnumerable <string> lines = null; lines = GetNextBlock(fileLines, block); while (block.Count > 0) { var blockID = GetNEUDataBlockID(block); if (dataBlockObjects.ContainsKey(blockID)) { dataBlockObjects[blockID].ExtractData(model, block); } lines = GetNextBlock(lines, block); } return(GetModelFromNEUModel(model, includeRotationsWhenEmbedding)); }
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 materialId = Int32.Parse(idLine[2]); NEUElementType typeId = (NEUElementType)Int32.Parse(idLine[3]); int laminaLines = (int)Math.Ceiling(Double.Parse(lines[index + 3], CultureInfo.InvariantCulture) / 8.0); int valueLines = (int)Math.Ceiling(Double.Parse(lines[index + 4 + laminaLines], CultureInfo.InvariantCulture) / 5.0); int outLineLines = Int32.Parse(lines[index + 5 + laminaLines + valueLines].Split(',')[0]); int outLine2Lines = Int32.Parse(lines[index + 6 + laminaLines + valueLines + outLineLines].Split(',')[0]); INEUProperty property = propertyObjects.ContainsKey(typeId) ? propertyObjects[typeId].BuildFromBlock(lines.ToList <string>().GetRange(index + 5 + laminaLines, valueLines)) : new NEUGenericProperty(); property.MaterialID = materialId; model.Properties.Add(id, property); index += 7 + laminaLines + valueLines + outLineLines + outLine2Lines; } }
public void ExtractData(NEUModel model, IList <string> lines) { for (int i = 2; i < lines.Count - 1; i++) { var separatedLine = lines[i].Split(','); int id = Int32.Parse(separatedLine[0]); var node = new Node() { ID = id, X = Double.Parse(separatedLine[11], CultureInfo.InvariantCulture), Y = Double.Parse(separatedLine[12], CultureInfo.InvariantCulture), Z = Double.Parse(separatedLine[13], CultureInfo.InvariantCulture) }; for (int j = 0; j < constraints.Length; j++) { if (Int32.Parse(separatedLine[5 + j]) == 1) { node.Constraints.Add(constraints[j]); } } model.Nodes.Add(id, node); } }
public void ExtractData(NEUModel model, IList <string> lines) { int id = Int32.Parse(lines[2].Split(',')[0]); int index = 4; int nodeId = 0; while (nodeId != -1 && index < lines.Count - 1) { var nodalConstraintsLine = lines[index].Split(','); nodeId = Int32.Parse(nodalConstraintsLine[0]); if (nodeId != -1) { for (int j = 0; j < constraints.Length; j++) { if (Int32.Parse(nodalConstraintsLine[3 + j]) == 1) { model.Constraints.Add(new Tuple <int, DOFType>(nodeId, constraints[j])); } } index++; } } }
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 void ExtractData(NEUModel model, IList <string> lines) { int index = 2; var splitLine = lines[index].Split(','); int loadId = Int32.Parse(splitLine[0]); if (lines.Count == 3) { return; } index += 21; // Mesh based loads while (!lines[index].StartsWith("-1")) { splitLine = lines[index].Split(','); int nodeId = Int32.Parse(splitLine[0]); NEULoadType loadType = (NEULoadType)Int32.Parse(splitLine[1]); splitLine = lines[index + 1].Split(','); bool[] enabledLoads = new bool[] { splitLine[0] == "1", splitLine[1] == "1", splitLine[2] == "1" }; splitLine = lines[index + 2].Split(','); double[] loads = new double[] { Double.Parse(splitLine[0], CultureInfo.InvariantCulture), Double.Parse(splitLine[1], CultureInfo.InvariantCulture), Double.Parse(splitLine[2], CultureInfo.InvariantCulture) }; for (int i = 0; i < 3; i++) { if (enabledLoads[i]) { model.Loads.Add(new Tuple <int, NEULoadType, int, DOFType, double>(loadId, loadType, nodeId, directions[i], loads[i])); } } index += 7; } index++; // Geometry based loads while (!lines[index].StartsWith("-1")) { index += 19; } index++; // Nodal temp based loads while (!lines[index].StartsWith("-1")) { index += 1; } index++; // Element temp based loads while (!lines[index].StartsWith("-1")) { index += 1; } index++; // For version 9.3+ //// Bolt preload loads //while (!lines[index].StartsWith("-1")) //{ // index += 1; //} //index++; //// Load definition loads //while (!lines[index].StartsWith("-1")) //{ // index += 1; //} //index++; }