OTSClassifyEng.cpp 62 KB

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