source: ThirdParty/vmg/src/base/interface.cpp@ 33a694

Action_Thermostats Add_AtomRandomPerturbation Add_RotateAroundBondAction Add_SelectAtomByNameAction Adding_Graph_to_ChangeBondActions Adding_MD_integration_tests Adding_StructOpt_integration_tests AutomationFragmentation_failures Candidate_v1.6.1 ChangeBugEmailaddress ChangingTestPorts ChemicalSpaceEvaluator Docu_Python_wait EmpiricalPotential_contain_HomologyGraph_documentation Enhance_userguide Enhanced_StructuralOptimization Enhanced_StructuralOptimization_continued Example_ManyWaysToTranslateAtom Exclude_Hydrogens_annealWithBondGraph Fix_ChronosMutex Fix_StatusMsg Fix_StepWorldTime_single_argument Fix_Verbose_Codepatterns ForceAnnealing_goodresults ForceAnnealing_oldresults ForceAnnealing_tocheck ForceAnnealing_with_BondGraph ForceAnnealing_with_BondGraph_continued ForceAnnealing_with_BondGraph_continued_betteresults ForceAnnealing_with_BondGraph_contraction-expansion GeometryObjects Gui_displays_atomic_force_velocity IndependentFragmentGrids_IntegrationTest JobMarket_RobustOnKillsSegFaults JobMarket_StableWorkerPool PythonUI_with_named_parameters QtGui_reactivate_TimeChanged_changes Recreated_GuiChecks RotateToPrincipalAxisSystem_UndoRedo StoppableMakroAction TremoloParser_IncreasedPrecision TremoloParser_MultipleTimesteps Ubuntu_1604_changes
Last change on this file since 33a694 was 7faa5c, checked in by Frederik Heber <heber@…>, 8 years ago

Merge commit 'de061d9d851257a04e924d4472df4523d33bb08b' as 'ThirdParty/vmg'

  • Property mode set to 100644
File size: 5.7 KB
Line 
1/*
2 * vmg - a versatile multigrid solver
3 * Copyright (C) 2012 Institute for Numerical Simulation, University of Bonn
4 *
5 * vmg is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * vmg is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19/**
20 * @file interface.cpp
21 * @author Julian Iseringhausen <isering@ins.uni-bonn.de>
22 * @date Mon Apr 18 12:55:48 2011
23 *
24 * @brief VMG::Interface
25 *
26 */
27
28#ifdef HAVE_CONFIG_H
29#include <libvmg_config.h>
30#endif
31
32#include <algorithm>
33#include <cmath>
34
35#include "base/helper.hpp"
36#include "base/interface.hpp"
37
38using namespace VMG;
39
40void Interface::InitInterface(const Vector& box_offset, const vmg_float& box_size,
41 const int& max_boundary_nodes, const vmg_float& alpha)
42{
43 Index num_cells, size_factor;
44
45 const Index add_node = Index(bc[0]==Periodic ? 0 : 1,
46 bc[1]==Periodic ? 0 : 1,
47 bc[2]==Periodic ? 0 : 1);
48
49 const Index inner_boundary = Index(bc[0]==Open ? 2 : 0,
50 bc[1]==Open ? 2 : 0,
51 bc[2]==Open ? 2 : 0);
52
53
54 const Vector box_center = box_offset + 0.5 * box_size;
55
56 /*
57 * Get Extents
58 */
59 if (bc[0] == Open || bc[1] == Open || bc[2] == Open) {
60
61 //TODO: Change this to max_boundary_nodes at one point
62 while (global.size() == 0 ||
63 (bc[0] == Open && global.back().GlobalSize()[0] > Helper::intpow(2, levelMin)+1) ||
64 (bc[1] == Open && global.back().GlobalSize()[1] > Helper::intpow(2, levelMin)+1) ||
65 (bc[2] == Open && global.back().GlobalSize()[2] > Helper::intpow(2, levelMin)+1)) {
66
67 global.push_back(GlobalIndices());
68 extent.push_back(SpatialExtent());
69
70 for (int j=0; j<3; ++j)
71 size_factor[j] = (bc[j] == Open ? Helper::intpow(2, static_cast<int>(log(pow(alpha, global.size())) / log(2.0) + 1.0)) : 1);
72
73 num_cells = static_cast<Vector>(std::pow(2.0, levelMax-static_cast<int>(global.size())+1)) * size_factor + 0.5;
74
75 extent.back().MeshWidth() = box_size * static_cast<Vector>(size_factor) / num_cells;
76 extent.back().Size() = (num_cells + inner_boundary) * extent.back().MeshWidth();
77 extent.back().Begin() = box_center - 0.5 * extent.back().Size();
78 extent.back().End() = extent.back().Begin() + extent.back().Size();
79
80 global.back().LocalSize() = num_cells + add_node + inner_boundary;
81 global.back().LocalBegin() = -1 * (num_cells + inner_boundary) / 2;
82 global.back().LocalEnd() = (num_cells + inner_boundary) / 2 + add_node;
83
84 global.back().GlobalSize() = global.back().LocalSize();
85 global.back().GlobalBegin() = global.back().LocalBegin();
86 global.back().GlobalEnd() = global.back().LocalEnd();
87
88 global.back().GlobalSizeFinest() = Helper::intpow(2, global.size()-1) * (num_cells+inner_boundary) + add_node;
89 global.back().GlobalBeginFinest() = -1 * ((Helper::intpow(2, global.size()-1) * (num_cells + inner_boundary)) / 2);
90 global.back().GlobalEndFinest() = (Helper::intpow(2, global.size()-1) * (num_cells + inner_boundary)) / 2 + add_node;
91
92 global.back().BoundaryType() = LocallyRefined;
93
94 }
95
96 global.back().BoundaryType() = GlobalMax;
97
98 } else {
99
100 num_cells = Helper::intpow(2, levelMax);
101
102 global.push_back(GlobalIndices());
103 extent.push_back(SpatialExtent());
104
105 extent.back().Size() = box_size;
106 extent.back().Begin() = box_center - 0.5 * extent.back().Size();
107 extent.back().End() = extent.back().Begin() + extent.back().Size();
108 extent.back().MeshWidth() = extent.back().Size() / num_cells;
109
110 global.back().LocalSize() = num_cells + add_node;
111 global.back().LocalBegin() = -1 * num_cells/2;
112 global.back().LocalEnd() = num_cells/2 + add_node;
113
114 global.back().GlobalSize() = global.back().LocalSize();
115 global.back().GlobalBegin() = global.back().LocalBegin();
116 global.back().GlobalEnd() = global.back().LocalEnd();
117
118 global.back().GlobalSizeFinest() = global.back().LocalSize();
119 global.back().GlobalBeginFinest() = global.back().LocalBegin();
120 global.back().GlobalEndFinest() = global.back().LocalEnd();
121
122 global.back().BoundaryType() = GlobalMax;
123
124 }
125
126 while (global.back().GlobalSize().Min() > Helper::intpow(2, levelMin)+1) {
127
128 num_cells /= 2;
129
130 global.push_back(GlobalIndices());
131 extent.push_back(SpatialExtent());
132
133 extent.back().Size() = (++extent.rbegin())->Size();
134 extent.back().Begin() = (++extent.rbegin())->Begin();
135 extent.back().End() = (++extent.rbegin())->End();
136 extent.back().MeshWidth() = 2.0 * (++extent.rbegin())->MeshWidth();
137
138 global.back().LocalSize() = num_cells + add_node;
139 global.back().LocalBegin() = -1 * num_cells/2;
140 global.back().LocalEnd() = num_cells/2 + add_node;
141
142 global.back().GlobalSize() = global.back().LocalSize();
143 global.back().GlobalBegin() = global.back().LocalBegin();
144 global.back().GlobalEnd() = global.back().LocalEnd();
145
146 global.back().GlobalSizeFinest() = (++global.rbegin())->GlobalSizeFinest();
147 global.back().GlobalBeginFinest() = (++global.rbegin())->GlobalBeginFinest();
148 global.back().GlobalEndFinest() = (++global.rbegin())->GlobalEndFinest();
149
150 global.back().BoundaryType() = GlobalCoarsened;
151
152 }
153
154 levelMin = levelMax - global.size() + 1;
155}
Note: See TracBrowser for help on using the repository browser.