-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmicromagnetics_flux_element.h
381 lines (306 loc) · 12.2 KB
/
micromagnetics_flux_element.h
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
#ifndef OOMPH_MICROMAGNETICS_FLUX_ELEMENT_H
#define OOMPH_MICROMAGNETICS_FLUX_ELEMENT_H
// class MicromagEquations;
#include "./micromagnetics_element.h"
#include "new_interpolators.h"
#include "llg_factories.h"
#include <memory> // unique_ptr
// Note: we can't use a .cc file here easily because then we would need to
// instantiate the template for every possible element, of which there are
// quite a few...
namespace oomph
{
//======================================================================
/// A face element to impose the flux boundary condition on the potential for
/// micromagnetics. It is not possible to use the existing Poisson flux
/// elements becuase they assume that:
///
/// 1) The corresponding bulk element will be a PoissonElement.
///
/// 2) The Jacobian contribution due to the flux elements is always
/// zero. This is not true for our case since the flux is fixed as m.n
/// (where m is the magnetisation). So differentiation wrt m gives a
/// non-zero result.
// ======================================================================
template <class ELEMENT>
class MicromagFluxElement : public virtual FaceGeometry<ELEMENT>,
public virtual FaceElement
{
public:
/// \short Constructor, takes the pointer to the "bulk" element and the
/// index of the face to which the element is attached.
MicromagFluxElement(FiniteElement* const &bulk_el_pt,
const int& face_index);
/// Add the element's contribution to its residual vector
void fill_in_contribution_to_residuals(Vector<double> &residuals)
{
// Call the generic residuals function with flag set to 0 using a dummy
// matrix argument
fill_in_generic_residual_contribution_fluxes
(residuals,GeneralisedElement::Dummy_matrix,0);
}
/// \short Add the element's contribution to its residual vector and its
/// Jacobian matrix
void fill_in_contribution_to_jacobian(Vector<double> &residuals,
DenseMatrix<double> &jacobian)
{
if(bulk_element_pt()->Use_fd_jacobian)
{
// Generalised element version is by FD
FiniteElement::fill_in_contribution_to_jacobian(residuals,
jacobian);
}
else
{
//Call the generic routine with the flag set to 1
fill_in_generic_residual_contribution_fluxes(residuals,jacobian,1);
}
}
/// \short Output function -- forward to broken version in FiniteElement.
void output(std::ostream &outfile, const unsigned &n_plot=5)
{FiniteElement::output(outfile,n_plot);}
/// \short C-style output function -- forward to broken version in
/// FiniteElement.
void output(FILE* file_pt, const unsigned &n_plot=5)
{FiniteElement::output(file_pt,n_plot);}
MicromagEquations* bulk_element_pt() const
{
return Bulk_element_pt;
}
unsigned m_index_micromag(const unsigned &i) const
{
return bulk_element_pt()->m_index_micromag(i);
}
unsigned ndof_types() const {return 0;}
/// \short Element makes no changes to dof numbering - do nothing.
void get_dof_numbers_for_unknowns
(std::list<std::pair<unsigned long,unsigned> >& block_lookup_list) const
{}
/// Return m . dm/dn at s.
double interpolated_mdotdmdn_micromag(const Vector<double> &s) const
{
// dm_i/dn = dm_i/dx . normal
std::string err = "Untested with midpoint, not using interpolator so prob. no good";
throw OomphLibWarning(err, OOMPH_EXCEPTION_LOCATION,
OOMPH_CURRENT_FUNCTION);
// Get shape functions
Shape psi(nnode()); DShape dpsidx(nnode(),dim());
dshape_local(s,psi,dpsidx);
// Get unit normal
Vector<double> normal(nodal_dimension(),0.0);
outer_unit_normal(s, normal);
// For each m direction
Vector<double> dmdn(3,0.0), m(3,0.0);
for(unsigned i_m=0; i_m<3; i_m++)
{
// Interpolate dm_idx and m_i
Vector<double> dmidx(nodal_dimension(),0.0);
for(unsigned l=0, nl=nnode(); l<nl; l++)
{
for(unsigned j=0; j<dim(); j++)
{
dmidx[j] += nodal_value(l,m_index_micromag(i_m))*dpsidx(l,j);
}
m[i_m] += nodal_value(l,m_index_micromag(i_m)) * psi(l);
}
// Take dot product
dmdn[i_m] = VectorOps::dot(dmidx, normal);
}
// Get m . dm/dn (because it's easy now and we probably need it)
return VectorOps::dot(m,dmdn);
}
protected:
/// \short Function to compute the shape and test functions and to return
/// the Jacobian of mapping between local and global (Eulerian)
/// coordinates
double shape_test(const Vector<double> &s, Shape &psi, Shape &test)
const
{
//Get the shape functions
shape(s,psi);
//Set the test functions to be the same as the shape functions
test = psi;
//Return the value of the jacobian
return J_eulerian(s);
}
/// \short Add the element's contribution to its residual vector. When
/// flag=1 (or 0): do (or don't) compute the contribution to the Jacobian as
/// well.
void fill_in_generic_residual_contribution_fluxes
(Vector<double> &residuals, DenseMatrix<double> &jacobian,
const unsigned& flag);
void fill_in_contribution_to_mass_matrix
(Vector<double> &residuals, DenseMatrix<double> &mmatrix);
private:
/// Pointer to the attached bulk element
MicromagEquations* Bulk_element_pt;
///\short Broken empty constructor
MicromagFluxElement()
{
throw OomphLibError
("Don't call empty constructor for MicromagFluxElement",
OOMPH_CURRENT_FUNCTION,
OOMPH_EXCEPTION_LOCATION);
}
/// Broken copy constructor
MicromagFluxElement(const MicromagFluxElement& dummy)
{
BrokenCopy::broken_copy("MicromagFluxElement");
}
/// Broken assignment operator
void operator=(const MicromagFluxElement&)
{
BrokenCopy::broken_assign("MicromagFluxElement");
}
};
//===========================================================================
/// Constructor, takes the pointer to the "bulk" element, the
/// index of the fixed local coordinate and its value represented
/// by an integer (+/- 1), indicating that the face is located
/// at the max. or min. value of the "fixed" local coordinate
/// in the bulk element.
//===========================================================================
template<class ELEMENT>
MicromagFluxElement<ELEMENT>::
MicromagFluxElement(FiniteElement* const &bulk_el_pt, const int &face_index)
: FaceGeometry<ELEMENT>(), FaceElement(),
Bulk_element_pt(checked_dynamic_cast<MicromagEquations*>(bulk_el_pt))
{
// Let the bulk element build the FaceElement, i.e. setup the pointers
// to its nodes (by referring to the appropriate nodes in the bulk
// element), etc.
bulk_element_pt()->build_face_element(face_index,this);
}
//===========================================================================
/// Compute the element's residual vector and the Jacobian matrix.
//===========================================================================
template<class ELEMENT>
void MicromagFluxElement<ELEMENT>::
fill_in_generic_residual_contribution_fluxes
(Vector<double> &residuals,
DenseMatrix<double> &jacobian,
const unsigned& flag)
{
// If there is some surface anisotropy then throw an error: not
// implemented.
#ifdef PARANOID
if(bulk_element_pt()->magnetic_parameters_pt()->surface_anisotropy_enabled())
{
std::ostringstream error_msg;
error_msg << "Surface anisotropy is not implemented";
throw OomphLibError(error_msg.str(),
OOMPH_CURRENT_FUNCTION,
OOMPH_EXCEPTION_LOCATION);
}
#endif
const unsigned n_node = nnode();
const unsigned n_intpt = integral_pt()->nweight();
const unsigned dim = node_pt(0)->ndim();
Shape psi(n_node), test(n_node);
// indicies:
unsigned phi1_index = bulk_element_pt()->phi_1_index_micromag();
Vector<unsigned> m_index(3, 0);
for(unsigned j=0; j<3; j++)
{
m_index[j] = bulk_element_pt()->m_index_micromag(j);
}
// Create interpolator ??ds might need some changes to handle face
// element derivatives..
std::auto_ptr<CachingMMArrayInterpolator>
intp_pt(Factories::mm_array_interpolator_factory(this));
//Loop over the integration points
//--------------------------------
for(unsigned ipt=0;ipt<n_intpt;ipt++)
{
// Local coords
Vector<double> s(dim-1);
for(unsigned i=0; i<(dim-1); i++) {s[i] = integral_pt()->knot(ipt, i);}
// Set up interpolator at this point
intp_pt->build(s);
const double* m = intp_pt->m();
const double W = integral_pt()->weight(ipt) * intp_pt->j();
// Get normal vector, force 3 entries for ease of combination with
// m which always has 3 entries.
Vector<double> normal(dim,0.0);
outer_unit_normal(s, normal);
normal.resize(3, 0.0); // make 3d, initialise new values to zero.
// Get mdotn at this point
double mdotn = 0.0;
for(unsigned j=0; j<dim; j++)
{
mdotn += m[j] * normal[j];
}
// Loop over the test functions doing residual and Jacobian
// contributions.
for(unsigned l=0;l<n_node;l++)
{
// Get indicies for phi_1 equation
int phi_1_eqn = nodal_local_eqn (l, phi1_index);
// Skip if a dirichlet b.c.
if(phi_1_eqn < 0) continue;
// Add contribution to phi residual
residuals[phi_1_eqn] += mdotn * intp_pt->test(l) * W;
// Skip rest if Jacobian not requested
if(!flag) continue;
for(unsigned l2=0; l2<n_node; l2++)
{
// Loop over which m we are differentiating w.r.t
for(unsigned j=0; j<3; j++)
{
int m_unknown = nodal_local_eqn(l2, m_index[j]);
// Skip rest is m[j] pinned
if(m_unknown < 0) continue;
// phi_1 residual w.r.t m[j]
jacobian(phi_1_eqn, m_unknown)
+= intp_pt->psi(l2) * intp_pt->test(l) * normal[j] * W;
}
}
}
}
}
/// This might go better inside generic get jacobian etc. once I write
/// it.
template<class ELEMENT>
void MicromagFluxElement<ELEMENT>::fill_in_contribution_to_mass_matrix
(Vector<double> &residuals, DenseMatrix<double> &mmatrix)
{
// Get the residuals
fill_in_contribution_to_residuals(residuals);
const unsigned n_node = this->nnode();
const unsigned eldim = this->dim();
const unsigned n_unknowns = ndof_types();
Shape psi(n_node), test(n_node);
Vector<double> s(eldim);
//Loop over the integration points
for(unsigned ipt=0, nipt=this->integral_pt()->nweight(); ipt<nipt; ipt++)
{
// Get position
for(unsigned j=0; j<eldim; j++)
{s[j] = this->integral_pt()->knot(ipt,j);}
// Get shape/test/coord transform Jacobian
double J = J_eulerian(s);
shape(s, psi);
test = psi;
double W = this->integral_pt()->weight(ipt) * J;
for(unsigned l=0;l<n_node;l++)
{
//Loop over the unknowns
for(unsigned i=0;i<n_unknowns;i++)
{
int local_eqn = this->nodal_local_eqn(l,i);
if(local_eqn < 0) continue;
for(unsigned l2=0;l2<n_node;l2++)
{
int local_unknown = this->nodal_local_eqn(l2,i);
if(local_unknown < 0) continue;
//??ds do we need to multiply by
//d_valuederivative_evaltime_by_dvalue_np1?
mmatrix(local_eqn, local_unknown) +=
psi(l2)*test(l)*W;
}
}
}
}
}
} // End of oomph namespace
#endif