summaryrefslogtreecommitdiffstatshomepage
path: root/src/lib/netlist/solver/nld_ms_direct2.h
blob: 4094f84c8a2aa826f97d9b9e2dce750561ddc1b1 (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
// license:GPL-2.0+
// copyright-holders:Couriersud
/*
 * nld_ms_direct1.h
 *
 */

#ifndef NLD_MS_DIRECT2_H_
#define NLD_MS_DIRECT2_H_

#include "solver/nld_ms_direct.h"
#include "solver/nld_solver.h"

namespace netlist
{
	namespace devices
	{

class matrix_solver_direct2_t: public matrix_solver_direct_t<2,2>
{
public:

	matrix_solver_direct2_t(netlist_t &anetlist, const pstring &name, const solver_parameters_t *params)
		: matrix_solver_direct_t<2, 2>(anetlist, name, params, 2)
		{}
	virtual int vsolve_non_dynamic(const bool newton_raphson) override;

};

// ----------------------------------------------------------------------------------------
// matrix_solver - Direct2
// ----------------------------------------------------------------------------------------

inline int matrix_solver_direct2_t::vsolve_non_dynamic(ATTR_UNUSED const bool newton_raphson)
{
	build_LE_A<matrix_solver_direct2_t>();
	build_LE_RHS<matrix_solver_direct2_t>();

	const nl_double a = A(0,0);
	const nl_double b = A(0,1);
	const nl_double c = A(1,0);
	const nl_double d = A(1,1);

	nl_double new_val[2];
	new_val[1] = (a * RHS(1) - c * RHS(0)) / (a * d - b * c);
	new_val[0] = (RHS(0) - b * new_val[1]) / a;

	if (has_dynamic_devices())
	{
		nl_double err = this->delta(new_val);
		store(new_val);
		if (err > m_params.m_accuracy )
			return 2;
		else
			return 1;
	}
	store(new_val);
	return 1;
}

	} //namespace devices
} // namespace netlist

#endif /* NLD_MS_DIRECT2_H_ */