OTSClassifyEng.cpp 67 KB

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