OTSClassifyEng.cpp 67 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491
  1. #pragma once
  2. #include "stdafx.h"
  3. #include "OTSClassifyEng.h"
  4. #include "OTSHelper.h"
  5. namespace OTSClassifyEngine
  6. {
  7. using namespace OTSClassifyEngine;
  8. const double MIN_ELEMENT_SUM = 0.02;
  9. const long INC_DEFAULTSIZE = 100;
  10. const long INC_ELEMENTSIZE_MIN = 0;
  11. const CString STR_CONNECT = _T("-");
  12. const CString STR_FE = _T("Fe");
  13. const CString STR_C = _T("C");
  14. const CString STR_SI = _T("Si");
  15. const CString STR_O = _T("O");
  16. const CString STR_SUL = _T("S");
  17. const CString STR_N = _T("N");
  18. const CString STR_CR = _T("Cr");
  19. const CString STR_P = _T("P");
  20. const CString STR_Na = _T("Na");
  21. const CString STR_F = _T("F");
  22. const double SIC_MOLAR_CUTOFF = 85.0;
  23. const double NBC_MOLAR_CUTOFF = 30.0;
  24. const double FEO_MOLAR_CUTOFF = 85.0;
  25. // key element
  26. const long INC_KEY_ELEMENT_MAX = 4;
  27. const double INC_KEY_ELEMENT_CUT_OFF = 0.02; // weight%
  28. const double INC_KEY_ELEMENT_TOTAL_100 = 5.0; // total molar value
  29. const CString INC_KEY_ELEMENT_NAMES[INC_KEY_ELEMENT_MAX] =
  30. {
  31. _T("S"),_T("N"),_T("O")
  32. };
  33. // sub element
  34. const long INC_SUB_ELEMENT_MAX = 12;
  35. const double INC_SUB_ELEMENT_CUT_OFF = 0.02; // weight%
  36. const double INC_SUB_ELEMENT_TOTAL_100 = 5.0; // molar value
  37. const CString INC_SUB_ELEMENT_NAMES[INC_SUB_ELEMENT_MAX] =
  38. {
  39. _T("Mg"),_T("Al"),_T("Si"),_T("Ca"),_T("Ti"),_T("V"),_T("Mn"),_T("Zr"),_T("Nb"),_T("Mo"),_T("Ce"),_T("La")
  40. };
  41. // element 100 % molar value mapping cut off
  42. const double ELEMENT_MAPPING_100MOLAR = 2.0;
  43. // sulfur classification
  44. const double MIN_SUL_MOLAR = ELEMENT_MAPPING_100MOLAR;
  45. const double MIN_SUL_SUB_MOLAR = ELEMENT_MAPPING_100MOLAR;
  46. const long INC_SUL_SUB_ELEMENT_MAX = 5;
  47. const CString INC_SUL_SUB_ELEMENT_NAMES[INC_SUL_SUB_ELEMENT_MAX] =
  48. {
  49. _T("Mn"),_T("Ca"),_T("Mg"),_T("Ce"),_T("La")
  50. };
  51. const CString INC_SULFILSES_NAMES[INC_SUL_SUB_ELEMENT_MAX] =
  52. {
  53. _T("MnS"),_T("CaS"),_T("MgS"),_T("Ce(La)2S3"),_T("Ce(La)2S3")
  54. };
  55. const double INC_SULFILSES_MAPPING_RATIO[INC_SUL_SUB_ELEMENT_MAX] =
  56. {
  57. 1.0, 1.0, 1.0, 1.5, 1.5
  58. };
  59. const double SULFIDE_MOLAR_CUTOFF = 5.0;
  60. const CString SULFIDE_STR = _T("Sulfide");
  61. // O classification
  62. const long INC_OXIDE_SUB_ELEMENT_MAX = 9;
  63. const CString INC_OXIDE_SUB_ELEMENT_NAMES[INC_OXIDE_SUB_ELEMENT_MAX] =
  64. {
  65. _T("Al"),_T("Mg"),_T("Si"),_T("Mn"),_T("Ca"),_T("Ce"),_T("Cr"),_T("Ti"),_T("La")
  66. };
  67. const CString INC_OXIDE_NAMES[INC_OXIDE_SUB_ELEMENT_MAX] =
  68. {
  69. _T("Al2O3"),_T("MgO"),_T("SiO2"),_T("MnO"),_T("CaO"),_T("CeO"),_T("Oxide"),_T("Oxide"),_T("REOxide")
  70. };
  71. const double SIMPLE_OXIDE_MOLAR_CUTOFF = 90.0;
  72. const long REOXIDE_KEY_ELEMENT_MAX = 2;
  73. const CString REOXIDE_KEY_ELEMENT_NAMES[REOXIDE_KEY_ELEMENT_MAX] =
  74. {
  75. _T("Ce"),_T("La")
  76. };
  77. const CString REOXIDE_STR = _T("REOxide");
  78. const long REALOXIDE_SUB_ELEMENT_MAX = 2;
  79. const CString REALOXIDE_SUB_ELEMENT_NAMES[REALOXIDE_SUB_ELEMENT_MAX] =
  80. {
  81. _T("Si"),_T("Al")
  82. };
  83. const double REALOXIDE_ELEMELTS_MOLAR_CUTOFF = 90.0;
  84. const CString REALOXIDE_STR = _T("REAlOxide");
  85. const long SPINEL_KEY_ELEMENT_MAX = 2;
  86. const double REALOXIDE_ELEMENT_MOLAR_LOW_CUTOFF = 20;
  87. const CString SPINEL_KEY_ELEMENT_NAMES[SPINEL_KEY_ELEMENT_MAX] =
  88. {
  89. _T("Mg"),_T("Al")
  90. };
  91. const double SPINEL_KEY_ELEMENT_MOLAR_TOTAL = 90.0;
  92. const double SPINEL_ELEMENT_RATIO_MIN = 1.6;
  93. const double SPINEL_ELEMENT_RATIO_MAX = 2.4;
  94. const CString SPINEL_STR = _T("Spinel");
  95. const CString SILICATE_KEY_ELEMENT_NAME = _T("Si");
  96. const double SILICATE_KEY_ELEMENT_MOLAR_TOTAL_MIN = 10.0;
  97. const double SILICATE_KEY_ELEMENT_MOLAR_TOTAL_MAX = 90.0;
  98. const CString SILICATE_STR = _T("Silicate");
  99. const long ALUMINATE_KEY_ELEMENT_MAX = 2;
  100. const CString ALUMINATE_KEY_ELEMENT_NAME[ALUMINATE_KEY_ELEMENT_MAX] =
  101. {
  102. _T("Al"),_T("Ca")
  103. };
  104. const double ALUMINAT_KEY_ELEMENT_MOLAR_TOTAL_MIN = 10.0;
  105. const double ALUMINAT_KEY_ELEMENT_MOLAR_TOTAL_MAX = 90.0;
  106. const CString ALUMINATE12CaO_7Al2O3_STR = _T("12CaO-7Al2O3");
  107. const CString ALUMINATE3CaO_Al2O3_STR = _T("3CaO-Al2O3");
  108. const CString ALUMINATE_STR = _T("Aluminate");
  109. const CString Ca_ALUMINATE_STR = _T("Ca-Aluminate");
  110. const CString STR_OXIDE = _T("O");
  111. const double MIN_OXIDE_MOLAR = 5.0;
  112. const double MIN_OXIDE_SUB_MOLAR_TOTAL = 5.0;
  113. const double MIN_OXIDE_SUB_MOLAR_CUTOFF = ELEMENT_MAPPING_100MOLAR;
  114. const CString OXIDE_STR = _T("Oxide");
  115. // nitrogen classification
  116. const long INC_NITR_SUB_ELEMENT_MAX = 8;
  117. const CString INC_NITR_SUB_ELEMENT_NAMES[INC_NITR_SUB_ELEMENT_MAX] =
  118. {
  119. _T("Ti"),_T("V"),_T("Nb"),_T("Al"),_T("Zr"),_T("Cr"),_T("La"),_T("Ce")
  120. };
  121. const CString INC_NITR_NAMES[INC_NITR_SUB_ELEMENT_MAX] =
  122. {
  123. _T("TiN"),_T("VN"),_T("NbN"),_T("AlN"),_T("Nitride"),_T("Nitride"),_T("Nitride"),_T("Nitride")
  124. };
  125. const double INC_NITR_MAPPING_RATIO[INC_NITR_SUB_ELEMENT_MAX] =
  126. {
  127. 1.0, 1.0, 1.0, 1.0, 1.0, 2.0, 1.0, 1.0
  128. };
  129. const CString STR_NITR = _T("N");
  130. const CString STR_Nb = _T("Nb");
  131. const CString STR_Mn = _T("Mn");
  132. const double MIN_NITR_MOLAR = ELEMENT_MAPPING_100MOLAR;
  133. const double MIN_NITR_SUB_MOLAR = ELEMENT_MAPPING_100MOLAR;
  134. const double NITRIDE_MOLAR_CUTOFF = 5.0;
  135. const CString NITRIDE_STR = _T("Nitride");
  136. #pragma region
  137. // carbon classification
  138. const long INC_CAR_SUB_ELEMENT_MAX = 1;
  139. const CString INC_CAR_SUB_ELEMENT_NAMES[INC_CAR_SUB_ELEMENT_MAX] =
  140. {
  141. _T("Nb")
  142. };
  143. const CString INC_CAR_NAMES[INC_CAR_SUB_ELEMENT_MAX] =
  144. {
  145. _T("NbC")
  146. };
  147. const double INC_CAR_MAPPING_RATIO[INC_CAR_SUB_ELEMENT_MAX] =
  148. {
  149. 1.0
  150. };
  151. const CString STR_CAR = _T("C");
  152. const double MIN_CAR_MOLAR = ELEMENT_MAPPING_100MOLAR;
  153. const double MIN_CAR_SUB_MOLAR = ELEMENT_MAPPING_100MOLAR;
  154. const double CARBON_MOLAR_CUTOFF = 5.0;
  155. const CString CARBON_STR = _T("Carbon");
  156. #pragma endregion
  157. COTSClassifyEng::COTSClassifyEng(CInclutionSTDDataPtr a_pPartSTDData) // constructor
  158. {
  159. ASSERT(a_pPartSTDData);
  160. // get all sulfides STD items
  161. pPartSTDData = a_pPartSTDData;
  162. if (!GetClassifySTDItem(a_pPartSTDData, INC_CLASSIFY_TYPE::SUL, listSulfideSTD))
  163. {
  164. // something is wrong
  165. LogErrorTrace(__FILE__, __LINE__, _T("COTSClassifyEng::SulClassify: failed to call GetClassifySTDItem method."));
  166. }
  167. // get all oxides STD items
  168. if (!GetClassifySTDItem(a_pPartSTDData, INC_CLASSIFY_TYPE::OXIDE, listOxideSTD))
  169. {
  170. // something wrong
  171. LogErrorTrace(__FILE__, __LINE__, _T("COTSClassifyEng::OxideClassify: failed to call GetClassifySTDItem method."));
  172. }
  173. // get all nitride STD items
  174. if (!GetClassifySTDItem(a_pPartSTDData, INC_CLASSIFY_TYPE::NITR, listNitrideSTD))
  175. {
  176. // something wrong
  177. LogErrorTrace(__FILE__, __LINE__, _T("COTSClassifyEng::NitrideClassify: failed to call GetClassifySTDItem method."));
  178. }
  179. }
  180. COTSClassifyEng::~COTSClassifyEng() // detractor
  181. {
  182. }
  183. //Dispose ClassifyXray
  184. BOOL COTSClassifyEng::ClassifyXray( STEEL_TECHNOLOGY steelTech, CElementChemistriesList& a_listElementChemistries, int& a_nIncId, int& a_GrpId)
  185. {
  186. // the element chemistries list is an inclusion
  187. CElementChemistriesList listElChemsIncNoFe;
  188. double dMolarSumNoFe = 0.0f;
  189. OTS_PARTICLE_TYPE incId;
  190. NOT_INCLUTION_ID notAIncId;// is not an inc but we can identify
  191. if (!FilterInvalidIncXRay(a_listElementChemistries, listElChemsIncNoFe,dMolarSumNoFe, incId, notAIncId))
  192. {
  193. LogErrorTrace(__FILE__, __LINE__, _T("COTSClassifyEng::failed to call IsAnValidIncXRay"));
  194. return FALSE;
  195. }
  196. if (incId == OTS_PARTCLE_TYPE::ISNOT_INCLUTION)// this is not an inclution particle,but we can identify.
  197. {
  198. a_nIncId =(int) notAIncId;
  199. a_GrpId = (int)OTS_PARTCLE_TYPE::ISNOT_INCLUTION;
  200. return TRUE;
  201. }
  202. if (incId == OTS_PARTCLE_TYPE::INVALID)// this is not an valid inclution particle.
  203. {
  204. a_nIncId = (int)OTS_PARTCLE_TYPE::INVALID;
  205. a_GrpId = (int)OTS_PARTCLE_TYPE::INVALID;
  206. return TRUE;
  207. }
  208. // system STD classification
  209. int nIncId = (int)OTS_PARTICLE_TYPE::NOT_IDENTIFIED;
  210. if (!SystemClassify( steelTech, listElChemsIncNoFe, dMolarSumNoFe, nIncId))
  211. {
  212. LogErrorTrace(__FILE__, __LINE__, _T("COTSClassifyEng::ClassifyXray: failed to call SystemClassify method."));
  213. a_nIncId = (int)OTS_PARTICLE_TYPE::NOT_IDENTIFIED;
  214. return FALSE;
  215. }
  216. // identified?
  217. if (nIncId > (int)OTS_PARTICLE_TYPE::IDENTIFIED)
  218. {// identified, return TRUE
  219. a_nIncId = nIncId;
  220. IDENTIFIED_INC_GRP_ID grpid;
  221. GroupClassify(a_listElementChemistries,nIncId, grpid);
  222. a_GrpId = (int)grpid;
  223. return TRUE;
  224. }
  225. // identified?
  226. if (nIncId > (int)OTS_PARTICLE_TYPE::IDENTIFIED)
  227. {
  228. // identified, return TRUE
  229. a_nIncId = nIncId;
  230. IDENTIFIED_INC_GRP_ID grpid;
  231. GroupClassify(a_listElementChemistries,nIncId, grpid);
  232. a_GrpId = (int)grpid;
  233. return TRUE;
  234. }
  235. // can't identify this inclusion
  236. a_nIncId = (int)OTS_PARTICLE_TYPE::NOT_IDENTIFIED;
  237. IDENTIFIED_INC_GRP_ID grpid;
  238. GroupClassify(a_listElementChemistries,nIncId, grpid);
  239. a_GrpId = (int)grpid;
  240. return TRUE;
  241. }
  242. // public
  243. // check if the x-ray is an inc x-ray,
  244. BOOL COTSClassifyEng::FilterInvalidIncXRay(CElementChemistriesList a_listElementChemistries,
  245. CElementChemistriesList& a_listElChemsIncNoFe,
  246. double& a_dMolarSumNoFe,
  247. OTS_PARTICLE_TYPE& a_nIncId,
  248. NOT_INCLUTION_ID& notIncId)
  249. {
  250. // go through all elementS
  251. a_listElChemsIncNoFe.clear();
  252. a_dMolarSumNoFe = 0;
  253. double dSumKeyElements = 0;
  254. double dSumSubElements = 0;
  255. double dCarbonMolar = 0;
  256. double dCarbonWeight = 0;
  257. double dNbMolar = 0;
  258. double dMnWeight = 0;
  259. double dOMolar = 0;
  260. double dOweight = 0;
  261. double dSiMolar = 0;
  262. double dFeMolar = 0;
  263. double dFeWeight = 0;
  264. double dPWeight = 0;
  265. double dNaWeight = 0;
  266. double dFWeight = 0;
  267. for (auto pElChem : a_listElementChemistries)
  268. {
  269. // create a new element chemistry
  270. CElementChemistryPtr pElChemNew = CElementChemistryPtr(new CElementChemistry(*pElChem.get()));
  271. // key element? S,O,N
  272. if (IsKeyElement(pElChem))
  273. {
  274. // this is a key element
  275. // get molar percentage of this element
  276. double dMolarPercentage = pElChem->GetMolarPercentage();
  277. // cal molar percentage sum (both lists)
  278. a_dMolarSumNoFe += dMolarPercentage;
  279. // cal key element molar percentage sum
  280. dSumKeyElements += dMolarPercentage;
  281. // add the element into the two lists
  282. a_listElChemsIncNoFe.push_back(pElChemNew);
  283. if (pElChem->GetName().CompareNoCase(STR_O) == 0)
  284. {
  285. dOMolar = pElChem->GetMolarPercentage();
  286. dOweight = pElChem->GetPercentage();
  287. }
  288. }
  289. // sub element?, include Fe
  290. else if (IsSubElement(pElChem))
  291. {
  292. // this is a sub element
  293. // get molar percentage of this element
  294. double dMolarPercentage = pElChem->GetMolarPercentage();
  295. // cal molar percentage sum list (no Fe)
  296. a_dMolarSumNoFe += pElChem->GetMolarPercentage();
  297. // cal key element molar percentage sum
  298. dSumSubElements += dMolarPercentage;
  299. // add the element into the list (no Fe)
  300. a_listElChemsIncNoFe.push_back(pElChemNew);
  301. // Si
  302. if (pElChem->GetName().CompareNoCase(STR_SI) == 0)
  303. {
  304. dSiMolar = pElChem->GetMolarPercentage();
  305. }
  306. if (pElChem->GetName().CompareNoCase(STR_Nb) == 0)
  307. {
  308. dNbMolar = pElChem->GetMolarPercentage();
  309. }
  310. if (pElChem->GetName().CompareNoCase(STR_Mn) == 0)
  311. {
  312. dMnWeight = pElChem->GetPercentage();
  313. }
  314. }
  315. else if (pElChem->GetName().CompareNoCase(STR_FE) == 0)
  316. {
  317. dFeMolar = pElChem->GetMolarPercentage();
  318. dFeWeight = pElChem->GetPercentage();
  319. }
  320. else if (pElChem->GetName().CompareNoCase(STR_C) == 0)
  321. {
  322. dCarbonMolar = pElChem->GetMolarPercentage();
  323. dCarbonWeight = pElChem->GetPercentage();
  324. }
  325. else if (pElChem->GetName().CompareNoCase(STR_P) == 0)
  326. {
  327. dPWeight = pElChem->GetPercentage();
  328. }
  329. else if (pElChem->GetName().CompareNoCase(STR_Na) == 0)
  330. {
  331. dNaWeight = pElChem->GetPercentage();
  332. }
  333. else if (pElChem->GetName().CompareNoCase(STR_F) == 0)
  334. {
  335. dFWeight = pElChem->GetPercentage();
  336. }
  337. }
  338. // not a inc if this is a SiC
  339. //=========================================
  340. // any carbon?
  341. if (dCarbonMolar > MIN_DOUBLE_VALUE)
  342. {
  343. // calculate molar % of C + Si
  344. double dMolarC_Si = Cal100NorValue(dCarbonMolar + dSiMolar, a_dMolarSumNoFe + dCarbonMolar);
  345. if (dMolarC_Si > SIC_MOLAR_CUTOFF && dSiMolar> INC_SUB_ELEMENT_CUT_OFF)
  346. {
  347. // this is a SiC, not a inclusion, return FALSE
  348. a_nIncId =OTS_PARTCLE_TYPE::ISNOT_INCLUTION;
  349. notIncId = NOT_INCLUTION_ID::SiC;
  350. return TRUE;
  351. }
  352. double dMolarC_Nb = Cal100NorValue(dCarbonMolar + dNbMolar, a_dMolarSumNoFe + dCarbonMolar);
  353. if (dMolarC_Nb > NBC_MOLAR_CUTOFF && dNbMolar > INC_SUB_ELEMENT_CUT_OFF)
  354. {
  355. // this is a SiC, not a inclusion, return FALSE
  356. a_nIncId = OTS_PARTCLE_TYPE::ISNOT_INCLUTION;
  357. notIncId = NOT_INCLUTION_ID::NbC;
  358. return TRUE;
  359. }
  360. }
  361. //=========================================
  362. //FeO
  363. if (dOMolar > MIN_DOUBLE_VALUE)
  364. {
  365. // calculate molar % of Fe + O
  366. double dMolarFe_O = Cal100NorValue(dOMolar + dFeMolar, a_dMolarSumNoFe + dCarbonMolar);
  367. if (dMolarFe_O > FEO_MOLAR_CUTOFF)
  368. {
  369. if (a_listElementChemistries.size() == 2)//there is only Fe and O
  370. {
  371. if (std::find_if(a_listElementChemistries.begin(), a_listElementChemistries.end(), [](CElementChemistryPtr i) {return ((i->GetName().CompareNoCase(STR_CR) != 0) && (i->GetName().CompareNoCase(STR_O) != 0)); }) != a_listElementChemistries.end())
  372. {
  373. //this is a FeO, not a inclusion
  374. a_nIncId = OTS_PARTCLE_TYPE::ISNOT_INCLUTION;
  375. notIncId = NOT_INCLUTION_ID::FeO;
  376. return TRUE;
  377. }
  378. }
  379. }
  380. if (dMolarFe_O > FEO_MOLAR_CUTOFF && dMnWeight < 20 && dMnWeight>0)
  381. {
  382. if (a_listElementChemistries.size() == 3)//there is only Fe and O and Mn(<20)
  383. {
  384. a_nIncId = OTS_PARTCLE_TYPE::ISNOT_INCLUTION;
  385. notIncId = NOT_INCLUTION_ID::FeO;
  386. return TRUE;
  387. }
  388. if (a_listElementChemistries.size() == 4)//there is only Fe and O and Mn(<20) and C
  389. {
  390. if (dCarbonWeight > 0)
  391. {
  392. a_nIncId = OTS_PARTCLE_TYPE::ISNOT_INCLUTION;
  393. notIncId = NOT_INCLUTION_ID::FeO;
  394. return TRUE;
  395. }
  396. }
  397. }
  398. }
  399. if (a_dMolarSumNoFe < MIN_ELEMENT_SUM)
  400. {
  401. a_nIncId = OTS_PARTICLE_TYPE::INVALID;
  402. return TRUE;
  403. }
  404. double sumOfCarboOxideFe=0;
  405. if (dCarbonWeight > 0 || dFeWeight > 0)
  406. {
  407. sumOfCarboOxideFe = dOweight + dCarbonWeight + dFeWeight;
  408. }
  409. if (sumOfCarboOxideFe > 95)// contain too much c o fe then classify it as invalid
  410. {
  411. a_nIncId = OTS_PARTICLE_TYPE::INVALID;
  412. return TRUE;
  413. }
  414. if (dPWeight > 0 || dNaWeight > 0)// contain any of P Na then set it as invalid.
  415. {
  416. a_nIncId = OTS_PARTICLE_TYPE::INVALID;
  417. return TRUE;
  418. }
  419. // both key molar percentage sum and sub molar percentage sum have to be over certain values
  420. double dSumKeyElementsMolar = Cal100NorValue(dSumKeyElements, a_dMolarSumNoFe);
  421. double dSumSubElementsMolar = Cal100NorValue(dSumSubElements, a_dMolarSumNoFe);
  422. if (dSumKeyElementsMolar > INC_KEY_ELEMENT_TOTAL_100 && dSumSubElementsMolar > INC_SUB_ELEMENT_TOTAL_100)
  423. {
  424. a_nIncId = OTS_PARTCLE_TYPE::NOT_IDENTIFIED;
  425. return TRUE;
  426. }
  427. else
  428. {
  429. a_nIncId = OTS_PARTICLE_TYPE::INVALID;
  430. return TRUE;
  431. }
  432. }
  433. // system classification
  434. BOOL COTSClassifyEng::SystemClassify(
  435. STEEL_TECHNOLOGY steelTech,
  436. CElementChemistriesList& a_listElChemsIncNoFe,
  437. double a_dMolarSumNoFe,
  438. int& a_nIncId)
  439. {
  440. // try sulfide classification
  441. int nIncId = (int)OTS_PARTICLE_TYPE::INVALID;
  442. if (!SulClassify(steelTech, a_listElChemsIncNoFe, a_dMolarSumNoFe, nIncId))
  443. {
  444. // something wrong
  445. LogErrorTrace(__FILE__, __LINE__, _T("COTSClassifyEng::ClassifyXray: failed to call SulClassify method."));
  446. a_nIncId = (int)OTS_PARTICLE_TYPE::NOT_IDENTIFIED;
  447. return FALSE;
  448. }
  449. // inclusion identified?
  450. if (nIncId != (int)OTS_PARTICLE_TYPE::INVALID)
  451. {
  452. // yes, this is a sulfide
  453. a_nIncId = nIncId;
  454. return TRUE;
  455. }
  456. // nitride classification
  457. if (!NitrideClassify(steelTech,a_listElChemsIncNoFe, a_dMolarSumNoFe, nIncId))
  458. {
  459. // something wrong
  460. LogErrorTrace(__FILE__, __LINE__, _T("COTSClassifyEng::ClassifyXray: failed to call NitrideClassify method."));
  461. a_nIncId = (int)OTS_PARTICLE_TYPE::NOT_IDENTIFIED;
  462. return FALSE;
  463. }
  464. // inclusion identified?
  465. if (nIncId != (int)OTS_PARTICLE_TYPE::INVALID)
  466. {
  467. // yes, this is a nitride
  468. a_nIncId = nIncId;
  469. return TRUE;
  470. }
  471. // oxide classification
  472. if (!OxideClassify(steelTech, a_listElChemsIncNoFe, a_dMolarSumNoFe, nIncId))
  473. {
  474. // something wrong
  475. LogErrorTrace(__FILE__, __LINE__, _T("COTSClassifyEng::ClassifyXray: failed to call OxideClassify method."));
  476. a_nIncId = (int)OTS_PARTICLE_TYPE::NOT_IDENTIFIED;
  477. return FALSE;
  478. }
  479. // inclusion identified?
  480. if (nIncId != (int)OTS_PARTICLE_TYPE::INVALID)
  481. {
  482. // yes, this is a oxide
  483. a_nIncId = nIncId;
  484. return TRUE;
  485. }
  486. // can't identify this inclusion
  487. a_nIncId = (int)OTS_PARTICLE_TYPE::NOT_IDENTIFIED;
  488. return TRUE;
  489. }
  490. BOOL COTSClassifyEng::GroupClassify(CElementChemistriesList& a_listElChemsIncNoFe,int incId, IDENTIFIED_INC_GRP_ID& a_GrpId)
  491. {
  492. double dOWeight = 0;
  493. double dSWeight = 0;
  494. double dNWeight = 0;
  495. auto stdItm =pPartSTDData->GetSTDItemById( incId);
  496. if (incId == (int)OTS_PARTICLE_TYPE::NOT_IDENTIFIED)
  497. {
  498. a_GrpId = IDENTIFIED_INC_GRP_ID::Others;
  499. return true;
  500. }
  501. auto stdName = stdItm->GetName();
  502. // sulfide classification
  503. for (long i = 0; i < INC_SUL_SUB_ELEMENT_MAX; i++)
  504. {
  505. if (stdName.CompareNoCase(INC_SULFILSES_NAMES[i]) == 0 )
  506. {
  507. a_GrpId = IDENTIFIED_INC_GRP_ID::SULFIDE;
  508. return true;
  509. }
  510. }
  511. if (stdName.CompareNoCase(SULFIDE_STR) == 0 )
  512. {
  513. a_GrpId = IDENTIFIED_INC_GRP_ID::SULFIDE;
  514. return true;
  515. }
  516. //oxide classification
  517. for (long i = 0; i < INC_OXIDE_SUB_ELEMENT_MAX; i++)
  518. {
  519. if (stdName.CompareNoCase(INC_OXIDE_NAMES[i]) == 0)
  520. {
  521. a_GrpId = IDENTIFIED_INC_GRP_ID::OXIDE;
  522. return true;
  523. }
  524. }
  525. if (stdName.CompareNoCase(SPINEL_STR) == 0)
  526. {
  527. a_GrpId = IDENTIFIED_INC_GRP_ID::OXIDE;
  528. return true;
  529. }
  530. if (stdName.CompareNoCase(ALUMINATE12CaO_7Al2O3_STR) == 0)
  531. {
  532. a_GrpId = IDENTIFIED_INC_GRP_ID::OXIDE;
  533. return true;
  534. }
  535. if (stdName.CompareNoCase(ALUMINATE3CaO_Al2O3_STR) == 0)
  536. {
  537. a_GrpId = IDENTIFIED_INC_GRP_ID::OXIDE;
  538. return true;
  539. }
  540. if (stdName.CompareNoCase(ALUMINATE_STR) == 0)
  541. {
  542. a_GrpId = IDENTIFIED_INC_GRP_ID::OXIDE;
  543. return true;
  544. }
  545. if (stdName.CompareNoCase(Ca_ALUMINATE_STR) == 0)
  546. {
  547. a_GrpId = IDENTIFIED_INC_GRP_ID::OXIDE;
  548. return true;
  549. }
  550. if (stdName.CompareNoCase(SILICATE_STR) == 0)
  551. {
  552. a_GrpId = IDENTIFIED_INC_GRP_ID::OXIDE;
  553. return true;
  554. }
  555. for (long i = 0; i < INC_NITR_SUB_ELEMENT_MAX; i++)
  556. {
  557. if (stdName.CompareNoCase(INC_NITR_NAMES[i]) == 0)
  558. {
  559. a_GrpId = IDENTIFIED_INC_GRP_ID::CARBONNITRIDE_NITRIDE;
  560. return true;
  561. }
  562. }
  563. for (auto pElChem : a_listElChemsIncNoFe)
  564. {
  565. if (pElChem->GetName().CompareNoCase(STR_O) == 0)
  566. {
  567. dOWeight = pElChem->GetPercentage();
  568. }
  569. else if (pElChem->GetName().CompareNoCase(STR_SUL) == 0)
  570. {
  571. dSWeight = pElChem->GetPercentage();
  572. }
  573. else if (pElChem->GetName().CompareNoCase(STR_N) == 0)
  574. {
  575. dNWeight = pElChem->GetPercentage();
  576. }
  577. }
  578. if ( dSWeight >= MIN_ELEMENT_SUM && dOWeight < MIN_ELEMENT_SUM && dNWeight <= MIN_ELEMENT_SUM)
  579. {
  580. a_GrpId = IDENTIFIED_INC_GRP_ID::SULFIDE;
  581. }
  582. else if (dOWeight >= MIN_ELEMENT_SUM && dSWeight >= MIN_ELEMENT_SUM && dNWeight<=MIN_ELEMENT_SUM)
  583. {
  584. a_GrpId = IDENTIFIED_INC_GRP_ID::SULFIDE_OXIDE;
  585. }
  586. else if ( dNWeight >= MIN_ELEMENT_SUM)
  587. {
  588. a_GrpId = IDENTIFIED_INC_GRP_ID::CARBONNITRIDE_NITRIDE;
  589. }else
  590. if (dOWeight >= MIN_ELEMENT_SUM && dSWeight < MIN_ELEMENT_SUM)
  591. {
  592. a_GrpId = IDENTIFIED_INC_GRP_ID::OXIDE;
  593. }
  594. else
  595. {
  596. a_GrpId = IDENTIFIED_INC_GRP_ID::Others;
  597. }
  598. return TRUE;
  599. }
  600. BOOL COTSClassifyEng::GroupClassify1(CElementChemistriesList& a_listElChemsIncNoFe, int incId, IDENTIFIED_INC_GRP_ID& a_GrpId)
  601. {
  602. double dOWeight = 0;
  603. double dSWeight = 0;
  604. double dNWeight = 0;
  605. for (auto pElChem : a_listElChemsIncNoFe)
  606. {
  607. if (pElChem->GetName().CompareNoCase(STR_O) == 0)
  608. {
  609. dOWeight = pElChem->GetPercentage();
  610. }
  611. else if (pElChem->GetName().CompareNoCase(STR_SUL) == 0)
  612. {
  613. dSWeight = pElChem->GetPercentage();
  614. }
  615. else if (pElChem->GetName().CompareNoCase(STR_N) == 0)
  616. {
  617. dNWeight = pElChem->GetPercentage();
  618. }
  619. }
  620. auto stdItm = pPartSTDData->GetSTDItemById(incId);
  621. INC_CLASSIFY_TYPE claType = INC_CLASSIFY_TYPE::INVALID;
  622. this->GetClassifyTypeOfSTDItem(incId, claType);
  623. if (claType == INC_CLASSIFY_TYPE::COMPLEX_OXIDE || claType == INC_CLASSIFY_TYPE::OXIDE || claType == INC_CLASSIFY_TYPE::SIMPLE_OXIDE)
  624. {
  625. a_GrpId = IDENTIFIED_INC_GRP_ID::OXIDE;
  626. return true;
  627. }
  628. else if (claType == INC_CLASSIFY_TYPE::SUL)
  629. {
  630. if (dOWeight >= MIN_ELEMENT_SUM && dSWeight <= 1)
  631. {
  632. a_GrpId = IDENTIFIED_INC_GRP_ID::SULFIDE_OXIDE;
  633. }
  634. else
  635. {
  636. a_GrpId = IDENTIFIED_INC_GRP_ID::SULFIDE;
  637. }
  638. }
  639. else if (claType == INC_CLASSIFY_TYPE::NITR)
  640. {
  641. a_GrpId = IDENTIFIED_INC_GRP_ID::CARBONNITRIDE_NITRIDE;
  642. }
  643. else
  644. {
  645. a_GrpId = IDENTIFIED_INC_GRP_ID::Others;
  646. }
  647. return TRUE;
  648. }
  649. BOOL COTSClassifyEng::GetGroupNameAndColorById(int grpId,std::string& grpName,std::string& grpColor)
  650. {
  651. if (grpId == (int)OTS_PARTICLE_TYPE::INVALID)
  652. {
  653. grpName = "Invalid";
  654. grpColor = "#000000";
  655. }
  656. if (grpId == (int)OTS_PARTICLE_TYPE::NOT_IDENTIFIED)
  657. {
  658. grpName = "Not Identified";
  659. grpColor = "#000000";
  660. }
  661. if (grpId == (int)OTS_PARTICLE_TYPE::ISNOT_INCLUTION)
  662. {
  663. grpName = "NOT_INCLUTION";
  664. grpColor = "#483D8B";
  665. }
  666. switch (grpId)
  667. {
  668. case (int)IDENTIFIED_INC_GRP_ID::OXIDE:
  669. grpName = "Oxide";
  670. grpColor = "#FF69B4";
  671. break;
  672. case (int)IDENTIFIED_INC_GRP_ID::SULFIDE:
  673. grpName = "Sulfide";
  674. grpColor = "#FF00FF";
  675. break;
  676. case (int)IDENTIFIED_INC_GRP_ID::SULFIDE_OXIDE:
  677. grpName = "Sulfide_Oxide";
  678. grpColor = "#0000FF";
  679. break;
  680. case (int)IDENTIFIED_INC_GRP_ID::CARBONNITRIDE_NITRIDE:
  681. grpName = "CarbonNitride/Nitride";
  682. grpColor = "#00FF7F";
  683. break;
  684. case (int)IDENTIFIED_INC_GRP_ID::Others:
  685. grpName = "Other";
  686. grpColor = "#B0C4DE";
  687. break;
  688. default:
  689. break;
  690. }
  691. return true;
  692. }
  693. // sulfides classification
  694. BOOL COTSClassifyEng::SulClassify(
  695. STEEL_TECHNOLOGY steelTech,
  696. CElementChemistriesList& a_listElChemsIncNoFe,
  697. double a_dMolarSumNoFe,
  698. int& a_nIncId)
  699. {
  700. // check if element chemistries list contain any sulfur
  701. CElementChemistryPtr pSulElChem = GetNamedElementChemistry(a_listElChemsIncNoFe, STR_SUL);
  702. if (!pSulElChem)
  703. {
  704. // contains no sulfur, this is not a sulfide
  705. return TRUE;
  706. }
  707. // calculate sulfur 100 percentage molar
  708. double dSulMolar100 = Cal100NorValue(pSulElChem->GetMolarPercentage(), a_dMolarSumNoFe);
  709. // check if sulfur amount enough
  710. if (dSulMolar100 < MIN_SUL_MOLAR)
  711. {
  712. // no enough sulfur, this is not a sulfide
  713. return TRUE;
  714. }
  715. // this is a sulfide
  716. if (listSulfideSTD.empty())// any sulfides STD items
  717. {
  718. // no sulfides std items. can't identify sulfide
  719. // can't identify this inclusion
  720. a_nIncId = (int)OTS_PARTICLE_TYPE::NOT_IDENTIFIED;
  721. return TRUE;
  722. }
  723. // mapping Mn first
  724. double dSulRemain;
  725. BOOL bMnMapped = FALSE;
  726. {
  727. CString strMn = INC_SUL_SUB_ELEMENT_NAMES[0];
  728. double dMappingRatio = INC_SULFILSES_MAPPING_RATIO[0];
  729. bMnMapped = ElementMatching(a_dMolarSumNoFe, a_listElChemsIncNoFe, pSulElChem, strMn, dMappingRatio, dSulRemain);
  730. }
  731. // process mapping if sulfur amount enough
  732. CString strProMappingSulName = _T("");
  733. BOOL bSteelTechMapped = FALSE;
  734. if (dSulRemain > MIN_SUL_MOLAR)// still have enough sulfur, mapping Ca, Mg or Ce, La
  735. {
  736. FilterOnSteelTech(steelTech, a_listElChemsIncNoFe);
  737. bSteelTechMapped = ElementMatchingOnSteelTech(a_dMolarSumNoFe, steelTech, a_listElChemsIncNoFe, pSulElChem, strProMappingSulName);
  738. }
  739. // set sulfide base name
  740. CString strSulfideBaseName = _T("");
  741. if (bMnMapped && bSteelTechMapped)
  742. {
  743. // both Mn and process mapped
  744. strSulfideBaseName = INC_SULFILSES_NAMES[0] + strProMappingSulName;
  745. }
  746. else if (bMnMapped)
  747. {
  748. // Mn mapped only
  749. strSulfideBaseName = INC_SULFILSES_NAMES[0];
  750. }
  751. else if (bSteelTechMapped)
  752. {
  753. // process mapped only
  754. strSulfideBaseName = strProMappingSulName;
  755. }
  756. else
  757. {
  758. // // mapped nothing, force sulfide base name as "Sulfide" if sulfur 100% molar value over cutting off value
  759. if (dSulMolar100 > SULFIDE_MOLAR_CUTOFF)
  760. {
  761. strSulfideBaseName = SULFIDE_STR;
  762. }
  763. else
  764. {
  765. // no enough sulfur, consider that it is not a sulfide
  766. return TRUE;
  767. }
  768. }
  769. // check if the rest element chemistries map an oxide
  770. int nIncId = (int)OTS_PARTICLE_TYPE::NOT_IDENTIFIED;
  771. if (!GetSulfildeOxideComplexItemId(steelTech,a_listElChemsIncNoFe, a_dMolarSumNoFe, strSulfideBaseName, nIncId))
  772. {
  773. a_nIncId = (int)OTS_PARTICLE_TYPE::NOT_IDENTIFIED;
  774. return FALSE;
  775. }
  776. if (nIncId >= (int)OTS_PARTICLE_TYPE::IDENTIFIED)
  777. {
  778. a_nIncId = nIncId;
  779. return TRUE;
  780. }
  781. nIncId = (int)OTS_PARTICLE_TYPE::NOT_IDENTIFIED;
  782. if (!GetSulfildeNitrideComplexItemId(steelTech,a_listElChemsIncNoFe, a_dMolarSumNoFe, strSulfideBaseName, nIncId))
  783. {
  784. a_nIncId = (int)OTS_PARTICLE_TYPE::NOT_IDENTIFIED;
  785. return FALSE;
  786. }
  787. if (nIncId >= (int)OTS_PARTICLE_TYPE::IDENTIFIED)
  788. {
  789. a_nIncId = nIncId;
  790. return TRUE;
  791. }
  792. // try to find the STD item // this is a general sulfide// confirm the sulfide id
  793. CSTDItemPtr pSulSTDItem = GetSTDItemByName(listSulfideSTD, strSulfideBaseName);
  794. if (pSulSTDItem)
  795. {
  796. a_nIncId = pSulSTDItem->GetSTDId();
  797. return TRUE;
  798. }
  799. // rename the sulfides name as "Sulfide" if it is not
  800. if (strSulfideBaseName.CompareNoCase(SULFIDE_STR) != 0)
  801. {
  802. strSulfideBaseName = SULFIDE_STR;
  803. pSulSTDItem = GetSTDItemByName(listSulfideSTD, strSulfideBaseName);
  804. if (pSulSTDItem)
  805. {
  806. // found the STD item
  807. a_nIncId = pSulSTDItem->GetSTDId();
  808. return TRUE;
  809. }
  810. }
  811. // can't identify this inclusion
  812. a_nIncId = (int)OTS_PARTICLE_TYPE::NOT_IDENTIFIED;
  813. return TRUE;
  814. }
  815. // oxides classification
  816. BOOL COTSClassifyEng::OxideClassify(STEEL_TECHNOLOGY steelTech,
  817. CElementChemistriesList& a_listElChemsIncNoFe,
  818. double a_dMolarSumNoFe,
  819. int& a_nIncId)
  820. {
  821. // check if element chemistries list contain any oxygen
  822. CElementChemistryPtr pOElChem = GetNamedElementChemistry(a_listElChemsIncNoFe, STR_OXIDE);
  823. if (!pOElChem)
  824. {
  825. // contains no oxygen, this is not an oxide
  826. return TRUE;
  827. }
  828. // check if oxygen amount enough
  829. double dOMolar100 = Cal100NorValue(pOElChem->GetMolarPercentage(), a_dMolarSumNoFe);
  830. if (dOMolar100 < MIN_OXIDE_MOLAR)
  831. {
  832. // no enough oxygen, this is not an oxide
  833. return TRUE;
  834. }
  835. // this is an oxide
  836. // any oxide STD items
  837. if (listOxideSTD.empty())
  838. {
  839. // no oxide STD items, can't identify oxide
  840. // can't identify this inclusion
  841. a_nIncId = (int)OTS_PARTICLE_TYPE::NOT_IDENTIFIED;
  842. return TRUE;
  843. }
  844. // build oxide sub elements list
  845. // =========================================
  846. // get all possible oxide sub element chemistries
  847. CElementChemistriesList listTempOxideSubElChems;
  848. double dTempOxideSubElMolarSum = 0;
  849. for (int i = 0; i < INC_OXIDE_SUB_ELEMENT_MAX; ++i)
  850. {
  851. // try to get the oxide sub element
  852. CElementChemistryPtr pSubElChem = GetNamedElementChemistry(a_listElChemsIncNoFe, INC_OXIDE_SUB_ELEMENT_NAMES[i]);
  853. // found it?
  854. if (pSubElChem)
  855. {
  856. // got one
  857. // get the %molar value of the sub element chemistries
  858. double dSubElMolar = pSubElChem->GetMolarPercentage();
  859. // add the sub element chemistries into the oxides element chemistries list
  860. listTempOxideSubElChems.push_back(pSubElChem);
  861. dTempOxideSubElMolarSum += dSubElMolar;
  862. }
  863. }
  864. // clear oxide sub element chemistries list
  865. CElementChemistriesList listOxideSubElChems;
  866. double dOxideSubElMolarSum = 0;
  867. for (auto pElChem : listTempOxideSubElChems)
  868. {
  869. // get the %molar value of the sub element chemistries
  870. double dSubElMolar = pElChem->GetMolarPercentage();
  871. // the %molar value of the sub element chemistries of the sub element chemistries list
  872. double dSubElMolarMolar100 = Cal100NorValue(dSubElMolar, dTempOxideSubElMolarSum);
  873. // remove the sub element chemistries less than the cut off (2%)
  874. if (dSubElMolarMolar100 > MIN_OXIDE_SUB_MOLAR_CUTOFF)
  875. {
  876. // keep it
  877. listOxideSubElChems.push_back(pElChem);
  878. dOxideSubElMolarSum += dSubElMolar;
  879. }
  880. }
  881. // =========================================
  882. // check oxide elements list
  883. CString strOxideName = _T("");
  884. CString aluminateStr=_T("");
  885. if (listOxideSubElChems.empty())
  886. {
  887. // no oxide sub elements
  888. // consider this is not a oxide (may be it just is a dust)
  889. return TRUE;
  890. }
  891. // is a simple oxide?
  892. else if(IsASimpleOxide(listOxideSubElChems, dOxideSubElMolarSum, strOxideName))
  893. {
  894. // this is a simple oxide
  895. // named already during checking
  896. }
  897. // is it a REOxide (La-Ce-Oxide)?
  898. else if (IsAREOxide(listOxideSubElChems, dOxideSubElMolarSum))
  899. {
  900. // REOxcide
  901. strOxideName = REOXIDE_STR;
  902. }
  903. // should be a complex oxide
  904. // is it a REAlOxide?
  905. else if (IsAnREAlOxide(listOxideSubElChems, dOxideSubElMolarSum))
  906. {
  907. // REOxcide
  908. strOxideName = REALOXIDE_STR;
  909. }
  910. // is it a Spinel?
  911. else if (IsASpinel(listOxideSubElChems, dOxideSubElMolarSum))
  912. {
  913. // Spinel
  914. strOxideName = SPINEL_STR;
  915. }
  916. // is it a Silicate?
  917. else if (IsASilicate(listOxideSubElChems, dOxideSubElMolarSum))
  918. {
  919. // Silicate
  920. strOxideName = SILICATE_STR;
  921. }
  922. // is it an Aluminate?
  923. else if (IsAnCa_Aluminate(steelTech, listOxideSubElChems, dOxideSubElMolarSum, aluminateStr))
  924. {
  925. // Aluminate
  926. strOxideName = aluminateStr;
  927. }
  928. // fit none of them, simply name it as an oxide
  929. else
  930. {
  931. strOxideName = OXIDE_STR;
  932. }
  933. // confirm the oxide id
  934. // try to find the STD
  935. auto pSTDItem = GetSTDItemByName(listOxideSTD, strOxideName);
  936. if (pSTDItem)
  937. {
  938. // found the STD item
  939. a_nIncId = pSTDItem->GetSTDId();
  940. return TRUE;
  941. }
  942. // rename the oxide as "Oxide" if it is not
  943. if (strOxideName.CompareNoCase(OXIDE_STR) != 0)
  944. {
  945. strOxideName = OXIDE_STR;
  946. auto pSTDItem = GetSTDItemByName(listOxideSTD, strOxideName);
  947. if (pSTDItem)
  948. {
  949. // found the STD item
  950. a_nIncId = pSTDItem->GetSTDId();
  951. return TRUE;
  952. }
  953. }
  954. // can't identify this inclusion
  955. a_nIncId = (int)OTS_PARTICLE_TYPE::NOT_IDENTIFIED;
  956. return TRUE;
  957. }
  958. // nitrides classification
  959. BOOL COTSClassifyEng::NitrideClassify(STEEL_TECHNOLOGY steelTech,
  960. CElementChemistriesList& a_listElChemsIncNoFe,
  961. double a_dMolarSumNoFe,
  962. int& a_nIncId)
  963. {
  964. // check if element chemistries list contain any nitrogen
  965. CElementChemistryPtr pNitrElChem = GetNamedElementChemistry(a_listElChemsIncNoFe, STR_NITR);
  966. if (!pNitrElChem)
  967. {
  968. // contains no nitrogen, this is not a nitride
  969. return TRUE;
  970. }
  971. // check if nitrogen amount enough
  972. double dNitrMolar100 = Cal100NorValue(pNitrElChem->GetMolarPercentage(), a_dMolarSumNoFe);
  973. if (dNitrMolar100 < MIN_NITR_MOLAR)
  974. {
  975. // have no enough nitrogen, this is not a nitride
  976. return TRUE;
  977. }
  978. // this is a nitride
  979. // any nitride STD items
  980. if (listNitrideSTD.empty())
  981. {
  982. // no nitrides std items.
  983. // can't identify this inclusion
  984. a_nIncId = (int)OTS_PARTICLE_TYPE::NOT_IDENTIFIED;
  985. return TRUE;
  986. }
  987. // mapping nitride sub elements
  988. CString strNitrideName = _T("");
  989. BOOL bMapped = FALSE;
  990. for (int i = 0; i < INC_NITR_SUB_ELEMENT_MAX; ++i)
  991. {
  992. CElementChemistryPtr pNitrSubElChem = GetNamedElementChemistry(a_listElChemsIncNoFe, INC_NITR_SUB_ELEMENT_NAMES[i]);
  993. if (pNitrSubElChem)
  994. {
  995. // this is a nitride sub element chemistry
  996. // get %molar value of this sub element chemistry
  997. double dNitr_Sub_Molar = Cal100NorValue(pNitrSubElChem->GetMolarPercentage(), a_dMolarSumNoFe);
  998. // make sure the sub element molar value is over mapping min value
  999. if (dNitr_Sub_Molar > MIN_NITR_SUB_MOLAR)
  1000. {
  1001. // mapping this sub element chemistry
  1002. double dMappingRadio = INC_NITR_MAPPING_RATIO[i];
  1003. if (!ElementsMapping(a_dMolarSumNoFe, dMappingRadio, pNitrSubElChem, pNitrElChem, bMapped))
  1004. {
  1005. // something is wrong
  1006. LogErrorTrace(__FILE__, __LINE__, _T("COTSClassifyEng::NitrideClassify: failed to call ElementsMapping method."));
  1007. return FALSE;
  1008. }
  1009. // mapping succeed?
  1010. if(bMapped)
  1011. {
  1012. // is mapped Ti?
  1013. if (i == 0)
  1014. {
  1015. // the first mapped nitride is "TiN"
  1016. // try to map Nb
  1017. BOOL bNbMapped = FALSE;
  1018. // get molar % of the rest nitrogen
  1019. dNitrMolar100 = Cal100NorValue(pNitrElChem->GetMolarPercentage(), a_dMolarSumNoFe);
  1020. // make sure nitrogen amount is enough
  1021. if (dNitrMolar100 > MIN_NITR_MOLAR)
  1022. {
  1023. // get element "Nb"
  1024. CElementChemistryPtr pElChemNb = GetNamedElementChemistry(a_listElChemsIncNoFe, STR_Nb);
  1025. // is there Nb in the list
  1026. if (pElChemNb)
  1027. {
  1028. // get %molar value of Nb
  1029. double dNb_Molar = Cal100NorValue(pElChemNb->GetMolarPercentage(), a_dMolarSumNoFe);
  1030. // make sure Nb molar value is over mapping min value
  1031. double dNbMappingRadio = INC_NITR_MAPPING_RATIO[2];
  1032. if (dNb_Molar > MIN_NITR_SUB_MOLAR)
  1033. {
  1034. if (!ElementsMapping(a_dMolarSumNoFe, dNbMappingRadio, pElChemNb, pNitrElChem, bNbMapped))
  1035. {
  1036. // something is wrong
  1037. LogErrorTrace(__FILE__, __LINE__, _T("COTSClassifyEng::NitrideClassify: failed to call ElementsMapping method."));
  1038. return FALSE;
  1039. }
  1040. }
  1041. }
  1042. }
  1043. // mapped "Nb"
  1044. if (bNbMapped)
  1045. {
  1046. // nitride name is "TiN-NbN"
  1047. strNitrideName = INC_NITR_NAMES[0] + STR_CONNECT + INC_NITR_NAMES[2];
  1048. }
  1049. else
  1050. {
  1051. // nitride name is "TiN"
  1052. strNitrideName = INC_NITR_NAMES[0];
  1053. }
  1054. }
  1055. else
  1056. {
  1057. // get the nitride name
  1058. strNitrideName = INC_NITR_NAMES[i];
  1059. }
  1060. // completed mapping, get out the loop
  1061. break;
  1062. }
  1063. }
  1064. }
  1065. }
  1066. // not mapped?
  1067. if (!bMapped)
  1068. {
  1069. // force to name it as "Nitride" if N 100% molar value over cutting off value
  1070. if (dNitrMolar100 > NITRIDE_MOLAR_CUTOFF)
  1071. {
  1072. strNitrideName = NITRIDE_STR;
  1073. }
  1074. else
  1075. {
  1076. // no enough nitride, consider that it is not a nitride
  1077. return TRUE;
  1078. }
  1079. }
  1080. // check if the rest element chemistries map an oxide
  1081. int nIncId = (int)OTS_PARTICLE_TYPE::INVALID;
  1082. if (!OxideClassify(steelTech, a_listElChemsIncNoFe, a_dMolarSumNoFe, nIncId))
  1083. {
  1084. // something wrong
  1085. LogErrorTrace(__FILE__, __LINE__, _T("COTSClassifyEng::NitrideClassify: failed to call OxideClassify method."));
  1086. return FALSE;
  1087. }
  1088. // mapped?
  1089. if (nIncId >= (int)OTS_PARTICLE_TYPE::IDENTIFIED)
  1090. {
  1091. // this is an oxide nitride
  1092. // confirm the oxide nitride id
  1093. // get the STD item of the mapped oxide
  1094. CSTDItemPtr pOxideSTDItem = pPartSTDData->GetSTDItemById(nIncId);
  1095. if (pOxideSTDItem)
  1096. {
  1097. // get mapped oxide name
  1098. CString strOxideName = pOxideSTDItem->GetName();
  1099. // oxide nitride name: oxide + "-" + nitride base string
  1100. CString strOxide_NitrName = strOxideName + STR_CONNECT + strNitrideName;
  1101. // try to find the STD item
  1102. CSTDItemPtr pOxideNitrSTDItem = GetSTDItemByName(listNitrideSTD, strOxide_NitrName);
  1103. if (pOxideNitrSTDItem)
  1104. {
  1105. // found the STD item
  1106. a_nIncId = pOxideNitrSTDItem->GetSTDId();
  1107. return TRUE;
  1108. }
  1109. // can't find the STD item
  1110. // rename the oxide nitride name as "Oxide" + "-" + nitride base string
  1111. strOxide_NitrName = OXIDE_STR + STR_CONNECT + strOxide_NitrName;
  1112. // try to find the STD item
  1113. pOxideNitrSTDItem = GetSTDItemByName(listNitrideSTD, strOxide_NitrName);
  1114. if (pOxideNitrSTDItem)
  1115. {
  1116. // found the STD item
  1117. a_nIncId = pOxideNitrSTDItem->GetSTDId();
  1118. return TRUE;
  1119. }
  1120. // rename the oxide nitride name as strOxideName + "-" + "Nitride"
  1121. strOxide_NitrName = strOxideName + STR_CONNECT + NITRIDE_STR;
  1122. // try to find the STD item
  1123. pOxideNitrSTDItem = GetSTDItemByName(listNitrideSTD, strOxide_NitrName);
  1124. if (pOxideNitrSTDItem)
  1125. {
  1126. // found the STD item
  1127. a_nIncId = pOxideNitrSTDItem->GetSTDId();
  1128. return TRUE;
  1129. }
  1130. // rename the oxide nitride name as "Oxide" + "-" + "Nitride"
  1131. strOxide_NitrName = OXIDE_STR + STR_CONNECT + NITRIDE_STR;
  1132. // try to find the STD item
  1133. pOxideNitrSTDItem = GetSTDItemByName(listNitrideSTD, strOxide_NitrName);
  1134. if (pOxideNitrSTDItem)
  1135. {
  1136. // found the STD item
  1137. a_nIncId = pOxideNitrSTDItem->GetSTDId();
  1138. return TRUE;
  1139. }
  1140. // rename the oxide nitride name as "Nitride"
  1141. strOxide_NitrName = NITRIDE_STR;
  1142. // try to find the STD item
  1143. pOxideNitrSTDItem = GetSTDItemByName(listNitrideSTD, strOxide_NitrName);
  1144. if (pOxideNitrSTDItem)
  1145. {
  1146. // found the STD item
  1147. a_nIncId = pOxideSTDItem->GetSTDId();
  1148. return TRUE;
  1149. }
  1150. }
  1151. // can't identify this inclusion
  1152. a_nIncId = (int)OTS_PARTICLE_TYPE::NOT_IDENTIFIED;
  1153. return TRUE;
  1154. }
  1155. // confirm the nitride id
  1156. // try to find the STD
  1157. auto pSTDItem = GetSTDItemByName(listNitrideSTD, strNitrideName);
  1158. if (pSTDItem)
  1159. {
  1160. // found the STD item
  1161. a_nIncId = pSTDItem->GetSTDId();
  1162. return TRUE;
  1163. }
  1164. // rename the nitride as "Nitride" if it is not
  1165. if (strNitrideName.CompareNoCase(NITRIDE_STR) != 0)
  1166. {
  1167. strNitrideName = NITRIDE_STR;
  1168. auto pSTDItem = GetSTDItemByName(listNitrideSTD, strNitrideName);
  1169. if (pSTDItem)
  1170. {
  1171. // found the STD item
  1172. a_nIncId = pSTDItem->GetSTDId();
  1173. return TRUE;
  1174. }
  1175. }
  1176. // can't identify this inclusion
  1177. a_nIncId = (int)OTS_PARTICLE_TYPE::NOT_IDENTIFIED;
  1178. return TRUE;
  1179. }
  1180. // nominate element chemistries list
  1181. BOOL COTSClassifyEng::NominateElChemsList( CElementChemistriesList& a_listElChemsInc,
  1182. CElementChemistriesList& a_listNomiElChemsInc)
  1183. {
  1184. // return FALSE if nothing in the input list
  1185. if (a_listElChemsInc.empty())
  1186. {
  1187. //LogErrorTrace(__FILE__, __LINE__, _T("COTSClassifyEng::NomiNateElChemsList: invalid inclusion x-ray data."));
  1188. return FALSE;
  1189. }
  1190. // initialize outputs
  1191. a_listNomiElChemsInc.clear();
  1192. // go thought all element chemistry objects of the input lit
  1193. double dWeightPerSum = 0;
  1194. for (auto pElChem : a_listElChemsInc)
  1195. {
  1196. // create a new element chemistry
  1197. CElementChemistryPtr pElChemNew = CElementChemistryPtr(new CElementChemistry(*pElChem.get()));
  1198. // key element?
  1199. if (IsKeyElement(pElChem))
  1200. {
  1201. // this is a key element
  1202. // cal weight percentage sum
  1203. dWeightPerSum += pElChem->GetPercentage();
  1204. // add the element into the output list
  1205. a_listNomiElChemsInc.push_back(pElChemNew);
  1206. }
  1207. // sub element?
  1208. else if (IsSubElement(pElChem))
  1209. {
  1210. // this is a sub element
  1211. // Fe?
  1212. if (pElChem->GetName().CompareNoCase("Fe") != 0)
  1213. {
  1214. // cal weight percentage sum
  1215. dWeightPerSum += pElChem->GetPercentage();
  1216. // add the element into the output list
  1217. a_listNomiElChemsInc.push_back(pElChemNew);
  1218. }
  1219. }
  1220. }
  1221. // return FALSE if nothing in the input list or sum less than cut off value
  1222. if (a_listNomiElChemsInc.empty() || dWeightPerSum < INC_SUB_ELEMENT_CUT_OFF)
  1223. {
  1224. // something wrong
  1225. LogErrorTrace(__FILE__, __LINE__, _T("COTSClassifyEng::NomiNateElChemsList: invalid inclusion x-ray data."));
  1226. return FALSE;
  1227. }
  1228. // go thought all element chemistry objects of the output lit
  1229. for (auto pElChem : a_listNomiElChemsInc)
  1230. {
  1231. // reset weight % value
  1232. // get weight % value
  1233. double dWeightPer = pElChem->GetPercentage();
  1234. // calculate new weight % value
  1235. double dWeightPerNew = Cal100NorValue(dWeightPer, dWeightPerSum);
  1236. // reset
  1237. pElChem->SetPercentage(dWeightPerNew);
  1238. }
  1239. // ok, return TRUE
  1240. return TRUE;
  1241. }
  1242. // protected
  1243. // check if this is a key element
  1244. BOOL COTSClassifyEng::IsKeyElement(CElementChemistryPtr a_pElChem)
  1245. {
  1246. // safety check
  1247. ASSERT(a_pElChem);
  1248. if (!a_pElChem)
  1249. {
  1250. // something wrong
  1251. LogErrorTrace(__FILE__, __LINE__, _T("COTSClassifyEng::IsKeyElement: invalid CElementChemistryPtr."));
  1252. return FALSE;
  1253. }
  1254. // go thought all key element
  1255. for (long i = 0; i < INC_KEY_ELEMENT_MAX; ++i)
  1256. {
  1257. // compare
  1258. if ((a_pElChem->GetName().CompareNoCase(INC_KEY_ELEMENT_NAMES[i]) == 0) && (a_pElChem->GetPercentage() >= INC_KEY_ELEMENT_CUT_OFF))
  1259. {
  1260. // this is a key element, return TRUE
  1261. return TRUE;
  1262. }
  1263. }
  1264. // this is not a key element, return FALSE
  1265. return FALSE;
  1266. }
  1267. // check if this is a sub element
  1268. BOOL COTSClassifyEng::IsSubElement(CElementChemistryPtr a_pElChem)
  1269. {
  1270. // safety check
  1271. ASSERT(a_pElChem);
  1272. if (!a_pElChem)
  1273. {
  1274. // something wrong
  1275. LogErrorTrace(__FILE__, __LINE__, _T("COTSClassifyEng::IsSubElement: invalid CElementChemistryPtr."));
  1276. return FALSE;
  1277. }
  1278. // go thought all sub element
  1279. for (long i = 0; i < INC_SUB_ELEMENT_MAX; ++i)
  1280. {
  1281. // compare
  1282. if ((a_pElChem->GetName().CompareNoCase(INC_SUB_ELEMENT_NAMES[i]) == 0) && (a_pElChem->GetPercentage() >= INC_SUB_ELEMENT_CUT_OFF))
  1283. {
  1284. // this is a key element, return TRUE
  1285. return TRUE;
  1286. }
  1287. }
  1288. // this is not a key element, return FALSE
  1289. return FALSE;
  1290. }
  1291. // get named element chemistry
  1292. CElementChemistryPtr COTSClassifyEng::GetNamedElementChemistry(CElementChemistriesList & a_listChemistriesElements, const CString a_strElementName)
  1293. {
  1294. CElementChemistryPtr pElChem = nullptr;
  1295. CString strName = a_strElementName;
  1296. auto itr = std::find_if(a_listChemistriesElements.begin(), a_listChemistriesElements.end(), [strName](CElementChemistryPtr& poElementChemistry) { return poElementChemistry->GetName().CompareNoCase(strName) == 0; });
  1297. if (itr != a_listChemistriesElements.end())
  1298. {
  1299. pElChem = *itr;
  1300. }
  1301. return pElChem;
  1302. }
  1303. bool SortBySTDID(const std::shared_ptr< CSTDItem> &v1, const std::shared_ptr< CSTDItem> &v2)
  1304. {
  1305. return v1->GetSTDId() < v2->GetSTDId();
  1306. }
  1307. // get classify STD items
  1308. BOOL COTSClassifyEng::GetClassifySTDItem(CInclutionSTDDataPtr a_pPartSTDDataPtr, INC_CLASSIFY_TYPE a_nClassifyType, CSTDItemsList& a_listSTDItems)
  1309. {
  1310. // cal STD item id value range
  1311. OTS_STD_ITEM_VALUE nSTDIdRangeMin = OTS_STD_ITEM_VALUE::INVALID;
  1312. OTS_STD_ITEM_VALUE nSTDIdRangeMax = OTS_STD_ITEM_VALUE::INVALID;
  1313. switch (a_nClassifyType)
  1314. {
  1315. case INC_CLASSIFY_TYPE::SIMPLE_OXIDE:
  1316. {
  1317. nSTDIdRangeMin = OTS_STD_ITEM_VALUE::SYS_SIMPLE_OXIDE_MIN;
  1318. nSTDIdRangeMax = OTS_STD_ITEM_VALUE::SYS_SIMPLE_OXIDE_MAX;
  1319. }
  1320. break;
  1321. case INC_CLASSIFY_TYPE::COMPLEX_OXIDE:
  1322. {
  1323. nSTDIdRangeMin = OTS_STD_ITEM_VALUE::SYS_COMPLEX_OXIDE_MIN;
  1324. nSTDIdRangeMax = OTS_STD_ITEM_VALUE::SYS_COMPLEX_OXIDE_MAX;
  1325. }
  1326. break;
  1327. case INC_CLASSIFY_TYPE::OXIDE:
  1328. {
  1329. nSTDIdRangeMin = OTS_STD_ITEM_VALUE::SYS_OXIDE_MIN;
  1330. nSTDIdRangeMax = OTS_STD_ITEM_VALUE::SYS_OXIDE_MAX;
  1331. }
  1332. break;
  1333. case INC_CLASSIFY_TYPE::SUL:
  1334. {
  1335. nSTDIdRangeMin = OTS_STD_ITEM_VALUE::SYS_SUL_MIN;
  1336. nSTDIdRangeMax = OTS_STD_ITEM_VALUE::SYS_SUL_MAX;
  1337. }
  1338. break;
  1339. case INC_CLASSIFY_TYPE::NITR:
  1340. {
  1341. nSTDIdRangeMin = OTS_STD_ITEM_VALUE::SYS_NITRIDE_MIN;
  1342. nSTDIdRangeMax = OTS_STD_ITEM_VALUE::SYS_NITRIDE_MAX;
  1343. }
  1344. break;
  1345. case INC_CLASSIFY_TYPE::CARBON:
  1346. {
  1347. nSTDIdRangeMin = OTS_STD_ITEM_VALUE::SYS_CARBON_MIN;
  1348. nSTDIdRangeMax = OTS_STD_ITEM_VALUE::SYS_CARBON_MAX;
  1349. }
  1350. break;
  1351. case INC_CLASSIFY_TYPE::USER:
  1352. {
  1353. nSTDIdRangeMin = OTS_STD_ITEM_VALUE::USER_MIN;
  1354. nSTDIdRangeMax = OTS_STD_ITEM_VALUE::USER_MAX;
  1355. }
  1356. break;
  1357. default:
  1358. {
  1359. // wrong classify type value, return FALSE
  1360. return FALSE;
  1361. }
  1362. break;
  1363. }
  1364. // go through all STD items
  1365. a_listSTDItems.clear();
  1366. for (auto pSTDItem : a_pPartSTDDataPtr->GetSTDItemsList())
  1367. {
  1368. // is matching STD item?
  1369. if (pSTDItem->GetSTDId() >= (int)nSTDIdRangeMin && pSTDItem->GetSTDId() <= (int)nSTDIdRangeMax)
  1370. {
  1371. // get matching STD item
  1372. a_listSTDItems.push_back(pSTDItem);
  1373. }
  1374. }
  1375. // sort std item by std id
  1376. sort(a_listSTDItems.begin(), a_listSTDItems.end(), SortBySTDID);
  1377. // ok, return TRUE
  1378. return TRUE;
  1379. }
  1380. BOOL COTSClassifyEng::GetClassifyTypeOfSTDItem(int a_nIncId, INC_CLASSIFY_TYPE& a_nClassifyType)
  1381. {
  1382. a_nClassifyType = INC_CLASSIFY_TYPE::INVALID;
  1383. if (a_nIncId >=(int) OTS_STD_ITEM_VALUE::SYS_SIMPLE_OXIDE_MIN && a_nIncId < (int)OTS_STD_ITEM_VALUE::SYS_SIMPLE_OXIDE_MAX)
  1384. {
  1385. a_nClassifyType = INC_CLASSIFY_TYPE::SIMPLE_OXIDE;
  1386. }else if(a_nIncId >= (int) OTS_STD_ITEM_VALUE::SYS_COMPLEX_OXIDE_MIN && a_nIncId < (int)OTS_STD_ITEM_VALUE::SYS_COMPLEX_OXIDE_MAX)
  1387. {
  1388. a_nClassifyType = INC_CLASSIFY_TYPE::COMPLEX_OXIDE;
  1389. }
  1390. else if (a_nIncId >= (int)OTS_STD_ITEM_VALUE::SYS_OXIDE_MIN && a_nIncId < (int)OTS_STD_ITEM_VALUE::SYS_OXIDE_MAX)
  1391. {
  1392. a_nClassifyType = INC_CLASSIFY_TYPE::OXIDE;
  1393. }
  1394. else if (a_nIncId >= (int)OTS_STD_ITEM_VALUE::SYS_SUL_MIN && a_nIncId < (int)OTS_STD_ITEM_VALUE::SYS_SUL_MAX)
  1395. {
  1396. a_nClassifyType = INC_CLASSIFY_TYPE::SUL;
  1397. }
  1398. else if (a_nIncId >= (int)OTS_STD_ITEM_VALUE::SYS_NITRIDE_MIN && a_nIncId < (int)OTS_STD_ITEM_VALUE::SYS_NITRIDE_MAX)
  1399. {
  1400. a_nClassifyType = INC_CLASSIFY_TYPE::NITR;
  1401. }
  1402. return true;
  1403. }
  1404. BOOL COTSClassifyEng::GetSulfildeOxideComplexItemId(STEEL_TECHNOLOGY steelTech, CElementChemistriesList& a_listElChemsIncNoFe, double a_dMolarSumNoFe, CString strSulfideBaseName, int& a_nIncId)
  1405. {
  1406. int nIncId;
  1407. if (!OxideClassify(steelTech,a_listElChemsIncNoFe, a_dMolarSumNoFe, nIncId))
  1408. {
  1409. a_nIncId = (int)OTS_PARTICLE_TYPE::NOT_IDENTIFIED;
  1410. return FALSE;
  1411. }
  1412. // mapped?
  1413. if (nIncId >= (int)OTS_PARTICLE_TYPE::IDENTIFIED)
  1414. {
  1415. // this is an oxide sulfide
  1416. // confirm the oxide sulfide id
  1417. // get the STD item of the mapped oxide
  1418. CSTDItemPtr pOxideSTDItem = pPartSTDData->GetSTDItemById(nIncId);
  1419. if (pOxideSTDItem)
  1420. {
  1421. // get mapped oxide name
  1422. CString strOxideName = pOxideSTDItem->GetName();
  1423. // oxide sulfide name: oxide + "-" + sulfide base string
  1424. CString strOxide_SulName = strOxideName + STR_CONNECT + strSulfideBaseName;
  1425. // try to find the STD item
  1426. CSTDItemPtr pOxideSulSTDItem = GetSTDItemByName(listSulfideSTD, strOxide_SulName);
  1427. if (pOxideSulSTDItem)
  1428. {
  1429. // found the STD item
  1430. a_nIncId = pOxideSulSTDItem->GetSTDId();
  1431. return TRUE;
  1432. }
  1433. // rename the oxide sulfide name as "Oxide" + "-" + sulfide base string
  1434. strOxide_SulName = OXIDE_STR + STR_CONNECT + strSulfideBaseName;
  1435. // try to find the STD item
  1436. pOxideSulSTDItem = GetSTDItemByName(listSulfideSTD, strOxide_SulName);
  1437. if (pOxideSulSTDItem)
  1438. {
  1439. // found the STD item
  1440. a_nIncId = pOxideSulSTDItem->GetSTDId();
  1441. return TRUE;
  1442. }
  1443. // rename the oxide sulfide name as strOxideName + "-" + "Sulfide"
  1444. strOxide_SulName = strOxideName + STR_CONNECT + SULFIDE_STR;
  1445. // try to find the STD item
  1446. pOxideSulSTDItem = GetSTDItemByName(listSulfideSTD, strOxide_SulName);
  1447. if (pOxideSulSTDItem)
  1448. {
  1449. // found the STD item
  1450. a_nIncId = pOxideSulSTDItem->GetSTDId();
  1451. return TRUE;
  1452. }
  1453. // rename the oxide sulfide name as "Oxide" + "-" + "Sulfide"
  1454. strOxide_SulName = OXIDE_STR + STR_CONNECT + SULFIDE_STR;
  1455. // try to find the STD item
  1456. pOxideSulSTDItem = GetSTDItemByName(listSulfideSTD, strOxide_SulName);
  1457. if (pOxideSulSTDItem)
  1458. {
  1459. // found the STD item
  1460. a_nIncId = pOxideSulSTDItem->GetSTDId();
  1461. return TRUE;
  1462. }
  1463. // rename the oxide sulfide name as "Sulfide"
  1464. strOxide_SulName = SULFIDE_STR;
  1465. // try to find the STD item
  1466. pOxideSulSTDItem = GetSTDItemByName(listSulfideSTD, strOxide_SulName);
  1467. if (pOxideSulSTDItem)
  1468. {
  1469. // found the STD item
  1470. a_nIncId = pOxideSulSTDItem->GetSTDId();
  1471. return TRUE;
  1472. }
  1473. }
  1474. // can't identify this inclusion
  1475. a_nIncId = (int)OTS_PARTICLE_TYPE::NOT_IDENTIFIED;
  1476. return TRUE;
  1477. }
  1478. a_nIncId = (int)OTS_PARTICLE_TYPE::NOT_IDENTIFIED;
  1479. return TRUE;
  1480. }
  1481. BOOL COTSClassifyEng::GetSulfildeNitrideComplexItemId(STEEL_TECHNOLOGY steelTech, CElementChemistriesList& a_listElChemsIncNoFe, double a_dMolarSumNoFe, CString strSulfideBaseName, int& a_nIncId)
  1482. {
  1483. int nIncId;
  1484. if (!NitrideClassify(steelTech,a_listElChemsIncNoFe, a_dMolarSumNoFe, nIncId))
  1485. {
  1486. a_nIncId = (int)OTS_PARTICLE_TYPE::NOT_IDENTIFIED;
  1487. return FALSE;
  1488. }
  1489. if (nIncId >= (int)OTS_PARTICLE_TYPE::IDENTIFIED)
  1490. {
  1491. CSTDItemPtr pNitrideTDItem = pPartSTDData->GetSTDItemById(nIncId);
  1492. if (pNitrideTDItem)
  1493. {// get mapped oxide name
  1494. CString strNitrideName = pNitrideTDItem->GetName();
  1495. // oxide sulfide name: oxide + "-" + sulfide base string
  1496. CString strNitride_SulName = strNitrideName + STR_CONNECT + strSulfideBaseName;
  1497. // try to find the STD item
  1498. CSTDItemPtr pNitrideSulSTDItem = GetSTDItemByName(listSulfideSTD, strNitride_SulName);
  1499. if (pNitrideSulSTDItem)
  1500. {
  1501. // found the STD item
  1502. a_nIncId = pNitrideSulSTDItem->GetSTDId();
  1503. return TRUE;
  1504. }
  1505. // rename the oxide sulfide name as "Oxide" + "-" + sulfide base string
  1506. strNitride_SulName = NITRIDE_STR + STR_CONNECT + strSulfideBaseName;
  1507. // try to find the STD item
  1508. pNitrideSulSTDItem = GetSTDItemByName(listSulfideSTD, strNitride_SulName);
  1509. if (pNitrideSulSTDItem)
  1510. {
  1511. // found the STD item
  1512. a_nIncId = pNitrideSulSTDItem->GetSTDId();
  1513. return TRUE;
  1514. }
  1515. // rename the oxide sulfide name as strOxideName + "-" + "Sulfide"
  1516. strNitride_SulName = strNitrideName + STR_CONNECT + SULFIDE_STR;
  1517. // try to find the STD item
  1518. pNitrideSulSTDItem = GetSTDItemByName(listSulfideSTD, strNitride_SulName);
  1519. if (pNitrideSulSTDItem)
  1520. {
  1521. // found the STD item
  1522. a_nIncId = pNitrideSulSTDItem->GetSTDId();
  1523. return TRUE;
  1524. }
  1525. // rename the oxide sulfide name as "Oxide" + "-" + "Sulfide"
  1526. strNitride_SulName = NITRIDE_STR + STR_CONNECT + SULFIDE_STR;
  1527. // try to find the STD item
  1528. pNitrideSulSTDItem = GetSTDItemByName(listSulfideSTD, strNitride_SulName);
  1529. if (pNitrideSulSTDItem)
  1530. {
  1531. // found the STD item
  1532. a_nIncId = pNitrideSulSTDItem->GetSTDId();
  1533. return TRUE;
  1534. }
  1535. // rename the oxide sulfide name as "Sulfide"
  1536. strNitride_SulName = SULFIDE_STR;
  1537. // try to find the STD item
  1538. pNitrideSulSTDItem = GetSTDItemByName(listSulfideSTD, strNitride_SulName);
  1539. if (pNitrideSulSTDItem)
  1540. {
  1541. // found the STD item
  1542. a_nIncId = pNitrideSulSTDItem->GetSTDId();
  1543. return TRUE;
  1544. }
  1545. }
  1546. }
  1547. return true;
  1548. }
  1549. void COTSClassifyEng::FilterOnSteelTech(STEEL_TECHNOLOGY steelTech, CElementChemistriesList& a_listElChemsIncNoFe)
  1550. {
  1551. CElementChemistriesList listChemistriesToAnalysis;
  1552. switch (steelTech)
  1553. {
  1554. // Ca process
  1555. case STEEL_TECHNOLOGY::CaProcessMode:
  1556. {
  1557. //remove the Mg element first
  1558. CElementChemistryPtr pElChemMg = GetNamedElementChemistry(a_listElChemsIncNoFe, INC_SUL_SUB_ELEMENT_NAMES[2]);
  1559. if (pElChemMg)
  1560. {
  1561. for (auto el : a_listElChemsIncNoFe)
  1562. {
  1563. if (!el->GetName().CompareNoCase(INC_SUL_SUB_ELEMENT_NAMES[2]))
  1564. {
  1565. listChemistriesToAnalysis.push_back(el);
  1566. }
  1567. }
  1568. }
  1569. else
  1570. {
  1571. listChemistriesToAnalysis = a_listElChemsIncNoFe;
  1572. }
  1573. }
  1574. break;
  1575. // Mg process
  1576. case STEEL_TECHNOLOGY::MgProcessMode:
  1577. {
  1578. //remove the Ca element first
  1579. CElementChemistryPtr pElChemCa = GetNamedElementChemistry(a_listElChemsIncNoFe, INC_SUL_SUB_ELEMENT_NAMES[1]);
  1580. if (pElChemCa)
  1581. {
  1582. for (auto el : a_listElChemsIncNoFe)
  1583. {
  1584. if (!el->GetName().CompareNoCase(INC_SUL_SUB_ELEMENT_NAMES[1]))
  1585. {
  1586. listChemistriesToAnalysis.push_back(el);
  1587. }
  1588. }
  1589. }
  1590. else
  1591. {
  1592. listChemistriesToAnalysis = a_listElChemsIncNoFe;
  1593. }
  1594. }
  1595. break;
  1596. // real earth elements process
  1597. case STEEL_TECHNOLOGY::RareEarthMode:
  1598. {
  1599. listChemistriesToAnalysis = a_listElChemsIncNoFe;
  1600. }
  1601. break;
  1602. default:
  1603. listChemistriesToAnalysis = a_listElChemsIncNoFe;
  1604. break;
  1605. }
  1606. a_listElChemsIncNoFe = listChemistriesToAnalysis;
  1607. }
  1608. BOOL COTSClassifyEng::ElementMatching(double a_dMolarSum,CElementChemistriesList a_listElChemsInc, CElementChemistryPtr KeyEleChemistry,CString subEleName,double mappingRatio, double& dKeyEleRemainMolar100)
  1609. {
  1610. BOOL bMapped = FALSE;
  1611. {
  1612. CElementChemistryPtr psubChem = GetNamedElementChemistry(a_listElChemsInc, subEleName);
  1613. if (psubChem)
  1614. {
  1615. if (!ElementsMapping(a_dMolarSum, mappingRatio, psubChem, KeyEleChemistry, bMapped))
  1616. {
  1617. return FALSE;
  1618. }
  1619. }
  1620. }
  1621. // need to re-calculate 100% molar value if mapped
  1622. if (bMapped)
  1623. {
  1624. dKeyEleRemainMolar100 = Cal100NorValue(KeyEleChemistry->GetMolarPercentage(), a_dMolarSum);
  1625. }
  1626. return bMapped;
  1627. }
  1628. BOOL COTSClassifyEng::ElementMatchingOnSteelTech(double a_dMolarSumNoFe,STEEL_TECHNOLOGY steelTech, CElementChemistriesList a_listElChemsIncNoFe, CElementChemistryPtr pSulElChem,CString& strProMappingSulName)
  1629. {
  1630. BOOL bProMapped=false;
  1631. double dSulResidual;
  1632. switch (steelTech)
  1633. {
  1634. case STEEL_TECHNOLOGY::CaProcessMode:
  1635. {
  1636. BOOL bCaMapped = FALSE;
  1637. {
  1638. CString strEle = INC_SUL_SUB_ELEMENT_NAMES[1];
  1639. double dMappingRatio = INC_SULFILSES_MAPPING_RATIO[1];
  1640. bCaMapped = ElementMatching(a_dMolarSumNoFe, a_listElChemsIncNoFe, pSulElChem, strEle, dMappingRatio, dSulResidual);
  1641. }
  1642. bProMapped = bCaMapped;
  1643. if (bProMapped)
  1644. {
  1645. strProMappingSulName = INC_SULFILSES_NAMES[1];
  1646. }
  1647. }
  1648. break;
  1649. case STEEL_TECHNOLOGY::MgProcessMode:
  1650. {
  1651. BOOL bMgMapped = FALSE;
  1652. {
  1653. CString strEle = INC_SUL_SUB_ELEMENT_NAMES[2];
  1654. double dMappingRatio = INC_SULFILSES_MAPPING_RATIO[2];
  1655. bMgMapped = ElementMatching(a_dMolarSumNoFe, a_listElChemsIncNoFe, pSulElChem, strEle, dMappingRatio, dSulResidual);
  1656. }
  1657. bProMapped = bMgMapped;
  1658. if (bProMapped)
  1659. {
  1660. strProMappingSulName = INC_SULFILSES_NAMES[2];
  1661. }
  1662. }
  1663. break;
  1664. case STEEL_TECHNOLOGY::RareEarthMode:
  1665. {
  1666. BOOL bCeMapped = FALSE;
  1667. {
  1668. CString strEle = INC_SUL_SUB_ELEMENT_NAMES[3];
  1669. double dMappingRatio = INC_SULFILSES_MAPPING_RATIO[3];
  1670. bCeMapped = ElementMatching(a_dMolarSumNoFe, a_listElChemsIncNoFe, pSulElChem, strEle, dMappingRatio, dSulResidual);
  1671. }
  1672. BOOL bLaMapped = FALSE;
  1673. {
  1674. CString strEle = INC_SUL_SUB_ELEMENT_NAMES[4];
  1675. double dMappingRatio = INC_SULFILSES_MAPPING_RATIO[4];
  1676. bLaMapped = ElementMatching(a_dMolarSumNoFe, a_listElChemsIncNoFe, pSulElChem, strEle, dMappingRatio, dSulResidual);
  1677. }
  1678. if (bCeMapped && bLaMapped)
  1679. {
  1680. strProMappingSulName = INC_SULFILSES_NAMES[3] + STR_CONNECT + INC_SULFILSES_NAMES[4];
  1681. bProMapped = TRUE;
  1682. }
  1683. else if (bCeMapped)
  1684. {
  1685. strProMappingSulName = INC_SULFILSES_NAMES[3];
  1686. bProMapped = TRUE;
  1687. }
  1688. else if (bLaMapped)
  1689. {
  1690. strProMappingSulName = INC_SULFILSES_NAMES[4];
  1691. bProMapped = TRUE;
  1692. }
  1693. }
  1694. break;
  1695. default:
  1696. break;
  1697. }
  1698. return bProMapped;
  1699. }
  1700. // get STD item by name
  1701. CSTDItemPtr COTSClassifyEng::GetSTDItemByName(CSTDItemsList& a_listSTDItems, CString a_strName)
  1702. {
  1703. CSTDItemPtr pSTDItem = nullptr;
  1704. auto itr = std::find_if(a_listSTDItems.begin(), a_listSTDItems.end(), [a_strName](CSTDItemPtr& pSTD) { return pSTD->GetName().CompareNoCase(a_strName) == 0; });
  1705. if (itr != a_listSTDItems.end())
  1706. {
  1707. // found the STD item
  1708. pSTDItem = *itr;
  1709. }
  1710. return pSTDItem;
  1711. }
  1712. // get STD item name by id
  1713. CString COTSClassifyEng::GetSTDItemNameById(CSTDItemsList& a_listSTDItems, int a_nItemId)
  1714. {
  1715. CString strName = _T("");
  1716. CSTDItemPtr pSTDItem = nullptr;
  1717. auto itr = std::find_if(a_listSTDItems.begin(), a_listSTDItems.end(), [a_nItemId](CSTDItemPtr& pSTD) { return pSTD->GetSTDId() == a_nItemId; });
  1718. if (itr != a_listSTDItems.end())
  1719. {
  1720. // found the STD item
  1721. pSTDItem = *itr;
  1722. strName = pSTDItem->GetName();
  1723. }
  1724. return strName;
  1725. }
  1726. // elements mapping
  1727. BOOL COTSClassifyEng::ElementsMapping(double a_dMolarSumNoFe,
  1728. double a_dMappingRatio,
  1729. CElementChemistryPtr a_pFirstElChem,
  1730. CElementChemistryPtr a_pSecondElChem,
  1731. BOOL& a_bMapped)
  1732. {
  1733. // safety check
  1734. ASSERT(a_pFirstElChem);
  1735. ASSERT(a_pSecondElChem);
  1736. if (a_dMolarSumNoFe < MIN_ELEMENT_SUM)
  1737. {
  1738. return FALSE;
  1739. }
  1740. if (a_dMappingRatio < MIN_DOUBLE_VALUE)
  1741. {
  1742. return FALSE;
  1743. }
  1744. // set mapped flag to FALSE as default
  1745. a_bMapped = FALSE;
  1746. // get first mapping element molar value
  1747. double dFirstMolar = a_pFirstElChem->GetMolarPercentage();
  1748. // make sure molar value of the first mapping element chemistry is enough
  1749. double dFirstMolar100 = Cal100NorValue(dFirstMolar, a_dMolarSumNoFe);
  1750. if (dFirstMolar100 > ELEMENT_MAPPING_100MOLAR)
  1751. {
  1752. // get second mapping element chemistry molar value
  1753. double dSecondElMolar = a_pSecondElChem->GetMolarPercentage();
  1754. // make sure second mapping element chemistry value is enough
  1755. double dSecondElMolar100 = Cal100NorValue(dSecondElMolar, a_dMolarSumNoFe);
  1756. if (dSecondElMolar100 > ELEMENT_MAPPING_100MOLAR)
  1757. {
  1758. // set mapped flag to true
  1759. a_bMapped = TRUE;
  1760. // reset mapping element chemistry molar values
  1761. // is there any first element left?
  1762. if (dFirstMolar - dSecondElMolar * a_dMappingRatio > 0)
  1763. {
  1764. // no more second element chemistry left;
  1765. a_pSecondElChem->SetPercentage(0.0);
  1766. // still there are some first element left
  1767. // calculate left first element molar value
  1768. dFirstMolar = dFirstMolar - (dSecondElMolar * a_dMappingRatio);
  1769. dFirstMolar100 = Cal100NorValue(dFirstMolar100, a_dMolarSumNoFe);
  1770. // is there enough first element left?
  1771. if (dFirstMolar100 > ELEMENT_MAPPING_100MOLAR)
  1772. {
  1773. // still have enough first element left
  1774. a_pFirstElChem->SetMolarPercentage(dFirstMolar);
  1775. }
  1776. else
  1777. {
  1778. // no enough enough first element left, set to 0.0
  1779. a_pFirstElChem->SetPercentage(0.0);
  1780. }
  1781. }
  1782. else
  1783. {
  1784. // no more first element chemistry left
  1785. a_pFirstElChem->SetPercentage(0.0);
  1786. // still there are some second element left
  1787. // calculate left second element molar value
  1788. dSecondElMolar = dSecondElMolar - dFirstMolar / a_dMappingRatio;
  1789. dSecondElMolar100 = Cal100NorValue(dSecondElMolar, a_dMolarSumNoFe);
  1790. // is there enough second element left?
  1791. if (dSecondElMolar100 > ELEMENT_MAPPING_100MOLAR)
  1792. {
  1793. // still have enough second element left
  1794. a_pSecondElChem->SetMolarPercentage(dSecondElMolar);
  1795. }
  1796. else
  1797. {
  1798. // no enough enough second element left, set to 0.0
  1799. a_pSecondElChem->SetPercentage(0.0);
  1800. }
  1801. }
  1802. }
  1803. }
  1804. // ok, return TRUE
  1805. return TRUE;
  1806. }
  1807. // check if is a REOxide
  1808. BOOL COTSClassifyEng::IsASimpleOxide(CElementChemistriesList& a_listElChems, double a_dMolarSum, CString& a_strSimOxName)
  1809. {
  1810. // go through oxide sub element chemistries
  1811. for (auto pOxideSubElChems : a_listElChems)
  1812. {
  1813. // calculate the %molar value of the sub element chemistry in the list
  1814. double dSubElMolar100 = Cal100NorValue(pOxideSubElChems->GetMolarPercentage(), a_dMolarSum);
  1815. // over simple oxide cut_off
  1816. if (dSubElMolar100 > SIMPLE_OXIDE_MOLAR_CUTOFF)
  1817. {
  1818. // this is a simple oxide, name it
  1819. for (int i = 0; i < INC_OXIDE_SUB_ELEMENT_MAX; ++i)
  1820. {
  1821. if (pOxideSubElChems->GetName().CompareNoCase(INC_OXIDE_SUB_ELEMENT_NAMES[i]) == 0)
  1822. {
  1823. // found it
  1824. // assign simple oxide name
  1825. a_strSimOxName = INC_OXIDE_NAMES[i];
  1826. // return TRUE
  1827. return TRUE;
  1828. }
  1829. }
  1830. }
  1831. }
  1832. // not a simple oxide, return FALSE
  1833. return FALSE;
  1834. }
  1835. // check if is a REOxide (deal with La-Ce-Oxide)
  1836. BOOL COTSClassifyEng::IsAREOxide(CElementChemistriesList& a_listElChems, double a_dMolarSum)
  1837. {
  1838. // calculate real element molar %
  1839. double dREElementMolarSum = 0;
  1840. for (int i = 0; i < REOXIDE_KEY_ELEMENT_MAX; ++i)
  1841. {
  1842. CElementChemistryPtr pREElement = GetNamedElementChemistry(a_listElChems, REOXIDE_KEY_ELEMENT_NAMES[i]);
  1843. if (pREElement)
  1844. {
  1845. // got a real element
  1846. // calculate the %molar value of the real element chemistry in the list
  1847. double dSubElMolar100 = Cal100NorValue(pREElement->GetMolarPercentage(), a_dMolarSum);
  1848. // calculate real element molar %
  1849. dREElementMolarSum += dSubElMolar100;
  1850. }
  1851. }
  1852. // is real element molar % over REAlOxide elements molar % cut_off
  1853. if (dREElementMolarSum > REALOXIDE_ELEMELTS_MOLAR_CUTOFF)
  1854. {
  1855. // this is a REAlOxide, return TRUE
  1856. return TRUE;
  1857. }
  1858. // not a REOxide, return FALSE
  1859. return FALSE;
  1860. }
  1861. // check if is a REAlOxide
  1862. BOOL COTSClassifyEng::IsAnREAlOxide(CElementChemistriesList& a_listElChems, double a_dMolarSum)
  1863. {
  1864. // calculate real element molar %
  1865. double dREElementMolarSum = 0;
  1866. for (int i = 0; i < REOXIDE_KEY_ELEMENT_MAX; ++i)
  1867. {
  1868. CElementChemistryPtr pREElement = GetNamedElementChemistry(a_listElChems, REOXIDE_KEY_ELEMENT_NAMES[i]);
  1869. if (pREElement)
  1870. {
  1871. // got a real element
  1872. // calculate the %molar value of the real element chemistry in the list
  1873. double dSubElMolar100 = Cal100NorValue(pREElement->GetMolarPercentage(), a_dMolarSum);
  1874. // calculate real element molar %
  1875. dREElementMolarSum += dSubElMolar100;
  1876. }
  1877. }
  1878. // is real element molar % over REAlOxide element molar % min cut_off
  1879. if (dREElementMolarSum < REALOXIDE_ELEMENT_MOLAR_LOW_CUTOFF)
  1880. {
  1881. // no, this is not a REALOxide, return FALSE
  1882. return FALSE;
  1883. }
  1884. // calculate Al/Si elements molar %
  1885. double dAl_Si_ElementMolarSum = 0;
  1886. for (int i = 0; i < REALOXIDE_SUB_ELEMENT_MAX; ++i)
  1887. {
  1888. CElementChemistryPtr pAlSiElement = GetNamedElementChemistry(a_listElChems, REALOXIDE_SUB_ELEMENT_NAMES[i]);
  1889. if (pAlSiElement)
  1890. {
  1891. // got a Al or Si element
  1892. // calculate the %molar value of the Al and Si element chemistry in the list
  1893. double dAl_SiElMolar100 = Cal100NorValue(pAlSiElement->GetMolarPercentage(), a_dMolarSum);
  1894. // calculate Al/Si elements molar %
  1895. dAl_Si_ElementMolarSum += dAl_SiElMolar100;
  1896. }
  1897. }
  1898. // is Al/Si elements molar % over REAlOxide element molar % min cut_off
  1899. if (dAl_Si_ElementMolarSum < REALOXIDE_ELEMENT_MOLAR_LOW_CUTOFF)
  1900. {
  1901. // no, this is not a REALOxide, return FALSE
  1902. return FALSE;
  1903. }
  1904. // is real element molar % + Al/Si elements molar % over the cut off
  1905. if (dREElementMolarSum + dAl_Si_ElementMolarSum > SIMPLE_OXIDE_MOLAR_CUTOFF)
  1906. {
  1907. // this is a REAlOxide, return TRUE
  1908. return TRUE;
  1909. }
  1910. // not a REAlOxide, return FALSE
  1911. return FALSE;
  1912. }
  1913. // check if is a Spinel
  1914. BOOL COTSClassifyEng::IsASpinel(CElementChemistriesList& a_listElChems, double a_dMolarSum)
  1915. {
  1916. // we deal with Mg, Al Spinel only
  1917. // get the first key element of Spinel
  1918. CElementChemistryPtr pFirstElChem = GetNamedElementChemistry(a_listElChems, SPINEL_KEY_ELEMENT_NAMES[0]);
  1919. if (!pFirstElChem)
  1920. {
  1921. // not a Spinel, return FALSE
  1922. return FALSE;
  1923. }
  1924. // get the second key element of Spinel
  1925. CElementChemistryPtr pSecondElChem = GetNamedElementChemistry(a_listElChems, SPINEL_KEY_ELEMENT_NAMES[1]);
  1926. if (!pSecondElChem)
  1927. {
  1928. // not a Spinel, return FALSE
  1929. return FALSE;
  1930. }
  1931. // check ratio between the two elements
  1932. double dFirstElMolar = pFirstElChem->GetMolarPercentage();
  1933. double dSecondElMolar = pSecondElChem->GetMolarPercentage();
  1934. if (dFirstElMolar < MIN_DOUBLE_VALUE)
  1935. {
  1936. // something wrong
  1937. // not a Spinel, return FALSE
  1938. return FALSE;
  1939. }
  1940. double dRatio = dSecondElMolar / dFirstElMolar;
  1941. if (dRatio < SPINEL_ELEMENT_RATIO_MIN || dRatio > SPINEL_ELEMENT_RATIO_MAX)
  1942. {
  1943. // not a Spinel, return FALSE
  1944. return FALSE;
  1945. }
  1946. // molar % amount check
  1947. double dFirstElMolar100 = Cal100NorValue(dFirstElMolar, a_dMolarSum);
  1948. double dSecondElMolar100 = Cal100NorValue(dSecondElMolar, a_dMolarSum);
  1949. if (dFirstElMolar100 + dSecondElMolar100 > SPINEL_KEY_ELEMENT_MOLAR_TOTAL)
  1950. {
  1951. // this is a Spinel
  1952. return TRUE;
  1953. }
  1954. // not a Spinel, return FALSE
  1955. return FALSE;
  1956. }
  1957. // check if is a Silicate
  1958. BOOL COTSClassifyEng::IsASilicate(CElementChemistriesList& a_listElChems, double a_dMolarSum)
  1959. {
  1960. // get key element of Silicate
  1961. CElementChemistryPtr pKeyElChem = GetNamedElementChemistry(a_listElChems, SILICATE_KEY_ELEMENT_NAME);
  1962. if (!pKeyElChem)
  1963. {
  1964. // not a Silicate, return FALSE
  1965. return FALSE;
  1966. }
  1967. // molar % amount check
  1968. double dKeyElMolar100 = Cal100NorValue(pKeyElChem->GetMolarPercentage(), a_dMolarSum);
  1969. if (dKeyElMolar100 > SILICATE_KEY_ELEMENT_MOLAR_TOTAL_MIN && dKeyElMolar100 < SILICATE_KEY_ELEMENT_MOLAR_TOTAL_MAX)
  1970. {
  1971. // this is a Silicate, return TRUE
  1972. return TRUE;
  1973. }
  1974. // not a Silicate, return FALSE
  1975. return FALSE;
  1976. }
  1977. // check if is a Aluminate
  1978. BOOL COTSClassifyEng::IsAnCa_Aluminate(STEEL_TECHNOLOGY steelTech,CElementChemistriesList& a_listElChems, double a_dMolarSum,CString& strName)
  1979. {
  1980. // get key element of Aluminate
  1981. CElementChemistryPtr pKeyElChem = GetNamedElementChemistry(a_listElChems, ALUMINATE_KEY_ELEMENT_NAME[0]);
  1982. if (!pKeyElChem)
  1983. {
  1984. // not an Aluminate, return FALSE
  1985. return FALSE;
  1986. }
  1987. // molar % amount check
  1988. double dKeyElMolar100 = Cal100NorValue(pKeyElChem->GetMolarPercentage(), a_dMolarSum);
  1989. if (dKeyElMolar100 > ALUMINAT_KEY_ELEMENT_MOLAR_TOTAL_MIN && dKeyElMolar100 < ALUMINAT_KEY_ELEMENT_MOLAR_TOTAL_MAX)
  1990. {
  1991. CElementChemistryPtr pKeyElChem2 = GetNamedElementChemistry(a_listElChems, ALUMINATE_KEY_ELEMENT_NAME[1]);
  1992. if (!pKeyElChem2|| pKeyElChem2->GetPercentage()< MIN_ELEMENT_SUM)
  1993. {
  1994. strName = ALUMINATE_STR;
  1995. return TRUE;
  1996. }
  1997. double dFirstElMolar = pKeyElChem->GetMolarPercentage();//Al
  1998. double dSecondElMolar = pKeyElChem2->GetMolarPercentage();//Ca
  1999. double dRatio = dFirstElMolar/dSecondElMolar ;// Al/Ca
  2000. if (steelTech == STEEL_TECHNOLOGY::CaProcessMode)
  2001. {
  2002. if (dRatio < 1.2 || dRatio > 1.0)//12CaO-7Al2O3 14/12
  2003. {
  2004. // not a Spinel, return FALSE
  2005. strName = ALUMINATE12CaO_7Al2O3_STR;
  2006. return TRUE;
  2007. }
  2008. if (dRatio < 0.9 || dRatio > 0.6)//3CaO-Al2O3 2/3
  2009. {
  2010. // not a Spinel, return FALSE
  2011. strName = ALUMINATE3CaO_Al2O3_STR;
  2012. return TRUE;
  2013. }
  2014. }
  2015. else
  2016. {
  2017. strName = Ca_ALUMINATE_STR;
  2018. }
  2019. // this is a Aluminate, return TRUE
  2020. return TRUE;
  2021. }
  2022. // not a Aluminate, return FALSE
  2023. return FALSE;
  2024. }
  2025. // check if the element chemistries list matching the STD
  2026. BOOL COTSClassifyEng::MatchingSTD(CElementChemistriesList& a_listElChems, CSTDItemPtr a_pSTDItem, double a_dMolarSum)
  2027. {
  2028. // safety check
  2029. ASSERT(a_pSTDItem);
  2030. if (!a_pSTDItem)
  2031. {
  2032. // something wrong
  2033. LogErrorTrace(__FILE__, __LINE__, _T("COTSClassifyEng::MatchingSTD: invalid CSTDItemPtr."));
  2034. return FALSE;
  2035. }
  2036. if (a_dMolarSum < MIN_ELEMENT_SUM)
  2037. {
  2038. // something wrong
  2039. LogErrorTrace(__FILE__, __LINE__, _T("COTSClassifyEng::MatchingSTD: invalid molar sum value."));
  2040. return FALSE;
  2041. }
  2042. // find out how many elements need for the STD
  2043. CElementRangeList& listElementRange = a_pSTDItem->GetElementRangeList();
  2044. int nElNoMin = 0;
  2045. for (auto pElmentRange : listElementRange)
  2046. {
  2047. int nStart = pElmentRange->GetRange()->GetStart();
  2048. if (nStart > 0)
  2049. {
  2050. // this element has to have
  2051. ++nElNoMin;
  2052. }
  2053. }
  2054. int nElNoMax = (int)listElementRange.size();
  2055. // a_listChemistriesElements size has to be between nElNoMin and nElNoMax
  2056. int nElementSize = (int)a_listElChems.size();
  2057. //if (nElementSize < nElNoMin || nElementSize > nElNoMax)
  2058. if (nElementSize < nElNoMin)
  2059. {
  2060. // a_listChemistriesElements size not match
  2061. return FALSE;
  2062. }
  2063. // all element chemistries have to be in listElementRange and in the range
  2064. for (auto pElChems : a_listElChems)
  2065. {
  2066. CString strElement = pElChems->GetName();
  2067. auto itr = std::find_if(listElementRange.begin(), listElementRange.end(), [strElement](CElementRangePtr& poElemenRange) { return poElemenRange->GetElement()->GetName().CompareNoCase(strElement) == 0; });
  2068. if (itr == listElementRange.end())
  2069. {
  2070. // not in the element range list, not match then
  2071. return FALSE;
  2072. }
  2073. // molar value has to be in the range
  2074. double dMolar = pElChems->GetMolarPercentage();
  2075. dMolar = Cal100NorValue(dMolar, a_dMolarSum);
  2076. if (dMolar < (double)(*itr)->GetRange()->GetStart() || dMolar >(double)(*itr)->GetRange()->GetEnd())
  2077. {
  2078. // molar value has to be in the range, not match then
  2079. return FALSE;
  2080. }
  2081. }
  2082. // the two are matching each other, return TRUE
  2083. return TRUE;
  2084. }
  2085. // calculate 100% normalize value (molar)
  2086. double COTSClassifyEng::Cal100NorValue(double a_dValue, double a_dSumValue)
  2087. {
  2088. double d100NorCalue = MIN_DOUBLE_VALUE;
  2089. // sum has a cut off
  2090. if (a_dSumValue < MIN_ELEMENT_SUM)
  2091. {
  2092. return d100NorCalue;
  2093. }
  2094. d100NorCalue = a_dValue / a_dSumValue * 100;
  2095. return d100NorCalue;
  2096. }
  2097. }