Nektar++
MMFMaxwell.cpp
Go to the documentation of this file.
1 /////////////////////////////////////////////////////////////////////////////
2 //
3 // File MMFMaxwell.cpp
4 //
5 // For more information, please see: http://www.nektar.info
6 //
7 // The MIT License
8 //
9 // Copyright (c) 2006 Division of Applied Mathematics, Brown University (USA),
10 // Department of Aeronautics, Imperial College London (UK), and Scientific
11 // Computing and Imaging Institute, University of Utah (USA).
12 //
13 // Permission is hereby granted, free of charge, to any person obtaining a
14 // copy of this software and associated documentation files (the "Software"),
15 // to deal in the Software without restriction, including without limitation
16 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
17 // and/or sell copies of the Software, and to permit persons to whom the
18 // Software is furnished to do so, subject to the following conditions:
19 //
20 // The above copyright notice and this permission notice shall be included
21 // in all copies or substantial portions of the Software.
22 //
23 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
24 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
26 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
29 // DEALINGS IN THE SOFTWARE.
30 //
31 // Description: MMF Maxwell solve routines
32 //
33 ///////////////////////////////////////////////////////////////////////////////
34 
36 
37 #include <boost/core/ignore_unused.hpp>
38 #include <boost/algorithm/string/predicate.hpp>
39 #include <iomanip>
40 #include <iostream>
41 
44 #include <SolverUtils/MMFSystem.h>
45 
46 #include <typeinfo>
47 
48 namespace Nektar
49 {
50 std::string MMFMaxwell::className =
52  "MMFMaxwell", MMFMaxwell::create, "MMFMaxwell equation.");
53 
56  : UnsteadySystem(pSession, pGraph), MMFSystem(pSession, pGraph)
57 {
58 }
59 
60 /**
61  * @brief Initialisation object for the unsteady linear advection equation.
62  */
64 {
65  // Call to the initialisation object
67 
68  int nq = m_fields[0]->GetNpoints();
69  int shapedim = m_fields[0]->GetShapeDimension();
70 
71  m_session->LoadParameter("ElemtGroup0", m_ElemtGroup0, 0);
72  m_session->LoadParameter("ElemtGroup1", m_ElemtGroup1, 0);
73  m_session->LoadParameter("boundaryforSF", m_boundaryforSF, 0);
74  m_session->LoadParameter("PrintoutSurfaceCurrent", m_PrintoutSurfaceCurrent,
75  0);
76 
77  m_session->LoadParameter("AddRotation", m_AddRotation, 0);
78 
79  m_session->LoadParameter("NoInc", m_NoInc, 0);
80 
81  // PML parameters
82  m_session->LoadParameter("TestPML", m_TestPML, 0);
83  m_session->LoadParameter("PMLelement", m_PMLelement, 0);
84  m_session->LoadParameter("RecPML", m_RecPML, 0);
85 
86  m_session->LoadParameter("AddPML", m_AddPML, 0);
87  if (m_AddPML == 1)
88  {
90  }
91  m_session->LoadParameter("PMLorder", m_PMLorder, 3);
92 
93  m_session->LoadParameter("PMLthickness", m_PMLthickness, 0.0);
94  m_session->LoadParameter("PMLstart", m_PMLstart, 0.0);
95  m_session->LoadParameter("PMLmaxsigma", m_PMLmaxsigma, 100.0);
96 
97  // Point Source parmaters
98  m_session->LoadParameter("Psx", m_Psx, 0.0);
99  m_session->LoadParameter("Psy", m_Psy, 0.0);
100  m_session->LoadParameter("Psz", m_Psz, 0.0);
101  m_session->LoadParameter("PSduration", m_PSduration, 1.0);
102  m_session->LoadParameter("Gaussianradius", m_Gaussianradius, 1.0);
103 
104  // Cloaking parameter
105  m_session->LoadParameter("CloakNlayer", m_CloakNlayer, 5);
106  m_session->LoadParameter("Cloakraddelta", m_Cloakraddelta, 0.0);
107 
109  m_session->LoadParameter("varepsilon1", m_varepsilon[0], 1.0);
110  m_session->LoadParameter("varepsilon2", m_varepsilon[1], 1.0);
111  m_session->LoadParameter("varepsilon3", m_varepsilon[2], 1.0);
112  m_n1 = sqrt(m_varepsilon[0]);
113  m_n2 = sqrt(m_varepsilon[1]);
114  m_n3 = sqrt(m_varepsilon[2]);
115 
117  m_session->LoadParameter("mu1", m_mu[0], 1.0);
118  m_session->LoadParameter("mu2", m_mu[1], 1.0);
119  m_session->LoadParameter("mu3", m_mu[2], 1.0);
120 
121  Array<OneD, Array<OneD, NekDouble>> Anisotropy(shapedim);
122  for (int j = 0; j < shapedim; ++j)
123  {
124  Anisotropy[j] = Array<OneD, NekDouble>(nq, 1.0);
125  }
126 
127  // Add Rectangular PML
128  MMFSystem::MMFInitObject(Anisotropy, m_RecPML);
129 
130  // Compute the cross producted MF
132 
133  m_session->LoadParameter("Frequency", m_freq, 1.0);
134 
135  // Define TestMaxwellType
136  if (m_session->DefinesSolverInfo("TESTMAXWELLTYPE"))
137  {
138  std::string TestMaxwellTypeStr =
139  m_session->GetSolverInfo("TESTMAXWELLTYPE");
140  for (int i = 0; i < (int)SolverUtils::SIZE_TestMaxwellType; ++i)
141  {
142  if (boost::iequals(SolverUtils::TestMaxwellTypeMap[i],
143  TestMaxwellTypeStr))
144  {
146  break;
147  }
148  }
149  }
150 
151  else
152  {
154  }
155 
156  // Define Polarization
157  if (m_session->DefinesSolverInfo("POLTYPE"))
158  {
159  std::string PolTypeStr = m_session->GetSolverInfo("POLTYPE");
160  for (int i = 0; i < (int)SolverUtils::SIZE_PolType; ++i)
161  {
162  if (boost::iequals(SolverUtils::PolTypeMap[i], PolTypeStr))
163  {
165  break;
166  }
167  }
168  }
169  else
170  {
172  }
173 
174  // Define Incident wave Type
175  if (m_session->DefinesSolverInfo("INCTYPE"))
176  {
177  std::string IncTypeStr = m_session->GetSolverInfo("INCTYPE");
178  for (int i = 0; i < (int)SolverUtils::SIZE_IncType; ++i)
179  {
180  if (boost::iequals(SolverUtils::IncTypeMap[i], IncTypeStr))
181  {
183  break;
184  }
185  }
186  }
187  else
188  {
190  }
191 
192  // Define Cloak Type
193  if (m_session->DefinesSolverInfo("CLOAKTYPE"))
194  {
195  std::string CloakTypeStr = m_session->GetSolverInfo("CLOAKTYPE");
196  for (int i = 0; i < (int)SIZE_CloakType; ++i)
197  {
198  if (boost::iequals(CloakTypeMap[i], CloakTypeStr))
199  {
200  m_CloakType = (CloakType)i;
201  break;
202  }
203  }
204  }
205  else
206  {
207  m_CloakType = (CloakType)0;
208  }
209 
210  // Define Source Type
211  if (m_session->DefinesSolverInfo("SOURCETYPE"))
212  {
213  std::string SourceTypeStr = m_session->GetSolverInfo("SOURCETYPE");
214  for (int i = 0; i < (int)SIZE_SourceType; ++i)
215  {
216  if (boost::iequals(SourceTypeMap[i], SourceTypeStr))
217  {
219  break;
220  }
221  }
222  }
223  else
224  {
226  }
227 
228  // Compute n_timesMFFwd and m_times_timesMFFwd
229  ComputeNtimesMF();
230 
231  // Compute vaepsilon and mu vector (m_epsveci, m_muvec0);
234  for (int k = 0; k < m_spacedim; ++k)
235  {
236  m_epsvec[k] = Array<OneD, NekDouble>(nq, 1.0);
237  m_muvec[k] = Array<OneD, NekDouble>(nq, 1.0);
238  }
239 
240  Array<OneD, NekDouble> radvec(nq);
241  m_DispersiveCloak = false;
242  switch (m_CloakType)
243  {
244  case eOpticalCloak:
245  {
246  radvec = ComputeRadCloak();
247  ComputeMaterialOpticalCloak(radvec, m_epsvec, m_muvec, false);
248  }
249  break;
250 
251  case eOpticalConstCloak:
252  {
253  radvec = ComputeRadCloak(m_CloakNlayer);
254  ComputeMaterialOpticalCloak(radvec, m_epsvec, m_muvec, false);
255 
256  std::cout << "*** rad = [ " << Vmath::Vmax(nq, radvec, 1) << " , "
257  << Vmath::Vmin(nq, radvec, 1) << " ) " << std::endl;
258  }
259  break;
260 
262  {
263  m_DispersiveCloak = true;
264  m_wp2Tol = 0.01;
265  radvec = ComputeRadCloak();
266  ComputeMaterialOpticalCloak(radvec, m_epsvec, m_muvec, true);
267 
268  std::cout << "*** rad = [ " << Vmath::Vmax(nq, radvec, 1) << " , "
269  << Vmath::Vmin(nq, radvec, 1) << " ) " << std::endl;
270  std::cout << "*** wp2 = [ " << Vmath::Vmax(nq, m_wp2, 1) << " , "
271  << Vmath::Vmin(nq, m_wp2, 1) << " ) " << std::endl;
272  }
273  break;
274 
275  case eMicroWaveCloak:
276  {
277  radvec = ComputeRadCloak();
278  ComputeMaterialMicroWaveCloak(radvec, m_epsvec, m_muvec);
279  }
280  break;
281 
282  default:
283  {
285  }
286  break;
287  }
288 
289  NekDouble eps1min, eps1max, eps2min, eps2max, eps3min, eps3max;
290  NekDouble mu1min, mu1max, mu2min, mu2max, mu3min, mu3max;
291 
292  eps1min = Vmath::Vmin(nq, m_epsvec[0], 1);
293  eps3min = Vmath::Vmin(nq, m_epsvec[2], 1);
294  eps1max = Vmath::Vmax(nq, m_epsvec[0], 1);
295  eps3max = Vmath::Vmax(nq, m_epsvec[2], 1);
296 
297  if (m_DispersiveCloak)
298  {
299  Array<OneD, NekDouble> realepsr(nq);
300  Vmath::Sadd(nq, -m_wp2Tol, m_wp2, 1, realepsr, 1);
301  Vmath::Smul(nq, 1.0 / (m_Incfreq * m_Incfreq), realepsr, 1, realepsr,
302  1);
303  Vmath::Neg(nq, realepsr, 1);
304  Vmath::Sadd(nq, 1.0, realepsr, 1, realepsr, 1);
305 
306  eps2min = Vmath::Vmin(nq, realepsr, 1);
307  eps2max = Vmath::Vmax(nq, realepsr, 1);
308  }
309 
310  else
311  {
312  eps2min = Vmath::Vmin(nq, m_epsvec[1], 1);
313  eps2max = Vmath::Vmax(nq, m_epsvec[1], 1);
314  }
315 
316  mu1min = Vmath::Vmin(nq, m_muvec[0], 1);
317  mu2min = Vmath::Vmin(nq, m_muvec[1], 1);
318  mu3min = Vmath::Vmin(nq, m_muvec[2], 1);
319  mu1max = Vmath::Vmax(nq, m_muvec[0], 1);
320  mu2max = Vmath::Vmax(nq, m_muvec[1], 1);
321  mu3max = Vmath::Vmax(nq, m_muvec[2], 1);
322 
323  std::cout << "muvec0 = " << RootMeanSquare(m_muvec[0])
324  << ", muvec1 = " << RootMeanSquare(m_muvec[1]) << std::endl;
325 
326  std::cout << "*** epsvec1 = [ " << eps1min << " , " << eps1max
327  << " ], epsvec2 = [ " << eps2min << " , " << eps2max
328  << " ], epsvec3 = [ " << eps3min << " , " << eps3max << " ] "
329  << std::endl;
330  std::cout << "*** muvec1 = [ " << mu1min << " , " << mu1max
331  << " ], muvec2 = [ " << mu2min << " , " << mu2max
332  << " ], muvec3 = [ " << mu3min << " , " << mu3max << " ] "
333  << std::endl;
334 
335  NekDouble dtFactor;
336  switch (m_PolType)
337  {
338  // eTransMagnetic
340  {
341  dtFactor = mu1min * eps3min;
342  if (mu1min > mu2min)
343  {
344  dtFactor = mu2min * eps3min;
345  }
346  }
347  break;
348 
350  {
351  dtFactor = eps1min * mu3min;
352  if (eps1min > eps2min)
353  {
354  dtFactor = eps2min * mu3min;
355  }
356  }
357  break;
358 
359  default:
360  {
361  dtFactor = 1.0;
362  }
363  break;
364  }
365  std::cout << "*** dt factor proportional to varepsilon * mu is " << dtFactor
366  << std::endl;
367 
368  // Compute m_Zim and m_Yim
369  ComputeZimYim(m_epsvec, m_muvec);
370 
371  // Compute m_epsvecminus1 and m_muminus1
374  for (int k = 0; k < m_spacedim; ++k)
375  {
377  m_negmuvecminus1[k] = Array<OneD, NekDouble>(nq, 0.0);
378 
379  if (!m_NoInc)
380  {
381  Vmath::Sadd(nq, -1.0, m_muvec[k], 1, m_negmuvecminus1[k], 1);
382  Vmath::Sadd(nq, -1.0, m_epsvec[k], 1, m_negepsvecminus1[k], 1);
383 
384  Vmath::Neg(nq, m_negmuvecminus1[k], 1);
385  Vmath::Neg(nq, m_negepsvecminus1[k], 1);
386  }
387  }
388 
389  eps1min = Vmath::Vmin(nq, m_negepsvecminus1[0], 1);
390  eps2min = Vmath::Vmin(nq, m_negepsvecminus1[1], 1);
391  eps3min = Vmath::Vmin(nq, m_negepsvecminus1[2], 1);
392  eps1max = Vmath::Vmax(nq, m_negepsvecminus1[0], 1);
393  eps2max = Vmath::Vmax(nq, m_negepsvecminus1[1], 1);
394  eps3max = Vmath::Vmax(nq, m_negepsvecminus1[2], 1);
395 
396  mu1min = Vmath::Vmin(nq, m_negmuvecminus1[0], 1);
397  mu2min = Vmath::Vmin(nq, m_negmuvecminus1[1], 1);
398  mu3min = Vmath::Vmin(nq, m_negmuvecminus1[2], 1);
399  mu1max = Vmath::Vmax(nq, m_negmuvecminus1[0], 1);
400  mu2max = Vmath::Vmax(nq, m_negmuvecminus1[1], 1);
401  mu3max = Vmath::Vmax(nq, m_negmuvecminus1[2], 1);
402 
403  std::cout << "*** negepsvecminus1 = [ " << eps1min << " , " << eps1max
404  << " ], negepsvecminus1 = [ " << eps2min << " , " << eps2max
405  << " ], negepsvecminus1 = [ " << eps3min << " , " << eps3max
406  << " ] " << std::endl;
407  std::cout << "*** negmuvecminus1 = [ " << mu1min << " , " << mu1max
408  << " ], negmuvecminus1 = [ " << mu2min << " , " << mu2max
409  << " ], negmuvecminus1 = [ " << mu3min << " , " << mu3max << " ] "
410  << std::endl;
411 
412  // Compute de^m/dt \cdot e^k
413  if (m_AddRotation)
414  {
417 
419  }
420 
421  // Generate Sigma Block with thicknes of m_PMLthickness and m_PMLmax
422  if (m_AddPML > 0)
423  {
425  }
426 
427  // If explicit it computes RHS and PROJECTION for the time integration
429  {
432  }
433  // Otherwise it gives an error (no implicit integration)
434  else
435  {
436  ASSERTL0(false, "Implicit unsteady Advection not set up.");
437  }
438 }
439 
440 /**
441  * @brief Unsteady linear advection equation destructor.
442  */
444 {
445 }
446 
448 {
449  ASSERTL0(m_intScheme != 0, "No time integration scheme.");
450 
451  int i, nchk = 1;
452  int nq = GetTotPoints();
453  int nvariables = 0;
454  int nfields = m_fields.num_elements();
455 
456  if (m_intVariables.empty())
457  {
458  for (i = 0; i < nfields; ++i)
459  {
460  m_intVariables.push_back(i);
461  }
462  nvariables = nfields;
463  }
464  else
465  {
466  nvariables = m_intVariables.size();
467  }
468 
469  // Set up wrapper to fields data storage.
470  Array<OneD, Array<OneD, NekDouble>> fields(nvariables);
471  Array<OneD, Array<OneD, NekDouble>> tmp(nvariables);
472 
473  // Order storage to list time-integrated fields first.
474  for (i = 0; i < nvariables; ++i)
475  {
476  fields[i] = m_fields[m_intVariables[i]]->GetPhys();
477  m_fields[m_intVariables[i]]->SetPhysState(false);
478  }
479 
480  // Initialise time integration scheme
481  m_intSoln =
482  m_intScheme->InitializeScheme(m_timestep, fields, m_time, m_ode);
483 
484  // Check uniqueness of checkpoint output
485  ASSERTL0((m_checktime == 0.0 && m_checksteps == 0) ||
486  (m_checktime > 0.0 && m_checksteps == 0) ||
487  (m_checktime == 0.0 && m_checksteps > 0),
488  "Only one of IO_CheckTime and IO_CheckSteps "
489  "should be set!");
490 
491  int Ntot = m_steps / m_checksteps + 1;
492 
493  Array<OneD, NekDouble> TimeSeries(Ntot);
494  Array<OneD, NekDouble> Energy(Ntot);
495 
496  LibUtilities::Timer timer;
497  bool doCheckTime = false;
498  int step = 0;
499  NekDouble intTime = 0.0;
500  NekDouble cpuTime = 0.0;
501  NekDouble elapsed = 0.0;
502 
503  int cntap = 0;
504  Array<OneD, NekDouble> Ezantipod;
505  int indxantipod = 0;
506 
507  switch (m_SourceType)
508  {
509  case ePointSource:
510  {
512 
516 
517  m_fields[0]->GetCoords(x, y, z);
518 
519  NekDouble Tol = 0.000001;
520  NekDouble rad;
521  for (i = 0; i < nq; ++i)
522  {
523  rad = sqrt((x[i] + m_Psx) * (x[i] + m_Psx) +
524  (y[i] + m_Psy) * (y[i] + m_Psy) +
525  (z[i] + m_Psz) * (z[i] + m_Psz));
526  std::cout << "rad" << rad << std::endl;
527  if (rad < Tol)
528  {
529  indxantipod = i;
530  break;
531  }
532  }
533  }
534  break;
535 
536  case ePlanarSource:
537  {
539 
543 
544  m_fields[0]->GetCoords(x, y, z);
545 
546  NekDouble Tol = 0.000001;
547  NekDouble rad;
548  for (i = 0; i < nq; ++i)
549  {
550  rad = sqrt((x[i] - m_Psx) * (x[i] - m_Psx));
551  if (rad < Tol)
552  {
553  m_SourceVector[i] = 1.0;
554  }
555  }
556 
557  std::cout << "*** Area of Planar Source = "
558  << m_fields[0]->PhysIntegral(m_SourceVector) << std::endl;
559  }
560  break;
561 
562  default:
563  break;
564  }
565 
566  int cntpml = 0;
567  int P1indx = 0, P2indx = 0, P3indx = 0;
571  if (m_TestPML)
572  {
576 
580 
581  m_fields[0]->GetCoords(x, y, z);
582 
583  NekDouble Tol = 0.000001;
584  NekDouble rad;
585  for (int i = 0; i < nq; ++i)
586  {
587  rad = sqrt((x[i] + 3.0) * (x[i] + 3.0) + (y[i]) * (y[i]));
588 
589  if (rad < Tol)
590  {
591  P1indx = i;
592  break;
593  }
594  }
595 
596  for (int i = 0; i < nq; ++i)
597  {
598  rad =
599  sqrt((x[i] + 3.0) * (x[i] + 3.0) + (y[i] - 1.5) * (y[i] - 1.5));
600  if (rad < Tol)
601  {
602  P2indx = i;
603  break;
604  }
605  }
606 
607  for (int i = 0; i < nq; ++i)
608  {
609  rad =
610  sqrt((x[i] + 3.0) * (x[i] + 3.0) + (y[i] - 3.0) * (y[i] - 3.0));
611  if (rad < Tol)
612  {
613  P3indx = i;
614  break;
615  }
616  }
617  }
618 
619  int indx;
620  while (step < m_steps || m_time < m_fintime - NekConstants::kNekZeroTol)
621  {
622 
623  timer.Start();
624  fields = m_intScheme->TimeIntegrate(step, m_timestep, m_intSoln, m_ode);
625  timer.Stop();
626 
627  /*std::cout << typeid(m_intSoln->GetValue(0)).name() << std::endl;
628  for (int i=0; i< Ntot; ++i)
629  {
630  std::cout << "[" << i << "] = " << inarray[i] <<std::endl;
631  reval = reval + inarray[i]*inarray[i];
632  }*/
633 
634  m_time += m_timestep;
635  elapsed = timer.TimePerTest(1);
636  intTime += elapsed;
637  cpuTime += elapsed;
638 
639  // Write out status information
640  if (m_session->GetComm()->GetRank() == 0 && !((step + 1) % m_infosteps))
641  {
642  std::cout << "Steps: " << std::setw(8) << std::left << step + 1 << " "
643  << "Time: " << std::setw(12) << std::left << m_time;
644 
645  std::stringstream ss;
646  ss << cpuTime / 60.0 << " min.";
647  std::cout << " CPU Time: " << std::setw(8) << std::left << ss.str()
648  << std::endl;
649 
650  cpuTime = 0.0;
651  }
652 
653  switch (m_SourceType)
654  {
655  case ePointSource:
656  {
657  if (m_time <= m_PSduration)
658  {
659  Array<OneD, NekDouble> Impulse(nq);
660  Impulse = GaussianPulse(m_time, m_Psx, m_Psy, m_Psz,
662  Vmath::Vadd(nq, &Impulse[0], 1,
663  &fields[m_intVariables[2]][0], 1,
664  &fields[m_intVariables[2]][0], 1);
665  }
666  }
667  break;
668 
669  case ePlanarSource:
670  {
671  Array<OneD, NekDouble> Impulse(nq);
672  for (int i = 0; i < 3; ++i)
673  {
674  Impulse = GetIncidentField(i, m_time);
675  Vmath::Vmul(nq, m_SourceVector, 1, Impulse, 1, Impulse, 1);
676  Vmath::Vadd(nq, &Impulse[0], 1,
677  &fields[m_intVariables[i]][0], 1,
678  &fields[m_intVariables[i]][0], 1);
679  }
680  }
681  break;
682 
683  default:
684  break;
685  }
686 
687  // Transform data into coefficient space
688  for (i = 0; i < nvariables; ++i)
689  {
690  m_fields[m_intVariables[i]]->SetPhys(fields[i]);
691  m_fields[m_intVariables[i]]->FwdTrans_IterPerExp(
692  fields[i], m_fields[m_intVariables[i]]->UpdateCoeffs());
693  m_fields[m_intVariables[i]]->SetPhysState(false);
694  }
695  // for (i = 0; i < nq; ++i)
696  // std::cout << m_fields[0][0][i] <<std::endl;
697 
698  // Write out checkpoint files
699  if ((m_checksteps && step && !((step + 1) % m_checksteps)) ||
700  doCheckTime)
701  {
702  indx = (step + 1) / m_checksteps;
703  TimeSeries[indx] = m_time;
704 
706  {
707  Checkpoint_TotalFieldOutput(nchk, m_time, fields);
708  Checkpoint_TotPlotOutput(nchk, m_time, fields);
709  }
710  Checkpoint_PlotOutput(nchk, fields);
711  Checkpoint_EDFluxOutput(nchk, m_time, fields);
712  Checkpoint_EnergyOutput(nchk, m_time, fields);
713  Checkpoint_Output(nchk++);
714 
715  Energy[indx] = ComputeEnergyDensity(fields);
716 
717  std::cout << "|EHr|: F1 = " << RootMeanSquare(fields[0])
718  << ", F2 = " << RootMeanSquare(fields[1])
719  << ", F3 = " << RootMeanSquare(fields[2])
720  << ", Energy = " << Energy[indx] << std::endl;
721  if (nfields > 3)
722  {
723  std::cout << "|DBr|: D1 = " << RootMeanSquare(fields[3])
724  << ", D2 = " << RootMeanSquare(fields[4])
725  << ", D3 = " << RootMeanSquare(fields[5]) << std::endl;
726 
727  int nTraceNumPoints = GetTraceNpoints();
728  int totbdryexp =
729  m_fields[0]->GetBndCondExpansions()[0]->GetExpSize();
730  int npts = m_fields[0]
731  ->GetBndCondExpansions()[0]
732  ->GetExp(0)
733  ->GetNumPoints(0);
734 
735  Array<OneD, NekDouble> x0(nq);
736  Array<OneD, NekDouble> x1(nq);
737  Array<OneD, NekDouble> x2(nq);
738 
739  m_fields[0]->GetCoords(x0, x1, x2);
740 
741  Array<OneD, NekDouble> E1Fwd(nTraceNumPoints);
742  Array<OneD, NekDouble> E2Fwd(nTraceNumPoints);
743  Array<OneD, NekDouble> H3Fwd(nTraceNumPoints);
744 
745  m_fields[0]->ExtractTracePhys(fields[0], E1Fwd);
746  m_fields[0]->ExtractTracePhys(fields[1], E2Fwd);
747  m_fields[0]->ExtractTracePhys(fields[2], H3Fwd);
748 
749  int id2, cnt = 0;
750  NekDouble E1atPECloc, E1atPEC = 0.0;
751  NekDouble E2atPECloc, E2atPEC = 0.0;
752  NekDouble H3atPECloc, H3atPEC = 0.0;
753 
754  Array<OneD, NekDouble> E1Fwdloc(npts);
755  Array<OneD, NekDouble> E2Fwdloc(npts);
756  Array<OneD, NekDouble> H3Fwdloc(npts);
757 
758  for (int e = 0; e < totbdryexp; ++e)
759  {
760  id2 = m_fields[0]->GetTrace()->GetPhys_Offset(
761  m_fields[0]
762  ->GetTraceMap()
763  ->GetBndCondCoeffsToGlobalCoeffsMap(cnt + e));
764 
765  Vmath::Vcopy(npts, &E1Fwd[id2], 1, &E1Fwdloc[0], 1);
766  Vmath::Vcopy(npts, &E2Fwd[id2], 1, &E2Fwdloc[0], 1);
767  Vmath::Vcopy(npts, &H3Fwd[id2], 1, &H3Fwdloc[0], 1);
768 
769  E1atPECloc = Vmath::Vamax(npts, E1Fwdloc, 1);
770  E2atPECloc = Vmath::Vamax(npts, E2Fwdloc, 1);
771  H3atPECloc = Vmath::Vamax(npts, H3Fwdloc, 1);
772 
773  if (E1atPEC < E1atPECloc)
774  {
775  E1atPEC = E1atPECloc;
776  }
777 
778  if (E2atPEC < E2atPECloc)
779  {
780  E2atPEC = E2atPECloc;
781  }
782 
783  if (H3atPEC < H3atPECloc)
784  {
785  H3atPEC = H3atPECloc;
786  }
787  }
788 
789  std::cout << "At PEC, Max. E1 = " << E1atPEC
790  << ", E2 = " << E2atPEC << ", H3 = " << H3atPEC
791  << std::endl;
792  }
793 
794  if (m_SourceType == ePointSource)
795  {
796  Ezantipod[cntap++] = fields[2][indxantipod];
797  }
798 
799  if (m_TestPML)
800  {
801  P1[cntpml] = fields[2][P1indx];
802  P2[cntpml] = fields[2][P2indx];
803  P3[cntpml] = fields[2][P3indx];
804  cntpml++;
805  }
806  doCheckTime = false;
807  }
808 
809  // Step advance
810  ++step;
811  }
812 
813  // Print out summary statistics
814  if (m_session->GetComm()->GetRank() == 0)
815  {
816  std::cout << "Time-integration : " << intTime << "s" << std::endl;
817 
818  std::cout << "TimeSeries = " << std::endl;
819  for (int i = 0; i < m_steps / m_checksteps; ++i)
820  {
821  std::cout << TimeSeries[i] << ", ";
822  }
823  std::cout << std::endl << std::endl;
824 
825  std::cout << "Energy Density = " << std::endl;
826  for (int i = 0; i < m_steps / m_checksteps; ++i)
827  {
828  std::cout << Energy[i] << ", ";
829  }
830  std::cout << std::endl << std::endl;
831 
833  {
835  }
836 
837  if (m_SourceType == ePointSource)
838  {
839  std::cout << "Ez at antipod = " << std::endl;
840  for (int i = 0; i < m_steps / m_checksteps; ++i)
841  {
842  std::cout << Ezantipod[i] << ", ";
843  }
844  std::cout << std::endl << std::endl;
845  }
846 
847  if (m_TestPML)
848  {
849  std::cout << "P1 = " << std::endl;
850  for (int i = 0; i < m_steps / m_checksteps; ++i)
851  {
852  std::cout << P1[i] << ", ";
853  }
854  std::cout << std::endl << std::endl;
855 
856  std::cout << "P2 = " << std::endl;
857  for (int i = 0; i < m_steps / m_checksteps; ++i)
858  {
859  std::cout << P2[i] << ", ";
860  }
861  std::cout << std::endl << std::endl;
862 
863  std::cout << "P3 = " << std::endl;
864  for (int i = 0; i < m_steps / m_checksteps; ++i)
865  {
866  std::cout << P3[i] << ", ";
867  }
868  std::cout << std::endl << std::endl;
869  }
870  }
871 
872  for (i = 0; i < nvariables; ++i)
873  {
874  m_fields[m_intVariables[i]]->SetPhys(fields[i]);
875  m_fields[m_intVariables[i]]->SetPhysState(true);
876  }
877 
878  for (i = 0; i < nvariables; ++i)
879  {
880  m_fields[i]->FwdTrans(m_fields[i]->GetPhys(),
881  m_fields[i]->UpdateCoeffs());
882  }
883 }
884 
885 /**
886  * @brief Compute the right-hand side for the linear advection equation.
887  *
888  * @param inarray Given fields.
889  * @param outarray Calculated solution.
890  * @param time Time.
891  */
893  const Array<OneD, const Array<OneD, NekDouble>> &inarray,
894  Array<OneD, Array<OneD, NekDouble>> &outarray, const NekDouble time)
895 {
896  int i;
897  int nvar = inarray.num_elements();
898  int ncoeffs = GetNcoeffs();
899  int nq = GetTotPoints();
900 
901  Array<OneD, Array<OneD, NekDouble>> physarray(nvar);
902  Array<OneD, Array<OneD, NekDouble>> modarray(nvar);
903  for (i = 0; i < nvar; ++i)
904  {
905  physarray[i] = Array<OneD, NekDouble>(nq);
906  modarray[i] = Array<OneD, NekDouble>(ncoeffs, 0.0);
907 
908  Vmath::Vcopy(nq, &inarray[i][0], 1, &physarray[i][0], 1);
909  }
910 
911  for (i = 0; i < nvar; i++)
912  {
913  m_fields[i]->SetPhysState(true);
914  }
915 
916  // Compute Curl
917  switch (m_TestMaxwellType)
918  {
921 
922  {
923 
924  // Imaginary part is computed the same as Real part
927 
928  for (int i = 0; i < 3; ++i)
929  {
930  tmpin[i] = Array<OneD, NekDouble>(nq);
931  tmpout[i] = Array<OneD, NekDouble>(ncoeffs, 0.0);
932 
933  Vmath::Vcopy(nq, &physarray[i][0], 1, &tmpin[i][0], 1);
934  }
935 
936  WeakDGMaxwellDirDeriv(tmpin, tmpout, time);
937  AddGreenDerivCompensate(tmpin, tmpout);
938 
939  for (int i = 0; i < 3; ++i)
940  {
941  // For E and H
942  Vmath::Vcopy(ncoeffs, &tmpout[i][0], 1, &modarray[i][0], 1);
943  }
944  }
945  break;
946 
947  default:
948  {
949 
950  WeakDGMaxwellDirDeriv(physarray, modarray, time);
951  AddGreenDerivCompensate(physarray, modarray);
952  }
953  break;
954  }
955 
956  for (i = 0; i < nvar; ++i)
957  {
958  m_fields[i]->MultiplyByElmtInvMass(modarray[i], modarray[i]);
959  m_fields[i]->BwdTrans(modarray[i], outarray[i]);
960  }
961 
963  {
965  for (int j = 0; j < 2; ++j)
966  {
967  F = TestMaxwellSphere(time, m_freq, 3 + j);
968  Vmath::Vadd(nq, &F[0], 1, &outarray[j][0], 1, &outarray[j][0], 1);
969  }
970  }
971 
972  // Add Absorbing Boundary Conditions
973  if (m_AddPML > 0)
974  {
975  AddPML(physarray, outarray);
976  }
977 
978  // Add dedt component
979  if (m_AddRotation)
980  {
981  AddCoriolis(physarray, outarray);
982  AdddedtMaxwell(physarray, outarray);
983  }
984 
985  // Divide it by varepsilon or mu
986  Array<OneD, NekDouble> dFdt(nq, 0.0);
987  switch (m_TestMaxwellType)
988  {
990  {
991  Vmath::Vdiv(nq, outarray[0], 1, m_epsvec[0], 1, outarray[0], 1);
992  Vmath::Vdiv(nq, outarray[1], 1, m_muvec[0], 1, outarray[1], 1);
993  }
994  break;
995 
996  // TO BE CHANGED
998  {
999  Array<OneD, NekDouble> Hxdt(nq, 0.0);
1000  Array<OneD, NekDouble> Hydt(nq, 0.0);
1001 
1002  Hxdt = TestMaxwell2DPEC(time, 10, m_PolType);
1003  Hydt = TestMaxwell2DPEC(time, 11, m_PolType);
1004 
1005  Array<OneD, NekDouble> x0(nq);
1006  Array<OneD, NekDouble> x1(nq);
1007  Array<OneD, NekDouble> x2(nq);
1008 
1009  m_fields[0]->GetCoords(x0, x1, x2);
1010 
1011  NekDouble theta, tmpx, tmpy;
1012  NekDouble uxx, uxy, uyy, detu, uti, uri;
1013  Array<OneD, NekDouble> utvec(nq, 1.0);
1014  Array<OneD, NekDouble> urvec(nq, 1.0);
1015  Array<OneD, NekDouble> tmpIN(nq);
1016 
1017  // Case I: ut = 4.0, ur = 0.5
1018  // NekDouble ut=4.0;
1019  // NekDouble ur=0.5;
1020 
1021  // m_fields[0]->GenerateElementVector(m_ElemtGroup1, ut, 1.0,
1022  // utvec);
1023  // m_fields[0]->GenerateElementVector(m_ElemtGroup1, ur, 1.0,
1024  // urvec);
1025 
1026  // Case II: ut = 0.5, ur = 1 - 2x^2
1027  NekDouble ut = 0.5;
1028  m_fields[0]->GenerateElementVector(m_ElemtGroup1, ut, 1.0, utvec);
1029 
1030  m_fields[0]->GenerateElementVector(m_ElemtGroup1, 1.0, 0.0, tmpIN);
1031 
1032  for (int i = 0; i < nq; i++)
1033  {
1034  urvec[i] =
1035  tmpIN[i] * (1.0 - 2 * x0[i] * x0[i]) + (1.0 - tmpIN[i]);
1036  }
1037 
1038  for (int i = 0; i < nq; ++i)
1039  {
1040  theta = atan2((x1[i] + 2.0), (x0[i] + 2.0));
1041 
1042  uti = utvec[i];
1043  uri = urvec[i];
1044 
1045  uxx = uti * cos(theta) * cos(theta) +
1046  uri * sin(theta) * sin(theta);
1047  uyy = uti * sin(theta) * sin(theta) +
1048  uri * cos(theta) * cos(theta);
1049  uxy = (uti - uri) * cos(theta) * sin(theta);
1050 
1051  detu = uxx * uyy - uxy * uxy;
1052 
1053  tmpx = outarray[0][i] + (1.0 - uxx) * Hxdt[i] - uxy * Hydt[i];
1054  tmpy = outarray[1][i] - uxy * Hxdt[i] + (1.0 - uyy) * Hydt[i];
1055 
1056  outarray[0][i] = (1 / detu) * (uyy * tmpx - uxy * tmpy);
1057  outarray[1][i] = (1 / detu) * (-uxy * tmpx + uxx * tmpy);
1058  }
1059  }
1060  break;
1061 
1065  {
1066  switch (m_PolType)
1067  {
1069  {
1071  {
1072  dFdt = TestMaxwell2DPEC(time, 10, m_PolType);
1073  Vmath::Vvtvp(nq, m_negmuvecminus1[0], 1, dFdt, 1,
1074  outarray[0], 1, outarray[0], 1);
1075 
1076  dFdt = TestMaxwell2DPEC(time, 11, m_PolType);
1077  Vmath::Vvtvp(nq, m_negmuvecminus1[1], 1, dFdt, 1,
1078  outarray[1], 1, outarray[1], 1);
1079 
1080  dFdt = TestMaxwell2DPEC(time, 12, m_PolType);
1081  Vmath::Vvtvp(nq, m_negepsvecminus1[2], 1, dFdt, 1,
1082  outarray[2], 1, outarray[2], 1);
1083  }
1084 
1086  {
1087  dFdt = GetIncidentField(10, time);
1088  Vmath::Vvtvp(nq, m_negmuvecminus1[0], 1, dFdt, 1,
1089  outarray[0], 1, outarray[0], 1);
1090 
1091  dFdt = GetIncidentField(11, time);
1092  Vmath::Vvtvp(nq, m_negmuvecminus1[1], 1, dFdt, 1,
1093  outarray[1], 1, outarray[1], 1);
1094 
1095  dFdt = GetIncidentField(12, time);
1096  Vmath::Vvtvp(nq, m_negepsvecminus1[2], 1, dFdt, 1,
1097  outarray[2], 1, outarray[2], 1);
1098  }
1099 
1100  Vmath::Vdiv(nq, outarray[0], 1, m_muvec[0], 1, outarray[0],
1101  1);
1102  Vmath::Vdiv(nq, outarray[1], 1, m_muvec[1], 1, outarray[1],
1103  1);
1104  Vmath::Vdiv(nq, outarray[2], 1, m_epsvec[2], 1, outarray[2],
1105  1);
1106  }
1107  break;
1108 
1110  {
1112  {
1113  // (I - \mu^i) d F^{inc} / dt
1114  dFdt = TestMaxwell2DPEC(time, 10, m_PolType);
1115  Vmath::Vvtvp(nq, m_negepsvecminus1[0], 1, dFdt, 1,
1116  outarray[0], 1, outarray[0], 1);
1117 
1118  dFdt = TestMaxwell2DPEC(time, 11, m_PolType);
1119  Vmath::Vvtvp(nq, m_negepsvecminus1[1], 1, dFdt, 1,
1120  outarray[1], 1, outarray[1], 1);
1121 
1122  dFdt = TestMaxwell2DPEC(time, 12, m_PolType);
1123  Vmath::Vvtvp(nq, m_negmuvecminus1[2], 1, dFdt, 1,
1124  outarray[2], 1, outarray[2], 1);
1125  }
1126 
1128  {
1129  dFdt = GetIncidentField(10, time);
1130  Vmath::Vvtvp(nq, m_negepsvecminus1[0], 1, dFdt, 1,
1131  outarray[0], 1, outarray[0], 1);
1132 
1133  // Add - wp^2 \int E_2^{inc}
1134  dFdt = GetIncidentField(21, time);
1135  if (m_DispersiveCloak)
1136  {
1137  Vmath::Vmul(nq, m_wp2, 1, dFdt, 1, dFdt, 1);
1138  Vmath::Vsub(nq, outarray[1], 1, dFdt, 1,
1139  outarray[1], 1);
1140  }
1141 
1142  else
1143  {
1144  Vmath::Vvtvp(nq, m_negepsvecminus1[1], 1, dFdt, 1,
1145  outarray[1], 1, outarray[1], 1);
1146  }
1147 
1148  dFdt = GetIncidentField(12, time);
1149  Vmath::Vvtvp(nq, m_negmuvecminus1[2], 1, dFdt, 1,
1150  outarray[2], 1, outarray[2], 1);
1151  }
1152 
1153  Vmath::Vdiv(nq, outarray[0], 1, m_epsvec[0], 1, outarray[0],
1154  1);
1155  Vmath::Vdiv(nq, outarray[1], 1, m_epsvec[1], 1, outarray[1],
1156  1);
1157  Vmath::Vdiv(nq, outarray[2], 1, m_muvec[2], 1, outarray[2],
1158  1);
1159  }
1160  break;
1161 
1162  default:
1163  break;
1164  }
1165  }
1166  break; // case SolverUtils::eTestMaxwell2DPEC:
1167 
1168  default:
1169  break;
1170 
1171  } // switch(m_TestMaxwellType)
1172 }
1173 
1175  const Array<OneD, const Array<OneD, NekDouble>> &physarray,
1176  Array<OneD, Array<OneD, NekDouble>> &outarray)
1177 {
1178  // routine works for both primitive and conservative formulations
1179  int ncoeffs = outarray[0].num_elements();
1180  int nq = physarray[0].num_elements();
1181 
1182  Array<OneD, NekDouble> tmp(nq);
1183  Array<OneD, NekDouble> tmpc(ncoeffs);
1184 
1186  for (int j = 0; j < m_shapedim; ++j)
1187  {
1188  fluxvector[j] = Array<OneD, NekDouble>(nq);
1189  }
1190 
1191  // m_CurlMF[0][0] = e^3 \cdot (\nabla \times e^1) [ NEW m_CurlMF[0][2] ]
1192  // m_CurlMF[0][1] = 0.0
1193  // m_CurlMF[1][0] = 0.0,
1194  // m_CurlMF[1][1] = e^3 \cdot (\nabla \times e^2) [ NEW m_CurlMF[1][2] ]
1195  // m_CurlMF[2][0] = e^1 \cdot (\nabla \times e^3) [ NEW m_CurlMF[2][0] ]
1196  // m_CurlMF[2][1] = e^2 \cdot (\nabla \times e^3) [ NEW m_CurlMF[2][1] ]
1197 
1198  int var;
1199 
1200  switch (m_TestMaxwellType)
1201  {
1209  {
1210  var = 0;
1211  GetMaxwellFluxVector(var, physarray, fluxvector);
1212  Vmath::Vmul(nq, &fluxvector[0][0], 1, &m_CurlMF[0][2][0], 1,
1213  &tmp[0], 1);
1214  m_fields[var]->IProductWRTBase(tmp, tmpc);
1215  Vmath::Vadd(ncoeffs, tmpc, 1, outarray[var], 1, outarray[var], 1);
1216 
1217  var = 1;
1218  GetMaxwellFluxVector(var, physarray, fluxvector);
1219  Vmath::Vmul(nq, &fluxvector[1][0], 1, &m_CurlMF[1][2][0], 1,
1220  &tmp[0], 1);
1221  Vmath::Neg(nq, tmp, 1);
1222  m_fields[var]->IProductWRTBase(tmp, tmpc);
1223  Vmath::Vadd(ncoeffs, tmpc, 1, outarray[var], 1, outarray[var], 1);
1224 
1225  var = 2;
1226  GetMaxwellFluxVector(var, physarray, fluxvector);
1227  Vmath::Vmul(nq, &fluxvector[0][0], 1, &m_CurlMF[2][0][0], 1,
1228  &tmp[0], 1);
1229  Vmath::Vvtvm(nq, &fluxvector[1][0], 1, &m_CurlMF[2][1][0], 1,
1230  &tmp[0], 1, &tmp[0], 1);
1231  m_fields[var]->IProductWRTBase(tmp, tmpc);
1232  Vmath::Vadd(ncoeffs, tmpc, 1, outarray[var], 1, outarray[var], 1);
1233  }
1234  break;
1235 
1236  default:
1237  break;
1238  }
1239 }
1240 
1241 /**
1242  * @brief Calculate weak DG advection in the form \f$ \langle\phi,
1243  * \hat{F}\cdot n\rangle - (\nabla \phi \cdot F) \f$
1244  *
1245  * @param InField Fields.
1246  * @param OutField Storage for result.
1247  * @param NumericalFluxIncludesNormal Default: true.
1248  * @param InFieldIsPhysSpace Default: false.
1249  * @param nvariables Number of fields.
1250  */
1252  const Array<OneD, const Array<OneD, NekDouble>> &InField,
1253  Array<OneD, Array<OneD, NekDouble>> &OutField, const NekDouble time)
1254 {
1255  int i;
1256  int nq = GetNpoints();
1257  int ncoeffs = GetNcoeffs();
1258  int nTracePointsTot = GetTraceNpoints();
1259  int nvar = 3;
1260 
1262  for (i = 0; i < m_shapedim; ++i)
1263  {
1264  fluxvector[i] = Array<OneD, NekDouble>(nq);
1265  }
1266 
1267  Array<OneD, Array<OneD, NekDouble>> physfield(nvar);
1268  for (i = 0; i < nvar; ++i)
1269  {
1270  physfield[i] = InField[i];
1271  }
1272 
1273  Array<OneD, NekDouble> tmpc(ncoeffs);
1274  for (i = 0; i < nvar; ++i)
1275  {
1276  GetMaxwellFluxVector(i, physfield, fluxvector);
1277 
1278  OutField[i] = Array<OneD, NekDouble>(ncoeffs, 0.0);
1279  for (int j = 0; j < m_shapedim; ++j)
1280  {
1281  // Directional derivation with respect to the j'th moving frame
1282  // tmp_j = ( \nabla \phi, fluxvector[j] \mathbf{e}^j )
1283  m_fields[i]->IProductWRTDirectionalDerivBase(m_CrossProductMF[j],
1284  fluxvector[j], tmpc);
1285  Vmath::Vadd(ncoeffs, &tmpc[0], 1, &OutField[i][0], 1,
1286  &OutField[i][0], 1);
1287  }
1288  }
1289 
1290  // V the numerical flux and add to the modal coeffs
1291  // if the NumericalFlux function does not include the
1292  // normal in the output
1293  Array<OneD, Array<OneD, NekDouble>> numfluxFwd(nvar);
1294  Array<OneD, Array<OneD, NekDouble>> numfluxBwd(nvar);
1295 
1296  for (i = 0; i < nvar; ++i)
1297  {
1298  numfluxFwd[i] = Array<OneD, NekDouble>(nTracePointsTot, 0.0);
1299  numfluxBwd[i] = Array<OneD, NekDouble>(nTracePointsTot, 0.0);
1300  }
1301 
1302  // Evaluate numerical flux in physical space which may in
1303  // general couple all component of vectors
1304  NumericalMaxwellFlux(physfield, numfluxFwd, numfluxBwd, time);
1305 
1306  // Evaulate <\phi, \hat{F}\cdot n> - OutField[i]
1307  for (i = 0; i < nvar; ++i)
1308  {
1309  Vmath::Neg(ncoeffs, OutField[i], 1);
1310  m_fields[i]->AddFwdBwdTraceIntegral(numfluxFwd[i], numfluxBwd[i],
1311  OutField[i]);
1312  m_fields[i]->SetPhysState(false);
1313  }
1314 }
1315 
1316 /**
1317  * @brief Compute the projection for the linear advection equation.
1318  *
1319  * @param inarray Given fields.
1320  * @param outarray Calculated solution.
1321  * @param time Time.
1322  */
1324  const Array<OneD, const Array<OneD, NekDouble>> &inarray,
1325  Array<OneD, Array<OneD, NekDouble>> &outarray, const NekDouble time)
1326 {
1327  boost::ignore_unused(time);
1328 
1329  int var = inarray.num_elements();
1330 
1331  // SetBoundaryConditions(time);
1332 
1333  int nq = GetNpoints();
1334  for (int i = 0; i < var; ++i)
1335  {
1336  Vmath::Vcopy(nq, inarray[i], 1, outarray[i], 1);
1337  }
1338 }
1339 
1341  bool dumpInitialConditions,
1342  const int domain)
1343 {
1344  boost::ignore_unused(domain);
1345 
1346  int nq = GetTotPoints();
1347  int nvar = m_fields.num_elements();
1348 
1349  switch (m_TestMaxwellType)
1350  {
1352  {
1353  m_fields[0]->SetPhys(TestMaxwell1D(initialtime, 0));
1354  m_fields[1]->SetPhys(TestMaxwell1D(initialtime, 1));
1355  }
1356  break;
1357 
1360  {
1361  m_fields[0]->SetPhys(TestMaxwell2DPEC(initialtime, 0, m_PolType));
1362  m_fields[1]->SetPhys(TestMaxwell2DPEC(initialtime, 1, m_PolType));
1363  m_fields[2]->SetPhys(TestMaxwell2DPEC(initialtime, 2, m_PolType));
1364  }
1365  break;
1366 
1368  {
1369  m_fields[0]->SetPhys(TestMaxwell2DPMC(initialtime, 0, m_PolType));
1370  m_fields[1]->SetPhys(TestMaxwell2DPMC(initialtime, 1, m_PolType));
1371  m_fields[2]->SetPhys(TestMaxwell2DPMC(initialtime, 2, m_PolType));
1372  }
1373  break;
1374 
1377  {
1378  Array<OneD, NekDouble> Zeros(nq, 0.0);
1379 
1380  for (int i = 0; i < nvar; i++)
1381  {
1382  m_fields[i]->SetPhys(Zeros);
1383  }
1384  }
1385  break;
1386 
1388  {
1389  m_fields[0]->SetPhys(TestMaxwellSphere(initialtime, m_freq, 0));
1390  m_fields[1]->SetPhys(TestMaxwellSphere(initialtime, m_freq, 1));
1391  m_fields[2]->SetPhys(TestMaxwellSphere(initialtime, m_freq, 2));
1392  }
1393  break;
1394 
1396  {
1397  m_fields[2]->SetPhys(GaussianPulse(initialtime, m_Psx, m_Psy, m_Psz,
1398  m_Gaussianradius));
1399  }
1400  break;
1401 
1402  default:
1403  break;
1404  }
1405 
1406  // forward transform to fill the modal coeffs
1407  for (int i = 0; i < nvar; ++i)
1408  {
1409  m_fields[i]->SetPhysState(true);
1410  m_fields[i]->FwdTrans(m_fields[i]->GetPhys(),
1411  m_fields[i]->UpdateCoeffs());
1412  }
1413 
1414  if (dumpInitialConditions)
1415  {
1416  std::string outname = m_sessionName + "_initial.chk";
1417  WriteFld(outname);
1418 
1419  Array<OneD, Array<OneD, NekDouble>> fields(nvar);
1420  for (int i = 0; i < nvar; ++i)
1421  {
1422  fields[i] = m_fields[i]->GetPhys();
1423  }
1424 
1425  Checkpoint_PlotOutput(0, fields);
1426  }
1427 }
1428 
1429 void MMFMaxwell::v_EvaluateExactSolution(unsigned int field,
1430  Array<OneD, NekDouble> &outfield,
1431  const NekDouble time)
1432 {
1433  int nq = m_fields[0]->GetNpoints();
1434  outfield = Array<OneD, NekDouble>(nq);
1435 
1436  switch (m_TestMaxwellType)
1437  {
1439  {
1440  outfield = TestMaxwell1D(time, field);
1441  }
1442  break;
1443 
1446  {
1447  outfield = TestMaxwell2DPEC(time, field, m_PolType);
1448  }
1449  break;
1450 
1452  {
1453  outfield = TestMaxwell2DPMC(time, field, m_PolType);
1454  }
1455  break;
1456 
1458  {
1459  outfield = TestMaxwellSphere(time, m_freq, field);
1460  }
1461  break;
1462 
1463  default:
1464  {
1465  outfield = Array<OneD, NekDouble>(nq, 0.0);
1466  }
1467  break;
1468  }
1469 }
1470 
1472  unsigned int field)
1473 {
1474  int nq = m_fields[0]->GetNpoints();
1475 
1476  Array<OneD, NekDouble> x0(nq);
1477  Array<OneD, NekDouble> x1(nq);
1478  Array<OneD, NekDouble> x2(nq);
1479 
1480  m_fields[0]->GetCoords(x0, x1, x2);
1481 
1482  Array<OneD, NekDouble> E(nq);
1483  Array<OneD, NekDouble> H(nq);
1484 
1485  // Derive the frequency \omega
1486  NekDouble omega;
1487  NekDouble Tol = 0.000000001;
1488  if (fabs(m_n1 - m_n2) < Tol)
1489  {
1490  omega = m_pi / m_n1;
1491  }
1492 
1493  else
1494  {
1495  omega = 2.0 * m_pi / m_n2;
1496 
1497  NekDouble newomega, F, Fprime;
1498  for (int i = 0; i < 10000; ++i)
1499  {
1500  F = m_n1 * tan(m_n2 * omega) + m_n2 * tan(m_n1 * omega);
1501  Fprime =
1502  m_n1 * m_n2 * (1.0 / cos(m_n2 * omega) / cos(m_n2 * omega) +
1503  1.0 / cos(m_n1 * omega) / cos(m_n1 * omega));
1504 
1505  newomega = omega - F / Fprime;
1506 
1507  if (fabs(newomega - omega) > Tol)
1508  {
1509  omega = newomega;
1510  }
1511 
1512  else
1513  {
1514  break;
1515  }
1516  }
1517  }
1518 
1519  // Generate A^k and B^k
1520  std::complex<double> im = sqrt(std::complex<double>(-1));
1521  std::complex<double> A1, A2, B1, B2;
1522  std::complex<double> Ak, Bk, nk;
1523  std::complex<double> Ec, Hc;
1524 
1525  A1 = m_n2 * cos(m_n2 * omega) / (m_n1 * cos(m_n1 * omega));
1526  A2 = exp(-1.0 * im * omega * (m_n1 + m_n2));
1527  B1 = A1 * exp(-2.0 * im * m_n1 * omega);
1528  B2 = A2 * exp(2.0 * im * m_n2 * omega);
1529 
1530  for (int i = 0; i < nq; ++i)
1531  {
1532  if (x0[i] > 0)
1533  {
1534  Ak = A2;
1535  Bk = B2;
1536  nk = m_n2;
1537  }
1538 
1539  else
1540  {
1541  Ak = A1;
1542  Bk = B1;
1543  nk = m_n1;
1544  }
1545 
1546  Ec = (Ak * exp(im * nk * omega * x0[i]) -
1547  Bk * exp(-im * nk * omega * x0[i])) *
1548  exp(im * omega * time);
1549  Hc = nk * (Ak * exp(im * nk * omega * x0[i]) +
1550  Bk * exp(-im * nk * omega * x0[i])) *
1551  exp(im * omega * time);
1552 
1553  E[i] = Ec.real();
1554  H[i] = Hc.real();
1555  }
1556 
1557  Array<OneD, NekDouble> outfield;
1558  switch (field)
1559  {
1560  case (0):
1561  {
1562  outfield = E;
1563  }
1564  break;
1565 
1566  case (1):
1567  {
1568  outfield = H;
1569  }
1570  break;
1571  }
1572 
1573  return outfield;
1574 }
1575 
1577  const NekDouble time, unsigned int field,
1578  const SolverUtils::PolType Polarization)
1579 {
1580  int nq = m_fields[0]->GetNpoints();
1581 
1582  Array<OneD, NekDouble> x0(nq);
1583  Array<OneD, NekDouble> x1(nq);
1584  Array<OneD, NekDouble> x2(nq);
1585 
1586  m_fields[0]->GetCoords(x0, x1, x2);
1587 
1588  NekDouble freqm = 1.0, freqn = 1.0;
1589  NekDouble omega = m_pi * sqrt(freqm * freqm + freqn * freqn);
1590  NekDouble mpi = freqm * m_pi;
1591  NekDouble npi = freqn * m_pi;
1592 
1593  Array<OneD, NekDouble> F1(nq);
1594  Array<OneD, NekDouble> F2(nq);
1595  Array<OneD, NekDouble> Fz(nq);
1596  Array<OneD, NekDouble> dF1dt(nq);
1597  Array<OneD, NekDouble> dF2dt(nq);
1598  Array<OneD, NekDouble> dFzdt(nq);
1599  NekDouble Fx, Fy, dFxdt, dFydt;
1600 
1601  for (int i = 0; i < nq; ++i)
1602  {
1603  switch (Polarization)
1604  {
1606  {
1607  Fx = -1.0 * (npi / omega) * sin(mpi * x0[i]) *
1608  cos(npi * x1[i]) * sin(omega * time);
1609  Fy = (mpi / omega) * cos(mpi * x0[i]) * sin(npi * x1[i]) *
1610  sin(omega * time);
1611 
1612  F1[i] =
1613  Fx * m_movingframes[0][i] + Fy * m_movingframes[0][i + nq];
1614  F2[i] =
1615  Fx * m_movingframes[1][i] + Fy * m_movingframes[1][i + nq];
1616  Fz[i] = sin(mpi * x0[i]) * sin(npi * x1[i]) * cos(omega * time);
1617 
1618  dFxdt = (npi)*sin(mpi * x0[i]) * cos(npi * x1[i]) *
1619  cos(omega * time);
1620  dFydt = -1.0 * (mpi)*cos(mpi * x0[i]) * sin(npi * x1[i]) *
1621  cos(omega * time);
1622 
1623  dF1dt[i] = dFxdt * m_movingframes[0][i] +
1624  dFydt * m_movingframes[0][i + nq];
1625  dF2dt[i] = dFxdt * m_movingframes[1][i] +
1626  dFydt * m_movingframes[1][i + nq];
1627  dFzdt[i] = omega * sin(mpi * x0[i]) * sin(npi * x1[i]) *
1628  sin(omega * time);
1629  }
1630  break;
1631 
1633  {
1634  Fx = -1.0 * (npi / omega) * cos(mpi * x0[i]) *
1635  sin(npi * x1[i]) * sin(omega * time);
1636  Fy = (mpi / omega) * sin(mpi * x0[i]) * cos(npi * x1[i]) *
1637  sin(omega * time);
1638 
1639  F1[i] =
1640  Fx * m_movingframes[0][i] + Fy * m_movingframes[0][i + nq];
1641  F2[i] =
1642  Fx * m_movingframes[1][i] + Fy * m_movingframes[1][i + nq];
1643  Fz[i] = cos(mpi * x0[i]) * cos(npi * x1[i]) * cos(omega * time);
1644 
1645  dFxdt = (npi)*cos(mpi * x0[i]) * sin(npi * x1[i]) *
1646  cos(omega * time);
1647  dFydt = -1.0 * (mpi)*sin(mpi * x0[i]) * cos(npi * x1[i]) *
1648  cos(omega * time);
1649 
1650  dF1dt[i] = dFxdt * m_movingframes[0][i] +
1651  dFydt * m_movingframes[0][i + nq];
1652  dF2dt[i] = dFxdt * m_movingframes[1][i] +
1653  dFydt * m_movingframes[1][i + nq];
1654  dFzdt[i] = omega * cos(mpi * x0[i]) * cos(npi * x1[i]) *
1655  sin(omega * time);
1656  }
1657  break;
1658 
1659  default:
1660  break;
1661  }
1662  }
1663 
1664  Array<OneD, NekDouble> outfield;
1665  switch (field)
1666  {
1667  case (0):
1668  {
1669  outfield = F1;
1670  }
1671  break;
1672 
1673  case (1):
1674  {
1675  outfield = F2;
1676  }
1677  break;
1678 
1679  case (2):
1680  {
1681  outfield = Fz;
1682  }
1683  break;
1684 
1685  case (10):
1686  {
1687  outfield = dF1dt;
1688  }
1689  break;
1690 
1691  case (11):
1692  {
1693  outfield = dF2dt;
1694  }
1695  break;
1696 
1697  case (12):
1698  {
1699  outfield = dFzdt;
1700  }
1701  break;
1702  }
1703 
1704  return outfield;
1705 }
1706 
1708  const NekDouble time, unsigned int field,
1709  const SolverUtils::PolType Polarization)
1710 {
1711  int nq = m_fields[0]->GetNpoints();
1712 
1713  Array<OneD, NekDouble> x0(nq);
1714  Array<OneD, NekDouble> x1(nq);
1715  Array<OneD, NekDouble> x2(nq);
1716 
1717  m_fields[0]->GetCoords(x0, x1, x2);
1718 
1719  NekDouble freqm = 1.0, freqn = 1.0;
1720  NekDouble omega = m_pi * sqrt(freqm * freqm + freqn * freqn);
1721  NekDouble mpi = freqm * m_pi;
1722  NekDouble npi = freqn * m_pi;
1723 
1724  Array<OneD, NekDouble> F1(nq);
1725  Array<OneD, NekDouble> F2(nq);
1726  Array<OneD, NekDouble> Fz(nq);
1727  NekDouble Fx, Fy;
1728 
1729  for (int i = 0; i < nq; ++i)
1730  {
1731  switch (Polarization)
1732  {
1734  {
1735  Fx = (npi / omega) * cos(mpi * x0[i]) * sin(npi * x1[i]) *
1736  sin(omega * time);
1737  Fy = -(mpi / omega) * sin(mpi * x0[i]) * cos(npi * x1[i]) *
1738  sin(omega * time);
1739 
1740  F1[i] =
1741  Fx * m_movingframes[0][i] + Fy * m_movingframes[0][i + nq];
1742  F2[i] =
1743  Fx * m_movingframes[1][i] + Fy * m_movingframes[1][i + nq];
1744  Fz[i] = cos(mpi * x0[i]) * cos(npi * x1[i]) * cos(omega * time);
1745  }
1746  break;
1747 
1749  {
1750  Fx = (npi / omega) * sin(mpi * x0[i]) * cos(npi * x1[i]) *
1751  sin(omega * time);
1752  Fy = -(mpi / omega) * cos(mpi * x0[i]) * sin(npi * x1[i]) *
1753  sin(omega * time);
1754 
1755  F1[i] =
1756  Fx * m_movingframes[0][i] + Fy * m_movingframes[0][i + nq];
1757  F2[i] =
1758  Fx * m_movingframes[1][i] + Fy * m_movingframes[1][i + nq];
1759  Fz[i] = sin(mpi * x0[i]) * sin(npi * x1[i]) * cos(omega * time);
1760  }
1761  break;
1762 
1763  default:
1764  break;
1765  }
1766  }
1767 
1768  Array<OneD, NekDouble> outfield;
1769  switch (field)
1770  {
1771  case (0):
1772  {
1773  outfield = F1;
1774  }
1775  break;
1776 
1777  case (1):
1778  {
1779  outfield = F2;
1780  }
1781  break;
1782 
1783  case (2):
1784  {
1785  outfield = Fz;
1786  }
1787  break;
1788  }
1789 
1790  return outfield;
1791 }
1792 
1794  const NekDouble omega,
1795  unsigned int field)
1796 {
1797  int nq = m_fields[0]->GetTotPoints();
1798 
1799  Array<OneD, NekDouble> outfield(nq);
1800 
1801  Array<OneD, NekDouble> x(nq);
1802  Array<OneD, NekDouble> y(nq);
1803  Array<OneD, NekDouble> z(nq);
1804 
1805  m_fields[0]->GetCoords(x, y, z);
1806 
1807  Array<OneD, NekDouble> H1(nq);
1808  Array<OneD, NekDouble> H2(nq);
1809  Array<OneD, NekDouble> E3(nq);
1810  Array<OneD, NekDouble> F1(nq);
1811  Array<OneD, NekDouble> F2(nq);
1812 
1813  Array<OneD, NekDouble> curlv(nq);
1816  for (int i = 0; i < m_spacedim; ++i)
1817  {
1818  velvec[i] = Array<OneD, NekDouble>(nq, 0.0);
1819  Fvec[i] = Array<OneD, NekDouble>(nq, 0.0);
1820  }
1821 
1822  NekDouble xj, yj, zj, sin_varphi, cos_varphi, sin_theta, cos_theta;
1823  NekDouble vth, vphi, Fth, Fphi;
1824  for (int i = 0; i < nq; i++)
1825  {
1826  xj = x[i];
1827  yj = y[i];
1828  zj = z[i];
1829 
1830  CartesianToSpherical(xj, yj, zj, sin_varphi, cos_varphi, sin_theta,
1831  cos_theta);
1832 
1833  vth = -4.0 * sin_varphi * cos_varphi * cos_theta * cos_theta *
1834  cos_theta * sin_theta;
1835  vphi =
1836  -1.0 * sin_varphi * sin_varphi * cos_theta * cos_theta * cos_theta;
1837  velvec[0][i] = -vth * sin_theta * cos_varphi - vphi * sin_varphi;
1838  velvec[1][i] = -vth * sin_theta * sin_varphi + vphi * cos_varphi;
1839  velvec[2][i] = vth * cos_theta;
1840 
1841  E3[i] = (-4.0 * cos_theta * cos_theta * sin_theta * cos_varphi *
1842  cos_varphi) *
1843  (1.0 / omega * sin(omega * time));
1844 
1845  Fth = -omega * vth -
1846  (8.0 / omega) * cos_theta * sin_theta * cos_varphi * sin_varphi;
1847  Fphi = -omega * vphi +
1848  (4.0 / omega) * cos_varphi * cos_varphi * cos_theta *
1849  (2.0 * sin_theta * sin_theta - cos_theta * cos_theta);
1850  Fvec[0][i] = -Fth * sin_theta * cos_varphi - Fphi * sin_varphi;
1851  Fvec[1][i] = -Fth * sin_theta * sin_varphi + Fphi * cos_varphi;
1852  Fvec[2][i] = Fth * cos_theta;
1853  }
1854 
1855  H1 = CartesianToMovingframes(velvec, 0);
1856  H2 = CartesianToMovingframes(velvec, 1);
1857 
1858  Vmath::Smul(nq, cos(omega * time), H1, 1, H1, 1);
1859  Vmath::Smul(nq, cos(omega * time), H2, 1, H2, 1);
1860 
1861  F1 = CartesianToMovingframes(Fvec, 0);
1862  F2 = CartesianToMovingframes(Fvec, 1);
1863 
1864  Vmath::Smul(nq, sin(omega * time), F1, 1, F1, 1);
1865  Vmath::Smul(nq, sin(omega * time), F2, 1, F2, 1);
1866 
1867  switch (field)
1868  {
1869  // return H1
1870  case 0:
1871  {
1872  outfield = H1;
1873  }
1874  break;
1875 
1876  case 1:
1877  {
1878  outfield = H2;
1879  }
1880  break;
1881 
1882  case 2:
1883  {
1884  outfield = E3;
1885  }
1886  break;
1887 
1888  case 3:
1889  {
1890  outfield = F1;
1891  }
1892  break;
1893 
1894  case 4:
1895  {
1896  outfield = F2;
1897  }
1898  break;
1899 
1900  default:
1901  break;
1902  }
1903 
1904  return outfield;
1905 }
1906 
1908  Array<OneD, Array<OneD, NekDouble>> &fields, const int time)
1909 {
1910  int nq = m_fields[0]->GetTotPoints();
1911  int nTraceNumPoints = GetTraceTotPoints();
1912 
1913  int totbdryexp =
1914  m_fields[0]->GetBndCondExpansions()[m_boundaryforSF]->GetExpSize();
1915  int npts = m_fields[0]
1916  ->GetBndCondExpansions()[m_boundaryforSF]
1917  ->GetExp(0)
1918  ->GetNumPoints(0);
1919  int totnpts = totbdryexp * npts;
1920 
1921  Array<OneD, NekDouble> Jphi(totnpts);
1922  Array<OneD, NekDouble> Jrad(totnpts);
1923  Array<OneD, NekDouble> Jcurrent(totnpts);
1924 
1925  Array<OneD, NekDouble> phiFwd(nTraceNumPoints);
1926  Array<OneD, NekDouble> radFwd(nTraceNumPoints);
1927 
1928  // Compute phiFwd = acos(-x/r) along the trace
1929  Array<OneD, NekDouble> x(nq);
1930  Array<OneD, NekDouble> y(nq);
1931  Array<OneD, NekDouble> z(nq);
1932 
1933  m_fields[0]->GetCoords(x, y, z);
1934 
1935  Array<OneD, NekDouble> xFwd(nTraceNumPoints);
1936  Array<OneD, NekDouble> yFwd(nTraceNumPoints);
1937 
1938  m_fields[0]->ExtractTracePhys(x, xFwd);
1939  m_fields[0]->ExtractTracePhys(y, yFwd);
1940 
1941  for (int i = 0; i < nTraceNumPoints; ++i)
1942  {
1943  radFwd[i] = sqrt(xFwd[i] * xFwd[i] / m_MMFfactors[0] / m_MMFfactors[0] +
1944  yFwd[i] * yFwd[i] / m_MMFfactors[1] / m_MMFfactors[1]);
1945  phiFwd[i] = atan2(yFwd[i] / radFwd[i], -1.0 * xFwd[i] / radFwd[i]);
1946  }
1947 
1948  Array<OneD, NekDouble> ntimesHFwd(nTraceNumPoints);
1949  ntimesHFwd = ComputeSurfaceCurrent(time, fields);
1950 
1951  // The surface for current should be the first boundary
1952  int id2, cnt = 0;
1953  for (int e = 0; e < totbdryexp; ++e)
1954  {
1955  id2 = m_fields[0]->GetTrace()->GetPhys_Offset(
1956  m_fields[0]->GetTraceMap()->GetBndCondCoeffsToGlobalCoeffsMap(cnt +
1957  e));
1958 
1959  Vmath::Vcopy(npts, &phiFwd[id2], 1, &Jphi[e * npts], 1);
1960  Vmath::Vcopy(npts, &radFwd[id2], 1, &Jrad[e * npts], 1);
1961  Vmath::Vcopy(npts, &ntimesHFwd[id2], 1, &Jcurrent[e * npts], 1);
1962  }
1963 
1964  // Vmath::Vmul(totnpts, tmpr, 1, tmpr, 1, Jcurrent, 1);
1965  // Vmath::Vvtvp(totnpts, tmpi, 1, tmpi, 1, Jcurrent, 1, Jcurrent, 1);
1966  // Vmath::Vsqrt(totnpts, Jcurrent, 1, Jcurrent, 1);
1967 
1968  std::cout << "========================================================"
1969  << std::endl;
1970 
1971  std::cout << "phi = " << std::endl;
1972  for (int i = 0; i < totnpts; ++i)
1973  {
1974  std::cout << Jphi[i] << ", ";
1975  }
1976  std::cout << std::endl << std::endl;
1977 
1978  std::cout << "J = " << std::endl;
1979  for (int i = 0; i < totnpts; ++i)
1980  {
1981  std::cout << Jcurrent[i] << ", ";
1982  }
1983  std::cout << std::endl << std::endl;
1984 }
1985 
1987  const int time, const Array<OneD, const Array<OneD, NekDouble>> &fields)
1988 {
1989  int nq = m_fields[0]->GetTotPoints();
1990  int nTraceNumPoints = GetTraceTotPoints();
1991 
1992  Array<OneD, NekDouble> outfield(nTraceNumPoints, 0.0);
1993 
1994  switch (m_PolType)
1995  {
1996  // (n \times H^r)_z = H1r (n \times e^1)_z + H2r (n \times e^2)_z,
1998  {
1999  Array<OneD, NekDouble> tmp(nq);
2000  Array<OneD, NekDouble> tmpFwd(nTraceNumPoints);
2001 
2002  for (int i = 0; i < 2; i++)
2003  {
2004  tmp = GetIncidentField(i, time);
2005  Vmath::Vadd(nq, fields[i], 1, tmp, 1, tmp, 1);
2006 
2007  m_fields[0]->ExtractTracePhys(tmp, tmpFwd);
2008  Vmath::Vvtvp(nTraceNumPoints, &m_ntimesMFFwd[i][2][0], 1,
2009  &tmpFwd[0], 1, &outfield[0], 1, &outfield[0], 1);
2010  }
2011  }
2012  break;
2013 
2015  {
2016  Array<OneD, NekDouble> tmp(nq);
2017 
2018  tmp = GetIncidentField(2, time);
2019  Vmath::Vadd(nq, fields[2], 1, tmp, 1, tmp, 1);
2020  m_fields[0]->ExtractTracePhys(tmp, outfield);
2021  }
2022  break;
2023 
2024  default:
2025  break;
2026  }
2027 
2028  return outfield;
2029 }
2030 
2031 void MMFMaxwell::GenerateSigmaPML(const NekDouble PMLthickness,
2032  const NekDouble PMLstart,
2033  const NekDouble PMLmaxsigma,
2034  Array<OneD, Array<OneD, NekDouble>> &SigmaPML)
2035 {
2036  int nq = m_fields[0]->GetNpoints();
2037 
2038  // Construct sigmaX and sigmaY for UPML
2039  Array<OneD, NekDouble> x(nq);
2040  Array<OneD, NekDouble> y(nq);
2041  Array<OneD, NekDouble> z(nq);
2042 
2043  m_fields[0]->GetCoords(x, y, z);
2044 
2045  // Construction of SigmaPML
2047  for (int j = 0; j < m_shapedim; j++)
2048  {
2049  SigmaPML[j] = Array<OneD, NekDouble>(nq, 0.0);
2050  }
2051 
2052  // PML region indicator: [ 0 : curvedPML : RecPML]
2053  // RecPML = [0 : 0 : 1]
2054  // PMLRegion = [0 : 1 : 1], CurvedPML = PMLRegion - RecPML = [0: 1: 0]
2055  Array<OneD, NekDouble> RecPML(nq);
2056  Array<OneD, NekDouble> CurvedPML(nq);
2057  Array<OneD, NekDouble> PMLRegion(nq);
2058  m_fields[0]->GenerateElementVector(m_RecPML, 0.0, 1.0, RecPML);
2059  m_fields[0]->GenerateElementVector(m_PMLelement, 0.0, 1.0, PMLRegion);
2060  Vmath::Vsub(nq, PMLRegion, 1, RecPML, 1, CurvedPML, 1);
2061 
2062  switch (m_AddPML)
2063  {
2064  // RecPML only
2065  case 1:
2066  {
2067  // Rectangular PML
2068  NekDouble xRlayer, xLlayer, yRlayer, yLlayer;
2069 
2070  xRlayer = Vmath::Vmax(nq, x, 1) - PMLthickness;
2071  xLlayer = Vmath::Vmin(nq, x, 1) + PMLthickness;
2072  yRlayer = Vmath::Vmax(nq, y, 1) - PMLthickness;
2073  yLlayer = Vmath::Vmin(nq, y, 1) + PMLthickness;
2074 
2075  NekDouble xd, yd;
2076  for (int i = 0; i < nq; i++)
2077  {
2078  // SimgaPML along e^1
2079  if (x[i] >= xRlayer)
2080  {
2081  xd = (x[i] - xRlayer) / PMLthickness;
2082  }
2083 
2084  else if (x[i] <= xLlayer)
2085  {
2086  xd = (xLlayer - x[i]) / PMLthickness;
2087  }
2088 
2089  else
2090  {
2091  xd = 0.0;
2092  }
2093 
2094  SigmaPML[0][i] = RecPML[i] * PMLmaxsigma * (xd * xd * xd);
2095 
2096  // SigmaPML along e^2
2097  if (y[i] >= yRlayer)
2098  {
2099  yd = (y[i] - yRlayer) / PMLthickness;
2100  }
2101 
2102  else if (y[i] <= yLlayer)
2103  {
2104  yd = (yLlayer - y[i]) / PMLthickness;
2105  }
2106 
2107  else
2108  {
2109  yd = 0.0;
2110  }
2111 
2112  SigmaPML[1][i] = PMLRegion[i] * PMLmaxsigma * (yd * yd * yd);
2113  }
2114  }
2115  break;
2116 
2117  // CurvedPML only
2118  case 2:
2119  {
2120  // Curved PML
2121  NekDouble relrad, rad;
2122  for (int i = 0; i < nq; i++)
2123  {
2124  rad = sqrt(x[i] * x[i] / m_MMFfactors[0] / m_MMFfactors[0] +
2125  y[i] * y[i] / m_MMFfactors[1] / m_MMFfactors[1]);
2126 
2127  if (rad >= PMLstart)
2128  {
2129  relrad = (rad - PMLstart) / PMLthickness;
2130  SigmaPML[1][i] =
2131  PMLRegion[i] * PMLmaxsigma * pow(relrad, m_PMLorder);
2132  }
2133  }
2134  }
2135  break;
2136 
2137  // Slanted PML
2138  case 3:
2139  {
2140  NekDouble relrad, radon, radtw, radth, radfo;
2141  for (int i = 0; i < nq; i++)
2142  {
2143  radon = -1.0 * x[i] + y[i] - 7;
2144  radtw = x[i] + y[i] - 7;
2145  radth = -x[i] - y[i] - 7;
2146  radfo = x[i] - y[i] - 7;
2147 
2148  if (radon >= 0.0)
2149  {
2150  relrad = radon / PMLthickness;
2151  SigmaPML[1][i] =
2152  PMLRegion[i] * PMLmaxsigma * pow(relrad, m_PMLorder);
2153  }
2154 
2155  if (radtw >= 0.0)
2156  {
2157  relrad = radtw / PMLthickness;
2158  SigmaPML[0][i] =
2159  PMLRegion[i] * PMLmaxsigma * pow(relrad, m_PMLorder);
2160  }
2161 
2162  if (radth >= 0.0)
2163  {
2164  relrad = radth / PMLthickness;
2165  SigmaPML[0][i] =
2166  PMLRegion[i] * PMLmaxsigma * pow(relrad, m_PMLorder);
2167  }
2168 
2169  if (radfo >= 0.0)
2170  {
2171  relrad = radfo / PMLthickness;
2172  SigmaPML[1][i] =
2173  PMLRegion[i] * PMLmaxsigma * pow(relrad, m_PMLorder);
2174  }
2175  }
2176  }
2177  break;
2178  }
2179 
2180  std::cout << "*** sigma1 = [ " << Vmath::Vmin(nq, &SigmaPML[0][0], 1)
2181  << " , " << Vmath::Vmax(nq, &SigmaPML[0][0], 1)
2182  << " ] , sigma2 = [ " << Vmath::Vmin(nq, &SigmaPML[1][0], 1)
2183  << " , " << Vmath::Vmax(nq, &SigmaPML[1][0], 1) << " ] "
2184  << std::endl;
2185 }
2186 
2188  Array<OneD, Array<OneD, NekDouble>> &fields)
2189 {
2190  int nq = GetTotPoints();
2191  NekDouble energy;
2192 
2193  Array<OneD, NekDouble> tmp(nq, 0.0);
2194 
2195  for (int i = 0; i < 3; ++i)
2196  {
2197  Vmath::Vvtvp(nq, &fields[i][0], 1, &fields[i][0], 1, &tmp[0], 1,
2198  &tmp[0], 1);
2199  }
2200 
2201  energy = 0.5 * (m_fields[0]->PhysIntegral(tmp));
2202  return energy;
2203 }
2204 
2206  Array<OneD, Array<OneD, NekDouble>> &epsvec,
2208 {
2209  switch (m_TestMaxwellType)
2210  {
2212  {
2213  m_fields[0]->GenerateElementVector(m_ElemtGroup1, m_varepsilon[0],
2214  m_varepsilon[1], epsvec[0]);
2215  m_fields[0]->GenerateElementVector(m_ElemtGroup1, 1.0, 1.0,
2216  muvec[0]);
2217  }
2218  break;
2219 
2225  {
2226  switch (m_PolType)
2227  {
2229  {
2230  m_fields[0]->GenerateElementVector(m_ElemtGroup1, m_mu[0],
2231  1.0, muvec[0]);
2232  m_fields[0]->GenerateElementVector(m_ElemtGroup1, m_mu[1],
2233  1.0, muvec[1]);
2234  m_fields[0]->GenerateElementVector(
2235  m_ElemtGroup1, m_varepsilon[2], 1.0, epsvec[2]);
2236 
2237  // // ONLY FOR VARIABLE ANISOTROPY TEST
2238  // int nq = GetTotPoints();
2239 
2240  // Array<OneD, NekDouble> tmpIN(nq);
2241 
2242  // m_fields[0]->GenerateElementVector(m_ElemtGroup1, 1.0,
2243  // 0.0, tmpIN);
2244 
2245  // Array<OneD, NekDouble> x0(nq);
2246  // Array<OneD, NekDouble> x1(nq);
2247  // Array<OneD, NekDouble> x2(nq);
2248 
2249  // m_fields[0]->GetCoords(x0,x1,x2);
2250 
2251  // for (int i=0; i<nq; i++)
2252  // {
2253  // muvec[1][i] = tmpIN[i]*(1.0 - 2*x0[i]*x0[i]) +
2254  // (1.0-tmpIN[i]);
2255  // }
2256  }
2257  break;
2258 
2260  {
2261  m_fields[0]->GenerateElementVector(
2262  m_ElemtGroup1, m_varepsilon[0], 1.0, epsvec[0]);
2263  m_fields[0]->GenerateElementVector(
2264  m_ElemtGroup1, m_varepsilon[1], 1.0, epsvec[1]);
2265  m_fields[0]->GenerateElementVector(m_ElemtGroup1, m_mu[2],
2266  1.0, muvec[2]);
2267 
2268  // // ONLY FOR VARIABLE ANISOTROPY TEST
2269  // int nq = GetTotPoints();
2270 
2271  // Array<OneD, NekDouble> tmpIN(nq);
2272 
2273  // m_fields[0]->GenerateElementVector(m_ElemtGroup1, 1.0,
2274  // 0.0, tmpIN);
2275 
2276  // Array<OneD, NekDouble> x0(nq);
2277  // Array<OneD, NekDouble> x1(nq);
2278  // Array<OneD, NekDouble> x2(nq);
2279 
2280  // m_fields[0]->GetCoords(x0,x1,x2);
2281 
2282  // for (int i=0; i<nq; i++)
2283  // {
2284  // epsvec[1][i] = tmpIN[i]*(1.0 - 2*x0[i]*x0[i]) +
2285  // (1.0-tmpIN[i]);
2286  // }
2287  }
2288  break;
2289 
2290  default:
2291  break; // Pol
2292  }
2293  }
2294 
2295  default:
2296  break; // TestType
2297  }
2298 }
2299 
2301  const Array<OneD, const NekDouble> &radvec,
2302  Array<OneD, Array<OneD, NekDouble>> &epsvec,
2303  Array<OneD, Array<OneD, NekDouble>> &muvec, const bool Dispersion)
2304 {
2305  boost::ignore_unused(muvec, Dispersion);
2306 
2307  int nq = GetNpoints();
2308 
2309  // Cloaking metamaterial
2310  // \varepsilon_\theta = (b/(b-a))^2
2311  // \varepsilon_r = (b/(b-a))^2 ((r-a)/r)^2
2312  // \mu_z = 1.0m_CloakingOn
2313 
2314  NekDouble m_b = 1.0 / 0.314;
2315  NekDouble m_a = 1.0;
2316 
2317  NekDouble m_adel = m_a - m_Cloakraddelta;
2318 
2319  NekDouble boveradel = m_b / (m_b - m_adel);
2320 
2321  Array<OneD, NekDouble> Cloakregion(nq, 0.0);
2322 
2323  NekDouble la = m_MMFfactors[0];
2324  NekDouble lb = m_MMFfactors[1];
2325 
2326  NekDouble ExactCloakArea;
2327  if (fabs(la * lb - 1.0) < 0.00001)
2328  {
2329  ExactCloakArea = m_pi * (m_b * m_b - m_a * m_a);
2330  }
2331 
2332  else
2333  {
2334  ExactCloakArea = m_pi * (3.0 * lb * 3.0 * la - lb * la);
2335  }
2336 
2337  m_fields[0]->GenerateElementVector(m_ElemtGroup1, 1.0, 0.0, Cloakregion);
2338 
2339  ExactCloakArea = ExactCloakArea - (m_fields[0]->PhysIntegral(Cloakregion));
2340  std::cout << "*** Error of Cloakregion area = " << ExactCloakArea
2341  << std::endl;
2342 
2343  NekDouble ratio;
2344 
2345  epsvec[0] = Array<OneD, NekDouble>(nq, 1.0);
2346  epsvec[1] = Array<OneD, NekDouble>(nq, 1.0);
2347  m_wp2 = Array<OneD, NekDouble>(nq, 0.0);
2348  for (int i = 0; i < nq; ++i)
2349  {
2350  if (Cloakregion[i] > 0)
2351  {
2352  // relrad = m_a +
2353  // (m_b-m_adel)*(radvec[i]-m_adel)/(Cloakradmax-m_adel);
2354  ratio = (radvec[i] - m_adel) / radvec[i];
2355 
2356  epsvec[0][i] = boveradel * boveradel;
2357  if (m_DispersiveCloak)
2358  {
2359  epsvec[1][i] = 1.0;
2360  m_wp2[i] = m_Incfreq * m_Incfreq *
2361  (1.0 - boveradel * boveradel * ratio * ratio) +
2362  m_wp2Tol;
2363  }
2364 
2365  else
2366  {
2367  epsvec[1][i] = boveradel * boveradel * (ratio * ratio);
2368  }
2369  }
2370  }
2371 }
2372 
2374  const Array<OneD, const NekDouble> &radvec,
2375  Array<OneD, Array<OneD, NekDouble>> &epsvec,
2377 {
2378  int nq = GetNpoints();
2379 
2380  NekDouble m_b = 2.67;
2381  NekDouble m_a = 1.33;
2382  NekDouble m_adel;
2383 
2384  m_adel = m_a - m_Cloakraddelta;
2385 
2386  Array<OneD, NekDouble> Cloakregion(nq, 0.0);
2387  NekDouble ExactCloakArea = m_pi * (m_b * m_b - m_a * m_a);
2388  m_fields[0]->GenerateElementVector(m_ElemtGroup1, 1.0, 0.0, Cloakregion);
2389 
2390  if (m_ElemtGroup0 > 0)
2391  {
2392  Array<OneD, NekDouble> Vacregion(nq, 0.0);
2393  m_fields[0]->GenerateElementVector(m_ElemtGroup0, 1.0, 0.0, Vacregion);
2394 
2395  Vmath::Vsub(nq, Cloakregion, 1, Vacregion, 1, Cloakregion, 1);
2396  }
2397 
2398  ExactCloakArea = ExactCloakArea - (m_fields[0]->PhysIntegral(Cloakregion));
2399  std::cout << "*** Error of Cloakregion area = " << ExactCloakArea
2400  << std::endl;
2401 
2402  epsvec[0] = Array<OneD, NekDouble>(nq, 1.0);
2403  epsvec[1] = Array<OneD, NekDouble>(nq, 1.0);
2404 
2405  muvec[0] = Array<OneD, NekDouble>(nq, 1.0);
2406  muvec[1] = Array<OneD, NekDouble>(nq, 1.0);
2407  for (int i = 0; i < nq; ++i)
2408  {
2409  if (Cloakregion[i] > 0)
2410  {
2411  // relrad = m_a +
2412  // (m_b-m_a)*(radvec[i]-Cloakradmin)/(Cloakradmax-Cloakradmin);
2413  // ratio = (relrad - m_a + m_Cloakraddelta)/relrad;
2414 
2415  epsvec[0][i] = radvec[i] / (radvec[i] - m_adel);
2416  epsvec[1][i] = (radvec[i] - m_adel) / radvec[i];
2417  muvec[2][i] = (m_b / (m_b - m_adel)) * (m_b / (m_b - m_adel)) *
2418  (radvec[i] - m_adel) / radvec[i];
2419 
2420  muvec[0][i] = epsvec[0][i];
2421  muvec[1][i] = epsvec[1][i];
2422  epsvec[2][i] = muvec[2][i];
2423  }
2424  }
2425 }
2426 
2428  const Array<OneD, const Array<OneD, NekDouble>> &physarray,
2429  Array<OneD, Array<OneD, NekDouble>> &outarray)
2430 {
2431  int nq = m_fields[0]->GetTotPoints();
2432  Array<OneD, NekDouble> tmp(nq);
2433 
2434  Array<OneD, NekDouble> Sigma0plus1Neg(nq);
2435  Array<OneD, NekDouble> Sigma0minus1(nq);
2436  Array<OneD, NekDouble> Sigma1minus0(nq);
2437 
2438  Vmath::Vsub(nq, &m_SigmaPML[1][0], 1, &m_SigmaPML[0][0], 1,
2439  &Sigma1minus0[0], 1);
2440  Vmath::Vsub(nq, &m_SigmaPML[0][0], 1, &m_SigmaPML[1][0], 1,
2441  &Sigma0minus1[0], 1);
2442  Vmath::Vadd(nq, &m_SigmaPML[0][0], 1, &m_SigmaPML[1][0], 1,
2443  &Sigma0plus1Neg[0], 1);
2444  Vmath::Neg(nq, Sigma0plus1Neg, 1);
2445 
2446  switch (m_PolType)
2447  {
2449  {
2450  int indxH0 = 0;
2451  int indxH1 = 1;
2452  int indxE2 = 2;
2453  int indxQ0 = 3;
2454  int indxQ1 = 4;
2455  int indxP2 = 5;
2456 
2457  // dH0/dt: Add (sigma_0 - \sigma_1) H0 + Q0
2458  Vmath::Vvtvp(nq, &Sigma0minus1[0], 1, &physarray[indxH0][0], 1,
2459  &outarray[indxH0][0], 1, &outarray[indxH0][0], 1);
2460  Vmath::Vadd(nq, &physarray[indxQ0][0], 1, &outarray[indxH0][0], 1,
2461  &outarray[indxH0][0], 1);
2462 
2463  // dH1/dt: Add (sigma_1 - \sigma_0) H1 + Q1
2464  Vmath::Vvtvp(nq, &Sigma1minus0[0], 1, &physarray[indxH1][0], 1,
2465  &outarray[indxH1][0], 1, &outarray[indxH1][0], 1);
2466  Vmath::Vadd(nq, &physarray[indxQ1][0], 1, &outarray[indxH1][0], 1,
2467  &outarray[indxH1][0], 1);
2468 
2469  // dHz/dt: Add -(\sigma_0 + \sigma_1) Ez + Pz
2470  Vmath::Vvtvp(nq, &Sigma0plus1Neg[0], 1, &physarray[indxE2][0], 1,
2471  &outarray[indxE2][0], 1, &outarray[indxE2][0], 1);
2472  Vmath::Vadd(nq, &physarray[indxP2][0], 1, &outarray[indxE2][0], 1,
2473  &outarray[indxE2][0], 1);
2474 
2475  // dQ0/dt: Assign -\sigma_0 * ( Q0 + (\sigma_0 - \sigma_1) * H0 )
2476  Vmath::Vvtvp(nq, &Sigma0minus1[0], 1, &physarray[indxH0][0], 1,
2477  &physarray[indxQ0][0], 1, &outarray[indxQ0][0], 1);
2478  Vmath::Vmul(nq, &m_SigmaPML[0][0], 1, &outarray[indxQ0][0], 1,
2479  &outarray[indxQ0][0], 1);
2480  Vmath::Neg(nq, &outarray[indxQ0][0], 1);
2481 
2482  // dQ1/dt: Assign -\sigma_1 * ( Q1 + (\sigma_1 - \sigma_0) * H1 )
2483  Vmath::Vvtvp(nq, &Sigma1minus0[0], 1, &physarray[indxH1][0], 1,
2484  &physarray[indxQ1][0], 1, &outarray[indxQ1][0], 1);
2485  Vmath::Vmul(nq, &m_SigmaPML[1][0], 1, &outarray[indxQ1][0], 1,
2486  &outarray[indxQ1][0], 1);
2487  Vmath::Neg(nq, &outarray[indxQ1][0], 1);
2488 
2489  if (m_DispersiveCloak)
2490  {
2491  Vmath::Vvtvp(nq, &m_wp2[0], 1, &physarray[indxH1][0], 1,
2492  &outarray[indxQ1][0], 1, &outarray[indxQ1][0], 1);
2493  }
2494 
2495  // dP3/dt: Assign - \sigma_1 * \sigma_2 * E_z
2496  Vmath::Vmul(nq, &m_SigmaPML[0][0], 1, &m_SigmaPML[1][0], 1,
2497  &outarray[indxP2][0], 1);
2498  Vmath::Vmul(nq, &physarray[indxE2][0], 1, &outarray[indxP2][0], 1,
2499  &outarray[indxP2][0], 1);
2500  Vmath::Neg(nq, &outarray[indxP2][0], 1);
2501  }
2502  break;
2503 
2505  {
2506  int indxE0 = 0;
2507  int indxE1 = 1;
2508  int indxH2 = 2;
2509  int indxQ0 = 3;
2510  int indxQ1 = 4;
2511  int indxP2 = 5;
2512 
2513  // dE0/dt: Add (sigma_0 - \sigma_1) E0 - Q0
2514  Vmath::Vvtvp(nq, &Sigma0minus1[0], 1, &physarray[indxE0][0], 1,
2515  &outarray[indxE0][0], 1, &outarray[indxE0][0], 1);
2516  Vmath::Vsub(nq, &outarray[indxE0][0], 1, &physarray[indxQ0][0], 1,
2517  &outarray[indxE0][0], 1);
2518 
2519  // dE1/dt: Add (sigma_1 - \sigma_0) E1 - Q1
2520  Vmath::Vvtvp(nq, &Sigma1minus0[0], 1, &physarray[indxE1][0], 1,
2521  &outarray[indxE1][0], 1, &outarray[indxE1][0], 1);
2522  Vmath::Vsub(nq, &outarray[indxE1][0], 1, &physarray[indxQ1][0], 1,
2523  &outarray[indxE1][0], 1);
2524 
2525  // dHz/dt: Add -(\sigma_0 + \sigma_1) Hz - Pz
2526  Vmath::Vvtvp(nq, &Sigma0plus1Neg[0], 1, &physarray[indxH2][0], 1,
2527  &outarray[indxH2][0], 1, &outarray[indxH2][0], 1);
2528  Vmath::Vsub(nq, &outarray[indxH2][0], 1, &physarray[indxP2][0], 1,
2529  &outarray[indxH2][0], 1);
2530 
2531  // dQ0/dt: Assign -\sigma_0 * ( Q0 + (\sigma_1 - \sigma_0) * E0 )
2532  Vmath::Vvtvp(nq, &Sigma1minus0[0], 1, &physarray[indxE0][0], 1,
2533  &physarray[indxQ0][0], 1, &outarray[indxQ0][0], 1);
2534  Vmath::Vmul(nq, &m_SigmaPML[0][0], 1, &outarray[indxQ0][0], 1,
2535  &outarray[indxQ0][0], 1);
2536  Vmath::Neg(nq, &outarray[indxQ0][0], 1);
2537 
2538  // dQ1/dt: Assign -\sigma_1 * ( Q1 + (\sigma_0 - \sigma_1) * E1 )
2539  Vmath::Vvtvp(nq, &Sigma0minus1[0], 1, &physarray[indxE1][0], 1,
2540  &physarray[indxQ1][0], 1, &outarray[indxQ1][0], 1);
2541  Vmath::Vmul(nq, &m_SigmaPML[1][0], 1, &outarray[indxQ1][0], 1,
2542  &outarray[indxQ1][0], 1);
2543  Vmath::Neg(nq, &outarray[indxQ1][0], 1);
2544 
2545  if (m_DispersiveCloak)
2546  {
2547  Vmath::Vvtvp(nq, &m_wp2[0], 1, &physarray[indxE1][0], 1,
2548  &outarray[indxQ1][0], 1, &outarray[indxQ1][0], 1);
2549  }
2550 
2551  // dP3/dt: Assign \sigma_1 * \sigma_2 * H_z
2552  Vmath::Vmul(nq, &m_SigmaPML[0][0], 1, &m_SigmaPML[1][0], 1,
2553  &outarray[indxP2][0], 1);
2554  Vmath::Vmul(nq, &physarray[indxH2][0], 1, &outarray[indxP2][0], 1,
2555  &outarray[indxP2][0], 1);
2556  }
2557  break;
2558 
2559  default:
2560  break;
2561  }
2562 }
2563 
2565  const int n, const NekDouble time,
2566  const Array<OneD, const Array<OneD, NekDouble>> &fieldphys)
2567 {
2568  int nvar = m_fields.num_elements();
2569  int nq = m_fields[0]->GetTotPoints();
2570  int ncoeffs = m_fields[0]->GetNcoeffs();
2571 
2572  std::string outname =
2573  m_sessionName + "Tot_" + boost::lexical_cast<std::string>(n) + ".chk";
2574 
2575  std::vector<std::string> variables(nvar);
2576  std::vector<Array<OneD, NekDouble>> fieldcoeffs(nvar);
2577 
2578  for (int i = 0; i < nvar; ++i)
2579  {
2580  fieldcoeffs[i] = Array<OneD, NekDouble>(ncoeffs);
2581  }
2582 
2583  Array<OneD, NekDouble> totfield(nq);
2584  for (int i = 0; i < nvar; ++i)
2585  {
2586  totfield = GetIncidentField(i, time);
2587  Vmath::Vadd(nq, fieldphys[i], 1, totfield, 1, totfield, 1);
2588 
2589  m_fields[i]->FwdTrans(totfield, fieldcoeffs[i]);
2590  variables[i] = m_boundaryConditions->GetVariable(i);
2591  }
2592 
2593  WriteFld(outname, m_fields[0], fieldcoeffs, variables);
2594 }
2595 
2596 // Only for nvar = 3
2598  const int n, const Array<OneD, const Array<OneD, NekDouble>> &fieldphys)
2599 {
2600  int nvar = m_fields.num_elements();
2601  int nq = m_fields[0]->GetTotPoints();
2602  int ncoeffs = m_fields[0]->GetNcoeffs();
2603 
2604  std::string outname =
2605  m_sessionName + "Plot_" + boost::lexical_cast<std::string>(n) + ".chk";
2606 
2607  std::vector<std::string> variables(nvar);
2608  variables[0] = "Fx";
2609  variables[1] = "Fy";
2610  variables[2] = "Fz";
2611 
2612  std::vector<Array<OneD, NekDouble>> fieldcoeffs(nvar);
2613  for (int i = 0; i < nvar; ++i)
2614  {
2615  fieldcoeffs[i] = Array<OneD, NekDouble>(ncoeffs);
2616  }
2617 
2618  Array<OneD, NekDouble> tmp(nq);
2619  for (int k = 0; k < m_spacedim; ++k)
2620  {
2621  Vmath::Vmul(nq, &fieldphys[0][0], 1, &m_movingframes[0][k * nq], 1,
2622  &tmp[0], 1);
2623  Vmath::Vvtvp(nq, &fieldphys[1][0], 1, &m_movingframes[1][k * nq], 1,
2624  &tmp[0], 1, &tmp[0], 1);
2625 
2626  m_fields[k]->FwdTrans(tmp, fieldcoeffs[k]);
2627  }
2628 
2629  WriteFld(outname, m_fields[0], fieldcoeffs, variables);
2630 }
2631 
2633  const int n, const NekDouble time,
2634  const Array<OneD, const Array<OneD, NekDouble>> &fieldphys)
2635 {
2636  int nvar = m_fields.num_elements();
2637  int nq = m_fields[0]->GetTotPoints();
2638  int ncoeffs = m_fields[0]->GetNcoeffs();
2639 
2640  std::string outname = m_sessionName + "TotPlot_" +
2641  boost::lexical_cast<std::string>(n) + ".chk";
2642 
2643  std::vector<std::string> variables(nvar);
2644  variables[0] = "Frx";
2645  variables[1] = "Fry";
2646  variables[2] = "Frz";
2647  for (int i = 3; i < nvar; ++i)
2648  {
2649  variables[i] = m_boundaryConditions->GetVariable(i);
2650  }
2651 
2652  std::vector<Array<OneD, NekDouble>> fieldcoeffs(nvar);
2653  for (int i = 0; i < nvar; ++i)
2654  {
2655  fieldcoeffs[i] = Array<OneD, NekDouble>(ncoeffs);
2656  }
2657 
2658  Array<OneD, NekDouble> tmp(nq);
2659  Array<OneD, NekDouble> totfield0(nq);
2660  Array<OneD, NekDouble> totfield1(nq);
2661 
2662  totfield0 = GetIncidentField(0, time);
2663  Vmath::Vadd(nq, fieldphys[0], 1, totfield0, 1, totfield0, 1);
2664 
2665  totfield1 = GetIncidentField(1, time);
2666  Vmath::Vadd(nq, fieldphys[1], 1, totfield1, 1, totfield1, 1);
2667 
2668  for (int k = 0; k < m_spacedim; ++k)
2669  {
2670  Vmath::Vmul(nq, &totfield0[0], 1, &m_movingframes[0][k * nq], 1,
2671  &tmp[0], 1);
2672  Vmath::Vvtvp(nq, &totfield1[0], 1, &m_movingframes[1][k * nq], 1,
2673  &tmp[0], 1, &tmp[0], 1);
2674 
2675  m_fields[k]->FwdTrans(tmp, fieldcoeffs[k]);
2676  }
2677 
2678  for (int j = 3; j < nvar; ++j)
2679  {
2680  m_fields[j]->FwdTrans(fieldphys[j], fieldcoeffs[j]);
2681  }
2682 
2683  WriteFld(outname, m_fields[0], fieldcoeffs, variables);
2684 }
2685 
2687  const int n, const NekDouble time,
2688  const Array<OneD, const Array<OneD, NekDouble>> &fieldphys)
2689 {
2690  boost::ignore_unused(time);
2691 
2692  int nvar = m_fields.num_elements();
2693  int nq = m_fields[0]->GetTotPoints();
2694  int ncoeffs = m_fields[0]->GetNcoeffs();
2695 
2696  std::string outname = m_sessionName + "EDFlux_" +
2697  boost::lexical_cast<std::string>(n) + ".chk";
2698 
2699  std::vector<std::string> variables(nvar);
2700  variables[0] = "EDFx";
2701  variables[1] = "EDFy";
2702  variables[2] = "EDFz";
2703  for (int i = 3; i < nvar; ++i)
2704  {
2705  variables[i] = m_boundaryConditions->GetVariable(i);
2706  }
2707 
2708  std::vector<Array<OneD, NekDouble>> fieldcoeffs(nvar);
2709  for (int i = 0; i < nvar; ++i)
2710  {
2711  fieldcoeffs[i] = Array<OneD, NekDouble>(ncoeffs);
2712  }
2713 
2714  Array<OneD, NekDouble> tmp(nq);
2715 
2716  // TE: H^3 (E^2 e^1 - E^1 e^2 )
2717  // TM: -E^3 (H^2 e^1 - H^1 e^2 )
2718  for (int k = 0; k < m_spacedim; ++k)
2719  {
2720  Vmath::Vmul(nq, &fieldphys[0][0], 1, &m_movingframes[1][k * nq], 1,
2721  &tmp[0], 1);
2722  Vmath::Vvtvm(nq, &fieldphys[1][0], 1, &m_movingframes[0][k * nq], 1,
2723  &tmp[0], 1, &tmp[0], 1);
2724 
2725  Vmath::Vmul(nq, &fieldphys[2][0], 1, &tmp[0], 1, &tmp[0], 1);
2726 
2728  {
2729  Vmath::Neg(nq, tmp, 1);
2730  }
2731 
2732  m_fields[k]->FwdTrans(tmp, fieldcoeffs[k]);
2733  }
2734 
2735  WriteFld(outname, m_fields[0], fieldcoeffs, variables);
2736 }
2737 
2739  const int n, const NekDouble time,
2740  const Array<OneD, const Array<OneD, NekDouble>> &fieldphys)
2741 {
2742  boost::ignore_unused(time);
2743 
2744  int nvar = m_fields.num_elements();
2745  int nq = m_fields[0]->GetTotPoints();
2746  int ncoeffs = m_fields[0]->GetNcoeffs();
2747 
2748  std::string outname = m_sessionName + "Energy_" +
2749  boost::lexical_cast<std::string>(n) + ".chk";
2750 
2751  std::vector<std::string> variables(nvar);
2752  variables[0] = "Energy";
2753  variables[1] = "EnergyFlux";
2754  variables[2] = "Zero";
2755  for (int i = 3; i < nvar; ++i)
2756  {
2757  variables[i] = m_boundaryConditions->GetVariable(i);
2758  }
2759 
2760  std::vector<Array<OneD, NekDouble>> fieldcoeffs(nvar);
2761  for (int i = 0; i < nvar; ++i)
2762  {
2763  fieldcoeffs[i] = Array<OneD, NekDouble>(ncoeffs);
2764  }
2765 
2766  // Energy = 0.5 * ( E^2 + H^2 )
2767  Array<OneD, NekDouble> energy(nq, 0.0);
2768  Array<OneD, NekDouble> totfield(nq);
2769  for (int k = 0; k < m_spacedim; ++k)
2770  {
2771  // totfield = GetIncidentField(k,time);
2772  // Vmath::Vadd(nq, &fieldphys[k][0], 1, &totfield[0], 1, &totfield[0],
2773  // 1);
2774 
2775  Vmath::Vvtvp(nq, &fieldphys[k][0], 1, &fieldphys[k][0], 1, &energy[0],
2776  1, &energy[0], 1);
2777  }
2778  Vmath::Smul(nq, 0.5, energy, 1, energy, 1);
2779  m_fields[0]->FwdTrans(energy, fieldcoeffs[0]);
2780 
2781  // EnergyFlux = F3* sqrt( F1^2 + F2^2 )
2782  Array<OneD, NekDouble> energyflux(nq, 0.0);
2783  Array<OneD, NekDouble> Zero(nq, 0.0);
2784  for (int k = 0; k < 2; ++k)
2785  {
2786  // totfield = GetIncidentField(k,time);
2787  // Vmath::Vadd(nq, &fieldphys[k][0], 1, &totfield[0], 1, &totfield[0],
2788  // 1);
2789 
2790  Vmath::Vvtvp(nq, &fieldphys[k][0], 1, &fieldphys[k][0], 1,
2791  &energyflux[0], 1, &energyflux[0], 1);
2792  }
2793 
2794  Vmath::Vsqrt(nq, energyflux, 1, energyflux, 1);
2795  Vmath::Vmul(nq, &fieldphys[2][0], 1, &energyflux[0], 1, &energyflux[0], 1);
2796 
2797  m_fields[1]->FwdTrans(energyflux, fieldcoeffs[1]);
2798  m_fields[2]->FwdTrans(Zero, fieldcoeffs[2]);
2799 
2800  WriteFld(outname, m_fields[0], fieldcoeffs, variables);
2801 }
2802 
2804  const NekDouble Psx,
2805  const NekDouble Psy,
2806  const NekDouble Psz,
2807  const NekDouble Gaussianradius)
2808 {
2809  int nq = m_fields[0]->GetTotPoints();
2810  int ncoeffs = m_fields[0]->GetNcoeffs();
2811 
2812  Array<OneD, NekDouble> x(nq);
2813  Array<OneD, NekDouble> y(nq);
2814  Array<OneD, NekDouble> z(nq);
2815 
2816  m_fields[0]->GetCoords(x, y, z);
2817 
2818  Array<OneD, NekDouble> outarray(nq, 0.0);
2819  Array<OneD, NekDouble> tmpc(ncoeffs);
2820  NekDouble rad;
2821 
2822  NekDouble SFradius = m_PSduration * 0.1;
2823  NekDouble SmoothFactor =
2824  1.0 / (1.0 + exp(-0.5 * (time - m_PSduration) / SFradius));
2825 
2826  for (int j = 0; j < nq; ++j)
2827  {
2828  rad = sqrt((x[j] - Psx) * (x[j] - Psx) + (y[j] - Psy) * (y[j] - Psy) +
2829  (z[j] - Psz) * (z[j] - Psz));
2830  outarray[j] = SmoothFactor * exp(-1.0 * (rad / Gaussianradius) *
2831  (rad / Gaussianradius));
2832  }
2833 
2834  m_fields[0]->FwdTrans_IterPerExp(outarray, tmpc);
2835  m_fields[0]->BwdTrans(tmpc, outarray);
2836 
2837  return outarray;
2838 }
2839 
2841 {
2842  int nq = GetTotPoints();
2843 
2844  NekDouble m_Omega = 1.5486 * 0.000001;
2845 
2846  NekDouble x0j, x1j, x2j;
2847  NekDouble sin_theta, cos_theta, sin_varphi, cos_varphi;
2848 
2849  Array<OneD, NekDouble> x(nq);
2850  Array<OneD, NekDouble> y(nq);
2851  Array<OneD, NekDouble> z(nq);
2852 
2853  m_fields[0]->GetCoords(x, y, z);
2854 
2855  Array<OneD, NekDouble> outarray(nq, 0.0);
2856  for (int j = 0; j < nq; ++j)
2857  {
2858  x0j = x[j];
2859  x1j = y[j];
2860  x2j = z[j];
2861 
2862  CartesianToSpherical(x0j, x1j, x2j, sin_varphi, cos_varphi, sin_theta,
2863  cos_theta);
2864 
2865  outarray[j] = 2.0 * m_Omega * sin_theta;
2866  }
2867 
2868  return outarray;
2869 }
2870 
2872  Array<OneD, Array<OneD, NekDouble>> &outarray)
2873 {
2874  int nq = physarray[0].num_elements();
2875 
2876  Array<OneD, NekDouble> tmp(nq);
2877 
2878  int indx;
2879  for (int j = 0; j < m_shapedim; ++j)
2880  {
2881  if (j == 0)
2882  {
2883  indx = 2;
2884  }
2885 
2886  else if (j == 1)
2887  {
2888  indx = 1;
2889  }
2890 
2891  Vmath::Vmul(nq, m_coriolis, 1, physarray[indx], 1, tmp, 1);
2892 
2893  switch (m_PolType)
2894  {
2896  {
2897  Vmath::Vmul(nq, m_muvec[indx], 1, tmp, 1, tmp, 1);
2898  }
2899  break;
2900 
2902  {
2903  Vmath::Vmul(nq, m_epsvec[indx], 1, tmp, 1, tmp, 1);
2904  }
2905  break;
2906 
2907  default:
2908  break;
2909  }
2910 
2911  if (j == 1)
2912  {
2913  Vmath::Neg(nq, tmp, 1);
2914  }
2915 
2916  Vmath::Vadd(nq, tmp, 1, outarray[j], 1, outarray[j], 1);
2917  }
2918 }
2919 
2921 {
2922  int nq = GetNpoints();
2923 
2924  NekDouble m_b = 1.0 / 0.314;
2925  NekDouble m_a = 1.0;
2926 
2927  Array<OneD, int> Layer(CloakNlayer);
2928 
2929  NekDouble la = m_MMFfactors[0];
2930  NekDouble lb = m_MMFfactors[1];
2931  if (CloakNlayer == 8)
2932  {
2933  // Circular 8 layer
2934  if (fabs(la * lb - 1.0) < 0.0001)
2935  {
2936  Layer[0] = 119;
2937  Layer[1] = 239;
2938  Layer[2] = 323;
2939  Layer[3] = 459;
2940  Layer[4] = 575;
2941  Layer[5] = 727;
2942  Layer[6] = 891;
2943  Layer[7] = 1059;
2944  }
2945 
2946  // Ellipsoid 8 layer
2947  else
2948  {
2949  Layer[0] = 115;
2950  Layer[1] = 219;
2951  Layer[2] = 335;
2952  Layer[3] = 459;
2953  Layer[4] = 607;
2954  Layer[5] = 767;
2955  Layer[6] = 951;
2956  Layer[7] = 1155;
2957  }
2958  }
2959 
2960  if (CloakNlayer == 16)
2961  {
2962  // Circular 16 layer
2963  if (fabs(la * lb - 1.0) < 0.0001)
2964  {
2965  Layer[0] = 43;
2966  Layer[1] = 87;
2967  Layer[2] = 135;
2968  Layer[3] = 187;
2969  Layer[4] = 239;
2970  Layer[5] = 295;
2971  Layer[6] = 355;
2972  Layer[7] = 415;
2973  Layer[8] = 479;
2974  Layer[9] = 555;
2975  Layer[10] = 639;
2976  Layer[11] = 727;
2977  Layer[12] = 823;
2978  Layer[13] = 927;
2979  Layer[14] = 1039;
2980  Layer[15] = 1159;
2981  }
2982 
2983  // Ellipsoid 8 layer
2984  else
2985  {
2986  Layer[0] = 135;
2987  Layer[1] = 259;
2988  Layer[2] = 387;
2989  Layer[3] = 523;
2990  Layer[4] = 667;
2991  Layer[5] = 803;
2992  Layer[6] = 939;
2993  Layer[7] = 1083;
2994  Layer[8] = 1235;
2995  Layer[9] = 1387;
2996  Layer[10] = 1539;
2997  Layer[11] = 1699;
2998  Layer[12] = 1867;
2999  Layer[13] = 2035;
3000  Layer[14] = 2203;
3001  Layer[15] = 2379;
3002  }
3003  }
3004 
3005  Array<OneD, NekDouble> x0(nq);
3006  Array<OneD, NekDouble> x1(nq);
3007  Array<OneD, NekDouble> x2(nq);
3008 
3009  m_fields[0]->GetCoords(x0, x1, x2);
3010 
3011  Array<OneD, NekDouble> Formertmp(nq, 0.0);
3012  Array<OneD, NekDouble> Currenttmp(nq, 0.0);
3013  Array<OneD, NekDouble> Cloakregion(nq, 0.0);
3014 
3015  m_fields[0]->GenerateElementVector(Layer[0], 1.0, 0.0, Currenttmp);
3016  Vmath::Vcopy(nq, Currenttmp, 1, Cloakregion, 1);
3017  for (int i = 1; i < CloakNlayer; ++i)
3018  {
3019  m_fields[0]->GenerateElementVector(Layer[i], 1.0, 0.0, Currenttmp);
3020  m_fields[0]->GenerateElementVector(Layer[i - 1], 1.0, 0.0, Formertmp);
3021 
3022  Vmath::Vsub(nq, Currenttmp, 1, Formertmp, 1, Currenttmp, 1);
3023 
3024  Vmath::Svtvp(nq, 1.0 * (i + 1), Currenttmp, 1, Cloakregion, 1,
3025  Cloakregion, 1);
3026  }
3027 
3028  Array<OneD, NekDouble> radvec(nq);
3029 
3030  for (int i = 0; i < nq; ++i)
3031  {
3032  switch (m_MMFdir)
3033  {
3035  {
3036  if ((Cloakregion[i] > 0) && (CloakNlayer > 0))
3037  {
3038  radvec[i] =
3039  1.0 +
3040  (m_b - m_a) / CloakNlayer * (Cloakregion[i] - 0.5);
3041  }
3042 
3043  else
3044  {
3045  radvec[i] =
3046  sqrt(x0[i] * x0[i] / la / la + x1[i] * x1[i] / lb / lb);
3047  }
3048  }
3049  break;
3050 
3052  {
3053  radvec[i] = sqrt(2.0 * x0[i] * x0[i] +
3054  x1[i] * x1[i] * x1[i] * x1[i] + x1[i] * x1[i]);
3055  }
3056  break;
3057 
3059  {
3060  radvec[i] = sqrt(3.0 * x0[i] * x0[i] +
3061  x1[i] * x1[i] * x1[i] * x1[i] - x1[i] * x1[i]);
3062  }
3063  break;
3064 
3065  default:
3066  break;
3067  }
3068  }
3069 
3070  return radvec;
3071 }
3072 
3074 {
3077  s, "TestMaxwellType",
3079  SolverUtils::AddSummaryItem(s, "PolType",
3081  SolverUtils::AddSummaryItem(s, "IncType",
3083 
3084  if (m_varepsilon[0] * m_varepsilon[1] * m_varepsilon[2] > 1.0)
3085  {
3086  SolverUtils::AddSummaryItem(s, "varepsilon1", m_varepsilon[0]);
3087  SolverUtils::AddSummaryItem(s, "varepsilon2", m_varepsilon[1]);
3088  SolverUtils::AddSummaryItem(s, "varepsilon3", m_varepsilon[2]);
3089  }
3090 
3091  if (m_mu[0] * m_mu[1] * m_mu[2] > 1.0)
3092  {
3093  SolverUtils::AddSummaryItem(s, "mu1", m_mu[0]);
3094  SolverUtils::AddSummaryItem(s, "mu2", m_mu[1]);
3095  SolverUtils::AddSummaryItem(s, "mu3", m_mu[2]);
3096  }
3097 
3098  if (m_boundaryforSF > 0)
3099  {
3100  SolverUtils::AddSummaryItem(s, "boundarySF", m_boundaryforSF);
3101  }
3102 
3103  if (m_ElemtGroup1 > 0)
3104  {
3105  SolverUtils::AddSummaryItem(s, "CloakNlayer", m_CloakNlayer);
3106  SolverUtils::AddSummaryItem(s, "ElemtGroup1", m_ElemtGroup1);
3107  }
3108 
3109  SolverUtils::AddSummaryItem(s, "AddRotation", m_AddRotation);
3110 
3111  if (m_AddPML > 0)
3112  {
3113  SolverUtils::AddSummaryItem(s, "AddPML", m_AddPML);
3114  SolverUtils::AddSummaryItem(s, "PMLelement", m_PMLelement);
3115  SolverUtils::AddSummaryItem(s, "RecPML", m_RecPML);
3116  SolverUtils::AddSummaryItem(s, "PMLorder", m_PMLorder);
3117  SolverUtils::AddSummaryItem(s, "PMLthickness", m_PMLthickness);
3118  SolverUtils::AddSummaryItem(s, "PMLstart", m_PMLstart);
3119  SolverUtils::AddSummaryItem(s, "PMLmaxsigma", m_PMLmaxsigma);
3120  }
3121 
3122  if (m_SourceType)
3123  {
3124  SolverUtils::AddSummaryItem(s, "SourceType",
3129  SolverUtils::AddSummaryItem(s, "PSduration", m_PSduration);
3130  SolverUtils::AddSummaryItem(s, "Gaussianradius", m_Gaussianradius);
3131  }
3132 
3133  if (m_CloakType)
3134  {
3136  SolverUtils::AddSummaryItem(s, "DispersiveCloak", m_DispersiveCloak);
3137  SolverUtils::AddSummaryItem(s, "CloakNlayer", m_CloakNlayer);
3138  SolverUtils::AddSummaryItem(s, "Cloakraddelta", m_Cloakraddelta);
3139  }
3140 }
3142 {
3143  int Ntot = inarray.num_elements();
3144 
3145  NekDouble reval = 0.0;
3146  for (int i = 0; i < Ntot; ++i)
3147  {
3148  std::cout << "[" << i << "] = " << inarray[2][i] << std::endl;
3149  // reval = reval + inarray[i]*inarray[i];
3150  }
3151  reval = sqrt(reval / Ntot);
3152 }
3153 }
Array< OneD, NekDouble > TestMaxwell2DPEC(const NekDouble time, unsigned int field, const SolverUtils::PolType Polarization)
Array< OneD, NekDouble > TestMaxwell2DPMC(const NekDouble time, unsigned int field, const SolverUtils::PolType Polarization)
NekDouble m_PSduration
Definition: MMFMaxwell.h:121
virtual void v_DoSolve()
Solves an unsteady problem.
Definition: MMFMaxwell.cpp:447
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:216
std::shared_ptr< MeshGraph > MeshGraphSharedPtr
Definition: MeshGraph.h:163
void DoOdeRhs(const Array< OneD, const Array< OneD, NekDouble >> &inarray, Array< OneD, Array< OneD, NekDouble >> &outarray, const NekDouble time)
Compute the RHS.
Definition: MMFMaxwell.cpp:892
virtual ~MMFMaxwell()
Destructor.
Definition: MMFMaxwell.cpp:443
Array< OneD, NekDouble > m_coriolis
Definition: MMFMaxwell.h:142
SOLVER_UTILS_EXPORT void AdddedtMaxwell(const Array< OneD, const Array< OneD, NekDouble >> &physarray, Array< OneD, Array< OneD, NekDouble >> &outarray)
Definition: MMFSystem.cpp:1369
virtual void v_InitObject()
Initialise the object.
Definition: MMFMaxwell.cpp:63
CloakType m_CloakType
Definition: MMFMaxwell.h:76
NekDouble m_time
Current time of simulation.
Circular around the centre of domain.
int m_PrintoutSurfaceCurrent
Definition: MMFMaxwell.h:105
void Vsqrt(int n, const T *x, const int incx, T *y, const int incy)
sqrt y = sqrt(x)
Definition: Vmath.cpp:411
Array< OneD, NekDouble > TestMaxwell1D(const NekDouble time, unsigned int field)
A base class for PDEs which include an advection component.
Definition: MMFSystem.h:140
T Vmax(int n, const T *x, const int incx)
Return the maximum element in x – called vmax to avoid conflict with max.
Definition: Vmath.cpp:782
LibUtilities::TimeIntegrationSchemeOperators m_ode
The time integration scheme operators to use.
NekDouble m_PMLthickness
Definition: MMFMaxwell.h:137
NekDouble m_timestep
Time step size.
NekDouble TimePerTest(unsigned int n)
Returns amount of seconds per iteration in a test with n iterations.
Definition: Timer.cpp:57
SOLVER_UTILS_EXPORT Array< OneD, NekDouble > GetIncidentField(const int var, const NekDouble time)
Definition: MMFSystem.cpp:2034
Array< OneD, NekDouble > m_wp2
Definition: MMFMaxwell.h:117
Array< OneD, Array< OneD, NekDouble > > m_negepsvecminus1
Definition: MMFSystem.h:209
std::vector< std::pair< std::string, std::string > > SummaryList
Definition: Misc.h:46
NekDouble m_Gaussianradius
Definition: MMFMaxwell.h:121
T Vmin(int n, const T *x, const int incx)
Return the minimum element in x - called vmin to avoid conflict with min.
Definition: Vmath.cpp:874
Array< OneD, Array< OneD, Array< OneD, NekDouble > > > m_CurlMF
Definition: MMFSystem.h:190
MMFMaxwell(const LibUtilities::SessionReaderSharedPtr &pSession, const SpatialDomains::MeshGraphSharedPtr &pGraph)
Session reader.
Definition: MMFMaxwell.cpp:54
void Checkpoint_TotPlotOutput(const int n, const NekDouble time, const Array< OneD, const Array< OneD, NekDouble >> &fieldphys)
SOLVER_UTILS_EXPORT void Checkpoint_Output(const int n)
Write checkpoint file of m_fields.
void Printout_SurfaceCurrent(Array< OneD, Array< OneD, NekDouble >> &fields, const int time)
void Svtvp(int n, const T alpha, const T *x, const int incx, const T *y, const int incy, T *z, const int incz)
svtvp (scalar times vector plus vector): z = alpha*x + y
Definition: Vmath.cpp:488
void Vvtvp(int n, const T *w, const int incw, const T *x, const int incx, const T *y, const int incy, T *z, const int incz)
vvtvp (vector times vector plus vector): z = w*x + y
Definition: Vmath.cpp:445
const char *const IncTypeMap[]
Definition: MMFSystem.h:135
SOLVER_UTILS_EXPORT void DeriveCrossProductMF(Array< OneD, Array< OneD, NekDouble >> &CrossProductMF)
Definition: MMFSystem.cpp:571
NekDouble m_checktime
Time between checkpoints.
void DoOdeProjection(const Array< OneD, const Array< OneD, NekDouble >> &inarray, Array< OneD, Array< OneD, NekDouble >> &outarray, const NekDouble time)
Compute the projection.
void ComputeMaterialMicroWaveCloak(const Array< OneD, const NekDouble > &radvec, Array< OneD, Array< OneD, NekDouble >> &epsvec, Array< OneD, Array< OneD, NekDouble >> &muvec)
void Vdiv(int n, const T *x, const int incx, const T *y, const int incy, T *z, const int incz)
Multiply vector z = x/y.
Definition: Vmath.cpp:244
SOLVER_UTILS_EXPORT void ComputeZimYim(Array< OneD, Array< OneD, NekDouble >> &epsvec, Array< OneD, Array< OneD, NekDouble >> &muvec)
Definition: MMFSystem.cpp:1107
SOLVER_UTILS_EXPORT void Computedemdxicdote()
Definition: MMFSystem.cpp:1279
std::string m_sessionName
Name of the session.
int m_checksteps
Number of steps between checkpoints.
Array< OneD, NekDouble > GaussianPulse(const NekDouble time, const NekDouble Psx, const NekDouble Psy, const NekDouble Psz, const NekDouble Gaussianradius)
void AddPML(const Array< OneD, const Array< OneD, NekDouble >> &physarray, Array< OneD, Array< OneD, NekDouble >> &outarray)
Array< OneD, Array< OneD, NekDouble > > m_epsvec
Definition: MMFSystem.h:206
Array< OneD, NekDouble > m_varepsilon
Definition: MMFMaxwell.h:132
SOLVER_UTILS_EXPORT int GetTotPoints()
Array< OneD, Array< OneD, NekDouble > > m_movingframes
Definition: MMFSystem.h:180
NekDouble m_fintime
Finish time of the simulation.
int m_steps
Number of steps to take.
NekDouble m_Cloakraddelta
Definition: MMFMaxwell.h:114
Array< OneD, NekDouble > m_SourceVector
Definition: MMFMaxwell.h:119
Array< OneD, Array< OneD, NekDouble > > m_SigmaPML
Definition: MMFMaxwell.h:138
NekDouble m_PMLstart
Definition: MMFMaxwell.h:137
void DefineProjection(FuncPointerT func, ObjectPointerT obj)
TestMaxwellType m_TestMaxwellType
Definition: MMFSystem.h:150
const char *const TestMaxwellTypeMap[]
Definition: MMFSystem.h:108
Array< OneD, Array< OneD, NekDouble > > m_muvec
Definition: MMFSystem.h:207
static const NekDouble kNekZeroTol
void Smul(int n, const T alpha, const T *x, const int incx, T *y, const int incy)
Scalar multiply y = alpha*y.
Definition: Vmath.cpp:216
Circular around the centre of domain.
bool m_explicitAdvection
Indicates if explicit or implicit treatment of advection is used.
SOLVER_UTILS_EXPORT Array< OneD, NekDouble > CartesianToMovingframes(const Array< OneD, const Array< OneD, NekDouble >> &uvec, unsigned int field)
Definition: MMFSystem.cpp:774
void DefineOdeRhs(FuncPointerT func, ObjectPointerT obj)
void ComputeMaterialOpticalCloak(const Array< OneD, const NekDouble > &radvec, Array< OneD, Array< OneD, NekDouble >> &epsvec, Array< OneD, Array< OneD, NekDouble >> &muvec, const bool Dispersion=false)
void Checkpoint_EnergyOutput(const int n, const NekDouble time, const Array< OneD, const Array< OneD, NekDouble >> &fieldphys)
Base class for unsteady solvers.
SOLVER_UTILS_EXPORT NekDouble RootMeanSquare(const Array< OneD, const NekDouble > &inarray)
Definition: MMFSystem.cpp:2367
void AddSummaryItem(SummaryList &l, const std::string &name, const std::string &value)
Adds a summary item to the summary info list.
Definition: Misc.cpp:49
CloakType
Definition: MMFMaxwell.h:41
SpatialDomains::BoundaryConditionsSharedPtr m_boundaryConditions
Pointer to boundary conditions object.
const char *const PolTypeMap[]
Definition: MMFSystem.h:123
int m_spacedim
Spatial dimension (>= expansion dim).
SOLVER_UTILS_EXPORT void ComputeNtimesMF()
Definition: MMFSystem.cpp:618
SOLVER_UTILS_EXPORT void NumericalMaxwellFlux(Array< OneD, Array< OneD, NekDouble >> &physfield, Array< OneD, Array< OneD, NekDouble >> &numfluxFwd, Array< OneD, Array< OneD, NekDouble >> &numfluxBwd, const NekDouble time=0.0)
Definition: MMFSystem.cpp:1735
void Checkpoint_TotalFieldOutput(const int n, const NekDouble time, const Array< OneD, const Array< OneD, NekDouble >> &fieldphys)
void print_MMF(Array< OneD, Array< OneD, NekDouble >> &inarray)
void Neg(int n, T *x, const int incx)
Negate x = -x.
Definition: Vmath.cpp:399
double NekDouble
SOLVER_UTILS_EXPORT void MMFInitObject(const Array< OneD, const Array< OneD, NekDouble >> &Anisotropy, const int TangentXelem=-1)
Definition: MMFSystem.cpp:53
static SolverUtils::EquationSystemSharedPtr create(const LibUtilities::SessionReaderSharedPtr &pSession, const SpatialDomains::MeshGraphSharedPtr &pGraph)
Creates an instance of this class.
Definition: MMFMaxwell.h:81
virtual SOLVER_UTILS_EXPORT void v_InitObject()
Init object for UnsteadySystem class.
NekDouble m_freq
Definition: MMFMaxwell.h:129
T Vamax(int n, const T *x, const int incx)
Return the maximum absolute element in x called vamax to avoid conflict with max. ...
Definition: Vmath.cpp:828
SourceType
Definition: MMFMaxwell.h:57
void Sadd(int n, const T alpha, const T *x, const int incx, T *y, const int incy)
Add vector y = alpha + x.
Definition: Vmath.cpp:318
const char *const CloakTypeMap[]
Definition: MMFMaxwell.h:51
Array< OneD, NekDouble > m_MMFfactors
Definition: MMFSystem.h:154
void GenerateSigmaPML(const NekDouble PMLthickness, const NekDouble PMLstart, const NekDouble PMLmaxsigma, Array< OneD, Array< OneD, NekDouble >> &SigmaPML)
void WeakDGMaxwellDirDeriv(const Array< OneD, const Array< OneD, NekDouble >> &InField, Array< OneD, Array< OneD, NekDouble >> &OutField, const NekDouble time=0.0)
Calculate weak DG advection in the form .
EquationSystemFactory & GetEquationSystemFactory()
NekDouble m_wp2Tol
Definition: MMFMaxwell.h:116
NekDouble m_PMLmaxsigma
Definition: MMFMaxwell.h:137
void Checkpoint_EDFluxOutput(const int n, const NekDouble time, const Array< OneD, const Array< OneD, NekDouble >> &fieldphys)
SOLVER_UTILS_EXPORT void CartesianToSpherical(const NekDouble x0j, const NekDouble x1j, const NekDouble x2j, NekDouble &sin_varphi, NekDouble &cos_varphi, NekDouble &sin_theta, NekDouble &cos_theta)
Definition: MMFSystem.cpp:795
SourceType m_SourceType
Definition: MMFMaxwell.h:77
virtual void v_SetInitialConditions(const NekDouble initialtime, bool dumpInitialConditions, const int domain)
Array< OneD, Array< OneD, NekDouble > > m_negmuvecminus1
Definition: MMFSystem.h:210
void Vsub(int n, const T *x, const int incx, const T *y, const int incy, T *z, const int incz)
Subtract vector z = x-y.
Definition: Vmath.cpp:346
SOLVER_UTILS_EXPORT int GetTraceTotPoints()
static std::string className
Name of class.
Definition: MMFMaxwell.h:91
static NekDouble rad(NekDouble x, NekDouble y)
Definition: Interpreter.cpp:86
SOLVER_UTILS_EXPORT void WriteFld(const std::string &outname)
Write field data to the given filename.
virtual void v_EvaluateExactSolution(unsigned int field, Array< OneD, NekDouble > &outfield, const NekDouble time)
SOLVER_UTILS_EXPORT int GetNpoints()
void AddCoriolis(Array< OneD, Array< OneD, NekDouble >> &physarray, Array< OneD, Array< OneD, NekDouble >> &outarray)
NekDouble m_CloakNlayer
Definition: MMFMaxwell.h:113
Array< OneD, MultiRegions::ExpListSharedPtr > m_fields
Array holding all dependent variables.
LibUtilities::SessionReaderSharedPtr m_session
The session reader.
void Vvtvm(int n, const T *w, const int incw, const T *x, const int incx, const T *y, const int incy, T *z, const int incz)
vvtvm (vector times vector plus vector): z = w*x - y
Definition: Vmath.cpp:468
Array< OneD, Array< OneD, NekDouble > > m_CrossProductMF
Definition: MMFMaxwell.h:123
SOLVER_UTILS_EXPORT int GetTraceNpoints()
SOLVER_UTILS_EXPORT int GetNcoeffs()
SOLVER_UTILS_EXPORT void GetMaxwellFluxVector(const int var, const Array< OneD, const Array< OneD, NekDouble >> &physfield, Array< OneD, Array< OneD, NekDouble >> &flux)
Definition: MMFSystem.cpp:1614
void Checkpoint_PlotOutput(const int n, const Array< OneD, const Array< OneD, NekDouble >> &fieldphys)
LibUtilities::TimeIntegrationWrapperSharedPtr m_intScheme
Wrapper to the time integration scheme.
Circular around the centre of domain.
virtual void v_GenerateSummary(SolverUtils::SummaryList &s)
Print Summary.
int m_infosteps
Number of time steps between outputting status information.
Array< OneD, Array< OneD, Array< OneD, NekDouble > > > m_ntimesMFFwd
Definition: MMFSystem.h:196
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, std::string pDesc="")
Register a class with the factory.
Definition: NekFactory.hpp:199
Array< OneD, NekDouble > ComputeRadCloak(const int Nlayer=5)
void Zero(int n, T *x, const int incx)
Zero vector.
Definition: Vmath.cpp:376
NekDouble ComputeEnergyDensity(Array< OneD, Array< OneD, NekDouble >> &fields)
Array< OneD, NekDouble > EvaluateCoriolis()
virtual SOLVER_UTILS_EXPORT void v_GenerateSummary(SummaryList &s)
Print a summary of time stepping parameters.
Definition: MMFSystem.cpp:2492
const char *const SourceTypeMap[]
Definition: MMFMaxwell.h:65
void Vcopy(int n, const T *x, const int incx, T *y, const int incy)
Definition: Vmath.cpp:1064
void ComputeMaterialVector(Array< OneD, Array< OneD, NekDouble >> &epsvec, Array< OneD, Array< OneD, NekDouble >> &muvec)
LibUtilities::TimeIntegrationSolutionSharedPtr m_intSoln
std::shared_ptr< SessionReader > SessionReaderSharedPtr
void Vadd(int n, const T *x, const int incx, const T *y, const int incy, T *z, const int incz)
Add vector z = x+y.
Definition: Vmath.cpp:302
void Vmul(int n, const T *x, const int incx, const T *y, const int incy, T *z, const int incz)
Multiply vector z = x*y.
Definition: Vmath.cpp:186
Array< OneD, NekDouble > TestMaxwellSphere(const NekDouble time, const NekDouble omega, unsigned int field)
Array< OneD, NekDouble > ComputeSurfaceCurrent(const int time, const Array< OneD, const Array< OneD, NekDouble >> &fields)
void AddGreenDerivCompensate(const Array< OneD, const Array< OneD, NekDouble >> &physarray, Array< OneD, Array< OneD, NekDouble >> &outarray)
Array< OneD, NekDouble > m_mu
Definition: MMFMaxwell.h:133
SpatialDomains::GeomMMF m_MMFdir
Definition: MMFSystem.h:216