OTSClassifyEng.cpp 60 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218
  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 notAIncId;// is not an inc but we can identify
  32. if (!IsAnValidIncXRay(a_listElementChemistries, listElChemsInc, listElChemsIncNoFe, dMolarSum, dMolarSumNoFe, incId, notAIncId))
  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) notAIncId;
  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 )
  313. {
  314. a_GrpId = IDENTIFIED_INC_GRP_ID::OXIDE;
  315. }
  316. else if ( dSMolar >= MIN_ELEMENT_SUM && dOMolar < MIN_ELEMENT_SUM)
  317. {
  318. a_GrpId = IDENTIFIED_INC_GRP_ID::SULFIDE;
  319. }
  320. else if (dOMolar >= MIN_ELEMENT_SUM && dSMolar > 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 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. if (pElChemMg)
  456. {
  457. for (auto el : a_listElChemsIncNoFe)
  458. {
  459. if (!el->GetName().CompareNoCase(INC_SUL_SUB_ELEMENT_NAMES[2]))
  460. {
  461. listChemistriesToAnalysis.push_back(el);
  462. }
  463. }
  464. }
  465. else
  466. {
  467. listChemistriesToAnalysis = a_listElChemsIncNoFe;
  468. }
  469. // try to get Ca element chemistry
  470. CElementChemistryPtr pElChemCa = GetNamedElementChemistry(a_listElChemsIncNoFe, INC_SUL_SUB_ELEMENT_NAMES[1]);
  471. if (pElChemCa)
  472. {
  473. // there Ca in the element list, map Ca & S
  474. dMappingRadio = INC_SULFILSES_MAPPING_RATIO[1];
  475. if (!ElementsMapping(a_dMolarSumNoFe, dMappingRadio, pElChemCa, pSulElChem, bProMapped))
  476. {
  477. // something is wrong
  478. LogErrorTrace(__FILE__, __LINE__, _T("COTSClassifyEng::SulClassify: failed to call ElementsMapping method."));
  479. return FALSE;
  480. }
  481. // mapping successful?
  482. if (bProMapped)
  483. {
  484. strProMappingSulName = INC_SULFILSES_NAMES[1];
  485. }
  486. }
  487. }
  488. break;
  489. // Mg process
  490. case STEEL_TECHNOLOGY::MgProcessMode:
  491. {
  492. //remove the Ca element first
  493. CElementChemistryPtr pElChemCa = GetNamedElementChemistry(a_listElChemsIncNoFe, INC_SUL_SUB_ELEMENT_NAMES[1]);
  494. if (pElChemCa)
  495. {
  496. for (auto el : a_listElChemsIncNoFe)
  497. {
  498. if (!el->GetName().CompareNoCase(INC_SUL_SUB_ELEMENT_NAMES[1]))
  499. {
  500. listChemistriesToAnalysis.push_back(el);
  501. }
  502. }
  503. }
  504. else
  505. {
  506. listChemistriesToAnalysis = a_listElChemsIncNoFe;
  507. }
  508. // try to get Mg element chemistry
  509. CElementChemistryPtr pElChemMg = GetNamedElementChemistry(a_listElChemsIncNoFe, INC_SUL_SUB_ELEMENT_NAMES[2]);
  510. if (pElChemMg)
  511. {
  512. // there Mg in the element list, map Mg & S
  513. dMappingRadio = INC_SULFILSES_MAPPING_RATIO[2];
  514. if (!ElementsMapping(a_dMolarSumNoFe, dMappingRadio, pElChemMg, pSulElChem, bProMapped))
  515. {
  516. // something is wrong
  517. LogErrorTrace(__FILE__, __LINE__, _T("COTSClassifyEng::SulClassify: failed to call ElementsMapping method."));
  518. return FALSE;
  519. }
  520. // mapping successful?
  521. if (bProMapped)
  522. {
  523. strProMappingSulName = INC_SULFILSES_NAMES[2];
  524. }
  525. }
  526. }
  527. break;
  528. // real earth elements process
  529. case STEEL_TECHNOLOGY::RareEarthMode:
  530. {
  531. listChemistriesToAnalysis = a_listElChemsIncNoFe;
  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. default:
  579. listChemistriesToAnalysis = a_listElChemsIncNoFe;
  580. break;
  581. }
  582. }
  583. // set sulfide base name
  584. CString strSulfideBaseName = _T("");
  585. if (bMnMapped && bProMapped)
  586. {
  587. // both Mn and process mapped
  588. strSulfideBaseName = INC_SULFILSES_NAMES[0] + strProMappingSulName;
  589. }
  590. else if (bMnMapped)
  591. {
  592. // Mn mapped only
  593. strSulfideBaseName = INC_SULFILSES_NAMES[0];
  594. }
  595. else if (bProMapped)
  596. {
  597. // process mapped only
  598. strSulfideBaseName = strProMappingSulName;
  599. }
  600. else
  601. {
  602. // mapped nothing
  603. // force sulfide base name as "Sulfide" if sulfur 100% molar value over cutting off value
  604. if (dSulMolar100 > SULFIDE_MOLAR_CUTOFF)
  605. {
  606. strSulfideBaseName = SULFIDE_STR;
  607. }
  608. else
  609. {
  610. // no enough sulfur, consider that it is not a sulfide
  611. return TRUE;
  612. }
  613. }
  614. // check if the rest element chemistries map an oxide
  615. int nIncId = (int)OTS_PARTICLE_TYPE::INVALID;
  616. if (!OxideClassify(a_pPartSTDData, listChemistriesToAnalysis, a_dMolarSumNoFe, nIncId))
  617. {
  618. // something wrong
  619. LogErrorTrace(__FILE__, __LINE__, _T("COTSClassifyEng::SulClassify: failed to call OxideClassify method."));
  620. return FALSE;
  621. }
  622. // mapped?
  623. if (nIncId >= (int)OTS_PARTICLE_TYPE::IDENTIFIED)
  624. {
  625. // this is an oxide sulfide
  626. // confirm the oxide sulfide id
  627. // get the STD item of the mapped oxide
  628. CSTDItemPtr pOxideSTDItem = a_pPartSTDData->GetSTDItemById(nIncId);
  629. if (pOxideSTDItem)
  630. {
  631. // get mapped oxide name
  632. CString strOxideName = pOxideSTDItem->GetName();
  633. // oxide sulfide name: oxide + "-" + sulfide base string
  634. CString strOxide_SulName = strOxideName + STR_CONNECT + strSulfideBaseName;
  635. // try to find the STD item
  636. CSTDItemPtr pOxideSulSTDItem = GetSTDItemByName(listSulfideSTD, strOxide_SulName);
  637. if (pOxideSulSTDItem)
  638. {
  639. // found the STD item
  640. a_nIncId = pOxideSulSTDItem->GetSTDId();
  641. return TRUE;
  642. }
  643. // rename the oxide sulfide name as "Oxide" + "-" + sulfide base string
  644. strOxide_SulName = OXIDE_STR + STR_CONNECT + strSulfideBaseName;
  645. // try to find the STD item
  646. pOxideSulSTDItem = GetSTDItemByName(listSulfideSTD, strOxide_SulName);
  647. if (pOxideSulSTDItem)
  648. {
  649. // found the STD item
  650. a_nIncId = pOxideSulSTDItem->GetSTDId();
  651. return TRUE;
  652. }
  653. // rename the oxide sulfide name as strOxideName + "-" + "Sulfide"
  654. strOxide_SulName = strOxideName + STR_CONNECT + SULFIDE_STR;
  655. // try to find the STD item
  656. pOxideSulSTDItem = GetSTDItemByName(listSulfideSTD, strOxide_SulName);
  657. if (pOxideSulSTDItem)
  658. {
  659. // found the STD item
  660. a_nIncId = pOxideSulSTDItem->GetSTDId();
  661. return TRUE;
  662. }
  663. // rename the oxide sulfide name as "Oxide" + "-" + "Sulfide"
  664. strOxide_SulName = OXIDE_STR + STR_CONNECT + SULFIDE_STR;
  665. // try to find the STD item
  666. pOxideSulSTDItem = GetSTDItemByName(listSulfideSTD, strOxide_SulName);
  667. if (pOxideSulSTDItem)
  668. {
  669. // found the STD item
  670. a_nIncId = pOxideSulSTDItem->GetSTDId();
  671. return TRUE;
  672. }
  673. // rename the oxide sulfide name as "Sulfide"
  674. strOxide_SulName = SULFIDE_STR;
  675. // try to find the STD item
  676. pOxideSulSTDItem = GetSTDItemByName(listSulfideSTD, strOxide_SulName);
  677. if (pOxideSulSTDItem)
  678. {
  679. // found the STD item
  680. a_nIncId = pOxideSulSTDItem->GetSTDId();
  681. return TRUE;
  682. }
  683. }
  684. // can't identify this inclusion
  685. a_nIncId = (int)OTS_PARTICLE_TYPE::NOT_IDENTIFIED;
  686. return TRUE;
  687. }
  688. // this is a general sulfide
  689. // confirm the sulfide id
  690. // try to find the STD item
  691. CSTDItemPtr pSulSTDItem = GetSTDItemByName(listSulfideSTD, strSulfideBaseName);
  692. if (pSulSTDItem)
  693. {
  694. // found the STD item
  695. a_nIncId = pSulSTDItem->GetSTDId();
  696. return TRUE;
  697. }
  698. // rename the sulfides name as "Sulfide" if it is not
  699. if (strSulfideBaseName.CompareNoCase(SULFIDE_STR) != 0)
  700. {
  701. strSulfideBaseName = SULFIDE_STR;
  702. pSulSTDItem = GetSTDItemByName(listSulfideSTD, strSulfideBaseName);
  703. if (pSulSTDItem)
  704. {
  705. // found the STD item
  706. a_nIncId = pSulSTDItem->GetSTDId();
  707. return TRUE;
  708. }
  709. }
  710. // can't identify this inclusion
  711. a_nIncId = (int)OTS_PARTICLE_TYPE::NOT_IDENTIFIED;
  712. return TRUE;
  713. }
  714. // oxides classification
  715. BOOL COTSClassifyEng::OxideClassify(CInclutionSTDDataPtr a_pPartSTDData,
  716. CElementChemistriesList& a_listElChemsIncNoFe,
  717. double a_dMolarSumNoFe,
  718. int& a_nIncId)
  719. {
  720. // safety check
  721. ASSERT(a_pPartSTDData);
  722. // get all oxides STD items
  723. CSTDItemsList listOxideSTD;
  724. if (!GetClassifySTDItem(a_pPartSTDData, INC_CLASSIFY_TYPE::OXIDE, listOxideSTD))
  725. {
  726. // something wrong
  727. LogErrorTrace(__FILE__, __LINE__, _T("COTSClassifyEng::OxideClassify: failed to call GetClassifySTDItem method."));
  728. return FALSE;
  729. }
  730. // check if element chemistries list contain any oxygen
  731. CElementChemistryPtr pOElChem = GetNamedElementChemistry(a_listElChemsIncNoFe, STR_OXIDE);
  732. if (!pOElChem)
  733. {
  734. // contains no oxygen, this is not an oxide
  735. return TRUE;
  736. }
  737. // check if oxygen amount enough
  738. double dOMolar100 = Cal100NorValue(pOElChem->GetMolarPercentage(), a_dMolarSumNoFe);
  739. if (dOMolar100 < MIN_OXIDE_MOLAR)
  740. {
  741. // no enough oxygen, this is not an oxide
  742. return TRUE;
  743. }
  744. // this is an oxide
  745. // any oxide STD items
  746. if (listOxideSTD.empty())
  747. {
  748. // no oxide STD items, can't identify oxide
  749. // can't identify this inclusion
  750. a_nIncId = (int)OTS_PARTICLE_TYPE::NOT_IDENTIFIED;
  751. return TRUE;
  752. }
  753. // build oxide sub elements list
  754. // =========================================
  755. // get all possible oxide sub element chemistries
  756. CElementChemistriesList listTempOxideSubElChems;
  757. double dTempOxideSubElMolarSum = 0;
  758. for (int i = 0; i < INC_OXIDE_SUB_ELEMENT_MAX; ++i)
  759. {
  760. // try to get the oxide sub element
  761. CElementChemistryPtr pSubElChem = GetNamedElementChemistry(a_listElChemsIncNoFe, INC_OXIDE_SUB_ELEMENT_NAMES[i]);
  762. // found it?
  763. if (pSubElChem)
  764. {
  765. // got one
  766. // get the %molar value of the sub element chemistries
  767. double dSubElMolar = pSubElChem->GetMolarPercentage();
  768. // add the sub element chemistries into the oxides element chemistries list
  769. listTempOxideSubElChems.push_back(pSubElChem);
  770. dTempOxideSubElMolarSum += dSubElMolar;
  771. }
  772. }
  773. // clear oxide sub element chemistries list
  774. CElementChemistriesList listOxideSubElChems;
  775. double dOxideSubElMolarSum = 0;
  776. for (auto pElChem : listTempOxideSubElChems)
  777. {
  778. // get the %molar value of the sub element chemistries
  779. double dSubElMolar = pElChem->GetMolarPercentage();
  780. // the %molar value of the sub element chemistries of the sub element chemistries list
  781. double dSubElMolarMolar100 = Cal100NorValue(dSubElMolar, dTempOxideSubElMolarSum);
  782. // remove the sub element chemistries less than the cut off (2%)
  783. if (dSubElMolarMolar100 > MIN_OXIDE_SUB_MOLAR_CUTOFF)
  784. {
  785. // keep it
  786. listOxideSubElChems.push_back(pElChem);
  787. dOxideSubElMolarSum += dSubElMolar;
  788. }
  789. }
  790. // =========================================
  791. // check oxide elements list
  792. CString strOxideName = _T("");
  793. CString aluminateStr=_T("");
  794. if (listOxideSubElChems.empty())
  795. {
  796. // no oxide sub elements
  797. // consider this is not a oxide (may be it just is a dust)
  798. return TRUE;
  799. }
  800. // is a simple oxide?
  801. else if(IsASimpleOxide(listOxideSubElChems, dOxideSubElMolarSum, strOxideName))
  802. {
  803. // this is a simple oxide
  804. // named already during checking
  805. }
  806. // is it a REOxide (La-Ce-Oxide)?
  807. else if (IsAREOxide(listOxideSubElChems, dOxideSubElMolarSum))
  808. {
  809. // REOxcide
  810. strOxideName = REOXIDE_STR;
  811. }
  812. // should be a complex oxide
  813. // is it a REAlOxide?
  814. else if (IsAnREAlOxide(listOxideSubElChems, dOxideSubElMolarSum))
  815. {
  816. // REOxcide
  817. strOxideName = REALOXIDE_STR;
  818. }
  819. // is it a Spinel?
  820. else if (IsASpinel(listOxideSubElChems, dOxideSubElMolarSum))
  821. {
  822. // Spinel
  823. strOxideName = SPINEL_STR;
  824. }
  825. // is it a Silicate?
  826. else if (IsASilicate(listOxideSubElChems, dOxideSubElMolarSum))
  827. {
  828. // Silicate
  829. strOxideName = SILICATE_STR;
  830. }
  831. // is it an Aluminate?
  832. else if (IsAnCa_Aluminate(listOxideSubElChems, dOxideSubElMolarSum, aluminateStr))
  833. {
  834. // Aluminate
  835. strOxideName = aluminateStr;
  836. }
  837. // fit none of them, simply name it as an oxide
  838. else
  839. {
  840. strOxideName = OXIDE_STR;
  841. }
  842. // confirm the oxide id
  843. // try to find the STD
  844. auto pSTDItem = GetSTDItemByName(listOxideSTD, strOxideName);
  845. if (pSTDItem)
  846. {
  847. // found the STD item
  848. a_nIncId = pSTDItem->GetSTDId();
  849. return TRUE;
  850. }
  851. // rename the oxide as "Oxide" if it is not
  852. if (strOxideName.CompareNoCase(OXIDE_STR) != 0)
  853. {
  854. strOxideName = OXIDE_STR;
  855. auto pSTDItem = GetSTDItemByName(listOxideSTD, strOxideName);
  856. if (pSTDItem)
  857. {
  858. // found the STD item
  859. a_nIncId = pSTDItem->GetSTDId();
  860. return TRUE;
  861. }
  862. }
  863. // can't identify this inclusion
  864. a_nIncId = (int)OTS_PARTICLE_TYPE::NOT_IDENTIFIED;
  865. return TRUE;
  866. }
  867. // nitrides classification
  868. BOOL COTSClassifyEng::NitrideClassify(CInclutionSTDDataPtr a_pPartSTDData,
  869. CElementChemistriesList& a_listElChemsIncNoFe,
  870. double a_dMolarSumNoFe,
  871. int& a_nIncId)
  872. {
  873. // safety check
  874. ASSERT(a_pPartSTDData);
  875. // get all nitride STD items
  876. CSTDItemsList listNitrideSTD;
  877. if (!GetClassifySTDItem(a_pPartSTDData, INC_CLASSIFY_TYPE::NITR, listNitrideSTD))
  878. {
  879. // something wrong
  880. LogErrorTrace(__FILE__, __LINE__, _T("COTSClassifyEng::NitrideClassify: failed to call GetClassifySTDItem method."));
  881. return FALSE;
  882. }
  883. // check if element chemistries list contain any nitrogen
  884. CElementChemistryPtr pNitrElChem = GetNamedElementChemistry(a_listElChemsIncNoFe, STR_NITR);
  885. if (!pNitrElChem)
  886. {
  887. // contains no nitrogen, this is not a nitride
  888. return TRUE;
  889. }
  890. // check if nitrogen amount enough
  891. double dNitrMolar100 = Cal100NorValue(pNitrElChem->GetMolarPercentage(), a_dMolarSumNoFe);
  892. if (dNitrMolar100 < MIN_NITR_MOLAR)
  893. {
  894. // have no enough nitrogen, this is not a nitride
  895. return TRUE;
  896. }
  897. // this is a nitride
  898. // any nitride STD items
  899. if (listNitrideSTD.empty())
  900. {
  901. // no nitrides std items.
  902. // can't identify this inclusion
  903. a_nIncId = (int)OTS_PARTICLE_TYPE::NOT_IDENTIFIED;
  904. return TRUE;
  905. }
  906. // mapping nitride sub elements
  907. CString strNitrideName = _T("");
  908. BOOL bMapped = FALSE;
  909. for (int i = 0; i < INC_NITR_SUB_ELEMENT_MAX; ++i)
  910. {
  911. CElementChemistryPtr pNitrSubElChem = GetNamedElementChemistry(a_listElChemsIncNoFe, INC_NITR_SUB_ELEMENT_NAMES[i]);
  912. if (pNitrSubElChem)
  913. {
  914. // this is a nitride sub element chemistry
  915. // get %molar value of this sub element chemistry
  916. double dNitr_Sub_Molar = Cal100NorValue(pNitrSubElChem->GetMolarPercentage(), a_dMolarSumNoFe);
  917. // make sure the sub element molar value is over mapping min value
  918. if (dNitr_Sub_Molar > MIN_NITR_SUB_MOLAR)
  919. {
  920. // mapping this sub element chemistry
  921. double dMappingRadio = INC_NITR_MAPPING_RATIO[i];
  922. if (!ElementsMapping(a_dMolarSumNoFe, dMappingRadio, pNitrSubElChem, pNitrElChem, bMapped))
  923. {
  924. // something is wrong
  925. LogErrorTrace(__FILE__, __LINE__, _T("COTSClassifyEng::NitrideClassify: failed to call ElementsMapping method."));
  926. return FALSE;
  927. }
  928. // mapping succeed?
  929. if(bMapped)
  930. {
  931. // is mapped Ti?
  932. if (i == 0)
  933. {
  934. // the first mapped nitride is "TiN"
  935. // try to map Nb
  936. BOOL bNbMapped = FALSE;
  937. // get molar % of the rest nitrogen
  938. dNitrMolar100 = Cal100NorValue(pNitrElChem->GetMolarPercentage(), a_dMolarSumNoFe);
  939. // make sure nitrogen amount is enough
  940. if (dNitrMolar100 > MIN_NITR_MOLAR)
  941. {
  942. // get element "Nb"
  943. CElementChemistryPtr pElChemNb = GetNamedElementChemistry(a_listElChemsIncNoFe, STR_Nb);
  944. // is there Nb in the list
  945. if (pElChemNb)
  946. {
  947. // get %molar value of Nb
  948. double dNb_Molar = Cal100NorValue(pElChemNb->GetMolarPercentage(), a_dMolarSumNoFe);
  949. // make sure Nb molar value is over mapping min value
  950. double dNbMappingRadio = INC_NITR_MAPPING_RATIO[2];
  951. if (dNb_Molar > MIN_NITR_SUB_MOLAR)
  952. {
  953. if (!ElementsMapping(a_dMolarSumNoFe, dNbMappingRadio, pElChemNb, pNitrElChem, bNbMapped))
  954. {
  955. // something is wrong
  956. LogErrorTrace(__FILE__, __LINE__, _T("COTSClassifyEng::NitrideClassify: failed to call ElementsMapping method."));
  957. return FALSE;
  958. }
  959. }
  960. }
  961. }
  962. // mapped "Nb"
  963. if (bNbMapped)
  964. {
  965. // nitride name is "TiN-NbN"
  966. strNitrideName = INC_NITR_NAMES[0] + STR_CONNECT + INC_NITR_NAMES[2];
  967. }
  968. else
  969. {
  970. // nitride name is "TiN"
  971. strNitrideName = INC_NITR_NAMES[0];
  972. }
  973. }
  974. else
  975. {
  976. // get the nitride name
  977. strNitrideName = INC_NITR_NAMES[i];
  978. }
  979. // completed mapping, get out the loop
  980. break;
  981. }
  982. }
  983. }
  984. }
  985. // not mapped?
  986. if (!bMapped)
  987. {
  988. // force to name it as "Nitride" if N 100% molar value over cutting off value
  989. if (dNitrMolar100 > NITRIDE_MOLAR_CUTOFF)
  990. {
  991. strNitrideName = NITRIDE_STR;
  992. }
  993. else
  994. {
  995. // no enough nitride, consider that it is not a nitride
  996. return TRUE;
  997. }
  998. }
  999. // check if the rest element chemistries map an oxide
  1000. int nIncId = (int)OTS_PARTICLE_TYPE::INVALID;
  1001. if (!OxideClassify(a_pPartSTDData, a_listElChemsIncNoFe, a_dMolarSumNoFe, nIncId))
  1002. {
  1003. // something wrong
  1004. LogErrorTrace(__FILE__, __LINE__, _T("COTSClassifyEng::NitrideClassify: failed to call OxideClassify method."));
  1005. return FALSE;
  1006. }
  1007. // mapped?
  1008. if (nIncId >= (int)OTS_PARTICLE_TYPE::IDENTIFIED)
  1009. {
  1010. // this is an oxide nitride
  1011. // confirm the oxide nitride id
  1012. // get the STD item of the mapped oxide
  1013. CSTDItemPtr pOxideSTDItem = a_pPartSTDData->GetSTDItemById(nIncId);
  1014. if (pOxideSTDItem)
  1015. {
  1016. // get mapped oxide name
  1017. CString strOxideName = pOxideSTDItem->GetName();
  1018. // oxide nitride name: oxide + "-" + nitride base string
  1019. CString strOxide_NitrName = strOxideName + STR_CONNECT + strNitrideName;
  1020. // try to find the STD item
  1021. CSTDItemPtr pOxideNitrSTDItem = GetSTDItemByName(listNitrideSTD, strOxide_NitrName);
  1022. if (pOxideNitrSTDItem)
  1023. {
  1024. // found the STD item
  1025. a_nIncId = pOxideNitrSTDItem->GetSTDId();
  1026. return TRUE;
  1027. }
  1028. // can't find the STD item
  1029. // rename the oxide nitride name as "Oxide" + "-" + nitride base string
  1030. strOxide_NitrName = OXIDE_STR + STR_CONNECT + strOxide_NitrName;
  1031. // try to find the STD item
  1032. pOxideNitrSTDItem = GetSTDItemByName(listNitrideSTD, strOxide_NitrName);
  1033. if (pOxideNitrSTDItem)
  1034. {
  1035. // found the STD item
  1036. a_nIncId = pOxideNitrSTDItem->GetSTDId();
  1037. return TRUE;
  1038. }
  1039. // rename the oxide nitride name as strOxideName + "-" + "Nitride"
  1040. strOxide_NitrName = strOxideName + STR_CONNECT + NITRIDE_STR;
  1041. // try to find the STD item
  1042. pOxideNitrSTDItem = GetSTDItemByName(listNitrideSTD, strOxide_NitrName);
  1043. if (strOxide_NitrName)
  1044. {
  1045. // found the STD item
  1046. a_nIncId = pOxideNitrSTDItem->GetSTDId();
  1047. return TRUE;
  1048. }
  1049. // rename the oxide nitride name as "Oxide" + "-" + "Nitride"
  1050. strOxide_NitrName = OXIDE_STR + STR_CONNECT + NITRIDE_STR;
  1051. // try to find the STD item
  1052. pOxideNitrSTDItem = GetSTDItemByName(listNitrideSTD, strOxide_NitrName);
  1053. if (pOxideNitrSTDItem)
  1054. {
  1055. // found the STD item
  1056. a_nIncId = pOxideNitrSTDItem->GetSTDId();
  1057. return TRUE;
  1058. }
  1059. // rename the oxide nitride name as "Nitride"
  1060. strOxide_NitrName = NITRIDE_STR;
  1061. // try to find the STD item
  1062. pOxideNitrSTDItem = GetSTDItemByName(listNitrideSTD, strOxide_NitrName);
  1063. if (pOxideNitrSTDItem)
  1064. {
  1065. // found the STD item
  1066. a_nIncId = pOxideSTDItem->GetSTDId();
  1067. return TRUE;
  1068. }
  1069. }
  1070. // can't identify this inclusion
  1071. a_nIncId = (int)OTS_PARTICLE_TYPE::NOT_IDENTIFIED;
  1072. return TRUE;
  1073. }
  1074. // confirm the nitride id
  1075. // try to find the STD
  1076. auto pSTDItem = GetSTDItemByName(listNitrideSTD, strNitrideName);
  1077. if (pSTDItem)
  1078. {
  1079. // found the STD item
  1080. a_nIncId = pSTDItem->GetSTDId();
  1081. return TRUE;
  1082. }
  1083. // rename the nitride as "Nitride" if it is not
  1084. if (strNitrideName.CompareNoCase(NITRIDE_STR) != 0)
  1085. {
  1086. strNitrideName = NITRIDE_STR;
  1087. auto pSTDItem = GetSTDItemByName(listNitrideSTD, strNitrideName);
  1088. if (pSTDItem)
  1089. {
  1090. // found the STD item
  1091. a_nIncId = pSTDItem->GetSTDId();
  1092. return TRUE;
  1093. }
  1094. }
  1095. // can't identify this inclusion
  1096. a_nIncId = (int)OTS_PARTICLE_TYPE::NOT_IDENTIFIED;
  1097. return TRUE;
  1098. }
  1099. // nitrides classification
  1100. BOOL COTSClassifyEng::CarbonClassify(CInclutionSTDDataPtr a_pPartSTDData,
  1101. CElementChemistriesList& a_listElChemsIncNoFe,
  1102. double a_dMolarSumNoFe,
  1103. int& a_nIncId)
  1104. {
  1105. // safety check
  1106. ASSERT(a_pPartSTDData);
  1107. // get all nitride STD items
  1108. CSTDItemsList listCarbonSTD;
  1109. if (!GetClassifySTDItem(a_pPartSTDData, INC_CLASSIFY_TYPE::CARBON, listCarbonSTD))
  1110. {
  1111. // something wrong
  1112. LogErrorTrace(__FILE__, __LINE__, _T("CClassifyEng::NitrideClassify: failed to call GetClassifySTDItem method."));
  1113. return FALSE;
  1114. }
  1115. // check if element chemistries list contain any nitrogen
  1116. CElementChemistryPtr pCarElChem = GetNamedElementChemistry(a_listElChemsIncNoFe, STR_CAR);
  1117. if (!pCarElChem)
  1118. {
  1119. // contains no nitrogen, this is not a nitride
  1120. return TRUE;
  1121. }
  1122. // check if nitrogen amount enough
  1123. double dCarMolar100 = Cal100NorValue(pCarElChem->GetMolarPercentage(), a_dMolarSumNoFe);
  1124. if (dCarMolar100 < MIN_CAR_MOLAR)
  1125. {
  1126. // have no enough nitrogen, this is not a nitride
  1127. return TRUE;
  1128. }
  1129. // this is a carbon
  1130. // any carbon STD items
  1131. if (listCarbonSTD.empty())
  1132. {
  1133. // no nitrides std items.
  1134. // can't identify this inclusion
  1135. a_nIncId = (int)OTS_PARTICLE_TYPE::NOT_IDENTIFIED;
  1136. return TRUE;
  1137. }
  1138. // mapping carbon sub elements
  1139. CString strCarbonName = _T("");
  1140. BOOL bMapped = FALSE;
  1141. for (int i = 0; i < INC_CAR_SUB_ELEMENT_MAX; ++i)
  1142. {
  1143. CElementChemistryPtr pCarSubElChem = GetNamedElementChemistry(a_listElChemsIncNoFe, INC_CAR_SUB_ELEMENT_NAMES[i]);
  1144. if (pCarSubElChem)
  1145. {
  1146. // this is a nitride sub element chemistry
  1147. // get %molar value of this sub element chemistry
  1148. double dCar_Sub_Molar = Cal100NorValue(pCarSubElChem->GetMolarPercentage(), a_dMolarSumNoFe);
  1149. // make sure the sub element molar value is over mapping min value
  1150. if (dCar_Sub_Molar > MIN_CAR_SUB_MOLAR)
  1151. {
  1152. // try to map Nb
  1153. BOOL bNbMapped = FALSE;
  1154. // get molar % of the rest nitrogen
  1155. dCarMolar100 = Cal100NorValue(pCarElChem->GetMolarPercentage(), a_dMolarSumNoFe);
  1156. // make sure nitrogen amount is enough
  1157. if (dCarMolar100 > MIN_CAR_MOLAR)
  1158. {
  1159. // get element "Nb"
  1160. CElementChemistryPtr pElChemNb = GetNamedElementChemistry(a_listElChemsIncNoFe, STR_Nb);
  1161. // is there Nb in the list
  1162. if (pElChemNb)
  1163. {
  1164. // get %molar value of Nb
  1165. double dNb_Molar = Cal100NorValue(pElChemNb->GetMolarPercentage(), a_dMolarSumNoFe);
  1166. // make sure Nb molar value is over mapping min value
  1167. double dNbMappingRatio = INC_NITR_MAPPING_RATIO[2];
  1168. if (dNb_Molar > MIN_CAR_SUB_MOLAR)
  1169. {
  1170. if (!ElementsMapping(a_dMolarSumNoFe, dNbMappingRatio, pElChemNb, pCarElChem, bNbMapped))
  1171. {
  1172. // something is wrong
  1173. LogErrorTrace(__FILE__, __LINE__, _T("CClassifyEng::NitrideClassify: failed to call ElementsMapping method."));
  1174. return FALSE;
  1175. }
  1176. }
  1177. }
  1178. }
  1179. // mapped "Nb"
  1180. if (bNbMapped)
  1181. {
  1182. // carbon name is "NbC"
  1183. strCarbonName = INC_CAR_NAMES[0];
  1184. }
  1185. // completed mapping, get out the loop
  1186. break;
  1187. }
  1188. }
  1189. }
  1190. // mapped?
  1191. if (a_nIncId >= (int)OTS_PARTICLE_TYPE::IDENTIFIED)
  1192. {
  1193. // this is an oxide nitride
  1194. // confirm the oxide nitride id
  1195. CSTDItemPtr pCarSTDItem = GetSTDItemByName(listCarbonSTD, strCarbonName);
  1196. // get the STD item of the mapped oxide
  1197. if (pCarSTDItem)
  1198. {
  1199. // found the STD item
  1200. a_nIncId = pCarSTDItem->GetSTDId();
  1201. return TRUE;
  1202. }
  1203. // can't identify this inclusion
  1204. a_nIncId = (int)OTS_PARTICLE_TYPE::NOT_IDENTIFIED;
  1205. return TRUE;
  1206. }
  1207. // confirm the carben id
  1208. // try to find the STD
  1209. auto pSTDItem = GetSTDItemByName(listCarbonSTD, strCarbonName);
  1210. if (pSTDItem)
  1211. {
  1212. // found the STD item
  1213. a_nIncId = pSTDItem->GetSTDId();
  1214. return TRUE;
  1215. }
  1216. // rename the Carbon as "Carbon" if it is not
  1217. if (strCarbonName.CompareNoCase(CARBON_STR) != 0)
  1218. {
  1219. strCarbonName = NITRIDE_STR;
  1220. auto pSTDItem = GetSTDItemByName(listCarbonSTD, strCarbonName);
  1221. if (pSTDItem)
  1222. {
  1223. // found the STD item
  1224. a_nIncId = pSTDItem->GetSTDId();
  1225. return TRUE;
  1226. }
  1227. }
  1228. // can't identify this inclusion
  1229. a_nIncId = (int)OTS_PARTICLE_TYPE::NOT_IDENTIFIED;
  1230. return TRUE;
  1231. }
  1232. // user STD items classification
  1233. BOOL COTSClassifyEng::UserClassify(CInclutionSTDDataPtr a_pPartSTDData,
  1234. CElementChemistriesList& a_listEltChemsInc,
  1235. double dSum,
  1236. int& a_nIncId)
  1237. {
  1238. // safety check
  1239. ASSERT(a_pPartSTDData);
  1240. // get user STD items
  1241. CSTDItemsList listUserSTD;
  1242. if (!GetClassifySTDItem(a_pPartSTDData, INC_CLASSIFY_TYPE::USER, listUserSTD))
  1243. {
  1244. // something wrong
  1245. LogErrorTrace(__FILE__, __LINE__, _T("COTSClassifyEng::OxideClassify: failed to call GetClassifySTDItem method."));
  1246. return FALSE;
  1247. }
  1248. // try to identify the oxide
  1249. for (auto pUserSTD : listUserSTD)
  1250. {
  1251. // matching STD?
  1252. if (MatchingSTD(a_listEltChemsInc, pUserSTD, dSum))
  1253. {
  1254. // found matching STD
  1255. a_nIncId = pUserSTD->GetSTDId();
  1256. return TRUE;
  1257. }
  1258. }
  1259. // can't identify this inclusion
  1260. a_nIncId = (int)OTS_PARTICLE_TYPE::NOT_IDENTIFIED;
  1261. return TRUE;
  1262. }
  1263. // nominate element chemistries list
  1264. BOOL COTSClassifyEng::NomiNateElChemsList( CElementChemistriesList& a_listElChemsInc,
  1265. CElementChemistriesList& a_listNomiElChemsInc)
  1266. {
  1267. // return FALSE if nothing in the input list
  1268. if (a_listElChemsInc.empty())
  1269. {
  1270. LogErrorTrace(__FILE__, __LINE__, _T("COTSClassifyEng::NomiNateElChemsList: invalid inclusion x-ray data."));
  1271. return FALSE;
  1272. }
  1273. // initialize outputs
  1274. a_listNomiElChemsInc.clear();
  1275. // go thought all element chemistry objects of the input lit
  1276. double dWeightPerSum = 0;
  1277. for (auto pElChem : a_listElChemsInc)
  1278. {
  1279. // create a new element chemistry
  1280. CElementChemistryPtr pElChemNew = CElementChemistryPtr(new CElementChemistry(*pElChem.get()));
  1281. // key element?
  1282. if (IsKeyElement(pElChem))
  1283. {
  1284. // this is a key element
  1285. // cal weight percentage sum
  1286. dWeightPerSum += pElChem->GetPercentage();
  1287. // add the element into the output list
  1288. a_listNomiElChemsInc.push_back(pElChemNew);
  1289. }
  1290. // sub element?
  1291. else if (IsSubElement(pElChem))
  1292. {
  1293. // this is a sub element
  1294. // Fe?
  1295. if (pElChem->GetName().CompareNoCase("Fe") != 0)
  1296. {
  1297. // cal weight percentage sum
  1298. dWeightPerSum += pElChem->GetPercentage();
  1299. // add the element into the output list
  1300. a_listNomiElChemsInc.push_back(pElChemNew);
  1301. }
  1302. }
  1303. }
  1304. // return FALSE if nothing in the input list or sum less than cut off value
  1305. if (a_listNomiElChemsInc.empty() || dWeightPerSum < INC_SUB_ELEMENT_CUT_OFF)
  1306. {
  1307. // something wrong
  1308. LogErrorTrace(__FILE__, __LINE__, _T("COTSClassifyEng::NomiNateElChemsList: invalid inclusion x-ray data."));
  1309. return FALSE;
  1310. }
  1311. // go thought all element chemistry objects of the output lit
  1312. for (auto pElChem : a_listNomiElChemsInc)
  1313. {
  1314. // reset weight % value
  1315. // get weight % value
  1316. double dWeightPer = pElChem->GetPercentage();
  1317. // calculate new weight % value
  1318. double dWeightPerNew = Cal100NorValue(dWeightPer, dWeightPerSum);
  1319. // reset
  1320. pElChem->SetPercentage(dWeightPerNew);
  1321. }
  1322. // ok, return TRUE
  1323. return TRUE;
  1324. }
  1325. // protected
  1326. // check if this is a key element
  1327. BOOL COTSClassifyEng::IsKeyElement(CElementChemistryPtr a_pElChem)
  1328. {
  1329. // safety check
  1330. ASSERT(a_pElChem);
  1331. if (!a_pElChem)
  1332. {
  1333. // something wrong
  1334. LogErrorTrace(__FILE__, __LINE__, _T("COTSClassifyEng::IsKeyElement: invalid CElementChemistryPtr."));
  1335. return FALSE;
  1336. }
  1337. // go thought all key element
  1338. for (long i = 0; i < INC_KEY_ELEMENT_MAX; ++i)
  1339. {
  1340. // compare
  1341. if ((a_pElChem->GetName().CompareNoCase(INC_KEY_ELEMENT_NAMES[i]) == 0) && (a_pElChem->GetPercentage() >= INC_KEY_ELEMENT_CUT_OFF))
  1342. {
  1343. // this is a key element, return TRUE
  1344. return TRUE;
  1345. }
  1346. }
  1347. // this is not a key element, return FALSE
  1348. return FALSE;
  1349. }
  1350. // check if this is a sub element
  1351. BOOL COTSClassifyEng::IsSubElement(CElementChemistryPtr a_pElChem)
  1352. {
  1353. // safety check
  1354. ASSERT(a_pElChem);
  1355. if (!a_pElChem)
  1356. {
  1357. // something wrong
  1358. LogErrorTrace(__FILE__, __LINE__, _T("COTSClassifyEng::IsSubElement: invalid CElementChemistryPtr."));
  1359. return FALSE;
  1360. }
  1361. // go thought all sub element
  1362. for (long i = 0; i < INC_SUB_ELEMENT_MAX; ++i)
  1363. {
  1364. // compare
  1365. if ((a_pElChem->GetName().CompareNoCase(INC_SUB_ELEMENT_NAMES[i]) == 0) && (a_pElChem->GetPercentage() >= INC_SUB_ELEMENT_CUT_OFF))
  1366. {
  1367. // this is a key element, return TRUE
  1368. return TRUE;
  1369. }
  1370. }
  1371. // this is not a key element, return FALSE
  1372. return FALSE;
  1373. }
  1374. // get named element chemistry
  1375. CElementChemistryPtr COTSClassifyEng::GetNamedElementChemistry(CElementChemistriesList & a_listChemistriesElements, const CString a_strElementName)
  1376. {
  1377. CElementChemistryPtr pElChem = nullptr;
  1378. CString strName = a_strElementName;
  1379. auto itr = std::find_if(a_listChemistriesElements.begin(), a_listChemistriesElements.end(), [strName](CElementChemistryPtr& poElementChemistry) { return poElementChemistry->GetName().CompareNoCase(strName) == 0; });
  1380. if (itr != a_listChemistriesElements.end())
  1381. {
  1382. pElChem = *itr;
  1383. }
  1384. return pElChem;
  1385. }
  1386. bool SortBySTDID(const std::shared_ptr< CSTDItem> &v1, const std::shared_ptr< CSTDItem> &v2)
  1387. {
  1388. return v1->GetSTDId() < v2->GetSTDId();
  1389. }
  1390. // get classify STD items
  1391. BOOL COTSClassifyEng::GetClassifySTDItem(CInclutionSTDDataPtr a_pPartSTDDataPtr, INC_CLASSIFY_TYPE a_nClassifyType, CSTDItemsList& a_listSTDItems)
  1392. {
  1393. // safety check
  1394. ASSERT(a_pPartSTDDataPtr);
  1395. if (!a_pPartSTDDataPtr)
  1396. {
  1397. // something wrong
  1398. LogErrorTrace(__FILE__, __LINE__, _T("COTSClassifyEng::GetClassifySTDItem: invalid CPartSTDDataPtr."));
  1399. return FALSE;
  1400. }
  1401. // cal STD item id value range
  1402. OTS_STD_ITEM_VALUE nSTDIdRangeMin = OTS_STD_ITEM_VALUE::INVALID;
  1403. OTS_STD_ITEM_VALUE nSTDIdRangeMax = OTS_STD_ITEM_VALUE::INVALID;
  1404. switch (a_nClassifyType)
  1405. {
  1406. case INC_CLASSIFY_TYPE::SIMPLE_OXIDE:
  1407. {
  1408. nSTDIdRangeMin = OTS_STD_ITEM_VALUE::SYS_SIMPLE_OXIDE_MIN;
  1409. nSTDIdRangeMax = OTS_STD_ITEM_VALUE::SYS_SIMPLE_OXIDE_MAX;
  1410. }
  1411. break;
  1412. case INC_CLASSIFY_TYPE::COMPLEX_OXIDE:
  1413. {
  1414. nSTDIdRangeMin = OTS_STD_ITEM_VALUE::SYS_COMPLEX_OXIDE_MIN;
  1415. nSTDIdRangeMax = OTS_STD_ITEM_VALUE::SYS_COMPLEX_OXIDE_MAX;
  1416. }
  1417. break;
  1418. case INC_CLASSIFY_TYPE::OXIDE:
  1419. {
  1420. nSTDIdRangeMin = OTS_STD_ITEM_VALUE::SYS_OXIDE_MIN;
  1421. nSTDIdRangeMax = OTS_STD_ITEM_VALUE::SYS_OXIDE_MAX;
  1422. }
  1423. break;
  1424. case INC_CLASSIFY_TYPE::SUL:
  1425. {
  1426. nSTDIdRangeMin = OTS_STD_ITEM_VALUE::SYS_SUL_MIN;
  1427. nSTDIdRangeMax = OTS_STD_ITEM_VALUE::SYS_SUL_MAX;
  1428. }
  1429. break;
  1430. case INC_CLASSIFY_TYPE::NITR:
  1431. {
  1432. nSTDIdRangeMin = OTS_STD_ITEM_VALUE::SYS_NITRIDE_MIN;
  1433. nSTDIdRangeMax = OTS_STD_ITEM_VALUE::SYS_NITRIDE_MAX;
  1434. }
  1435. break;
  1436. case INC_CLASSIFY_TYPE::CARBON:
  1437. {
  1438. nSTDIdRangeMin = OTS_STD_ITEM_VALUE::SYS_CARBON_MIN;
  1439. nSTDIdRangeMax = OTS_STD_ITEM_VALUE::SYS_CARBON_MAX;
  1440. }
  1441. break;
  1442. case INC_CLASSIFY_TYPE::USER:
  1443. {
  1444. nSTDIdRangeMin = OTS_STD_ITEM_VALUE::USER_MIN;
  1445. nSTDIdRangeMax = OTS_STD_ITEM_VALUE::USER_MAX;
  1446. }
  1447. break;
  1448. default:
  1449. {
  1450. // wrong classify type value, return FALSE
  1451. return FALSE;
  1452. }
  1453. break;
  1454. }
  1455. // go through all STD items
  1456. a_listSTDItems.clear();
  1457. for (auto pSTDItem : a_pPartSTDDataPtr->GetSTDItemsList())
  1458. {
  1459. // is matching STD item?
  1460. if (pSTDItem->GetSTDId() >= (int)nSTDIdRangeMin && pSTDItem->GetSTDId() <= (int)nSTDIdRangeMax)
  1461. {
  1462. // get matching STD item
  1463. a_listSTDItems.push_back(pSTDItem);
  1464. }
  1465. }
  1466. // sort std item by std id
  1467. sort(a_listSTDItems.begin(), a_listSTDItems.end(), SortBySTDID);
  1468. // ok, return TRUE
  1469. return TRUE;
  1470. }
  1471. // get STD item by name
  1472. CSTDItemPtr COTSClassifyEng::GetSTDItemByName(CSTDItemsList& a_listSTDItems, CString a_strName)
  1473. {
  1474. CSTDItemPtr pSTDItem = nullptr;
  1475. auto itr = std::find_if(a_listSTDItems.begin(), a_listSTDItems.end(), [a_strName](CSTDItemPtr& pSTD) { return pSTD->GetName().CompareNoCase(a_strName) == 0; });
  1476. if (itr != a_listSTDItems.end())
  1477. {
  1478. // found the STD item
  1479. pSTDItem = *itr;
  1480. }
  1481. return pSTDItem;
  1482. }
  1483. // get STD item name by id
  1484. CString COTSClassifyEng::GetSTDItemNameById(CSTDItemsList& a_listSTDItems, int a_nItemId)
  1485. {
  1486. CString strName = _T("");
  1487. CSTDItemPtr pSTDItem = nullptr;
  1488. auto itr = std::find_if(a_listSTDItems.begin(), a_listSTDItems.end(), [a_nItemId](CSTDItemPtr& pSTD) { return pSTD->GetSTDId() == a_nItemId; });
  1489. if (itr != a_listSTDItems.end())
  1490. {
  1491. // found the STD item
  1492. pSTDItem = *itr;
  1493. strName = pSTDItem->GetName();
  1494. }
  1495. return strName;
  1496. }
  1497. // elements mapping
  1498. BOOL COTSClassifyEng::ElementsMapping(double a_dMolarSumNoFe,
  1499. double a_dMappingRatio,
  1500. CElementChemistryPtr a_pFirstElChem,
  1501. CElementChemistryPtr a_pSecondElChem,
  1502. BOOL& a_bMapped)
  1503. {
  1504. // safety check
  1505. ASSERT(a_pFirstElChem);
  1506. if (!a_pFirstElChem)
  1507. {
  1508. // something wrong
  1509. LogErrorTrace(__FILE__, __LINE__, _T("COTSClassifyEng::ElementsMapping: invalid a_pFirstElChem."));
  1510. return FALSE;
  1511. }
  1512. ASSERT(a_pSecondElChem);
  1513. if (!a_pSecondElChem)
  1514. {
  1515. // something wrong
  1516. LogErrorTrace(__FILE__, __LINE__, _T("COTSClassifyEng::ElementsMapping: invalid a_pSecondElChem."));
  1517. return FALSE;
  1518. }
  1519. if (a_dMolarSumNoFe < MIN_ELEMENT_SUM)
  1520. {
  1521. // something wrong
  1522. LogErrorTrace(__FILE__, __LINE__, _T("COTSClassifyEng::ElementsMapping: invalid molar sum value."));
  1523. return FALSE;
  1524. }
  1525. if (a_dMappingRatio < MIN_DOUBLE_VALUE)
  1526. {
  1527. // something wrong
  1528. LogErrorTrace(__FILE__, __LINE__, _T("COTSClassifyEng::ElementsMapping: invalid mapping radio value."));
  1529. return FALSE;
  1530. }
  1531. // set mapped flag to FALSE as default
  1532. a_bMapped = FALSE;
  1533. // get first mapping element molar value
  1534. double dFirstMolar = a_pFirstElChem->GetMolarPercentage();
  1535. // make sure molar value of the first mapping element chemistry is enough
  1536. double dFirstMolar100 = Cal100NorValue(dFirstMolar, a_dMolarSumNoFe);
  1537. if (dFirstMolar100 > ELEMENT_MAPPING_100MOLAR)
  1538. {
  1539. // get second mapping element chemistry molar value
  1540. double dSecondElMolar = a_pSecondElChem->GetMolarPercentage();
  1541. // make sure second mapping element chemistry value is enough
  1542. double dSecondElMolar100 = Cal100NorValue(dSecondElMolar, a_dMolarSumNoFe);
  1543. if (dSecondElMolar100 > ELEMENT_MAPPING_100MOLAR)
  1544. {
  1545. // set mapped flag to true
  1546. a_bMapped = TRUE;
  1547. // reset mapping element chemistry molar values
  1548. // is there any first element left?
  1549. if (dFirstMolar - dSecondElMolar * a_dMappingRatio > 0)
  1550. {
  1551. // no more second element chemistry left;
  1552. a_pSecondElChem->SetPercentage(0.0);
  1553. // still there are some first element left
  1554. // calculate left first element molar value
  1555. dFirstMolar = dFirstMolar - (dSecondElMolar * a_dMappingRatio);
  1556. dFirstMolar100 = Cal100NorValue(dFirstMolar100, a_dMolarSumNoFe);
  1557. // is there enough first element left?
  1558. if (dFirstMolar100 > ELEMENT_MAPPING_100MOLAR)
  1559. {
  1560. // still have enough first element left
  1561. a_pFirstElChem->SetMolarPercentage(dFirstMolar);
  1562. }
  1563. else
  1564. {
  1565. // no enough enough first element left, set to 0.0
  1566. a_pFirstElChem->SetPercentage(0.0);
  1567. }
  1568. }
  1569. else
  1570. {
  1571. // no more first element chemistry left
  1572. a_pFirstElChem->SetPercentage(0.0);
  1573. // still there are some second element left
  1574. // calculate left second element molar value
  1575. dSecondElMolar = dSecondElMolar - dFirstMolar / a_dMappingRatio;
  1576. dSecondElMolar100 = Cal100NorValue(dSecondElMolar, a_dMolarSumNoFe);
  1577. // is there enough second element left?
  1578. if (dSecondElMolar100 > ELEMENT_MAPPING_100MOLAR)
  1579. {
  1580. // still have enough second element left
  1581. a_pSecondElChem->SetMolarPercentage(dSecondElMolar);
  1582. }
  1583. else
  1584. {
  1585. // no enough enough second element left, set to 0.0
  1586. a_pSecondElChem->SetPercentage(0.0);
  1587. }
  1588. }
  1589. }
  1590. }
  1591. // ok, return TRUE
  1592. return TRUE;
  1593. }
  1594. // check if is a REOxide
  1595. BOOL COTSClassifyEng::IsASimpleOxide(CElementChemistriesList& a_listElChems, double a_dMolarSum, CString& a_strSimOxName)
  1596. {
  1597. // go through oxide sub element chemistries
  1598. for (auto pOxideSubElChems : a_listElChems)
  1599. {
  1600. // calculate the %molar value of the sub element chemistry in the list
  1601. double dSubElMolar100 = Cal100NorValue(pOxideSubElChems->GetMolarPercentage(), a_dMolarSum);
  1602. // over simple oxide cut_off
  1603. if (dSubElMolar100 > SIMPLE_OXIDE_MOLAR_CUTOFF)
  1604. {
  1605. // this is a simple oxide, name it
  1606. for (int i = 0; i < INC_OXIDE_SUB_ELEMENT_MAX; ++i)
  1607. {
  1608. if (pOxideSubElChems->GetName().CompareNoCase(INC_OXIDE_SUB_ELEMENT_NAMES[i]) == 0)
  1609. {
  1610. // found it
  1611. // assign simple oxide name
  1612. a_strSimOxName = INC_OXIDE_NAMES[i];
  1613. // return TRUE
  1614. return TRUE;
  1615. }
  1616. }
  1617. }
  1618. }
  1619. // not a simple oxide, return FALSE
  1620. return FALSE;
  1621. }
  1622. // check if is a REOxide (deal with La-Ce-Oxide)
  1623. BOOL COTSClassifyEng::IsAREOxide(CElementChemistriesList& a_listElChems, double a_dMolarSum)
  1624. {
  1625. // calculate real element molar %
  1626. double dREElementMolarSum = 0;
  1627. for (int i = 0; i < REOXIDE_KEY_ELEMENT_MAX; ++i)
  1628. {
  1629. CElementChemistryPtr pREElement = GetNamedElementChemistry(a_listElChems, REOXIDE_KEY_ELEMENT_NAMES[i]);
  1630. if (pREElement)
  1631. {
  1632. // got a real element
  1633. // calculate the %molar value of the real element chemistry in the list
  1634. double dSubElMolar100 = Cal100NorValue(pREElement->GetMolarPercentage(), a_dMolarSum);
  1635. // calculate real element molar %
  1636. dREElementMolarSum += dSubElMolar100;
  1637. }
  1638. }
  1639. // is real element molar % over REAlOxide elements molar % cut_off
  1640. if (dREElementMolarSum > REALOXIDE_ELEMELTS_MOLAR_CUTOFF)
  1641. {
  1642. // this is a REAlOxide, return TRUE
  1643. return TRUE;
  1644. }
  1645. // not a REOxide, return FALSE
  1646. return FALSE;
  1647. }
  1648. // check if is a REAlOxide
  1649. BOOL COTSClassifyEng::IsAnREAlOxide(CElementChemistriesList& a_listElChems, double a_dMolarSum)
  1650. {
  1651. // calculate real element molar %
  1652. double dREElementMolarSum = 0;
  1653. for (int i = 0; i < REOXIDE_KEY_ELEMENT_MAX; ++i)
  1654. {
  1655. CElementChemistryPtr pREElement = GetNamedElementChemistry(a_listElChems, REOXIDE_KEY_ELEMENT_NAMES[i]);
  1656. if (pREElement)
  1657. {
  1658. // got a real element
  1659. // calculate the %molar value of the real element chemistry in the list
  1660. double dSubElMolar100 = Cal100NorValue(pREElement->GetMolarPercentage(), a_dMolarSum);
  1661. // calculate real element molar %
  1662. dREElementMolarSum += dSubElMolar100;
  1663. }
  1664. }
  1665. // is real element molar % over REAlOxide element molar % min cut_off
  1666. if (dREElementMolarSum < REALOXIDE_ELEMENT_MOLAR_LOW_CUTOFF)
  1667. {
  1668. // no, this is not a REALOxide, return FALSE
  1669. return FALSE;
  1670. }
  1671. // calculate Al/Si elements molar %
  1672. double dAl_Si_ElementMolarSum = 0;
  1673. for (int i = 0; i < REALOXIDE_SUB_ELEMENT_MAX; ++i)
  1674. {
  1675. CElementChemistryPtr pAlSiElement = GetNamedElementChemistry(a_listElChems, REALOXIDE_SUB_ELEMENT_NAMES[i]);
  1676. if (pAlSiElement)
  1677. {
  1678. // got a Al or Si element
  1679. // calculate the %molar value of the Al and Si element chemistry in the list
  1680. double dAl_SiElMolar100 = Cal100NorValue(pAlSiElement->GetMolarPercentage(), a_dMolarSum);
  1681. // calculate Al/Si elements molar %
  1682. dAl_Si_ElementMolarSum += dAl_SiElMolar100;
  1683. }
  1684. }
  1685. // is Al/Si elements molar % over REAlOxide element molar % min cut_off
  1686. if (dAl_Si_ElementMolarSum < REALOXIDE_ELEMENT_MOLAR_LOW_CUTOFF)
  1687. {
  1688. // no, this is not a REALOxide, return FALSE
  1689. return FALSE;
  1690. }
  1691. // is real element molar % + Al/Si elements molar % over the cut off
  1692. if (dREElementMolarSum + dAl_Si_ElementMolarSum > SIMPLE_OXIDE_MOLAR_CUTOFF)
  1693. {
  1694. // this is a REAlOxide, return TRUE
  1695. return TRUE;
  1696. }
  1697. // not a REAlOxide, return FALSE
  1698. return FALSE;
  1699. }
  1700. // check if is a Spinel
  1701. BOOL COTSClassifyEng::IsASpinel(CElementChemistriesList& a_listElChems, double a_dMolarSum)
  1702. {
  1703. // we deal with Mg, Al Spinel only
  1704. // get the first key element of Spinel
  1705. CElementChemistryPtr pFirstElChem = GetNamedElementChemistry(a_listElChems, SPINEL_KEY_ELEMENT_NAMES[0]);
  1706. if (!pFirstElChem)
  1707. {
  1708. // not a Spinel, return FALSE
  1709. return FALSE;
  1710. }
  1711. // get the second key element of Spinel
  1712. CElementChemistryPtr pSecondElChem = GetNamedElementChemistry(a_listElChems, SPINEL_KEY_ELEMENT_NAMES[1]);
  1713. if (!pSecondElChem)
  1714. {
  1715. // not a Spinel, return FALSE
  1716. return FALSE;
  1717. }
  1718. // check ratio between the two elements
  1719. double dFirstElMolar = pFirstElChem->GetMolarPercentage();
  1720. double dSecondElMolar = pSecondElChem->GetMolarPercentage();
  1721. if (dFirstElMolar < MIN_DOUBLE_VALUE)
  1722. {
  1723. // something wrong
  1724. // not a Spinel, return FALSE
  1725. return FALSE;
  1726. }
  1727. double dRatio = dSecondElMolar / dFirstElMolar;
  1728. if (dRatio < SPINEL_ELEMENT_RATIO_MIN || dRatio > SPINEL_ELEMENT_RATIO_MAX)
  1729. {
  1730. // not a Spinel, return FALSE
  1731. return FALSE;
  1732. }
  1733. // molar % amount check
  1734. double dFirstElMolar100 = Cal100NorValue(dFirstElMolar, a_dMolarSum);
  1735. double dSecondElMolar100 = Cal100NorValue(dSecondElMolar, a_dMolarSum);
  1736. if (dFirstElMolar100 + dSecondElMolar100 > SPINEL_KEY_ELEMENT_MOLAR_TOTAL)
  1737. {
  1738. // this is a Spinel
  1739. return TRUE;
  1740. }
  1741. // not a Spinel, return FALSE
  1742. return FALSE;
  1743. }
  1744. // check if is a Silicate
  1745. BOOL COTSClassifyEng::IsASilicate(CElementChemistriesList& a_listElChems, double a_dMolarSum)
  1746. {
  1747. // get key element of Silicate
  1748. CElementChemistryPtr pKeyElChem = GetNamedElementChemistry(a_listElChems, SILICATE_KEY_ELEMENT_NAME);
  1749. if (!pKeyElChem)
  1750. {
  1751. // not a Silicate, return FALSE
  1752. return FALSE;
  1753. }
  1754. // molar % amount check
  1755. double dKeyElMolar100 = Cal100NorValue(pKeyElChem->GetMolarPercentage(), a_dMolarSum);
  1756. if (dKeyElMolar100 > SILICATE_KEY_ELEMENT_MOLAR_TOTAL_MIN && dKeyElMolar100 < SILICATE_KEY_ELEMENT_MOLAR_TOTAL_MAX)
  1757. {
  1758. // this is a Silicate, return TRUE
  1759. return TRUE;
  1760. }
  1761. // not a Silicate, return FALSE
  1762. return FALSE;
  1763. }
  1764. // check if is a Aluminate
  1765. BOOL COTSClassifyEng::IsAnCa_Aluminate(CElementChemistriesList& a_listElChems, double a_dMolarSum,CString& strName)
  1766. {
  1767. // get key element of Aluminate
  1768. CElementChemistryPtr pKeyElChem = GetNamedElementChemistry(a_listElChems, ALUMINATE_KEY_ELEMENT_NAME[0]);
  1769. if (!pKeyElChem)
  1770. {
  1771. // not an Aluminate, return FALSE
  1772. return FALSE;
  1773. }
  1774. // molar % amount check
  1775. double dKeyElMolar100 = Cal100NorValue(pKeyElChem->GetMolarPercentage(), a_dMolarSum);
  1776. if (dKeyElMolar100 > ALUMINAT_KEY_ELEMENT_MOLAR_TOTAL_MIN && dKeyElMolar100 < ALUMINAT_KEY_ELEMENT_MOLAR_TOTAL_MAX)
  1777. {
  1778. CElementChemistryPtr pKeyElChem2 = GetNamedElementChemistry(a_listElChems, ALUMINATE_KEY_ELEMENT_NAME[1]);
  1779. if (!pKeyElChem2)
  1780. {
  1781. strName = ALUMINATE_STR;
  1782. return TRUE;
  1783. }
  1784. double dFirstElMolar = pKeyElChem->GetMolarPercentage();//Al
  1785. double dSecondElMolar = pKeyElChem2->GetMolarPercentage();//Ca
  1786. double dRatio = dFirstElMolar/dSecondElMolar ;// Al/Ca
  1787. if (dRatio < 1.3 || dRatio > 0.9)//12CaO-7Al2O3 14/12
  1788. {
  1789. // not a Spinel, return FALSE
  1790. strName = ALUMINATE12CaO_7Al2O3_STR;
  1791. return TRUE;
  1792. }
  1793. if (dRatio < 0.9 || dRatio > 0.4)//3CaO-Al2O3 2/3
  1794. {
  1795. // not a Spinel, return FALSE
  1796. strName = ALUMINATE3CaO_Al2O3_STR;
  1797. return TRUE;
  1798. }
  1799. else
  1800. {
  1801. strName = ALUMINATE_STR;
  1802. }
  1803. // this is a Aluminate, return TRUE
  1804. return TRUE;
  1805. }
  1806. // not a Aluminate, return FALSE
  1807. return FALSE;
  1808. }
  1809. // check if the element chemistries list matching the STD
  1810. BOOL COTSClassifyEng::MatchingSTD(CElementChemistriesList& a_listElChems, CSTDItemPtr a_pSTDItem, double a_dMolarSum)
  1811. {
  1812. // safety check
  1813. ASSERT(a_pSTDItem);
  1814. if (!a_pSTDItem)
  1815. {
  1816. // something wrong
  1817. LogErrorTrace(__FILE__, __LINE__, _T("COTSClassifyEng::MatchingSTD: invalid CSTDItemPtr."));
  1818. return FALSE;
  1819. }
  1820. if (a_dMolarSum < MIN_ELEMENT_SUM)
  1821. {
  1822. // something wrong
  1823. LogErrorTrace(__FILE__, __LINE__, _T("COTSClassifyEng::MatchingSTD: invalid molar sum value."));
  1824. return FALSE;
  1825. }
  1826. // find out how many elements need for the STD
  1827. CElementRangeList& listElementRange = a_pSTDItem->GetElementRangeList();
  1828. int nElNoMin = 0;
  1829. for (auto pElmentRange : listElementRange)
  1830. {
  1831. int nStart = pElmentRange->GetRange()->GetStart();
  1832. if (nStart > 0)
  1833. {
  1834. // this element has to have
  1835. ++nElNoMin;
  1836. }
  1837. }
  1838. int nElNoMax = (int)listElementRange.size();
  1839. // a_listChemistriesElements size has to be between nElNoMin and nElNoMax
  1840. int nElementSize = (int)a_listElChems.size();
  1841. //if (nElementSize < nElNoMin || nElementSize > nElNoMax)
  1842. if (nElementSize < nElNoMin)
  1843. {
  1844. // a_listChemistriesElements size not match
  1845. return FALSE;
  1846. }
  1847. // all element chemistries have to be in listElementRange and in the range
  1848. for (auto pElChems : a_listElChems)
  1849. {
  1850. CString strElement = pElChems->GetName();
  1851. auto itr = std::find_if(listElementRange.begin(), listElementRange.end(), [strElement](CElementRangePtr& poElemenRange) { return poElemenRange->GetElement()->GetName().CompareNoCase(strElement) == 0; });
  1852. if (itr == listElementRange.end())
  1853. {
  1854. // not in the element range list, not match then
  1855. return FALSE;
  1856. }
  1857. // molar value has to be in the range
  1858. double dMolar = pElChems->GetMolarPercentage();
  1859. dMolar = Cal100NorValue(dMolar, a_dMolarSum);
  1860. if (dMolar < (double)(*itr)->GetRange()->GetStart() || dMolar >(double)(*itr)->GetRange()->GetEnd())
  1861. {
  1862. // molar value has to be in the range, not match then
  1863. return FALSE;
  1864. }
  1865. }
  1866. // the two are matching each other, return TRUE
  1867. return TRUE;
  1868. }
  1869. // calculate 100% normalize value (molar)
  1870. double COTSClassifyEng::Cal100NorValue(double a_dValue, double a_dSumValue)
  1871. {
  1872. double d100NorCalue = MIN_DOUBLE_VALUE;
  1873. // sum has a cut off
  1874. if (a_dSumValue < MIN_ELEMENT_SUM)
  1875. {
  1876. return d100NorCalue;
  1877. }
  1878. d100NorCalue = a_dValue / a_dSumValue * 100;
  1879. return d100NorCalue;
  1880. }
  1881. }