/
rational_dreamer
/
fast-mc
Обзор
Документация
Войти
/
rational_dreamer
/
fast-mc
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
HeisModel/common/node_data.cuh
129 строк
3 KB
Evgeny Vasinovich
add license
31 окт 2025, 15:45
31 окт 2025, 15:45
332460e
Код
Авторство
О чём код?
/* * Copyright 2025 FastMC authors (see AUTHORS file) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * SPDX-License-Identifier: Apache-2.0 */ #pragma once #include "vector_types.h" #include <cuComplex.h> struct NodeData{ double E; double M; double Mafm; }; __constant__ float2 sigmaX[2][2] = { {{0,0},{1,0}}, {{1,0},{0,0}} }; __constant__ float2 sigmaY[2][2] = { {{0,0},{0,-1}}, {{0,1},{0,0}} }; __constant__ float2 sigmaZ[2][2] = { {{1,0},{0,0}}, {{0,0},{-1,0}} }; __host__ __device__ float2 operator*(const float2& z1, const float2& z2){ return cuCmulf(z1,z2); } __host__ __device__ float2 operator*(const float& r1, const float2& z2){ return {z2.x * r1, z2.y * r1}; } __host__ __device__ float2 operator*(const float2& z1, const float& r2){ return r2 * z1; } __host__ __device__ float2 operator/(const float2& z1, const float& r2){ return {z1.x / r2, z1.y / r2}; } __host__ __device__ float2 operator+(const float2& z1, const float2& z2){ return cuCaddf(z1,z2); } __host__ __device__ float2 operator-(const float2& z1, const float2& z2){ return cuCsubf(z1,z2); } __host__ __device__ float2 cuExpf(const float2& z){ float x = expf(z.x) * cosf(z.y); float y = expf(z.x) * sinf(z.y); return {x,y}; } __host__ __device__ float2 cuExpfI(const float& r){ return {cosf(r),sinf(r)}; } struct Node{ __host__ __device__ float Sx() const{ return average(sigmaX); }; __host__ __device__ float Sy() const{ return average(sigmaY); }; __host__ __device__ float Sz() const{ return average(sigmaZ); }; __host__ __device__ // среднее значение передаваемого оператора (матрица 2x2) на текущем состоянии float average(float2 op[2][2]) const{ float2 C0_1 = op[0][0] * C0 + op[0][1] * C1; float2 C1_1 = op[1][0] * C0 + op[1][1] * C1; return cuCrealf(cuConjf(C0) * C0_1 + cuConjf(C1) * C1_1); }; __host__ __device__ Node(float2 C0, float2 C1) :C0(C0), C1(C1) {} // __host__ __device__ Node() = default; //private: float2 C0 = {1,0}; float2 C1 = {0,0}; }; __host__ __device__ float operator* (const Node& l,const Node& r){ return l.Sx() * r.Sx() + l.Sy() * r.Sy() + l.Sz() * r.Sz(); } __host__ __device__ NodeData operator+ (const NodeData& l,const NodeData& r) { return {l.E + r.E, l.M + r.M, l.Mafm + r.Mafm}; }