nncarlson / petaca

Petaca: A collection of foundational Fortran modules
MIT License
39 stars 5 forks source link

Support for complex-valued parameters #36

Open nncarlson opened 4 hours ago

nncarlson commented 4 hours ago

Add support for complex-valued parameters.

nncarlson commented 3 hours ago

The parameter_list type already supports complex variables via the set and get_any methods. The only missing piece is specific get methods for complex arguments. This is trivial to add.

Adding support for complex data to parameter_list_json is more difficult as JSON has no intrinsic notion of complex numbers. I see two options (not necessarily exclusive):

  1. Represent complex data as a structure, such as {re: 1.0, im: 2.0};
  2. Represent complex data as an array of size 2 [1.0, 2.0].

The main difference between the two is on where the capability is implemented. In option 1, the parameter list reader will need to examine each sublist it reads, and when it finds this special structure, replace the sublist with a complex-valued parameter. No change is needed to parameter_list. With option 2, no change to the parameter list reader is needed. Instead the parameter_list%get method for complex arguments needs to be extended to allow a size-2 array to be mapped to a complex value.