-
Notifications
You must be signed in to change notification settings - Fork 3
/
LevelSetInitialCondition.cpp
91 lines (75 loc) · 3.23 KB
/
LevelSetInitialCondition.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
// ---------------------------------------------------------------------
//
// Copyright (c) 2019 - 2022 by the IBAMR developers
// All rights reserved.
//
//
// IBAMR is free software and is distributed under the 3-clause BSD
// license. The full text of the license can be found in the file
// COPYRIGHT at the top level directory of IBAMR.
//
// ---------------------------------------------------------------------
#include "LevelSetInitialCondition.h"
/////////////////////////////// INCLUDES /////////////////////////////////////
// SAMRAI INCLUDES
#include <HierarchyDataOpsManager.h>
/////////////////////////////// PUBLIC ///////////////////////////////////////
LevelSetInitialCondition::LevelSetInitialCondition(const std::string& object_name, CylinderInterface init_cylinder)
: d_object_name(object_name), d_init_cylinder(init_cylinder)
{
// intentionally blank
return;
} // LevelSetInitialCondition
LevelSetInitialCondition::~LevelSetInitialCondition()
{
// intentionally blank
return;
} // ~LevelSetInitialCondition
bool
LevelSetInitialCondition::isTimeDependent() const
{
return true;
} // isTimeDependent
void
LevelSetInitialCondition::setDataOnPatch(const int data_idx,
Pointer<Variable<NDIM> > /*var*/,
Pointer<Patch<NDIM> > patch,
const double /*data_time*/,
const bool initial_time,
Pointer<PatchLevel<NDIM> > /*patch_level*/)
{
// Set the level set function throughout the domain
if (initial_time)
{
// Get the parameters for the interface
const double& R = d_init_cylinder.R;
const double& L = d_init_cylinder.L;
const Eigen::Vector3d& X0 = d_init_cylinder.X0;
double distance[3]; // 3D cylinder has three surfaces.
const Box<NDIM>& patch_box = patch->getBox();
Pointer<CellData<NDIM, double> > D_data = patch->getPatchData(data_idx);
for (Box<NDIM>::Iterator it(patch_box); it; it++)
{
CellIndex<NDIM> ci(it());
// Get physical coordinates
IBTK::Vector coord = IBTK::Vector::Zero();
Pointer<CartesianPatchGeometry<NDIM> > patch_geom = patch->getPatchGeometry();
const double* patch_X_lower = patch_geom->getXLower();
const hier::Index<NDIM>& patch_lower_idx = patch_box.lower();
const double* const patch_dx = patch_geom->getDx();
for (int d = 0; d < NDIM; ++d)
{
coord[d] = patch_X_lower[d] + patch_dx[d] * (static_cast<double>(ci(d) - patch_lower_idx(d)) + 0.5);
}
// Distance from the circular surface.
distance[0] = std::sqrt(std::pow((coord[0] - X0(0)), 2.0) + std::pow((coord[1] - X0(1)), 2.0)) - R;
// Distance from top circle.
distance[1] = coord[2] - (X0(2) + L / 2.0);
// Distance from bottom circle.
distance[2] = (X0(2) - L / 2.0) - coord[2];
(*D_data)(ci) = *std::max_element(distance, distance + 3);
}
}
return;
} // setDataOnPatch
//////////////////////////////////////////////////////////////////////////////