MFEM v4.9.0
Finite element discretization library
Loading...
Searching...
No Matches
mortarintegrator.cpp
Go to the documentation of this file.
1// Copyright (c) 2010-2025, Lawrence Livermore National Security, LLC. Produced
2// at the Lawrence Livermore National Laboratory. All Rights reserved. See files
3// LICENSE and NOTICE for details. LLNL-CODE-806117.
4//
5// This file is part of the MFEM library. For more information and source code
6// availability visit https://mfem.org.
7//
8// MFEM is free software; you can redistribute it and/or modify it under the
9// terms of the BSD-3 license. We welcome feedback and contributions, see file
10// CONTRIBUTING.md for details.
11
13
14#ifdef MFEM_USE_MOONOLITH
15
16#include "mortarintegrator.hpp"
17
18namespace mfem
19{
20
22 const FiniteElement &trial, const IntegrationRule &trial_ir,
23 ElementTransformation &trial_Trans, const FiniteElement &test,
24 const IntegrationRule &test_ir, ElementTransformation &test_Trans,
25 DenseMatrix &elmat)
26{
27 int tr_nd = trial.GetDof();
28 int te_nd = test.GetDof();
29 double w;
30
31 Vector shape, te_shape;
32
33 elmat.SetSize(te_nd, tr_nd);
34 shape.SetSize(tr_nd);
35 te_shape.SetSize(te_nd);
36
37 elmat = 0.0;
38 for (int i = 0; i < test_ir.GetNPoints(); i++)
39 {
40 const IntegrationPoint &trial_ip = trial_ir.IntPoint(i);
41 const IntegrationPoint &test_ip = test_ir.IntPoint(i);
42 test_Trans.SetIntPoint(&test_ip);
43
44 trial.CalcShape(trial_ip, shape);
45 test.CalcShape(test_ip, te_shape);
46
47 w = test_Trans.Weight() * test_ip.weight;
48
49 te_shape *= w;
50 AddMultVWt(te_shape, shape, elmat);
51 }
52}
53
55
57 const FiniteElement &trial, const IntegrationRule &trial_ir,
58 ElementTransformation &trial_Trans, const FiniteElement &test,
59 const IntegrationRule &test_ir, ElementTransformation &test_Trans,
60 DenseMatrix &elmat)
61{
62 if (test.GetRangeType() == FiniteElement::SCALAR && VQ)
63 {
64 // assume test is scalar FE and trial is vector FE
65 int dim = test.GetDim();
66 int trial_dof = trial.GetDof();
67 int test_dof = test.GetDof();
68 double w;
69
70 if (MQ)
71 mfem_error("VectorFEMassIntegrator::AssembleElementMatrix2(...)\n"
72 " is not implemented for tensor materials");
73
74#ifdef MFEM_THREAD_SAFE
75 DenseMatrix trial_vshape(trial_dof, dim);
76 Vector shape(test_dof);
77 Vector D(dim);
78#else
79 trial_vshape.SetSize(trial_dof, dim);
80 shape.SetSize(test_dof);
81 D.SetSize(dim);
82#endif
83
84 elmat.SetSize(test_dof, trial_dof);
85
86 elmat = 0.0;
87 for (int i = 0; i < test_ir.GetNPoints(); i++)
88 {
89 const IntegrationPoint &trial_ip = trial_ir.IntPoint(i);
90 const IntegrationPoint &test_ip = test_ir.IntPoint(i);
91
92 trial_Trans.SetIntPoint(&trial_ip);
93 test_Trans.SetIntPoint(&test_ip);
94
95 trial.CalcVShape(trial_Trans, trial_vshape);
96 test.CalcShape(test_ip, shape);
97
98 w = test_ip.weight * test_Trans.Weight();
99 VQ->Eval(D, test_Trans, test_ip);
100 D *= w;
101
102 for (int d = 0; d < dim; d++)
103 {
104 for (int j = 0; j < test_dof; j++)
105 {
106 for (int k = 0; k < trial_dof; k++)
107 {
108 elmat(j, k) += D[d] * shape(j) * trial_vshape(k, d);
109 }
110 }
111 }
112 }
113 }
114 else if (test.GetRangeType() == FiniteElement::SCALAR)
115 {
116 // assume test is scalar FE and trial is vector FE
117 int dim = test.GetDim();
118 int trial_dof = trial.GetDof();
119 int test_dof = test.GetDof();
120 double w;
121
122 if (VQ || MQ)
123 mfem_error("VectorFEMassIntegrator::AssembleElementMatrix2(...)\n"
124 " is not implemented for vector/tensor permeability");
125
126#ifdef MFEM_THREAD_SAFE
127 DenseMatrix trial_vshape(trial_dof, dim);
128 Vector shape(test_dof);
129#else
130 trial_vshape.SetSize(trial_dof, dim);
131 shape.SetSize(test_dof);
132#endif
133
134 elmat.SetSize(dim * test_dof, trial_dof);
135
136 elmat = 0.0;
137 for (int i = 0; i < test_ir.GetNPoints(); i++)
138 {
139 const IntegrationPoint &trial_ip = trial_ir.IntPoint(i);
140 const IntegrationPoint &test_ip = test_ir.IntPoint(i);
141
142 trial_Trans.SetIntPoint(&trial_ip);
143 test_Trans.SetIntPoint(&test_ip);
144
145 trial.CalcVShape(trial_Trans, trial_vshape);
146 test.CalcShape(test_ip, shape);
147
148 w = test_ip.weight * test_Trans.Weight();
149
150 if (Q)
151 {
152 w *= Q->Eval(test_Trans, test_ip);
153 }
154
155 for (int d = 0; d < dim; d++)
156 {
157 for (int j = 0; j < test_dof; j++)
158 {
159 for (int k = 0; k < trial_dof; k++)
160 {
161 elmat(d * test_dof + j, k) += w * shape(j) * trial_vshape(k, d);
162 }
163 }
164 }
165 }
166 }
167 else
168 {
169 // assume both test and trial are vector FE
170 int dim = test.GetDim();
171 int trial_dof = trial.GetDof();
172 int test_dof = test.GetDof();
173 double w;
174
175 if (VQ || MQ)
176 mfem_error("VectorFEMassIntegrator::AssembleElementMatrix2(...)\n"
177 " is not implemented for vector/tensor permeability");
178
179#ifdef MFEM_THREAD_SAFE
180 DenseMatrix trial_vshape(trial_dof, dim);
181 DenseMatrix test_vshape(test_dof, dim);
182#else
183 trial_vshape.SetSize(trial_dof, dim);
184 test_vshape.SetSize(test_dof, dim);
185#endif
186
187 elmat.SetSize(test_dof, trial_dof);
188
189 elmat = 0.0;
190 for (int i = 0; i < test_ir.GetNPoints(); i++)
191 {
192 const IntegrationPoint &trial_ip = trial_ir.IntPoint(i);
193 const IntegrationPoint &test_ip = test_ir.IntPoint(i);
194
195 trial_Trans.SetIntPoint(&trial_ip);
196 test_Trans.SetIntPoint(&test_ip);
197
198 trial.CalcVShape(trial_Trans, trial_vshape);
199 test.CalcVShape(test_Trans, test_vshape);
200
201 w = test_ip.weight * test_Trans.Weight();
202 if (Q)
203 {
204 w *= Q->Eval(test_Trans, test_ip);
205 }
206
207 for (int d = 0; d < dim; d++)
208 {
209 for (int j = 0; j < test_dof; j++)
210 {
211 for (int k = 0; k < trial_dof; k++)
212 {
213 elmat(j, k) += w * test_vshape(j, d) * trial_vshape(k, d);
214 }
215 }
216 }
217 }
218 }
219}
220
222
223
225 const FiniteElement &trial,
226 const IntegrationRule &trial_ir,
227 ElementTransformation &trial_Trans,
228 const FiniteElement &test,
229 const IntegrationRule &test_ir,
230 ElementTransformation &test_Trans,
231 DenseMatrix &elmat)
232{
233 int tr_nd = trial.GetDof();
234 int te_nd = test.GetDof();
235
236 double norm;
237
238 // If vdim is not set, set it to the space dimension
239 vdim = (vdim == -1) ? test_Trans.GetSpaceDim() : vdim;
240
241#ifdef MFEM_THREAD_SAFE
242 Vector D;
243 Vector vec;
249#endif
250
251 elmat.SetSize(te_nd*vdim, tr_nd*vdim);
252 trial_shape.SetSize(tr_nd);
253 test_shape.SetSize(te_nd);
254 partelmat.SetSize(te_nd, tr_nd);
255
256 if (VQ)
257 {
258 vec.SetSize(vdim);
259 }
260 else if (MQ)
261 {
262 mcoeff.SetSize(vdim);
263 }
264
265 elmat = 0.0;
266 for (int s = 0; s < test_ir.GetNPoints(); s++)
267 {
268 trial.CalcShape(trial_ir.IntPoint(s), trial_shape);
269 test.CalcShape(test_ir.IntPoint(s), test_shape);
270
271 test_Trans.SetIntPoint(&test_ir.IntPoint(s));
272 norm = test_ir.IntPoint(s).weight * test_Trans.Weight();
273
275
276 if (VQ)
277 {
278 VQ->Eval(vec, test_Trans, test_ir.IntPoint(s));
279 for (int k = 0; k < vdim; k++)
280 {
281 elmat.AddMatrix(norm*vec(k), partelmat, te_nd*k, tr_nd*k);
282 }
283 }
284 else if (MQ)
285 {
286 MQ->Eval(mcoeff, test_Trans, test_ir.IntPoint(s));
287 for (int i = 0; i < vdim; i++)
288 for (int j = 0; j < vdim; j++)
289 {
290 elmat.AddMatrix(norm*mcoeff(i,j), partelmat, te_nd*i, tr_nd*j);
291 }
292 }
293 else
294 {
295 if (Q)
296 {
297 norm *= Q->Eval(test_Trans, test_ir.IntPoint(s));
298 }
299 partelmat *= norm;
300 for (int k = 0; k < vdim; k++)
301 {
302 elmat.AddMatrix(partelmat, te_nd*k, tr_nd*k);
303 }
304 }
305 }
306}
307
310
311} // namespace mfem
312
313#endif // MFEM_USE_MOONOLITH
Abstract base class BilinearFormIntegrator.
virtual real_t Eval(ElementTransformation &T, const IntegrationPoint &ip)=0
Evaluate the coefficient in the element described by T at the point ip.
Data type dense matrix using column-major storage.
Definition densemat.hpp:24
void SetSize(int s)
Change the size of the DenseMatrix to s x s.
Definition densemat.hpp:116
void AddMatrix(DenseMatrix &A, int ro, int co)
Perform (ro+i,co+j)+=A(i,j) for 0<=i.
virtual int GetSpaceDim() const =0
Get the dimension of the target (physical) space.
real_t Weight()
Return the weight of the Jacobian matrix of the transformation at the currently set IntegrationPoint....
Definition eltrans.hpp:144
void SetIntPoint(const IntegrationPoint *ip)
Set the integration point ip that weights and Jacobians will be evaluated at.
Definition eltrans.hpp:106
Abstract class for all finite elements.
Definition fe_base.hpp:247
virtual void CalcVShape(const IntegrationPoint &ip, DenseMatrix &shape) const
Evaluate the values of all shape functions of a vector finite element in reference space at the given...
Definition fe_base.cpp:50
int GetDim() const
Returns the reference space dimension for the finite element.
Definition fe_base.hpp:324
int GetRangeType() const
Returns the FiniteElement::RangeType of the element, one of {SCALAR, VECTOR}.
Definition fe_base.hpp:354
virtual void CalcShape(const IntegrationPoint &ip, Vector &shape) const =0
Evaluate the values of all shape functions of a scalar finite element in reference space at the given...
int GetDof() const
Returns the number of degrees of freedom in the finite element.
Definition fe_base.hpp:337
Class for integration point with weight.
Definition intrules.hpp:35
Class for an integration rule - an Array of IntegrationPoint.
Definition intrules.hpp:100
int GetNPoints() const
Returns the number of the points in the integration rule.
Definition intrules.hpp:256
IntegrationPoint & IntPoint(int i)
Returns a reference to the i-th integration point.
Definition intrules.hpp:259
BilinearFormIntegrator * newBFormIntegrator() const override
void AssembleElementMatrix(const FiniteElement &trial, const IntegrationRule &trial_ir, ElementTransformation &trial_Trans, const FiniteElement &test, const IntegrationRule &test_ir, ElementTransformation &test_Trans, DenseMatrix &elemmat) override
Implements the assembly routine.
void AssembleElementMatrix(const FiniteElement &trial, const IntegrationRule &trial_ir, ElementTransformation &trial_Trans, const FiniteElement &test, const IntegrationRule &test_ir, ElementTransformation &test_Trans, DenseMatrix &elemmat) override
Implements the assembly routine.
BilinearFormIntegrator * newBFormIntegrator() const override
virtual void Eval(DenseMatrix &K, ElementTransformation &T, const IntegrationPoint &ip)=0
Evaluate the matrix coefficient in the element described by T at the point ip, storing the result in ...
virtual void Eval(Vector &V, ElementTransformation &T, const IntegrationPoint &ip)=0
Evaluate the vector coefficient in the element described by T at the point ip, storing the result in ...
BilinearFormIntegrator * newBFormIntegrator() const override
void AssembleElementMatrix(const FiniteElement &trial, const IntegrationRule &trial_ir, ElementTransformation &trial_Trans, const FiniteElement &test, const IntegrationRule &test_ir, ElementTransformation &test_Trans, DenseMatrix &elemmat) override
Implements the assembly routine.
Vector data type.
Definition vector.hpp:82
void SetSize(int s)
Resize the vector to size s.
Definition vector.hpp:584
int dim
Definition ex24.cpp:53
void mfem_error(const char *msg)
Definition error.cpp:154
void MultVWt(const Vector &v, const Vector &w, DenseMatrix &VWt)
void AddMultVWt(const Vector &v, const Vector &w, DenseMatrix &VWt)
VWt += v w^t.
MFEM_HOST_DEVICE real_t norm(const Complex &z)