Nektar++
Loading...
Searching...
No Matches
LaplacePhi.cpp
Go to the documentation of this file.
1///////////////////////////////////////////////////////////////////////////////
2//
3// File: LaplacePhi.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: Compute the velocity potentials around a rigid body
32//
33// 2D, phi0, phi1 [translation]; phi2 [rotation]; phi3 [bulge]
34// 3D, phi0, phi1, phi2 [translation]; phi3, phi4, phi5 [rotation]; phi6 [bulge]
35///////////////////////////////////////////////////////////////////////////////
36
39namespace Nektar
40{
41std::string LaplacePhi::className =
44
52
53void LaplacePhi::v_InitObject(bool DeclareFields)
54{
55 EquationSystem::v_InitObject(DeclareFields);
56 int ndim = m_fields[0]->GetCoordim(0);
57 // number of potential fields
58 int bndsize = (ndim == 2) ? 4 : 7;
59 // check variable name phi[0-bndsize]
60 for (const auto &it : m_session->GetVariables())
61 {
62 if (it.size() != 4 || it[0] != 'p' || it[1] != 'h' || it[2] != 'i' ||
63 it[3] < '0' || it[4] >= bndsize + '0')
64 {
66 "Error: incorrect variable name '" + it +
67 "', should be phi[0-3] or phi[0-6].");
68 }
69 }
70 // number of physics points for each field
71 int numpts = 0;
73 m_fields[0]->GetBndConditions();
75 m_fields[0]->GetBndCondExpansions();
76 for (int i = 0; i < m_BndConds.size(); ++i)
77 {
78 if (boost::iequals(m_BndConds[i]->GetUserDefined(), "MOVE"))
79 {
80 numpts += m_BndExp[i]->GetTotPoints();
81 }
82 }
83 // load pivot point
85 if (m_session->DefinesParameter("Pivotx"))
86 {
87 m_pivot[0] = m_session->GetParameter("Pivotx");
88 }
89 if (m_session->DefinesParameter("Pivoty"))
90 {
91 m_pivot[1] = m_session->GetParameter("Pivoty");
92 }
93 if (m_session->DefinesParameter("Pivotz"))
94 {
95 m_pivot[2] = m_session->GetParameter("Pivotz");
96 }
97 // allocate storage
99 for (int i = 0; i < bndsize; ++i)
100 {
101 m_boundValues[i] = Array<OneD, NekDouble>(numpts, 0.);
102 }
103 // calculate values
104 int offset = 0;
105 for (int i = 0; i < m_BndConds.size(); ++i)
106 {
107 if (boost::iequals(m_BndConds[i]->GetUserDefined(), "MOVE"))
108 {
109 int npts = m_BndExp[i]->GetTotPoints();
112 for (int j = 0; j < 3; ++j)
113 {
114 n[j] = Array<OneD, NekDouble>(npts, 0.);
115 x[j] = Array<OneD, NekDouble>(npts, 0.);
116 }
117 m_BndExp[i]->GetNormals(n);
118 m_BndExp[i]->GetCoords(x[0], x[1], x[2]);
119 for (int j = 0; j < 3; ++j)
120 {
121 Vmath::Sadd(npts, -m_pivot[j], x[j], 1, x[j], 1);
122 }
124 for (int j = 0; j < ndim; ++j)
125 {
126 Vmath::Smul(npts, -1., n[j], 1,
127 atmp = m_boundValues[j] + offset, 1);
128 }
129 atmp = m_boundValues[bndsize - 2] + offset;
130 Vmath::Vvtvvtm(npts, &x[1][0], 1, &n[0][0], 1, &x[0][0], 1,
131 &n[1][0], 1, &atmp[0], 1);
132 if (ndim == 3)
133 {
134 atmp = m_boundValues[3] + offset;
135 Vmath::Vvtvvtm(npts, &x[2][0], 1, &n[1][0], 1, &x[1][0], 1,
136 &n[2][0], 1, &atmp[0], 1);
137 atmp = m_boundValues[4] + offset;
138 Vmath::Vvtvvtm(npts, &x[0][0], 1, &n[2][0], 1, &x[2][0], 1,
139 &n[0][0], 1, &atmp[0], 1);
140 }
141 atmp = m_boundValues[bndsize - 1] + offset;
142 for (int j = 0; j < 2; ++j)
143 {
144 Vmath::Vvtvp(npts, x[j], 1, n[j], 1, atmp, 1, atmp, 1);
145 }
146 Vmath::Neg(npts, atmp, 1);
147 offset += npts;
148 }
149 }
150}
151
158
159void LaplacePhi::v_DoInitialise([[maybe_unused]] bool dumpInitialConditions)
160{
161 // Set initial conditions from session file
162 SetInitialConditions(0.0, false, 0);
163}
164
166{
167 for (int i = 0; i < m_fields.size(); ++i)
168 {
171 m_fields[i]->HelmSolve(forcing, m_fields[i]->UpdateCoeffs(), m_factors);
172 m_fields[i]->BwdTrans(m_fields[i]->GetCoeffs(),
173 m_fields[i]->UpdatePhys());
174 m_fields[i]->SetPhysState(true);
175 }
177}
178
180{
181 return Array<OneD, bool>(m_session->GetVariables().size(), true);
182}
183
185{
186 int m = m_session->GetVariable(n)[3] - '0';
188 m_fields[n]->GetBndConditions();
190 m_fields[n]->GetBndCondExpansions();
191 int offset = 0;
192 for (int i = 0; i < m_BndConds.size(); ++i)
193 {
194 if (boost::iequals(m_BndConds[i]->GetUserDefined(), "MOVE"))
195 {
196 m_BndExp[i]->IProductWRTBase(m_boundValues[m] + offset,
197 m_BndExp[i]->UpdateCoeffs());
198 offset += m_BndExp[i]->GetTotPoints();
199 }
200 }
201}
202
204{
206 m_fields[0]->GetBndConditions();
208 m_fields[0]->GetBndCondExpansions();
209 int nfld = m_fields.size();
210 Array<OneD, NekDouble> value(nfld * nfld,
211 std::numeric_limits<NekDouble>::lowest());
212 int offset = 0;
213 for (int i = 0; i < m_BndConds.size(); ++i)
214 {
215 if (boost::iequals(m_BndConds[i]->GetUserDefined(), "MOVE"))
216 {
217 MultiRegions::ExpListSharedPtr edgeExplist = m_BndExp[i];
220 m_fields[0]->GetBndElmtExpansion(i, BndElmtExp, false);
221 Array<OneD, NekDouble> phiElm(BndElmtExp->GetTotPoints(), 0.);
222 for (int j = 0; j < nfld; ++j)
223 {
224 m_fields[j]->ExtractPhysToBndElmt(i, m_fields[j]->GetPhys(),
225 phiElm);
226 m_fields[j]->ExtractElmtToBndPhys(i, phiElm, phi[j]);
227 }
228 ////phi_0 n_0, phi_0 n_1, phi_1 n_0, phi_1 n_1
229 Array<OneD, NekDouble> mularray(edgeExplist->GetTotPoints(), 0.);
230 for (int j = 0; j < nfld; ++j)
231 {
232 for (int k = 0; k < m_boundValues.size(); ++k)
233 {
234 Vmath::Vmul(edgeExplist->GetTotPoints(), phi[j], 1,
235 m_boundValues[k] + offset, 1, mularray, 1);
236 value[k + j * nfld] = edgeExplist->Integral(mularray);
237 }
238 }
239 offset += edgeExplist->GetTotPoints();
240 }
241 }
242
243 m_session->GetComm()->AllReduce(value, LibUtilities::ReduceMax);
244 if (m_session->GetComm()->GetRank() == 0)
245 {
246 for (int j = 0; j < nfld; ++j)
247 {
248 for (int k = 0; k < nfld; ++k)
249 {
250 std::cout << "value[" << m_session->GetVariable(j)[3] << ", "
251 << m_session->GetVariable(k)[3]
252 << "] = " << std::scientific << std::setprecision(7)
253 << value[k + j * nfld] << std::endl;
254 }
255 }
256 }
257}
258} // namespace Nektar
#define NEKERROR(type, msg)
Assert Level 0 – Fundamental assert which is used whether in FULLDEBUG, DEBUG or OPT compilation mode...
Array< OneD, bool > v_GetSystemSingularChecks() override
static EquationSystemSharedPtr create(const LibUtilities::SessionReaderSharedPtr &pSession, const SpatialDomains::MeshGraphSharedPtr &pGraph)
Creates an instance of this class.
Definition LaplacePhi.h:51
void v_GenerateSummary(SolverUtils::SummaryList &s) override
Virtual function for generating summary information.
void v_DoSolve() override
Virtual function for solve implementation.
StdRegions::ConstFactorMap m_factors
Definition LaplacePhi.h:65
void setUserDefinedBC(int n)
Array< OneD, NekDouble > m_pivot
Definition LaplacePhi.h:82
void v_DoInitialise(bool dumpInitialConditions=true) override
Virtual function for initialisation implementation.
LaplacePhi(const LibUtilities::SessionReaderSharedPtr &pSession, const SpatialDomains::MeshGraphSharedPtr &pGraph)
static std::string className
Name of class.
Definition LaplacePhi.h:62
Array< OneD, Array< OneD, NekDouble > > m_boundValues
Definition LaplacePhi.h:81
void v_InitObject(bool DeclareFields=true) override
Initialisation object for EquationSystem.
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, std::string pDesc="")
Register a class with the factory.
A base class for describing how to solve specific equations.
SOLVER_UTILS_EXPORT void SessionSummary(SummaryList &vSummary)
Write out a session summary.
Array< OneD, MultiRegions::ExpListSharedPtr > m_fields
Array holding all dependent variables.
virtual SOLVER_UTILS_EXPORT void v_InitObject(bool DeclareFeld=true)
Initialisation object for EquationSystem.
LibUtilities::SessionReaderSharedPtr m_session
The session reader.
SOLVER_UTILS_EXPORT void SetInitialConditions(NekDouble initialtime=0.0, bool dumpInitialConditions=true, const int domain=0)
Initialise the data in the dependent fields.
SOLVER_UTILS_EXPORT int GetTotPoints()
std::shared_ptr< SessionReader > SessionReaderSharedPtr
std::shared_ptr< ExpList > ExpListSharedPtr
Shared pointer to an ExpList object.
std::vector< std::pair< std::string, std::string > > SummaryList
Definition Misc.h:46
EquationSystemFactory & GetEquationSystemFactory()
void AddSummaryItem(SummaryList &l, const std::string &name, const std::string &value)
Adds a summary item to the summary info list.
Definition Misc.cpp:47
std::shared_ptr< MeshGraph > MeshGraphSharedPtr
Definition MeshGraph.h:217
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.hpp:72
void Neg(int n, T *x, const int incx)
Negate x = -x.
Definition Vmath.hpp:292
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.hpp:366
void Vvtvvtm(int n, const T *v, int incv, const T *w, int incw, const T *x, int incx, const T *y, int incy, T *z, int incz)
vvtvvtm (vector times vector minus vector times vector):
Definition Vmath.hpp:456
void Smul(int n, const T alpha, const T *x, const int incx, T *y, const int incy)
Scalar multiply y = alpha*x.
Definition Vmath.hpp:100
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.hpp:194