Mercurial > fem-fenics-eugenio
comparison src/assemble.cc @ 268:61830a4f9ab9
Improve formatting
author | Eugenio Gianniti <eugenio.gianniti@mail.polimi.it> |
---|---|
date | Thu, 14 Aug 2014 12:26:55 +0200 |
parents | 5e9b5bbdc56b |
children | f4d6ae912a08 |
comparison
equal
deleted
inserted
replaced
267:53039ac90368 | 268:61830a4f9ab9 |
---|---|
18 #include "form.h" | 18 #include "form.h" |
19 #include "boundarycondition.h" | 19 #include "boundarycondition.h" |
20 #include "femfenics_factory.h" | 20 #include "femfenics_factory.h" |
21 #include "dolfin_compat.h" | 21 #include "dolfin_compat.h" |
22 | 22 |
23 DEFUN_DLD (assemble, args, nargout, | 23 DEFUN_DLD (assemble, args, nargout, |
24 "-*- texinfo -*-\n\ | 24 "-*- texinfo -*-\n\ |
25 @deftypefn {Function File} {[@var{A}], [@var{x}(Optional)]} = \ | 25 @deftypefn {Function File} {[@var{A}], [@var{x}(Optional)]} = \ |
26 assemble (@var{form_a}, @var{DirichletBC}) \n\ | 26 assemble (@var{form_a}, @var{DirichletBC}) \n\ |
27 Construct the discretization of a Form and apply essential BC.\n\ | 27 Construct the discretization of a Form and apply essential BC.\n\ |
28 The input arguments are\n\ | 28 The input arguments are\n\ |
65 } | 65 } |
66 | 66 |
67 if (nargout == 1) | 67 if (nargout == 1) |
68 { | 68 { |
69 if (nargin < 1) | 69 if (nargin < 1) |
70 print_usage (); | 70 { print_usage (); } |
71 else | 71 else |
72 { | 72 { |
73 if (args(0).type_id () == form::static_type_id ()) | 73 if (args(0).type_id () == form::static_type_id ()) |
74 { | 74 { |
75 const form & frm = static_cast<const form&> (args(0).get_rep ()); | 75 const form & frm = static_cast<const form &> (args(0).get_rep ()); |
76 | 76 |
77 if (! error_state) | 77 if (! error_state) |
78 { | 78 { |
79 const dolfin::Form & a = frm.get_form (); | 79 const dolfin::Form & a = frm.get_form (); |
80 a.check (); | 80 a.check (); |
86 dolfin::Matrix A; | 86 dolfin::Matrix A; |
87 dolfin::assemble (A, a); | 87 dolfin::assemble (A, a); |
88 | 88 |
89 for (std::size_t i = 1; i < nargin; ++i) | 89 for (std::size_t i = 1; i < nargin; ++i) |
90 { | 90 { |
91 if (args(i).type_id () == | 91 if (args(i).type_id () == |
92 boundarycondition::static_type_id ()) | 92 boundarycondition::static_type_id ()) |
93 { | 93 { |
94 const boundarycondition & bc | 94 const boundarycondition & bc |
95 = static_cast<const boundarycondition&> | 95 = static_cast<const boundarycondition &> |
96 (args(i).get_rep ()); | 96 (args(i).get_rep ()); |
97 | 97 |
98 const | 98 const std::vector<SHARED_PTR |
99 std::vector<SHARED_PTR | 99 <const dolfin::DirichletBC> > |
100 <const dolfin::DirichletBC> > | |
101 & pbc = bc.get_bc (); | 100 & pbc = bc.get_bc (); |
102 | 101 |
103 for (std::size_t j = 0; j < pbc.size (); ++j) | 102 for (std::size_t j = 0; j < pbc.size (); ++j) |
104 pbc[j]->apply(A); | 103 { pbc[j]->apply (A); } |
105 } | 104 } |
106 else | 105 else |
107 error ("assemble: unknown argument type"); | 106 { error ("assemble: unknown argument type"); } |
108 } | 107 } |
109 | 108 |
110 retval(0) = factory.matrix (A); | 109 retval(0) = factory.matrix (A); |
111 } | 110 } |
112 | 111 |
117 dolfin::Vector A; | 116 dolfin::Vector A; |
118 dolfin::assemble (A, a); | 117 dolfin::assemble (A, a); |
119 | 118 |
120 for (std::size_t i = 1; i < nargin; ++i) | 119 for (std::size_t i = 1; i < nargin; ++i) |
121 { | 120 { |
122 if (args(i).type_id () == | 121 if (args(i).type_id () == |
123 boundarycondition::static_type_id ()) | 122 boundarycondition::static_type_id ()) |
124 { | 123 { |
125 const boundarycondition & bc | 124 const boundarycondition & bc |
126 = static_cast<const boundarycondition&> | 125 = static_cast<const boundarycondition &> |
127 (args(i).get_rep ()); | 126 (args(i).get_rep ()); |
128 | 127 |
129 const std::vector<SHARED_PTR | 128 const std::vector<SHARED_PTR |
130 <const dolfin::DirichletBC> > | 129 <const dolfin::DirichletBC> > |
131 & pbc = bc.get_bc (); | 130 & pbc = bc.get_bc (); |
132 | 131 |
133 for (std::size_t j = 0; j < pbc.size (); ++j) | 132 for (std::size_t j = 0; j < pbc.size (); ++j) |
134 pbc[j]->apply(A); | 133 { pbc[j]->apply (A); } |
135 } | 134 } |
136 else | 135 else |
137 error ("assemble: unknown argument type"); | 136 { error ("assemble: unknown argument type"); } |
138 } | 137 } |
139 | 138 |
140 retval(0) = factory.vector (A); | 139 retval(0) = factory.vector (A); |
141 } | 140 } |
142 | 141 |
145 double b = dolfin::assemble (a); | 144 double b = dolfin::assemble (a); |
146 retval(0) = octave_value (b); | 145 retval(0) = octave_value (b); |
147 } | 146 } |
148 | 147 |
149 else | 148 else |
150 error ("assemble: unknown form size"); | 149 { error ("assemble: unknown form size"); } |
151 } | 150 } |
152 } | 151 } |
153 } | 152 } |
154 } | 153 } |
155 else if (nargout == 2) | 154 else if (nargout == 2) |
156 { | 155 { |
157 if (nargin < 2) | 156 if (nargin < 2) |
158 print_usage (); | 157 { print_usage (); } |
159 else | 158 else |
160 { | 159 { |
161 if (args(0).type_id () == form::static_type_id ()) | 160 if (args(0).type_id () == form::static_type_id ()) |
162 { | 161 { |
163 const form & frm = | 162 const form & frm = |
164 static_cast<const form &> (args(0).get_rep ()); | 163 static_cast<const form &> (args(0).get_rep ()); |
165 const Array<double> myx = args(1).array_value (); | 164 const Array<double> myx = args(1).array_value (); |
166 | 165 |
167 if (! error_state) | 166 if (! error_state) |
168 { | 167 { |
180 dolfin::Vector x (MPI_COMM_WORLD, myx.length ()); | 179 dolfin::Vector x (MPI_COMM_WORLD, myx.length ()); |
181 #else | 180 #else |
182 dolfin::Vector x (myx.length ()); | 181 dolfin::Vector x (myx.length ()); |
183 #endif | 182 #endif |
184 for (std::size_t i = 0; i < myx.length (); ++i) | 183 for (std::size_t i = 0; i < myx.length (); ++i) |
185 x.setitem (i, myx.xelem (i)); | 184 { x.setitem (i, myx.xelem (i)); } |
186 | 185 |
187 for (std::size_t i = 2; i < nargin; ++i) | 186 for (std::size_t i = 2; i < nargin; ++i) |
188 { | 187 { |
189 if (args(i).type_id () == | 188 if (args(i).type_id () == |
190 boundarycondition::static_type_id ()) | 189 boundarycondition::static_type_id ()) |
191 { | 190 { |
192 const boundarycondition & bc | 191 const boundarycondition & bc |
193 = static_cast<const boundarycondition&> | 192 = static_cast<const boundarycondition &> |
194 (args(i).get_rep ()); | 193 (args(i).get_rep ()); |
195 | 194 |
196 const std::vector<SHARED_PTR | 195 const std::vector<SHARED_PTR |
197 <const dolfin::DirichletBC> > | 196 <const dolfin::DirichletBC> > |
198 & pbc = bc.get_bc (); | 197 & pbc = bc.get_bc (); |
199 | 198 |
200 for (std::size_t j = 0; | 199 for (std::size_t j = 0; |
201 j < pbc.size (); ++j) | 200 j < pbc.size (); ++j) |
202 pbc[j]->apply(A, x); | 201 { pbc[j]->apply (A, x); } |
203 } | 202 } |
204 else | 203 else |
205 error ("assemble: unknown argument type"); | 204 { error ("assemble: unknown argument type"); } |
206 } | 205 } |
207 | 206 |
208 retval(0) = factory.vector (A); | 207 retval(0) = factory.vector (A); |
209 retval(1) = factory.vector (x); | 208 retval(1) = factory.vector (x); |
210 } | 209 } |
211 | 210 |
212 else | 211 else |
213 error ("assemble: unknown size"); | 212 { error ("assemble: unknown size"); } |
214 } | 213 } |
215 } | 214 } |
216 } | 215 } |
217 } | 216 } |
218 | 217 |