Beispiel #1
0
        protected void AddStaticAnalysisMetrics(CAD.AssemblyType assemblyRoot)
        {
            if (ExportComponentPoints && cadDataContainer.PointCoordinatesList.Any())
            {
                StaticAnalysisMetrics.AddRange(cadDataContainer.PointCoordinatesList.Where(x => !StaticAnalysisMetrics.Exists(r => r.MetricID == x.MetricID)));
            }

            if (StaticAnalysisMetrics.Any())
            {
                CAD.AnalysesType cadanalysis    = GetCADAnalysis(assemblyRoot);
                CAD.StaticType   staticanalysis = GetStaticAnalysis(cadanalysis);         //CAD.StaticType staticanalysis = new CAD.StaticType();

                List <CAD.MetricType> metriclist = MetricsToCADXMLOutput(StaticAnalysisMetrics);
                staticanalysis.Metrics        = new CAD.MetricsType();
                staticanalysis.Metrics._id    = UtilityHelpers.MakeUdmID();
                staticanalysis.Metrics.Metric = metriclist.ToArray();

                cadanalysis.Static = new CAD.StaticType[] { staticanalysis };
            }
        }
Beispiel #2
0
        public override void TraverseTestBench(CyPhy.TestBenchType testBenchBase)
        {
            CyPhy.KinematicTestBench testBench = testBenchBase as CyPhy.KinematicTestBench;
            if (testBench == null)
            {
                testBench = CyPhyClasses.KinematicTestBench.Cast(testBenchBase.Impl);
            }

            base.TraverseTestBench(testBenchBase);

            //NonSTEP_DataExchangeFormats.Add("Parasolid");

            Name           = testBench.Name;
            SimulationStep = testBench.Attributes.SimulationResolution;
            SimulationTime = testBench.Attributes.Duration;

            if (testBench.Children.GravityLoadCollection.Any())
            {
                CyPhy.GravityLoad load = testBench.Children.GravityLoadCollection.First();
                double            x    = 0;
                double            y    = 0;
                double            z    = 0;

                GetGravityLoadParam(load, "X", out x);
                GetGravityLoadParam(load, "Y", out y);
                GetGravityLoadParam(load, "Z", out z);
                Gravity = new KinematicGravity(x, y, z, load.Attributes.Active);
            }

            var terrain = testBench.Children.ComponentRefCollection.Where(c => ((MgaFCO)c.Impl).MetaRole.Name == "Terrain");

            if (terrain.Any())
            {
                CyPhy.Component terraincomp = terrain.First().AllReferred as CyPhy.Component;
                if (terraincomp == null)
                {
                    Logger.Instance.AddLogMessage("Terrain component reference must refer to a cyphy component.", Severity.Error);
                    return;
                }
                if (!terraincomp.Children.CADModelCollection.Any())
                {
                    Logger.Instance.AddLogMessage("Terrain component must contain a CAD model.", Severity.Error);
                    return;
                }
                TerrainFileName = terraincomp.Children.ResourceCollection.First().Attributes.Path;
                try
                {
                    File.Copy(Path.Combine(terraincomp.GetDirectoryPath(), TerrainFileName), Path.Combine(OutputDirectory, Path.GetFileName(TerrainFileName)));
                }
                catch (Exception e)
                {
                    Logger.Instance.AddLogMessage("Unable to copy terrain file: " + e.Message, Severity.Warning);
                }
                TerrainFileName = Path.GetFileNameWithoutExtension(TerrainFileName);
            }
            else
            {
                if (testBench.Children.AnchorCollection.Any())
                {
                    CyPhy.Anchor anchor    = testBench.Children.AnchorCollection.First();
                    var          pointList = anchor
                                             .DstConnections
                                             .SetAnchorCollection
                                             .Select(x => x.DstEnds.Point)
                                             .Concat(anchor
                                                     .SrcConnections
                                                     .SetAnchorCollection
                                                     .Select(x => x.SrcEnds.Point));

                    if (!pointList.Any())
                    {
                        Logger.Instance.AddLogMessage("Anchor is not connected to a point. Anchor should be connected to a datum point on one of the components.", Severity.Error);
                        return;
                    }

                    var point = pointList.First();
                    PointMetricTraversal traverser = new PointMetricTraversal(point);
                    foreach (var pointFound in traverser.portsFound)
                    {
                        string name        = (pointFound as CyPhy.Point).Attributes.DatumName;
                        string componentID = CyPhyClasses.Component.Cast((pointFound as CyPhy.Point).ParentContainer.ParentContainer.Impl).Attributes.InstanceGUID;
                        StaticAnalysisMetrics.Add(new TBComputation()
                        {
                            ComponentID = componentID, Details = name, MetricID = "Anchor", ComputationType = TBComputation.Type.POINTCOORDINATES, RequestedValueType = "Vector"
                        });
                        //Computations.Add(new TBComputation() { ComponentID = componentID, FeatureDatumName = name, MetricID = "Anchor", ComputationType = TBComputation.Type.POINTCOORDINATES, RequestedValueType = "Vector" });
                        GroundCyphyID = componentID;
                    }
                }
                else
                {
                    Logger.Instance.AddLogMessage("Anchor not found. There should be exactly one anchor in the testbench, to specify which body is fixed to the ground in the kinematic simnulation.", Severity.Error);
                    return;
                }
            }

            foreach (var motion in testBench.Children.MotionLoadCollection)
            {
                var connectorList = motion
                                    .SrcConnections
                                    .ApplyMotionToJointCollection
                                    .Select(x => x.SrcEnds.Connector)
                                    .Concat(motion
                                            .DstConnections
                                            .ApplyMotionToJointCollection
                                            .Select(x => x.DstEnds.Connector)
                                            );

                var toplevelSUT = testBench.Children.ComponentAssemblyCollection.FirstOrDefault();

                foreach (var connector in connectorList)
                {
                    OriginatingConnectorTraversal traverser = new OriginatingConnectorTraversal(connector);

                    if (traverser.result != null)
                    {
                        CyPhy.KinematicJoint joint = GetJoint(traverser.result);
                        if (joint != null)
                        {
                            Multibody.ModelLoadsMotion mbdMotion = new Multibody.ModelLoadsMotion();
                            mbdMotion.Active         = (motion.Attributes.Active) ? Multibody.ModelLoadsMotionActive.on : Multibody.ModelLoadsMotionActive.off;
                            mbdMotion.FreedomType    = (Multibody.ModelLoadsMotionFreedomType)((int)motion.Attributes.JointFreedomType);
                            mbdMotion.Function       = motion.Attributes.CustomFunction;
                            mbdMotion.JointID        = cadDataContainer.GetJointIDFromGMEID(joint.ID);
                            mbdMotion.MotionID       = motion.Name;
                            mbdMotion.TimeDerivative = (Multibody.ModelLoadsMotionTimeDerivative)((int)motion.Attributes.TimeDerivative);
                            mbdMotion.Type           = "JointMotion";

                            MotionList.Add(mbdMotion);
                        }
                        else
                        {
                            Logger.Instance.AddLogMessage("Kinematic motion is connected to a connector without joint information: " + connector.ToHyperLink(), Severity.Error);
                        }
                    }
                }
            }

            if (testBench.Children.AdamsScriptCollection.Any())
            {
                Scripts = new List <Multibody.ModelScript>();
                foreach (var script in testBench.Children.AdamsScriptCollection)
                {
                    Scripts.Add(new Multibody.ModelScript()
                    {
                        Path = script.Attributes.Path
                    });
                }
            }

            ProcessContacts(testBench);
        }
Beispiel #3
0
        public override void TraverseTestBench(CyPhy.TestBenchType testBenchBase)
        {
            CyPhy.TestBench testBench = testBenchBase as CyPhy.TestBench;
            if (testBench == null)
            {
                testBench = CyPhyClasses.TestBench.Cast(testBenchBase.Impl);
            }
            base.TraverseTestBench(testBenchBase);   //AnalysisID = testBench.ID;

            // R.O. added 11/15/2016, because the MSD_CAD.xme/TestBench_Valid was failing because the schema for CADAssmbly.xml requires
            // that ComponentID be set for Metrics/Metric attributes.  For Mass, CenterOfGravity, BoundingBox, and Interference,
            // the metric applies to the entire assembly; therefore, we will use the top-level assembly as the ComponentID.
            var catlsut = testBench.Children.ComponentAssemblyCollection.FirstOrDefault();     // should be an instance b/c elaborate was called earlier

            if (catlsut == null)
            {
                // This check occurs earlier in ProcessCAD(), but will repeat here in case someone changes the code to not
                // test this earlier.
                throw new Exception("There is no elaborated system under test component assembly in the model!");
            }
            // "|1" is set in other places in the code for the top-level assembly.  Search on "|" to see those places.
            // If someone changes to another system ( different suffix than "|1") and does not change the following
            // line, then the CreateAssembly program will throw an exception.  This will be caught by the build tests
            // (e.g. MSD_CAD.xme/TestBench_Valid).
            string topLevelAssemblyComponentInstanceID_temp = catlsut.Attributes.ConfigurationUniqueID + "|" + "1";

            // CADComputations Metrics
            foreach (var conn in testBench.Children.CADComputation2MetricCollection)
            {
                CyPhy.CADComputationType cadcomputation = conn.SrcEnds.CADComputationType;

                TBComputation tbcomputation = new TBComputation();
                tbcomputation.MetricID = conn.DstEnds.Metric.ID;
                if (cadcomputation is CyPhy.CenterOfGravity)
                {
                    tbcomputation.ComponentID        = topLevelAssemblyComponentInstanceID_temp;
                    tbcomputation.RequestedValueType = (cadcomputation as CyPhy.CenterOfGravity).Attributes.CADComputationRequestedValue.ToString();
                    tbcomputation.ComputationType    = TBComputation.Type.CENTEROFGRAVITY;
                }
                else if (cadcomputation is CyPhy.BoundingBox)
                {
                    tbcomputation.ComponentID        = topLevelAssemblyComponentInstanceID_temp;
                    tbcomputation.RequestedValueType = (cadcomputation as CyPhy.BoundingBox).Attributes.CADComputationRequestedValue.ToString();
                    tbcomputation.ComputationType    = TBComputation.Type.BOUNDINGBOX;
                }
                else if (cadcomputation is CyPhy.InterferenceCount)
                {
                    tbcomputation.ComponentID        = topLevelAssemblyComponentInstanceID_temp;
                    tbcomputation.RequestedValueType = "Scalar";
                    tbcomputation.ComputationType    = TBComputation.Type.INTERFERENCECOUNT;
                }
                else if (cadcomputation is CyPhy.Mass)
                {
                    tbcomputation.ComponentID        = topLevelAssemblyComponentInstanceID_temp;
                    tbcomputation.RequestedValueType = "Scalar";
                    tbcomputation.ComputationType    = TBComputation.Type.MASS;
                }

                this.StaticAnalysisMetrics.Add(tbcomputation);
            }

            // PointCoordinate Metrics
            foreach (var metric in testBench.Children.MetricCollection)
            {
                List <CyPhy.Point> points_list = new List <CyPhy.Point>();
                foreach (var pt in metric.SrcConnections.PointCoordinates2MetricCollection)
                {
                    points_list.Add(pt.SrcEnds.Point);
                }

                foreach (var pt in metric.DstConnections.PointCoordinates2MetricCollection)
                {
                    points_list.Add(pt.DstEnds.Point);
                }

                if (points_list.Any())
                {
                    if (points_list.Count() > 1)
                    {
                        Logger.Instance.AddLogMessage("Metric should not be connected to multiple Point datums in a test bench.", Severity.Error);
                    }

                    CyPhy.Point point = points_list.First();

                    PointMetricTraversal traverser = new PointMetricTraversal(point);
                    if (traverser.portsFound.Count() == 1)
                    {
                        TBComputation tbcomputation = new TBComputation();
                        tbcomputation.ComputationType    = TBComputation.Type.POINTCOORDINATES;
                        tbcomputation.MetricID           = metric.ID;
                        tbcomputation.RequestedValueType = "Vector";
                        tbcomputation.Details            = (traverser.portsFound.First() as CyPhy.Point).Attributes.DatumName;
                        tbcomputation.ComponentID        = CyPhyClasses.Component.Cast(traverser.portsFound.First().ParentContainer.ParentContainer.Impl).Attributes.InstanceGUID;
                        tbcomputation.MetricName         = metric.Name;
                        StaticAnalysisMetrics.Add(tbcomputation);
                    }
                }
            }

            // Post Processing Blocks
            foreach (var postprocess in testBench.Children.PostProcessingCollection)
            {
                PostProcessScripts.Add(postprocess.Attributes.ScriptPath);
            }
        }