aboutsummaryrefslogtreecommitdiff
path: root/Source/Initialization/TemperatureProperties.cpp
blob: 76ea1ac1bccabcf8444889253113a67f25cf620a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/* Copyright 2021 Hannah Klion
 *
 *
 * This file is part of WarpX.
 *
 * License: BSD-3-Clause-LBNL
 */
#include "TemperatureProperties.H"

#include "Utils/Parser/ParserUtils.H"
#include "Utils/TextMsg.H"

#include <ablastr/warn_manager/WarnManager.H>

/*
 * Construct TemperatureProperties based on the passed parameters.
 * If temperature is a constant, store value. If a parser, make and
 * store the parser function
 */
TemperatureProperties::TemperatureProperties (amrex::ParmParse& pp) {
    // Set defaults
    amrex::Real theta;
    std::string temp_dist_s = "constant";
    std::string mom_dist_s;

    pp.query("theta_distribution_type", temp_dist_s);
    pp.query("momentum_distribution_type", mom_dist_s);
    if (temp_dist_s == "constant") {
        WARPX_ALWAYS_ASSERT_WITH_MESSAGE(
            utils::parser::queryWithParser(pp, "theta", theta),
            "Temperature parameter theta not specified");

        // Do validation on theta value

        WARPX_ALWAYS_ASSERT_WITH_MESSAGE(theta >= 0,
            "Temperature parameter theta = " + std::to_string(theta) +
            " is less than zero, which is not allowed");

        WARPX_ALWAYS_ASSERT_WITH_MESSAGE(
            mom_dist_s != "maxwell_juttner" ||
            theta >= 0.1,
            "Temperature parameter theta = " +
            std::to_string(theta) +
            " is less than minimum 0.1 allowed for Maxwell-Juttner."
        );


        if (mom_dist_s == "maxwell_boltzmann" && theta > 0.01) {
            ablastr::warn_manager::WMRecordWarning(
                "Temperature",
                std::string{"Maxwell-Boltzmann distribution has errors greater than 1%"} +
                std::string{" for temperature parameter theta > 0.01. (theta = "} +
                std::to_string(theta) + " given)");
        }

        m_type = TempConstantValue;
        m_temperature = theta;
    }
    else if (temp_dist_s == "parser") {
        std::string str_theta_function;
        utils::parser::Store_parserString(pp, "theta_function(x,y,z)", str_theta_function);
        m_ptr_temperature_parser =
            std::make_unique<amrex::Parser>(
                utils::parser::makeParser(str_theta_function,{"x","y","z"}));
        m_type = TempParserFunction;
    }
    else {
        std::stringstream stringstream;
        std::string string;
        stringstream << "Temperature distribution type '" << temp_dist_s << "' not recognized.";
        string = stringstream.str();
        WARPX_ABORT_WITH_MESSAGE(string.c_str());
    }
}