Example #1
0
        public override void TraverseTestBench(CyPhy.TestBenchType testBenchBase)
        {           
            string stepFormat = "AP203_E2_Single_File";
            if (!DataExchangeFormats.Contains(stepFormat))
                DataExchangeFormats.Add(stepFormat);

            CyPhy.CADTestBench testBench = testBenchBase as CyPhy.CADTestBench;
            if (testBench == null)
                testBench = CyPhyClasses.CADTestBench.Cast(testBenchBase.Impl);

            this.CyphyTestBenchRef = testBench;
            base.TraverseTestBench(testBenchBase);

            AdjSurfTreatment = CyphyTestBenchRef.Attributes.AdjoiningTreatment;

            // Solver Settings
            ElementType = "MIDPOINT_PARABOLIC_FIXED";
            ShellType = "N/A";
            SolverType = testBench.Attributes.SolverType.ToString(); 
            MeshType = "SOLID";
            MaxAdaptiveIterations = testBench.Attributes.MaxAdaptiveIterations;

            FEAAnalysisType = "STRUCTURAL";
            if (testBench.Children.ThermalLoadCollection.Any() || testBench.Children.ThermalEnvironmentCollection.Any())
            {
                FEAAnalysisType = "THERMAL";
            }


            // Metrics
            foreach (var item in testBench.Children.TIP2StructuralMetricCollection)
            {
                if (item.SrcEnds.TestInjectionPoint != null)
                {
                    CyPhy.TestInjectionPoint tip = item.SrcEnds.TestInjectionPoint;
                    CyPhy.StructuralFEAComputation feaComp = item.DstEnds.StructuralFEAComputation;

                    if (tip.AllReferred == null)
                        continue;

                    List<CyPhy.Component> testComponents = new List<CyPhy.Component>();
                    if (tip.AllReferred is CyPhy.ComponentAssembly)
                    {
                        CollectLeafComponents(testComponents, tip.AllReferred as CyPhy.ComponentAssembly);
                    }
                    else if (tip.AllReferred is CyPhy.Component)
                    {
                        // Interested in components with CAD Model only
                        if ((tip.AllReferred as CyPhy.Component).Children.CADModelCollection.Any())
                            testComponents.Add(tip.AllReferred as CyPhy.Component);
                    }

                    foreach (CyPhy.Component comp in testComponents)
                    {
                        string compId = comp.Attributes.InstanceGUID;

                        foreach (var cyphycompport in feaComp.Children.StructuralAnalysisComputationTypeCollection)
                        {
                            TBComputation tbcomputation = new TBComputation();
                            if (cyphycompport is CyPhy.BearingStress)
                            {
                                tbcomputation.ComputationType = TBComputation.Type.BEARINGSTRESS;
                            } else if (cyphycompport is CyPhy.MisesStress)
                            {
                                tbcomputation.ComputationType = TBComputation.Type.VONMISESSTRESS;
                            } else if (cyphycompport is CyPhy.ShearStress)
                            {
                                tbcomputation.ComputationType = TBComputation.Type.SHEARSTRESS;
                            } else if (cyphycompport is CyPhy.MaximumDisplacement)
                            {
                                tbcomputation.ComputationType = TBComputation.Type.DISPLACEMENT;
                            } else if (cyphycompport is CyPhy.FactorOfSafety)
                            {
                                tbcomputation.ComputationType = TBComputation.Type.FACTOROFSAFETY;
                            }
                            tbcomputation.FeatureDatumName = "";
                            tbcomputation.RequestedValueType = "Scalar";
                            tbcomputation.Details = "InfiniteCycle";
                            tbcomputation.ComponentID = compId;

                            foreach (var cyphyconn in cyphycompport.DstConnections.FEAComputation2MetricCollection)
                            {
                                tbcomputation.MetricID = cyphyconn.DstEnds.Metric.ID;
                            }

                            if (!String.IsNullOrEmpty(tbcomputation.MetricID))
                                this.Computations.Add(tbcomputation);
                        }
                    }
                }
            }

            // Thermal Metrics
            foreach (var item in testBench.Children.TIP2ThermalMetricCollection)
            {
                if (item.SrcEnds.TestInjectionPoint != null)
                {
                    CyPhy.TestInjectionPoint tip = item.SrcEnds.TestInjectionPoint;
                    CyPhy.ThermalFEAComputation feaComp = item.DstEnds.ThermalFEAComputation;

                    if (tip.AllReferred == null)
                        continue;

                    List<CyPhy.Component> testComponents = new List<CyPhy.Component>();
                    if (tip.AllReferred is CyPhy.ComponentAssembly)
                    {
                        CollectLeafComponents(testComponents, tip.AllReferred as CyPhy.ComponentAssembly);
                    }
                    else if (tip.AllReferred is CyPhy.Component)
                    {
                        // Interested in components with CAD Model only
                        if ((tip.AllReferred as CyPhy.Component).Children.CADModelCollection.Any())
                            testComponents.Add(tip.AllReferred as CyPhy.Component);
                    }

                    foreach (CyPhy.Component comp in testComponents)
                    {
                        string compId = comp.Attributes.InstanceGUID;

                        foreach (var cyphycompport in feaComp.Children.ThermalAnalysisMetricsCollection)
                        {
                            TBComputation tbcomputation = new TBComputation();
                            if (cyphycompport is CyPhy.MinimumTemperature)
                            {
                                tbcomputation.ComputationType = TBComputation.Type.MINIMUMTEMPERATURE;
                            } else if (cyphycompport is CyPhy.MaximumTemperature)
                            {
                                tbcomputation.ComputationType = TBComputation.Type.MAXIMUMTEMPERATURE;
                            }
                            tbcomputation.FeatureDatumName = "";
                            tbcomputation.RequestedValueType = "Scalar";
                            tbcomputation.Details = "InfiniteCycle";
                            tbcomputation.ComponentID = compId;

                            foreach (var cyphyconn in cyphycompport.DstConnections.FEAComputation2MetricCollection)
                            {
                                tbcomputation.MetricID = cyphyconn.DstEnds.Metric.ID;
                            }

                            if (!String.IsNullOrEmpty(tbcomputation.MetricID))
                                this.Computations.Add(tbcomputation);
                        }
                    }
                }
            }

            bool convectionPresent = false;
            bool ambientTempPresent = false;

            // thermal elements
            foreach(var item in testBench.Children.ThermalFEAElementsCollection)
            {
                foreach (var conn in item.DstConnections.ThermalElement2TIPCollection)
                {
                    CyPhy.TestInjectionPoint tip = conn.DstEnds.TestInjectionPoint;

                    if (tip.AllReferred == null)
                        continue;

                    List<CyPhy.Component> testComponents = new List<CyPhy.Component>();
                    if (tip.AllReferred is CyPhy.ComponentAssembly)
                    {
                        CollectLeafComponents(testComponents, tip.AllReferred as CyPhy.ComponentAssembly);
                    }
                    else if (tip.AllReferred is CyPhy.Component)
                    {
                        // Interested in components with CAD Model only
                        if ((tip.AllReferred as CyPhy.Component).Children.CADModelCollection.Any())
                            testComponents.Add(tip.AllReferred as CyPhy.Component);
                    }

                    foreach (var component in testComponents)
                    {
                        FEAThermalElement[] element = FEAThermalElement.Extract(item, component.Attributes.InstanceGUID, null);
                        if (element.Where(e => e.Type == "Convection").Any())
                        {
                            convectionPresent = true;
                        }
                        ThermalElements.AddRange(element);
                    }
                }

                foreach (var conn in item.DstConnections.ThermalElements2GeometryCollection)
                {
                    CyPhy.GeometryBase geometryBase = conn.DstEnds.GeometryTypes;
                    string tipContextPath = Path.GetDirectoryName(geometryBase.Path);
                    CADGeometry geometryRep = FillOutGeometryRep(geometryBase.Impl as MgaFCO,
                                                                 tipContextPath);
                    FEAThermalElement[] element = FEAThermalElement.Extract(item, null, geometryRep);
                    ThermalElements.AddRange(element);
                }
            }

            if (testBench.Children.ThermalEnvironmentCollection.Any())
            {
                if (testBench.Children.ThermalEnvironmentCollection.Count() > 1)
                {
                    Logger.Instance.AddLogMessage("Multiple ThermalEnvironments are present in the testbench. There should be only one.", Severity.Error);
                }
                else
                {
                    if (!testBench.Children.ThermalEnvironmentCollection.First().Children.ParameterCollection.Any())
                    {
                        Logger.Instance.AddLogMessage("ThermalEnvironment is present but there are no parameters specified in it.", Severity.Warning);
                    }
                    else
                    {
                        foreach (var param in testBench.Children.ThermalEnvironmentCollection.First().Children.ParameterCollection)
                        {
                            var elem = new FEAThermalElement(param) { Unit = "K", ComponentID = cadDataContainer.assemblies.First().Key };
                            ThermalElements.Add(elem);
                            ambientTempPresent = true;
                        }
                    }
                }
            }

            if (convectionPresent && !ambientTempPresent)
            {
                Logger.Instance.AddLogMessage("Convection is present but no Ambient Temperature has been specified. Please specify Ambient Temperature.", Severity.Error);
            }

            // Constraints
            foreach (var cyphyconstraint in testBench.Children.AnalysisConstraintCollection)
            {
                if (cyphyconstraint.Kind == "PinConstraint")
                {
                    CyPhy.PinConstraint pinConstraint = CyPhyClasses.PinConstraint.Cast(cyphyconstraint.Impl);

                    // Geometry - must be a cylinder
                    foreach (var geometry in pinConstraint.DstConnections.Pin2CylinderCollection)
                    {
                        FEAPinConstraint feapinRep = new FEAPinConstraint();
                        feapinRep.AxialDisplacement = pinConstraint.Attributes.AxialDisplacement.ToString();
                        feapinRep.AxialRotation = pinConstraint.Attributes.AxialRotation.ToString();

                        CyPhy.CylinderGeometryType cylinderType = geometry.DstEnds.CylinderGeometryType;
                        if (cylinderType != null)
                        {
                            string tipContextPath = Path.GetDirectoryName(cylinderType.Path);
                            AddGeometry2Constraint(feapinRep,
                                                   cylinderType.Impl as MgaFCO,
                                                   tipContextPath, true);
                        }
                    }

                }
                else if (cyphyconstraint.Kind == "BallConstraint")
                {
                    CyPhy.BallConstraint ballConstraint = CyPhyClasses.BallConstraint.Cast(cyphyconstraint.Impl);

                    foreach (var item in ballConstraint.DstConnections.Ball2SphereCollection)
                    {
                        FEABallConstraint feaballRep = new FEABallConstraint();
                        CyPhy.SphereGeometryType sphereType = item.DstEnds.SphereGeometryType;
                        if (sphereType != null)
                        {
                            string tipContextPath = Path.GetDirectoryName(sphereType.Path);
                            AddGeometry2Constraint(feaballRep,
                                                   sphereType.Impl as MgaFCO,
                                                   tipContextPath, true);
                        }
                    }
                }
                else if (cyphyconstraint.Kind == "DisplacementConstraint")
                {
                    CyPhy.DisplacementConstraint displacementConstraint = CyPhyClasses.DisplacementConstraint.Cast(cyphyconstraint.Impl);                    

                    string tx = "FREE", ty = "FREE", tz = "FREE", tunit = "mm", rx = "FREE", ry = "FREE", rz = "FREE", runit = "deg";

                    CyPhy.Rotation rotation = displacementConstraint.Children.RotationCollection.FirstOrDefault();
                    if (rotation != null)
                    {
                        bool hasScalar = (rotation.Attributes.XDirection == CyPhyClasses.Rotation.AttributesClass.XDirection_enum.SCALAR) ||
                                         (rotation.Attributes.YDirection == CyPhyClasses.Rotation.AttributesClass.YDirection_enum.SCALAR) ||
                                         (rotation.Attributes.ZDirection == CyPhyClasses.Rotation.AttributesClass.ZDirection_enum.SCALAR) ;
                        rx = (rotation.Attributes.XDirection == CyPhyClasses.Rotation.AttributesClass.XDirection_enum.SCALAR) ? 
                              rotation.Attributes.XDirectionValue.ToString() : rotation.Attributes.XDirection.ToString();
                        ry = (rotation.Attributes.YDirection == CyPhyClasses.Rotation.AttributesClass.YDirection_enum.SCALAR) ?
                              rotation.Attributes.YDirectionValue.ToString() : rotation.Attributes.YDirection.ToString();
                        rz = (rotation.Attributes.ZDirection == CyPhyClasses.Rotation.AttributesClass.ZDirection_enum.SCALAR) ?
                              rotation.Attributes.ZDirectionValue.ToString() : rotation.Attributes.ZDirection.ToString();

                        if (!hasScalar)
                        {
                            runit = "N/A";
                        }
                        else
                        {
                            if (rotation.Referred.unit != null)
                                runit = rotation.Referred.unit.Name;
                        }
                    }

                    CyPhy.Translation translation = displacementConstraint.Children.TranslationCollection.FirstOrDefault();
                    if (translation != null)
                    {
                        bool hasScalar = (translation.Attributes.XDirection == CyPhyClasses.Translation.AttributesClass.XDirection_enum.SCALAR) ||
                                         (translation.Attributes.YDirection == CyPhyClasses.Translation.AttributesClass.YDirection_enum.SCALAR) ||
                                         (translation.Attributes.ZDirection == CyPhyClasses.Translation.AttributesClass.ZDirection_enum.SCALAR);
                        tx = (translation.Attributes.XDirection == CyPhyClasses.Translation.AttributesClass.XDirection_enum.SCALAR) ?
                              translation.Attributes.XDirectionValue.ToString() : translation.Attributes.XDirection.ToString();
                        ty = (translation.Attributes.YDirection == CyPhyClasses.Translation.AttributesClass.YDirection_enum.SCALAR) ?
                              translation.Attributes.YDirectionValue.ToString() : translation.Attributes.YDirection.ToString();
                        tz = (translation.Attributes.ZDirection == CyPhyClasses.Translation.AttributesClass.ZDirection_enum.SCALAR) ?
                              translation.Attributes.ZDirectionValue.ToString() : translation.Attributes.ZDirection.ToString();

                        if (!hasScalar)
                        {
                            tunit = "N/A";
                        }
                        else
                        {
                            if (translation.Referred.unit != null)
                                tunit = translation.Referred.unit.Name;
                        }
                        
                    }


                    foreach (var item in displacementConstraint.DstConnections.Displacement2GeometryCollection)
                    {
                        FEADisplacementConstraint feadispRep = new FEADisplacementConstraint();
                        feadispRep.Rotation_X = rx;
                        feadispRep.Rotation_Y = ry;
                        feadispRep.Rotation_Z = rz;
                        feadispRep.RotationUnits = runit;
                        feadispRep.Translation_X = tx;
                        feadispRep.Translation_Y = ty;
                        feadispRep.Translation_Z = tz;
                        feadispRep.TranslationUnits = tunit;

                        Logger.Instance.AddLogMessage(String.Format("DisplacementConstraint Units - Rotation Component = {0}, Translation Component = {1}", runit, tunit), Severity.Info);

                        CyPhy.GeometryBase geometry = item.DstEnds.GeometryBase;
                        if (geometry != null)
                        {
                            string tipContextPath = Path.GetDirectoryName(geometry.Path);
                            AddGeometry2Constraint(feadispRep,
                                                   geometry.Impl as MgaFCO,
                                                   tipContextPath, true);
                        }
                    }
                }
                
            }

            // Loads
            foreach (var cyphyload in testBench.Children.AnalysisLoadCollection)
            {
                if (cyphyload is CyPhy.ForceLoadParam)
                {
                    CyPhy.ForceLoadParam forceLoad = CyPhyClasses.ForceLoadParam.Cast(cyphyload.Impl);

                    double fx = 0.0, fy = 0.0, fz = 0.0, mx = 0.0, my = 0.0, mz = 0.0;
                    string funit = "N", munit = "N-mm";

                    CyPhy.Parameter p1 = GetForceLoadParam(forceLoad, "ForceX", out fx);
                    GetForceLoadParam(forceLoad, "ForceY", out fy);
                    GetForceLoadParam(forceLoad, "ForceZ", out fz);
                    CyPhy.Parameter p2 = GetForceLoadParam(forceLoad, "MomentX", out mx);
                    GetForceLoadParam(forceLoad, "MomentY", out my);
                    GetForceLoadParam(forceLoad, "MomentZ", out mz);

                    GetParamUnitName(p1, ref funit);
                    GetParamUnitName(p2, ref munit);


                    foreach (var item in forceLoad.DstConnections.ForceLoadParam2GeometryCollection)

                    {
                        FEAForceLoad feaforceRep = new FEAForceLoad();
                        feaforceRep.Force_X = fx;
                        feaforceRep.Force_Y = fy;
                        feaforceRep.Force_Z = fz;
                        feaforceRep.ForceUnit = funit;
                        feaforceRep.Moment_X = mx;
                        feaforceRep.Moment_Y = my;
                        feaforceRep.Moment_Z = mz;
                        feaforceRep.MomentUnit = munit;

                        Logger.Instance.AddLogMessage(String.Format("ForceLoad Units - Force Component = {0}, Moment Component = {1}", funit, munit), Severity.Info);

                        CyPhy.GeometryBase geometry = item.DstEnds.GeometryBase;
                        if (geometry != null)
                        {
                            string tipContextPath = Path.GetDirectoryName(geometry.Path);
                            AddGeometry2Load(feaforceRep,
                                             geometry.Impl as MgaFCO,
                                             tipContextPath, true);
                        }
                    }
                }
                else
                if (cyphyload is CyPhy.ForceLoad)
                {
                    Logger.Instance.AddLogMessage("ForceLoad is used in FEA testbench. This construct is obsolete, please use ForceLoadParam instead.", Severity.Warning);
                    CyPhy.ForceLoad forceLoad = CyPhyClasses.ForceLoad.Cast(cyphyload.Impl);
                    
                    double fx = 0.0, fy = 0.0, fz = 0.0, mx = 0.0, my = 0.0, mz = 0.0;
		            string funit = "N", munit = "N-mm";

                    CyPhy.Force force = forceLoad.Children.ForceCollection.FirstOrDefault();
                    if (force != null)
                    {
                        fx = force.Attributes.XDirectionValue;
                        fy = force.Attributes.YDirectionValue;
                        fz = force.Attributes.ZDirectionValue;
                        if (force.Referred.unit != null)
                            funit = force.Referred.unit.Name;
                    }

                    CyPhy.Moment moment = forceLoad.Children.MomentCollection.FirstOrDefault();
                    if (moment != null)
                    {
                        mx = moment.Attributes.XDirectionValue;
                        my = moment.Attributes.YDirectionValue;
                        mz = moment.Attributes.ZDirectionValue;
                        if (moment.Referred.unit != null)
                            munit = moment.Referred.unit.Name;
                    }


                    foreach (var item in forceLoad.DstConnections.Force2GeometryCollection)
                    {
                        FEAForceLoad feaforceRep = new FEAForceLoad();
                        feaforceRep.Force_X = fx;
                        feaforceRep.Force_Y = fy;
                        feaforceRep.Force_Z = fz;
                        feaforceRep.ForceUnit = funit;
                        feaforceRep.Moment_X = mx;
                        feaforceRep.Moment_Y = my;
                        feaforceRep.Moment_Z = mz;
                        feaforceRep.MomentUnit = munit;

                        Logger.Instance.AddLogMessage(String.Format("ForceLoad Units - Force Component = {0}, Moment Component = {1}", funit, munit), Severity.Info);

                        CyPhy.GeometryBase geometry = item.DstEnds.GeometryBase;
                        if (geometry != null)
                        {
                            string tipContextPath = Path.GetDirectoryName(geometry.Path);
                            AddGeometry2Load(feaforceRep,
                                             geometry.Impl as MgaFCO,
                                             tipContextPath, true);
                        }
                    }

                }
                else if (cyphyload is CyPhy.AccelerationLoadParam)
                {
                    CyPhy.AccelerationLoadParam acceleration = CyPhyClasses.AccelerationLoadParam.Cast(cyphyload.Impl);
                    FEAccelerationLoad feaaccelRep = new FEAccelerationLoad();
                    double x = 0;
                    double y = 0;
                    double z = 0;
                    CyPhy.Parameter p1 = GetAccelerationLoadParam(acceleration, "X", out x);
                    GetAccelerationLoadParam(acceleration, "Y", out y);
                    GetAccelerationLoadParam(acceleration, "Z", out z);
                    feaaccelRep.X = x;
                    feaaccelRep.Y = y;
                    feaaccelRep.Z = z;

                    string unit = "mm/s^2";
                    GetParamUnitName(p1, ref unit);
                    feaaccelRep.Units = unit;

                    Logger.Instance.AddLogMessage(String.Format("AccelerationLoad Units = {0}", feaaccelRep.Units), Severity.Info);

                    this.Loads.Add(feaaccelRep);

                }
                else if (cyphyload is CyPhy.AccelerationLoad)
                {
                    Logger.Instance.AddLogMessage("AccelerationLoad is used in FEA testbench. This construct is obsolete, please use AccelerationLoadParam instead.", Severity.Warning);
                    CyPhy.AccelerationLoad acceleration = CyPhyClasses.AccelerationLoad.Cast(cyphyload.Impl);
                    FEAccelerationLoad feaaccelRep = new FEAccelerationLoad();
                    feaaccelRep.X = acceleration.Attributes.XDirectionValue;
                    feaaccelRep.Y = acceleration.Attributes.YDirectionValue;
                    feaaccelRep.Z = acceleration.Attributes.ZDirectionValue;
                    if (acceleration.Referred.unit != null)
                        feaaccelRep.Units = acceleration.Referred.unit.Name;
                    else
                        feaaccelRep.Units = "mm/s^2";

                    Logger.Instance.AddLogMessage(String.Format("AccelerationLoad Units = {0}", feaaccelRep.Units), Severity.Info);

                    this.Loads.Add(feaaccelRep);
                }
                else if (cyphyload is CyPhy.PressureLoadParam)
                {
                    CyPhy.PressureLoadParam pressure = CyPhyClasses.PressureLoadParam.Cast(cyphyload.Impl);

                    foreach (var item in pressure.DstConnections.PressureParam2GeometryCollection)
                    {
                        FEAPressureLoad feapressRep = new FEAPressureLoad();
                        double p = 0;
                        CyPhy.Parameter p1 = GetPressureLoadParam(pressure, "PressureLoad", out p);
                        feapressRep.Value = p;
                        string unit = "MPa";
                        GetParamUnitName(p1, ref unit);
                        feapressRep.Units = unit;

                        Logger.Instance.AddLogMessage(String.Format("PressureLoad Units = {0}", feapressRep.Units), Severity.Info);

                        CyPhy.GeometryBase geometry = item.DstEnds.GeometryBase;
                        if (geometry != null)
                        {
                            string tipContextPath = Path.GetDirectoryName(geometry.Path);
                            AddGeometry2Load(feapressRep,
                                             geometry.Impl as MgaFCO,
                                             tipContextPath, true);
                        }
                    }
                }
                else if (cyphyload is CyPhy.PressureLoad)
                {
                    Logger.Instance.AddLogMessage("PressureLoad is used in FEA testbench. This construct is obsolete, please use PressureLoadParam instead.", Severity.Warning);

                    CyPhy.PressureLoad pressure = CyPhyClasses.PressureLoad.Cast(cyphyload.Impl);

                    foreach (var item in pressure.DstConnections.Pressure2GeometryCollection)
                    {
                        FEAPressureLoad feapressRep = new FEAPressureLoad();
                        feapressRep.Value = pressure.Attributes.Value;
                        if (pressure.Referred.unit != null)
                            feapressRep.Units = pressure.Referred.unit.Name;
                        else
                            feapressRep.Units = "MPa";

                        Logger.Instance.AddLogMessage(String.Format("PressureLoad Units = {0}", feapressRep.Units), Severity.Info);

                        CyPhy.GeometryBase geometry = item.DstEnds.GeometryBase;
                        if (geometry != null)
                        {
                            string tipContextPath = Path.GetDirectoryName(geometry.Path);
                            AddGeometry2Load(feapressRep,
                                             geometry.Impl as MgaFCO,
                                             tipContextPath, true);
                        }
                    }
                }
            }
            // Post Processing Blocks
            foreach (var postprocess in testBench.Children.PostProcessingCollection)
            {
                PostProcessScripts.Add(postprocess.Attributes.ScriptPath);
            }


        }
Example #2
0
        /***************************************************************************/
        /************************* Test Injection Points ***************************/
        /***************************************************************************/
        public void CreateFlatData(CyPhy.CADTestBench testBench,
                                   string catlsut)
        {
            List <CyPhy.Component> regular  = new List <CyPhy.Component>();
            List <CyPhy.Component> size2fit = new List <CyPhy.Component>();

            bool asmprocessed = false;


            var toplevelSUT = testBench.Children.ComponentAssemblyCollection.FirstOrDefault();     // should be an instance b/c elaborate was called earlier

            // CyPhy2CAD_CSharp::ProcessCAD already validated that toplevelSUT != null.  Check again in case some removes the check in  CyPhy2CAD_CSharp::ProcessCAD
            if (toplevelSUT != null)
            {
                // We must cover the case where the TestBench (TB) only consists of TestInjectionPoints that are
                // only Components and not ComponentAssemblies.  The following code in this function does not accomodate
                // that case.  Adding the ReferenceCoordinateSystems now will assure that if a ReferenceCoordinateSystem is set for
                // a Component (i.e. part not assembly) that the ReferenceCoordinateSystem will be used and will force that
                // component to be added first.
                // Also, note that the FindStartingComponent function ignores components with ReferenceCoordinateSystems if those components
                // are not actually referenced by the TB.  In other words, adding ReferenceCoordinateSystems to
                // CyPhy2CAD_CSharp::referenceCoordComponents that are not actually referenced by the TB is not a problem.
                ProcessReferenceCoordinateSystems(toplevelSUT);
            }

            foreach (var tip in testBench.Children.TestInjectionPointCollection)
            {
                if (tip.Referred != null)
                {
                    string tipKind = tip.Referred.TIPRefBase.Kind;
                    Logger.Instance.AddLogMessage("Test Injection Point kind is: [" + tipKind + "]", Severity.Info);
                    if (tipKind == "Component")
                    {
                        CyPhy.Component component = tip.Referred.Component;
                        if (CheckComponent(component))
                        {
                            // size2fit or regular
                            if (component.Children.SizedToFitCollection.Any())
                            {
                                size2fit.Add(component);
                            }
                            else
                            {
                                regular.Add(component);
                            }
                        }
                    }
                    else if (tipKind == "ComponentAssembly")
                    {
                        List <CyPhy.Component>  asmregular            = new List <CyPhy.Component>();
                        List <CyPhy.Component>  asmsize2fitcomponents = new List <CyPhy.Component>();
                        CyPhy.ComponentAssembly componentAsm          = tip.Referred.ComponentAssembly;
                        FindComponents(componentAsm,
                                       asmregular,
                                       asmsize2fitcomponents);
                        ProcessComponents(asmregular, asmsize2fitcomponents, componentAsm);
                        ProcessReferenceCoordinateSystems(componentAsm);
                        asmprocessed = true;
                    }
                    else
                    {
                        Logger.Instance.AddLogMessage("Not supported Test Injection Point kind [" + tipKind + "]", Severity.Error);
                    }
                }
                else
                {
                    throw new META.InterpreterException("Null Test Injection Point in FEA Test Bench!");
                }
            }

            /*
             * if (regular.Count < 1)
             * {
             * }
             *
             * // [] Create CADComponent, size2fit, and edges
             * foreach (var item in regular)
             * {
             *  DataRep.CADComponent component = new DataRep.CADComponent(item, ProjectDirectory: this.ProjectDirectory);
             *  this.regularComponents[item.ID] = component;
             *
             * }
             *
             * foreach (var item in size2fit)
             * {
             *  DataRep.CADComponent component = new DataRep.CADComponent(item, ProjectDirectory: this.ProjectDirectory, size2fit: true);
             *  this.size2fitComponents[item.ID] = component;
             * }
             *
             * // [] Create Edges
             * foreach (KeyValuePair<string, DataRep.CADComponent> item in size2fitComponents)
             * {
             *  CreateEdges(item.Value, null, true); // snyako: what's the top assembly here?
             * }
             *
             * foreach (KeyValuePair<string, DataRep.CADComponent> item in regularComponents)
             * {
             *  CreateEdges(item.Value, null); // snyako: what's the top assembly here?
             * }
             *
             * // [] Print Assembly
             * PrintAssembly();*/

            if (!asmprocessed || (regular.Count != 0 && size2fit.Count != 0))
            {
                ProcessComponents(regular, size2fit, null);
            }
        }
Example #3
0
        private void ProcessCAD(MgaFCO currentobj)
        {
            string outputdir = this.mainParameters.OutputDirectory;

            if (!Directory.Exists(outputdir))
            {
                Directory.CreateDirectory(outputdir);
            }

            string debuglogdir = Path.Combine(outputdir, "log");

            if (!Directory.Exists(debuglogdir))
            {
                Directory.CreateDirectory(debuglogdir);
            }

            string projectdir = this.mainParameters.ProjectDirectory;

            CyPhy2CADSettings cadSetting = (CyPhy2CADSettings)this.mainParameters.config;
            string            cadauxdir  = cadSetting.AuxiliaryDirectory;

            CyPhy.ComponentAssembly curassembly;


            string curObjMetaBase = currentobj.MetaBase.Name;

            if (curObjMetaBase == "TestBench" || curObjMetaBase == "BallisticTestBench" || curObjMetaBase == "CFDTestBench" || curObjMetaBase == "BlastTestBench" || curObjMetaBase == "KinematicTestBench")
            {
                CyPhy.TestBenchType tb = CyPhyClasses.TestBenchType.Cast(currentobj);
                if (result != null && curObjMetaBase == "BlastTestBench")
                {
                    result.Labels = JobManager.Job.DefaultLabels + "&&SwRI_Blast";
                }
                if (result != null && curObjMetaBase == "KinematicTestBench")
                {
                    result.Labels = JobManager.Job.DefaultLabels + "&&Adams";
                }

                var catlsut = tb.Children.ComponentAssemblyCollection.FirstOrDefault();     // should be an instance b/c elaborate was called earlier
                if (catlsut == null)
                {
                    result.Success = false;
                    throw new Exception("There is no elaborated system under test component assembly in the model!");
                }

                curassembly = catlsut;

                if (curassembly == null)
                {
                    result.Success = false;
                    throw new Exception("No Valid Component Assembly.");
                }

                // META-1971: ADM + ACM file export for blast + ballistics
                if (curObjMetaBase == "BallisticTestBench" || curObjMetaBase == "BlastTestBench")
                {
                    // ADM: Export DDP 2.x version (XML)
                    {
                        var    design        = CyPhy2DesignInterchange.CyPhy2DesignInterchange.Convert(catlsut, this.result.Traceability);
                        string TestBenchName = tb.Name;

                        string admDir = Path.Combine(cadSetting.OutputDirectory, "DesignADM");
                        if (!Directory.Exists(admDir))
                        {
                            Directory.CreateDirectory(admDir);
                        }
                        OpenMETA.Interchange.AvmXmlSerializer.SaveToFile(Path.Combine(admDir, TestBenchName + ".adm"), design);
                    }
                }
                // end META-1971

                // META-2987
                GenerateCADParameterMapping(tb,
                                            outputdir, new List <object>());

                CADFlatDataCreator datacreator = new CADFlatDataCreator(debuglogdir, this.mainParameters.ProjectDirectory, CadFormat);
                datacreator.Traceability = this.result.Traceability;
                datacreator.CreateFlatData(curassembly);
                DataRep.CADContainer cadcontainer = datacreator.CreateCADDataContainer(curassembly.Attributes.ConfigurationUniqueID,
                                                                                       UtilityHelpers.CleanString2(curassembly.Name));

                using (StreamWriter writer = new StreamWriter(Path.Combine(outputdir, "log", "CyPhy2CAD_Graphviz_Representation.gv")))
                {
                    writer.WriteLine(cadcontainer.ToGraphviz(true));
                }

                if (!cadcontainer.IsAnalyzable() && curObjMetaBase != "TestBench")
                {
                    result.Success = false;
                    //Logger.Instance.AddLogMessage("Test Bench can not proceed because the test bench contains islands and/or orphans! Please see graphviz file in /log directory for details.", Severity.Error);
                    throw new META.InterpreterException("Test Bench can not proceed because the test bench contains islands and/or orphans, see graphviz file in /log/CyPhy2CAD_Graphviz_Representation.gv for details. Please remove islands/orphans and try again.");
                }

                TestBenchModel.TestBenchBase testBenchRep = TestBenchModelFactory.CreateTestBenchModel(curObjMetaBase,
                                                                                                       cadSetting,
                                                                                                       outputdir,
                                                                                                       projectdir,
                                                                                                       Automation);

                testBenchRep.cadDataContainer = cadcontainer;
                testBenchRep.CopySTL          = this.CopySTL;

                if (curObjMetaBase != "ComponentAssembly")
                {
                    testBenchRep.TraverseTestBench(tb);
                }

                testBenchRep.CollectDirectories();
                result.Success = testBenchRep.GenerateOutputFiles();
            }
            else if (curObjMetaBase == "CADTestBench")
            {
                CyPhy.CADTestBench tb = CyPhyClasses.CADTestBench.Cast(currentobj);
                // META-1701: label for Abaqus
                if (result != null)
                {
                    Dictionary <CyPhyClasses.CADTestBench.AttributesClass.SolverType_enum, string> labelMap = new Dictionary <CyPhyClasses.CADTestBench.AttributesClass.SolverType_enum, string>()
                    {
                        { CyPhyClasses.CADTestBench.AttributesClass.SolverType_enum.ABAQUS_Deck_Based, "Abaqus" },
                        { CyPhyClasses.CADTestBench.AttributesClass.SolverType_enum.ABAQUS_Model_Based, "Abaqus" },
                        { CyPhyClasses.CADTestBench.AttributesClass.SolverType_enum.NASTRAN, "Nastran" },
                    };
                    string label = "Abaqus";
                    labelMap.TryGetValue(tb.Attributes.SolverType, out label);
                    result.Labels += "&&" + label;
                }
                var toplevelSUT = tb.Children.ComponentAssemblyCollection.FirstOrDefault();     // should be an instance b/c elaborate was called earlier
                if (toplevelSUT == null)
                {
                    result.Success = false;
                    throw new Exception("There is no elaborated system under test component assembly in the model!");
                }

                CADFlatDataCreator datacreator = new CADFlatDataCreator(debuglogdir, this.mainParameters.ProjectDirectory, CadFormat);
                datacreator.Traceability = this.result.Traceability;
                datacreator.CreateFlatData(tb,
                                           toplevelSUT.Path);
                DataRep.CADContainer cadcontainer = datacreator.CreateCADDataContainer(tb.Guid.ToString(),
                                                                                       UtilityHelpers.CleanString2(tb.Name));

                using (StreamWriter writer = new StreamWriter(Path.Combine(outputdir, "log", "CyPhy2CAD_Graphviz_Representation.gv")))
                {
                    writer.WriteLine(cadcontainer.ToGraphviz(true));
                }
                result.Success = false;

                if (!cadcontainer.IsAnalyzable())
                {
                    //Logger.Instance.AddLogMessage("FEA Test Bench can not proceed because the test bench contains islands and/or orphans! Please see graphviz file in /log directory for details.", Severity.Error);
                    throw new META.InterpreterException("FEA Test Bench can not proceed because the test bench contains islands and/or orphans, see graphviz file in /log/CyPhy2CAD_Graphviz_Representation.gv for details. Please remove islands/orphans and try again.");
                }

                TestBenchModel.TestBenchBase testBenchRep = TestBenchModelFactory.CreateTestBenchModel(curObjMetaBase,
                                                                                                       cadSetting,
                                                                                                       outputdir,
                                                                                                       projectdir,
                                                                                                       Automation);
                testBenchRep.cadDataContainer = cadcontainer;
                testBenchRep.CopySTL          = this.CopySTL;
                testBenchRep.TraverseTestBench(tb);
                testBenchRep.CollectDirectories();
                result.Success = testBenchRep.GenerateOutputFiles();

                List <object> mappings = new List <object>();
                if (testBenchRep is TestBenchModel.FEATestBench)
                {
                    var feaRep = (TestBenchModel.FEATestBench)testBenchRep;
                    mappings = feaRep.TestBenchParameterMappings;
                }
                // META-2987
                GenerateCADParameterMapping(tb, outputdir, mappings);
            }
            else if (curObjMetaBase == "ComponentAssembly")
            {
                curassembly = CyPhyClasses.ComponentAssembly.Cast(currentobj);
                CADFlatDataCreator datacreator = new CADFlatDataCreator(debuglogdir, this.mainParameters.ProjectDirectory, CadFormat);
                datacreator.Traceability = this.result.Traceability;
                datacreator.CreateFlatData(curassembly);
                DataRep.CADContainer cadcontainer = datacreator.CreateCADDataContainer(curassembly.Guid.ToString(),
                                                                                       UtilityHelpers.CleanString2(curassembly.Name));

                TestBenchModel.TestBenchBase testbenchbase = new TestBenchModel.TestBenchBase(cadSetting,
                                                                                              outputdir,
                                                                                              projectdir);
                testbenchbase.cadDataContainer = cadcontainer;
                testbenchbase.CopySTL          = this.CopySTL;
                testbenchbase.CollectDirectories();
            }
            else
            {
                result.Success = false;
                throw new NotImplementedException(String.Format("Running Cyphy2CAD on {0} is not implemented.", curObjMetaBase));
            }
        }