Xây dựng thư viện các mô hình đối tượng của quá trình công nghệ phục vụ nghiên cứu và giảng dạy

155 376 0
Xây dựng thư viện các mô hình đối tượng của quá trình công nghệ phục vụ nghiên cứu và giảng dạy

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

BỘ GIÁO DỤC VÀ ĐÀO TẠO TRƯỜNG ĐẠI HỌC BÁCH KHOA HÀ NỘI -[\ [\ - TÁC GIẢ Nguyễn Ngọc Thắng TÊN ĐỀ TÀI Xây dưng thư viện mơ hình đối tượng q trình xây dựng phục vụ nghiên cứu giảng dạy LUẬN VĂN THẠC SỸ KHOA HỌC NGƯỜI HƯỚNG DẪN KHOA HỌC TS Nguyễn Huy Phương Hà Nội, năm 2011 -1- Luận văn cao học MỤC LỤC DANH MỤC CÁC BẢNG BIỂU, HÌNH VẼ MỞ ĐẦU CHƢƠNG 1: TỔNG QUAN CHUNG VỀ ĐIỀU KHIỂN QUÁ TRÌNH 11 1.1 Các khái niệm 11 1.1.1 Quá trình trình kỹ thuật 11 1.1.2 Biến trình 12 1.1.3 Khái niệm điều khiển trình 12 1.2 Cấu trúc hệ thống điều khiển trình 13 1.2.1 Thiết bị đo 14 1.2.2 Thiết bị điều khiển 14 1.2.3 Thiết bị chấp hành 15 1.3 Mục đích chức điều khiển q trình 16 1.4 Phân cấp chức điều khiển trình 16 1.4.1 Giao diện trình 17 1.4.2 Điều khiển sở 17 1.4.3 Điều khiển vận hành giám sát 18 1.4.4 Điều khiển cao cấp 18 1.5 Các bƣớc phát triển hệ thống 18 CHƢƠNG 2: CÁC MƠ HÌNH TỐN HỌC 21 2.1 Mơ hình hóa lý thuyết 21 2.1.1 Tổng quan bước tiến hành 21 2.1.2 Nhận biết biến trình 23 2.1.3 Những định luật sở áp dụng cho việc mơ hình hóa 23 2.1.4 Phân tích bậc tự mơ hình 32 2.2 Mơ hình hóa số q trình 33 2.2.1 Các hệ thống tích trữ chất lỏng 33 2.2.1.1 Hệ thống bình mức 33 2.2.1.2 Hệ thống hai bình mức tương tác 36 2.2.2 Các trình pha trộn 37 2.2.3 Các trình truyền nhiệt 39 2.2.3.1 Truyền nhiệt thông qua cuộn gia nhiệt nước 39 2.2.3.2 Truyền nhiệt thông qua jacket 41 Luận văn cao học 2.2.4 Các q trình phản ứng hóa học 42 2.2.4.1 Phản ứng đẳng nhiệt 43 2.2.4.2 Phản ứng cân 44 2.2.4.3 Chuỗi phản ứng 45 2.2.4.4 Phản ứng không đẳng nhiệt 46 CHƢƠNG 3: XÂY DỰNG THƢ VIỆN MƠ HÌNH CÁC Q TRÌNH 49 3.1 Giới thiệu S-Function 49 3.1.1 Những phương pháp xây dựng S-Function 50 3.1.2 Cấu trúc chương trình viết C-MEX S- Function 51 3.1.3 Những phương thức gọi hàm S-Function 54 3.2 Xây dựng thƣ viện 56 3.2.1 Các hệ thống tích trữ chất lỏng 56 3.2.1.1 Hệ thống bình mức đầu vào 56 3.2.1.2 Hệ thống bình mức hai đầu vào 59 3.2.1.3 Hệ thống hai bình mức tương tác 60 3.2.2 Các trình pha trộn 63 3.2.3 Các trình truyền nhiệt 65 3.2.3.1 Truyền nhiệt thông qua cuộn gia nhiệt nước 65 3.2.3.1.1 Thể tích bình khơng đổi 65 3.2.3.1.2 Thể tích bình thay đổi 66 3.2.3.2 Truyền nhiệt thông qua jacket 69 3.2.4 Các trình phản ứng hóa học 71 3.2.4.1 Phản ứng đẳng nhiệt 71 3.2.4.2 Phản ứng cân 73 3.2.4.3 Chuỗi phản ứng 75 3.2.4.4 Phản ứng không đẳng nhiệt 77 CHƢƠNG 4: MƠ PHỎNG, TÍNH TỐN, KIỂM NGHIỆM CÁC MƠ HÌNH Q TRÌNH 81 4.1 Các hệ thống tích trữ chất lỏng 81 4.1.1 Hệ thống bình mức đầu vào 81 4.1.2 Hệ thống hai bình mức tương tác 83 4.2 Các trình pha trộn 86 4.3 Các trình truyền nhiệt 88 4.4 Các trình phản ứng hóa học 91 4.4.1 Phản ứng đẳng nhiệt 91 Luận văn cao học 4.4.2 Phản ứng cân 93 4.4.3 Chuỗi phản ứng 96 4.4.4 Phản ứng không đẳng nhiệt 98 KẾT LUẬN 102 TÀI LIỆU THAM KHẢO 103 PHỤ LỤC 104 Luận văn cao học DANH MỤC CÁC BẢNG BIỂU, HÌNH VẼ Hình 1.1 Q trình phân loại biến trình 11 Hình 1.2 Cấu trúc hệ thống điều khiển trình 13 Hình 1.3 Các thành phần hệ thống điều khiển trình 13 Hình 1.4 Cấu trúc thiết bị đo 14 Hình 1.5 Cấu trúc thiết bị điều khiển 14 Hình 1.6 Cấu trúc thiết bị chấp hành 15 Hình 1.7 Sơ đồ phân cấp chức điều khiển trình 16 Hình 1.8 Sơ đồ bước phát triển hệ thống 19 Hình 2.1 Hệ thống bình mức 33 Hình 2.2 Hệ thống hai bình mức tương tác 36 Hình 2.3 Hệ thống pha trộn khuấy 37 Hình 2.4 Hệ thống gia nhiệt thông qua cuộn gia nhiệt nước 39 Hình 2.5 Hệ thống làm mát bình jacket 41 Hình 2.6 Quá trình phản ứng đẳng nhiệt bậc 43 Hình 3.1 Hệ thống bình mức đầu vào đầu 57 Hình 3.2 Khối Simulink Single Tank 57 Hình 3.3 Tham số khối Single Tank 58 Hình 3.4 Hệ thống bình mức hai đầu vào đầu 59 Hình 3.5 Khối Simulink Single Tank 59 Hình 3.6 Tham số khối Single Tank 60 Hình 3.7 Hệ thống hai bình mức 61 Hình 3.8 Khối Simulink Two Tanks 61 Hình 3.9 Tham số khối Two Tanks 62 Hình 3.10 Hệ thống pha trộn khuấy 63 Luận văn cao học Hình 3.11 Khối Simulink Blending Tank 63 Hình 3.12 Tham số khối Blending-Tank 64 Hình 3.13 Hệ thống gia nhiệt nước giữ V=const 65 Hình 3.14 Khối Simulink Steam-Heating Tank V=const 65 Hình 3.15 Tham số khối Steam-Heating Tank V=const 66 Hình 3.16 Khối Simulink Steam-Heating Tank thể tích thay đổi 67 Hình 3.17 Tham số khối Steam-Heating Tank với thể tích thay đổi 68 Hình 3.18 Hệ thống làm mát jacket giữ V=const 69 Hình 3.19 Khối Simulink Cooling Jacket 69 Hình 3.20 Tham số khối Cooling Jacket 70 Hình 3.21 Quá trình phản ứng hóa học 71 Hình 3.22 Khối Simulink Isothermal First-Order Reaction 71 Hình 3.23 Tham số khối First-Order Reaction 72 Hình 3.24 Khối Simulink Equilibrium Reaction 73 Hình 3.25 Tham số khối Equilibrium Reaction 74 Hình 3.26 Khối Simulink Consecutive Reaction 75 Hình 3.27 Tham số khối Consecutive Reaction 76 Hình 3.28 Khối Simulink Non-Isothermal Reaction Cooling 77 Hình 3.29.Tham số khối Non-Isothermal Reaction Cooling 78 Hình 4.1 Sơ đồ mơ Simulink hệ thống bình mức đầu vào 82 Hình 4.2 Đáp ứng mức nước h(m) 82 Hình 4.3 Lưu lượng vào(m3/s) 82 Hình 4.4 Lưu lượng ra(m3/s) 83 Hình 4.5 Sơ đồ mơ Simulink hệ thống hai bình mức tương tác 84 Hình 4.6 Đáp ứng mức nước (m) 85 Hình 4.7 Đáp ứng mức nước (m) 85 Luận văn cao học Hình 4.8 Lưu lượng vào (m3/s) 85 Hình 4.9 Lưu lượng (m3/s) 85 Hình 4.10 Lưu lượng (m3/s) 85 Hình 4.11 Sơ đồ mơ Simulink cho trình khuấy trộn 87 Hình 4.12 Thành phần chất sau pha trộn 87 Hình 4.13 Lưu lượng vào (kg/s) 88 Hình 4.14 Lưu lượng vào (kg/s) 88 Hình 4.15 Sơ đồ mơ Simulink cho trình truyền nhiệt 90 Hình 4.16 Đáp ứng thể tích (m3) 90 Hình 4.17 Đáp ứng nhiệt độ (K) 90 Hình 4.18 Đáp ứng lưu lượng vào(m3/s) 91 Hình 4.19 Đáp ứng lưu lượng ra(m3/s) 91 Hình 4.20 Sơ đồ mơ Simulink cho q trình phản ứng đẳng nhiệt 92 Hình 4.21 Nồng độ chất A(kg/m3) 93 Hình 4.22 Nồng độ chất B(kg/m3) 93 Hình 4.23 Lưu lượng vào(m3/s) 93 Hình 4.24 Sơ đồ mơ Simulink cho trình phản ứng cân 95 Hình 4.25 Nồng độ chất A(kg/m3) 95 Hình 4.26 Nồng độ chất B(kg/m3) 95 Hình 4.27 Lưu lượng vào(m3/s) 95 Hình 4.28 Sơ đồ mơ Simulink cho trình chuỗi phản ứng 97 Hình 4.29 Nồng độ chất A(kg/m3) 98 Hình 4.30 Nồng độ chất B (kg/m3) 98 Hình 4.31 Nồng độ chất C (kg/m3) 98 Hình 4.32 Lưu lượng vào(m3/s) 98 Hình 4.33 Sơ đồ mơ Simulink cho q trình phản ứng khơng đẳng nhiệt 100 Luận văn cao học Hình 4.34 Nồng độ chất A(kg/m3) 100 Hình 4.35 Nhiệt độ dung dịch T(K) 100 Hình 4.36 Lưu lượng vào(m3/s) 101 Bảng 3.1 Các phương thức gọi hàm 54 Bảng 3.2 Thư viện mơ hình q trình tham số 79 Luận văn cao học MỞ ĐẦU Tính cần thiết đề tài Điều khiển trình lĩnh vực mà áp dụng lý thuyết điều khiển tự động cách triệt để, giải nhiều vấn đề đặt trình từ nguyên liệu đầu vào tới sản phẩm đầu ra, liên quan tới chất lượng sản phẩm, an toàn cho người máy móc….Do điều khiển q trình môn học thiếu kỹ sư làm việc liên quan tới q trình cơng nghệ Trong khoảng 40 năm trở lại, giới chứng kiến phát triển nhảy vọt khoa học kĩ thuật Từ đèn bán dẫn thô sơ cồng kềnh biến thành chíp bán dẫn tích hợp số lượng transitor vơ lớn với khả tính toán ngày siêu việt Với khả tăng trưởng chóng mặt mặt cơng nghệ lực tính tốn thiết bị điện tử tích hợp làm thay đổi nhiều tư mở nhiều hướng phát triển Điều khiển tự động ngành gắn chặt với xu hướng phát triển với nhiều phương pháp nghiên cứu triển khai dựa thành tựu công nghệ Hiện giới nghiên cứu phát triển lý thuyết điều khiển mà khơng cần biết xác mơ hình Tuy nhiên, sách lược điều khiển dựa mơ hình đóng vai trị vơ lớn chưa thể thay ưu điểm tính minh bạch qn Mơ hình khơng hồn tồn xác nhiều yếu tố ngoại cảnh công cụ quan trọng việc nghiên cứu, đào tạo vận hành….Chính việc mơ hình hóa mơ q trình quan trọng Do đề tài “Xây dựng thư viện mơ hình đối tượng q trình cơng nghệ phục vụ nghiên cứu giảng dạy” cần thiết thực tiễn thiếu thốn điều kiện thí nghiệm q trình nước ta Luận văn cao học Lịch sử nghiên cứu Việc xây dựng mơ hình làm từ sớm với nhiều phần mềm thương mại Tuy nhiên việc xây dựng toolbox Matlab cịn chưa nhiều chưa phổ biến Ở Việt Nam, toolbox anh Nghiêm Xuân Trường xây dựng thành công với mô hình đối tượng bình mức phịng thí nghiệm môn Điều Khiển Tự Động-Đại học Bách Khoa Hà Nội Mục đích nghiên cứu luận văn, đối tƣợng, phạm vi nghiên cứu Mục tiêu đề tài tạo công cụ (toolbox) hay thư viện mơ hình q trình tiêu biểu thường gặp điều khiển trình Luận văn nguồn tham khảo hữu ích cho việc phát triển tiếp thư viện với hướng phương pháp nghiên cứu tác giả Phạm vi đối tượng nghiên cứu nhắm vào trình giúp sinh viên hiểu rõ chất mơn học Có thể liệt kê trình mức, truyền nhiệt, khuấy trộn dạng phản ứng hóa học Nội dung luận văn Để giải nội dung đề tài, luận văn gồm chương: - Chƣơng 1:Tổng quan chung điều khiển trình Giới thiệu cách tổng quát khái niệm cấu trúc hệ thống điều khiển trình - Chƣơng 2: Các mơ hình tốn học Đề cập tới phương pháp mơ hình hóa lý thuyết xây dựng mơ hình tốn học cho q trình mơ hình hóa - Chƣơng 3: Xây dựng thƣ viện mơ hình q trình Mơ tả khối xây dựng - Chƣơng 4: Mơ phỏng, tính tốn,kiểm nghiệm mơ hình q trình Luận văn cao học //======================================================================= == #define MDL_DERIVATIVES static void mdlDerivatives(SimStruct *S) { real_T *dx = ssGetdX(S); real_T *x = ssGetContStates(S); InputRealPtrsType uPtrs1 = ssGetInputPortRealSignalPtrs(S,0); InputRealPtrsType uPtrs2 = ssGetInputPortRealSignalPtrs(S,1); InputRealPtrsType uPtrs3 = ssGetInputPortRealSignalPtrs(S,2); const real_T *apr = mxGetPr(A_PARAM(S)); const real_T *cvpr = mxGetPr(CV_PARAM(S)); dx[0]=(U1(0)*U3(0)-U2(0)*cvpr[0]*sqrt(x[0]))/apr[0]; } //======================================================================= == static void mdlTerminate(SimStruct *S) { UNUSED_ARG(S); /* unused input argument */ } #ifdef MATLAB_MEX_FILE */ #include "simulink.c" #else #include "cg_sfun.h" #endif /* Is this file being compiled as a MEX-file? /* MEX-file interface mechanism */ /* Code generation registration function */ 10 File singletankv2.c viết cho mơ hình bình mức hai đầu vào #define S_FUNCTION_NAME singletankv2 #define S_FUNCTION_LEVEL #include "simstruc.h" #include "math.h" #define #define #define #define #define U1(element) U2(element) U3(element) U4(element) U5(element) (*uPtrs1[element]) (*uPtrs2[element]) (*uPtrs3[element]) (*uPtrs4[element]) (*uPtrs5[element]) /* /* /* /* /* #define A_IDX #define A_PARAM(S) ssGetSFcnParam(S,A_IDX) #define P_IDX #define P_PARAM(S) ssGetSFcnParam(S,P_IDX) 140 Pointer Pointer Pointer Pointer Pointer to to to to to Input Input Input Input Input Port0 Port1 Port2 Port3 Port4 */ */ */ */ */ Luận văn cao học #define CV_IDX #define CV_PARAM(S) ssGetSFcnParam(S,CV_IDX) #define IL_IDX #define IL_PARAM(S) ssGetSFcnParam(S,IL_IDX) #define NPARAMS /*====================* * S-function methods * *====================*/ //======================================================================= == #define MDL_CHECK_PARAMETERS #if defined(MDL_CHECK_PARAMETERS) && defined(MATLAB_MEX_FILE) static void mdlCheckParameters(SimStruct *S) { const real_T *apr = mxGetPr(A_PARAM(S)); const real_T *ppr = mxGetPr(P_PARAM(S)); const real_T *cvpr = mxGetPr(CV_PARAM(S)); const real_T *ilpr = mxGetPr(IL_PARAM(S)); // Check 1st parameter: Across-Area of Tank if ( *apr < 0) { ssSetErrorStatus(S,"Across-Area of Tank must be greater than 0"); return; } // Check 2nd parameter: Density if ( *ppr < 0) { ssSetErrorStatus(S,"Density must be greater than 0"); return; } // Check 3rd parameter: Valve coefficient if ( *cvpr < 0) { ssSetErrorStatus(S,"Valve coefficient must be greater than to 0"); return; } // Check 4th parameter: Initial Level if ( *ilpr < 0) { ssSetErrorStatus(S,"Initial Level must be greater than 0"); return; } } #endif /* MDL_CHECK_PARAMETERS */ //======================================================================= == static void mdlInitializeSizes(SimStruct *S) 141 Luận văn cao học { ssSetNumSFcnParams(S,NPARAMS); #if defined(MATLAB_MEX_FILE) if (ssGetNumSFcnParams(S) == ssGetSFcnParamsCount(S)) { mdlCheckParameters(S); if (ssGetErrorStatus(S) != NULL) { return; } } else { return; /* Parameter mismatch will be reported by Simulink */ } #endif ssSetNumContStates(S, 1); ssSetNumDiscStates(S, 0); if (!ssSetNumInputPorts(S, 5)) return; ssSetInputPortWidth(S, 0, 1); ssSetInputPortDirectFeedThrough(S, 0, 1); ssSetInputPortWidth(S, 1, 1); ssSetInputPortDirectFeedThrough(S, 1, 1); ssSetInputPortWidth(S, 2, 1); ssSetInputPortDirectFeedThrough(S, 2, 1); ssSetInputPortWidth(S, 3, 1); ssSetInputPortDirectFeedThrough(S, 3, 1); ssSetInputPortWidth(S, 4, 1); ssSetInputPortDirectFeedThrough(S, 4, 1); if (!ssSetNumOutputPorts(S, 4)) return; ssSetOutputPortWidth(S, 0, 1); ssSetOutputPortWidth(S, 1, 1); ssSetOutputPortWidth(S, 2, 1); ssSetOutputPortWidth(S, 3, 1); ssSetNumSampleTimes(S, 1); ssSetNumRWork(S, 0); ssSetNumIWork(S, 0); ssSetNumPWork(S, 0); ssSetNumModes(S, 0); ssSetNumNonsampledZCs(S, 0); ssSetSimStateCompliance(S, USE_DEFAULT_SIM_STATE); /* Take care when specifying exception free code - see sfuntmpl_doc.c */ ssSetOptions(S, SS_OPTION_EXCEPTION_FREE_CODE); } //======================================================================= == static void mdlInitializeSampleTimes(SimStruct *S) { ssSetSampleTime(S, 0, CONTINUOUS_SAMPLE_TIME); ssSetOffsetTime(S, 0, 0.0); ssSetModelReferenceSampleTimeDefaultInheritance(S); } 142 Luận văn cao học //======================================================================= == #define MDL_INITIALIZE_CONDITIONS static void mdlInitializeConditions(SimStruct *S) { real_T *x0 = ssGetContStates(S); const real_T *ilpr = mxGetPr(IL_PARAM(S)); *x0=*ilpr; } //======================================================================= == static void mdlOutputs(SimStruct *S, int_T tid) { real_T *y1 = ssGetOutputPortRealSignal(S,0); real_T *y2 = ssGetOutputPortRealSignal(S,1); real_T *y3 = ssGetOutputPortRealSignal(S,2); real_T *y4 = ssGetOutputPortRealSignal(S,3); real_T *x InputRealPtrsType InputRealPtrsType InputRealPtrsType InputRealPtrsType InputRealPtrsType uPtrs1 uPtrs2 uPtrs3 uPtrs4 uPtrs5 = ssGetContStates(S); = = = = = ssGetInputPortRealSignalPtrs(S,0); ssGetInputPortRealSignalPtrs(S,1); ssGetInputPortRealSignalPtrs(S,2); ssGetInputPortRealSignalPtrs(S,3); ssGetInputPortRealSignalPtrs(S,4); const real_T *apr = mxGetPr(A_PARAM(S)); const real_T *ppr = mxGetPr(P_PARAM(S)); const real_T *cvpr = mxGetPr(CV_PARAM(S)); UNUSED_ARG(tid); /* not used in single tasking mode */ y1[0]=x[0]; y2[0]=U1(0)*U4(0); y3[0]=U2(0)*U5(0); y4[0]=U3(0)*cvpr[0]*sqrt(y1[0]); } //======================================================================= == #define MDL_DERIVATIVES static void mdlDerivatives(SimStruct *S) { real_T *dx = ssGetdX(S); real_T *x = ssGetContStates(S); InputRealPtrsType InputRealPtrsType InputRealPtrsType InputRealPtrsType InputRealPtrsType uPtrs1 uPtrs2 uPtrs3 uPtrs4 uPtrs5 = = = = = ssGetInputPortRealSignalPtrs(S,0); ssGetInputPortRealSignalPtrs(S,1); ssGetInputPortRealSignalPtrs(S,2); ssGetInputPortRealSignalPtrs(S,3); ssGetInputPortRealSignalPtrs(S,4); const real_T *apr = mxGetPr(A_PARAM(S)); const real_T *ppr = mxGetPr(P_PARAM(S)); 143 Luận văn cao học const real_T *cvpr = mxGetPr(CV_PARAM(S)); dx[0]=(U1(0)*U4(0)+U2(0)*U5(0)U3(0)*cvpr[0]*sqrt(x[0]))/(ppr[0]*apr[0]); } //======================================================================= == static void mdlTerminate(SimStruct *S) { UNUSED_ARG(S); /* unused input argument */ } #ifdef MATLAB_MEX_FILE */ #include "simulink.c" #else #include "cg_sfun.h" #endif /* Is this file being compiled as a MEX-file? /* MEX-file interface mechanism */ /* Code generation registration function */ 11 File twotank.c viết cho mơ hình hai bình mức tƣơng tác #define S_FUNCTION_NAME twotank #define S_FUNCTION_LEVEL #include "simstruc.h" #include "math.h" #define #define #define #define U1(element) U2(element) U3(element) U4(element) (*uPtrs1[element]) (*uPtrs2[element]) (*uPtrs3[element]) (*uPtrs4[element]) /* Pointer to Input Port0 */ /* Pointer to Input Port1 */ /* Pointer to Input Port2 */ #define A1_IDX #define A1_PARAM(S) ssGetSFcnParam(S,A1_IDX) #define A2_IDX #define A2_PARAM(S) ssGetSFcnParam(S,A2_IDX) #define CV1_IDX #define CV1_PARAM(S) ssGetSFcnParam(S,CV1_IDX) #define CV2_IDX #define CV2_PARAM(S) ssGetSFcnParam(S,CV2_IDX) #define IL1_IDX #define IL1_PARAM(S) ssGetSFcnParam(S,IL1_IDX) #define IL2_IDX #define IL2_PARAM(S) ssGetSFcnParam(S,IL2_IDX) #define NPARAMS 144 Luận văn cao học /*====================* * S-function methods * *====================*/ //======================================================================= == #define MDL_CHECK_PARAMETERS #if defined(MDL_CHECK_PARAMETERS) && defined(MATLAB_MEX_FILE) static void mdlCheckParameters(SimStruct *S) { const real_T *a1pr = mxGetPr(A1_PARAM(S)); const real_T *cv1pr = mxGetPr(CV1_PARAM(S)); const real_T *il1pr = mxGetPr(IL1_PARAM(S)); const real_T *a2pr = mxGetPr(A2_PARAM(S)); const real_T *cv2pr = mxGetPr(CV2_PARAM(S)); const real_T *il2pr = mxGetPr(IL2_PARAM(S)); // Check parameter: Across-Area of Tank if ( *a1pr < 0) { ssSetErrorStatus(S,"Across-Area of Tank must be greater than 0"); return; } if ( *a2pr < 0) { ssSetErrorStatus(S,"Across-Area of Tank must be greater than 0"); return; } // Check parameter: Valve Coeffient if ( *cv1pr < 0) { ssSetErrorStatus(S,"Valve Coeffient must be greater than 1"); return; } if ( *cv2pr < 0) { ssSetErrorStatus(S,"Valve Coeffient must be greater than 1"); return; } // Check parameter: Initial Level if ( *il1pr < 0) { ssSetErrorStatus(S,"Initial Level must be greater than 0"); return; } if ( *il2pr < 0) { ssSetErrorStatus(S,"Initial Level must be greater than 0"); return; } } #endif /* MDL_CHECK_PARAMETERS */ 145 Luận văn cao học //======================================================================= == static void mdlInitializeSizes(SimStruct *S) { //boolean_T *maniflowpr = mxGetPr(MANIFLOW_PARAM(S)); //int_T i,ninput = 2; ssSetNumSFcnParams(S,NPARAMS); #if defined(MATLAB_MEX_FILE) if (ssGetNumSFcnParams(S) == ssGetSFcnParamsCount(S)) { mdlCheckParameters(S); if (ssGetErrorStatus(S) != NULL) { return; } } else { return; /* Parameter mismatch will be reported by Simulink */ } #endif ssSetNumContStates(S, 2); ssSetNumDiscStates(S, 0); if (!ssSetNumInputPorts(S, 4)) return; ssSetInputPortWidth(S, 0, 1); ssSetInputPortDirectFeedThrough(S, 0, 1); ssSetInputPortWidth(S, 1, 1); ssSetInputPortDirectFeedThrough(S, 1, 1); ssSetInputPortWidth(S, 2, 1); ssSetInputPortDirectFeedThrough(S, 2, 1); ssSetInputPortWidth(S, 3, 1); ssSetInputPortDirectFeedThrough(S, 3, 1); if (!ssSetNumOutputPorts(S, 5)) return; ssSetOutputPortWidth(S, 0, 1); ssSetOutputPortWidth(S, 1, 1); ssSetOutputPortWidth(S, 2, 1); ssSetOutputPortWidth(S, 3, 1); ssSetOutputPortWidth(S, 4, 1); ssSetNumSampleTimes(S, 1); ssSetNumRWork(S, 0); ssSetNumIWork(S, 0); ssSetNumPWork(S, 0); ssSetNumModes(S, 0); ssSetNumNonsampledZCs(S, 0); ssSetSimStateCompliance(S, USE_DEFAULT_SIM_STATE); /* Take care when specifying exception free code - see sfuntmpl_doc.c */ ssSetOptions(S, SS_OPTION_EXCEPTION_FREE_CODE); } //======================================================================= == static void mdlInitializeSampleTimes(SimStruct *S) { 146 Luận văn cao học ssSetSampleTime(S, 0, CONTINUOUS_SAMPLE_TIME); ssSetOffsetTime(S, 0, 0.0); ssSetModelReferenceSampleTimeDefaultInheritance(S); } //======================================================================= == #define MDL_INITIALIZE_CONDITIONS static void mdlInitializeConditions(SimStruct *S) { real_T *x0 = ssGetContStates(S); const real_T *il1pr = mxGetPr(IL1_PARAM(S)); const real_T *il2pr = mxGetPr(IL2_PARAM(S)); x0[0]=*il1pr; x0[1]=*il2pr; } //======================================================================= == static void mdlOutputs(SimStruct *S, int_T tid) { real_T *y1 = ssGetOutputPortRealSignal(S,0); real_T *y2 = ssGetOutputPortRealSignal(S,1); real_T *y3 = ssGetOutputPortRealSignal(S,2); real_T *y4 = ssGetOutputPortRealSignal(S,3); real_T *y5 = ssGetOutputPortRealSignal(S,4); real_T *x InputRealPtrsType InputRealPtrsType InputRealPtrsType InputRealPtrsType uPtrs1 uPtrs2 uPtrs3 uPtrs4 = ssGetContStates(S); = = = = ssGetInputPortRealSignalPtrs(S,0); ssGetInputPortRealSignalPtrs(S,1); ssGetInputPortRealSignalPtrs(S,2); ssGetInputPortRealSignalPtrs(S,3); const real_T *cv1pr = mxGetPr(CV1_PARAM(S)); const real_T *cv2pr = mxGetPr(CV2_PARAM(S)); UNUSED_ARG(tid); /* not used in single tasking mode */ y1[0]=x[0]; y2[0]=x[1]; y3[0]=U1(0)*U4(0); y4[0]=U2(0)*cv1pr[0]*sqrt(y1[0]-y2[0]); y5[0]=U3(0)*cv2pr[0]*sqrt(y2[0]); } //======================================================================= == #define MDL_DERIVATIVES static void mdlDerivatives(SimStruct *S) { real_T *dx = ssGetdX(S); real_T *x = ssGetContStates(S); InputRealPtrsType uPtrs1 = ssGetInputPortRealSignalPtrs(S,0); InputRealPtrsType uPtrs2 = ssGetInputPortRealSignalPtrs(S,1); 147 Luận văn cao học InputRealPtrsType uPtrs3 = ssGetInputPortRealSignalPtrs(S,2); InputRealPtrsType uPtrs4 = ssGetInputPortRealSignalPtrs(S,3); const const const const real_T real_T real_T real_T *a1pr = mxGetPr(A1_PARAM(S)); *cv1pr = mxGetPr(CV1_PARAM(S)); *a2pr = mxGetPr(A2_PARAM(S)); *cv2pr = mxGetPr(CV2_PARAM(S)); dx[0]=(U1(0)*U4(0)-U2(0)*cv1pr[0]*sqrt(x[0]-x[1]))/a1pr[0]; dx[1]=(U2(0)*cv1pr[0]*sqrt(x[0]-x[1])U2(0)*cv2pr[0]*sqrt(x[1]))/a2pr[0]; } //======================================================================= == static void mdlTerminate(SimStruct *S) { UNUSED_ARG(S); /* unused input argument */ } #ifdef MATLAB_MEX_FILE */ #include "simulink.c" #else #include "cg_sfun.h" #endif /* Is this file being compiled as a MEX-file? /* MEX-file interface mechanism */ /* Code generation registration function */ 12 File blendingtank.c viết cho mơ hình bình khuấy trộn #define S_FUNCTION_NAME blendingtank #define S_FUNCTION_LEVEL #include "simstruc.h" #include "math.h" #define #define #define #define #define #define U1(element) U2(element) U3(element) U4(element) U5(element) U6(element) (*uPtrs1[element]) (*uPtrs2[element]) (*uPtrs3[element]) (*uPtrs4[element]) (*uPtrs5[element]) (*uPtrs6[element]) /* /* /* /* /* /* Pointer Pointer Pointer Pointer Pointer Pointer #define P_IDX #define P_PARAM(S) ssGetSFcnParam(S,P_IDX) #define V_IDX #define V_PARAM(S) ssGetSFcnParam(S,V_IDX) #define IX_IDX #define IX_PARAM(S) ssGetSFcnParam(S,IX_IDX) #define NPARAMS 148 to to to to to to Input Input Input Input Input Input Port0 Port1 Port2 Port3 Port4 Port5 */ */ */ */ */ */ Luận văn cao học /*====================* * S-function methods * *====================*/ //======================================================================= == #define MDL_CHECK_PARAMETERS #if defined(MDL_CHECK_PARAMETERS) && defined(MATLAB_MEX_FILE) static void mdlCheckParameters(SimStruct *S) { const real_T *ppr = mxGetPr(P_PARAM(S)); const real_T *vpr = mxGetPr(V_PARAM(S)); const real_T *ixpr = mxGetPr(IX_PARAM(S)); // Check parameter: Density if ( *ppr < 0) { ssSetErrorStatus(S,"Density of the liquid must be greater than 0"); return; } //Check parameter: Volume if ( *vpr < 0) { ssSetErrorStatus(S,"Volume of the Tank must be greater than 0"); return; } //Check parameter: Initial Composition if ( *ixpr < && *ixpr >1) { ssSetErrorStatus(S,"Initial Composition must be between and 1"); return; } } #endif /* MDL_CHECK_PARAMETERS */ //======================================================================= == static void mdlInitializeSizes(SimStruct *S) { ssSetNumSFcnParams(S,NPARAMS); #if defined(MATLAB_MEX_FILE) if (ssGetNumSFcnParams(S) == ssGetSFcnParamsCount(S)) { mdlCheckParameters(S); if (ssGetErrorStatus(S) != NULL) { return; } } else { return; /* Parameter mismatch will be reported by Simulink */ } #endif ssSetNumContStates(S, 1); ssSetNumDiscStates(S, 0); 149 Luận văn cao học if (!ssSetNumInputPorts(S, 6)) return; ssSetInputPortWidth(S, 0, 1); ssSetInputPortDirectFeedThrough(S, 0, 1); ssSetInputPortWidth(S, 1, 1); ssSetInputPortDirectFeedThrough(S, 1, 1); ssSetInputPortWidth(S, 2, 1); ssSetInputPortDirectFeedThrough(S, 2, 1); ssSetInputPortWidth(S, 3, 1); ssSetInputPortDirectFeedThrough(S, 3, 1); ssSetInputPortWidth(S, 4, 1); ssSetInputPortDirectFeedThrough(S, 4, 1); ssSetInputPortWidth(S, 5, 1); ssSetInputPortDirectFeedThrough(S, 5, 1); if (!ssSetNumOutputPorts(S, 3)) return; ssSetOutputPortWidth(S, 0, 1); ssSetOutputPortWidth(S, 1, 1); ssSetOutputPortWidth(S, 2, 1); ssSetNumSampleTimes(S, 1); ssSetNumRWork(S, 0); ssSetNumIWork(S, 0); ssSetNumPWork(S, 0); ssSetNumModes(S, 0); ssSetNumNonsampledZCs(S, 0); ssSetSimStateCompliance(S, USE_DEFAULT_SIM_STATE); /* Take care when specifying exception free code - see sfuntmpl_doc.c */ ssSetOptions(S, SS_OPTION_EXCEPTION_FREE_CODE); } //======================================================================= == static void mdlInitializeSampleTimes(SimStruct *S) { ssSetSampleTime(S, 0, CONTINUOUS_SAMPLE_TIME); ssSetOffsetTime(S, 0, 0.0); ssSetModelReferenceSampleTimeDefaultInheritance(S); } //======================================================================= == #define MDL_INITIALIZE_CONDITIONS static void mdlInitializeConditions(SimStruct *S) { real_T *x0 = ssGetContStates(S); const real_T *ixpr = mxGetPr(IX_PARAM(S)); x0[0]=*ixpr; } //======================================================================= == static void mdlOutputs(SimStruct *S, int_T tid) 150 Luận văn cao học { real_T real_T real_T *y1 *y2 *y3 real_T *x = ssGetOutputPortRealSignal(S,0); = ssGetOutputPortRealSignal(S,1); = ssGetOutputPortRealSignal(S,2); = ssGetContStates(S); InputRealPtrsType uPtrs1 = ssGetInputPortRealSignalPtrs(S,0); InputRealPtrsType uPtrs2 = ssGetInputPortRealSignalPtrs(S,1); InputRealPtrsType uPtrs5 = ssGetInputPortRealSignalPtrs(S,4); InputRealPtrsType uPtrs6 = ssGetInputPortRealSignalPtrs(S,5); UNUSED_ARG(tid); /* not used in single tasking mode */ y1[0]=x[0]; y2[0]=U1(0)*U5(0); y3[0]=U2(0)*U6(0); } //======================================================================= == #define MDL_DERIVATIVES static void mdlDerivatives(SimStruct *S) { real_T *dx = ssGetdX(S); real_T *x = ssGetContStates(S); InputRealPtrsType uPtrs1 = ssGetInputPortRealSignalPtrs(S,0); InputRealPtrsType uPtrs2 = ssGetInputPortRealSignalPtrs(S,1); InputRealPtrsType uPtrs3 = ssGetInputPortRealSignalPtrs(S,2); InputRealPtrsType uPtrs4 = ssGetInputPortRealSignalPtrs(S,3); InputRealPtrsType uPtrs5 = ssGetInputPortRealSignalPtrs(S,4); InputRealPtrsType uPtrs6 = ssGetInputPortRealSignalPtrs(S,5); const real_T *ppr = mxGetPr(P_PARAM(S)); const real_T *vpr = mxGetPr(V_PARAM(S)); dx[0]=(U1(0)*U5(0)*U3(0)+U2(0)*U6(0)*U4(0)(U1(0)*U5(0)+U2(0)*U6(0))*x[0])/(ppr[0]*vpr[0]); } //======================================================================= == static void mdlTerminate(SimStruct *S) { UNUSED_ARG(S); /* unused input argument */ } #ifdef MATLAB_MEX_FILE */ #include "simulink.c" /* Is this file being compiled as a MEX-file? /* MEX-file interface mechanism */ 151 Luận văn cao học #else #include "cg_sfun.h" #endif /* Code generation registration function */ 13 File valve.c viết cho mơ hình động học van #define S_FUNCTION_NAME valve #define S_FUNCTION_LEVEL #include "simstruc.h" #include "math.h" #define U1(element) (*uPtrs1[element]) /* Pointer to Input Port0 */ #define K_IDX #define K_PARAM(S) ssGetSFcnParam(S,K_IDX) #define T_IDX #define T_PARAM(S) ssGetSFcnParam(S,T_IDX) #define IV_IDX #define IV_PARAM(S) ssGetSFcnParam(S,IV_IDX) #define NPARAMS /*====================* * S-function methods * *====================*/ //======================================================================= == #define MDL_CHECK_PARAMETERS #if defined(MDL_CHECK_PARAMETERS) && defined(MATLAB_MEX_FILE) static void mdlCheckParameters(SimStruct *S) { const real_T *kpr = mxGetPr(K_PARAM(S)); const real_T *tpr = mxGetPr(T_PARAM(S)); const real_T *ivpr = mxGetPr(IV_PARAM(S)); // Check parameter: Gain if ( *kpr < 0) { ssSetErrorStatus(S,"Gain must be greater than 0"); return; } //Check parameter: Time Constant if ( *tpr < 0) { ssSetErrorStatus(S,"Time Constant must be greater than 0"); return; } //Check parameter: Initial Valve Opening if ( *ivpr < && *ivpr >1) { ssSetErrorStatus(S,"Initial Valve Opening must be between and 1"); 152 Luận văn cao học return; } } #endif /* MDL_CHECK_PARAMETERS */ //======================================================================= == static void mdlInitializeSizes(SimStruct *S) { ssSetNumSFcnParams(S,NPARAMS); #if defined(MATLAB_MEX_FILE) if (ssGetNumSFcnParams(S) == ssGetSFcnParamsCount(S)) { mdlCheckParameters(S); if (ssGetErrorStatus(S) != NULL) { return; } } else { return; /* Parameter mismatch will be reported by Simulink */ } #endif ssSetNumContStates(S, 1); ssSetNumDiscStates(S, 0); if (!ssSetNumInputPorts(S, 1)) return; ssSetInputPortWidth(S, 0, 1); if (!ssSetNumOutputPorts(S, 1)) return; ssSetOutputPortWidth(S, 0, 1); ssSetNumSampleTimes(S, 1); ssSetNumRWork(S, 0); ssSetNumIWork(S, 0); ssSetNumPWork(S, 0); ssSetNumModes(S, 0); ssSetNumNonsampledZCs(S, 0); ssSetSimStateCompliance(S, USE_DEFAULT_SIM_STATE); /* Take care when specifying exception free code - see sfuntmpl_doc.c */ ssSetOptions(S, SS_OPTION_EXCEPTION_FREE_CODE); } //======================================================================= == static void mdlInitializeSampleTimes(SimStruct *S) { ssSetSampleTime(S, 0, CONTINUOUS_SAMPLE_TIME); ssSetOffsetTime(S, 0, 0.0); ssSetModelReferenceSampleTimeDefaultInheritance(S); } //======================================================================= == 153 Luận văn cao học #define MDL_INITIALIZE_CONDITIONS static void mdlInitializeConditions(SimStruct *S) { real_T *x0 = ssGetContStates(S); const real_T *ivpr = mxGetPr(IV_PARAM(S)); x0[0]=*ivpr; } //======================================================================= == static void mdlOutputs(SimStruct *S, int_T tid) { real_T *y1 = ssGetOutputPortRealSignal(S,0); real_T *x = ssGetContStates(S); InputRealPtrsType uPtrs1 = ssGetInputPortRealSignalPtrs(S,0); UNUSED_ARG(tid); /* not used in single tasking mode */ y1[0]=x[0]; } //======================================================================= == #define MDL_DERIVATIVES static void mdlDerivatives(SimStruct *S) { real_T *dx = ssGetdX(S); real_T *x = ssGetContStates(S); InputRealPtrsType uPtrs1 = ssGetInputPortRealSignalPtrs(S,0); const real_T *kpr = mxGetPr(K_PARAM(S)); const real_T *tpr = mxGetPr(T_PARAM(S)); dx[0]=(kpr[0]*U1(0)-x[0])/tpr[0]; } //======================================================================= == static void mdlTerminate(SimStruct *S) { UNUSED_ARG(S); /* unused input argument */ } #ifdef MATLAB_MEX_FILE */ #include "simulink.c" #else #include "cg_sfun.h" #endif /* Is this file being compiled as a MEX-file? /* MEX-file interface mechanism */ /* Code generation registration function */ 154 ... hình hóa lý thuyết số q trình phục vụ cho nhu cầu xây dựng thư viện chương ba Chương ta giới thiệu số phương pháp xây dựng thư viện mô tả đặc tính khối thư viện xây dựng dựa phương pháp C-MEX S-Function... đối tượng q trình cơng nghệ phục vụ nghiên cứu giảng dạy? ?? cần thiết thực tiễn thiếu thốn điều kiện thí nghiệm q trình nước ta Luận văn cao học Lịch sử nghiên cứu Việc xây dựng mơ hình làm từ... học CHƢƠNG TỔNG QUAN CHUNG VỀ ĐIỀU KHIỂN QUÁ TRÌNH 1.1 Các khái niệm 1.1.1 Quá trình trình kỹ thuật Hình 1.1 Quá trình phân loại biến trình  Quá trình trình tự diễn biến vật lý, hóa học sinh

Ngày đăng: 19/07/2017, 22:56

Từ khóa liên quan

Mục lục

  • MỤC LỤC

  • DANH MỤC CÁC BẢNG BIỂU, HÌNH VẼ

  • MỞ ĐẦU

  • CHƢƠNG 1

  • CHƢƠNG 2

  • CHƢƠNG 3

  • CHƢƠNG 4

  • KẾT LUẬN

  • TÀI LIỆU THAM KHẢO

  • PHỤ LỤC

Tài liệu cùng người dùng

Tài liệu liên quan