OTSClassifyEng.cpp 60 KB

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