OTSClassifyEng.cpp 62 KB

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