11 using namespace Nektar;
13 int main(
int argc,
char *argv[])
20 fprintf(stderr,
"Usage: FldAddScalGrad meshfile infld outfld BoundaryID\n");
24 surfID = boost::lexical_cast<
int>(argv[argc - 1]);
26 argv[argc -1] = argv[argc - 2];
33 string meshfile(argv[argc-4]);
39 string fieldfile(argv[argc-3]);
40 vector<LibUtilities::FieldDefinitionsSharedPtr> fielddef;
41 vector<vector<NekDouble> > fielddata;
47 int expdim = graphShPt->GetMeshDimension();
50 Array<OneD, MultiRegions::ExpListSharedPtr> exp(nfields + addfields);
57 ASSERTL0(
false,
"Expansion dimension not recognised");
62 ASSERTL0(
false,
"Expansion dimension not recognised");
70 vSession->GetVariable(0));
72 m_locToGlobalMap = originalfield->GetLocalToGlobalMap();
74 exp[0] = originalfield;
78 vSession->GetVariable(0));
82 ASSERTL0(
false,
"Expansion dimension not recognised");
89 for(j = 0; j < nfields+addfields; ++j)
91 for(
int i = 0; i < fielddata.size(); ++i)
93 exp[j]->ExtractDataToCoeffs(fielddef [i],
95 fielddef [i]->m_fields[0],
96 exp[j]->UpdateCoeffs());
99 exp[j]->BwdTrans(exp[j]->GetCoeffs(),exp[j]->UpdatePhys());
106 int n, cnt, elmtid, nq, offset, nt, boundary, nfq;
107 nt = exp[0]->GetNpoints();
108 Array<OneD, Array<OneD, NekDouble> > grad(expdim);
109 Array<OneD, Array<OneD, NekDouble> > fgrad(expdim);
114 Array<OneD, int> BoundarytoElmtID;
115 Array<OneD, int> BoundarytoTraceID;
116 Array<OneD, MultiRegions::ExpListSharedPtr> BndExp;
117 Array<OneD, const NekDouble> U(nt);
118 Array<OneD, NekDouble> values;
119 Array<OneD, NekDouble> outvalues;
121 exp[0]->GetBoundaryToElmtMap(BoundarytoElmtID,BoundarytoTraceID);
124 BndExp = exp[0]->GetBndCondExpansions();
127 for(cnt = n = 0; n < BndExp.num_elements(); ++n)
132 for(i = 0; i < BndExp[n]->GetExpSize(); ++i, cnt++)
135 elmtid = BoundarytoElmtID[cnt];
136 elmt = exp[0]->GetExp(elmtid);
137 nq = elmt->GetTotPoints();
138 offset = exp[0]->GetPhys_Offset(elmtid);
142 for(j = 0; j < expdim; ++j)
144 grad[j] = Array<OneD, NekDouble>(nq);
150 boundary = BoundarytoTraceID[cnt];
153 U = exp[0]->GetPhys() + offset;
163 for(j = 0; j < expdim; ++j)
165 fgrad[j] = Array<OneD, NekDouble>(nq);
169 boundary = BoundarytoTraceID[cnt];
172 for(j = 0; j < expdim; ++j)
179 values = BndExp[n]->UpdateCoeffs()+BndExp[n]->GetCoeff_Offset(i);
180 bc->NormVectorIProductWRTBase(fgrad[0],fgrad[1],values);
191 boundary = BoundarytoTraceID[cnt];
194 U = exp[0]->GetPhys() + offset;
197 elmt->PhysDeriv(U,grad[0],grad[1],grad[2]);
199 for(j = 0; j < expdim; ++j)
201 fgrad[j] = Array<OneD, NekDouble>(nfq);
205 for(j = 0; j < expdim; ++j)
207 elmt->GetFacePhysVals(boundary,bc,grad[j],fgrad[j]);
212 const Array<OneD, const Array<OneD, NekDouble> > normals
213 = elmt->GetFaceNormal(boundary);
215 Array<OneD, NekDouble> gradnorm(nfq);
218 values = BndExp[n]->UpdateCoeffs() + BndExp[n]->GetCoeff_Offset(i);
223 normals[1],1,fgrad[1],1,gradnorm,1);
224 Vmath::Vvtvp (nfq,normals[2],1,fgrad[2],1,gradnorm,1,gradnorm,1);
229 normals[1][0],fgrad[1],1,gradnorm,1);
230 Vmath::Svtvp(nfq,normals[2][0],fgrad[2],1,gradnorm,1,gradnorm,1);
235 bc->FwdTrans(gradnorm,values);
242 cnt += BndExp[n]->GetExpSize();
246 int ncoeffs = exp[1]->GetNcoeffs();
247 Array<OneD, NekDouble> output(ncoeffs);
249 output=exp[1]->UpdateCoeffs();
251 int nGlobal=m_locToGlobalMap->GetNumGlobalCoeffs();
252 Array<OneD, NekDouble> outarray(nGlobal,0.0);
256 const Array<OneD,const int>& map = m_locToGlobalMap->GetBndCondCoeffsToGlobalCoeffsMap();
258 for(i = 0; i < BndExp.num_elements(); ++i)
262 const Array<OneD,const NekDouble>& coeffs = BndExp[i]->GetCoeffs();
263 for(
int k = 0; k < (BndExp[i])->GetNcoeffs(); ++k)
265 outarray[map[bndcnt++]] = coeffs[k];
270 bndcnt += BndExp[i]->GetNcoeffs();
273 m_locToGlobalMap->GlobalToLocal(outarray,output);
277 string out(argv[argc-2]);
278 std::vector<LibUtilities::FieldDefinitionsSharedPtr> FieldDef
279 = exp[0]->GetFieldDefinitions();
280 std::vector<std::vector<NekDouble> > FieldData(FieldDef.size());
282 vector<string > outname;
284 outname.push_back(
"gradient");
287 for(j = 0; j < nfields+addfields; ++j)
289 for(i = 0; i < FieldDef.size(); ++i)
293 FieldDef[i]->m_fields.push_back(outname[j-nfields]);
297 FieldDef[i]->m_fields.push_back(fielddef[i]->m_fields[j]);
299 exp[j]->AppendFieldData(FieldDef[i], FieldData[i]);