Skip to content

Incorrect bounds checking on conductive_aux.rho_* #350

@prmunro

Description

@prmunro

Describe the bug
When the multilayer variable in the input file is not set to [], there are two errors, one within iteratefdtd_matrix.m and one within the TDMS executeable. The first error (iteratefdtd_matrix) is due to a check to ensure the entries in multilayer increase monotomically, however, this test was specified incorrectly. The second error assumes that resulting data structures (conductive_aux.rho_x and conductive_aux.rho_y) should be vectors, which is incorrect.

To Reproduce

  1. Run gen_input_file.m in the attached, path to TDMS will need updating.
  2. This will generate an error in iteratefdtd_matrix.m, which may be fixed using the following change:

line 299 of iteratefdtd_matrix.m, currently has:

elseif all(sort(multilayer)==multilayer)

whereas is should be

elseif ~all(sort(multilayer)==multilayer)
  1. With the above correction made, tdms can be run, which will generate this error:
terminate called after throwing an instance of 'std::runtime_error'
  what():  Incorrect dimension conductive_aux.rho_x. Required 1D

Inspecting the mat file produced by iteratefdtd_matrix reveals:

>> dat.conductive_aux

ans = 

  struct with fields:

    rho_x: [41x61 double]
    rho_y: [41x61 double]
    rho_z: [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ... ]

meaning that rho_x and rho_y are not vectors, which is the expected behavior. Looking at the original version of the PSTD/FDTD code, we see the following error checking:


  /*Get conductive_aux */

  if(mxIsStruct(prhs[input_counter])){
    num_fields = mxGetNumberOfFields(prhs[input_counter]);
    if(num_fields != 3){
      sprintf(message_buffer, "conductive_aux should have 3 members, it has %d",num_fields);
      mexfprintf(message_buffer);
    }
    for(int i=0;i<3;i++){
      element = mxGetField( (mxArray *)prhs[input_counter], 0, conductive_aux_elements[i]);
      ndims = mxGetNumberOfDimensions(element);
      if( ndims == 2 ){
	dimptr_out = mxGetDimensions(element);
	if( !(dimptr_out[0] == 1 ||dimptr_out[0] == 0) ){ 
	  //sprintf(message_buffer, "Incorrect dimension on conductive_aux.%s",conductive_aux_elements[i]);
	  //mexfprintf(message_buffer);
	}
      }
      if(!strcmp(conductive_aux_elements[i],"rho_x")){
	rho_x = mxGetPr(element);
      }
      else if(!strcmp(conductive_aux_elements[i],"rho_y")){
	rho_y = mxGetPr(element);
      }
      else if(!strcmp(conductive_aux_elements[i],"rho_z")){
	rho_z = mxGetPr(element);
      }
      else{
	sprintf(message_buffer, "element conductive_aux.%s not handled",conductive_aux_elements[i]);
	mexfprintf(message_buffer);
      }
    }
  }
  else{
    sprintf(message_buffer, "Argument %d was expected to be a structure (conductive_aux)",input_counter);
    mexfprintf(message_buffer);
  }
  input_counter++;
  /*Get conductive_aux */
************************************************************** 

which does not require elements to be vectors. I am happy to not check the dimension of these variables since they should be set correctly in iteratefdtd_matrix

input_file_ml.zip

This bug is platform independent.

Metadata

Metadata

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions