A Parallel Driving Method for 3D CAD Models Based on Process Scheduling
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-08-25
- Publication Date
- 2026-08-11
AI Technical Summary
由于目前主流三维CAD软件(CATIA、NX、Solidworks等)内核底层机制不支持多线程运算,在模型驱动运算过程中,仅依靠CPU单核性能进行计算,大型模型驱动更新速度慢,无法利用现代CPU多核心并行计算的优势;目前三维CAD模型的装配结构在建模时就已经定义好了,对于装配模型中需要使用不同品牌子零件进行替换时,需要把所有子零件均装配至模型中,并通过约束控制零件的显示状态
[0048]1、通过进程调度机制,实现多进程模型驱动运算,充分利用CPU多核心计算性能,最终达到大型模型结构驱动耗时成倍减少的效果。
Smart Images

Figure CN115509737B_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of digital mold manufacturing, specifically involving a parallel driving method for three-dimensional CAD models based on process scheduling. Background Technology
[0002] The current standardized modeling method for 3D design involves first establishing basic part model structures, such as screws, pressure plates, and push rods; then creating special structures, such as slider seats and A / B plates; and finally assembling various parts into a whole using assembly techniques, constraining the dimensions and positions of the assembled sub-parts through inter-assembly expression relationships. However, because the underlying mechanisms of mainstream 3D CAD software (CATIA, NX, Solidworks, etc.) do not support multi-threaded computation, model-driven computation relies solely on the performance of a single CPU core. This results in slow updates for large models and fails to leverage the advantages of modern CPU multi-core parallel computing. Furthermore, the assembly structure of current 3D CAD models is defined during modeling. When different brands of sub-parts need to be replaced in the assembly model, all sub-parts must be assembled into the model, and their display status controlled by constraints. This approach leads to an exceptionally complex assembly model structure, increasing disk space usage after model import and requiring the solving of expressions for irrelevant parts during model-driven computation, thus increasing the time required for model-driven computation. Summary of the Invention
[0003] The purpose of this invention is to provide a parallel driving method for 3D CAD models based on process scheduling. This method decomposes complex assembly structures into sub-tasks for solving multiple single-part models. Based on the process scheduling task mechanism, the model driving work is allocated to background processes according to resource consumption prediction and dependency relationships. By adopting a method of customizable replaceable assembly part structures, it ensures that the resource models of the standard parts library only need to maintain one model structure, without having to create sub-assemblies of different brands of parts through assembly suppression.
[0004] To solve the above-mentioned technical problems, the technical solution of the present invention is: a parallel driving method for three-dimensional CAD models based on process scheduling, comprising the following steps:
[0005] S1. Obtain and identify sub-parts in the assembly model;
[0006] S2. Create an empty task queue Q;
[0007] S3. Create a task scheduling thread and initialize the child process;
[0008] S4. Subprocess analyzes the dependencies of model expressions; obtains the dependency analysis of model files and stores them in the file dependency table; splices the dependencies of model files into a model dependency graph with a preset structure and parses the model dependency graph, calculates the maximum depth of each file node to obtain depth information, and stores the depth information in the file dependency table.
[0009] S5. Store the files in the file dependency table in the task queue Q in ascending order of their depth to form a model depth queue, and create an empty global expression list G to store the expression values of each part that has been completed in model-driven mode.
[0010] S6. Update the model for each file in the model depth queue and store it.
[0011] S7. After the update is complete, add the main model file.
[0012] The specific steps of S1 are as follows:
[0013] S11. Match the possible sub-parts in the main model of the resource file;
[0014] S12. Read the binary file of the main model in text format;
[0015] S13. Retrieve all character positions N1, N2...Nn containing the keyword by text matching, where n is a positive real number;
[0016] S14. Using Nn as the starting position, search for the key character in reverse order. The key character represents the starting position Mn of the file name description string. Extract (M, Nn+4) to obtain the complete file name.
[0017] It also includes the following steps: comparing and storing all files in the assembly structure, the specific steps of which are as follows:
[0018] S15. Find the files with the complete file names of all files in the folder where the main model is located, and collect them in the model list H.
[0019] S16. Collect the main model files into model list H;
[0020] S17. Copy all files in model list H to the temporary folder.
[0021] The specific steps for S3 are as follows:
[0022] S31. Obtain the current number of CPU cores C using the Windows API GetSystemInfo;
[0023] S32. Create (C-1) task management threads Th, and create a model-driven process running in the background within Th; create a main process event Em and a child process event Es bound to the background model-driven process in thread Th using CreateEvnet; create a shared memory block T bound to the background model-driven process using CreateFileMapping; wait for the Em event to be triggered by the child process; the shared memory block is divided into two parts: the head part contains task information keywords, with a size of 1024 bytes, storing the task type and status; the body part contains task parameters and return results, with a size of 10Mb, storing the parameters and return results of the model-driven process;
[0024] S33. After the background model-driven process starts, it first performs linear initialization work, synchronizing with the management thread in the task scheduling main process. It opens the main process event, child process event, and shared memory block created by the main process through OpenEvent and OpenFileMapping. Then, it fills the head part of the shared memory block with the key information of "initialized" indicating that the initialization has been completed, and fills the body part with "true" to indicate that the initialization was successful. It then triggers the main process event "Em" through SetEvent. The child process enters the waiting task state.
[0025] S34. The main process retrieves the head portion of T and returns "initialized", while the body portion returns "true". It then enters a loop waiting to retrieve a task from the task queue Q.
[0026] The specific steps of S4 are as follows:
[0027] S41. Load the model files in the model list H into the task queue Q of the task scheduling module in sequence;
[0028] S42. Each task management thread Th sequentially obtains the model name corresponding to the task from the task queue Q, sets the head part of the corresponding shared memory block T to Dependency Analysis, sets the body part to the name of the parsed model file obtained from the task queue Q, and triggers the child process event Es through SetEvent.
[0029] S43. The child process terminates the blocking of the Es event, obtains the task type from the head part of T, obtains the file name F from the body part, sets the assembly loading option to load only structures, opens the file F, obtains all expressions in the file, identifies all external dependency expressions through the expression reference keyword "::", and parses out the dependency file names;
[0030] S44. The child process stores the parsed dependency files in the body part of T, and triggers the main process event Em through SetEvent;
[0031] S45, Th ends the Em event blocking, obtains the dependency analysis of the current model file, and stores it in the file dependency table DAM;
[0032] S46 and Th continue to retrieve tasks from the task queue Q and repeat S43-S45 until the task queue is empty and all child processes have completed their tasks.
[0033] S47. Concatenate the dependencies of the model files into a model dependency graph using a preset structure and parse the model dependency graph;
[0034] S48. Calculate the maximum depth of each file node and store the file node depth information in DAM.
[0035] The specific steps of S5 are as follows:
[0036] S51. Store the files in DAM in ascending order of their depth into the task queue Q, and create an empty global expression list G to store the expression values of each part that has been completed and driven by the model.
[0037] S52. Each task management thread Th sequentially retrieves the model name corresponding to the task from the task queue Q, sets the head part of the corresponding shared memory block T to Updata, stores the name of the parsed model file obtained from the task queue Q, the model expression parameter E obtained from the interface and the database, and the global expression list G in the body part, and triggers the child process event Es through SetEvent.
[0038] The child process terminates the blocking of the Es event, obtains the task type from the head part of T, obtains the file name F and expression parameter E from the body part, sets the assembly loading option to load only structures, and opens file F;
[0039] Update the model expression sequentially according to parameter E, save the file after the model is updated, set the return result in the body part to true, and add the expression value Gn after executing the model-driven process; if any abnormal state exists during the model-driven process, set the return result in the body part to false and add error information, and trigger the main process event Es through SetEvent.
[0040] The main process will retrieve the part expression value Gn for this drive from the body part of T, and store Gn along with the file name in the value G.
[0041] It also includes the step of assembly and replacement, which specifically includes:
[0042] The file to be replaced is placed in the main model parameter table using the keyword REPLACE. The replacement is performed according to the preset replacement rules, which are as follows: when the user selects TYPE=A, partA is replaced with partA1 and partB is replaced with partB1; when TYPE=B, partA is replaced with partA1 and partB is replaced with partB2; when TYPE=C, partA is replaced with partA2 and partB is replaced with partB1; when TYPE=D, partA is replaced with partA2 and partB is replaced with partB2.
[0043] The system calculates the names of the files to be replaced based on the parameters selected by the user, and then copies and renames the files to be replaced to a temporary folder.
[0044] It also includes the step of dependency expression update, which is as follows: If there is a dependency expression Po = "partX"::X, where X is any character, during the model-driven process, a temporary file is created in the process and named partX, and the expression parameter corresponding to partX in G is assigned to the temporary file partX. At this time, Po will be able to correctly reference its dependency.
[0045] A computer device is also provided, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor, when executing the computer program, performs the steps of the method as described in any of the preceding claims.
[0046] A computer-readable storage medium is also provided, on which a computer program is stored, which, when executed by a processor, implements the steps of the method as described in any of the preceding claims.
[0047] Compared with the prior art, the beneficial effects of the present invention are as follows:
[0048] 1. By using a process scheduling mechanism, multi-process model-driven computation is achieved, making full use of the CPU's multi-core computing performance, ultimately reducing the time consumption of driving large model structures by a factor of two.
[0049] 2. By using assembly replacement technology, the repetitive assembly work of sub-parts of different brands in the resource model is eliminated, reducing the consumption of model disk storage space and improving the model driving speed. Attached Figure Description
[0050] Figure 1 This is a flowchart illustrating an embodiment of the present invention;
[0051] Figure 2This is a flowchart illustrating the steps of creating a task scheduling thread and initializing a child process in an embodiment of the present invention.
[0052] Figure 3 This is a flowchart illustrating the steps for analyzing the dependency relationships of model expressions in an embodiment of the present invention;
[0053] Figure 4 This is a flowchart illustrating the model-driven update queue step in an embodiment of the present invention;
[0054] Figure 5 This is a schematic diagram of the dependency splicing structure in an embodiment of the present invention. Detailed Implementation
[0055] The invention will be further described below with reference to specific examples and accompanying drawings.
[0056] 1. Analysis of assembly sub-parts
[0057] 1.1 Identify possible sub-parts of the main model in the resource file.
[0058] This invention uses a binary search on the main model of the resource file to find related sub-files, which improves search performance by 1 to 2 orders of magnitude compared to the native assembly structure traversal search method of 3D CAD platforms.
[0059] Step 1. Read the binary file of the main model in text format;
[0060] Step 2. Retrieve all character positions N1, N2, ..., Nn containing the keyword ".prt / .CATProduct" through text matching;
[0061] Step 3. Using the character position Nn found in Step 2 as the starting position, search backwards for the '\0' key character, which represents the starting position Mn of the file name description string. Extract the substring (M, Nn+4) to obtain the complete file name.
[0062] 1.2 Compare and store all files in the assembly structure.
[0063] Step 1. Based on the file name found in Step 3 of 1.1, search for the file with the corresponding name in the folder where the main model is located, and collect it in the model list H.
[0064] Step 2. Collect the main model files into the model list H.
[0065] Step 3. Copy all files in model list H to the temporary folder temp.
[0066] 2. Task scheduling module
[0067] 2.1 Model-driven subprocess initialization
[0068] Step 1. The Task Scheduler service obtains the current number of CPU cores C using the Windows API GetSystemInfo and creates an empty thread-safe queue Q.
[0069] Step 2. The task scheduling service creates C-1 task management threads Th, where C-1 represents a reserved core for supporting the main process. Within Th, a model-driven process running in the background is created. Using CreateEvent, a main process event Em and a child process event Es, bound to the background model-driven process, are created within thread Th; a shared memory block T, bound to the background model-driven process, is created using CreateFileMapping. The naming convention for events and memory blocks is: keyword + process ID. Then, the process waits for the Em event to be triggered by the child process.
[0070] The shared memory block is divided into two parts: the head part contains task information keywords, which is 1024 bytes in size and stores the task type and status; the body part contains task parameters and return results, which is 10Mb in size and stores the parameters and return results in the model-driven process.
[0071] Step 3. After the background model-driven process starts, it first performs linear initialization, synchronizing with the management thread in the task scheduling main process. It uses OpenEvent and OpenFileMapping to open the main process events, child process events, and shared memory blocks created by the main process. Then, it fills the memory block's head with the critical information "initialized" indicating successful initialization, and fills the body with "true" to indicate successful initialization. Finally, it triggers the main process event "Em" via SetEvent. The child process then enters a waiting task state.
[0072] Step 4. The main process retrieves the head portion of T and returns "initialized", while the body portion returns "true". It then enters a loop waiting to retrieve tasks from the task queue Q.
[0073] 2.2 Model Expression Dependency Resolution Task
[0074] Step 1. Load the model files from the model task list in 1.2 into the task queue Q of the task scheduling module in sequence.
[0075] Step 2. Each task management thread Th sequentially retrieves the model name corresponding to the task from the task queue Q, sets the head of the corresponding shared memory block T to "Dependency analysis", and sets the body to the name of the parsed model file retrieved from the task queue Q. Then, it triggers the child process event Es via SetEvent.
[0076] Step 3. The child process terminates the blocking of the Es event, obtains the task type from the head part of T, obtains the file name F from the body part, sets the assembly loading option to load only structures, opens the file F, obtains all expressions in the file, identifies all external dependency expressions by the expression reference keyword "::", and parses out the dependency file names.
[0077] Step 4. The child process stores the parsed dependency files in the body of T, and triggers the main process event Em through SetEvent.
[0078] Step 5. Thread Th ends the Em event blocking, obtains the dependency DA of the current model file, and stores it in the file dependency table DAM.
[0079] Step 6. Thread Th continues to retrieve tasks from task queue Q and repeats steps 3-5 until the task queue is empty and all child processes have completed their tasks.
[0080] Step 7. Concatenate all file dependencies into a graph structure. For example:
[0081] If A depends on B and C, B depends on C, and C depends on D, then the resulting graph after stitching together will look like this:
[0082] Step 8. Calculate the maximum depth of each file node, such as... Figure 5 The depth of D is 0 because it has no dependencies; the depth of C is 1 because it depends on D; the depth of B is 2 because it depends on C with a depth of 1; the depth of A is 3 because it depends on B and C, with B having a depth of 2 and C having a depth of 1, taking the maximum value of 2. The file node depth information is then stored in DAM.
[0083] 2.3 Model Expression-Driven Tasks
[0084] Step 1. Store the files in DAM into the task queue Q in ascending order of their depth. Also, create an empty global expression list G to store the expression values for each completed model-driven part.
[0085] Step 2. Each task management thread Th sequentially retrieves the model name corresponding to the task from the task queue Q, sets the head in the corresponding shared memory block T to Update, and stores the parsed model file name retrieved from the task queue Q, the model expression parameter E obtained through the interface and the database, and the global expression list G in the body. Then, it triggers the child process event Es via SetEvent.
[0086] Step 3. The child process terminates the blocking of the Es event, obtains the task type from the head part of T, obtains the file name F and expression parameter E from the body part, sets the assembly loading option to load only structures, and opens file F.
[0087] Step 4. Update the model expressions sequentially according to parameter E, and save the file after the model is updated. Set the return value in the body to true and add the expression value Gn after executing the model-driven process. If any abnormal state occurs during the model-driven process, set the return value in the body to false and add an error message. Trigger the main process event Es using SetEvent.
[0088] Step 5. The main process will retrieve the part expression value Gn of this drive from the body of T, and store Gn along with the file name in the value G.
[0089] Step 6. After completing all model-driven tasks, simply add the main model file to complete the entire model-driven process.
[0090] 3. Assembly replacement and dependency expression update
[0091] 3.1 Assembly and Replacement
[0092] Step 1. Configure the files to be replaced in the main model parameter table using the REPLACE keyword. The format is as follows: when the user selects TYPE=A, replace partA with partA1 and partB with partB1; when TYPE=B, replace partA with partA1 and partB with partB2; when TYPE=C, replace partA with partA2 and partB with partB1; when TYPE=D, replace partA with partA2 and partB with partB2.
[0093] Step 2. Calculate the names of the files to be replaced based on the parameters selected by the user, and copy and rename the files to be replaced to the temp folder.
[0094] 3.2 Dependency Expression Update
[0095] Step 1. During model-driven processing, if a dependency expression exists, such as Po = "partA"::A, a temporary file named partA is created in the child process, and the expression parameter corresponding to partA in G is assigned to the temporary file partA. At this point, Po will be able to correctly reference its dependencies.
[0096] Those skilled in the art will readily understand that the above description is merely a preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of the present invention should be included within the scope of protection of the present invention.
Claims
1. A parallel driving method for 3D CAD models based on process scheduling, characterized in that, Includes the following steps: S1. Obtain and identify sub-parts in the assembly model; S2. Create an empty task queue Q; S3. Create a task scheduling thread and initialize the child process; the specific steps are as follows: S31. Obtain the current number of CPU cores C using the Windows API GetSystemInfo; S32. Create (C-1) task management threads Th, and create a model-driven process running in the background within Th; create a main process event Em and a child process event Es bound to the background model-driven process in thread Th using CreateEvent; create a shared memory block T bound to the background model-driven process using CreateFileMapping; wait for the Em event to be triggered by the child process; the shared memory block is divided into two parts: the head part contains task information keywords, with a size of 1024 bytes, storing the task type and status; the body part contains task parameters and return results, with a size of 10 Mb, storing the parameters and return results of the model-driven process; S33. After the background model driver process starts, it first performs initialization work, synchronizes with the management thread in the task scheduling main process, and opens the main process event, child process event and shared memory block created by the main process through OpenEvent and OpenFileMapping; then, it fills the head part of the shared memory block with the key information of initialization completed, and fills the body part with true to indicate that the initialization is successful, and triggers the main process event Em through SetEvent; the child process enters the waiting task state. S34. The main process retrieves the head part of T and returns the result as initialized, and the result in body is true. Then it enters a loop to wait for a task to be retrieved from the task queue Q. S4. The subprocess analyzes the dependencies of the model expressions; obtains the dependencies of the model files and stores them in the file dependency table; it then assembles the dependencies of the model files into a model dependency graph using a preset structure, parses the model dependency graph, calculates the maximum depth of each file node to obtain depth information, and stores the depth information in the file dependency table. The specific steps are as follows: S41. Load the model files in the model list H into the task queue Q of the task scheduling module in sequence; S42. Each task management thread Th sequentially obtains the model name corresponding to the task from the task queue Q, sets the head part of the corresponding shared memory block T to Dependency Analysis, sets the body part to the name of the model file to be parsed obtained from the task queue Q, and triggers the child process event Es through SetEvent. S43. The child process terminates the blocking of the Es event, obtains the task type from the head part of T, obtains the file name F from the body part, sets the assembly loading option to load only structures, opens the file F, obtains all expressions in the file, identifies all external dependency expressions by the expression reference keyword "::", and parses out the dependency file names; S44. The child process stores the parsed dependency files in the body part of T, and triggers the main process event Em through SetEvent; S45, Th ends the Em event blocking, obtains the dependency analysis of the current model file, and stores it in the file dependency table DAM; S46 and Th continue to retrieve tasks from the task queue Q and repeat S43-S45 until the task queue is empty and all child processes have completed their tasks. S47. Concatenate the dependencies of the model files into a model dependency graph using a preset structure and parse the model dependency graph; S48. Calculate the maximum depth of each file node and store the file node depth information in DAM; S5. Store the files in the file dependency table in the task queue Q according to their depth from smallest to largest to form a model depth queue, and create an empty global expression list G to store the expression values of each part that has been completed in model-driven mode; the specific steps are as follows: S51. Store the files in DAM in ascending order of their depth into the task queue Q, and create an empty global expression list G to store the expression values of each part that has been completed and driven by the model. S52. Each task management thread Th sequentially retrieves the model name corresponding to the task from the task queue Q, sets the head part of the corresponding shared memory block T to Updata, stores the name of the parsed model file obtained from the task queue Q, the model expression parameter E obtained from the interface and the database, and the global expression list G in the body part, and triggers the child process event Es through SetEvent. The child process terminates the blocking of the Es event, obtains the task type from the head part of T, obtains the file name F and expression parameter E from the body part, sets the assembly loading option to load only structures, and opens file F; Update the model expression sequentially according to parameter E, save the file after the model is updated, set the return result in the body part to true, and add the expression value Gn after executing the model-driven process; if there is any abnormal state during the model-driven process, set the return result in the body part to false and add error information, and trigger the main process event Es through SetEvent; The main process will retrieve the part expression value Gn for this drive from the body part of T, and store Gn along with the file name into G; S6. Update the model for each file in the model depth queue and store it. S7. After the update is complete, add the main model file.
2. The parallel driving method for 3D CAD models based on process scheduling according to claim 1, characterized in that, The specific steps of S1 are as follows: S11. Match the possible sub-parts in the main model of the resource file; S12. Read the binary file of the main model in text format; S13. Retrieve all character positions N1, N2...Nn containing the keyword by text matching, where n is a positive real number; S14. Using Nn as the starting position, search for the key character in reverse order. The key character represents the starting position Mn of the file name description string. Extract (M, Nn+4) to obtain the complete file name.
3. The parallel driving method for 3D CAD models based on process scheduling according to claim 2, characterized in that, It also includes the following steps: The specific steps for comparing and storing all files in the assembly structure are as follows: S15. Locate the files with the complete file names of all files in the folder where the main model is located, and collect them in the model list H. S16. Collect the main model files into model list H; S17. Copy all files in model list H to the temporary folder.
4. The parallel driving method for 3D CAD models based on process scheduling according to claim 1, characterized in that, It also includes the step of assembly and replacement, which specifically includes: The file to be replaced is placed in the main model parameter table using the keyword REPLACE. The replacement is performed according to the preset replacement rules, which are as follows: when the user selects TYPE=A, partA is replaced with partA1 and partB is replaced with partB1; when TYPE=B, partA is replaced with partA1 and partB is replaced with partB2; when TYPE=C, partA is replaced with partA2 and partB is replaced with partB1; when TYPE=D, partA is replaced with partA2 and partB is replaced with partB2. The system calculates the names of the files to be replaced based on the parameters selected by the user, and then copies and renames the files to be replaced to a temporary folder.
5. The parallel driving method for three-dimensional CAD models based on process scheduling according to claim 4, characterized in that, It also includes the step of dependency expression update, which is as follows: if there is a dependency expression Po="partX"::X during the model-driven process, the child process creates a temporary file named partX in the process and assigns the expression parameter corresponding to partX in G to the temporary file partX. At this time, Po will be able to correctly reference its dependency.
6. A computer device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the computer program, it implements the steps of the method as described in any one of claims 1-5.
7. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by a processor, it implements the steps of the method as described in any one of claims 1-5.
Citation Information
Patent Citations
Task scheduling method and system based on big data service
CN112667375A
Protection early warning strategy simulation operation method for multi-device waveform file transmission
CN113177282A