/
rational_dreamer
/
fast-mc
Обзор
Документация
Войти
/
rational_dreamer
/
fast-mc
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
HeisModel/common/model_data.h
112 строк
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> #include <string> #include <iostream> #include <fstream> #include <vector_types.h> struct ComputePoint { int L; int copies; float J; float h; float T; int aSteps; int mSteps; __host__ __device__ int pbc(int x){ if(x < 0) return x + L; return x % L; }; friend std::ifstream& operator>>(std::ifstream& ifs, ComputePoint& p); friend std::ostream& operator<<(std::ostream& out, const ComputePoint& p); }; std::ifstream& operator>>(std::ifstream& ifs, ComputePoint& p) { int L; if(ifs >> L){ p.L = L; ifs >> p.copies >> p.J >> p.h >> p.T >> p.aSteps >> p.mSteps; } return ifs; } std::ostream& operator<<(std::ostream& out, const ComputePoint& p) { std::cout << "L: " << p.L << " copies: " << p.copies << " J: " << p.J << " h: " << p.h << " T:" << p.T << " aSteps:" << p.aSteps << " mSteps:" << p.mSteps; return out; } struct ModelParams{ std::vector<ComputePoint> computePoints; void read(const std::string fileName) { using namespace std; ifstream ifs(fileName, ifstream::in); if (!ifs) { cout << "не удалось открыть файл с параметрами" << endl; return; } ComputePoint p; while (ifs >> p) { computePoints.push_back(p); } ifs.close(); } void readOldFormat(const std::string fileName) { using namespace std; ifstream ifs(fileName, ifstream::in); if (!ifs) { cout << "не удалось открыть файл с параметрами" << endl; return; } ComputePoint p; string name; ifs >> name >> p.L; cout << name << " = " << p.L << endl; ifs >> name >> p.copies; cout << name << " = " << p.copies << endl; ifs >> name >> p.J; cout << name << " = " << p.J << endl; ifs >> name >> p.h; cout << name << " = " << p.h << endl; int count; //кол-во диапазонов ifs >> name >> count; cout << name << count <<endl; for (int i = 0; i < count; i++) { float T1; float T2; float dT; ifs >> T1 >> T2 >> dT >> p.aSteps >> p.mSteps; for (p.T = T1; p.T > T2 - dT / 2; p.T -= dT){ computePoints.push_back(p); } } if (!ifs) { cout << "ошибка при чтении файла " << fileName << endl; return; } } };