PLaSK library

Loading...
Searching...
No Matches
rootdigger.cpp
Go to the documentation of this file.
1/*
2 * This file is part of PLaSK (https://plask.app) by Photonics Group at TUL
3 * Copyright (c) 2022 Lodz University of Technology
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, version 3.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 */
14#include "rootdigger.hpp"
15#include "muller.hpp"
16#include "broyden.hpp"
17#include "brent.hpp"
18
19 namespace plask { namespace optical { namespace effective {
20
21std::unique_ptr<RootDigger> RootDigger::get(Solver* solver, const function_type& func, DataLog<dcomplex,dcomplex>& detlog, const Params& params) {
22 typedef std::unique_ptr<RootDigger> Res;
23 if (params.method == RootDigger::ROOT_MULLER) return Res(new RootMuller(*solver, func, detlog, params));
24 else if (params.method == RootDigger::ROOT_BROYDEN) return Res(new RootBroyden(*solver, func, detlog, params));
25 else if (params.method == RootDigger::ROOT_BRENT) return Res(new RootBrent(*solver, func, detlog, params));
26 throw BadInput(solver->getId(), "wrong root finding method");
27 return Res();
28}
29
30 void RootDigger::readRootDiggerConfig(XMLReader& reader, Params& params) {
31 params.tolx = reader.getAttribute<double>("tolx", params.tolx);
32 params.tolf_min = reader.getAttribute<double>("tolf-min", params.tolf_min);
33 params.tolf_max = reader.getAttribute<double>("tolf-max", params.tolf_max);
34 params.maxstep = reader.getAttribute<double>("maxstep", params.maxstep);
35 params.maxiter = reader.getAttribute<int>("maxiter", params.maxiter);
36 params.alpha = reader.getAttribute<double>("alpha", params.alpha);
37 params.lambda_min = reader.getAttribute<double>("lambd", params.lambda_min);
38 params.initial_dist = reader.getAttribute<dcomplex>("initial-range", params.initial_dist);
39 params.method = reader.enumAttribute<RootDigger::Method>("method")
40 .value("brent", RootDigger::ROOT_BRENT)
41 .value("broyden", RootDigger::ROOT_BROYDEN)
42 .value("muller", RootDigger::ROOT_MULLER)
43 .get(params.method);
44 params.stairs = reader.getAttribute<int>("stairs", params.stairs);
45 reader.requireTagEnd();
46}
47
48}}} // namespace plask::optical::effective