licenses
sequencelengths
1
3
version
stringclasses
677 values
tree_hash
stringlengths
40
40
path
stringclasses
1 value
type
stringclasses
2 values
size
stringlengths
2
8
text
stringlengths
25
67.1M
package_name
stringlengths
2
41
repo
stringlengths
33
86
[ "MIT" ]
0.1.2
47a08b35777450039eaa8e971e1278369931b431
code
146
abstract type AbstractContext end abstract type AbstractDeviceOrTrigger end abstract type AbstractBuffer end abstract type AbstractChannel end
LibIIO
https://github.com/TacHawkes/LibIIO.jl.git
[ "MIT" ]
0.1.2
47a08b35777450039eaa8e971e1278369931b431
code
5520
module CLibIIO using libiio_jll const libiio = libiio_jll.libiio const BUF_SIZE = 16384 const DST_BUFFER = Vector{Cchar}(undef, BUF_SIZE) include("ctypes.jl") export iio_scan_context, iio_scan_block, iio_context_info, iio_context, iio_device, iio_channel, iio_buffer, iio_data_format, iio_modifier, iio_chan_type # enum exports for s in instances(iio_modifier) @eval export $(Symbol(s)) end for s in instances(iio_chan_type) @eval export $(Symbol(s)) end include("util.jl") export dev_is_buffer_capable include("scan.jl") export iio_context_info_get_description, iio_context_info_get_uri, iio_context_info_list_free, iio_create_scan_block, iio_create_scan_context, iio_scan_block_destroy, iio_scan_block_get_info, iio_scan_block_scan, iio_scan_context_destroy, iio_scan_context_get_info_list include("toplevel.jl") export iio_get_backend, iio_get_backends_count, iio_has_backend, iio_library_get_version, iio_strerror include("context.jl") export iio_context_clone, iio_context_destroy, iio_context_find_device, iio_context_get_attr, iio_context_get_attr_value, iio_context_get_attrs_count, iio_context_get_description, iio_context_get_device, iio_context_get_devices_count, iio_context_get_name, iio_context_get_version, iio_context_get_xml, iio_context_set_timeout, iio_create_context_from_uri, iio_create_default_context, iio_create_local_context, iio_create_network_context, iio_create_xml_context, iio_create_xml_context_mem include("device.jl") export iio_device_attr_read, iio_device_attr_read_all, iio_device_attr_read_bool, iio_device_attr_read_double, iio_device_attr_read_longlong, iio_device_attr_write, iio_device_attr_write_all, iio_device_attr_write_bool, iio_device_attr_write_double, iio_device_attr_write_longlong, iio_device_attr_write_raw, iio_device_buffer_attr_read, iio_device_buffer_attr_read_all, iio_device_buffer_attr_read_bool, iio_device_buffer_attr_read_double, iio_device_buffer_attr_read_longlong, iio_device_buffer_attr_write, iio_device_buffer_attr_write_all, iio_device_buffer_attr_write_bool, iio_device_buffer_attr_write_double, iio_device_buffer_attr_write_longlong, iio_device_buffer_attr_write_raw, iio_device_find_attr, iio_device_find_buffer_attr, iio_device_find_channel, iio_device_get_attr, iio_device_get_attrs_count, iio_device_get_buffer_attr, iio_device_get_buffer_attrs_count, iio_device_get_channel, iio_device_get_channels_count, iio_device_get_context, iio_device_get_data, iio_device_get_id, iio_device_get_name, iio_device_get_label, iio_device_get_trigger, iio_device_is_trigger, iio_device_set_data, iio_device_set_kernel_buffers_count, iio_device_set_trigger include("channel.jl") export iio_channel_attr_get_filename, iio_channel_attr_read, iio_channel_attr_read_all, iio_channel_attr_read_bool, iio_channel_attr_read_double, iio_channel_attr_read_longlong, iio_channel_attr_write, iio_channel_attr_write_all, iio_channel_attr_write_bool, iio_channel_attr_write_double, iio_channel_attr_write_longlong, iio_channel_attr_write_raw, iio_channel_disable, iio_channel_enable, iio_channel_find_attr, iio_channel_get_attr, iio_channel_get_attrs_count, iio_channel_get_data, iio_channel_get_device, iio_channel_get_id, iio_channel_get_modifier, iio_channel_get_name, iio_channel_get_type, iio_channel_is_enabled, iio_channel_is_output, iio_channel_is_scan_element, iio_channel_read, iio_channel_read_raw, iio_channel_set_data, iio_channel_write, iio_channel_write_raw include("buffer.jl") export iio_buffer_cancel, iio_buffer_destroy, iio_buffer_end, iio_buffer_first, iio_buffer_foreach_sample, iio_buffer_get_data, iio_buffer_get_device, iio_buffer_get_poll_fd, iio_buffer_push, iio_buffer_push_partial, iio_buffer_refill, iio_buffer_set_blocking_mode, iio_buffer_set_data, iio_buffer_start, iio_buffer_step, iio_device_create_buffer include("debug.jl") export iio_device_get_sample_size, iio_channel_get_index, iio_channel_get_data_format, iio_channel_convert, iio_channel_convert_inverse, iio_device_get_debug_attrs_count, iio_device_get_debug_attr, iio_device_find_debug_attr, iio_device_debug_attr_read, iio_device_debug_attr_read_all, iio_device_debug_attr_write, iio_device_debug_attr_write_raw, iio_device_debug_attr_write_all, iio_device_debug_attr_read_bool, iio_device_debug_attr_read_longlong, iio_device_debug_attr_read_double, iio_device_debug_attr_write_bool, iio_device_debug_attr_write_longlong, iio_device_debug_attr_write_double, iio_device_identify_filename, iio_device_reg_write, iio_device_reg_read end
LibIIO
https://github.com/TacHawkes/LibIIO.jl.git
[ "MIT" ]
0.1.2
47a08b35777450039eaa8e971e1278369931b431
code
12437
""" iio_buffer_get_device(buffer) Retrieves a pointer to the [`iio_device`](@ref) structure. # Parameters - `buf::Ptr{iio_buffer}` : A pointer to an [`iio_buffer`](@ref) structure # Returns - A pointer to an [`iio_device`](@ref) structure See [libiio](https://analogdevicesinc.github.io/libiio/master/libiio/group__Buffer.html#ga42367567d47f501d1922d1b331cf64fb) """ function iio_buffer_get_device(buffer::Ptr{iio_buffer}) return ccall((:iio_buffer_get_device, libiio), Ptr{iio_device}, (Ptr{iio_device},), buffer) end """ iio_device_create_buffer(dev, samples_count, cyclic) Create an input or output buffer associated to the given device. # Parameters - `dev::Ptr{iio_device}` : A pointer to an [`iio_device`](@ref) structure - `samples_count::Csize_t` : The number of samples that the buffer should contain - `cyclic::Bool` : If true, enable cyclic mode # Returns - On success, a pointer to an [`iio_buffer`](@ref) structure - On error, an error is raised !!! note Channels that have to be written to / read from must be enabled before creating the buffer. See [libiio](https://analogdevicesinc.github.io/libiio/master/libiio/group__Buffer.html#gaea8067aca27b93a1260a0c563607a501) """ function iio_device_create_buffer(dev::Ptr{iio_device}, samples_count::Csize_t, cyclic::Bool) return @check_null ccall((:iio_device_create_buffer, libiio), Ptr{iio_buffer}, (Ptr{iio_device}, Csize_t, Cuchar), dev, samples_count, cyclic) end """ iio_buffer_destroy(buf) Destroy the given buffer. # Parameters - `buf::Ptr{iio_buffer}` : A pointer to an [`iio_buffer`](@ref) structure # Returns - A pointer corresponding to the address that follows the last sample present in the buffer See [libiio](https://analogdevicesinc.github.io/libiio/master/libiio/group__Buffer.html#gaba58dc2780be63fead6f09397ce90d10) """ function iio_buffer_destroy(buf::Ptr{iio_buffer}) ccall((:iio_buffer_destroy, libiio), Cvoid, (Ptr{iio_buffer},), buf) end """ iio_buffer_get_poll_fd(buf) Get a pollable file descriptor. Can be used to know when [`iio_buffer_refill`](@ref) or [`iio_buffer_push`](@ref) can be called # Parameters - `buf::Ptr{iio_buffer}` : A pointer to an [`iio_buffer`](@ref) structure # Returns - On success, valid file descriptor - On error, a negative errno code is returned See [libiio](https://analogdevicesinc.github.io/libiio/master/libiio/group__Buffer.html#ga2ae96ee9f0748e55dfad996d6e9883f2) """ function iio_buffer_get_poll_fd(buf::Ptr{iio_buffer}) return ccall((:iio_buffer_get_poll_fd, libiio), Cint, (Ptr{iio_buffer},), buf) end """ iio_buffer_set_blocking_mode(buf, blocking) Make [`iio_buffer_refill`](@ref) and [`iio_buffer_push`](@ref) blocking or not. After this function has been called with blocking == false, [`iio_buffer_refill`](@ref) and [`iio_buffer_push`](@ref) will return `-EAGAIN` if no data is ready. A device is blocking by default. # Parameters - `buf::Ptr{iio_buffer}` : A pointer to an [`iio_buffer`](@ref) structure - `blocking::Bool` : true if the buffer API should be blocking, else false # Returns - On success, 0 - On error, a negative errno code is returned See [libiio](https://analogdevicesinc.github.io/libiio/master/libiio/group__Buffer.html#gadf834d825ece149886283bcb8c2a5466) """ function iio_buffer_set_blocking_mode(buf::Ptr{iio_buffer}, blocking::Bool) return ccall((:iio_buffer_set_blocking_mode, libiio), Cint, (Ptr{iio_buffer}, Cuchar), buf, blocking) end """ iio_buffer_refill(buf) Fetch more samples from the hardware. # Parameters - `buf::Ptr{iio_buffer}` : A pointer to an [`iio_buffer`](@ref) structure # Returns - On success, the number of bytes read is returned - On error, a negative errno code is returned See [libiio](https://analogdevicesinc.github.io/libiio/master/libiio/group__Buffer.html#gac999e5244b5a2cbbca5ecaef8303a4ff) """ function iio_buffer_refill(buf::Ptr{iio_buffer}) return ccall((:iio_buffer_refill, libiio), Cssize_t, (Ptr{iio_buffer},), buf) end """ iio_buffer_push(buf) Send the samples to the hardware. # Parameters - `buf::Ptr{iio_buffer}` : A pointer to an [`iio_buffer`](@ref) structure # Returns - On success, the number of bytes written is returned - On error, a negative errno code is returned !!! note Only valid for output buffers See [libiio](https://analogdevicesinc.github.io/libiio/master/libiio/group__Buffer.html#gae7033c625d128667a56cf482aa3149bd) """ function iio_buffer_push(buf::Ptr{iio_buffer}) return ccall((:iio_buffer_push, libiio), Cssize_t, (Ptr{iio_buffer},), buf) end """ iio_buffer_push_partial(buf, samples_count) Send a given number of samples to the hardware. # Parameters - `buf::Ptr{iio_buffer}` : A pointer to an [`iio_buffer`](@ref) structure - `samples_count::Csize_t` : The number of samples to submit # Returns - On success, the number of bytes written is returned - On error, a negative errno code is returned !!! note Only valid for output buffers See [libiio](https://analogdevicesinc.github.io/libiio/master/libiio/group__Buffer.html#ga367b7368532aebb35a0d56bccc550570) """ function iio_buffer_push_partial(buf::Ptr{iio_buffer}, samples_count::Csize_t) return ccall((:iio_buffer_push_partial, libiio), Cssize_t, (Ptr{iio_buffer}, Csize_t), buf, samples_count) end """ iio_buffer_cancel(buf) Cancel all buffer operations. # Parameters - `buf::Ptr{iio_buffer}` : A pointer to an [`iio_buffer`](@ref) structure This function cancels all outstanding buffer operations previously scheduled. This means any pending [`iio_buffer_push`](@ref) or [`iio_buffer_refill`](@ref) operation will abort and return immediately, any further invocations of these functions on the same buffer will return immediately with an error. Usually [`iio_buffer_push`](@ref) and [`iio_buffer_refill`](@ref) will block until either all data has been transferred or a timeout occurs. This can depending on the configuration take a significant amount of time. [`iio_buffer_cancel`](@ref) is useful to bypass these conditions if the buffer operation is supposed to be stopped in response to an external event (e.g. user input). To be able to capture additional data after calling this function the buffer should be destroyed and then re-created. This function can be called multiple times for the same buffer, but all but the first invocation will be without additional effect. This function is thread-safe, but not signal-safe, i.e. it must not be called from a signal handler. See [libiio](https://analogdevicesinc.github.io/libiio/master/libiio/group__Buffer.html#ga0e42431688750313cfa077ab4f6e0282) """ function iio_buffer_cancel(buf::Ptr{iio_buffer}) ccall((:iio_buffer_cancel, libiio), Cvoid, (Ptr{iio_buffer},), buf) end """ iio_buffer_start(buf) Get the start address of the buffer. # Parameters - `buf::Ptr{iio_buffer}` : A pointer to an [`iio_buffer`](@ref) structure # Returns - A pointer corresponding to the start address of the buffer See [libiio](https://analogdevicesinc.github.io/libiio/master/libiio/group__Buffer.html#ga7fdacbfda79aa5120f34ea73ae2ea5ab) """ function iio_buffer_start(buf::Ptr{iio_buffer}) return ccall((:iio_buffer_start, libiio), Ptr{Cuchar}, (Ptr{iio_buffer},), buf) end """ iio_buffer_first(buf, chn) Find the first sample of a channel in a buffer. # Parameters - `buf::Ptr{iio_buffer}` : A pointer to an [`iio_buffer`](@ref) structure - `chn::Ptr{iio_channel}` :A pointer to an [`iio_channel`](@ref) structure # Returns - A pointer to the first sample found, or to the end of the buffer if no sample for the given channel is present in the buffer !!! note This function, coupled with iio_buffer_step and iio_buffer_end, can be used to iterate on all the samples of a given channel present in the buffer, doing the following: ```julia # Note that you have to adjust the end of the range for Julia, as the last value is included for ptr in iio_buffer_first(buf, chn):iio_buffer_step(buf):(iio_buffer_end(buf) - iio_buffer_step(buf)) .... end ``` See [libiio](https://analogdevicesinc.github.io/libiio/master/libiio/group__Buffer.html#ga000d2f4c8b72060db1c38ec905bf4156) """ function iio_buffer_first(buf::Ptr{iio_buffer}, chn::Ptr{iio_channel}) return ccall((:iio_buffer_first, libiio), Ptr{Cuchar}, (Ptr{iio_channel}, Ptr{iio_channel}), buf, chn) end """ iio_buffer_step(buf) Get the step size between two samples of one channel. # Parameters - `buf::Ptr{iio_buffer}` : A pointer to an [`iio_buffer`](@ref) structure # Returns - The difference between the addresses of two consecutive samples of one same channel See [libiio](https://analogdevicesinc.github.io/libiio/master/libiio/group__Buffer.html#ga5532665a8776cec1c209d6cf8d0bb409) """ function iio_buffer_step(buf::Ptr{iio_buffer}) return ccall((:iio_buffer_step, libiio), Cssize_t, (Ptr{iio_buffer},), buf) end """ iio_buffer_end(buf) Get the address that follows the last sample in a buffer. # Parameters - `buf::Ptr{iio_buffer}` : A pointer to an [`iio_buffer`](@ref) structure # Returns - A pointer corresponding to the address that follows the last sample present in the buffer See [libiio](https://analogdevicesinc.github.io/libiio/master/libiio/group__Buffer.html#gab5300f917bbdfc5dafc093a60138f131) """ function iio_buffer_end(buf::Ptr{iio_buffer}) return ccall((:iio_buffer_end, libiio), Ptr{Cuchar}, (Ptr{iio_buffer},), buf) end """ iio_buffer_foreach_sample(buf, callback, data) Call the supplied callback each sample found in a buffer. # Parameters - `buf::Ptr{iio_buffer}` : A pointer to an [`iio_buffer`](@ref) structure - `callback::Ptr{Cvoid}` : A pointer to a function to call for each sample found - `data::Ptr{Cvoid}` : A user-specified pointer that will be passed to the callback # Returns - Number of bytes processed !!! note The callback receives four arguments: - A pointer to the [`iio_channel`](@ref) structure corresponding to the sample, - A pointer to the sample itself, - The length of the sample in bytes, - The user-specified pointer passed to [`iio_buffer_foreach_sample`](@ref). See [libiio](https://analogdevicesinc.github.io/libiio/master/libiio/group__Buffer.html#ga810ec50155e82331b18ec71d3c507104) """ function iio_buffer_foreach_sample(buf::Ptr{iio_buffer}, callback::Ptr{Cvoid}, data::Ptr{Cvoid}) return ccall((:iio_buffer_foreach_sample, libiio), Cssize_t, (Ptr{iio_buffer}, Ptr{Cvoid}, Ptr{Cvoid}), buf, callback, data) end """ iio_buffer_set_data(buf, data) Associate a pointer to an [`iio_buffer`](@ref) structure. # Parameters - `buf::Ptr{iio_buffer}` : A pointer to an [`iio_buffer`](@ref) structure - `data::Ptr{Cuchar}` : The pointer to be associated See [libiio](https://analogdevicesinc.github.io/libiio/master/libiio/group__Buffer.html#ga07f485e4e2de57c8c1cd0141611187dc) """ function iio_buffer_set_data(buf::Ptr{iio_buffer}, data::Ptr{Cuchar}) return ccall((:iio_buffer_set_data, libiio), Cvoid, (Ptr{iio_buffer}, Ptr{Cuchar}), buf, data) end """ iio_buffer_get_data(buf) Retrieve a pointer to the [`iio_device`](@ref) structure. # Parameters - `buf::Ptr{iio_buffer}` : A pointer to an [`iio_buffer`](@ref) structure # Returns - A pointer to an [`iio_device`](@ref) structure See [libiio](https://analogdevicesinc.github.io/libiio/master/libiio/group__Buffer.html#gac110da795a50dc45fe998cace656329b) """ function iio_buffer_get_data(buf::Ptr{iio_buffer}) return ccall((:iio_buffer_get_data, libiio), Ptr{iio_device}, (Ptr{iio_buffer},), buf) end
LibIIO
https://github.com/TacHawkes/LibIIO.jl.git
[ "MIT" ]
0.1.2
47a08b35777450039eaa8e971e1278369931b431
code
24778
""" iio_channel_get_device(chn) Retrieve a pointer to the [`iio_device`](@ref) structure. # Parameters - `chn::Ptr{iio_channel}` : A pointer to an [`iio_channel`](@ref) structure # Returns - A pointer to a [`iio_device`](@ref) structure See [libiio](https://analogdevicesinc.github.io/libiio/master/libiio/group__Channel.html#gaf2800d7a6953c5dd3271df390c062439) """ function iio_channel_get_device(chn::Ptr{iio_channel}) return ccall((:iio_channel_get_device, libiio), Ptr{iio_device}, (Ptr{iio_channel},), chn) end """ iio_channel_get_id(chn) Retrieve the channel ID (e.g. `voltage0`) # Parameters - `chn::Ptr{iio_channel}` : A pointer to an [`iio_channel`](@ref) structure # Returns - A string with the channel ID See [libiio](https://analogdevicesinc.github.io/libiio/master/libiio/group__Channel.html#gafda1782de4655905ad08a40492f3dc64) """ function iio_channel_get_id(chn::Ptr{iio_channel}) return unsafe_string(ccall((:iio_channel_get_id, libiio), Cstring, (Ptr{iio_channel},), chn)) end """ iio_channel_get_name(chn) Retrieve the channel name (e.g. `vccint`) # Parameters - `chn::Ptr{iio_channel}` : A pointer to an [`iio_channel`](@ref) structure # Returns - A string with the channel name !!! note If the channel has no name, an empty string is returned. See [libiio](https://analogdevicesinc.github.io/libiio/master/libiio/group__Channel.html#ga37346a6f3fcfb1eb40572aec6c3b39ac) """ function iio_channel_get_name(chn::Ptr{iio_channel}) name = ccall((:iio_channel_get_name, libiio), Cstring, (Ptr{iio_channel},), chn) return name == C_NULL ? "" : unsafe_string(name) end """ iio_channel_is_output(chn) Return true if the given channel is an output channel # Parameters - `chn::Ptr{iio_channel}` : A pointer to an [`iio_channel`](@ref) structure # Returns - True if the channel is an output channel, false otherweise See [libiio](https://analogdevicesinc.github.io/libiio/master/libiio/group__Channel.html#ga3c24e9c93e2217c9506073d04b878461) """ function iio_channel_is_output(chn::Ptr{iio_channel}) return convert(Bool, ccall((:iio_channel_is_output, libiio), Cuchar, (Ptr{iio_channel},), chn)) end """ iio_channel_is_scan_element(chn) Return true of the given channel is a scan element. # Parameters - `chn::Ptr{iio_channel}` : A pointer to an [`iio_channel`](@ref) structure # Returns - True if the channel is a scan element, false otherweise !!! note A channel that is a scan element is a channel that can generate samples (for an input channel) or receive samples (for an output channel) after being enabled. See [libiio](https://analogdevicesinc.github.io/libiio/master/libiio/group__Channel.html#ga07892a3c0c31e7a3eecf76ec72a8669d) """ function iio_channel_is_scan_element(chn::Ptr{iio_channel}) return convert(Bool, ccall((:iio_channel_is_scan_element, libiio), Cuchar, (Ptr{iio_channel},), chn)) end """ iio_channel_get_attrs_count(chn) Enumerate the channel-specific attributes of the given channel. # Parameters - `chn::Ptr{iio_channel}` : A pointer to an [`iio_channel`](@ref) structure # Returns - The number of channel-specific attributes found See [libiio](https://analogdevicesinc.github.io/libiio/master/libiio/group__Channel.html#ga14869c3fda8b04f413a02f15dfa6ef7c) """ function iio_channel_get_attrs_count(chn::Ptr{iio_channel}) return ccall((:iio_channel_get_attrs_count, libiio), Cuint, (Ptr{iio_channel},), chn) end """ iio_channel_get_attr(chn, index) Get the channel-specific attribute present at the given index. # Parameters - `chn::Ptr{iio_channel}` : A pointer to an [`iio_channel`](@ref) structure - `index::Cuint` : The index corresponding to the attribute # Returns - On success, a string containing the attribute name - If the index is invalid, an empty string will be returned See [libiio](https://analogdevicesinc.github.io/libiio/master/libiio/group__Channel.html#gafc3c52f360424c097a24d1925923d772) """ function iio_channel_get_attr(chn::Ptr{iio_channel}, index::Cuint) attr = ccall((:iio_channel_get_attr, libiio), Cstring, (Ptr{iio_channel}, Cuint), chn, index) return attr == C_NULL ? "" : unsafe_string(attr) end """ iio_channel_find_attr(chn, name) Try to find a channel-specific attribute by its name. # Parameters - `chn::Ptr{iio_channel}` : A pointer to an [`iio_channel`](@ref) structure - `name::String` : A string corresponding to the name of the attribute # Returns - On succes, a string containing the attribute name - If the name does not correspond to any know atribute of the channel, an empty string is returned !!! note This function is useful to detect the presence of an attribute. See [libiio](https://analogdevicesinc.github.io/libiio/master/libiio/group__Channel.html#ga13b2db3252a2380a2b0b1bb15b8034a4) """ function iio_channel_find_attr(chn::Ptr{iio_channel}, name::String) attr = ccall((:iio_channel_find_attr, libiio), Cstring, (Ptr{iio_channel}, Cstring), chn, name) return attr == C_NULL ? "" : unsafe_string(attr) end """ iio_channel_attr_get_filename(chn, attr) Retrieve the filename of an attribute. # Parameters - `chn::Ptr{iio_channel}` : A pointer to an [`iio_channel`](@ref) structure - `attr::String` ; A string corresponding to the name of the attribute # Returns - On success, a string with the filename - If the attribute is unknown, an empty string is returned See [libiio](https://analogdevicesinc.github.io/libiio/master/libiio/group__Channel.html#gab6462404bb6667e9e9241a18e09a1638) """ function iio_channel_attr_get_filename(chn::Ptr{iio_channel}, attr::String) name = ccall((:iio_channel_attr_get_filename, libiio), Cstring, (Ptr{iio_channel}, Cstring), chn, attr) return name == C_NULL ? "" : unsafe_string(name) end """ iio_channel_attr_read(dev, attr) Read the content of the given channel-specific attribute. # Parameters - `chn::Ptr{iio_channel}` : A pointer to an [`iio_channel`](@ref) structure - `attr::String` : A string corresponding to the name of the attribute # Returns - On success, a string with the attribute value. - On error, a negative errno code is returned !!! note This function deviates from the C library [`iio_channel_attr_read`](@ref). Instead of passing an empty string, call the function without the attr argument. See [libiio](https://analogdevicesinc.github.io/libiio/master/libiio/group__Channel.html#ga2c2ca5696d1341067051eb390d5014ae) """ function iio_channel_attr_read(chn::Ptr{iio_channel}, attr::String) dst = DST_BUFFER ret = ccall((:iio_channel_attr_read, libiio), Cssize_t, (Ptr{iio_channel}, Cstring, Cstring, Csize_t), chn, attr, pointer(dst), BUF_SIZE) attrs = unsafe_string(pointer(dst)) return ret, attrs end """ iio_channel_attr_read(dev) Read the content of the given channel-specific attribute. # Parameters - `chn::Ptr{iio_channel}` : A pointer to an [`iio_channel`](@ref) structure # Returns - On success, a Vector of Tuples of attribute index and value. - On error, a negative errno code is returned See [libiio](https://analogdevicesinc.github.io/libiio/master/libiio/group__Channel.html#ga2c2ca5696d1341067051eb390d5014ae) """ function iio_channel_attr_read(chn::Ptr{iio_channel}) attr = C_NULL dst = DST_BUFFER ret = ccall((:iio_channel_attr_read, libiio), Cssize_t, (Ptr{iio_channel}, Cstring, Cstring, Csize_t), chn, attr, pointer(dst), BUF_SIZE) attrs = iio_parse_attr(dst, ret) return ret, attrs end """ iio_channel_attr_read_all(dev, cb, data) Read the content of all channel-specific attributes. # Parameters - `chn::Ptr{iio_channel}` : A pointer to an [`iio_channel`](@ref) structure - `cb::Ptr{Cvoid}` : A pointer to a callback function - `data::Ptr{Cvoid}` : A pointer that will be passed to the callback function # Returns - On success, 0 is returned - On error, a negative errno code is returned !!! note This function is especially useful when used with the network backend, as all the channel-specific attributes are read in one single command. See [libiio](https://analogdevicesinc.github.io/libiio/master/libiio/group__Channel.html#gab9c28b0cd94c0607bcc7cac16219eb48) """ function iio_channel_attr_read_all(chn::Ptr{iio_channel}, cb::Ptr{Cvoid}, data::Ptr{Cvoid}) return ccall((:iio_channel_attr_read_all, libiio), Cint, (Ptr{iio_channel}, Ptr{Cvoid}, Ptr{Cvoid}), chn, cb, data) end """ iio_channel_attr_read_bool(dev, attr) Read the content of the given channel-specific attribute. # Parameters - `chn::Ptr{iio_channel}` : A pointer to an [`iio_channel`](@ref) structure - `attr::String` : A string corresponding to the name of the attribute # Returns - On success, 0 and the bool value is returned - On error, a negative errno code is returned See [libiio](https://analogdevicesinc.github.io/libiio/master/libiio/group__Channel.html#ga319f39c313bbd4d331e23df51e4d3ce6) """ function iio_channel_attr_read_bool(chn::Ptr{iio_channel}, attr::String) value = Ref{Cuchar}(0) ret = ccall((:iio_channel_attr_read_bool, libiio), Cint, (Ptr{iio_channel}, Cstring, Ptr{Cuchar}), chn, attr, value) return ret, convert(Bool, value[]) end """ iio_channel_attr_read_longlong(dev, attr) Read the content of the given channel-specific attribute. # Parameters - `chn::Ptr{iio_channel}` : A pointer to an [`iio_channel`](@ref) structure - `attr::String` : A string corresponding to the name of the attribute # Returns - On success, 0 and the Clonglong value is returned - On error, a negative errno code is returned See [libiio](https://analogdevicesinc.github.io/libiio/master/libiio/group__Channel.html#ga116c61892bf3d20ff07efd642c5dfbe1) """ function iio_channel_attr_read_longlong(chn::Ptr{iio_channel}, attr::String) value = Ref{Clonglong}(0) ret = ccall((:iio_channel_attr_read_longlong, libiio), Cint, (Ptr{iio_channel}, Cstring, Ptr{Clonglong}), chn, attr, value) return ret, value[] end """ iio_channel_attr_read_double(dev, attr) Read the content of the given channel-specific attribute. # Parameters - `chn::Ptr{iio_channel}` : A pointer to an [`iio_channel`](@ref) structure - `attr::String` : A string corresponding to the name of the attribute # Returns - On success, 0 and the Cdouble value is returned - On error, a negative errno code is returned See [libiio](https://analogdevicesinc.github.io/libiio/master/libiio/group__Channel.html#ga75ac9b81eb7e7e8a961afb67748e4102) """ function iio_channel_attr_read_double(chn::Ptr{iio_channel}, attr::String) value = Ref{Cdouble}(0) ret = ccall((:iio_channel_attr_read_double, libiio), Cint, (Ptr{iio_channel}, Cstring, Ptr{Cdouble}), chn, attr, value) return ret, value[] end """ iio_channel_attr_write(dev, attr, src) Set the value of the given channel-specific attribute. # Parameters - `chn::Ptr{iio_channel}` : A pointer to an [`iio_channel`](@ref) structure - `attr::String` : A string corresponding to the name of the attribute - `src::String` A string to set the attribute to # Returns - On success, the number of bytes written - On error, a negative errno code is returned !!! note By passing `C_NULL` as the "attr" argument to [`iio_channel_attr_write`](@ref), it is now possible to write all of the attributes of a device. The buffer must contain one block of data per attribute of the device, by the order they appear in the iio_device structure. The first four bytes of one block correspond to a 32-bit signed value in network order. If negative, the attribute is not written; if positive, it corresponds to the length of the data to write. In that case, the rest of the block must contain the data. See [libiio](https://analogdevicesinc.github.io/libiio/master/libiio/group__Channel.html#ga35c76ce5fcae4c551b7c78d648665a41) """ function iio_channel_attr_write(chn::Ptr{iio_channel}, attr::String, src::String) return ccall((:iio_channel_attr_write, libiio), Cssize_t, (Ptr{iio_channel}, Cstring, Cstring), chn, attr, src) end """ iio_channel_attr_write_raw(dev, attr, src, len) Set the value of the given channel-specific attribute. # Parameters - `chn::Ptr{iio_channel}` : A pointer to an [`iio_channel`](@ref) structure - `attr::String` : A string corresponding to the name of the attribute - `src::Ptr{Cvoid}` : A pointer to the data to be written - `len::Csize_t` : The number of bytes that should be written # Returns - On success, the number of bytes written - On error, a negative errno code is returned See [libiio](https://analogdevicesinc.github.io/libiio/master/libiio/group__Channel.html#gacd0d3dd36bdc64a9f967e21a891230eb) """ function iio_channel_attr_write_raw(chn::Ptr{iio_channel}, attr::String, src::Ptr{Cvoid}, len::Csize_t) return ccall((:iio_channel_attr_write_raw, libiio), Cssize_t, (Ptr{iio_channel}, Cstring, Ptr{Cvoid}, Csize_t), chn, attr, src, len) end """ iio_channel_attr_write_all(dev, cb, data) Set the values of all channel-specifc attributes. # Parameters - `chn::Ptr{iio_channel}` : A pointer to an [`iio_channel`](@ref) structure - `cb::Ptr{Cvoid}` : A pointer to a callback function - `data::Ptr{Cvoid}` : A pointer that will be passed to the callback function # Returns - On success, 0 is returned - On error, a negative errno code is returned !!! note This function is especially useful when used with the network backend, as all the chsnnel-specific attributes are written in one single command. See [libiio](https://analogdevicesinc.github.io/libiio/master/libiio/group__Channel.html#ga6df693ee4f0c329d957f7c7ca3588f3f) """ function iio_channel_attr_write_all(chn::Ptr{iio_channel}, cb::Ptr{Cvoid}, data::Ptr{Cvoid}) return ccall((:iio_channel_attr_write_all, libiio), Cint, (Ptr{iio_channel}, Ptr{Cvoid}, Ptr{Cvoid}), chn, cb, data) end """ iio_channel_attr_write_bool(dev, attr, val) Set the value of the given channel-specific attribute. # Parameters - `chn::Ptr{iio_channel}` : A pointer to an [`iio_channel`](@ref) structure - `attr::String` : A string corresponding to the name of the attribute - `val::Bool` : A bool value to set the attribute to # Returns - On success, 0 is returned - On error, a negative errno code is returned See [libiio](https://analogdevicesinc.github.io/libiio/master/libiio/group__Channel.html#ga9a385b9b05d20f33f8e587feb2ebe81a) """ function iio_channel_attr_write_bool(chn::Ptr{iio_channel}, attr::String, val::Bool) return ccall((:iio_channel_attr_write_bool, libiio), Cint, (Ptr{iio_channel}, Cstring, Cuchar), chn, attr, val) end """ iio_channel_attr_write_longlong(dev, attr, val) Set the value of the given channel-specific attribute. # Parameters - `chn::Ptr{iio_channel}` : A pointer to an [`iio_channel`](@ref) structure - `attr::String` : A string corresponding to the name of the attribute - `val::Clonglong` : A Clonglong value to set the attribute to # Returns - On success, 0 is returned - On error, a negative errno code is returned See [libiio](https://analogdevicesinc.github.io/libiio/master/libiio/group__Channel.html#gac55cb77a1baf797e54a8a4e31b2f4680) """ function iio_channel_attr_write_longlong(chn::Ptr{iio_channel}, attr::String, val::Clonglong) return ccall((:iio_channel_attr_write_longlong, libiio), Cint, (Ptr{iio_channel}, Cstring, Clonglong), chn, attr, val) end """ iio_channel_attr_write_double(dev, attr, val) Set the value of the given channel-specific attribute. # Parameters - `chn::Ptr{iio_channel}` : A pointer to an [`iio_channel`](@ref) structure - `attr::String` : A string corresponding to the name of the attribute - `val::Cdouble` : A Cdouble value to set the attribute to # Returns - On success, 0 is returned - On error, a negative errno code is returned See [libiio](https://analogdevicesinc.github.io/libiio/master/libiio/group__Channel.html#gad9d6ec4a02948c6416cc99254bdbfa50) """ function iio_channel_attr_write_double(chn::Ptr{iio_channel}, attr::String, val::Cdouble) return ccall((:iio_channel_attr_write_double, libiio), Cint, (Ptr{iio_channel}, Cstring, Cdouble), chn, attr, val) end """ iio_channel_enable(chn) Enable the given channel. # Parameters - `chn::Ptr{iio_channel}` : A pointer to an [`iio_channel`](@ref) structure !!! note Before creating an [`iio_buffer`](@ref) structure with [`iio_device_create_buffer`](@ref), it is required to enable at least one channel of the device to read from. See [libiio](https://analogdevicesinc.github.io/libiio/master/libiio/group__Channel.html#ga2b787983683d37966b5e1e5c6c121d6a) """ function iio_channel_enable(chn::Ptr{iio_channel}) ccall((:iio_channel_enable, libiio), Cvoid, (Ptr{iio_channel},), chn) end """ iio_channel_disable(chn) Disable the given channel. # Parameters - `chn::Ptr{iio_channel}` : A pointer to an [`iio_channel`](@ref) structure See [libiio](https://analogdevicesinc.github.io/libiio/master/libiio/group__Channel.html#gad7c7c91c61b8a97187dc73cbcdb60c06) """ function iio_channel_disable(chn::Ptr{iio_channel}) ccall((:iio_channel_disable, libiio), Cvoid, (Ptr{iio_channel},), chn) end """ iio_channel_is_enabled(chn) Returns true of the channel is enabled. # Parameters - `chn::Ptr{iio_channel}` : A pointer to an [`iio_channel`](@ref) structure # Returns - True if the channel is enabled, false otherwise See [libiio](https://analogdevicesinc.github.io/libiio/master/libiio/group__Channel.html#gaf10427dc35adaa0991cd34a9dd45a82f) """ function iio_channel_is_enabled(chn::Ptr{iio_channel}) return convert(Bool, ccall((:iio_channel_is_enabled, libiio), Cuchar, (Ptr{iio_channel},), chn)) end """ iio_channel_read_raw(chn, buffer, dst) Demultiplex the samples of a given channel. # Parameters - `chn::Ptr{iio_channel}` : A pointer to an [`iio_channel`](@ref) structure - `buffer::Ptr{iio_buffer}` : A pointer to an [`iio_buffer`](@ref) structure - `dst::Vector{Cuchar}` : A destination memory area where the demultiplexed data will be stored # Returns - The size of the demultiplexed data, in bytes See [libiio](https://analogdevicesinc.github.io/libiio/master/libiio/group__Channel.html#gacd227a6861960ea2fb49d957f62887dd) """ function iio_channel_read_raw(chn::Ptr{iio_channel}, buffer::Ptr{iio_buffer}, dst::Vector{Cuchar}) return ccall((:iio_channel_read_raw, libiio), Csize_t, (Ptr{iio_channel}, Ptr{iio_buffer}, Ptr{Cuchar}, Csize_t), chn, buffer, pointer(dst), length(dst)) end """ iio_channel_read(chn, buffer, dst) Demultiplex and convert the samples of a given channel. # Parameters - `chn::Ptr{iio_channel}` : A pointer to an [`iio_channel`](@ref) structure - `buffer::Ptr{iio_buffer}` : A pointer to an [`iio_buffer`](@ref) structure - `dst::Vector{Cuchar}` : A destination memory area where the converted data will be stored # Returns - The size of the converted data, in bytes See [libiio](https://analogdevicesinc.github.io/libiio/master/libiio/group__Channel.html#ga5c01edc37b0b57aef503abd5989a6a30) """ function iio_channel_read(chn::Ptr{iio_channel}, buffer::Ptr{iio_buffer}, dst::Vector{Cuchar}) return ccall((:iio_channel_read, libiio), Csize_t, (Ptr{iio_channel}, Ptr{iio_buffer}, Ptr{Cuchar}, Csize_t), chn, buffer, pointer(dst), length(dst)) end """ iio_channel_write_raw(chn, buffer, dst) Multiplex the samples of a given channel. # Parameters - `chn::Ptr{iio_channel}` : A pointer to an [`iio_channel`](@ref) structure - `buffer::Ptr{iio_buffer}` : A pointer to an [`iio_buffer`](@ref) structure - `src::Vector{Cuchar}` : A source memory area where the sequential data will be read from # Returns - The number of bytes actually multiplexed See [libiio](https://analogdevicesinc.github.io/libiio/master/libiio/group__Channel.html#ga350e81855764c159c6aefa12fb78e1c2) """ function iio_channel_write_raw(chn::Ptr{iio_channel}, buffer::Ptr{iio_buffer}, src::Vector{Cuchar}) return ccall((:iio_channel_write_raw, libiio), Csize_t, (Ptr{iio_channel}, Ptr{iio_buffer}, Ptr{Cuchar}, Csize_t), chn, buffer, pointer(src), length(src)) end """ iio_channel_write(chn, buffer, dst) Convert and multiplex the samples of a given channel. # Parameters - `chn::Ptr{iio_channel}` : A pointer to an [`iio_channel`](@ref) structure - `buffer::Ptr{iio_buffer}` : A pointer to an [`iio_buffer`](@ref) structure - `src::Vector{Cuchar}` : A source memory area where the sequential data will be read from # Returns - The number of bytes actually converted and multiplexed See [libiio](https://analogdevicesinc.github.io/libiio/master/libiio/group__Channel.html#ga350e81855764c159c6aefa12fb78e1c2) """ function iio_channel_write(chn::Ptr{iio_channel}, buffer::Ptr{iio_buffer}, src::Vector{Cuchar}) return ccall((:iio_channel_write, libiio), Csize_t, (Ptr{iio_channel}, Ptr{iio_buffer}, Ptr{Cuchar}, Csize_t), chn, buffer, pointer(src), length(src)) end """ iio_channel_set_data(dev, data) Associate a pointer to an [`iio_channel`](@ref) structure. # Parameters - `chn::Ptr{iio_channel}` : A pointer to an [`iio_channel`](@ref) structure - `data::Ptr{Cvoid}` : The pointer to be associated See [libiio](https://analogdevicesinc.github.io/libiio/master/libiio/group__Channel.html#ga5150c9b73386d899460ebafbe614f338) """ function iio_channel_set_data(chn::Ptr{iio_channel}, data::Ptr{Cvoid}) ccall((:iio_channel_set_data, libiio), Cvoid, (Ptr{iio_channel}, Ptr{Cvoid}), chn, data) end """ iio_channel_get_data(dev) Retrieve a previously associated pointer of an [`iio_channel`](@ref) structure. # Parameters - `chn::Ptr{iio_channel}` : A pointer to an [`iio_channel`](@ref) structure # Returns - The pointer previously associated if present, or C_NULL See [libiio](https://analogdevicesinc.github.io/libiio/master/libiio/group__Channel.html#gacbce92eaefb8d61c1e4f0dc042b211e6) """ function iio_channel_get_data(chn::Ptr{iio_channel}) return ccall((:iio_channel_get_data, libiio), Ptr{Cvoid}, (Ptr{iio_channel},), chn) end """ iio_channel_get_type(chn) Get the type of the given channel. # Parameters - `chn::Ptr{iio_channel}` : A pointer to an [`iio_channel`](@ref) structure # Returns - The type of the channel See [libiio](https://analogdevicesinc.github.io/libiio/master/libiio/group__Channel.html#ga281660051fb40b5b4055227466a3be36) """ function iio_channel_get_type(chn::Ptr{iio_channel}) return ccall((:iio_channel_get_type, libiio), iio_chan_type, (Ptr{iio_channel},), chn) end """ iio_channel_get_modifier(chn) Get the modifier type of the given channel. # Parameters - `chn::Ptr{iio_channel}` : A pointer to an [`iio_channel`](@ref) structure # Returns - The modifier type of the channel See [libiio](https://analogdevicesinc.github.io/libiio/master/libiio/group__Channel.html#ga4c3179cee86d8992ee6c6bdbcaa44156) """ function iio_channel_get_modifier(chn::Ptr{iio_channel}) return ccall((:iio_channel_get_modifier, libiio), iio_modifier, (Ptr{iio_channel},), chn) end
LibIIO
https://github.com/TacHawkes/LibIIO.jl.git
[ "MIT" ]
0.1.2
47a08b35777450039eaa8e971e1278369931b431
code
15733
""" iio_create_default_context() Create a context from local or remote IIO devices. # Returns - On success, a pointer to an [`iio_context`](@ref) structure - On failure, an error is raised !!! note This function will create a context with the URI provided in the IIOD_REMOTE environment variable. If not set, a local context will be created instead. See [libiio](https://analogdevicesinc.github.io/libiio/master/libiio/group__Context.html#ga21076125f817a680e0c01d4a490f0416) """ function iio_create_default_context() return @check_null ccall((:iio_create_default_context, libiio), Ptr{iio_context}, ()) end """ iio_create_local_context() Create a context from local IIO devices (Linux only) # Returns - On success, a pointer to an [`iio_context`](@ref) structure - On failure, an error is raised See [libiio](https://analogdevicesinc.github.io/libiio/master/libiio/group__Context.html#gaf31acec2d0f9f498870cc52a1d49783e) """ function iio_create_local_context() return @check_null ccall((:iio_create_local_context, libiio), Ptr{iio_context}, ()) end """ iio_create_xml_context(xml_file) Create a context from a XML file. # Parameters - `xml_file::String` : Path to the XML file to open # Returns - On success, a pointer to an [`iio_context`](@ref) structure - On failure, an error is raised !!! note The format of the XML must comply to the one returned by iio_context_get_xml. See [libiio](https://analogdevicesinc.github.io/libiio/master/libiio/group__Context.html#ga9925a84e596c3003e30b1cdd2b65d029) """ function iio_create_xml_context(xml_file::String) return @check_null ccall((:iio_create_xml_context, libiio), Ptr{iio_context}, (Cstring,), xml_file) end """ iio_create_xml_context_mem(xml, len) Create a context from a XML data in memory. # Parameters - `xml::String` : String with the XML data in memory - `len::Csize_t` : Length of the XML string in memory # Returns - On success, a pointer to an [`iio_context`](@ref) - On failure, an error is raised !!! note The format of the XML must comply to the one returned by iio_context_get_xml. See [libiio](https://analogdevicesinc.github.io/libiio/master/libiio/group__Context.html#gabaa848ca554af5723a44b9b7fd0ba6a3) """ function iio_create_xml_context_mem(xml::String, len::Csize_t) return @check_null ccall((:iio_create_xml_context_mem, libiio), Ptr{iio_context}, (Cstring, Csize_t), xml, len) end """ iio_create_network_context(host) Create a context from the network. # Parameters - `host::String` : Hostname, IPv4 or IPv6 address where the IIO Daemon is running # Returns - On success, a pointer to an [`iio_context`](@ref) structure - On failure, an error is raised See [libiio](https://analogdevicesinc.github.io/libiio/master/libiio/group__Context.html#ga8adf2ef4d2b62aa34201469cd7049617) """ function iio_create_network_context(host::String) return @check_null ccall((:iio_create_network_context, libiio), Ptr{iio_context}, (Cstring,), host) end """ iio_create_context_from_uri(uri) Create a context from an URI description. # Parameters - `uri::String` : An URI describing the context location # Returns - On success, a pointer to an [`iio_context`](@ref) structure - On failure, an error is raised !!! note The following URIs are supported based on compile time backend support: - Local backend, "local:" Does not have an address part. For example "local:" - XML backend, "xml:" Requires a path to the XML file for the address part. For example "xml:/home/user/file.xml" - Network backend, "ip:" Requires a hostname, IPv4, or IPv6 to connect to a specific running IIO Daemon or no address part for automatic discovery when library is compiled with ZeroConf support. For example "ip:192.168.2.1", or "ip:localhost", or "ip:" or "ip:plutosdr.local". To support alternative port numbers the standard ip:host:port format is used. A special format is required as defined in RFC2732 for IPv6 literal hostnames, (adding '[]' around the host) to use a ip:[x:x:x:x:x:x:x:x]:port format. Valid examples would be: - ip: Any host on default port - ip::40000 Any host on port 40000 - ip:analog.local Default port - ip:brain.local:40000 Port 40000 - ip:192.168.1.119 Default Port - ip:192.168.1.119:40000 Port 40000 - ip:2601:190:400:da:47b3:55ab:3914:bff1 Default Port - ip:[2601:190:400:da:9a90:96ff:feb5:acaa]:40000 Port 40000 - USB backend, "usb:" When more than one usb device is attached, requires bus, address, and interface parts separated with a dot. For example "usb:3.32.5". Where there is only one USB device attached, the shorthand "usb:" can be used. - Serial backend, "serial:" Requires: - a port (/dev/ttyUSB0), - baud_rate (default 115200) - serial port configuration - data bits (5 6 7 8 9) - parity ('n' none, 'o' odd, 'e' even, 'm' mark, 's' space) - stop bits (1 2) - flow control ('\0' none, 'x' Xon Xoff, 'r' RTSCTS, 'd' DTRDSR) For example "serial:/dev/ttyUSB0,115200" or "serial:/dev/ttyUSB0,115200,8n1" See [libiio](https://analogdevicesinc.github.io/libiio/master/libiio/group__Context.html#gafdcee40508700fa395370b6c636e16fe) """ function iio_create_context_from_uri(uri::String) return @check_null ccall((:iio_create_context_from_uri, libiio), Ptr{iio_context}, (Cstring,), uri) end """ iio_context_clone(ctx) Duplicate a pre-existing IIO context. # Parameters - `ctx::Ptr{iio_context}` : A pointer to an [`iio_context`](@ref) structure # Returns - On success, a pointer to an [`iio_context`](@ref) structure - On failure, an error is raised !!! note This function is not supported on 'usb:' contexts, since libusb can only claim the interface once. "Function not implemented" is the expected errno. Any context which is cloned, must be destroyed via calling [`iio_context_destroy()`](@ref) See [libiio](https://analogdevicesinc.github.io/libiio/master/libiio/group__Context.html#ga1815e7c39b9a69aa11cf948b0433df01) """ function iio_context_clone(ctx::Ptr{iio_context}) return @check_null ccall((:iio_context_clone, libiio), Ptr{iio_context}, (Ptr{iio_context},), ctx) end """ iio_context_destroy(ctx) Destroy the given context. # Parameters - `ctx::Ptr{iio_context}` : A pointer to an [`iio_context`](@ref) structure !!! note After that function, the iio_context pointer shall be invalid. See [libiio](https://analogdevicesinc.github.io/libiio/master/libiio/group__Context.html#ga75de8dae515c539818e52b408830d3ba) """ function iio_context_destroy(ctx::Ptr{iio_context}) return @check_null ccall((:iio_context_destroy, libiio), Cvoid, (Ptr{iio_context},), ctx) end """ iio_context_get_version(ctx) Get the version of the backend in use. # Parameters - `ctx::Ptr{iio_context}` : A pointer to an [`iio_context`](@ref) structure # Returns - On success, A 4-Tuple of (0, major, minor, git_tag) is returned - On error, a negative errno code is returned See [libiio](https://analogdevicesinc.github.io/libiio/master/libiio/group__Context.html#ga342bf90d946e7ed3815372db22c4d3a6) """ function iio_context_get_version(ctx::Ptr{iio_context}) major, minor, git_tag = Ref{Cuint}(0), Ref{Cuint}(0), Vector{Cchar}(undef, 8) ret = ccall((:iio_context_get_version, libiio), Cint, (Ptr{iio_context}, Ref{Cuint}, Ref{Cuint}, Ptr{Cchar}), ctx, major, minor, pointer(git_tag)) return ret, UInt(major[]), UInt(minor[]), unsafe_string(pointer(git_tag)) end """ iio_context_get_xml(ctx) Obtain a XML representation of the given context. # Parameters - `ctx::Ptr{iio_context}` : A pointer to an [`iio_context`](@ref) structure # Returns - A `String` containing the XML content. See [libiio](https://analogdevicesinc.github.io/libiio/master/libiio/group__Context.html#ga86554706f17faf41e61e3295dc68a70c) """ function iio_context_get_xml(ctx::Ptr{iio_context}) return unsafe_string(ccall((:iio_context_get_xml, libiio), Cstring, (Ptr{iio_context},), ctx)) end """ iio_context_get_name(ctx) Get the name of the given context. # Parameters - `ctx::Ptr{iio_context}` : A pointer to an [`iio_context`](@ref) structure # Returns - A `String` containing the name !!! note The returned string will be local, xml or network when the context has been created with the local, xml and network backends respectively. See [libiio](https://analogdevicesinc.github.io/libiio/master/libiio/group__Context.html#gafed8e036873ad6f70c3db92c7136ad31) """ function iio_context_get_name(ctx::Ptr{iio_context}) return unsafe_string(ccall((:iio_context_get_name, libiio), Cstring, (Ptr{iio_context},), ctx)) end """ iio_context_get_description(ctx) Get a description of the given context. # Parameters - `ctx::Ptr{iio_context}` : A pointer to an [`iio_context`](@ref) structure # Returns - A `String` containing the description !!! note The returned string will contain human-readable information about the current context. See [libiio](https://analogdevicesinc.github.io/libiio/master/libiio/group__Context.html#ga5591da0927887e88be4ef7d670cb60a9) """ function iio_context_get_description(ctx::Ptr{iio_context}) return unsafe_string(ccall((:iio_context_get_description, libiio), Cstring, (Ptr{iio_context},), ctx)) end """ iio_context_get_attrs_count(ctx) Get the number of context-specific attributes. # Parameters - `ctx::Ptr{iio_context}` : A pointer to an [`iio_context`](@ref) structure # Returns - The number of context-specific attributes Introduced in version 0.9 See [libiio](https://analogdevicesinc.github.io/libiio/master/libiio/group__Context.html#ga91e0c4ed91d760b411d4cbea28c993da) """ function iio_context_get_attrs_count(ctx::Ptr{iio_context}) return ccall((:iio_context_get_attrs_count, libiio), Cuint, (Ptr{iio_context},), ctx) end """ iio_context_get_attr(ctx, index) Retrieve the name and value of a context-specific attribute. # Parameters - `ctx::Ptr{iio_context}` : A pointer to an [`iio_context`](@ref) structure - `index::Cuint` : The index corresponding to the attribute # Returns - On success, a 3-Tuple of (0, name, value) is returned - On error, a negative errno code is returned Introduced in version 0.9 See [libiio](https://analogdevicesinc.github.io/libiio/master/libiio/group__Context.html#ga477dfddaefe0acda401f600247e13fc7) """ function iio_context_get_attr(ctx::Ptr{iio_context}, index::Cuint) name, value = Ref{Cstring}(), Ref{Cstring}() ret = ccall((:iio_context_get_attr, libiio), Cint, (Ptr{iio_context}, Cuint, Ptr{Cstring}, Ptr{Cstring}), ctx, index, name, value) return (ret == 0) ? (ret, unsafe_string(name[]), unsafe_string(value[])) : (ret, "", "") end """ iio_context_get_attr_value(ctx, name) Retrieve the value of a context-specific attribute. # Parameters - `ctx::Ptr{iio_context}` : A pointer to an [`iio_context`](@ref) structure - `name::String` : The name of the context attribute to read # Returns - On success, a `String` with the value of the attribute - If the name does not correspond to any attribute, C_NULL is returned Introduced in version 0.9 See [libiio](https://analogdevicesinc.github.io/libiio/master/libiio/group__Context.html#ga6394d108d425e4a6ed28d00c0e93d6ed) """ function iio_context_get_attr_value(ctx::Ptr{iio_context}, name::String) value = ccall((:iio_context_get_attr_value, libiio), Cstring, (Ptr{iio_context}, Cstring), ctx, name) return value != C_NULL ? unsafe_string(value) : "" end """ iio_context_get_devices_count(ctx) Enumerate the devices found in the given context. # Parameters - `ctx::Ptr{iio_context}` : A pointer to an [`iio_context`](@ref) structure # Returns - The number of devices found See [libiio](https://analogdevicesinc.github.io/libiio/master/libiio/group__Context.html#gab4fc2a93fd5824f3c9e06aa81e8097d1) """ function iio_context_get_devices_count(ctx::Ptr{iio_context}) return ccall((:iio_context_get_devices_count, libiio), Cuint, (Ptr{iio_context},), ctx) end """ iio_context_get_device(ctx, index) Get the device present at the given index. # Parameters - `ctx::Ptr{iio_context}` : A pointer to an [`iio_context`](@ref) structure - `index::Cuint` : The index corresponding to the device # Returns - On success, a pointer to an [`iio_device`](@ref) structure - If the index is invalid, an error is raised See [libiio](https://analogdevicesinc.github.io/libiio/master/libiio/group__Context.html#ga3f2813ff34bf96c7c85dd05909f1c709) """ function iio_context_get_device(ctx::Ptr{iio_context}, index::Cuint) return @check_null ccall((:iio_context_get_device, libiio), Ptr{iio_device}, (Ptr{iio_context}, Cuint), ctx, index) end """ iio_context_find_device(ctx, name) Try to find a device structure by its ID, label or name. # Parameters - `ctx::Ptr{iio_context}` : A pointer to an [`iio_context`](@ref) structure - `name::String` : A string corresponding to the ID, label or name of the device to search for # Returns - On success, a pointer to an [`iio_device`](@ref) structure - If the parameter does not correspond to the ID, label or name of any known device, an error is raised See [libiio](https://analogdevicesinc.github.io/libiio/master/libiio/group__Context.html#gade1dadfb5bc3c3b236add67f803c50c3) """ function iio_context_find_device(ctx::Ptr{iio_context}, name::String) return @check_null ccall((:iio_context_find_device, libiio), Ptr{iio_device}, (Ptr{iio_context}, Cstring), ctx, name) end """ iio_context_set_timeout(ctx, timeout_ms) Set a timeout for I/O operations. # Parameters - `ctx::Ptr{iio_context}` : A pointer to an [`iio_context`](@ref) structure - `timeout_ms::Cuint` : A positive integer representing the time in milliseconds after which a timeout occurs. A value of 0 is used to specify that no timeout should occur. # Returns - On success, 0 is returned - On error, a negative errno code is returned See [libiio](https://analogdevicesinc.github.io/libiio/master/libiio/group__Context.html#gaba3f4c4f9f885f41a6c0b9ac79b7f28d) """ function iio_context_set_timeout(ctx::Ptr{iio_context}, timeout_ms::Cuint) return ccall((:iio_context_set_timeout, libiio), Cint, (Ptr{iio_context}, Cuint), ctx, timeout_ms) end
LibIIO
https://github.com/TacHawkes/LibIIO.jl.git
[ "MIT" ]
0.1.2
47a08b35777450039eaa8e971e1278369931b431
code
4719
#= Empty structs for C pointers =# mutable struct iio_scan_context end mutable struct iio_scan_block end """ The information related to a discovered context See [libiio](https://analogdevicesinc.github.io/libiio/master/libiio/structiio__context__info.html#details) """ mutable struct iio_context_info end """ Contains the representation of an IIO context See [libiio](https://analogdevicesinc.github.io/libiio/master/libiio/structiio__context.html#details) """ mutable struct iio_context end """ Represents a device in the IIO context See [libiio](https://analogdevicesinc.github.io/libiio/master/libiio/structiio__device.html#details) """ mutable struct iio_device end """ Represents an input or output channel of a device See [libiio](https://analogdevicesinc.github.io/libiio/master/libiio/structiio__channel.html#details) """ mutable struct iio_channel end """ An input or output buffer, used to read or write samples See [libiio](https://analogdevicesinc.github.io/libiio/master/libiio/structiio__buffer.html#details) """ mutable struct iio_buffer end """ iio_data_format Contains the format of a data sample. # Data Fields - `length::Cuint` : Total length of the sample in bits - `bits::Cuint` : Length of the valuable data in the samples, in bits - `shift:Cuint` : Right-shift to apply when converting sample - `is_signed::Cuchar` : Contains true if the sample is signed - `is_fully_defined::Cuchar` : Contains true if the sample is fully defoned, sign extended, etc. - `is_be::Cuchar` : Contains true if the sample is in big-endian format - `with_scale::Cuchar` : Contains true if the sample should be scaled or converted - `scale::Cdouble` : Contains the scale to apply if `with_scale` is set - `repeat::Cuint` : Numver of times length repeats See [libiio](https://analogdevicesinc.github.io/libiio/master/libiio/structiio__data__format.html) """ mutable struct iio_data_format length::Cuint bits::Cuint shift::Cuint is_signed::Cuchar is_fully_defined::Cuchar is_be::Cuchar with_scale::Cuchar scale::Cdouble repeat::Cuint end """ iio_modifier IIO channel type. An IIO channel has a type specifying the type of data associated with the channel. See [libiio] (https://analogdevicesinc.github.io/libiio/master/libiio/iio_8h.html#a944ad22f426e09cdbb493081a05472e5) """ @enum iio_modifier begin IIO_NO_MOD IIO_MOD_X IIO_MOD_Y IIO_MOD_Z IIO_MOD_X_AND_Y IIO_MOD_X_AND_Z IIO_MOD_Y_AND_Z IIO_MOD_X_AND_Y_AND_Z IIO_MOD_X_OR_Y IIO_MOD_X_OR_Z IIO_MOD_Y_OR_Z IIO_MOD_X_OR_Y_OR_Z IIO_MOD_LIGHT_BOTH IIO_MOD_LIGHT_IR IIO_MOD_ROOT_SUM_SQUARED_X_Y IIO_MOD_SUM_SQUARED_X_Y_Z IIO_MOD_LIGHT_CLEAR IIO_MOD_LIGHT_RED IIO_MOD_LIGHT_GREEN IIO_MOD_LIGHT_BLUE IIO_MOD_QUATERNION IIO_MOD_TEMP_AMBIENT IIO_MOD_TEMP_OBJECT IIO_MOD_NORTH_MAGN IIO_MOD_NORTH_TRUE IIO_MOD_NORTH_MAGN_TILT_COMP IIO_MOD_NORTH_TRUE_TILT_COMP IIO_MOD_RUNNING IIO_MOD_JOGGING IIO_MOD_WALKING IIO_MOD_STILL IIO_MOD_ROOT_SUM_SQUARED_X_Y_Z IIO_MOD_I IIO_MOD_Q IIO_MOD_CO2 IIO_MOD_VOC IIO_MOD_LIGHT_UV IIO_MOD_LIGHT_DUV IIO_MOD_PM1 IIO_MOD_PM2P5 IIO_MOD_PM4 IIO_MOD_PM10 IIO_MOD_ETHANOL IIO_MOD_H2 IIO_MOD_O2 IIO_MOD_LINEAR_X IIO_MOD_LINEAR_Y IIO_MOD_LINEAR_Z IIO_MOD_PITCH IIO_MOD_YAW IIO_MOD_ROLL end """ iio_chan_type IIO channel type An IIO channel has a type specifying the type of data associated with the channel. See [libiio](https://analogdevicesinc.github.io/libiio/master/libiio/iio_8h.html#a29714c3a5add6b599e29be0485ca548b) """ @enum iio_chan_type begin IIO_VOLTAGE IIO_CURRENT IIO_POWER IIO_ACCEL IIO_ANGL_VEL IIO_MAGN IIO_LIGHT IIO_INTENSITY IIO_PROXIMITY IIO_TEMP IIO_INCLI IIO_ROT IIO_ANGL IIO_TIMESTAMP IIO_CAPACITANCE IIO_ALTVOLTAGE IIO_CCT IIO_PRESSURE IIO_HUMIDITYRELATIVE IIO_ACTIVITY IIO_STEPS IIO_ENERGY IIO_DISTANCE IIO_VELOCITY IIO_CONCENTRATION IIO_RESISTANCE IIO_PH IIO_UVINDEX IIO_ELECTRICALCONDUCTIVITY IIO_COUNT IIO_INDEX IIO_GRAVITY IIO_POSITIONRELATIVE IIO_PHASE IIO_MASSCONCENTRATION IIO_CHAN_TYPE_UNKNOWN = typemax(Cint) end function check_null(input) if input == C_NULL @static if Sys.iswindows() err = Libc.GetLastError() error(Libc.FormatMessage(err)) else err = Libc.errno() error(Libc.strerror(err)) end end return input end macro check_null(ex) quote local val = $(esc(ex)) check_null(val) end end
LibIIO
https://github.com/TacHawkes/LibIIO.jl.git
[ "MIT" ]
0.1.2
47a08b35777450039eaa8e971e1278369931b431
code
19097
""" iio_device_get_sample_size(dev) Get the current sample size. # Parameters - `dev::Ptr{iio_device}` : A pointer to an [`iio_device`](@ref) structure # Returns - On success, the sample size in bytes - On error, a negative errno code is returned !!! note The sample size is not constant and will change when channels get enabled or disabled. See [libiio](https://analogdevicesinc.github.io/libiio/master/libiio/group__Debug.html#ga52b3e955c10d6f962b2c2e749c7c02fb) """ function iio_device_get_sample_size(dev::Ptr{iio_device}) return ccall((:iio_device_get_sample_size, libiio), Cssize_t, (Ptr{iio_device},), dev) end """ iio_channel_get_index(chn) Get the index of the given channel. # Parameters - `chn::Ptr{iio_channel}` : A pointer to an [`iio_channel`](@ref) structure # Returns - On success, a the index of the specified channel - On error, an negative errno code is returned See [libiio](https://analogdevicesinc.github.io/libiio/master/libiio/group__Debug.html#gaf9cc94902b5081bdacc4aed05e7d2412) """ function iio_channel_get_index(chn::Ptr{iio_channel}) return convert(Int, ccall((:iio_channel_get_index, libiio), Clong, (Ptr{iio_channel},), chn)) end """ iio_channel_get_data_format(chn) Get a pointer to a channel's data format structure. # Parameters - `chn::Ptr{iio_channel}` : A pointer to an [`iio_channel`](@ref) structure # Returns - A pointer to the channel's [`iio_data_format`](@ref) structure See [libiio](https://analogdevicesinc.github.io/libiio/master/libiio/group__Debug.html#gadbb2dabfdd85c3f2c6b168f0512c7748) """ function iio_channel_get_data_format(chn::Ptr{iio_channel}) df = ccall((:iio_channel_get_data_format, libiio), Ptr{iio_data_format}, (Ptr{iio_channel},), chn) return unsafe_load(df) end """ iio_channel_convert(chn, dst, src) Convert the sample from hardware format to host format. # Parameters - `chn::Ptr{iio_channel}` : A pointer to an [`iio_channel`](@ref) structure - `dst::Ptr{Cvoid}` : A pointer to the destination buffer where the converted sample should be written - `src::Ptr{Cvoid}` : A pointer to the source buffer containing the sample See [libiio](https://analogdevicesinc.github.io/libiio/master/libiio/group__Debug.html#gaf910dce06335badc1ba307526c4112a6) """ function iio_channel_convert(chn::Ptr{iio_channel}, dst::Ptr{Cvoid}, src::Ptr{Cvoid}) ccall((:iio_channel_convert, libiio), Cvoid, (Ptr{iio_channel_convert}, Ptr{Cvoid}, Ptr{Cvoid}), chn, dst, src) end """ iio_channel_convert_inverse(chn, dst, src) Convert the sample from host format to hardware format. # Parameters - `chn::Ptr{iio_channel}` : A pointer to an [`iio_channel`](@ref) structure - `dst::Ptr{Cvoid}` : A pointer to the destination buffer where the converted sample should be written - `src::Ptr{Cvoid}` : A pointer to the source buffer containing the sample See [libiio](https://analogdevicesinc.github.io/libiio/master/libiio/group__Debug.html#gaf0a9a659af18b62ffa0520301402eabb) """ function iio_channel_convert_inverse(chn::Ptr{iio_channel}, dst::Ptr{Cvoid}, src::Ptr{Cvoid}) ccall((:iio_channel_convert_inverse, libiio), Cvoid, (Ptr{iio_channel_convert}, Ptr{Cvoid}, Ptr{Cvoid}), chn, dst, src) end """ iio_device_get_debug_attrs_count(dev) Enumerate the debug attributes of the given deivce. # Parameters - `dev::Ptr{iio_device}` : A pointer to an [`iio_device`](@ref) structure # Returns - The number of debug attributes found See [libiio](https://analogdevicesinc.github.io/libiio/master/libiio/group__Debug.html#gabacd0e63720d19e7335088c2fd19bbdc) """ function iio_device_get_debug_attrs_count(dev::Ptr{iio_device}) return ccall((:iio_device_get_debug_attrs_count, libiio), Cuint, (Ptr{iio_device},), dev) end """ iio_device_get_debug_attr(dev, index) Get the debug attribute present at the given index. # Parameters - `dev::Ptr{iio_device}` : A pointer to an [`iio_device`] structure - `index::Cuint` : The index corresponding to the debug attribute # Returns - On succes, a string containing the attribute value - If the index is invalid, an empty string is returned See [libiio](https://analogdevicesinc.github.io/libiio/master/libiio/group__Debug.html#gafe451e9a078ed5588b43a4a34cf3b2bc) """ function iio_device_get_debug_attr(dev::Ptr{iio_device}, index::Cuint) attr = ccall((:iio_device_get_debug_attr, libiio), Cstring, (Ptr{iio_device}, Cuint), dev, index) return attr != C_NULL ? unsafe_string(attr) : "" end """ iio_device_find_debug_attr(dev, name) Try to find a debug attribute by its name. # Parameters - `dev::Ptr{iio_device}` : A pointer to an [`iio_device`] structure # Returns - On success, a string with the attribute name - If the name does not correspond to any known debug attribute of the given device, an empty string is returned !!! note This function is useful to detect the presence of a debug attribute. See [libiio](https://analogdevicesinc.github.io/libiio/master/libiio/group__Debug.html#ga2923f184fc57071db9fda14e16c40a9c) """ function iio_device_find_debug_attr(dev::Ptr{iio_device}, name::String) attr = ccall((:iio_device_find_debug_attr, libiio), Cstring, (Ptr{iio_device}, Cstring), dev, name) return attr != C_NULL ? unsafe_string(attr) : "" end """ iio_device_debug_attr_read(dev, attr) Read the content of the given debug attribute. # Parameters - `dev::Ptr{iio_device}` : A pointer to an [`iio_device`](@ref) structure - `attr::String` : A string corresponding to the name of the attribute # Returns - On success, a Vector of Tuples of attribute index and value if `attr` is an empty string, otherwise a string with the attribute value. - On error, a negative errno code is returned !!! note By an empty string as the "attr" argument to [`iio_device_debug_attr_read`](@ref), it is now possible to read all of the buffer attributes of a device. See [libiio](https://analogdevicesinc.github.io/libiio/master/libiio/group__Debug.html#ga8d786ee19093f86da4feb92fb91dd5d7) """ function iio_device_debug_attr_read(dev::Ptr{iio_device}, attr::String) attr == "" && (attr = C_NULL) dst = Vector{Cchar}(undef, BUF_SIZE) ret = ccall((:iio_device_debug_attr_read, libiio), Cssize_t, (Ptr{iio_device}, Cstring, Cstring, Csize_t), dev, attr, pointer(dst), BUF_SIZE) attr == C_NULL ? attrs = iio_parse_attr(dst, ret) : attrs = unsafe_string(pointer(dst)) return ret, attrs end """ iio_device_debug_attr_read_all(dev, cb, data) Read the content of all debug attributes. # Parameters - `dev::Ptr{iio_device}` : A pointer to an [`iio_device`](@ref) structure - `cb::Ptr{Cvoid}` : A pointer to a callback function - `data::Ptr{Cvoid}` : A pointer that will be passed to the callback function # Returns - On success, 0 is returned - On error, a negative errno code is returned !!! note This function is especially useful when used with the network backend, as all the debug attributes are read in one single command. See [libiio](https://analogdevicesinc.github.io/libiio/master/libiio/group__Debug.html#ga1fb487123cf36ea55b650165d49a91ff) """ function iio_device_debug_attr_read_all(dev::Ptr{iio_device}, cb::Ptr{Cvoid}, data::Ptr{Cvoid}) return ccall((:iio_device_debug_attr_read_all, libiio), Cint, (Ptr{iio_device}, Ptr{Cvoid}, Ptr{Cvoid}), dev, cb, data) end """ iio_device_debug_attr_write(dev, attr, src) Set the value of the given debug attribute. # Parameters - `dev::Ptr{iio_device}` : A pointer to an [`iio_device`](@ref) structure - `attr::String` : A string corresponding to the name of the attribute - `src::String` A string to set the attribute to # Returns - On success, the number of bytes written - On error, a negative errno code is returned !!! note By passing `C_NULL` as the "attr" argument to [`iio_device_debug_attr_write`](@ref), it is now possible to write all of the debug attributes of a device. The buffer must contain one block of data per attribute of the device, by the order they appear in the iio_device structure. The first four bytes of one block correspond to a 32-bit signed value in network order. If negative, the attribute is not written; if positive, it corresponds to the length of the data to write. In that case, the rest of the block must contain the data. See [libiio](https://analogdevicesinc.github.io/libiio/master/libiio/group__Debug.html#gaea7f639edb7efd15b718be4c7faaeae5) """ function iio_device_debug_attr_write(dev::Ptr{iio_device}, attr::String, src::String) return ccall((:iio_device_debug_attr_write, libiio), Cssize_t, (Ptr{iio_device}, Cstring, Cstring), dev, attr, src) end """ iio_device_debug_attr_write_raw(dev, attr, src, len) Set the value of the given debug attribute. # Parameters - `dev::Ptr{iio_device}` : A pointer to an [`iio_device`](@ref) structure - `attr::String` : A string corresponding to the name of the attribute - `src::Ptr{Cvoid}` : A pointer to the data to be written - `len::Csize_t` : The number of bytes that should be written # Returns - On success, the number of bytes written - On error, a negative errno code is returned See [libiio](https://analogdevicesinc.github.io/libiio/master/libiio/group__Debug.html#ga1eac5d59a58b6c8e2db892adce7a05a3) """ function iio_device_debug_attr_write_raw(dev::Ptr{iio_device}, attr::String, src::Ptr{Cvoid}, len::Csize_t) return ccall((:iio_device_debug_attr_write_raw, libiio), Cssize_t, (Ptr{iio_device}, Cstring, Ptr{Cvoid}, Csize_t), dev, attr, src, len) end """ iio_device_debug_attr_write_all(dev, cb, data) Set the values of all debug attributes. # Parameters - `dev::Ptr{iio_device}` : A pointer to an [`iio_device`](@ref) structure - `cb::Ptr{Cvoid}` : A pointer to a callback function - `data::Ptr{Cvoid}` : A pointer that will be passed to the callback function # Returns - On success, 0 is returned - On error, a negative errno code is returned !!! note This function is especially useful when used with the network backend, as all the debug attributes are written in one single command. See [libiio](https://analogdevicesinc.github.io/libiio/master/libiio/group__Debug.html#ga57e3af5219859303c2a8629e9b80f9ca) """ function iio_device_debug_attr_write_all(dev::Ptr{iio_device}, cb::Ptr{Cvoid}, data::Ptr{Cvoid}) return ccall((:iio_device_debug_attr_write_all, libiio), Cint, (Ptr{iio_device}, Ptr{Cvoid}, Ptr{Cvoid}), dev, cb, data) end """ iio_device_debug_attr_read_bool(dev, attr) Read the content of the given debug attribute. # Parameters - `dev::Ptr{iio_device}` : A pointer to an [`iio_device`](@ref) structure - `attr::String` : A string corresponding to the name of the attribute # Returns - On success, 0 and the bool value is returned - On error, a negative errno code is returned See [libiio](https://analogdevicesinc.github.io/libiio/master/libiio/group__Debug.html#gadffd69effb8ff8ddb504ea9492a29529) """ function iio_device_debug_attr_read_bool(dev::Ptr{iio_device}, attr::String) value = Ref{Cuchar}(0) ret = ccall((:iio_device_debug_attr_read_bool, libiio), Cint, (Ptr{iio_device}, Cstring, Ptr{Cuchar}), dev, attr, value) return ret, convert(Bool, value[]) end """ iio_device_debug_attr_read_longlong(dev, attr) Read the content of the given debug attribute. # Parameters - `dev::Ptr{iio_device}` : A pointer to an [`iio_device`](@ref) structure - `attr::String` : A string corresponding to the name of the attribute # Returns - On success, 0 and the Clonglong value is returned - On error, a negative errno code is returned See [libiio](https://analogdevicesinc.github.io/libiio/master/libiio/group__Debug.html#gaff27d1a48f8469531c25471918d0b6de) """ function iio_device_debug_attr_read_longlong(dev::Ptr{iio_device}, attr::String) value = Ref{Clonglong}(0) ret = ccall((:iio_device_debug_attr_read_longlong, libiio), Cint, (Ptr{iio_device}, Cstring, Ptr{Clonglong}), dev, attr, value) return ret, value[] end """ iio_device_debug_attr_read_double(dev, attr) Read the content of the given debug attribute. # Parameters - `dev::Ptr{iio_device}` : A pointer to an [`iio_device`](@ref) structure - `attr::String` : A string corresponding to the name of the attribute # Returns - On success, 0 and the Cdouble value is returned - On error, a negative errno code is returned See [libiio](https://analogdevicesinc.github.io/libiio/master/libiio/group__Debug.html#ga1356356c2eebcb56df2d72e93042d896) """ function iio_device_debug_attr_read_double(dev::Ptr{iio_device}, attr::String) value = Ref{Cdouble}(0) ret = ccall((:iio_device_debug_attr_read_double, libiio), Cint, (Ptr{iio_device}, Cstring, Ptr{Cdouble}), dev, attr, value) return ret, value[] end """ iio_device_debug_attr_write_bool(dev, attr, val) Set the value of the given debug attribute. # Parameters - `dev::Ptr{iio_device}` : A pointer to an [`iio_device`](@ref) structure - `attr::String` : A string corresponding to the name of the attribute - `val::Bool` : A bool value to set the attribute to # Returns - On success, 0 is returned - On error, a negative errno code is returned See [libiio](https://analogdevicesinc.github.io/libiio/master/libiio/group__Debug.html#ga40579d97ca0b68f2244bed67ece80ce6) """ function iio_device_debug_attr_write_bool(dev::Ptr{iio_device}, attr::String, val::Bool) return ccall((:iio_device_debug_attr_write_bool, libiio), Cint, (Ptr{iio_device}, Cstring, Cuchar), dev, attr, val) end """ iio_device_debug_attr_write_longlong(dev, attr, val) Set the value of the given debug attribute. # Parameters - `dev::Ptr{iio_device}` : A pointer to an [`iio_device`](@ref) structure - `attr::String` : A string corresponding to the name of the attribute - `val::Clonglong` : A Clonglong value to set the attribute to # Returns - On success, 0 is returned - On error, a negative errno code is returned See [libiio](https://analogdevicesinc.github.io/libiio/master/libiio/group__Debug.html#ga22df5b7b0606a9e453fac421d15e6fb2) """ function iio_device_debug_attr_write_longlong(dev::Ptr{iio_device}, attr::String, val::Clonglong) return ccall((:iio_device_debug_attr_write_longlong, libiio), Cint, (Ptr{iio_device}, Cstring, Clonglong), dev, attr, val) end """ iio_device_debug_attr_write_double(dev, attr, val) Set the value of the given debug attribute. # Parameters - `dev::Ptr{iio_device}` : A pointer to an [`iio_device`](@ref) structure - `attr::String` : A string corresponding to the name of the attribute - `val::Cdouble` : A Cdouble value to set the attribute to # Returns - On success, 0 is returned - On error, a negative errno code is returned See [libiio](https://analogdevicesinc.github.io/libiio/master/libiio/group__Debug.html#ga2a4e26d2d33db7fe9fc76d3034cb264f) """ function iio_device_debug_attr_write_double(dev::Ptr{iio_device}, attr::String, val::Cdouble) return ccall((:iio_device_debug_attr_write_double, libiio), Cint, (Ptr{iio_device}, Cstring, Cdouble), dev, attr, val) end """ iio_device_identify_filename(dev, filename, chn, attr) Identify the channel or debug attribute corresponding to a filename. # Parameters - `dev::Ptr{iio_device}` : A pointer to an [`iio_device`](@ref) structure - `filename::String` : A string corresponding to the filename - `chn::Ptr{Ptr{iio_channel}}` : A pointer to a pointer of an [`iio_channel`](@ref). The pointed pointer will be set to the address of the [`iio_channel`](@ref) structure if the filename correspond to the attribute of a channel, or `C_NULL` otherwise. - `attr::String` : A string field. The string will be set to the name of the attribute corresponding to the filename. # Returns - On success, 0 is returned, and chn and attr are modified - On error, a negative errno code is returned. chn and attr are not modified. See [libiio](https://analogdevicesinc.github.io/libiio/master/libiio/group__Debug.html#ga87ef46fa578c7be7b3e2a6f9f16fdf7e) """ function iio_device_identify_filename(dev::Ptr{iio_device}, filename::String, chn::Ptr{Ptr{iio_channel}}, attr::String) return ccall((:iio_device_identify_filename, libiio), Cint, (Ptr{iio_device}, Cstring, Ptr{Ptr{iio_channel}}, Cstring), dev, filename, chn, attr) end """ iio_device_reg_write(dev, address, value) Set the value of a hardware register. # Parameters - `dev::Ptr{iio_device}` : A pointer to an [`iio_device`](@ref) structure - `address::Cuint` : The address of the register - `value::Cuint` : The value to set the register to # Returns - On success, 0 is returned - On error, a negative errno code is returned See [libiio](https://analogdevicesinc.github.io/libiio/master/libiio/group__Debug.html#ga170d5a84de1d5fdb987113aa90e2a19b) """ function iio_device_reg_write(dev::Ptr{iio_device}, address::Cuint, value::Cuint) return ccall((:iio_device_reg_write, libiio), Cint, (Ptr{iio_device}, Cuint, Cuint), dev, address, value) end """ iio_device_reg_read(dev, address) Get the value of a hardware register. # Parameters - `dev::Ptr{iio_device}` : A pointer to an [`iio_device`](@ref) structure - `address::Cuint` : The address of the register # Returns - On success, 0 and the register value is returned - On error, a negative errno code is returned See [libiio](https://analogdevicesinc.github.io/libiio/master/libiio/group__Debug.html#ga70829552f676ef9fc74e755933da05d8) """ function iio_device_reg_read(dev::Ptr{iio_device}, address::Cuint) value = Ref{Cuint}() ret = ccall((:iio_device_reg_read, libiio), Cint, (Ptr{iio_device}, Cuint, Ptr{Cuint}), dev, address, value) return ret, value[] end
LibIIO
https://github.com/TacHawkes/LibIIO.jl.git
[ "MIT" ]
0.1.2
47a08b35777450039eaa8e971e1278369931b431
code
35087
""" iio_device_get_context(dev) Retrieve a pointer to the [`iio_context`](@ref) structure. # Parameters - `dev::Ptr{iio_device}` : A pointer to an [`iio_device`](@ref) structure # Returns - A pointer to an [`iio_context`](@ref) See [libiio](https://analogdevicesinc.github.io/libiio/master/libiio/group__Device.html#gacc7d7b43ca5a1e228ef4c3a4952195fd) """ function iio_device_get_context(dev::Ptr{iio_device}) return ccall((:iio_device_get_context, libiio), Ptr{iio_context}, (Ptr{iio_device},), dev) end """ iio_device_get_id(dev) Retrieve the device ID (e.g. **iio:device0**) # Parameters - `dev::Ptr{iio_device}` : A pointer to an [`iio_device`](@ref) structure # Returns - A string containing the id See [libiio](https://analogdevicesinc.github.io/libiio/master/libiio/group__Device.html#ga9e6610c3dd7cc45bebcc7ed7a1b064c6) """ function iio_device_get_id(dev::Ptr{iio_device}) return unsafe_string(ccall((:iio_device_get_id, libiio), Cstring, (Ptr{iio_device},), dev)) end """ iio_device_get_name(dev) Retrieve the device name (e.g. `xadc`) # Parameters - `dev::Ptr{iio_device}` : A pointer to an [`iio_device`](@ref) structure # Returns - A string containing the name !!! note If the device has no name, an empty string is returned See [libiio](https://analogdevicesinc.github.io/libiio/master/libiio/group__Device.html#ga711666b3b3b6314fbe7e592b4632ab85) """ function iio_device_get_name(dev::Ptr{iio_device}) name = ccall((:iio_device_get_name, libiio), Cstring, (Ptr{iio_device},), dev) return name != C_NULL ? unsafe_string(name) : "" end """ iio_device_get_label(dev) Retrieve the device label (e.g. `lo_pll0_rx_adf4351`) # Parameters - `dev::Ptr{iio_device}` : A pointer to an [`iio_device`](@ref) structure # Returns - A string containing the label !!! note If the device has no label, an empty string is returned See [libiio](https://analogdevicesinc.github.io/libiio/master/libiio/group__Device.html#gaa7dfffe6431d1f36abf523470e866641) """ function iio_device_get_label(dev::Ptr{iio_device}) label = ccall((:iio_device_get_label, libiio), Cstring, (Ptr{iio_device},), dev) label != C_NULL ? unsafe_string(label) : "" end """ iio_device_get_channels_count(dev) Enumerate the channels of the given device. # Parameters - `dev::Ptr{iio_device}` : A pointer to an [`iio_device`](@ref) structure # Returns - The number of channels found See [libiio](https://analogdevicesinc.github.io/libiio/master/libiio/group__Device.html#gae10ff440f64dac52b4229eb3f2ebea76) """ function iio_device_get_channels_count(dev::Ptr{iio_device}) return ccall((:iio_device_get_channels_count, libiio), Cuint, (Ptr{iio_device},), dev) end """ iio_device_get_attrs_count(dev) Enumerate the device-specific attributes of the given device. # Parameters - `dev::Ptr{iio_device}` : A pointer to an [`iio_device`](@ref) structure # Returns - The number of device-specific attributes found See [libiio](https://analogdevicesinc.github.io/libiio/master/libiio/group__Device.html#ga36c2d0f703a803f44a578bc83fdab6a0) """ function iio_device_get_attrs_count(dev::Ptr{iio_device}) return ccall((:iio_device_get_attrs_count, libiio), Cuint, (Ptr{iio_device},), dev) end """ iio_device_get_buffer_attrs_count(dev) Enumerate the buffer-specific attributes of the given device. # Parameters - `dev::Ptr{iio_device}` : A pointer to an [`iio_device`](@ref) structure # Returns - The number of buffer-specific attributes found See [libiio](https://analogdevicesinc.github.io/libiio/master/libiio/group__Device.html#ga6d4bd3c4f9791c706d9baa4454e0f1d3) """ function iio_device_get_buffer_attrs_count(dev::Ptr{iio_device}) return ccall((:iio_device_get_buffer_attrs_count, libiio), Cuint, (Ptr{iio_device},), dev) end """ iio_device_get_channel(dev, index) Get the channel present at the given index. # Parameters - `dev::Ptr{iio_device}` : A pointer to an [`iio_device`](@ref) structure - `index::Cuint` : The index corresponding to the channel # Returns - On success, a pointer to an [`iio_channel`](@ref) - If the index is invalid, an error is raised See [libiio](https://analogdevicesinc.github.io/libiio/master/libiio/group__Device.html#ga67289d735b7d8e1ed12ae0ea642bd1ac) """ function iio_device_get_channel(dev::Ptr{iio_device}, index::Cuint) return @check_null ccall((:iio_device_get_channel, libiio), Ptr{iio_channel}, (Ptr{iio_device}, Cuint), dev, index) end """ iio_device_get_attr(dev, index) Get the device-specific attribute present at the given index. # Parameters - `dev::Ptr{iio_device}` : A pointer to an [`iio_device`](@ref) structure - `index::Cuint` : The index corresponding to the attribute # Returns - On success, a string containing the attribute name - If the index is invalid, an empty string will be returned See [libiio](https://analogdevicesinc.github.io/libiio/master/libiio/group__Device.html#ga70b03d4cb3cc3c4fb1b6451764c8ccec) """ function iio_device_get_attr(dev::Ptr{iio_device}, index::Cuint) attr = ccall((:iio_device_get_attr, libiio), Cstring, (Ptr{iio_device}, Cuint), dev, index) return attr != C_NULL ? unsafe_string(attr) : "" end """ iio_device_get_buffer_attr(dev, index) Get the buffer-specific attribute present at the given index. # Parameters - `dev::Ptr{iio_device}` : A pointer to an [`iio_device`](@ref) structure - `index::Cuint` : The index corresponding to the attribute # Returns - On success, a string containing the attribute name - If the index is invalid, an empty string will be returned See [libiio](https://analogdevicesinc.github.io/libiio/master/libiio/group__Device.html#ga7225b9df06559012d549d627fb451c2a) """ function iio_device_get_buffer_attr(dev::Ptr{iio_device}, index::Cuint) attr = ccall((:iio_device_get_buffer_attr, libiio), Cstring, (Ptr{iio_device}, Cuint), dev, index) return attr != C_NULL ? unsafe_string(attr) : "" end """ iio_device_find_channel(dev, name, output) Try to find a channel structure by its name or ID. # Parameters - `dev::Ptr{iio_device}` : A pointer to an [`iio_device`](@ref) structure - `name::String` : A string corresponding to the name or ID of the channel to search for - `output::Bool` : True if the searched channel is output, false otherwise # Returns - On success, a pointer to an [`iio_channel`](@ref) structure - If the name or ID does not correspond to any known channel of the given device, an error is raised See [libiio](https://analogdevicesinc.github.io/libiio/master/libiio/group__Device.html#gaffc6086189ba801ab5e95341d68f882b) """ function iio_device_find_channel(dev::Ptr{iio_device}, name::String, output::Bool) return @check_null ccall((:iio_device_find_channel, libiio), Ptr{iio_channel}, (Ptr{iio_device}, Cstring, Cuchar), dev, name, output) end """ iio_device_find_attr(dev, name) Try to find a device-specific attribute by its name. # Parameters - `dev::Ptr{iio_device}` : A pointer to an [`iio_device`](@ref) structure - `name::String` : A string corresponding to the name of the attribute # Returns - On succes, a string containing the attribute name - If the name does not correspond to any know aatribute of the device, an empty string is returned !!! note This function is useful to detect the presence of an attribute. See [libiio](https://analogdevicesinc.github.io/libiio/master/libiio/group__Device.html#gafcbece1ac6260b06bcdf02d9eb55e5fd) """ function iio_device_find_attr(dev::Ptr{iio_device}, name::String) attr = ccall((:iio_device_find_attr, libiio), Cstring, (Ptr{iio_device}, Cstring), dev, name) return attr != C_NULL ? unsafe_string(attr) : "" end """ iio_device_find_buffer_attr(dev, name) Try to find a buffer-specific attribute by its name. # Parameters - `dev::Ptr{iio_device}` : A pointer to an [`iio_device`](@ref) structure - `name::String` : A string corresponding to the name of the attribute # Returns - On succes, a string containing the attribute name - If the name does not correspond to any know aatribute of the device, an empty string is returned !!! note This function is useful to detect the presence of an attribute. See [libiio](https://analogdevicesinc.github.io/libiio/master/libiio/group__Device.html#ga58baa15da06b2d497fb0334f35264240) """ function iio_device_find_buffer_attr(dev::Ptr{iio_device}, name::String) attr = ccall((:iio_device_find_buffer_attr, libiio), Cstring, (Ptr{iio_device}, Cstring), dev, name) return attr != C_NULL ? unsafe_string(attr) : "" end """ iio_device_attr_read(dev, attr) Read the content of the given device-specific attribute. # Parameters - `dev::Ptr{iio_device}` : A pointer to an [`iio_device`](@ref) structure - `attr::String` : A string corresponding to the name of the attribute # Returns - On success, a string with the attribute value. - On error, a negative errno code is returned !!! note This function deviates from the C library [`iio_device_attr_read`](@ref). Instead of passing an empty string, call the function without the attr argument. See [libiio](https://analogdevicesinc.github.io/libiio/master/libiio/group__Device.html#gaf0233eb0ef4a64ad70ebaef6328b0494) """ function iio_device_attr_read(dev::Ptr{iio_device}, attr::String) dst = DST_BUFFER ret = ccall((:iio_device_attr_read, libiio), Cssize_t, (Ptr{iio_device}, Cstring, Cstring, Csize_t), dev, attr, pointer(dst), BUF_SIZE) attrs = unsafe_string(pointer(dst)) return ret, attrs end """ iio_device_attr_read(dev) Read the content of the given device-specific attribute. # Parameters - `dev::Ptr{iio_device}` : A pointer to an [`iio_device`](@ref) structure # Returns - On success, a Vector of Tuples of attribute index and value - On error, a negative errno code is returned See [libiio](https://analogdevicesinc.github.io/libiio/master/libiio/group__Device.html#gaf0233eb0ef4a64ad70ebaef6328b0494) """ function iio_device_attr_read(dev::Ptr{iio_device}) attr = C_NULL dst = DST_BUFFER ret = ccall((:iio_device_attr_read, libiio), Cssize_t, (Ptr{iio_device}, Cstring, Cstring, Csize_t), dev, attr, pointer(dst), BUF_SIZE) attrs = iio_parse_attr(dst, ret) return ret, attrs end """ iio_device_attr_read_all(dev, cb, data) Read the content of all device-specific attributes. # Parameters - `dev::Ptr{iio_device}` : A pointer to an [`iio_device`](@ref) structure - `cb::Ptr{Cvoid}` : A pointer to a callback function - `data::Ptr{Cvoid}` : A pointer that will be passed to the callback function # Returns - On success, 0 is returned - On error, a negative errno code is returned !!! note This function is especially useful when used with the network backend, as all the device-specific attributes are read in one single command. See [libiio](https://analogdevicesinc.github.io/libiio/master/libiio/group__Device.html#ga5b1fef1333c4835942384b661f148b36) """ function iio_device_attr_read_all(dev::Ptr{iio_device}, cb::Ptr{Cvoid}, data::Ptr{Cvoid}) return ccall((:iio_device_attr_read_all, libiio), Cint, (Ptr{iio_device}, Ptr{Cvoid}, Ptr{Cvoid}), dev, cb, data) end """ iio_device_attr_read_bool(dev, attr) Read the content of the given device-specific attribute. # Parameters - `dev::Ptr{iio_device}` : A pointer to an [`iio_device`](@ref) structure - `attr::String` : A string corresponding to the name of the attribute # Returns - On success, 0 and the bool value is returned - On error, a negative errno code is returned See [libiio](https://analogdevicesinc.github.io/libiio/master/libiio/group__Device.html#ga96364b7c7097bb8e4656924ea896a502) """ function iio_device_attr_read_bool(dev::Ptr{iio_device}, attr::String) value = Ref{Cuchar}(0) ret = ccall((:iio_device_attr_read_bool, libiio), Cint, (Ptr{iio_device}, Cstring, Ptr{Cuchar}), dev, attr, value) return ret, convert(Bool, value[]) end """ iio_device_attr_read_longlong(dev, attr) Read the content of the given device-specific attribute. # Parameters - `dev::Ptr{iio_device}` : A pointer to an [`iio_device`](@ref) structure - `attr::String` : A string corresponding to the name of the attribute # Returns - On success, 0 and the Clonglong value is returned - On error, a negative errno code is returned See [libiio](https://analogdevicesinc.github.io/libiio/master/libiio/group__Device.html#ga0f7b5d21a4e40efac68e1ece44d7ba74) """ function iio_device_attr_read_longlong(dev::Ptr{iio_device}, attr::String) value = Ref{Clonglong}(0) ret = ccall((:iio_device_attr_read_longlong, libiio), Cint, (Ptr{iio_device}, Cstring, Ptr{Clonglong}), dev, attr, value) return ret, value[] end """ iio_device_attr_read_double(dev, attr) Read the content of the given device-specific attribute. # Parameters - `dev::Ptr{iio_device}` : A pointer to an [`iio_device`](@ref) structure - `attr::String` : A string corresponding to the name of the attribute # Returns - On success, 0 and the Cdouble value is returned - On error, a negative errno code is returned See [libiio](https://analogdevicesinc.github.io/libiio/master/libiio/group__Device.html#gab1b150a5bfa7b1ab7fd76c538e15e4da) """ function iio_device_attr_read_double(dev::Ptr{iio_device}, attr::String) value = Ref{Cdouble}(0) ret = ccall((:iio_device_attr_read_double, libiio), Cint, (Ptr{iio_device}, Cstring, Ptr{Cdouble}), dev, attr, value) return ret, value[] end """ iio_device_attr_write(dev, attr, src) Set the value of the given device-specific attribute. # Parameters - `dev::Ptr{iio_device}` : A pointer to an [`iio_device`](@ref) structure - `attr::String` : A string corresponding to the name of the attribute - `src::String` A string to set the attribute to # Returns - On success, the number of bytes written - On error, a negative errno code is returned !!! note By passing `C_NULL` as the "attr" argument to [`iio_device_attr_write`](@ref), it is now possible to write all of the attributes of a device. The buffer must contain one block of data per attribute of the device, by the order they appear in the iio_device structure. The first four bytes of one block correspond to a 32-bit signed value in network order. If negative, the attribute is not written; if positive, it corresponds to the length of the data to write. In that case, the rest of the block must contain the data. See [libiio](https://analogdevicesinc.github.io/libiio/master/libiio/group__Device.html#gaaa2d1867c15ef8f8424164d0ccea4dd8) """ function iio_device_attr_write(dev::Ptr{iio_device}, attr::String, src::String) return ccall((:iio_device_attr_write, libiio), Cssize_t, (Ptr{iio_device}, Cstring, Cstring), dev, attr, src) end """ iio_device_attr_write_raw(dev, attr, src, len) Set the value of the given device-specific attribute. # Parameters - `dev::Ptr{iio_device}` : A pointer to an [`iio_device`](@ref) structure - `attr::String` : A string corresponding to the name of the attribute - `src::Ptr{Cvoid}` : A pointer to the data to be written - `len::Csize_t` : The number of bytes that should be written # Returns - On success, the number of bytes written - On error, a negative errno code is returned See [libiio](https://analogdevicesinc.github.io/libiio/master/libiio/group__Device.html#ga30829a67dcdffc902c4ba6801233e79a) """ function iio_device_attr_write_raw(dev::Ptr{iio_device}, attr::String, src::Ptr{Cvoid}, len::Csize_t) return ccall((:iio_device_attr_write_raw, libiio), Cssize_t, (Ptr{iio_device}, Cstring, Ptr{Cvoid}, Csize_t), dev, attr, src, len) end """ iio_device_attr_write_all(dev, cb, data) Set the values of all device-specifc attributes. # Parameters - `dev::Ptr{iio_device}` : A pointer to an [`iio_device`](@ref) structure - `cb::Ptr{Cvoid}` : A pointer to a callback function - `data::Ptr{Cvoid}` : A pointer that will be passed to the callback function # Returns - On success, 0 is returned - On error, a negative errno code is returned !!! note This function is especially useful when used with the network backend, as all the device-specific attributes are written in one single command. See [libiio](https://analogdevicesinc.github.io/libiio/master/libiio/group__Device.html#gadfbbfafabc32d6954d3f3dfcda957735) """ function iio_device_attr_write_all(dev::Ptr{iio_device}, cb::Ptr{Cvoid}, data::Ptr{Cvoid}) return ccall((:iio_device_attr_write_all, libiio), Cint, (Ptr{iio_device}, Ptr{Cvoid}, Ptr{Cvoid}), dev, cb, data) end """ iio_device_attr_write_bool(dev, attr, val) Set the value of the given device-specific attribute. # Parameters - `dev::Ptr{iio_device}` : A pointer to an [`iio_device`](@ref) structure - `attr::String` : A string corresponding to the name of the attribute - `val::Bool` : A bool value to set the attribute to # Returns - On success, 0 is returned - On error, a negative errno code is returned See [libiio](https://analogdevicesinc.github.io/libiio/master/libiio/group__Device.html#ga9f53f9d1c3dc9f87191943fcbd1a7324) """ function iio_device_attr_write_bool(dev::Ptr{iio_device}, attr::String, val::Bool) return ccall((:iio_device_attr_write_bool, libiio), Cint, (Ptr{iio_device}, Cstring, Cuchar), dev, attr, val) end """ iio_device_attr_write_longlong(dev, attr, val) Set the value of the given device-specific attribute. # Parameters - `dev::Ptr{iio_device}` : A pointer to an [`iio_device`](@ref) structure - `attr::String` : A string corresponding to the name of the attribute - `val::Clonglong` : A Clonglong value to set the attribute to # Returns - On success, 0 is returned - On error, a negative errno code is returned See [libiio](https://analogdevicesinc.github.io/libiio/master/libiio/group__Device.html#ga3fcba684f6b07d3f6295759bb788c4d2) """ function iio_device_attr_write_longlong(dev::Ptr{iio_device}, attr::String, val::Clonglong) return ccall((:iio_device_attr_write_longlong, libiio), Cint, (Ptr{iio_device}, Cstring, Clonglong), dev, attr, val) end """ iio_device_attr_write_double(dev, attr, val) Set the value of the given device-specific attribute. # Parameters - `dev::Ptr{iio_device}` : A pointer to an [`iio_device`](@ref) structure - `attr::String` : A string corresponding to the name of the attribute - `val::Cdouble` : A Cdouble value to set the attribute to # Returns - On success, 0 is returned - On error, a negative errno code is returned See [libiio](https://analogdevicesinc.github.io/libiio/master/libiio/group__Device.html#gacdaf529f12b46ba2a5290bbc590c8b9e) """ function iio_device_attr_write_double(dev::Ptr{iio_device}, attr::String, val::Cdouble) return ccall((:iio_device_attr_write_double, libiio), Cint, (Ptr{iio_device}, Cstring, Cdouble), dev, attr, val) end """ iio_device_buffer_attr_read(dev, attr) Read the content of the given buffer-specific attribute. # Parameters - `dev::Ptr{iio_device}` : A pointer to an [`iio_device`](@ref) structure - `attr::String` : A string corresponding to the name of the attribute # Returns - On success, a Vector of Tuples of attribute index and value if `attr` is an empty string, otherwise a string with the attribute value. - On error, a negative errno code is returned !!! note By an empty string as the "attr" argument to [`iio_device_buffer_attr_read`](@ref), it is now possible to read all of the buffer attributes of a device. See [libiio](https://analogdevicesinc.github.io/libiio/master/libiio/group__Device.html#gaa77d52bb9dea248cc3de682778a08a6f) """ function iio_device_buffer_attr_read(dev::Ptr{iio_device}, attr::String) attr == "" && (attr = C_NULL) dst = Vector{Cchar}(undef, BUF_SIZE) ret = ccall((:iio_device_buffer_attr_read, libiio), Cssize_t, (Ptr{iio_device}, Cstring, Cstring, Csize_t), dev, attr, pointer(dst), BUF_SIZE) attr == C_NULL ? attrs = iio_parse_attr(dst, ret) : attrs = unsafe_string(pointer(dst)) return ret, attrs end """ iio_device_buffer_attr_read_all(dev, cb, data) Read the content of all buffer-specific attributes. # Parameters - `dev::Ptr{iio_device}` : A pointer to an [`iio_device`](@ref) structure - `cb::Ptr{Cvoid}` : A pointer to a callback function - `data::Ptr{Cvoid}` : A pointer that will be passed to the callback function # Returns - On success, 0 is returned - On error, a negative errno code is returned !!! note This function is especially useful when used with the network backend, as all the buffer-specific attributes are read in one single command. See [libiio](https://analogdevicesinc.github.io/libiio/master/libiio/group__Device.html#gaae5bf33ad1bd1b14155eab4a018c576c) """ function iio_device_buffer_attr_read_all(dev::Ptr{iio_device}, cb::Ptr{Cvoid}, data::Ptr{Cvoid}) return ccall((:iio_device_buffer_attr_read_all, libiio), Cint, (Ptr{iio_device}, Ptr{Cvoid}, Ptr{Cvoid}), dev, cb, data) end """ iio_device_buffer_attr_read_bool(dev, attr) Read the content of the given buffer-specific attribute. # Parameters - `dev::Ptr{iio_device}` : A pointer to an [`iio_device`](@ref) structure - `attr::String` : A string corresponding to the name of the attribute # Returns - On success, 0 and the bool value is returned - On error, a negative errno code is returned See [libiio](https://analogdevicesinc.github.io/libiio/master/libiio/group__Device.html#ga92ee863b94e6f841efec3919f57f5193) """ function iio_device_buffer_attr_read_bool(dev::Ptr{iio_device}, attr::String) value = Ref{Cuchar}(0) ret = ccall((:iio_device_buffer_attr_read_bool, libiio), Cint, (Ptr{iio_device}, Cstring, Ptr{Cuchar}), dev, attr, value) return ret, convert(Bool, value[]) end """ iio_device_buffer_attr_read_longlong(dev, attr) Read the content of the given buffer-specific attribute. # Parameters - `dev::Ptr{iio_device}` : A pointer to an [`iio_device`](@ref) structure - `attr::String` : A string corresponding to the name of the attribute # Returns - On success, 0 and the Clonglong value is returned - On error, a negative errno code is returned See [libiio](https://analogdevicesinc.github.io/libiio/master/libiio/group__Device.html#gae5b9be890edb372d3e30a14ce1c79874) """ function iio_device_buffer_attr_read_longlong(dev::Ptr{iio_device}, attr::String) value = Ref{Clonglong}(0) ret = ccall((:iio_device_buffer_attr_read_longlong, libiio), Cint, (Ptr{iio_device}, Cstring, Ptr{Clonglong}), dev, attr, value) return ret, value[] end """ iio_device_buffer_attr_read_double(dev, attr) Read the content of the given buffer-specific attribute. # Parameters - `dev::Ptr{iio_device}` : A pointer to an [`iio_device`](@ref) structure - `attr::String` : A string corresponding to the name of the attribute # Returns - On success, 0 and the Cdouble value is returned - On error, a negative errno code is returned See [libiio](https://analogdevicesinc.github.io/libiio/master/libiio/group__Device.html#ga44952198b73ff6b0c0c0b53d3cd6d1bd) """ function iio_device_buffer_attr_read_double(dev::Ptr{iio_device}, attr::String) value = Ref{Cdouble}(0) ret = ccall((:iio_device_buffer_attr_read_double, libiio), Cint, (Ptr{iio_device}, Cstring, Ptr{Cdouble}), dev, attr, value) return ret, value[] end """ iio_device_buffer_attr_write(dev, attr, src) Set the value of the given buffer-specific attribute. # Parameters - `dev::Ptr{iio_device}` : A pointer to an [`iio_device`](@ref) structure - `attr::String` : A string corresponding to the name of the attribute - `src::String` A string to set the attribute to # Returns - On success, the number of bytes written - On error, a negative errno code is returned !!! note By passing `C_NULL` as the "attr" argument to [`iio_device_buffer_attr_write`](@ref), it is now possible to write all of the attributes of a device. The buffer must contain one block of data per attribute of the device, by the order they appear in the iio_device structure. The first four bytes of one block correspond to a 32-bit signed value in network order. If negative, the attribute is not written; if positive, it corresponds to the length of the data to write. In that case, the rest of the block must contain the data. See [libiio](https://analogdevicesinc.github.io/libiio/master/libiio/group__Device.html#ga3d77bb90c22eb1d0a13805bf69def068) """ function iio_device_buffer_attr_write(dev::Ptr{iio_device}, attr::String, src::String) return ccall((:iio_device_buffer_attr_write, libiio), Cssize_t, (Ptr{iio_device}, Cstring, Cstring), dev, attr, src) end """ iio_device_buffer_attr_write_raw(dev, attr, src, len) Set the value of the given buffer-specific attribute. # Parameters - `dev::Ptr{iio_device}` : A pointer to an [`iio_device`](@ref) structure - `attr::String` : A string corresponding to the name of the attribute - `src::Ptr{Cvoid}` : A pointer to the data to be written - `len::Csize_t` : The number of bytes that should be written # Returns - On success, the number of bytes written - On error, a negative errno code is returned See [libiio](https://analogdevicesinc.github.io/libiio/master/libiio/group__Device.html#ga982e2bcb890aab88eabf833a00ba841a) """ function iio_device_buffer_attr_write_raw(dev::Ptr{iio_device}, attr::String, src::Ptr{Cvoid}, len::Csize_t) return ccall((:iio_device_buffer_attr_write_raw, libiio), Cssize_t, (Ptr{iio_device}, Cstring, Ptr{Cvoid}, Csize_t), dev, attr, src, len) end """ iio_device_buffer_attr_write_all(dev, cb, data) Set the values of all buffer-specific attributes. # Parameters - `dev::Ptr{iio_device}` : A pointer to an [`iio_device`](@ref) structure - `cb::Ptr{Cvoid}` : A pointer to a callback function - `data::Ptr{Cvoid}` : A pointer that will be passed to the callback function # Returns - On success, 0 is returned - On error, a negative errno code is returned !!! note This function is especially useful when used with the network backend, as all the buffer-specific attributes are written in one single command. See [libiio](https://analogdevicesinc.github.io/libiio/master/libiio/group__Device.html#ga3d77bb90c22eb1d0a13805bf69def068) """ function iio_device_buffer_attr_write_all(dev::Ptr{iio_device}, cb::Ptr{Cvoid}, data::Ptr{Cvoid}) return ccall((:iio_device_buffer_attr_write_all, libiio), Cint, (Ptr{iio_device}, Ptr{Cvoid}, Ptr{Cvoid}), dev, cb, data) end """ iio_device_buffer_attr_write_bool(dev, attr, val) Set the value of the given buffer-specific attribute. # Parameters - `dev::Ptr{iio_device}` : A pointer to an [`iio_device`](@ref) structure - `attr::String` : A string corresponding to the name of the attribute - `val::Bool` : A bool value to set the attribute to # Returns - On success, 0 is returned - On error, a negative errno code is returned See [libiio](https://analogdevicesinc.github.io/libiio/master/libiio/group__Device.html#ga3fad39798014287c24c36bac4a67648e) """ function iio_device_buffer_attr_write_bool(dev::Ptr{iio_device}, attr::String, val::Bool) return ccall((:iio_device_buffer_attr_write_bool, libiio), Cint, (Ptr{iio_device}, Cstring, Cuchar), dev, attr, val) end """ iio_device_buffer_attr_write_longlong(dev, attr, val) Set the value of the given buffer-specific attribute. # Parameters - `dev::Ptr{iio_device}` : A pointer to an [`iio_device`](@ref) structure - `attr::String` : A string corresponding to the name of the attribute - `val::Clonglong` : A Clonglong value to set the attribute to # Returns - On success, 0 is returned - On error, a negative errno code is returned See [libiio](https://analogdevicesinc.github.io/libiio/master/libiio/group__Device.html#gac05869aa707121328dd72cdad10cedf2) """ function iio_device_buffer_attr_write_longlong(dev::Ptr{iio_device}, attr::String, val::Clonglong) return ccall((:iio_device_buffer_attr_write_longlong, libiio), Cint, (Ptr{iio_device}, Cstring, Clonglong), dev, attr, val) end """ iio_device_buffer_attr_write_double(dev, attr, val) Set the value of the given buffer-specific attribute. # Parameters - `dev::Ptr{iio_device}` : A pointer to an [`iio_device`](@ref) structure - `attr::String` : A string corresponding to the name of the attribute - `val::Cdouble` : A Cdouble value to set the attribute to # Returns - On success, 0 is returned - On error, a negative errno code is returned See [libiio](https://analogdevicesinc.github.io/libiio/master/libiio/group__Device.html#ga10d47af8de4ad1f9dc4b63ce0aa0ff7d) """ function iio_device_buffer_attr_write_double(dev::Ptr{iio_device}, attr::String, val::Cdouble) return ccall((:iio_device_buffer_attr_write_double, libiio), Cint, (Ptr{iio_device}, Cstring, Cdouble), dev, attr, val) end """ iio_device_set_data(dev, data) Associate a pointer to an [`iio_device`](@ref) structure. # Parameters - `dev::Ptr{iio_device}` : A pointer to an [`iio_device`](@ref) structure - `data::Ptr{Cvoid}` : The pointer to be associated See [libiio](https://analogdevicesinc.github.io/libiio/master/libiio/group__Device.html#gab566248f50503d8975cf258a1f218275) """ function iio_device_set_data(dev::Ptr{iio_device}, data::Ptr{Cvoid}) ccall((:iio_device_set_data, libiio), Cvoid, (Ptr{iio_device}, Ptr{Cvoid}), dev, data) end """ iio_device_get_data(dev) Retrieve a previously associated pointer of an [`iio_device`](@ref) structure. # Parameters - `dev::Ptr{iio_device}` : A pointer to an [`iio_device`](@ref) structure # Returns - The pointer previously associated if present, or C_NULL See [libiio](https://analogdevicesinc.github.io/libiio/master/libiio/group__Device.html#ga87cff8d90e1a68e73410e4a527cc5334) """ function iio_device_get_data(dev::Ptr{iio_device}) return ccall((:iio_device_get_data, libiio), Ptr{Cvoid}, (Ptr{iio_device},), dev) end """ iio_device_get_trigger(dev) Retrieve the trigger of a given device. # Parameters - `dev::Ptr{iio_device}` : A pointer to an [`iio_device`](@ref) structure - `trigger::Ptr{iio_device}` : A pointer to an [`iio_device`][@ref] structure. The pointer will be set to the address of the [`iio_device`](@ref) structure corresponding to the associated trigger device. # Returns - On success, 0 is returned - On error, a negative errno code is returned See [libiio](https://analogdevicesinc.github.io/libiio/master/libiio/group__Device.html#gae3ce1d7385ca02a9f6c36768fa41c610) """ function iio_device_get_trigger(dev::Ptr{iio_device}) trigger = Ptr{iio_device}() ret = ccall((:iio_device_get_trigger, libiio), Cint, (Ptr{iio_device}, Ref{Ptr{iio_device}}), dev, Ref(trigger)) return ret, trigger end """ iio_device_set_trigger(dev, trigger) Associate a trigger to a given device. # Parameters - `dev::Ptr{iio_device}` : A pointer to an [`iio_device`](@ref) structure - `trigger::Ptr{iio_device` : A pointer to an [`iio_device`](@ref) structure corresponding to the trigger that should be associated. # Returns - On success, 0 is returned - On error, a negative errno code is returned See [libiio](https://analogdevicesinc.github.io/libiio/master/libiio/group__Device.html#ga3b8d1e621357f0755925d98555f53d9a) """ function iio_device_set_trigger(dev::Ptr{iio_device}, trigger::Ptr{iio_device}) return ccall((:iio_device_set_trigger, libiio), Cint, (Ptr{iio_device}, Ptr{iio_device}), dev, trigger) end """ iio_device_is_trigger(dev) Returns true of the given device is a trigger. # Parameters - `dev::Ptr{iio_device}` : A pointer to an [`iio_device`](@ref) structure # Returns - True if the deivce is a trigger, false otherwise See [libiio](https://analogdevicesinc.github.io/libiio/master/libiio/group__Device.html#ga7e3e5dee1ac8c082de038829c88edda8) """ function iio_device_is_trigger(dev::Ptr{iio_device}) return convert(Bool, ccall((:iio_device_is_trigger, libiio), Cuchar, (Ptr{iio_device},), dev)) end """ iio_device_set_kernel_buffers_count(dev, nb_buffers) Configure the number of kernel buffers for a device. This function allows to change the number of buffers on kernel side. # Parameters - `dev::Ptr{iio_device}` : A pointer to an [`iio_device`](@ref) structure - `nb_buffers::Cuint` : The number of buffers # Returns - On success, 0 is returned - On error, a negative errno code is returned See [libiio](https://analogdevicesinc.github.io/libiio/master/libiio/group__Device.html#ga8ad2357c4caf7afc778060a08e6e2209) """ function iio_device_set_kernel_buffers_count(dev::Ptr{iio_device}, nb_buffers::Cuint) return ccall((:iio_device_set_kernel_buffers_count, libiio), Cint, (Ptr{iio_device}, Cuint), dev, nb_buffers) end
LibIIO
https://github.com/TacHawkes/LibIIO.jl.git
[ "MIT" ]
0.1.2
47a08b35777450039eaa8e971e1278369931b431
code
7402
""" iio_create_scan_context(backend, flags = 0) Create a scan context. # Parameters - `backend::String` : A string containing a comma-separated list of the backend(s) to use for scanning. - `flags::Cuint` : Unused for now. Set to 0. # Returns - on success, a pointer to a `iio_scan_context` structure - On failure, an error is raised !!! note Libiio version 0.20 and above can handle multiple strings, for instance "local:usb:", "ip:usb:", "local:usb:ip:", and require a colon as the delimiter. Libiio version 0.24 and above prefer a comma instead of colon as the delimiter, and handle specifying backend-specific information. For instance, "local,usb=0456:*" will scan the local backend and limit scans on USB to vendor ID 0x0456, and accept all product IDs. The "usb=0456:b673" string would limit the scan to the device with this particular VID/PID. Both IDs are expected in hexadecimal, no 0x prefix needed. """ function iio_create_scan_context(backend::String, flags::Cuint = Cuint(0)) _backend = isempty(backend) ? C_NULL : backend @check_null ccall((:iio_create_scan_context, libiio), Ptr{iio_scan_context}, (Cstring, Cuint), _backend, flags) end """ iio_scan_context_destroy(ctx) Destroy the given scan context. # Parameters - `ctx::Ptr{iio_scan_context}` : A pointer to an `iio_scan_context` structure !!! note After that function, the `iio_scan_context` pointer shall be invalid. See [libiio](https://analogdevicesinc.github.io/libiio/master/libiio/group__Scan.html#ga649d7821636c744753067e8301a84e6d) """ function iio_scan_context_destroy(ctx::Ptr{iio_scan_context}) ccall((:iio_scan_context_destroy, libiio), Cvoid, (Ptr{iio_scan_context},), ctx) end """ iio_scan_context_get_info_list(ctx, info) Enumerate available contexts. # Parameters - `ctx::Ptr{iio_scan_context}` : A pointer to an `iio_scan_context` structure - `info::Ref{Ptr{Ptr{iio_context_info}}}` : A pointer to a list of [`iio_context_info`](@ref) pointers. The pointed variable will be initialized on success. # Returns - On success, the number of contexts found. - On failure, a negative error number. See [libiio](https://analogdevicesinc.github.io/libiio/master/libiio/group__Scan.html#ga5d364d8d008bdbfe5486e6329d06257f) """ function iio_scan_context_get_info_list(ctx::Ptr{iio_scan_context}, info::Ref{Ptr{Ptr{iio_context_info}}}) return convert(Int, ccall((:iio_scan_context_get_info_list, libiio), Cssize_t, (Ptr{iio_scan_context}, Ptr{Ptr{Ptr{iio_context_info}}}), ctx, info)) end """ iio_context_info_list_free(info) Free a context info list. # Parameters - `info::Ptr{Ptr{iio_context_info}}` : A pointer to a [`iio_context_info`](@ref) pointer. See [libiio](https://analogdevicesinc.github.io/libiio/master/libiio/group__Scan.html#ga4e618c6efb5a62e04a664f53f1b80d99) """ function iio_context_info_list_free(info::Ptr{Ptr{iio_context_info}}) ccall((:iio_context_info_list_free, libiio), Cvoid, (Ptr{Ptr{iio_context_info}},), info) end """ iio_context_info_get_description(info) Get a description of a discovered context. # Parameters - `Ptr{iio_context_info}`: A pointer to a [`iio_context_info`](@ref) structure. # Returns - A `String` containing the description. See [libiio](https://analogdevicesinc.github.io/libiio/master/libiio/group__Scan.html#ga885558697d0e4dad11a4a5b6f5fbc4d6) """ function iio_context_info_get_description(info::Ptr{iio_context_info}) return unsafe_string(ccall((:iio_context_info_get_description, libiio), Cstring, (Ptr{iio_context_info},), info)) end """ iio_context_info_get_uri(info) Get the URI of a discovered context. # Parameters - `Ptr{iio_context_info}`: A pointer to a [`iio_context_info`](@ref) structure. # Returns - A `String` containing the URI. See [libiio](https://analogdevicesinc.github.io/libiio/master/libiio/group__Scan.html#ga6a142a62112a0f84370d22facb2f2a37) """ function iio_context_info_get_uri(info::Ptr{iio_context_info}) return unsafe_string(ccall((:iio_context_info_get_uri, libiio), Cstring, (Ptr{iio_context_info},), info)) end """ iio_create_scan_block(backend, flags = 0) # Parameters - `backend::String` : A string containing the backend to use for scanning. Can be empty to use all available backends. - `flags::Cuint` (optional) : Unused for now. Set to 0. # Returns - on success, a pointer to an `iio_scan_block` structure - on failure, an error is raised See [libiio](https://analogdevicesinc.github.io/libiio/master/libiio/group__Scan.html#gad7fd2ea05bf5a8cebaff26b60edb8a13) """ function iio_create_scan_block(backend::String, flags::Cuint = Cuint(0)) _backend = isempty(backend) ? C_NULL : backend return @check_null scan_block = ccall((:iio_create_scan_block, libiio), Ptr{iio_scan_block}, (Cstring, Cuint), _backend, flags) end """ iio_scan_block_destroy(blk) Destroy the given scan block. # Parameters - `blk::Ptr{iio_scan_block}` : A pointer to an `iio_scan_block` structure !!! note After that function, the iio_scan_block pointer shall be invalid. Introduced in version 0.20. See [libiio](https://analogdevicesinc.github.io/libiio/master/libiio/group__Scan.html#ga91f6902ca18c491f96627cadb88c5c0a) """ function iio_scan_block_destroy(blk::Ptr{iio_scan_block}) ccall((:iio_scan_block_destroy, libiio), Cvoid, (Ptr{iio_scan_block},), blk) end """ iio_scan_block_scan(blk) Enumerate available contexts via scan block. # Parameters - `blk::Ptr{iio_scan_block}` : A pointer to an `iio_scan_block` structure # Returns - On success, the number of contexts found. - On failure, a negative error number. See [libiio](https://analogdevicesinc.github.io/libiio/master/libiio/group__Scan.html#gaee7e04572c3b4d202cd0043bb8cee642) """ function iio_scan_block_scan(blk::Ptr{iio_scan_block}) return convert(Int, ccall((:iio_scan_block, libiio), Cssize_t, (Ptr{iio_scan_block},), blk)) end """ iio_scan_block_get_info(blk, index) Get the [`iio_context_info`](@ref) for a particular context. # Parameters - `blk::Ptr{iio_scan_block}` : A pointer to an `iio_scan_block` structure - `index::Cuint` : The index corresponding to the context. # Returns - A pointer to the [`iio_context_info`](@ref) for the context - On success, a pointer to the specified [`iio_context_info`](@ref) - On failure, an error is raised """ function iio_scan_block_get_info(blk::Ptr{iio_scan_block}, index::Cuint) return @check_null ccall((:iio_scan_block_get_info, libiio), Ptr{iio_context_info}, (Ptr{iio_scan_block}, Cuint), blk, index) end
LibIIO
https://github.com/TacHawkes/LibIIO.jl.git
[ "MIT" ]
0.1.2
47a08b35777450039eaa8e971e1278369931b431
code
2852
""" iio_library_get_version() Get the version of the libiio library. # Returns - `major::UInt` : The major version - `minor::UInt` : The minor version - `git_tag::String` : The version's git tag See: [libiio](https://analogdevicesinc.github.io/libiio/master/libiio/group__TopLevel.html#gaaa29e5bac86d00a1cef6e2d00b0ea24c) """ function iio_library_get_version() major, minor, git_tag = Ref{Cuint}(0), Ref{Cuint}(0), Vector{Cchar}(undef, 8) ccall((:iio_library_get_version, libiio), Cvoid, (Ref{Cuint}, Ref{Cuint}, Ptr{Cchar}), major, minor, pointer(git_tag)) return UInt(major[]), UInt(minor[]), unsafe_string(pointer(git_tag)) end """ iio_strerror(err) Get a string description of an error code. # Parameters - `err::Int` : The error code # Returns - `dst::String` : The string description of the error See: [libiio](https://analogdevicesinc.github.io/libiio/master/libiio/group__TopLevel.html#ga4a117b0ac02e97aeda92e33c063f7cf0) """ function iio_strerror(err::Cint) dst = Vector{Cchar}(undef, 256) ccall((:iio_strerror, libiio), Cvoid, (Cint, Ptr{Cchar}, Csize_t), err, pointer(dst), length(dst)) return unsafe_string(pointer(dst)) end """ iio_has_backend(backend) Check if the specified backend is available. # Parameters - `backend::String` : The name of the backend to query # Returns - True if the backend is available, false otherwise See: [libiio](https://analogdevicesinc.github.io/libiio/master/libiio/group__TopLevel.html#ga8cf6a3818d471333f4115f3d0d8d95a2) """ function iio_has_backend(backend::String) return convert(Bool, ccall((:iio_has_backend, libiio), Cuchar, (Cstring,), backend)) end """ iio_get_backends_count_count() Get the number of available backends. # Returns - The number of available backends See: [libiio](https://analogdevicesinc.github.io/libiio/master/libiio/group__TopLevel.html#gabe08d9f1e10801b0334575063a66a56c) """ function iio_get_backends_count() return ccall((:iio_get_backends_count, libiio), Cuint, ()) end """ iio_get_backend(index) Retrieve the name of a given backend. # Parameters - `index` : The index corresponding to the attribute # Returns: - On success, a string containing the backend - If the index is invalid, an empty string is returned See: [libiio](https://analogdevicesinc.github.io/libiio/master/libiio/group__TopLevel.html#ga0b950d578c5e4e06232949159c491dab) """ function iio_get_backend(index::Cuint) out = ccall((:iio_get_backend, libiio), Cstring, (Cuint,), index) return out != C_NULL ? unsafe_string(out) : "" end iio_get_backend(index::Int) = iio_get_backend(convert(Cuint, index))
LibIIO
https://github.com/TacHawkes/LibIIO.jl.git
[ "MIT" ]
0.1.2
47a08b35777450039eaa8e971e1278369931b431
code
898
function iio_parse_attr(buffer::Vector{Cchar}, size::Cssize_t) # prepare output attributes = Tuple{Int, String}[] parsed = 0 while parsed < size index = parsed + 1 block_prefix = reinterpret(Int32, ntoh(buffer[index:(index + 3)])) if block_prefix < 0 # error push!(attributes, (block_prefix, "")) parsed += 4 else # success (and Julia can do pointer arithmetics :) push!(attributes, (block_prefix, unsafe_string(pointer(buffer) + (4 + parsed)))) parsed += 4 + block_prefix end end return attributes end function dev_is_buffer_capable(dev::Ptr{iio_device}) for i in 0:(iio_device_get_channels_count(dev) - 1) chn = iio_device_get_channel(dev, convert(Cuint, i)) iio_channel_is_scan_element(chn) && return true end return false end
LibIIO
https://github.com/TacHawkes/LibIIO.jl.git
[ "MIT" ]
0.1.2
47a08b35777450039eaa8e971e1278369931b431
code
240
using LibIIO using Test # As libiio does not have tests or a test mode, this package is hardly testable as # most of the calls end up in a ccall immediately... @testset "LibIIO.jl" begin @test_nowarn LibIIO._get_library_version() end
LibIIO
https://github.com/TacHawkes/LibIIO.jl.git
[ "MIT" ]
0.1.2
47a08b35777450039eaa8e971e1278369931b431
docs
4403
# LibIIO.jl [![Build Status](https://github.com/tachawkes/LibIIO.jl/actions/workflows/CI.yml/badge.svg?branch=main)](https://github.com/tachawkes/LibIIO.jl/actions/workflows/CI.yml?query=branch%3Amain) [![Build Status](https://ci.appveyor.com/api/projects/status/github/tachawkes/LibIIO.jl?svg=true)](https://ci.appveyor.com/project/tachawkes/LibIIO-jl) LibIIO.jl provides Julia bindings for [libiio](https://wiki.analog.com/resources/tools-software/linux-software/libiio) which is a library for interfacing with Linux industrial I/O devices. This packages is meant to give you an easy-to-use high-level API interface matching the [Python-bindings](https://github.com/analogdevicesinc/libiio/tree/master/bindings/python) with some adaptions to Julia-specifics. If you prefer to work directly with libiio, all C-functions are exposed (but not exported) as a Julia function matching the C functions exactly in name. These function mostly match their C-counterparts but have some added convenience around them and convert their results to Julia types where applicable. ## Documentation [![Stable](https://img.shields.io/badge/docs-stable-blue.svg)](https://tachawkes.github.io/LibIIO.jl/stable/) [![Dev](https://img.shields.io/badge/docs-dev-blue.svg)](https://tachawkes.github.io/LibIIO.jl/dev/) ## Installation Install the package using: ```julia ] add LibIIO ``` ## Example The package prints information about the objects in the same fashion as `iio_info` does. For example, if you have the [IIO Demo](https://wiki.analog.com/resources/eval/user-guides/iio_demo/no-os-setup) installed, you can connect to the IIO network context using: ```julia using LibIIO # Adjust to your settings uri = "ip:127.0.0.1" # Connect to the context using the network backend. ctx = Context(uri) ``` This will print (note, that the trigger errors are correct here!): ``` IIO context created with network backend. Backend version: 1.1 (git tag: 0000000) Backend description string: 127.0.0.1 no-OS analog 1.1.0-g0000000 #1 Tue Nov 26 09:52:32 IST 2019 armv7l IIO context has 3 attributes: no-OS: 1.1.0-g0000000 ip,ip-addr: 192.168.64.2 uri: ip:192.168.64.2 IIO context has 2 devices: iio:device0: adc_demo (buffer capable) 2 channels found: voltage0: adc_in_ch0 (input, index: 0, format: le:S16/16>>0) 1 channel-specific attributes found: attr 0: adc_channel_attr value: 1111 voltage1: adc_in_ch1 (input, index: 1, format: le:S16/16>>0) 1 channel-specific attributes found: attr 0: adc_channel_attr value: 1112 1 device-specific attributes found: attr 0: adc_global_attr value: 3333 1 debug-specific attributes found: attr 0: direct_reg_access value: 0 ERROR: checking for trigger : Invalid argument (22) iio:device1: dac_demo (buffer capable) 2 channels found: voltage0: dac_out_ch0 (output, index: 0, format: le:S16/16>>0) 1 channel-specific attributes found: attr 0: dac_channel_attr value: 1111 voltage1: dac_out_ch1 (output, index: 1, format: le:S16/16>>0) 1 channel-specific attributes found: attr 0: dac_channel_attr value: 1112 1 device-specific attributes found: attr 0: dac_global_attr value: 4444 1 debug-specific attributes found: attr 0: direct_reg_access value: 0 ERROR: checking for trigger : Invalid argument (22) ``` See the examples folder for more details or the documentation. ## Similar packages The [AdalmPluto.jl](https://github.com/JuliaTelecom/AdalmPluto.jl) package is focussed on just interfacing an [AdalmPluto](https://www.analog.com/en/design-center/evaluation-hardware-and-software/evaluation-boards-kits/adalm-pluto.html) but actually has a quite complete libiio implementation in its internals. Actually this package uses their libiio_jll package (Kudos for that!) to provide the C binaries. However, that package is not focussed on exposing the libiio API and only gives low-level access.
LibIIO
https://github.com/TacHawkes/LibIIO.jl.git
[ "MIT" ]
0.1.2
47a08b35777450039eaa8e971e1278369931b431
docs
94
```@index Pages = ["buffer.md"] ``` ```@autodocs Modules = [LibIIO] Pages = ["buffer.jl"] ```
LibIIO
https://github.com/TacHawkes/LibIIO.jl.git
[ "MIT" ]
0.1.2
47a08b35777450039eaa8e971e1278369931b431
docs
446
```@meta CurrentModule = LibIIO.CLibIIO ``` # Index ```@index Pages = ["cbuffer.md"] ``` # Documentation ```@docs iio_buffer_get_device iio_device_create_buffer iio_buffer_destroy iio_buffer_get_poll_fd iio_buffer_set_blocking_mode iio_buffer_refill iio_buffer_push iio_buffer_push_partial iio_buffer_cancel iio_buffer_start iio_buffer_first iio_buffer_step iio_buffer_end iio_buffer_foreach_sample iio_buffer_set_data iio_buffer_get_data ```
LibIIO
https://github.com/TacHawkes/LibIIO.jl.git
[ "MIT" ]
0.1.2
47a08b35777450039eaa8e971e1278369931b431
docs
866
```@meta CurrentModule = LibIIO.CLibIIO ``` # Index ```@index Pages = ["cchannel.md"] ``` # Documentation ```@docs iio_channel_get_device iio_channel_get_id iio_channel_get_name iio_channel_is_output iio_channel_is_scan_element iio_channel_get_attrs_count iio_channel_get_attr iio_channel_find_attr iio_channel_attr_get_filename iio_channel_attr_read iio_channel_attr_read_all iio_channel_attr_read_bool iio_channel_attr_read_longlong iio_channel_attr_read_double iio_channel_attr_write iio_channel_attr_write_raw iio_channel_attr_write_all iio_channel_attr_write_bool iio_channel_attr_write_longlong iio_channel_attr_write_double iio_channel_enable iio_channel_disable iio_channel_is_enabled iio_channel_read_raw iio_channel_read iio_channel_write_raw iio_channel_write iio_channel_set_data iio_channel_get_data iio_channel_get_type iio_channel_get_modifier ```
LibIIO
https://github.com/TacHawkes/LibIIO.jl.git
[ "MIT" ]
0.1.2
47a08b35777450039eaa8e971e1278369931b431
docs
146
```@meta CurrentModule = LibIIO ``` ```@index Pages = ["ccontext.md"] ``` ```@autodocs Modules = [LibIIO.CLibIIO] Pages = ["context.jl"] ```
LibIIO
https://github.com/TacHawkes/LibIIO.jl.git
[ "MIT" ]
0.1.2
47a08b35777450039eaa8e971e1278369931b431
docs
758
```@meta CurrentModule = LibIIO.CLibIIO ``` # Index ```@index Pages = ["cdebug.md"] ``` # Documentation ```@docs iio_device_get_sample_size iio_channel_get_index iio_channel_get_data_format iio_channel_convert iio_channel_convert_inverse iio_device_get_debug_attrs_count iio_device_get_debug_attr iio_device_find_debug_attr iio_device_debug_attr_read iio_device_debug_attr_read_all iio_device_debug_attr_write iio_device_debug_attr_write_raw iio_device_debug_attr_write_all iio_device_debug_attr_read_bool iio_device_debug_attr_read_longlong iio_device_debug_attr_read_double iio_device_debug_attr_write_bool iio_device_debug_attr_write_longlong iio_device_debug_attr_write_double iio_device_identify_filename iio_device_reg_write iio_device_reg_read ```
LibIIO
https://github.com/TacHawkes/LibIIO.jl.git
[ "MIT" ]
0.1.2
47a08b35777450039eaa8e971e1278369931b431
docs
1240
```@meta CurrentModule = LibIIO.CLibIIO ``` # Index ```@index Pages = ["cdevice.md"] ``` # Documentation ```@docs iio_device_get_context iio_device_get_id iio_device_get_name iio_device_get_label iio_device_get_channels_count iio_device_get_attrs_count iio_device_get_buffer_attrs_count iio_device_get_channel iio_device_get_attr iio_device_get_buffer_attr iio_device_find_channel iio_device_find_attr iio_device_find_buffer_attr iio_device_attr_read iio_device_attr_read_all iio_device_attr_read_bool iio_device_attr_read_longlong iio_device_attr_read_double iio_device_attr_write iio_device_attr_write_raw iio_device_attr_write_all iio_device_attr_write_bool iio_device_attr_write_longlong iio_device_attr_write_double iio_device_buffer_attr_read iio_device_buffer_attr_read_all iio_device_buffer_attr_read_bool iio_device_buffer_attr_read_longlong iio_device_buffer_attr_read_double iio_device_buffer_attr_write iio_device_buffer_attr_write_raw iio_device_buffer_attr_write_all iio_device_buffer_attr_write_bool iio_device_buffer_attr_write_longlong iio_device_buffer_attr_write_double iio_device_set_data iio_device_get_data iio_device_get_trigger iio_device_set_trigger iio_device_is_trigger iio_device_set_kernel_buffers_count ```
LibIIO
https://github.com/TacHawkes/LibIIO.jl.git
[ "MIT" ]
0.1.2
47a08b35777450039eaa8e971e1278369931b431
docs
96
```@index Pages = ["channel.md"] ``` ```@autodocs Modules = [LibIIO] Pages = ["channel.jl"] ```
LibIIO
https://github.com/TacHawkes/LibIIO.jl.git
[ "MIT" ]
0.1.2
47a08b35777450039eaa8e971e1278369931b431
docs
1085
```@meta CurrentModule = LibIIO ``` # [Introduction](@id clib-index) The package wraps all of the libiio C-functions in Julia functions with the same name. You can load them into your current namespace with ```julia using LibIIO.CLibIIO ``` Usage of these low-level functions is recommended for advanced users who are familiar with the inner workings of iio/libiio. Please not that while the provided functions are _almost_ identical to their C counterparts, they have been modified for some convenience. All functions working with char pointers, take Julia Strings as their inputs and also return Julia strings if the C function would require a modifiable C-pointer. Furthermore, most functions requiring pointers (e.g. buffers) to be passed to the C function will create them within the wrapper and return a Julia-type to the user with the value instead. This requires a bit more allocations but in turn you do not have to take care of pointers and garbage collection issues. ```@index Pages = ["cindex.md"] ``` ```@autodocs Modules = [LibIIO.CLibIIO] Pages = ["ctypes.jl"] ```
LibIIO
https://github.com/TacHawkes/LibIIO.jl.git
[ "MIT" ]
0.1.2
47a08b35777450039eaa8e971e1278369931b431
docs
133
```@meta CurrentModule = LibIIO ``` ```@index Pages = ["context.md"] ``` ```@autodocs Modules = [LibIIO] Pages = ["context.jl"] ```
LibIIO
https://github.com/TacHawkes/LibIIO.jl.git
[ "MIT" ]
0.1.2
47a08b35777450039eaa8e971e1278369931b431
docs
373
```@meta CurrentModule = LibIIO.CLibIIO ``` # Index ```@index Pages = ["cscan.md"] ``` # Documentation ```@docs iio_create_scan_context iio_scan_context_destroy iio_scan_context_get_info_list iio_context_info_list_free iio_context_info_get_description iio_context_info_get_uri iio_create_scan_block iio_scan_block_destroy iio_scan_block_scan iio_scan_block_get_info ```
LibIIO
https://github.com/TacHawkes/LibIIO.jl.git
[ "MIT" ]
0.1.2
47a08b35777450039eaa8e971e1278369931b431
docs
214
```@meta CurrentModule = LibIIO.CLibIIO ``` # Index ```@index Pages = ["ctoplevel.md"] ``` # Documentation ```@docs iio_library_get_version iio_strerror iio_has_backend iio_get_backends_count iio_get_backend ```
LibIIO
https://github.com/TacHawkes/LibIIO.jl.git
[ "MIT" ]
0.1.2
47a08b35777450039eaa8e971e1278369931b431
docs
131
```@meta CurrentModule = LibIIO ``` ```@index Pages = ["device.md"] ``` ```@autodocs Modules = [LibIIO] Pages = ["device.jl"] ```
LibIIO
https://github.com/TacHawkes/LibIIO.jl.git
[ "MIT" ]
0.1.2
47a08b35777450039eaa8e971e1278369931b431
docs
9531
# [Setting up the libiio and the IIO demo project](@id iio_demo) For this example you need a linux system with [libiio](https://wiki.analog.com/resources/tools-software/linux-software/libiio) installed. Many distros have a bundled package. If you prefer to build it from source, you can follow this [build guide](https://wiki.analog.com/resources/tools-software/linux-software/libiio#building_on_the_linux_host_target). If you want to setup a sandbox for testing IIO, using [multipass](https://multipass.run) (she knows it's a multipass) is a quick way to set up an Ubuntu VM where the IIO demo project can be installed. The IIO demo project is a small demo of the IIO framework where a 16 bit ADC and a 16 bit DAC is simulated with buffer support. With default settings there is a loopback between DAC/ADC, i.e. data you send to the DAC is piped back into the ADC. Furthermore you need to build the [IIO Demo](https://wiki.analog.com/resources/eval/user-guides/iio_demo/no-os-setup). This can be done with these stepse: 1. Clone the `no-os` git repostitory from Analog Devices: ```bash git clone --recursive https://github.com/analogdevicesinc/no-OS ``` 2. Enter into the projects folder with ```bash cd no-OS/projects/iio_demo ``` 3. Compile the demo project using ```bash make PLATFORM = linux ``` 4. Execute the demo project using ```bash ./build/iio_demo.out ``` Now you can use the demo devices either on the same system or from a different system. If you use another system you need to have a network connection between these two systems. # Using LibIIO.jl with the IIO demo devices This example will send a sine wave signal to the DAC device using buffers and reads the signal back using the ADC device with another buffer and checks that data is identical. Create a new Julia environment with `LibIIO.jl` installed as package. Then create a new Julia file and load the package with ```julia using LibIIO ``` Now we try to connect with the IIO daemon using the network context. This is done the following way: ```julia uri = "ip:192.168.64.2" ctx = Context(uri) ``` !!! note Do not forget to change the IP address to your settings. For a local connection use `127.0.0.1`. This should print the details of the context (attributes, devices, channels etc.) on the REPL console like this: ``` IIO context created with network backend. Backend version: 1.1 (git tag: 0000000) Backend description string: 192.168.64.2 no-OS analog 1.1.0-g0000000 #1 Tue Nov 26 09:52:32 IST 2019 armv7l IIO context has 3 attributes: no-OS: 1.1.0-g0000000 ip,ip-addr: 192.168.64.2 uri: ip:192.168.64.2 IIO context has 2 devices: iio:device0: adc_demo (buffer capable) 2 channels found: voltage0: adc_in_ch0 (input, index: 0, format: le:S16/16>>0) 1 channel-specific attributes found: attr 0: adc_channel_attr value: 1111 voltage1: adc_in_ch1 (input, index: 1, format: le:S16/16>>0) 1 channel-specific attributes found: attr 0: adc_channel_attr value: 1112 1 device-specific attributes found: attr 0: adc_global_attr value: 3333 1 debug-specific attributes found: attr 0: direct_reg_access value: 0 ERROR: checking for trigger : Invalid argument (22) iio:device1: dac_demo (buffer capable) 2 channels found: voltage0: dac_out_ch0 (output, index: 0, format: le:S16/16>>0) 1 channel-specific attributes found: attr 0: dac_channel_attr value: 1111 voltage1: dac_out_ch1 (output, index: 1, format: le:S16/16>>0) 1 channel-specific attributes found: attr 0: dac_channel_attr value: 1112 1 device-specific attributes found: attr 0: dac_global_attr value: 4444 1 debug-specific attributes found: attr 0: direct_reg_access value: 0 ERROR: checking for trigger : Invalid argument (22) ``` !!! info Do not worry about the errors. This demo is built without trigger support, therefore the error message is actually correct. The context has two devices, called `adc_demo` and `dac_demo`. It would be also possible to address them using their IDs `iio:device0` and `iio:devic1` instead of their names. To retrieve a device handle we use the code: ```julia dac = find_device(ctx, "dac_demo") adc = find_device(ctx, "adc_demo") ``` Now we need to get a handle to the channel of each device respectively. Note that for the DAC, the argument `is_output` of the [`find_channel`](@ref) function has to be set to `true`. The demo devices each have two channels, we use only the first channel (`voltage0`). The channels are named `adc_in_ch0` and `dac_out_ch0` for this example. ```julia dac_chn = find_channel(dac, "dac_out_ch0", true) adc_chn = find_channel(adc, "adc_in_ch0") ``` Before creating a buffer for writing/reading channels, the channels have to be enabled: ```julia enabled!(dac_chn, true) enabled!(adc_chn, true) ``` In the next step a buffer for each device for 400 samples is set up. ```julia dac_buf = Buffer(dac, 400) adc_buf = Buffer(adc, 400) ``` !!! warning The buffer creation can be done only once, otherwise a "busy"-error will be issued. The buffer object should be stored savely. If you delete the buffer (e.g. with `dac_buf = nothing`) the Julia garbage collector does not run immediately (you can explicitly run it with `GC.gc()`) and so the C-pointer and connected ressources are not freed immediately. In general `LibIIO.jl` tries to properly cleanup the C-pointers using the libiio `destroy` functions but due to the nature of the garbage collector this is not done immediately upon deleting the Julia references to the objects. For the sake of this example, we now generate 400 samples of a sine wave with two full periods: ```julia y = round.(Int16, 10000*sin.(2π*1/200*(1:400))) ``` This data can now be written to the `dac_buffer` object which just copies the data into the buffer's memory but this memory is still on the host computer and not on the physical device. This transfer to the device is issued by calling the [`push`](@ref) function on the buffer. ```julia write(dac_buffer, y) push(dac_buffer) ``` For a real device the data would be physically sent to the DAC device and would be measurable as an analog signal (i.e. using an oscilloscope). In this demo the data can be immediately read back using the ADC device. First we have to issue the physical transfer from the ADC device to the buffer memory and then read the data into a Julia variable: ```julia refill(adc_buf) data = read(adc_buf) ``` The data is returned as bytes, so for our 16 bit ADC/DAC devices we will receive 800 bytes of data when sending/requestion 400 samples. The data is returned as `Cuchar`/`UInt8` and has to be reinterpreted to the device sample format: ``` d2 = reinterpret(Int16, data) ``` !!! note In general this can be way more complex depending on the device. `iio_info` or using this package you get an info string for each channel which tells you how to interpret the raw binary data from the device. In this example the ADC channel has the info `voltage0: adc_in_ch0 (input, index: 0, format: le:S16/16>>0)`. The `format` part tells you that this device transmit in little Endian format (the library takes care of conversion when not using the `raw` mode) and signed 16 bit samples are transfered where the full 16 bits represent one sample, so a right-shift of zero (i.e. no shift at all) is required to interpet the sample. You can get a structured information of the data format of a channel using the [`data_format`](@ref LibIIO.data_format) function. This function will also give you a scaling factor, i.e. for temperature sensors where the integer data has to be scale to a float value. Now the variable `d2` contains the samples read from the ADC in the correct format. To check if this matches our original signal in `y` you can use: ```julia if all(d2 .== y) @info "Loopback successful" else @error "Loopback failed" end ``` # The full example ```julia using LibIIO # Adjust to your settings uri = "ip:192.168.64.2" # create context ctx = Context(uri) # get both device handles by their name dac = find_device(ctx, "dac_demo") adc = find_device(ctx, "adc_demo") # get both channels (adc/dac) dac_chn = find_channel(dac, "dac_out_ch0", true) adc_chn = find_channel(adc, "adc_in_ch0") # enable the channels enabled!(dac_chn, true) enabled!(adc_chn, true) # create DAC buffer with 400 samples dac_buf = Buffer(dac, 400) # create the ADC buffer for reading adc_buf = Buffer(adc, 400) # dummy signal to feed into the DAC and read back using the ADC y = round.(Int16, 10000*sin.(2π*1/200*(1:400))) # write the test signal into the buffer write(dac_buf, y) # push the buffer to the hardware push(dac_buf) # Read samples from the ADC hardware into the buffer refill(adc_buf) # Retrieve the samples from the buffer data = read(adc_buf) # Reinterpret as Int16, the actual sample format d2 = reinterpret(Int16, data) # Verify that the read signal matches the original signal if all(d2 .== y) @info "Loopback successful" else @error "Loopback failed" end ```
LibIIO
https://github.com/TacHawkes/LibIIO.jl.git
[ "MIT" ]
0.1.2
47a08b35777450039eaa8e971e1278369931b431
docs
2535
```@meta CurrentModule = LibIIO ``` # LibIIO LibIIO.jl provides Julia bindings for [libiio](https://wiki.analog.com/resources/tools-software/linux-software/libiio) which is a library for interfacing with Linux industrial I/O devices. This packages is meant to give you an easy-to-use high-level API interface matching the [Python-bindings](https://github.com/analogdevicesinc/libiio/tree/master/bindings/python) with some adaptions to Julia-specifics. If you prefer to work directly with libiio, all C-functions are exposed (but not exported) as a Julia function matching the C functions exactly in name. These function mostly match their C-counterparts but have some added convenience around them and convert their results to Julia types where applicable. # Installation Install the packing using the package manager with: ```julia ] add LibIIO ``` # Usage There are two ways to use this package: 1. If you want an easy experience, almost identical to the libiio Python bindings, use the high-level wrappers for the IIO concepts, like contexts, devices, channels, buffers and attributes. You will be only using Julia types and do not have to deal with the C pointers and C data types. See the [IIO Demo](@ref iio_demo) page for an example. 2. If you are well familiar with the C libary, this package wraps all libiio C functions an exposes them with exactly the same names. However, they are not eported by `using LibIIO`. You must address them by prefixing them with the package name or load them explicitly by writing `using LibIIO.CLibIIO`. See the [low-level documentation](@ref clib-index) pages for further documentation. The documentation is mainly copied over (and linked) from the original C-library documentation but there are small adaptions for easier use of the library in Julia. Therefore it is recommend to read the docs of this package. # Libiio 1.0 In the near future [libiio 1.0](https://www.youtube.com/watch?v=Y7JhEeWma_s) will be released with libiio 0.24 being the last 0.x release. The new version will have some (partially breaking) changes to the buffer interface, which will also affect language bindings. There will be a compatibility layer for libiio so that 0.x and 1.x version will be up-/downwards compatible. When libiio 1.0 is released, these bindings will be updated to the new interface. If you want to have a look, what will be coming, you can checkout the updated Python bindings on the `dev` branch of libiio: <https://github.com/analogdevicesinc/libiio/blob/dev/bindings/python/iio.py>
LibIIO
https://github.com/TacHawkes/LibIIO.jl.git
[ "MIT" ]
0.1.3
d62c0014dfc5d64ecd16190fa069a8bb04627006
code
4014
using Plots, SparseArrays, Symbolics, SparseDiffTools, Printf, ExactFieldSolutions import LinearAlgebra: norm import Statistics: mean function Residual!(F, T, T0, k, ρ, Cp, Δx, Δt, x, t) ncx = length(F) params = (T0=1.0, K=1.0, σ=0.1) for i in eachindex(T) # West boundary if i==1 sol = Diffusion1D_Gaussian([x.min-Δx/2.0; t]; params ) Ta = sol.u qxW = -k*(T[i] - Ta)/Δx end # East boundary if i==ncx sol = Diffusion1D_Gaussian([x.min+Δx/2.0; t]; params ) Ta = sol.u qxE = -k*(Ta - T[i])/Δx end # West flux if i>1 # Left flux qxW = -k*(T[i] - T[i-1])/Δx end # East if i<ncx # Right flux qxE = -k*(T[i+1] - T[i])/Δx end # Balance F[i] = ρ*Cp*(T[i] - T0[i])/Δt + (qxE - qxW)/Δx end return nothing end function main(Δx, Δt, ncx, nt, L) # Parameters x = (min=-L/2, max=L/2) xc = LinRange(x.min+Δx/2., x.max-Δx/2., ncx) ρ = 1.0 Cp = 1.0 k = 1.0 t = 0. # Allocations T = zeros(ncx) T0 = zeros(ncx) F = zeros(ncx) δT = zeros(ncx) Ta = zeros(ncx) # Sparsity pattern input = rand(ncx) output = similar(input) Res_closed! = (F, T) -> Residual!(F, T, T0, k, ρ, Cp, Δx, Δt, x, t) sparsity = Symbolics.jacobian_sparsity(Res_closed!, output, input) J = Float64.(sparse(sparsity)) # Makes coloring colors = matrix_colors(J) # Initial condition: Evaluate exact initial solution params = (T0=1.0, K=1.0, σ=0.1) for i in eachindex(T) sol = Diffusion1D_Gaussian([xc[i]; t]; params ) T[i] = sol.u end # Time loop for it=1:nt T0 .= T t += Δt # @printf("########### Step %06d ###########\n", it) for iter=1:10 # Residual evaluation: T is found if F = 0 Residual!(F, T, T0, k, ρ, Cp, Δx, Δt, x, t) Res_closed! = (F, T) -> Residual!(F, T, T0, k, ρ, Cp, Δx, Δt, x, t) r = norm(F)/ncx # @printf("## Iteration %06d: r = %1.2e ##\n", iter, r) if r < 1e-10 break end # Jacobian assembly forwarddiff_color_jacobian!(J, Res_closed!, T, colorvec = colors) # Solve δT .= .-J\F # update T .+= δT end end # Evaluate exact solution for i in eachindex(T) sol = Diffusion1D_Gaussian([xc[i]; t]; params ) Ta[i] = sol.u end # Error return mean(abs.(T .- Ta)) end function ConvergenceAnalysis() L = 2. tt = 0.01 K = 1. # Time ncx = 1000 Δx = L/ncx Nt = [10, 20, 40, 80, 160, 320, 640] Δtv = 0.01 ./ Nt ϵt = zero(Δtv) for i in eachindex(Nt) Δx = sqrt(Δtv[i]*sqrt(K)) ncx = Int64(floor(L/Δx)) L = ncx*Δx ϵt[i] = main(Δx, Δtv[i], ncx, Nt[i], L) end # Time L = 2. nt = 100 Ncx = [ 40, 80, 160, 320, 640] Δxv = 2.0 ./ Ncx ϵx = zero(Δtv) for i in eachindex(Ncx) Δt = Δxv[i]^2/sqrt(K) nt = Int64(floor(tt/Δt)) ϵx[i] = main(Δxv[i], Δt, Ncx[i], nt, L) end p1 = plot(xlabel="log10(1/Δx)", ylabel="log10(ϵx)") p1 = scatter!( log10.( 1.0./Δxv ), log10.(ϵx), label="ϵ") p1 = plot!( log10.( 1.0./Δxv ), log10.(ϵx[1]) .- 1.0* ( log10.( 1.0./Δxv ) .- log10.( 1.0./Δxv[1] ) ), label="O1" ) p1 = plot!( log10.( 1.0./Δxv ), log10.(ϵx[1]) .- 2.0* ( log10.( 1.0./Δxv ) .- log10.( 1.0./Δxv[1] ) ), label="O2" ) p2 = plot(xlabel="log10(1/Δt)", ylabel="log10(ϵt)") p2 = scatter!( log10.( 1.0./Δtv ), log10.(ϵt), label="ϵ") p2 = plot!( log10.( 1.0./Δtv ), log10.(ϵt[1]) .- 1.0* ( log10.( 1.0./Δtv ) .- log10.( 1.0./Δtv[1] ) ), label="O1" ) display(plot(p1, p2)) end ConvergenceAnalysis()
ExactFieldSolutions
https://github.com/tduretz/ExactFieldSolutions.jl.git
[ "MIT" ]
0.1.3
d62c0014dfc5d64ecd16190fa069a8bb04627006
code
1578
using ExactFieldSolutions, Plots, Printf import LinearAlgebra: norm function main() # Define domain Nx = 50 x = LinRange(-1/2, 1/2, Nx) xc = 0.5*(x[2:end] .+ x[1:end-1]) # Allocate arrays t = [0.0 1e3 1e4 1e5] u = zeros(length(t), Nx-1) s = zeros(length(t), Nx-1) ∂u∂x = zeros(length(t), Nx-1) # Evaluate solution for it in eachindex(t) for i=1:Nx-1 sol = Diffusion1D_Gaussian( [xc[i]; t[it]] ) u[it,i] = sol.u s[it,i] = sol.s ∂u∂x[it,i] = sol.∇u[1] end @printf("Net source term should be 0.0: norm(s) = %1.2e\n", norm(s[it,:,:])) end # Visualise p1 = plot(xlabel = "x", ylabel= "u") p1 = plot!(xc, u[1,:], title=@sprintf("u @ t = %1.2e", t[1]), label="u₀") p1 = plot!(xc, u[1,:], title=@sprintf("u @ t = %1.2e", t[1]), label="u") p2 = plot(xlabel = "x", ylabel= "u") p2 = plot!(xc, u[1,:], title=@sprintf("u @ t = %1.2e", t[1]), label="u₀") p2 = plot!(xc, u[2,:], title=@sprintf("u @ t = %1.2e", t[2]), label="u") p3 = plot(xlabel = "x", ylabel= "u") p3 = plot!(xc, u[1,:], title=@sprintf("u @ t = %1.2e", t[1]), label="u₀") p3 = plot!(xc, u[3,:], title=@sprintf("u @ t = %1.2e", t[3]), label="u") p4 = plot(xlabel = "x", ylabel= "u") p4 = plot!(xc, u[1,:], title=@sprintf("u @ t = %1.2e", t[1]), label="u₀") p4 = plot!(xc, u[4,:], title=@sprintf("u @ t = %1.2e", t[4]), label="u") display( plot(p1,p2,p3,p4, layout=(2,2)) ) end main()
ExactFieldSolutions
https://github.com/tduretz/ExactFieldSolutions.jl.git
[ "MIT" ]
0.1.3
d62c0014dfc5d64ecd16190fa069a8bb04627006
code
1532
using ExactFieldSolutions, Plots, Printf import LinearAlgebra: norm function main() # Define domain Nx, Ny = 50, 50 x = LinRange(-1/2, 1/2, Nx) y = LinRange(-1/2, 1/2, Ny) xc = 0.5*(x[2:end] .+ x[1:end-1]) yc = 0.5*(y[2:end] .+ y[1:end-1]) # Allocate arrays t = [0.0 1e3 1e4 1e5] u = zeros(length(t), Nx-1, Ny-1) s = zeros(length(t), Nx-1, Ny-1) ∂u∂x = zeros(length(t), Nx-1, Ny-1) ∂u∂y = zeros(length(t), Nx-1, Ny-1) # Evaluate solution for it in eachindex(t) for i=1:Nx-1, j=1:Ny-1 sol = Diffusion2D_Gaussian( [xc[i]; yc[j]; t[it]] ) u[it,i,j] = sol.u s[it,i,j] = sol.s ∂u∂x[it,i,j] = sol.∇u[1] ∂u∂y[it,i,j] = sol.∇u[2] end @printf("Net source term should be 0.0: norm(s) = %1.2e\n", norm(s[it,:,:])) end # Visualise p1 = heatmap(x, y, u[1,:,:]', aspect_ratio=1, xlims=(-1/2,1/2), color=cgrad(:roma, rev=true), title=@sprintf("u @ t = %1.2e", t[1])) p2 = heatmap(x, y, u[2,:,:]', aspect_ratio=1, xlims=(-1/2,1/2), color=cgrad(:roma, rev=true), title=@sprintf("u @ t = %1.2e", t[2])) p3 = heatmap(x, y, u[3,:,:]', aspect_ratio=1, xlims=(-1/2,1/2), color=cgrad(:roma, rev=true), title=@sprintf("u @ t = %1.2e", t[3])) p4 = heatmap(x, y, u[4,:,:]', aspect_ratio=1, xlims=(-1/2,1/2), color=cgrad(:roma, rev=true), title=@sprintf("u @ t = %1.2e", t[4])) display( plot(p1,p2,p3,p4, layout=(2,2)) ) end main()
ExactFieldSolutions
https://github.com/tduretz/ExactFieldSolutions.jl.git
[ "MIT" ]
0.1.3
d62c0014dfc5d64ecd16190fa069a8bb04627006
code
950
using ExactFieldSolutions, Plots function main() # Define domain Nx, Ny = 100, 100 x = LinRange(-0.5, 0.5, Nx) y = LinRange(-0.5, 0.5, Ny) # Allocate arrays p = zeros(Nx, Ny) τxx = zeros(Nx, Ny) τyy = zeros(Nx, Ny) τxy = zeros(Nx, Ny) # Evaluate solution for i=1:Nx, j=1:Ny sol = Elasticity2D_Hole( [x[i]; y[j]] ) p[i,j] = sol.p τxx[i,j] = sol.τ[1,1] τyy[i,j] = sol.τ[2,2] τxy[i,j] = sol.τ[1,2] end # Visualise p1 = heatmap(x, y, p', aspect_ratio=1, xlims=(-0.5,0.5), color=:jet, title="p") p2 = heatmap(x, y, τxy', aspect_ratio=1, xlims=(-0.5,0.5), color=:jet, title="τxy") p3 = heatmap(x, y, τxx', aspect_ratio=1, xlims=(-0.5,0.5), color=:jet, title="τxx") p4 = heatmap(x, y, τyy', aspect_ratio=1, xlims=(-0.5,0.5), color=:jet, title="τyy") display( plot(p1,p2,p3,p4, layout=(2,2)) ) end main()
ExactFieldSolutions
https://github.com/tduretz/ExactFieldSolutions.jl.git
[ "MIT" ]
0.1.3
d62c0014dfc5d64ecd16190fa069a8bb04627006
code
1018
using ExactFieldSolutions, Plots function main() # Define domain Nx, Ny = 9, 9 x = LinRange(0, 1, Nx) y = LinRange(0, 1, Ny) xc = 0.5*(x[2:end] .+ x[1:end-1]) yc = 0.5*(y[2:end] .+ y[1:end-1]) # Allocate arrays u = zeros(Nx-1, Ny-1) s = zeros(Nx-1, Ny-1) ∂u∂x = zeros(Nx-1, Ny-1) ∂u∂y = zeros(Nx-1, Ny-1) # Evaluate solution for i=1:Nx-1, j=1:Ny-1 sol = Poisson2D_Sevilla2018( [xc[i]; yc[j]] ) u[i,j] = sol.u s[i,j] = sol.s ∂u∂x[i,j] = sol.∇u[1] ∂u∂y[i,j] = sol.∇u[2] end # Visualise p1 = heatmap(x, y, u', aspect_ratio=1, xlims=(0,1), color=:jet, title="u") p2 = heatmap(x, y, s', aspect_ratio=1, xlims=(0,1), color=:jet, title="s") p3 = heatmap(x, y, ∂u∂x', aspect_ratio=1, xlims=(0,1), color=:jet, title="∂u∂x") p4 = heatmap(x, y, ∂u∂y', aspect_ratio=1, xlims=(0,1), color=:jet, title="∂u∂y") display( plot(p1,p2,p3,p4, layout=(2,2)) ) end main()
ExactFieldSolutions
https://github.com/tduretz/ExactFieldSolutions.jl.git
[ "MIT" ]
0.1.3
d62c0014dfc5d64ecd16190fa069a8bb04627006
code
1078
using ExactFieldSolutions, Plots function main() # Define domain Nx, Ny, Nz = 8, 8, 8 x = LinRange(0, 1, Nx) y = LinRange(0, 1, Ny) z = LinRange(0, 1, Ny) # Allocate arrays u = zeros(Nx, Ny, Nz) s = zeros(Nx, Ny, Nz) ∂u∂x = zeros(Nx, Ny, Nz) ∂u∂y = zeros(Nx, Ny, Nz) ∂u∂z = zeros(Nx, Ny, Nz) # Evaluate solution for i=1:Nx, j=1:Ny, k=1:Ny sol = Poisson3D_Sevilla2018( [x[i]; y[j]; z[j]] ) u[i,j,k] = sol.u s[i,j,k] = sol.s ∂u∂x[i,j,k] = sol.∇u[1] ∂u∂y[i,j,k] = sol.∇u[2] ∂u∂z[i,j,k] = sol.∇u[3] end # Visualise p1 = heatmap(x, y, u[:,:,Int64(ceil(Nz/2))]', aspect_ratio=1, xlims=(0,1), color=:jet, title="u - xy middle cut") p2 = heatmap(x, y, u[:,Int64(ceil(Ny/2)),:]', aspect_ratio=1, xlims=(0,1), color=:jet, title="u - xz middle cut") p3 = heatmap(x, y, u[Int64(ceil(Nx/2)),:,:]', aspect_ratio=1, xlims=(0,1), color=:jet, title="u - yz middle cut") display( plot(p1,p2,p3, layout=(2,2)) ) end main()
ExactFieldSolutions
https://github.com/tduretz/ExactFieldSolutions.jl.git
[ "MIT" ]
0.1.3
d62c0014dfc5d64ecd16190fa069a8bb04627006
code
1748
using ExactFieldSolutions, Plots function main() # Define domain Nx, Ny = 100, 100 x = LinRange(-1.0, 1.0, Nx) y = LinRange(-1.0, 1.0, Ny) # Allocate arrays p = zeros(Nx, Ny) Vx = zeros(Nx, Ny) Vy = zeros(Nx, Ny) Vm = zeros(Nx, Ny) ε̇II = zeros(Nx, Ny) δ = 1.1 γ = sqrt( (sqrt(δ) - 1) / (sqrt(δ) + 1) ) ε̇0 = 1.0 r = 0.1 # Evaluate solution for i=1:Nx, j=1:Ny X = x[i] + im*y[j] X̄ = conj(X) Xm = X - γ*X̄ Xp = X + γ*X̄ # X̄m = X̄ - γ*conj(X̄) # X̄p = X̄ + γ*conj(X̄) X̄m = conj(Xm) X̄p = conj(Xp) V = im*ε̇0*r/(4*γ^2) * (γ*(sqrt(Xp - 4*γ) - sqrt(Xm + 4*γ) + Xm - Xp) + (sqrt(X̄p - 4*γ) + sqrt(X̄m + 4*γ) + X̄m - X̄p)) Vx[i,j] = real(V) #- ε̇0/2*y[j] Vy[i,j] = imag(V) #- ε̇0/2*x[j] Vm[i,j] = sqrt( Vx[i,j]^2 + Vy[i,j]^2 ) if (x[i]^2 + y[j]^2)<r Vx[i,j] = NaN Vy[i,j] = NaN Vm[i,j] = NaN end # sol = Stokes2D_Schmid2003( [x[i]; y[j]] ) # p[i,j] = sol.p # Vx[i,j] = sol.V[1] # Vy[i,j] = sol.V[2] # ε̇II[i,j] = sqrt( 1/2*(sol.ε̇[1,1]^2 + sol.ε̇[2,2]^2) + sol.ε̇[1,2]^2 ) end # Visualise p1 = heatmap(x, y, Vm', aspect_ratio=1, xlims=(-1.0,1.0), color=:jet, title="|V|") p2 = heatmap(x, y, ε̇II', aspect_ratio=1, xlims=(-1.0,1.0), color=:jet, title="ε̇II") p3 = heatmap(x, y, Vx', aspect_ratio=1, xlims=(-1.0,1.0), color=:jet, title="Vx") p4 = heatmap(x, y, Vy', aspect_ratio=1, xlims=(-1.0,1.0), color=:jet, title="Vy") display( plot(p1,p2,p3,p4, layout=(2,2)) ) end main()
ExactFieldSolutions
https://github.com/tduretz/ExactFieldSolutions.jl.git
[ "MIT" ]
0.1.3
d62c0014dfc5d64ecd16190fa069a8bb04627006
code
996
using ExactFieldSolutions, Plots function main() # Define domain Nx, Ny = 100, 100 x = LinRange(0, 1, Nx) y = LinRange(0, 1, Ny) # Allocate arrays p = zeros(Nx, Ny) Vx = zeros(Nx, Ny) Vy = zeros(Nx, Ny) ε̇II = zeros(Nx, Ny) # Evaluate solution for i=1:Nx, j=1:Ny sol = Stokes2D_Donea2003( [x[i]; y[j]] ) p[i,j] = sol.p Vx[i,j] = sol.V[1] Vy[i,j] = sol.V[2] ε̇II[i,j] = sqrt( 1/2*(sol.ε̇[1,1]^2 + sol.ε̇[2,2]^2) + sol.ε̇[1,2]^2 ) end # Visualise p1 = heatmap(x, y, p', aspect_ratio=1, xlims=(-0,1), color=:jet, title="p") p2 = heatmap(x, y, ε̇II', aspect_ratio=1, xlims=(-0,1), color=:jet, title="ε̇II") p3 = heatmap(x, y, sqrt.(Vx.^2 .+ Vy.^2)', aspect_ratio=1, xlims=(-0,1), color=:jet, title="|V|") # p3 = heatmap(x, y, Vx', aspect_ratio=1, xlims=(-0,1), color=:jet, title="Vx") display( plot(p1,p2,p3, layout=(2,2)) ) end main()
ExactFieldSolutions
https://github.com/tduretz/ExactFieldSolutions.jl.git
[ "MIT" ]
0.1.3
d62c0014dfc5d64ecd16190fa069a8bb04627006
code
1447
using ExactFieldSolutions, Plots function main() params = ( θ1 = 30π/180, θ2 = 180π/180, η1 = 1e0, η2 = 1e3, Vr0 = -1., Vt0 = 0., Vr2 = 0., Vt2 = 0., ) # Define domain Lx = 10. Ly = 5. Nx = 400 Ny = Int64(round(abs(Ly)/(Lx)*Nx)) x = LinRange(-Lx/2, Lx/2, Nx) y = LinRange( 0, Ly, Ny) # Allocate arrays p = zeros(Nx, Ny) Vx = zeros(Nx, Ny) Vy = zeros(Nx, Ny) V = zeros(Nx, Ny) ε̇II = zeros(Nx, Ny) # Evaluate solution for i=1:Nx, j=1:Ny sol = Stokes2D_Moulas2021( [x[i]; y[j]]; params ) V[i,j] = sqrt(sol.V[1]^2 + sol.V[2]^2) p[i,j] = sol.p Vx[i,j] = sol.V[1] Vy[i,j] = sol.V[2] ε̇II[i,j] = sqrt( 1/2*(sol.ε̇[1,1]^2 + sol.ε̇[2,2]^2) + sol.ε̇[1,2]^2 ) end # Visualise p1 = heatmap(x, y, p', ylims=(0,Ly), aspect_ratio=1, color=:vik, clims=(-20,20), title="p - Fig. 4 Moulas et al. (2021)", titlefontsize=10) p2 = heatmap(x, y, ε̇II', ylims=(0,Ly), aspect_ratio=1, color=:vik, clims=(0,1), title="ε̇II", titlefontsize=10) p3 = heatmap(x, y, Vx', ylims=(0,Ly), aspect_ratio=1 , color=:vik, title="Vx", titlefontsize=10) p4 = heatmap(x, y, Vy', ylims=(0,Ly), aspect_ratio=1 , color=:vik, title="Vy", titlefontsize=10) display( plot(p1,p2,p3,p4, layout=(2,2)) ) end main()
ExactFieldSolutions
https://github.com/tduretz/ExactFieldSolutions.jl.git
[ "MIT" ]
0.1.3
d62c0014dfc5d64ecd16190fa069a8bb04627006
code
1004
using ExactFieldSolutions, Plots function main() # Define domain Nx, Ny = 100, 100 x = LinRange(-0.5, 0.5, Nx) y = LinRange(-0.5, 0.5, Ny) # Allocate arrays p = zeros(Nx, Ny) Vx = zeros(Nx, Ny) Vy = zeros(Nx, Ny) ε̇II = zeros(Nx, Ny) # Evaluate solution for i=1:Nx, j=1:Ny sol = Stokes2D_Schmid2003( [x[i]; y[j]] ) p[i,j] = sol.p Vx[i,j] = sol.V[1] Vy[i,j] = sol.V[2] ε̇II[i,j] = sqrt( 1/2*(sol.ε̇[1,1]^2 + sol.ε̇[2,2]^2) + sol.ε̇[1,2]^2 ) end # Visualise p1 = heatmap(x, y, p', aspect_ratio=1, xlims=(-0.5,0.5), color=:jet, title="p") p2 = heatmap(x, y, ε̇II', aspect_ratio=1, xlims=(-0.5,0.5), color=:jet, title="ε̇II") p3 = heatmap(x, y, Vx', aspect_ratio=1, xlims=(-0.5,0.5), color=:jet, title="Vx") p4 = heatmap(x, y, Vy', aspect_ratio=1, xlims=(-0.5,0.5), color=:jet, title="Vy") display( plot(p1,p2,p3,p4, layout=(2,2)) ) end main()
ExactFieldSolutions
https://github.com/tduretz/ExactFieldSolutions.jl.git
[ "MIT" ]
0.1.3
d62c0014dfc5d64ecd16190fa069a8bb04627006
code
784
using ExactFieldSolutions, Plots function main() # Define domain Nx, Ny = 100, 100 x = LinRange(0, 1.0, Nx) y = LinRange(0, 1.0, Ny) # Allocate arrays p = zeros(Nx, Ny) Vx = zeros(Nx, Ny) Vy = zeros(Nx, Ny) # Evaluate solution for j=1:Ny, i=1:Nx sol = Stokes2D_SolCx_Zhong1996( [x[i], y[j]] ) p[i,j] = sol.p Vx[i,j] = sol.V[1] Vy[i,j] = sol.V[2] end # Visualise p1 = heatmap(x, y, p', aspect_ratio=1, xlims=(0,1.0), color=:jet, title="p") p2 = heatmap(x, y, Vx', aspect_ratio=1, xlims=(0,1.0), color=:jet, title="Vx") p3 = heatmap(x, y, Vy', aspect_ratio=1, xlims=(0,1.0), color=:jet, title="Vy") display( plot(p1,p2,p3, layout=(2,2)) ) end main()
ExactFieldSolutions
https://github.com/tduretz/ExactFieldSolutions.jl.git
[ "MIT" ]
0.1.3
d62c0014dfc5d64ecd16190fa069a8bb04627006
code
930
using ExactFieldSolutions, Plots function main() # Define domain Nx, Ny = 100, 100 x = LinRange(0, 1.0, Nx) y = LinRange(0, 1.0, Ny) # Allocate arrays p = zeros(Nx, Ny) Vx = zeros(Nx, Ny) Vy = zeros(Nx, Ny) ρ = zeros(Nx, Ny) # Evaluate solution for i=1:Nx, j=1:Ny sol = Stokes2D_SolKz_Zhong1996( [x[i]; y[j]] ) p[i,j] = sol.p Vx[i,j] = sol.V[1] Vy[i,j] = sol.V[2] ρ[i,j] = sol.ρ end # Visualise p1 = heatmap(x, y, p', aspect_ratio=1, xlims=(0,1.0), color=:jet, title="p") p2 = heatmap(x, y, ρ', aspect_ratio=1, xlims=(0,1.0), color=:jet, title="ρ") p3 = heatmap(x, y, Vx', aspect_ratio=1, xlims=(0,1.0), color=:jet, title="Vx") p4 = heatmap(x, y, Vy', aspect_ratio=1, xlims=(0,1.0), color=:jet, title="Vy") display( plot(p1,p2,p3,p4, layout=(2,2)) ) end main()
ExactFieldSolutions
https://github.com/tduretz/ExactFieldSolutions.jl.git
[ "MIT" ]
0.1.3
d62c0014dfc5d64ecd16190fa069a8bb04627006
code
910
module ExactFieldSolutions using Plots, SpecialFunctions, ForwardDiff, UnPack, StaticArrays include("Diffusion1D/Diffusion1D_Gaussian.jl") export Diffusion1D_Gaussian include("Diffusion2D/Diffusion2D_Gaussian.jl") export Diffusion2D_Gaussian include("Poisson2D/Poisson2D_Sevilla2018.jl") # export Poisson2D_Sevilla2018_enz export Poisson2D_Sevilla2018 include("Poisson3D/Poisson3D_Sevilla2018.jl") export Poisson3D_Sevilla2018 include("Stokes2D/Stokes2D_Donea2003.jl") export Stokes2D_Donea2003 include("Stokes2D/Stokes2D_Schmid2003.jl") export Stokes2D_Schmid2003 include("Stokes2D/Stokes2D_Moulas2021.jl") export Stokes2D_Moulas2021 include("Stokes2D/Stokes2D_SolKz_Zhong1996.jl") export Stokes2D_SolKz_Zhong1996 include("Stokes2D/Stokes2D_SolCx_Zhong1996.jl") export Stokes2D_SolCx_Zhong1996 include("Elasticity2D/Elasticity2D_Hole.jl") export Elasticity2D_Hole end # module ExactFieldSolutions
ExactFieldSolutions
https://github.com/tduretz/ExactFieldSolutions.jl.git
[ "MIT" ]
0.1.3
d62c0014dfc5d64ecd16190fa069a8bb04627006
code
1211
function Diffusion1D_Gaussian_u_fwd(x, params) @unpack T0, K, σ = params return T0 / sqrt(1 + 2*x[2]*K/σ^2) * exp.(-x[1]^2 / (2*(σ^2 + 2*x[2]*K)) ) end @doc raw""" sol = Diffusion1D_Gaussian(x; params) Evaluates the manufactured solution of an initial 2D Gaussian anomaly: x : is the coordinate and time vector, x[1] is space and x[2] is time params : optional parameter array, default: (T0 = 100., K = 1e-6, σ = 0.1 ) and returns: sol : tuple containing the solution fields u, ∇u and the source term s = -Δu # Examples ```julia-repl julia> Diffusion1D_Gaussian([0 0]) (u = 100.0, ∇u = [0.0 0.0 -0.06283185307179585], s = 0.0) ``` ```julia-repl julia> params = (T0 = 1., K = 1.0, σ = 0.1 ) (T0 = 1.0, K = 1.0, σ = 0.1) julia> Diffusion1D_Gaussian([0 0]) (u = 1.0, ∇u = [0.0 -99.99999999999999], s = 0.0) ``` """ function Diffusion1D_Gaussian(x; params = (T0 = 100., K = 1e-6, σ = 0.1 ) ) u = Diffusion1D_Gaussian_u_fwd(x, params) f_cl = x -> Diffusion1D_Gaussian_u_fwd(x, params) gradu = ForwardDiff.gradient(f_cl, x) hessu = ForwardDiff.hessian(f_cl, x) s = gradu[2] - params.K*(hessu[1,1]) return (u=u, ∇u=gradu, s=s) end
ExactFieldSolutions
https://github.com/tduretz/ExactFieldSolutions.jl.git
[ "MIT" ]
0.1.3
d62c0014dfc5d64ecd16190fa069a8bb04627006
code
1004
function DiffusionReaction1D_Stefan_u_fwd(x, params) @unpack T0, K, σ = params λ = s/(2*sqrt(K*x[2])) return T0 - T0/erf(λ) * erf(x[1]/(2*sqrt(K*x[2]))) end @doc raw""" sol = Diffusion1D_Gaussian(x; params) Evaluates the manufactured solution of an initial 2D Gaussian anomaly: x : is the coordinate and time vector, x[1] is space and x[2] is time params : optional parameter array and returns: sol : tuple containing the solution fields u, ∇u and the source term s = -Δu # Examples ```julia-repl julia> Diffusion1D_Gaussian([0 0]) (u = 100.0, ∇u = [0.0 0.0 -0.06283185307179585], s = 0.0) ``` """ function Diffusion1D_Gaussian(x; params = (T0 = 100., K = 1e-6, σ = 0.1 ) ) u = Diffusion1D_Gaussian_u_fwd(x, params) f_cl = x -> Diffusion1D_Gaussian_u_fwd(x, params) gradu = ForwardDiff.gradient(f_cl, x) hessu = ForwardDiff.hessian(f_cl, x) s = gradu[2] - params.K*(hessu[1,1]) return (u=u, ∇u=gradu, s=s) end
ExactFieldSolutions
https://github.com/tduretz/ExactFieldSolutions.jl.git
[ "MIT" ]
0.1.3
d62c0014dfc5d64ecd16190fa069a8bb04627006
code
1009
function Diffusion2D_Gaussian_u_fwd(x, params) @unpack T0, K, σ = params return T0/(1 + 2*π*K*x[3]/σ^2)*exp(-(x[1]^2 + x[2]^2) /( 2*σ^2/π + 4*K*x[3])) end @doc raw""" sol = Diffusion2D_Gaussian(x; params) Evaluates the manufactured solution of an initial 2D Gaussian anomaly: x : is the coordinate and time vector, x[1:2] is space and x[3] is time params : optional parameter array and returns: sol : tuple containing the solution fields u, ∇u and the source term s = -Δu # Examples ```julia-repl julia> Diffusion2D_Gaussian([0 0 0]) (u = 100.0, ∇u = [0.0 0.0 -0.06283185307179585], s = 0.0) ``` """ function Diffusion2D_Gaussian(x; params = (T0 = 100., K = 1e-6, σ = 0.1 ) ) u = Diffusion2D_Gaussian_u_fwd(x, params) f_cl = x -> Diffusion2D_Gaussian_u_fwd(x, params) gradu = ForwardDiff.gradient(f_cl, x) hessu = ForwardDiff.hessian(f_cl, x) s = gradu[3] - params.K*(hessu[1,1] + hessu[2,2]) return (u=u, ∇u=gradu, s=s) end
ExactFieldSolutions
https://github.com/tduretz/ExactFieldSolutions.jl.git
[ "MIT" ]
0.1.3
d62c0014dfc5d64ecd16190fa069a8bb04627006
code
1316
@doc raw""" sol = Elasticity2D_Hole(x; params) Evaluates the solution for an elastic medium with a circular hole under far field stress (derived from Kirsch solution, Jaeger & Cook etc...): x : is the coordinate vector params : optional parameter array and returns: sol : tuple containing the solution fields u, ∇u and the source term s = -Δu # Examples ```julia-repl julia> Elasticity2D_Hole([0,0]) (p = -0.01, τ = [0.0 -0.0; -0.0 -0.0]) ``` """ function Elasticity2D_Hole(x; params = (r0 = 0.2, P_inf = 1e-2, P0 = -1e-2, tau_inf = -1e-2)) @unpack r0, P_inf, P0, tau_inf = params rad = sqrt(x[1]^2 + x[2]^2) irad = 1.0/max(rad,r0/2); irad>1/r0 ? irad = 0 : nothing r0_r = r0*irad cost = x[1]*irad sint = x[2]*irad C1 = -3*r0_r^4 + 2*r0_r^2 C2 = -3*r0_r^4 + 2*r0_r^2 cos2t = cost^2 - sint^2 sin2t = 2*cost*sint Pt = P_inf - 2*tau_inf* r0_r^2.0.*cos2t tau_rr = (P_inf-P0)*r0_r^2 + tau_inf*(C1 - 1)*cos2t tau_rt = tau_inf*(C2 + 1)*sin2t tau_tt = -tau_rr Txx = cos2t*tau_rr - sin2t*tau_rt Txy = -sin2t*tau_tt + tau_rt*cos2t Tyy = -Txx rad.<r0 ? Pt = P0 : nothing return (p= Pt, τ=[Txx Txy; Txy Tyy]) end
ExactFieldSolutions
https://github.com/tduretz/ExactFieldSolutions.jl.git
[ "MIT" ]
0.1.3
d62c0014dfc5d64ecd16190fa069a8bb04627006
code
3267
function Poisson2D_Sevilla2018_u_fwd(x, params) @unpack α, β, a, b, c, d = params return exp(α*sin(a*x[1] + c*x[2]) + β*cos(b*x[1] + d*x[2])) end @doc raw""" sol = Poisson2D_Sevilla2018(x; params) Evaluates the manufactured solution of [Sevilla et al. (2018)](https://onlinelibrary.wiley.com/doi/abs/10.1002/nme.5833): x : is the coordinate vector params : optional parameter array and returns: sol : tuple containing the solution fields u, ∇u and the source term s = -Δu # Examples ```julia-repl julia> Poisson2D_Sevilla2018( [0, 0] ) (u = 1.3498588075760032, ∇u = [0.6884279918637617, -0.8369124606971221], s = 11.298993148814933) ``` """ function Poisson2D_Sevilla2018(x; params = (α = 0.1, β = 0.3, a = 5.1, b = 4.3, c = -6.2, d = 3.4) ) u = Poisson2D_Sevilla2018_u_fwd(x, params) f_cl = x -> Poisson2D_Sevilla2018_u_fwd(x, params) gradu = ForwardDiff.gradient(f_cl, x) hessu = ForwardDiff.hessian(f_cl, x) s = -(hessu[1,1] + hessu[2,2]) # T = u # @unpack α, β, a, b, c, d = params # s = T*(-a*α*cos(a*x[1] + c*x[2]) + b*β*sin(b*x[1] + d*x[2]))*(a*α*cos(a*x[1] + c*x[2]) - b*β*sin(b*x[1] + d*x[2])) + T*(a^2*α*sin(a*x[1] + c*x[2]) + b^2*β*cos(b*x[1] + d*x[2])) + T*(-α*c*cos(a*x[1] + c*x[2]) + β*d*sin(b*x[1] + d*x[2]))*(α*c*cos(a*x[1] + c*x[2]) - β*d*sin(b*x[1] + d*x[2])) + T*(α*c^2*sin(a*x[1] + c*x[2]) + β*d^2*cos(b*x[1] + d*x[2])) return (u=u, ∇u=gradu, s=s) end # I've tried to use Enzyme BUT: # 1) outputs are difficult gradient components end nested in complicated data structures (arrays of arrays or tuples of arrays) # 2) never managed to compute higher order derivatives # 3) overall package compilation seemed much slower than with ForwardDiff # Poisson2D_Sevilla2018_gradu(x, y, params) = autodiff(Reverse, Poisson2D_Sevilla2018_u, Active(x), Active(y), Const(params)) # Poisson2D_Sevilla2018_dudx( x, y, params) = autodiff(Reverse, Poisson2D_Sevilla2018_u, Active(x), Const(y), Const(params)) # Poisson2D_Sevilla2018_d2udx2( x, y, params) = autodiff_deferred(Reverse, Poisson2D_Sevilla2018_dudx, Active(x), Const(y), Const(params)) # Poisson2D_Sevilla2018_dudx(x, y, params) = autodiff(Reverse, Poisson2D_Sevilla2018_u, Active(x), Const(y), Const(params)) # Poisson2D_Sevilla2018_d2udx2(x, y, params) = autodiff_deferred(Reverse, Poisson2D_Sevilla2018_dudx, Active(x), Const(y), Const(params)) # Poisson2D_Sevilla2018_d2udy2(x, y, params) = autodiff_deferred(Reverse, Poisson2D_Sevilla2018_dudx, Const(x), Active(y), Const(params)) # function Poisson2D_Sevilla2018_s(x, y, params) # end # function Poisson2D_Sevilla2018_u(x, y, params) # @unpack α, β, a, b, c, d = params # return exp(α*sin(a*x + c*y) + β*cos(b*x + d*y)) # end # function Poisson2D_Sevilla2018_enz(x, y; # params = (α = 0.1, β = 0.3, a = 5.1, b = 4.3, c = -6.2, d = 3.4) ) # u = Poisson2D_Sevilla2018_u(x, y, params) # gradu = Poisson2D_Sevilla2018_gradu(x, y, params) # # ∂2u∂x2 = Poisson2D_Sevilla2018_d2udx2(x, y, params) # # ∂2u∂y2 = Poisson2D_Sevilla2018_d2udy2(x, y, params) # # Poisson2D_Sevilla2018_d2udx2(x, y, params) # s = 1 # # @show ∂2u∂y2[1][1] # return (u=u, ∂u∂x=gradu[1][1], ∂u∂y=gradu[1][2], s=s) # end
ExactFieldSolutions
https://github.com/tduretz/ExactFieldSolutions.jl.git
[ "MIT" ]
0.1.3
d62c0014dfc5d64ecd16190fa069a8bb04627006
code
1122
function Poisson3D_Sevilla2018_u(x, params) @unpack α, β, a, b, c, d, e, f = params return exp(α*sin(a*x[1] + c*x[2] + e*x[3]) + β*cos(b*x[1] + d*x[2] + f*x[3])) end @doc raw""" sol = Poisson3D_Sevilla2018(x; params) Evaluates the manufactured solution of [Sevilla et al. (2018)](https://onlinelibrary.wiley.com/doi/abs/10.1002/nme.5833): x : is the coordinate vector params : optional parameter array and returns: sol : tuple containing the solution fields u, ∇u and the source term s = -Δu # Examples ```julia-repl julia> Poisson3D_Sevilla2018( [0; 0; 0]) (u = 1.3498588075760032, ∇u = [0.6884279918637617, -0.8369124606971221, 0.2429745853636806], s = 12.425585309617865) ``` """ function Poisson3D_Sevilla2018(x; params = (α = 0.1, β = 0.3, a = 5.1, b = 4.3, c = -6.2, d = 3.4, e = 1.8, f = 1.7) ) u = Poisson3D_Sevilla2018_u(x, params) f_cl = x -> Poisson3D_Sevilla2018_u(x, params) gradu = ForwardDiff.gradient(f_cl, x) hessu = ForwardDiff.hessian(f_cl, x) s = -(hessu[1,1] + hessu[2,2] + hessu[3,3]) return (u=u, ∇u=gradu, s=s) end
ExactFieldSolutions
https://github.com/tduretz/ExactFieldSolutions.jl.git
[ "MIT" ]
0.1.3
d62c0014dfc5d64ecd16190fa069a8bb04627006
code
2455
function Stokes2D_Donea2003_p(x, params) return x[1]*(1-x[1]) end function Stokes2D_Donea2003_V(x, params) vx = x[1]^2*(1 - x[1])^2*(4*x[2]^3 - 6*x[2]^2 + 2*x[2]) vy = -x[2]^2*(1 - x[2])^2*(4*x[1]^3 - 6*x[1]^2 + 2*x[1]) return [vx; vy] end function TotalStress( x,; params = (η=1,) ) p = Stokes2D_Donea2003_p(x, params) v = Stokes2D_Donea2003_V(x, params) f_cl = x -> Stokes2D_Donea2003_V(x, params) L = ForwardDiff.jacobian(f_cl, x) # Deviatoric strain rate ε̇ = 1/2*(L + L') # Deviatoric stress τ = 2*params.η*ε̇ # Total stress return τ - [1 0; 0 1].*p end @doc raw""" sol = Stokes2D_Donea2003(x; params) Evaluates a manufactured solution from [Donea & Huerta (2003)](https://onlinelibrary.wiley.com/doi/book/10.1002/0470013826): x : is the coordinate vector params : optional parameter array and returns: sol : tuple containing the solution fields p (pressure), V (velocity vector), L (velocity gratdient tensor), ε̇ (deviatoric strain rate tensor) and τ (deviatoric stress tensor) # Examples ```julia-repl julia> Stokes2D_Donea2003([1/4;1/4]) (p = 0.1875, V = [0.006591796875, -0.006591796875], L = [0.03515625 -0.0087890625; 0.0087890625 -0.03515625], ε̇ = [0.03515625 0.0; 0.0 -0.03515625], τ = [0.0703125 0.0; 0.0 -0.0703125]) ``` """ function Stokes2D_Donea2003(X; params = (η=1,) ) p = Stokes2D_Donea2003_p(X, params) v = Stokes2D_Donea2003_V(X, params) f_cl = X -> Stokes2D_Donea2003_V(X, params) L = ForwardDiff.jacobian(f_cl, X) # Deviatoric strain rate ε̇ = 1/2*(L + L') # Deviatoric stress τ = 2*params.η*ε̇ # Total stress σ = TotalStress( X ) g_cl = X -> TotalStress(X; params) ∂σ∂x = ForwardDiff.jacobian(g_cl, X) # Stokes residual is the source for this solution s = -[∂σ∂x[1] + ∂σ∂x[3,2]; ∂σ∂x[2,1] + ∂σ∂x[4,2]] # # Just to check # x, y = X[1], X[2] # sx = -p^2*(24*y - 12) - 4*x^2*(4*y^3 - 6*y^2 + 2*y) - 8*x*(2*x - 2)*(4*y^3 - 6*y^2 + 2*y) - 2*x + 1.0*y^2*(2*y - 2)*(12*x^2 - 12*x + 2) + 2.0*y*(1 - y)^2*(12*x^2 - 12*x + 2) - 4*(1 - x)^2*(4*y^3 - 6*y^2 + 2*y) + 1 # sy = -2*p*(1 - x)*(12*y^2 - 12*y + 2) - x^2*(2*x - 2)*(12*y^2 - 12*y + 2) + 1.0*y^2*(1 - y)^2*(24*x - 12) + 4*y^2*(4*x^3 - 6*x^2 + 2*x) + 8*y*(2*y - 2)*(4*x^3 - 6*x^2 + 2*x) + 4*(1 - y)^2*(4*x^3 - 6*x^2 + 2*x) # @show sy-s[2] return (p=p, V=v, L=L, ε̇=ε̇, τ=τ, s=s) end
ExactFieldSolutions
https://github.com/tduretz/ExactFieldSolutions.jl.git
[ "MIT" ]
0.1.3
d62c0014dfc5d64ecd16190fa069a8bb04627006
code
17362
function ComputeConstants( params ) @unpack θ1, θ2, η1, η2, Vr0, Vt0, Vr2, Vt2 = params A1 = -Vt0 B1 = ((sin(θ1)^2*(η1*η2*cos(θ2)^2+η1^2*(θ2^2*sin(θ2)^2+(θ2^2-1.0)*cos(θ2)^2)+θ1^2* (η2^2*(cos(θ2)^2+sin(θ2)^2)+η1^2*(cos(θ2)^2+sin(θ2)^2)+η1*η2*(-2.0*cos(θ2)^2-2.0*sin(θ2)^2))+θ1* (η1*η2*(2.0*θ2*cos(θ2)^2+2.0*θ2*sin(θ2)^2)+η1^2*(-2.0*θ2*cos(θ2)^2-2.0*θ2*sin(θ2)^2)))+cos(θ1)^2*(η1*η2*sin(θ2)^2+η1^2*((θ2^2-1.0)*sin(θ2)^2+θ2^2*cos(θ2)^2)+θ1^2* (η2^2*(cos(θ2)^2+sin(θ2)^2)+η1^2*(cos(θ2)^2+sin(θ2)^2)+η1*η2*(-2.0*cos(θ2)^2-2.0*sin(θ2)^2))+θ1* (η1*η2*(2.0*θ2*cos(θ2)^2+2.0*θ2*sin(θ2)^2)+η1^2*(-2.0*θ2*cos(θ2)^2-2.0*θ2*sin(θ2)^2)))+cos(θ1)*sin(θ1)*(2.0*η1^2*cos(θ2)*sin(θ2)-2.0*η1*η2*cos(θ2)*sin(θ2)))*Vr0+( sin(θ1)^2*(η1*η2*(-1.0*θ2*sin(θ2)^2-1.0*cos(θ2)*sin(θ2)-1.0*θ2*cos(θ2)^2)+θ1*(η1*η2*(cos(θ2)^2+sin(θ2)^2)+η2^2*(-1.0*cos(θ2)^2-1.0*sin(θ2)^2)))+cos(θ1)^2* (η1*η2*(-1.0*θ2*sin(θ2)^2-1.0*cos(θ2)*sin(θ2)-1.0*θ2*cos(θ2)^2)+θ1*(η1*η2*(cos(θ2)^2+sin(θ2)^2)+η2^2*(-1.0*cos(θ2)^2-1.0*sin(θ2)^2)))+cos(θ1)*sin(θ1)* (η2^2*(-1.0*sin(θ2)^2-1.0*cos(θ2)^2)+η1*η2*(sin(θ2)^2+cos(θ2)^2)))*Vt0+cos(θ1)*sin(θ1)*(η2^2*(sin(θ2)*Vr2+cos(θ2)*Vt2)+η1*η2*(-1.0*sin(θ2)*Vr2-1.0*cos(θ2)*Vt2))+ sin(θ1)^2* (θ1*(η1*η2*(-1.0*cos(θ2)*Vt2-1.0*sin(θ2)*Vr2)+η2^2*(cos(θ2)*Vt2+sin(θ2)*Vr2))+η2^2*(sin(θ2)*Vt2-1.0*cos(θ2)*Vr2)+η1*η2*((θ2*sin(θ2)+cos(θ2))*Vr2+θ2*cos(θ2)*Vt2)) +cos(θ1)^2*(θ1*(η1*η2*(-1.0*cos(θ2)*Vt2-1.0*sin(θ2)*Vr2)+η2^2*(cos(θ2)*Vt2+sin(θ2)*Vr2))+η1*η2*(θ2*sin(θ2)*Vr2+θ2*cos(θ2)*Vt2+sin(θ2)*Vt2)))/(sin(θ1)^2*(2.0*η1* η2*cos(θ2)^2+η2^2*(-1.0*sin(θ2)^2-1.0*cos(θ2)^2)+η1^2*(θ2^2*sin(θ2)^2+(θ2^2-1.0)*cos(θ2)^2)+θ1^2* (η2^2*(cos(θ2)^2+sin(θ2)^2)+η1^2*(cos(θ2)^2+sin(θ2)^2)+η1*η2*(-2.0*cos(θ2)^2-2.0*sin(θ2)^2))+θ1* (η1*η2*(2.0*θ2*cos(θ2)^2+2.0*θ2*sin(θ2)^2)+η1^2*(-2.0*θ2*cos(θ2)^2-2.0*θ2*sin(θ2)^2)))+cos(θ1)^2*(η1^2*((θ2^2-1.0)*sin(θ2)^2+θ2^2*cos(θ2)^2)+θ1^2* (η2^2*(cos(θ2)^2+sin(θ2)^2)+η1^2*(cos(θ2)^2+sin(θ2)^2)+η1*η2*(-2.0*cos(θ2)^2-2.0*sin(θ2)^2))+θ1* (η1*η2*(2.0*θ2*cos(θ2)^2+2.0*θ2*sin(θ2)^2)+η1^2*(-2.0*θ2*cos(θ2)^2-2.0*θ2*sin(θ2)^2)))+cos(θ1)*sin(θ1)*(2.0*η1^2*cos(θ2)*sin(θ2)-2.0*η1*η2*cos(θ2)*sin(θ2))); C1 = -(1.0*((sin(θ1)^2*(η2^2*(sin(θ2)^2+cos(θ2)^2)-1.0*η1*η2*cos(θ2)^2)+η1*η2*cos(θ1)^2*sin(θ2)^2)*Vr0+(sin(θ1)^2* (η1*η2*(-1.0*θ2*sin(θ2)^2-1.0*cos(θ2)*sin(θ2)-1.0*θ2*cos(θ2)^2)+θ1*(η1*η2*(cos(θ2)^2+sin(θ2)^2)+η2^2*(-1.0*cos(θ2)^2-1.0*sin(θ2)^2)))+cos(θ1)^2* (η1*η2*(-1.0*θ2*sin(θ2)^2-1.0*cos(θ2)*sin(θ2)-1.0*θ2*cos(θ2)^2)+θ1*(η1*η2*(cos(θ2)^2+sin(θ2)^2)+η2^2*(-1.0*cos(θ2)^2-1.0*sin(θ2)^2)))+cos(θ1)*sin(θ1)* (η2^2*(-1.0*sin(θ2)^2-1.0*cos(θ2)^2)+η1*η2*(sin(θ2)^2+cos(θ2)^2)))*Vt0+cos(θ1)*sin(θ1)*(η2^2*(sin(θ2)*Vr2+cos(θ2)*Vt2)+η1*η2*(-1.0*sin(θ2)*Vr2-1.0*cos(θ2)*Vt2))+ sin(θ1)^2* (θ1*(η1*η2*(-1.0*cos(θ2)*Vt2-1.0*sin(θ2)*Vr2)+η2^2*(cos(θ2)*Vt2+sin(θ2)*Vr2))+η2^2*(sin(θ2)*Vt2-1.0*cos(θ2)*Vr2)+η1*η2*((θ2*sin(θ2)+cos(θ2))*Vr2+θ2*cos(θ2)*Vt2)) +cos(θ1)^2*(θ1*(η1*η2*(-1.0*cos(θ2)*Vt2-1.0*sin(θ2)*Vr2)+η2^2*(cos(θ2)*Vt2+sin(θ2)*Vr2))+η1*η2*(θ2*sin(θ2)*Vr2+θ2*cos(θ2)*Vt2+sin(θ2)*Vt2))))/(sin(θ1)^2*(2.0*η1* η2*cos(θ2)^2+η2^2*(-1.0*sin(θ2)^2-1.0*cos(θ2)^2)+η1^2*(θ2^2*sin(θ2)^2+(θ2^2-1.0)*cos(θ2)^2)+θ1^2* (η2^2*(cos(θ2)^2+sin(θ2)^2)+η1^2*(cos(θ2)^2+sin(θ2)^2)+η1*η2*(-2.0*cos(θ2)^2-2.0*sin(θ2)^2))+θ1* (η1*η2*(2.0*θ2*cos(θ2)^2+2.0*θ2*sin(θ2)^2)+η1^2*(-2.0*θ2*cos(θ2)^2-2.0*θ2*sin(θ2)^2)))+cos(θ1)^2*(η1^2*((θ2^2-1.0)*sin(θ2)^2+θ2^2*cos(θ2)^2)+θ1^2* (η2^2*(cos(θ2)^2+sin(θ2)^2)+η1^2*(cos(θ2)^2+sin(θ2)^2)+η1*η2*(-2.0*cos(θ2)^2-2.0*sin(θ2)^2))+θ1* (η1*η2*(2.0*θ2*cos(θ2)^2+2.0*θ2*sin(θ2)^2)+η1^2*(-2.0*θ2*cos(θ2)^2-2.0*θ2*sin(θ2)^2)))+cos(θ1)*sin(θ1)*(2.0*η1^2*cos(θ2)*sin(θ2)-2.0*η1*η2*cos(θ2)*sin(θ2))); D1 = -(1.0*((sin(θ1)^2*(η1*η2*(θ2*sin(θ2)^2-1.0*cos(θ2)*sin(θ2)+θ2*cos(θ2)^2)+θ1*(η2^2*(cos(θ2)^2+sin(θ2)^2)+η1*η2*(-1.0*cos(θ2)^2-1.0*sin(θ2)^2)))+cos(θ1)^2* (η1*η2*(θ2*sin(θ2)^2-1.0*cos(θ2)*sin(θ2)+θ2*cos(θ2)^2)+θ1*(η2^2*(cos(θ2)^2+sin(θ2)^2)+η1*η2*(-1.0*cos(θ2)^2-1.0*sin(θ2)^2)))+cos(θ1)*sin(θ1)* (η2^2*(-1.0*sin(θ2)^2-1.0*cos(θ2)^2)+η1*η2*(sin(θ2)^2+cos(θ2)^2)))*Vr0+(sin(θ1)^2*(η1*η2*cos(θ2)^2+η2^2*(-1.0*sin(θ2)^2-1.0*cos(θ2)^2))-1.0*η1*η2*cos(θ1)^2*sin(θ2)^2)* Vt0+cos(θ1)*sin(θ1)*(η1*η2*(sin(θ2)*Vt2-1.0*cos(θ2)*Vr2)+η2^2*(cos(θ2)*Vr2-1.0*sin(θ2)*Vt2))+cos(θ1)^2* (θ1*(η1*η2*(cos(θ2)*Vr2-1.0*sin(θ2)*Vt2)+η2^2*(sin(θ2)*Vt2-1.0*cos(θ2)*Vr2))+η1*η2*((sin(θ2)-1.0*θ2*cos(θ2))*Vr2+θ2*sin(θ2)*Vt2))+sin(θ1)^2*(θ1* (η1*η2*(cos(θ2)*Vr2-1.0*sin(θ2)*Vt2)+η2^2*(sin(θ2)*Vt2-1.0*cos(θ2)*Vr2))+η1*η2*(-1.0*θ2*cos(θ2)*Vr2-1.0*cos(θ2)*Vt2+θ2*sin(θ2)*Vt2)+η2^2*(sin(θ2)*Vr2+cos(θ2)*Vt2)) ))/(sin(θ1)^2*(2.0*η1*η2*cos(θ2)^2+η2^2*(-1.0*sin(θ2)^2-1.0*cos(θ2)^2)+η1^2*(θ2^2*sin(θ2)^2+(θ2^2-1.0)*cos(θ2)^2)+θ1^2* (η2^2*(cos(θ2)^2+sin(θ2)^2)+η1^2*(cos(θ2)^2+sin(θ2)^2)+η1*η2*(-2.0*cos(θ2)^2-2.0*sin(θ2)^2))+θ1* (η1*η2*(2.0*θ2*cos(θ2)^2+2.0*θ2*sin(θ2)^2)+η1^2*(-2.0*θ2*cos(θ2)^2-2.0*θ2*sin(θ2)^2)))+cos(θ1)^2*(η1^2*((θ2^2-1.0)*sin(θ2)^2+θ2^2*cos(θ2)^2)+θ1^2* (η2^2*(cos(θ2)^2+sin(θ2)^2)+η1^2*(cos(θ2)^2+sin(θ2)^2)+η1*η2*(-2.0*cos(θ2)^2-2.0*sin(θ2)^2))+θ1* (η1*η2*(2.0*θ2*cos(θ2)^2+2.0*θ2*sin(θ2)^2)+η1^2*(-2.0*θ2*cos(θ2)^2-2.0*θ2*sin(θ2)^2)))+cos(θ1)*sin(θ1)*(2.0*η1^2*cos(θ2)*sin(θ2)-2.0*η1*η2*cos(θ2)*sin(θ2))); A2 = -(1.0*((sin(θ1)^2* (θ1*(η1*η2*sin(θ2)^2-1.0*η1^2*sin(θ2)^2)+η1*η2*(-1.0*θ2*sin(θ2)^2+cos(θ2)*sin(θ2)-1.0*θ2*cos(θ2)^2)+η1^2*(θ2*sin(θ2)^2-1.0*cos(θ2)*sin(θ2)+θ2*cos(θ2)^2))+θ1* cos(θ1)^2*(η1*η2*sin(θ2)^2-1.0*η1^2*sin(θ2)^2)+cos(θ1)*sin(θ1)*(η1^2*sin(θ2)^2-1.0*η1*η2*sin(θ2)^2))*Vr0+(sin(θ1)^2*(-1.0*η1*η2*sin(θ2)^2+η1^2* (θ2^2*sin(θ2)^2+θ2^2*cos(θ2)^2)+θ1*(η1*η2*(θ2*cos(θ2)^2-1.0*cos(θ2)*sin(θ2)+θ2*sin(θ2)^2)+η1^2*(-1.0*θ2*cos(θ2)^2+cos(θ2)*sin(θ2)-1.0*θ2*sin(θ2)^2)))+cos(θ1)^2* (η1^2*((θ2^2-1.0)*sin(θ2)^2+θ2^2*cos(θ2)^2)+θ1*(η1*η2*(θ2*cos(θ2)^2-1.0*cos(θ2)*sin(θ2)+θ2*sin(θ2)^2)+η1^2*(-1.0*θ2*cos(θ2)^2+cos(θ2)*sin(θ2)-1.0*θ2*sin(θ2)^2)))+ cos(θ1)*sin(θ1)*(η1^2*(-1.0*θ2*sin(θ2)^2+cos(θ2)*sin(θ2)-1.0*θ2*cos(θ2)^2)+η1*η2*(θ2*sin(θ2)^2-1.0*cos(θ2)*sin(θ2)+θ2*cos(θ2)^2)))*Vt0+cos(θ1)*sin(θ1)* (η1^2*(θ2*sin(θ2)*Vr2+θ2*cos(θ2)*Vt2+sin(θ2)*Vt2)+η1*η2*(-1.0*θ2*sin(θ2)*Vr2-1.0*θ2*cos(θ2)*Vt2-1.0*sin(θ2)*Vt2))+cos(θ1)^2*(θ1* (η1^2*(-1.0*sin(θ2)*Vt2-1.0*θ2*cos(θ2)*Vt2-1.0*θ2*sin(θ2)*Vr2)+η1*η2*(sin(θ2)*Vt2+θ2*cos(θ2)*Vt2+θ2*sin(θ2)*Vr2))+θ1^2* (η1*η2*(-2.0*cos(θ2)*Vt2-2.0*sin(θ2)*Vr2)+η1^2*(cos(θ2)*Vt2+sin(θ2)*Vr2)+η2^2*(cos(θ2)*Vt2+sin(θ2)*Vr2)))+sin(θ1)^2*(θ1* (η1^2*(-1.0*sin(θ2)*Vt2-1.0*θ2*cos(θ2)*Vt2-1.0*θ2*sin(θ2)*Vr2)+η1*η2*(sin(θ2)*Vt2+θ2*cos(θ2)*Vt2+θ2*sin(θ2)*Vr2))+θ1^2* (η1*η2*(-2.0*cos(θ2)*Vt2-2.0*sin(θ2)*Vr2)+η1^2*(cos(θ2)*Vt2+sin(θ2)*Vr2)+η2^2*(cos(θ2)*Vt2+sin(θ2)*Vr2))+η1^2*(-1.0*θ2*cos(θ2)*Vr2-1.0*cos(θ2)*Vt2+θ2*sin(θ2)*Vt2)+ η1*η2*((sin(θ2)+θ2*cos(θ2))*Vr2+2.0*cos(θ2)*Vt2-1.0*θ2*sin(θ2)*Vt2)+η2^2*(-1.0*sin(θ2)*Vr2-1.0*cos(θ2)*Vt2))))/(sin(θ1)^2*(2.0*η1*η2*cos(θ2)^2+η2^2* (-1.0*sin(θ2)^2-1.0*cos(θ2)^2)+η1^2*(θ2^2*sin(θ2)^2+(θ2^2-1.0)*cos(θ2)^2)+θ1^2*(η2^2*(cos(θ2)^2+sin(θ2)^2)+η1^2*(cos(θ2)^2+sin(θ2)^2)+η1*η2*(-2.0*cos(θ2)^2-2.0*sin(θ2)^2))+ θ1*(η1*η2*(2.0*θ2*cos(θ2)^2+2.0*θ2*sin(θ2)^2)+η1^2*(-2.0*θ2*cos(θ2)^2-2.0*θ2*sin(θ2)^2)))+cos(θ1)^2*(η1^2*((θ2^2-1.0)*sin(θ2)^2+θ2^2*cos(θ2)^2)+θ1^2* (η2^2*(cos(θ2)^2+sin(θ2)^2)+η1^2*(cos(θ2)^2+sin(θ2)^2)+η1*η2*(-2.0*cos(θ2)^2-2.0*sin(θ2)^2))+θ1* (η1*η2*(2.0*θ2*cos(θ2)^2+2.0*θ2*sin(θ2)^2)+η1^2*(-2.0*θ2*cos(θ2)^2-2.0*θ2*sin(θ2)^2)))+cos(θ1)*sin(θ1)*(2.0*η1^2*cos(θ2)*sin(θ2)-2.0*η1*η2*cos(θ2)*sin(θ2))); B2 = ((cos(θ1)^2* (η1^2*(θ2^2*sin(θ2)^2+θ2^2*cos(θ2)^2)+θ1*(η1*η2*(θ2*cos(θ2)^2+cos(θ2)*sin(θ2)+θ2*sin(θ2)^2)+η1^2*(-1.0*θ2*cos(θ2)^2-1.0*cos(θ2)*sin(θ2)-1.0*θ2*sin(θ2)^2)))+sin(θ1)^2*( η1*η2*cos(θ2)^2+η1^2*(θ2^2*sin(θ2)^2+(θ2^2-1.0)*cos(θ2)^2)+θ1* (η1*η2*(θ2*cos(θ2)^2+cos(θ2)*sin(θ2)+θ2*sin(θ2)^2)+η1^2*(-1.0*θ2*cos(θ2)^2-1.0*cos(θ2)*sin(θ2)-1.0*θ2*sin(θ2)^2)))+cos(θ1)*sin(θ1)* (η1*η2*(-1.0*θ2*sin(θ2)^2-1.0*cos(θ2)*sin(θ2)-1.0*θ2*cos(θ2)^2)+η1^2*(θ2*sin(θ2)^2+cos(θ2)*sin(θ2)+θ2*cos(θ2)^2)))*Vr0+(sin(θ1)^2* (θ1*(η1^2*cos(θ2)^2-1.0*η1*η2*cos(θ2)^2)+η1*η2*(-1.0*θ2*sin(θ2)^2-1.0*cos(θ2)*sin(θ2)-1.0*θ2*cos(θ2)^2))+cos(θ1)^2* (θ1*(η1^2*cos(θ2)^2-1.0*η1*η2*cos(θ2)^2)+η1^2*(-1.0*θ2*sin(θ2)^2-1.0*cos(θ2)*sin(θ2)-1.0*θ2*cos(θ2)^2))+cos(θ1)*sin(θ1)*(η1^2*cos(θ2)^2-1.0*η1*η2*cos(θ2)^2))*Vt0+ cos(θ1)*sin(θ1)*(η1^2*(-1.0*θ2*cos(θ2)*Vr2-1.0*cos(θ2)*Vt2+θ2*sin(θ2)*Vt2)+η1*η2*(θ2*cos(θ2)*Vr2+cos(θ2)*Vt2-1.0*θ2*sin(θ2)*Vt2))+sin(θ1)^2*(θ1* (η1*η2*(-1.0*θ2*sin(θ2)*Vt2+cos(θ2)*Vt2+θ2*cos(θ2)*Vr2)+η1^2*(θ2*sin(θ2)*Vt2-1.0*cos(θ2)*Vt2-1.0*θ2*cos(θ2)*Vr2))+θ1^2* (η1^2*(cos(θ2)*Vr2-1.0*sin(θ2)*Vt2)+η2^2*(cos(θ2)*Vr2-1.0*sin(θ2)*Vt2)+η1*η2*(2.0*sin(θ2)*Vt2-2.0*cos(θ2)*Vr2))+η2^2*(sin(θ2)*Vt2-1.0*cos(θ2)*Vr2)+η1*η2* ((θ2*sin(θ2)+cos(θ2))*Vr2+θ2*cos(θ2)*Vt2))+cos(θ1)^2*(θ1* (η1*η2*(-1.0*θ2*sin(θ2)*Vt2+cos(θ2)*Vt2+θ2*cos(θ2)*Vr2)+η1^2*(θ2*sin(θ2)*Vt2-1.0*cos(θ2)*Vt2-1.0*θ2*cos(θ2)*Vr2))+θ1^2* (η1^2*(cos(θ2)*Vr2-1.0*sin(θ2)*Vt2)+η2^2*(cos(θ2)*Vr2-1.0*sin(θ2)*Vt2)+η1*η2*(2.0*sin(θ2)*Vt2-2.0*cos(θ2)*Vr2))+η1^2*(θ2*sin(θ2)*Vr2+θ2*cos(θ2)*Vt2+sin(θ2)*Vt2)))/( sin(θ1)^2*(2.0*η1*η2*cos(θ2)^2+η2^2*(-1.0*sin(θ2)^2-1.0*cos(θ2)^2)+η1^2*(θ2^2*sin(θ2)^2+(θ2^2-1.0)*cos(θ2)^2)+θ1^2* (η2^2*(cos(θ2)^2+sin(θ2)^2)+η1^2*(cos(θ2)^2+sin(θ2)^2)+η1*η2*(-2.0*cos(θ2)^2-2.0*sin(θ2)^2))+θ1* (η1*η2*(2.0*θ2*cos(θ2)^2+2.0*θ2*sin(θ2)^2)+η1^2*(-2.0*θ2*cos(θ2)^2-2.0*θ2*sin(θ2)^2)))+cos(θ1)^2*(η1^2*((θ2^2-1.0)*sin(θ2)^2+θ2^2*cos(θ2)^2)+θ1^2* (η2^2*(cos(θ2)^2+sin(θ2)^2)+η1^2*(cos(θ2)^2+sin(θ2)^2)+η1*η2*(-2.0*cos(θ2)^2-2.0*sin(θ2)^2))+θ1* (η1*η2*(2.0*θ2*cos(θ2)^2+2.0*θ2*sin(θ2)^2)+η1^2*(-2.0*θ2*cos(θ2)^2-2.0*θ2*sin(θ2)^2)))+cos(θ1)*sin(θ1)*(2.0*η1^2*cos(θ2)*sin(θ2)-2.0*η1*η2*cos(θ2)*sin(θ2))); C2 = -(1.0*((sin(θ1)^2*(η1*η2*(sin(θ2)^2+cos(θ2)^2)-1.0*η1^2*cos(θ2)^2)+η1^2*cos(θ1)^2*sin(θ2)^2)*Vr0+(sin(θ1)^2* (η1^2*(-1.0*θ2*sin(θ2)^2-1.0*cos(θ2)*sin(θ2)-1.0*θ2*cos(θ2)^2)+θ1*(η1^2*(cos(θ2)^2+sin(θ2)^2)+η1*η2*(-1.0*cos(θ2)^2-1.0*sin(θ2)^2)))+cos(θ1)^2* (η1^2*(-1.0*θ2*sin(θ2)^2-1.0*cos(θ2)*sin(θ2)-1.0*θ2*cos(θ2)^2)+θ1*(η1^2*(cos(θ2)^2+sin(θ2)^2)+η1*η2*(-1.0*cos(θ2)^2-1.0*sin(θ2)^2)))+cos(θ1)*sin(θ1)* (η1*η2*(-1.0*sin(θ2)^2-1.0*cos(θ2)^2)+η1^2*(sin(θ2)^2+cos(θ2)^2)))*Vt0+cos(θ1)*sin(θ1)*(η1*η2*(sin(θ2)*Vr2+cos(θ2)*Vt2)+η1^2*(-1.0*sin(θ2)*Vr2-1.0*cos(θ2)*Vt2))+ sin(θ1)^2* (θ1*(η1^2*(-1.0*cos(θ2)*Vt2-1.0*sin(θ2)*Vr2)+η1*η2*(cos(θ2)*Vt2+sin(θ2)*Vr2))+η1*η2*(sin(θ2)*Vt2-1.0*cos(θ2)*Vr2)+η1^2*((θ2*sin(θ2)+cos(θ2))*Vr2+θ2*cos(θ2)*Vt2)) +cos(θ1)^2*(θ1*(η1^2*(-1.0*cos(θ2)*Vt2-1.0*sin(θ2)*Vr2)+η1*η2*(cos(θ2)*Vt2+sin(θ2)*Vr2))+η1^2*(θ2*sin(θ2)*Vr2+θ2*cos(θ2)*Vt2+sin(θ2)*Vt2))))/(sin(θ1)^2*(2.0*η1*η2* cos(θ2)^2+η2^2*(-1.0*sin(θ2)^2-1.0*cos(θ2)^2)+η1^2*(θ2^2*sin(θ2)^2+(θ2^2-1.0)*cos(θ2)^2)+θ1^2* (η2^2*(cos(θ2)^2+sin(θ2)^2)+η1^2*(cos(θ2)^2+sin(θ2)^2)+η1*η2*(-2.0*cos(θ2)^2-2.0*sin(θ2)^2))+θ1* (η1*η2*(2.0*θ2*cos(θ2)^2+2.0*θ2*sin(θ2)^2)+η1^2*(-2.0*θ2*cos(θ2)^2-2.0*θ2*sin(θ2)^2)))+cos(θ1)^2*(η1^2*((θ2^2-1.0)*sin(θ2)^2+θ2^2*cos(θ2)^2)+θ1^2* (η2^2*(cos(θ2)^2+sin(θ2)^2)+η1^2*(cos(θ2)^2+sin(θ2)^2)+η1*η2*(-2.0*cos(θ2)^2-2.0*sin(θ2)^2))+θ1* (η1*η2*(2.0*θ2*cos(θ2)^2+2.0*θ2*sin(θ2)^2)+η1^2*(-2.0*θ2*cos(θ2)^2-2.0*θ2*sin(θ2)^2)))+cos(θ1)*sin(θ1)*(2.0*η1^2*cos(θ2)*sin(θ2)-2.0*η1*η2*cos(θ2)*sin(θ2))); D2 = -(1.0*((sin(θ1)^2*(η1^2*(θ2*sin(θ2)^2-1.0*cos(θ2)*sin(θ2)+θ2*cos(θ2)^2)+θ1*(η1*η2*(cos(θ2)^2+sin(θ2)^2)+η1^2*(-1.0*cos(θ2)^2-1.0*sin(θ2)^2)))+cos(θ1)^2* (η1^2*(θ2*sin(θ2)^2-1.0*cos(θ2)*sin(θ2)+θ2*cos(θ2)^2)+θ1*(η1*η2*(cos(θ2)^2+sin(θ2)^2)+η1^2*(-1.0*cos(θ2)^2-1.0*sin(θ2)^2)))+cos(θ1)*sin(θ1)* (η1*η2*(-1.0*sin(θ2)^2-1.0*cos(θ2)^2)+η1^2*(sin(θ2)^2+cos(θ2)^2)))*Vr0+(sin(θ1)^2*(η1^2*cos(θ2)^2+η1*η2*(-1.0*sin(θ2)^2-1.0*cos(θ2)^2))-1.0*η1^2*cos(θ1)^2*sin(θ2)^2)*Vt0+ cos(θ1)*sin(θ1)*(η1^2*(sin(θ2)*Vt2-1.0*cos(θ2)*Vr2)+η1*η2*(cos(θ2)*Vr2-1.0*sin(θ2)*Vt2))+cos(θ1)^2* (θ1*(η1^2*(cos(θ2)*Vr2-1.0*sin(θ2)*Vt2)+η1*η2*(sin(θ2)*Vt2-1.0*cos(θ2)*Vr2))+η1^2*((sin(θ2)-1.0*θ2*cos(θ2))*Vr2+θ2*sin(θ2)*Vt2))+sin(θ1)^2*(θ1* (η1^2*(cos(θ2)*Vr2-1.0*sin(θ2)*Vt2)+η1*η2*(sin(θ2)*Vt2-1.0*cos(θ2)*Vr2))+η1^2*(-1.0*θ2*cos(θ2)*Vr2-1.0*cos(θ2)*Vt2+θ2*sin(θ2)*Vt2)+η1*η2*(sin(θ2)*Vr2+cos(θ2)*Vt2)) ))/(sin(θ1)^2*(2.0*η1*η2*cos(θ2)^2+η2^2*(-1.0*sin(θ2)^2-1.0*cos(θ2)^2)+η1^2*(θ2^2*sin(θ2)^2+(θ2^2-1.0)*cos(θ2)^2)+θ1^2* (η2^2*(cos(θ2)^2+sin(θ2)^2)+η1^2*(cos(θ2)^2+sin(θ2)^2)+η1*η2*(-2.0*cos(θ2)^2-2.0*sin(θ2)^2))+θ1* (η1*η2*(2.0*θ2*cos(θ2)^2+2.0*θ2*sin(θ2)^2)+η1^2*(-2.0*θ2*cos(θ2)^2-2.0*θ2*sin(θ2)^2)))+cos(θ1)^2*(η1^2*((θ2^2-1.0)*sin(θ2)^2+θ2^2*cos(θ2)^2)+θ1^2* (η2^2*(cos(θ2)^2+sin(θ2)^2)+η1^2*(cos(θ2)^2+sin(θ2)^2)+η1*η2*(-2.0*cos(θ2)^2-2.0*sin(θ2)^2))+θ1* (η1*η2*(2.0*θ2*cos(θ2)^2+2.0*θ2*sin(θ2)^2)+η1^2*(-2.0*θ2*cos(θ2)^2-2.0*θ2*sin(θ2)^2)))+cos(θ1)*sin(θ1)*(2.0*η1^2*cos(θ2)*sin(θ2)-2.0*η1*η2*cos(θ2)*sin(θ2))); return (A1, B1, C1, D1, A2, B2, C2, D2) end function ComputeLocation( X, c, params ) @unpack θ1, θ2, η1, η2, Vr0, Vt0, Vr2, Vt2 = params r = sqrt(X[1]^2 + X[2]^2) θ = atan(X[2]/X[1]) # Corner facing up or if sign(θ1) == -1 if (θ >= 0.) θ -= π end else if (θ <= 0.) θ += π end end # Define which corner is which ind1, ind2 = false, false if sign(θ1) == -1 if (θ>=θ1) ind1 = true end if (θ<θ1 && θ>θ2) ind2 = true end else if (θ<=θ1) ind1 = true end if (θ>θ1 && θ<θ2) ind2 = true end end η, A, B, C, D = NaN, NaN, NaN, NaN, NaN if ind1 == true η = η1 A = c[1] B = c[2] C = c[3] D = c[4] elseif ind2 == true η = η2 A = c[5] B = c[6] C = c[7] D = c[8] end return r, θ, η, A, B, C, D, ind1, ind2 end function Stokes2D_Moulas2021_p( X, c, params ) @unpack θ1, θ2, η1, η2, Vr0, Vt0, Vr2, Vt2 = params # Compute location r, θ, η, A, B, C, D, ind1, ind2 = ComputeLocation( X, c, params ) # Pressure in both corners p = -(-2*η*cos(θ)*C - 2*η*sin(θ)*D)/r return p end function Stokes2D_Moulas2021_V( X, c, params ) @unpack θ1, θ2, η1, η2, Vr0, Vt0, Vr2, Vt2 = params # Compute location r, θ, η, A, B, C, D, ind1, ind2 = ComputeLocation( X, c, params ) # Velocity in both corners Vr = -A*sin(θ) + B*cos(θ) +C*cos(θ)-C*θ*sin(θ)+D*sin(θ)+D*θ*cos(θ) Vt = -A*cos(θ) - B*sin(θ) - C*θ*cos(θ) - D*θ*sin(θ) 𝑉 = @SVector([Vr; Vt]) R = @SMatrix([cos(θ) -sin(θ); sin(θ) cos(θ)]) return V = R*𝑉 end function Stokes2D_Moulas2021_σrt( X, c, params ) @unpack θ1, θ2, η1, η2, Vr0, Vt0, Vr2, Vt2 = params r, θ, η, A, B, C, D, ind1, ind2 = ComputeLocation( X, c, params ) σrt = η*((cos(θ)*A+sin(θ)*B+θ*cos(θ)*C+θ*sin(θ)*D)/r+ (-cos(θ)*A-sin(θ)*B-θ*cos(θ)*C-2*sin(θ)*C+2*cos(θ)*D-θ*sin(θ)*D)/r); return σrt end @doc raw""" sol = Stokes2D_Moulas2021(x; params) Evaluates the analytical solution of [Moulas et al. (2021)](https://academic.oup.com/gji/article/227/1/576/6309899): x : is the coordinate vector params : optional parameter array and returns: sol : tuple containing the solution fields p (pressure), V (velocity vector), L (velocity gratdient tensor), ε̇ (deviatoric strain rate tensor) and τ (deviatoric stress tensor) # Examples ```julia-repl julia> Stokes2D_Moulas2021( [1, 1] ) (p = 12.53061977287755, V = [-0.010899335607440476, 0.02773892842336736], L = [0.0028483768768197255 -0.0028483768768197255; 0.0028483768768197246 -0.0028483768768197246], ε̇ = [0.0028483768768197255 -4.336808689942018e-19; -4.336808689942018e-19 -0.0028483768768197246], τ = [5.696753753639451 -8.673617379884035e-16; -8.673617379884035e-16 -5.696753753639449], η = 1000.0) ``` """ function Stokes2D_Moulas2021(X; params = ( θ1 = 30π/180, θ2 = 180π/180, η1 = 1e0, η2 = 1e3, Vr0 = -1., Vt0 = 0., Vr2 = 0., Vt2 = 0.,) ) # Constants c = ComputeConstants( params ) # Check position r, θ, η, ind1, ind2 = ComputeLocation( X, c, params) p = Stokes2D_Moulas2021_p(X, c, params) v = Stokes2D_Moulas2021_V(X, c, params) # L = Stokes2D_Schmid2003_L(x, params) # just to check if automatic derivatives are correct f_cl = x -> Stokes2D_Moulas2021_V(x, c, params) L = ForwardDiff.jacobian(f_cl, X) # Postprocess deviatoric stress and strain rate ε̇ = 1/2*(L + L') τ = 2*η*ε̇ # # CHECK: normal deviatoric stress components should vanish in polar coordinates # # Rotation matrix # R = @SMatrix([cos(θ) -sin(θ); sin(θ) cos(θ)]) # τ_rot = R'*τ*R # # CHECK: shear stress in polar coordinates should equate the analytical solution # τ = Stokes2D_Moulas2021_σrt( X, c, params ) # τrt[i,j] = τ_rot[1,2] # @show τ_rot[1,1], abs(τ_rot[1,2] - τ), ε̇[1,1]+ε̇[2,2] return (p=p, V=v, L=L, ε̇=ε̇, τ=τ, η=η) end
ExactFieldSolutions
https://github.com/tduretz/ExactFieldSolutions.jl.git
[ "MIT" ]
0.1.3
d62c0014dfc5d64ecd16190fa069a8bb04627006
code
5237
function Stokes2D_Schmid2003_p(x, params) @unpack mm, mc, rc, gr, er = params # Check position (x[1]^2 + x[2]^2) < rc^2 ? in=true : in=false # Outside pmat = (4*mm*rc^2*(mm - mc)*(er*x[1]^2 + gr*x[1]*x[2] - er*x[2]^2))/((x[1]^2 + x[2]^2)^2*(mm + mc)) # Inside pinc = 0.0 # Where it's needed p = (in==0)*pmat + (in==1)*pinc return p end function Stokes2D_Schmid2003_V(x, params) @unpack mm, mc, rc, gr, er = params # Check position (x[1]^2 + x[2]^2) < rc^2 ? in=true : in=false # Outside A = mm*(mc-mm)/(mc+mm); v1mat = (2*A*er*rc^4*x[1]^3 + 3*A*gr*rc^4*x[1]^2*x[2] - 6*A*er*rc^4*x[1]*x[2]^2 - A*gr*rc^4*x[2]^3 - 4*A*er*rc^2*x[1]^5 - 4*A*gr*rc^2*x[1]^4*x[2] - 4*A*gr*rc^2*x[1]^2*x[2]^3 + 4*A*er*rc^2*x[1]*x[2]^4 + 2*er*mm*x[1]^7 + 2*gr*mm*x[1]^6*x[2] + 6*er*mm*x[1]^5*x[2]^2 + 6*gr*mm*x[1]^4*x[2]^3 + 6*er*mm*x[1]^3*x[2]^4 + 6*gr*mm*x[1]^2*x[2]^5 + 2*er*mm*x[1]*x[2]^6 + 2*gr*mm*x[2]^7)/(2*mm*(x[1]^2 + x[2]^2)^3) v2mat = -(A*gr*rc^4*x[1]^3 - 6*A*er*rc^4*x[1]^2*x[2] - 3*A*gr*rc^4*x[1]*x[2]^2 + 2*A*er*rc^4*x[2]^3 + 4*A*er*rc^2*x[1]^4*x[2] + 4*A*gr*rc^2*x[1]^3*x[2]^2 + 4*A*gr*rc^2*x[1]*x[2]^4 - 4*A*er*rc^2*x[2]^5 + 2*er*mm*x[1]^6*x[2] + 6*er*mm*x[1]^4*x[2]^3 + 6*er*mm*x[1]^2*x[2]^5 + 2*er*mm*x[2]^7)/(2*mm*(x[1]^2 + x[2]^2)^3) # Inside v1inc = (4*er*mm*x[1] + 3*gr*mm*x[2] + gr*mc*x[2])/(2*(mm + mc)); v2inc = -(4*er*mm*x[2] - gr*mm*x[1] + gr*mc*x[1])/(2*(mm + mc)); # Where it's needed vx = (in==0)*v1mat + (in==1)*v1inc vy = (in==0)*v2mat + (in==1)*v2inc return [vx; vy] end function Stokes2D_Schmid2003_L(x, params) # just to check if automatic derivatives are correct @unpack mm, mc, rc, gr, er = params # Check position (x[1]^2 + x[2]^2) < rc^2 ? in=true : in=false # Outside A = mm*(mc-mm)/(mc+mm); dvxdxmat = (- 3*A*er*rc^4*x[1]^4 - 6*A*gr*rc^4*x[1]^3*x[2] + 18*A*er*rc^4*x[1]^2*x[2]^2 + 6*A*gr*rc^4*x[1]*x[2]^3 - 3*A*er*rc^4*x[2]^4 + 2*A*er*rc^2*x[1]^6 + 4*A*gr*rc^2*x[1]^5*x[2] - 10*A*er*rc^2*x[1]^4*x[2]^2 - 10*A*er*rc^2*x[1]^2*x[2]^4 - 4*A*gr*rc^2*x[1]*x[2]^5 + 2*A*er*rc^2*x[2]^6 + er*mm*x[1]^8 + 4*er*mm*x[1]^6*x[2]^2 + 6*er*mm*x[1]^4*x[2]^4 + 4*er*mm*x[1]^2*x[2]^6 + er*mm*x[2]^8)/(mm*(x[1]^2 + x[2]^2)^4); dvxdymat = (3*A*gr*rc^4*x[1]^4 - 24*A*er*rc^4*x[1]^3*x[2] - 18*A*gr*rc^4*x[1]^2*x[2]^2 + 24*A*er*rc^4*x[1]*x[2]^3 + 3*A*gr*rc^4*x[2]^4 - 4*A*gr*rc^2*x[1]^6 + 24*A*er*rc^2*x[1]^5*x[2] + 8*A*gr*rc^2*x[1]^4*x[2]^2 + 16*A*er*rc^2*x[1]^3*x[2]^3 + 12*A*gr*rc^2*x[1]^2*x[2]^4 - 8*A*er*rc^2*x[1]*x[2]^5 + 2*gr*mm*x[1]^8 + 8*gr*mm*x[1]^6*x[2]^2 + 12*gr*mm*x[1]^4*x[2]^4 + 8*gr*mm*x[1]^2*x[2]^6 + 2*gr*mm*x[2]^8)/(2*mm*(x[1]^2 + x[2]^2)^4); dvydxmat = (A*rc^2*(3*gr*rc^2*x[1]^4 - 24*er*rc^2*x[1]^3*x[2] - 18*gr*rc^2*x[1]^2*x[2]^2 + 24*er*rc^2*x[1]*x[2]^3 + 3*gr*rc^2*x[2]^4 + 8*er*x[1]^5*x[2] + 12*gr*x[1]^4*x[2]^2 - 16*er*x[1]^3*x[2]^3 + 8*gr*x[1]^2*x[2]^4 - 24*er*x[1]*x[2]^5 - 4*gr*x[2]^6))/(2*mm*(x[1]^2 + x[2]^2)^4); dvydymat = -(- 3*A*er*rc^4*x[1]^4 - 6*A*gr*rc^4*x[1]^3*x[2] + 18*A*er*rc^4*x[1]^2*x[2]^2 + 6*A*gr*rc^4*x[1]*x[2]^3 - 3*A*er*rc^4*x[2]^4 + 2*A*er*rc^2*x[1]^6 + 4*A*gr*rc^2*x[1]^5*x[2] - 10*A*er*rc^2*x[1]^4*x[2]^2 - 10*A*er*rc^2*x[1]^2*x[2]^4 - 4*A*gr*rc^2*x[1]*x[2]^5 + 2*A*er*rc^2*x[2]^6 + er*mm*x[1]^8 + 4*er*mm*x[1]^6*x[2]^2 + 6*er*mm*x[1]^4*x[2]^4 + 4*er*mm*x[1]^2*x[2]^6 + er*mm*x[2]^8)/(mm*(x[1]^2 + x[2]^2)^4); # Inside dvxdxinc = (2*er*mm)/(mm + mc); dvxdyinc = (gr*(3*mm + mc))/(2*(mm + mc)); dvydxinc = (gr*(mm - mc))/(2*(mm + mc)); dvydyinc = -(2*er*mm)/(mm + mc); # Where it's needed dvxdx = (in==0)*dvxdxmat + (in==1)*dvxdxinc dvxdy = (in==0)*dvxdymat + (in==1)*dvxdyinc dvydx = (in==0)*dvydxmat + (in==1)*dvydxinc dvydy = (in==0)*dvydymat + (in==1)*dvydyinc return [dvxdx dvxdy; dvydx dvydy] end @doc raw""" sol = Stokes2D_Schmid2003(x; params) Evaluates the analytical solution of [Schmid & Podladchikov (2003)](https://academic.oup.com/gji/article/155/1/269/713923): x : is the coordinate vector params : optional parameter array and returns: sol : tuple containing the solution fields p (pressure), V (velocity vector), L (velocity gratdient tensor), ε̇ (deviatoric strain rate tensor) and τ (deviatoric stress tensor) # Examples ```julia-repl julia> Stokes2D_Schmid2003( [0, 0] ) (p = 0.0, V = [0.0, 0.0], L = [-0.019801980198019802 0.0; 0.0 0.019801980198019802], ε̇ = [-0.019801980198019802 0.0; 0.0 0.019801980198019802], τ = [-3.9603960396039604 0.0; 0.0 3.9603960396039604]) ``` """ function Stokes2D_Schmid2003(x; params = (mm = 1.0, mc = 100, rc = 0.2, gr = 0.0, er =-1.0) ) p = Stokes2D_Schmid2003_p(x, params) v = Stokes2D_Schmid2003_V(x, params) # L = Stokes2D_Schmid2003_L(x, params) # just to check if automatic derivatives are correct f_cl = x -> Stokes2D_Schmid2003_V(x, params) L = ForwardDiff.jacobian(f_cl, x) # Postprocess deviatoric stress and strain rate ε̇ = 1/2*(L + L') # Check position (x[1]^2 + x[2]^2) < params.rc^2 ? η=params.mc : η=params.mm τ = 2*η*ε̇ return (p=p, V=v, L=L, ε̇=ε̇, τ=τ, η=η) end
ExactFieldSolutions
https://github.com/tduretz/ExactFieldSolutions.jl.git
[ "MIT" ]
0.1.3
d62c0014dfc5d64ecd16190fa069a8bb04627006
code
119576
@doc raw""" sol = Stokes2D_SolCx_Zhong1996(x; params) Evaluates the manufactured solution of [Zhong et al., (1996)](https://booksite.elsevier.com/brochures/geophysics/PDFs/00118.pdf). Analytical solution adapted from Underworld (https://github.com/underworldcode, LGPL-3 license). The solution requires the following expressions the density and viscosity fields: ρ = sin(π * x[2]) * cos(π * x[1]) η = if 0 ≤ x ≤ 0.5 A elseif 0.5 < x ≤ 1 B end Input parameters are: x : is the coordinate vector params : optional parameter array and returns: sol : tuple containing the solution fields p (pressure) and V (velocity vector) # Examples ```julia-repl julia> Stokes2D_SolCx_Zhong1996( [0; 0] ) (V = [0.0, 0.0], p = -0.18450665902742763) ``` """ function Stokes2D_SolCx_Zhong1996(x; params=(; ηA=1, ηB=2)) sol = SolCx_solution(x[1], x[2], params.ηA, params.ηB) return sol end #= Analytical solution adapted from Underworld (https://github.com/underworldcode). As stated in the Underworld repository, the code is released under the GNU LESSER GENERAL PUBLIC LICENSE (LGPL-3) license =# function SolCx_solution(x, z, ηA, ηB) n, nx = 1, 1 ZA = ηA # left column viscosity ZB = ηB # right column viscosity xc = 0.5 _C1A = 0 t1 = nx * 0.3141592654e1 t2 = sin(t1) t3 = nx * t2 t4 = n * n t5 = t4 * t4 t6 = 0.3141592654e1 * 0.3141592654e1 t8 = t3 * t5 * t6 t9 = ZA * xc t12 = exp(xc * n * 0.3141592654e1) t13 = t12 * t12 t15 = n * 0.3141592654e1 t16 = exp(t15) t17 = t16 * t16 t18 = t17 * t16 t19 = ZB * t13 * t18 t20 = t9 * t19 t23 = ZA * ZA t24 = nx * nx t25 = t24 * nx t26 = t23 * t25 t28 = t13 * t13 t29 = t28 * t13 t33 = nx * ZB t34 = t1 * xc t35 = sin(t34) t36 = t4 * n t37 = t35 * t36 t38 = t33 * t37 t39 = 0.3141592654e1 * ZA t40 = t13 * t12 t41 = t17 * t40 t45 = ZB * ZB t46 = t45 * t24 t47 = t46 * t4 t48 = 0.3141592654e1 * xc t49 = t13 * t17 t53 = xc * xc t54 = t36 * t53 t56 = t54 * t6 * t45 t57 = cos(t34) t58 = t57 * t24 t59 = t28 * t12 t60 = t17 * t59 t61 = t58 * t60 t64 = t25 * t2 t65 = t64 * t15 t72 = nx * t23 t74 = t72 * t2 * t5 t75 = t6 * t53 t76 = t16 * t29 t80 = t23 * n t81 = t80 * 0.3141592654e1 t82 = t18 * t28 t86 = nx * t5 t87 = t23 * t6 t89 = xc * t2 t90 = t13 * t18 t91 = t89 * t90 t94 = t28 * t28 t96 = t24 * n t98 = t4 * t45 t99 = t98 * 0.3141592654e1 t100 = t58 * t41 t104 = 0.3141592654e1 * t25 t105 = ZA * n * t104 t106 = t2 * ZB t110 = t17 * t17 t111 = ZA * t110 t116 = n * t28 t122 = t64 * t4 * t6 t126 = t23 * t29 * t4 t128 = t24 * xc t132 = t36 * t23 t133 = t6 * t57 t135 = t128 * t41 t138 = t6 * xc t142 = t72 * t2 t147 = 0.4e1 * t8 * t20 - 0.2e1 * t26 * t2 * t16 * t29 - 0.8e1 * t38 * t39 * t41 + 0.4e1 * t47 * t48 * t49 - 0.8e1 * t56 * t61 - 0.4e1 * t65 * t20 + 0.2e1 * t26 * t2 * t18 * t28 - 0.4e1 * t74 * t75 * t76 - 0.2e1 * t81 * t64 * t82 - 0.4e1 * t86 * t87 * t91 - t23 * t94 * t96 + 0.8e1 * t99 * t100 - 0.2e1 * t105 * t106 * t82 - 0.4e1 * t38 * t48 * t111 * t12 + 0.2e1 * t116 * ZB * t111 * t24 + 0.4e1 * t122 * t20 + 0.4e1 * t126 * 0.3141592654e1 * t17 * t128 + 0.8e1 * t132 * t133 * t135 + 0.4e1 * t74 * t138 * t76 - 0.2e1 * t142 * t4 * t18 * t28 t149 = ZA * t25 * t2 t150 = ZB * t28 t154 = t35 * t5 t155 = t72 * t154 t156 = t75 * t41 t159 = nx * ZA t160 = t2 * t36 t161 = t159 * t160 t162 = 0.3141592654e1 * ZB t163 = t28 * t16 t167 = t23 * t57 t168 = t167 * t24 t169 = n * t110 t170 = t169 * t40 t173 = ZA * ZB t174 = t173 * t90 t177 = t36 * 0.3141592654e1 t181 = t80 * t104 t184 = n * t17 t188 = t17 * t29 t190 = t4 * 0.3141592654e1 t191 = t190 * t24 t206 = t138 * t60 t209 = t23 * t4 t211 = t209 * t6 * t25 t212 = t89 * t76 t216 = ZB * t16 * t29 t217 = t9 * t216 t220 = ZB * t110 t221 = ZA * t24 t222 = t221 * n t225 = t132 * t75 t232 = t45 * t28 t233 = t110 * t24 t234 = t233 * n t236 = t209 * 0.3141592654e1 t237 = t17 * xc t239 = t237 * t13 * t24 t242 = -0.2e1 * t149 * t150 * t16 - 0.8e1 * t155 * t156 - 0.2e1 * t161 * t162 * t163 + 0.2e1 * t168 * t170 + 0.2e1 * t65 * t174 - 0.2e1 * t142 * t177 * t76 + 0.4e1 * t181 * t91 - 0.4e1 * t168 * t184 * t59 - 0.4e1 * t188 * t23 * t191 + 0.4e1 * t38 * t48 * ZA * t17 * t40 + 0.4e1 * t49 * t23 * t191 + 0.2e1 * t26 * t2 * t13 * t18 - 0.8e1 * t155 * t206 + 0.4e1 * t211 * t212 - 0.4e1 * t8 * t217 + 0.2e1 * t220 * t222 - 0.8e1 * t225 * t100 + 0.2e1 * t142 * t4 * t16 * t29 + t232 * t234 - 0.4e1 * t236 * t239 t244 = nx * t45 t245 = t244 * t37 t246 = t110 * t40 t251 = t237 * t59 t256 = t64 * t90 t260 = t36 * t45 * t133 t263 = t45 * t57 t264 = t263 * t24 t265 = t169 * t12 t269 = t6 * t36 t270 = t17 * t24 t274 = t110 * t13 t276 = t190 * t128 t279 = nx * t36 t281 = t28 * t40 t282 = t281 * t35 t286 = t138 * t41 t289 = t75 * t60 t296 = t190 * t173 t305 = t86 * t45 * t35 t312 = t33 * t154 t313 = t6 * ZA t324 = t232 * t270 t327 = -0.2e1 * t245 * t48 * t246 + 0.4e1 * t159 * t37 * t162 * t251 + 0.4e1 * t209 * t75 * t256 + 0.8e1 * t260 * t135 + 0.2e1 * t264 * t265 + 0.32e2 * t9 * t150 * t269 * t270 + 0.4e1 * t274 * t23 * t276 + 0.2e1 * t279 * t45 * t282 * t48 + 0.8e1 * t155 * t286 + 0.8e1 * t155 * t289 - 0.8e1 * t150 * ZA * t96 * t17 + 0.8e1 * t296 * t61 - 0.2e1 * t105 * t106 * t163 - 0.2e1 * t81 * t256 - 0.8e1 * t305 * t156 - 0.4e1 * t33 * t282 * t177 * t9 - 0.16e2 * t312 * t313 * t237 * t40 - 0.4e1 * t168 * t184 * t40 + 0.2e1 * t168 * t265 + 0.16e2 * t269 * t53 * t324 t328 = t3 * t4 t331 = t72 * t37 t332 = t48 * t60 t335 = n * t94 t345 = t72 * t35 t349 = t173 * t57 t355 = t53 * t17 t364 = t54 * t6 * ZB t365 = t28 * t17 t369 = xc * ZB t370 = t269 * t369 t371 = ZA * t57 t373 = t371 * t270 * t40 t385 = nx * t35 t396 = t4 * xc t397 = t396 * t162 t415 = t37 * t48 t418 = -0.32e2 * t364 * t365 * t221 - 0.16e2 * t370 * t373 - 0.4e1 * t331 * t48 * t41 + 0.4e1 * t86 * t23 * t53 * t6 * t2 * t90 + 0.2e1 * t385 * t177 * t23 * xc * t246 + 0.16e2 * t132 * t53 * t6 * t28 * t270 - 0.4e1 * t397 * t371 * t233 * t12 - 0.12e2 * t173 * t58 * t190 * t251 + 0.2e1 * t385 * t36 * 0.3141592654e1 * t23 * xc * t59 - 0.8e1 * t99 * t61 - 0.2e1 * t244 * t59 * t415 t427 = t371 * t270 * t59 t439 = t209 * t48 t440 = t110 * t12 t441 = t58 * t440 t447 = t36 * xc t455 = t48 * t440 t471 = ZB * t17 t492 = 0.12e2 * t397 * t373 - 0.4e1 * t122 * t217 + 0.16e2 * t364 * t427 + 0.16e2 * t312 * t313 * t355 * t40 - 0.8e1 * t279 * t39 * t35 * ZB * t60 + 0.2e1 * t439 * t441 - 0.2e1 * t81 * t64 * t163 + 0.8e1 * t447 * t87 * t61 + 0.2e1 * t23 * t59 * t57 * t276 + 0.2e1 * t245 * t455 - 0.4e1 * t349 * t96 * t440 - 0.16e2 * t370 * t427 + 0.4e1 * t181 * t212 - 0.16e2 * t365 * t23 * t269 * t128 + 0.16e2 * t86 * t138 * ZA * t35 * t471 * t59 + 0.8e1 * t305 * t289 - 0.4e1 * t439 * t100 + 0.2e1 * ZB * t25 * t2 * ZA * t18 * t28 + 0.2e1 * t142 * t4 * t28 * t16 - 0.8e1 * t56 * t100 t499 = ZA * t53 * t19 t505 = t396 * 0.3141592654e1 t518 = t173 * t53 * t16 * t29 t533 = t23 * t28 t535 = t188 * t45 t538 = t24 * t4 t545 = t3 * t177 t546 = t173 * t76 t555 = t45 * t110 t557 = t72 * t160 t561 = -0.8e1 * t225 * t61 - 0.2e1 * t161 * t162 * t82 + t533 * t234 + 0.4e1 * t535 * t191 + 0.4e1 * t167 * t538 * t332 + 0.4e1 * t349 * t96 * t60 + 0.2e1 * t545 * t546 - 0.2e1 * t264 * t170 + 0.4e1 * t397 * t281 * ZA * t58 - t555 * t96 - 0.4e1 * t557 * t48 * t76 t567 = t396 * 0.3141592654e1 * t45 t568 = t58 * t246 t597 = t58 * n t615 = t13 * t45 t616 = t615 * t233 t619 = t94 * t45 t621 = t45 * t59 t625 = 0.2e1 * t149 * t216 + 0.2e1 * t567 * t568 - 0.16e2 * t269 * xc * t324 - 0.2e1 * t236 * xc * t281 * t58 - 0.2e1 * t142 * t177 * t90 - 0.8e1 * t567 * t100 + 0.2e1 * t65 * t546 - 0.8e1 * t305 * t206 + 0.2e1 * n * t45 * t281 * t57 * t24 - t23 * t110 * t96 - 0.8e1 * t296 * t100 + 0.2e1 * t23 * t281 * t597 + 0.4e1 * t545 * t20 + 0.2e1 * t159 * t2 * t4 * ZB * t163 - 0.4e1 * t557 * t48 * t90 + 0.4e1 * t122 * t518 + 0.8e1 * t263 * t538 * t332 - 0.4e1 * t505 * t616 - t619 * t96 - 0.2e1 * t621 * t57 * t276 t626 = t49 * t45 t660 = t29 * t45 t685 = 0.2e1 * t545 * t174 - 0.4e1 * t126 * 0.3141592654e1 * t24 * xc - 0.4e1 * t47 * t48 * t188 + 0.4e1 * t505 * t660 * t24 - 0.2e1 * t142 * t177 * t163 - 0.2e1 * t142 * t4 * t13 * t18 + 0.8e1 * t260 * t128 * t60 - 0.2e1 * t328 * t546 - 0.2e1 * t26 * t2 * t28 * t16 + 0.4e1 * t545 * t217 - 0.4e1 * t209 * t138 * t256 t690 = t6 * 0.3141592654e1 t691 = ZA * t690 t693 = t24 * t24 t694 = t693 * xc t695 = t188 * t694 t698 = t23 * ZA t699 = t698 * t690 t700 = t699 * t5 t704 = t5 * t4 t705 = t691 * t704 t709 = t691 * t5 t713 = t5 * n t714 = t713 * ZB t718 = t698 * t6 t719 = t713 * t28 t722 = t699 * t704 t726 = t713 * t94 t733 = t713 * t45 t736 = t87 * t36 t740 = -0.4e1 * t691 * t98 * t695 + 0.8e1 * t700 * t270 * t13 + 0.4e1 * t705 * t660 * xc + 0.8e1 * t709 * t660 * t128 + 0.2e1 * t87 * t714 * t110 + t718 * t719 * t110 - 0.4e1 * t722 * t237 * t13 - t313 * t726 * t45 - 0.4e1 * t699 * t704 * xc * t29 + t313 * t733 * t28 + 0.4e1 * t736 * t150 * t233 t746 = t313 * t36 t752 = t6 * t6 t753 = t23 * t752 t759 = t698 * t752 t760 = t759 * t36 t761 = t17 * t693 t762 = xc * t28 t763 = t761 * t762 t766 = t87 * t713 t773 = t699 * t4 t774 = t110 * t693 t775 = xc * t13 t785 = t704 * t17 t789 = -0.16e2 * t736 * t150 * t270 + t718 * t116 * t693 - 0.2e1 * t746 * t555 * t24 + 0.4e1 * t705 * t535 + 0.64e2 * t753 * t713 * t17 * t150 * t128 - 0.16e2 * t760 * t763 + 0.2e1 * t766 * t150 * t110 + 0.4e1 * t722 * t274 * xc + 0.4e1 * t773 * t774 * t775 - 0.8e1 * t766 * t150 * t17 + 0.8e1 * t700 * t233 * t775 + 0.4e1 * t699 * t785 * t13 t791 = t691 * t4 t792 = t45 * t693 t793 = t49 * t792 t796 = t759 * t713 t797 = t53 * t28 t798 = t270 * t797 t801 = t87 * n t818 = t5 * t36 t819 = t753 * t818 t827 = t753 * t36 * ZB t830 = xc * t45 t834 = -0.4e1 * t791 * t793 + 0.32e2 * t796 * t798 + 0.2e1 * t801 * ZB * t693 * t110 + 0.2e1 * t718 * t36 * t28 * t24 - 0.8e1 * t700 * t128 * t29 - 0.8e1 * t700 * t239 - 0.8e1 * t801 * t150 * t761 + 0.32e2 * t819 * t365 * t369 - 0.64e2 * t753 * t714 * t798 + 0.32e2 * t827 * t763 + 0.4e1 * t705 * t830 * t49 t842 = xc * t29 t843 = t270 * t842 t849 = t759 * t818 t853 = t691 * t396 t857 = t691 * t5 * t45 t869 = t313 * n t874 = -0.2e1 * t718 * t36 * t94 * t24 - 0.4e1 * t773 * t761 * t29 + 0.8e1 * t700 * t843 + 0.2e1 * t87 * t726 * ZB + 0.16e2 * t849 * t797 * t17 + 0.4e1 * t853 * t793 + 0.8e1 * t857 * t239 + 0.2e1 * t801 * t150 * t693 - 0.8e1 * t700 * t270 * t29 - 0.8e1 * t709 * t49 * t46 - t869 * t619 * t693 + t869 * t232 * t693 t877 = ZA * t752 t878 = t877 * t818 t911 = 0.16e2 * t878 * t53 * t45 * t365 - 0.4e1 * t699 * t785 * t29 - 0.4e1 * t705 * t188 * t830 + 0.2e1 * t801 * t94 * t693 * ZB - 0.8e1 * t857 * t843 - t718 * t726 + 0.4e1 * t773 * t761 * t13 - 0.4e1 * t705 * t775 * t555 + 0.2e1 * t746 * t232 * t233 - 0.16e2 * t878 * t830 * t365 - 0.2e1 * t746 * t619 * t24 t916 = t110 * t28 t945 = t28 * t693 * t45 * t17 t948 = 0.32e2 * t877 * t733 * t798 + 0.2e1 * t718 * t36 * t916 * t24 - 0.4e1 * t705 * t626 + t718 * n * t916 * t693 - t869 * t792 * t110 - 0.4e1 * t773 * t761 * t775 + t718 * t719 + 0.2e1 * t746 * t232 * t24 - 0.16e2 * t849 * t365 * xc - t718 * t713 * t110 - 0.4e1 * t773 * t694 * t29 + 0.16e2 * t877 * t54 * t945 t974 = t761 * t797 t987 = 0.4e1 * t773 * t695 + 0.4e1 * t736 * t150 * t24 + 0.4e1 * t722 * t842 * t17 - 0.16e2 * t877 * t447 * t945 + 0.2e1 * t87 * t714 * t28 + t313 * t713 * t916 * t45 - 0.4e1 * t853 * t615 * t774 - 0.32e2 * t877 * t713 * xc * t324 + 0.16e2 * t760 * t974 + 0.4e1 * t736 * t94 * t24 * ZB + t869 * t792 * t916 - 0.8e1 * t691 * t5 * xc * t616 t1021 = -t718 * t169 * t693 - 0.32e2 * t827 * t974 + 0.2e1 * t801 * t150 * t774 + 0.4e1 * t791 * t188 * t792 + 0.4e1 * t736 * t220 * t24 + 0.4e1 * t791 * t842 * t792 + 0.8e1 * t709 * t660 * t270 - t718 * t335 * t693 - 0.2e1 * t718 * t36 * t110 * t24 - 0.32e2 * t819 * t797 * t471 - t313 * t733 * t110 - 0.32e2 * t796 * t270 * t762 _C2A = ( t147 - 0.4e1 * t65 * t217 + t418 + 0.2e1 * t150 * t222 + t327 - 0.2e1 * t149 * t19 + 0.2e1 * t335 * ZB * t24 * ZA - 0.16e2 * t312 * t313 * t355 * t59 - 0.4e1 * t281 * ZB * ZA * t597 - 0.2e1 * t505 * t45 * t281 * t58 - 0.4e1 * t211 * t2 * t53 * t76 + 0.8e1 * t305 * t286 - 0.4e1 * t122 * t499 - 0.4e1 * t331 * t332 + 0.8e1 * t345 * t177 * t60 - 0.2e1 * t142 * t177 * t82 + 0.2e1 * t72 * t281 * t415 + 0.4e1 * t349 * t96 * t41 - 0.2e1 * t81 * t64 * t76 + 0.2e1 * t58 * t80 * t59 + 0.8e1 * t345 * t177 * t41 - 0.4e1 * t8 * t499 + t242 + 0.4e1 * t8 * t518 + t625 + t685 + 0.2e1 * t328 * t174 + 0.2e1 * t331 * t455 - 0.2e1 * t33 * t2 * t4 * ZA * t82 - 0.4e1 * t626 * t191 + 0.16e2 * t364 * t373 - 0.2e1 * t621 * t597 - 0.2e1 * t439 * t568 + t492 + t533 * t96 + t232 * t96 + 0.2e1 * t567 * t441 + t561 ) / (t740 + t789 + t834 + t874 + t911 + t948 + t987 + t1021) t1 = n * n t2 = t1 * n t3 = t2 * 0.3141592654e1 t4 = t3 * xc t5 = ZB * ZB t7 = exp(n * 0.3141592654e1) t8 = t7 * t7 t9 = t5 * t8 t12 = exp(xc * n * 0.3141592654e1) t13 = t12 * t12 t14 = t13 * t13 t15 = t14 * t13 t19 = nx * nx t21 = nx * 0.3141592654e1 t22 = sin(t21) t23 = t19 * nx * t22 t24 = t23 * 0.3141592654e1 t25 = ZA * ZB t26 = t7 * t15 t27 = t25 * t26 t30 = t21 * xc t31 = sin(t30) t32 = t31 * nx t33 = t32 * n t34 = ZA * ZA t35 = t8 * t8 t36 = t34 * t35 t40 = t2 * t34 t41 = 0.3141592654e1 * t8 t42 = t41 * t15 t45 = t1 * t5 t46 = t14 * t14 t49 = t19 * t5 t51 = t19 * t46 t53 = t19 * t34 t55 = t8 * t7 t56 = t13 * t55 t57 = t25 * t56 t60 = t2 * nx t61 = 0.3141592654e1 * 0.3141592654e1 t63 = t60 * t31 * t61 t64 = xc * xc t65 = ZA * t64 t66 = ZB * t8 t67 = t14 * t12 t68 = t66 * t67 t69 = t65 * t68 t72 = -0.4e1 * t4 * t9 * t15 + 0.4e1 * t24 * t27 + 0.4e1 * t33 * t36 * t12 - 0.4e1 * t40 * t42 - t45 * t46 + t45 * t14 - t49 * t14 + t51 * t5 - t53 * t14 + 0.4e1 * t24 * t57 + 0.32e2 * t63 * t69 t73 = t1 * nx t75 = t73 * t31 * 0.3141592654e1 t76 = t8 * t67 t77 = t25 * t76 t80 = t1 * t1 t81 = t80 * t34 t83 = t61 * t14 t87 = t1 * t19 t88 = cos(t30) t90 = t87 * t88 * t61 t91 = t5 * t64 t92 = t13 * t12 t93 = t8 * t92 t94 = t91 * t93 t100 = ZB * t64 * ZA * t8 * t92 t103 = n * t19 t105 = t103 * t88 * 0.3141592654e1 t106 = ZA * xc t107 = ZB * t35 t109 = t106 * t107 * t12 t112 = t34 * xc t113 = t112 * t93 t116 = t35 * t14 t118 = t1 * ZA t119 = ZB * t14 t122 = t1 * t46 t125 = t19 * ZB t126 = t35 * ZA t127 = t125 * t126 t129 = t1 * ZB t132 = -0.16e2 * t75 * t77 + 0.16e2 * t81 * t64 * t83 * t8 + 0.16e2 * t90 * t94 - 0.32e2 * t90 * t100 + 0.8e1 * t105 * t109 - 0.8e1 * t75 * t113 + t45 * t116 + 0.2e1 * t118 * t119 + 0.2e1 * t122 * t25 - 0.2e1 * t127 + 0.2e1 * t129 * t126 t134 = t1 * t34 t136 = t34 * t64 t137 = t136 * t76 t141 = t91 * t76 t145 = t103 * t34 t146 = 0.3141592654e1 * xc t147 = t8 * t13 t153 = t14 * ZA t156 = xc * t5 t157 = t156 * t93 t160 = t103 * t5 t162 = t146 * t8 * t15 t166 = t34 * t7 * t15 t169 = t134 * t116 - 0.16e2 * t63 * t137 - t49 * t116 - 0.16e2 * t63 * t141 - t53 * t116 + 0.4e1 * t145 * t146 * t147 - 0.2e1 * t51 * t25 - 0.2e1 * t125 * t153 - 0.16e2 * t75 * t157 + 0.4e1 * t160 * t162 - 0.4e1 * t24 * t166 t170 = t106 * t68 t177 = t35 * t92 t178 = t112 * t177 t181 = t156 * t76 t186 = t35 * t12 t187 = t112 * t186 t193 = t5 * 0.3141592654e1 t206 = t34 * t14 t207 = t206 * t7 t210 = -0.32e2 * t63 * t170 + 0.32e2 * t90 * t170 + 0.8e1 * t75 * t109 + 0.4e1 * t105 * t178 - 0.16e2 * t75 * t181 - 0.16e2 * t90 * t113 - 0.4e1 * t75 * t187 + 0.16e2 * t90 * t141 - 0.4e1 * t103 * t15 * t193 * xc + 0.16e2 * t73 * t22 * t34 * t146 * t26 + 0.4e1 * t32 * n * t34 * t67 + 0.4e1 * t24 * t207 t217 = t106 * t66 * t92 t226 = t88 * t19 * n t227 = 0.3141592654e1 * t34 t229 = t227 * xc * t67 t232 = t73 * t31 t234 = t146 * t5 * t67 t238 = t61 * ZB t239 = t14 * t8 t240 = t238 * t239 t243 = t136 * t93 t246 = -0.8e1 * t33 * t25 * t186 + 0.32e2 * t90 * t217 - t45 * t35 + t53 * t35 - t134 * t35 - t134 * t46 + t134 * t14 - 0.4e1 * t226 * t229 + 0.4e1 * t232 * t234 + 0.32e2 * t87 * t65 * t240 + 0.16e2 * t63 * t243 t247 = t14 * t92 t249 = t227 * t247 * xc t254 = t73 * t22 t259 = t60 * t22 * t61 t260 = t112 * t26 t264 = t146 * t247 * t5 t268 = xc * t14 t274 = t5 * t14 t275 = t274 * t8 t280 = n * nx t281 = t280 * t22 t282 = t55 * t14 t283 = t25 * t282 t290 = ZA * t247 * xc * ZB t295 = t22 * nx * t1 * 0.3141592654e1 t298 = -0.4e1 * t232 * t249 + 0.8e1 * t105 * t217 - 0.4e1 * t254 * t227 * t26 - 0.8e1 * t259 * t260 - 0.4e1 * t232 * t264 - 0.16e2 * t81 * t61 * t268 * t8 + 0.16e2 * t80 * t64 * t61 * t275 - 0.4e1 * t232 * t229 + 0.8e1 * t281 * t283 - 0.4e1 * t105 * t187 + 0.8e1 * t75 * t290 + 0.4e1 * t295 * t27 t301 = t61 * t5 t307 = t87 * t34 t312 = t61 * xc t313 = t312 * t239 t317 = t34 * t55 * t14 t329 = ZB * t13 * t55 t330 = t65 * t329 t337 = -0.16e2 * t87 * t64 * t301 * t239 - 0.32e2 * t90 * t69 - 0.16e2 * t307 * t64 * t61 * t239 + 0.16e2 * t307 * t313 + 0.4e1 * t24 * t317 + t53 * t46 + t49 * t35 - 0.32e2 * t63 * t100 - 0.4e1 * t280 * t31 * t34 * t247 + 0.8e1 * t259 * t330 - 0.4e1 * t280 * t31 * t247 * t5 t340 = t5 * t35 t344 = t25 * t93 t356 = t41 * t13 t360 = t23 * n * t61 t363 = t25 * t64 * t7 * t15 t366 = t156 * t177 t369 = t14 * t7 t370 = t25 * t369 t373 = t156 * t186 t378 = 0.4e1 * t24 * t283 + 0.4e1 * t33 * t340 * t12 - 0.16e2 * t75 * t344 - 0.4e1 * t280 * t31 * t5 * t67 + 0.8e1 * t33 * t25 * t247 + 0.32e2 * t63 * t217 + 0.4e1 * t40 * t356 - 0.8e1 * t360 * t363 + 0.4e1 * t75 * t366 + 0.4e1 * t295 * t370 - 0.4e1 * t75 * t373 - 0.4e1 * t105 * t366 t382 = t112 * t76 t387 = t80 * t61 t391 = t136 * t26 t409 = 0.16e2 * t63 * t382 + 0.4e1 * t226 * t234 - 0.16e2 * t387 * xc * t275 + 0.8e1 * t259 * t391 - 0.16e2 * t105 * t344 + 0.4e1 * t226 * t264 - 0.8e1 * t105 * t170 + 0.16e2 * t232 * t193 * t76 + 0.8e1 * t360 * t330 - 0.8e1 * t105 * t290 + 0.16e2 * t90 * t243 t423 = t153 * t8 t426 = t34 * t13 t427 = t426 * t55 t430 = t34 * t8 t437 = t80 * ZA t441 = 0.4e1 * t145 * t42 - 0.16e2 * t90 * t157 + 0.24e2 * t75 * t217 + 0.4e1 * t226 * t249 + 0.4e1 * t254 * t227 * t282 + 0.4e1 * t160 * t356 - 0.8e1 * t129 * t423 - 0.8e1 * t281 * t427 - 0.8e1 * t33 * t430 * t67 + 0.8e1 * t33 * t430 * t92 + 0.32e2 * t437 * ZB * t313 t453 = t106 * ZB * t7 * t15 t456 = t2 * t5 t459 = t112 * t56 t462 = t126 * t14 t474 = t40 * 0.3141592654e1 t475 = xc * t8 t480 = t146 * t13 * t35 t483 = -0.4e1 * t103 * xc * t193 * t147 + 0.16e2 * t87 * t61 * t156 * t239 + 0.8e1 * t259 * t453 - 0.4e1 * t456 * t356 + 0.8e1 * t259 * t459 - 0.2e1 * t125 * t462 - 0.8e1 * t281 * t207 + 0.16e2 * t295 * t459 - 0.8e1 * t60 * t22 * ZA * t312 * t329 + 0.4e1 * t474 * t475 * t15 + 0.4e1 * t160 * t480 t497 = t136 * t56 t504 = t9 * t13 t509 = t475 * t13 t512 = -0.8e1 * t105 * t113 - 0.4e1 * t254 * t227 * t56 + 0.8e1 * t281 * t57 + 0.4e1 * t295 * t283 + 0.2e1 * t129 * t462 + 0.4e1 * t24 * t370 - 0.8e1 * t360 * t497 - 0.4e1 * t24 * t427 - 0.4e1 * t145 * t162 + 0.4e1 * t4 * t504 - 0.8e1 * t281 * t370 - 0.4e1 * t474 * t509 t528 = t5 * t13 t529 = t528 * t35 t532 = t106 * t329 t542 = -0.16e2 * t295 * t453 - 0.32e2 * t437 * t64 * t240 + 0.8e1 * t281 * t317 + 0.24e2 * t75 * t170 - 0.4e1 * t75 * t178 + 0.8e1 * t360 * t453 - 0.4e1 * t4 * t529 - 0.16e2 * t295 * t532 - 0.8e1 * t33 * t344 - 0.16e2 * t90 * t181 + 0.4e1 * t33 * t340 * t92 t557 = t146 * t15 t562 = xc * t15 t563 = t562 * t5 t573 = 0.16e2 * t232 * t193 * t93 - 0.8e1 * t259 * t363 - 0.8e1 * t259 * t497 + 0.8e1 * t33 * t77 + 0.8e1 * t360 * t391 + 0.4e1 * t254 * t227 * t369 + 0.4e1 * t145 * t557 + 0.8e1 * t281 * t166 + 0.4e1 * t3 * t563 + 0.8e1 * t105 * t382 - 0.4e1 * t145 * t480 - 0.4e1 * t33 * t36 * t92 t600 = 0.4e1 * t456 * t42 - 0.8e1 * t360 * t260 - 0.4e1 * t40 * t557 - 0.4e1 * t105 * t373 + 0.16e2 * t226 * t227 * t93 - 0.16e2 * t90 * t382 - 0.4e1 * t145 * t356 - 0.16e2 * t63 * t157 - 0.32e2 * t87 * t25 * t313 - 0.16e2 * t226 * t227 * t76 - 0.16e2 * t63 * t113 t623 = xc * t13 t627 = 0.8e1 * t125 * t423 - 0.8e1 * t360 * t532 + 0.16e2 * t90 * t137 - 0.4e1 * t160 * t42 + 0.16e2 * t63 * t94 + 0.16e2 * t63 * t181 - 0.8e1 * t281 * t27 - 0.8e1 * t75 * t382 + 0.8e1 * t360 * t459 + 0.4e1 * t295 * t57 + 0.16e2 * t105 * t77 + 0.4e1 * t474 * t623 * t35 t632 = t61 * 0.3141592654e1 t633 = t632 * t8 t634 = t80 * n t638 = t632 * t634 t639 = t638 * xc t642 = t61 * t34 t643 = t122 * t19 t649 = t61 * t61 t650 = t649 * t1 t652 = t19 * t19 t653 = t14 * t652 t654 = t653 * t9 t657 = t14 * t1 t658 = t657 * t19 t665 = t632 * t34 t666 = t665 * t2 t667 = t8 * t19 t668 = t667 * t623 t674 = t665 * n t675 = t652 * xc t682 = 0.8e1 * t633 * t426 * t634 - 0.8e1 * t639 * t529 - 0.4e1 * t642 * t643 + 0.2e1 * t642 * t116 * t80 + 0.32e2 * t650 * t64 * t654 + 0.4e1 * t301 * t658 + 0.4e1 * t387 * t46 * ZA * ZB - 0.16e2 * t666 * t668 - 0.16e2 * t666 * t667 * t15 - 0.8e1 * t674 * t675 * t15 + 0.4e1 * t238 * t153 * t80 t683 = t46 * t652 t686 = t633 * t15 t691 = t35 * t80 t698 = t35 * t652 t705 = t14 * t80 t708 = t61 * t35 t717 = -0.2e1 * t642 * t683 - 0.8e1 * t686 * t5 * t634 * xc - 0.2e1 * t301 * t691 + 0.8e1 * t638 * t563 - 0.2e1 * t642 * t691 - 0.2e1 * t642 * t698 - 0.2e1 * t301 * t698 - 0.2e1 * t301 * t683 + 0.2e1 * t642 * t705 + 0.2e1 * t708 * t274 * t80 + 0.2e1 * t301 * t653 - 0.2e1 * t642 * t80 * t46 t727 = t61 * t46 t737 = t649 * t34 t738 = t737 * t1 t739 = t8 * t652 t740 = t739 * t268 t746 = t61 * ZA t754 = t632 * n * xc t758 = 0.2e1 * t301 * t705 + 0.2e1 * t642 * t653 - 0.8e1 * t665 * xc * t634 * t15 - 0.2e1 * t727 * t5 * t80 - 0.32e2 * t650 * xc * t654 + 0.2e1 * t301 * t698 * t14 - 0.32e2 * t738 * t740 + 0.8e1 * t674 * t739 * t562 + 0.4e1 * t746 * t119 * t652 + 0.8e1 * t674 * t698 * t623 - 0.8e1 * t754 * t528 * t698 t762 = t633 * t13 t764 = t5 * n * t652 t767 = t80 * t1 t768 = t649 * t767 t772 = t649 * ZA t773 = t772 * t129 t777 = t35 * t1 * t19 t780 = t632 * t5 t781 = t780 * t15 t786 = t698 * ZA t790 = t64 * t14 t800 = t649 * t8 t809 = 0.4e1 * t238 * t126 * t80 - 0.8e1 * t762 * t764 - 0.32e2 * t768 * xc * t275 + 0.64e2 * t773 * t740 - 0.4e1 * t301 * t777 - 0.8e1 * t781 * n * t8 * t675 + 0.4e1 * t238 * t786 + 0.32e2 * t768 * t34 * t790 * t8 - 0.8e1 * t633 * t528 * t634 + 0.8e1 * t754 * t528 * t739 + 0.128e3 * t800 * t119 * t80 * t19 * t106 + 0.8e1 * t674 * t739 * t13 t812 = t649 * t80 t817 = t83 * ZB t824 = t746 * ZB t828 = t800 * t14 t855 = -0.64e2 * t812 * xc * t274 * t667 + 0.4e1 * t817 * t786 + 0.4e1 * t727 * ZA * t652 * ZB - 0.32e2 * t824 * t657 * t667 - 0.32e2 * t828 * t34 * t767 * xc - 0.8e1 * t633 * t15 * t34 * t634 - 0.8e1 * t674 * t739 * t15 + 0.32e2 * t768 * t64 * t275 + 0.4e1 * t708 * t14 * t307 + 0.2e1 * t708 * t206 * t652 + 0.8e1 * t632 * t35 * t13 * t34 * t634 * xc t858 = t35 * t19 t873 = t2 * t8 t878 = t61 * t1 t901 = -0.16e2 * t632 * t2 * xc * t528 * t858 + 0.8e1 * t824 * t658 + 0.4e1 * t301 * t14 * t777 - 0.8e1 * t665 * t634 * t509 - 0.8e1 * t674 * t739 * t623 - 0.16e2 * t781 * t873 * t19 * xc + 0.8e1 * t878 * t14 * t127 + 0.8e1 * t878 * ZA * t51 * ZB + 0.8e1 * t686 * t764 + 0.8e1 * t665 * xc * t634 * t15 * t8 + 0.8e1 * t633 * t15 * t5 * t634 + 0.4e1 * t387 * t14 * t107 * ZA t903 = t739 * t790 t923 = t737 * t80 t924 = t667 * t790 t927 = t780 * t2 t937 = t15 * t19 * xc t943 = 0.32e2 * t738 * t903 + 0.16e2 * t781 * t873 * t19 + 0.8e1 * t754 * t15 * t652 * t5 + 0.16e2 * t666 * t858 * t623 + 0.64e2 * t828 * t25 * t767 * xc - 0.16e2 * t762 * t456 * t19 + 0.64e2 * t923 * t924 + 0.16e2 * t927 * t668 - 0.64e2 * t768 * ZA * t790 * t66 - 0.64e2 * t773 * t903 + 0.16e2 * t927 * t937 + 0.16e2 * t666 * t667 * t562 t977 = 0.64e2 * t812 * t5 * t924 + 0.8e1 * t639 * t504 + 0.8e1 * t238 * t35 * t118 * t19 + 0.4e1 * t642 * t658 - 0.16e2 * t817 * t437 * t8 - 0.128e3 * t772 * ZB * t80 * t924 + 0.16e2 * t666 * t667 * t13 - 0.4e1 * t301 * t643 - 0.16e2 * t824 * t653 * t8 - 0.4e1 * t642 * t777 - 0.64e2 * t923 * t667 * t268 - 0.16e2 * t666 * t937 _C3A = ( t72 + t132 + t169 + t210 + t246 + t298 + t337 + t378 + t409 + t441 + t483 + t512 + t542 + t573 + t600 + t627 ) / (t682 + t717 + t758 + t809 + t855 + t901 + t943 + t977) #************************************************************************************** _C4A = 0 #************************************************************************************** t1 = nx * 0.3141592654e1 t2 = t1 * xc t3 = cos(t2) t4 = nx * nx t6 = n * 0.3141592654e1 t7 = t3 * t4 * t6 t8 = ZA * ZB t9 = exp(t6) t10 = t9 * t9 t11 = xc * n t13 = exp(t11 * 0.3141592654e1) t14 = t13 * t13 t15 = t14 * t13 t16 = t14 * t14 t17 = t16 * t15 t18 = t10 * t17 t19 = t8 * t18 t22 = sin(t2) t23 = nx * t22 t24 = t23 * n t25 = ZB * ZB t30 = n * n t31 = t30 * n t32 = t31 * nx t33 = 0.3141592654e1 * 0.3141592654e1 t35 = t32 * t22 * t33 t36 = ZA * ZA t37 = t36 * xc t38 = t16 * t13 t39 = t10 * t38 t40 = t37 * t39 t43 = sin(t1) t44 = nx * t43 t45 = t30 * 0.3141592654e1 t46 = t44 * t45 t47 = ZA * xc t49 = ZB * t16 * t9 t54 = t4 * nx * t43 t55 = xc * xc t57 = t54 * t30 * t55 t58 = t33 * 0.3141592654e1 t59 = t58 * t25 t60 = t16 * t9 t61 = t59 * t60 t64 = xc * t25 t65 = t14 * t9 t66 = t64 * t65 t70 = t44 * t31 * t33 t71 = t37 * t65 t74 = t10 * t15 t75 = t64 * t74 t78 = t25 * t10 t83 = t54 * n * t33 t84 = t55 * t25 t85 = t10 * t9 t86 = t14 * t85 t87 = t84 * t86 t90 = t30 * t30 t92 = t44 * t90 * t58 t93 = t55 * xc t94 = t93 * t25 t95 = t85 * t16 t96 = t94 * t95 t102 = t23 * t45 t103 = t10 * t10 t104 = ZB * t103 t106 = t47 * t104 * t15 t111 = t54 * 0.3141592654e1 t112 = t25 * t85 t113 = t112 * t16 t115 = t8 * t39 t118 = t16 * t14 t119 = t85 * t118 t120 = t37 * t119 t123 = t16 * t16 t124 = t36 * t123 t125 = t124 * t9 t127 = -0.8e1 * t7 * t19 + 0.2e1 * t24 * t25 * t13 * t10 - 0.16e2 * t35 * t40 - 0.16e2 * t46 * t47 * t49 - 0.8e1 * t57 * t61 + 0.4e1 * t46 * t66 + 0.2e1 * t70 * t71 - 0.16e2 * t35 * t75 + 0.6e1 * t24 * t78 * t38 - 0.2e1 * t83 * t87 - 0.8e1 * t92 * t96 - 0.8e1 * t46 * t37 * t95 - 0.12e2 * t102 * t106 + 0.2e1 * t83 * t71 + t111 * t113 + 0.8e1 * t7 * t115 + 0.2e1 * t83 * t120 + t111 * t125 t128 = t37 * t74 t131 = t44 * n t133 = t25 * t9 * t118 t136 = t36 * t14 t137 = t136 * t9 t140 = t30 * t4 t142 = t140 * t3 * t33 t143 = t64 * t39 t147 = t30 * nx * t43 t148 = 0.3141592654e1 * t36 t149 = t9 * t118 t153 = t44 * t31 * ZA t154 = t33 * xc t155 = t154 * t49 t160 = ZA * t17 * xc * ZB t163 = t103 * t13 t164 = t64 * t163 t170 = t44 * t90 * t55 t171 = t58 * ZB t172 = ZA * t16 t174 = t171 * t172 * t9 t177 = t36 * t55 t178 = t177 * t149 t181 = t54 * t11 t182 = t33 * t25 t186 = t25 * t14 t187 = t186 * t9 t193 = t186 * t85 t198 = ZB * t55 t199 = ZA * t103 t201 = t198 * t199 * t15 t204 = 0.2e1 * t7 * t128 - 0.2e1 * t131 * t133 - 0.2e1 * t131 * t137 + 0.16e2 * t142 * t143 - t147 * t148 * t149 + 0.8e1 * t153 * t155 - 0.4e1 * t7 * t160 + 0.2e1 * t7 * t164 + 0.10e2 * t102 * t40 + 0.16e2 * t170 * t174 + 0.2e1 * t83 * t178 - 0.2e1 * t181 * t182 * t65 - t111 * t187 - 0.2e1 * t70 * t87 + 0.4e1 * t102 * t160 - 0.2e1 * t131 * t193 - 0.16e2 * t142 * t75 + 0.16e2 * t35 * t201 t210 = t32 * t22 t211 = t33 * t55 t212 = t25 * t38 t213 = t211 * t212 t216 = n * nx t217 = t22 * t25 t222 = ZB * t85 * t16 t226 = t23 * t30 t227 = t13 * t10 t228 = t148 * t227 t233 = t37 * t163 t237 = n * t4 * t3 t238 = t148 * t74 t241 = t64 * t86 t245 = t148 * xc * t15 t248 = t112 * t118 t250 = t22 * t36 t256 = 0.3141592654e1 * t25 t257 = t256 * t39 t262 = t38 * t103 t263 = t37 * t262 t267 = t148 * t17 * xc t270 = -0.6e1 * t7 * t143 - 0.4e1 * t24 * t19 - 0.8e1 * t210 * t213 - 0.2e1 * t216 * t217 * t15 - 0.32e2 * t153 * t211 * t222 + 0.4e1 * t226 * t228 + 0.16e2 * t142 * t201 + 0.2e1 * t7 * t233 - 0.4e1 * t237 * t238 - 0.2e1 * t83 * t241 - 0.2e1 * t237 * t245 + t111 * t248 + 0.2e1 * t216 * t250 * t15 - 0.2e1 * t131 * t125 - 0.4e1 * t226 * t257 + t147 * t148 * t95 - 0.2e1 * t102 * t263 + 0.2e1 * t237 * t267 t273 = t37 * t149 t277 = t47 * t104 * t13 t285 = t31 * t36 t286 = t44 * t285 t291 = t25 * t123 * t9 t304 = 0.3141592654e1 * xc t305 = t304 * t212 t312 = t256 * t18 t315 = t8 * t60 t319 = t54 * t30 * t58 t323 = t90 * t36 t324 = t44 * t323 t325 = t55 * t58 t326 = t325 * t60 t329 = 0.2e1 * t102 * t164 + 0.2e1 * t83 * t273 - 0.4e1 * t102 * t277 - 0.2e1 * t7 * t263 + 0.4e1 * t24 * t8 * t17 - 0.4e1 * t286 * t154 * t60 - 0.2e1 * t131 * t291 - t147 * t148 * t119 + 0.2e1 * t24 * t78 * t17 + 0.2e1 * t54 * t85 * 0.3141592654e1 * ZA * ZB - 0.4e1 * t226 * t305 - 0.2e1 * t70 * t66 + t147 * t256 * t95 + 0.4e1 * t237 * t312 + 0.2e1 * t111 * t315 - 0.8e1 * t319 * t96 - t111 * t193 - 0.8e1 * t324 * t326 t332 = t8 * t95 t335 = t136 * t85 t337 = t256 * t227 t340 = t177 * t119 t346 = t37 * t86 t351 = t103 * t15 t352 = t177 * t351 t355 = t64 * t119 t358 = t8 * t227 t361 = t85 * 0.3141592654e1 t365 = t84 * t39 t372 = ZB * t10 t373 = t372 * t38 t374 = t47 * t373 t379 = t177 * t39 t384 = -0.2e1 * t46 * t332 + t111 * t335 + 0.4e1 * t237 * t337 - 0.2e1 * t83 * t340 + 0.16e2 * t286 * t211 * t95 + 0.2e1 * t70 * t346 - 0.8e1 * t170 * t61 - 0.8e1 * t142 * t352 - 0.2e1 * t83 * t355 - 0.4e1 * t24 * t358 + 0.2e1 * t147 * t361 * t8 + 0.8e1 * t35 * t365 - 0.2e1 * t226 * t267 + 0.8e1 * t102 * t115 - 0.12e2 * t102 * t374 + 0.16e2 * t142 * t40 - 0.8e1 * t142 * t379 + 0.4e1 * t237 * t228 t386 = t54 * t30 * t93 t387 = ZA * t85 t389 = t171 * t387 * t16 t394 = t64 * t60 t398 = t304 * t25 * t15 t401 = t361 * t25 t405 = t84 * t65 t410 = t148 * t18 t414 = t25 * t16 * t9 t417 = t84 * t74 t422 = t177 * t86 t428 = ZB * t38 t429 = t47 * t428 t432 = t148 * t39 t439 = 0.16e2 * t386 * t389 - 0.16e2 * t386 * t174 + 0.8e1 * t46 * t394 + 0.2e1 * t237 * t398 - t147 * t401 + 0.4e1 * t7 * t374 + 0.2e1 * t83 * t405 - 0.4e1 * t46 * t241 - 0.4e1 * t226 * t410 + 0.2e1 * t131 * t414 + 0.8e1 * t35 * t417 - 0.8e1 * t142 * t365 + 0.2e1 * t70 * t422 - 0.4e1 * t181 * t182 * t60 + 0.12e2 * t102 * t429 - 0.4e1 * t226 * t432 + 0.32e2 * t35 * t374 - 0.4e1 * t7 * t106 t442 = t36 * t9 * t118 t444 = t123 * t9 t445 = t8 * t444 t448 = t361 * t36 t451 = t47 * t372 * t17 t454 = t94 * t60 t457 = t25 * t103 t465 = t47 * t372 * t15 t468 = t36 * t85 t469 = t468 * t16 t474 = t43 * t85 t478 = t8 * t74 t484 = t256 * t74 t489 = t198 * ZA * t10 * t15 t501 = -t111 * t442 + 0.4e1 * t131 * t445 - t147 * t448 + 0.4e1 * t7 * t451 + 0.8e1 * t92 * t454 - 0.2e1 * t24 * t457 * t13 - 0.2e1 * t286 * t211 * t65 + 0.4e1 * t7 * t465 + t111 * t469 - 0.2e1 * t216 * t250 * t17 - 0.2e1 * t216 * t474 * t25 - 0.4e1 * t24 * t478 + 0.4e1 * t24 * t8 * t38 + 0.4e1 * t226 * t484 - 0.16e2 * t142 * t489 - 0.2e1 * t24 * t212 * t103 - 0.2e1 * t216 * t22 * t17 * t25 + 0.2e1 * t70 * t120 t504 = t33 * t36 * t55 * t38 t507 = t37 * t18 t512 = t47 * ZB * t13 * t10 t518 = t59 * t95 t530 = t84 * t351 t534 = t37 * t227 t549 = -0.8e1 * t210 * t504 + 0.2e1 * t102 * t507 + 0.4e1 * t7 * t512 + t111 * t133 - 0.16e2 * t35 * t489 + 0.8e1 * t170 * t518 + 0.2e1 * t24 * t36 * t13 * t10 + 0.4e1 * t131 * t387 * ZB + 0.12e2 * t102 * t465 - 0.8e1 * t142 * t530 + t111 * t291 - 0.2e1 * t102 * t534 - 0.4e1 * t70 * t394 - 0.10e2 * t102 * t128 + 0.4e1 * t237 * t305 + 0.8e1 * t102 * t19 + 0.2e1 * t83 * t346 - 0.16e2 * t35 * t128 t557 = t468 * t118 t562 = t93 * t58 t563 = t562 * t60 t567 = t44 * t90 * t93 t575 = ZA * t55 t576 = t575 * t428 t583 = t37 * t60 t590 = t140 * t3 t601 = -0.2e1 * t226 * t398 - 0.2e1 * t70 * t340 - 0.2e1 * t131 * t557 - 0.4e1 * t24 * t115 + 0.8e1 * t324 * t563 + 0.16e2 * t567 * t389 + 0.16e2 * t70 * t84 * t95 + 0.2e1 * t70 * t178 - 0.16e2 * t142 * t576 - 0.4e1 * t237 * t257 - 0.4e1 * t226 * t312 + 0.8e1 * t46 * t583 + 0.2e1 * t24 * t36 * t38 * t103 + 0.8e1 * t590 * t213 + 0.2e1 * t102 * t143 - 0.16e2 * t35 * t143 + 0.2e1 * t131 * t248 + 0.4e1 * t46 * t346 t604 = n * t36 t606 = t154 * t95 t625 = t36 * t103 t640 = t30 * t36 t641 = t54 * t640 t642 = t325 * t95 t647 = -0.4e1 * t131 * t315 - 0.4e1 * t54 * t604 * t606 - t147 * t148 * t60 + 0.16e2 * t35 * t576 - 0.8e1 * t102 * t478 + 0.32e2 * t142 * t465 - 0.4e1 * t237 * t484 - 0.2e1 * t70 * t355 + 0.2e1 * t70 * t273 + 0.2e1 * t102 * t233 - 0.2e1 * t24 * t625 * t13 - 0.8e1 * t7 * t358 - 0.2e1 * t111 * t445 - 0.4e1 * t7 * t429 + 0.16e2 * t46 * t47 * t222 + 0.2e1 * t131 * t113 + 0.8e1 * t641 * t642 - 0.2e1 * t7 * t534 t652 = t36 * t16 t653 = t652 * t9 t655 = t64 * t227 t658 = t182 * t95 t663 = t562 * t95 t684 = t64 * t351 t689 = t36 * t10 t695 = t154 * t222 t698 = -0.4e1 * t216 * t217 * t38 - t111 * t653 - 0.2e1 * t7 * t655 - 0.4e1 * t181 * t658 + 0.2e1 * t131 * t469 - 0.8e1 * t641 * t663 - 0.4e1 * t83 * t583 - 0.2e1 * t83 * t177 * t65 - 0.4e1 * t24 * t457 * t15 + 0.16e2 * t70 * t84 * t60 + 0.8e1 * t57 * t518 - 0.32e2 * t142 * t374 + 0.4e1 * t24 * t8 * t351 + 0.4e1 * t102 * t684 - t147 * t256 * t86 - 0.2e1 * t24 * t689 * t15 - 0.2e1 * t70 * t241 + 0.8e1 * t153 * t695 t711 = t575 * t373 t717 = t304 * t17 * t25 t736 = t177 * t74 t739 = 0.2e1 * t226 * t245 - 0.8e1 * t102 * t358 - 0.16e2 * t57 * t389 - 0.2e1 * t102 * t655 + 0.8e1 * t590 * t504 - 0.8e1 * t641 * t326 - 0.16e2 * t35 * t711 - t111 * t557 + t111 * t137 - 0.2e1 * t226 * t717 + 0.8e1 * t102 * t37 * t351 + 0.2e1 * t131 * t335 - 0.4e1 * t131 * t332 - 0.2e1 * t216 * t474 * t36 - 0.2e1 * t111 * t332 + 0.16e2 * t142 * t711 - t147 * t256 * t60 + 0.8e1 * t142 * t736 t750 = t64 * t262 t763 = t44 * t640 t770 = t84 * t119 t782 = 0.4e1 * t102 * t512 + 0.8e1 * t142 * t417 + 0.8e1 * t641 * t563 - 0.2e1 * t7 * t507 + 0.2e1 * t7 * t750 - 0.8e1 * t35 * t352 + 0.4e1 * t237 * t410 + 0.4e1 * t7 * t684 - 0.2e1 * t46 * t445 + t147 * t148 * t65 + 0.4e1 * t763 * t304 * t119 + 0.16e2 * t70 * t177 * t60 + 0.2e1 * t70 * t770 - t111 * t414 - 0.16e2 * t567 * t174 - 0.4e1 * t46 * t71 - 0.4e1 * t46 * t355 - 0.4e1 * t7 * t277 t797 = t64 * t149 t821 = -t54 * t448 + 0.2e1 * t131 * t442 + 0.8e1 * t7 * t478 + 0.8e1 * t35 * t379 - 0.2e1 * t181 * t182 * t149 + 0.2e1 * t70 * t405 + 0.2e1 * t83 * t770 - 0.2e1 * t70 * t797 - 0.6e1 * t7 * t75 - 0.4e1 * t286 * t606 - 0.4e1 * t237 * t432 + t147 * t256 * t149 - 0.4e1 * t763 * t304 * t149 - 0.2e1 * t102 * t75 + 0.2e1 * t237 * t717 + 0.8e1 * t324 * t642 - 0.16e2 * t170 * t389 + 0.2e1 * t83 * t422 t827 = t84 * t149 t846 = t54 * n * ZA t854 = t64 * t18 t867 = -0.16e2 * t142 * t128 + 0.32e2 * t35 * t465 - 0.2e1 * t83 * t827 + 0.2e1 * t46 * t315 + t147 * t148 * t86 - 0.4e1 * t102 * t451 - 0.8e1 * t226 * t148 * xc * t38 - 0.2e1 * t24 * t689 * t38 + 0.2e1 * t131 * t187 + 0.8e1 * t846 * t155 + 0.8e1 * t35 * t736 + 0.2e1 * t24 * t689 * t17 - 0.2e1 * t7 * t854 + t147 * t256 * t119 + 0.2e1 * t102 * t854 - 0.8e1 * t35 * t530 + 0.4e1 * t46 * t797 + 0.2e1 * t102 * t750 t909 = -0.8e1 * t324 * t663 + t147 * t256 * t444 - t147 * t256 * t65 + 0.4e1 * t226 * t238 + 0.2e1 * t7 * t40 - t54 * t401 + 0.16e2 * t57 * t174 + 0.4e1 * t226 * t337 + 0.4e1 * t24 * t8 * t163 + 0.8e1 * t846 * t695 + 0.8e1 * t319 * t454 + 0.2e1 * t131 * t653 - 0.8e1 * t46 * t64 * t95 + 0.6e1 * t24 * t78 * t15 - 0.4e1 * t44 * t31 * xc * t658 - 0.32e2 * t153 * t211 * t49 - 0.2e1 * t70 * t827 + t147 * t148 * t444 t914 = t25 * ZB t915 = t33 * t914 t919 = t4 * t4 t920 = t16 * t919 t929 = t123 * t90 t932 = t919 * t103 t935 = t33 * ZB t939 = t652 * t919 t942 = t16 * t30 t943 = t942 * t4 t949 = t103 * t16 t950 = t949 * t90 t953 = -0.2e1 * t915 * t103 * t90 + 0.2e1 * t915 * t920 - 0.2e1 * t915 * t123 * t919 + 0.2e1 * t915 * t16 * t90 - 0.2e1 * t915 * t929 - 0.2e1 * t915 * t932 - 0.2e1 * t935 * t323 * t123 + 0.2e1 * t935 * t939 + 0.4e1 * t915 * t943 + 0.4e1 * t182 * t172 * t90 + 0.2e1 * t915 * t950 t954 = t171 * t36 t955 = t90 * n t956 = xc * t955 t957 = t118 * t10 t964 = t33 * t33 t965 = t964 * ZB t966 = t965 * t640 t967 = t10 * t919 t968 = t55 * t16 t969 = t967 * t968 t972 = t935 * t36 t974 = t103 * t30 * t4 t977 = xc * t16 t978 = t967 * t977 t981 = t90 * t30 t983 = t16 * t10 t987 = t182 * ZA t988 = t4 * t10 t992 = t171 * t604 t993 = xc * t14 t994 = t932 * t993 t997 = t182 * t30 t1005 = t171 * t285 t1006 = t988 * t993 t1009 = t58 * t914 t1010 = t1009 * t31 t1013 = 0.8e1 * t954 * t956 * t957 + 0.2e1 * t915 * t932 * t16 + 0.32e2 * t966 * t969 - 0.4e1 * t972 * t974 - 0.32e2 * t966 * t978 + 0.32e2 * t965 * t981 * t177 * t983 - 0.32e2 * t987 * t942 * t988 + 0.8e1 * t992 * t994 + 0.8e1 * t997 * t949 * ZA * t4 - 0.2e1 * t935 * t124 * t919 - 0.16e2 * t1005 * t1006 + 0.16e2 * t1010 * t1006 t1015 = t964 * t25 t1016 = ZA * t30 t1017 = t1015 * t1016 t1020 = t967 * t993 t1031 = t1009 * t118 t1032 = t31 * t10 t1040 = t964 * t914 t1041 = t1040 * t90 t1044 = t55 * t10 * t4 * t16 t1047 = t1040 * t30 t1050 = t123 * ZA t1054 = t977 * t988 t1057 = 0.64e2 * t1017 * t978 - 0.8e1 * t992 * t1020 + 0.2e1 * t972 * t950 + 0.4e1 * t182 * t929 * ZA + 0.4e1 * t182 * t199 * t90 - 0.16e2 * t1031 * t1032 * t4 * xc + 0.4e1 * t182 * t172 * t919 + 0.64e2 * t1041 * t1044 + 0.32e2 * t1047 * t969 + 0.4e1 * t182 * t1050 * t919 - 0.64e2 * t1041 * t1054 t1058 = t1009 * n t1063 = t932 * ZA t1069 = t123 * t30 * t4 t1080 = t993 * t103 * t4 t1088 = t935 * t103 t1094 = -0.8e1 * t1058 * t994 - 0.32e2 * t1047 * t978 + 0.4e1 * t182 * t1063 - 0.4e1 * t915 * t974 - 0.4e1 * t915 * t1069 - 0.2e1 * t935 * t625 * t90 - 0.8e1 * t1009 * t10 * t14 * t955 - 0.16e2 * t1010 * t1080 - 0.2e1 * t935 * t625 * t919 - 0.64e2 * t1017 * t969 + 0.2e1 * t1088 * t939 + 0.8e1 * t1009 * t957 * t955 t1113 = t955 * t118 * xc t1120 = t4 * t118 t1125 = t981 * xc t1133 = n * t10 t1140 = -0.8e1 * t954 * t955 * t10 * t993 + 0.2e1 * t935 * t652 * t90 - 0.64e2 * t1015 * t981 * t575 * t983 + 0.8e1 * t182 * t103 * t1016 * t4 + 0.8e1 * t1009 * t1113 + 0.16e2 * t954 * t1032 * t4 * t14 - 0.16e2 * t954 * t1032 * t1120 + 0.64e2 * t1015 * t10 * t172 * t1125 + 0.8e1 * t171 * t103 * t136 * t956 - 0.8e1 * t1031 * t1133 * t919 * xc + 0.8e1 * t1058 * t1020 t1153 = xc * t118 t1165 = t182 * t16 t1170 = t171 * t10 t1178 = ZA * t90 t1182 = 0.4e1 * t1088 * t652 * t140 + 0.8e1 * t954 * t1133 * t919 * t14 + 0.4e1 * t972 * t943 - 0.4e1 * t972 * t1069 - 0.16e2 * t954 * t31 * t4 * t1153 - 0.8e1 * t954 * n * t919 * t1153 - 0.8e1 * t954 * t1133 * t919 * t118 + 0.4e1 * t1165 * t1063 + 0.16e2 * t1005 * t1080 - 0.8e1 * t1170 * t118 * t36 * t955 - 0.16e2 * t987 * t920 * t10 - 0.16e2 * t1165 * t1178 * t10 t1195 = t1040 * t981 t1199 = t1009 * t955 t1203 = t1009 * t10 t1211 = t965 * t323 t1225 = -0.32e2 * t965 * t10 * t652 * t1125 + 0.4e1 * t915 * t16 * t974 + 0.4e1 * t182 * t90 * t949 * ZA + 0.32e2 * t1195 * t968 * t10 - 0.8e1 * t1199 * t993 * t103 + 0.8e1 * t1203 * t118 * n * t919 + 0.8e1 * t1170 * t136 * t955 + 0.64e2 * t1211 * t1044 + 0.16e2 * t1031 * t1032 * t4 + 0.8e1 * t987 * t943 + 0.8e1 * t1199 * t993 * t10 + 0.8e1 * t997 * t1050 * t4 t1263 = -0.128e3 * t1015 * t1178 * t1044 + 0.16e2 * t1005 * t988 * t1153 + 0.8e1 * t1058 * t1153 * t919 + 0.16e2 * t1010 * t1120 * xc - 0.8e1 * t954 * t1113 - 0.8e1 * t1203 * t14 * n * t919 - 0.16e2 * t1203 * t14 * t31 * t4 - 0.8e1 * t1203 * t1113 - 0.32e2 * t1195 * t977 * t10 - 0.64e2 * t1211 * t1054 + 0.8e1 * t992 * t967 * t1153 + 0.128e3 * t1015 * t983 * t90 * t4 * t47 _C1B = ( t127 + t204 + t270 + t329 + t384 + t439 + t501 + t549 + t601 + t647 + t698 + t739 + t782 + t821 + t867 + t909 ) / (t953 + t1013 + t1057 + t1094 + t1140 + t1182 + t1225 + t1263) t1 = n * n t2 = t1 * n t3 = nx * t2 t4 = 0.3141592654e1 * ZA t5 = t3 * t4 t6 = nx * 0.3141592654e1 t7 = t6 * xc t8 = sin(t7) t9 = t8 * ZB t10 = n * 0.3141592654e1 t11 = exp(t10) t12 = t11 * t11 t15 = exp(xc * n * 0.3141592654e1) t16 = t15 * t15 t17 = t16 * t16 t18 = t17 * t15 t19 = t12 * t18 t23 = t1 * t1 t24 = nx * t23 t25 = ZB * ZB t27 = t18 * t8 t28 = 0.3141592654e1 * 0.3141592654e1 t29 = xc * xc t30 = t28 * t29 t34 = t1 * xc t35 = 0.3141592654e1 * ZB t36 = t34 * t35 t37 = cos(t7) t38 = ZA * t37 t39 = nx * nx t40 = t39 * t12 t41 = t16 * t15 t43 = t38 * t40 * t41 t46 = t25 * n t47 = t46 * 0.3141592654e1 t48 = t39 * nx t49 = sin(t6) t50 = t48 * t49 t51 = t12 * t11 t52 = t51 * t17 t53 = t50 * t52 t56 = t34 * 0.3141592654e1 * t25 t57 = t37 * t39 t58 = t17 * t41 t59 = t12 * t58 t60 = t57 * t59 t63 = t25 * t18 t64 = t57 * n t67 = ZA * ZA t68 = t67 * n t69 = 0.3141592654e1 * t48 t70 = t68 * t69 t71 = t49 * xc t72 = t17 * t16 t73 = t11 * t72 t74 = t71 * t73 t77 = t1 * t67 t78 = t77 * 0.3141592654e1 t81 = nx * t25 t82 = t81 * t49 t83 = t17 * t17 t85 = t1 * t83 * t11 t87 = nx * ZB t88 = t8 * t2 t89 = t87 * t88 t90 = 0.3141592654e1 * xc t91 = t12 * t12 t92 = ZA * t91 t97 = ZB * ZA t98 = t97 * t37 t99 = t39 * n t100 = t12 * t41 t104 = 0.8e1 * t5 * t9 * t19 + 0.8e1 * t24 * t25 * t27 * t30 + 0.12e2 * t36 * t43 - t47 * t53 - 0.2e1 * t56 * t60 - 0.4e1 * t63 * t64 + 0.6e1 * t70 * t74 + 0.4e1 * t78 * t60 - t82 * t85 + 0.4e1 * t89 * t90 * t92 * t41 + 0.4e1 * t98 * t99 * t100 t105 = t67 * t48 t106 = t49 * t51 t107 = t106 * t72 t109 = t1 * 0.3141592654e1 t110 = t109 * xc t115 = nx * t67 t116 = t115 * t49 t117 = t1 * t16 t118 = t117 * t11 t120 = t2 * t25 t121 = t28 * 0.3141592654e1 t122 = t121 * t29 t123 = t120 * t122 t129 = t1 * ZB t130 = t129 * t4 t131 = t57 * t100 t134 = t12 * t16 t136 = t109 * t39 t139 = ZB * t18 t141 = t39 * t1 t142 = t141 * t90 t145 = t77 * t90 t146 = t91 * t41 t147 = t57 * t146 t151 = t25 * t39 * t1 t152 = t72 * t12 t156 = t49 * t2 t158 = t83 * t11 t162 = -t105 * t107 + 0.8e1 * t110 * t72 * t25 * t39 - t116 * t118 + 0.8e1 * t123 * t53 + 0.8e1 * t5 * t9 * t59 - 0.8e1 * t130 * t131 - 0.8e1 * t134 * t25 * t136 - 0.12e2 * t139 * t38 * t142 - 0.8e1 * t145 * t147 - 0.8e1 * t151 * t90 * t152 - 0.2e1 * t87 * t156 * t4 * t158 t164 = t115 * t88 t165 = t90 * t19 t168 = t25 * t48 t169 = t49 * t16 t170 = t169 * t11 t174 = ZA * n * t69 t175 = ZB * t51 t176 = t175 * t17 t177 = t71 * t176 t180 = t1 * t29 t181 = t28 * t25 t182 = t180 * t181 t183 = t50 * t73 t186 = ZA * t1 t187 = t28 * t48 t188 = t186 * t187 t189 = ZB * t17 t190 = t189 * t11 t191 = t71 * t190 t194 = t50 * t158 t196 = t115 * t156 t197 = t90 * t73 t201 = t49 * t17 * t11 t204 = t88 * t90 t207 = t68 * 0.3141592654e1 t208 = t17 * t11 t209 = t50 * t208 t211 = -0.2e1 * t164 * t165 - t168 * t170 + t168 * t107 + 0.8e1 * t174 * t177 + 0.2e1 * t182 * t183 + 0.8e1 * t188 * t191 + t47 * t194 - 0.6e1 * t196 * t197 - t168 * t201 - 0.4e1 * t81 * t18 * t204 - t207 * t209 t212 = t2 * 0.3141592654e1 t213 = t212 * t52 t215 = t81 * t8 t216 = t212 * t59 t219 = t3 * t90 t220 = t25 * t8 t221 = t18 * t91 t225 = t71 * t52 t231 = t16 * t51 t232 = t50 * t231 t237 = ZA * t12 t243 = t67 * t28 t244 = t24 * t243 t245 = t71 * t231 t249 = -t116 * t213 - 0.4e1 * t215 * t216 + 0.2e1 * t219 * t220 * t221 - 0.4e1 * t70 * t225 + 0.4e1 * t98 * t99 * t146 + t47 * t232 - 0.2e1 * t145 * t57 * t221 + 0.4e1 * t89 * t90 * t237 * t41 - t105 * t201 - 0.6e1 * t244 * t245 + t105 * t170 t252 = t25 * t37 t253 = t252 * t39 t255 = n * t15 * t12 t258 = t2 * t29 t259 = ZB * t28 t260 = t258 * t259 t263 = t106 * t17 t265 = xc * t25 t269 = t25 * t49 t270 = t269 * t52 t273 = t1 * t25 t274 = t273 * 0.3141592654e1 t275 = t57 * t19 t278 = t24 * t30 t288 = t1 * t11 * t72 t290 = t212 * t208 t292 = t2 * xc t296 = 0.2e1 * t253 * t255 + 0.16e2 * t260 * t43 + t105 * t263 - 0.4e1 * t10 * t265 * t53 + 0.4e1 * t219 * t270 - 0.12e2 * t274 * t275 + 0.8e1 * t278 * t270 - 0.2e1 * ZB * n * t69 * t49 * ZA * t158 - t82 * t288 - t116 * t290 + 0.16e2 * t292 * t243 * t275 t301 = t50 * t176 t304 = t51 * t72 t305 = t71 * t304 t308 = t25 * t41 t311 = ZA * t48 t312 = t311 * t49 t317 = t91 * t15 t318 = t57 * t317 t321 = t81 * t88 t322 = t90 * t59 t325 = t212 * t231 t327 = t15 * t12 t328 = t57 * t327 t331 = t77 * t187 t334 = t2 * ZA t335 = t334 * t122 t336 = t50 * t190 t339 = 0.8e1 * t151 * t90 * t134 + 0.16e2 * t186 * t30 * t301 - 0.2e1 * t70 * t305 + 0.2e1 * t308 * t64 - 0.2e1 * t312 * ZB * t83 * t11 + 0.2e1 * t56 * t318 + 0.2e1 * t321 * t322 - t116 * t325 - 0.4e1 * t274 * t328 + 0.2e1 * t331 * t305 - 0.16e2 * t335 * t336 t341 = t169 * t51 t344 = t49 * t11 * t72 t346 = t77 * t30 t347 = t50 * t304 t350 = t25 * t51 t352 = nx * ZA t353 = t49 * t23 t354 = t352 * t353 t355 = t28 * xc t362 = t25 * t91 t365 = t23 * n t366 = nx * t365 t367 = t366 * t122 t368 = ZB * t49 t369 = ZA * t51 t370 = t369 * t17 t371 = t368 * t370 t374 = t115 * t353 t375 = t355 * t73 t381 = t105 * t341 - t105 * t344 - 0.2e1 * t346 * t347 - t350 * t50 - 0.8e1 * t354 * t355 * t176 - 0.4e1 * t98 * t99 * t317 - 0.2e1 * t362 * t99 - 0.16e2 * t367 * t371 + 0.6e1 * t374 * t375 - 0.8e1 * t182 * t53 - t82 * t290 t382 = t71 * t208 t394 = t2 * t67 t395 = t394 * t122 t398 = t352 * t156 t402 = t17 * t12 t403 = t39 * ZA t404 = t402 * t403 t407 = t269 * t208 t411 = t49 * t83 * t11 t413 = t46 * t69 t419 = -0.4e1 * t331 * t382 + 0.2e1 * t115 * t58 * t204 - 0.2e1 * t145 * t60 + 0.12e2 * t274 * t131 + 0.2e1 * t346 * t232 + 0.8e1 * t395 * t53 - 0.8e1 * t398 * t90 * t176 - 0.64e2 * t260 * t404 + 0.4e1 * t219 * t407 + t168 * t411 - 0.6e1 * t413 * t74 - 0.2e1 * t110 * t308 * t57 t424 = t16 * t11 t425 = t212 * t424 t427 = t258 * t181 t430 = t67 * t29 t431 = t366 * t430 t432 = t121 * t49 t433 = t432 * t52 t436 = n * t12 t437 = t436 * t18 t440 = t29 * xc t441 = t440 * t121 t442 = t394 * t441 t445 = t67 * t37 t446 = t445 * t39 t448 = n * t18 * t91 t453 = t352 * t49 t458 = t8 * t23 t462 = t81 * t458 t463 = t30 * t19 t466 = -t47 * t209 + t116 * t425 - 0.8e1 * t427 * t275 + 0.8e1 * t431 * t433 - 0.2e1 * t253 * t437 - 0.8e1 * t442 * t53 - 0.2e1 * t446 * t448 + 0.2e1 * t175 * t312 + 0.6e1 * t453 * t129 * t208 + 0.8e1 * t115 * t18 * t458 * t30 + 0.8e1 * t462 * t463 t470 = t436 * t58 t475 = t2 * t121 * t440 * t25 t485 = t212 * t73 t488 = t67 * t72 * t1 t490 = t39 * xc t501 = 0.4e1 * t374 * t355 * t52 + 0.2e1 * t446 * t470 - 0.8e1 * t475 * t53 - 0.2e1 * t446 * t437 - 0.4e1 * t36 * t38 * t39 * t15 * t12 - t116 * t485 + 0.8e1 * t488 * 0.3141592654e1 * t12 * t490 - t207 * t183 - 0.2e1 * t182 * t232 - 0.6e1 * t413 * t245 - 0.4e1 * t413 * t382 t503 = t115 * t8 t510 = t355 * t19 t513 = t432 * t208 t525 = t38 * t40 * t18 t533 = -0.4e1 * t503 * t216 - 0.4e1 * t89 * t90 * t92 * t15 - 0.16e2 * t462 * t510 + 0.8e1 * t431 * t513 - 0.4e1 * t78 * t131 + t47 * t183 - 0.2e1 * t67 * t83 * t99 + 0.4e1 * t331 * t225 + 0.16e2 * t260 * t525 - 0.4e1 * t89 * t90 * t237 * t58 - t207 * t53 t536 = t28 * t37 t538 = t490 * t100 t541 = t334 * t441 t547 = t394 * t30 t550 = t212 * t19 t553 = t366 * t441 t556 = n * t17 t571 = -0.8e1 * t427 * t131 + 0.16e2 * t394 * t536 * t538 + 0.16e2 * t541 * t336 + 0.2e1 * t453 * t129 * t158 - 0.8e1 * t547 * t147 + 0.4e1 * t503 * t550 - 0.8e1 * t553 * t270 + 0.4e1 * t556 * ZB * t92 * t39 - 0.2e1 * t67 * t91 * t99 - t82 * t425 + 0.4e1 * t78 * t275 + 0.2e1 * t78 * xc * t41 * t57 t583 = t90 * t317 t594 = t212 * t158 t596 = t152 * t67 t602 = t67 * t17 t607 = 0.8e1 * t367 * t407 - 0.4e1 * t98 * t99 * t59 + 0.16e2 * t260 * t18 * ZA * t57 + 0.2e1 * t321 * t583 - 0.6e1 * t174 * t368 * t52 - 0.4e1 * t89 * t90 * ZA * t15 * t12 + t116 * t594 - 0.8e1 * t596 * t136 - 0.4e1 * t98 * t99 * t327 + 0.2e1 * t602 * t99 + 0.2e1 * t164 * t583 t613 = t83 * t25 t616 = t81 * t156 t627 = t90 * t231 t630 = t91 * t16 t638 = 0.4e1 * t196 * t90 * t208 - 0.8e1 * t130 * t60 - 0.2e1 * t613 * t99 + 0.6e1 * t616 * t197 - 0.8e1 * t547 * t131 + 0.8e1 * t67 * t18 * t37 * t142 + 0.2e1 * t145 * t328 - 0.6e1 * t196 * t627 + 0.8e1 * t630 * t67 * t142 - 0.8e1 * t547 * t275 + 0.8e1 * t395 * t209 t643 = t77 * t355 t648 = t115 * t458 t651 = t134 * t67 t657 = t30 * t304 t660 = t30 * t146 t665 = t25 * t17 t668 = t50 * t424 t671 = -0.4e1 * t321 * t90 * t146 - 0.6e1 * t643 * t232 + 0.8e1 * t182 * t209 - 0.16e2 * t648 * t510 + 0.8e1 * t651 * t136 + 0.8e1 * t89 * t4 * t100 - 0.2e1 * t374 * t657 - 0.8e1 * t648 * t660 + 0.8e1 * t130 * t328 + 0.2e1 * t665 * t99 + 0.2e1 * t346 * t668 t672 = t90 * t424 t676 = t120 * t536 t680 = t436 * t41 t688 = t366 * t67 * t440 t696 = xc * t12 t697 = t696 * t18 t701 = t252 * t141 t702 = t90 * t221 t705 = 0.2e1 * t196 * t672 - t47 * t347 + 0.16e2 * t676 * t538 - t116 * t85 - 0.2e1 * t253 * t680 + t207 * t194 + 0.4e1 * t98 * t99 * t19 - 0.8e1 * t688 * t433 + 0.16e2 * t541 * t301 - 0.6e1 * t312 * t190 + 0.4e1 * t352 * t88 * t35 * t697 + 0.2e1 * t701 * t702 t712 = t24 * t430 t713 = t28 * t49 t721 = t1 * t17 * t11 t726 = ZB * xc t737 = n * t91 t741 = 0.8e1 * t346 * t209 + 0.2e1 * t712 * t713 * t424 + 0.8e1 * t130 * t275 - t47 * t668 + t116 * t721 - 0.8e1 * t688 * t513 + 0.4e1 * t352 * t27 * t212 * t726 + 0.8e1 * t648 * t463 + 0.4e1 * t274 * t60 - 0.4e1 * t374 * t355 * t208 - 0.4e1 * t253 * t737 * t41 t745 = t269 * t231 t749 = t1 * t28 * t265 t757 = t16 * t39 t758 = t696 * t757 t762 = t69 * t49 t772 = t355 * t100 t775 = t81 * t353 t778 = -0.8e1 * t398 * t90 * t190 - 0.2e1 * t278 * t745 + 0.4e1 * t749 * t53 + 0.32e2 * t394 * t29 * t28 * t17 * t40 - 0.8e1 * t78 * t758 + t350 * n * t762 - 0.6e1 * t87 * t49 * t186 * t52 - 0.8e1 * t553 * t407 - 0.4e1 * t749 * t209 + 0.16e2 * t648 * t772 - 0.6e1 * t775 * t375 t790 = t212 * t304 t793 = t156 * 0.3141592654e1 t795 = t355 * t304 t800 = t91 * t39 t801 = t800 * n t807 = t2 * t28 t808 = t807 * t726 t811 = -0.2e1 * t616 * t672 - 0.2e1 * t446 * t680 - 0.2e1 * t78 * xc * t58 * t57 + 0.8e1 * t367 * t270 - t82 * t790 + t115 * t51 * t793 - 0.2e1 * t775 * t795 + 0.8e1 * t123 * t209 + 0.2e1 * t665 * t801 - 0.2e1 * t67 * t41 * t64 - 0.32e2 * t808 * t43 t812 = t117 * t51 t821 = t24 * t355 t827 = t90 * t304 t840 = t800 * t41 t844 = -t116 * t812 - 0.2e1 * t110 * t25 * t58 * t57 - 0.4e1 * t78 * t328 + t82 * t485 - 0.4e1 * t821 * t407 + 0.4e1 * t196 * t90 * t52 + 0.2e1 * t196 * t827 + t82 * t325 + 0.2e1 * t253 * t448 - 0.32e2 * t402 * t67 * t807 * t490 - t207 * t232 + 0.12e2 * t186 * t90 * ZB * t37 * t840 t849 = t1 * t51 t850 = t849 * t17 t860 = t269 * t424 t863 = t273 * t187 t874 = 0.16e2 * t462 * t772 - t116 * t850 + 0.16e2 * t553 * t371 + t116 * t288 - 0.12e2 * t97 * t57 * t109 * t697 + t82 * t594 - 0.2e1 * t278 * t860 - 0.2e1 * t863 * t305 - 0.16e2 * t180 * t259 * t311 * t201 - 0.6e1 * t863 * t74 + 0.8e1 * t174 * t191 t879 = xc * ZA t888 = t67 * t51 t901 = ZA * t17 t903 = t368 * t901 * t11 t908 = -0.2e1 * t352 * t51 * t156 * t35 + 0.64e2 * t879 * t189 * t807 * t40 + 0.2e1 * t46 * t58 * t37 * t39 - t888 * t50 + t105 * t411 - 0.16e2 * t335 * t301 + 0.8e1 * t152 * t25 * t136 - 0.8e1 * t278 * t407 + 0.2e1 * t712 * t713 * t231 - 0.16e2 * t367 * t903 + 0.2e1 * t145 * t318 t923 = t71 * t424 t926 = t87 * t458 t927 = t28 * ZA t944 = 0.8e1 * t354 * t355 * t190 - 0.8e1 * t110 * t16 * t25 * t800 - 0.2e1 * t374 * t30 * t73 - 0.16e2 * t354 * t30 * t176 - 0.2e1 * t244 * t923 - 0.32e2 * t926 * t927 * t696 * t41 - 0.32e2 * t808 * t525 + 0.6e1 * t749 * t232 - 0.8e1 * t188 * t177 + 0.4e1 * t36 * t58 * ZA * t57 + 0.4e1 * t821 * t270 t948 = t90 * t327 t961 = t30 * t100 t964 = t29 * t49 t981 = t106 * t1 t983 = -0.2e1 * t219 * t220 * t100 + 0.2e1 * t321 * t948 - 0.16e2 * t189 * ZA * t99 * t12 - 0.2e1 * t369 * n * t69 * t368 + 0.2e1 * t374 * t795 - 0.8e1 * t462 * t961 - 0.8e1 * t244 * t964 * t208 + 0.2e1 * t413 * t923 + 0.4e1 * t36 * t38 * t40 * t58 - 0.2e1 * t87 * t51 * t49 * t1 * ZA + t888 * n * t762 + t115 * t981 t1012 = 0.6e1 * t616 * t627 - t82 * t213 + 0.2e1 * t775 * t657 - 0.12e2 * t215 * t550 - 0.6e1 * t145 * t131 + 0.2e1 * t81 * t41 * t204 + 0.6e1 * ZB * t48 * t49 * t370 - 0.4e1 * t70 * t382 + 0.2e1 * t446 * t255 + 0.8e1 * t89 * t4 * t327 - 0.4e1 * t56 * t147 t1018 = t212 * t100 t1029 = t212 * t327 t1040 = 0.6e1 * t70 * t245 + 0.2e1 * t56 * t328 + t207 * t668 + 0.4e1 * t503 * t1018 + 0.2e1 * t253 * t470 - 0.6e1 * t398 * t35 * t208 - 0.8e1 * t331 * t964 * t52 - 0.4e1 * t503 * t1029 + 0.6e1 * t821 * t745 + 0.4e1 * t63 * t37 * t142 + 0.16e2 * t260 * t38 * t840 t1068 = t207 * t347 - 0.2e1 * t164 * t702 - 0.2e1 * t331 * t964 * t73 + 0.8e1 * t374 * t30 * t52 + 0.16e2 * t278 * t903 + 0.2e1 * t863 * t923 + 0.6e1 * t445 * t141 * t165 - 0.2e1 * t164 * t90 * t100 + 0.6e1 * t331 * t74 - 0.2e1 * t182 * t668 - 0.2e1 * t115 * t41 * t204 t1079 = t58 * t8 t1091 = t807 * t29 t1092 = t665 * t40 t1101 = ZB * t91 t1102 = t403 * n t1105 = -0.4e1 * t58 * ZB * ZA * t64 - t82 * t850 + 0.2e1 * t821 * t860 + t81 * t51 * t793 + 0.2e1 * t3 * t25 * t1079 * t90 + t82 * t721 - 0.2e1 * t643 * t668 + 0.16e2 * t926 * t927 * t29 * t91 * t41 + 0.32e2 * t1091 * t1092 - 0.2e1 * t219 * t220 * t19 + 0.4e1 * t139 * ZA * t64 + 0.4e1 * t1101 * t1102 t1108 = t849 * t72 t1121 = t737 * t15 t1124 = t29 * t12 t1133 = t116 * t1108 - 0.8e1 * t475 * t209 - 0.32e2 * t807 * xc * t1092 + 0.2e1 * t278 * t269 * t73 + t82 * t812 - 0.6e1 * t56 * t131 + 0.2e1 * t253 * t1121 + 0.16e2 * t926 * t927 * t1124 * t41 + t168 * t263 - 0.2e1 * t616 * t827 + t81 * t981 t1134 = t394 * t28 t1159 = -0.8e1 * t1134 * t29 * t18 * t57 + t82 * t118 - 0.12e2 * t215 * t1018 + 0.2e1 * t602 * t801 - t168 * t341 + 0.2e1 * t67 * t58 * t64 + t168 * t344 - 0.6e1 * t174 * t368 * t208 + 0.16e2 * t553 * t903 + t116 * t790 - 0.4e1 * t36 * t38 * t800 * t15 t1161 = n * t83 t1173 = ZB * t12 t1196 = 0.4e1 * t1161 * ZB * t39 * ZA - 0.4e1 * t215 * t1029 - 0.8e1 * t488 * 0.3141592654e1 * t39 * xc + 0.32e2 * t821 * ZA * t8 * t1173 * t18 - 0.8e1 * t427 * t147 + 0.6e1 * t701 * t165 - 0.16e2 * t926 * t927 * t1124 * t18 - 0.8e1 * t1091 * t63 * t57 - 0.8e1 * t442 * t209 - 0.8e1 * t462 * t660 - 0.6e1 * t398 * t35 * t52 t1228 = 0.2e1 * t413 * t305 - 0.8e1 * t648 * t961 - 0.16e2 * t87 * t27 * t23 * t28 * ZA * t29 + 0.4e1 * t189 * t1102 - 0.4e1 * t87 * t1079 * t212 * t879 + 0.2e1 * t164 * t948 - 0.2e1 * t70 * t923 + 0.2e1 * t164 * t322 + 0.2e1 * t446 * t1121 + 0.2e1 * t863 * t964 * t304 - t82 * t1108 + 0.16e2 * t676 * t490 * t19 t1234 = t25 * ZB t1235 = t1234 * t28 t1236 = t365 * t91 t1240 = ZB * t121 t1241 = t1240 * t77 t1242 = t39 * t39 t1243 = t12 * t1242 t1244 = xc * t72 t1245 = t1243 * t1244 t1248 = t365 * t25 t1252 = t243 * n t1257 = t23 * t1 t1258 = t1240 * t1257 t1259 = t67 * t12 t1260 = xc * t16 t1268 = t1234 * t121 t1269 = t1268 * t23 t1272 = t1242 * t91 t1280 = t67 * xc t1284 = t28 * t28 t1285 = t67 * t1284 t1287 = t1285 * t2 * ZB t1288 = t17 * xc t1289 = t1243 * t1288 t1292 = 0.2e1 * t1235 * t1236 * t17 + 0.8e1 * t1241 * t1245 + 0.4e1 * t927 * t1248 * t91 - 0.2e1 * t1252 * ZB * t1242 * t91 - 0.8e1 * t1258 * t1259 * t1260 - 0.4e1 * t1235 * t2 * t83 * t39 + 0.16e2 * t1269 * t758 + 0.2e1 * t1252 * t189 * t1272 - 0.2e1 * t1252 * t83 * t1242 * ZB + 0.8e1 * t1258 * t630 * t1280 - 0.32e2 * t1287 * t1289 t1293 = t365 * t83 t1300 = ZA * t1284 t1304 = t17 * t1242 * t25 * t12 t1307 = t927 * t2 t1311 = t23 * t2 t1312 = t1300 * t1311 t1316 = t1234 * t1284 t1317 = t1316 * t1311 t1321 = t1240 * t23 t1331 = t1240 * t23 * t67 t1332 = t40 * t1244 t1338 = t1243 * t1260 t1344 = -0.2e1 * t1235 * t1293 - 0.16e2 * t181 * t365 * t901 * t12 - 0.64e2 * t1300 * t258 * t1304 + 0.8e1 * t1307 * t613 * t39 + 0.64e2 * t1312 * t265 * t402 - 0.32e2 * t1317 * t1288 * t12 - 0.16e2 * t1321 * t67 * t39 * t1244 + 0.2e1 * t1235 * n * t1272 * t17 + 0.16e2 * t1331 * t1332 + 0.64e2 * t1300 * t292 * t1304 - 0.8e1 * t1241 * t1338 - 0.2e1 * t243 * t1293 * ZB t1346 = t1316 * t2 t1349 = t927 * n t1350 = t25 * t1242 t1354 = t1268 * t1257 t1366 = t1268 * t1 t1370 = t29 * t17 t1371 = t1243 * t1370 t1386 = -0.32e2 * t1346 * t1289 + 0.4e1 * t1349 * t1350 * t91 + 0.8e1 * t1354 * t1260 * t12 - 0.16e2 * t181 * n * t901 * t1243 - 0.4e1 * t1235 * t2 * t91 * t39 + 0.8e1 * t1366 * t152 * t1242 + 0.32e2 * t1287 * t1371 + 0.8e1 * t1258 * t1280 * t152 - 0.8e1 * t1354 * t1260 * t91 + 0.128e3 * t1300 * t365 * xc * t1092 + 0.8e1 * t1366 * t1338 t1387 = t1257 * t12 t1391 = t1240 * t1 t1399 = t1272 * t1260 t1412 = t1285 * t1311 t1427 = -0.8e1 * t1268 * t1387 * t16 - 0.8e1 * t1391 * t67 * t1242 * t1244 - 0.4e1 * t1134 * t1101 * t39 + 0.8e1 * t1241 * t1399 - 0.8e1 * t1258 * t596 + 0.4e1 * t927 * t1293 * t25 - 0.16e2 * t1331 * t758 + 0.8e1 * t1307 * t665 * t39 + 0.32e2 * t1412 * t1370 * t1173 + 0.8e1 * t1307 * t665 * t800 + 0.8e1 * t1391 * t1259 * t1242 * t16 - 0.8e1 * t1391 * t1259 * t1242 * t72 t1456 = t365 * ZB t1468 = 0.4e1 * t927 * t1248 * t17 - 0.2e1 * t1235 * n * t1242 * t91 + 0.8e1 * t1366 * t1244 * t1242 - 0.16e2 * t1269 * t134 * t39 + 0.8e1 * t1268 * t1257 * t72 * xc + 0.16e2 * t1321 * t1259 * t757 + 0.32e2 * t1317 * t1370 * t12 + 0.4e1 * t1349 * t613 * t1242 + 0.2e1 * t243 * t1456 * t17 - 0.64e2 * t1285 * t365 * t12 * t189 * t490 - 0.8e1 * t1354 * t152 * xc t1472 = t1316 * t365 t1474 = t1124 * t39 * t17 t1478 = t17 * t91 t1504 = t72 * t39 t1511 = 0.4e1 * t1134 * t189 * t800 + 0.64e2 * t1472 * t1474 + 0.4e1 * t1235 * t2 * t1478 * t39 + 0.4e1 * t1349 * t665 * t1242 - 0.8e1 * t1258 * t1280 * t72 + 0.2e1 * t1252 * t189 * t1242 + 0.2e1 * t243 * t365 * t189 * t91 + 0.4e1 * t927 * t365 * t1478 * t25 - 0.128e3 * t1300 * t1248 * t1474 - 0.2e1 * t1235 * t1236 + 0.16e2 * t1269 * t1504 * xc + 0.2e1 * t1235 * t365 * t17 t1545 = -0.2e1 * t1235 * t1161 * t1242 + 0.4e1 * t1349 * t1350 * t1478 - 0.8e1 * t1366 * t1245 + 0.2e1 * t1235 * t556 * t1242 - 0.32e2 * t1412 * t402 * t726 - 0.8e1 * t1366 * t1399 + 0.8e1 * t1258 * t651 - 0.2e1 * t243 * t1456 * t91 + 0.8e1 * t1268 * t1387 * t72 - 0.16e2 * t1269 * t1332 + 0.4e1 * t1134 * t189 * t39 + 0.16e2 * t1269 * t152 * t39 t1564 = t1260 * t800 t1583 = 0.64e2 * t1285 * t1456 * t1474 - 0.64e2 * t1472 * t1288 * t40 - 0.8e1 * t1366 * t134 * t1242 + 0.8e1 * t1307 * t362 * t39 + 0.4e1 * t1235 * t2 * t17 * t39 + 0.32e2 * t1346 * t1371 - 0.16e2 * t1269 * t1564 - 0.16e2 * t1321 * t1259 * t1504 + 0.16e2 * t1331 * t1564 - 0.64e2 * t1312 * t29 * t25 * t402 - 0.4e1 * t1134 * t83 * t39 * ZB - 0.32e2 * t181 * t2 * t404 _C2B = ( t1133 + t1196 + t1068 + t811 + t466 + t1012 + t381 + t162 + t249 + t533 + t844 + t104 + t1159 + t571 + t211 + t874 + t607 + t339 + t296 + t638 + t908 + t671 + t419 + t983 + t705 + t1105 + t501 + t778 + t1040 + t1228 + t741 + t944 ) / (t1292 + t1344 + t1386 + t1427 + t1468 + t1511 + t1545 + t1583) #************************************************************************************** t1 = n * n t2 = t1 * n t3 = t2 * nx t4 = nx * 0.3141592654e1 t5 = t4 * xc t6 = sin(t5) t7 = 0.3141592654e1 * 0.3141592654e1 t9 = t3 * t6 * t7 t10 = xc * xc t11 = ZA * ZA t12 = t10 * t11 t13 = n * 0.3141592654e1 t14 = exp(t13) t15 = t14 * t14 t16 = xc * n t18 = exp(t16 * 0.3141592654e1) t19 = t18 * t18 t20 = t19 * t18 t21 = t15 * t20 t22 = t12 * t21 t25 = nx * t6 t26 = t1 * 0.3141592654e1 t27 = t25 * t26 t28 = ZA * ZB t29 = t18 * t15 t30 = t28 * t29 t33 = t25 * n t34 = t11 * t15 t35 = t19 * t19 t36 = t35 * t18 t40 = t25 * t1 t41 = 0.3141592654e1 * t11 t42 = t15 * t36 t43 = t41 * t42 t46 = nx * nx t47 = t1 * t46 t48 = t47 * t11 t49 = t7 * xc t50 = t35 * t15 t51 = t49 * t50 t55 = sin(t4) t56 = t46 * nx * t55 t58 = t56 * n * t7 t59 = ZB * ZB t60 = t10 * t59 t61 = t15 * t14 t62 = t19 * t61 t63 = t60 * t62 t66 = t19 * t14 t67 = t60 * t66 t70 = t28 * t42 t73 = cos(t5) t74 = t47 * t73 t75 = t7 * t11 t77 = t75 * t10 * t36 t80 = t73 * t46 t81 = t80 * n t82 = 0.3141592654e1 * t59 t83 = t82 * t42 t87 = xc * t11 t88 = t87 * t62 t91 = n * nx t92 = t55 * t61 t96 = nx * t55 t98 = t96 * t2 * t7 t101 = xc * t59 t102 = t101 * t62 t108 = t1 * t1 t109 = t108 * t7 t111 = t59 * t35 t112 = t111 * t15 t115 = t35 * t20 t123 = t1 * nx * t55 t124 = t61 * t35 t127 = t35 * t19 t128 = t61 * t127 t129 = t60 * t128 t132 = t56 * t16 t133 = t7 * t59 t134 = t133 * t124 t137 = 0.6e1 * t58 * t88 - 0.2e1 * t91 * t92 * t11 + 0.2e1 * t98 * t63 - 0.6e1 * t58 * t102 - 0.2e1 * t91 * t92 * t59 - 0.16e2 * t109 * xc * t112 - 0.2e1 * t91 * t6 * t115 * t59 + 0.12e2 * t40 * t83 + t123 * t41 * t124 - 0.2e1 * t58 * t129 + 0.4e1 * t132 * t134 t139 = t56 * 0.3141592654e1 t140 = t111 * t14 t144 = t49 * t124 t147 = t91 * t55 t148 = t61 * ZA t154 = ZA * t115 * xc * ZB t157 = t7 * 0.3141592654e1 t159 = t96 * t108 * t157 t160 = t10 * xc t161 = t160 * t59 t162 = t35 * t14 t163 = t161 * t162 t166 = t28 * t162 t169 = t80 * t13 t170 = t101 * t42 t173 = t2 * t11 t174 = t96 * t173 t175 = t7 * t10 t179 = t59 * t15 t184 = t15 * t15 t193 = t139 * t140 + 0.4e1 * t56 * n * t11 * t144 + 0.4e1 * t147 * t148 * ZB + 0.4e1 * t27 * t154 + 0.8e1 * t159 * t163 - 0.12e2 * t147 * t166 + 0.2e1 * t169 * t170 - 0.16e2 * t174 * t175 * t124 + 0.2e1 * t33 * t179 * t20 - 0.2e1 * t33 * t11 * t36 * t184 + 0.2e1 * t56 * t61 * 0.3141592654e1 * ZA * ZB t194 = t173 * 0.3141592654e1 t195 = xc * t15 t196 = t195 * t19 t202 = t15 * t115 t203 = t28 * t202 t206 = t96 * t26 t207 = t14 * t127 t208 = t101 * t207 t211 = t12 * t128 t218 = t11 * t61 t219 = t218 * t35 t221 = t108 * ZA t223 = t7 * ZB t224 = t223 * t50 t227 = ZA * xc t228 = ZB * t15 t229 = t228 * t36 t230 = t227 * t229 t233 = t87 * t207 t236 = t6 * t11 t240 = -0.4e1 * t194 * t196 + 0.4e1 * t194 * t195 * t127 + 0.4e1 * t33 * t203 - 0.12e2 * t206 * t208 + 0.2e1 * t58 * t211 - 0.16e2 * t47 * t10 * t133 * t50 + t139 * t219 - 0.32e2 * t221 * t10 * t224 - 0.4e1 * t169 * t230 - 0.6e1 * t98 * t233 + 0.2e1 * t91 * t236 * t20 t244 = t227 * t228 * t20 t252 = t184 * t18 t253 = t101 * t252 t256 = t35 * t35 t257 = t256 * t14 t258 = t28 * t257 t261 = t108 * t11 t263 = t7 * t35 t268 = ZB * t61 * t35 t273 = t96 * t108 * t160 t274 = t157 * ZB t276 = t274 * t148 * t35 t279 = t101 * t21 t282 = 0.3141592654e1 * xc t283 = t59 * t36 t284 = t282 * t283 t289 = 0.4e1 * t169 * t244 - 0.4e1 * t132 * t133 * t162 - 0.2e1 * t147 * t140 - 0.2e1 * t27 * t253 + 0.2e1 * t139 * t258 + 0.16e2 * t261 * t10 * t263 * t15 - 0.16e2 * t206 * t227 * t268 - 0.16e2 * t273 * t276 - 0.6e1 * t27 * t279 - 0.4e1 * t40 * t284 - 0.32e2 * t9 * t230 t290 = t1 * t11 t291 = t96 * t290 t297 = t59 * t61 t298 = t297 * t127 t300 = ZB * t36 t301 = t227 * t300 t304 = t1 * t59 t305 = t184 * t35 t310 = t46 * ZB t311 = t184 * ZA t312 = t310 * t311 t314 = t60 * t21 t317 = t1 * ZA t318 = ZB * t35 t321 = t1 * t256 t324 = t96 * t261 t325 = t10 * t157 t326 = t325 * t124 t329 = -0.4e1 * t291 * t282 * t128 + t123 * t82 * t62 - t139 * t298 + 0.12e2 * t27 * t301 + t304 * t305 - 0.2e1 * t58 * t12 * t66 - 0.2e1 * t312 + 0.8e1 * t9 * t314 + 0.2e1 * t317 * t318 + 0.2e1 * t321 * t28 - 0.8e1 * t324 * t326 t331 = t28 * t124 t334 = 0.3141592654e1 * t15 t335 = t334 * t127 t338 = t35 * ZA t341 = t46 * t256 t344 = t46 * t11 t346 = t46 * t59 t348 = t297 * t35 t351 = ZA * t10 t352 = t351 * t300 t355 = t1 * ZB t362 = 0.12e2 * t147 * t331 - 0.4e1 * t173 * t335 - 0.2e1 * t310 * t338 - 0.2e1 * t341 * t28 - t344 * t305 - t346 * t305 + 0.2e1 * t147 * t348 + 0.16e2 * t9 * t352 + 0.2e1 * t355 * t311 + t290 * t305 + 0.2e1 * t33 * t34 * t20 t363 = t36 * t184 t364 = t87 * t363 t368 = t47 * t73 * t7 t373 = t160 * t157 t374 = t373 * t124 t377 = t311 * t35 t380 = t12 * t62 t386 = ZB * t10 * ZA * t15 * t20 t389 = t87 * t66 t393 = t56 * t1 * t10 t401 = 0.2e1 * t27 * t364 - 0.16e2 * t368 * t279 - t123 * t41 * t257 + 0.8e1 * t324 * t374 + 0.2e1 * t355 * t377 - 0.2e1 * t98 * t380 - 0.16e2 * t9 * t386 + 0.2e1 * t58 * t389 + 0.16e2 * t393 * t276 + t123 * t82 * t162 - 0.2e1 * t33 * t179 * t36 t412 = t11 * t14 * t127 t416 = t11 * t19 t417 = t416 * t61 t421 = t96 * t2 * ZA t426 = t56 * n * ZA t427 = t318 * t14 t428 = t49 * t427 t431 = t82 * t29 t434 = t87 * t21 t442 = 0.2e1 * t33 * t11 * t184 * t18 + 0.4e1 * t81 * t284 - t139 * t412 + 0.2e1 * t147 * t219 - 0.2e1 * t147 * t417 + 0.32e2 * t421 * t175 * t268 + 0.8e1 * t426 * t428 + 0.4e1 * t81 * t431 - 0.2e1 * t169 * t434 - 0.2e1 * t98 * t129 - 0.32e2 * t47 * t28 * t51 t443 = t184 * t20 t447 = t61 * 0.3141592654e1 t448 = t447 * t11 t450 = t49 * t268 t453 = t60 * t42 t456 = t41 * t202 t463 = t101 * t443 t469 = t41 * xc * t20 t474 = -0.8e1 * t27 * t87 * t443 - t56 * t448 - 0.8e1 * t426 * t450 + 0.8e1 * t368 * t453 + 0.4e1 * t40 * t456 + 0.4e1 * t40 * t431 - 0.4e1 * t81 * t456 - 0.4e1 * t27 * t463 + 0.6e1 * t139 * t331 + 0.2e1 * t40 * t469 - 0.16e2 * t9 * t434 t482 = t108 * t10 t492 = n * t46 t493 = t492 * t11 t495 = t282 * t19 * t184 t498 = t56 * t290 t499 = t325 * t162 t502 = t416 * t14 t504 = t60 * t207 t507 = -t123 * t82 * t257 - 0.4e1 * t169 * t301 + t123 * t41 * t162 + 0.16e2 * t482 * t7 * t112 - 0.12e2 * t206 * t102 - t123 * t82 * t66 - 0.4e1 * t147 * t258 - 0.4e1 * t493 * t495 - 0.8e1 * t498 * t499 + t139 * t502 - 0.2e1 * t98 * t504 t508 = t101 * t162 t512 = t41 * t115 * xc t515 = t87 * t42 t520 = ZB * t184 t522 = t227 * t520 * t18 t525 = t492 * t59 t528 = t6 * t59 t532 = t520 * t20 t533 = t351 * t532 t539 = t447 * t59 t544 = 0.8e1 * t206 * t508 - 0.2e1 * t40 * t512 - 0.16e2 * t368 * t515 + 0.12e2 * t206 * t88 + 0.4e1 * t27 * t522 + 0.4e1 * t525 * t495 - 0.4e1 * t91 * t528 * t36 - 0.16e2 * t368 * t533 - 0.16e2 * t206 * t227 * t427 - t56 * t539 - 0.2e1 * t132 * t133 * t66 t551 = t87 * t162 t554 = t351 * t229 t560 = t59 * t19 t561 = t560 * t14 t564 = t101 * t202 t567 = t87 * t252 t573 = t227 * t228 * t115 t578 = 0.4e1 * t33 * t70 + 0.4e1 * t493 * t335 - 0.4e1 * t58 * t551 + 0.16e2 * t9 * t554 - 0.4e1 * t33 * t28 * t252 + 0.2e1 * t147 * t561 + 0.2e1 * t169 * t564 - 0.2e1 * t27 * t567 - 0.8e1 * t324 * t499 - 0.4e1 * t169 * t573 + 0.12e2 * t27 * t244 t579 = t82 * t202 t591 = t282 * t115 * t59 t598 = t101 * t66 t606 = -0.4e1 * t81 * t579 - 0.2e1 * t169 * t567 - 0.6e1 * t27 * t170 + 0.8e1 * t169 * t203 + 0.2e1 * t98 * t67 + 0.2e1 * t81 * t591 + 0.32e2 * t368 * t244 - 0.2e1 * t27 * t564 + 0.4e1 * t206 * t598 + 0.16e2 * t9 * t170 + 0.2e1 * t33 * t283 * t184 t608 = t373 * t162 t611 = t59 * t184 t617 = t101 * t29 t624 = t227 * ZB * t18 * t15 t629 = t157 * t59 t630 = t629 * t124 t633 = t3 * t6 t634 = t175 * t283 t644 = 0.8e1 * t498 * t608 + 0.2e1 * t33 * t611 * t18 - 0.4e1 * t206 * t389 - 0.2e1 * t27 * t617 - 0.4e1 * t169 * t154 + 0.4e1 * t27 * t624 + 0.12e2 * t27 * t230 - 0.8e1 * t393 * t630 - 0.8e1 * t633 * t634 + 0.16e2 * t47 * t7 * t101 * t50 + 0.2e1 * t123 * t447 * t28 t645 = t41 * t29 t648 = t2 * 0.3141592654e1 t649 = t648 * xc t650 = t560 * t184 t656 = t56 * t1 * t157 t659 = t87 * t128 t662 = t96 * t482 t663 = t629 * t162 t671 = t161 * t124 t674 = t218 * t127 t679 = 0.4e1 * t81 * t645 - 0.4e1 * t649 * t650 - 0.8e1 * t169 * t70 + 0.8e1 * t656 * t163 - 0.2e1 * t98 * t659 - 0.8e1 * t662 * t663 - 0.32e2 * t421 * t175 * t427 - 0.2e1 * t147 * t502 + 0.8e1 * t656 * t671 + 0.2e1 * t147 * t674 - 0.16e2 * t368 * t386 t714 = t334 * t19 t719 = t12 * t42 t722 = t304 * t35 - t346 * t35 + t341 * t59 - t344 * t35 + t344 * t256 + t346 * t184 - 0.16e2 * t368 * t554 - 0.16e2 * t48 * t175 * t50 + 0.4e1 * t525 * t714 - 0.2e1 * t58 * t659 + 0.8e1 * t368 * t719 t730 = xc * t19 t735 = t59 * t256 * t14 t752 = 0.4e1 * t173 * t714 - 0.6e1 * t27 * t515 - 0.16e2 * t9 * t279 + 0.4e1 * t194 * t730 * t184 - t139 * t735 - 0.4e1 * t492 * t127 * t82 * xc - 0.4e1 * t98 * t508 - t123 * t41 * t207 - 0.2e1 * t147 * t298 + 0.8e1 * t368 * t314 + 0.6e1 * t132 * t133 * t207 t755 = t28 * t21 t759 = t274 * t338 * t14 t767 = t11 * t35 t768 = t767 * t14 t778 = t560 * t61 t781 = -0.2e1 * t58 * t504 - 0.8e1 * t27 * t755 + 0.16e2 * t662 * t759 + 0.12e2 * t291 * t282 * t207 - 0.6e1 * t27 * t434 + t139 * t768 - 0.8e1 * t498 * t326 + 0.4e1 * t33 * t611 * t20 + 0.2e1 * t81 * t512 - t139 * t561 + 0.2e1 * t147 * t778 t786 = t12 * t443 t790 = t282 * t59 * t20 t796 = t59 * t14 * t127 t806 = t41 * t21 t811 = -0.8e1 * t393 * t663 + 0.8e1 * t368 * t786 + 0.2e1 * t81 * t790 + 0.4e1 * t169 * t624 + t139 * t796 + 0.2e1 * t206 * t258 - 0.2e1 * t40 * t591 - 0.8e1 * t662 * t630 - 0.4e1 * t33 * t30 - 0.4e1 * t40 * t806 + 0.8e1 * t9 * t786 t819 = t282 * t15 * t127 t822 = t101 * t363 t830 = t11 * t256 * t14 t835 = t227 * t532 t842 = 0.2e1 * t33 * t11 * t18 * t15 + t123 * t41 * t66 - 0.4e1 * t493 * t819 - 0.2e1 * t27 * t822 - 0.16e2 * t368 * t170 - 0.4e1 * t169 * t463 - t139 * t830 - 0.4e1 * t649 * t179 * t127 + 0.12e2 * t27 * t835 - 0.16e2 * t368 * t434 - 0.2e1 * t40 * t790 t845 = t87 * t202 t854 = t338 * t15 t859 = t12 * t207 t868 = t139 * t348 - 0.2e1 * t27 * t845 + 0.8e1 * t169 * t755 - 0.2e1 * t58 * t380 + 0.6e1 * t206 * t331 + 0.8e1 * t310 * t854 - 0.2e1 * t169 * t822 + 0.2e1 * t98 * t859 + 0.8e1 * t159 * t671 + 0.8e1 * t74 * t634 - 0.2e1 * t169 * t253 t880 = t60 * t443 t891 = t101 * t128 t894 = -t123 * t539 - 0.2e1 * t147 * t796 + 0.32e2 * t368 * t230 + t139 * t674 - 0.16e2 * t98 * t60 * t124 + 0.32e2 * t9 * t244 + 0.8e1 * t368 * t880 - 0.8e1 * t40 * t41 * xc * t36 - t123 * t82 * t128 - 0.6e1 * t58 * t233 + 0.2e1 * t58 * t891 t903 = t179 * t19 t920 = t56 * t1 * t160 t925 = -0.2e1 * t174 * t175 * t66 - 0.4e1 * t493 * t714 + 0.4e1 * t649 * t903 - 0.4e1 * t81 * t43 + t123 * t82 * t207 + 0.4e1 * t206 * t891 - 0.16e2 * t273 * t759 - 0.8e1 * t27 * t203 + 0.32e2 * t221 * ZB * t51 - 0.16e2 * t920 * t759 - 0.8e1 * t9 * t453 t932 = t87 * t29 t945 = t82 * t21 t953 = -0.16e2 * t920 * t276 - 0.8e1 * t169 * t30 - 0.8e1 * t633 * t77 - 0.2e1 * t27 * t932 - 0.4e1 * t174 * t49 * t162 + 0.8e1 * t206 * t87 * t124 - 0.2e1 * t147 * t768 + 0.4e1 * t169 * t522 - 0.12e2 * t81 * t945 + 0.4e1 * t33 * t28 * t115 + 0.4e1 * t525 * t819 t971 = t282 * t127 t978 = -0.6e1 * t98 * t102 + 0.2e1 * t169 * t515 - 0.2e1 * t310 * t377 + 0.2e1 * t147 * t830 + 0.8e1 * t368 * t22 - 0.2e1 * t169 * t617 + 0.16e2 * t662 * t276 - 0.8e1 * t355 * t854 + 0.4e1 * t493 * t971 - 0.16e2 * t9 * t533 - 0.2e1 * t169 * t279 t997 = xc * t127 t998 = t997 * t59 t1003 = 0.4e1 * t40 * t579 + 0.2e1 * t169 * t845 + 0.16e2 * t9 * t515 + 0.8e1 * t206 * t551 + t123 * t41 * t128 + 0.16e2 * t98 * t60 * t162 + 0.2e1 * t169 * t364 - 0.2e1 * t169 * t932 + t139 * t778 + 0.4e1 * t648 * t998 + 0.2e1 * t147 * t412 t1006 = t2 * t59 t1017 = xc * t35 t1033 = 0.4e1 * t1006 * t335 + 0.4e1 * t81 * t806 - 0.2e1 * t33 * t34 * t115 + 0.8e1 * t498 * t374 - 0.16e2 * t261 * t7 * t1017 * t15 + 0.8e1 * t206 * t101 * t124 - t123 * t448 + 0.2e1 * t147 * t735 + 0.6e1 * t98 * t208 + 0.6e1 * t98 * t88 - 0.4e1 * t33 * t755 t1055 = -0.4e1 * t173 * t971 + 0.2e1 * t98 * t891 + 0.8e1 * t9 * t880 + 0.4e1 * t169 * t835 - t304 * t184 + t344 * t184 - t123 * t41 * t62 - 0.2e1 * t98 * t598 + 0.2e1 * t58 * t859 + 0.32e2 * t47 * t351 * t224 + 0.2e1 * t98 * t389 t1070 = t15 * t19 t1089 = -0.16e2 * t368 * t352 - 0.8e1 * t9 * t719 + 0.4e1 * t96 * t2 * xc * t134 - 0.2e1 * t91 * t236 * t115 + 0.4e1 * t27 * t573 + 0.4e1 * t493 * t282 * t1070 + 0.2e1 * t33 * t59 * t18 * t15 + 0.12e2 * t40 * t945 - 0.4e1 * t492 * xc * t82 * t1070 - 0.2e1 * t91 * t528 * t20 + 0.8e1 * t324 * t608 t1113 = t123 * t82 * t124 + 0.8e1 * t421 * t428 - t139 * t417 + 0.4e1 * t40 * t645 + 0.16e2 * t393 * t759 - 0.2e1 * t33 * t179 * t115 - 0.4e1 * t525 * t335 + 0.4e1 * t33 * t28 * t36 - 0.4e1 * t1006 * t714 + 0.6e1 * t206 * t166 - 0.8e1 * t421 * t450 t1119 = t321 * t46 t1122 = t157 * t11 t1123 = t1122 * t2 t1124 = t184 * t46 t1128 = t108 * n t1132 = t7 * t7 t1133 = t1132 * t11 t1134 = t1133 * t108 t1135 = t15 * t46 t1139 = t7 * ZA t1140 = t1139 * ZB t1141 = t1 * t35 t1145 = t629 * t2 t1146 = t1135 * t730 t1149 = t157 * t1128 t1150 = t1149 * xc t1153 = t46 * xc t1154 = t1153 * t127 t1158 = t184 * t1 * t46 t1161 = t46 * t46 t1162 = t35 * t1161 t1166 = t7 * t1 t1170 = -0.4e1 * t133 * t1119 + 0.16e2 * t1123 * t1124 * t730 - 0.8e1 * t1122 * t1128 * t196 - 0.64e2 * t1134 * t1135 * t1017 - 0.32e2 * t1140 * t1141 * t1135 + 0.16e2 * t1145 * t1146 - 0.8e1 * t1150 * t650 - 0.16e2 * t1123 * t1154 - 0.4e1 * t133 * t1158 - 0.16e2 * t1140 * t1162 * t15 + 0.8e1 * t1166 * t35 * t312 t1171 = t1161 * t184 t1175 = t1122 * n t1176 = t15 * t1161 t1180 = t1132 * ZA t1181 = t1180 * t355 t1182 = t1176 * t1017 t1185 = t1161 * xc t1189 = t1133 * t1 t1192 = t108 * t1 t1193 = t1132 * t1192 t1195 = t10 * t35 t1199 = t157 * t15 t1203 = t1141 * t46 t1211 = t184 * t108 t1218 = 0.2e1 * t133 * t1171 * t35 + 0.8e1 * t1175 * t1176 * t997 + 0.64e2 * t1181 * t1182 - 0.8e1 * t1175 * t1185 * t127 - 0.32e2 * t1189 * t1182 - 0.64e2 * t1193 * ZA * t1195 * t228 + 0.8e1 * t1199 * t416 * t1128 + 0.8e1 * t1140 * t1203 - 0.4e1 * t75 * t1158 - 0.8e1 * t1199 * t560 * t1128 - 0.2e1 * t133 * t1211 - 0.8e1 * t1199 * t127 * t11 * t1128 t1221 = t256 * t1161 t1224 = t35 * t108 t1233 = t7 * t256 t1236 = -t75 * t1211 - t75 * t1221 - t133 * t1221 + t75 * t1224 - t75 * t1171 - t133 * t1171 + t133 * t1224 + t75 * t1162 - t75 * t108 * t256 + t133 * t1162 - t1233 * t59 * t108 t1240 = t1135 * t1195 t1252 = t629 * t127 t1263 = t1171 * ZA t1280 = -0.128e3 * t1180 * ZB * t108 * t1240 + 0.32e2 * t1193 * t10 * t112 + 0.4e1 * t133 * t1203 + 0.4e1 * t109 * t256 * ZA * ZB - 0.8e1 * t1252 * n * t15 * t1185 + 0.8e1 * t1175 * t1171 * t730 - 0.8e1 * t1175 * t1176 * t127 + 0.4e1 * t223 * t1263 - 0.8e1 * t1175 * t1176 * t730 + 0.8e1 * t1166 * ZA * t341 * ZB + 0.64e2 * t1134 * t1240 + 0.8e1 * t1122 * xc * t1128 * t127 * t15 t1283 = t1199 * t19 t1287 = t1199 * t127 t1289 = t59 * n * t1161 t1293 = t157 * n * xc t1304 = t1132 * t108 t1310 = t263 * ZB t1316 = t2 * t15 t1323 = -0.16e2 * t1283 * t1006 * t46 + 0.8e1 * t1287 * t1289 + 0.8e1 * t1293 * t127 * t1161 * t59 + 0.16e2 * t1123 * t1135 * t19 + 0.8e1 * t1293 * t560 * t1176 + 0.64e2 * t1304 * t59 * t1240 + 0.4e1 * t75 * t1203 + 0.4e1 * t1310 * t1263 + 0.4e1 * t223 * t338 * t108 - 0.16e2 * t1252 * t1316 * t1153 - 0.16e2 * t1310 * t221 * t15 t1330 = t1132 * t15 t1336 = t1132 * t1 t1338 = t1162 * t179 t1370 = 0.8e1 * t1175 * t1176 * t19 + 0.4e1 * t1139 * t318 * t1161 + 0.128e3 * t1330 * t318 * t108 * t46 * t227 - 0.32e2 * t1336 * xc * t1338 + 0.4e1 * t1233 * ZA * t1161 * ZB - 0.8e1 * t1287 * t59 * t1128 * xc + 0.2e1 * t75 * t305 * t108 + 0.8e1 * t1199 * t127 * t59 * t1128 - 0.8e1 * t1283 * t1289 - 0.8e1 * t1293 * t560 * t1171 + 0.4e1 * t133 * t35 * t1158 + 0.8e1 * t157 * t184 * t19 * t11 * t1128 * xc t1376 = t7 * t184 t1380 = t1176 * t1195 t1393 = t1330 * t35 t1411 = 0.16e2 * t1145 * t1154 + 0.8e1 * t1149 * t998 + 0.4e1 * t1376 * t35 * t48 + 0.32e2 * t1189 * t1380 + 0.32e2 * t1193 * t11 * t1195 * t15 - 0.64e2 * t1304 * xc * t111 * t1135 - 0.16e2 * t1123 * t1146 + 0.64e2 * t1393 * t28 * t1192 * xc - 0.16e2 * t1123 * t1135 * t127 - 0.8e1 * t1122 * xc * t1128 * t127 - 0.32e2 * t1193 * xc * t112 + 0.16e2 * t1252 * t1316 * t46 t1450 = 0.2e1 * t1376 * t767 * t1161 + 0.2e1 * t1376 * t111 * t108 + 0.4e1 * t223 * t311 * t108 + 0.4e1 * t109 * t35 * t520 * ZA + 0.16e2 * t1123 * t1135 * t997 - 0.64e2 * t1181 * t1380 + 0.8e1 * t1150 * t903 - 0.32e2 * t1393 * t11 * t1192 * xc - 0.16e2 * t157 * t2 * xc * t560 * t1124 + 0.8e1 * t223 * t184 * t317 * t46 + 0.32e2 * t1336 * t10 * t1338 - 0.4e1 * t75 * t1119 _C3B = ( t606 + t722 + t1089 + t781 + 0.16e2 * t48 * t51 + t978 + t868 + t507 - t304 * t256 + 0.8e1 * t9 * t22 + t752 + 0.4e1 * t174 * t144 - 0.2e1 * t81 * t469 + 0.6e1 * t139 * t166 + t362 + 0.2e1 * t98 * t211 + t925 + t137 - t290 * t184 + 0.12e2 * t81 * t83 + t842 + 0.8e1 * t74 * t77 + 0.16e2 * t98 * t12 * t162 - 0.4e1 * t33 * t28 * t443 - 0.8e1 * t27 * t70 - 0.2e1 * t33 * t34 * t36 - 0.8e1 * t27 * t30 + 0.2e1 * t58 * t67 - 0.4e1 * t40 * t43 + 0.2e1 * t58 * t63 + t1033 - t290 * t256 + t290 * t35 + t193 + t1113 + t578 + t442 + t474 + t544 + t329 + t679 + t401 + t953 + t811 + t644 + t894 + t289 + t240 + t1055 + t1003 ) / (t1170 + t1218 + 0.2e1 * t1236 + t1280 + t1323 + t1370 + t1411 + t1450) t1 = n * n t2 = t1 * xc t3 = ZB * ZB t5 = t2 * 0.3141592654e1 * t3 t6 = nx * 0.3141592654e1 t7 = t6 * xc t8 = cos(t7) t9 = nx * nx t10 = t8 * t9 t11 = n * 0.3141592654e1 t12 = exp(t11) t13 = t12 * t12 t16 = exp(xc * n * 0.3141592654e1) t17 = t16 * t16 t18 = t17 * t16 t19 = t17 * t17 t20 = t19 * t18 t21 = t13 * t20 t22 = t10 * t21 t25 = ZA * ZA t26 = t1 * t25 t27 = xc * 0.3141592654e1 t28 = t26 * t27 t29 = t19 * t16 t30 = t13 * t13 t31 = t29 * t30 t35 = t9 * nx t36 = t3 * t35 t37 = sin(t6) t38 = t13 * t12 t39 = t37 * t38 t40 = t39 * t19 t42 = t1 * t1 t43 = nx * t42 t44 = xc * xc t45 = t25 * t44 t46 = t43 * t45 t47 = 0.3141592654e1 * 0.3141592654e1 t48 = t47 * t37 t49 = t17 * t38 t54 = 0.3141592654e1 * t35 t55 = ZA * n * t54 t56 = t37 * ZB t57 = t19 * t12 t61 = t25 * t8 t62 = t61 * t9 t63 = n * t30 t64 = t63 * t16 t67 = t1 * n t69 = t47 * ZB t70 = t67 * t44 * t69 t75 = nx * t3 t76 = t75 * t37 t77 = t67 * 0.3141592654e1 t78 = t19 * t19 t79 = t78 * t12 t80 = t77 * t79 t82 = t3 * t38 t84 = t54 * t37 t87 = sin(t7) t88 = t29 * t87 t89 = t47 * t44 t93 = nx * t25 t94 = t87 * t42 t95 = t93 * t94 t96 = t47 * xc t97 = t13 * t29 t98 = t96 * t97 t101 = t87 * t67 t102 = t93 * t101 t103 = t13 * t18 t107 = t47 * t35 t108 = t26 * t107 t109 = t37 * t44 t110 = t19 * t17 t111 = t12 * t110 t116 = t37 * t19 * t12 t118 = t37 * xc t119 = ZB * t19 t120 = t119 * t12 t121 = t118 * t120 t125 = xc * t3 t126 = t1 * t47 * t125 t127 = t35 * t37 t128 = t38 * t19 t129 = t127 * t128 t132 = t26 * 0.3141592654e1 t133 = t16 * t13 t134 = t10 * t133 t137 = 0.3141592654e1 * ZB t138 = t2 * t137 t139 = ZA * t8 t140 = t9 * t13 t145 = t30 * t18 t146 = t10 * t145 t149 = t3 * t8 t150 = t149 * t9 t153 = 0.2e1 * t5 * t22 + 0.2e1 * t28 * t10 * t31 + t36 * t40 - 0.2e1 * t46 * t48 * t49 - 0.2e1 * t55 * t56 * t57 - 0.2e1 * t62 * t64 + 0.16e2 * t70 * t29 * ZA * t10 - t76 * t80 + t82 * n * t84 + 0.8e1 * t43 * t3 * t88 * t89 + 0.16e2 * t95 * t98 + 0.2e1 * t102 * t27 * t103 - 0.2e1 * t108 * t109 * t111 + t36 * t116 + 0.8e1 * t55 * t121 - 0.4e1 * t126 * t129 - 0.4e1 * t132 * t134 - 0.4e1 * t138 * t139 * t140 * t20 + 0.8e1 * t28 * t146 - 0.2e1 * t150 * t64 t154 = t42 * n t155 = nx * t154 t156 = t44 * xc t157 = t47 * 0.3141592654e1 t158 = t156 * t157 t159 = t155 * t158 t162 = t56 * ZA * t19 * t12 t165 = t77 * t49 t167 = t1 * t3 t168 = t167 * t89 t169 = t127 * t49 t172 = t37 * t67 t173 = t75 * t172 t174 = t38 * t110 t175 = t27 * t174 t179 = t47 * t25 t181 = t10 * t97 t184 = t27 * t31 t187 = t67 * t47 t188 = t44 * t3 t189 = t187 * t188 t192 = t25 * t35 t193 = t37 * t17 t194 = t193 * t12 t196 = nx * ZA t197 = t196 * t172 t198 = ZB * t38 t199 = t198 * t19 t204 = t1 * t12 * t110 t207 = nx * ZB t209 = t1 * ZA t215 = t67 * t3 t216 = t47 * t8 t217 = t215 * t216 t218 = t9 * xc t222 = nx * t67 t223 = t222 * t27 t224 = t3 * t87 t228 = t167 * t107 t232 = t26 * t96 t235 = t207 * t94 t236 = t47 * ZA t243 = xc * t13 t244 = t243 * t29 t248 = t25 * n t249 = t248 * 0.3141592654e1 t253 = ZB * ZA t254 = t253 * t8 t255 = t9 * n t256 = t30 * t16 t260 = 0.2e1 * t207 * t37 * t209 * t128 + 0.2e1 * t5 * t134 - 0.16e2 * t217 * t218 * t97 - 0.2e1 * t223 * t224 * t31 - 0.2e1 * t228 * t109 * t174 - 0.2e1 * t232 * t169 - 0.16e2 * t235 * t236 * t44 * t30 * t18 - 0.4e1 * t196 * t101 * t137 * t244 + t249 * t169 + 0.8e1 * t168 * t129 + 0.4e1 * t254 * t255 * t256 t263 = t43 * t179 t267 = t3 * n t268 = t267 * t54 t269 = t118 * t57 t272 = t39 * t1 t274 = t67 * t25 t275 = t274 * t158 t278 = t75 * t87 t279 = t77 * t103 t282 = t25 * t38 t285 = ZA * t38 t290 = t267 * 0.3141592654e1 t296 = t77 * t111 t298 = t196 * t37 t299 = t1 * ZB t303 = t37 * t42 t304 = t196 * t303 t308 = t77 * t57 t310 = t26 * t89 t313 = t77 * t128 t316 = t101 * t27 t319 = t93 * t87 t320 = t77 * t97 t323 = t127 * t57 t326 = t10 * n t329 = t118 * t174 t332 = -0.8e1 * t263 * t109 * t57 - 0.4e1 * t268 * t269 + t93 * t272 + 0.8e1 * t275 * t129 - 0.4e1 * t278 * t279 + t282 * n * t84 - 0.2e1 * t285 * n * t54 * t56 - t290 * t169 - 0.2e1 * t196 * t38 * t172 * t137 + t76 * t296 - 0.2e1 * t298 * t299 * t79 + 0.8e1 * t304 * t96 * t120 + t76 * t308 - 0.2e1 * t310 * t169 - t76 * t313 + 0.2e1 * t75 * t18 * t316 + 0.4e1 * t319 * t320 + t249 * t323 - 0.2e1 * t25 * t18 * t326 + 0.2e1 * t228 * t329 t335 = t75 * t101 t336 = t27 * t21 t342 = t77 * t133 t347 = t209 * t137 t350 = t9 * t1 t351 = t149 * t350 t355 = t37 * t78 * t12 t359 = t93 * t303 t367 = t172 * 0.3141592654e1 t369 = t96 * t103 t376 = t209 * t107 t379 = t10 * t103 t383 = t207 * t101 t389 = 0.3141592654e1 * ZA t390 = t222 * t389 t391 = t87 * ZB t398 = -0.2e1 * t102 * t336 + t93 * t38 * t367 + 0.16e2 * t95 * t369 - t82 * t127 - 0.8e1 * t197 * t27 * t120 + 0.8e1 * t376 * t121 - 0.8e1 * t189 * t379 - t249 * t129 - 0.4e1 * t383 * t27 * ZA * t16 * t13 - 0.8e1 * t390 * t391 * t21 - 0.2e1 * t197 * t137 * t57 t402 = t39 * t110 t404 = t193 * t38 t406 = t127 * t174 t408 = t167 * 0.3141592654e1 t411 = t44 * t157 t412 = t155 * t411 t413 = t285 * t19 t414 = t56 * t413 t417 = ZA * t30 t424 = t93 * t37 t426 = t248 * t54 t427 = t17 * t12 t428 = t118 * t427 t431 = t77 * t21 t438 = ZA * t13 t443 = t93 * t172 t444 = t27 * t427 t448 = t1 * t78 * t12 t455 = t274 * t89 t461 = t118 * t111 t464 = -t36 * t402 + t36 * t404 - t249 * t406 - 0.4e1 * t408 * t134 + 0.16e2 * t412 * t414 - 0.4e1 * t383 * t27 * t417 * t18 + 0.2e1 * t28 * t22 - t424 * t80 - 0.2e1 * t426 * t428 + 0.4e1 * t278 * t431 + 0.4e1 * t254 * t255 * t103 + t290 * t323 + 0.4e1 * t383 * t27 * t438 * t20 + 0.2e1 * t443 * t444 + t424 * t448 - t36 * t194 - 0.32e2 * t235 * t236 * t243 * t18 + 0.8e1 * t455 * t181 - 0.4e1 * t359 * t96 * t128 - 0.2e1 * t426 * t461 t469 = n * t16 * t13 t474 = t1 * t38 t475 = t474 * t19 t480 = t89 * t103 t483 = t67 * ZA t484 = t483 * t411 t485 = t127 * t120 t488 = t127 * t111 t497 = t77 * t427 t502 = t27 * t97 t508 = t1 * t19 * t12 t511 = t155 * t25 * t156 t512 = t157 * t37 t513 = t512 * t128 t527 = t1 * t17 t528 = t527 * t38 t530 = -t76 * t497 - 0.4e1 * t254 * t255 * t97 - 0.2e1 * t102 * t502 - 0.4e1 * t108 * t269 - t76 * t508 + 0.8e1 * t511 * t513 + 0.4e1 * t150 * t63 * t18 + 0.4e1 * t383 * t27 * t438 * t18 + 0.4e1 * t132 * t379 + 0.2e1 * t168 * t488 - t76 * t528 t535 = t44 * t13 t542 = t527 * t12 t544 = n * t13 t545 = t544 * t20 t548 = t75 * t303 t549 = t96 * t111 t552 = ZA * t35 t553 = t552 * t37 t562 = t43 * t96 t563 = t3 * t37 t564 = t563 * t128 t579 = t474 * t110 t590 = t9 * t30 t591 = t590 * t18 t595 = t127 * t427 t598 = t77 * t174 t600 = 0.4e1 * t5 * t146 + 0.16e2 * t235 * t236 * t535 * t18 + 0.8e1 * t455 * t146 + t76 * t542 - 0.2e1 * t150 * t545 + 0.2e1 * t548 * t549 - 0.2e1 * t553 * t120 + t290 * t488 - 0.8e1 * t274 * t47 * t44 * t29 * t10 - 0.4e1 * t562 * t564 - 0.2e1 * t132 * xc * t20 * t10 - 0.32e2 * t562 * ZA * t87 * ZB * t13 * t29 - 0.8e1 * t347 * t379 + t76 * t579 - 0.4e1 * t359 * t96 * t57 + 0.4e1 * t408 * t181 - 0.4e1 * t223 * t564 - 0.12e2 * t209 * t27 * ZB * t8 * t591 + 0.2e1 * t310 * t595 + t76 * t598 t601 = t27 * t49 t604 = t127 * t79 t606 = ZB * t29 t616 = t139 * t140 * t18 t638 = t10 * t256 t643 = t118 * t199 t653 = t544 * t29 t658 = t3 * t29 t660 = t350 * t27 t663 = -0.4e1 * t254 * t255 * t145 + 0.2e1 * t267 * t20 * t8 * t9 - 0.4e1 * t138 * t139 * t9 * t16 * t13 - 0.2e1 * t5 * t638 + 0.2e1 * t126 * t169 + 0.8e1 * t376 * t643 + 0.4e1 * t335 * t27 * t145 + 0.16e2 * t235 * t236 * t535 * t29 + 0.6e1 * t150 * t653 - 0.4e1 * t426 * t269 + 0.4e1 * t658 * t8 * t660 t670 = t274 * t411 t673 = t118 * t49 t694 = t155 * t45 t713 = n * t29 * t30 t717 = t20 * t87 t723 = t512 * t57 t728 = -0.2e1 * t443 * t175 - 0.8e1 * t670 * t129 + 0.2e1 * t426 * t673 - 0.16e2 * t207 * t88 * t42 * t47 * ZA * t44 + 0.4e1 * t254 * t255 * t21 + t249 * t595 + 0.8e1 * t25 * t29 * t8 * t660 + 0.2e1 * t268 * t461 + 0.8e1 * t189 * t181 - 0.8e1 * t694 * t513 + 0.2e1 * t198 * t553 - 0.12e2 * t606 * t139 * t660 - 0.2e1 * t359 * t549 + 0.4e1 * t138 * t139 * t590 * t16 + 0.8e1 * t93 * t29 * t94 * t89 - 0.2e1 * t150 * t713 + 0.2e1 * t222 * t3 * t717 * t27 + 0.8e1 * t670 * t323 + 0.8e1 * t694 * t723 - 0.2e1 * t62 * t653 t734 = t43 * t89 t735 = t563 * t427 t740 = t75 * t94 t744 = ZB * xc t750 = t563 * t57 t754 = t218 * t103 t771 = t127 * t199 t776 = t89 * t174 t791 = -0.4e1 * t207 * t717 * t77 * xc * ZA + 0.4e1 * t443 * t27 * t57 + t192 * t40 - 0.8e1 * t55 * t643 - 0.16e2 * t209 * t89 * t771 - 0.8e1 * t275 * t323 + 0.2e1 * t359 * t776 + 0.16e2 * t304 * t89 * t199 + 0.4e1 * t278 * t320 + 0.2e1 * t207 * t172 * t389 * t79 - 0.8e1 * t390 * t391 * t97 t794 = t483 * t158 t801 = t2 * 0.3141592654e1 t818 = t215 * t411 t827 = t96 * t174 t837 = t37 * t12 * t110 t845 = 0.16e2 * t794 * t485 + 0.8e1 * t159 * t564 - 0.8e1 * t455 * t379 - 0.2e1 * t801 * t3 * t20 * t10 - 0.4e1 * t132 * t22 - 0.8e1 * t734 * t564 - 0.8e1 * t187 * t44 * t658 * t10 - 0.8e1 * t412 * t564 + 0.4e1 * t132 * t181 - 0.8e1 * t818 * t129 + 0.2e1 * t46 * t48 * t427 - 0.4e1 * t75 * t29 * t316 - 0.2e1 * t359 * t827 - t290 * t595 + 0.16e2 * t217 * t754 - t424 * t542 - 0.8e1 * t734 * t750 - t192 * t837 - 0.4e1 * t254 * t255 * t133 + 0.8e1 * t304 * t96 * t199 t864 = t544 * t18 t867 = t3 * t18 t884 = t27 * t256 t891 = t187 * t744 t894 = t563 * t49 t900 = -0.2e1 * t263 * t428 + 0.2e1 * t228 * t428 - 0.6e1 * t223 * t224 * t103 - t192 * t404 + 0.2e1 * t268 * t428 - 0.2e1 * t335 * t884 - t424 * t296 + 0.2e1 * t93 * t20 * t316 - 0.32e2 * t891 * t616 + 0.2e1 * t562 * t894 - 0.2e1 * t801 * t867 * t10 t904 = t27 * t111 t907 = t118 * t128 t915 = t89 * t145 t947 = t139 * t140 * t29 t952 = -0.2e1 * t173 * t904 + 0.4e1 * t426 * t907 + 0.12e2 * t253 * t10 * t1 * 0.3141592654e1 * t244 + 0.8e1 * t95 * t915 - t36 * t355 - 0.16e2 * t794 * t771 - 0.8e1 * t511 * t723 + 0.16e2 * t734 * t162 + t36 * t837 + 0.2e1 * t298 * t299 * t57 - 0.2e1 * t28 * t638 - 0.2e1 * t62 * t545 + 0.2e1 * t310 * t406 + 0.12e2 * t138 * t616 + 0.4e1 * t223 * t750 + t424 * t497 + 0.2e1 * t734 * t894 + 0.2e1 * t132 * xc * t18 * t10 - 0.16e2 * t70 * t947 + 0.32e2 * t891 * t947 t969 = t67 * t157 * t156 * t3 t974 = t27 * t133 t1001 = -0.8e1 * t159 * t750 - 0.16e2 * t412 * t162 - t290 * t129 + 0.8e1 * t310 * t323 - 0.4e1 * t319 * t342 + t75 * t272 + t192 * t402 - 0.8e1 * t359 * t89 * t128 - 0.10e2 * t61 * t350 * t502 + 0.8e1 * t818 * t323 - 0.4e1 * t108 * t907 t1042 = t89 * t97 t1055 = -0.2e1 * t168 * t595 + 0.16e2 * t484 * t771 + 0.4e1 * t11 * t125 * t129 - 0.2e1 * t173 * t444 + 0.2e1 * ZB * n * t54 * t37 * ZA * t79 - t424 * t475 + 0.2e1 * t562 * t735 - 0.2e1 * t548 * t776 + t424 * t204 + 0.2e1 * t25 * t20 * t326 + 0.8e1 * t383 * t389 * t133 + t75 * t38 * t367 + 0.2e1 * t62 * t469 + 0.2e1 * t197 * t137 * t128 - 0.2e1 * t102 * t884 - 0.2e1 * t5 * t379 - 0.8e1 * t740 * t1042 - 0.16e2 * t159 * t414 - 0.2e1 * ZB * t35 * t37 * t413 + 0.2e1 * t553 * ZB * t78 * t12 t1096 = 0.2e1 * t443 * t904 - 0.2e1 * t268 * t329 - 0.2e1 * t443 * t601 + 0.2e1 * t102 * t974 - 0.2e1 * t263 * t673 + t424 * t165 + 0.2e1 * t62 * t713 + t424 * t308 - t424 * t313 + 0.8e1 * t347 * t22 - t424 * t598 t1103 = t42 * t1 * t157 t1104 = t1103 * t25 t1108 = t3 * t19 t1112 = n * t47 t1113 = t9 * t9 t1118 = t42 * t157 t1119 = t1118 * t9 t1120 = t25 * xc t1121 = t13 * t110 t1122 = t1120 * t1121 t1125 = t47 * t47 t1126 = t67 * t1125 t1127 = t1113 * ZA t1128 = t1126 * t1127 t1129 = t19 * t13 t1130 = t744 * t1129 t1133 = t154 * t1125 t1134 = t1133 * t9 t1135 = t45 * t1129 t1138 = t154 * t47 t1139 = t25 * t30 t1142 = t1126 * t1113 t1145 = t125 * t1129 t1148 = t1103 * xc t1149 = t3 * t13 t1150 = t1149 * t17 t1153 = t25 * t78 t1156 = -0.8e1 * t1104 * t243 * t17 + 0.4e1 * t187 * t1108 * t9 - 0.2e1 * t1112 * t3 * t1113 * t30 + 0.16e2 * t1119 * t1122 + 0.64e2 * t1128 * t1130 + 0.64e2 * t1134 * t1135 - 0.2e1 * t1138 * t1139 + 0.32e2 * t1142 * t1135 - 0.32e2 * t1142 * t1145 + 0.8e1 * t1148 * t1150 - 0.2e1 * t1138 * t1153 t1157 = t25 * t13 t1158 = t1157 * t17 t1161 = t13 * t17 t1162 = t1120 * t1161 t1165 = t3 * t78 t1170 = t42 * t67 * t1125 t1172 = t1108 * t13 t1175 = t1 * t157 t1176 = t1175 * t1113 t1182 = t1120 * t1129 t1189 = t110 * t9 * xc t1192 = t1149 * t110 t1201 = 0.8e1 * t1103 * t1158 - 0.16e2 * t1119 * t1162 - 0.2e1 * t1112 * t1165 * t1113 + 0.32e2 * t1170 * t44 * t1172 - 0.8e1 * t1176 * t1162 + 0.8e1 * t1104 * t243 * t110 - 0.64e2 * t1134 * t1182 - 0.64e2 * t1134 * t1145 + 0.16e2 * t1118 * t3 * t1189 + 0.16e2 * t1119 * t1192 - 0.4e1 * t187 * t1165 * t9 - 0.4e1 * t187 * t1139 * t9 t1209 = t17 * t30 t1210 = t125 * t1209 t1213 = t1138 * ZA t1214 = ZB * t30 t1218 = t1157 * t110 t1226 = t3 * t30 t1237 = t1170 * t25 t1242 = 0.4e1 * t1112 * ZA * t119 * t1113 - 0.16e2 * t1119 * t1150 - 0.8e1 * t1176 * t1210 + 0.4e1 * t1213 * t1214 * t19 - 0.16e2 * t1119 * t1218 - 0.32e2 * t1142 * t1182 - 0.8e1 * t1103 * t1120 * t110 - 0.4e1 * t187 * t1226 * t9 + 0.8e1 * t1103 * t1192 + 0.4e1 * t1112 * ZB * t1113 * t30 * ZA - 0.32e2 * t1237 * xc * t19 * t13 t1251 = t125 * t1121 t1260 = t1120 * t1209 t1263 = t1139 * t19 t1282 = 0.8e1 * t1103 * t110 * t3 * xc + 0.8e1 * t1104 * xc * t17 * t30 - 0.8e1 * t1176 * t1251 + 0.16e2 * t1119 * t1158 + 0.4e1 * t1112 * t78 * t1127 * ZB + 0.16e2 * t1119 * t1260 + 0.2e1 * t1138 * t1263 - 0.32e2 * t1170 * xc * t1172 - 0.16e2 * t1213 * t119 * t13 + 0.4e1 * t1138 * t1214 * ZA + 0.32e2 * t1237 * t44 * t19 * t13 - 0.16e2 * t1118 * t25 * t1189 t1287 = t188 * t1129 t1292 = t25 * t19 t1296 = t187 * t9 t1297 = t1226 * t19 t1311 = t1112 * t1113 t1317 = -0.8e1 * t1176 * t1150 + 0.32e2 * t1142 * t1287 - 0.8e1 * t1103 * t1150 + 0.2e1 * t1112 * t1292 * t1113 + 0.4e1 * t1296 * t1297 + 0.8e1 * t1176 * t1192 + 0.4e1 * t1296 * t1263 + 0.8e1 * t1176 * t1158 - 0.8e1 * t1175 * t25 * t1113 * xc * t110 + 0.2e1 * t1311 * t1297 + 0.2e1 * t1112 * t1108 * t1113 t1320 = t253 * t1129 t1328 = t253 * t30 * t19 t1333 = t125 * t1161 t1343 = ZB * t44 * t1129 t1350 = -0.8e1 * t1176 * t1218 - 0.16e2 * t1311 * t1320 + 0.8e1 * t1176 * t1260 - 0.16e2 * t1119 * t1210 + 0.4e1 * t1311 * t1328 + 0.2e1 * t1311 * t1263 + 0.8e1 * t1176 * t1333 + 0.8e1 * t187 * ZB * t417 * t9 - 0.2e1 * t1138 * t1165 - 0.64e2 * t1128 * t1343 + 0.64e2 * t1134 * t1287 + 0.2e1 * t1138 * t1108 t1369 = t1133 * t9 * ZA t1378 = t187 * ZA t1383 = t1170 * ZA t1388 = 0.2e1 * t1138 * t1297 - 0.8e1 * t1148 * t1192 + 0.2e1 * t1138 * t1292 - 0.16e2 * t1119 * t1251 + 0.8e1 * t1175 * xc * t110 * t1113 * t3 - 0.2e1 * t1112 * t1153 * t1113 + 0.128e3 * t1369 * t1130 + 0.16e2 * t1119 * t1333 + 0.4e1 * t1138 * t78 * ZA * ZB + 0.8e1 * t1378 * t78 * t9 * ZB - 0.64e2 * t1383 * t1343 + 0.64e2 * t1383 * t1130 t1420 = 0.4e1 * t1138 * t119 * ZA - 0.128e3 * t1369 * t1343 - 0.4e1 * t187 * t1153 * t9 - 0.2e1 * t1138 * t1226 + 0.8e1 * t1296 * t1328 - 0.2e1 * t1112 * t1139 * t1113 - 0.8e1 * t1148 * t3 * t17 * t30 - 0.32e2 * t1296 * t1320 + 0.8e1 * t1176 * t1122 + 0.4e1 * t187 * t1292 * t9 + 0.8e1 * t1378 * t119 * t9 - 0.8e1 * t1103 * t1218 _C4B = ( -t424 * t508 + 0.8e1 * t412 * t750 - 0.2e1 * t232 * t595 - 0.4e1 * t126 * t323 + t1096 - t76 * t204 + t728 + 0.2e1 * t548 * t827 + 0.2e1 * t150 * t469 + t398 + 0.8e1 * t189 * t146 + t260 - 0.2e1 * t351 * t184 - 0.2e1 * t268 * t673 - 0.4e1 * t319 * t279 + t464 - 0.2e1 * t108 * t461 + 0.16e2 * t740 * t369 + 0.16e2 * t274 * t216 * t754 - 0.16e2 * t70 * t139 * t591 + 0.2e1 * t55 * t56 * t128 - 0.2e1 * t359 * t89 * t111 + 0.2e1 * t734 * t563 * t111 + 0.6e1 * t223 * t224 * t97 + 0.8e1 * t383 * t389 * t103 + 0.4e1 * t606 * ZA * t326 - 0.2e1 * t93 * t18 * t316 - 0.4e1 * t443 * t27 * t128 + 0.8e1 * t197 * t27 * t199 + 0.8e1 * t108 * t109 * t128 - t249 * t604 + 0.16e2 * t70 * t616 - 0.8e1 * t969 * t323 + t845 - t424 * t579 + 0.16e2 * t159 * t162 + t290 * t406 - 0.6e1 * t150 * t864 + t192 * t116 + 0.2e1 * t867 * t326 - 0.4e1 * t658 * t326 - 0.2e1 * t351 * t502 - t76 * t165 + t900 + 0.8e1 * t168 * t323 + t791 + 0.8e1 * t740 * t915 - 0.4e1 * t562 * t750 - 0.4e1 * t278 * t342 + 0.4e1 * t319 * t431 + 0.2e1 * t173 * t175 + t424 * t528 + 0.8e1 * t969 * t129 - 0.8e1 * t347 * t181 + t332 + t530 - 0.2e1 * t108 * t329 - 0.2e1 * t207 * t38 * t37 * t1 * ZA + t1001 + 0.4e1 * t408 * t379 + t76 * t448 + 0.2e1 * t102 * t184 + 0.2e1 * t426 * t329 + 0.16e2 * t740 * t98 - t282 * t127 - 0.16e2 * t1 * t44 * t69 * t552 * t116 + 0.2e1 * t168 * t169 + 0.2e1 * t28 * t134 - t290 * t604 - 0.16e2 * t484 * t485 - 0.8e1 * t740 * t480 + 0.2e1 * t173 * t601 - 0.2e1 * t335 * t336 + t600 + 0.2e1 * t62 * t864 + t952 + 0.8e1 * t347 * t134 - t192 * t355 + t192 * t194 + 0.2e1 * t228 * t461 + t663 + 0.4e1 * t383 * t27 * t417 * t16 + 0.4e1 * t138 * t20 * ZA * t10 - 0.4e1 * t20 * ZB * ZA * t326 + 0.4e1 * t196 * t88 * t77 * t744 - 0.16e2 * t67 * xc * t179 * t181 - 0.8e1 * t95 * t480 - t249 * t488 - t76 * t475 + t1055 - 0.4e1 * t408 * t22 - 0.10e2 * t28 * t379 + 0.2e1 * t335 * t974 + t153 - 0.8e1 * t95 * t1042 - 0.2e1 * t734 * t735 ) / (t1156 + t1201 + t1242 + t1282 + t1317 + t1350 + t1388 + t1420) if x > xc _C1 = _C1B _C2 = _C2B _C3 = _C3B _C4 = _C4B Z = ZB else _C1 = _C1A _C2 = _C2A _C3 = _C3A _C4 = _C4A Z = ZA end t1 = n * n t2 = t1 * t1 t3 = t2 * n t4 = x * t3 t5 = 0.3141592654e1 * 0.3141592654e1 t6 = t5 * 0.3141592654e1 t11 = _C3 * t6 t12 = x * n t13 = nx * nx t14 = t13 * t13 t15 = t12 * t14 t19 = exp(t12 * 0.3141592654e1) t20 = t19 * t19 t21 = t4 * t20 t24 = _C1 * t5 t25 = Z * t20 t29 = _C1 * t6 t30 = t29 * Z t31 = t1 * n t32 = x * t31 t33 = t32 * t13 t36 = t11 * x t41 = n * t20 t45 = t6 * _C4 t49 = t20 * t1 t51 = _C2 * Z t55 = -0.2e1 * t4 * t6 * _C2 * Z - 0.2e1 * t11 * t15 - 0.2e1 * t11 * t21 + 0.2e1 * t24 * t25 * t14 - t13 + 0.4e1 * t30 * t33 - 0.4e1 * t36 * t31 * t20 * t13 - 0.2e1 * t36 * t41 * t14 - 0.2e1 * t4 * t45 * t20 - t49 - 0.2e1 * t4 * t6 * t51 * t20 t58 = t32 * t6 t59 = _C4 * t20 t63 = t20 * t13 t67 = t12 * t6 t68 = t20 * t14 t87 = t49 * t13 t90 = -0.4e1 * t11 * t33 - 0.4e1 * t58 * t59 * t13 - 0.4e1 * t58 * t51 * t63 - 0.2e1 * t67 * t51 * t68 + 0.4e1 * t32 * t45 * t13 - 0.2e1 * t67 * t59 * t14 - 0.2e1 * t30 * t21 + t1 + 0.2e1 * t24 * t25 * t2 + 0.2e1 * t12 * t45 * t14 + 0.4e1 * t24 * Z * t87 t106 = _C3 * t5 t120 = -0.4e1 * t30 * t32 * t63 + t63 + 0.4e1 * t24 * Z * t1 * t13 + 0.2e1 * t29 * Z * x * t3 - 0.4e1 * t58 * t51 * t13 - 0.2e1 * t106 * t2 + t32 * 0.3141592654e1 - 0.2e1 * t106 * t14 - 0.2e1 * t30 * t12 * t68 - 0.2e1 * t67 * t51 * t14 + 0.4e1 * t106 * t87 t129 = sin(nx * 0.3141592654e1 * x) t155 = 0.2e1 * t30 * t15 + x * 0.3141592654e1 * t41 * t13 - 0.4e1 * t19 * nx * t129 * n + t32 * 0.3141592654e1 * t20 + 0.2e1 * t106 * t68 + 0.2e1 * t106 * t20 * t2 - 0.4e1 * t106 * t1 * t13 - 0.2e1 * t11 * t4 + 0.2e1 * t4 * t45 + 0.2e1 * t24 * Z * t2 + 0.2e1 * t24 * Z * t14 + t12 * 0.3141592654e1 * t13 t158 = t5 * Z u1 = (t55 + t90 + t120 + t155) / (0.4e1 * t158 * t19 * t2 + 0.8e1 * t158 * t19 * t1 * t13 + 0.4e1 * t158 * t19 * t14) t1 = n * n t2 = t1 * n t3 = x * t2 t4 = 0.3141592654e1 * 0.3141592654e1 t5 = t4 * 0.3141592654e1 t6 = t3 * t5 t7 = _C2 * Z t8 = nx * nx t12 = t1 * t1 t13 = t12 * n t14 = x * t13 t15 = t5 * _C4 t16 = x * n t18 = exp(t16 * 0.3141592654e1) t19 = t18 * t18 t23 = t16 * t5 t24 = t8 * t8 t28 = _C3 * t5 t29 = t14 * t19 t32 = _C1 * t5 t33 = t32 * Z t34 = t16 * t24 t37 = _C4 * t19 t45 = _C2 * t4 t53 = t19 * t8 t58 = _C4 * t4 t60 = t1 * t19 * t8 t63 = t19 * t24 t67 = t3 * t8 t73 = n * t19 t86 = t28 * x t91 = 0.4e1 * t58 * t60 + 0.2e1 * t33 * t16 * t63 + 0.4e1 * t33 * t67 + 0.2e1 * t33 * t29 - x * 0.3141592654e1 * t73 * t8 - 0.2e1 * t53 + 0.2e1 * t32 * Z * x * t13 - 0.2e1 * t58 * t12 - 0.2e1 * t58 * t24 + t3 * 0.3141592654e1 + 0.4e1 * t86 * t2 * t19 * t8 t94 = Z * t12 t121 = -0.2e1 * t8 + 0.2e1 * t45 * t94 * t19 + 0.2e1 * t14 * t5 * t7 * t19 + 0.4e1 * t6 * t7 * t53 + 0.2e1 * t23 * t7 * t63 - 0.4e1 * t28 * t67 + 0.2e1 * t45 * t94 + 0.2e1 * t58 * t12 * t19 + t16 * 0.3141592654e1 * t8 + 0.2e1 * t14 * t15 - 0.2e1 * t28 * t14 t146 = cos(nx * 0.3141592654e1 * x) t156 = -t3 * 0.3141592654e1 * t19 + 0.2e1 * t58 * t63 - 0.4e1 * t58 * t1 * t8 + 0.4e1 * t45 * Z * t1 * t8 - 0.2e1 * t28 * t34 + 0.2e1 * t86 * t73 * t24 + 0.4e1 * t3 * t15 * t8 + 0.4e1 * t45 * Z * t60 + 0.4e1 * t18 * t146 * t8 + 0.2e1 * t45 * Z * t24 + 0.2e1 * t16 * t15 * t24 t159 = t4 * Z u2 = ( -0.4e1 * t6 * t7 * t8 + 0.2e1 * t14 * t15 * t19 - 0.2e1 * t23 * t7 * t24 + 0.2e1 * t28 * t29 + 0.2e1 * t33 * t34 + 0.4e1 * t6 * t37 * t8 - 0.2e1 * t14 * t5 * _C2 * Z + 0.2e1 * t45 * Z * t19 * t24 + 0.2e1 * t23 * t37 * t24 + 0.4e1 * t33 * t3 * t53 + t91 + t121 + t156 ) / (0.4e1 * t159 * t18 * t12 + 0.8e1 * t159 * t18 * t1 * t8 + 0.4e1 * t159 * t18 * t24) t1 = 0.3141592654e1 * 0.3141592654e1 t2 = t1 * 0.3141592654e1 t3 = _C1 * t2 t4 = t3 * Z t5 = n * n t6 = t5 * t5 t7 = t6 * n t8 = x * t7 t9 = x * n t11 = exp(t9 * 0.3141592654e1) t12 = t11 * t11 t13 = t8 * t12 t16 = t5 * n t17 = x * t16 t18 = t17 * t2 t19 = _C4 * t12 t20 = nx * nx t24 = t2 * _C4 t28 = _C3 * t2 t29 = t28 * x t30 = t12 * n t31 = t20 * t20 t40 = _C2 * Z t44 = t9 * t2 t48 = t12 * t20 t52 = t17 * t20 t57 = -0.2e1 * t4 * t13 - 0.4e1 * t18 * t19 * t20 - 0.2e1 * t8 * t24 * t12 - 0.2e1 * t29 * t30 * t31 + 0.2e1 * t8 * t2 * _C2 * Z - 0.2e1 * t8 * t2 * t40 * t12 - 0.2e1 * t44 * t19 * t31 - 0.4e1 * t18 * t40 * t48 + t20 + 0.4e1 * t28 * t52 + t17 * 0.3141592654e1 * t12 t58 = t9 * t31 t61 = _C3 * t1 t62 = t12 * t31 t73 = t5 * t20 t78 = _C1 * t1 t90 = Z * t12 t94 = 0.2e1 * t28 * t58 + 0.2e1 * t61 * t62 + 0.2e1 * t61 * t12 * t6 - 0.4e1 * t4 * t17 * t48 + 0.2e1 * t28 * t8 + 0.4e1 * t61 * t73 - 0.2e1 * t8 * t24 - 0.2e1 * t78 * Z * t6 - 0.2e1 * t44 * t40 * t62 - 0.2e1 * t78 * Z * t31 - t9 * 0.3141592654e1 * t20 + 0.2e1 * t78 * t90 * t6 t101 = cos(nx * 0.3141592654e1 * x) t102 = t11 * t101 t109 = t12 * t5 t110 = t109 * t20 t128 = 0.2e1 * t61 * t6 - t17 * 0.3141592654e1 + 0.2e1 * t102 * t5 - 0.4e1 * t17 * t24 * t20 + 0.4e1 * t78 * Z * t110 - 0.2e1 * t9 * t24 * t31 - 0.4e1 * t4 * t52 - 0.2e1 * t4 * t9 * t62 + x * 0.3141592654e1 * t30 * t20 - t5 - 0.4e1 * t78 * Z * t5 * t20 t156 = 0.2e1 * t78 * t90 * t31 - 0.2e1 * t3 * Z * x * t7 + t48 + 0.4e1 * t61 * t110 + 0.4e1 * t18 * t40 * t20 - 0.2e1 * t102 * t20 + 0.2e1 * t61 * t31 + 0.2e1 * t44 * t40 * t31 - t109 - 0.2e1 * t4 * t58 - 0.2e1 * t28 * t13 - 0.4e1 * t29 * t16 * t12 * t20 t159 = t1 * t11 u3 = (t57 + t94 + t128 + t156) / (0.4e1 * t159 * t6 + 0.8e1 * t159 * t73 + 0.4e1 * t159 * t31) t1 = _C2 * Z t2 = 0.3141592654e1 * 0.3141592654e1 t3 = t2 * 0.3141592654e1 t4 = n * n t5 = t4 * t4 t6 = t5 * t4 t8 = t3 * t6 * x t11 = x * t4 t12 = t11 * t3 t15 = exp(x * n * 0.3141592654e1) t16 = t15 * t15 t17 = _C3 * t16 t18 = nx * nx t19 = t18 * t18 t23 = t5 * n t24 = t2 * t23 t28 = t1 * t3 t29 = t6 * x t30 = t29 * t16 t33 = _C4 * t3 t34 = t5 * x t35 = t34 * t18 t41 = sin(nx * 0.3141592654e1 * x) t47 = t11 * t19 t54 = t3 * _C3 t57 = 0.2e1 * t1 * t8 + 0.2e1 * t12 * t17 * t19 + 0.2e1 * t1 * t24 * t16 + 0.2e1 * t28 * t30 - 0.4e1 * t33 * t35 + 0.2e1 * t15 * nx * t41 * t4 + 0.4e1 * t28 * t35 - 0.2e1 * t33 * t47 - 0.2e1 * t1 * t24 - 0.2e1 * t33 * t29 + 0.2e1 * t29 * t54 t58 = 0.3141592654e1 * t16 t60 = t2 * _C4 t69 = t4 * n t73 = t1 * t2 t75 = t69 * t16 * t18 t79 = x * t16 t83 = n * t16 t84 = t83 * t19 t95 = -t34 * t58 + 0.2e1 * t60 * t23 * t16 + 0.2e1 * t60 * n * t19 - t11 * 0.3141592654e1 * t18 + 0.4e1 * t60 * t69 * t18 + 0.4e1 * t73 * t75 + 0.4e1 * t33 * t5 * t79 * t18 + 0.2e1 * t73 * t84 + 0.2e1 * t60 * t84 + 0.2e1 * t33 * t4 * t79 * t19 + 0.4e1 * t60 * t75 t97 = t34 * t3 t101 = Z * _C1 t102 = t16 * t19 t106 = t16 * t18 t127 = t2 * t69 t131 = t2 * n t135 = 0.4e1 * t97 * t17 * t18 + 0.2e1 * t12 * t101 * t102 + 0.4e1 * t28 * t34 * t106 + 0.2e1 * t28 * t11 * t102 - 0.2e1 * t29 * t3 * Z * _C1 - 0.4e1 * t97 * t101 * t18 - 0.2e1 * t12 * t101 * t19 + 0.2e1 * t60 * t23 - 0.2e1 * t83 * t18 - 0.4e1 * t1 * t127 * t18 - 0.2e1 * t1 * t131 * t19 t164 = 0.2e1 * t28 * t47 + 0.2e1 * t11 * t54 * t19 + 0.2e1 * t8 * t101 * t16 + 0.2e1 * t33 * t30 - t11 * t58 * t18 + 0.2e1 * t29 * t54 * t16 + 0.4e1 * t34 * t54 * t18 + 0.4e1 * t97 * t101 * t106 - 0.2e1 * t15 * t18 * nx * t41 - t34 * 0.3141592654e1 + 0.2e1 * n * t18 u4 = (t57 + t95 + t135 + t164) / (0.4e1 * t24 * t15 + 0.8e1 * t127 * t15 * t18 + 0.4e1 * t131 * t15 * t19) u5 = (-2 * Z * n * π * u2 - u3 * 2 * n * π) * cos(n * π * z) # pressure u6 = (u3 * 2 * n * π + 4 * Z * n * π * u2) * cos(n * π * z) # zz stress sum5 = u5 sum6 = u6 u1 *= cos(n * π * z) # x velocity sum1 = u1 u2 *= sin(n * π * z) # z velocity sum2 = u2 u3 *= 2 * n * π * cos(n * π * z) # xx stress sum3 = u3 u4 *= 2 * n * π * sin(n * π * z) # zx stress sum4 = u4 vx = sum1 vz = sum2 p = sum5 return (; V=[vx, vz], p) end
ExactFieldSolutions
https://github.com/tduretz/ExactFieldSolutions.jl.git
[ "MIT" ]
0.1.3
d62c0014dfc5d64ecd16190fa069a8bb04627006
code
15131
@doc raw""" sol = Stokes2D_SolKz_Zhong1996(x; params) Evaluates the manufactured solution of [Zhong et al., (1996)](https://booksite.elsevier.com/brochures/geophysics/PDFs/00118.pdf). Analytical solution adapted from Underworld (https://github.com/underworldcode, LGPL-3 license). The solution requires the following expressions the density and viscosity fields: ρ = -σ*sin(km*x[2])*cos(kn*x[1]) η = exp(2*B*x[2]) Input parameters are: x : is the coordinate vector params : optional parameter array and returns: sol : tuple containing the solution fields p (pressure), V (velocity vector), ρ (density) and η (viscosity) # Examples ```julia-repl julia> Stokes2D_SolKz_Zhong1996([0; 0]) (p = -0.017494712727797308, V = [0.0, 0.0], ρ = 0.0, η = 1.0) ``` """ function Stokes2D_SolKz_Zhong1996(x; params = (Δη=1e6, B = 6.9, km = 1.6*π, n = 3, σ = 1.0 ) ) @unpack Δη, B, km, n, σ = params #************************************************************************% #************************************************************************% kn = 3*π a = B*B + kn*kn b = 2.0*kn*B r = sqrt(a*a + b*b) Rp = sqrt( (r+a)/2.0 ) Rm = sqrt( (r-a)/2.0 ) UU = Rp - B VV = Rp + B sum1 = 0.0; sum2 = 0.0; sum3 = 0.0; sum4 = 0.0; sum5 = 0.0; sum6 = 0.0; sum7 = 0.0; #*******************************************% # calculate the constants % #*******************************************% t3 = kn * kn; t4 = km * km; t6 = B * B; t8 = 0.4e1 * t3 * t6; t10 = 0.4e1 * t4 * t6; t13 = 0.8e1 * kn * t6 * km; t14 = t4 * t4; t16 = 0.2e1 * t3 * t4; t17 = t3 * t3; aa = -0.4e1 * B * km * kn * (t3 + t4) / (t8 + t10 + t13 + t14 + t16 + t17) / (-t13 + t8 + t10 + t14 + t16 + t17); t1 = kn * kn; t2 = t1 * t1; t3 = B * B; t5 = 0.4e1 * t1 * t3; t6 = km * km; t7 = t6 * t6; t9 = 0.2e1 * t1 * t6; t11 = 0.4e1 * t3 * t6; t16 = 0.8e1 * kn * t3 * km; bb = kn * (t2 + t5 + t7 + t9 - t11) / (t5 + t11 + t16 + t7 + t9 + t2) / (-t16 + t5 + t11 + t7 + t9 + t2); AA = aa; BB = bb; t1 = B * B; t2 = t1 * Rp; t4 = Rm * Rm; t5 = t4 * Rp; t7 = t4 * B; t8 = km * km; t12 = Rp * Rp; t13 = B * t12; t21 = 0.8e1 * t1 * km * BB * Rp; t23 = 0.2e1 * Rm; t24 = cos(t23); t26 = Rm * Rp; t38 = sin(t23); t51 = exp(-0.2e1 * Rp); t53 = B + Rp; t54 = Rm * t53; t55 = Rm * B; t57 = 0.2e1 * B * km; t58 = t55 + t57 - t26; t62 = 0.3e1 * t1; t64 = 0.2e1 * Rp * B; t65 = t62 + t64 + t4 - t8 - t12; t67 = t54 * t65 * BB; t69 = Rm - km; t70 = cos(t69); t72 = -t57 + t55 - t26; t77 = Rm + km; t78 = cos(t77); t81 = t54 * t65 * AA; t86 = sin(t77); t92 = sin(t69); t96 = exp(-t53); t98 = B - Rp; t99 = Rm * t98; t100 = t55 + t57 + t26; t104 = t62 - t64 + t4 - t8 - t12; t106 = t99 * t104 * BB; t109 = -t57 + t55 + t26; t116 = t99 * t104 * AA; t130 = exp(-0.3e1 * Rp - B); t135 = exp(-0.4e1 * Rp); t144 = t4 * t1; t150 = t4 * t12; C1 = (((0.2e1 * Rp * (0.2e1 * t2 + 0.2e1 * t5 + t7 + B * t8 - 0.3e1 * t1 * B + t13) * AA + t21) * t24 + (-0.2e1 * t26 * (t4 - t8 - t12 + 0.5e1 * t1) * AA + 0.8e1 * B * BB * km * Rm * Rp) * t38 - 0.2e1 * B * (0.2e1 * t13 + t12 * Rp - 0.3e1 * t2 + t5 + 0.2e1 * t7 + t8 * Rp) * AA - t21) * t51 + ((0.2e1 * t54 * t58 * AA + t67) * t70 + (0.2e1 * t54 * t72 * AA - t67) * t78 + (t81 + 0.2e1 * t54 * t72 * BB) * t86 + (t81 - 0.2e1 * t54 * t58 * BB) * t92) * t96 + ((-0.2e1 * t99 * t100 * AA - t106) * t70 + (-0.2e1 * t99 * t109 * AA + t106) * t78 + (-t116 - 0.2e1 * t99 * t109 * BB) * t86 + (-t116 + 0.2e1 * t99 * t100 * BB) * t92) * t130 + 0.4e1 * t4 * t98 * t53 * AA * t135) / (((-0.8e1 * t4 - 0.8e1 * t1) * t12 * t24 + 0.8e1 * t144 + 0.8e1 * t12 * t1) * t51 + (0.4e1 * t150 - 0.4e1 * t144) * t135 + 0.4e1 * t150 - 0.4e1 * t144); t1 = Rm * Rp; t2 = Rm * Rm; t3 = km * km; t4 = Rp * Rp; t5 = B * B; t12 = km * Rm; t17 = 0.2e1 * Rm; t18 = cos(t17); t22 = t2 * Rp; t25 = B * t3; t26 = t5 * B; t33 = t5 * km; t38 = sin(t17); t40 = Rm * B; t41 = 0.3e1 * t5; t51 = exp(-0.2e1 * Rp); t53 = B + Rp; t54 = Rm * t53; t57 = t41 + 0.2e1 * Rp * B + t2 - t3 - t4; t59 = t54 * t57 * AA; t60 = B * km; t61 = 0.2e1 * t60; t62 = t40 + t61 - t1; t67 = Rm - km; t68 = cos(t67); t70 = -t61 + t40 - t1; t75 = Rm + km; t76 = cos(t75); t82 = t54 * t57 * BB; t84 = sin(t75); t90 = sin(t67); t94 = exp(-t53); t97 = 0.3e1 * Rm * t26; t98 = t2 * Rm; t99 = t98 * B; t100 = t3 * Rm; t101 = t100 * Rp; t103 = Rm * t4 * B; t104 = t4 * Rp; t105 = Rm * t104; t107 = 0.8e1 * t33 * Rp; t109 = 0.5e1 * t1 * t5; t110 = t98 * Rp; t111 = t100 * B; t112 = t97 + t99 - t101 + t103 - t105 + t107 + t109 + t110 - t111; t114 = t2 * t4; t116 = 0.2e1 * t60 * t1; t117 = t2 * t5; t119 = 0.3e1 * t26 * Rp; t120 = t104 * B; t121 = t4 * t5; t122 = 0.2e1 * t121; t123 = t22 * B; t125 = 0.2e1 * t33 * Rm; t126 = t25 * Rp; t127 = t114 + t116 + t117 - t119 + t120 + t122 + t123 + t125 + t126; t132 = -t107 + t103 - t105 - t101 + t97 - t111 + t110 + t109 + t99; t134 = t120 - t125 + t123 - t116 + t122 + t117 + t114 + t126 - t119; t152 = exp(-0.3e1 * Rp - B); t161 = exp(-0.4e1 * Rp); C2 = (((0.2e1 * t1 * (t2 - t3 - t4 + 0.5e1 * t5) * AA - 0.8e1 * B * BB * t12 * Rp) * t18 + (0.2e1 * Rp * (0.2e1 * t5 * Rp + 0.2e1 * t22 + t2 * B + t25 - 0.3e1 * t26 + B * t4) * AA + 0.8e1 * t33 * BB * Rp) * t38 + 0.2e1 * t40 * (t41 + t4 + t2 - t3) * AA - 0.8e1 * t5 * BB * t12) * t51 + ((-t59 + 0.2e1 * t54 * t62 * BB) * t68 + (-t59 - 0.2e1 * t54 * t70 * BB) * t76 + (0.2e1 * t54 * t70 * AA - t82) * t84 + (0.2e1 * t54 * t62 * AA + t82) * t90) * t94 + ((t112 * AA - 0.2e1 * t127 * BB) * t68 + (t132 * AA + 0.2e1 * t134 * BB) * t76 + (-0.2e1 * t134 * AA + t132 * BB) * t84 + (-0.2e1 * t127 * AA - t112 * BB) * t90) * t152 + (-0.2e1 * t59 + 0.8e1 * t40 * km * t53 * BB) * t161) / (((-0.8e1 * t2 - 0.8e1 * t5) * t4 * t18 + 0.8e1 * t117 + 0.8e1 * t121) * t51 + (0.4e1 * t114 - 0.4e1 * t117) * t161 + 0.4e1 * t114 - 0.4e1 * t117); t1 = B * B; t2 = t1 * Rp; t4 = Rm * Rm; t5 = t4 * Rp; t7 = Rp * Rp; t8 = B * t7; t11 = km * km; t13 = t4 * B; t21 = 0.8e1 * t1 * km * BB * Rp; t23 = 0.2e1 * Rm; t24 = cos(t23); t26 = Rm * Rp; t38 = sin(t23); t51 = exp(-0.2e1 * Rp); t53 = B + Rp; t54 = Rm * t53; t55 = Rm * B; t57 = 0.2e1 * B * km; t58 = t55 + t57 - t26; t62 = 0.3e1 * t1; t64 = 0.2e1 * Rp * B; t65 = t62 + t64 + t4 - t11 - t7; t67 = t54 * t65 * BB; t69 = Rm - km; t70 = cos(t69); t72 = -t57 + t55 - t26; t77 = Rm + km; t78 = cos(t77); t81 = t54 * t65 * AA; t86 = sin(t77); t92 = sin(t69); t96 = exp(-t53); t98 = B - Rp; t99 = Rm * t98; t100 = t55 + t57 + t26; t104 = t62 - t64 + t4 - t11 - t7; t106 = t99 * t104 * BB; t109 = -t57 + t55 + t26; t116 = t99 * t104 * AA; t130 = exp(-0.3e1 * Rp - B); t141 = t4 * t1; t147 = t4 * t7; t151 = exp(-0.4e1 * Rp); C3 = (((-0.2e1 * Rp * (-0.2e1 * t2 - 0.2e1 * t5 + t8 - 0.3e1 * t1 * B + B * t11 + t13) * AA - t21) * t24 + (0.2e1 * t26 * (t4 - t11 - t7 + 0.5e1 * t1) * AA - 0.8e1 * B * BB * km * Rm * Rp) * t38 - 0.2e1 * B * (0.2e1 * t8 + 0.2e1 * t13 + 0.3e1 * t2 - t7 * Rp - t5 - t11 * Rp) * AA + t21) * t51 + ((-0.2e1 * t54 * t58 * AA - t67) * t70 + (-0.2e1 * t54 * t72 * AA + t67) * t78 + (-t81 - 0.2e1 * t54 * t72 * BB) * t86 + (-t81 + 0.2e1 * t54 * t58 * BB) * t92) * t96 + ((0.2e1 * t99 * t100 * AA + t106) * t70 + (0.2e1 * t99 * t109 * AA - t106) * t78 + (t116 + 0.2e1 * t99 * t109 * BB) * t86 + (t116 - 0.2e1 * t99 * t100 * BB) * t92) * t130 + 0.4e1 * t4 * t98 * t53 * AA) / (((-0.8e1 * t4 - 0.8e1 * t1) * t7 * t24 + 0.8e1 * t141 + 0.8e1 * t7 * t1) * t51 + (0.4e1 * t147 - 0.4e1 * t141) * t151 + 0.4e1 * t147 - 0.4e1 * t141); t1 = Rm * Rp; t2 = Rm * Rm; t3 = km * km; t4 = Rp * Rp; t5 = B * B; t12 = km * Rm; t17 = 0.2e1 * Rm; t18 = cos(t17); t22 = t2 * Rp; t25 = t5 * B; t27 = B * t3; t33 = t5 * km; t38 = sin(t17); t40 = Rm * B; t41 = 0.3e1 * t5; t51 = exp(-0.2e1 * Rp); t53 = t2 * Rm; t54 = t53 * B; t56 = 0.5e1 * t1 * t5; t58 = Rm * t4 * B; t59 = t3 * Rm; t60 = t59 * Rp; t62 = 0.8e1 * t33 * Rp; t64 = 0.3e1 * Rm * t25; t65 = t53 * Rp; t66 = t59 * B; t67 = t4 * Rp; t68 = Rm * t67; t69 = t54 - t56 + t58 + t60 - t62 + t64 - t65 - t66 + t68; t71 = t2 * t4; t73 = 0.3e1 * t25 * Rp; t74 = t2 * t5; t75 = t27 * Rp; t76 = B * km; t78 = 0.2e1 * t76 * t1; t80 = 0.2e1 * t33 * Rm; t81 = t22 * B; t82 = t4 * t5; t83 = 0.2e1 * t82; t84 = t67 * B; t85 = t71 + t73 + t74 - t75 - t78 + t80 - t81 + t83 - t84; t89 = Rm - km; t90 = cos(t89); t92 = t60 - t66 - t65 + t58 + t54 - t56 + t62 + t68 + t64; t94 = t73 + t78 - t81 + t74 - t80 - t84 - t75 + t83 + t71; t98 = Rm + km; t99 = cos(t98); t105 = sin(t98); t111 = sin(t89); t115 = exp(-Rp - B); t117 = B - Rp; t118 = Rm * t117; t121 = t41 - 0.2e1 * Rp * B + t2 - t3 - t4; t123 = t118 * t121 * AA; t124 = 0.2e1 * t76; t125 = t40 + t124 + t1; t131 = -t124 + t40 + t1; t141 = t118 * t121 * BB; t152 = exp(-0.3e1 * Rp - B); t171 = exp(-0.4e1 * Rp); C4 = (((-0.2e1 * t1 * (t2 - t3 - t4 + 0.5e1 * t5) * AA + 0.8e1 * B * BB * t12 * Rp) * t18 + (-0.2e1 * Rp * (-0.2e1 * t5 * Rp - 0.2e1 * t22 + t4 * B - 0.3e1 * t25 + t27 + t2 * B) * AA - 0.8e1 * t33 * BB * Rp) * t38 + 0.2e1 * t40 * (t41 + t4 + t2 - t3) * AA - 0.8e1 * t5 * BB * t12) * t51 + ((t69 * AA - 0.2e1 * t85 * BB) * t90 + (t92 * AA + 0.2e1 * t94 * BB) * t99 + (-0.2e1 * t94 * AA + t92 * BB) * t105 + (-0.2e1 * t85 * AA - t69 * BB) * t111) * t115 + ((-t123 + 0.2e1 * t118 * t125 * BB) * t90 + (-t123 - 0.2e1 * t118 * t131 * BB) * t99 + (0.2e1 * t118 * t131 * AA - t141) * t105 + (0.2e1 * t118 * t125 * AA + t141) * t111) * t152 - 0.2e1 * t123 + 0.8e1 * t40 * km * t117 * BB) / (((-0.8e1 * t2 - 0.8e1 * t5) * t4 * t18 + 0.8e1 * t74 + 0.8e1 * t82) * t51 + (0.4e1 * t71 - 0.4e1 * t74) * t171 + 0.4e1 * t71 - 0.4e1 * t74); #******************************************************************% #******************************************************************% #*******************************************% #* calculate the velocities etc *% #*******************************************% t2 = exp(UU * x[2]); t3 = Rm * x[2]; t4 = cos(t3); t6 = sin(t3); t11 = exp(-VV * x[2]); t18 = exp(-0.2e1 * x[2] * B); t19 = km * x[2]; t20 = cos(t19); t22 = sin(t19); u1 = kn * (t2 * (C1 * t4 + C2 * t6) + t11 * (C3 * t4 + C4 * t6) + t18 * (AA * t20 + BB * t22)); t1 = Rm * x[2]; t2 = cos(t1); t4 = sin(t1); t14 = exp(UU * x[2]); t26 = exp(-VV * x[2]); t28 = km * x[2]; t29 = cos(t28); t31 = sin(t28); t43 = exp(-0.2e1 * x[2] * B); u2 = (-UU * (C1 * t2 + C2 * t4) + C1 * t4 * Rm - C2 * t2 * Rm) * t14 + (VV * (C3 * t2 + C4 * t4) + C3 * t4 * Rm - C4 * t2 * Rm) * t26 + (0.2e1 * B * (AA * t29 + BB * t31) + AA * t31 * km - BB * t29 * km) * t43; t2 = 0.2e1 * x[2] * B; t3 = exp(t2); t4 = t3 * kn; t5 = Rm * x[2]; t6 = cos(t5); t8 = sin(t5); t18 = exp(UU * x[2]); t31 = exp(-VV * x[2]); t34 = km * x[2]; t35 = cos(t34); t37 = sin(t34); t47 = exp(-t2); u3 = 0.2e1 * t4 * (UU * (C1 * t6 + C2 * t8) - C1 * t8 * Rm + C2 * t6 * Rm) * t18 + 0.2e1 * t4 * (-VV * (C3 * t6 + C4 * t8) - C3 * t8 * Rm + C4 * t6 * Rm) * t31 + 0.2e1 * t4 * (-0.2e1 * B * (AA * t35 + BB * t37) - AA * t37 * km + BB * t35 * km) * t47; t1 = Rm * Rm; t3 = UU * UU; t8 = kn * kn; t11 = Rm * x[2]; t12 = sin(t11); t14 = cos(t11); t20 = t14 * Rm; t27 = 0.2e1 * x[2] * B; t28 = exp(t27); t31 = exp(UU * x[2]); t38 = VV * VV; t54 = exp(-VV * x[2]); t56 = km * km; t59 = B * B; t66 = km * x[2]; t67 = sin(t66); t69 = cos(t66); t83 = exp(-t27); u4 = ((C2 * t1 - t3 * C2 + 0.2e1 * UU * C1 * Rm - C2 * t8) * t12 + C1 * t14 * t1 - t3 * C1 * t14 - 0.2e1 * UU * C2 * t20 - t8 * C1 * t14) * t28 * t31 + ((-0.2e1 * VV * C3 * Rm + C4 * t1 - C4 * t8 - t38 * C4) * t12 + 0.2e1 * VV * C4 * t20 + C3 * t14 * t1 - t8 * C3 * t14 - t38 * C3 * t14) * t28 * t54 + ((BB * t56 - t8 * BB - 0.4e1 * t59 * BB - 0.4e1 * B * AA * km) * t67 + AA * t69 * t56 - t8 * AA * t69 - 0.4e1 * t59 * AA * t69 + 0.4e1 * B * BB * t69 * km) * t28 * t83; t1 = Rm * x[2]; t2 = sin(t1); t3 = Rm * Rm; t4 = t3 * Rm; t5 = t2 * t4; t6 = UU * UU; t7 = t6 * UU; t8 = cos(t1); t15 = 0.2e1 * B * t8 * t3; t19 = B * UU; t20 = t2 * Rm; t23 = kn * kn; t24 = B * t23; t26 = 0.2e1 * t24 * t8; t27 = t23 * UU; t29 = B * t6; t33 = t23 * t2 * Rm; t35 = 0.1e1 / kn; t42 = 0.2e1 * B * t2 * t3; t43 = t8 * t4; t45 = 0.2e1 * t24 * t2; t52 = t23 * t8 * Rm; t53 = t8 * Rm; t64 = 0.2e1 * x[2] * B; t65 = exp(t64); t68 = exp(UU * x[2]); t70 = B * VV; t76 = t23 * VV; t78 = VV * VV; t79 = t78 * VV; t84 = B * t78; t108 = exp(-VV * x[2]); t111 = km * x[2]; t112 = sin(t111); t113 = km * km; t118 = cos(t111); t119 = t118 * km; t121 = B * B; t123 = t112 * km; t130 = t113 * km; t148 = exp(-t64); u5 = (-(-t5 - t7 * t8 + 0.3e1 * UU * t8 * t3 + t15 + 0.3e1 * t6 * t2 * Rm + 0.4e1 * t19 * t20 - t26 + t27 * t8 - 0.2e1 * t29 * t8 - t33) * t35 * C1 - (-t7 * t2 + t27 * t2 + t42 + t43 - t45 + 0.3e1 * UU * t2 * t3 - 0.2e1 * t29 * t2 + t52 - 0.4e1 * t19 * t53 - 0.3e1 * t6 * t8 * Rm) * t35 * C2) * t65 * t68 + (-(t15 - 0.4e1 * t70 * t20 - t33 - 0.3e1 * VV * t8 * t3 - t76 * t8 + t79 * t8 + 0.3e1 * t78 * t2 * Rm - 0.2e1 * t84 * t8 - t26 - t5) * t35 * C3 - (t52 - 0.3e1 * VV * t2 * t3 + t79 * t2 + 0.4e1 * t70 * t53 - 0.3e1 * t78 * t8 * Rm - 0.2e1 * t84 * t2 + t43 - t76 * t2 + t42 - t45) * t35 * C4) * t65 * t108 - t65 * (-0.4e1 * B * BB * t112 * t113 + t23 * BB * t119 + 0.4e1 * t121 * AA * t123 - 0.4e1 * t121 * BB * t119 + BB * t118 * t130 - AA * t112 * t130 - 0.4e1 * B * AA * t118 * t113 - t23 * AA * t123 - 0.4e1 * t24 * AA * t118 - 0.4e1 * t24 * BB * t112) * t35 * t148; t2 = 0.2e1 * x[2] * B; t3 = exp(t2); t4 = t3 * kn; t5 = Rm * x[2]; t6 = cos(t5); t8 = sin(t5); t18 = exp(UU * x[2]); t31 = exp(-VV * x[2]); t34 = km * x[2]; t35 = cos(t34); t37 = sin(t34); t47 = exp(-t2); u6 = -0.2e1 * t4 * (UU * (C1 * t6 + C2 * t8) - C1 * t8 * Rm + C2 * t6 * Rm) * t18 - 0.2e1 * t4 * (-VV * (C3 * t6 + C4 * t8) - C3 * t8 * Rm + C4 * t6 * Rm) * t31 - 0.2e1 * t4 * (-0.2e1 * B * (AA * t35 + BB * t37) - AA * t37 * km + BB * t35 * km) * t47; #******************************************************************% #******************************************************************% u1 = u1 * cos(n*π*x[1]); # x[2] velocity sum1 = sum1 + u1; u2 = u2 * sin(n*π*x[1]); # x[1] velocity sum2 = sum2 + u2; sum5 = sum5 + u5*cos(n*π*x[1]); # pressure u6 = u6 - u5; # get total stress sum6 = sum6 + u6*cos(n*π*x[1]); # xx stress u3 = u3 - u5; # get total stress u3 = u3 * cos(n*π*x[1]); # zz stress sum3 = sum3 + u3; u4 = u4 * sin(n*π*x[1]); # zx stress sum4 = sum4 + u4; ρ = -σ*sin(km*x[2])*cos(kn*x[1]); # density sum7 = sum7 + ρ; SS = exp(UU*x[2])*(C1*cos(Rm*x[2])+C2*sin(Rm*x[2])) +exp(-VV*x[2])*(C3*cos(Rm*x[2])+C4*sin(Rm*x[2])) + exp(-2*x[2]*B)*(AA*cos(km*x[2])+BB*sin(km*x[2])); SS = SS * sin(kn*x[1]); # stream function mag = sqrt(u1*u1+u2*u2); # Output vx = sum2; vz = sum1; p = sum5; ρ = sum7; η = exp( 2.0 * B * x[2] ); return ( p=p, V=[vx, vz], ρ=ρ, η=η) end
ExactFieldSolutions
https://github.com/tduretz/ExactFieldSolutions.jl.git
[ "MIT" ]
0.1.3
d62c0014dfc5d64ecd16190fa069a8bb04627006
docs
3153
## ExactFieldSolutions.jl Full field solutions are essential for the verification of numerical codes that are based on the solution of Partial Differential Equations (PDE). They allow for checking if numerical solutions are meaningful in eyeball norm but, more importantly, they allow for the quantification of discretisation errors. This quantification further enables to check whether numerical solutions converge to exact solutions at expected theoretical rates. `ExactFieldSolutions` compiles full field solutions for 1D, 2D and 3D PDE problems including Poisson-type and mechanical problems (Stokes, elasticity). Contributions are welcome and full field solutions to other problems (electric, magnetic, MHD) are more than welcome. Feel free to make a PR. `ExactFieldSolutions` benefits from automatic differentiation tools available within the Julia ecosystem (e.g., ForwardDiff). These allow to evaluate fluxes and sources terms in a simplified way. [See this manufactured solution for the 2D Poisson problem](src/Poisson2D_Sevilla2018.jl). Please note that `ExactFieldSolutions` is a registered package, so you can install it simply by typing `add ExactFieldSolutions` in package mode. ### Poisson 2D [Sevilla et al. (2018)](examples/visualisations/Visualize_Poisson2D_Sevilla2018.jl) ![alt text](img/Poisson2D_Sevilla2018.svg "Sevilla et al. (2018)") ### Poisson 3D [Sevilla et al. (2018)](examples/visualisations/Visualize_Poisson3D_Sevilla2018.jl) ![alt text](img/Poisson3D_Sevilla2018.svg "Sevilla et al. (2018)") ### Diffusion 1D [Diffusion of a 1D Gaussian](examples/visualisations/Visualize_Diffusion1D_Gaussian.jl) ![alt text](img/Diffusion1D_Gaussian.svg) ### Diffusion 2D [Diffusion of a 2D Gaussian](examples/visualisations/Visualize_Diffusion2D_Gaussian.jl) ![alt text](img/Diffusion2D_Gaussian.svg) ### Stokes 2D [Viscous inclusion - Schmid & Podladchikov (2003)](examples/visualisations/Visualize_Stokes2D_Schmid2003.jl) ![alt text](img/Stokes2D_Schmid2003.svg "Schmid & Podladchikov (2003)") [Double corner flow - Moulas et al., (2021)](examples/visualisations/Visualize_Stokes2D_Moulas2021.jl) ![alt text](img/Stokes2D_Moulas2021.svg "Moulas et al. (2021)") [Donea & Huerta (2003)](examples/visualisations/Visualize_Stokes2D_Donea2003.jl) ![alt text](img/Stokes2D_Donea2003.svg "Donea & Huerta (2003)") [SolKz - Zhong et al. (1996)](examples/visualisations/Visualize_Stokes2D_SolKz_Zhong1996.jl) ![alt text](img/Stokes2D_SolKz_Zhong1996.svg "Zhong et al. (1996)") [SolCx - Zhong et al. (1996)](examples/visualisations/Visualize_Stokes2D_SolCx_Zhong1996.jl) ![alt text](img/Stokes2D_SolCx_Zhong1996.svg "Zhong et al. (1996)") ### Elasticity 2D [Elastic plate with a hole](examples/visualisations/Visualize_Elasticity2D_Hole.jl) ![alt text](img/Elasticity2D_Hole.svg "Elastic plate with a hole") ### Benchmarking [1D diffusion: Finite Difference Method (FDM) with backward-Euler integration and spatial staggering](examples/benchmarks/Benchmark_Thermal1D.jl) ![alt text](img/Benchmark_Diffusion1D_FDM.svg "Diffusion in 1D using the Finite Difference Method (FDM): backward-Euler and spatial staggering")
ExactFieldSolutions
https://github.com/tduretz/ExactFieldSolutions.jl.git
[ "MIT" ]
0.1.0
ce4c98fdd7977797f62a1d80cdae7c3fffdfce37
code
208
module Geocoder include("geocode.jl") include("geom.jl") export geocode export geometry export address export geomgoogle export geomOSM export longitude export latitude end
Geocoder
https://github.com/arubhardwaj/Geocoder.jl.git
[ "MIT" ]
0.1.0
ce4c98fdd7977797f62a1d80cdae7c3fffdfce37
code
2387
using HTTP using JSON using DataFrames """ For obtaining the address in the format to use with the API key `address()` can be used. Example: julia> address("1600 Amphitheatre Parkway, Mountain View, CA") """ function address(street_address::Vector{String}) street_address = replace.(street_address, r"\s*(,)?\s+" => "+") return(street_address) end """ `julia> geocode(street_address::String, api_key::String, method::String)` JuliaMaps has `geocode()` for obtaining the coordingates of locations. It will produce `longitude` and `latitude` of location in `Dict`. Usage: `julia> geocode("full address", "api key", "method")` Note: Currently, `geocode()` can call from two methods: "google" and "osm". If there are more than one addresses, it'd be reueired to use broadcasting operator with `geocode()`. Example: `julia> geocode.(address_list, "api","method")` Method: - google: Calls data from google maps. In this case, it'd be reqired to use google maps api key. - osm: Calls data from open street maps, using MapQuest api. Visit: https://developer.mapquest.com/documentation/ """ function geocode(street_address::String, api_key::String, method::String) street_address = replace.(street_address, r"\s*(,)?\s+" => "+") if method == "google" url = "https://maps.googleapis.com/maps/api/geocode/json?address=$street_address&key=$api_key" response = HTTP.get(url) gem = geomgoogle(JSON.parse(String(response.body))) elseif method == "osm" url = "http://www.mapquestapi.com/geocoding/v1/address?key=$api_key&location=$street_address" response = HTTP.get(url) gem = geomOSM(JSON.parse(String(response.body))) else gem = error("Please use method correctly. Currently JuliaMaps.jl only supports two methods: google and osm") end return(gem) end """ If there were more than one addresses in geocoding, while using `geocode()`, all the longitudes and latitudes can be printed in a data frame using `geometry(geocod_output)`. Usage: `julia> geometry(geocode_output)` Note: This function can only be used if there were more than one addresses in `geocode()`. """ function geometry(geocode_output) lat = getindex.(geocode_output, "lat") lng = getindex.(geocode_output, "lng") d = DataFrame(Longitude = lng, Latitude = lat) return(d) end
Geocoder
https://github.com/arubhardwaj/Geocoder.jl.git
[ "MIT" ]
0.1.0
ce4c98fdd7977797f62a1d80cdae7c3fffdfce37
code
870
function geomgoogle(json_response::Dict{String, Any}) gem = json_response["results"][1]["geometry"]["location"] return((gem)) end function geomOSM(json_response::Dict{String, Any}) gem = json_response["results"][1]["locations"][1]["latLng"] return((gem)) end """ Print all the longitudes from geocode output. Usage: `julia> longitude(geocode_output)` Note: This function can only be used if there were more than one addresses in `geocode()`. """ function longitude(geocode_output) lng = getindex.(geocode_output, "lng") return(lng) end """ Print all the latitudes from geocode output. Usage: `julia> latitude(geocode_output)` Note: This function can only be used if there were more than one addresses in `geocode()`. """ function latitude(geocode_output) lat = getindex.(geocode_output, "lat") return(lat) end
Geocoder
https://github.com/arubhardwaj/Geocoder.jl.git
[ "MIT" ]
0.1.0
ce4c98fdd7977797f62a1d80cdae7c3fffdfce37
docs
1913
# Geocoder Geocoder.jl is a packag for geocoding. It is a part of [JuliaMaps.jl](https://github.com/arubhardwaj/JuliaMaps.jl). The idea of this project is to create something like [ggmap](https://github.com/dkahle/ggmap) for plotting maps in Julia. Currently, `Geocoder.jl` it can only be used as a geocoding client for Google Maps API and Open Street Maps API. It is needed to have an API key for using this package, which can be requested from [Google Cloud Console](https://console.cloud.google.com/) (for google maps) and from [Maps Quest](https://developer.mapquest.com/) (for Open Streets Map). For more information on requesting an API visit: - [Google Maps Documentation](https://developers.google.com/maps/gmp-get-started) - [MapQuest Documentation]("https://developer.mapquest.com/documentation/geocoding-api/) # Installation ` pkg> add Geocoder` # Usage ```julia using JuliaMaps geocode("Address", "Api Key", "method") ```` Right now, JuliaMaps.jl supports only two methods: `google` and `osm`. `google` as method supports api from google maps, and `osm` supports api from Open Streets Map. For example: ```julia geocode("1600 Amphitheatre Parkway, Mountain View, CA", "API Key", "method") ``` For a vector, it'd be required to use [broadcasting](https://julia.guide/broadcasting) feature. For example: ```julia geocode.(addresses, "API Key", "method") ``` `geocode()` will call the data from Google Maps API. For printing coordinates of longitudes and latitudes, execute `geometry(geocode_output)`. Example: ```julia geocode_output = geocode("1600 Amphitheatre Parkway, Mountain View, CA", "API Key", "method") geometry(geocode_output) ``` It is also possible to print only longitudes and only latitudes using `longitude(geocode_output)` and `latitude(geocode_output)` # Credits Thanks to [@dzonimn](https://github.com/dzonimn) for help in writing and checkin the functions.
Geocoder
https://github.com/arubhardwaj/Geocoder.jl.git
[ "MIT" ]
0.1.0
e89bd057bffc25399668e48067458eb93a12998e
code
594
using StaticTrafficAssignment using Documenter makedocs(; modules=[StaticTrafficAssignment], authors="Sai Kiran Mayakuntla", repo="https://github.com/SaiKiran92/StaticTrafficAssignment.jl/blob/{commit}{path}#L{line}", sitename="StaticTrafficAssignment.jl", format=Documenter.HTML(; prettyurls=get(ENV, "CI", "false") == "true", canonical="https://SaiKiran92.github.io/StaticTrafficAssignment.jl", assets=String[], ), pages=[ "Home" => "index.md", ], ) deploydocs(; repo="github.com/SaiKiran92/StaticTrafficAssignment.jl", )
StaticTrafficAssignment
https://github.com/SaiKiran92/StaticTrafficAssignment.jl.git
[ "MIT" ]
0.1.0
e89bd057bffc25399668e48067458eb93a12998e
code
585
module StaticTrafficAssignment using DataFrames: nrow using LightGraphs: Edge, add_edge!, edges, src, dst, nv, ne using LightGraphs.Parallel: dijkstra_shortest_paths using MetaGraphs: MetaDiGraph, set_prop!, set_props!, get_prop, props using SparseArrays: sparse export readtntpdata, CostFunctionGenerator, ProblemType, UEProblem, SOProblem, BPR, allornothing, frankwolfe include("utils.jl") include("data_loaders/TNTP_loader.jl") include("costfunctions/generator.jl") include("costfunctions/bprfn.jl") include("algorithms/allornothing.jl") include("algorithms/frankwolfe.jl") end
StaticTrafficAssignment
https://github.com/SaiKiran92/StaticTrafficAssignment.jl.git
[ "MIT" ]
0.1.0
e89bd057bffc25399668e48067458eb93a12998e
code
408
Base.convert(::Type{Tuple}, e::Edge) = (src(e), dst(e)) Base.:*(d::Dict, p::Real) = Dict(k => (v*p) for (k,v) in d) Base.zero(d::Dict) = d * 0. NamedTuple(d::Dict) = (; zip(keys(d), values(d))...) function bisection(fn; a=0., b=1., ϵ=1e-05) μ = 0. while (b - a) > ϵ μ = 0.5*(a + b) if fn(μ) > 0 b = μ else a = μ end end return μ end
StaticTrafficAssignment
https://github.com/SaiKiran92/StaticTrafficAssignment.jl.git
[ "MIT" ]
0.1.0
e89bd057bffc25399668e48067458eb93a12998e
code
1706
function allornothing(network::MetaDiGraph, trips::Array{<:Real,2}, costs::Array) # Initialization nnodes = nv(network) nzones = get_prop(network, :nzones) flows = zeros(ne(network)) # Making cost matrix costmx = sparse([], [], Float64[], nnodes, nnodes) #costmx = zeros(nnodes, nnodes) for (c,e) in zip(costs,edges(network)) costmx[src(e),dst(e)] = c end flowmx = zero(costmx) # for computational purposes # Computing shortest paths shortpaths = dijkstra_shortest_paths(network, 1:nzones, costmx) parentmx = shortpaths.parents # Determining flows tripswaiting = copy(trips) for orig in 1:nzones for dest in 1:nzones t = tripswaiting[orig,dest] if isapprox(t, 0.) continue end tripswaiting[orig,dest] = 0. # Finding the shortest path path = [dest] currnode = dest while currnode != orig prevnode = parentmx[orig,currnode] currnode = prevnode push!(path, currnode) end # Assigning flows currnode = orig for nextnode in path[(end-1):-1:1] flowmx[currnode, nextnode] += t t += tripswaiting[nextnode,dest] tripswaiting[nextnode,dest] = 0. currnode = nextnode end end end for (i,e) in enumerate(edges(network)) flows[i] = flowmx[src(e),dst(e)] end return flows end allornothing(network::MetaDiGraph, trips::Array{<:Real,2}, costfn::Function) = allornothing(network, trips, costfn(zeros(ne(network))).costs)
StaticTrafficAssignment
https://github.com/SaiKiran92/StaticTrafficAssignment.jl.git
[ "MIT" ]
0.1.0
e89bd057bffc25399668e48067458eb93a12998e
code
718
function frankwolfe(network::MetaDiGraph, trips::Array{<:Real,2}, costfn::Function; reltol=1e-04) # initialize flows = allornothing(network, trips, costfn) relerr = 1 while relerr > reltol # compute costs costs = costfn(flows)[:costs] # update flows ## calculate shortpathflows shortpathflows = allornothing(network, trips, costs) ## determining μ μ = bisection((μ) -> sum(costfn(μ * shortpathflows + (1 - μ) * flows).costs .* (shortpathflows - flows))) ## update flows += μ * (shortpathflows - flows) # relerr update relerr = sum(flows .* costs)/sum(shortpathflows .* costs) - 1 end return flows end
StaticTrafficAssignment
https://github.com/SaiKiran92/StaticTrafficAssignment.jl.git
[ "MIT" ]
0.1.0
e89bd057bffc25399668e48067458eb93a12998e
code
243
function BPR(data) b, C, F, p = data[:b], data[:capacity], data[:free_flow_time], data[:power] fn(x) = F*(1 + b*(x/C)^p) dfn(x) = F*b*(p/C)*(x/C)^(p-1) ddfn(x) = F*b*(p*(p-1)/(C^2))*(x/C)^(p-2) return (fn, dfn, ddfn) end
StaticTrafficAssignment
https://github.com/SaiKiran92/StaticTrafficAssignment.jl.git
[ "MIT" ]
0.1.0
e89bd057bffc25399668e48067458eb93a12998e
code
2180
struct CostFunctionGenerator <: Function times::Function dtimes::Function ddtimes::Function function CostFunctionGenerator(network, timefn) fns = [] dfns = [] ddfns = [] for e in edges(network) edata = props(network, e) rv = timefn(edata) push!(fns, rv[1]) try push!(dfns, rv[2]) catch push!(dfns, nothing) end try push!(ddfns, rv[3]) catch push!(ddfns, nothing) end end times(x) = [fn(xi) for (fn,xi) in zip(fns,x)] dtimes(x) = [((dfn == nothing) ? nothing : dfn(xi)) for (dfn,xi) in zip(dfns,x)] ddtimes(x) = [((ddfn == nothing) ? nothing : ddfn(xi)) for (ddfn,xi) in zip(ddfns,x)] return new(times, dtimes, ddtimes) end end abstract type ProblemType end abstract type UEProblem <: ProblemType end abstract type SOProblem <: ProblemType end function (f::CostFunctionGenerator)(::Type{UEProblem}) function fn(x::Array{<:Real,1}; returntsc::Bool=false, returnhessian::Bool=false, tolls=nothing) times = f.times(x) rv = Dict() rv[:costs] = times if tolls != nothing rv[:costs] += tolls end if returntsc rv[:tsc] = totalsystemcost(x, times) end if returnhessian rv[:hessian] = Diagonal(f.dtimes(x)) end return NamedTuple(rv) end fn end function (f::CostFunctionGenerator)(::Type{SOProblem}) function fn(x::Array{<:Real,1}; returntsc=true, returnhessian=false) times = f.times(x) dtimes = f.dtimes(x) rv = Dict() rv[:costs] = times .+ x .* dtimes if returntsc rv[:tsc] = totalsystemcost(x, times) end if returnhessian rv[:hessian] = Diagonal(2 * dtimes + x .* f.ddtimes(x)) end return NamedTuple(rv) end fn end totalsystemcost(x::Array{<:Real,1}, timesfn::Function) = sum(x .* timesfn(x)) totalsystemcost(x::Array{<:Real,1}, times::Array{<:Real,1}) = sum(x .* times)
StaticTrafficAssignment
https://github.com/SaiKiran92/StaticTrafficAssignment.jl.git
[ "MIT" ]
0.1.0
e89bd057bffc25399668e48067458eb93a12998e
code
4461
using CSV: read struct InputError <: Exception s::String end Base.showerror(io::IO, ex::InputError) = print(io, ex.s) # helper function function readvalue(io, s::String, dtype=Int) l = strip(readline(io)) occursin(s, l) || throw(InputError(filepath)) parse(dtype, split(l)[end]) end function readnettntp(filepath::String; _dtypes = Dict(:init_node => Int, :term_node => Int, :capacity => Float64, :length => Float64, :free_flow_time => Float64, :power => Float64, :b => Float64, :speed => Float64, :toll => Float64, :link_type => Int)) # reading metadata nzones, nnodes, ftnode, nlinks, headerrow = open(filepath) do io nzones = readvalue(io, "<NUMBER OF ZONES>") nnodes = readvalue(io, "<NUMBER OF NODES>") ftnode = readvalue(io, "<FIRST THRU NODE>") nlinks = readvalue(io, "<NUMBER OF LINKS>") headerrow = 4 while(headerrow += 1; ((line = strip(readline(io))) == "") || !startswith(line, "~")) if eof(io) throw(InputError("network data")) end end return (nzones, nnodes, ftnode, nlinks, headerrow) end # reading network-link data linkdf = read(filepath, skipto=headerrow+1, header=headerrow, types=_dtypes) linkdf = linkdf[:,2:(end-1)] return (nzones, nnodes, ftnode, nlinks, linkdf) end function readtriptntp(filepath::String) nzones, totalflow, trips = open(filepath) do io # reading metadata nzones = readvalue(io, "<NUMBER OF ZONES>") totalflow = readvalue(io, "<TOTAL OD FLOW>", Float64) # reading trip data while (line = strip(readline(io)); ~occursin("Origin", line)) end trips = zeros(nzones, nzones) i = parse(Int, split(line)[end]) while !eof(io) line = strip(readline(io)) if occursin("Origin", line) i = parse(Int, split(line)[end]) elseif (line == "") else line = line[1:(end - (line[end] == ';'))] for traw in split(line, ";") ttmp = split(traw) trips[i, parse(Int, ttmp[1])] = parse(Float64, ttmp[end]) end end end return (nzones, totalflow, trips) end return (nzones, totalflow, trips) end function readnodetntp(filepath::String) data = read(filepath) data = data[:, 1:(end-1)] return data end readflowtntp(filepath::String) = read(filepath) function readtntpdata(folderpath::String) contents = filter((f) -> endswith(f, ".tntp"), readdir(folderpath)) filetypes = [:net, :trips, :flow, :node] filepaths = Dict() for ft in filetypes files = filter(x -> endswith(x, "_$ft.tntp"), contents) if length(files) > 1 throw("More than one $ft files found in the folder!") elseif length(files) == 0 throw("No $ft files found in the folder!") else f = files[1] end filepaths[ft] = folderpath*f end nzones, nnodes, ftnode, nlinks, linkdf = readnettntp(filepaths[:net]) nzones2, totalflow, trips = readtriptntp(filepaths[:trips]) @assert nzones == nzones2 "Number of zones inconsistent" @assert totalflow ≈ sum(trips) "Number of trips inconsistent" @assert nlinks == nrow(linkdf) "Number of links inconsistent" @assert all((1 .<= linkdf.init_node .<= nnodes) .& (1 .<= linkdf.term_node .<= nnodes)) "Number of nodes inconsistent" @assert ftnode <= nnodes "First through node inconsistent" # building the network network = MetaDiGraph(nnodes) set_prop!(network, :nzones, nzones) for row in eachrow(linkdf) e = Edge(row[:init_node], row[:term_node]) add_edge!(network, e) set_props!(network, e, Dict(Symbol(n) => row[n] for n in names(row) if ~(n in (row[:init_node], row[:term_node])))) end if :node in keys(filepaths) geometry = readnodetntp(filepaths[:node]) set_prop!(network, :geometry, geometry) end bestsolution = nothing if :flow in keys(filepaths) bestsolution = readflowtntp(filepaths[:flow]) @assert nlinks == nrow(bestsolution) "Number of links inconsistent with flow file" end return (network = network, trips = trips, firstthroughnode = ftnode, bestsolution = bestsolution) end
StaticTrafficAssignment
https://github.com/SaiKiran92/StaticTrafficAssignment.jl.git
[ "MIT" ]
0.1.0
e89bd057bffc25399668e48067458eb93a12998e
code
119
using StaticTrafficAssignment using Test @testset "StaticTrafficAssignment.jl" begin # Write your tests here. end
StaticTrafficAssignment
https://github.com/SaiKiran92/StaticTrafficAssignment.jl.git
[ "MIT" ]
0.1.0
e89bd057bffc25399668e48067458eb93a12998e
docs
1416
# StaticTrafficAssignment [![Build Status](https://travis-ci.org/SaiKiran92/StaticTrafficAssignment.jl.svg?branch=master)](https://travis-ci.org/SaiKiran92/StaticTrafficAssignment.jl) [![Coverage](https://codecov.io/gh/SaiKiran92/StaticTrafficAssignment.jl/branch/master/graph/badge.svg)](https://codecov.io/gh/SaiKiran92/StaticTrafficAssignment.jl) [![Stable](https://img.shields.io/badge/docs-stable-blue.svg)](https://SaiKiran92.github.io/StaticTrafficAssignment.jl/stable) [![Dev](https://img.shields.io/badge/docs-dev-blue.svg)](https://SaiKiran92.github.io/StaticTrafficAssignment.jl/dev) This package contains functions to load road network data in TNTP format. Check out [this GitHub repository](https://github.com/bstabler/TransportationNetworks) to learn more about the format and download some standard networks. I have implemented two assignment algorithms: All-Or-Nothing and Frank-Wolfe. More will be coming soon. No support yet for nodes that do not allow through flows, i.e. for networks with \<FIRST THRU NODE\> > 1 (in \*_net.tntp). Custom delay functions are supported. Both UE and SO assignments can be easily calculated. Sorry about the lack of documentation. But I think the package is pretty readable for anyone with some experience with Julia. Will try to add a couple more examples soon. ## Coming soon ### Algorithms - Conjugate Frank-Wolfe - Biconjugate Frank-Wolfe - Algorithm B
StaticTrafficAssignment
https://github.com/SaiKiran92/StaticTrafficAssignment.jl.git
[ "MIT" ]
0.1.0
e89bd057bffc25399668e48067458eb93a12998e
docs
149
```@meta CurrentModule = StaticTrafficAssignment ``` # StaticTrafficAssignment ```@index ``` ```@autodocs Modules = [StaticTrafficAssignment] ```
StaticTrafficAssignment
https://github.com/SaiKiran92/StaticTrafficAssignment.jl.git
[ "MIT" ]
0.1.0
e89bd057bffc25399668e48067458eb93a12998e
docs
4563
# Sioux Falls Network WARNING: The Sioux-Falls network is not considered as a realistic one. However, this network was used in many publications. It is good for code debugging. ## Source / History Via: [http://www.bgu.ac.il/~bargera/tntp/](http://www.bgu.ac.il/~bargera/tntp/) All network data including the link numbers indicated on the map (but excluding node coordinates), are taken from the following paper: “An efficient approach to solving the road network equilibrium traffic assignment problem” by LeBlanc, L.J., Morlok, E.K., Pierskalla, W.P., Transportation Research Vol. 9, pp. 309-318, 1975. The links in the network file are sorted by their tail node, thus they do not follow the same order as the original publication. OD flows in the original paper (Table 1) are given in thousands of vehicles per day, with integer values up to 44. OD flows here are the values form the table multiplied by 100. They are therefore 0.1 of the original daily flows, and in that sense might be viewed as approximate hourly flows. This conversion was done to enable comparison of objective values with papers published during the 1980's and the 1990's. The units of free flow travel times are 0.01 hours, but they are often viewed as if they were minutes. Link lengths are set arbitrarily equal to free flow travel times. The parameters in the paper are given in the format of `t=a+b*flow^4`. The original parameter a is the free flow travel time given here. The original parameter b is equal to (free flow travel time)*B/(capacity^Power) in the format used here. In the data here the “traditional” BPR value of B=0.15 is assumed, and the given capacities are computed accordingly. Node coordinates were generated artificially to reproduce the diagram shown in the paper. [Walter Wong](mailto://[email protected]) points out that another version of the Sioux-Falls network appears in a different publication, “An algorithm for the Discrete Network,” LeBlanc, L.J., Transportation Science, Vol 9, pp 183-199, 1975. The difference between the two versions is that the free-flow travel times on links 15-19, 19-15, 15-22 and 22-15 are 4 instead of 3, and the free-flow travel time on links 10-16 and 16-10 are 5 instead of 4. [Andrew Koh](mailto://[email protected]) reports that a third version of the Sioux-Falls network has appeared in “Equilibrium Decomposed Optimization: A Heuristic for the Continuous Equilibrium Network Design Problem,” Suwansirikul, C., Friesz, T.L., Tobin, R.L., Transportation Science, Vol. 21(4), 1987, pp. 254-263. Click here for a list of differences between the two versions. [Gregor Laemmel](mailto://[email protected]) reports that the first published version of the Sioux-Falls network appears in "Development and Application of a Highway Network Design Model - Volumes 1 and 2," Morlok, E.K., Schofer, J.L., Pierskalla, Marsten, R.E., W.P., Agarwal, S.K., Stoner, J.W., Edwards, J.L., LeBlanc, L.J., and Spacek, D.T., Final Report to the Federal Highway Administration under contract number DOT-FH-11-7862, Department of Civil Engineering, Northwestern University, Evanston, Illinois, July 1973. Link lengths (in miles) are given the following file: Sioux-Falls Network, which is identical to the first version given here in all other attributes. [David Boyce](mailto://[email protected]) comments that yet another slightly different version of the Sioux Falls network appears in LeBlanc’s Ph.D. thesis. The main difference from the published paper version is that flows in the published paper are multiplied by 100, rounded in an unclear manner, and presented as integers, while flows in the thesis are in tenths. See also: [Sioux Falls Variants for Network Design](http://www.bgu.ac.il/~bargera/tntp/SiouxFalls_CNDP/SiouxFallsVariantsForNetworkDesign.html) ## Scenario ## Contents - `SiouxFalls_net.tntp` Network - `SiouxFalls_trips.tntp` Demand - `SiouxFalls_node.tntp` Node Coordinates - `SiouxFalls_flow.tntp` Best known flow solution - `Sioux-Falls-Network.pdf` Picture of Network - `SiouxFallsMap_AAA1998.jpg` Picture of actual Sioux Falls from 1998 ## Dimensions Zones: 24 Nodes: 24 Links: 76 Trips: 360,600.0 ## Units Time: Distance: Speed: Cost: Coordinates: ## Generalized Cost Weights Toll: 0 Distance: 0 ## Solutions `SiouxFalls_flow.tntp` contains best known link flows solution with Average Excess Cost (normalized gap) of 3.9E-15. Optimal objective function value: 42.31335287107440 ## Known Issues FIXME translate to Github Issues
StaticTrafficAssignment
https://github.com/SaiKiran92/StaticTrafficAssignment.jl.git
[ "MIT" ]
0.16.5
7c4d085f436b699e746e19173a3c640a79ceec8a
code
2268
using Documenter, Literate, RegularizedLeastSquares # Generate examples OUTPUT_BASE = joinpath(@__DIR__(), "src/generated") INPUT_BASE = joinpath(@__DIR__(), "src/literate") for (_, dirs, _) in walkdir(INPUT_BASE) for dir in dirs OUTPUT = joinpath(OUTPUT_BASE, dir) INPUT = joinpath(INPUT_BASE, dir) for file in filter(f -> endswith(f, ".jl"), readdir(INPUT)) Literate.markdown(joinpath(INPUT, file), OUTPUT) end end end makedocs( format = Documenter.HTML(; prettyurls=get(ENV, "CI", "false") == "true", canonical="https://github.com/JuliaImageRecon/RegularizedLeastSquares.jl", assets=String[], collapselevel=1, ), repo="https://github.com/JuliaImageRecon/RegularizedLeastSquares.jl/blob/{commit}{path}#{line}", modules = [RegularizedLeastSquares], sitename = "RegularizedLeastSquares.jl", authors = "Tobias Knopp, Mirco Grosser, Martin Möddel, Niklas Hackelberg, Andrew Mao, Jakob Assländer", pages = [ "Home" => "index.md", "Getting Started" => "generated/examples/getting_started.md", "Examples" => Any["Compressed Sensing" => "generated/examples/compressed_sensing.md", "Computed Tomography" => "generated/examples/computed_tomography.md"], "Solvers" => "solvers.md", "Regularization" => "generated/explanations/regularization.md", "How to" => Any[ "Weighting" => "generated/howto/weighting.md", "Normal Operator" => "generated/howto/normal_operator.md", "Multi-Threading" => "generated/howto/multi_threading.md", "GPU Acceleration" => "generated/howto/gpu_acceleration.md", "Efficient Kaczmarz" => "generated/howto/efficient_kaczmarz.md", "Callbacks" => "generated/howto/callbacks.md", "Plug-and-Play Regularization" => "generated/howto/plug-and-play.md" ], "API Reference" => Any["Solvers" => "API/solvers.md", "Regularization Terms" => "API/regularization.md"], ], pagesonly = true, checkdocs = :none, doctest = false, doctestfilters = [r"(\d*)\.(\d{4})\d+"] ) deploydocs(repo = "github.com/JuliaImageRecon/RegularizedLeastSquares.jl.git", push_preview = true)
RegularizedLeastSquares
https://github.com/JuliaImageRecon/RegularizedLeastSquares.jl.git
[ "MIT" ]
0.16.5
7c4d085f436b699e746e19173a3c640a79ceec8a
code
3371
# # Compressed Sensing Example # In this example we will go through a simple example from the field of Compressed Sensing. # In addtion to RegularizedLeastSquares.jl, we will need the packages [LinearOperatorCollection.jl](https://github.com/JuliaImageRecon/LinearOperatorCollection.jl), [ImagePhantoms.jl](https://github.com/JuliaImageRecon/ImagePhantoms.jl), [ImageGeoms.jl](https://github.com/JuliaImageRecon/ImageGeoms.jl) and Random.jl, as well as [CairoMakie.jl](https://docs.makie.org/stable/) for visualization. We can install them the same way we did RegularizedLeastSquares.jl. # ## Preparing the Inverse Problem # To get started, let us generate a simple phantom using the ImagePhantoms and ImageGeom packages: using ImagePhantoms, ImageGeoms N = 256 image = shepp_logan(N, SheppLoganToft()) size(image) # This produces a 256x256 image of a Shepp-Logan phantom. # In this example, we consider a problem in which we randomly sample a third of the pixels in the image. Such a problem and the corresponding measurement can be constructed with the packages LinearOperatorCollection and Random: # We first randomly shuffle the indices of the image and then select the first third of the indices to sample. using Random, LinearOperatorCollection randomIndices = shuffle(eachindex(image)) sampledIndices = sort(randomIndices[1:div(end, 3)]) # Afterwards we build a sampling operator which samples the image at the selected indices. A = SamplingOp(eltype(image), pattern = sampledIndices , shape = size(image)); # Then we apply the sampling operator to the vectorized image to obtain the sampled measurement vector b = A*vec(image); # To visualize our image we can use CairoMakie: using CairoMakie function plot_image(figPos, img; title = "", width = 150, height = 150) ax = CairoMakie.Axis(figPos; yreversed=true, title, width, height) hidedecorations!(ax) heatmap!(ax, img) end fig = Figure() plot_image(fig[1,1], image, title = "Image") samplingMask = fill(false, size(image)) samplingMask[sampledIndices] .= true plot_image(fig[1,2], image .* samplingMask, title = "Sampled Image") resize_to_layout!(fig) fig # As we can see in the right image, only a third of the pixels are sampled. The goal of the inverse problem is to recover the original image from this measurement vector. # ## Solving the Inverse Problem # To recover the image from the measurement vector, we solve the TV-regularized least squares problem: # ```math # \begin{equation} # \underset{\mathbf{x}}{argmin} \frac{1}{2}\vert\vert \mathbf{A}\mathbf{x}-\mathbf{b} \vert\vert_2^2 + \lambda\vert\vert\mathbf{x}\vert\vert_{\text{TV}} . # \end{equation} # ``` # For this purpose we build a TV regularizer with regularization parameter $λ=0.01$ using RegularizedLeastSquares reg = TVRegularization(0.01; shape=size(image)); # We will use the Fast Iterative Shrinkage-Thresholding Algorithm (FISTA) to solve our inverse problem. Thus, we build the corresponding solver solver = createLinearSolver(FISTA, A; reg=reg, iterations=20); # and apply it to our measurement vector img_approx = solve!(solver,b) # To visualize the reconstructed image, we need to reshape the result vector to the correct shape. Afterwards we can use CairoMakie again: img_approx = reshape(img_approx,size(image)); plot_image(fig[1,3], img_approx, title = "Reconstructed Image") resize_to_layout!(fig) fig
RegularizedLeastSquares
https://github.com/JuliaImageRecon/RegularizedLeastSquares.jl.git
[ "MIT" ]
0.16.5
7c4d085f436b699e746e19173a3c640a79ceec8a
code
3373
# # Computed Tomography Example # In this example we will go through a simple example from the field of Computed Tomography. # In addtion to RegularizedLeastSquares.jl, we will need the packages [LinearOperatorCollection.jl](https://github.com/JuliaImageRecon/LinearOperatorCollection.jl), [ImagePhantoms.jl](https://github.com/JuliaImageRecon/ImagePhantoms.jl), [ImageGeoms.jl](https://github.com/JuliaImageRecon/ImageGeoms.jl) # and [RadonKA.jl](https://github.com/roflmaostc/RadonKA.jl/tree/main), as well as [CairoMakie.jl](https://docs.makie.org/stable/) for visualization. We can install them the same way we did RegularizedLeastSquares.jl. # RadonKA is a package for the computation of the Radon transform and its adjoint. It is implemented with KernelAbstractions.jl and supports GPU acceleration. See the GPU acceleration [how-to](../howto/gpu_acceleration.md) for more information. # ## Preparing the Inverse Problem # To get started, let us generate a simple phantom using the ImagePhantoms and ImageGeom packages: using ImagePhantoms, ImageGeoms N = 256 image = shepp_logan(N, SheppLoganToft()) size(image) # This produces a 256x256 image of a Shepp-Logan phantom. using RadonKA, LinearOperatorCollection angles = collect(range(0, π, 256)) sinogram = Array(RadonKA.radon(image, angles)) # Afterwards we build a Radon operator implementing both the forward and adjoint Radon transform A = RadonOp(eltype(image); angles, shape = size(image)); # To visualize our image we can use CairoMakie: using CairoMakie function plot_image(figPos, img; title = "", width = 150, height = 150) ax = CairoMakie.Axis(figPos[1, 1]; yreversed=true, title, width, height) hidedecorations!(ax) hm = heatmap!(ax, img) Colorbar(figPos[2, 1], hm, vertical = false, flipaxis = false) end fig = Figure() plot_image(fig[1,1], image, title = "Image") plot_image(fig[1,2], sinogram, title = "Sinogram") plot_image(fig[1,3], backproject(sinogram, angles), title = "Backprojection") resize_to_layout!(fig) fig # In the figure we can see our original image, the sinogram, and the backprojection of the sinogram. The goal of the inverse problem is to recover the original image from the sinogram. # ## Solving the Inverse Problem # To recover the image from the measurement vector, we solve the $l^2_2$-regularized least squares problem # ```math # \begin{equation} # \underset{\mathbf{x}}{argmin} \frac{1}{2}\vert\vert \mathbf{A}\mathbf{x}-\mathbf{b} \vert\vert_2^2 + \lambda\vert\vert\mathbf{x}\vert\vert^2_2 . # \end{equation} # ``` # For this purpose we build a $l^2_2$ with regularization parameter $λ=0.001$ using RegularizedLeastSquares reg = L2Regularization(0.001); # To solve this inverse problem, the Conjugate Gradient Normal Residual (CGNR) algorithm can be used. This solver is based on the normal operator of the Radon operator and uses both the forward and adjoint Radon transform internally. # We now build the corresponding solver solver = createLinearSolver(CGNR, A; reg=reg, iterations=20); # and apply it to our measurement vector img_approx = solve!(solver, vec(sinogram)) # To visualize the reconstructed image, we need to reshape the result vector to the correct shape. Afterwards we can use CairoMakie again: img_approx = reshape(img_approx,size(image)); plot_image(fig[1,4], img_approx, title = "Reconstructed Image") resize_to_layout!(fig) fig
RegularizedLeastSquares
https://github.com/JuliaImageRecon/RegularizedLeastSquares.jl.git
[ "MIT" ]
0.16.5
7c4d085f436b699e746e19173a3c640a79ceec8a
code
2281
# # Getting Started # In this example we will go through a simple random inverse problem to get familiar with RegularizedLeastSquares.jl. # ## Installation # To install RegularizedLeastSquares.jl, you can use the Julia package manager. Open a Julia REPL and run the following command: # ```julia # using Pkg # Pkg.add("RegularizedLeastSquares") # ``` # This will download and install the RegularizedLeastSquares.jl package and its dependencies. To install a different version, please consult the [Pkg documentation](https://pkgdocs.julialang.org/dev/managing-packages/#Adding-packages). # Once the installation is complete, you can import the package with the `using` keyword: using RegularizedLeastSquares # RegularizedLeastSquares aims to solve inverse problems of the form: # ```math # \begin{equation} # \underset{\mathbf{x}}{argmin} \frac{1}{2}\vert\vert \mathbf{A}\mathbf{x}-\mathbf{b} \vert\vert_2^2 + \mathbf{R(x)} . # \end{equation} # ``` # where $\mathbf{A}$ is a linear operator, $\mathbf{b}$ is the measurement vector, and $\mathbf{R(x)}$ is an (optional) regularization term. # The goal is to retrieve an approximation of the unknown vector $\mathbf{x}$. In this first exampel we will just work with simple random arrays. For more advanced examples, please refer to the examples. A = rand(32, 16) x = rand(16) b = A*x; # To approximate x from b, we can use the Conjugate Gradient Normal Residual (CGNR) algorithm. We first build the corresponding solver: solver = createLinearSolver(CGNR, A; iterations=32); # and apply it to our measurement vector x_approx = solve!(solver, b) isapprox(x, x_approx, rtol = 0.001) # Usually the inverse problems are ill-posed and require regularization. RegularizedLeastSquares.jl provides a variety of regularization terms. # The CGNR algorithm can solve optimzation problems of the form: # ```math # \begin{equation} # \underset{\mathbf{x}}{argmin} \frac{1}{2}\vert\vert \mathbf{A}\mathbf{x}-\mathbf{b} \vert\vert_2^2 + \lambda\vert\vert\mathbf{x}\vert\vert^2_2 . # \end{equation} # ``` # The corresponding solver can be built with the $l^2_2$-regularization term: solver = createLinearSolver(CGNR, A; reg = L2Regularization(0.0001), iterations=32); x_approx = solve!(solver, b) isapprox(x, x_approx, rtol = 0.001)
RegularizedLeastSquares
https://github.com/JuliaImageRecon/RegularizedLeastSquares.jl.git
[ "MIT" ]
0.16.5
7c4d085f436b699e746e19173a3c640a79ceec8a
code
4708
# # Regularization # When formulating inverse problems, a regulariser is formulated as an additional cost function which has to be minimised. # Many algorithms deal with a regularizers $g$, by computing the proximal map: # ```math # \begin{equation} # prox_g (\mathbf{x}) = \underset{\mathbf{u}}{argmin} \frac{1}{2}\vert\vert \mathbf{u}-\mathbf{x} \vert {\vert}^2 + g(\mathbf{x}). # \end{equation} # ``` # For many regularizers, the proximal map can be computed efficiently in a closed form. # In order to implement these proximal mappings, RegularizedLeastSquares.jl defines the following type hierarchy: # ```julia # abstract type AbstractRegularization # prox!(reg::AbstractRegularization, x) # norm(reg::AbstractRegularization, x) # ``` # Here `prox!(reg, x)` is an in-place function which computes the proximal map on the input-vector `x`. The function `norm` computes the value of the corresponding term in the inverse problem. RegularizedLeastSquares.jl provides `AbstractParameterizedRegularization` and `AbstractProjectionRegularization` as core regularization types. # ## Parameterized Regularization Terms # This group of regularization terms features a regularization parameter `λ` that is used during the `prox!` and `norm `computations. Examples of this regulariztion group are `L1`, `L2` or `LLR` (locally low rank) regularization terms. # These terms are constructed by supplying a `λ` and optionally term specific keyword arguments: using RegularizedLeastSquares l2 = L2Regularization(0.3) # Parameterized regularization terms implement: # ```julia # prox!(reg::AbstractParameterizedRegularization, x, λ) # norm(reg::AbstractParameterizedRegularization, x, λ) # ``` # where `λ` by default is filled with the value used during construction. # Invoking `λ` on a parameterized term retrieves its regularization parameter. This can be used in a solver to scale and overwrite the parameter as follows: prox!(l2, [1.0]) # param = λ(l2) prox!(l2, [1.0], param*0.2) # ## Projection Regularization Terms # This group of regularization terms implement projections, such as a positivity constraint or a projection with a given convex projection function. # These are essentially proximal maps where $g(\mathbf{x})$ is the indicator function of a convex set. positive = PositiveRegularization() prox!(positive, [2.0, -0.2]) # ## Nested Regularization Terms # Nested regularization terms are terms that act as decorators to the core regularization terms. # These terms can be nested around other terms and add functionality to a regularization term, such as scaling `λ` based on the provided operator or applying a transform, such as the Wavelet, to `x`. # As an example, we can nest a `L1` regularization term around a `Wavelet` operator. # First we generate an image and apply a wavelet operator to it: using Wavelets, LinearOperatorCollection, ImagePhantoms, ImageGeoms N = 256 image = shepp_logan(N, SheppLoganToft()) wop = WaveletOp(Float32, shape = size(image)) wavelet_image = reshape(wop*vec(image), size(image)) wavelet_image = log.(abs.(wavelet_image) .+ 0.01) # We will use CairoMakie for visualization: using CairoMakie function plot_image(figPos, img; title = "", width = 150, height = 150) ax = CairoMakie.Axis(figPos; yreversed=true, title, width, height) hidedecorations!(ax) heatmap!(ax, img) end fig = Figure() plot_image(fig[1,1], image, title = "Image") plot_image(fig[1,2], wavelet_image, title = "Wavelet Image") resize_to_layout!(fig) fig # To apply soft-thresholding in the wavelet domain, we can nest a `L1` regularization term around the `Wavelet` operator: core = L1Regularization(0.1) reg = TransformedRegularization(core, wop); # We can then apply the proximal map to the image or the image in the wavelet domain: img_prox_image = prox!(core, copy(vec(image))); img_prox_wavelet = prox!(reg, copy(vec(image))); # We can visualize the result: img_prox_image = reshape(img_prox_image, size(image)) img_prox_wavelet = reshape(img_prox_wavelet, size(image)) plot_image(fig[1,3], img_prox_image, title = "Reg. Image Domain") plot_image(fig[1,4], img_prox_wavelet, title = "Reg. Wavelet Domain") resize_to_layout!(fig) fig # Generally, regularization terms can be nested arbitrarly deep, adding new functionality with each layer. Each nested regularization term can return its `inner` regularization term. # Furthermore, all regularization terms implement the iteration interface to iterate over the nesting. The innermost regularization term of a nested term must be a core regularization term and it can be returned by the `sink` function: RegularizedLeastSquares.innerreg(reg) == core # sink(reg) == core # foreach(r -> println(nameof(typeof(r))), reg)
RegularizedLeastSquares
https://github.com/JuliaImageRecon/RegularizedLeastSquares.jl.git
[ "MIT" ]
0.16.5
7c4d085f436b699e746e19173a3c640a79ceec8a
code
2618
# # Callbacks # For certain optimization it is important to monitor the internal state of the solver. RegularizedLeastSquares.jl provides a callback mechanism to allow developres to access this state after each iteration. # The package provides a variety of default callbacks, which for example store the solution after each iteration. More information can be found in the API reference for the `solve!` function. # In this example we will revist the compressed sensing compressed sensing [example](../examples/compressed_sensing.md) and implement a custom callback using the do-syntax of the `solve!` function. # This allows us to implement our callback inline and access the solver state after each iteration. # We first recreate the operator `A` and the measurement vector `b`: using ImagePhantoms, ImageGeoms N = 256 image = shepp_logan(N, SheppLoganToft()) size(image) using Random, LinearOperatorCollection randomIndices = shuffle(eachindex(image)) sampledIndices = sort(randomIndices[1:div(end, 3)]) A = SamplingOp(eltype(image), pattern = sampledIndices , shape = size(image)); b = A*vec(image); # Next we prepare our visualization helper function: using CairoMakie function plot_image(figPos, img; title = "", width = 150, height = 150, clim = extrema(img)) ax = CairoMakie.Axis(figPos; yreversed=true, title, width, height) hidedecorations!(ax) heatmap!(ax, img, colorrange = clim) end # Now we construct the solver with the TV regularization term: using RegularizedLeastSquares reg = TVRegularization(0.01; shape=size(image)); solver = createLinearSolver(FISTA, A; reg=reg, iterations=20); # We will now implement a callback that plots the solution every four iteration: fig = Figure() idx = 1 solve!(solver, b) do solver, iteration if iteration % 4 == 0 img_approx = copy(solversolution(solver)) img_approx = reshape(img_approx, size(image)) plot_image(fig[div(idx -1, 3) + 1, mod1(idx, 3)], img_approx, clim = extrema(image), title = "$iteration") global idx += 1 end end # In the callback we have to copy the solution, as the solver will update it in place. # As is explained in the solver section, each features fields that are intended to be immutable during a `solve!` call and a state that is modified in each iteration. # Depending on the solvers parameters and the measurement input, the state can differ in its fields and their type. Ideally, one tries to avoid accessing the state directly and uses the provided functions to access the state. # The resulting figure shows the reconstructed image after 0, 4, 8, 12, 16 and 20 iterations: resize_to_layout!(fig) fig
RegularizedLeastSquares
https://github.com/JuliaImageRecon/RegularizedLeastSquares.jl.git
[ "MIT" ]
0.16.5
7c4d085f436b699e746e19173a3c640a79ceec8a
code
1972
# # Efficient Kaczmarz # Unlike many of the other solvers provided by RegularizedLeastSquares.jl, the Kaczmarz method does not utilize a matrix-vector product with the operator $\mathbf{A}$ nor the normal operator $\mathbf{A*A}$. Instead, it uses the rows of $\mathbf{A}$ to update the solution iteratively. # Efficient Kaczmarz implementation therefore require very efficient dot products with the rows of $\mathbf{A}$. In RegularizedLeastSquares.jl, this is achieved with the `dot_with_matrix_row` function. using RegularizedLeastSquares A = randn(256, 256) x = randn(256) b = A*x; # The `dot_with_matrix_row` function calculates the dot product between a row of A and the current approximate solution of x: row = 1 isapprox(RegularizedLeastSquares.dot_with_matrix_row(A, x, row), sum(A[row, :] .* x)) # Since in Julia, dense arrays are stored in column-major order, such a row-based operation is quite inefficient. A workaround is to transpose the matrix then pass it to a Kaczmarz solver. At = collect(transpose(A)) A_eff = transpose(At) # Note that the transpose function can return a lazy transpose object, so we first collect the transpose into a dense matrix. # Then we transpose it again to get the efficient representation of the matrix. # We can compare the performance using the BenchmarkTools.jl package. First for the original matrix: using BenchmarkTools solver = createLinearSolver(Kaczmarz, A; reg = L2Regularization(0.0001), iterations=100) @benchmark solve!(solver, b) samples = 100 # And then for the efficient matrix: solver_eff = createLinearSolver(Kaczmarz, A_eff; reg = L2Regularization(0.0001), iterations=100) @benchmark solve!(solver_eff, b) samples = 100 # We can also combine the efficient matrix with a weighting matrix, as is shown in the [Weighting](weighting.md) example. # Custom operators need to implement the `dot_with_matrix_row` function to be used with the Kaczmarz solver. Ideally, such an implementation is allocation free.
RegularizedLeastSquares
https://github.com/JuliaImageRecon/RegularizedLeastSquares.jl.git
[ "MIT" ]
0.16.5
7c4d085f436b699e746e19173a3c640a79ceec8a
code
3919
# # GPU Acceleration # RegularizedLeastSquares.jl supports generic GPU acceleration. This means that the user can use any GPU array type that supports the GPUArrays interface. This includes [CUDA.jl](https://github.com/JuliaGPU/CUDA.jl), [AMDGPU.jl](https://github.com/JuliaGPU/AMDGPU.jl), and [Metal.jl](https://github.com/JuliaGPU/Metal.jl). # In this example we will use the package JLArrays.jl which provides a reference implementation for GPUArrays, that can runs on CPUs. using JLArrays gpu = JLArray; # To use the following examples on an actual GPU, load the appropraite package replace `JLArray` with the respective GPU array type, for example: # ```julia # using CUDA # gpu = CuArray # ``` # At first we will look at an example of dense GPU arrays. using RegularizedLeastSquares A = gpu(rand(Float32, 32, 16)) x = gpu(rand(Float32, 16)) b = A*x; # Solvers adapt their states based on the type of the given measurement vector. This means that the solver will automatically switch to GPU acceleration if a GPU array is passed as the measurement vector. solver = createLinearSolver(CGNR, A; reg = L2Regularization(0.0001), iterations=32); x_approx = solve!(solver, b) # This adaption does not include the operator. So if we want to compare with CPU result, we need to construct a new solver with a CPU operator. solver = createLinearSolver(CGNR, Array(A); reg = L2Regularization(0.0001), iterations=32); x_cpu = solve!(solver, Array(b)) isapprox(Array(x_approx), x_cpu) # ## Matrix-Free Operators # A special case is the usage of matrix-free operators. Since these operators do not have a concrete matrix representation, their GPU support depends on their implementation. # Since not all multiplications within a solver approximation are in-place, the operator also needs to support the `*` operation and construct an appropriate result vector. # For matrix-free operators based on LinearOperators.jl, this can be achieved by implementing the `LinearOperators.storage_type` method. # In the following, we will take another look at the CS example and execute it on the GPU. Note that for the JLArray example we chose a small phantom, since the JLArray implementation is not optimized for performance: using ImagePhantoms, ImageGeoms N = 32 image = shepp_logan(N, SheppLoganToft()) using Random, LinearOperatorCollection randomIndices = shuffle(eachindex(image)) sampledIndices = sort(randomIndices[1:div(end, 3)]); # To construct the operator, we need to convert the indices to a GPU array. # We also need to specify the correct storage type. In both LinearOperators.jl and LinearOperatorCollection.jl this is done with the `S` keyword argument. gpu_indices = gpu(sampledIndices) A = SamplingOp(eltype(image), pattern = gpu_indices, shape = size(image), S = typeof(b)); # Let's inspect the storage type of the operator: using LinearOperatorCollection.LinearOperators LinearOperators.storage_type(A) # Afterwards we can use the operator as usual: b = A*vec(gpu(image)); # And use it in the solver: using RegularizedLeastSquares reg = TVRegularization(0.01; shape=size(image)) solver = createLinearSolver(FISTA, A; reg=reg, iterations=20) img_approx = solve!(solver,b); # To visualize the reconstructed image, we need to reshape the result vector to the correct shape and convert it to a CPU array: img_approx = reshape(Array(img_approx),size(image)) # We will again use CairoMakie for visualization: using CairoMakie function plot_image(figPos, img; title = "", width = 150, height = 150) ax = CairoMakie.Axis(figPos; yreversed=true, title, width, height) hidedecorations!(ax) heatmap!(ax, img) end fig = Figure() plot_image(fig[1,1], image, title = "Image") samplingMask = fill(false, size(image)) samplingMask[sampledIndices] .= true plot_image(fig[1,2], image .* samplingMask, title = "Sampled Image") plot_image(fig[1,3], img_approx, title = "Reconstructed Image") resize_to_layout!(fig) fig
RegularizedLeastSquares
https://github.com/JuliaImageRecon/RegularizedLeastSquares.jl.git
[ "MIT" ]
0.16.5
7c4d085f436b699e746e19173a3c640a79ceec8a
code
4030
# # Multi-Threading # There are different ways multi-threading can be used with RegularizedLeastSquares.jl. To use multi-threading in Julia, one needs to start their session with multi-threads, see the [Julia documentation](https://docs.julialang.org/en/v1/manual/multi-threading/) for more information. # ## Solver Based Multi-Threading # This type of multi-threading is transparent to the solver and is applicable if the total solution is composed of individual solutions that can be solved in parallel. # In particular, this approach also allows for using solvers with different parameters, such as their operator or regularization parameters. using RegularizedLeastSquares As = [rand(32, 16) for _ in 1:4] xs = [rand(16) for _ in 1:4] bs = [A*x for (A, x) in zip(As, xs)] xs_approx = similar(xs) Threads.@threads for i in 1:4 solver = createLinearSolver(CGNR, As[i]; iterations=32) xs_approx[i] = solve!(solver, bs[i]) end # ## Operator Based Multi-Threading # This type of multi-threading involves linear operators or proximal maps that can be implemnted in parallel. # Examples of this include the proximal map of the TV regularization term, which is based on the multi-threaded GradientOp from LinearOperatorCollection. # GPU acceleration also falls under this approach, see [GPU Acceleration](gpu_acceleration.md) for more information. # ## Measurement Based Multi-Threading # This level of multi-threading applies the same solver (and its parameters) to multiple measurement vectors or rather a measurement matrix B. # This is useful in the case of multiple measurements that can be solved in parallel and can reuse the same solver. This approach is not applicable if the operator is stateful. # To use this approach we first build a measurement matrix B and a corresponding solver: A = first(As) B = mapreduce(x -> A*x, hcat, xs) solver = createLinearSolver(CGNR, A; iterations=32) # We can then simply pass the measurement matrix to the solver. The result will be the same as if we passed each colument of B seperately: x_approx = solve!(solver, B) size(x_approx) # The previous `solve!` call was still executed sequentially. To execute it in parallel, we have to specify a multi-threaded `scheduler` as a keyword-argument of the `solve!` call. # RegularizedLeastSquares.jl provides a `MultiThreadingState` scheduler that can be used for this purpose. This scheduler is based on the `Threads.@threads` macro: x_multi = solve!(solver, B; scheduler = MultiThreadingState) x_approx == x_multi # ## Custom Scheduling # It is possible to implement custom scheduling. The following code shows how to implement this for the `Threads.@spawn` macro. Usually one this to implement multi-threading with a package such as FLoop.jl or ThreadPools.jl for thread pinning: # Since most solver have conv. criteria, they can finish at different iteration numbers, which we track this information with flags. mutable struct SpawnState{S, ST <: AbstractSolverState{S}} <: RegularizedLeastSquares.AbstractMatrixSolverState{S} states::Vector{ST} active::Vector{Bool} SpawnState(states::Vector{ST}) where {S, ST <: AbstractSolverState{S}} = new{S, ST}(states, fill(true, length(states))) end # To hook into the existing init! code we only have to supply a method that gets a copyable "vector" state. This will invoke our SpawnState constructor with copies of the given state. prepareMultiStates(solver::AbstractLinearSolver, state::SpawnState, b::AbstractMatrix) = prepareMultiStates(solver, first(state.states), b); # We specialise the iterate function which is called with the idx of still active states function Base.iterate(solver::AbstractLinearSolver, state::SpawnState, activeIdx) @sync Threads.@spawn for i in activeIdx res = iterate(solver, state.states[i]) if isnothing(res) state.active[i] = false end end return state.active, state end # Now we can simply use the SpawnState scheduler in the solve! call: x_custom = solve!(solver, B; scheduler = SpawnState) x_approx == x_multi
RegularizedLeastSquares
https://github.com/JuliaImageRecon/RegularizedLeastSquares.jl.git
[ "MIT" ]
0.16.5
7c4d085f436b699e746e19173a3c640a79ceec8a
code
3150
# # Normal Operator # Many solvers in RegularizedLeastSquares.jl are based on the normal operator $\mathbf{A}^*\mathbf{A}$ of the linear operator $\mathbf{A}$. # # Solvers such as ADMM, FISTA and POGM generally solve optimization problems of the form: # ```math # \begin{equation} # \underset{\mathbf{x}}{argmin} \mathbf{f(x)}+ \mathbf{R(x)} # \end{equation} # ``` # and require the gradient of the function $\mathbf{f(x)}$. In this package we specialise the function $\mathbf{f(x)}$ to the least squares norm: # ```math # \begin{equation} # \mathbf{f(x)} = \frac{1}{2}\vert\vert \mathbf{A}\mathbf{x}-\mathbf{b} \vert\vert^2_2 # \end{equation} # ``` # The gradient of this function is: # ```math # \begin{equation} # \nabla \mathbf{f(x)} = \mathbf{A}^*(\mathbf{A}\mathbf{x}-\mathbf{b}) = \mathbf{A}^*\mathbf{Ax} - \mathbf{A}^*\mathbf{b} # \end{equation} # ``` # Similarily, the conjugate gradient normal residual (CGNR) algorithm applies conjugate gradient algorithm to: # ```math # \begin{equation} # \mathbf{A}^*\mathbf{A}\mathbf{x} = \mathbf{A}^*\mathbf{b} # \end{equation} # ``` # The normal operator can be passed directly to these solvers, otherwise it is computed internally. using RegularizedLeastSquares A = randn(32, 16) x = randn(16) b = A*x solver = createLinearSolver(CGNR, A; AHA = adjoint(A) * A, reg = L2Regularization(0.0001), iterations=32); x_approx = solve!(solver, b) # The normal operator can also be computed using the `normalOperator` function from LinearOperatorCollection.jl. This is useful if the normal operator is not directly available or shouldn't be stored in memory. # This function is opinionated and attempts to optimize the resulting operator for iterative applications. Specifying a custom method for a custom operator allows one to control this optimization. # An example of such an optimization is a matrix-free weighting of $\mathbf{A}$ as shown in the [Weighting](weighting.md) example: using LinearOperatorCollection weights = rand(32) WA = ProdOp(WeightingOp(weights), A) AHA = LinearOperatorCollection.normalOperator(WA) # Without an optimization a matrix-free product would apply the following operator each iteration: # ```math # \begin{equation} # (\mathbf{WA})^*\mathbf{WA} = \mathbf{A}^*\mathbf{W}^*\mathbf{W}\mathbf{A} # \end{equation} # ``` # This is not efficient and instead the normal operator can be optimized by initially computing the weights: # ```math # \begin{equation} # \tilde{\mathbf{W}} = \mathbf{W}^*\mathbf{W} # \end{equation} # ``` # and then applying the following each iteration: # ```math # \begin{equation} # \mathbf{A}^*\tilde{\mathbf{W}}\mathbf{A} # \end{equation} # ``` # The optimized normal operator can then be passed to the solver: solver = createLinearSolver(CGNR, WA; AHA = AHA, reg = L2Regularization(0.0001), iterations=32); x_approx2 = solve!(solver, weights .* b) # Of course it is also possible to optimize a normal operator with other means and pass it to the solver via the AHA keyword argument. # It is also possible to only supply the normal operator to these solvers, however on then needs to supply $\mathbf{A^*b}$ intead of $\mathbf{b}$.
RegularizedLeastSquares
https://github.com/JuliaImageRecon/RegularizedLeastSquares.jl.git
[ "MIT" ]
0.16.5
7c4d085f436b699e746e19173a3c640a79ceec8a
code
1485
# # Plug-and-Play Regularization # A group of regularization terms that can not be directly written down as function are learned plug-and-play (PnP) priors. # These are terms based on deep neural networks, which are trainted to implement the proximal map corresponding to the regularization term. # Such a PnP prior can be used in the same way as any other regularization term. # The following example shows how to use a PnP prior in the context of the `Kaczmarz` solver. using RegularizedLeastSquares A = randn(32, 16) x = randn(16) b = A*x; # For the documentation we will just use the identity function as a placeholder for the PnP prior. model = identity # In practice, you would replace this with a neural network: # ```julia # using Flux # model = Flux.loadmodel!(model, ...) # ``` # The model can then be used together with the `PnPRegularization` term: reg = PnPRegularization(1.0; model = model, shape = [16]); # Since models often expect a specific input range, we can use the `MinMaxTransform` to normalize the input: reg = PnPRegularization(1.0; model = model, shape = [16], input_transform = RegularizedLeastSquares.MinMaxTransform); # Custom input transforms can be implemented by passing something callable as the `input_transform` keyword argument. For more details see the PnPRegularization documentation. # The regularization term can then be used in the solver: solver = createLinearSolver(Kaczmarz, A; reg = reg, iterations = 32) x_approx = solve!(solver, b)
RegularizedLeastSquares
https://github.com/JuliaImageRecon/RegularizedLeastSquares.jl.git
[ "MIT" ]
0.16.5
7c4d085f436b699e746e19173a3c640a79ceec8a
code
2071
# # Weighting # Often time one wants to solve a weighted least squares problem of the form: # ```math # \begin{equation} # \underset{\mathbf{x}}{argmin} \frac{1}{2}\vert\vert \mathbf{A}\mathbf{x}-\mathbf{b} \vert\vert^2_{\mathbf{W}} + \mathbf{R(x)} . # \end{equation} # ``` # where $\mathbf{W}$ is a symmetric, positive weighting matrix and $\vert\vert\mathbf{y}\vert\vert^2_\mathbf{W}$ denotes the weighted Euclidean norm. # An example of such a weighting matrix is a noise whitening matrix. Another example could be a scaling of the matrix rows by the reciprocal of their row energy. # In the following, we will solve a weighted least squares problem of the form: # ```math # \begin{equation} # \underset{\mathbf{x}}{argmin} \frac{1}{2}\vert\vert \mathbf{A}\mathbf{x}-\mathbf{b} \vert\vert_\mathbf{W}^2 + \lambda\vert\vert\mathbf{x}\vert\vert^2_2 . # \end{equation} # ``` using RegularizedLeastSquares, LinearOperatorCollection, LinearAlgebra A = rand(32, 16) x = rand(16) b = A*x; # As a weighting matrix, we will use the reciprocal of the row energy of the matrix A. weights = map(row -> 1/rownorm²(A, row), 1:size(A, 1)); # First, let us solve the problem with matrices we manually weighted. WA = diagm(weights) * A solver = createLinearSolver(Kaczmarz, WA; reg = L2Regularization(0.0001), iterations=10) x_approx = solve!(solver, weights .* b); # The operator A is not always a dense matrix and the product between the operator and the weighting matrix is not always efficient or possible. # The package [LinearOperatorCollection.jl](https://github.com/JuliaImageRecon/LinearOperatorCollection.jl) provides a matrix-free implementation of a diagonal weighting matrix, as well as a matrix free product between two matrices. # This weighted operator has efficient implementations of the normal operator and also for the row-action operations of the Kaczmarz solver. W = WeightingOp(weights) P = ProdOp(W, A) solver = createLinearSolver(Kaczmarz, P; reg = L2Regularization(0.0001), iterations=10) x_approx2 = solve!(solver, W * b) isapprox(x_approx, x_approx2)
RegularizedLeastSquares
https://github.com/JuliaImageRecon/RegularizedLeastSquares.jl.git
[ "MIT" ]
0.16.5
7c4d085f436b699e746e19173a3c640a79ceec8a
code
551
# CuSparseArrays are not part of the AbstractGPUArrays hierarchy function RegularizedLeastSquares.normalize(::SystemMatrixBasedNormalization, A::AbstractCuSparseMatrix, b) N = size(A, 2) energy = sqrt.(mapreduce(abs2, +, A, dims = 2)) return norm(energy)^2/N end function RegularizedLeastSquares.normalize(::SystemMatrixBasedNormalization, P::ProdOp{T, <:WeightingOp, matT}, b) where {T, matT <: AbstractCuSparseMatrix} N = size(P, 2) A = P.B energy = sqrt.(P.A.weights.^2 .* mapreduce(abs2, +, A, dims = 2)) return norm(energy)^2/N end
RegularizedLeastSquares
https://github.com/JuliaImageRecon/RegularizedLeastSquares.jl.git
[ "MIT" ]
0.16.5
7c4d085f436b699e746e19173a3c640a79ceec8a
code
237
module RegularizedLeastSquaresCUDAExt using RegularizedLeastSquares, RegularizedLeastSquares.LinearAlgebra, RegularizedLeastSquares.LinearOperatorCollection using CUDA, CUDA.CUSPARSE include("NormalizedRegularization.jl") end # module
RegularizedLeastSquares
https://github.com/JuliaImageRecon/RegularizedLeastSquares.jl.git
[ "MIT" ]
0.16.5
7c4d085f436b699e746e19173a3c640a79ceec8a
code
1191
function RegularizedLeastSquares.iterate_row_index(solver::Kaczmarz, state::RegularizedLeastSquares.KaczmarzState{T, vecT}, A, row, index) where {T, vecT <: AbstractGPUArray} state.τl = RegularizedLeastSquares.dot_with_matrix_row(A,state.x,row) @allowscalar state.αl = solver.denom[index]*(state.u[row]-state.τl-state.ɛw*state.vl[row]) RegularizedLeastSquares.kaczmarz_update!(A,state.x,row,state.αl) @allowscalar state.vl[row] += state.αl*state.ɛw end function RegularizedLeastSquares.kaczmarz_update!(A::matT, x::vecT, row, beta) where {T, matT <: AbstractGPUArray{T}, vecT <: AbstractGPUVector{T}} x[:] .= x .+ beta * conj.(view(A, row, :)) end function RegularizedLeastSquares.kaczmarz_update!(B::Transpose{T, S}, x::vecT, row, beta) where {T, S <: AbstractGPUArray{T}, vecT <: AbstractGPUVector{T}} A = B.parent x[:] .= x .+ beta * conj.(view(A, :, row)) end function RegularizedLeastSquares.kaczmarz_update!(prod::ProdOp{Tc, WeightingOp{T, vecT}}, x, k, beta) where {T, Tc<:Union{T, Complex{T}}, vecT <: AbstractGPUVector{T}} weight = @allowscalar prod.A.weights[k] RegularizedLeastSquares.kaczmarz_update!(prod.B, x, k, weight*beta) # only for real weights end
RegularizedLeastSquares
https://github.com/JuliaImageRecon/RegularizedLeastSquares.jl.git
[ "MIT" ]
0.16.5
7c4d085f436b699e746e19173a3c640a79ceec8a
code
474
function RegularizedLeastSquares.normalize(::SystemMatrixBasedNormalization, A::AbstractGPUArray, b) N = size(A, 2) energy = sqrt.(mapreduce(abs2, +, A, dims = 2)) return norm(energy)^2/N end function RegularizedLeastSquares.normalize(::SystemMatrixBasedNormalization, P::ProdOp{T, <:WeightingOp, matT}, b) where {T, matT <: AbstractGPUArray} N = size(P, 2) A = P.B energy = sqrt.(P.A.weights.^2 .* mapreduce(abs2, +, A, dims = 2)) return norm(energy)^2/N end
RegularizedLeastSquares
https://github.com/JuliaImageRecon/RegularizedLeastSquares.jl.git
[ "MIT" ]
0.16.5
7c4d085f436b699e746e19173a3c640a79ceec8a
code
555
function RegularizedLeastSquares.proxL21!(x::vecT, λ::T, slices::Int64) where {T, vecT <: Union{AbstractGPUVector{T}, AbstractGPUVector{Complex{T}}}} sliceLength = div(length(x),slices) groupNorm = copyto!(similar(x, Float32, sliceLength), [Float32(norm(x[i:sliceLength:end])) for i=1:sliceLength]) gpu_call(x, λ, groupNorm, sliceLength) do ctx, x_, λ_, groupNorm_, sliceLength_ i = @linearidx(x_) @inbounds x_[i] = x_[i]*max( (groupNorm_[mod1(i,sliceLength_)]-λ_)/groupNorm_[mod1(i,sliceLength_)],0) return nothing end return x end
RegularizedLeastSquares
https://github.com/JuliaImageRecon/RegularizedLeastSquares.jl.git
[ "MIT" ]
0.16.5
7c4d085f436b699e746e19173a3c640a79ceec8a
code
528
function RegularizedLeastSquares.tv_restrictMagnitude!(x::vecT) where {T, vecT <: AbstractGPUVector{T}} gpu_call(x) do ctx, x_ i = @linearidx(x_) @inbounds x_[i] /= max(1, abs(x_[i])) return nothing end end function RegularizedLeastSquares.tv_linearcomb!(rs::vecT, t3, pq::vecT, t2, pqOld::vecT) where {T, vecT <: AbstractGPUVector{T}} gpu_call(rs, t3, pq, t2, pqOld) do ctx, rs_, t3_, pq_, t2_, pqOld_ i = @linearidx(rs_) @inbounds rs_[i] = t3_ * pq_[i] - t2_ * pqOld_[i] return nothing end end
RegularizedLeastSquares
https://github.com/JuliaImageRecon/RegularizedLeastSquares.jl.git
[ "MIT" ]
0.16.5
7c4d085f436b699e746e19173a3c640a79ceec8a
code
309
module RegularizedLeastSquaresGPUArraysExt using RegularizedLeastSquares, RegularizedLeastSquares.LinearAlgebra, RegularizedLeastSquares.LinearOperatorCollection using GPUArrays include("Utils.jl") include("ProxTV.jl") include("ProxL21.jl") include("NormalizedRegularization.jl") include("Kaczmarz.jl") end
RegularizedLeastSquares
https://github.com/JuliaImageRecon/RegularizedLeastSquares.jl.git
[ "MIT" ]
0.16.5
7c4d085f436b699e746e19173a3c640a79ceec8a
code
2413
""" This function enforces the constraint of a real solution. """ function RegularizedLeastSquares.enfReal!(x::arrT) where {N, T<:Complex, arrGPUT <: AbstractGPUArray{T}, arrT <: Union{arrGPUT, SubArray{T, N, arrGPUT}}} #Returns x as complex vector with imaginary part set to zero gpu_call(x) do ctx, x_ i = @linearidx(x_) @inbounds (x_[i] = complex(x_[i].re)) return nothing end end """ This function enforces the constraint of a real solution. """ RegularizedLeastSquares.enfReal!(x::arrT) where {N, T<:Real, arrGPUT <: AbstractGPUArray{T}, arrT <: Union{arrGPUT, SubArray{T, N, arrGPUT}}} = nothing """ This function enforces positivity constraints on its input. """ function RegularizedLeastSquares.enfPos!(x::arrT) where {N, T<:Complex, arrGPUT <: AbstractGPUArray{T}, arrT <: Union{arrGPUT, SubArray{T, N, arrGPUT}}} #Return x as complex vector with negative parts projected onto 0 gpu_call(x) do ctx, x_ i = @linearidx(x_) @inbounds (x_[i].re < 0) && (x_[i] = im*x_[i].im) return nothing end end """ This function enforces positivity constraints on its input. """ function RegularizedLeastSquares.enfPos!(x::arrT) where {T<:Real, arrT <: AbstractGPUArray{T}} #Return x as complex vector with negative parts projected onto 0 gpu_call(x) do ctx, x_ i = @linearidx(x_) @inbounds (x_[i] < 0) && (x_[i] = zero(T)) return nothing end end RegularizedLeastSquares.rownorm²(A::AbstractGPUMatrix,row::Int64) = sum(map(abs2, @view A[row, :])) RegularizedLeastSquares.rownorm²(B::Transpose{T,S},row::Int64) where {T,S<:AbstractGPUArray} = sum(map(abs2, @view B.parent[:, row])) RegularizedLeastSquares.rownorm²(A::ProdOp{T, WeightingOp{T2, vecT2}, matT}, row::Int64) where {T, T2, vecT2 <: AbstractGPUArray, matT} = GPUArrays.@allowscalar A.A.weights[row]^2 * rownorm²(A.B, row) RegularizedLeastSquares.dot_with_matrix_row(A::AbstractGPUMatrix{T}, x::AbstractGPUVector{T}, k::Int64) where {T} = reduce(+, x .* view(A, k, :)) RegularizedLeastSquares.dot_with_matrix_row(B::Transpose{T,S}, x::AbstractGPUVector{T}, k::Int64) where {T,S<:AbstractGPUArray} = reduce(+, x .* view(B.parent, :, k)) RegularizedLeastSquares.dot_with_matrix_row(A::ProdOp{T, WeightingOp{T2, vecT2}, matT}, x::AbstractGPUVector{T}, k::Int64) where {T, T2, vecT2 <: AbstractGPUArray, matT} = GPUArrays.@allowscalar A.A.weights[k] * RegularizedLeastSquares.dot_with_matrix_row(A.B, x, k)
RegularizedLeastSquares
https://github.com/JuliaImageRecon/RegularizedLeastSquares.jl.git
[ "MIT" ]
0.16.5
7c4d085f436b699e746e19173a3c640a79ceec8a
code
11536
export ADMM mutable struct ADMM{matT,opT,R,ropT,P,preconT} <: AbstractPrimalDualSolver A::matT reg::Vector{R} regTrafo::Vector{ropT} proj::Vector{P} AHA::opT precon::preconT normalizeReg::AbstractRegularizationNormalization vary_ρ::Symbol verbose::Bool iterations::Int64 iterationsCG::Int64 state::AbstractSolverState{<:ADMM} end mutable struct ADMMState{rT <: Real, rvecT <: AbstractVector{rT}, vecT <: Union{AbstractVector{rT}, AbstractVector{Complex{rT}}}} <: AbstractSolverState{ADMM} # fields and operators for x update β::vecT β_y::vecT # fields for primal & dual variables x::vecT xᵒˡᵈ::vecT z::Vector{vecT} zᵒˡᵈ::Vector{vecT} u::Vector{vecT} uᵒˡᵈ::Vector{vecT} # other paremters ρ::rvecT iteration::Int64 # state variables for CG cgStateVars::CGStateVariables # convergence parameters rᵏ::rvecT sᵏ::rvecT ɛᵖʳⁱ::rvecT ɛᵈᵘᵃ::rvecT σᵃᵇˢ::rT Δ::rvecT absTol::rT relTol::rT tolInner::rT end """ ADMM(A; AHA = A'*A, precon = Identity(), reg = L1Regularization(zero(real(eltype(AHA)))), regTrafo = opEye(eltype(AHA), size(AHA,1)), normalizeReg = NoNormalization(), rho = 1e-1, vary_rho = :none, iterations = 10, iterationsCG = 10, absTol = eps(real(eltype(AHA))), relTol = eps(real(eltype(AHA))), tolInner = 1e-5, verbose = false) ADMM( ; AHA = , precon = Identity(), reg = L1Regularization(zero(real(eltype(AHA)))), regTrafo = opEye(eltype(AHA), size(AHA,1)), normalizeReg = NoNormalization(), rho = 1e-1, vary_rho = :none, iterations = 10, iterationsCG = 10, absTol = eps(real(eltype(AHA))), relTol = eps(real(eltype(AHA))), tolInner = 1e-5, verbose = false) Creates an `ADMM` object for the forward operator `A` or normal operator `AHA`. # Required Arguments * `A` - forward operator OR * `AHA` - normal operator (as a keyword argument) # Optional Keyword Arguments * `AHA` - normal operator is optional if `A` is supplied * `precon` - preconditionner for the internal CG algorithm * `reg::AbstractParameterizedRegularization` - regularization term; can also be a vector of regularization terms * `regTrafo` - transformation to a space in which `reg` is applied; if `reg` is a vector, `regTrafo` has to be a vector of the same length. Use `opEye(eltype(AHA), size(AHA,1))` if no transformation is desired. * `normalizeReg::AbstractRegularizationNormalization` - regularization normalization scheme; options are `NoNormalization()`, `MeasurementBasedNormalization()`, `SystemMatrixBasedNormalization()` * `rho::Real` - penalty of the augmented Lagrangian * `vary_rho::Symbol` - vary rho to balance primal and dual feasibility; options `:none`, `:balance`, `:PnP` * `iterations::Int` - maximum number of (outer) ADMM iterations * `iterationsCG::Int` - maximum number of (inner) CG iterations * `absTol::Real` - absolute tolerance for stopping criterion * `relTol::Real` - relative tolerance for stopping criterion * `tolInner::Real` - relative tolerance for CG stopping criterion * `verbose::Bool` - print residual in each iteration ADMM differs from ISTA-type algorithms in the sense that the proximal operation is applied separately from the transformation to the space in which the penalty is applied. This is reflected by the interface which has `reg` and `regTrafo` as separate arguments. E.g., for a TV penalty, you should NOT set `reg=TVRegularization`, but instead use `reg=L1Regularization(λ), regTrafo=RegularizedLeastSquares.GradientOp(Float64; shape=(Nx,Ny,Nz))`. See also [`createLinearSolver`](@ref), [`solve!`](@ref). """ ADMM(; AHA, kwargs...) = ADMM(nothing; kwargs..., AHA = AHA) function ADMM(A ; AHA = A'*A , precon = Identity() , reg = L1Regularization(zero(real(eltype(AHA)))) , regTrafo = opEye(eltype(AHA), size(AHA,1), S = LinearOperators.storage_type(AHA)) , normalizeReg::AbstractRegularizationNormalization = NoNormalization() , rho = 1e-1 , vary_rho::Symbol = :none , iterations::Int = 10 , iterationsCG::Int = 10 , absTol::Real = eps(real(eltype(AHA))) , relTol::Real = eps(real(eltype(AHA))) , tolInner::Real = 1e-5 , verbose = false ) T = eltype(AHA) rT = real(T) reg = isa(reg, AbstractVector) ? reg : [reg] regTrafo = isa(regTrafo, AbstractVector) ? regTrafo : [regTrafo] @assert length(reg) == length(regTrafo) "reg and regTrafo must have the same length" indices = findsinks(AbstractProjectionRegularization, reg) proj = [reg[i] for i in indices] proj = identity.(proj) deleteat!(reg, indices) deleteat!(regTrafo, indices) if typeof(rho) <: Number rho = [rT.(rho) for _ ∈ eachindex(reg)] else rho = rT.(rho) end x = Vector{T}(undef, size(AHA,2)) xᵒˡᵈ = similar(x) β = similar(x) β_y = similar(x) # fields for primal & dual variables z = [similar(x, size(regTrafo[i],1)) for i ∈ eachindex(reg)] zᵒˡᵈ = [similar(z[i]) for i ∈ eachindex(reg)] u = [similar(z[i]) for i ∈ eachindex(reg)] uᵒˡᵈ = [similar(u[i]) for i ∈ eachindex(reg)] # statevariables for CG # we store them here to prevent CG from allocating new fields at each call cgStateVars = CGStateVariables(zero(x),similar(x),similar(x)) # convergence parameters rᵏ = Array{rT}(undef, length(reg)) sᵏ = similar(rᵏ) ɛᵖʳⁱ = similar(rᵏ) ɛᵈᵘᵃ = similar(rᵏ) Δ = similar(rᵏ) # normalization parameters reg = normalize(ADMM, normalizeReg, reg, A, nothing) state = ADMMState(β, β_y, x, xᵒˡᵈ, z, zᵒˡᵈ, u, uᵒˡᵈ, rho, 0, cgStateVars, rᵏ, sᵏ, ɛᵖʳⁱ, ɛᵈᵘᵃ, rT(0), Δ, rT(absTol), rT(relTol), rT(tolInner)) return ADMM(A, reg, regTrafo, proj, AHA, precon, normalizeReg, vary_rho, verbose, iterations, iterationsCG, state) end function init!(solver::ADMM, state::ADMMState{rT, rvecT, vecT}, b::otherT; kwargs...) where {rT, rvecT, vecT, otherT <: AbstractVector} x = similar(b, size(state.x)...) xᵒˡᵈ = similar(b, size(state.xᵒˡᵈ)...) β = similar(b, size(state.β)...) β_y = similar(b, size(state.β_y)...) z = [similar(b, size(state.z[i])...) for i ∈ eachindex(solver.reg)] zᵒˡᵈ = [similar(b, size(state.zᵒˡᵈ[i])...) for i ∈ eachindex(solver.reg)] u = [similar(b, size(state.u[i])...) for i ∈ eachindex(solver.reg)] uᵒˡᵈ = [similar(b, size(state.uᵒˡᵈ[i])...) for i ∈ eachindex(solver.reg)] cgStateVars = CGStateVariables(zero(x),similar(x),similar(x)) state = ADMMState(β, β_y, x, xᵒˡᵈ, z, zᵒˡᵈ, u, uᵒˡᵈ, state.ρ, state.iteration, cgStateVars, state.rᵏ, state.sᵏ, state.ɛᵖʳⁱ, state.ɛᵈᵘᵃ, state.σᵃᵇˢ, state.Δ, state.absTol, state.relTol, state.tolInner) solver.state = state init!(solver, state, b; kwargs...) end """ init!(solver::ADMM, b; x0 = 0) (re-) initializes the ADMM iterator """ function init!(solver::ADMM, state::ADMMState{rT, rvecT, vecT}, b::vecT; x0 = 0) where {rT, rvecT, vecT <: AbstractVector} state.x .= x0 # right hand side for the x-update if solver.A === nothing state.β_y .= b else mul!(state.β_y, adjoint(solver.A), b) end # primal and dual variables for i ∈ eachindex(solver.reg) state.z[i] .= solver.regTrafo[i] * state.x state.u[i] .= 0 end # convergence parameter state.rᵏ .= Inf state.sᵏ .= Inf state.ɛᵖʳⁱ .= 0 state.ɛᵈᵘᵃ .= 0 state.σᵃᵇˢ = sqrt(length(b)) * state.absTol state.Δ .= Inf state.iteration = 0 # normalization of regularization parameters solver.reg = normalize(solver, solver.normalizeReg, solver.reg, solver.A, b) end solverconvergence(state::ADMMState) = (; :primal => state.rᵏ, :dual => state.sᵏ) """ iterate(it::ADMM, iteration::Int=0) performs one ADMM iteration. """ function iterate(solver::ADMM, state::ADMMState) done(solver, state) && return nothing solver.verbose && println("Outer ADMM Iteration #$(state.iteration)") # 1. solve arg min_x 1/2|| Ax-b ||² + ρ/2 Σ_i||Φi*x+ui-zi||² # <=> (A'A+ρ Σ_i Φi'Φi)*x = A'b+ρΣ_i Φi'(zi-ui) state.β .= state.β_y AHA = solver.AHA for i ∈ eachindex(solver.reg) mul!(state.β, adjoint(solver.regTrafo[i]), state.z[i], state.ρ[i], 1) mul!(state.β, adjoint(solver.regTrafo[i]), state.u[i], -state.ρ[i], 1) AHA += state.ρ[i] * adjoint(solver.regTrafo[i]) * solver.regTrafo[i] end solver.verbose && println("conjugated gradients: ") state.xᵒˡᵈ .= state.x cg!(state.x, AHA, state.β, Pl=solver.precon, maxiter=solver.iterationsCG, reltol=state.tolInner, statevars=state.cgStateVars, verbose=solver.verbose) for proj in solver.proj prox!(proj, state.x) end # proximal map for regularization terms for i ∈ eachindex(solver.reg) # swap z and zᵒˡᵈ w/o copying data tmp = state.zᵒˡᵈ[i] state.zᵒˡᵈ[i] = state.z[i] state.z[i] = tmp # 2. update z using the proximal map of 1/ρ*g(x) mul!(state.z[i], solver.regTrafo[i], state.x) state.z[i] .+= state.u[i] if state.ρ[i] != 0 prox!(solver.reg[i], state.z[i], λ(solver.reg[i])/2state.ρ[i]) # λ is divided by 2 to match the ISTA-type algorithms end # 3. update u state.uᵒˡᵈ[i] .= state.u[i] mul!(state.u[i], solver.regTrafo[i], state.x, 1, 1) state.u[i] .-= state.z[i] # update convergence criteria (one for each constraint) state.rᵏ[i] = norm(solver.regTrafo[i] * state.x - state.z[i]) # primal residual (x-z) state.sᵏ[i] = norm(state.ρ[i] * adjoint(solver.regTrafo[i]) * (state.z[i] .- state.zᵒˡᵈ[i])) # dual residual (concerning f(x)) state.ɛᵖʳⁱ[i] = max(norm(solver.regTrafo[i] * state.x), norm(state.z[i])) state.ɛᵈᵘᵃ[i] = norm(state.ρ[i] * adjoint(solver.regTrafo[i]) * state.u[i]) Δᵒˡᵈ = state.Δ[i] state.Δ[i] = norm(state.x .- state.xᵒˡᵈ ) + norm(state.z[i] .- state.zᵒˡᵈ[i]) + norm(state.u[i] .- state.uᵒˡᵈ[i]) if (solver.vary_ρ == :balance && state.rᵏ[i]/state.ɛᵖʳⁱ[i] > 10state.sᵏ[i]/state.ɛᵈᵘᵃ[i]) || # adapt ρ according to Boyd et al. (solver.vary_ρ == :PnP && state.Δ[i]/Δᵒˡᵈ > 0.9) # adapt ρ according to Chang et al. state.ρ[i] *= 2 state.u[i] ./= 2 elseif solver.vary_ρ == :balance && state.sᵏ[i]/state.ɛᵈᵘᵃ[i] > 10state.rᵏ[i]/state.ɛᵖʳⁱ[i] state.ρ[i] /= 2 state.u[i] .*= 2 end if solver.verbose println("rᵏ[$i]/ɛᵖʳⁱ[$i] = $(state.rᵏ[i]/state.ɛᵖʳⁱ[i])") println("sᵏ[$i]/ɛᵈᵘᵃ[$i] = $(state.sᵏ[i]/state.ɛᵈᵘᵃ[i])") println("Δ[$i]/Δᵒˡᵈ[$i] = $(state.Δ[i]/Δᵒˡᵈ)") println("new ρ[$i] = $(state.ρ[i])") flush(stdout) end end state.iteration += 1 return state.x, state end function converged(solver::ADMM, state::ADMMState) for i ∈ eachindex(solver.reg) (state.rᵏ[i] >= state.σᵃᵇˢ + state.relTol * state.ɛᵖʳⁱ[i]) && return false (state.sᵏ[i] >= state.σᵃᵇˢ + state.relTol * state.ɛᵈᵘᵃ[i]) && return false end return true end @inline done(solver::ADMM, state::ADMMState) = converged(solver, state) || state.iteration >= solver.iterations
RegularizedLeastSquares
https://github.com/JuliaImageRecon/RegularizedLeastSquares.jl.git
[ "MIT" ]
0.16.5
7c4d085f436b699e746e19173a3c640a79ceec8a
code
5854
export cgnr, CGNR mutable struct CGNR{matT,opT, R,PR} <: AbstractKrylovSolver A::matT AHA::opT L2::R constr::PR normalizeReg::AbstractRegularizationNormalization iterations::Int64 state::AbstractSolverState{<:CGNR} end mutable struct CGNRState{T, Tc, vecTc} <: AbstractSolverState{CGNR} where {T, Tc <: Union{T, Complex{T}}, vecTc<:AbstractArray{Tc}} x::vecTc x₀::vecTc pl::vecTc vl::vecTc αl::Tc βl::Tc ζl::Tc iteration::Int64 relTol::T z0::T end """ CGNR(A; AHA = A' * A, reg = L2Regularization(zero(real(eltype(AHA)))), normalizeReg = NoNormalization(), iterations = 10, relTol = eps(real(eltype(AHA)))) CGNR( ; AHA = , reg = L2Regularization(zero(real(eltype(AHA)))), normalizeReg = NoNormalization(), iterations = 10, relTol = eps(real(eltype(AHA)))) creates an `CGNR` object for the forward operator `A` or normal operator `AHA`. # Required Arguments * `A` - forward operator OR * `AHA` - normal operator (as a keyword argument) # Optional Keyword Arguments * `AHA` - normal operator is optional if `A` is supplied * `reg::AbstractParameterizedRegularization` - regularization term; can also be a vector of regularization terms * `normalizeReg::AbstractRegularizationNormalization` - regularization normalization scheme; options are `NoNormalization()`, `MeasurementBasedNormalization()`, `SystemMatrixBasedNormalization()` * `iterations::Int` - maximum number of iterations * `relTol::Real` - tolerance for stopping criterion See also [`createLinearSolver`](@ref), [`solve!`](@ref). """ CGNR(; AHA, kwargs...) = CGNR(nothing; AHA = AHA, kwargs...) function CGNR(A ; AHA = A'*A , reg = L2Regularization(zero(real(eltype(AHA)))) , normalizeReg::AbstractRegularizationNormalization = NoNormalization() , iterations::Int = 10 , relTol::Real = eps(real(eltype(AHA))) ) T = eltype(AHA) x = Vector{T}(undef, size(AHA, 2)) x₀ = similar(x) #temporary vector pl = similar(x) #temporary vector vl = similar(x) #temporary vector αl = zero(T) #temporary scalar βl = zero(T) #temporary scalar ζl = zero(T) #temporary scalar # Prepare regularization terms reg = isa(reg, AbstractVector) ? reg : [reg] reg = normalize(CGNR, normalizeReg, reg, A, nothing) idx = findsink(L2Regularization, reg) if isnothing(idx) L2 = L2Regularization(zero(T)) else L2 = reg[idx] deleteat!(reg, idx) end indices = findsinks(RealRegularization, reg) push!(indices, findsinks(PositiveRegularization, reg)...) other = [reg[i] for i in indices] deleteat!(reg, indices) if length(reg) > 0 error("CGNR does not allow for more additional regularization terms, found $(length(reg))") end other = identity.(other) state = CGNRState(x, x₀, pl, vl, αl, βl, ζl, 0, real(T)(relTol), zero(real(T))) return CGNR(A, AHA, L2, other, normalizeReg, iterations, state) end function init!(solver::CGNR, state::CGNRState{T, Tc, vecTc}, b::otherTc; kwargs...) where {T, Tc, vecTc, otherTc <: AbstractVector{Tc}} x = similar(b, size(state.x)...) x₀ = similar(b, size(state.x₀)...) pl = similar(b, size(state.pl)...) vl = similar(b, size(state.vl)...) state = CGNRState(x, x₀, pl, vl, state.αl, state.βl, state.ζl, state.iteration, state.relTol, state.z0) solver.state = state init!(solver, state, b; kwargs...) end """ init!(solver::CGNR, b; x0 = 0) (re-) initializes the CGNR iterator """ function init!(solver::CGNR, state::CGNRState{T, Tc, vecTc}, b::vecTc; x0 = 0) where {T, Tc <: Union{T, Complex{T}}, vecTc<:AbstractVector{Tc}} state.pl .= 0 #temporary vector state.vl .= 0 #temporary vector state.αl = 0 #temporary scalar state.βl = 0 #temporary scalar state.ζl = 0 #temporary scalar state.iteration = 0 if all(x0 .== 0) state.x .= 0 else solver.A === nothing && error("providing x0 requires solver.A to be defined") state.x .= x0 mul!(b, solver.A, solver.x, -1, 1) end #x₀ = Aᶜ*rl, where ᶜ denotes complex conjugation initCGNR(state.x₀, solver.A, b) state.z0 = norm(state.x₀) copyto!(state.pl, state.x₀) # normalization of regularization parameters solver.L2 = normalize(solver, solver.normalizeReg, solver.L2, solver.A, b) end initCGNR(x₀, A, b) = mul!(x₀, adjoint(A), b) #initCGNR(x₀, prod::ProdOp{T, <:WeightingOp, matT}, b) where {T, matT} = mul!(x₀, adjoint(prod.B), b) initCGNR(x₀, ::Nothing, b) = x₀ .= b solverconvergence(state::CGNRState) = (; :residual => norm(state.x₀)) """ iterate(solver::CGNR{vecT,T,Tsparse}, iteration::Int=0) where {vecT,T,Tsparse} performs one CGNR iteration. """ function iterate(solver::CGNR, state::CGNRState) if done(solver, state) for r in solver.constr prox!(r, state.x) end return nothing end mul!(state.vl, solver.AHA, state.pl) state.ζl = norm(state.x₀)^2 normvl = dot(state.pl, state.vl) λ_ = λ(solver.L2) if λ_ > 0 state.αl = state.ζl / (normvl + λ_ * norm(state.pl)^2) else state.αl = state.ζl / normvl end state.x .+= state.pl .* state.αl state.x₀ .+= state.vl .* -state.αl if λ_ > 0 state.x₀ .+= state.pl .* -λ_ * state.αl end state.βl = dot(state.x₀, state.x₀) / state.ζl rmul!(state.pl, state.βl) state.pl .+= state.x₀ state.iteration += 1 return state.x, state end function converged(::CGNR, state::CGNRState) return norm(state.x₀) / state.z0 <= state.relTol end @inline done(solver::CGNR, state::CGNRState) = converged(solver, state) || state.iteration >= min(solver.iterations, size(solver.AHA, 2))
RegularizedLeastSquares
https://github.com/JuliaImageRecon/RegularizedLeastSquares.jl.git
[ "MIT" ]
0.16.5
7c4d085f436b699e746e19173a3c640a79ceec8a
code
1678
export CompareSolutionCallback mutable struct CompareSolutionCallback{T, F} ref::Vector{T} cmp::F results::Vector{Float64} end """ CompareSolutionCallback(ref, cmp) Callback that compares the solvers current `solution` with the given reference via `cmp(ref, solution)` per iteration. Results are stored in the `results` field. """ CompareSolutionCallback(ref::Vector{T}, cmp = nrmsd) where T = CompareSolutionCallback(ref, cmp, Vector{Float64}()) function (cb::CompareSolutionCallback)(solver::AbstractLinearSolver, _) x = solversolution(solver) push!(cb.results, cb.cmp(cb.ref, x)) end export StoreSolutionCallback mutable struct StoreSolutionCallback{T} solutions::Vector{Vector{T}} end """ StoreSolutionCallback(T) Callback that accumlates the solvers `solution` per iteration. Results are stored in the `solutions` field. """ StoreSolutionCallback(T::Type=Number) = StoreSolutionCallback(Vector{Vector{T}}()) function (cb::StoreSolutionCallback)(solver::AbstractLinearSolver, _) x = solversolution(solver) push!(cb.solutions, deepcopy(x)) end export StoreConvergenceCallback mutable struct StoreConvergenceCallback convMeas::Dict{Symbol, Any} end """ StoreConvergenceCallback() Callback that accumlates the solvers convergence metrics per iteration. Results are stored in the `convMeas` field. """ StoreConvergenceCallback() = StoreConvergenceCallback(Dict{Symbol, Any}()) function (cb::StoreConvergenceCallback)(solver::AbstractLinearSolver, _) meas = solverconvergence(solver) for key in keys(meas) values = get(cb.convMeas, key, Vector{typeof(meas[key])}()) push!(values, meas[key]) cb.convMeas[key] = values end end
RegularizedLeastSquares
https://github.com/JuliaImageRecon/RegularizedLeastSquares.jl.git
[ "MIT" ]
0.16.5
7c4d085f436b699e746e19173a3c640a79ceec8a
code
6340
export DaxConstrained mutable struct DaxConstrained{matT,T,Tsparse,U} <: AbstractRowActionSolver A::matT u::Vector{T} λ::Float64 B::Tsparse Bnorm²::Vector{Float64} denom::Vector{U} rowindex::Vector{Int64} x::Vector{T} bk::Vector{T} bc::Vector{T} xl::Vector{T} yl::Vector{T} yc::Vector{T} δc::Vector{T} εw::Vector{T} τl::T αl::T weights::Vector{U} iterations::Int64 iterationsInner::Int64 end """ DaxConstrained(A; b=nothing, λ=0, weights=ones(real(eltype(A)),size(A,1)), sparseTrafo=nothing, iterations=3, iterationsInner=2) Creates an `DaxConstrained` object for the forward operator `A`. Solves a constrained linear least squares problem using an algorithm proposed in [1]. Returns an approximate solution to Sᵀx = u s.t. Bx>=0 (each component >=0). [1] Dax, A. On Row Relaxation Methods for Large Constrained Least Squares Problems. SIAM J. Sci. Comput. 14, 570–584 (1993). # Required Arguments * `A` - forward operator # Optional Keyword Arguments * `b::AbstractMatrix` - transpose of basistransformation if solving in dual space * `λ::Real` - regularization parameter ɛ>0 influences the speed of convergence but not the solution. * `weights::AbstractVector` - the larger the weight the more one 'trusts' a sqecific equation * `iterations::Int` - maximum number of (outer) ADMM iterations * `iterationsInner::Int` - max number of (inner) dax iterations See also [`createLinearSolver`](@ref), [`solve!`](@ref). """ function DaxConstrained(A ; b=nothing , λ::Real=0 , weights::AbstractVector=ones(real(eltype(A)),size(A,1)) , sparseTrafo=nothing , iterations::Int=3 , iterationsInner::Int=2 ) T = eltype(A) rT = real(eltype(A)) M,N = size(A) # setup denom and rowindex denom, rowindex = initkaczmarzconstraineddax(A,λ,weights) # set basis transformation sparseTrafo === nothing ? B=Matrix{rT}(I, size(A,2), size(A,2)) : B=sparseTrafo Bnorm² = [rownorm²(B,i) for i=1:size(B,2)] if b !== nothing u = b else u = zeros(T,M) end x = zeros(T,N) bk = zeros(T,M) bc = zeros(rT,size(B,2)) xl = zeros(T,N) yl = zeros(T,M) yc = zeros(T,N) δc = zeros(T,N) εw = zeros(T,length(rowindex)) τl = zero(T) αl = zero(T) return DaxConstrained(A,u,Float64(λ),B,Bnorm²,denom,rowindex,x,bk,bc,xl,yl,yc,δc,εw,τl,αl ,rT.(weights),iterations,iterationsInner) end function init!(solver::DaxConstrained, b; x0 = 0) solver.u .= b solver.x .= x0 solver.bk .= 0 solver.bc .= 0 solver.xl .= 0 solver.yl .= 0 solver.yc .= 0 solver.δc .= 0 solver.αl = 0 solver.τl = 0 for i=1:length(solver.rowindex) j = solver.rowindex[i] solver.ɛw[i] = sqrt(solver.λ)/solver.weights[j] end end solverconvergence(solver::DaxConstrained) = (; :residual => norm(solver.bk)) function iterate(solver::DaxConstrained, iteration::Int=0) if done(solver,iteration) return nothing end # bk = u-A'*x copyto!(solver.bk,solver.u) gemv!('N',-1.0,solver.A,solver.x,1.0,solver.bk) # solve min ɛ|x|²+|W*A*x-W*bk|² with weightingmatrix W=diag(wᵢ), i=1,...,M. for l=1:solver.iterationsInner for i=1:length(solver.rowindex) # perform kaczmarz for all rows, which receive an update. j = solver.rowindex[i] solver.τl = dot_with_matrix_row(solver.A,solver.xl,j) solver.αl = solver.denom[i]*(solver.bk[j]-solver.τl-solver.ɛw[i]*solver.yl[j]) kaczmarz_update!(solver.A,solver.xl,j,solver.αl) solver.yl[j] += solver.αl*solver.ɛw[i] end #Lent-Censor scheme for ensuring B(xl+x) >= 0 # copyto!(solver.δc,solver.xl) # BLAS.axpy!(1.0,solver.x,solver.δc) # lmul!(solver.B, solver.δc) # lentcensormin!(solver.δc,solver.yc) # # BLAS.axpy!(1.0,solver.δc,solver.yc) # yc += δc # # δc = gemv('T',solver.B,solver.δc) # BLAS.axpy!(1.0,solver.solver.δc,solver.xl) # xl += Bᵀ*δc #Lent-Censor scheme for solving Bx >= 0 # bc = xl + x copyto!(solver.bc,solver.x) BLAS.axpy!(1.0,solver.xl,solver.bc) for i=1:size(solver.B,2) δ = dot_with_matrix_row(solver.B,solver.bc,i)/solver.Bnorm²[i] δ = δ<solver.yc[i] ? -δ : -solver.yc[i] solver.yc[i] += δ kaczmarz_update!(solver.B,solver.xl,i,δ) # update xl kaczmarz_update!(solver.B,solver.bc,i,δ) # update bc end end BLAS.axpy!(1.0,solver.xl,solver.x) # x += xl # reset xl and yl for next Kaczmarz run rmul!(solver.xl,0.0) rmul!(solver.yl,0.0) rmul!(solver.yc,0.0) return solver.bk, iteration+1 end @inline done(solver::DaxConstrained,iteration::Int) = iteration>=solver.iterations function lentcensormin!(x::Vector{T},y::Vector{T}) where {T<:Real} α = -one(T) @simd for i=1:length(x) @inbounds x[i]<=y[i] ? x[i] = α*x[i] : x[i] = α*y[i] end end """This function saves the denominators to compute αl in denom and the rowindices, which lead to an update of cl in rowindex.""" function initkaczmarzconstraineddax(A::AbstractMatrix,ɛ::Number,weights::Vector) length(weights)==size(A,1) ? nothing : error("number of weights must equal number of equations") denom = Float64[] rowindex = Int64[] for i=1:size(A,1) s² = rownorm²(A,i)*weights[i]^2 if s²>0 push!(denom,weights[i]^2/(s²+ɛ)) push!(rowindex,i) end end return denom, rowindex end """ This function saves the denominators to compute αl in denom and the rowindices, which lead to an update of cl in rowindex. """ function initkaczmarzconstraineddaxfft(A::AbstractMatrix,ɛ::Number,weights::Vector) length(weights)==size(A,1) ? nothing : error("number of weights must equal number of equations") denom = Float64[] rowindex = Int64[] for i=1:2:size(A,1) s²a = (rownorm²(A,i)+rownorm²(A,i+1))*weights[i]^2 s²b = (rownorm²(A,i)+rownorm²(A,i+1))*weights[i+1]^2 if s²a>0 && s²b>0 push!(denom,weights[i]^2/(s²a+ɛ)) push!(denom,weights[i+1]^2/(s²b+ɛ)) push!(rowindex,i) push!(rowindex,i+1) end end return denom, rowindex end
RegularizedLeastSquares
https://github.com/JuliaImageRecon/RegularizedLeastSquares.jl.git
[ "MIT" ]
0.16.5
7c4d085f436b699e746e19173a3c640a79ceec8a
code
5444
export DaxKaczmarz mutable struct DaxKaczmarz{matT,T,U} <: AbstractRowActionSolver A::matT u::Vector{T} reg::Vector{<:AbstractRegularization} λ::Float64 denom::Vector{U} rowindex::Vector{Int64} sumrowweights::Vector{Float64} x::Vector{T} bk::Vector{T} xl::Vector{T} yl::Vector{T} εw::Vector{T} τl::T αl::T weights::Vector{U} iterations::Int64 iterationsInner::Int64 end """ DaxKaczmarz(A; b=nothing, λ=0, weights=ones(real(eltype(A)),size(A,1)), sparseTrafo=nothing, enforceReal=false, enforcePositive=false, iterations=3, iterationsInner=2) Creates an `DaxKaczmarz` object for the forward operator `A`. Solves a unconstrained linear least squares problem using an algorithm proposed in [1] combined with a randomized version of kaczmarz [2]. Returns an approximate solution to the linear least squares problem Sᵀx = u. [1] Dax, A. On Row Relaxation Methods for Large Constrained Least Squares Problems. SIAM J. Sci. Comput. 14, 570–584 (1993). [2] Strohmer, T. & Vershynin, R. A Randomized Kaczmarz Algorithm with Exponential Convergence. J. Fourier Anal. Appl. 15, 262–278 (2008). # Required Arguments * `A` - forward operator # Optional Keyword Arguments * `b::AbstractMatrix` - transpose of basistransformation if solving in dual space * `λ::Real` - regularization parameter ɛ>0 influences the speed of convergence but not the solution. * `sparseTrafo` - TODO * `enforceReal::Bool` - TODO * `enforcePositive::Bool` - TODO * `iterations::Int` - maximum number of (outer) ADMM iterations * `iterationsInner::Int` - max number of (inner) dax iterations See also [`createLinearSolver`](@ref), [`solve!`](@ref). """ function DaxKaczmarz(A ; b=nothing , λ::Real=0 , weights::Vector=ones(real(eltype(A)),size(A,1)) , sparseTrafo=nothing , enforceReal::Bool=false , enforcePositive::Bool=false , iterations::Int=3 , iterationsInner::Int=2 ) # setup denom and rowindex sumrowweights, denom, rowindex = initkaczmarzdax(A,λ,weights) T = typeof(real(A[1])) M,N = size(A) if b != nothing u = b else u = zeros(eltype(A),M) end x = zeros(eltype(A),N) bk = zeros(eltype(A),M) xl = zeros(eltype(A),N) yl = zeros(eltype(A),M) εw = zeros(eltype(A),length(rowindex)) τl = zero(eltype(A)) αl = zero(eltype(A)) reg = AbstractRegularization[] if enforcePositive && enforceReal push!(reg, PositiveRegularization()) elseif enforceReal push!(reg, RealRegularization()) end if !isempty(reg) && !isnothing(sparseTrafo) reg = map(r -> TransformedRegularization(r, sparseTrafo), reg) end return DaxKaczmarz(A,u,reg, Float64(λ), denom,rowindex,sumrowweights,x,bk,xl,yl,εw,τl,αl ,T.(weights) ,iterations,iterationsInner) end function init!(solver::DaxKaczmarz, b; x0 = 0) solver.u .= b solver.x .= x0 solver.bk .= 0 solver.xl .= 0 solver.yl .= 0 solver.αl = 0 solver.τl = 0 for i=1:length(solver.rowindex) j = solver.rowindex[i] solver.ɛw[i] = sqrt(solver.λ)/solver.weights[j] end end function iterate(solver::DaxKaczmarz, iteration::Int=0) if done(solver,iteration) for r in solver.reg prox!(r, solver.x) end return nothing end copyto!(solver.bk, solver.u) gemv!('N',-1.0,solver.A,solver.x,1.0,solver.bk) # solve min ɛ|x|²+|W*A*x-W*bk|² with weightingmatrix W=diag(wᵢ), i=1,...,M. for l=1:length(solver.rowindex)*solver.iterationsInner i::Int64 = getrandindex(solver.sumrowweights,rand()*solver.sumrowweights[end]) #choose row with propability proportional to its weight. j = solver.rowindex[i] solver.τl = dot_with_matrix_row(solver.A,solver.xl,j) solver.αl = solver.denom[i]*(solver.bk[j]-solver.τl-solver.ɛw[i]*solver.yl[j]) kaczmarz_update!(solver.A,solver.xl,j,solver.αl) solver.yl[j] += solver.αl*solver.ɛw[i] end BLAS.axpy!(1.0,solver.xl,solver.x) # x += xl # reset xl and yl for next Kaczmarz run rmul!(solver.xl,0.0) rmul!(solver.yl,0.0) return solver.bk, iteration+1 end @inline done(solver::DaxKaczmarz,iteration::Int) = iteration>=solver.iterations """This function saves the denominators to compute αl in denom and the rowindices, which lead to an update of cl in rowindex. """ function initkaczmarzdax(A::AbstractMatrix, ɛ, weights::Vector) length(weights)==size(A,1) ? nothing : error("number of weights must equal number of equations") denom = Float64[] sumrowweights = Float64[] rowindex = Int64[] push!(sumrowweights,0.0) for i=1:size(A,1) s² = rownorm²(A,i)*weights[i]^2 if s²>0 push!(denom,weights[i]^2/(s²+ɛ)) push!(sumrowweights,s²+ɛ+sumrowweights[end]) push!(rowindex,i) end end return sumrowweights, denom, rowindex end "This function returns the next index for the randomized Kaczmarz algorithm." function getrandindex(v::AbstractVector, x) lo::Int64 = 0 hi::Int64 = length(v)+1 while lo < hi-1 m = (lo+hi)>>>1 x<v[m] ? hi = m : lo = m end return lo end
RegularizedLeastSquares
https://github.com/JuliaImageRecon/RegularizedLeastSquares.jl.git
[ "MIT" ]
0.16.5
7c4d085f436b699e746e19173a3c640a79ceec8a
code
4968
export PseudoInverse, DirectSolver ### Direct Solver ### mutable struct DirectSolver{matT, R, PR} <: AbstractDirectSolver A::matT l2::R normalizeReg::AbstractRegularizationNormalization proj::Vector{PR} state::AbstractSolverState{<:AbstractDirectSolver} end mutable struct DirectSolverState{vecT} <: AbstractSolverState{DirectSolver} x::vecT b::vecT end function DirectSolver(A; reg::Vector{<:AbstractRegularization} = [L2Regularization(zero(real(eltype(A))))], normalizeReg::AbstractRegularizationNormalization = NoNormalization()) reg = normalize(DirectSolver, normalizeReg, reg, A, nothing) idx = findsink(L2Regularization, reg) if isnothing(idx) L2 = L2Regularization(zero(T)) else L2 = reg[idx] deleteat!(reg, idx) end indices = findsinks(AbstractProjectionRegularization, reg) other = AbstractRegularization[reg[i] for i in indices] deleteat!(reg, indices) if length(reg) == 1 push!(other, reg[1]) elseif length(reg) > 1 error("PseudoInverse does not allow for more than one L2 regularization term, found $(length(reg))") end other = identity.(other) T = eltype(A) x = Vector{T}(undef,size(A, 2)) b = zeros(T, size(A,1)) return DirectSolver(A, L2, normalizeReg, other, DirectSolverState(x, b)) end function init!(solver::DirectSolver, state::DirectSolverState{vecT}, b::otherT; kwargs...) where {vecT, otherT <: AbstractVector} x = similar(b, size(state.x)...) bvecT = similar(b, size(state.b)...) solver.state = DirectSolverState(x, bvecT) init!(solver, solver.state, b; kwargs...) end function init!(solver::DirectSolver, state::DirectSolverState{vecT}, b::vecT; x0=0) where vecT <: AbstractVector solver.l2 = normalize(solver, solver.normalizeReg, solver.l2, solver.A, b) state.b .= b state.x .= x0 end function iterate(solver::DirectSolver, state::DirectSolverState) A = solver.A λ_ = λ(solver.l2) lufact = lu(A'*A .+ λ_) x = \(lufact,A' * state.b) for p in solver.proj prox!(p, x) end state.x .= x return nothing end #type for Gauß elimination mutable struct tikhonovLU S::Matrix LUfact end tikhonovLU(S::AbstractMatrix) = tikhonovLU(S, lufact(S'*S)) Base.size(A::tikhonovLU) = size(A.S) Base.length(A::tikhonovLU) = length(A.S) """ This function can be used to calculate the singular values used for Tikhonov regularization. """ function setlambda(A::tikhonovLU, λ::Real) A.LUfact = lufact(A.S'*A.S + λ*speye(size(A,2),size(A,2))) return nothing end # Simple Tikonov regularized reconstruction function directSolver(A::tikhonovLU, b::Vector; enforceReal=false, enforcePositive=false, kargs...) x = \(A.LUfact,A.S' * b) enforceReal ? enfReal!(x) : nothing enforcePositive ? enfPos!(x) : nothing return x end ### Pseudoinverse ### mutable struct PseudoInverse{R, PR} <: AbstractDirectSolver svd::SVD l2::R normalizeReg::AbstractRegularizationNormalization proj::Vector{PR} state::AbstractSolverState{<:AbstractDirectSolver} end function PseudoInverse(A; reg::Vector{<:AbstractRegularization} = [L2Regularization(zero(real(eltype(A))))], normalizeReg::AbstractRegularizationNormalization = NoNormalization()) reg = normalize(PseudoInverse, normalizeReg, reg, A, nothing) idx = findsink(L2Regularization, reg) if isnothing(idx) L2 = L2Regularization(zero(T)) else L2 = reg[idx] deleteat!(reg, idx) end indices = findsinks(AbstractProjectionRegularization, reg) other = AbstractRegularization[reg[i] for i in indices] deleteat!(reg, indices) if length(reg) == 1 push!(other, reg[1]) elseif length(reg) > 1 error("PseudoInverse does not allow for more than one L2 regularization term, found $(length(reg))") end other = identity.(other) T = eltype(A) x = Vector{T}(undef,size(A, 2)) b = zeros(T, size(A,1)) return PseudoInverse(A, x, b, L2, normalizeReg, other) end function PseudoInverse(A::AbstractMatrix, x, b, l2, norm, proj) u, s, v = svd(A) temp = SVD(u, s, v) return PseudoInverse(temp, l2, norm, proj, DirectSolverState(x, b)) end function init!(solver::PseudoInverse, state::DirectSolverState{vecT}, b::otherT; kwargs...) where {vecT, otherT <: AbstractVector} x = similar(b, size(state.x)...) bvecT = similar(b, size(state.b)...) solver.state = DirectSolverState(x, bvecT) init!(solver, solver.state, b; kwargs...) end function init!(solver::PseudoInverse, state::DirectSolverState{vecT}, b::vecT; x0=0) where vecT <: AbstractVector solver.l2 = normalize(solver, solver.normalizeReg, solver.l2, solver.svd, b) state.b .= b end function iterate(solver::PseudoInverse, state::DirectSolverState) # Inversion by using the pseudoinverse of the SVD svd = solver.svd # Calculate singular values used for tikhonov regularization λ_ = λ(solver.l2) D = svd.S ./ (svd.S.*svd.S .+ λ_ ) tmp = adjoint(svd.U)*state.b tmp .*= D x = svd.Vt * tmp for p in solver.proj prox!(p, x) end state.x = x return nothing end
RegularizedLeastSquares
https://github.com/JuliaImageRecon/RegularizedLeastSquares.jl.git
[ "MIT" ]
0.16.5
7c4d085f436b699e746e19173a3c640a79ceec8a
code
7223
export FISTA mutable struct FISTA{matA, matAHA, R, RN} <: AbstractProximalGradientSolver A::matA AHA::matAHA reg::R proj::Vector{RN} normalizeReg::AbstractRegularizationNormalization verbose::Bool restart::Symbol iterations::Int64 state::AbstractSolverState{<:FISTA} end mutable struct FISTAState{rT <: Real, vecT <: Union{AbstractVector{rT}, AbstractVector{Complex{rT}}}} <: AbstractSolverState{FISTA} x::vecT x₀::vecT xᵒˡᵈ::vecT res::vecT ρ::rT theta::rT thetaᵒˡᵈ::rT iteration::Int64 relTol::rT norm_x₀::rT rel_res_norm::rT end """ FISTA(A; AHA=A'*A, reg=L1Regularization(zero(real(eltype(AHA)))), normalizeReg=NoNormalization(), iterations=50, verbose = false, rho = 0.95 / power_iterations(AHA), theta=1, relTol=eps(real(eltype(AHA))), restart = :none) FISTA( ; AHA=, reg=L1Regularization(zero(real(eltype(AHA)))), normalizeReg=NoNormalization(), iterations=50, verbose = false, rho = 0.95 / power_iterations(AHA), theta=1, relTol=eps(real(eltype(AHA))), restart = :none) creates a `FISTA` object for the forward operator `A` or normal operator `AHA`. # Required Arguments * `A` - forward operator OR * `AHA` - normal operator (as a keyword argument) # Optional Keyword Arguments * `AHA` - normal operator is optional if `A` is supplied * `precon` - preconditionner for the internal CG algorithm * `reg::AbstractParameterizedRegularization` - regularization term; can also be a vector of regularization terms * `normalizeReg::AbstractRegularizationNormalization` - regularization normalization scheme; options are `NoNormalization()`, `MeasurementBasedNormalization()`, `SystemMatrixBasedNormalization()` * `rho::Real` - step size for gradient step; the default is `0.95 / max_eigenvalue` as determined with power iterations. * `theta::Real` - parameter for predictor-corrector step * `relTol::Real` - tolerance for stopping criterion * `iterations::Int` - maximum number of iterations * `restart::Symbol` - `:none`, `:gradient` options for restarting * `verbose::Bool` - print residual in each iteration See also [`createLinearSolver`](@ref), [`solve!`](@ref). """ FISTA(; AHA, kwargs...) = FISTA(nothing; AHA = AHA, kwargs...) function FISTA(A ; AHA = A'*A , reg = L1Regularization(zero(real(eltype(AHA)))) , normalizeReg = NoNormalization() , iterations = 50 , verbose = false , rho = 0.95 / power_iterations(AHA; verbose) , theta = 1 , relTol = eps(real(eltype(AHA))) , restart = :none ) T = eltype(AHA) rT = real(T) x = Vector{T}(undef,size(AHA,2)) x₀ = similar(x) xᵒˡᵈ = similar(x) res = similar(x) res[1] = Inf # avoid spurious convergence in first iterations # Prepare regularization terms reg = isa(reg, AbstractVector) ? reg : [reg] indices = findsinks(AbstractProjectionRegularization, reg) other = [reg[i] for i in indices] deleteat!(reg, indices) if length(reg) != 1 error("FISTA does not allow for more additional regularization terms, found $(length(reg))") end other = identity.(other) reg = normalize(FISTA, normalizeReg, reg, A, nothing) state = FISTAState(x, x₀, xᵒˡᵈ, res, rT(rho), rT(theta), rT(theta), 0, rT(relTol), one(rT), rT(Inf)) return FISTA(A, AHA, reg[1], other, normalizeReg, verbose, restart, iterations, state) end function init!(solver::FISTA, state::FISTAState{rT, vecT}, b::otherT; kwargs...) where {rT, vecT, otherT <: AbstractVector} x = similar(b, size(state.x)...) x₀ = similar(b, size(state.x₀)...) xᵒˡᵈ = similar(b, size(state.xᵒˡᵈ)...) res = similar(b, size(state.res)...) state = FISTAState(x, x₀, xᵒˡᵈ, res, state.ρ, state.theta, state.theta, state.iteration, state.relTol, state.norm_x₀, state.rel_res_norm) solver.state = state init!(solver, state, b; kwargs...) end """ init!(it::FISTA, b; x0 = 0, theta = 1) (re-) initializes the FISTA iterator """ function init!(solver::FISTA, state::FISTAState{rT, vecT}, b::vecT; x0 = 0, theta=1) where {rT, vecT <: AbstractVector} if solver.A === nothing state.x₀ .= b else mul!(state.x₀, adjoint(solver.A), b) end state.iteration = 0 state.norm_x₀ = norm(state.x₀) state.x .= x0 state.xᵒˡᵈ .= 0 # makes no difference in 1st iteration what this is set to state.res[:] .= rT(Inf) state.theta = theta state.thetaᵒˡᵈ = theta state.rel_res_norm = rT(Inf) # normalization of regularization parameters solver.reg = normalize(solver, solver.normalizeReg, solver.reg, solver.A, state.x₀) end solverconvergence(state::FISTAState) = (; :residual => norm(state.res)) """ iterate(it::FISTA, iteration::Int=0) performs one fista iteration. """ function iterate(solver::FISTA, state::FISTAState) if done(solver, state) return nothing end # momentum / Nesterov step # this implementation mimics BART, saving memory by first swapping x and xᵒˡᵈ before calculating x + α * (x - xᵒˡᵈ) tmp = state.xᵒˡᵈ state.xᵒˡᵈ = state.x state.x = tmp # swap x and xᵒˡᵈ state.x .*= ((1 - state.thetaᵒˡᵈ)/state.theta) # here we calculate -α * xᵒˡᵈ, where xᵒˡᵈ is now stored in x state.x .+= ((state.thetaᵒˡᵈ-1)/state.theta + 1) .* (state.xᵒˡᵈ) # add (α+1)*x, where x is now stored in xᵒˡᵈ # calculate residuum and do gradient step # solver.x .-= solver.ρ .* (solver.AHA * solver.x .- solver.x₀) mul!(state.res, solver.AHA, state.x) state.res .-= state.x₀ state.x .-= state.ρ .* state.res state.rel_res_norm = norm(state.res) / state.norm_x₀ solver.verbose && println("Iteration $(state.iteration); rel. residual = $(state.rel_res_norm)") # the two lines below are equivalent to the ones above and non-allocating, but require the 5-argument mul! function to implemented for AHA, i.e. if AHA is LinearOperator, it requires LinearOperators.jl v2 # mul!(solver.x, solver.AHA, solver.xᵒˡᵈ, -solver.ρ, 1) # solver.x .+= solver.ρ .* solver.x₀ # proximal map prox!(solver.reg, state.x, state.ρ * λ(solver.reg)) for proj in solver.proj prox!(proj, state.x) end # gradient restart conditions if solver.restart == :gradient if real(state.res ⋅ (state.x .- state.xᵒˡᵈ) ) > 0 #if momentum is at an obtuse angle to the negative gradient solver.verbose && println("Gradient restart at iter $(state.iteration)") state.theta = 1 end end # predictor-corrector update state.thetaᵒˡᵈ = state.theta state.theta = (1 + sqrt(1 + 4 * state.thetaᵒˡᵈ^2)) / 2 state.iteration += 1 # return the residual-norm as item and iteration number as state return state.x, state end @inline converged(::FISTA, state::FISTAState) = (state.rel_res_norm < state.relTol) @inline done(solver::FISTA, state::FISTAState) = converged(solver, state) || state.iteration>=solver.iterations
RegularizedLeastSquares
https://github.com/JuliaImageRecon/RegularizedLeastSquares.jl.git
[ "MIT" ]
0.16.5
7c4d085f436b699e746e19173a3c640a79ceec8a
code
12185
export kaczmarz export Kaczmarz mutable struct Kaczmarz{matT,R,U,RN} <: AbstractRowActionSolver A::matT L2::R reg::Vector{RN} denom::Vector{U} rowindex::Vector{Int64} rowIndexCycle::Vector{Int64} randomized::Bool subMatrixSize::Int64 probabilities::Vector{U} shuffleRows::Bool seed::Int64 normalizeReg::AbstractRegularizationNormalization iterations::Int64 state::AbstractSolverState{<:Kaczmarz} end mutable struct KaczmarzState{T, vecT <: AbstractArray{T}} <: AbstractSolverState{Kaczmarz} u::vecT x::vecT vl::vecT εw::T τl::T αl::T iteration::Int64 end """ Kaczmarz(A; reg = L2Regularization(0), normalizeReg = NoNormalization(), randomized=false, subMatrixFraction=0.15, shuffleRows=false, seed=1234, iterations=10) Creates a Kaczmarz object for the forward operator `A`. # Required Arguments * `A` - forward operator # Optional Keyword Arguments * `reg::AbstractParameterizedRegularization` - regularization term * `normalizeReg::AbstractRegularizationNormalization` - regularization normalization scheme; options are `NoNormalization()`, `MeasurementBasedNormalization()`, `SystemMatrixBasedNormalization()` * `randomized::Bool` - randomize Kacmarz algorithm * `subMatrixFraction::Real` - fraction of rows used in randomized Kaczmarz algorithm * `shuffleRows::Bool` - randomize Kacmarz algorithm * `seed::Int` - seed for randomized algorithm * `iterations::Int` - number of iterations See also [`createLinearSolver`](@ref), [`solve!`](@ref). """ function Kaczmarz(A ; reg = L2Regularization(zero(real(eltype(A)))) , normalizeReg::AbstractRegularizationNormalization = NoNormalization() , randomized::Bool = false , subMatrixFraction::Real = 0.15 , shuffleRows::Bool = false , seed::Int = 1234 , iterations::Int = 10 ) T = real(eltype(A)) # Prepare regularization terms reg = isa(reg, AbstractVector) ? reg : [reg] reg = normalize(Kaczmarz, normalizeReg, reg, A, nothing) idx = findsink(L2Regularization, reg) if isnothing(idx) L2 = L2Regularization(zero(T)) else L2 = reg[idx] deleteat!(reg, idx) end # Tikhonov matrix is only valid with NoNormalization or SystemMatrixBasedNormalization if λ(L2) isa AbstractVector && !(normalizeReg isa NoNormalization || normalizeReg isa SystemMatrixBasedNormalization) error("Tikhonov matrix for Kaczmarz is only valid with no or system matrix based normalization") end indices = findsinks(AbstractProjectionRegularization, reg) other = AbstractRegularization[reg[i] for i in indices] deleteat!(reg, indices) if length(reg) == 1 push!(other, reg[1]) elseif length(reg) > 1 error("Kaczmarz does not allow for more than one additional regularization term, found $(length(reg))") end other = identity.(other) # setup denom and rowindex A, denom, rowindex = initkaczmarz(A, λ(L2)) rowIndexCycle = collect(1:length(rowindex)) probabilities = eltype(denom)[] if randomized probabilities = T.(rowProbabilities(A, rowindex)) end M,N = size(A) subMatrixSize = round(Int, subMatrixFraction*M) u = zeros(eltype(A),M) x = zeros(eltype(A),N) vl = zeros(eltype(A),M) εw = zero(eltype(A)) τl = zero(eltype(A)) αl = zero(eltype(A)) state = KaczmarzState(u, x, vl, εw, τl, αl, 0) return Kaczmarz(A, L2, other, denom, rowindex, rowIndexCycle, randomized, subMatrixSize, probabilities, shuffleRows, Int64(seed), normalizeReg, iterations, state) end function init!(solver::Kaczmarz, state::KaczmarzState{T, vecT}, b::otherT; kwargs...) where {T, vecT, otherT <: AbstractVector} u = similar(b, size(state.u)...) x = similar(b, size(state.x)...) vl = similar(b, size(state.vl)...) state = KaczmarzState(u, x, vl, state.εw, state.τl, state.αl, state.iteration) solver.state = state init!(solver, state, b; kwargs...) end """ init!(solver::Kaczmarz, b; x0 = 0) (re-) initializes the Kacmarz iterator """ function init!(solver::Kaczmarz, state::KaczmarzState{T, vecT}, b::vecT; x0 = 0) where {T, vecT <: AbstractVector} λ_prev = λ(solver.L2) solver.L2 = normalize(solver, solver.normalizeReg, solver.L2, solver.A, b) solver.reg = normalize(solver, solver.normalizeReg, solver.reg, solver.A, b) λ_ = λ(solver.L2) # λ changed => recompute denoms if λ_ != λ_prev # A must be unchanged, since we do not store the original SM _, solver.denom, solver.rowindex = initkaczmarz(solver.A, λ_) solver.rowIndexCycle = collect(1:length(rowindex)) if solver.randomized solver.probabilities = T.(rowProbabilities(solver.A, rowindex)) end end if solver.shuffleRows || solver.randomized Random.seed!(solver.seed) end if solver.shuffleRows shuffle!(solver.rowIndexCycle) end # start vector state.x .= x0 state.vl .= 0 state.u .= b if λ_ isa AbstractVector state.ɛw = 0 else state.ɛw = sqrt(λ_) end state.iteration = 0 end function solversolution(solver::Kaczmarz{matT, RN}) where {matT, R<:L2Regularization{<:AbstractVector}, RN <: Union{R, AbstractNestedRegularization{<:R}}} return solversolution(solver.state) .* (1 ./ sqrt.(λ(solver.L2))) end solversolution(solver::Kaczmarz) = solversolution(solver.state) solverconvergence(state::KaczmarzState) = (; :residual => norm(state.vl)) function iterate(solver::Kaczmarz, state::KaczmarzState) if done(solver,state) return nothing end if solver.randomized usedIndices = Int.(StatsBase.sample!(Random.GLOBAL_RNG, solver.rowIndexCycle, weights(solver.probabilities), zeros(solver.subMatrixSize), replace=false)) else usedIndices = solver.rowIndexCycle end for i in usedIndices row = solver.rowindex[i] iterate_row_index(solver, state, solver.A, row, i) end for r in solver.reg prox!(r, state.x) end state.iteration += 1 return state.x, state end iterate_row_index(solver::Kaczmarz, state::KaczmarzState, A::AbstractLinearSolver, row, index) = iterate_row_index(solver, Matrix(A[row, :]), row, index) function iterate_row_index(solver::Kaczmarz, state::KaczmarzState, A, row, index) state.τl = dot_with_matrix_row(A,state.x,row) state.αl = solver.denom[index]*(state.u[row]-state.τl-state.ɛw*state.vl[row]) kaczmarz_update!(A,state.x,row,state.αl) state.vl[row] += state.αl*state.ɛw end @inline done(solver::Kaczmarz,state::KaczmarzState) = state.iteration>=solver.iterations """ This function calculates the probabilities of the rows of the system matrix """ function rowProbabilities(A, rowindex) normA² = rownorm²(A, 1:size(A, 1)) p = zeros(length(rowindex)) for i=1:length(rowindex) j = rowindex[i] p[i] = rownorm²(A, j) / (normA²) end return p end ### initkaczmarz ### """ initkaczmarz(A::AbstractMatrix,λ) This function saves the denominators to compute αl in denom and the rowindices, which lead to an update of x in rowindex. """ function initkaczmarz(A,λ) T = real(eltype(A)) denom = T[] rowindex = Int64[] for i = 1:size(A, 1) s² = rownorm²(A,i) if s²>0 push!(denom,1/(s²+λ)) push!(rowindex,i) end end return A, denom, rowindex end function initkaczmarz(A, λ::AbstractVector) λ = real(eltype(A)).(λ) A = initikhonov(A, λ) return initkaczmarz(A, 0) end initikhonov(A, λ) = transpose((1 ./ sqrt.(λ)) .* transpose(A)) # optimize structure for row access initikhonov(prod::ProdOp{Tc, <:WeightingOp, matT}, λ) where {T, Tc<:Union{T, Complex{T}}, matT} = ProdOp(prod.A, initikhonov(prod.B, λ)) ### kaczmarz_update! ### """ kaczmarz_update!(A::DenseMatrix{T}, x::Vector, k::Integer, beta) where T This function updates x during the kaczmarz algorithm for dense matrices. """ function kaczmarz_update!(A::DenseMatrix{T}, x::Vector, k::Integer, beta) where T @simd for n=1:size(A,2) @inbounds x[n] += beta*conj(A[k,n]) end end """ kaczmarz_update!(B::Transpose{T,S}, x::Vector, k::Integer, beta) where {T,S<:DenseMatrix} This function updates x during the kaczmarz algorithm for dense matrices. """ function kaczmarz_update!(B::Transpose{T,S}, x::Vector, k::Integer, beta) where {T,S<:DenseMatrix} A = B.parent @inbounds @simd for n=1:size(A,1) x[n] += beta*conj(A[n,k]) end end function kaczmarz_update!(prod::ProdOp{Tc, WeightingOp{T, vecT}}, x, k, beta) where {T, Tc<:Union{T, Complex{T}}, vecT} weight = prod.A.weights[k] kaczmarz_update!(prod.B, x, k, weight*beta) # only for real weights end # kaczmarz_update! with manual simd optimization for (T,W, WS,shufflevectorMask,vσ) in [(Float32,:WF32,:WF32S,:shufflevectorMaskF32,:vσF32),(Float64,:WF64,:WF64S,:shufflevectorMaskF64,:vσF64)] eval(quote const $WS = VectorizationBase.pick_vector_width($T) const $W = Int(VectorizationBase.pick_vector_width($T)) const $shufflevectorMask = Val(ntuple(k -> iseven(k-1) ? k : k-2, $W)) const $vσ = Vec(ntuple(k -> (-1f0)^(k+1),$W)...) function kaczmarz_update!(A::Transpose{Complex{$T},S}, b::Vector{Complex{$T}}, k::Integer, beta::Complex{$T}) where {S<:DenseMatrix} b = reinterpret($T,b) A = reinterpret($T,A.parent) N = length(b) Nrep, Nrem = divrem(N,4*$W) # main loop Mrep, Mrem = divrem(Nrem,$W) # last iterations idx = MM{$W}(1) iOffset = 4*$W vβr = vbroadcast($WS, beta.re) * $vσ # vector containing (βᵣ,-βᵣ,βᵣ,-βᵣ,...) vβi = vbroadcast($WS, beta.im) # vector containing (βᵢ,βᵢ,βᵢ,βᵢ,...) GC.@preserve b A begin # protect A and y from GC vptrA = stridedpointer(A) vptrb = stridedpointer(b) for _ = 1:Nrep Base.Cartesian.@nexprs 4 i -> vb_i = vload(vptrb, ($W*(i-1) + idx,)) Base.Cartesian.@nexprs 4 i -> va_i = vload(vptrA, ($W*(i-1) + idx,k)) Base.Cartesian.@nexprs 4 i -> begin vb_i = muladd(va_i, vβr, vb_i) va_i = shufflevector(va_i, $shufflevectorMask) vb_i = muladd(va_i, vβi, vb_i) vstore!(vptrb, vb_i, ($W*(i-1) + idx,)) end idx += iOffset end for _ = 1:Mrep vb = vload(vptrb, (idx,)) va = vload(vptrA, (idx,k)) vb = muladd(va, vβr, vb) va = shufflevector(va, $shufflevectorMask) vb = muladd(va, vβi, vb) vstore!(vptrb, vb, (idx,)) idx += $W end if Mrem!=0 vloadMask = VectorizationBase.mask($T, Mrem) vb = vload(vptrb, (idx,), vloadMask) va = vload(vptrA, (idx,k), vloadMask) vb = muladd(va, vβr, vb) va = shufflevector(va, $shufflevectorMask) vb = muladd(va, vβi, vb) vstore!(vptrb, vb, (idx,), vloadMask) end end # GC.@preserve end end) end #= @doc "This function updates x during the kaczmarz algorithm for dense matrices." -> function kaczmarz_update!{T}(A::Matrix{T}, x::Vector{T}, k::Integer, beta::T) BLAS.axpy!(length(x), beta, pointer(A,sub2ind(size(A),1,k)), 1, pointer(x), 1) end =# """ kaczmarz_update!(B::Transpose{T,S}, x::Vector, k::Integer, beta) where {T,S<:SparseMatrixCSC} This funtion updates x during the kaczmarz algorithm for sparse matrices. """ function kaczmarz_update!(B::Transpose{T,S}, x::Vector, k::Integer, beta) where {T,S<:SparseMatrixCSC} A = B.parent N = A.colptr[k+1]-A.colptr[k] for n=A.colptr[k]:N-1+A.colptr[k] @inbounds x[A.rowval[n]] += beta*conj(A.nzval[n]) end end
RegularizedLeastSquares
https://github.com/JuliaImageRecon/RegularizedLeastSquares.jl.git
[ "MIT" ]
0.16.5
7c4d085f436b699e746e19173a3c640a79ceec8a
code
3067
export SequentialState, MultiThreadingState, prepareMatrixStates abstract type AbstractMatrixSolverState{S} <: AbstractSolverState{S} end """ SequentialState(states::Vector{ST}) where {S, ST <: AbstractSolverState{S}} SequentialState is a scheduler that runs each active state sequentially per iteration. """ mutable struct SequentialState{S, ST <: AbstractSolverState{S}} <: AbstractMatrixSolverState{S} states::Vector{ST} active::Vector{Bool} SequentialState(states::Vector{ST}) where {S, ST <: AbstractSolverState{S}} = new{S, ST}(states, fill(true, length(states))) end """ MultiThreadingState(states::Vector{ST}) where {S, ST <: AbstractSolverState{S}} MultiThreadingState is a scheduler that runs each active state in parallel per iteration. """ mutable struct MultiThreadingState{S, ST <: AbstractSolverState{S}} <: AbstractMatrixSolverState{S} states::Vector{ST} active::Vector{Bool} MultiThreadingState(states::Vector{ST}) where {S, ST <: AbstractSolverState{S}} = new{S, ST}(states, fill(true, length(states))) end """ init!(solver::AbstractLinearSolver, state::AbstractSolverState, b::AbstractMatrix; scheduler = SequentialState, kwargs...) Initialize the solver with each column of `b` and pass the corresponding states to the scheduler. """ function init!(solver::AbstractLinearSolver, state::AbstractSolverState, b::AbstractMatrix; scheduler = SequentialState, kwargs...) states = prepareMatrixStates(solver, state, b) multiState = scheduler(states) solver.state = multiState for (i, s) in enumerate(solver.state.states) init!(solver, s, b[:, i]; kwargs...) end solver.state.active .= true end function init!(solver::AbstractLinearSolver, state::AbstractMatrixSolverState, b::AbstractVector; kwargs...) singleState = first(state.states) solver.state = singleState init!(solver, singleState, b; kwargs...) end function prepareMatrixStates(solver::AbstractLinearSolver, state::AbstractSolverState, b::AbstractMatrix) states = [deepcopy(state) for _ in 1:size(b, 2)] return states end prepareMatrixStates(solver::AbstractLinearSolver, state::Union{SequentialState, MultiThreadingState}, b::AbstractMatrix) = prepareMatrixStates(solver, first(state.states), b) function iterate(solver::S, state::AbstractMatrixSolverState) where {S <: AbstractLinearSolver} activeIdx = findall(state.active) if isempty(activeIdx) return nothing end return iterate(solver, state, activeIdx) end function iterate(solver::AbstractLinearSolver, state::SequentialState, activeIdx) for i in activeIdx res = iterate(solver, state.states[i]) if isnothing(res) state.active[i] = false end end return state.active, state end function iterate(solver::AbstractLinearSolver, state::MultiThreadingState, activeIdx) Threads.@threads for i in activeIdx res = iterate(solver, state.states[i]) if isnothing(res) state.active[i] = false end end return state.active, state end solversolution(state::AbstractMatrixSolverState) = mapreduce(solversolution, hcat, state.states)
RegularizedLeastSquares
https://github.com/JuliaImageRecon/RegularizedLeastSquares.jl.git
[ "MIT" ]
0.16.5
7c4d085f436b699e746e19173a3c640a79ceec8a
code
7509
export optista, OptISTA mutable struct OptISTA{matA, matAHA, R, RN} <: AbstractProximalGradientSolver A::matA AHA::matAHA reg::R proj::Vector{RN} normalizeReg::AbstractRegularizationNormalization verbose::Bool iterations::Int64 state::AbstractSolverState{<:OptISTA} end mutable struct OptISTAState{rT <: Real, vecT <: Union{AbstractVector{rT}, AbstractVector{Complex{rT}}}} <: AbstractSolverState{OptISTA} x::vecT x₀::vecT y::vecT z::vecT zᵒˡᵈ::vecT res::vecT ρ::rT θ::rT θᵒˡᵈ::rT θn::rT α::rT β::rT γ::rT iteration::Int64 relTol::rT norm_x₀::rT rel_res_norm::rT end """ OptISTA(A; AHA=A'*A, reg=L1Regularization(zero(real(eltype(AHA)))), normalizeReg=NoNormalization(), iterations=50, verbose = false, rho=0.95 / power_iterations(AHA), theta=1, relTol=eps(real(eltype(AHA)))) OptISTA( ; AHA=, reg=L1Regularization(zero(real(eltype(AHA)))), normalizeReg=NoNormalization(), iterations=50, verbose = false, rho=0.95 / power_iterations(AHA), theta=1, relTol=eps(real(eltype(AHA)))) creates a `OptISTA` object for the forward operator `A` or normal operator `AHA`. OptISTA has a 2x better worst-case bound than FISTA, but actual performance varies by application. It stores 2 extra intermediate variables the size of the image compared to FISTA. Reference: - Uijeong Jang, Shuvomoy Das Gupta, Ernest K. Ryu, "Computer-Assisted Design of Accelerated Composite Optimization Methods: OptISTA," arXiv:2305.15704, 2023, [https://arxiv.org/abs/2305.15704] # Required Arguments * `A` - forward operator OR * `AHA` - normal operator (as a keyword argument) # Optional Keyword Arguments * `AHA` - normal operator is optional if `A` is supplied * `reg::AbstractParameterizedRegularization` - regularization term * `normalizeReg::AbstractRegularizationNormalization` - regularization normalization scheme; options are `NoNormalization()`, `MeasurementBasedNormalization()`, `SystemMatrixBasedNormalization()` * `rho::Real` - step size for gradient step; the default is `0.95 / max_eigenvalue` as determined with power iterations. * `theta::Real` - parameter for predictor-corrector step * `relTol::Real` - tolerance for stopping criterion * `iterations::Int` - maximum number of iterations * `verbose::Bool` - print residual in each iteration See also [`createLinearSolver`](@ref), [`solve!`](@ref). """ OptISTA(; AHA, kwargs...) = OptISTA(nothing; AHA = AHA, kwargs...) function OptISTA(A ; AHA = A'*A , reg = L1Regularization(zero(real(eltype(AHA)))) , normalizeReg = NoNormalization() , iterations = 50 , verbose = false , rho = 0.95 / power_iterations(AHA; verbose) , theta = 1 , relTol = eps(real(eltype(AHA))) ) T = eltype(AHA) rT = real(T) x = Vector{T}(undef,size(AHA,2)) x₀ = similar(x) y = similar(x) z = similar(x) zᵒˡᵈ = similar(x) res = similar(x) res[1] = Inf # avoid spurious convergence in first iterations θn = 1 for _ = 1:(iterations-1) θn = (1 + sqrt(1 + 4 * θn^2)) / 2 end θn = (1 + sqrt(1 + 8 * θn^2)) / 2 # Prepare regularization terms reg = isa(reg, AbstractVector) ? reg : [reg] indices = findsinks(AbstractProjectionRegularization, reg) other = [reg[i] for i in indices] deleteat!(reg, indices) if length(reg) != 1 error("OptISTA does not allow for more additional regularization terms, found $(length(reg))") end other = identity.(other) reg = normalize(OptISTA, normalizeReg, reg, A, nothing) state = OptISTAState(x, x₀, y, z, zᵒˡᵈ, res, rT(rho),rT(theta),rT(theta),rT(θn),rT(0),rT(1),rT(1), 0,rT(relTol), one(rT),rT(Inf)) return OptISTA(A, AHA, reg[1], other, normalizeReg, verbose, iterations, state) end function init!(solver::OptISTA, state::OptISTAState{rT, vecT}, b::otherT; kwargs...) where {rT, vecT, otherT <: AbstractVector} x = similar(b, size(state.x)...) x₀ = similar(b, size(state.x₀)...) y = similar(b, size(state.y)...) z = similar(b, size(state.z)...) zᵒˡᵈ = similar(b, size(state.zᵒˡᵈ)...) res = similar(b, size(state.res)...) state = OptISTAState(x, x₀, y, z, zᵒˡᵈ, res, state.ρ, state.θ, state.θᵒˡᵈ, state.θn, state.α, state.β, state.γ, state.iteration, state.relTol, state.norm_x₀, state.rel_res_norm) solver.state = state init!(solver, state, b; kwargs...) end """ init!(it::OptISTA, b::vecT ; A=solver.A , x::vecT=similar(b,0) , t::Float64=1.0) where T (re-) initializes the OptISTA iterator """ function init!(solver::OptISTA, state::OptISTAState{rT, vecT}, b::vecT; x0 = 0, θ=1) where {rT, vecT <: AbstractVector} if solver.A === nothing state.x₀ .= b else mul!(state.x₀, adjoint(solver.A), b) end state.norm_x₀ = norm(state.x₀) state.x .= x0 state.y .= state.x state.z .= state.x state.zᵒˡᵈ .= state.x state.res[:] .= rT(Inf) state.θ = θ state.θᵒˡᵈ = θ state.θn = θ for _ = 1:(solver.iterations-1) state.θn = (1 + sqrt(1 + 4 * state.θn^2)) / 2 end state.θn = (1 + sqrt(1 + 8 * state.θn^2)) / 2 state.rel_res_norm = rT(Inf) state.iteration = 0 # normalization of regularization parameters solver.reg = normalize(solver, solver.normalizeReg, solver.reg, solver.A, state.x₀) end solverconvergence(state::OptISTAState) = (; :residual => norm(state.res)) """ iterate(it::OptISTA, iteration::Int=0) performs one OptISTA iteration. """ function iterate(solver::OptISTA, state::OptISTAState) if done(solver, state) return nothing end # inertial parameters state.γ = 2state.θ / state.θn^2 * (state.θn^2 - 2state.θ^2 + state.θ) state.θᵒˡᵈ = state.θ if state.iteration == solver.iterations - 1 #the convergence rate depends on choice of # iterations! state.θ = (1 + sqrt(1 + 8 * state.θᵒˡᵈ^2)) / 2 else state.θ = (1 + sqrt(1 + 4 * state.θᵒˡᵈ^2)) / 2 end state.α = (state.θᵒˡᵈ - 1) / state.θ state.β = state.θᵒˡᵈ / state.θ # calculate residuum and do gradient step # state.y .-= state.ρ * state.γ .* (solver.AHA * state.x .- state.x₀) state.zᵒˡᵈ .= state.z #store this for inertia step state.z .= state.y #save yᵒˡᵈ in the variable z mul!(state.res, solver.AHA, state.x) state.res .-= state.x₀ state.y .-= state.ρ * state.γ .* state.res state.rel_res_norm = norm(state.res) / state.norm_x₀ solver.verbose && println("Iteration $(state.iteration); rel. residual = $(state.rel_res_norm)") # proximal map prox!(solver.reg, state.y, state.ρ * state.γ * λ(solver.reg)) # inertia steps # z = x + (y - yᵒˡᵈ) / γ # x = z + α * (z - zᵒˡᵈ) + β * (z - x) state.z ./= -state.γ #yᵒˡᵈ is already stored in z state.z .+= state.x .+ state.y ./ state.γ state.x .*= -state.β state.x .+= (1 + state.α + state.β) .* state.z state.x .-= state.α .* state.zᵒˡᵈ state.iteration += 1 # return the residual-norm as item and iteration number as state return state.x, state end @inline converged(solver::OptISTA, state::OptISTAState) = (state.rel_res_norm < state.relTol) @inline done(solver::OptISTA, state::OptISTAState) = converged(solver, state) || state.iteration >= solver.iterations
RegularizedLeastSquares
https://github.com/JuliaImageRecon/RegularizedLeastSquares.jl.git
[ "MIT" ]
0.16.5
7c4d085f436b699e746e19173a3c640a79ceec8a
code
8885
export pogm, POGM mutable struct POGM{matA,matAHA,R,RN} <: AbstractProximalGradientSolver A::matA AHA::matAHA reg::R proj::Vector{RN} normalizeReg::AbstractRegularizationNormalization verbose::Bool restart::Symbol iterations::Int64 state::AbstractSolverState{<:POGM} end mutable struct POGMState{rT <: Real, vecT <: Union{AbstractVector{rT}, AbstractVector{Complex{rT}}}} <: AbstractSolverState{POGM} x::vecT x₀::vecT xᵒˡᵈ::vecT y::vecT z::vecT w::vecT res::vecT ρ::rT theta::rT thetaᵒˡᵈ::rT α::rT β::rT γ::rT γᵒˡᵈ::rT σ::rT σ_fac::rT iteration::Int64 relTol::rT norm_x₀::rT rel_res_norm::rT end """ POGM(A; AHA = A'*A, reg = L1Regularization(zero(real(eltype(AHA)))), normalizeReg = NoNormalization(), iterations = 50, verbose = false, rho = 0.95 / power_iterations(AHA), theta = 1, sigma_fac = 1, relTol = eps(real(eltype(AHA))), restart = :none) POGM( ; AHA = , reg = L1Regularization(zero(real(eltype(AHA)))), normalizeReg = NoNormalization(), iterations = 50, verbose = false, rho = 0.95 / power_iterations(AHA), theta = 1, sigma_fac = 1, relTol = eps(real(eltype(AHA))), restart = :none) Creates a `POGM` object for the forward operator `A` or normal operator `AHA`. POGM has a 2x better worst-case bound than FISTA, but actual performance varies by application. It stores 3 extra intermediate variables the size of the image compared to FISTA. Only gradient restart scheme is implemented for now. # References: - A.B. Taylor, J.M. Hendrickx, F. Glineur, "Exact worst-case performance of first-order algorithms for composite convex optimization," Arxiv:1512.07516, 2015, SIAM J. Opt. 2017 [http://doi.org/10.1137/16m108104x] - Kim, D., & Fessler, J. A. (2018). Adaptive Restart of the Optimized Gradient Method for Convex Optimization. Journal of Optimization Theory and Applications, 178(1), 240–263. [https://doi.org/10.1007/s10957-018-1287-4] # Required Arguments * `A` - forward operator OR * `AHA` - normal operator (as a keyword argument) # Optional Keyword Arguments * `AHA` - normal operator is optional if `A` is supplied * `reg::AbstractParameterizedRegularization` - regularization term * `normalizeReg::AbstractRegularizationNormalization` - regularization normalization scheme; options are `NoNormalization()`, `MeasurementBasedNormalization()`, `SystemMatrixBasedNormalization()` * `rho::Real` - step size for gradient step; the default is `0.95 / max_eigenvalue` as determined with power iterations. * `theta::Real` - parameter for predictor-corrector step * `sigma_fac::Real` - parameter for decreasing γ-momentum ∈ [0,1] * `relTol::Real` - tolerance for stopping criterion * `iterations::Int` - maximum number of iterations * `restart::Symbol` - `:none`, `:gradient` options for restarting * `verbose::Bool` - print residual in each iteration See also [`createLinearSolver`](@ref), [`solve!`](@ref). """ POGM(; AHA, kwargs...) = POGM(nothing; kwargs..., AHA = AHA) function POGM(A ; AHA = A'*A , reg = L1Regularization(zero(real(eltype(AHA)))) , normalizeReg = NoNormalization() , iterations = 50 , verbose = false , rho = 0.95 / power_iterations(AHA; verbose) , theta = 1 , sigma_fac = 1 , relTol = eps(real(eltype(AHA))) , restart = :none ) T = eltype(AHA) rT = real(T) x = Vector{T}(undef, size(AHA, 2)) x₀ = similar(x) xᵒˡᵈ = similar(x) y = similar(x) z = similar(x) w = similar(x) res = similar(x) res[1] = Inf # avoid spurious convergence in first iterations reg = isa(reg, AbstractVector) ? reg : [reg] indices = findsinks(AbstractProjectionRegularization, reg) other = [reg[i] for i in indices] deleteat!(reg, indices) if length(reg) != 1 error("POGM does not allow for more additional regularization terms, found $(length(reg))") end other = identity.(other) reg = normalize(POGM, normalizeReg, reg, A, nothing) state = POGMState(x, x₀, xᵒˡᵈ, y, z, w, res, rT(rho), rT(theta), rT(theta), rT(0), rT(1), rT(1), rT(1), rT(1), rT(sigma_fac), 0, rT(relTol), one(rT), rT(Inf)) return POGM(A, AHA, reg[1], other, normalizeReg, verbose, restart, iterations, state) end function init!(solver::POGM, state::POGMState{rT, vecT}, b::otherT; kwargs...) where {rT, vecT, otherT <: AbstractVector} x = similar(b, size(state.x)...) x₀ = similar(b, size(state.x₀)...) xᵒˡᵈ = similar(b, size(state.xᵒˡᵈ)...) y = similar(b, size(state.y)...) z = similar(b, size(state.z)...) w = similar(b, size(state.w)...) res = similar(b, size(state.res)...) state = POGMState(x, x₀, xᵒˡᵈ, y, z, w, res, state.ρ, state.theta, state.theta, state.α, state.β, state.γ, state.γᵒˡᵈ, state.σ, state.σ_fac, state.iteration, state.relTol, state.norm_x₀, state.rel_res_norm) solver.state = state init!(solver, state, b; kwargs...) end """ init!(it::POGM, b::vecT, x::vecT=similar(b,0), theta::Number=1) (re-) initializes the POGM iterator """ function init!(solver::POGM, state::POGMState{rT, vecT}, b::vecT; x0 = 0, theta=1) where {rT, vecT <: AbstractVector} if solver.A === nothing state.x₀ .= b else mul!(state.x₀, adjoint(solver.A), b) end state.norm_x₀ = norm(state.x₀) state.x .= x0 state.xᵒˡᵈ .= 0 # makes no difference in 1st iteration what this is set to state.y .= 0 state.z .= 0 if solver.restart != :none #save time if not using restart state.w .= 0 end state.res[:] .= rT(Inf) state.theta = theta state.thetaᵒˡᵈ = theta state.σ = 1 state.rel_res_norm = rT(Inf) state.iteration = 0 # normalization of regularization parameters solver.reg = normalize(solver, solver.normalizeReg, solver.reg, solver.A, state.x₀) end solverconvergence(state::POGMState) = (; :residual => norm(state.res)) """ iterate(it::POGM, iteration::Int=0) performs one POGM iteration. """ function iterate(solver::POGM, state::POGMState) if done(solver, state) return nothing end # calculate residuum and do gradient step # solver.x .-= solver.ρ .* (solver.AHA * solver.x .- solver.x₀) state.xᵒˡᵈ .= state.x #save this for inertia step later mul!(state.res, solver.AHA, state.x) state.res .-= state.x₀ state.x .-= state.ρ .* state.res state.rel_res_norm = norm(state.res) / state.norm_x₀ solver.verbose && println("Iteration $(state.iteration); rel. residual = $(state.rel_res_norm)") # inertial parameters state.thetaᵒˡᵈ = state.theta if state.iteration == solver.iterations - 1 && solver.restart != :none #the convergence rate depends on choice of # iterations! state.theta = (1 + sqrt(1 + 8 * state.thetaᵒˡᵈ^2)) / 2 else state.theta = (1 + sqrt(1 + 4 * state.thetaᵒˡᵈ^2)) / 2 end state.α = (state.thetaᵒˡᵈ - 1) / state.theta state.β = state.σ * state.thetaᵒˡᵈ / state.theta state.γᵒˡᵈ = state.γ if solver.restart == :gradient state.γ = state.ρ * (1 + state.α + state.β) else state.γ = state.ρ * (2state.thetaᵒˡᵈ + state.theta - 1) / state.theta end # inertia steps # x + α * (x - y) + β * (x - xᵒˡᵈ) + ρα/γᵒˡᵈ * (z - xᵒˡᵈ) tmp = state.y state.y = state.x state.x = tmp # swap x and y state.x .*= -state.α # here we calculate -α * y, where y is now stored in x state.x .+= (1 + state.α + state.β) .* state.y state.x .-= (state.β + state.ρ * state.α / state.γᵒˡᵈ) .* state.xᵒˡᵈ state.x .+= state.ρ * state.α / state.γᵒˡᵈ .* state.z state.z .= state.x #store this for next iteration and GR # proximal map prox!(solver.reg, state.x, state.γ * λ(solver.reg)) for proj in solver.proj prox!(proj, state.x) end # gradient restart conditions if solver.restart == :gradient state.w .+= state.y .+ state.ρ ./ state.γ .* (state.x .- state.z) if real((state.w ⋅ state.x - state.w ⋅ state.z) / state.γ - state.w ⋅ state.res) < 0 solver.verbose && println("Gradient restart at iter $(state.iteration)") state.σ = 1 state.theta = 1 else # decreasing γ state.σ *= state.σ_fac end state.w .= state.ρ / state.γ .* (state.z .- state.x) .- state.y end # return the residual-norm as item and iteration number as state state.iteration += 1 return state.x, state end @inline converged(solver::POGM, state::POGMState) = (state.rel_res_norm < state.relTol) @inline done(solver::POGM, state::POGMState) = converged(solver, state) || state.iteration >= solver.iterations
RegularizedLeastSquares
https://github.com/JuliaImageRecon/RegularizedLeastSquares.jl.git
[ "MIT" ]
0.16.5
7c4d085f436b699e746e19173a3c640a79ceec8a
code
11273
export PrimalDualSolver mutable struct PrimalDualSolver{T,A} <: AbstractPrimalDualSolver A::Matrix{T} reg::Vector{<:AbstractRegularization} gradientOp::A u::Vector{T} x::Vector{T} cO::Vector{T} y1::Vector{T} y2::Vector{T} σ::T τ::T ϵ::T PrimalDualGap::T enforceReal::Bool enforcePositive::Bool iterations::Int64 shape::NTuple{2,Int64} normalizeReg::AbstractRegularizationNormalization end """ PrimalDualSolver(A; λ = 1e-4, reg = L1Regularization(λ), gradientOp = nothing, enforceReal=false, enforcePositive=false, iterations=10, σ=1, τ=1, ϵ=1e-10, PrimalDualGap=1, shape=(size(A,2),1), normalizeReg = NoNormalization()) creates a `PrimalDualSolver` object for the forward operator `A`. # Required Arguments * `A` - forward operator # Optional Keyword Arguments * TODO See also [`createLinearSolver`](@ref), [`solve!`](@ref). """ # TODO: replace keywords with ASCII symbols function PrimalDualSolver(A::Matrix{T} ; λ = 1e-4 , reg = L1Regularization(λ) , normalizeReg::AbstractRegularizationNormalization = NoNormalization() , gradientOp = nothing , enforceReal::Bool=false , enforcePositive::Bool=false , iterations::Int64=10 , σ=1 , τ=1 , ϵ=1e-10 , PrimalDualGap=1 , shape::NTuple{2,Int64}=(size(A,2),1) ) where T M,N = size(A) reg = isa(reg, AbstractVector) ? reg : [reg] if reg[1] isa L1Regularization gradientOp = opEye(T,N) #UniformScaling(one(T)) elseif reg[1] isa TVRegularization gradientOp = gradientOperator(T,shape) end u = zeros(T,M) x = zeros(T,N) cO = zeros(T,N) y1 = zeros(T,M) y2 = zeros(T,size(gradientOp*x,1)) # normalization parameters reg = normalize(PrimalDualSolver, normalizeReg, reg, A, nothing) return PrimalDualSolver(A,reg,gradientOp,u,x,cO,y1,y2,T(σ),T(τ),T(ϵ),T(PrimalDualGap),enforceReal,enforcePositive,iterations,shape, normalizeReg) end function init!(solver::PrimalDualSolver, b; x0 = 0) solver.u .= b solver.PrimalDualGap = (1/2)*(norm(solver.u,2))^2 solver.x .= x0 solver.cO .= 0 solver.y1 .= 0 solver.y2 .= 0 solver.reg = normalize(solver, solver.normalizeReg, solver.reg, solver.A, b) end function iterate(solver::PrimalDualSolver, iteration=0) if done(solver,iteration) return nothing end # updating dual variables for i=1:length(solver.reg) solver.y1 .= (solver.y1 + solver.σ*(solver.A*solver.x - solver.u))./(1+solver.σ) if solver.reg[1] isa L1Regularization solver.y2 .= ProxL1Conj(solver.y2 + solver.σ*solver.gradientOp*solver.x, solver.reg[1].λ, solver.shape) elseif solver.reg[1] isa TVRegularization solver.y2 .= ProxTVConj(solver.y2 + solver.σ*solver.gradientOp*solver.x, solver.reg[1].λ, solver.shape) end end # updating primal variable for i=1:length(solver.reg) solver.x += - solver.τ*(adjoint(solver.A)*solver.y1 + adjoint(solver.gradientOp)*solver.y2) end applyConstraints(solver.x, nothing, solver.enforceReal, solver.enforcePositive) # todo remove constraints # updating convergence measure for i=1:length(solver.reg) # todo how to handle projection reg solver.PrimalDualGap = abs((1/2)*norm(solver.A*solver.x-solver.u)^2 + solver.reg[1].λ*norm(solver.x,1) + (1/2)*norm(solver.y1,2)^2 + dot(solver.y1,solver.u)) end return solver.y1, iteration+1 end function converged(solver::PrimalDualSolver) if (solver.PrimalDualGap) >= solver.ϵ return false end return true end @inline done(solver::PrimalDualSolver,iteration::Int) = converged(solver) || iteration>=solver.iterations # Proximal map of the convex conjugate of the l1 norm function ProxL1Conj(x::Vector{T},α::T,shape::NTuple{2,Int64}) where T m,n = shape p1 = reshape(x,m,n) # threshold p1 for j=1:n, i=1:m p1[i,j] = sign(p1[i,j])*min(norm(p1[i,j]),α) end for i=1:m p1[i,n] = sign(p1[i,n])*min(abs(p1[i,n]),α) end return vcat(vec(p1)) end # Gradient function BB(u::Vector{T}, shape::NTuple{2,Int64}) where T m,n = shape u = reshape(u,m,n) p1 = zeros(T,m,n); p2 = zeros(T,m,n); p3 = zeros(T,m,n); p4 = zeros(T,m,n) p5 = zeros(T,m,n); p6 = zeros(T,m,n); p7 = zeros(T,m,n); p8 = zeros(T,m,n) p1[1:m-1,1:n] = u[1:m-1,1:n]-u[2:m,1:n] p2[1:m,1:n-1] = u[1:m,1:n-1]-u[1:m,2:n] p3[1:m-1,1:n-1] = u[1:m-1,1:n-1]-u[2:m,2:n] p4[1:m-1,2:n] = u[1:m-1,2:n]-u[2:m,1:n-1] p5[1:m-2,1:n-1] = u[1:m-2,1:n-1]-u[3:m,2:n] p6[1:m-2,2:n] = u[1:m-2,2:n]-u[3:m,1:n-1] p7[1:m-1,1:n-2] = u[1:m-1,1:n-2]-u[2:m,3:n] p8[1:m-1,3:n] = u[1:m-1,3:n]-u[2:m,1:n-2] return vcat(vec(p1),vec(p2),vec(p3),vec(p4),vec(p5),vec(p6),vec(p7),vec(p8)) end # Divergence function BBS(u::Array{T},shape::NTuple{2,Int64}) where T m,n = shape p1 = reshape(u[1:m*n],m,n); p2 = reshape(u[m*n+1:2*n*m],m,n) p3 = reshape(u[2*m*n+1:3*m*n],m,n); p4 = reshape(u[3*m*n+1:4*m*n],m,n) p5 = reshape(u[4*m*n+1:5*m*n],m,n); p6 = reshape(u[5*m*n+1:6*m*n],m,n) p7 = reshape(u[6*m*n+1:7*m*n],m,n); p8 = reshape(u[7*m*n+1:end],m,n) x = zeros(T, m, n) # points in the corners x[1,1] = p1[1,1]+p2[1,1]+p3[1,1]+p4[1,1]+p5[1,1]+p6[1,1]+p7[1,1]+p8[1,1] x[m,1] = p2[m,1]-p1[m-1,1]+p3[m,1]+p4[m,1]-p4[m-1,2]+p5[m,1]+p6[m,1]-p6[m-2,2]+p7[m,1]+p8[m,1]-p8[m-1,3] x[1,n] = p1[1,n]-p2[1,n-1]+p3[1,n]+p4[1,n]+p5[1,n]+p6[1,n]+p7[1,n]+p8[1,n] x[m,n] = -p1[m-1,n]-p2[m,n-1]-p3[m-1,n-1]-p5[m-2,n-1]-p7[m-1,n-2] # remaining points with i=1 (first row) x[1,2:n-1] = p1[1,2:n-1]+p2[1,2:n-1]-p2[1,1:n-2]+p3[1,2:n-1]+p4[1,2:n-1]+p5[1,2:n-1]+p6[1,2:n-1]+p7[1,2:n-1]+p8[1,2:n-1] # remaining points with i=2 (second row) x[2,3:n-2] = p1[2,3:n-2]-p1[1,3:n-2]+p2[2,3:n-2]-p2[2,2:n-3]+p3[2,3:n-2]-p3[1,2:n-3]+p4[2,3:n-2]-p4[1,4:n-1]+p5[2,3:n-2]+p6[2,3:n-2]+p7[2,3:n-2]-p7[1,1:n-4]+p8[2,3:n-2]-p8[1,5:n] #remaining points with i=m (last row) x[m,3:n-2] = -p1[m-1,3:n-2]+p2[m,3:n-2]-p2[m,2:n-3]-p3[m-1,2:n-3]+p4[m,3:n-2]-p4[m-1,4:n-1]+p5[m,3:n-2]-p5[m-2,2:n-3]+p6[m,3:n-2]-p6[m-2,4:n-1]+p7[m,3:n-2]-p7[m-1,1:n-4]+p8[m,3:n-2]-p8[m-1,5:n] # remaingin points with j=1 (first column) x[3:m,1] = p1[3:m,1]-p1[2:m-1,1]+p2[3:m,1]+p3[3:m,1]+p4[3:m,1]-p4[2:m-1,2]+p5[3:m,1]+p6[3:m,1]-p6[1:m-2,2]+p7[3:m,1]+p8[3:m,1]-p8[2:m-1,3] # remaingin points with j=2 (second column) x[3:m,2] = p1[3:m,2]-p1[2:m-1,2]+p2[3:m,2]-p2[3:m,1]+p3[3:m,2]-p3[2:m-1,1]+p4[3:m,2]-p4[2:m-1,3]+p5[3:m,2]-p5[1:m-2,1]+p6[3:m,2]-p6[1:m-2,3]+p7[3:m,2]+p8[3:m,2]-p8[2:m-1,4] #remaingin points with j=n (last column) x[3:m,n] = p1[3:m,n]-p1[2:m-1,n]-p2[3:m,n-1]-p3[2:m-1,n-1]+p4[3:m,n]+p5[3:m,n]-p5[1:m-2,n-1]+p6[3:m,n]+p7[3:m,n]-p7[2:m-1,n-2]+p8[3:m,n] #remaingin points with j=n-1 x[3:m,n-1] = p1[3:m,n-1]-p1[2:m-1,n-1]+p2[3:m,n-1]-p2[3:m,n-2]+p3[3:m,n-1]-p3[2:m-1,n-2]+p4[3:m,n-1]-p4[2:m-1,n]+p5[3:m,n-1]-p5[1:m-2,n-2]+p6[3:m,n-1]-p6[1:m-2,n]+p7[3:m,n-1]-p7[2:m-1,n-3]+p8[3:m,n-1] #remaingin points with j=n-2 x[3:m,n-2] = p1[3:m,n-2]-p1[2:m-1,n-2]+p2[3:m,n-2]-p2[3:m,n-3]+p3[3:m,n-2]-p3[2:m-1,n-3]+p4[3:m,n-2]-p4[2:m-1,n-1]+p5[3:m,n-2]-p5[1:m-2,n-3]+p6[3:m,n-2]-p6[1:m-2,n-1]+p7[3:m,n-2]-p7[2:m-1,n-4]+p8[3:m,n-2]-p8[2:m-1,n] #all remaining (inner) matrix elements x[3:m-1,3:n-3] = p1[3:m-1,3:n-3]-p1[2:m-2,3:n-3]+p2[3:m-1,3:n-3]-p2[3:m-1,2:n-4]+p3[3:m-1,3:n-3]-p3[2:m-2,2:n-4]+p4[3:m-1,3:n-3]-p4[2:m-2,4:n-2]+p5[3:m-1,3:n-3]-p5[1:m-3,2:n-4]+p6[3:m-1,3:n-3]-p6[1:m-3,4:n-2]+p7[3:m-1,3:n-3]-p7[2:m-2,1:n-5]+p8[3:m-1,3:n-3]-p8[2:m-2,5:n-1] return vec(x) end function gradientOperator(::Type{T},shape::NTuple{2,Int64}) where T M,N = shape ncol = M*N nrow = 8*M*N return LinearOperator{T}(nrow,ncol,false,false,x->BB(x,shape),nothing,x->BBS(x,shape)) end # Proximal map of the convex conjugate of the debiasing function function ProxTVConj(x::Vector{T},α::T,shape::NTuple{2,Int64}) where T m,n = shape p1 = reshape(x[1:m*n],m,n) p2 = reshape(x[m*n+1:2*m*n],m,n) p3 = reshape(x[2*m*n+1:3*m*n],m,n) p4 = reshape(x[3*m*n+1:4*m*n],m,n) p5 = reshape(x[4*m*n+1:5*m*n],m,n) p6 = reshape(x[5*m*n+1:6*m*n],m,n) p7 = reshape(x[6*m*n+1:7*m*n],m,n) p8 = reshape(x[7*m*n+1:end],m,n) # threshold p1 for j=1:n, i=1:m p1[i,j] = (sqrt(5)-2)*sign(p1[i,j])*min(norm([p1[i,j],p2[i,j],p3[i,j],p4[i,j],p5[i,j],p6[i,j],p7[i,j],p8[i,j]]),α) end for i=1:m p1[i,n] = (sqrt(5)-2)*sign(p1[i,n])*min(abs(p1[i,n]),α) end # threshold p2 for j=1:n, i=1:m p2[i,j] = (sqrt(5)-2)*sign(p2[i,j])*min(norm([p1[i,j],p2[i,j],p3[i,j],p4[i,j],p5[i,j],p6[i,j],p7[i,j],p8[i,j]]),α) end for j=1:n p2[m,j] = (sqrt(5)-2)*sign(p2[m,j])*min(abs(p2[m,j]),α) end # threshold p3 for j=1:n, i=1:m p3[i,j] = (sqrt(5)-3*sqrt(2)/2)*sign(p3[i,j])*min(norm([p1[i,j],p2[i,j],p3[i,j],p4[i,j],p5[i,j],p6[i,j],p7[i,j],p8[i,j]]),α) end for i=1:m p3[i,n] = (sqrt(5)-3*sqrt(2)/2)*sign(p3[i,n])*min(abs(p3[i,n]),α) end for j=1:n p3[m,j] = (sqrt(5)-3*sqrt(2)/2)*sign(p3[m,j])*min(abs(p3[m,j]),α) end # threshold p4 for j=1:n, i=1:m p4[i,j] = (sqrt(5)-3*sqrt(2)/2)*sign(p4[i,j])*min(norm([p1[i,j],p2[i,j],p3[i,j],p4[i,j],p5[i,j],p6[i,j],p7[i,j],p8[i,j]]),α) end for i=1:m p4[i,n] = (sqrt(5)-3*sqrt(2)/2)*sign(p4[i,n])*min(abs(p4[i,n]),α) end for j=1:n p4[m,j] = (sqrt(5)-3*sqrt(2)/2)*sign(p4[m,j])*min(abs(p4[m,j]),α) end # threshold p5 for j=1:n, i=1:m p5[i,j] = ((1+sqrt(2)-sqrt(5))/2)*sign(p5[i,j])*min(norm([p1[i,j],p2[i,j],p3[i,j],p4[i,j],p5[i,j],p6[i,j],p7[i,j],p8[i,j]]),α) end for i=1:m p5[i,n] = ((1+sqrt(2)-sqrt(5))/2)*sign(p5[i,n])*min(abs(p5[i,n]),α) end for j=1:n p5[m,j] = ((1+sqrt(2)-sqrt(5))/2)*sign(p5[m,j])*min(abs(p5[m,j]),α) end # threshold p6 for j=1:n, i=1:m p6[i,j] = ((1+sqrt(2)-sqrt(5))/2)*sign(p6[i,j])*min(norm([p1[i,j],p2[i,j],p3[i,j],p4[i,j],p5[i,j],p6[i,j],p7[i,j],p8[i,j]]),α) end for i=1:m p6[i,n] = ((1+sqrt(2)-sqrt(5))/2)*sign(p6[i,n])*min(abs(p6[i,n]),α) end for j=1:n p6[m,j] = ((1+sqrt(2)-sqrt(5))/2)*sign(p6[m,j])*min(abs(p6[m,j]),α) end # threshold p7 for j=1:n, i=1:m p7[i,j] = ((1+sqrt(2)-sqrt(5))/2)*sign(p7[i,j])*min(norm([p1[i,j],p2[i,j],p3[i,j],p4[i,j],p5[i,j],p6[i,j],p7[i,j],p8[i,j]]),α) end for i=1:m p7[i,n] = ((1+sqrt(2)-sqrt(5))/2)*sign(p7[i,n])*min(abs(p7[i,n]),α) end for j=1:n p7[m,j] = ((1+sqrt(2)-sqrt(5))/2)*sign(p7[m,j])*min(abs(p7[m,j]),α) end # threshold p8 for j=1:n, i=1:m p8[i,j] = ((1+sqrt(2)-sqrt(5))/2)*sign(p8[i,j])*min(norm([p1[i,j],p2[i,j],p3[i,j],p4[i,j],p5[i,j],p6[i,j],p7[i,j],p8[i,j]]),α) end for i=1:m p8[i,n] = ((1+sqrt(2)-sqrt(5))/2)*sign(p8[i,n])*min(abs(p8[i,n]),α) end for j=1:n p8[m,j] = ((1+sqrt(2)-sqrt(5))/2)*sign(p8[m,j])*min(abs(p8[m,j]),α) end return vcat(vec(p1),vec(p2),vec(p3),vec(p4),vec(p5),vec(p6),vec(p7),vec(p8)) end
RegularizedLeastSquares
https://github.com/JuliaImageRecon/RegularizedLeastSquares.jl.git