source: ThirdParty/vmg/src/solver/dgesv.hpp@ 33a694

Action_Thermostats Add_AtomRandomPerturbation Add_RotateAroundBondAction Add_SelectAtomByNameAction Adding_Graph_to_ChangeBondActions Adding_MD_integration_tests Adding_StructOpt_integration_tests AutomationFragmentation_failures Candidate_v1.6.1 ChangeBugEmailaddress ChangingTestPorts ChemicalSpaceEvaluator Docu_Python_wait EmpiricalPotential_contain_HomologyGraph_documentation Enhance_userguide Enhanced_StructuralOptimization Enhanced_StructuralOptimization_continued Example_ManyWaysToTranslateAtom Exclude_Hydrogens_annealWithBondGraph Fix_ChronosMutex Fix_StatusMsg Fix_StepWorldTime_single_argument Fix_Verbose_Codepatterns ForceAnnealing_goodresults ForceAnnealing_oldresults ForceAnnealing_tocheck ForceAnnealing_with_BondGraph ForceAnnealing_with_BondGraph_continued ForceAnnealing_with_BondGraph_continued_betteresults ForceAnnealing_with_BondGraph_contraction-expansion GeometryObjects Gui_displays_atomic_force_velocity IndependentFragmentGrids_IntegrationTest JobMarket_RobustOnKillsSegFaults JobMarket_StableWorkerPool PythonUI_with_named_parameters QtGui_reactivate_TimeChanged_changes Recreated_GuiChecks RotateToPrincipalAxisSystem_UndoRedo StoppableMakroAction TremoloParser_IncreasedPrecision TremoloParser_MultipleTimesteps Ubuntu_1604_changes
Last change on this file since 33a694 was 7faa5c, checked in by Frederik Heber <heber@…>, 8 years ago

Merge commit 'de061d9d851257a04e924d4472df4523d33bb08b' as 'ThirdParty/vmg'

  • Property mode set to 100644
File size: 3.2 KB
Line 
1/*
2 * vmg - a versatile multigrid solver
3 * Copyright (C) 2012 Institute for Numerical Simulation, University of Bonn
4 *
5 * vmg 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, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * vmg is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19/**
20 * @file dgesv.hpp
21 * @author Julian Iseringhausen <isering@ins.uni-bonn.de>
22 * @date Mon Apr 18 13:09:29 2011
23 *
24 * @brief Lapack solver for general matrices.
25 *
26 */
27
28#ifndef DGESV_HPP_
29#define DGESV_HPP_
30
31#ifndef HAVE_LAPACK
32#error You need LAPACK in order to use MGDSYSV
33#endif
34
35#include <cassert>
36#include <cstddef>
37
38namespace VMG
39{
40
41extern "C" {
42
43void FC_FUNC(dgesv,DGESV) (const int* N, const int* NRHS, vmg_float* A,
44 const int* LDA, int* IPIV, vmg_float* B,
45 const int* LDB, int* INFO);
46
47void FC_FUNC(sgesv, SGESV) (const int* N, const int* NRHS, vmg_float* A,
48 const int* LDA, int* IPIV, vmg_float* B,
49 const int* LDB, int* INFO);
50
51} /* extern "C" */
52
53/* By default, assume fcs_float is double. */
54#if defined(FCS_FLOAT_IS_FLOAT)
55#define dgesv FC_FUNC(sgesv,SGESV)
56#else
57#define dgesv FC_FUNC(dgesv,DGESV)
58#endif
59
60template<class T>
61class DGESV : public T
62{
63public:
64 DGESV(bool register_ = true) :
65 T(register_)
66 {Init();}
67
68 DGESV(int size, bool register_ = true) :
69 T(size, register_)
70 {Init();}
71
72 virtual ~DGESV();
73
74protected:
75 void Compute();
76
77private:
78 void Init();
79 void Realloc();
80
81 int la_INFO, la_LDA, la_LDB, la_N, la_NRHS;
82 int *la_IPIV;
83 vmg_float *la_A, *la_B;
84
85 int la_cur_size, la_max_size;
86};
87
88template<class T>
89void DGESV<T>::Compute()
90{
91 // Adjust size of vectors
92 this->Realloc();
93
94 la_N = la_LDA = la_LDB = la_cur_size;
95
96 // Rewrite matrix in column-major order
97 for (int i=0; i<la_N; i++) {
98 la_B[i] = this->Rhs(i);
99 for (int j=0; j<la_N; j++)
100 la_A[i + j*la_N] = this->Mat(i,j);
101 }
102
103 // Solve system of equations
104 dgesv(&la_N, &la_NRHS, la_A, &la_LDA, la_IPIV, la_B, &la_LDB, &la_INFO);
105
106 // Assert successful exit of solver routine
107 assert(la_INFO == 0);
108
109 // Write solution back
110 for (int i=0; i<la_N; i++)
111 this->Sol(i) = la_B[i];
112}
113
114template<class T>
115void DGESV<T>::Init()
116{
117 la_cur_size = 0;
118 la_max_size = 0;
119 la_NRHS = 1;
120
121 la_IPIV = NULL;
122 la_A = NULL;
123 la_B = NULL;
124}
125
126template<class T>
127void DGESV<T>::Realloc()
128{
129 la_cur_size = this->Size();
130
131 if (la_cur_size > la_max_size) {
132
133 delete [] la_IPIV;
134 delete [] la_A;
135 delete [] la_B;
136
137 la_IPIV = new int[la_cur_size];
138 la_A = new vmg_float[la_cur_size*la_cur_size];
139 la_B = new vmg_float[la_cur_size];
140
141 la_max_size = la_cur_size;
142
143 }
144}
145
146template<class T>
147DGESV<T>::~DGESV()
148{
149 delete [] la_IPIV;
150 delete [] la_A;
151 delete [] la_B;
152}
153
154}
155
156#endif /* DGESV_HPP_ */
Note: See TracBrowser for help on using the repository browser.