Module: CodeRunner::Gs2::GSLVectorComplexes

Included in:
CodeRunner::Gs2
Defined in:
lib/gs2crmod/gsl_data.rb

Instance Method Summary collapse

Instance Method Details

#phi_along_field_line_gsl_vector_complex(options) ⇒ Object



1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
# File 'lib/gs2crmod/gsl_data.rb', line 1022

def phi_along_field_line_gsl_vector_complex(options)
Dir.chdir(@directory) do
# 		eputs options[:ky]
# 		eputs Dir.pwd
		#eputs "Start phi_along_field_line"
		options.convert_to_index(self, :ky)
		if options[:t_index] or options[:t]
			#extra option required is t_index
			raise CRFatal.new("write_phi_over_time is not enabled so this function won't work") unless @write_phi_over_time
			
			options.convert_to_index(self, :t)
			case @grid_option
			when "single"
				temp = GSL::Vector.alloc(netcdf_file.var('phi_t').get({'start' => [0,0,0,0, options[:t_index] - 1], 'end' => [-1,-1,0,0, options[:t_index] - 1]}).to_a[0][0][0].flatten)
			when "range"
				a = netcdf_file.var('phi_t').get({'start' => [0, 0, options[:kx_index]-1, options[:ky_index] - 1, options[:t_index] - 1], 'end' => [-1, -1, options[:kx_index]-1, options[:ky_index] - 1, options[:t_index]-1]})
				#temp =  GSL::Vector.alloc(a.to_a[0].values_at(*kx_elements).flatten)
				temp =  GSL::Vector.alloc(a.to_a[0][0].flatten)
			when "box"
				options.convert_to_index(self, :ky, :kx)
				kx_elements = gsl_vector('linked_kx_elements', options).to_a
#  				pp kx_elements
				a = netcdf_file.var('phi_t').get({
					'start' => [0,0,0,options[:ky_index] - 1, options[:t_index] - 1], 
					'end' => [-1,-1,-1, options[:ky_index] - 1, options[:t_index] - 1]
				}).to_a[0][0].values_at(*kx_elements).flatten
# 				pp a.index(nil)
# 				temp = GSL::Vector.alloc(netcdf_file.var('phi').get.to_a[options[:ky_index] - 1 ].values_at(*kx_elements).flatten)
				#ep a
				temp = GSL::Vector.alloc(a)
			end

			#eputs "End phi_along_field_line"
			return GSL::Vector::Complex.alloc(temp.subvector_with_stride(0, 2), temp.subvector_with_stride(1, 2)) 
		else
			case @grid_option
			when "single"
				temp = GSL::Vector.alloc(netcdf_file.var('phi').get({'start' => [0,0, 0, 0], 'end' => [-1,-1,0,0]}).to_a.flatten)
			when "range"
				a = netcdf_file.var('phi').get({'start' => [0, 0, 0, options[:ky_index] - 1], 'end' => [-1, -1, -1, options[:ky_index] - 1]})
				#temp =  GSL::Vector.alloc(a.to_a[0].values_at(*kx_elements).flatten)
				temp =  GSL::Vector.alloc(a.to_a[0][0].flatten)
			when "box"
				ep 'kx_elements', kx_elements = gsl_vector('linked_kx_elements', options).to_a
				a = netcdf_file.var('phi').get({'start' => [0, 0, 0, options[:ky_index] - 1], 'end' => [-1, -1, -1, options[:ky_index] - 1]})
				temp =  GSL::Vector.alloc(a.to_a[0].values_at(*kx_elements).flatten)
			else
				raise "invalid grid option"
			end
			
			vector = GSL::Vector::Complex.alloc(temp.subvector_with_stride(0, 2), temp.subvector_with_stride(1, 2))
			#ep 'vector', vector.real
			return vector
		end
	end
#  			eputs data; gets
end