| 1 |
/* |
| 2 |
* Advanced Simulation Library <http://asl.org.il> |
| 3 |
* |
| 4 |
* Copyright 2015 Avtech Scientific <http://avtechscientific.com> |
| 5 |
* |
| 6 |
* |
| 7 |
* This file is part of Advanced Simulation Library (ASL). |
| 8 |
* |
| 9 |
* ASL is free software: you can redistribute it and/or modify it |
| 10 |
* under the terms of the GNU Affero General Public License as |
| 11 |
* published by the Free Software Foundation, version 3 of the License. |
| 12 |
* |
| 13 |
* ASL is distributed in the hope that it will be useful, |
| 14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 |
* GNU Affero General Public License for more details. |
| 17 |
* |
| 18 |
* You should have received a copy of the GNU Affero General Public License |
| 19 |
* along with ASL. If not, see <http://www.gnu.org/licenses/>. |
| 20 |
* |
| 21 |
*/ |
| 22 |
|
| 23 |
|
| 24 |
#include "aslFDMultiPhase.h" |
| 25 |
#include <aslGenerators.h> |
| 26 |
#include <acl/aclGenerators.h> |
| 27 |
#include <acl/acl.h> |
| 28 |
#include <math/aslTemplateVE.h> |
| 29 |
#include <acl/aclMath/aclVectorOfElements.h> |
| 30 |
|
| 31 |
#include <data/aslDataWithGhostNodes.h> |
| 32 |
#include <acl/Kernels/aclKernel.h> |
| 33 |
#include <math/aslTemplates.h> |
| 34 |
|
| 35 |
#include <acl/Kernels/aclKernelConfigurationTemplates.h> |
| 36 |
|
| 37 |
namespace asl |
| 38 |
{ |
| 39 |
FDMultiPhase::FDMultiPhase(): |
| 40 |
SingleKernelNM(acl::KERNEL_SIMDUA), |
| 41 |
cData(0), |
| 42 |
cInternalData(0), |
| 43 |
compressibilityCorrectionFlag(false), |
| 44 |
vectorTemplate(NULL) |
| 45 |
{ |
| 46 |
} |
| 47 |
|
| 48 |
|
| 49 |
FDMultiPhase::FDMultiPhase(Data c, |
| 50 |
const acl::VectorOfElements & dC, |
| 51 |
const acl::VectorOfElements & rC, |
| 52 |
const VectorTemplate* vT): |
| 53 |
SingleKernelNM(acl::KERNEL_SIMDUA), |
| 54 |
cData(1u, c), |
| 55 |
cInternalData(0u), |
| 56 |
compressibilityCorrectionFlag(false), |
| 57 |
vectorTemplate(vT), |
| 58 |
diffusionCoefficient(dC), |
| 59 |
repulsionConstant(rC) |
| 60 |
{ |
| 61 |
} |
| 62 |
|
| 63 |
void FDMultiPhase::init0() |
| 64 |
{ |
| 65 |
|
| 66 |
acl::TypeID type(getElementType(cData[0]->getDContainer())); |
| 67 |
|
| 68 |
cInternalData.resize(cData.size()); |
| 69 |
for (unsigned int i(0); i < cData.size(); ++i) |
| 70 |
cInternalData[i] = clone(cData[i]); |
| 71 |
acl::VectorOfElements cnew(acl::generateVEPrivateVariable(1, type)); |
| 72 |
std::unique_ptr<TemplateVE> f1; |
| 73 |
std::unique_ptr<TemplateVE> f2; |
| 74 |
std::unique_ptr<TemplateVE> phi; |
| 75 |
|
| 76 |
unsigned int nd(nD(*vectorTemplate)); |
| 77 |
|
| 78 |
vector<TemplateVE> velocityT(nd); |
| 79 |
if(velocity.get() != 0) |
| 80 |
for(unsigned int i(0); i < nd; ++i) |
| 81 |
{ |
| 82 |
velocityT[i].init(*velocity, *vectorTemplate, i); |
| 83 |
*(kernel) << velocityT[i].initValues; |
| 84 |
} |
| 85 |
|
| 86 |
TemplateVE cT; |
| 87 |
auto vOne(acl::generateVEConstantN(vectorTemplate->vectors.size(),1.)); |
| 88 |
for (unsigned int i(0); i < cData.size(); ++i) |
| 89 |
{ |
| 90 |
cT.init(*cData[i], *vectorTemplate); |
| 91 |
(*kernel) << cT.initValues; |
| 92 |
TemplateVE cTAbove(productOfElements((cT.values-vOne),.5*(sign(cT.values-vOne)+vOne)),*vectorTemplate); |
| 93 |
TemplateVE cTBelow(productOfElements(cT.values,.5*(vOne-sign(cT.values))),*vectorTemplate); |
| 94 |
|
| 95 |
(*kernel) << (cnew = |
| 96 |
diffusionCoefficient * laplas(cT) + |
| 97 |
0.15 * laplas(cTAbove) + |
| 98 |
0.15 * laplas(cTBelow) - |
| 99 |
repulsionConstant* laplas(cT - cT * cT) + |
| 100 |
cT.getValue(0)); |
| 101 |
if(velocity.get() != 0) |
| 102 |
{ |
| 103 |
(*kernel) << (cnew -= divProduct(velocityT, cT)); |
| 104 |
if(compressibilityCorrectionFlag) |
| 105 |
{ |
| 106 |
(*kernel) << (cnew /= (1. - div(velocityT))); |
| 107 |
} |
| 108 |
} |
| 109 |
(*kernel) << (assignmentSafe(cInternalData[i]->getSubContainer(), cnew)); |
| 110 |
} |
| 111 |
} |
| 112 |
|
| 113 |
|
| 114 |
void FDMultiPhase::postProcessing() |
| 115 |
{ |
| 116 |
for (unsigned int i(0); i < cData.size(); ++i) |
| 117 |
swapBuffers(cData[i]->getDContainer(), cInternalData[i]->getDContainer()); |
| 118 |
} |
| 119 |
|
| 120 |
|
| 121 |
void FDMultiPhase::setDiffusionCoefficient(acl::VectorOfElements dC) |
| 122 |
{ |
| 123 |
copy(dC,diffusionCoefficient); |
| 124 |
} |
| 125 |
|
| 126 |
|
| 127 |
void FDMultiPhase::addComponent(Data c) |
| 128 |
{ |
| 129 |
cData.push_back(c); |
| 130 |
} |
| 131 |
|
| 132 |
|
| 133 |
void FDMultiPhase::setVelocity(Field v, bool cCF) |
| 134 |
{ |
| 135 |
velocity=v; |
| 136 |
compressibilityCorrectionFlag=cCF; |
| 137 |
} |
| 138 |
|
| 139 |
SPFDMultiPhase generateFDMultiPhase(SPDataWithGhostNodesACLData c, |
| 140 |
SPAbstractDataWithGhostNodes v, |
| 141 |
const VectorTemplate* vt, |
| 142 |
bool compressibilityCorrection) |
| 143 |
{ |
| 144 |
auto nm(make_shared<FDMultiPhase> (c, |
| 145 |
acl::generateVEConstant(0.07), |
| 146 |
acl::generateVEConstant(0.1), |
| 147 |
vt)); |
| 148 |
nm->setVelocity(v,compressibilityCorrection); |
| 149 |
return nm; |
| 150 |
} |
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
} //asl |