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

Method setDataOnPatch

examples/IBLevelSet/ex4/LevelSetInitialCondition.cpp:41–122  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

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