-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathTagLSRefinementCells.cpp
117 lines (93 loc) · 4.5 KB
/
TagLSRefinementCells.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
// ---------------------------------------------------------------------
//
// 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.
//
// ---------------------------------------------------------------------
// APPLICATION INCLUDES
#include <ibamr/app_namespaces.h>
#include "TagLSRefinementCells.h"
#include <CartesianGridGeometry.h>
#include <fstream>
// C++ INCLUDES
/////////////////////////////// STATIC ///////////////////////////////////////
void
callTagGasLSRefinementCellsCallbackFunction(const Pointer<BasePatchHierarchy<NDIM> > hierarchy,
const int level_number,
const double /*error_data_time*/,
const int tag_index,
const bool initial_time,
const bool /*uses_richardson_extrapolation_too*/,
void* ctx)
{
if (initial_time || level_number == hierarchy->getFinestLevelNumber()) return;
TagLSRefinementCells* ptr_ls_tagger = static_cast<TagLSRefinementCells*>(ctx);
TBOX_ASSERT(hierarchy);
TBOX_ASSERT((level_number >= 0) && (level_number < hierarchy->getFinestLevelNumber()));
TBOX_ASSERT(hierarchy->getPatchLevel(level_number));
// Get the current level set information
VariableDatabase<NDIM>* var_db = VariableDatabase<NDIM>::getDatabase();
const int ls_current_idx = var_db->mapVariableAndContextToIndex(
ptr_ls_tagger->d_ls_var, ptr_ls_tagger->d_adv_diff_solver->getCurrentContext());
// Tag cells based on the value of the level set variable
Pointer<PatchLevel<NDIM> > level = hierarchy->getPatchLevel(level_number);
for (PatchLevel<NDIM>::Iterator p(level); p; p++)
{
Pointer<Patch<NDIM> > patch = level->getPatch(p());
const Box<NDIM>& patch_box = patch->getBox();
Pointer<CellData<NDIM, int> > tags_data = patch->getPatchData(tag_index);
Pointer<CellData<NDIM, double> > ls_data = patch->getPatchData(ls_current_idx);
for (CellIterator<NDIM> ic(patch_box); ic; ic++)
{
const hier::Index<NDIM>& i = ic();
const double dist_norm = std::abs((*ls_data)(i)-ptr_ls_tagger->d_tag_value);
if (dist_norm <= ptr_ls_tagger->d_tag_abs_thresh)
{
(*tags_data)(i) = 1;
}
}
}
return;
} // callTagGasLSRefinementCellsCallBackFunction
void
callTagSolidLSRefinementCellsCallbackFunction(const Pointer<BasePatchHierarchy<NDIM> > hierarchy,
const int level_number,
const double /*error_data_time*/,
const int tag_index,
const bool initial_time,
const bool /*uses_richardson_extrapolation_too*/,
void* ctx)
{
TagLSRefinementCells* ptr_ls_tagger = static_cast<TagLSRefinementCells*>(ctx);
TBOX_ASSERT(hierarchy);
TBOX_ASSERT(level_number >= 0);
TBOX_ASSERT(hierarchy->getPatchLevel(level_number));
// Get the current level set information
VariableDatabase<NDIM>* var_db = VariableDatabase<NDIM>::getDatabase();
const int ls_current_idx = var_db->mapVariableAndContextToIndex(
ptr_ls_tagger->d_ls_var, ptr_ls_tagger->d_adv_diff_solver->getCurrentContext());
// Tag cells based on the value of the level set variable
Pointer<PatchLevel<NDIM> > level = hierarchy->getPatchLevel(level_number);
for (PatchLevel<NDIM>::Iterator p(level); p; p++)
{
Pointer<Patch<NDIM> > patch = level->getPatch(p());
const Box<NDIM>& patch_box = patch->getBox();
Pointer<CellData<NDIM, int> > tags_data = patch->getPatchData(tag_index);
Pointer<CellData<NDIM, double> > ls_data = patch->getPatchData(ls_current_idx);
for (CellIterator<NDIM> ic(patch_box); ic; ic++)
{
const hier::Index<NDIM>& i = ic();
const double dist = (*ls_data)(i);
if (dist <= ptr_ls_tagger->d_tag_abs_thresh)
{
(*tags_data)(i) = 1;
}
}
}
return;
} // callTagSolidLSRefinementCellsCallBackFunction