Changeset ac6d04 for src/interface
- Timestamp:
- Apr 10, 2012, 1:55:49 PM (14 years ago)
- Children:
- a40eea
- Parents:
- d24c2f
- Location:
- src/interface
- Files:
-
- 6 edited
-
interface.cpp (modified) (1 diff)
-
interface_fcs.cpp (modified) (8 diffs)
-
interface_fcs.h (modified) (1 diff)
-
interface_particles.cpp (modified) (9 diffs)
-
interface_particles.hpp (modified) (1 diff)
-
interface_particles_cf.cpp (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/interface/interface.cpp
rd24c2f rac6d04 23 23 const int& coarseningSteps, const vmg_float& alpha) 24 24 { 25 Index size_factor_max = 1; 26 int num_cells; 25 int i; 26 Index num_cells = Helper::intpow(2, levelMax); 27 Index size_factor; 27 28 28 29 const Vector box_center = box_offset + 0.5 * box_size; 29 30 30 for (i nt i=levelMax; i>=levelMin; --i) {31 for (i=0; i<coarseningSteps; ++i) { 31 32 32 33 global.push_back(GlobalIndices()); 33 34 extent.push_back(SpatialExtent()); 34 35 35 num_cells = Helper::intpow(2, i); 36 for (int j=0; j<3; ++j) 37 size_factor[j] = (bc[j] == Periodic ? 1 : Helper::intpow(2, static_cast<int>(log(pow(alpha, i+1)) / log(2.0) + 1.0))); 36 38 37 extent.back().SizeFactor() = 1; 38 extent.back().Size() = box_size; 39 extent.back().Begin() = box_offset; 40 extent.back().End() = box_offset + box_size; 41 extent.back().MeshWidth() = box_size / num_cells; 39 extent.back().Size() = box_size * static_cast<Vector>(size_factor); 40 extent.back().Begin() = box_center - 0.5 * extent.back().Size(); 41 extent.back().End() = extent.back().Begin() + extent.back().Size(); 42 extent.back().MeshWidth() = pow(2.0, i-levelMax); 42 43 43 global.back().SizeGlobal() = num_cells + 1; 44 global.back().SizeLocal() = num_cells + 1; 45 global.back().BeginFinest() = 0; 46 global.back().BeginLocal() = 0; 47 global.back().EndLocal() = num_cells + 1; 44 num_cells = Helper::intpow(2,levelMax-i) * size_factor; 48 45 49 if (i == levelMax) { 50 global.back().SizeFinest() = num_cells + 1; 51 global.back().EndFinest() = num_cells + 1; 52 global.back().BoundaryType() = GlobalMax; 46 global.back().GlobalSize() = num_cells + 1; 47 global.back().LocalSize() = num_cells + 1; 48 global.back().LocalBegin() = 0; 49 global.back().LocalEnd() = num_cells + 1; 50 51 global.back().FinestAbsSize() = Helper::intpow(2,i) * num_cells + 1; 52 global.back().FinestAbsBegin() = ((global.back().FinestAbsSize()-1) * (1-size_factor)) / (2*size_factor); 53 global.back().FinestAbsEnd() = global.back().FinestAbsBegin() + global.back().FinestAbsSize(); 54 55 if (i==0) 56 global.back().GlobalFinerBegin() = (num_cells - Helper::intpow(2, levelMax-i))/2; 57 else 58 global.back().GlobalFinerBegin() = (global.back().FinestAbsSize() - (++global.rbegin())->FinestAbsSize()) / Helper::intpow(2,i+1); 59 60 global.back().GlobalFinerEnd() = global.back().GlobalSize() - global.back().GlobalFinerBegin(); 61 global.back().GlobalFinerSize() = global.back().GlobalFinerEnd() - global.back().GlobalFinerBegin(); 62 63 global.back().LocalFinerBegin() = global.back().GlobalFinerBegin(); 64 global.back().LocalFinerEnd() = global.back().GlobalFinerEnd(); 65 global.back().LocalFinerSize() = global.back().GlobalFinerSize(); 66 } 67 68 while (global.size() == 0 || global.back().GlobalSize().Min() > Helper::intpow(2, levelMin)+1) { 69 70 if (global.size() > 0) 71 num_cells /= 2; 72 73 global.push_back(GlobalIndices()); 74 extent.push_back(SpatialExtent()); 75 76 if (global.size() == 1) { 77 extent.back().Size() = box_size; 78 extent.back().Begin() = box_offset; 79 extent.back().End() = box_offset + box_size; 80 extent.back().MeshWidth() = box_size / static_cast<Vector>(num_cells); 53 81 }else { 54 global.back().SizeFinest() = (++global.rbegin())->SizeFinest(); 55 global.back().EndFinest() = (++global.rbegin())->SizeFinest(); 56 global.back().BoundaryType() = GlobalCoarsened; 82 extent.back().Size() = (++extent.rbegin())->Size(); 83 extent.back().Begin() = (++extent.rbegin())->Begin(); 84 extent.back().End() = (++extent.rbegin())->End(); 85 extent.back().MeshWidth() = 2.0 * (++extent.rbegin())->MeshWidth(); 57 86 } 87 88 global.back().GlobalSize() = num_cells + 1; 89 global.back().LocalSize() = num_cells + 1; 90 global.back().LocalBegin() = 0; 91 global.back().LocalEnd() = num_cells + 1; 92 93 if (global.size() == 1) { 94 global.back().FinestAbsBegin() = 0; 95 global.back().FinestAbsEnd() = global.back().GlobalSize(); 96 global.back().FinestAbsSize() = global.back().GlobalSize(); 97 }else { 98 global.back().FinestAbsBegin() = (++global.rbegin())->FinestAbsBegin(); 99 global.back().FinestAbsEnd() = (++global.rbegin())->FinestAbsEnd(); 100 global.back().FinestAbsSize() = (++global.rbegin())->FinestAbsSize(); 101 } 102 103 global.back().GlobalFinerBegin() = 0; 104 global.back().GlobalFinerEnd() = global.back().GlobalSize(); 105 global.back().GlobalFinerSize() = global.back().GlobalSize(); 106 107 global.back().LocalFinerBegin() = global.back().GlobalFinerBegin(); 108 global.back().LocalFinerEnd() = global.back().GlobalFinerEnd(); 109 global.back().LocalFinerSize() = global.back().GlobalFinerSize(); 58 110 59 111 } 60 112 61 for (i nt i=0; i<3; ++i)113 for (i=0; i<3; ++i) 62 114 if (bc[i] == Periodic) 63 115 for (unsigned int j=0; j<global.size(); ++j) { 64 global[j].SizeGlobal()[i] -= 1; 65 global[j].SizeFinest()[i] -= Helper::intpow(2, j); 66 global[j].SizeLocal()[i] -= 1; 67 global[j].EndLocal()[i] -= 1; 68 global[j].EndFinest()[i] -= Helper::intpow(2, j); 116 global[j].GlobalSize()[i] -= 1; 117 global[j].FinestAbsSize()[i] -= Helper::intpow(2, j); 118 global[j].FinestAbsEnd()[i] -= Helper::intpow(2, j); 119 global[j].LocalSize()[i] -= 1; 120 global[j].LocalEnd()[i] -= 1; 121 global[j].GlobalFinerSize()[i] -= 1; 122 global[j].GlobalFinerEnd()[i] -= 1; 123 global[j].LocalFinerSize()[i] -= 1; 124 global[j].LocalFinerEnd()[i] -= 1; 69 125 } 70 126 71 127 levelMin = levelMax - global.size() + 1; 128 129 global.back().BoundaryType() = GlobalCoarsened; 130 131 for (i=global.size()-2; i>=0; --i) { 132 if (global[i].FinestAbsSize().Product() >= global[i+1].FinestAbsSize().Product()) { 133 global[i].BoundaryType() = GlobalCoarsened; 134 }else { 135 global[i].BoundaryType() = LocallyRefined; 136 global[i+1].BoundaryType() = GlobalMax; 137 break; 138 } 139 } 140 141 for (; i>=0; --i) 142 global[i].BoundaryType() = LocallyRefined; 143 144 if (global.front().BoundaryType() != LocallyRefined && 145 global.front().BoundaryType() != GlobalMax) 146 global.front().BoundaryType() = GlobalMax; 147 72 148 } -
src/interface/interface_fcs.cpp
rd24c2f rac6d04 17 17 18 18 #include <mpi.h> 19 #ifdef HAVE_MARMOT 20 #include <enhancempicalls.h> 21 #include <sourceinfompicalls.h> 22 #endif 19 23 20 24 #include "base/object.hpp" … … 22 26 #include "comm/comm_mpi.hpp" 23 27 #include "comm/domain_decomposition_mpi.hpp" 28 #include "comm/mpi/error_handler.hpp" 24 29 #include "interface/interface_fcs.h" 25 30 #include "interface/interface_particles.hpp" 26 31 #include "level/level_operator_cs.hpp" 32 #include "level/level_operator_fas.hpp" 27 33 #include "samples/discretization_poisson_fd.hpp" 34 #include "samples/discretization_poisson_fv.hpp" 28 35 #include "samples/stencils.hpp" 29 36 #include "samples/techniques.hpp" … … 70 77 VMGBackupSettings::mpi_comm = mpi_comm; 71 78 79 MPI_Errhandler mpiErrorHandler; 80 MPI_Comm_create_errhandler(VMG::MPI::ConvertToException, &mpiErrorHandler); 81 MPI_Comm_set_errhandler(MPI_COMM_WORLD, mpiErrorHandler); 82 72 83 const Boundary boundary(periodic[0] ? Periodic : Open, 73 84 periodic[1] ? Periodic : Open, … … 85 96 * Register particle interface. 86 97 */ 87 Interface* interface = new VMG::InterfaceParticles(boundary, 2, level, Vector(box_offset), box_size, near_field_cells); 98 Interface* interface; 99 if (singular) 100 interface = new InterfaceParticles(boundary, 2, level, Vector(box_offset), box_size, near_field_cells, 0, 1.0); 101 else 102 interface = new InterfaceParticles(boundary, 2, level, Vector(box_offset), box_size, near_field_cells, 2, 1.6); 88 103 MG::SetInterface(interface, comm); 89 104 90 105 /* 91 * Use a finite difference discretization of the Poisson equation 92 */ 93 Discretization* discretization = new DiscretizationPoissonFD(); 106 * Define discretization of the Poisson equation. 107 * Finite volumes for locally refined grids and 108 * finite differences otherwise. 109 */ 110 Discretization* discretization; 111 if (singular) 112 discretization = new DiscretizationPoissonFD(); 113 else 114 discretization = new DiscretizationPoissonFV(); 94 115 discretization->Register("DISCRETIZATION"); 95 116 … … 99 120 * with a half-weight version once debugging is finished. 100 121 */ 101 LevelOperator* lop = new LevelOperatorCS(Stencils::RestrictionFullWeight, Stencils::InterpolationTrilinear); 122 LevelOperator* lop; 123 if (singular) 124 lop = new LevelOperatorCS(Stencils::RestrictionFullWeight, Stencils::InterpolationTrilinear); 125 else 126 lop = new LevelOperatorFAS(Stencils::RestrictionFullWeight, Stencils::Injection, Stencils::InterpolationTrilinear); 102 127 lop->Register("LEVEL_OPERATOR"); 103 128 … … 126 151 */ 127 152 if (singular) 128 Techniques::SetCorrectionSchemePeriodic( 2, level, gamma);129 else 130 Techniques::Set CorrectionSchemeDirichlet(2, level, gamma);153 Techniques::SetCorrectionSchemePeriodic(interface->MinLevel(), interface->MaxLevel(), gamma); 154 else 155 Techniques::SetFullApproximationSchemeDirichlet(interface->MinLevel(), interface->MaxLevel(), gamma); 131 156 132 157 /* … … 137 162 new ObjectStorage<vmg_float>("PRECISION", precision); 138 163 new ObjectStorage<int>("MAX_ITERATION", max_iter); 139 140 164 new ObjectStorage<int>("PARTICLE_NEAR_FIELD_CELLS", near_field_cells); 141 165 … … 180 204 } 181 205 206 int VMG_fcs_check() 207 { 208 const int& near_field_cells = MG::GetFactory().GetObjectStorageVal<int>("PARTICLE_NEAR_FIELD_CELLS"); 209 const Multigrid& multigrid = *MG::GetRhs(); 210 const Grid& grid = multigrid(multigrid.MaxLevel()); 211 212 if (!grid.Global().LocalSize().IsComponentwiseGreater(near_field_cells)) 213 return 1; 214 215 return 0; 216 } 217 182 218 void VMG_fcs_run(vmg_float* x, vmg_float* q, vmg_float* p, vmg_float* f, vmg_int num_particles_local) 183 219 { -
src/interface/interface_fcs.h
rd24c2f rac6d04 13 13 #endif 14 14 15 void VMG_fcs_setup( vmg_int level, vmg_int* periodic, vmg_int max_iter,16 vmg_int smoothing_steps, vmg_int gamma, vmg_float precision,17 vmg_float* box_offset, vmg_float box_size,18 vmg_int near_field_cells, MPI_Comm mpi_comm);15 void VMG_fcs_setup(fcs_int level, fcs_int* periodic, fcs_int max_iter, 16 fcs_int smoothing_steps, fcs_int gamma, fcs_float precision, 17 fcs_float* box_offset, fcs_float box_size, 18 fcs_int near_field_cells, MPI_Comm mpi_comm); 19 19 20 void VMG_fcs_run(vmg_float* pos, vmg_float* charge, vmg_float* potential, vmg_float* f, vmg_int num_particles_local); 20 int VMG_fcs_check(); 21 22 void VMG_fcs_run(fcs_float* pos, fcs_float* charge, fcs_float* potential, fcs_float* f, fcs_int num_particles_local); 21 23 22 24 void VMG_fcs_print_timer(void); -
src/interface/interface_particles.cpp
rd24c2f rac6d04 14 14 #ifdef HAVE_MPI 15 15 #include <mpi.h> 16 #ifdef HAVE_MARMOT 17 #include <enhancempicalls.h> 18 #include <sourceinfompicalls.h> 19 #endif 16 20 #endif 17 21 … … 22 26 #include "base/index.hpp" 23 27 #include "base/linked_cell_list.hpp" 28 #include "base/math.hpp" 24 29 #include "base/vector.hpp" 25 30 #include "comm/comm.hpp" … … 42 47 const int& near_field_cells = factory.GetObjectStorageVal<int>("PARTICLE_NEAR_FIELD_CELLS"); 43 48 44 Grid& grid = multigrid(multigrid. GlobalMaxLevel());49 Grid& grid = multigrid(multigrid.MaxLevel()); 45 50 Grid& particle_grid = comm.GetParticleGrid(); 46 51 47 52 particle_grid.Clear(); 53 54 assert(particle_grid.Global().LocalSize().IsComponentwiseGreater(near_field_cells)); 48 55 49 56 /* … … 64 71 particle_charges = MG::GetComm()->GlobalSumRoot(particle_charges); 65 72 comm.PrintStringOnce("Particle list charge sum: %e", particle_charges); 73 comm.PrintString("Local number of particles: %d", particles.size()); 66 74 #endif 67 75 … … 76 84 for (index.Y()=0; index.Y()<grid.Local().Size().Y(); ++index.Y()) 77 85 for (index.Z()=0; index.Z()<grid.Local().Size().Z(); ++index.Z()) 78 grid(index + grid.Local().Begin()) = particle_grid.GetVal(index + particle_grid.Local().Begin());86 grid(index + grid.Local().Begin()) = 4.0 * Math::pi * particle_grid.GetVal(index + particle_grid.Local().Begin()); 79 87 80 88 #ifdef DEBUG_OUTPUT … … 98 106 vmg_float e_long = 0.0; 99 107 vmg_float e_self = 0.0; 108 vmg_float e_short = 0.0; 109 vmg_float e_shortcorr = 0.0; 100 110 #endif 101 111 … … 142 152 for (p_iter=particles.begin(); p_iter!=particles.end(); ++p_iter) { 143 153 144 // Interpolate long range part of potential 145 p_iter->Pot() = 0.5 * (Helper::InterpolateTrilinear(p_iter->Pos(), particle_grid) - p_iter->Charge() * spl.GetAntiDerivativeZero()); 146 147 #ifdef DEBUG_OUTPUT 154 // Interpolate long range part of potential minus self-interaction 155 p_iter->Pot() = Helper::InterpolateTrilinear(p_iter->Pos(), particle_grid) 156 - p_iter->Charge() * spl.GetAntiDerivativeAtZero(); 157 158 #ifdef DEBUG_OUTPUT 159 // TODO The scaling with 1/2 may not be correct. Check that. 148 160 e_long += 0.5 * p_iter->Charge() * Helper::InterpolateTrilinear(p_iter->Pos(), particle_grid); 149 e_self += 0.5 * p_iter->Charge() * p_iter->Charge() * spl.GetAntiDerivative Zero();161 e_self += 0.5 * p_iter->Charge() * p_iter->Charge() * spl.GetAntiDerivativeAtZero(); 150 162 #endif 151 163 152 164 } 153 154 comm.CommAddPotential(particles);155 165 156 166 /* … … 161 171 Grid::iterator iter; 162 172 163 comm.CommLCListGhosts(grid, lc); 164 165 for (iter=lc.Iterators().Local().Begin(); iter!=lc.Iterators().Local().End(); ++iter) 166 for (p1=lc(*iter).begin(); p1!=lc(*iter).end(); ++p1) 173 comm.CommLCListToGhosts(grid, lc); 174 175 for (iter=lc.Iterators().Local().Begin(); iter!=lc.Iterators().Local().End(); ++iter) { 176 std::list<Particle::Particle*>& lc_1 = lc(*iter); 177 for (p1=lc_1.begin(); p1!=lc_1.end(); ++p1) 167 178 for (index.X()=-1*near_field_cells-1; index.X()<=near_field_cells+1; ++index.X()) 168 179 for (index.Y()=-1*near_field_cells-1; index.Y()<=near_field_cells+1; ++index.Y()) 169 for (index.Z()=-1*near_field_cells-1; index.Z()<=near_field_cells+1; ++index.Z()) 170 for (p2=lc(*iter+index).begin(); p2!=lc(*iter+index).end(); ++p2) 180 for (index.Z()=-1*near_field_cells-1; index.Z()<=near_field_cells+1; ++index.Z()) { 181 std::list<Particle::Particle*>& lc_2 = lc(*iter+index); 182 for (p2=lc_2.begin(); p2!=lc_2.end(); ++p2) 171 183 if (*p1 != *p2) { 172 184 173 length = (p2->Pos() - p1->Pos()).Length(); 174 175 //TODO Rewrite this equation more efficiently 176 if (length < r_cut) 177 p1->Pot() += 0.5 * p2->Charge() / length * (0.25*M_1_PI + spl.EvaluatePotential(length)); 178 185 length = ((*p2)->Pos() - (*p1)->Pos()).Length(); 186 187 //TODO Rewrite this equation more efficiently 188 if (length < r_cut) { 189 (*p1)->Pot() += (*p2)->Charge() / length * (1.0 - spl.EvaluatePotential(length)); 190 191 #ifdef DEBUG_OUTPUT 192 e_short += 0.5 * (*p1)->Charge() * (*p2)->Charge() / length; 193 e_shortcorr -= 0.5 * (*p1)->Charge() * (*p2)->Charge() / length * spl.EvaluatePotential(length); 194 #endif 195 196 } 179 197 } 180 181 comm.CommAddPotential(lc); 198 } 199 } 200 201 comm.CommParticlesBack(particles); 182 202 183 203 #ifdef DEBUG_OUTPUT … … 185 205 186 206 for (int i=0; i<num_particles_local; ++i) 187 e += p[i] * q[i];207 e += 0.5 * p[i] * q[i]; 188 208 189 209 e = comm.GlobalSumRoot(e); 190 210 e_long = comm.GlobalSumRoot(e_long); 191 211 e_self = comm.GlobalSumRoot(e_self); 212 e_short = comm.GlobalSumRoot(e_short); 213 e_shortcorr = comm.GlobalSumRoot(e_shortcorr); 192 214 193 215 comm.PrintStringOnce("E_long: %e", e_long); 194 comm.PrintStringOnce("E_short: %e", e - e_long + e_self); 216 comm.PrintStringOnce("E_short: %e", e_short); 217 comm.PrintStringOnce("E_shortcorr: %e", e_shortcorr); 218 comm.PrintStringOnce("E_short*: %e", e - e_long + e_self); 195 219 comm.PrintStringOnce("E_self: %e", e_self); 196 220 comm.PrintStringOnce("E_total: %e", e); -
src/interface/interface_particles.hpp
rd24c2f rac6d04 31 31 InterfaceParticles(const Boundary& boundary, const int& levelMin, const int& levelMax, 32 32 const Vector& box_offset, const vmg_float& box_size, 33 const int& near_field_cells) : 34 Interface(boundary, levelMin, levelMax, box_offset, box_size, 0, 1.0), 33 const int& near_field_cells, 34 const int& coarsening_steps, const vmg_float& alpha) : 35 Interface(boundary, levelMin, levelMax, box_offset, box_size, coarsening_steps, alpha), 35 36 HasRequestVec(), 36 37 spl((near_field_cells+0.5)*Extent(MaxLevel()).MeshWidth().Max()) -
src/interface/interface_particles_cf.cpp
rd24c2f rac6d04 12 12 #ifdef HAVE_MPI 13 13 #include <mpi.h> 14 #ifdef HAVE_MARMOT 15 #include <enhancempicalls.h> 16 #include <sourceinfompicalls.h> 17 #endif 14 18 #endif 15 19 … … 119 123 comm->Register("COMM"); 120 124 121 Interface* interface = new InterfaceParticles(boundary, 2, max_level, 0.0, 1.0, near_field_cells );125 Interface* interface = new InterfaceParticles(boundary, 2, max_level, 0.0, 1.0, near_field_cells, 0, 1.0); 122 126 MG::SetInterface(interface, comm); 123 127
Note:
See TracChangeset
for help on using the changeset viewer.
