16 #include <boost/math/special_functions/fpclassify.hpp>
18 using namespace Nektar;
20 int main(
int argc,
char *argv[])
24 vector<LibUtilities::FieldDefinitionsSharedPtr> fielddef,
26 Array<OneD,MultiRegions::ExpListSharedPtr> &Exp,
28 const vector<std::string> &variables,
32 Array<OneD, MultiRegions::ExpListSharedPtr> &field0,
33 Array<OneD, MultiRegions::ExpListSharedPtr> &field1,
34 Array<OneD, NekDouble> x1,
35 Array<OneD, NekDouble> y1,
42 Array<OneD, NekDouble> x1,
43 Array<OneD, NekDouble> y1,
47 Array<OneD, NekDouble> x0,
48 Array<OneD, NekDouble> y0,
49 Array<OneD, NekDouble> x1,
50 Array<OneD, NekDouble> y1);
53 Array<OneD, NekDouble> x0,
54 Array<OneD, NekDouble> y0,
55 Array<OneD, NekDouble> z0,
56 Array<OneD, NekDouble> x1,
57 Array<OneD, NekDouble> y1,
58 Array<OneD, NekDouble> z1);
62 const vector<std::string> &variables,
65 Array<OneD, MultiRegions::ExpListSharedPtr> &outfield);
69 fprintf(stderr,
"Usage: ./FieldToField meshfile0 fieldfile0 "
70 "meshfile1 fieldfile1\n");
75 string meshfile0(argv[argc-4]);
76 string fieldfile0(argv[argc-3]);
78 std::vector<std::string> filenames0;
79 filenames0.push_back(meshfile0);
80 filenames0.push_back(meshfile0);
87 int expdim = graphShPt->GetMeshDimension();
91 vector<LibUtilities::FieldDefinitionsSharedPtr> fielddef;
92 vector<vector<NekDouble> > fielddata;
98 const std::vector<std::string> variables = vSession->GetVariables();
99 bool homo = (fielddef[0]->m_numHomogeneousDir > 0)?
true:
false;
103 nfields = variables.size();
104 Array<OneD, MultiRegions::ExpListSharedPtr> fields;
105 fields= Array<OneD, MultiRegions::ExpListSharedPtr>(nfields);
106 SetFields(graphShPt,fielddef, vSession,fields,nfields,variables,homo);
111 if (fielddef[0]->m_numHomogeneousDir == 1)
113 nq = fields[0]->GetPlane(1)->GetTotPoints();
116 for (
int j = 0; j < nfields; ++j)
118 for (
int i = 0; i < fielddata.size(); ++i)
120 fields[j]->ExtractDataToCoeffs(fielddef[i],
122 fielddef[i]->m_fields[j],
123 fields[j]->UpdateCoeffs());
127 fields[j]->GetPlane(0)->BwdTrans_IterPerExp(
128 fields[j]->GetPlane(0)->GetCoeffs(),
129 fields[j]->GetPlane(0)->UpdatePhys());
132 fields[j]->GetPlane(1)->BwdTrans_IterPerExp(
133 fields[j]->GetPlane(1)->GetCoeffs(),
134 fields[j]->GetPlane(1)->UpdatePhys());
139 nq = fields[0]->GetTotPoints();
140 for (
int j = 0; j < nfields; ++j)
142 for (
int i = 0; i < fielddata.size(); ++i)
144 fields[j]->ExtractDataToCoeffs(fielddef[i],
146 fielddef[i]->m_fields[j],
147 fields[j]->UpdateCoeffs());
149 fields[j]->BwdTrans_IterPerExp(fields[j]->GetCoeffs(),
150 fields[j]->UpdatePhys());
156 Array<OneD, NekDouble> x0(nq);
157 Array<OneD, NekDouble> y0(nq);
158 Array<OneD, NekDouble> z0(nq);
160 if (fielddef[0]->m_numHomogeneousDir == 1)
162 fields[0]->GetPlane(1)->GetCoords(x0, y0, z0);
168 fields[0]->GetCoords(x0, y0);
170 else if (expdim == 3)
172 fields[0]->GetCoords(x0, y0, z0);
180 string meshfile1(argv[argc-2]);
182 string fieldfile1(argv[argc-1]);
186 Array<OneD, MultiRegions::ExpListSharedPtr> outfield;
188 outfield = Array<OneD, MultiRegions::ExpListSharedPtr>(nfields);
200 std::vector<std::string> filenames1;
201 filenames1.push_back(meshfile1);
202 filenames1.push_back(meshfile1);
211 vSession->GetComm());
215 SetFields(graphShPt1, fielddef, vSession1, outfield, nfields,
220 if (fielddef[0]->m_numHomogeneousDir == 1)
222 nq1 = outfield[0]->GetPlane(1)->GetTotPoints();
226 nq1 = outfield[0]->GetTotPoints();
228 Array<OneD, NekDouble> x1(nq1);
229 Array<OneD, NekDouble> y1(nq1);
230 Array<OneD, NekDouble> z1(nq1);
232 if (fielddef[0]->m_numHomogeneousDir == 1)
234 outfield[0]->GetPlane(1)->GetCoords(x1, y1, z1);
240 outfield[0]->GetCoords(x1, y1);
242 else if (expdim == 3)
244 outfield[0]->GetCoords(x1, y1, z1);
257 else if (expdim == 3)
261 ASSERTL0(check,
"meshes not compatible (different borders)");
264 if (fielddef[0]->m_numHomogeneousDir == 1)
266 for (
int t = 0; t < nfields; t++)
273 cout <<
"Interpolating [" << flush;
279 else if (expdim == 3)
282 vSession->LoadParameter(
"ClampToUpperValue", clamp_up, 10000000);
283 vSession->LoadParameter(
"ClampToLowerValue", clamp_low, -10000000);
292 Writefield(vSession, variables, fieldfile1, graphShPt1, outfield);
302 vector<LibUtilities::FieldDefinitionsSharedPtr> fielddef,
304 Array<OneD,MultiRegions::ExpListSharedPtr> &Exp,
306 const vector<std::string> &variables,
317 bool static DeclareCoeffPhysArrays =
true;
322 bool static useFFT =
false;
323 bool static deal =
false;
327 int expdim = mesh->GetMeshDimension();
333 if (fielddef[0]->m_numHomogeneousDir == 1)
342 for (i = 0 ; i < nvariables; i++)
346 session, BkeyY, LhomY,
353 for (i = 0 ; i < nvariables; i++)
363 if (fielddef[0]->m_numHomogeneousDir == 1)
375 deal, mesh, variables[0]);
378 for (i = 1 ; i < nvariables; i++)
382 AllocateSharedPtr(*firstfield);
391 DeclareCoeffPhysArrays);
394 for (i = 1 ; i < nvariables; i++)
398 DeclareCoeffPhysArrays);
405 if (fielddef[0]->m_numHomogeneousDir == 1)
408 "3D fully periodic problems not implemented yet");
418 for (i = 1 ; i < nvariables; i++)
427 ASSERTL0(
false,
"Expansion dimension not recognised");
436 Array<OneD, MultiRegions::ExpListSharedPtr> &field0,
437 Array<OneD, MultiRegions::ExpListSharedPtr> &field1,
438 Array<OneD, NekDouble> x,
439 Array<OneD, NekDouble> y,
440 Array<OneD, NekDouble> z,
446 Array<OneD, NekDouble> coords(expdim), Lcoords(expdim);
447 int nq1 = field1[0]->GetTotPoints();
450 static int intpts = 0;
452 ASSERTL0(field0.num_elements() == field1.num_elements(),
453 "Input field dimension must be same as output dimension");
455 for (r = 0; r < nq1; r++)
465 elmtid = field0[0]->GetExpIndex(coords, Lcoords, 1e-3);
467 offset = field0[0]->GetPhys_Offset(field0[0]->
468 GetOffset_Elmt_Id(elmtid));
470 for (f = 0; f < field1.num_elements(); ++f)
473 value = field0[f]->GetExp(elmtid)->
474 StdPhysEvaluate(Lcoords, field0[f]->GetPhys() +offset);
476 if ((boost::math::isnan)(value))
478 ASSERTL0(
false,
"new value is not a number");
482 value = (value > clamp_up)? clamp_up :
483 ((value < clamp_low)? clamp_low :
486 field1[f]->UpdatePhys()[r] = value;
490 if (intpts%1000 == 0)
502 Array<OneD, NekDouble> x1,
503 Array<OneD, NekDouble> y1,
506 Array<OneD, NekDouble> coords(2);
507 int nq1 = field1->GetPlane(1)->GetTotPoints();
511 for (
int r = 0; r < nq1; r++)
516 elmtid = field0->GetPlane(0)->GetExpIndex(coords, 1e-3);
517 offset = field0->GetPlane(0)->GetPhys_Offset(elmtid);
518 field1->GetPlane(0)->UpdatePhys()[r] = field0->GetPlane(0)->
519 GetExp(elmtid)->PhysEvaluate(
521 field0->GetPlane(0)->GetPhys() +offset);
523 if ((boost::math::isnan)(field1->GetPlane(0)->UpdatePhys()[r]))
532 for (
int r = 0; r < nq1; r++)
537 elmtid = field0->GetPlane(1)->GetExpIndex(coords, 1e-3);
538 offset = field0->GetPlane(1)->GetPhys_Offset(elmtid);
539 field1->GetPlane(1)->UpdatePhys()[r] = field0->GetPlane(1)->
540 GetExp(elmtid)->PhysEvaluate(
542 field0->GetPlane(1)->GetPhys() +offset);
544 if((boost::math::isnan)(field1->GetPlane(1)->UpdatePhys()[r]))
556 Array<OneD, NekDouble> x0,
557 Array<OneD, NekDouble> y0,
558 Array<OneD, NekDouble> x1,
559 Array<OneD, NekDouble> y1)
575 if (abs(x0min-x1min) < tol1 &&
576 abs(x0max-x1max) < tol1 &&
577 abs(y0min-y1min) < tol1 &&
578 abs(y0max-y1max) < tol1)
580 if (abs(x0min-x1min) > tol ||
581 abs(x0max-x1max) > tol ||
582 abs(y0min-y1min) > tol ||
583 abs(y0max-y1max) > tol)
585 cout<<
"Warning: mesh boundary points differ more than 10^-7"<<endl;
598 Array<OneD, NekDouble> x0,
599 Array<OneD, NekDouble> y0,
600 Array<OneD, NekDouble> z0,
601 Array<OneD, NekDouble> x1,
602 Array<OneD, NekDouble> y1,
603 Array<OneD, NekDouble> z1)
605 NekDouble x0min, x0max, y0min, y0max, z0min, z0max;
606 NekDouble x1min, x1max, y1min, y1max, z1min, z1max;
623 if (abs(x0min-x1min) < tol1 &&
624 abs(x0max-x1max) < tol1 &&
625 abs(y0min-y1min) < tol1 &&
626 abs(y0max-y1max) < tol1 &&
627 abs(z0min-z1min) < tol1 &&
628 abs(z0max-z1max) < tol1)
630 if (abs(x0min-x1min) > tol ||
631 abs(x0max-x1max) > tol ||
632 abs(y0min-y1min) > tol ||
633 abs(y0max-y1max) > tol ||
634 abs(z0min-z1min) > tol ||
635 abs(z0max-z1max) > tol)
637 cout<<
"Warning: mesh boundary points differ more than 10^-7"<<endl;
651 const std::vector<std::string> &variables,
654 Array<OneD, MultiRegions::ExpListSharedPtr> &outfield)
657 std::vector<LibUtilities::FieldDefinitionsSharedPtr> FieldDef
658 = outfield[0]->GetFieldDefinitions();
659 std::vector<std::vector<NekDouble> > FieldData(FieldDef.size());
660 Array<OneD, Array<OneD, NekDouble> > fieldcoeffs(outfield.num_elements());
662 for (
int j = 0; j < fieldcoeffs.num_elements(); ++j)
664 if (FieldDef[0]->m_numHomogeneousDir == 1)
667 outfield[j]->GetPlane(0)->FwdTrans_IterPerExp(
668 outfield[j]->GetPlane(0)->GetPhys(),
669 outfield[j]->GetPlane(0)->UpdateCoeffs());
672 outfield[j]->GetPlane(1)->FwdTrans_IterPerExp(
673 outfield[j]->GetPlane(1)->GetPhys(),
674 outfield[j]->GetPlane(1)->UpdateCoeffs());
678 outfield[j]->FwdTrans_IterPerExp(
679 outfield[j]->GetPhys(),
680 outfield[j]->UpdateCoeffs());
683 fieldcoeffs[j] = outfield[j]->UpdateCoeffs();
685 for (
int i = 0; i < FieldDef.size(); i++)
687 FieldDef[i]->m_fields.push_back(variables[j]);
688 outfield[0]->AppendFieldData(FieldDef[i], FieldData[i],