OTSClassifyEng.cpp 65 KB

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