MCPcopy Create free account
hub / github.com/IBAMR/IBAMR / setDataOnPatch

Method setDataOnPatch

examples/IBLevelSet/ex5/LevelSetInitialCondition.cpp:42–123  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

40} // isTimeDependent
41
42void
43LevelSetInitialCondition::setDataOnPatch(const int data_idx,
44 Pointer<Variable<NDIM>> /*var*/,
45 Pointer<Patch<NDIM>> patch,
46 const double /*data_time*/,
47 const bool initial_time,
48 Pointer<PatchLevel<NDIM>> /*patch_level*/)
49{
50 // Set the level set function throughout the domain
51 if (initial_time)
52 {
53 // Get the parameters for the interface
54 const double& R = d_init_foil.R;
55 const Eigen::Vector3d& X0 = d_init_foil.X0;
56 const Eigen::Vector3d& X1 = d_init_foil.X1;
57 const Eigen::Vector3d& X2 = d_init_foil.X2;
58 const Eigen::Vector3d& X3 = d_init_foil.X3;
59 const Eigen::Vector3d& X_T = (X1 + X2 + X3) / 3.0;
60 Eigen::Vector3d check1, check2, check3, check4, check5, check6;
61
62 const double slope1 = (X3[1] - X1[1]) / (X3[0] - X1[0]);
63 const double slope2 = (X3[1] - X2[1]) / (X3[0] - X2[0]);
64 const double slope3 = (X2[0] - X1[0]) / (X2[1] - X1[1]);
65
66 const double y_intercept1 = X1[1] - slope1 * X1[0];
67 const double y_intercept2 = X2[1] - slope2 * X2[0];
68 const double x_intercept3 = X1[0] - slope3 * X1[1];
69
70 double distance1[2], distance2[3]; // Foil has three surfaces and 1 surface for circle.
71
72 const Box<NDIM>& patch_box = patch->getBox();
73 Pointer<CellData<NDIM, double>> D_data = patch->getPatchData(data_idx);
74 for (Box<NDIM>::Iterator it(patch_box); it; it++)
75 {
76 CellIndex<NDIM> ci(it());
77
78 // Get physical coordinates
79 IBTK::Vector3d coord = IBTK::Vector3d::Zero();
80 Pointer<CartesianPatchGeometry<NDIM>> patch_geom = patch->getPatchGeometry();
81 const double* patch_X_lower = patch_geom->getXLower();
82 const hier::Index<NDIM>& patch_lower_idx = patch_box.lower();
83 const double* const patch_dx = patch_geom->getDx();
84 for (int d = 0; d < NDIM; ++d)
85 {
86 coord[d] = patch_X_lower[d] + patch_dx[d] * (static_cast<double>(ci(d) - patch_lower_idx(d)) + 0.5);
87 }
88
89 // Distance from the semi-circle
90 distance1[0] = std::sqrt(std::pow((coord[0] - X0[0]), 2.0) + std::pow((coord[1] - X0[1]), 2.0)) - R;
91
92 // Distance from top triangle surface.
93 distance2[0] = std::abs(coord[1] - slope1 * coord[0] - y_intercept1) / std::sqrt(1.0 + slope1 * slope1);
94
95 check1 = (X1 - X3).cross(X_T - X3);
96 check2 = (X1 - X3).cross(coord - X3);
97
98 distance2[0] *= (-sgn(check1[2]) * sgn(check2[2]));
99

Callers

nothing calls this directly

Calls 5

crossMethod · 0.80
sgnFunction · 0.70
sqrtFunction · 0.50
powFunction · 0.50
absFunction · 0.50

Tested by

no test coverage detected