| 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 |
/** |
| 25 |
\example cubeGravity.cc |
| 26 |
*/ |
| 27 |
|
| 28 |
#include <aslDataInc.h> |
| 29 |
#include <acl/aclGenerators.h> |
| 30 |
#include <writers/aslVTKFormatWriters.h> |
| 31 |
#include <num/aslFDElasticity.h> |
| 32 |
#include <num/aslFDElasticityBC.h> |
| 33 |
#include <utilities/aslTimer.h> |
| 34 |
#include <utilities/aslParametersManager.h> |
| 35 |
#include <math/aslTemplates.h> |
| 36 |
#include <acl/aclMath/aclVectorOfElements.h> |
| 37 |
#include <aslGeomInc.h> |
| 38 |
#include <acl/aclUtilities.h> |
| 39 |
|
| 40 |
|
| 41 |
typedef float FlT; |
| 42 |
//typedef double FlT; |
| 43 |
typedef asl::UValue<FlT> Param; |
| 44 |
|
| 45 |
|
| 46 |
int main(int argc, char* argv[]) |
| 47 |
{ |
| 48 |
asl::ApplicationParametersManager appParamsManager("cubeGravity", "1.0"); |
| 49 |
asl::Parameter<asl::AVec<int> > size("size", "size 3D"); |
| 50 |
asl::Parameter<cl_float> dx("dx", "dx"); |
| 51 |
asl::Parameter<cl_float> dt("dt", "dt"); |
| 52 |
asl::Parameter<cl_float> bulkModulus("bulk_modulus", "bulk modulus"); |
| 53 |
asl::Parameter<cl_float> shearModulus("shear_modulus", "shear modulus"); |
| 54 |
asl::Parameter<cl_float> rho("rho", "density"); |
| 55 |
asl::Parameter<asl::AVec<FlT> > g("g", "gravity vector"); |
| 56 |
|
| 57 |
asl::Parameter<unsigned int> tsim("num_iterations", "number of iterations"); |
| 58 |
asl::Parameter<unsigned int> tout("num_it_out", "number of iterations between outputs"); |
| 59 |
|
| 60 |
appParamsManager.load(argc, argv); |
| 61 |
|
| 62 |
Param bulkModulusNum(bulkModulus.v()/rho.v()/dx.v()/dx.v()); |
| 63 |
Param shearModulusNum(shearModulus.v()/rho.v()/dx.v()/dx.v()); |
| 64 |
|
| 65 |
asl::AVec<FlT> gNum(g.v()/dx.v()); |
| 66 |
|
| 67 |
std::cout << "Data initialization... " << flush; |
| 68 |
|
| 69 |
asl::Block block(size.v(), dx.v()); |
| 70 |
auto displacement(asl::generateDataContainerACL_SP<FlT>(block, 3, 1u)); |
| 71 |
acl::initData(displacement->getEContainer(), acl::generateVEConstantN(3,0)); |
| 72 |
|
| 73 |
auto mapDF(asl::normalize(asl::generateDFInBlock(block, 0), dx.v())); |
| 74 |
auto map(asl::generateDataContainer_SP(block, mapDF, 1u, acl::typeToTypeID<FlT>())); |
| 75 |
auto mapX(asl::generateDataContainerACL_SP<FlT>(block, 1, 1u)); |
| 76 |
initData(mapX->getEContainer(), map->getEContainer()); |
| 77 |
|
| 78 |
|
| 79 |
asl::WriterVTKXML writer(appParamsManager.getDir() + "cubeGravity"); |
| 80 |
writer.addScalars("map", *mapX); |
| 81 |
writer.addVector("displacement", *displacement); |
| 82 |
writer.write(); |
| 83 |
|
| 84 |
std::cout << "Finished" << endl; |
| 85 |
|
| 86 |
std::cout << "Numerics initialization... " << flush; |
| 87 |
|
| 88 |
asl::SPFDElasticity2 elasticity(new asl::FDElasticity2(displacement, |
| 89 |
acl::generateVEConstant(bulkModulusNum.v()), |
| 90 |
acl::generateVEConstant(shearModulusNum.v()), |
| 91 |
acl::generateVEConstant(dt.v()), |
| 92 |
&asl::d3q15())); |
| 93 |
elasticity->setForce(acl::generateVEConstant(gNum)); |
| 94 |
elasticity->setDumpingFactor(acl::generateVEConstant(.9)); |
| 95 |
elasticity->init(); |
| 96 |
|
| 97 |
auto bcRigidWall(asl::generateBCRigidWall(elasticity, {asl::X0})); |
| 98 |
bcRigidWall->init(); |
| 99 |
|
| 100 |
auto bcFreeSurface(generateBCZeroStress(elasticity, mapX)); |
| 101 |
bcFreeSurface->init(); |
| 102 |
|
| 103 |
|
| 104 |
std::cout << "Finished" << endl; |
| 105 |
std::cout << "Computing..." << endl; |
| 106 |
asl::Timer timer; |
| 107 |
|
| 108 |
bcFreeSurface->execute(); |
| 109 |
bcRigidWall->execute(); |
| 110 |
|
| 111 |
|
| 112 |
timer.start(); |
| 113 |
for (unsigned int i(0); i < tsim.v(); ++i) |
| 114 |
{ |
| 115 |
elasticity->execute(); |
| 116 |
bcFreeSurface->execute(); |
| 117 |
bcRigidWall->execute(); |
| 118 |
if (!(i % tout.v())) |
| 119 |
{ |
| 120 |
cout << i << endl; |
| 121 |
writer.write(); |
| 122 |
} |
| 123 |
} |
| 124 |
timer.stop(); |
| 125 |
|
| 126 |
cout << "Finished" << endl; |
| 127 |
|
| 128 |
cout << "Computation statistic:" << endl; |
| 129 |
cout << "Real Time = " << timer.realTime() << "; Processor Time = " |
| 130 |
<< timer.processorTime() << "; Processor Load = " |
| 131 |
<< timer.processorLoad() * 100 << "%" << endl; |
| 132 |
|
| 133 |
return 0; |
| 134 |
} |