OTSClassifyEng.cpp 60 KB

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