Skip to content

Commit ab6aacf

Browse files
committed
Partial sync Union_make_material McStas <-> McXtrace
1 parent 17ff24b commit ab6aacf

2 files changed

Lines changed: 6 additions & 87 deletions

File tree

mcstas-comps/union/Union_make_material.comp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
*
1414
* %D
1515
* Part of the Union components, a set of components that work together and thus
16-
* sperates geometry and physics within McStas.
16+
* separates geometry and physics within McStas.
1717
* The use of this component requires other components to be used.
1818
*
1919
* 1) One specifies a number of processes using process components

mcxtrace-comps/union/Union_make_material.comp

Lines changed: 5 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
* material: [string] List of elements present in the material. Triggers a search for materials constants files.
3838
* init: [string] Name of Union_init component (typically "init", default)
3939
*
40-
* OUTPUT PARAMETERS:
40+
* CALCULATED PARAMETERS:
4141
* this_material: Structure that contains information on this material
4242
* global_material_element: Element of global_material_list which is a global variable
4343
*
@@ -50,7 +50,7 @@
5050
******************************************************************************/
5151

5252
DEFINE COMPONENT Union_make_material
53-
DEFINITION PARAMETERS ()
53+
5454
SETTING PARAMETERS(string process_string="NULL",my_absorption,absorber=0, string material_string="NULL", string init="init")
5555
OUTPUT PARAMETERS ()
5656

@@ -137,7 +137,6 @@ int manual_linking_function(char *name, char *input_string) {
137137
/* walk through other tokens */
138138
while( token != NULL )
139139
{
140-
//printf( " %s\n", token );
141140
if (strcmp(token,name) == 0) return_integer=1;
142141

143142
token = strtok(NULL,",");
@@ -146,71 +145,7 @@ int manual_linking_function(char *name, char *input_string) {
146145
return return_integer;
147146
}
148147

149-
150-
151-
/*
152-
int count_commas(char *string) {
153-
int return_value = 0;
154-
155-
int index;
156-
for (index=0;index<strlen(string);index++) {
157-
printf("%c \n",string[index]);
158-
if (string[index]==',') return_value++;
159-
}
160-
161-
//printf("number_of_commas = %d \n",return_value);
162-
return return_value;
163-
}
164-
*/
165-
166-
int build_my_absorption_table_function(const char *material_string, struct element_data_struct **elements){
167-
/*parse for commas*/
168-
char local_string[128];
169-
const int size=16; /*maximum number of elements in materials*/
170-
171-
strncpy(local_string,material_string,128);
172-
173-
/*for each token read the table and compute mu, scale by chemical number density, and put the thing in the new table*/
174-
175-
/*init empty elements - tables can be read later*/
176-
*elements = calloc(size,sizeof(**elements));
177-
178-
char *token,*saveptr=NULL;
179-
int table_counter=0;
180-
int status;
181-
token=strtok_r(local_string,",",&saveptr);
182-
while (token!=NULL){ printf("Union_make_material: Reading data table for material %s\n",token);
183-
/*allow an integer before the filename*/
184-
if( (sscanf(token,"%d",&( (*elements)->multiplicity) )==1) ){
185-
token+=1;
186-
}else{
187-
(*elements)->multiplicity=1;
188-
}
189-
if ( (status=Table_Read(&((*elements)->element_table),token,0))==-1){
190-
printf("Union_make_material: ERROR Reading file %s.\n", token);
191-
return -1;
192-
}
193-
/*parse the tabel header for some constants*/
194-
char **header_parsed;
195-
header_parsed=Table_ParseHeader((*elements)->element_table.header,"Z","A[r]","rho","Z/A","sigma[a]",NULL);
196-
if (header_parsed==NULL){
197-
/*something went wrong when parsing the header*/
198-
printf("Union_make_material: ERROR parsing header in file %s.\n", token);
199-
return -1;
200-
}
201-
if (header_parsed[0]){(*elements)->Z=strtol(header_parsed[0],NULL,10);}
202-
if (header_parsed[1]){(*elements)->Ar=strtod(header_parsed[1],NULL);}
203-
if (header_parsed[2]){(*elements)->rho=strtod(header_parsed[2],NULL);}
204-
else{fprintf(stderr,"Warning(Union_make_material): %s not found in header of %s, set to 1\n","rho",token);(*elements)->rho=1;}
205-
206-
table_counter++;
207-
token=strtok_r(NULL,",",&saveptr);
208-
209-
}
210-
return table_counter;
211-
}
212148
#ifndef MATERIAL_DETECTOR
213-
//struct pointer_to_global_material_list global_material_list = {0,NULL};
214149
#define MATERIAL_DETECTOR dummy
215150
#endif
216151

@@ -231,8 +166,6 @@ struct pointer_to_1d_int_list accepted_processes;
231166

232167
// Add setup for loggers since make_material is called before any volume / master
233168
#ifndef UNION_LOGGER_DECLARE
234-
//struct pointer_to_global_logger_list global_all_volume_logger_list = {0,NULL};
235-
//struct pointer_to_global_logger_list global_specific_volumes_logger_list = {0,NULL};
236169
#define UNION_LOGGER_DECLARE dummy
237170
#endif
238171

@@ -243,14 +176,7 @@ INITIALIZE
243176

244177
accepted_processes.num_elements = 0;
245178
accepted_processes.elements = NULL;
246-
247-
/*
248-
// Comma test
249-
printf("Starting comma test on string: %s \n",process_string);
250-
printf("Number of commas in string: %d \n",count_commas(process_string));
251-
exit(1);
252-
*/
253-
179+
254180

255181
if (0 == strcmp(NAME_CURRENT_COMP,"vacuum") || 0 == strcmp(NAME_CURRENT_COMP,"Vacuum")) {
256182
printf("ERROR, a Union material may not be called Vacuum. A vacuum volume may be created by material=\"Vacuum\" in a geometry component.\n");
@@ -260,19 +186,10 @@ INITIALIZE
260186
printf("ERROR, a Union material may not be called Exit. A exit volume may be created by material=\"Exit\" in a geometry component.\n");
261187
exit(1);
262188
}
263-
264-
if ( 0 == strcmp(material_string,"NULL") ){
265189
if (my_absorption < 0) {
266190
printf("ERROR, Union make material named %s has a negative absorption cross section!.\n",NAME_CURRENT_COMP);
267191
exit(1);
268192
}
269-
}else{
270-
/* a material_string is given so use that*/
271-
if ( (this_material.number_of_elements = build_my_absorption_table_function(material_string, &(this_material.p_element_array) ))==-1 ){
272-
printf("ERROR, The material data file assigned to Union make material named %s could not be read and parsed.\n",NAME_CURRENT_COMP);
273-
exit(1);
274-
}
275-
}
276193

277194
if (_getcomp_index(init) < 0) {
278195
fprintf(stderr,"Union_make_material:%s: Error identifying Union_init component, %s is not a known component name.\n",
@@ -339,6 +256,7 @@ struct pointer_to_global_master_list *global_master_list = COMP_GETPAR3(Union_in
339256
#ifdef MASTER_DETECTOR
340257
#ifdef ANY_GEOMETRY_DETECTOR_DECLARE
341258
#ifndef MASTER_DETECTOR_WARNING
259+
342260
for (loop_index=0;loop_index<global_geometry_list->num_elements;loop_index++) {
343261
if (global_geometry_list->elements[loop_index].component_index > global_master_list->elements[global_master_list->num_elements-1].component_index) {
344262
printf("WARNING: No Union_master component defined after Union volume named %s, this components did not affect the simulation in any way.\n",global_geometry_list->elements[loop_index].name);
@@ -370,3 +288,4 @@ struct pointer_to_global_master_list *global_master_list = COMP_GETPAR3(Union_in
370288
%}
371289

372290
END
291+

0 commit comments

Comments
 (0)