diff --git a/Common/DefaultOptions.h b/Common/DefaultOptions.h index fe3e73d1b099b5e5ec4a038daa5ed05807dc6371..a7dd1906ce8793f24ade025e12c9a6537c78c36c 100644 --- a/Common/DefaultOptions.h +++ b/Common/DefaultOptions.h @@ -1215,7 +1215,7 @@ StringXNumber MeshOptions_Number[] = { "Global scaling factor applied to the saved mesh" }, { F|O, "SecondOrderExperimental" , opt_mesh_second_order_experimental , 0. , "Use experimental code to generate second order mesh" }, - { F|O, "SecondOrderIncomplete" , opt_mesh_second_order_incomplete , 1. , + { F|O, "SecondOrderIncomplete" , opt_mesh_second_order_incomplete , 0. , "Create incomplete second order elements? (8-node quads, 20-node hexas, etc.)" }, { F|O, "SecondOrderLinear" , opt_mesh_second_order_linear , 0. , "Should second order vertices simply be created by linear interpolation?" }, diff --git a/Common/LuaBindings.cpp b/Common/LuaBindings.cpp index 6fe25b2e4a15519766456625c9a84b000c25bf17..9af7c869ed99bfe35cdf51085125019f6c05a55f 100644 --- a/Common/LuaBindings.cpp +++ b/Common/LuaBindings.cpp @@ -12,26 +12,10 @@ #include "luaFunction.h" #include "function.h" #include "GModel.h" -#include "dgGroupOfElements.h" -#include "dgDofContainer.h" -#include "dgConservationLawShallowWater2d.h" -#include "dgConservationLawShallowWater1d.h" -#include "dgConservationLawAdvection.h" -#include "dgConservationLawPerfectGas.h" -#include "dgConservationLawWaveEquation.h" -#include "dgConservationLawMaxwell.h" -#include "dgRungeKutta.h" -#include "dgRungeKuttaMultirate.h" -#include "dgSystemOfEquations.h" -#include "dgLimiter.h" -#include "dgTransformNodalValue.h" -#include "dgFunctionIntegrator.h" #include "Bindings.h" -#include "dgResidual.h" #include "drawContext.h" #include "GmshMessage.h" #include "linearSystemCSR.h" -#include "dgMesh2MeshProjection.h" extern "C" { #include "lua.h" @@ -309,7 +293,8 @@ void binding::interactiveSession() CTX::instance()->lock = lock; } -binding::binding(){ +binding::binding() +{ if(_instance){ Msg::Error("Only one instance of lua bindings is allowed"); } @@ -346,33 +331,11 @@ binding::binding(){ GVertex::registerBindings(this); MElement::registerBindings(this); MVertex::registerBindings(this); - dgBoundaryCondition::registerBindings(this); - dgConservationLaw::registerBindings(this); - dgConservationLawAdvectionDiffusionRegisterBindings(this); - dgConservationLawMaxwellRegisterBindings(this); - dgConservationLawShallowWater1dRegisterBindings(this); - dgConservationLawShallowWater2dRegisterBindings(this); - dgConservationLawWaveEquationRegisterBindings(this); - dgDofContainer::registerBindings(this); - dgGroupCollection::registerBindings(this); - dgLimiter::registerBindings(this); - dgTransformNodalValue::registerBindings(this); - dgPerfectGasLaw2dRegisterBindings(this); - dgResidual::registerBindings(this); - dgRungeKutta::registerBindings(this); - dgRungeKuttaMultirate43::registerBindings(this); - dgRungeKuttaMultirate22::registerBindings(this); - dgRungeKuttaMultirateConservative::registerBindings(this); - dgSlopeLimiterRegisterBindings(this); - dgSupraTransformNodalValueRegisterBindings(this); - dgSystemOfEquations::registerBindings(this); - dgFunctionIntegrator::registerBindings(this); fullMatrix<double>::registerBindings(this); function::registerBindings(this); gmshOptions::registerBindings(this); Msg::registerBindings(this); linearSystemCSRGmm<double>::registerBindings(this); - dgMesh2MeshProjection::registerBindings(this); } binding *binding::_instance=NULL; #endif diff --git a/Post/PViewDataList.h b/Post/PViewDataList.h index 923c1545b9d07cdcb4259f75df110f8e16fe7294..00b34deb0375b66862845bf920404c2699bdcf61 100644 --- a/Post/PViewDataList.h +++ b/Post/PViewDataList.h @@ -54,7 +54,6 @@ class PViewDataList : public PViewData { std::vector<double> &list, int nblist); void _getString(int dim, int i, int timestep, std::string &str, double &x, double &y, double &z, double &style); - void _splitCurvedElements(); public: PViewDataList(); ~PViewDataList(){} diff --git a/Solver/CMakeLists.txt b/Solver/CMakeLists.txt index 7d71f39788f90f4885abc9fd17643c3c2757aed3..7194342b31ca5407525f38a012b3cfc6e0983c0e 100644 --- a/Solver/CMakeLists.txt +++ b/Solver/CMakeLists.txt @@ -11,28 +11,10 @@ set(SRC SElement.cpp eigenSolver.cpp multiscaleLaplace.cpp - dgGroupOfElements.cpp - dgAlgorithm.cpp - dgRungeKutta.cpp - dgRungeKuttaMultirate.cpp - dgConservationLaw.cpp - dgConservationLawAdvection.cpp - dgSystemOfEquations.cpp - dgConservationLawShallowWater1d.cpp - dgConservationLawShallowWater2d.cpp - dgConservationLawWaveEquation.cpp - dgConservationLawMaxwell.cpp - dgConservationLawPerfectGas.cpp - dgLimiter.cpp - dgTransformNodalValue.cpp - dgResidual.cpp - dgDofContainer.cpp function.cpp functionDerivator.cpp luaFunction.cpp functionSpace.cpp - dgFunctionIntegrator.cpp - dgMesh2MeshProjection.cpp ) file(GLOB HDR RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.h) diff --git a/Solver/TESTCASES/Advection1D.lua b/Solver/TESTCASES/Advection1D.lua deleted file mode 100644 index f4a65368f1fc563af44bfdba8d08dd94eed913db..0000000000000000000000000000000000000000 --- a/Solver/TESTCASES/Advection1D.lua +++ /dev/null @@ -1,64 +0,0 @@ - ---[[ - Function for initial conditions ---]] - -function initial_condition( xyz , f ) - for i=0,xyz:size1()-1 do - x = xyz:get(i,0) - y = xyz:get(i,1) - z = xyz:get(i,2) - if (x>-0.3 and x<0.3) then - f:set (i, 0, 1) - else - f:set (i, 0, 0) - end - end -end - ---[[ - Example of a lua program driving the DG code ---]] - -model = GModel () -model:load ('edge.msh') -order=1 -dimension=1 - --- conservation law -law = dgConservationLawAdvectionDiffusion.advectionLaw(functionConstant({0.15,0,0})) - --- boundary condition -bndcondition=law:newOutsideValueBoundary(functionConstant({0})) -law:addBoundaryCondition('Left',bndcondition) -law:addBoundaryCondition('Right',bndcondition) - -groups = dgGroupCollection(model, dimension, order) -groups:buildGroupsOfInterfaces() - --- build Runge Kutta and limiter -rk=dgRungeKutta() -limiter = dgSlopeLimiter(law) -rk:setLimiter(limiter) - --- build solution vector -FS = functionLua(1, 'initial_condition', {functionCoordinates.get()}) -solution = dgDofContainer(groups, law:getNbFields()) -solution:L2Projection(FS) - -solution:exportMsh('output/init') -limiter:apply(solution) -solution:exportMsh('output/init_limit') - -print'*** solve ***' -local x = os.clock() -dt = 0.03 -for i=1,100 do - norm = rk:iterate44(law,dt,solution) - if (i % 20 == 0) then - print('|ITER|',i,'|NORM|',norm,'|DT|',dt,'|CPU|',os.clock() - x) - end - if (i % 200 == 0) then - solution:exportMsh(string.format('output/solution-%06d',i)) - end -end diff --git a/Solver/TESTCASES/Advection3D.lua b/Solver/TESTCASES/Advection3D.lua deleted file mode 100644 index 2b5eeccf38d078828d96b2c4440bbb35ef3e7a6a..0000000000000000000000000000000000000000 --- a/Solver/TESTCASES/Advection3D.lua +++ /dev/null @@ -1,52 +0,0 @@ - -model = GModel() -model:load('box.geo') -model:load('box.msh') -dg = dgSystemOfEquations(model) -dg:setOrder(1) - --- initial condition -function initial_condition(xyz ,f) - for i=0,xyz:size1()-1 do - x = xyz:get(i,0) - y = xyz:get(i,1) - z = xyz:get(i,2) - --f:set (i, 0, math.exp(-100*((x-0.5)^2))) - --f:set (i, 0, x ) - f:set (i, 0, math.sqrt((x-0.3)*(x-0.3)+(y-0.3)*(y-0.3)+z*z)-0.2) - --f:set(i, 0, math.exp((x-.3)*(x-.3)+(y-.3)*(y-.3)+z*z)-.2)) - end -end - --- conservation law --- advection speed -law = dgConservationLawAdvectionDiffusion.advectionLaw(functionConstant({0,0,0.15})) -dg:setConservationLaw(law) - --- boundary condition ---freestreem=law:newOutsideValueBoundary(functionConstant({0,0,0.15})) - -xyz = functionCoordinates.get() -freestream=law:newOutsideValueBoundary(functionLua(1,'initial_condition',{functionCoordinates:get()})) - -law:addBoundaryCondition('wall',law:new0FluxBoundary()) -law:addBoundaryCondition('inlet',freestream) -law:addBoundaryCondition('outlet',law:newSymmetryBoundary()) -law:addBoundaryCondition('symmetry',law:newSymmetryBoundary()) - -dg:setup() - -dg:L2Projection(functionLua(1,'initial_condition',{xyz})) -dg:exportSolution('output/Adv3D-00000') - -print'***exporting init solution ***' - --- main loop -n = 10 -for i=1,100*n do - norm = dg:RK44(0.03) - if (i % n == 0) then - print('iter',i,norm) - dg:exportSolution(string.format("output/Adv3D-%05d", i)) - end -end diff --git a/Solver/TESTCASES/AdvectionDiffusion.lua b/Solver/TESTCASES/AdvectionDiffusion.lua deleted file mode 100644 index 981314d0cdd2c8b09ec8d010c97ffa30f11bff3d..0000000000000000000000000000000000000000 --- a/Solver/TESTCASES/AdvectionDiffusion.lua +++ /dev/null @@ -1,37 +0,0 @@ -model = GModel () -model:load ('square.geo') -model:load ('square.msh') - -dg = dgSystemOfEquations (model) -dg:setOrder(1) - --- conservation law -law = dgConservationLawAdvectionDiffusion(functionConstant({0.15,0.05,0}),functionConstant({0.001})) -dg:setConservationLaw(law) - --- boundary condition -law:addBoundaryCondition('Border',law:newOutsideValueBoundary(functionConstant({0,0,0}))) - -dg:setup() - --- initial condition -function initial_condition( xyz , f ) - for i=0,xyz:size1()-1 do - x = xyz:get(i,0) - y = xyz:get(i,1) - z = xyz:get(i,2) - f:set (i, 0, math.exp(-100*((x-0.2)^2 +(y-0.3)^2))) - end -end -dg:L2Projection(functionLua(1,'initial_condition',{functionCoordinates.get()})) - -dg:exportSolution('output/Advection_00000') - --- main loop -for i=1,10000 do - norm = dg:RK44(0.001) - if (i % 10 == 0) then - print('iter',i,norm) - dg:exportSolution(string.format("output/Advection-%05d", i)) - end -end diff --git a/Solver/TESTCASES/Advection_1.lua b/Solver/TESTCASES/Advection_1.lua deleted file mode 100644 index 57198d6827aa0ad2ac6f6a328af2217f63369554..0000000000000000000000000000000000000000 --- a/Solver/TESTCASES/Advection_1.lua +++ /dev/null @@ -1,69 +0,0 @@ -model = GModel () -print'*** Loading the geo ***' -model:load ('square_m.geo') --- model:load ('square_p.geo') -print'*** Loading the mesh ***' -model:load ('square_m.msh') --- model:load('square_p.msh') -print'*** mesh loaded ***' -dg = dgSystemOfEquations (model) -order=3 -dg:setOrder(order) -print("*** order = " .. order .. " ***") -print'*** Model set ***' - -print("*** set initial condition ***") --- initial condition -function initial_condition( xyz , f ) - for i=0,xyz:size1()-1 do - x = xyz:get(i,0) - y = xyz:get(i,1) - z = xyz:get(i,2) - f:set (i, 0, math.exp(-100*((x+0.2)^2 +(y+0.3)^2))) - end -end - --- conservation law --- advection speed -v=fullMatrix(3,1); -v:set(0,0,0.01) -v:set(1,0,0.025) -v:set(2,0,0) ---print("*** set advection speed to: v_x=" .. v:get(0,0) ..", v_y=" .. v:get(1,0) .. ", v_z=" .. v:get(2,0) .. " ***") -law = dgConservationLawAdvectionDiffusion(functionConstant(v):getName(),'') -dg:setConservationLaw(law) - -print("*** set boundary conditions *** ") --- boundary condition -outside=fullMatrix(1,1) -outside:set(0,0,0.0) -bndcondition=law:newOutsideValueBoundary(functionConstant(outside):getName()) -law:addBoundaryCondition('Border',bndcondition) - ---dg:setup() --- create 2 groups of elements; criterion=maxEdge -dg:createGroups("maxEdge") --- dg:createGroups("minEdge") --- dg:createGroups("elementType") - -dg:L2Projection(functionLua(1,'initial_condition',{'XYZ'}):getName()) - -dg:exportSolution('output/Advection_00000') - -dg:computeInvSpectralRadius(); -T=40 -dt=0.1 - -print("*** default time step (dt)=" .. dt .. ", Period (T)=" ..T .." ***") - -N=T/dt -print("*** Number of time steps=" .. N .. " ***") --- main loop -for i=1,N do - norm = dg:multirateRK43(dt) - print('iter',i,norm) - if (i % 20 == 0) then - dg:exportSolution(string.format("output/Advection_%05d", i)) - end -end -print '*** adding the mesh and the model ***' diff --git a/Solver/TESTCASES/Aorta.lua b/Solver/TESTCASES/Aorta.lua deleted file mode 100644 index d1fc49859a40ae54e43b2c536a8ca45cf00b0a4a..0000000000000000000000000000000000000000 --- a/Solver/TESTCASES/Aorta.lua +++ /dev/null @@ -1,121 +0,0 @@ ---[[ - Function for initial conditions - CGS UNITS ---]] - -t=0 -Ainit = 3.0 -T= 0.05 -Amax = 0.01 -p0 = 0.0 -rho = 1.06 ---c = 500 ---beta = 2*rho*math.pow(c,2)/math.sqrt(A0) -beta = 282166 ---KR = 8*math.pi*0.04/rho -KR = 0.0 - ---[[ - Functions ---]] - -function initial_condition( xyz , f ) - for i=0,xyz:size1()-1 do - f:set (i, 0, 0) - f:set (i, 1, 0) - end -end - -function inlet( FCT ) - FCT:set(0,0,Amax*math.sin(2*math.pi*t/T)*math.atan(1000*(T/2-t))) - --FCT:set(0,0, Amax) - FCT:set(0,1, 0) -end - -function pressureFlux (solution, bathymetry, f) - for i=0,f:size1()-1 do - A0 = bathymetry:get(i,0) - A = A0 + solution:get(i,0) - p = p0 + beta*(math.sqrt(A)-math.sqrt(A0)) - f:set (i, 0, p) - end -end - -function celerityFunction (solution, bathymetry, f) - for i=0,f:size1()-1 do - A0 = bathymetry:get(i,0) - c = math.sqrt(beta/(2*rho))*math.pow(A0, 0.25) - f:set (i, 0, c) - end -end - - -function characteristicFunction (solution, celerity, f) - for i=0,f:size1()-1 do - W1 = sol:get(i,1) + 4*celerity:get(i,0) - W2 = sol:get(i,1) - 4*celerity:get(i,0) - f:set (i, 0, W1) - f:set (i, 1, W2) - end -end - ---[[ - Example of a lua program driving the DG code ---]] - -order=1 -dimension=1 - -model = GModel() -model:load('aorta.msh') ---options = gmshOptions() ---model:load ('aorta.geo') ---options:numberSet('Mesh',-1,'ElementOrder',order) ---model:mesh(dimension) ---model:save('aorta.msh') - -bathymetry = functionConstant({Ainit}) -dissipation = functionConstant({KR}) -pressure = functionLua(1,'pressureFlux', {functionSolution.get(), bathymetry}) -pwv = functionLua(1,'celerityFunction', {functionSolution.get(), bathymetry}) ---chars = functionLua(1,'characteristicFunction', {functionSolution.get(), pwv}) - --- boundary condition -inlet_bc = functionLua(2, 'inlet') -law = dgConservationLawShallowWater1d() -law:addBoundaryCondition('Inlet',law:newOutsideValueBoundary(inlet_bc)) -law:addBoundaryCondition('Outlet',law:newBoundaryWall()) -law:setLinearDissipation(dissipation) -law:setBathymetry(bathymetry) -law:setPressureFlux(pressure) -law:setCelerity(pwv) ---law:setCharacteristicFunction(chars) - -groups = dgGroupCollection(model, dimension, order) -groups:buildGroupsOfInterfaces() - -rk=dgRungeKutta() - -print'*** print projetion ***' --- build solution vector -FS = functionLua(2, 'initial_condition', {functionCoordinates.get()}) -solution = dgDofContainer(groups, law:getNbFields()) -solution:L2Projection(FS) - -print'*** print initial sol ***' -solution:exportMsh('output/init') - -print'*** solve ***' -CFL = 0.2; -x = os.clock() -for i=1,10000 do - dt = CFL * rk:computeInvSpectralRadius(law,solution); - t = t+dt - norm = rk:iterate44(law,dt,solution) - if (i % 100 == 0) then - print('|ITER|',i,'|NORM|',norm,'|DT|',dt, '|t|', t, '|CPU|',os.clock() - x) - end - if (i % 100 == 0) then - solution:exportMsh(string.format('output/solution-%06d', i)) - end -end diff --git a/Solver/TESTCASES/ConservationTestMRAdvection.lua b/Solver/TESTCASES/ConservationTestMRAdvection.lua deleted file mode 100644 index 32cb24bd49afd7c1fa2a679689d672dd6e2d62e9..0000000000000000000000000000000000000000 --- a/Solver/TESTCASES/ConservationTestMRAdvection.lua +++ /dev/null @@ -1,255 +0,0 @@ -PI = 3.14159 --- Defining functions - -function initial_condition( XYZ, FCT ) - for i=0,XYZ:size1()-1 do - X = XYZ:get(i,0) - Y = XYZ:get(i,1)+0.12 - V = math.exp(-(X*X+Y*Y)*100) - FCT:set(i,0,V) - end -end - -function velocity( XYZ, FCT ) - for i=0,XYZ:size1()-1 do - X = XYZ:get(i,0) - Y = XYZ:get(i,1) - FCT:set(i,0,0) - FCT:set(i,1,1) - FCT:set(i,2,0) - end -end - -function toIntegrate( sol, FCT ) - for i=0,sol:size1()-1 do - s = sol:get(i,0) - FCT:set(i,0,s) - end -end - -order = 1 -dimension = 2 -print'*** Loading the mesh and the model ***' -myModel = GModel () - myModel:load ('rect.geo') -if (order == 1) then - myModel:load ('rect.msh') -elseif (order == 2) then - myModel:load ('rect2.msh') -elseif (order == 3) then - myModel:load ('rect3.msh') -elseif (order == 4) then - myModel:load ('rect4.msh') -elseif (order == 5) then - myModel:load ('rect5.msh') -end - -print'*** Create a dg solver ***' - ---functions -xyzF = functionCoordinates.get() -velF = functionLua(3, 'velocity', {xyzF}) -nuF = functionConstant({0}) - ---Conservation laws -law=dgConservationLawAdvectionDiffusion(velF,nuF) - ---Add the boundary conditions -law:addBoundaryCondition('Walls',law:new0FluxBoundary()) -law:addBoundaryCondition('Top',law:new0FluxBoundary()) - ---Fix initial condition -FS = functionLua(1, 'initial_condition', {xyzF}) - --- Creating the different "base" Element groups before splitting them (if multirate) - --- Singlerate -GC0=dgGroupCollection(myModel,dimension,order) -solTmp0=dgDofContainer(GC0,1) -solTmp0:L2Projection(FS) -GC0:buildGroupsOfInterfaces(); - -GC1=dgGroupCollection(myModel,dimension,order) -solTmp1=dgDofContainer(GC1,1) -solTmp1:L2Projection(FS) -GC1:buildGroupsOfInterfaces(); - ---Multirate -GC2=dgGroupCollection(myModel,dimension,order) -solTmp2=dgDofContainer(GC2,1) -solTmp2:L2Projection(FS) - -GC3=dgGroupCollection(myModel,dimension,order) -solTmp3=dgDofContainer(GC3,1) -solTmp3:L2Projection(FS) - -GC4=dgGroupCollection(myModel,dimension,order) -solTmp4=dgDofContainer(GC4,1) -solTmp4:L2Projection(FS) - --- Example of Conservative Multirate scheme with Butcher tables as input (here RK2a) -A=fullMatrix(2, 2) -A:set(0, 0, 0) -A:set(0, 1, 0) -A:set(1, 0, 1) -A:set(1, 1, 0) - -b=fullMatrix(1, 2) -b:set(0, 0, 0.5) -b:set(0, 1, 0.5) - -c=fullMatrix(1, 2) -c:set(0, 0, 0) -c:set(0, 1, 1) - --- Building the RK objects - --- RK2a -print'--- RK2a ---' -RK2a=dgRungeKutta() ---dt0=RK2a:splitForMultirate(100, solTmp) --- RK43 -print'--- RK43 ---' -RK43=dgRungeKutta() ---dt1=RK43:splitForMultirate(100, solTmp) - --- Multirate RK2a - --- *** Default Multirate RK2a *** ---multirateRK2a=dgRungeKuttaMultirate22(GC,law) - --- *** Multirate RK2a with as input the butcher tables *** -print'--- multirateRK2a ---' -multirateRK2a=dgRungeKuttaMultirateConservative(GC2, law, A, b, c) -dt2=multirateRK2a:splitForMultirate(10, solTmp2) - --- Multirate RK43 -print'--- multirateRK43 ---' -multirateRK43=dgRungeKuttaMultirate43(GC3,law) -dt3=multirateRK43:splitForMultirate(10, solTmp3) - --- Multirate RK2b -print'--- multirateRK2b ---' -multirateRK2b=dgRungeKuttaMultirateConservative.new2b(GC4, law) --- multirateRK2b:printButcher() -dt4=multirateRK2b:splitForMultirate(10, solTmp4) - -dt0=dt2 -dt1=dt2 - -solution0=dgDofContainer(GC0,1) -solution1=dgDofContainer(GC1,1) -solution2=dgDofContainer(GC2,1) -solution3=dgDofContainer(GC3,1) -solution4=dgDofContainer(GC4,1) - -solution0:L2Projection(FS) -solution1:L2Projection(FS) -solution2:L2Projection(FS) -solution3:L2Projection(FS) -solution4:L2Projection(FS) - -solution4:exportGroupIdMsh() - -print'---- Groups splitted ----' - -print'*** setting the initial solution ***' - -solution0:exportMsh(string.format("outputSinglerate/adv_sr2a-%06d", 0)) -solution1:exportMsh(string.format("outputSinglerate/adv_sr43-%06d", 0)) -solution2:exportMsh(string.format("outputMultirate/adv_mr2a-%06d", 0)) -solution3:exportMsh(string.format("outputMultirate/adv_mr43-%06d", 0)) -solution4:exportMsh(string.format("outputMultirate/adv_mr2b-%06d", 0)) -print'*** solve ***' - -LC = 0.1*.1 -print('DT=',dt0) - -norm0=solution0:norm() -norm1=solution1:norm() -norm2=solution2:norm() -norm3=solution3:norm() -norm4=solution4:norm() - -print('Norm: ', norm0, norm1, norm2, norm3, norm4) -time0=0 -time1=0 -time2=0 -time3=0 -time4=0 -i=0 -integrator=dgFunctionIntegrator(functionLua(1, 'toIntegrate', {functionSolution.get()})) - -print('*** ITER-START ***') -w0=fullMatrix(1,1); -w1=fullMatrix(1,1); -w2=fullMatrix(1,1); -w3=fullMatrix(1,1); -w4=fullMatrix(1,1); - -integrator:compute(solution0,w0) -integrator:compute(solution1,w1) -integrator:compute(solution2,w2) -integrator:compute(solution3,w3) -integrator:compute(solution4,w4) - -w0ref=w0:get(0,0,0) -w1ref=w1:get(0,0,0) -w2ref=w2:get(0,0,0) -w3ref=w3:get(0,0,0) -w4ref=w4:get(0,0,0) - -print'*****************************************' -print('integral (SR2a) : ',w0:get(0,0,0)) -print('integral (SR43) : ',w1:get(0,0,0)) -print('integral (MR2a) : ',w2:get(0,0,0)) -print('integral (MR43) : ',w3:get(0,0,0)) -print('integral (MR2b) : ',w4:get(0,0,0)) -print'******************************************' - -while i<100 do - --iterate - norm0 = RK2a:iterate22(law, dt0, solution0) - norm1 = RK43:iterate43SchlegelJCAM2009(law, dt1, solution1) - norm2 = multirateRK2a:iterate(dt2, solution2) - norm3 = multirateRK43:iterate(dt3, solution3) - norm4 = multirateRK2b:iterate(dt4, solution4) - - --updating time - time0=time0+dt0 - time1=time1+dt1 - time2=time2+dt2 - time3=time3+dt3 - time4=time4+dt4 - - if (i % 10 == 0) then - print('*** ITER ***',i) - print'-----------------------------------------' - integrator:compute(solution0, w0) - integrator:compute(solution1, w1) - integrator:compute(solution2, w2) - integrator:compute(solution3, w3) - integrator:compute(solution4, w4) - - print('integral (SR2a) : ',w0:get(0,0,0)) - print('integral (SR43) : ',w1:get(0,0,0)) - print('integral (MR2a) : ',w2:get(0,0,0)) - print('integral (MR43) : ',w3:get(0,0,0)) - print('integral (MR2b) : ',w4:get(0,0,0)) - - print(string.format("Mass conservation relative error:\n SR2a=%0.16e,\n SR43=%0.16e,\n MR2a=%0.16e,\n MR43=%0.16e,\n MR2b=%0.16e",math.abs((w0ref-w0:get(0,0,0))/w0ref), math.abs((w1ref-w1:get(0,0,0))/w1ref),math.abs((w2ref-w2:get(0,0,0))/w2ref),math.abs((w3ref-w3:get(0,0,0))/w3ref), math.abs((w4ref-w4:get(0,0,0))/w4ref))); - print'-----------------------------------------' - end - if (i % 10 == 0) then - solution0:exportMsh(string.format("outputSinglerate/adv_sr2a-%06d", i)) - solution1:exportMsh(string.format("outputSinglerate/adv_sr43-%06d", i)) - solution2:exportMsh(string.format("outputMultirate/adv_mr2a-%06d", i)) - solution3:exportMsh(string.format("outputMultirate/adv_mr43-%06d", i)) - solution4:exportMsh(string.format("outputMultirate/adv_mr2b-%06d", i)) - end - i=i+1 -end - -print'*** done ***' - - diff --git a/Solver/TESTCASES/ConvergenceMultirate.lua b/Solver/TESTCASES/ConvergenceMultirate.lua deleted file mode 100644 index c2968487d690df7743f5a164f9c68bb94dda70bf..0000000000000000000000000000000000000000 --- a/Solver/TESTCASES/ConvergenceMultirate.lua +++ /dev/null @@ -1,123 +0,0 @@ -PI = 3.14159 - ---[[ - Function for initial conditions ---]] -function initial_condition( XYZ , FCT ) - for i=0,XYZ:size1()-1 do - X = XYZ:get(i,0) - Y = XYZ:get(i,1) - -- +0.12 - V = X*X*Y*Y - -- math.exp(-(X*X+Y*Y)*100) - FCT:set(i,0,V) - end -end -function velocity( XYZ, FCT ) - for i=0,XYZ:size1()-1 do - X = XYZ:get(i,0) - Y = XYZ:get(i,1) - FCT:set(i,0,0) - FCT:set(i,1,1) - FCT:set(i,2,0) - end -end - -function L2Norm( sol, FCT ) - for i=0,sol:size1()-1 do - s = sol:get(i,0) - FCT:set(i,0,s*s) - end -end -function solF( sol, FCT ) - for i=0,sol:size1()-1 do - s = sol:get(i,0) - FCT:set(i,0,s) - end -end ---[[ - Example of a lua program driving the DG code ---]] - -order = 1 -print'*** Loading the mesh and the model ***' -myModel = GModel () - myModel:load ('rect.geo') -if (order == 1) then - myModel:load ('rect.msh') -elseif (order == 2) then - myModel:load ('rect2.msh') -elseif (order == 3) then - myModel:load ('rect3.msh') -elseif (order == 4) then - myModel:load ('rect4.msh') -elseif (order == 5) then - myModel:load ('rect5.msh') -end - -print'*** Create a dg solver ***' -xyzF = functionCoordinates.get() -velF = functionLua(3, 'velocity', {xyzF}) -nuF = functionConstant({0}) -law = dgConservationLawAdvectionDiffusion(velF, nuF) - --- law:addBoundaryCondition('Walls',law:newOutsideValueBoundary(functionConstant(g))) --- law:addBoundaryCondition('Top',law:newOutsideValueBoundary(functionConstant(g))) -law:addBoundaryCondition('Walls',law:new0FluxBoundary()) -law:addBoundaryCondition('Top',law:new0FluxBoundary()) -FS = functionLua(1, 'initial_condition', {xyzF}) -GC=dgGroupCollection(myModel,2,order) -solTmp=dgDofContainer(GC,1) -solTmp:L2Projection(FS) -dt=GC:splitGroupsForMultirate(20,1,2,law,solTmp) -GC:buildGroupsOfInterfaces(myModel,2,order) -solution=dgDofContainer(GC,1) -solutionRef=dgDofContainer(GC,1) -solutionRef:L2Projection(FS) -solution:exportGroupIdMsh() -solution:exportMultirateGroupMsh() -solutionRef:exportMsh("solution") - -nRefSteps=40 -dtRef=dt/nRefSteps -RK=dgRungeKutta() -print'Compute reference solution' -for i=1,nRefSteps do - RK:iterate44(law,dtRef,solutionRef) - if(i%10==0) then - print('it ',i) - end -end - ---multirateRK=dgRungeKuttaMultirate43(GC,law) -multirateRK=dgRungeKuttaMultirate22(GC,law) -integrator=dgFunctionIntegrator(functionLua(1, 'L2Norm', {functionSolution.get()})) -intSol=dgFunctionIntegrator(functionLua(1, 'solF', {functionSolution.get()})) - -oldnorm=1 -for n=0,3 do - solution:L2Projection(FS) - print('solnorm ',solution:norm()) - sN1=fullMatrix(1,1) - intSol:compute(solution,sN1) - print(string.format("solution integral before: %0.16e",sN1:get(0,0))) - for i=1,2^n do - multirateRK:iterate(dt/(2^n),solution) - print('it ',i) - end - sN2=fullMatrix(1,1) - intSol:compute(solution,sN2) - print(string.format("solution integral after: %0.16e",sN2:get(0,0))) - print(string.format("Mass conservation relative error: %0.16e",(sN1:get(0,0)-sN2:get(0,0))/sN1:get(0,0) )) - solution:axpy(solutionRef,-1) - lsq=fullMatrix(1,1) - integrator:compute(solution,lsq) - norm=math.sqrt(lsq:get(0,0)) - print(string.format("L2 norm for dt/%d %e",2^n,norm)) - if ( n~=0 ) then - print(string.format("oldnorm/norm: %f",oldnorm/norm)) - print(string.format("Convergence rate: %f",math.log(oldnorm/norm)/math.log(2))) - end - oldnorm=norm - solution:exportMsh("solution") -end diff --git a/Solver/TESTCASES/CylinderEddies.lua b/Solver/TESTCASES/CylinderEddies.lua deleted file mode 100644 index 1d0eecb70c38bd0ab2b5a9e50e5ec5f82c15227d..0000000000000000000000000000000000000000 --- a/Solver/TESTCASES/CylinderEddies.lua +++ /dev/null @@ -1,77 +0,0 @@ -MACH = .05; -RHO = 1.0; -PRES = 1./(MACH*RHO*RHO*1.4*1.4) -V = 1 -SOUND = V/MACH - ---[[ - Function for initial conditions ---]] -function free_stream( XYZ, FCT ) - for i=0,XYZ:size1()-1 do - FCT:set(i,0,RHO) - FCT:set(i,1,RHO*V) - FCT:set(i,2,0.0) - FCT:set(i,3, 0.5*RHO*V*V+PRES/0.4) - end -end - ---[[ - Example of a lua program driving the DG code ---]] - -order = 4 -xyz = functionCoordinates.get() -FS = functionLua(4, 'free_stream', {xyz}) - --- diffusivity - -print'*** Loading the mesh and the model ***' -myModel = GModel () -myModel:load ('cyl2.geo') -myModel:load ('cyl2.msh') - -print'*** Create a dg solver ***' -DG = dgSystemOfEquations (myModel) -DG:setOrder(order) -law=dgPerfectGasLaw2d() - -law:setViscosityAndThermalConductivity(functionConstant({0.025}),functionConstant({0.01})); - -DG:setConservationLaw(law) -law:addBoundaryCondition('Cylinder',law:newNonSlipWallBoundary()) -law:addBoundaryCondition('Box' ,law:newOutsideValueBoundary(FS)) - -DG:setup() - -print'*** setting the initial solution ***' - -DG:L2Projection(FS) - ---print'*** export ***' - -DG:exportSolution('output/cyl_0') - -print'*** solve ***' - -CFL = 4.2; -dt = CFL * DG:computeInvSpectralRadius(); -print('DT = ',dt) -T = 0; -x = os.clock() -for i=1,100000 do - dt = CFL * DG:computeInvSpectralRadius(); - norm = DG:RK44(dt) - T = T + dt - if (i % 10 == 0) then - print('*** ITER ***',i,norm,dt,T,os.clock() - x) - end - if (i % 100 == 0) then --- DG:exportSolution(string.format("output/cyl-%06d", i)) --- DG:saveSolution(string.format("output/cyl-%06d.bin", i)) - end -end - -print'*** done ***' - - diff --git a/Solver/TESTCASES/DamBreak.lua b/Solver/TESTCASES/DamBreak.lua deleted file mode 100644 index 318f5735a7de452265b4726df74de98f90aab865..0000000000000000000000000000000000000000 --- a/Solver/TESTCASES/DamBreak.lua +++ /dev/null @@ -1,113 +0,0 @@ ---[[ - Function for initial conditions ---]] - -g = 9.81; - -function initial_condition( xyz , f ) - for i=0,xyz:size1()-1 do - x = xyz:get(i,0) - if (x<0.0) then - f:set (i, 0, 40) - f:set (i, 1, 0) - else - f:set (i, 0, 20) - f:set (i, 1, 0) - end - end -end - -function pressureFlux (solution, f) - for i=0,f:size1()-1 do - p = g*solution:get(i,0) - f:set (i, 0, p) - end -end -function celerityFunction (solution, bathymetry, f) - for i=0,f:size1()-1 do - c = math.sqrt(g*(bathymetry:get(i,0)+solution:get(i,0))) - f:set(i, 0, c) - end -end - - -CFunctions =[[ -void pressureFlux ( fullMatrix<double> &f, fullMatrix<double> &sol) { - for (size_t i = 0; i< f.size1(); i++) { - double p=9.81*sol(i,0); - f.set(i,0,p); - } -} -void celerityFunction (fullMatrix<double> &f , fullMatrix<double> &sol, fullMatrix<double> &bathymetry) { - for (size_t i = 0; i< sol.size1(); i++) { - double c =sqrt(9.81*(bathymetry(i,0)+sol(i,0))); - f.set(i,0,c); - } -}]] -if (Msg.getCommRank() == 0 ) then - cfile = io.popen("g++-4.2 -O3 -pipe -m32 -shared -o tmp.dylib -I ../../Numeric -I../../Common -I../../build/Common -x c++ - ","w"); - cfile:write("#include\"fullMatrix.h\"\nextern \"C\" {") - cfile:write(CFunctions) - cfile:write("}") - cfile:close() -end -Msg.barrier() - - -bathymetry = functionConstant({0}) -dissipation = functionConstant({0}) - ---[[ - Example of a lua program driving the DG code ---]] - -model = GModel() -model:load ('edge.msh') -order=1 -dimension=1 - - --- boundary condition -law = dgConservationLawShallowWater1d() -law:addBoundaryCondition('Left',law:newBoundaryWall()) -law:addBoundaryCondition('Right',law:newBoundaryWall()) -law:setLinearDissipation(dissipation) -law:setBathymetry(bathymetry) ---law:setPressureFlux(functionLua(1,'pressureFlux',{functionSolution.get()})) ---law:setCelerity(functionLua(1,'celerityFunction',{functionSolution.get(), bathymetry})) -law:setPressureFlux(functionC("tmp.dylib","pressureFlux",1,{functionSolution.get()})) -law:setCelerity(functionC("tmp.dylib","celerityFunction",1,{functionSolution.get(), bathymetry})) - -groups = dgGroupCollection(model, dimension, order) -groups:buildGroupsOfInterfaces() - -rk=dgRungeKutta() -limiter = dgSlopeLimiter(law) -rk:setLimiter(limiter) - --- build solution vector -FS = functionLua(2, 'initial_condition', {functionCoordinates.get()}) -solution = dgDofContainer(groups, law:getNbFields()) -solution:L2Projection(FS) - -print'*** print initial sol ***' ---solution:exportMsh('output/init') -limiter:apply(solution) -solution:exportMsh('output/init_limit') - -print'*** solve ***' - - - -CFL = 0.2; -for i=1,15000 do - dt = CFL * rk:computeInvSpectralRadius(law,solution); - norm = rk:iterate44(law,dt,solution) --- norm = rk:iterateEuler(law,dt,solution) - if (i % 100 == 0) then - print('|ITER|',i,'|NORM|',norm,'|DT|',dt,'|CPU|',os.clock() - x) - end - if (i % 100 == 0) then - solution:exportMsh(string.format('output/solution-%06d', i)) - end -end diff --git a/Solver/TESTCASES/DamBreak2d.lua b/Solver/TESTCASES/DamBreak2d.lua deleted file mode 100644 index 876827531e7ab9c55627ef9258427ca018aced0d..0000000000000000000000000000000000000000 --- a/Solver/TESTCASES/DamBreak2d.lua +++ /dev/null @@ -1,72 +0,0 @@ ---[[ - Function for initial conditions ---]] - -function initial_condition( xyz , f ) - for i=0,xyz:size1()-1 do - x = xyz:get(i,0) - y = xyz:get(i,1) - z = xyz:get(i,2) - if (x<0.0) then - f:set (i, 0, 40) - f:set (i, 1, 0) - f:set (i, 2, 0) - else - f:set (i, 0, 5) - f:set (i, 1, 0) - f:set (i, 2, 0) - end - end -end - ---[[ - Example of a lua program driving the DG code ---]] - -model = GModel() -model:load ('rect2.msh') -order=1 -dimension=2 - --- boundary condition -law = dgConservationLawShallowWater2d() -law:addBoundaryCondition('Wall',law:newBoundaryWall()) -law:addBoundaryCondition('Symmetry',law:newSymmetryBoundary()) -law:setCoriolisFactor(functionConstant({0})) -law:setQuadraticDissipation(functionConstant({0})) -law:setLinearDissipation(functionConstant({0})) -law:setSource(functionConstant({0})) -law:setBathymetry(functionConstant({0})) - -groups = dgGroupCollection(model, dimension, order) -groups:buildGroupsOfInterfaces() - -rk=dgRungeKutta() -limiter = dgSlopeLimiter(law) -rk:setLimiter(limiter) - --- build solution vector -xyz = functionCoordinates.get() -FS = functionLua(1, 'initial_condition', {xyz}) -solution = dgDofContainer(groups, law:getNbFields()) -solution:L2Projection(FS) - -print'*** print initial sol ***' ---solution:exportMsh('output/init') -limiter:apply(solution) -solution:exportMsh('output/init_limit') - -print'*** solve ***' ---dt = 0.00001; -CFL = 0.02; -for i=1,9000 do - dt = CFL * rk:computeInvSpectralRadius(law,solution); --- norm = rk:iterate44(law,dt,solution) - norm = rk:iterateEuler(law,dt,solution) - if (i % 100 == 0) then - print('|ITER|',i,'|NORM|',norm,'|DT|',dt,'|CPU|',os.clock() - x) - end - if (i % 100 == 0) then - solution:exportMsh(string.format('output/solution-%06d', i)) - end -end diff --git a/Solver/TESTCASES/Diffusion.lua b/Solver/TESTCASES/Diffusion.lua deleted file mode 100644 index c826589a6df63de3d26e9b1cc84595afa3bebd0f..0000000000000000000000000000000000000000 --- a/Solver/TESTCASES/Diffusion.lua +++ /dev/null @@ -1,40 +0,0 @@ -model = GModel () -model:load ('square.geo') -model:load ('square.msh') -dg = dgSystemOfEquations (model) -dg:setOrder(1) - - --- conservation law --- advection speed -law = dgConservationLawAdvectionDiffusion.diffusionLaw(functionConstant({0.01})) -dg:setConservationLaw(law) - --- boundary condition -law:addBoundaryCondition('Border',law:newOutsideValueBoundary(functionConstant({1}))) ---law:addBoundaryCondition('Border',law:new0FluxBoundary()) - -dg:setup() - --- initial condition -function initial_condition( xyz , f ) - for i=0,xyz:size1()-1 do - x = xyz:get(i,0) - y = xyz:get(i,1) - z = xyz:get(i,2) - f:set (i, 0, math.exp(-100*((x-0.2)^2 +(y-0.3)^2))) - end -end --- dg:L2Projection(functionLua(1,'initial_condition',{functionCoordinates.get()})) - -dg:exportSolution('output/Diffusion_00000') - --- main loop -for i=1,100 do - norm = dg:RK44(0.01) - --norm = dg:RK44_TransformNodalValue(0.00001) - if (i % 50 == 0) then - print('iter',i,norm) - dg:exportSolution(string.format("output/Diffusion-%05d", i)) - end -end diff --git a/Solver/TESTCASES/Diffusion3D.lua b/Solver/TESTCASES/Diffusion3D.lua deleted file mode 100644 index 197ecef455014179a065570e50d1db5e0d9a5ca0..0000000000000000000000000000000000000000 --- a/Solver/TESTCASES/Diffusion3D.lua +++ /dev/null @@ -1,73 +0,0 @@ -model = GModel() --- model:load('tetrahedra.geo') --- model:load('tetrahedra.msh') --- model:load('prisms.geo') --- model:load('prisms.msh') -model:load('mixed.geo') -model:load('mixed.msh') -dg = dgSystemOfEquations(model) -dg:setOrder(2) - --- initial condition -function initial_condition( xyz , f ) - for i=0,xyz:size1()-1 do - x = xyz:get(i,0) - y = xyz:get(i,1) - z = xyz:get(i,2) - f:set (i, 0, math.exp(-50*((x-0.4)^2+(y-0.3)^2))) --- f:set (i, 0, math.exp(-50*((x-0.4)^2+(z+0.3)^2))) - end -end - --- conservation law - -law = dgConservationLawAdvectionDiffusion:diffusionLaw(functionConstant({0.1})) -dg:setConservationLaw(law) - -law:addBoundaryCondition('side1',law:new0FluxBoundary()) -law:addBoundaryCondition('side2',law:new0FluxBoundary()) -law:addBoundaryCondition('side3',law:new0FluxBoundary()) -law:addBoundaryCondition('side4',law:new0FluxBoundary()) -law:addBoundaryCondition('top',law:newSymmetryBoundary()) -law:addBoundaryCondition('bottom',law:newSymmetryBoundary()) - -dg:setup() - ---dg:L2Projection(functionLua(1,'initial_condition',{'XYZ'})) - -dt = 0.0001 ---CFL = 20 -- good for lc=0.1 mesh -CFL = 1 --- dt = CFL*dg:computeInvSpectralRadius() --- export_interval = 5*dt -export_interval = 0.05 -end_time = 3 -output_dir = 'output' -output_prefix = 'diff3d' -output_pattern = output_dir .. '/' .. output_prefix .. '-' - - --- main loop -next_export_time = export_interval -export_count = 0 -io.write(string.format('Export: %d iter: %4d t: %.6f n: %.8f dt:%.8f\n',export_count,0,0,0,dt)) -dg:exportSolution(output_pattern .. string.format("%05d",export_count)) -for i=1,10000 do --- dt = CFL*dg:computeInvSpectralRadius() - norm = dg:RK44(dt) - time = i*dt - io.write('.') - io.flush() --- io.write('\n') --- io.write(string.format('Export: %d iter: %4d t: %.6f n: %.8f dt:%.8f\n',export_count,i,time,norm,dt)) - if (time >= next_export_time) then - export_count = export_count +1 - io.write('\n') - io.write(string.format('Export: %d iter: %4d t: %.6f n: %.8f dt:%.8f\n',export_count,i,time,norm,dt)) - dg:exportSolution(output_pattern .. string.format("%05d",export_count)) - next_export_time = next_export_time + export_interval - end - if time >= end_time then - break - end -end diff --git a/Solver/TESTCASES/Diffusion_supra.lua b/Solver/TESTCASES/Diffusion_supra.lua deleted file mode 100644 index 189d2439be3fc0865048744a355518b1146dd5c8..0000000000000000000000000000000000000000 --- a/Solver/TESTCASES/Diffusion_supra.lua +++ /dev/null @@ -1,77 +0,0 @@ -model = GModel () -model:load ('plaque_supra.geo') -model:load ('plaque_supra.msh') -dg = dgSystemOfEquations (model) -dg:setOrder(1) - -Ec=1e-7 -Jc=100 -mu0=4*math.pi*1e-10 -c=mu0*Jc/Ec - -Bmax = 1e-6/Ec -t=0 -dt=1e-6 - - -function diffusivity(f ) - for i=0,f:size1()-1 do - f:set (i, 0, 1/c ) - end -end - -function valueRight(f) - for i=0,f:size1()-1 do - f:set(i,0,Bmax) - end -end - -function valueLeft(f) - for i=0,f:size1()-1 do - f:set(i,0,Bmax) - end -end - - - -nu=fullMatrix(1,1); -nu:set(0,0,1/c) - --- conservation law --- advection speed -law = dgConservationLawAdvectionDiffusion.diffusionLaw(functionLua(1,'diffusivity',{})) -dg:setConservationLaw(law) - -law:addBoundaryCondition('Top',law:new0FluxBoundary()) -law:addBoundaryCondition('Bottom',law:new0FluxBoundary()) -leftFunction=functionLua(1,'valueLeft',{}) -rightFunction=functionLua(1,'valueRight',{}) - - -law:addBoundaryCondition('Right',law:newNeumannBoundary(rightFunction)) -law:addBoundaryCondition('Left',law:newNeumannBoundary(leftFunction)) -dg:setup() - --- initial condition -function initial_condition( xyz , f ) - for i=0,xyz:size1()-1 do - x = xyz:get(i,0) - y = xyz:get(i,1) - z = xyz:get(i,2) - f:set (i, 0, 0*math.exp(-100*((x-0.2)^2 +(y-0.3)^2))) - end -end - -dg:L2Projection(functionLua(1,'initial_condition',{functionCoordinates.get()})) -dg:exportSolution('output/DiffusionSupra_00000') - --- main loop -for i=1,1000 do - -- norm = dg:RK44(0.01) - norm = dg:RK44_TransformNodalValue_limiter(0.00001) - if (i % 50 == 0) then - print('iter',i,norm) - dg:exportSolution(string.format("output/DiffusionSupra-%05d", i)) - end -t=t+dt -end diff --git a/Solver/TESTCASES/ForwardFacingStep.lua b/Solver/TESTCASES/ForwardFacingStep.lua deleted file mode 100644 index ebe99da4e9056b55280fd54486aeefa3930676ad..0000000000000000000000000000000000000000 --- a/Solver/TESTCASES/ForwardFacingStep.lua +++ /dev/null @@ -1,79 +0,0 @@ -MACH = 3.0; -GAMMA = 1.4; -U = 3.0 -V = 0.0 -RHO = 1.4; - -PRES = RHO*U*U/(GAMMA*MACH*MACH) - ---PRES = 1; ---PRES = ./(MACH*RHO*RHO*GAMMA*GAMMA) - -SOUND = math.sqrt(U*U+V*V)/MACH - ---[[ - Function for initial conditions ---]] -function free_stream( XYZ, FCT ) - for i=0,XYZ:size1()-1 do - FCT:set(i,0,RHO) - FCT:set(i,1,RHO*U) - FCT:set(i,2,RHO*V) - FCT:set(i,3, 0.5*RHO*(U*U+V*V)+PRES/(GAMMA-1)) - end -end - ---[[ - Example of a lua program driving the DG code ---]] - -order = 1 -print'*** Loading the mesh and the model ***' -myModel = GModel () -myModel:load ('step.geo') -myModel:load ('step.msh') - -print'*** Create a dg solver ***' -DG = dgSystemOfEquations (myModel) -DG:setOrder(order) -FS = functionLua(4, 'free_stream', {'XYZ'}):getName() - -law=dgPerfectGasLaw2d() -DG:setConservationLaw(law) - -law:addBoundaryCondition('Walls',law:newNonSlipWallBoundary()) -law:addBoundaryCondition('LeftRight',law:newOutsideValueBoundary(FS)) ---law:addBoundaryCondition('Walls',law:newOutsideValueBoundary(FS)) - -DG:setup() - -print'*** setting the initial solution ***' - -DG:L2Projection(FS) -DG:limitSolution() - -print'*** export ***' - -DG:exportSolution('output/solution_0') - -print'*** solve ***' -CFL = 2 - -local x = os.clock() - -for i=1,5000 do - dt = CFL * DG:computeInvSpectralRadius(); --- norm = DG:RK44_limiter(dt) - norm = DG:ForwardEuler(dt) - DG:limitSolution() - if (i % 10 == 0) then - print('|ITER|',i,'|NORM|',norm,'|DT|',dt,'|CPU|',os.clock() - x) - end - if (i % 100 == 0) then - DG:exportSolution(string.format("output/solution-%06d", i)) - end -end - -print'*** done ***' - - diff --git a/Solver/TESTCASES/ForwardFacingStepNEW.lua b/Solver/TESTCASES/ForwardFacingStepNEW.lua deleted file mode 100644 index a87e559bfb524316f899e72533fd544f2ceff8fe..0000000000000000000000000000000000000000 --- a/Solver/TESTCASES/ForwardFacingStepNEW.lua +++ /dev/null @@ -1,82 +0,0 @@ -MACH = 3.0; -GAMMA = 1.4; -U = 3.0 -V = 0.0 -RHO = 1.4; - -PRES = RHO*U*U/(GAMMA*MACH*MACH) - ---PRES = 1; ---PRES = ./(MACH*RHO*RHO*GAMMA*GAMMA) - -SOUND = math.sqrt(U*U+V*V)/MACH - ---[[ - Function for initial conditions ---]] -function free_stream( XYZ, FCT ) - for i=0,XYZ:size1()-1 do - FCT:set(i,0,RHO) - FCT:set(i,1,RHO*U) - FCT:set(i,2,RHO*V) - FCT:set(i,3, 0.5*RHO*(U*U+V*V)+PRES/(GAMMA-1)) - end -end - ---[[ - Example of a lua program driving the DG code ---]] - - -print'*** Loading the mesh and the model ***' -model = GModel () -model:load ('step.geo') -model:load ('step.msh') -order = 1 -dimension = 2 - -FS = functionLua(4, 'free_stream', {XYZ}) - --- boundary condition -law=dgPerfectGasLaw2d() -law:addBoundaryCondition('Walls',law:newNonSlipWallBoundary()) -law:addBoundaryCondition('LeftRight',law:newOutsideValueBoundary(FS)) ---law:addBoundaryCondition('Walls',law:newOutsideValueBoundary(FS)) - -groups = dgGroupCollection(model, dimension, order) -groups:buildGroupsOfInterfaces() - --- build Runge Kutta and limiter -rk=dgRungeKutta() -limiter = dgSlopeLimiter(law) -rk:setLimiter(limiter) - --- build solution vector -solution = dgDofContainer(groups, law:getNbFields()) -solution:L2Projection(FS) -solution:exportGroupIdMsh() - -print'*** setting the initial solution ***' -solution:exportMsh('output/init') -limiter:apply(solution) -solution:exportMsh('output/init_limit') - -print'*** solve ***' -dg = dgSystemOfEquations (model) -CFL = 2 -local x = os.clock() -for i=1,5000 do - dt = CFL * rk:computeInvSpectralRadius(law,solution); --- norm = rk:iterate44(law,dt,solution) - norm = rk:iterateEuler(law,dt,solution) - if (i % 10 == 0) then - print('|ITER|',i,'|NORM|',norm,'|DT|',dt,'|CPU|',os.clock() - x) - end - if (i % 100 == 0) then - solution:exportMsh(string.format('output/solution-%06d', i)) - end -end - -print'*** done ***' - - diff --git a/Solver/TESTCASES/Maxwell.lua b/Solver/TESTCASES/Maxwell.lua deleted file mode 100644 index 04ee26c41f323a7f09bddc8de7aebfd258859254..0000000000000000000000000000000000000000 --- a/Solver/TESTCASES/Maxwell.lua +++ /dev/null @@ -1,95 +0,0 @@ -model = GModel () - -model:load ('box_maxwell.geo') -model:load ('box_maxwell.msh') -dg = dgSystemOfEquations (model) -dg:setOrder(1) - - - -function valueOutlet(xyz, f) - for i=0,xyz:size1()-1 do - X = xyz:get(i,0) - Y = xyz:get(i,1) - Z = xyz:get(i,2) - VALUE1= math.sqrt(X*X+Y*Y) - f:set(i,0,0) - f:set(i,1,0) - f:set(i,2,0) - f:set(i,3,0) - f:set(i,4,0) - f:set(i,5,0) - end -end - - -function valueInlet(xyz, f) - for i=0,xyz:size1()-1 do - X = xyz:get(i,0) - Y = xyz:get(i,1) - Z = xyz:get(i,2) - VALUE1= math.sqrt(X*X+Y*Y) - f:set(i,0,0) - f:set(i,2,0) - f:set(i,1,0*math.exp(-50*(z^2))) - f:set(i,3,0) - f:set(i,4,0) - f:set(i,5,0) - end -end - - -mu_eps=fullMatrix(6,1) -mu_eps:set(0,0,1) -mu_eps:set(1,0,1) -mu_eps:set(2,0,1) -mu_eps:set(3,0,1) -mu_eps:set(4,0,1) -mu_eps:set(5,0,1) -law = dgConservationLawMaxwell(functionConstant(mu_eps):getName()) -dg:setConservationLaw(law) - - --- box----- -outletFunction=functionLua(6,'valueOutlet',{'XYZ'}):getName() -inletFunction=functionLua(6,'valueInlet',{'XYZ'}):getName() - -law:addBoundaryCondition('wall',law:newBoundaryWall()) -law:addBoundaryCondition('symmetry',law:newBoundaryWall()) - -law:addBoundaryCondition('inlet',law:newSymmetryBoundary()) -law:addBoundaryCondition('outlet',law:newSymmetryBoundary()) - - -dg:setup() - --- initial condition -function initial_condition( xyz , f ) - for i=0,xyz:size1()-1 do - x = xyz:get(i,0) - y = xyz:get(i,1) - z = xyz:get(i,2) - f:set (i, 0,0) - f:set (i, 1,0) - f:set (i, 2,math.exp(-50*((x-0.3)^2+(y-0.3)^2))) - f:set (i, 3,0) - f:set (i, 4,0*math.cos(math.pi*x)) - f:set (i, 5,0) - end -end -dg:L2Projection(functionLua(6,'initial_condition',{'XYZ'}):getName()) - -dg:exportSolution('output/MaxW-00000') - -dt=0.00075 -n=50 - --- main loop -for i=1,3000 do - norm = dg:RK44(dt) - --t=t+dt - if (i % n == 0) then - print('iter',i,norm) - dg:exportSolution(string.format("output/MaxW-%05d",i)) - end -end diff --git a/Solver/TESTCASES/MultirateAdvection.lua b/Solver/TESTCASES/MultirateAdvection.lua deleted file mode 100644 index 96bf6a86333e1b14a21d569ece6404282425115e..0000000000000000000000000000000000000000 --- a/Solver/TESTCASES/MultirateAdvection.lua +++ /dev/null @@ -1,120 +0,0 @@ -PI = 3.14159 - ---[[ - Function for initial conditions ---]] -function initial_condition( XYZ, FCT ) - for i=0,XYZ:size1()-1 do - X = XYZ:get(i,0) - Y = XYZ:get(i,1)+0.12 - V = math.exp(-(X*X+Y*Y)*100) - FCT:set(i,0,V) - end -end -function velocity( XYZ, FCT ) - for i=0,XYZ:size1()-1 do - X = XYZ:get(i,0) - Y = XYZ:get(i,1) - FCT:set(i,0,0) - FCT:set(i,1,1) - FCT:set(i,2,0) - end -end - -function toIntegrate( XYZ, FCT ) - for i=0,XYZ:size1()-1 do - X = XYZ:get(i,0) - Y = XYZ:get(i,1) - FCT:set(i,0,X*X) - end -end ---[[ - Example of a lua program driving the DG code ---]] - -order = 1 -print'*** Loading the mesh and the model ***' -myModel = GModel () - myModel:load ('rect.geo') -if (order == 1) then - myModel:load ('rect.msh') -elseif (order == 2) then - myModel:load ('rect2.msh') -elseif (order == 3) then - myModel:load ('rect3.msh') -elseif (order == 4) then - myModel:load ('rect4.msh') -elseif (order == 5) then - myModel:load ('rect5.msh') -end - -print'*** Create a dg solver ***' -xyzF = functionCoordinates.get() -velF = functionLua(3, 'velocity', {xyzF}) -nuF = functionConstant({0}) -law=dgConservationLawAdvectionDiffusion(velF,nuF) - -law:addBoundaryCondition('Walls',law:new0FluxBoundary()) -law:addBoundaryCondition('Top',law:new0FluxBoundary()) -FS = functionLua(1, 'initial_condition', {xyzF}) - -GC=dgGroupCollection(myModel,2,order) -solTmp=dgDofContainer(GC,1) -solTmp:L2Projection(FS) -dt=GC:splitGroupsForMultirate(2,1,1,law,solTmp) -GC:buildGroupsOfInterfaces(myModel,2,order) -solution=dgDofContainer(GC,1) -solution:L2Projection(FS) -solution2=dgDofContainer(GC,1) -solution2:L2Projection(FS) -solution:exportGroupIdMsh() - -print'------------------- splitted !!' - --- limiter = dgSlopeLimiter(law) --- limiter:apply(solution) - -print'*** setting the initial solution ***' ---print'*** export ***' - -solution:exportMsh(string.format("output/rt-%06d", 0)) -solution2:exportMsh(string.format("outputMultirate/rt-%06d", 0)) - -print'*** solve ***' - -LC = 0.1*.1 -dt=dt -print('DT=',dt) -RK=dgRungeKutta() -multirateRK=dgRungeKuttaMultirate43(GC,law) ---multirateRK=dgRungeKuttaMultirate22(GC,law) -norm1=solution:norm() -norm2=solution2:norm() -print('Norm: ',norm1,norm2) -dt=dt -time=0 --- multirateRK:setLimiter(limiter) ---for i=1,1000 -i=0 -integrator=dgFunctionIntegrator(functionLua(1, 'toIntegrate', {xyzF})) -while i<1000 do --- norm1 = RK:iterate43SchlegelJCAM2009(law,dt,solution) --- TEST with Explicit Euler multirate !!! - norm2 = multirateRK:iterate(dt,solution2) - time=time+dt - if (i % 10 == 0) then - print('*** ITER ***',i,time,norm2) - v=fullMatrix(1,1); - integrator:compute(solution2,v); - print('integral : ',v:get(0,0,0)) - end - if (i % 10 == 0) then - -- solution:exportMsh(string.format("output/rt-%06d", i)) - solution2:exportMsh(string.format("outputMultirate/rt-%06d", i)) - end - i=i+1 -end - -print'*** done ***' - - diff --git a/Solver/TESTCASES/Projection2D3D.lua b/Solver/TESTCASES/Projection2D3D.lua deleted file mode 100644 index d33e35719536730ff2a212542e177869234f6de0..0000000000000000000000000000000000000000 --- a/Solver/TESTCASES/Projection2D3D.lua +++ /dev/null @@ -1,54 +0,0 @@ -model = GModel() --- model:load('tetrahedra.geo') --- model:load('tetrahedra.msh') -model:load('prisms.geo') -model:load('prisms.msh') --- model:load('mixed.geo') --- model:load('mixed.msh') -order=2 - --- initial condition -function initial_condition( xyz , f ) - for i=0,xyz:size1()-1 do - x = xyz:get(i,0) - y = xyz:get(i,1) - z = xyz:get(i,2) --- f:set (i, 0, math.exp(x+3*y)) - f:set (i, 0, math.exp(-20*((x-0.4)^2+(y-0.3)^2))) - end -end - -init_cond = functionLua(1, 'initial_condition', {functionCoordinates.get()}) -gc=dgGroupCollection(model,3,order) -gc:buildGroupsOfInterfaces(model,2,order) -solution=dgDofContainer(gc,1) -solution:L2Projection(init_cond) --- solution:setAll(3.0) -solution:exportMsh('sol3d.msh') - -gc2D = gc:newByTag(model,2,order,{"top"}) -solution2d=dgDofContainer(gc2D,1) --- solution2d:L2Projection(init_cond) -solution2d:setAll(2.0) -solution2d:exportMsh('sol2d.msh') - -print("** Build projection matrix **") -pm = dgMesh2MeshProjection(solution,solution2d) -print("** 3D->2D projection **") -pm:projectFromTo(solution,solution2d) -solution2d:exportMsh('proj3d2d.msh') -print("** 3D->2D copy **") -pm:copyFromTo(solution,solution2d) -solution2d:exportMsh('copy3d2d.msh') - -print("** 2D->3D projection **") -solution2d:setAll(2.0) -pm:projectFromTo(solution2d,solution) -solution:exportMsh('proj2d3d.msh') -print("** 2D->3D copy **") -pm:copyFromTo(solution2d,solution) -solution:exportMsh('copy2d3d.msh') - --- raises error --- pm:copyFromTo(solution,solution) --- pm:copyFromTo(solution2d,solution2d) diff --git a/Solver/TESTCASES/RayleighTaylor.lua b/Solver/TESTCASES/RayleighTaylor.lua deleted file mode 100644 index 3090f0c2d5b4d8b6bf60e60d04ba15cc65860208..0000000000000000000000000000000000000000 --- a/Solver/TESTCASES/RayleighTaylor.lua +++ /dev/null @@ -1,104 +0,0 @@ -ATWOOD = .5 -RHO1 = 1.0 -RHO2 = RHO1 * (1.+ATWOOD)/(1.-ATWOOD) -taper = 6.0 ---Mach number of perturbation -machnum =0.1 -GAMMA = 1.4 --- Min speed of sound is at top where p=1, rho=2 -epsilon_z= machnum * math.sqrt(GAMMA*1.0/2.0) -epsilon_xy= -epsilon_z*taper/16.0 -BANDWIDTH = 0.005; -PI = 3.14159 - ---[[ - Function for initial conditions ---]] -function initial_condition( XYZ, FCT ) - for i=0,XYZ:size1()-1 do - X = XYZ:get(i,0)-.125 - Y = XYZ:get(i,1) - RHO = 1; - if Y > 0.0 then - RHO = 2 - end --- smooth version - RHO = 1.0 + (math.atan (Y/BANDWIDTH) / PI + 0.5) - - PRES = 2 - RHO*Y; - vx = epsilon_xy * math.sin(X/0.25 * 2*PI) * math.cos(Y*PI) * math.pow(math.cos(Y*PI),taper-1.0); - vy = epsilon_z * math.cos(X/0.25 * 2*PI) * math.pow(math.cos(Y*PI),taper); - FCT:set(i,0,RHO) - FCT:set(i,1,RHO*vx) - FCT:set(i,2,RHO*vy) - FCT:set(i,3, 0.5*RHO*(vx*vx+vy*vy)+PRES/0.4) - end -end - ---[[ - Example of a lua program driving the DG code ---]] - -order = 1 -print'*** Loading the mesh and the model ***' -myModel = GModel () - myModel:load ('rect.geo') -if (order == 1) then - myModel:load ('rect.msh') -elseif (order == 2) then - myModel:load ('rect2.msh') -elseif (order == 3) then - myModel:load ('rect3.msh') -elseif (order == 4) then - myModel:load ('rect4.msh') -elseif (order == 5) then - myModel:load ('rect5.msh') -end - -print'*** Create a dg solver ***' -law=dgPerfectGasLaw2d() - -g=fullMatrix(4,1); -g:set(0,0,0) -g:set(1,0,0) -g:set(2,0,-1.) -g:set(3,0,0) - ---law:setSource(functionConstant(g):getName()) -law:addBoundaryCondition('Walls',law:newSlipWallBoundary()) -FS = functionLua(4, 'initial_condition', {'XYZ'}):getName() -law:addBoundaryCondition('Top',law:newOutsideValueBoundary(FS)) - -GC=dgGroupCollection(myModel,2,order) -solution=dgDofContainer(GC,4) -solution:L2Projection(FS) -limiter = dgSlopeLimiter(law) --- limiter:apply(solution) -GC:buildGroupsOfInterfaces(myModel,2,order) - -print'*** setting the initial solution ***' ---print'*** export ***' - -solution:exportMsh(string.format("output/rt-%06d", 0)) - -print'*** solve ***' - -LC = 0.1*.1 -dt = .0003; -print('DT=',dt) -RK=dgRungeKutta() -RK:setLimiter(limiter) -for i=1,10000 do --- norm = DG:RK44_limiter(dt) - norm = RK:iterate44(law,dt,solution) - if (i % 10 == 0) then - print('*** ITER ***',i,norm) - end - if (i % 100 == 0) then - solution:exportMsh(string.format("output/rt-%06d", i)) - end -end - -print'*** done ***' - - diff --git a/Solver/TESTCASES/RayleighTaylorMultirate.lua b/Solver/TESTCASES/RayleighTaylorMultirate.lua deleted file mode 100644 index 14b4939223d9a5447ca72d538d802b992a1c4f97..0000000000000000000000000000000000000000 --- a/Solver/TESTCASES/RayleighTaylorMultirate.lua +++ /dev/null @@ -1,111 +0,0 @@ -ATWOOD = .5 -RHO1 = 1.0 -RHO2 = RHO1 * (1.+ATWOOD)/(1.-ATWOOD) -taper = 6.0 ---Mach number of perturbation -machnum =0.1 -GAMMA = 1.4 --- Min speed of sound is at top where p=1, rho=2 -epsilon_z= machnum * math.sqrt(GAMMA*1.0/2.0) -epsilon_xy= -epsilon_z*taper/16.0 -BANDWIDTH = 0.005; -PI = 3.14159 - ---[[ - Function for initial conditions ---]] -function initial_condition( XYZ, FCT ) - for i=0,XYZ:size1()-1 do - X = XYZ:get(i,0)-.125 - Y = XYZ:get(i,1) - RHO = 1; - if Y > 0.0 then - RHO = 2 - end --- smooth version - RHO = 1.0 + (math.atan (Y/BANDWIDTH) / PI + 0.5) - - PRES = 2 - RHO*Y; - vx = epsilon_xy * math.sin(X/0.25 * 2*PI) * math.cos(Y*PI) * math.pow(math.cos(Y*PI),taper-1.0); - vy = epsilon_z * math.cos(X/0.25 * 2*PI) * math.pow(math.cos(Y*PI),taper); - FCT:set(i,0,RHO) - FCT:set(i,1,RHO*vx) - FCT:set(i,2,RHO*vy) - FCT:set(i,3, 0.5*RHO*(vx*vx+vy*vy)+PRES/0.4) - end -end - ---[[ - Example of a lua program driving the DG code ---]] - -order = 1 -print'*** Loading the mesh and the model ***' -myModel = GModel () - myModel:load ('rect.geo') -if (order == 1) then - myModel:load ('rect.msh') -elseif (order == 2) then - myModel:load ('rect2.msh') -elseif (order == 3) then - myModel:load ('rect3.msh') -elseif (order == 4) then - myModel:load ('rect4.msh') -elseif (order == 5) then - myModel:load ('rect5.msh') -end - -print'*** Create a dg solver ***' -law=dgPerfectGasLaw2d() - -g=fullMatrix(4,1); -g:set(0,0,0) -g:set(1,0,0) -g:set(2,0,-1.) -g:set(3,0,0) - -law:setSource(functionConstant(g):getName()) -law:addBoundaryCondition('Walls',law:newSlipWallBoundary()) -FS = functionLua(4, 'initial_condition', {'XYZ'}):getName() -law:addBoundaryCondition('Top',law:newOutsideValueBoundary(FS)) - -GC=dgGroupCollection(myModel,2,order) -solTmp=dgDofContainer(GC,4) -solTmp:L2Projection(FS) -dt=GC:splitGroupsForMultirate(8,law,solTmp) -GC:buildGroupsOfInterfaces(myModel,2,order) -solution=dgDofContainer(GC,4) -solution:L2Projection(FS) -solution:exportGroupIdMsh() - -print'------------------- splitted !!' - -limiter = dgSlopeLimiter(law) --- limiter:apply(solution) - -print'*** setting the initial solution ***' ---print'*** export ***' - -solution:exportMsh(string.format("output/rt-%06d", 0)) - -print'*** solve ***' - -LC = 0.1*.1 -print('DT=',dt) --- RK=dgRungeKutta() -multirateRK=dgRungeKuttaMultirate(GC,law) -multirateRK:setLimiter(limiter) -for i=1,1000 do --- norm = DG:RK44_limiter(dt) - norm = multirateRK:iterate(dt,solution) - if (i % 1 == 0) then - print('*** ITER ***',i,norm) - end - if (i % 1 == 0) then - solution:exportMsh(string.format("output/rt-%06d", i)) - end -end - -print'*** done ***' - - diff --git a/Solver/TESTCASES/Stommel.lua b/Solver/TESTCASES/Stommel.lua deleted file mode 100644 index f3ca9868a18c212b68a9d74b5d697cd3002356d2..0000000000000000000000000000000000000000 --- a/Solver/TESTCASES/Stommel.lua +++ /dev/null @@ -1,51 +0,0 @@ -model = GModel() -model:load ('stommel_square.msh') -order = 1 -dimension = 2 - -CFunctions =[[ -void wind (fullMatrix<double> &sol, fullMatrix<double> &xyz) { - for (size_t i = 0; i< sol.size1(); i++) { - sol.set(i,0,sin(xyz(i,1)/1e6)/1e6); - sol.set(i,1,0); - } -} -void coriolis (fullMatrix<double> &sol, fullMatrix<double> &xyz) { - for (size_t i = 0; i< sol.size1(); i++) { - sol.set(i,0,1e-4+2e-11*xyz(i,1)); - } -} -]] - -if (Msg.getCommRank() == 0 ) then - cfile = io.popen("g++-4.2 -O3 -pipe -m32 -shared -o tmp.dylib -I ../../Numeric -I../../Common -I../../build/Common -x c++ - ","w"); - cfile:write("#include\"fullMatrix.h\"\nextern \"C\" {") - cfile:write(CFunctions) - cfile:write("}") - cfile:close() -end - -Msg.barrier() - -claw = dgConservationLawShallowWater2d() -claw:addBoundaryCondition('Wall',claw:newBoundaryWall()) -XYZ = functionCoordinates.get(); -claw:setCoriolisFactor(functionC("tmp.dylib","coriolis",1,{XYZ})) -claw:setQuadraticDissipation(functionConstant({0})) -claw:setLinearDissipation(functionConstant({1e-6})) -claw:setSource(functionC("tmp.dylib","wind",2,{XYZ})) -claw:setBathymetry(functionConstant({1000})) -groups = dgGroupCollection(model, dimension, order) -groups:buildGroupsOfInterfaces() -solution = dgDofContainer(groups, claw:getNbFields()) -solution:exportMsh('output/init') -rk=dgRungeKutta() - -for i=1,60000 do - norm = rk:iterate33(claw,150*(3/(2.*order+1)/2),solution) - if ( i%100 ==0 ) then - print ('iter ', i, norm) - solution:exportMsh(string.format('output/solution-%06d',i)) - end -end - diff --git a/Solver/TESTCASES/aorta.geo b/Solver/TESTCASES/aorta.geo deleted file mode 100644 index bb78005fd622068969386e5ece5b4c9630324f9b..0000000000000000000000000000000000000000 --- a/Solver/TESTCASES/aorta.geo +++ /dev/null @@ -1,8 +0,0 @@ -lc = 0.5*50; -Point(1) = {0, 0, 0, lc}; -Point(2) = {100, 0, 0, lc}; -Line(1) = {1, 2}; - -Physical Point("Inlet") = {1}; -Physical Point("Outlet") = {2}; -Physical Line("Line") = {1}; diff --git a/Solver/TESTCASES/box.geo b/Solver/TESTCASES/box.geo deleted file mode 100644 index 0d763d0970e853dbf1e3fe31e3b0e0688791fd36..0000000000000000000000000000000000000000 --- a/Solver/TESTCASES/box.geo +++ /dev/null @@ -1,28 +0,0 @@ -C = 0.6; -Lup = 0.6; -L = 2.; -lc = .1; - -Point(1) = {0.0, 0.0, -Lup, lc}; -Point(2) = {C , 0.0, -Lup, lc}; -Point(3) = {C , C , -Lup, lc}; -Point(4) = {0.0, C , -Lup, lc}; - -Line(1) = {1,2}; -Line(2) = {2,3}; -Line(3) = {3,4}; -Line(4) = {4,1}; - - -Line Loop(4) = {1,2,3,4}; -Plane Surface(5) = {4}; - -Extrude {0,0,L} { - Surface{5}; -} - -Physical Surface("inlet") = {5}; -Physical Surface("outlet") = {27}; -Physical Surface("wall") = {14,22}; -Physical Surface("symmetry") = {26,18}; -Physical Volume("volume") = {1}; diff --git a/Solver/TESTCASES/box_maxwell.geo b/Solver/TESTCASES/box_maxwell.geo deleted file mode 100644 index 03dd0c37f06df77588eed413684d318939df5525..0000000000000000000000000000000000000000 --- a/Solver/TESTCASES/box_maxwell.geo +++ /dev/null @@ -1,28 +0,0 @@ -C = 0.6; -Lup = 0.6; -L = 0.6; -lc = .05; - -Point(1) = {0.0, 0.0, -Lup, lc}; -Point(2) = {C , 0.0, -Lup, lc}; -Point(3) = {C , C , -Lup, lc}; -Point(4) = {0.0, C , -Lup, lc}; - -Line(1) = {1,2}; -Line(2) = {2,3}; -Line(3) = {3,4}; -Line(4) = {4,1}; - - -Line Loop(4) = {1,2,3,4}; -Plane Surface(5) = {4}; - -Extrude {0,0,L} { - Surface{5}; -} - -Physical Surface("inlet") = {5}; -Physical Surface("outlet") = {27}; -Physical Surface("wall") = {14,22}; -Physical Surface("symmetry") = {26,18}; -Physical Volume("volume") = {1}; diff --git a/Solver/TESTCASES/cyl.geo b/Solver/TESTCASES/cyl.geo deleted file mode 100644 index 8b8595b31e20050136db0975d27b9f94b7b9c466..0000000000000000000000000000000000000000 --- a/Solver/TESTCASES/cyl.geo +++ /dev/null @@ -1,76 +0,0 @@ -a = .1; -b = 1; -radius = 0.5; -radiusBoundaryLayer = 0.7; -Point(1) = {0, 0, 0, a}; -Point(2) = {radius, 0, 0, a}; -Point(3) = {-radius, 0, 0, a}; -Point(4) = {0, radius, 0, a}; -Point(5) = {0, -radius, 0, a}; -Point(12) = {radiusBoundaryLayer, 0, 0, a}; -Point(13) = {-radiusBoundaryLayer, 0, 0, a}; -Point(14) = {0, radiusBoundaryLayer, 0, a}; -Point(15) = {0, -radiusBoundaryLayer, 0, a}; -Point(6) = {-5, -5, 0, b}; -Point(7) = {-5, 5, 0, b}; -Point(8) = {15, 5, 0, b}; -Point(9) = {15, -5, 0, b}; -Circle(1) = {4, 1, 2}; -Circle(2) = {2, 1, 5}; -Circle(3) = {5, 1, 3}; -Circle(4) = {3, 1, 4}; -Circle(11) = {14, 1, 12}; -Circle(12) = {12, 1, 15}; -Circle(13) = {15, 1, 13}; -Circle(14) = {13, 1, 14}; - -Line(5) = {7, 8}; -Line(6) = {8, 9}; -Line(7) = {9, 6}; -Line(8) = {6, 7}; -Line(22) ={2,12}; -Line(23) ={3,13}; -Line(24) ={4,14}; -Line(25) ={5,15}; - -Line Loop(1) = {1, 22, -11, -24}; -Plane Surface(1)={1}; -Line Loop(2) = {2, 25, -12, -22}; -Plane Surface(2)={2}; -Line Loop(3) = {3, 23, -13, -25}; -Plane Surface(3)={3}; -Line Loop(4) = {4, 24, -14, -23}; -Plane Surface(4)={4}; - -np=6; -np2=4; -Transfinite Line(1) = np; -Transfinite Line(2) = np; -Transfinite Line(3) = np; -Transfinite Line(4) = np; -Transfinite Line(11) = np; -Transfinite Line(12) = np; -Transfinite Line(13) = np; -Transfinite Line(14) = np; - -Transfinite Line(22) = np2; -Transfinite Line(23) = np2; -Transfinite Line(24) = np2; -Transfinite Line(25) = np2; - -Transfinite Surface(1) = {2,12,14,4}; -Transfinite Surface(2) = {5,15,12,2}; -Transfinite Surface(3) = {3,13,15,5}; -Transfinite Surface(4) = {4,14,13,3}; -Recombine Surface {1,2,3,4}; - -Line Loop(9) = {6, 7, 8, 5}; -Line Loop(10) = {11,12,13,14}; -Plane Surface(100) = {9, 10}; - -Physical Surface("Air") = {1,2,3,4}; -Physical Surface("BoundaryLayer") = {100}; -Physical Line("Cylinder") = {4, 1, 2, 3}; -Physical Line("Box") = {5, 6, 7, 8}; -Mesh.CharacteristicLengthExtendFromBoundary=1; -Recombine Surface {4, 1, 2, 3}; diff --git a/Solver/TESTCASES/cyl2.geo b/Solver/TESTCASES/cyl2.geo deleted file mode 100644 index 1e8ee12b1ef606f8127d17f1584e69ed3692ab76..0000000000000000000000000000000000000000 --- a/Solver/TESTCASES/cyl2.geo +++ /dev/null @@ -1,76 +0,0 @@ -a = .4; -b = 2; -radius = 0.5; -radiusBoundaryLayer = 0.7; -Point(1) = {0, 0, 0, a}; - -nlayers=2; -np=3; -np2=2; - - -For n In {0:nlayers} - r= radius + (radiusBoundaryLayer-radius)*n/nlayers; - Point(n*10+2) = {r,0,0,a}; - Point(n*10+3) = {0,-r,0,a}; - Point(n*10+4) = {-r,0,0,a}; - Point(n*10+5) = {0,r,0,a}; - - Circle(n*10+2) = {n*10+2,1,n*10+3}; - Circle(n*10+3) = {n*10+3,1,n*10+4}; - Circle(n*10+4) = {n*10+4,1,n*10+5}; - Circle(n*10+5) = {n*10+5,1,n*10+2}; - - Transfinite Line (n*10+2) = np; - Transfinite Line (n*10+3) = np; - Transfinite Line (n*10+4) = np; - Transfinite Line (n*10+5) = np; - - If (n>0) - Line (n*10+7) = {(n-1)*10+2, n*10+2}; - Line (n*10+8) = {(n-1)*10+3, n*10+3}; - Line (n*10+9) = {(n-1)*10+4, n*10+4}; - Line (n*10+10) = {(n-1)*10+5, n*10+5}; - - Transfinite Line (n*10+7) = np2; - Transfinite Line (n*10+8) = np2; - Transfinite Line (n*10+9) = np2; - Transfinite Line (n*10+10) = np2; - - Line Loop (n*10+2) = {n*10+2, -n*10-8, -(n-1)*10-2, n*10+7}; - Plane Surface(n*10+2) = {n*10+2}; - Transfinite Surface (n*10+2) = {n*10+2, n*10+3, (n-1)*10+3, (n-1)*10+2}; - Line Loop (n*10+3) = {n*10+3, -n*10-9, -(n-1)*10-3, n*10+8}; - Plane Surface(n*10+3) = {n*10+3}; - Transfinite Surface (n*10+3) = {n*10+3, n*10+4, (n-1)*10+4, (n-1)*10+3}; - Line Loop (n*10+4) = {n*10+4, -n*10-10, -(n-1)*10-4, n*10+9}; - Plane Surface(n*10+4) = {n*10+4}; - Transfinite Surface (n*10+4) = {n*10+4, n*10+5, (n-1)*10+5, (n-1)*10+4}; - Line Loop (n*10+5) = {n*10+5, -n*10-7, -(n-1)*10-5, n*10+10}; - Plane Surface(n*10+5) = {n*10+5}; - Transfinite Surface (n*10+5) = {n*10+5, n*10+2, (n-1)*10+2, (n-1)*10+5}; - - Recombine Surface {n*10+2, n*10+3, n*10+4,n*10+5}; - EndIf -EndFor - -Point(6) = {-5, -5, 0, b}; -Point(7) = {-5, 5, 0, b}; -Point(8) = {15, 5, 0, b}; -Point(9) = {15, -5, 0, b}; - -Line(10001) = {7, 8}; -Line(10002) = {8, 9}; -Line(10003) = {9, 6}; -Line(10004) = {6, 7}; - -Line Loop(1)={10001,10002,10003,10004}; -Line Loop(2)={-nlayers*10-5,-nlayers*10-4,-nlayers*10-3,-nlayers*10-2}; -Plane Surface(1)={1,2}; -Mesh.CharacteristicLengthExtendFromBoundary=1; - -Physical Line("Box") = {10004, 10001, 10002, 10003}; -Physical Line("Cylinder") = {2,3,4,5}; - -Physical Surface("BoundaryLayer") = {2:10000}; -Physical Surface("Air") = {1}; diff --git a/Solver/TESTCASES/edge.geo b/Solver/TESTCASES/edge.geo deleted file mode 100644 index 6c17d4e77a2cb495bf4ceea109693d0663a953d2..0000000000000000000000000000000000000000 --- a/Solver/TESTCASES/edge.geo +++ /dev/null @@ -1,8 +0,0 @@ - -Point(1) = {-1, 0, 0, 0.01}; -Point(2) = {1, 0, 0, 0.01}; -Line(1) = {1, 2}; - -Physical Point("Left") = {1}; -Physical Point("Right") = {2}; -Physical Line("Line") = {1}; diff --git a/Solver/TESTCASES/edge.msh b/Solver/TESTCASES/edge.msh deleted file mode 100644 index cc22a33becc217f87e5d645ba38655cd2ec883df..0000000000000000000000000000000000000000 --- a/Solver/TESTCASES/edge.msh +++ /dev/null @@ -1,416 +0,0 @@ -$MeshFormat -2.2 0 8 -$EndMeshFormat -$PhysicalNames -3 -0 1 "Left" -0 2 "Right" -1 3 "Line" -$EndPhysicalNames -$Nodes -200 -1 -1 0 0 -2 1 0 0 -3 -0.9899497487437465 0 0 -4 -0.9798994974874929 0 0 -5 -0.9698492462312395 0 0 -6 -0.959798994974986 0 0 -7 -0.9497487437187324 0 0 -8 -0.9396984924624789 0 0 -9 -0.9296482412062255 0 0 -10 -0.9195979899499719 0 0 -11 -0.9095477386937184 0 0 -12 -0.8994974874374648 0 0 -13 -0.8894472361812114 0 0 -14 -0.8793969849249579 0 0 -15 -0.8693467336687043 0 0 -16 -0.8592964824124508 0 0 -17 -0.8492462311561974 0 0 -18 -0.8391959798999438 0 0 -19 -0.8291457286436903 0 0 -20 -0.8190954773874368 0 0 -21 -0.8090452261311833 0 0 -22 -0.7989949748749298 0 0 -23 -0.7889447236186762 0 0 -24 -0.7788944723624227 0 0 -25 -0.7688442211061692 0 0 -26 -0.7587939698499158 0 0 -27 -0.7487437185936622 0 0 -28 -0.7386934673374086 0 0 -29 -0.7286432160811551 0 0 -30 -0.7185929648249016 0 0 -31 -0.7085427135686482 0 0 -32 -0.6984924623123947 0 0 -33 -0.6884422110561411 0 0 -34 -0.6783919597998876 0 0 -35 -0.6683417085436341 0 0 -36 -0.6582914572873806 0 0 -37 -0.6482412060311271 0 0 -38 -0.6381909547748735 0 0 -39 -0.6281407035186201 0 0 -40 -0.6180904522623666 0 0 -41 -0.608040201006113 0 0 -42 -0.5979899497498595 0 0 -43 -0.5879396984936061 0 0 -44 -0.5778894472373525 0 0 -45 -0.567839195981099 0 0 -46 -0.5577889447248455 0 0 -47 -0.5477386934685919 0 0 -48 -0.5376884422123385 0 0 -49 -0.527638190956085 0 0 -50 -0.5175879396998314 0 0 -51 -0.5075376884435779 0 0 -52 -0.4974874371873209 0 0 -53 -0.4874371859310535 0 0 -54 -0.477386934674786 0 0 -55 -0.4673366834185185 0 0 -56 -0.4572864321622511 0 0 -57 -0.4472361809059836 0 0 -58 -0.4371859296497161 0 0 -59 -0.4271356783934487 0 0 -60 -0.4170854271371812 0 0 -61 -0.4070351758809138 0 0 -62 -0.3969849246246463 0 0 -63 -0.3869346733683788 0 0 -64 -0.3768844221121114 0 0 -65 -0.3668341708558439 0 0 -66 -0.3567839195995764 0 0 -67 -0.346733668343309 0 0 -68 -0.3366834170870416 0 0 -69 -0.3266331658307741 0 0 -70 -0.3165829145745066 0 0 -71 -0.3065326633182393 0 0 -72 -0.2964824120619718 0 0 -73 -0.2864321608057042 0 0 -74 -0.2763819095494368 0 0 -75 -0.2663316582931694 0 0 -76 -0.2562814070369018 0 0 -77 -0.2462311557806344 0 0 -78 -0.236180904524367 0 0 -79 -0.2261306532680996 0 0 -80 -0.216080402011832 0 0 -81 -0.2060301507555646 0 0 -82 -0.1959798994992972 0 0 -83 -0.1859296482430296 0 0 -84 -0.1758793969867622 0 0 -85 -0.1658291457304948 0 0 -86 -0.1557788944742273 0 0 -87 -0.1457286432179599 0 0 -88 -0.1356783919616924 0 0 -89 -0.1256281407054249 0 0 -90 -0.1155778894491575 0 0 -91 -0.10552763819289 0 0 -92 -0.09547738693662255 0 0 -93 -0.08542713568035498 0 0 -94 -0.07537688442408763 0 0 -95 -0.06532663316782017 0 0 -96 -0.05527638191155271 0 0 -97 -0.04522613065528525 0 0 -98 -0.03517587939901778 0 0 -99 -0.02512562814275032 0 0 -100 -0.01507537688648286 0 0 -101 -0.005025125630215399 0 0 -102 0.005025125626066052 0 0 -103 0.01507537688236127 0 0 -104 0.02512562813865671 0 0 -105 0.03517587939495215 0 0 -106 0.04522613065124759 0 0 -107 0.0552763819075428 0 0 -108 0.06532663316383824 0 0 -109 0.07537688442013368 0 0 -110 0.0854271356764289 0 0 -111 0.09547738693272434 0 0 -112 0.1055276381890196 0 0 -113 0.115577889445315 0 0 -114 0.1256281407016102 0 0 -115 0.1356783919579057 0 0 -116 0.1457286432142011 0 0 -117 0.1557788944704963 0 0 -118 0.1658291457267917 0 0 -119 0.175879396983087 0 0 -120 0.1859296482393824 0 0 -121 0.1959798994956778 0 0 -122 0.2060301507519731 0 0 -123 0.2160804020082685 0 0 -124 0.2261306532645639 0 0 -125 0.2361809045208592 0 0 -126 0.2462311557771546 0 0 -127 0.25628140703345 0 0 -128 0.2663316582897453 0 0 -129 0.2763819095460405 0 0 -130 0.2864321608023359 0 0 -131 0.2964824120586314 0 0 -132 0.3065326633149268 0 0 -133 0.3165829145712222 0 0 -134 0.3266331658275172 0 0 -135 0.3366834170838127 0 0 -136 0.3467336683401081 0 0 -137 0.3567839195964035 0 0 -138 0.366834170852699 0 0 -139 0.3768844221089944 0 0 -140 0.3869346733652894 0 0 -141 0.3969849246215849 0 0 -142 0.4070351758778803 0 0 -143 0.4170854271341757 0 0 -144 0.427135678390471 0 0 -145 0.4371859296467664 0 0 -146 0.4472361809030618 0 0 -147 0.457286432159357 0 0 -148 0.4673366834156523 0 0 -149 0.4773869346719477 0 0 -150 0.4874371859282431 0 0 -151 0.4974874371845386 0 0 -152 0.5075376884408445 0 0 -153 0.5175879396971534 0 0 -154 0.5276381909534629 0 0 -155 0.5376884422097721 0 0 -156 0.5477386934660815 0 0 -157 0.5577889447223909 0 0 -158 0.5678391959787001 0 0 -159 0.5778894472350093 0 0 -160 0.5879396984913186 0 0 -161 0.597989949747628 0 0 -162 0.6080402010039372 0 0 -163 0.6180904522602466 0 0 -164 0.628140703516556 0 0 -165 0.6381909547728652 0 0 -166 0.6482412060291745 0 0 -167 0.6582914572854837 0 0 -168 0.6683417085417931 0 0 -169 0.6783919597981023 0 0 -170 0.6884422110544117 0 0 -171 0.6984924623107212 0 0 -172 0.7085427135670301 0 0 -173 0.7185929648233396 0 0 -174 0.7286432160796488 0 0 -175 0.7386934673359582 0 0 -176 0.7487437185922676 0 0 -177 0.7587939698485768 0 0 -178 0.768844221104886 0 0 -179 0.7788944723611952 0 0 -180 0.7889447236175047 0 0 -181 0.7989949748738141 0 0 -182 0.8090452261301233 0 0 -183 0.8190954773864327 0 0 -184 0.8291457286427419 0 0 -185 0.8391959798990509 0 0 -186 0.8492462311553604 0 0 -187 0.8592964824116698 0 0 -188 0.869346733667979 0 0 -189 0.8793969849242884 0 0 -190 0.8894472361805978 0 0 -191 0.8994974874369068 0 0 -192 0.9095477386932163 0 0 -193 0.9195979899495255 0 0 -194 0.9296482412058349 0 0 -195 0.9396984924621443 0 0 -196 0.9497487437184535 0 0 -197 0.959798994974763 0 0 -198 0.9698492462310719 0 0 -199 0.9798994974873814 0 0 -200 0.9899497487436908 0 0 -$EndNodes -$Elements -201 -1 15 2 1 1 1 -2 15 2 2 2 2 -3 1 2 3 1 1 3 -4 1 2 3 1 3 4 -5 1 2 3 1 4 5 -6 1 2 3 1 5 6 -7 1 2 3 1 6 7 -8 1 2 3 1 7 8 -9 1 2 3 1 8 9 -10 1 2 3 1 9 10 -11 1 2 3 1 10 11 -12 1 2 3 1 11 12 -13 1 2 3 1 12 13 -14 1 2 3 1 13 14 -15 1 2 3 1 14 15 -16 1 2 3 1 15 16 -17 1 2 3 1 16 17 -18 1 2 3 1 17 18 -19 1 2 3 1 18 19 -20 1 2 3 1 19 20 -21 1 2 3 1 20 21 -22 1 2 3 1 21 22 -23 1 2 3 1 22 23 -24 1 2 3 1 23 24 -25 1 2 3 1 24 25 -26 1 2 3 1 25 26 -27 1 2 3 1 26 27 -28 1 2 3 1 27 28 -29 1 2 3 1 28 29 -30 1 2 3 1 29 30 -31 1 2 3 1 30 31 -32 1 2 3 1 31 32 -33 1 2 3 1 32 33 -34 1 2 3 1 33 34 -35 1 2 3 1 34 35 -36 1 2 3 1 35 36 -37 1 2 3 1 36 37 -38 1 2 3 1 37 38 -39 1 2 3 1 38 39 -40 1 2 3 1 39 40 -41 1 2 3 1 40 41 -42 1 2 3 1 41 42 -43 1 2 3 1 42 43 -44 1 2 3 1 43 44 -45 1 2 3 1 44 45 -46 1 2 3 1 45 46 -47 1 2 3 1 46 47 -48 1 2 3 1 47 48 -49 1 2 3 1 48 49 -50 1 2 3 1 49 50 -51 1 2 3 1 50 51 -52 1 2 3 1 51 52 -53 1 2 3 1 52 53 -54 1 2 3 1 53 54 -55 1 2 3 1 54 55 -56 1 2 3 1 55 56 -57 1 2 3 1 56 57 -58 1 2 3 1 57 58 -59 1 2 3 1 58 59 -60 1 2 3 1 59 60 -61 1 2 3 1 60 61 -62 1 2 3 1 61 62 -63 1 2 3 1 62 63 -64 1 2 3 1 63 64 -65 1 2 3 1 64 65 -66 1 2 3 1 65 66 -67 1 2 3 1 66 67 -68 1 2 3 1 67 68 -69 1 2 3 1 68 69 -70 1 2 3 1 69 70 -71 1 2 3 1 70 71 -72 1 2 3 1 71 72 -73 1 2 3 1 72 73 -74 1 2 3 1 73 74 -75 1 2 3 1 74 75 -76 1 2 3 1 75 76 -77 1 2 3 1 76 77 -78 1 2 3 1 77 78 -79 1 2 3 1 78 79 -80 1 2 3 1 79 80 -81 1 2 3 1 80 81 -82 1 2 3 1 81 82 -83 1 2 3 1 82 83 -84 1 2 3 1 83 84 -85 1 2 3 1 84 85 -86 1 2 3 1 85 86 -87 1 2 3 1 86 87 -88 1 2 3 1 87 88 -89 1 2 3 1 88 89 -90 1 2 3 1 89 90 -91 1 2 3 1 90 91 -92 1 2 3 1 91 92 -93 1 2 3 1 92 93 -94 1 2 3 1 93 94 -95 1 2 3 1 94 95 -96 1 2 3 1 95 96 -97 1 2 3 1 96 97 -98 1 2 3 1 97 98 -99 1 2 3 1 98 99 -100 1 2 3 1 99 100 -101 1 2 3 1 100 101 -102 1 2 3 1 101 102 -103 1 2 3 1 102 103 -104 1 2 3 1 103 104 -105 1 2 3 1 104 105 -106 1 2 3 1 105 106 -107 1 2 3 1 106 107 -108 1 2 3 1 107 108 -109 1 2 3 1 108 109 -110 1 2 3 1 109 110 -111 1 2 3 1 110 111 -112 1 2 3 1 111 112 -113 1 2 3 1 112 113 -114 1 2 3 1 113 114 -115 1 2 3 1 114 115 -116 1 2 3 1 115 116 -117 1 2 3 1 116 117 -118 1 2 3 1 117 118 -119 1 2 3 1 118 119 -120 1 2 3 1 119 120 -121 1 2 3 1 120 121 -122 1 2 3 1 121 122 -123 1 2 3 1 122 123 -124 1 2 3 1 123 124 -125 1 2 3 1 124 125 -126 1 2 3 1 125 126 -127 1 2 3 1 126 127 -128 1 2 3 1 127 128 -129 1 2 3 1 128 129 -130 1 2 3 1 129 130 -131 1 2 3 1 130 131 -132 1 2 3 1 131 132 -133 1 2 3 1 132 133 -134 1 2 3 1 133 134 -135 1 2 3 1 134 135 -136 1 2 3 1 135 136 -137 1 2 3 1 136 137 -138 1 2 3 1 137 138 -139 1 2 3 1 138 139 -140 1 2 3 1 139 140 -141 1 2 3 1 140 141 -142 1 2 3 1 141 142 -143 1 2 3 1 142 143 -144 1 2 3 1 143 144 -145 1 2 3 1 144 145 -146 1 2 3 1 145 146 -147 1 2 3 1 146 147 -148 1 2 3 1 147 148 -149 1 2 3 1 148 149 -150 1 2 3 1 149 150 -151 1 2 3 1 150 151 -152 1 2 3 1 151 152 -153 1 2 3 1 152 153 -154 1 2 3 1 153 154 -155 1 2 3 1 154 155 -156 1 2 3 1 155 156 -157 1 2 3 1 156 157 -158 1 2 3 1 157 158 -159 1 2 3 1 158 159 -160 1 2 3 1 159 160 -161 1 2 3 1 160 161 -162 1 2 3 1 161 162 -163 1 2 3 1 162 163 -164 1 2 3 1 163 164 -165 1 2 3 1 164 165 -166 1 2 3 1 165 166 -167 1 2 3 1 166 167 -168 1 2 3 1 167 168 -169 1 2 3 1 168 169 -170 1 2 3 1 169 170 -171 1 2 3 1 170 171 -172 1 2 3 1 171 172 -173 1 2 3 1 172 173 -174 1 2 3 1 173 174 -175 1 2 3 1 174 175 -176 1 2 3 1 175 176 -177 1 2 3 1 176 177 -178 1 2 3 1 177 178 -179 1 2 3 1 178 179 -180 1 2 3 1 179 180 -181 1 2 3 1 180 181 -182 1 2 3 1 181 182 -183 1 2 3 1 182 183 -184 1 2 3 1 183 184 -185 1 2 3 1 184 185 -186 1 2 3 1 185 186 -187 1 2 3 1 186 187 -188 1 2 3 1 187 188 -189 1 2 3 1 188 189 -190 1 2 3 1 189 190 -191 1 2 3 1 190 191 -192 1 2 3 1 191 192 -193 1 2 3 1 192 193 -194 1 2 3 1 193 194 -195 1 2 3 1 194 195 -196 1 2 3 1 195 196 -197 1 2 3 1 196 197 -198 1 2 3 1 197 198 -199 1 2 3 1 198 199 -200 1 2 3 1 199 200 -201 1 2 3 1 200 2 -$EndElements diff --git a/Solver/TESTCASES/implicit.lua b/Solver/TESTCASES/implicit.lua deleted file mode 100644 index fa980b9d6afb0c9bf61064898ce304905175598c..0000000000000000000000000000000000000000 --- a/Solver/TESTCASES/implicit.lua +++ /dev/null @@ -1,16 +0,0 @@ -model = GModel() -model:load ('square2.msh') -order = 1 -dimension = 2 - -law = dgConservationLawAdvectionDiffusion:diffusionLaw(functionConstant({1})) -law:addBoundaryCondition('Border',law:new0FluxBoundary()) -groups = dgGroupCollection(model, dimension, order) -groups:buildGroupsOfInterfaces() -solution = dgDofContainer(groups, law:getNbFields()) -residual = dgDofContainer(groups, law:getNbFields()) -r = dgResidualVolume (law) -g = groups:getElementGroup(0) -j = fullMatrix(3,3*g:getNbElements()) -r:compute1GroupWithJacobian(g,solution:getGroupProxy(0),residual:getGroupProxy(0),j) -j:print("test") diff --git a/Solver/TESTCASES/mesh2mesh.lua b/Solver/TESTCASES/mesh2mesh.lua deleted file mode 100644 index 40cd190f1f661ee7d9419f26960b78b01d36e699..0000000000000000000000000000000000000000 --- a/Solver/TESTCASES/mesh2mesh.lua +++ /dev/null @@ -1,47 +0,0 @@ --- initial condition -function initial_condition( xyz , f ) - for i=0,xyz:size1()-1 do - x = xyz:get(i,0) - y = xyz:get(i,1) - z = xyz:get(i,2) - f:set (i, 0, math.exp(-100*((x-0.2)^2 +(y-0.3)^2))) - f:set (i, 1, math.exp(-100*((x-0.4)^2 +(y-0.3)^2))) - f:set (i, 2, math.exp(-100*((x+0.2)^2 +(y-0.3)^2))) - end -end - -dimension = 2 -order1 = 1 -order2 = 2 - -model1 = GModel() -model2 = GModel() --- load a mesh -model1:load('square1.msh') --- load another mesh -model2:load('square2.msh'); - --- create 2 groups related to the 2 models with different orders -groups1 = dgGroupCollection (model1 , dimension, order1) -groups1:buildGroupsOfInterfaces() -groups2 = dgGroupCollection (model2 , dimension, order2) -groups2:buildGroupsOfInterfaces() - --- create 2 solutions -solution1 = dgDofContainer(groups1, 3); -solution2 = dgDofContainer(groups2, 3); - --- apply initial solution to solution1 -solution1:L2Projection(functionLua(3,'initial_condition',{'XYZ'}):getName()) --- save the stuff -solution1:exportMsh('solution1'); - --- this is the function that interpolates solution1 -F = functionMesh2Mesh(solution1) - --- project solution 1 onto mesh 2 -solution2:L2Projection(F:getName()) --- save the stuff -solution2:exportMsh('solution2'); - - diff --git a/Solver/TESTCASES/mixed.geo b/Solver/TESTCASES/mixed.geo deleted file mode 100644 index c129eea5fbb3c1bbdba89001264f40985fcad009..0000000000000000000000000000000000000000 --- a/Solver/TESTCASES/mixed.geo +++ /dev/null @@ -1,41 +0,0 @@ -//*********** mixed.geo *************// -C = 1; -Lup = 1; -L = 1.; -lc = 0.3; - -Point(1) = {0.0, 0.0, -Lup, lc}; -Point(2) = {C , 0.0, -Lup, lc}; -Point(3) = {C , C , -Lup, lc}; -Point(4) = {0.0, C , -Lup, lc}; - -Line(1) = {1,2}; -Line(2) = {2,3}; -Line(3) = {3,4}; -Line(4) = {4,1}; - - -Line Loop(5) = {1,2,3,4}; -Plane Surface(6) = {5}; - -outtet[] = Extrude {0,0,0.7*L} { Surface{6};}; -// Printf("top surface = %g", outtet[0]); -// Printf("volume = %g", outtet[1]); -// Printf("side surfaces = %g %g %g %g", outtet[2], outtet[3], outtet[4], outtet[5]); - -outpri[]= Extrude {0,0,0.5*L}{ Surface{outtet[0]}; Layers{Ceil(0.5*L/lc)};Recombine;}; -// outv[]= Extrude {0,0,0.5*L}{ Surface{7}; Layers{5};Recombine;}; -// Printf("top surface = %g", outpri[0]); -// Printf("volume = %g", outpri[1]); -// Printf("side surfaces = %g %g %g %g", outpri[2], outpri[3], outpri[4], outpri[5]); - -Mesh.Algorithm3D=4; // frontal [lobes] - -Physical Surface("top") = {outpri[0]}; -Physical Surface("bottom") = {6}; -Physical Surface("side1") = {outpri[2],outtet[2]}; -Physical Surface("side2") = {outpri[3],outtet[3]}; -Physical Surface("side3") = {outpri[4],outtet[4]}; -Physical Surface("side4") = {outpri[5],outtet[5]}; -Physical Volume("volume") = {outtet[1],outpri[1]}; - diff --git a/Solver/TESTCASES/plaque_supra.geo b/Solver/TESTCASES/plaque_supra.geo deleted file mode 100644 index a4e076ba1cc308556a7c87fd47be0308ea5bc0c2..0000000000000000000000000000000000000000 --- a/Solver/TESTCASES/plaque_supra.geo +++ /dev/null @@ -1,23 +0,0 @@ -lc=0.25; -a=5; -b=0.5; - -Point(1) = {-a, -b, 0, lc}; -Point(2) = {-a, b, 0, lc}; -Point(3) = {a, b, 0, lc}; -Point(4) = {a, -b, 0, lc}; -Line(1) = {4, 3}; -Line(2) = {3, 2}; -Line(3) = {2, 1}; -Line(4) = {1, 4}; -Line Loop(5) = {2, 3, 4, 1}; -Plane Surface(6) = {5}; - -Physical Line("Right")={1}; -Physical Line("Top")={2}; -Physical Line("Left")={3}; -Physical Line("Bottom")={4}; -Physical Surface("Inside") = {6}; -//Mesh.CharacteristicLengthExtendFromBoundary=1; -//Transfinite Line {1, 2, 4, 3} = 2 Using Progression 1; -//Transfinite Surface {6}; diff --git a/Solver/TESTCASES/prisms.geo b/Solver/TESTCASES/prisms.geo deleted file mode 100644 index 2291c6120d79784dc00fd6ac3409c3c0e903c570..0000000000000000000000000000000000000000 --- a/Solver/TESTCASES/prisms.geo +++ /dev/null @@ -1,36 +0,0 @@ -//*********** prisms.geo *************// -C = 1; -L = 1.; -Lup = L; -lc = 0.1; - -Point(1) = {0.0, 0.0, -Lup, lc}; -Point(2) = {C , 0.0, -Lup, lc}; -Point(3) = {C , C , -Lup, lc}; -Point(4) = {0.0, C , -Lup, lc}; - -Line(1) = {1,2}; -Line(2) = {2,3}; -Line(3) = {3,4}; -Line(4) = {4,1}; - - -Line Loop(5) = {1,2,3,4}; -Plane Surface(6) = {5}; - -outpri[]= Extrude {0,0,L}{ Surface{6}; Layers{Ceil(L/lc)};Recombine;}; -// outv[]= Extrude {0,0,0.5*L}{ Surface{7}; Layers{5};Recombine;}; -// Printf("top surface = %g", outpri[0]); -// Printf("volume = %g", outpri[1]); -// Printf("side surfaces = %g %g %g %g", outpri[2], outpri[3], outpri[4], outpri[5]); - -Mesh.Algorithm3D=4; // frontal [lobes] - -Physical Surface("top") = {outpri[0]}; -Physical Surface("bottom") = {6}; -Physical Surface("side1") = {outpri[2]}; -Physical Surface("side2") = {outpri[3]}; -Physical Surface("side3") = {outpri[4]}; -Physical Surface("side4") = {outpri[5]}; -Physical Volume("volume") = {outpri[1]}; - diff --git a/Solver/TESTCASES/rect.geo b/Solver/TESTCASES/rect.geo deleted file mode 100644 index c124edd20362e3a73477d8a712f890a74e6f41f6..0000000000000000000000000000000000000000 --- a/Solver/TESTCASES/rect.geo +++ /dev/null @@ -1,27 +0,0 @@ -Point(1) = {-.125, 0, 0, .05}; -Point(2) = {.125, 0, 0, .05}; -Point(3) = {.125, .5, 0, .05}; -Point(4) = {-.125, .5, 0, .05}; -Point(5) = {-.125, -.5, 0, .05}; -Point(6) = {.125, -.5, 0, .05}; -Line(1) = {5, 1}; -Line(2) = {1, 2}; -Line(3) = {2, 6}; -Line(4) = {6, 5}; -Line(5) = {1, 4}; -Line(6) = {4, 3}; -Line(7) = {3, 2}; -Line Loop(8) = {7, -2, 5, 6}; -Plane Surface(9) = {8}; -Line Loop(10) = {3, 4, 1, 2}; -Plane Surface(11) = {10}; - -Physical Surface("sprut") = {11, 9}; -Physical Line("Walls") = {5, 7, 3, 4, 1}; -Physical Line("Top") = {6}; - -Recombine Surface {9, 11}; - -Field[1] = MathEval; -Field[1].F = "0.01*1+0.01*100*(y*y)"; -Background Field = 1; diff --git a/Solver/TESTCASES/square.geo b/Solver/TESTCASES/square.geo deleted file mode 100644 index d9302dde173ceace7f1cd33eb744cd609610c585..0000000000000000000000000000000000000000 --- a/Solver/TESTCASES/square.geo +++ /dev/null @@ -1,16 +0,0 @@ -lc = 0.1; -Point(1) = {0.0, 0.0, 0, lc}; -Point(2) = {1, 0.0, 0, lc}; -Point(3) = {1, 1, 0, lc}; -Point(4) = {0, 1, 0, lc}; -Line(1) = {4, 3}; -Line(2) = {3, 2}; -Line(3) = {2, 1}; -Line(4) = {1, 4}; -Line Loop(5) = {2, 3, 4, 1}; -Plane Surface(6) = {5}; -Physical Line("Border") = {1, 2, 3, 4}; -Physical Surface("Inside") = {6}; -Mesh.CharacteristicLengthExtendFromBoundary=1; -//Transfinite Line {1, 2, 4, 3} = 2 Using Progression 1; -//Transfinite Surface {6}; diff --git a/Solver/TESTCASES/square2.msh b/Solver/TESTCASES/square2.msh deleted file mode 100644 index 45daf6fee0d98c032ee09b7d5749ae55b2cde239..0000000000000000000000000000000000000000 --- a/Solver/TESTCASES/square2.msh +++ /dev/null @@ -1,24 +0,0 @@ -$MeshFormat -2.2 0 8 -$EndMeshFormat -$PhysicalNames -2 -1 1 "Border" -2 2 "Inside" -$EndPhysicalNames -$Nodes -4 -1 0 0 0 -2 1 0 0 -3 1 1 0 -4 0 1 0 -$EndNodes -$Elements -6 -1 1 2 1 1 4 3 -2 1 2 1 2 3 2 -3 1 2 1 3 2 1 -4 1 2 1 4 1 4 -5 2 2 2 6 1 2 3 -5 2 2 2 6 1 3 4 -$EndElements diff --git a/Solver/TESTCASES/square_m.geo b/Solver/TESTCASES/square_m.geo deleted file mode 100644 index 808e014b8ad7fcf76dd04d90ecd05dae1de830eb..0000000000000000000000000000000000000000 --- a/Solver/TESTCASES/square_m.geo +++ /dev/null @@ -1,15 +0,0 @@ -Point(1) = {-0.5, -0.5, 0, 0.025}; -Point(2) = {0.5, -0.5, 0, 0.025}; -Point(3) = {0.5, 0.5, 0, 0.125}; -Point(4) = {-0.5, 0.5, 0, 0.125}; -Line(1) = {4, 3}; -Line(2) = {3, 2}; -Line(3) = {2, 1}; -Line(4) = {1, 4}; -Line Loop(5) = {2, 3, 4, 1}; -Plane Surface(6) = {5}; -Physical Line("Border") = {1, 2, 3, 4}; -Physical Surface("Inside") = {6}; -//Mesh.CharacteristicLengthExtendFromBoundary=1; -//Transfinite Line {1, 2, 4, 3} = 20 Using Progression 1; -//Transfinite Surface {6}; diff --git a/Solver/TESTCASES/square_mixed.geo b/Solver/TESTCASES/square_mixed.geo deleted file mode 100644 index bfc7da2a66518f15fe09658bfed76d08e7983712..0000000000000000000000000000000000000000 --- a/Solver/TESTCASES/square_mixed.geo +++ /dev/null @@ -1,26 +0,0 @@ -N=5; -Point(1) = {0.0, 0.0, 0, .03}; -Point(2) = {1, 0.0, 0, .03}; -Point(3) = {1, 1, 0, .03}; -Point(4) = {0, 1, 0, .03}; -Point(5) = {2, 0.0, 0, .03}; -Point(6) = {2, 1, 0, .03}; -Line(1) = {4, 3}; -Line(2) = {3, 2}; -Line(3) = {2, 1}; -Line(4) = {1, 4}; -Line Loop(5) = {2, 3, 4, 1}; -Plane Surface(6) = {5}; -Transfinite Line {1, 2, 4, 3} = N Using Progression 1; -Transfinite Surface {6}; -Recombine Surface {6}; -//Line(22) = {3, 2}; -Line(7) = {3, 6}; -Line(8) = {6, 5}; -Line(9) = {5, 2}; -Line Loop(10) = {8, 9, -2, 7}; -Plane Surface(11) = {10}; -Transfinite Line {7, 8, 9} = N Using Progression 1; -Transfinite Surface {11}; -Physical Surface("Inside") = {6,11}; -Physical Line("Border") = {1, 3, 4, 7, 8, 9}; diff --git a/Solver/TESTCASES/square_p.geo b/Solver/TESTCASES/square_p.geo deleted file mode 100644 index 5426e6d6a87cee9ebc13e9739bc9cde356d07f8d..0000000000000000000000000000000000000000 --- a/Solver/TESTCASES/square_p.geo +++ /dev/null @@ -1,31 +0,0 @@ -Point(1) = {-0.5, -0.5, 0, .03}; -Point(2) = {0, -0.5, 0, .03}; -Point(3) = {0, 0.5, 0, .03}; -Point(4) = {-0.5, 0.5, 0, .03}; - -Point(5) = {0.5, -0.5, 0, .03}; -Point(6) = {0.5, 0.5, 0, .03}; - -Line(1) = {4, 3}; -Line(2) = {3, 2}; -Line(3) = {2, 1}; -Line(4) = {1, 4}; - -Line(7) = {3, 6}; -Line(8) = {6, 5}; -Line(9) = {5, 2}; - -Line Loop(5) = {2, 3, 4, 1}; -Line Loop(6) = {8, 9, -2, 7}; -Plane Surface(7) = {5}; -Plane Surface(8) = {6}; -Transfinite Line {4,8} = 20 ; -Transfinite Line{2}=20; -Transfinite Surface {7}; -Recombine Surface {7}; -Transfinite Line {3,1,7,9} = 10; -Transfinite Surface{8}; - -Physical Line("Border") = {1, 3, 4, 7, 8, 9}; -Physical Surface("Inside1") = {7}; -Physical Surface("Inside2") = {8}; diff --git a/Solver/TESTCASES/square_supra.geo b/Solver/TESTCASES/square_supra.geo deleted file mode 100644 index a7c8792cf5da18fda157ca135c1408d85c727240..0000000000000000000000000000000000000000 --- a/Solver/TESTCASES/square_supra.geo +++ /dev/null @@ -1,17 +0,0 @@ -Point(1) = {0.0, 0.0, 0, .03}; -Point(2) = {1, 0.0, 0, .03}; -Point(3) = {1, 1, 0, .03}; -Point(4) = {0, 1, 0, .03}; -Line(1) = {4, 3}; -Line(2) = {3, 2}; -Line(3) = {2, 1}; -Line(4) = {1, 4}; -Line Loop(5) = {2, 3, 4, 1}; -Plane Surface(6) = {5}; -Physical Line("Top") = {1}; -Physical Line("Right") = {2}; -Physical Line("Bottom") = {3}; -Physical Line("Left") = {4}; -Physical Surface("Inside") = {6}; -//Transfinite Line {1, 2, 4, 3} = 2 Using Progression 1; -//Transfinite Surface {6}; diff --git a/Solver/TESTCASES/step.geo b/Solver/TESTCASES/step.geo deleted file mode 100644 index f7a3d05a96094d315e83a00aace6ed50d09510f1..0000000000000000000000000000000000000000 --- a/Solver/TESTCASES/step.geo +++ /dev/null @@ -1,19 +0,0 @@ -Point(1) = {0, 0, 0, .1}; -Point(2) = {.6, 0, 0, .1}; -Point(3) = {.6, .2, 0, .1}; -Point(4) = {3, .2, 0, .1}; -Point(5) = {3, 1, 0, .1}; -Point(6) = {0, 1, 0, .1}; -Line(1) = {6, 5}; -Line(2) = {5, 4}; -Line(3) = {4, 3}; -Line(4) = {3, 2}; -Line(5) = {2, 1}; -Line(6) = {1, 6}; -Line Loop(7) = {2, 3, 4, 5, 6, 1}; -Plane Surface(8) = {7}; -Physical Line("Walls") = {1, 3, 4, 5}; -//Physical Line("Walls") = {1}; -Physical Line("LeftRight") = {2, 6}; -//Physical Line("LeftRight") = {2,3,4,5, 6}; -Physical Surface("Body") = {8}; diff --git a/Solver/TESTCASES/stommel_square.geo b/Solver/TESTCASES/stommel_square.geo deleted file mode 100644 index 56e56036a51d79c2b3b0ab3dbb7bdb599188d22f..0000000000000000000000000000000000000000 --- a/Solver/TESTCASES/stommel_square.geo +++ /dev/null @@ -1,16 +0,0 @@ -l = 5e5; -Point(1) = {-l, -l, 0}; -Point(2) = {l, -l, 0}; -Point(3) = {l, l, 0}; -Point(4) = {-l, l, 0}; -Line(1) = {1, 2}; -Line(2) = {2, 3}; -Line(3) = {3, 4}; -Line(4) = {4, 1}; -Line Loop(5) = {3, 4, 1, 2}; -Field[1] = MathEval; -Field[1].F = "0.5e5"; -Background Field = 1; -Plane Surface(6) = {5}; -Physical Surface(0)={6}; -Physical Line("Wall") = {3, 2, 1, 4}; diff --git a/Solver/TESTCASES/supra.lua b/Solver/TESTCASES/supra.lua deleted file mode 100644 index 1e828128ae2eda72bf2267bca1399dee8d5164a4..0000000000000000000000000000000000000000 --- a/Solver/TESTCASES/supra.lua +++ /dev/null @@ -1,75 +0,0 @@ -model = GModel () -model:load ('square_supra.geo') -model:load ('square_supra.msh') -dg = dgSystemOfEquations (model) -dg:setOrder(1) - -c=1e-3 -n=20 -t=0 -dt=1e-8 -T=3e-4 - -function diffusivity( sol , f ) - for i=0,f:size1()-1 do - f:set (i, 0, math.abs(sol:get(i,0))^(n-1)*n/c ) - end -end - -function valueRight(f) - for i=0,f:size1()-1 do - f:set(i,0,math.sin(2*math.pi*t/T+math.pi/2)) - end -end - -function valueLeft(f) - for i=0,f:size1()-1 do - f:set(i,0,-math.sin(2*math.pi*t/T+math.pi/2)) - end -end - -law = dgConservationLawAdvectionDiffusion.diffusionLaw(functionLua(1,'diffusivity',{functionSolution.get()})) -dg:setConservationLaw(law) - --- boundary condition ---[[ -outsideLeft=fullMatrix(1,1) -outsideLeft:set(0,0,-1) -outsideRight=fullMatrix(1,1) -outsideRight:set(0,0,1) ---]] -law:addBoundaryCondition('Top',law:new0FluxBoundary()) -law:addBoundaryCondition('Bottom',law:new0FluxBoundary()) -leftFunction=functionLua(1,'valueLeft',{}) -rightFunction=functionLua(1,'valueRight',{}) ---[[ -law:addBoundaryCondition('Left',law:newNeumannBoundary(leftFunction)) -law:addBoundaryCondition('Right',law:newNeumannBoundary(rightFunction)) ---]] -law:addBoundaryCondition('Left',law:newOutsideValueBoundary(leftFunction)) -law:addBoundaryCondition('Right',law:newOutsideValueBoundary(rightFunction)) - -dg:setup() - --- initial condition -function initial_condition( xyz , f ) - for i=0,xyz:size1()-1 do - x = xyz:get(i,0) - y = xyz:get(i,1) - z = xyz:get(i,2) - f:set (i, 0,0*math.exp(-100*((x-0.2)^2 +(y-0.3)^2))) - end -end -dg:L2Projection(functionLua(1,'initial_condition',{functionCoordinates.get()})) - -dg:exportSolution('output/supra-00000') - --- main loop -for i=1,150000 do - norm = dg:RK44_limiter(dt) - t=t+dt - if (i % 1 == 0) then - print('iter',i,norm) - dg:exportSolution(string.format("output/supra-%05d", i)) - end -end diff --git a/Solver/TESTCASES/validation/Advection1D.lua b/Solver/TESTCASES/validation/Advection1D.lua deleted file mode 100644 index a15fdf96163a41802d6ba7ba95b8713fe7ec9425..0000000000000000000000000000000000000000 --- a/Solver/TESTCASES/validation/Advection1D.lua +++ /dev/null @@ -1,67 +0,0 @@ - ---[[ - Function for initial conditions ---]] - -function initial_condition( xyz , f ) - for i=0,xyz:size1()-1 do - x = xyz:get(i,0) - y = xyz:get(i,1) - z = xyz:get(i,2) - if (x>-0.3 and x<0.3) then - f:set (i, 0, 1) - else - f:set (i, 0, 0) - end - end -end - ---[[ - Example of a lua program driving the DG code ---]] - -model = GModel () -model:load ('edge.msh') -order=1 -dimension=1 - --- conservation law --- advection speed -law = dgConservationLawAdvectionDiffusion:advectionLaw(functionConstant({0.15,0,0})) - --- boundary condition -outside=fullMatrix(1,1) -outside:set(0,0,0.) -bndcondition=law:newOutsideValueBoundary(functionConstant({0,0,0})) -law:addBoundaryCondition('Left',bndcondition) -law:addBoundaryCondition('Right',bndcondition) - -groups = dgGroupCollection(model, dimension, order) -groups:buildGroupsOfInterfaces() - --- build Runge Kutta and limiter -rk=dgRungeKutta() -limiter = dgSlopeLimiter(law) -rk:setLimiter(limiter) - --- build solution vector -FS = functionLua(1, 'initial_condition', {functionCoordinates.get()}) -solution = dgDofContainer(groups, law:getNbFields()) -solution:L2Projection(FS) - -solution:exportMsh('output/init') -limiter:apply(solution) -solution:exportMsh('output/init_limit') - -print'*** solve ***' -local x = os.clock() -dt = 0.03 -for i=1,100 do - norm = rk:iterate44(law,dt,solution) - if (i % 20 == 0) then - print('|ITER|',i,'|NORM|',norm,'|DT|',dt,'|CPU|',os.clock() - x) - end - if (i % 200 == 0) then - solution:exportMsh(string.format('output/solution-%06d',i)) - end -end diff --git a/Solver/TESTCASES/validation/WavePulse.lua b/Solver/TESTCASES/validation/WavePulse.lua deleted file mode 100644 index 16cf5b4107977a298cd1138d72b2f5cd5dd4a0b6..0000000000000000000000000000000000000000 --- a/Solver/TESTCASES/validation/WavePulse.lua +++ /dev/null @@ -1,65 +0,0 @@ ---[[ - Function for initial conditions ---]] -function initial_condition( xyz , f ) - for i=0,xyz:size1()-1 do - X = xyz:get(i,0) - .5 - Y = xyz:get(i,1) - .5 - Z = xyz:get(i,2) --- X2 = xyz:get(i,0) - 1.5 --- Y2 = xyz:get(i,1) - .5 --- Z2 = xyz:get(i,2) - VALUE = math.exp(-40*(X*X+Y*Y+Z*Z)) --- + math.exp(-40*(X2*X2+Y2*Y2+Z2*Z2)); - f:set(i,0,VALUE) - f:set(i,1,0.0) - f:set(i,2,0.0) - end -end - -print'*** Loading the mesh and the model ***' -myModel = GModel () ---myModel:load('box.geo') ---myModel:load('box.msh') ---myModel:load('square_quads.msh') --- myModel:load('square_part.msh') -myModel:load('square.geo') -myModel:mesh(2) -myModel:save('square.msh') - -print'*** Create a dg solver ***' -DG = dgSystemOfEquations (myModel) -DG:setOrder(3) -law=dgConservationLawWaveEquation(2) -DG:setConservationLaw(law) -law:addBoundaryCondition('Border',law:newBoundaryWall()) -DG:setup() - -initialCondition = functionLua(3,'initial_condition',{functionCoordinates.get()}) - -print'*** setting the initial solution ***' - -DG:L2Projection(initialCondition) - -print'*** export ***' - -DG:exportSolution('output/solution_000') - -print'*** solve ***' - -N = 100; -CFL = 2.1; -dt = CFL * DG:computeInvSpectralRadius(); -print('DT = ',dt) -for i=1,N do --- norm = DG:multirateRK43(dt) - norm = DG:RK44(dt) - if (i % 100 == 0) then - print('*** ITER ***',i,norm) - DG:exportSolution(string.format("output/solution-%04d", i)) - end -end - -print'*** done ***' - - diff --git a/Solver/TESTCASES/validation/edge.msh b/Solver/TESTCASES/validation/edge.msh deleted file mode 100644 index b77e58a920be6af1bbca0e3bc747580e9c5107a1..0000000000000000000000000000000000000000 --- a/Solver/TESTCASES/validation/edge.msh +++ /dev/null @@ -1,416 +0,0 @@ -$MeshFormat -2.2 0 8 -$EndMeshFormat -$PhysicalNames -3 -0 1 "Left" -0 2 "Right" -1 3 "Line" -$EndPhysicalNames -$Nodes -200 -1 -1 0 0 -2 1 0 0 -3 -0.9899497487437465 0 0 -4 -0.9798994974874929 0 0 -5 -0.9698492462312395 0 0 -6 -0.959798994974986 0 0 -7 -0.9497487437187324 0 0 -8 -0.9396984924624789 0 0 -9 -0.9296482412062255 0 0 -10 -0.9195979899499719 0 0 -11 -0.9095477386937184 0 0 -12 -0.8994974874374648 0 0 -13 -0.8894472361812114 0 0 -14 -0.8793969849249579 0 0 -15 -0.8693467336687044 0 0 -16 -0.8592964824124508 0 0 -17 -0.8492462311561974 0 0 -18 -0.8391959798999438 0 0 -19 -0.8291457286436903 0 0 -20 -0.8190954773874368 0 0 -21 -0.8090452261311832 0 0 -22 -0.7989949748749298 0 0 -23 -0.7889447236186762 0 0 -24 -0.7788944723624227 0 0 -25 -0.7688442211061692 0 0 -26 -0.7587939698499158 0 0 -27 -0.7487437185936622 0 0 -28 -0.7386934673374087 0 0 -29 -0.7286432160811551 0 0 -30 -0.7185929648249016 0 0 -31 -0.7085427135686482 0 0 -32 -0.6984924623123947 0 0 -33 -0.6884422110561411 0 0 -34 -0.6783919597998875 0 0 -35 -0.6683417085436341 0 0 -36 -0.6582914572873806 0 0 -37 -0.6482412060311271 0 0 -38 -0.6381909547748736 0 0 -39 -0.6281407035186201 0 0 -40 -0.6180904522623665 0 0 -41 -0.608040201006113 0 0 -42 -0.5979899497498595 0 0 -43 -0.5879396984936061 0 0 -44 -0.5778894472373525 0 0 -45 -0.567839195981099 0 0 -46 -0.5577889447248454 0 0 -47 -0.5477386934685919 0 0 -48 -0.5376884422123385 0 0 -49 -0.527638190956085 0 0 -50 -0.5175879396998314 0 0 -51 -0.5075376884435778 0 0 -52 -0.4974874371873209 0 0 -53 -0.4874371859310535 0 0 -54 -0.477386934674786 0 0 -55 -0.4673366834185185 0 0 -56 -0.4572864321622511 0 0 -57 -0.4472361809059836 0 0 -58 -0.4371859296497161 0 0 -59 -0.4271356783934487 0 0 -60 -0.4170854271371812 0 0 -61 -0.4070351758809138 0 0 -62 -0.3969849246246463 0 0 -63 -0.3869346733683788 0 0 -64 -0.3768844221121114 0 0 -65 -0.3668341708558439 0 0 -66 -0.3567839195995764 0 0 -67 -0.346733668343309 0 0 -68 -0.3366834170870415 0 0 -69 -0.3266331658307741 0 0 -70 -0.3165829145745066 0 0 -71 -0.3065326633182391 0 0 -72 -0.2964824120619717 0 0 -73 -0.2864321608057042 0 0 -74 -0.2763819095494368 0 0 -75 -0.2663316582931693 0 0 -76 -0.2562814070369018 0 0 -77 -0.2462311557806344 0 0 -78 -0.2361809045243669 0 0 -79 -0.2261306532680994 0 0 -80 -0.216080402011832 0 0 -81 -0.2060301507555645 0 0 -82 -0.1959798994992971 0 0 -83 -0.1859296482430296 0 0 -84 -0.1758793969867621 0 0 -85 -0.1658291457304947 0 0 -86 -0.1557788944742272 0 0 -87 -0.1457286432179598 0 0 -88 -0.1356783919616923 0 0 -89 -0.1256281407054248 0 0 -90 -0.1155778894491574 0 0 -91 -0.1055276381928899 0 0 -92 -0.09547738693662244 0 0 -93 -0.08542713568035498 0 0 -94 -0.07537688442408752 0 0 -95 -0.06532663316782006 0 0 -96 -0.0552763819115526 0 0 -97 -0.04522613065528525 0 0 -98 -0.03517587939901778 0 0 -99 -0.02512562814275032 0 0 -100 -0.01507537688648286 0 0 -101 -0.005025125630215399 0 0 -102 0.005025125626066052 0 0 -103 0.01507537688236149 0 0 -104 0.02512562813865671 0 0 -105 0.03517587939495215 0 0 -106 0.04522613065124759 0 0 -107 0.0552763819075428 0 0 -108 0.06532663316383824 0 0 -109 0.07537688442013346 0 0 -110 0.0854271356764289 0 0 -111 0.09547738693272434 0 0 -112 0.1055276381890196 0 0 -113 0.115577889445315 0 0 -114 0.1256281407016102 0 0 -115 0.1356783919579057 0 0 -116 0.1457286432142011 0 0 -117 0.1557788944704963 0 0 -118 0.1658291457267917 0 0 -119 0.1758793969830872 0 0 -120 0.1859296482393824 0 0 -121 0.1959798994956778 0 0 -122 0.2060301507519731 0 0 -123 0.2160804020082685 0 0 -124 0.2261306532645639 0 0 -125 0.2361809045208592 0 0 -126 0.2462311557771546 0 0 -127 0.25628140703345 0 0 -128 0.2663316582897453 0 0 -129 0.2763819095460407 0 0 -130 0.2864321608023359 0 0 -131 0.2964824120586314 0 0 -132 0.3065326633149268 0 0 -133 0.316582914571222 0 0 -134 0.3266331658275174 0 0 -135 0.3366834170838127 0 0 -136 0.3467336683401081 0 0 -137 0.3567839195964035 0 0 -138 0.3668341708526988 0 0 -139 0.3768844221089942 0 0 -140 0.3869346733652896 0 0 -141 0.3969849246215849 0 0 -142 0.4070351758778803 0 0 -143 0.4170854271341755 0 0 -144 0.427135678390471 0 0 -145 0.4371859296467664 0 0 -146 0.4472361809030616 0 0 -147 0.457286432159357 0 0 -148 0.4673366834156525 0 0 -149 0.4773869346719477 0 0 -150 0.4874371859282431 0 0 -151 0.4974874371845384 0 0 -152 0.5075376884408442 0 0 -153 0.5175879396971537 0 0 -154 0.5276381909534629 0 0 -155 0.5376884422097721 0 0 -156 0.5477386934660815 0 0 -157 0.5577889447223907 0 0 -158 0.5678391959787001 0 0 -159 0.5778894472350093 0 0 -160 0.5879396984913188 0 0 -161 0.597989949747628 0 0 -162 0.6080402010039372 0 0 -163 0.6180904522602466 0 0 -164 0.6281407035165558 0 0 -165 0.6381909547728652 0 0 -166 0.6482412060291745 0 0 -167 0.6582914572854837 0 0 -168 0.6683417085417931 0 0 -169 0.6783919597981023 0 0 -170 0.6884422110544117 0 0 -171 0.6984924623107209 0 0 -172 0.7085427135670304 0 0 -173 0.7185929648233396 0 0 -174 0.7286432160796488 0 0 -175 0.7386934673359582 0 0 -176 0.7487437185922674 0 0 -177 0.7587939698485768 0 0 -178 0.768844221104886 0 0 -179 0.7788944723611955 0 0 -180 0.7889447236175047 0 0 -181 0.7989949748738139 0 0 -182 0.8090452261301233 0 0 -183 0.8190954773864325 0 0 -184 0.8291457286427419 0 0 -185 0.8391959798990511 0 0 -186 0.8492462311553606 0 0 -187 0.8592964824116698 0 0 -188 0.869346733667979 0 0 -189 0.8793969849242884 0 0 -190 0.8894472361805976 0 0 -191 0.8994974874369071 0 0 -192 0.9095477386932163 0 0 -193 0.9195979899495255 0 0 -194 0.9296482412058349 0 0 -195 0.9396984924621441 0 0 -196 0.9497487437184535 0 0 -197 0.9597989949747627 0 0 -198 0.9698492462310722 0 0 -199 0.9798994974873814 0 0 -200 0.9899497487436906 0 0 -$EndNodes -$Elements -201 -1 15 2 1 1 1 -2 15 2 2 2 2 -3 1 2 3 1 1 3 -4 1 2 3 1 3 4 -5 1 2 3 1 4 5 -6 1 2 3 1 5 6 -7 1 2 3 1 6 7 -8 1 2 3 1 7 8 -9 1 2 3 1 8 9 -10 1 2 3 1 9 10 -11 1 2 3 1 10 11 -12 1 2 3 1 11 12 -13 1 2 3 1 12 13 -14 1 2 3 1 13 14 -15 1 2 3 1 14 15 -16 1 2 3 1 15 16 -17 1 2 3 1 16 17 -18 1 2 3 1 17 18 -19 1 2 3 1 18 19 -20 1 2 3 1 19 20 -21 1 2 3 1 20 21 -22 1 2 3 1 21 22 -23 1 2 3 1 22 23 -24 1 2 3 1 23 24 -25 1 2 3 1 24 25 -26 1 2 3 1 25 26 -27 1 2 3 1 26 27 -28 1 2 3 1 27 28 -29 1 2 3 1 28 29 -30 1 2 3 1 29 30 -31 1 2 3 1 30 31 -32 1 2 3 1 31 32 -33 1 2 3 1 32 33 -34 1 2 3 1 33 34 -35 1 2 3 1 34 35 -36 1 2 3 1 35 36 -37 1 2 3 1 36 37 -38 1 2 3 1 37 38 -39 1 2 3 1 38 39 -40 1 2 3 1 39 40 -41 1 2 3 1 40 41 -42 1 2 3 1 41 42 -43 1 2 3 1 42 43 -44 1 2 3 1 43 44 -45 1 2 3 1 44 45 -46 1 2 3 1 45 46 -47 1 2 3 1 46 47 -48 1 2 3 1 47 48 -49 1 2 3 1 48 49 -50 1 2 3 1 49 50 -51 1 2 3 1 50 51 -52 1 2 3 1 51 52 -53 1 2 3 1 52 53 -54 1 2 3 1 53 54 -55 1 2 3 1 54 55 -56 1 2 3 1 55 56 -57 1 2 3 1 56 57 -58 1 2 3 1 57 58 -59 1 2 3 1 58 59 -60 1 2 3 1 59 60 -61 1 2 3 1 60 61 -62 1 2 3 1 61 62 -63 1 2 3 1 62 63 -64 1 2 3 1 63 64 -65 1 2 3 1 64 65 -66 1 2 3 1 65 66 -67 1 2 3 1 66 67 -68 1 2 3 1 67 68 -69 1 2 3 1 68 69 -70 1 2 3 1 69 70 -71 1 2 3 1 70 71 -72 1 2 3 1 71 72 -73 1 2 3 1 72 73 -74 1 2 3 1 73 74 -75 1 2 3 1 74 75 -76 1 2 3 1 75 76 -77 1 2 3 1 76 77 -78 1 2 3 1 77 78 -79 1 2 3 1 78 79 -80 1 2 3 1 79 80 -81 1 2 3 1 80 81 -82 1 2 3 1 81 82 -83 1 2 3 1 82 83 -84 1 2 3 1 83 84 -85 1 2 3 1 84 85 -86 1 2 3 1 85 86 -87 1 2 3 1 86 87 -88 1 2 3 1 87 88 -89 1 2 3 1 88 89 -90 1 2 3 1 89 90 -91 1 2 3 1 90 91 -92 1 2 3 1 91 92 -93 1 2 3 1 92 93 -94 1 2 3 1 93 94 -95 1 2 3 1 94 95 -96 1 2 3 1 95 96 -97 1 2 3 1 96 97 -98 1 2 3 1 97 98 -99 1 2 3 1 98 99 -100 1 2 3 1 99 100 -101 1 2 3 1 100 101 -102 1 2 3 1 101 102 -103 1 2 3 1 102 103 -104 1 2 3 1 103 104 -105 1 2 3 1 104 105 -106 1 2 3 1 105 106 -107 1 2 3 1 106 107 -108 1 2 3 1 107 108 -109 1 2 3 1 108 109 -110 1 2 3 1 109 110 -111 1 2 3 1 110 111 -112 1 2 3 1 111 112 -113 1 2 3 1 112 113 -114 1 2 3 1 113 114 -115 1 2 3 1 114 115 -116 1 2 3 1 115 116 -117 1 2 3 1 116 117 -118 1 2 3 1 117 118 -119 1 2 3 1 118 119 -120 1 2 3 1 119 120 -121 1 2 3 1 120 121 -122 1 2 3 1 121 122 -123 1 2 3 1 122 123 -124 1 2 3 1 123 124 -125 1 2 3 1 124 125 -126 1 2 3 1 125 126 -127 1 2 3 1 126 127 -128 1 2 3 1 127 128 -129 1 2 3 1 128 129 -130 1 2 3 1 129 130 -131 1 2 3 1 130 131 -132 1 2 3 1 131 132 -133 1 2 3 1 132 133 -134 1 2 3 1 133 134 -135 1 2 3 1 134 135 -136 1 2 3 1 135 136 -137 1 2 3 1 136 137 -138 1 2 3 1 137 138 -139 1 2 3 1 138 139 -140 1 2 3 1 139 140 -141 1 2 3 1 140 141 -142 1 2 3 1 141 142 -143 1 2 3 1 142 143 -144 1 2 3 1 143 144 -145 1 2 3 1 144 145 -146 1 2 3 1 145 146 -147 1 2 3 1 146 147 -148 1 2 3 1 147 148 -149 1 2 3 1 148 149 -150 1 2 3 1 149 150 -151 1 2 3 1 150 151 -152 1 2 3 1 151 152 -153 1 2 3 1 152 153 -154 1 2 3 1 153 154 -155 1 2 3 1 154 155 -156 1 2 3 1 155 156 -157 1 2 3 1 156 157 -158 1 2 3 1 157 158 -159 1 2 3 1 158 159 -160 1 2 3 1 159 160 -161 1 2 3 1 160 161 -162 1 2 3 1 161 162 -163 1 2 3 1 162 163 -164 1 2 3 1 163 164 -165 1 2 3 1 164 165 -166 1 2 3 1 165 166 -167 1 2 3 1 166 167 -168 1 2 3 1 167 168 -169 1 2 3 1 168 169 -170 1 2 3 1 169 170 -171 1 2 3 1 170 171 -172 1 2 3 1 171 172 -173 1 2 3 1 172 173 -174 1 2 3 1 173 174 -175 1 2 3 1 174 175 -176 1 2 3 1 175 176 -177 1 2 3 1 176 177 -178 1 2 3 1 177 178 -179 1 2 3 1 178 179 -180 1 2 3 1 179 180 -181 1 2 3 1 180 181 -182 1 2 3 1 181 182 -183 1 2 3 1 182 183 -184 1 2 3 1 183 184 -185 1 2 3 1 184 185 -186 1 2 3 1 185 186 -187 1 2 3 1 186 187 -188 1 2 3 1 187 188 -189 1 2 3 1 188 189 -190 1 2 3 1 189 190 -191 1 2 3 1 190 191 -192 1 2 3 1 191 192 -193 1 2 3 1 192 193 -194 1 2 3 1 193 194 -195 1 2 3 1 194 195 -196 1 2 3 1 195 196 -197 1 2 3 1 196 197 -198 1 2 3 1 197 198 -199 1 2 3 1 198 199 -200 1 2 3 1 199 200 -201 1 2 3 1 200 2 -$EndElements diff --git a/Solver/TESTCASES/validation/square.geo b/Solver/TESTCASES/validation/square.geo deleted file mode 100644 index d2bd216e0f9333a241778610a256ad5dde9b4df1..0000000000000000000000000000000000000000 --- a/Solver/TESTCASES/validation/square.geo +++ /dev/null @@ -1,15 +0,0 @@ -Point(1) = {0.0, 0.0, 0, .03}; -Point(2) = {1, 0.0, 0, .03}; -Point(3) = {1, 1, 0, .03}; -Point(4) = {0, 1, 0, .03}; -Line(1) = {4, 3}; -Line(2) = {3, 2}; -Line(3) = {2, 1}; -Line(4) = {1, 4}; -Line Loop(5) = {2, 3, 4, 1}; -Plane Surface(6) = {5}; -Physical Line("Border") = {1, 2, 3, 4}; -Physical Surface("Inside") = {6}; -Mesh.CharacteristicLengthExtendFromBoundary=1; -//Transfinite Line {1, 2, 4, 3} = 2 Using Progression 1; -//Transfinite Surface {6}; diff --git a/Solver/dgAlgorithm.cpp b/Solver/dgAlgorithm.cpp deleted file mode 100644 index d663c64837f26dcf7da8612aad288a357155ed67..0000000000000000000000000000000000000000 --- a/Solver/dgAlgorithm.cpp +++ /dev/null @@ -1,75 +0,0 @@ -#include <set> -#include "dgAlgorithm.h" -#include "dgGroupOfElements.h" -#include "dgSystemOfEquations.h" -#include "dgConservationLaw.h" -#include "GEntity.h" -#include "MElement.h" -#include "GModel.h" -#include "MEdge.h" -#include "function.h" -#include "dgLimiter.h" -#include "dgTransformNodalValue.h" -#include "meshPartition.h" - -void dgAlgorithm::computeElementaryTimeSteps ( //dofManager &dof, // the DOF manager (maybe useless here) - const dgConservationLaw &claw, // the conservation law - const dgGroupOfElements & group, - fullMatrix<double> &solution, - std::vector<double> & DT - ) -{ - const int nbFields = claw.getNbFields(); - dataCacheMap cacheMap; - cacheMap.setNbEvaluationPoints(group.getNbIntegrationPoints()); - dataCacheDouble &sol = cacheMap.get(function::getSolution(), NULL); - dataCacheDouble &UVW = cacheMap.get(function::getParametricCoordinates(), NULL); - UVW.set()=group.getIntegrationPointsMatrix(); - // provided dataCache - dataCacheDouble *maxConvectiveSpeed = claw.newMaxConvectiveSpeed(cacheMap); - dataCacheDouble *maximumDiffusivity = claw.newMaximumDiffusivity(cacheMap); - - /* This is an estimate on how lengths changes with p - It is merely the smallest distance between gauss - points at order p + 1 */ - const double p = group.getOrder(); - const double Cip = 3 * (p + 1) * (p + group.getDimUVW()) ; - double l_red = 1./3.*p*p +7./6.*p +1.0; - double l_red_sq = l_red*l_red; - DT.resize(group.getNbElements()); - for (int iElement=0 ; iElement<group.getNbElements() ;++iElement) { - cacheMap.setElement(group.getElement(iElement)); - sol.set().setAsProxy(solution, iElement*nbFields, nbFields); - const double L = group.getInnerRadius(iElement); - double spectralRadius = 0.0; - if (maximumDiffusivity){ - double nu = (*maximumDiffusivity)(0,0); - for (int k=1;k<group.getNbNodes();k++) nu = std::max((*maximumDiffusivity)(k,0), nu); - spectralRadius += group.getDimUVW()*nu/(L*L)*std::max(l_red_sq,6.*l_red*Cip); - spectralRadius += 4.0*nu*l_red*Cip/(L*L); - } - if (maxConvectiveSpeed){ - double c = (*maxConvectiveSpeed)(0,0); - for (int k=1;k<group.getNbNodes();k++) c = std::max((*maxConvectiveSpeed)(k,0), c); - spectralRadius += 4.0*c*l_red/L; - } - DT[iElement] = 1./spectralRadius; - } -} - -void dgAlgorithm::multAddInverseMassMatrix ( /*dofManager &dof,*/ - const dgGroupOfElements & group, - fullMatrix<double> &residu, - fullMatrix<double> &sol) -{ - fullMatrix<double> residuEl; - fullMatrix<double> solEl; - fullMatrix<double> iMassEl; - int nFields=sol.size2()/group.getNbElements(); - for(int i=0;i<group.getNbElements();i++) { - residuEl.setAsProxy(residu,i*nFields,nFields); - solEl.setAsProxy(sol,i*nFields,nFields); - iMassEl.setAsProxy(group.getInverseMassMatrix(),i*group.getNbNodes(),group.getNbNodes()); - solEl.gemm(iMassEl,residuEl); - } -} diff --git a/Solver/dgAlgorithm.h b/Solver/dgAlgorithm.h deleted file mode 100644 index 014d0dec03e34ded8553d4aedbbcd8bee0c6b02b..0000000000000000000000000000000000000000 --- a/Solver/dgAlgorithm.h +++ /dev/null @@ -1,37 +0,0 @@ -#ifndef _DG_ALGORITHM_H_ -#define _DG_ALGORITHM_H_ - -#include "fullMatrix.h" -#include <vector> -class GModel; -class dgGroupCollection; -class dgGroupOfElements; -class dgGroupOfFaces; -class dgConservationLaw; -class dgDofContainer; -class dgTerm; -class dgLimiter; -class dgTransformNodalValue; -class dgSystemOfEquations; - -class dgAlgorithm { - public : - static void jacobianVolume ( //dofManager &dof, // the DOF manager (maybe useless here) - const dgConservationLaw &claw, // the conservation law - const dgGroupOfElements & group, - fullMatrix<double> &solution, - fullMatrix<double> &residual); - - static void computeElementaryTimeSteps ( //dofManager &dof, // the DOF manager (maybe useless here) - const dgConservationLaw &claw, // the conservation law - const dgGroupOfElements & group, // the group - fullMatrix<double> &solution, // the solution - std::vector<double> & DT // elementary time steps - ); - static void multAddInverseMassMatrix ( /*dofManager &dof,*/ - const dgGroupOfElements & group, - fullMatrix<double> &residu, - fullMatrix<double> &sol); -}; - -#endif diff --git a/Solver/dgConservationLaw.cpp b/Solver/dgConservationLaw.cpp deleted file mode 100644 index 511c721654c262a26a28dbb9131fcbcae18f085d..0000000000000000000000000000000000000000 --- a/Solver/dgConservationLaw.cpp +++ /dev/null @@ -1,225 +0,0 @@ -#include "dgConservationLaw.h" -#include "function.h" -class dgBoundaryConditionOutsideValue : public dgBoundaryCondition { - const function *_outsideValueFunction; - class term : public dataCacheDouble { - dataCacheMap cacheMapRight; // new cacheMap to pass to the Riemann solver - dataCacheDouble &solutionRight; - dataCacheDouble &outsideValue; - dataCacheDouble *riemannSolver; - dgConservationLaw *_claw; - public: - term(dgConservationLaw *claw, dataCacheMap &cacheMapLeft,const function *outsideValueFunction): - dataCacheDouble(cacheMapLeft, 1, claw->getNbFields()), - solutionRight(cacheMapRight.get(function::getSolution(),NULL)), - outsideValue(cacheMapLeft.get(outsideValueFunction,this)), - _claw(claw) - { - cacheMapRight.setNbEvaluationPoints(cacheMapLeft.getNbEvaluationPoints()); - riemannSolver=_claw->newRiemannSolver(cacheMapLeft,cacheMapRight); - if(riemannSolver) - riemannSolver->addMeAsDependencyOf(this); - } - - void _eval() { - solutionRight.set()=outsideValue(); - if(riemannSolver){ - for(int i=0;i<_value.size1(); i++) - for(int j=0;j<_value.size2(); j++) - _value(i,j) = (*riemannSolver)(i,j); - } - } - }; - class dirichlet : public dataCacheDouble { - dataCacheDouble &outsideValue; - public: - dirichlet(dgConservationLaw *claw, dataCacheMap &cacheMap,const function *outsideValueFunction): - dataCacheDouble(cacheMap, 1, claw->getNbFields()), - outsideValue(cacheMap.get(outsideValueFunction,this)){} - void _eval () { - for(int i=0;i<_value.size1();i++) - for(int j=0;j<_value.size2();j++) - _value(i,j)=outsideValue(i,j); - } - }; - class maximumDiffusivity : public dataCacheDouble { - dataCacheMap cacheMapRight; // new cacheMap to pass to the Riemann solver - dataCacheDouble &solutionRight; - dataCacheDouble &outsideValue; - dataCacheDouble *maxDif; - dgConservationLaw *_claw; - public: - maximumDiffusivity(dgConservationLaw *claw, dataCacheMap &cacheMapLeft,const function *outsideValueFunction): - dataCacheDouble(cacheMapLeft, 1, claw->getNbFields()), - solutionRight(cacheMapRight.get(function::getSolution(), NULL)), - outsideValue(cacheMapLeft.get(outsideValueFunction,this)), - _claw(claw) - { - cacheMapRight.setNbEvaluationPoints(cacheMapLeft.getNbEvaluationPoints()); - maxDif = _claw->newMaximumDiffusivity(cacheMapRight); - if(maxDif) - maxDif->addMeAsDependencyOf(this); - } - void _eval() { - if(maxDif){ - solutionRight.set()=outsideValue(); - for(int i=0;i<_value.size1(); i++) - for(int j=0;j<_value.size2(); j++) - _value(i,j) = (*maxDif)(i,j); - } - } - }; - public: - dgBoundaryConditionOutsideValue(dgConservationLaw *claw,const function *outsideValueFunction): dgBoundaryCondition(claw), - _outsideValueFunction(outsideValueFunction) - { } - dataCacheDouble *newBoundaryTerm(dataCacheMap &cacheMapLeft) const { - return new term(_claw,cacheMapLeft,_outsideValueFunction); - } - dataCacheDouble *newDiffusiveDirichletBC(dataCacheMap &cacheMapLeft) const { - return new dirichlet(_claw,cacheMapLeft,_outsideValueFunction); - } - dataCacheDouble *newMaximumDiffusivity(dataCacheMap &cacheMapLeft) const { - return new maximumDiffusivity(_claw,cacheMapLeft,_outsideValueFunction); - } -}; -class dgBoundaryConditionNeumann : public dgBoundaryCondition { - const function *_fluxFunction; - class term : public dataCacheDouble { - dataCacheDouble &flux; - public: - term(dgConservationLaw *claw, dataCacheMap &cacheMapLeft,const function *fluxFunction): - dataCacheDouble(cacheMapLeft,1 ,claw->getNbFields()), - flux(cacheMapLeft.get(fluxFunction,this)) - {} - void _eval() { - for(int i=0;i<_value.size1(); i++) - for(int j=0;j<_value.size2(); j++) - _value(i,j) = (flux)(i,j); - } - }; - public: - dgBoundaryConditionNeumann(dgConservationLaw *claw,const function *fluxFunction): dgBoundaryCondition(claw), - _fluxFunction(fluxFunction) - { } - dataCacheDouble *newBoundaryTerm(dataCacheMap &cacheMapLeft) const { - return new term(_claw,cacheMapLeft,_fluxFunction); - } -}; - -class dgBoundarySymmetry : public dgBoundaryCondition { - class term : public dataCacheDouble { - dataCacheDouble *riemannSolver; - dgConservationLaw *_claw; - public: - term(dgConservationLaw *claw, dataCacheMap &cacheMapLeft): - dataCacheDouble(cacheMapLeft, 1,claw->getNbFields()), _claw(claw) - { - riemannSolver=_claw->newRiemannSolver(cacheMapLeft,cacheMapLeft); - riemannSolver->addMeAsDependencyOf(this); - } - - void _eval() { - if(riemannSolver){ - for(int i=0;i<_value.size1(); i++) - for(int j=0;j<_value.size2(); j++) - _value(i,j) = (*riemannSolver)(i,j); - } - } - }; -public: - dgBoundarySymmetry(dgConservationLaw *claw): dgBoundaryCondition(claw) {} - dataCacheDouble *newBoundaryTerm(dataCacheMap &cacheMapLeft) const { - return new term(_claw,cacheMapLeft); - } -}; - -class dgBoundaryCondition0Flux : public dgBoundaryCondition { - class term : public dataCacheDouble { - public: - term(dgConservationLaw *claw,dataCacheMap &cacheMapLeft): - dataCacheDouble(cacheMapLeft,1,claw->getNbFields()) {} - void _eval() { - } - }; -public: - dgBoundaryCondition0Flux(dgConservationLaw *claw): dgBoundaryCondition(claw) {} - dataCacheDouble *newBoundaryTerm(dataCacheMap &cacheMapLeft) const { - return new term(_claw,cacheMapLeft); - } -}; - -dgBoundaryCondition *dgConservationLaw::newSymmetryBoundary() { - return new dgBoundarySymmetry(this); -} -dgBoundaryCondition *dgConservationLaw::newOutsideValueBoundary(const function *outsideValueFunction) { - return new dgBoundaryConditionOutsideValue(this,outsideValueFunction); -} -dgBoundaryCondition *dgConservationLaw::newNeumannBoundary(const function *fluxFunction) { - return new dgBoundaryConditionNeumann(this,fluxFunction); -} -dgBoundaryCondition *dgConservationLaw::new0FluxBoundary() { - return new dgBoundaryCondition0Flux(this); -} - -class dgBoundaryCondition::neumann_ : public dataCacheDouble { - dataCacheDouble &normals; - dataCacheDouble *diffusiveFlux; -public: - neumann_(dataCacheMap &cacheMap, dgConservationLaw *claw): - dataCacheDouble(cacheMap,1,claw->getNbFields()), - normals(cacheMap.get(function::getNormals(),this)) - { - diffusiveFlux=claw->newDiffusiveFlux(cacheMap); - if (diffusiveFlux)diffusiveFlux->addMeAsDependencyOf(this); - } - void _eval () { - int nbFields = _value.size2(); - const fullMatrix<double> &dfl = (*diffusiveFlux)(); - for(int i=0; i< _value.size1(); i++) { - for (int k=0;k<_value.size2();k++) { - _value(i,k) = - dfl(i,k+nbFields*0) *(normals)(0,i) + - dfl(i,k+nbFields*1) *(normals)(1,i) + - dfl(i,k+nbFields*2) *(normals)(2,i); - } - } - } - ~neumann_ () {} -}; - -dataCacheDouble *dgBoundaryCondition::newDiffusiveDirichletBC(dataCacheMap &cacheMapLeft) const { - return &cacheMapLeft.get(function::getSolution(),NULL); -} -dataCacheDouble *dgBoundaryCondition::newDiffusiveNeumannBC(dataCacheMap &cacheMapLeft) const { - return new dgBoundaryCondition::neumann_(cacheMapLeft, _claw); -} - - -#include "Bindings.h" - -void dgConservationLaw::registerBindings(binding *b){ - classBinding *cb = b->addClass<dgConservationLaw>("dgConservationLaw"); - cb->setDescription("A conservation law is defined a convective flux (f), a diffusive flux(g), a source term(r) and a set of boundary conditions.\n\\partial_t L(u) = \\nabla \\cdot (\\vec{f}(u,forcings)) + \\nabla \\cdot (\\vec{g}(u,\\nabla u,forcings) + r(u,forcings)."); - methodBinding *cm; - cm = cb->addMethod("addBoundaryCondition",&dgConservationLaw::addBoundaryCondition); - cm->setDescription("Use the boundary condition 'bc' for interface tagged with 'tag',"); - cm->setArgNames("tag","bc",NULL); - cm = cb->addMethod("new0FluxBoundary",&dgConservationLaw::new0FluxBoundary); - cm->setDescription("Create a new boundary condition which set to 0 all the fluxes through the interfaces."); - cm = cb->addMethod("newSymmetryBoundary",&dgConservationLaw::newSymmetryBoundary); - cm->setDescription("Create a new boundary condition using the values computed inside the domain as boundary values. (In practice, the fluxes are computed with the Riemann solver of this equation using the internal values as internal AND external values.)"); - cm = cb->addMethod("newOutsideValueBoundary",&dgConservationLaw::newOutsideValueBoundary); - cm->setDescription("Create a new boundary condition which compute the fluxes using the Riemann solver using the 'outsideFunction' function to compute external values."); - cm->setArgNames("outsideFunction",NULL); - cm = cb->addMethod("newNeumannBoundary",&dgConservationLaw::newNeumannBoundary); - cm->setDescription("Create a new boundary condition with a given flux (no other fluxes will be computed, nor with the rieman solver nor the IP diffusive term"); - cm->setArgNames("flux",NULL); - cm = cb->addMethod("getNbFields",&dgConservationLaw::getNbFields); - cm->setDescription("Return the number of fields composing the unknowns of this conservation law. For vectorial fields, each components is counted as one field."); -} - -void dgBoundaryCondition::registerBindings(binding *b){ - classBinding *cb = b->addClass<dgBoundaryCondition>("dgBoundaryCondition"); - cb->setDescription("A boundary condition of a conservation law. Boundary conditions should be associated with tag using dgConservationLaw::addBoundaryCondition."); -} diff --git a/Solver/dgConservationLaw.h b/Solver/dgConservationLaw.h deleted file mode 100644 index 09e198fe58080c60e2614b1b89519b171b451a8a..0000000000000000000000000000000000000000 --- a/Solver/dgConservationLaw.h +++ /dev/null @@ -1,81 +0,0 @@ -#ifndef _DG_CONSERVATION_LAW_H_ -#define _DG_CONSERVATION_LAW_H_ - -/* - \partial_t L(u) = \nabla \cdot (\vec{f}(u,forcings)) -> convective flux f - + \nabla \cdot (\vec{g}(u,\nabla u,forcings) -> diffusive flux g - + r(u,forcings) -> source term r -*/ -#include "fullMatrix.h" -class dataCacheDouble; -class dataCacheMap; -class function; - -class dgConservationLaw; -class binding; - -class dgBoundaryCondition { - class neumann_; - class dirichlet_; - protected: - dgConservationLaw *_claw; - public: - dgBoundaryCondition (dgConservationLaw *claw) : _claw(claw){} - virtual ~dgBoundaryCondition () {} - virtual dataCacheDouble *newBoundaryTerm(dataCacheMap &cacheMapLeft) const = 0; - virtual dataCacheDouble *newDiffusiveNeumannBC(dataCacheMap &cacheMapLeft) const; - virtual dataCacheDouble *newDiffusiveDirichletBC(dataCacheMap &cacheMapLeft) const; - virtual dataCacheDouble *newMaximumDiffusivity(dataCacheMap &cacheMapLeft)const {return NULL;} - static void registerBindings(binding *b); -}; - -class dgConservationLaw { - std::map<const std::string,dgBoundaryCondition*> _boundaryConditions; - protected : - int _nbf; - public: - virtual ~dgConservationLaw () {} - - int getNbFields() const {return _nbf;} - - virtual dataCacheDouble *newSourceTerm (dataCacheMap &cacheMap) const {return NULL;} - virtual dataCacheDouble *newDiffusiveFlux (dataCacheMap &cacheMap) const {return NULL;} - virtual dataCacheDouble *newDiffusiveInterfaceTerm (dataCacheMap &cacheMapLeft, dataCacheMap &cacheMapRight) const {return NULL;} - virtual dataCacheDouble *newMaximumDiffusivity (dataCacheMap &cacheMap) const {return NULL;} - virtual dataCacheDouble *newConvectiveFlux (dataCacheMap &cacheMap) const {return NULL;} - virtual dataCacheDouble *newMaxConvectiveSpeed (dataCacheMap &cacheMap) const {return NULL;} - virtual dataCacheDouble *newRiemannSolver (dataCacheMap &cacheMapLeft, dataCacheMap &cacheMapRight) const {return NULL;} - virtual dataCacheDouble *newBifurcationRiemannSolver (dataCacheMap &cacheMap0, dataCacheMap &cacheMap1, dataCacheMap &cacheMap2) const {return NULL;} - virtual dataCacheDouble *newClipToPhysics (dataCacheMap &cacheMap) const {return NULL;} - - inline const dgBoundaryCondition *getBoundaryCondition(const std::string tag) const { - std::map<const std::string,dgBoundaryCondition*>::const_iterator it = _boundaryConditions.find(tag); - if(it==_boundaryConditions.end()) { - Msg::Error("no boundary condition defined with tag '%s'", tag.c_str()); - throw; - } - return it->second; - } - - void addBoundaryCondition(std::string tag, dgBoundaryCondition * condition) { - if(_boundaryConditions.find(tag)!=_boundaryConditions.end()) - throw; - _boundaryConditions[tag]=condition; - } - - //a generic boundary condition using the Riemann solver of the conservation Law - dgBoundaryCondition *newOutsideValueBoundary(const function *outsideValueFunction); - dgBoundaryCondition *newNeumannBoundary(const function *fluxFunction); - dgBoundaryCondition *new0FluxBoundary(); - dgBoundaryCondition *newSymmetryBoundary(); - - static void registerBindings(binding *b); -}; - -dgConservationLaw *dgNewPerfectGasLaw2d(); - -dgBoundaryCondition *dgNewBoundaryConditionPerfectGasLaw2dWall(); -dgBoundaryCondition *dgNewBoundaryConditionPerfectGasLaw2dFreeStream(std::string&); - - -#endif diff --git a/Solver/dgConservationLawAdvection.cpp b/Solver/dgConservationLawAdvection.cpp deleted file mode 100644 index 7348a47f80912b679e0d2184576c6c5fa961b569..0000000000000000000000000000000000000000 --- a/Solver/dgConservationLawAdvection.cpp +++ /dev/null @@ -1,128 +0,0 @@ -#include "dgConservationLaw.h" -#include "fullMatrix.h" -#include "dgGroupOfElements.h" -#include "SPoint3.h" -#include "MElement.h" -#include "function.h" -#include "dgConservationLawAdvection.h" - -class dgConservationLawAdvectionDiffusion::advection : public dataCacheDouble { - dataCacheDouble &sol, &v; - public: - advection(const function *vFunction, dataCacheMap &cacheMap): - dataCacheDouble(cacheMap,1,3), - sol(cacheMap.get(function::getSolution(),this)), - v(cacheMap.get(vFunction,this)) - {}; - void _eval () { - for(int i=0; i< sol().size1(); i++) { - _value(i,0) = sol(i,0)*v(i,0); - _value(i,1) = sol(i,0)*v(i,1); - _value(i,2) = sol(i,0)*v(i,2); - } - } -}; - -class dgConservationLawAdvectionDiffusion::maxConvectiveSpeed : public dataCacheDouble { - dataCacheDouble &v; - public: - maxConvectiveSpeed(const function *vFunction,dataCacheMap &cacheMap): - dataCacheDouble(cacheMap,1,1), - v(cacheMap.get(vFunction,this)) - { - }; - void _eval () { - int nQP = v().size1(); - for(int i=0; i< nQP; i++) { - _value(i,0) = hypot(v(i,0),v(i,1)); - } - } -}; - -class dgConservationLawAdvectionDiffusion::riemann : public dataCacheDouble { - dataCacheDouble &normals, &solLeft, &solRight,&v; - public: - riemann(const function *vFunction, dataCacheMap &cacheMapLeft, dataCacheMap &cacheMapRight): - dataCacheDouble(cacheMapLeft,1,2), - normals(cacheMapLeft.get(function::getNormals(), this)), - solLeft(cacheMapLeft.get(function::getSolution(), this)), - solRight(cacheMapRight.get(function::getSolution(), this)), - v(cacheMapLeft.get(vFunction,this)) - {}; - void _eval () { - for(int i=0; i< _value.size1(); i++) { - double un=v(i,0)*normals(0,i)+v(i,1)*normals(1,i)+v(i,2)*normals(2,i); - if(un>0){ - _value(i,0) = -solLeft(i,0)*un; - _value(i,1) = solLeft(i,0)*un; - }else{ - _value(i,0) = -solRight(i,0)*un; - _value(i,1) = solRight(i,0)*un; - } - } - } -}; - -class dgConservationLawAdvectionDiffusion::diffusion : public dataCacheDouble { - dataCacheDouble &solgrad, ν - public: - diffusion(const function * nuFunction, dataCacheMap &cacheMap): - dataCacheDouble(cacheMap,1,3), - solgrad(cacheMap.get(function::getSolutionGradient(), this)), - nu(cacheMap.get(nuFunction,this)) - {}; - void _eval () { - for(int i=0; i< solgrad().size1(); i++) { - _value(i,0) = -solgrad(i,0)*nu(i,0); - _value(i,1) = -solgrad(i,1)*nu(i,0); - _value(i,2) = -solgrad(i,2)*nu(i,0); - } - } -}; - -dataCacheDouble *dgConservationLawAdvectionDiffusion::newConvectiveFlux( dataCacheMap &cacheMap) const { - return _vFunction ? new advection(_vFunction,cacheMap) : NULL; -} -dataCacheDouble *dgConservationLawAdvectionDiffusion::newMaxConvectiveSpeed( dataCacheMap &cacheMap) const { - return _vFunction ? new maxConvectiveSpeed(_vFunction,cacheMap) : NULL ; - -} -dataCacheDouble *dgConservationLawAdvectionDiffusion::newMaximumDiffusivity( dataCacheMap &cacheMap) const { - return _nuFunction ? &cacheMap.get(_nuFunction) : NULL; -} -dataCacheDouble *dgConservationLawAdvectionDiffusion::newRiemannSolver( dataCacheMap &cacheMapLeft, dataCacheMap &cacheMapRight) const { - return _vFunction ? new riemann(_vFunction,cacheMapLeft, cacheMapRight) : NULL; -} -dataCacheDouble *dgConservationLawAdvectionDiffusion::newDiffusiveFlux( dataCacheMap &cacheMap) const { - return _nuFunction ? new diffusion(_nuFunction,cacheMap) : NULL; -} - -dgConservationLawAdvectionDiffusion *dgConservationLawAdvectionDiffusion::diffusionLaw(const function *nu) { - return new dgConservationLawAdvectionDiffusion(NULL, nu); -} -dgConservationLawAdvectionDiffusion *dgConservationLawAdvectionDiffusion::advectionLaw(const function *v) { - return new dgConservationLawAdvectionDiffusion(v,NULL); -} - -dgConservationLawAdvectionDiffusion::dgConservationLawAdvectionDiffusion(const function *vFunction, const function *nuFunction) -{ - _vFunction = vFunction; - _nuFunction = nuFunction; - _nbf = 1; -} -#include "Bindings.h" -void dgConservationLawAdvectionDiffusionRegisterBindings (binding *b){ - classBinding *cb = b->addClass<dgConservationLawAdvectionDiffusion>("dgConservationLawAdvectionDiffusion"); - methodBinding *cm; - cm = cb->setConstructor<dgConservationLawAdvectionDiffusion,const function *, const function*>(); - cm->setArgNames("v","nu",NULL); - cm->setDescription("A new advection-diffusion law. The advection speed is given by 'v' vector function and the (scalar) diffusivity is given by the function 'nu'."); - cm = cb->addMethod("diffusionLaw",dgConservationLawAdvectionDiffusion::diffusionLaw); - cm->setDescription("static method to create an instance with diffusion only."); - cm->setArgNames("nu",NULL); - cm = cb->addMethod("advectionLaw",dgConservationLawAdvectionDiffusion::advectionLaw); - cm->setDescription("static method to create an instance with advection only."); - cm->setArgNames("v",NULL); - cb->setParentClass<dgConservationLaw>(); - cb->setDescription("Advection and diffusion of a scalar, the advection and diffusion are provided by functions."); -} diff --git a/Solver/dgConservationLawAdvection.h b/Solver/dgConservationLawAdvection.h deleted file mode 100644 index 758acf140b6dc3ec115e3cee0da97458d42aee4a..0000000000000000000000000000000000000000 --- a/Solver/dgConservationLawAdvection.h +++ /dev/null @@ -1,25 +0,0 @@ -#ifndef _DG_CONSERVATION_LAW_ADVECTION_DIFFUSION_H -#define _DG_CONSERVATION_LAW_ADVECTION_DIFFUSION_H -#include "dgConservationLaw.h" -//AdvectionDiffusion diffusion equation -//dc/dt + v div(c) - nu lapl(c) = 0 -class function; -class dgConservationLawAdvectionDiffusion : public dgConservationLaw { - const function *_vFunction, *_nuFunction; - class advection; - class riemann; - class diffusion; - class maxConvectiveSpeed; - public: - dataCacheDouble *newConvectiveFlux( dataCacheMap &cacheMap) const; - dataCacheDouble *newMaximumDiffusivity( dataCacheMap &cacheMap) const; - dataCacheDouble *newMaxConvectiveSpeed( dataCacheMap &cacheMap) const; - dataCacheDouble *newRiemannSolver( dataCacheMap &cacheMapLeft, dataCacheMap &cacheMapRight) const; - dataCacheDouble *newDiffusiveFlux( dataCacheMap &cacheMap) const; - dgConservationLawAdvectionDiffusion(const function *vFunction, const function *nuFunction); - static dgConservationLawAdvectionDiffusion *diffusionLaw(const function *nuFunction); - static dgConservationLawAdvectionDiffusion *advectionLaw(const function *vFunction); -}; -class binding; -void dgConservationLawAdvectionDiffusionRegisterBindings (binding *b); -#endif diff --git a/Solver/dgConservationLawMaxwell.cpp b/Solver/dgConservationLawMaxwell.cpp deleted file mode 100644 index 96da2f543397fad6c0ffadc8ce9738c21f67554a..0000000000000000000000000000000000000000 --- a/Solver/dgConservationLawMaxwell.cpp +++ /dev/null @@ -1,236 +0,0 @@ -#include "dgConservationLaw.h" -#include "dgConservationLawMaxwell.h" -#include "function.h" - - -class dgConservationLawMaxwell::advection : public dataCacheDouble { - dataCacheDouble &sol, &mu_eps; - public: - advection(const function *mu_epsFunction,dataCacheMap &cacheMap): - dataCacheDouble(cacheMap,1,18), - sol(cacheMap.get(function::getSolution(), this)), - mu_eps(cacheMap.get(mu_epsFunction,this)) - {}; - void _eval () { - int nQP = sol().size1(); - for(int i=0; i< nQP; i++) { - double Ex = sol(i,0); - double Ey = sol(i,1); - double Ez = sol(i,2); - - double Hx = sol(i,3); - double Hy = sol(i,4); - double Hz = sol(i,5); - // flux_x - _value(i,0) = 0; - _value(i,1) = -Hz*mu_eps(i,1); - _value(i,2) = Hy*mu_eps(i,2); - _value(i,3) = 0; - _value(i,4) = Ez*mu_eps(i,4); - _value(i,5) = -Ey*mu_eps(i,5); - // flux_y - _value(i,6) = Hz*mu_eps(i,0); - _value(i,7) =0; - _value(i,8) =-Hx*mu_eps(i,2); - _value(i,9) =-Ez*mu_eps(i,3); - _value(i,10) =0; - _value(i,11) =Ex*mu_eps(i,5); - // flux_z - _value(i,12) =-Hy*mu_eps(i,0); - _value(i,13) = Hx*mu_eps(i,1); - _value(i,14) =0; - _value(i,15) =Ey*mu_eps(i,3); - _value(i,16) =-Ex*mu_eps(i,4); - _value(i,17) = 0; - - } - } -}; - - -class dgConservationLawMaxwell::source: public dataCacheDouble { - dataCacheDouble &solution; - public : - source(dataCacheMap &cacheMap) : - dataCacheDouble(cacheMap,1,6), - solution(cacheMap.get(function::getSolution(), this)) - {} - void _eval () { - int nQP = _value.size1(); - for (int i=0; i<nQP; i++) { - - _value (i,0) = 0; - _value (i,1) = 0; - _value (i,2) = 0; - _value (i,3) = 0; - _value (i,4) = 0; - _value (i,5) = 0; - } - } -}; - - -class dgConservationLawMaxwell::riemann:public dataCacheDouble { - dataCacheDouble &normals, &solL, &solR, &mu_eps; - public: - riemann(const function *mu_epsFunction,dataCacheMap &cacheMapLeft, dataCacheMap &cacheMapRight): - dataCacheDouble(cacheMapLeft,1,12), - normals(cacheMapLeft.get(function::getNormals(), this)), - solL(cacheMapLeft.get(function::getSolution(), this)), - solR(cacheMapRight.get(function::getSolution(), this)), - mu_eps(cacheMapLeft.get(mu_epsFunction,this)) - {}; - void _eval () { - int nQP = solL().size1(); - for(int i=0; i< nQP; i++) { - - double nx= normals(0,i); - double ny= normals(1,i); - double nz= normals(2,i); - - double ExL = solL(i,0); - double EyL = solL(i,1); - double EzL = solL(i,2); - - double HxL = solL(i,3); - double HyL = solL(i,4); - double HzL = solL(i,5); - - - double ExR = solR(i,0); - double EyR = solR(i,1); - double EzR = solR(i,2); - - double HxR = solR(i,3); - double HyR = solR(i,4); - double HzR = solR(i,5); - - - - double FexL = (HzL*ny -HyL*nz)*mu_eps(i,0); - double FeyL = (-HzL*nx + HxL*nz)*mu_eps(i,1); - double FezL = (HyL*nx -HxL*ny)*mu_eps(i,2); - double FhxL = (-EzL*ny + EyL*nz)*mu_eps(i,3); - double FhyL = (EzL*nx - ExL*nz)*mu_eps(i,4); - double FhzL = ( -EyL*nx + ExL*ny)*mu_eps(i,5); - - double FexR = (HzR*ny - HyR*nz)*mu_eps(i,0); - double FeyR = (-HzR*nx + HxR*nz)*mu_eps(i,1); - double FezR = ( HyR*nx - HxR*ny)*mu_eps(i,2); - double FhxR = (-EzR*ny + EyR*nz)*mu_eps(i,3); - double FhyR = (EzR*nx - ExR*nz)*mu_eps(i,4); - double FhzR = (-EyR*nx + ExR*ny)*mu_eps(i,5); - - - - double Fwex = ((ny*(EzL-EzR) -(EyL-EyR)*nz))*mu_eps(i,0); - double Fwey = ((nz*(ExL-ExR) - (EzL-EzR)*nx))*mu_eps(i,1); - double Fwez = (((EyL-EyR)*nx -(ExL-ExR)*ny))*mu_eps(i,2); - double Fwhx = ((ny*(HzL-HzR) -(HyL-HyR)*nz))*mu_eps(i,3); - double Fwhy = ((nz*(HxL-HxR) - (HzL-HzR)*nx))*mu_eps(i,4); - double Fwhz = (((HyL-HyR)*nx -(HxL-HxR)*ny))*mu_eps(i,5); - - - _value(i,0) =-((FexL+FexR)/2-(ny*Fwez-nz*Fwey)/2); - _value(i,1) =-((FeyL+FeyR)/2-(nz*Fwex-nx*Fwez)/2); - _value(i,2) =-((FezL+FezR)/2-(nx*Fwey-ny*Fwex)/2); - _value(i,3) =-((FhxL+FhxR)/2-(ny*Fwhz-nz*Fwhy)/2); - _value(i,4) =-((FhyL+FhyR)/2-(nz*Fwhx-nx*Fwhz)/2); - _value(i,5) =-((FhzL+FhzR)/2-(nx*Fwhy-ny*Fwhx)/2); - - - _value(i,6) =-_value(i,0); - _value(i,7) =-_value(i,1); - _value(i,8) =-_value(i,2); - _value(i,9) =-_value(i,3); - _value(i,10) =-_value(i,4); - _value(i,11) =-_value(i,5); - - - } - } -}; - - -dataCacheDouble *dgConservationLawMaxwell::newConvectiveFlux( dataCacheMap &cacheMap) const { - return _mu_epsFunction ? new advection(_mu_epsFunction,cacheMap) : NULL; -} - - -dataCacheDouble *dgConservationLawMaxwell::newRiemannSolver( dataCacheMap &cacheMapLeft, dataCacheMap &cacheMapRight) const { - return _mu_epsFunction ? new riemann(_mu_epsFunction,cacheMapLeft, cacheMapRight) : NULL; -} - - -dataCacheDouble *dgConservationLawMaxwell::newSourceTerm (dataCacheMap &cacheMap) const { - return new source(cacheMap); -} - -dgConservationLawMaxwell::dgConservationLawMaxwell(const function *mu_epsFunction) -{ - _mu_epsFunction = mu_epsFunction; - _nbf = 6; -} - - -class dgBoundaryConditionMaxwellWall : public dgBoundaryCondition { - class term : public dataCacheDouble { - dataCacheDouble &sol,&normals; - public: - term(dataCacheMap &cacheMap): - dataCacheDouble(cacheMap,1,6), - sol(cacheMap.get(function::getSolution(), this)), - normals(cacheMap.get(function::getNormals(), this)) - {} - void _eval () { - int nQP = sol().size1(); - for(int i=0; i< nQP; i++) { - - double nx= normals(0,i); - double ny= normals(1,i); - double nz= normals(2,i); - - double Ex = sol(i,0); - double Ey = sol(i,1); - double Ez = sol(i,2); - - double Hx = sol(i,3); - double Hy = sol(i,4); - double Hz = sol(i,5); - - - _value(i,0) = (-Ez*ny+Ey*nz); - _value(i,1) = (Ez*nx-Ex*nz); - _value(i,2) = (-Ey*nx+Ex*ny); - _value(i,3) = (Hz*ny-Hy*nz); - _value(i,4) = (-Hz*nx+Hx*nz); - _value(i,5) = (Hy*nx-Hx*ny); - - } - } - }; - public: - dgBoundaryConditionMaxwellWall(dgConservationLaw *claw):dgBoundaryCondition(claw){} - dataCacheDouble *newBoundaryTerm(dataCacheMap &cacheMapLeft) const { - return new term(cacheMapLeft); - } -}; -dgBoundaryCondition *dgConservationLawMaxwell::newBoundaryWall(){ - return new dgBoundaryConditionMaxwellWall(this); -} - - - -#include "Bindings.h" -void dgConservationLawMaxwellRegisterBindings (binding *b){ - classBinding *cb = b->addClass<dgConservationLawMaxwell>("dgConservationLawMaxwell"); - cb->setDescription("The conservative law for Maxwell"); - methodBinding *cm; - cm = cb->addMethod("newBoundaryWall",&dgConservationLawMaxwell::newBoundaryWall); - cm->setDescription("wall boundary"); - cm = cb->setConstructor<dgConservationLawMaxwell, const function *>(); - cm->setArgNames("mu_eps",NULL); - cm->setDescription("A new Maxwell conservation law."); - cb->setParentClass<dgConservationLaw>(); - cb->setDescription("Advection for Maxwell equation."); -} diff --git a/Solver/dgConservationLawMaxwell.h b/Solver/dgConservationLawMaxwell.h deleted file mode 100644 index aa4e15ac6456b49f3c148faea8d21c20a16c7e4d..0000000000000000000000000000000000000000 --- a/Solver/dgConservationLawMaxwell.h +++ /dev/null @@ -1,22 +0,0 @@ -#ifndef _DG_CONSERVATION_LAW_MAXWELL_H -#define _DG_CONSERVATION_LAW_MAXWELL_H -#include "dgConservationLaw.h" - - - -class dgConservationLawMaxwell : public dgConservationLaw { - const function *_mu_epsFunction; - class advection; - class source; - class riemann; - public: - dataCacheDouble *newConvectiveFlux( dataCacheMap &cacheMap) const; - dataCacheDouble *newRiemannSolver( dataCacheMap &cacheMapLeft, dataCacheMap &cacheMapRight) const; - dataCacheDouble *newSourceTerm (dataCacheMap &cacheMap) const; - dgBoundaryCondition *newBoundaryWall () ; - dgConservationLawMaxwell(const function *mu_epsFunction); - -}; -class binding; -void dgConservationLawMaxwellRegisterBindings(binding *b); -#endif diff --git a/Solver/dgConservationLawPerfectGas.cpp b/Solver/dgConservationLawPerfectGas.cpp deleted file mode 100644 index 2ec3831ca8eea0b6643aea11142399c912fe39a5..0000000000000000000000000000000000000000 --- a/Solver/dgConservationLawPerfectGas.cpp +++ /dev/null @@ -1,868 +0,0 @@ -#include "dgConservationLawPerfectGas.h" -#include "function.h" -class dgPerfectGasLaw2d : public dgConservationLaw { - class advection; - class diffusion; - class riemann; - class riemannGodunov; - class source; - class maxConvectiveSpeed; - class maxDiffusivity; - class clipToPhysics; - // the name of the functions for - // viscosity (_muFunctionName) - // thermal conductivity (_kappaFunctionName) - const function *_kappaFunction, *_muFunction; - const function *_sourceFunction; - - public: - dataCacheDouble *newMaxConvectiveSpeed( dataCacheMap &cacheMap) const; - dataCacheDouble *newMaximumDiffusivity( dataCacheMap &cacheMap) const; - dataCacheDouble *newConvectiveFlux( dataCacheMap &cacheMap) const; - dataCacheDouble *newRiemannSolver( dataCacheMap &cacheMapLeft, dataCacheMap &cacheMapRight) const; - dataCacheDouble *newDiffusiveFlux( dataCacheMap &cacheMap) const; - dataCacheDouble *newSourceTerm (dataCacheMap &cacheMap) const; - dataCacheDouble *newClipToPhysics (dataCacheMap &cacheMap) const; - dgPerfectGasLaw2d(); - dgBoundaryCondition *newWallBoundary() ; - dgBoundaryCondition *newSlipWallBoundary() ; - // sets some coefficients - void setViscosityAndThermalConductivity (const function *a, const function *b){ - _muFunction = a; - _kappaFunction = b; - } - // sets some coefficients - void setSource(const function *a){ - _sourceFunction = a; - } -}; - -/* -\rho \left(\frac{\partial \mathbf{v}}{\partial t} + \mathbf{v} \cdot \nabla \mathbf{v}\right) = -\nabla p + \mu \nabla^2 \mathbf{v} + \left( \tfrac13 \mu + \mu^v) \nabla (\nabla \cdot \mathbf{v} \right) + \rho \mathbf{f} -*/ - -const double GAMMA = 1.4; -#define RIEM_TOL ((double)1e-12) /* Rel error to achieve in pstar */ -#define RIEM_ITER (20) /* Max number of iterations */ - -#define smallu ((double)1e-14) -#define smallp ((double)1e-14) - -#define max2(a,b) ( (a)>(b) ? (a) : (b) ) -#define max3(a,b,c) ( max2( a , max2(b,c) ) ) - -bool riemannExact( double rho1, /* inputs */ - double u1, - double v1, - double w1, - double p1, - double rho2, - double u2, - double v2, - double w2, - double p2, - double *rhoav, /* outputs */ - double *uav, - double *utav, - double *uttav, - double *pav ) -{ - - /* - * local variables (previously in commons) - */ - // double rho,u,p,ut,utt; - - int n; - double plft, vlft, ulft, utlft, uttlft, clft; - double prght, vrght, urght, utrght, uttrght, crght; - double pstar, ustar, rhostr, cestar, westar, vstar; - double rhos, us, uts, utts, ps; - double ws, vs, wes, ces; - double wlft, wrght; - double scrch1, scrch2, scrch3, scrch4; - double prevpstar, relpstar; - // double Q[4]; - - - // - // rml - convert to flash unknowns; - // - - vlft= (double)1/ rho1; // volume over mass - ulft= u1; - utlft= v1; - uttlft= w1; - plft= p1; - - if(plft/vlft < 0.0){ - return false;} - clft=sqrt(GAMMA*plft/vlft); // rho * eulerian sound speed - - vrght= (double)1/ rho2; - urght= u2; - utrght= v2; - uttrght= w2; - prght= p2; - if(prght/vrght < 0.0) { - - - return false;} - crght=sqrt(GAMMA*prght/vrght); - - // - // Start of Bruce's original code - // - - - pstar=prght-plft-crght*(urght-ulft); - pstar=plft+pstar*clft/(clft+crght); - pstar=max2(smallp,pstar); - - // - // rml - add ability to jump of out loop when converged - // - - prevpstar=pstar; // save previous value - relpstar=RIEM_TOL; - - for (n=0; n<RIEM_ITER && relpstar>=RIEM_TOL ; n++) - { - scrch1=0.5*(GAMMA+1.)/GAMMA; - wlft=1.+scrch1*(pstar-plft)/plft; - wrght=1.+scrch1*(pstar-prght)/prght; - - if(wlft<0.0 || wrght<0.0) - { - return false;} - wlft=clft*sqrt(wlft); - wrght=crght*sqrt(wrght); - - scrch1=4.*vlft*wlft*wlft; - scrch1=-scrch1*wlft/(scrch1-(GAMMA+1.)*(pstar-plft)); - scrch2=4.*vrght*wrght*wrght; - scrch2=scrch2*wrght/(scrch2-(GAMMA+1.)*(pstar-prght)); - scrch3=ulft-(pstar-plft)/wlft; - scrch4=urght+(pstar-prght)/wrght; - pstar=pstar+(scrch4-scrch3)*(scrch1*scrch2)/(scrch2-scrch1); - pstar=max2(smallp,pstar); - - // - // rml - compute relative error - // - - relpstar=fabs(pstar-prevpstar)/prevpstar; - // printf("pstar %e diff %e relpstar %e\n", - // pstar,pstar-prevpstar,relpstar); - - prevpstar=pstar; - } - - if (relpstar>=RIEM_TOL) - { - printf("Riemann solver failed : residual %12.5E\n",relpstar); - return false; - } - - scrch3=ulft-(pstar-plft)/wlft; - scrch4=urght+(pstar-prght)/wrght; - ustar=0.5*(scrch3+scrch4); - - if (ustar>=0) - scrch1= 1; - else - scrch1= -1; - - - scrch2=0.5*(1.+scrch1); - scrch3=0.5*(1.-scrch1); - ps=plft*scrch2+prght*scrch3; - us=ulft*scrch2+urght*scrch3; - uts=utlft*scrch2+utrght*scrch3; - utts=uttlft*scrch2+uttrght*scrch3; // rml 3rd dimension - - vs=vlft*scrch2+vrght*scrch3; - rhos=1./vs; - ws=wlft*scrch2+wrght*scrch3; - - if(ps*vs < 0) { - return false; - } - - ces=sqrt(GAMMA*ps*vs); - vstar=vs-(pstar-ps)/(ws*ws); - vstar=max2(vstar,(GAMMA-1.)/(GAMMA+1.)*vs); - rhostr=1./vstar; - - if(pstar*vstar < 0) - { - return false;} - - cestar=sqrt(GAMMA*pstar*vstar); - wes=ces-scrch1*us; - westar=cestar-scrch1*ustar; - scrch4=ws*vs-scrch1*us; - - if ( (pstar-ps) >= 0 ) - { - wes=scrch4; - westar=scrch4; - } - - - // - // compute correct state for rarefaction fan - // - - scrch1=max3(wes-westar,wes+westar,smallu); - scrch1=(wes+westar)/scrch1; - scrch1=0.5*(1.+scrch1); - scrch2=1.-scrch1; - - *rhoav= scrch1*rhostr+scrch2*rhos; - *uav= scrch1*ustar+scrch2*us; - *utav= uts; - *uttav= utts; // rml 3rd dimension // - *pav=scrch1*pstar+scrch2*ps; - - if (westar>=0) - { - *rhoav= rhostr; - *uav= ustar; - *pav= pstar; - } - - if (wes<0) - { - *rhoav= rhos; - *uav= us; - *pav= ps; - } - - return true; -} - -static inline void _ROE2D (const double &_GAMMA, - const double &nx, - const double &ny, - const double *solL, - const double *solR, - double *FLUX){ - - //sol cons var: rho, rhou, rhov, rhoE - //u prim var : rho, u, v, p - const double gamma = _GAMMA; - const double GM1 = gamma - 1.; - - double uL[4], uR[4]; - const double overRhoL = 1./solL[0]; - - uL[0] = solL[0]; - uL[1] = solL[1]*overRhoL; - uL[2] = solL[2]*overRhoL; - uL[3] = GM1*(solL[3] - 0.5* (solL[1]*solL[1]+solL[2]*solL[2])*overRhoL); - - const double overRhoR = 1./solR[0]; - uR[0] = solR[0]; - uR[1] = solR[1]*overRhoR; - uR[2] = solR[2]*overRhoR; - uR[3] = GM1*(solR[3] - 0.5* (solR[1]*solR[1]+solR[2]*solR[2])*overRhoR); - - //* --- central contributions ---*/ - - double halfrhoun; - // --- left contributions - halfrhoun = 0.5*(uL[0]*(uL[1]*nx + uL[2]*ny)); - double HL = gamma/GM1* uL[3]/uL[0]+0.5*(uL[1]*uL[1]+uL[2]*uL[2]); - FLUX[0] = halfrhoun; - FLUX[1] = halfrhoun*uL[1] + .5*uL[3]*nx; - FLUX[2] = halfrhoun*uL[2] + .5*uL[3]*ny; - FLUX[3] = halfrhoun*HL; - - // --- right contributions - halfrhoun = 0.5*(uR[0]*(uR[1]*nx+uR[2]*ny)); - double HR = gamma/GM1* uR[3]/uR[0]+0.5*(uR[1]*uR[1]+uR[2]*uR[2]); - FLUX[0] += halfrhoun; - FLUX[1] += halfrhoun*uR[1] + .5*uR[3]*nx; - FLUX[2] += halfrhoun*uR[2] + .5*uR[3]*ny; - FLUX[3] += halfrhoun*HR; - - /* --- add rhoe dissipation ---*/ - - double sqr_rhoL = sqrt(uL[0]); - double sqr_rhoR = sqrt(uR[0]); - double invz1 = 1./ (sqr_rhoL + sqr_rhoR); - - //rhoe average state - double u = ( sqr_rhoL* uL[1] + sqr_rhoR * uR[1] ) * invz1; - double v = ( sqr_rhoL* uL[2] + sqr_rhoR * uR[2] ) * invz1; - double H = ( sqr_rhoL* HL + sqr_rhoR * HR ) * invz1; - - double dU[4]; - for (int k=0;k<4;k++) dU[k] = solR[k] - solL[k]; - - double un = u*nx + v*ny ; - double tet = ny*u - nx*v; - - double u2 = u*u + v*v; - double c2 = GM1 * ( H - 0.5 * u2); - double c = sqrt(c2); - - double g1 = gamma - 1.; - double oC = 1./c; - double oC2 = oC*oC; - - double g1OnC2 = g1*oC2; - double TtOnT = (1.0 - u2*g1OnC2); - - // matrix of left eigenvectors - double L[16] = { - nx*TtOnT ,nx*u*g1OnC2 ,nx*v*g1OnC2 , -nx*g1OnC2, // L1 - - tet , ny ,-nx , 0, // L3 - g1*u2 - c*un , c*nx - g1*u , c*ny - g1*v, g1, // L3 - g1*u2 + c*un ,-c*nx - g1*u ,-c*ny - g1*v, g1}; // L4 - - // characteristic decomposition of differences - double dW[4] = {0,0,0,0}; - int idx = 0; - for (int i=0;i<4;i++) - for (int j=0;j<4;j++) - dW[i] += L[idx++]*dU[j]; - - // matrix of right eigenvectors - double R[16] = { - //R1 //R2 //R3 //R4 - nx ,0 ,0.5*oC2 ,0.5*oC2, - u*nx ,ny ,0.5*(nx*oC + u*oC2),0.5*(-nx*oC + u*oC2), - v*nx ,- nx ,0.5*(ny*oC + v*oC2),0.5*(-ny*oC + v*oC2), - u2*nx,tet ,0.5*(un*oC + H*oC2),0.5*(-un*oC + H*oC2)}; - - // eigenvalues - // TODO : shouldn't we take into account an entropy correction ? - // absorb half the surface : scaling wrt central term - - const double A = 0.5; - double eps = 1.e-6; - double absUn = (fabs(un) + eps*c)*A; - double lA[4] = {absUn, - absUn, - fabs(un + c)*A, - (fabs(un - c)+eps*c)*A}; - - // add wave contributions to flux - int index = 0; - - for (int k=0;k<4;k++) { - double lflux = FLUX[k]; - for (int j=0;j<4;j++) - lflux -= lA[j]*dW[j]*R[index++]; - FLUX[k] = -lflux; - } -}; - -class dgPerfectGasLaw2d::advection : public dataCacheDouble { - dataCacheDouble / - public: - advection(dataCacheMap &cacheMap): - dataCacheDouble(cacheMap,1,8), - sol(cacheMap.get(function::getSolution(), this)) - {}; - void _eval () { - const int nQP = _value.size1(); - const double GM1 = GAMMA - 1.0; - for (size_t k = 0 ; k < nQP; k++ ){ - const double invrho = 1./sol(k,0); - - const double q12 = sol(k,1)*sol(k,2)*invrho; - const double q11 = sol(k,1)*sol(k,1)*invrho; - const double q22 = sol(k,2)*sol(k,2)*invrho; - - const double p = GM1*sol(k,3) - 0.5*GM1*(q11+q22); - const double qq = invrho*(sol(k,3)+p); - - _value(k,0) = sol(k,1); - _value(k,1) = q11+p; - _value(k,2) = q12; - _value(k,3) = sol(k,1)*qq; - - _value(k,0+4) = sol(k,2); - _value(k,1+4) = q12; - _value(k,2+4) = q22+p; - _value(k,3+4) = sol(k,2)*qq; - - } - } -}; - -class dgPerfectGasLaw2d::diffusion : public dataCacheDouble { - dataCacheDouble &sol,&grad,&mu,κ - public: - diffusion(dataCacheMap &cacheMap, - const function * muFunction, - const function * kappaFunction ): - dataCacheDouble(cacheMap,1,12), - sol(cacheMap.get(function::getSolution(), this)), - grad(cacheMap.get(function::getSolutionGradient(), this)), - mu(cacheMap.get(muFunction,this)), - kappa(cacheMap.get(kappaFunction,this)) - {}; - void _eval () { - const int nQP = sol().size1(); - for (size_t k = 0 ; k < nQP; k++ ){ - const double muk = mu(k,0); - const double kappak = kappa(k,0); - // printf("%g %g grad rho (%g %g)\n",muk,kappak,grad(k*3+0,0),grad(k*3+1,0)); - // find gradients of primitive variables - const double overRho = 1./sol(k,0); - const double u = sol(k,1) * overRho; - const double v = sol(k,2) * overRho; - // grad v - const double dudx = (grad(k,3) - grad(k,0) * u) * overRho; - const double dudy = (grad(k,4) - grad(k,1) * u) * overRho; - const double dvdx = (grad(k,6) - grad(k,0) * v) * overRho; - const double dvdy = (grad(k,7) - grad(k,1) * v) * overRho; - // shear stress tensor - Newtonian fluid without bulk viscosity - - const double tauxx = muk * (dudx - dvdy); - const double tauxy = muk * (dudy + dvdx); - const double tauyy = - tauxx; - - _value(k,1) = -tauxx; - _value(k,2) = -tauxy; - - _value(k,1+4) = -tauxy; - _value(k,2+4) = -tauyy; - // heat flux - - const double kOverRhoCv = kappak * overRho; - const double Ek = u * u + v * v; - const double eMinus= sol(k,3) * overRho - Ek; - - // k grad T - - _value(k,3) = -kOverRhoCv*(grad(k, 9 ) - eMinus*grad(k, 0) - (grad(k, 3)*u + grad(k, 6)*v)); - _value(k,3+4) = -kOverRhoCv*(grad(k, 10) - eMinus*grad(k, 1) - (grad(k, 4)*u + grad(k, 7)*v)); - - // v . tau - momentum dissipation - - _value(k,3) -= (u * tauxx + v * tauxy); - _value(k,3+4) -= (u * tauxy + v * tauyy); - - // printf("%g %g %g %g %g %g %g %g \n",_value(k,0),_value(k,1),_value(k,2),_value(k,3),_value(k,4),_value(k,5),_value(k,6),_value(k,7)); - - } - } -}; - -class dgPerfectGasLaw2d::source : public dataCacheDouble { - dataCacheDouble &sol,&s; -public: - source(dataCacheMap &cacheMap, const function *sourceFunction): - dataCacheDouble(cacheMap,1,4), - sol(cacheMap.get(function::getSolution(), this)), - s(cacheMap.get(sourceFunction,this)) - {}; - void _eval () { - const int nQP = sol().size1(); - for (size_t k = 0 ; k < nQP; k++ ){ - _value(k,0) = sol(k,0)*s(0,0); - _value(k,1) = sol(k,0)*s(0,1); - _value(k,2) = sol(k,0)*s(0,2); - _value(k,3) = sol(k,0)*s(0,3); - } - } -}; - -class dgPerfectGasLaw2d::clipToPhysics : public dataCacheDouble { - dataCacheDouble / - double _presMin, _rhoMin; -public: - clipToPhysics(dataCacheMap &cacheMap, double presMin, double rhoMin): - dataCacheDouble(cacheMap,1,4), - sol(cacheMap.get(function::getSolution(), this)) - { - _presMin=presMin; - _rhoMin=rhoMin; - }; - void _eval () { - const int nDofs = sol().size1(); - for (size_t k = 0 ; k < nDofs; k++ ){ - _value(k,0) = sol(k,0); - _value(k,1) = sol(k,1); - _value(k,2) = sol(k,2); - _value(k,3) = sol(k,3); - if (sol(k,0) < _rhoMin){ - //printf("CL: clip rho min =%g \n", _rhoMin); - _value(k,0) = _rhoMin; - } - double rhoV2 = sol(k,1)*sol(k,1)+sol(k,2)*sol(k,2); - rhoV2 /= sol(k,0); - const double p = (GAMMA-1)*(sol(k,3) - 0.5*rhoV2); - if (p < _presMin) { - _value(k,3) = _presMin / (GAMMA-1) + 0.5 *rhoV2 ; - //printf("CL: clip pres min =%g \n ", _value(k,3)); - } - } - } -}; - - -class dgPerfectGasLaw2d::riemann : public dataCacheDouble { - dataCacheDouble &normals, &solL, &solR; - public: - riemann(dataCacheMap &cacheMapLeft, dataCacheMap &cacheMapRight): - dataCacheDouble(cacheMapLeft,1,12), - normals(cacheMapLeft.get(function::getNormals(), this)), - solL(cacheMapLeft.get(function::getSolution(), this)), - solR(cacheMapRight.get(function::getSolution(), this)) - {}; - void _eval () { - int nQP = solL().size1(); - for(int i=0; i< nQP; i++) { - const double solLeft [4] = {solL(i,0),solL(i,1),solL(i,2),solL(i,3)}; - const double solRight[4] = {solR(i,0),solR(i,1),solR(i,2),solR(i,3)}; - double FLUX[4] ; - const double nx = normals(0,i); - const double ny = normals(1,i); - _ROE2D (GAMMA,nx,ny,solLeft,solRight,FLUX); - - _value(i,0) = FLUX[0]; - _value(i,1) = FLUX[1]; - _value(i,2) = FLUX[2]; - _value(i,3) = FLUX[3]; - _value(i,4) = -_value(i,0); - _value(i,5) = -_value(i,1); - _value(i,6) = -_value(i,2); - _value(i,7) = -_value(i,3); - } - } -}; - -class dgPerfectGasLaw2d::riemannGodunov : public dataCacheDouble { - dataCacheDouble &normals, &solL, &solR; - public: - riemannGodunov(dataCacheMap &cacheMapLeft, dataCacheMap &cacheMapRight): - dataCacheDouble(cacheMapLeft,1,12), - normals(cacheMapLeft.get(function::getNormals(), this)), - solL(cacheMapLeft.get(function::getSolution(), this)), - solR(cacheMapRight.get(function::getSolution(), this)) - {}; - void _eval () { - int nQP = solL().size1(); - for(int i=0; i< nQP; i++) { - const double nx = normals(0,i); - const double ny = normals(1,i); - - const double unL = (solL(i,1)*nx+solL(i,2)*ny)/solL(i,0); - const double utL = (solL(i,1)*ny-solL(i,2)*nx)/solL(i,0); - const double rhoV2L = (unL*unL+utL*utL)*solL(i,0); - const double pL = (GAMMA-1.)*solL(i,3) - 0.5*(GAMMA-1.)* rhoV2L; - - const double unR = (solR(i,1)*nx+solR(i,2)*ny)/solR(i,0); - const double utR = (solR(i,1)*ny-solR(i,2)*nx)/solR(i,0); - const double rhoV2R = (unR*unR+utR*utR)*solR(i,0); - const double pR = (GAMMA-1.)*solR(i,3) - 0.5*(GAMMA-1.)* rhoV2R; - - double rhoAv,unAv,utAv,usAv,pAv; - riemannExact(solL(i,0), unL,utL,0.0,pL, - solR(i,0), unR,utR,0.0,pR, - &rhoAv,&unAv,&utAv,&usAv,&pAv); - - - const double vxAv = unAv * nx + utAv *ny; - const double vyAv = unAv * ny - utAv *nx; - // p = rho E (G-1) - 0.5 (G-1) * rho V^2 - // rho E = p / (G-1) + 0.5 * rho V^2 - const double rhoE = - (1./(GAMMA-1.)) * pAv + 0.5 * rhoAv * (vxAv*vxAv + vyAv*vyAv); - - /* printf("%g %g %g %g, (%g %g) %g %g %g %g\n", - solL(i,0), solL(i,1), solL(i,2), solL(i,3),pL,pAv, - rhoAv, rhoAv*vxAv,rhoAv*vyAv,rhoE); - */ - const double F0 = rhoAv * unAv; - /* - const double qq = invrho*(sol(k,3)+p); - - _value(k,0) = sol(k,1); - _value(k,1) = q11+p; - _value(k,2) = q12; - _value(k,3) = sol(k,1)*qq; - */ - - _value(i,0) = -F0; - _value(i,1) = -(F0*vxAv + pAv*nx); - _value(i,2) = -(F0*vyAv + pAv*ny); - _value(i,3) = - (rhoE+pAv) * unAv; - _value(i,4) = -_value(i,0); - _value(i,5) = -_value(i,1); - _value(i,6) = -_value(i,2); - _value(i,7) = -_value(i,3); - } - } -}; - -class dgPerfectGasLaw2d::maxConvectiveSpeed : public dataCacheDouble { - dataCacheDouble / - public: - maxConvectiveSpeed(dataCacheMap &cacheMap): - dataCacheDouble(cacheMap,1,1), - sol(cacheMap.get(function::getSolution(), this)) - { - }; - void _eval () { - int nQP = sol().size1(); - for(int i=0; i< nQP; i++) { - const double rhov2 = (sol(i,1)*sol(i,1) + sol(i,2)*sol(i,2))/sol(i,0); - const double p = (GAMMA-1.0)*(sol(i,3) - 0.5 * rhov2); - // printf("p = %g %g %g %g %g\n",p,_value(i,0),_value(i,1),_value(i,2),_value(i,3)); - const double c = sqrt(GAMMA*p/sol(i,0)); - _value(i,0) = c+sqrt(rhov2/sol(i,0)); - } - } -}; - -class dgPerfectGasLaw2d::maxDiffusivity : public dataCacheDouble { - dataCacheDouble &sol,&mu,κ - public: - maxDiffusivity(dataCacheMap &cacheMap, const function *muFunction, const function *kappaFunction ): - dataCacheDouble(cacheMap,1,1), - sol(cacheMap.get(function::getSolution(), this)), - mu(cacheMap.get(muFunction,this)), - kappa(cacheMap.get(kappaFunction,this)) - { - }; - void _eval () { - int nQP = sol().size1(); - for(int i=0; i< nQP; i++) { - _value(i,0) = std::max(mu(i,0),kappa(i,0)); - } - } -}; - - -dataCacheDouble *dgPerfectGasLaw2d::newMaximumDiffusivity( dataCacheMap &cacheMap) const { - return _muFunction ? new maxDiffusivity(cacheMap,_muFunction,_kappaFunction) : NULL; -} - -dataCacheDouble *dgPerfectGasLaw2d::newMaxConvectiveSpeed( dataCacheMap &cacheMap) const { - return new maxConvectiveSpeed(cacheMap); -} -dataCacheDouble *dgPerfectGasLaw2d::newConvectiveFlux( dataCacheMap &cacheMap) const { - return new advection(cacheMap); -} -dataCacheDouble *dgPerfectGasLaw2d::newRiemannSolver( dataCacheMap &cacheMapLeft, dataCacheMap &cacheMapRight) const { - return new riemannGodunov(cacheMapLeft, cacheMapRight); -} -dataCacheDouble *dgPerfectGasLaw2d::newDiffusiveFlux( dataCacheMap &cacheMap) const { - if (!_muFunction || !_kappaFunction) - return 0; - else - return new diffusion(cacheMap,_muFunction,_kappaFunction); -} -dataCacheDouble *dgPerfectGasLaw2d::newSourceTerm (dataCacheMap &cacheMap) const { - return _sourceFunction ? new source(cacheMap, _sourceFunction) : NULL; -} -dataCacheDouble *dgPerfectGasLaw2d::newClipToPhysics( dataCacheMap &cacheMap) const { - return new clipToPhysics(cacheMap,1e-3,1e-3); -} - -dgPerfectGasLaw2d::dgPerfectGasLaw2d() - : _kappaFunction(0), _muFunction(0), _sourceFunction(0) -{ - _nbf = 4; // \rho \rho u \rho v \rho e -} - -//------------------------------------------------------------------------------- -// A class for slip and non slip walls -// could easily add moving walls ... -//------------------------------------------------------------------------------- -class dgBoundaryConditionPerfectGasLaw2dWall : public dgBoundaryCondition { - int _type; - class term : public dataCacheDouble { - dataCacheDouble &sol,&normals; - public: -//------------------------------------------------------------------------------- -// NON VISCOUS BOUNDARY FLUX -//------------------------------------------------------------------------------- - term(dataCacheMap &cacheMap): - dataCacheDouble(cacheMap,1,4), - sol(cacheMap.get(function::getSolution(), this)), - normals(cacheMap.get(function::getNormals(), this)){} - void _eval () { - int nQP = sol().size1(); - for(int i=0; i< nQP; i++) { - const double nx = normals(0,i); - const double ny = normals(1,i); - - const double solLeft [4] = {sol(i,0),sol(i,1),sol(i,2),sol(i,3)}; - const double vn = (solLeft [1] * nx + solLeft [2] * ny); - const double solRight[4] = {sol(i,0), - sol(i,1) - 2 * vn * nx, - sol(i,2) - 2 * vn * ny, - sol(i,3)}; - double FLUX[4] ; - _ROE2D (GAMMA,nx,ny,solLeft,solRight,FLUX); - _value(i,0) = FLUX[0]; - _value(i,1) = FLUX[1]; - _value(i,2) = FLUX[2]; - _value(i,3) = FLUX[3]; - /* - const double q11 = sol(i,1)*sol(i,1)/sol(i,0); - const double q22 = sol(i,2)*sol(i,2)/sol(i,0); - const double p = (GAMMA-1.)*sol(i,3) - 0.5*(GAMMA-1.)*(q11+q22); - _value(i,0) = 0;//FLUX[0]; - _value(i,1) = -p*nx;//FLUX[1]; - _value(i,2) = -p*ny;//FLUX[2]; - _value(i,3) = 0.0;//FLUX[3]; - */ - - } - } - }; - -//------------------------------------------------------------------------------- -// Non Slip Dirichlet BC -- -// What to put on the right side of the IP (no velocity, same density) -// Assume Adiabatic Wall --> no heat transfer -> \partial_n T = 0 -// So, we use the same temperature as inside -//------------------------------------------------------------------------------- - class dirichletNonSlip : public dataCacheDouble { - dataCacheDouble / - public: - dirichletNonSlip(dataCacheMap &cacheMap): - dataCacheDouble(cacheMap,1,4), - sol(cacheMap.get(function::getSolution(), this)){} - void _eval () { - int nQP = sol().size1(); - for(int i=0; i< nQP; i++) { - _value(i,0) = sol(i,0); - _value(i,1) = 0.0; - _value(i,2) = 0.0; - _value(i,3) = sol(i,3) - 0.5 * (sol(i,1) * sol(i,1) + sol(i,2) * sol(i,2))/sol(i,0); - } - } - }; - -//------------------------------------------------------------------------------- -// Non Slip Neumann BC -- -// Compute normal diffusive fluxes at the boundary -// Assume Adiabatic Wall --> no heat transfer -> no flux for component 3 (in 2D) -//------------------------------------------------------------------------------- - - class neumannNonSlip : public dataCacheDouble { - dgConservationLaw *_claw; - dataCacheDouble &sol,&normals; - dataCacheDouble *diffusiveFlux; - public: - neumannNonSlip(dataCacheMap &cacheMap, dgConservationLaw *claw): - dataCacheDouble(cacheMap,1,4), - _claw (claw), - sol(cacheMap.get(function::getSolution(), this)), - normals(cacheMap.get(function::getNormals(), this)){ - diffusiveFlux=_claw->newDiffusiveFlux(cacheMap); - if (diffusiveFlux)diffusiveFlux->addMeAsDependencyOf(this); - } - void _eval () { - int nQP = sol().size1(); - const fullMatrix<double> &dfl = (*diffusiveFlux)(); - - for(int i=0; i< nQP; i++) { - for (int k=0;k<3;k++) { - _value(i,k) = - dfl(i,k+4*0) *normals(0,i) + - dfl(i,k+4*1) *normals(1,i) + - dfl(i,k+4*2) *normals(2,i); - } - _value(i,3) = 0.0; - } - } - ~neumannNonSlip (){}; - }; - -//------------------------------------------------------------------------------- -// Slip Wall Dirichlet BC -- -// Assume zero normal derivatives of all variables --> put the same as inside -//------------------------------------------------------------------------------- - - class dirichletSlip : public dataCacheDouble { - dataCacheDouble / - public: - dirichletSlip(dataCacheMap &cacheMap): - dataCacheDouble(cacheMap,1,cacheMap.get(function::getSolution(), NULL)().size2()), - sol(cacheMap.get(function::getSolution(), this)){} - void _eval () { - int nQP = sol().size1(); - for(int i=0; i< nQP; i++) { - for(int k=0; k< sol().size2(); k++) { - _value(i,k) = sol(i,k); - } - } - } - }; - -//------------------------------------------------------------------------------- -// Slip Wall or Symmetry Neumann BC -- assume NO FLUXES AT ALL -//------------------------------------------------------------------------------- - - class neumannSlip : public dataCacheDouble { - dgConservationLaw *_claw; - dataCacheDouble &sol,&normals; - public: - neumannSlip(dataCacheMap &cacheMap, dgConservationLaw *claw): - _claw (claw), - dataCacheDouble(cacheMap,1,4), - sol(cacheMap.get(function::getSolution(), this)), - normals(cacheMap.get(function::getNormals(), this)){ - } - void _eval () { - int nQP = sol().size1(); - _value.setAll(0.0); - } - }; - - public: - dgBoundaryConditionPerfectGasLaw2dWall(int type, dgPerfectGasLaw2d *claw):_type(type), dgBoundaryCondition(claw){} - dataCacheDouble *newBoundaryTerm(dataCacheMap &cacheMapLeft) const { - return new term(cacheMapLeft); - } - dataCacheDouble *newDiffusiveDirichletBC(dataCacheMap &cacheMapLeft) const { - switch(_type){ - case 1 : return new dirichletSlip(cacheMapLeft); - case 2 : return new dirichletNonSlip(cacheMapLeft); - } - } - dataCacheDouble *newDiffusiveNeumannBC(dataCacheMap &cacheMapLeft) const { - switch(_type){ - case 1 : return new neumannSlip(cacheMapLeft,_claw); - case 2 : return new neumannNonSlip(cacheMapLeft,_claw); - } - } -}; - -dgBoundaryCondition *dgPerfectGasLaw2d::newWallBoundary() { - return new dgBoundaryConditionPerfectGasLaw2dWall(2, this); -} -dgBoundaryCondition *dgPerfectGasLaw2d::newSlipWallBoundary() { - return new dgBoundaryConditionPerfectGasLaw2dWall(1, this); -} - -#include "Bindings.h" -void dgPerfectGasLaw2dRegisterBindings (binding *b){ - classBinding *cb = b->addClass<dgPerfectGasLaw2d>("dgPerfectGasLaw2d"); - cb->setDescription("Perfect Gas conservation law\n\\rho \\left(\\frac{\\partial \\mathbf{v}}{\\partial t} + \\mathbf{v} \\cdot \\nabla \\mathbf{v}\\right) = -\\nabla p + \\mu \\nabla^2 \\mathbf{v} + \\left( \\tfrac13 \\mu + \\mu^v) \\nabla (\\nabla \\cdot \\mathbf{v} \\right) + \\rho \\mathbf{f}"); - methodBinding *cm; - cm = cb->addMethod("newNonSlipWallBoundary",&dgPerfectGasLaw2d::newWallBoundary); - cm->setDescription("non slip wall"); - cm = cb->addMethod("newSlipWallBoundary",&dgPerfectGasLaw2d::newSlipWallBoundary); - cm->setDescription("slip wall"); - cm = cb->addMethod("setSource",&dgPerfectGasLaw2d::setSource); - cm->setArgNames("f",NULL); - cm->setDescription("set the function to compute the source term"); - cm = cb->addMethod("setViscosityAndThermalConductivity",&dgPerfectGasLaw2d::setViscosityAndThermalConductivity); - cm->setArgNames("f_mu","f_kappa",NULL); - cm->setDescription("set the fonctions to compute mu and kappa, the scalar viscosity and thermal conductivity coefficients"); - cm = cb->setConstructor<dgPerfectGasLaw2d>(); - cm->setDescription("A new perfect gas conservation law"); - cb->setParentClass<dgConservationLaw>(); -} diff --git a/Solver/dgConservationLawPerfectGas.h b/Solver/dgConservationLawPerfectGas.h deleted file mode 100644 index df0c4904f6986d049de5450ec37306d4fb5e3de2..0000000000000000000000000000000000000000 --- a/Solver/dgConservationLawPerfectGas.h +++ /dev/null @@ -1,11 +0,0 @@ -#ifndef _DG_CONSERVATION_LAW_PERFECT_GAS_H_ -#define _DG_CONSERVATION_LAW_PERFECT_GAS_H_ -#include "dgConservationLaw.h" -// Compressible Navier-Stokes equations -// d(rho)/dt + d(rhou)/dx + d(rhov)/dy = 0 -// d(rhou)/dt + d(rhou^2+p)/dx + d(rhouv)/dy + d(t_xx)/dx + d(t_xy)/dy= 0 -// d(rhov)/dt + d(rhouv)/dx + d(rhov^2+p)/dy + d(t_xy)/dx + d(t_yy)/dy= 0 -// d(rhoE)/dt + d(rhouH)/dx + d(rhovH)/dy + d(ut_xx+vt_xy-q_x)/dx + d(ut_xy+vt_yy-q_y)/dy= 0 -class binding; -void dgPerfectGasLaw2dRegisterBindings(binding *b); -#endif diff --git a/Solver/dgConservationLawShallowWater1d.cpp b/Solver/dgConservationLawShallowWater1d.cpp deleted file mode 100644 index a998cda842bfcaa27a114251e45f933ace0e5aba..0000000000000000000000000000000000000000 --- a/Solver/dgConservationLawShallowWater1d.cpp +++ /dev/null @@ -1,294 +0,0 @@ -#include "dgConservationLawShallowWater1d.h" -#include "function.h" - -class dgConservationLawShallowWater1d : public dgConservationLaw { - class advection; - class source; - class riemann; - class boundaryWall; - class clipToPhysics; - class maxConvectiveSpeed; - const function *_bathymetry, *_linearDissipation, *_pressure, *_celerity; - public: - dataCacheDouble *newConvectiveFlux( dataCacheMap &cacheMap) const; - dataCacheDouble *newMaxConvectiveSpeed( dataCacheMap &cacheMap) const; - dataCacheDouble *newRiemannSolver( dataCacheMap &cacheMapLeft, dataCacheMap &cacheMapRight) const; - dataCacheDouble *newDiffusiveFlux( dataCacheMap &cacheMap) const; - dataCacheDouble *newSourceTerm (dataCacheMap &cacheMap) const; - dataCacheDouble *newClipToPhysics (dataCacheMap &cacheMap) const; - inline void setPressureFlux(const function *pressure) { _pressure = pressure;} - inline void setCelerity(const function *celerity) { _celerity = celerity;} - inline void setBathymetry(const function *bathymetry) { _bathymetry = bathymetry;} - inline void setLinearDissipation(const function *linearDissipation){ _linearDissipation = linearDissipation;} - inline const function* getPressureFlux() {return _pressure;}; - dgConservationLawShallowWater1d() - { - _nbf = 2; // eta u - function *fzero = functionConstantNew(0.); - _pressure = fzero; - _celerity = fzero; - _bathymetry = fzero; - _linearDissipation = fzero; - } - dgBoundaryCondition *newBoundaryWall(); -}; - -class dgConservationLawShallowWater1d::clipToPhysics : public dataCacheDouble { - dataCacheDouble &sol, &_bathymetry; - double _hMin; -public: - clipToPhysics(dataCacheMap &cacheMap, const function *bathymetry, double hMin): - dataCacheDouble(cacheMap,1,3), - sol(cacheMap.get(function::getSolution(),this)), - _bathymetry(cacheMap.get(bathymetry,this)) - { - _hMin=hMin; - }; - void _eval () { - int nQP = _value.size1(); - for (size_t k = 0 ; k < nQP; k++ ){ - double h = _bathymetry(k,0); - _value(k,0) = sol(k,0); - _value(k,1) = sol(k,1); - double H = sol(k,0)+h; - if (H < _hMin){ - _value(k,0) = _hMin; - } - } - } -}; - -class dgConservationLawShallowWater1d::maxConvectiveSpeed : public dataCacheDouble { - dataCacheDouble &sol, &_celerity; - public: - maxConvectiveSpeed(dataCacheMap &cacheMap, const function *celerity): - dataCacheDouble(cacheMap,1,1), - sol(cacheMap.get(function::getSolution(),this)), - _celerity(cacheMap.get(celerity,this)) - {}; - void _eval () { - int nQP = sol().size1(); - for(int i=0; i< nQP; i++) { - _value(i,0) = sol(i,1) + _celerity(i,0); - } - } -}; - -class dgConservationLawShallowWater1d::advection: public dataCacheDouble { - dataCacheDouble &sol, &_bathymetry, &_pressure; - public: - advection(dataCacheMap &cacheMap, const function *bathymetry, const function *pressure): - dataCacheDouble(cacheMap,1,6), - sol(cacheMap.get(function::getSolution(),this)), - _bathymetry(cacheMap.get(bathymetry,this)), - _pressure(cacheMap.get(pressure,this)) - {}; - void _eval () { - int nQP = _value.size1(); - for(int i=0; i< nQP; i++) { - double h = _bathymetry(i,0); - double p = _pressure(i,0); - double eta = sol(i,0); - double u = sol(i,1); - // flux_x - _value(i,0) = (h+eta)*u; - _value(i,1) = .5*u*u + p; - // flux_y - _value(i,2) = 0; - _value(i,3) = 0; - // flux_z - _value(i,4) = 0; - _value(i,5) = 0; - } - } -}; - -class dgConservationLawShallowWater1d::source: public dataCacheDouble { - dataCacheDouble &solution; - dataCacheDouble &_linearDissipation, &_bathymetry; - public : - source(dataCacheMap &cacheMap, const function *linearDissipation, const function *bathymetry) : - dataCacheDouble(cacheMap,1,2), - _linearDissipation(cacheMap.get(linearDissipation,this)), - solution(cacheMap.get(function::getSolution(),this)), - _bathymetry(cacheMap.get(bathymetry,this)) - {} - void _eval () { - int nQP =_value.size1(); - for (int i=0; i<nQP; i++) { - double h = _bathymetry(i,0); - double eta = solution(i,0); - double u = solution(i,1); - _value (i,0) = 0; - _value (i,1) = - _linearDissipation(i,0)*u/(h+eta) ; - } - } -}; -class dgConservationLawShallowWater1d::riemann:public dataCacheDouble { - dataCacheDouble &normals, &solL, &solR, &_bathymetryL, &_bathymetryR; - dataCacheDouble &_pressureL, &_pressureR, &_celerityL, &_celerityR; - public: - riemann(dataCacheMap &cacheMapLeft, dataCacheMap &cacheMapRight, const function *bathymetry, - const function *pressure, const function *celerity): - dataCacheDouble(cacheMapLeft,1,4), - normals(cacheMapLeft.get(function::getNormals(), this)), - solL(cacheMapLeft.get(function::getSolution(),this)), - solR(cacheMapRight.get(function::getSolution(),this)), - _bathymetryL(cacheMapLeft.get(bathymetry, this)), - _bathymetryR(cacheMapRight.get(bathymetry, this)), - _pressureL(cacheMapLeft.get(pressure, this)), - _pressureR(cacheMapRight.get(pressure, this)), - _celerityL(cacheMapLeft.get(celerity, this)), - _celerityR(cacheMapRight.get(celerity, this)) - {}; - void _eval () { - int nQP = solL().size1(); - for(int i=0; i< nQP; i++) { - double hL = _bathymetryL(i,0); double hR = _bathymetryR(i,0); - double n0 = normals(0,i); - double HL = solL(i,0) + hL, HR = solR(i,0) + hR; - double uL = solL(i,1) , uR = solR(i,1) ; - double sqHL = sqrt(HL), sqHR = sqrt(HR); - double F1,F2; - -// //--------- -// //ROE -// //--------- -// double HuL = uL*HL, HuR = uR*HR; -// double HM = (HL+HR)/2, HJ = (HL-HR)/2; -// double HuM = (HuL+HuR)/2, HuJ = (HuL-HuR)/2; -// double u_roe = (sqHL*uL + sqHR*uR) / (sqHL + sqHR); -// double c_roe = sqrt(g*HM); //???? -// double H = HM + (HuJ - u_roe *HJ) / c_roe; -// double Hu = HuM + (c_roe - u_roe*u_roe/c_roe) *HJ + u_roe/c_roe *HuJ; -// double u = Hu / H; -// double p = RHO*g*(H-h); //???? -// F1 = H*u*n0; -// F2 = (.5*u*u + p/RHO)*n0; - -// //--------- -// //LAX -// //--------- - double pL = _pressureL(i,0); - double pR = _pressureR(i,0); - F1 = .5*( HL*uL + HR*uR )*n0; - F2 = .5*( .5*uL*uL+pL + .5*uR*uR+pR )*n0; - double maxlambdaL = uL + _celerityL(i,0); - double maxlambdaR = uR + _celerityR(i,0); - const double aMax = std::max(maxlambdaL,maxlambdaR); - F1 += aMax*(HL-HR); - F2 += aMax*(uL-uR); - -// //--------- -// //HLL -// //--------- - -// double pL = _pressureL(i,0); -// double pR = _pressureR(i,0); -// double ustar = (sqHL*uL + sqHR*uR) / (sqHL + sqHR); -// double Hstar = (HL+HR)*.5; -// double cstar = sqrt(g*Hstar); //???? -// double SL = std::min(uL - _celerityL(i,0), ustar - cstar); -// double SR = std::min(uR + _celerityR(i,0), ustar + cstar); -// if (SL >= 0.){ -// F1 = HL*uL*n0; -// F2 = (.5*uL*uL + pL/RHO )*n0 ; -// } -// else if (SR <=0.){ -// F1 = HR*uR*n0; -// F2 = (.5*uR*uR + pR/RHO )*n0 ; -// } -// else{ -// F1 = (SR*HL*uL*n0-SL*HR*uR*n0 + SL*SR*(HR-HL))/(SR-SL); -// F2 = (SR*(.5*uL*uL + pL/RHO )*n0-SL*(.5*uR*uR + pR/RHO )*n0 + SL*SR*(uR-uL))/(SR-SL); -// } - - //------------- - - _value(i,0) = -F1; - _value(i,1) = -F2; - _value(i,2) = -_value(i,0); - _value(i,3) = -_value(i,1); - - } - - } - -}; - -class dgConservationLawShallowWater1d::boundaryWall : public dgBoundaryCondition { - class term : public dataCacheDouble { - dataCacheDouble &sol,&normals, &_pressure; - public: - term(dataCacheMap &cacheMap, const function *pressure): - dataCacheDouble(cacheMap,1,2), - sol(cacheMap.get(function::getSolution(),this)), - _pressure(cacheMap.get(pressure,this)), - normals(cacheMap.get(function::getNormals(), this)) - {} - void _eval () { - int nQP = sol().size1(); - for(int i=0; i< nQP; i++) { - double n0 = normals(0,i); - double p = _pressure(i,0); - _value(i,0) = 0; - _value(i,1) = -p*n0; - } - } - }; - public: - dgConservationLawShallowWater1d *_claw; - boundaryWall(dgConservationLawShallowWater1d *claw) : dgBoundaryCondition(claw){_claw=claw;} - dataCacheDouble *newBoundaryTerm(dataCacheMap &cacheMapLeft) const { - return new term(cacheMapLeft, _claw->getPressureFlux()); - } -}; - - -dataCacheDouble *dgConservationLawShallowWater1d::newMaxConvectiveSpeed( dataCacheMap &cacheMap) const { - return new maxConvectiveSpeed(cacheMap, _celerity); -} -dataCacheDouble *dgConservationLawShallowWater1d::newConvectiveFlux( dataCacheMap &cacheMap) const { - return new advection(cacheMap, _bathymetry, _pressure); -} -dataCacheDouble *dgConservationLawShallowWater1d::newRiemannSolver( dataCacheMap &cacheMapLeft, dataCacheMap &cacheMapRight) const { - return new riemann(cacheMapLeft, cacheMapRight, _bathymetry, _pressure, _celerity); -} -dataCacheDouble *dgConservationLawShallowWater1d::newDiffusiveFlux( dataCacheMap &cacheMap) const { - return 0; -} -dataCacheDouble *dgConservationLawShallowWater1d::newSourceTerm (dataCacheMap &cacheMap) const { - return new source(cacheMap, _linearDissipation, _bathymetry); -} - -dgBoundaryCondition *dgConservationLawShallowWater1d::newBoundaryWall(){ - return new boundaryWall(this); -} - -dataCacheDouble *dgConservationLawShallowWater1d::newClipToPhysics( dataCacheMap &cacheMap) const { - return new clipToPhysics(cacheMap, _bathymetry, 1e-5); -} - -#include "Bindings.h" -void dgConservationLawShallowWater1dRegisterBindings (binding *b){ - classBinding *cb = b->addClass<dgConservationLawShallowWater1d>("dgConservationLawShallowWater1d"); - cb->setDescription("The non-conservative shallow water conservation law. (eta, u)"); - methodBinding *cm; - cm = cb->addMethod("newBoundaryWall",&dgConservationLawShallowWater1d::newBoundaryWall); - cm->setDescription("slip wall boundary"); - cm = cb->setConstructor<dgConservationLawShallowWater1d>(); - cm->setDescription("A new shallow water 1d conservation law."); - cb->setParentClass<dgConservationLaw>(); - cm = cb->addMethod("setLinearDissipation", &dgConservationLawShallowWater1d::setLinearDissipation); - cm->setDescription("set the function to evaluate the linear dissipation Kr u/A"); - cm->setArgNames("Kr",NULL); - cm = cb->addMethod("setBathymetry", &dgConservationLawShallowWater1d::setBathymetry); - cm->setDescription("set the function to evaluate the bathymetry h (H = h+eta)"); - cm->setArgNames("h",NULL); - cm = cb->addMethod("setPressureFlux", &dgConservationLawShallowWater1d::setPressureFlux); - cm->setDescription("set the function to evaluate the pressure flux"); - cm->setArgNames("pressureFlux",NULL); - cm = cb->addMethod("setCelerity", &dgConservationLawShallowWater1d::setCelerity); - cm->setDescription("set the function to the celerity of the waves"); - cm->setArgNames("celerity",NULL); -} diff --git a/Solver/dgConservationLawShallowWater1d.h b/Solver/dgConservationLawShallowWater1d.h deleted file mode 100644 index a2642a642e923ff7b82f81d5b4e958f152b5b7b3..0000000000000000000000000000000000000000 --- a/Solver/dgConservationLawShallowWater1d.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef _DG_CONSERVATION_LAW_SHALLOW_WATER_1D_ -#define _DG_CONSERVATION_LAW_SHALLOW_WATER_1D_ -#include "dgConservationLaw.h" - - -class binding; - -void dgConservationLawShallowWater1dRegisterBindings(binding *b); - -#endif diff --git a/Solver/dgConservationLawShallowWater2d.cpp b/Solver/dgConservationLawShallowWater2d.cpp deleted file mode 100644 index 46ac472ed4598410c267dcc457fb340e84049c38..0000000000000000000000000000000000000000 --- a/Solver/dgConservationLawShallowWater2d.cpp +++ /dev/null @@ -1,407 +0,0 @@ -#include "dgConservationLawShallowWater2d.h" -#include "function.h" -static double g = 9.81; - -class dgConservationLawShallowWater2d : public dgConservationLaw { - class advection; - class source; - class riemann; - class clipToPhysics; - class boundaryWall; - class maxConvectiveSpeed; - const function *_linearDissipation, *_quadraticDissipation, *_source, *_coriolisFactor, *_bathymetry; - mutable function *_advection, *_riemann; - public: - dataCacheDouble *newConvectiveFlux( dataCacheMap &cacheMap) const; - dataCacheDouble *newRiemannSolver( dataCacheMap &cacheMapLeft, dataCacheMap &cacheMapRight) const; - dataCacheDouble *newDiffusiveFlux( dataCacheMap &cacheMap) const; - dataCacheDouble *newSourceTerm (dataCacheMap &cacheMap) const; - dataCacheDouble *newMaxConvectiveSpeed (dataCacheMap &cacheMap) const; - dataCacheDouble *newClipToPhysics (dataCacheMap &cacheMap) const; - inline void setCoriolisFactor(const function *coriolisFactor){ _coriolisFactor = coriolisFactor;} - inline void setLinearDissipation(const function *linearDissipation){ _linearDissipation = linearDissipation;} - inline void setQuadraticDissipation(const function *quadraticDissipation){ _quadraticDissipation = quadraticDissipation;} - inline void setSource(const function *source){ _source = source;} - inline void setBathymetry(const function *bathymetry) { _bathymetry = bathymetry;} - dgConservationLawShallowWater2d(); - dgBoundaryCondition *newBoundaryWall(); -}; - -class dgConservationLawShallowWater2d::advection: public function { - public: - advection(const function *bathymetry, const function *solution):function(9) - { - addArgument(bathymetry); - addArgument(solution); - } - void call (dataCacheMap *m, const fullMatrix<double> &bathymetry, const fullMatrix<double> &sol, fullMatrix<double> &value) { - int nQP = value.size1(); - for(int i=0; i< nQP; i++) { - double h = bathymetry(i,0); - double eta = sol(i,0); - double u = sol(i,1); - double v = sol(i,2); - // flux_x - value(i,0) = (h+eta)*u; - value(i,1) = g*eta+u*u; - value(i,2) = u*v; - // flux_y - value(i,3) = (h+eta)*v; - value(i,4) = v*u; - value(i,5) = g*eta+v*v; - // flux_z - value(i,6) = 0; - value(i,7) = 0; - value(i,8) = 0; - } - } -}; - -class dgConservationLawShallowWater2d::clipToPhysics : public dataCacheDouble { - dataCacheDouble &sol, &_bathymetry; - double _hMin; -public: - clipToPhysics(dataCacheMap &cacheMap, const function *bathymetry, double hMin): - dataCacheDouble(cacheMap,1,3), - sol(cacheMap.get(function::getSolution(), this)), - _bathymetry(cacheMap.get(bathymetry,this)) - { - _hMin=hMin; - }; - void _eval () { - const int nQP = _value.size1(); - for (size_t k = 0 ; k < nQP; k++ ){ - double h = _bathymetry(k,0); - _value(k,0) = sol(k,0); - _value(k,1) = sol(k,1); - _value(k,2) = sol(k,2); - double H = sol(k,0)+h; - if (H < _hMin){ - _value(k,0) = _hMin; - } - } - } -}; - -class dgConservationLawShallowWater2d::maxConvectiveSpeed: public dataCacheDouble { - dataCacheDouble &sol, &_bathymetry; - public: - maxConvectiveSpeed(dataCacheMap &cacheMap, const function *bathymetry): - dataCacheDouble(cacheMap,1,1), - sol(cacheMap.get(function::getSolution(), this)), - _bathymetry(cacheMap.get(bathymetry,this)) - {}; - void _eval () { - int nQP = _value.size1(); - for(int i=0; i< nQP; i++) { - double h = _bathymetry(i,0); - double eta = sol(i,0); - double u = sol(i,1); - double v = sol(i,2); - _value(i,0) = sqrt((h+eta)*g)+hypot(u,v); - } - } -}; - - -/*class dgConservationLawShallowWater2d::advection: public dataCacheDouble { - dataCacheDouble &sol, &_bathymetry; - public: - advection(dataCacheMap &cacheMap, const function *bathymetry): - dataCacheDouble(cacheMap,1,9), - sol(cacheMap.get(function::getSolution(), this)), - _bathymetry(cacheMap.get(bathymetry,this)) - {}; - void _eval () { - int nQP = _value.size1(); - for(int i=0; i< nQP; i++) { - double h = _bathymetry(i,0); - double eta = sol(i,0); - double u = sol(i,1); - double v = sol(i,2); - // flux_x - _value(i,0) = (h+eta)*u; - _value(i,1) = g*eta+u*u; - _value(i,2) = u*v; - // flux_y - _value(i,3) = (h+eta)*v; - _value(i,4) = v*u; - _value(i,5) = g*eta+v*v; - // flux_z - _value(i,6) = 0; - _value(i,7) = 0; - _value(i,8) = 0; - } - } -};*/ - -class dgConservationLawShallowWater2d::source: public dataCacheDouble { - dataCacheDouble &solution,&solutionGradient; - dataCacheDouble &_coriolisFactor, &_source, &_linearDissipation, &_quadraticDissipation; - public : - source(dataCacheMap &cacheMap, const function *linearDissipation, const function *quadraticDissipation, const function *coriolisFactor, const function *source) : - dataCacheDouble(cacheMap,1,3), - _coriolisFactor(cacheMap.get(coriolisFactor,this)), - _source(cacheMap.get(source,this)), - _linearDissipation(cacheMap.get(linearDissipation,this)), - _quadraticDissipation(cacheMap.get(quadraticDissipation,this)), - solution(cacheMap.get(function::getSolution(), this)), - solutionGradient(cacheMap.get(function::getSolutionGradient(), this)) - { - } - void _eval () { - int nQP =_value.size1(); - for (int i=0; i<nQP; i++) { - double eta = solution(i,0); - double u = solution(i,1); - double v = solution(i,2); - double normu = hypot(u,v); - double dudx = solutionGradient(i,3); - double dvdx = solutionGradient(i,6); - double dudy = solutionGradient(i,4); - double dvdy = solutionGradient(i,7); - _value (i,0) = 0; - _value (i,1) = _coriolisFactor(i,0)*v - (_linearDissipation(i,0)+_quadraticDissipation(i,0)*normu)*u + _source(i,0) + u*(dudx+dvdy); - _value (i,2) = -_coriolisFactor(i,0)*u - (_linearDissipation(i,0)+_quadraticDissipation(i,0)*normu)*v + _source(i,1) + v*(dudx+dvdy); - } - } -}; - -#if 0 -class dgConservationLawShallowWater2d::riemann:public function { - public: - riemann (const function *bathymetry): function(6) - { - addArgument (function::getNormals(), 0); - addArgument (function::getSolution(), 0); - addArgument (function::getSolution(), 1); - addArgument (bathymetry, 0); - }; - void call (dataCacheMap *m, const fullMatrix<double> &normals, const fullMatrix<double> &solL, const fullMatrix<double> &solR, const fullMatrix<double> &_bathymetry, fullMatrix<double> &value) { - int nQP = solL.size1(); - for(int i=0; i< nQP; i++) { - double h = _bathymetry(i,0); - double nx = normals(0,i); - double ny = normals(1,i); - double HR = solR(i,0) + h, HL = solL(i,0) + h; - double uL = nx*solL(i,1) + ny*solL(i,2), uR = nx*solR(i,1) + ny*solR(i,2); - double vL = -ny*solL(i,1) + nx*solL(i,2), vR = - ny*solR(i,1) + nx*solR(i,2); - double HuL = uL*HL, HuR = uR*HR; - double HvL = vL*HL, HvR = vR*HR; - double HM = (HL+HR)/2, HJ = (HL-HR)/2; - double HuM = (HuL+HuR)/2, HuJ = (HuL-HuR)/2; - double HvM = (HvL+HvR)/2, HvJ = (HvL-HvR)/2; - double sqHL = sqrt(HL), sqHR = sqrt(HR); - double u_roe = (sqHL*uL + sqHR*uR) / (sqHL + sqHR); - double v_roe = (sqHL*vL + sqHR*vR) / (sqHL + sqHR); - double c_roe = sqrt(g*HM); - double H = HM + (HuJ - u_roe *HJ) / c_roe; - double Hu = HuM + (c_roe - u_roe*u_roe/c_roe) *HJ + u_roe/c_roe *HuJ; - double Hv = -v_roe*u_roe/c_roe*HJ + v_roe/c_roe*HuJ + (u_roe>0 ? -v_roe*HJ+HvL : v_roe*HJ+HvR); - double u = Hu / H; - double v = Hv / H; - double eta = H-h; - - /*double u = (uL+uR)/2; // - double v = (vL+vR)/2; - double eta = (HL+HR)/2-h; - double c = hypot(u,v)+sqrt(g*(h+eta)); - double Fun = -g*eta - u*u - (uL-uR)/2 * c; - double Fut = -u*( u>0 ? vL:vR); - double Feta = -(h+eta)*u - (HL-HR)/2 * c;*/ - - double Fun = -g*eta - u*u; - double Fut = -u*v; - double Feta = -(h+eta)*u; - - /* //linear equations - double unL = nx*solL(i,1) + ny*solL(i,2); - double unR = nx*solR(i,1) + ny*solR(i,2); - double etaR = solR(i,0); - double etaL = solL(i,0); - double sq_g_h = sqrt(g/h); - double etaRiemann = (etaL+etaR + (unL-unR)/sq_g_h)/2; - double unRiemann = (unL+unR + (etaL-etaR)*sq_g_h)/2; - double Fun = -g*etaRiemann; - double Fut = 0; - double Feta = -h*unRiemann; - */ - - value(i,0) = Feta; - value(i,1) = Fun*nx - Fut*ny; - value(i,2) = Fun*ny + Fut*nx; - value(i,3) = -value(i,0); - value(i,4) = -value(i,1); - value(i,5) = -value(i,2); - } - } -}; -#endif - -#if 1 -class dgConservationLawShallowWater2d::riemann:public dataCacheDouble { - dataCacheDouble &normals, &solL, &solR, &_bathymetry; - public: - riemann(dataCacheMap &cacheMapLeft, dataCacheMap &cacheMapRight, const function *bathymetry): - dataCacheDouble(cacheMapLeft,1,6), - normals(cacheMapLeft.get(function::getNormals(), this)), - solL(cacheMapLeft.get(function::getSolution(), this)), - solR(cacheMapRight.get(function::getSolution(), this)), - _bathymetry(cacheMapLeft.get(bathymetry, this)) - {}; - void _eval () { - int nQP = solL().size1(); - for(int i=0; i< nQP; i++) { - double h = _bathymetry(i,0); - double nx = normals(0,i); - double ny = normals(1,i); - double HR = solR(i,0) + h, HL = solL(i,0) + h; - double uL = nx*solL(i,1) + ny*solL(i,2), uR = nx*solR(i,1) + ny*solR(i,2); - double vL = -ny*solL(i,1) + nx*solL(i,2), vR = - ny*solR(i,1) + nx*solR(i,2); - double HuL = uL*HL, HuR = uR*HR; - double HvL = vL*HL, HvR = vR*HR; - double HM = (HL+HR)/2, HJ = (HL-HR)/2; - double HuM = (HuL+HuR)/2, HuJ = (HuL-HuR)/2; - double HvM = (HvL+HvR)/2, HvJ = (HvL-HvR)/2; - double sqHL = sqrt(HL), sqHR = sqrt(HR); - double u_roe = (sqHL*uL + sqHR*uR) / (sqHL + sqHR); - double v_roe = (sqHL*vL + sqHR*vR) / (sqHL + sqHR); - double c_roe = sqrt(g*HM); - double H = HM + (HuJ - u_roe *HJ) / c_roe; - double Hu = HuM + (c_roe - u_roe*u_roe/c_roe) *HJ + u_roe/c_roe *HuJ; - double Hv = -v_roe*u_roe/c_roe*HJ + v_roe/c_roe*HuJ + (u_roe>0 ? -v_roe*HJ+HvL : v_roe*HJ+HvR); - double u = Hu / H; - double v = Hv / H; - double eta = H-h; - - /*double u = (uL+uR)/2; // - double v = (vL+vR)/2; - double eta = (HL+HR)/2-h; - double c = hypot(u,v)+sqrt(g*(h+eta)); - double Fun = -g*eta - u*u - (uL-uR)/2 * c; - double Fut = -u*( u>0 ? vL:vR); - double Feta = -(h+eta)*u - (HL-HR)/2 * c;*/ - - double Fun = -g*eta - u*u; - double Fut = -u*v; - double Feta = -(h+eta)*u; - - /* //linear equations - double unL = nx*solL(i,1) + ny*solL(i,2); - double unR = nx*solR(i,1) + ny*solR(i,2); - double etaR = solR(i,0); - double etaL = solL(i,0); - double sq_g_h = sqrt(g/h); - double etaRiemann = (etaL+etaR + (unL-unR)/sq_g_h)/2; - double unRiemann = (unL+unR + (etaL-etaR)*sq_g_h)/2; - double Fun = -g*etaRiemann; - double Fut = 0; - double Feta = -h*unRiemann; - */ - - _value(i,0) = Feta; - _value(i,1) = Fun*nx - Fut*ny; - _value(i,2) = Fun*ny + Fut*nx; - _value(i,3) = -_value(i,0); - _value(i,4) = -_value(i,1); - _value(i,5) = -_value(i,2); - } - } -}; -#endif - -class dgConservationLawShallowWater2d::boundaryWall : public dgBoundaryCondition { - class term : public dataCacheDouble { - dataCacheDouble &sol,&normals; - public: - term(dataCacheMap &cacheMap): - dataCacheDouble(cacheMap,1,3), - sol(cacheMap.get(function::getSolution(), this)), - normals(cacheMap.get(function::getNormals(), this)){} - void _eval () { - int nQP = sol().size1(); - for(int i=0; i< nQP; i++) { - double nx = normals(0,i); - double ny = normals(1,i); - double eta = sol(i,0); - - _value(i,0) = 0; - _value(i,1) = -g*eta*nx; - _value(i,2) = -g*eta*ny; - } - } - }; - public: - boundaryWall(dgConservationLaw *claw) : dgBoundaryCondition(claw){} - dataCacheDouble *newBoundaryTerm(dataCacheMap &cacheMapLeft) const { - return new term(cacheMapLeft); - } -}; - -dataCacheDouble *dgConservationLawShallowWater2d::newConvectiveFlux( dataCacheMap &cacheMap) const { - if(_advection==NULL) - _advection = new advection(_bathymetry, function::getSolution()); - return &cacheMap.get(_advection, NULL); -} - -dataCacheDouble *dgConservationLawShallowWater2d::newRiemannSolver( dataCacheMap &cacheMapLeft, dataCacheMap &cacheMapRight) const { - //if(_riemann==NULL) - //_riemann = new riemann(_bathymetry); - //return &cacheMapLeft.get(_riemann, NULL); - return new riemann(cacheMapLeft, cacheMapRight, _bathymetry); -} -dataCacheDouble *dgConservationLawShallowWater2d::newDiffusiveFlux( dataCacheMap &cacheMap) const { - return 0; -} -dataCacheDouble *dgConservationLawShallowWater2d::newMaxConvectiveSpeed( dataCacheMap &cacheMap) const { - return new maxConvectiveSpeed(cacheMap, _bathymetry); -} -dataCacheDouble *dgConservationLawShallowWater2d::newSourceTerm (dataCacheMap &cacheMap) const { - return new source(cacheMap, _linearDissipation, _quadraticDissipation, _coriolisFactor, _source); -} - -dgBoundaryCondition *dgConservationLawShallowWater2d::newBoundaryWall(){ - return new boundaryWall(this); -} - -dataCacheDouble *dgConservationLawShallowWater2d::newClipToPhysics( dataCacheMap &cacheMap) const { - return new clipToPhysics(cacheMap, _bathymetry, 1e-5); -} -dgConservationLawShallowWater2d::dgConservationLawShallowWater2d() -{ - _nbf = 3; // eta u v - function *fzero = functionConstantNew(0.); - _bathymetry = fzero; - _linearDissipation = fzero; - _coriolisFactor = fzero; - _quadraticDissipation = fzero; - _source = fzero; - _advection = NULL; -} - -#include "Bindings.h" -void dgConservationLawShallowWater2dRegisterBindings (binding *b){ - classBinding *cb = b->addClass<dgConservationLawShallowWater2d>("dgConservationLawShallowWater2d"); - cb->setDescription("The non-conservative shallow water conservation law. (eta, u, v)"); - methodBinding *cm; - cm = cb->addMethod("newBoundaryWall",&dgConservationLawShallowWater2d::newBoundaryWall); - cm->setDescription("slip wall boundary"); - cm = cb->setConstructor<dgConservationLawShallowWater2d>(); - cm->setDescription("A new shallow water conservation law."); - cb->setParentClass<dgConservationLaw>(); - cm = cb->addMethod("setCoriolisFactor", &dgConservationLawShallowWater2d::setCoriolisFactor); - cm->setDescription("set the function to evaluate the coriolis factor du/dt = -f v ; dv/dt = f u"); - cm->setArgNames("f",NULL); - cm = cb->addMethod("setLinearDissipation", &dgConservationLawShallowWater2d::setLinearDissipation); - cm->setDescription("set the function to evaluate the linear dissipation du/dt = -gamma u; dv/dt = -gamma v"); - cm->setArgNames("gamma",NULL); - cm = cb->addMethod("setQuadraticDissipation", &dgConservationLawShallowWater2d::setQuadraticDissipation); - cm->setDescription("set the function to evaluate the quadratic dissipation du/dt = -c_d u||u||; dv/dt = -c_d v"); - cm->setArgNames("gamma",NULL); - cm = cb->addMethod("setSource", &dgConservationLawShallowWater2d::setSource); - cm->setDescription("set the function to evaluate the source term du/dt = s(0); dv/dt = s(1)"); - cm->setArgNames("s",NULL); - cm = cb->addMethod("setBathymetry", &dgConservationLawShallowWater2d::setBathymetry); - cm->setDescription("set the function to evaluate the bathymetry h (H = h+eta)"); - cm->setArgNames("h",NULL); -} diff --git a/Solver/dgConservationLawShallowWater2d.h b/Solver/dgConservationLawShallowWater2d.h deleted file mode 100644 index f6ac2b31d5ee253aeb6fc860241c245c704daa8a..0000000000000000000000000000000000000000 --- a/Solver/dgConservationLawShallowWater2d.h +++ /dev/null @@ -1,8 +0,0 @@ -#ifndef _DG_CONSERVATION_LAW_SHALLOW_WATER_2D_ -#define _DG_CONSERVATION_LAW_SHALLOW_WATER_2D_ -#include "dgConservationLaw.h" - -class binding; - -void dgConservationLawShallowWater2dRegisterBindings(binding *b); -#endif diff --git a/Solver/dgConservationLawWaveEquation.cpp b/Solver/dgConservationLawWaveEquation.cpp deleted file mode 100644 index 419d0ef3135053c13ea878720d6aaf7130609389..0000000000000000000000000000000000000000 --- a/Solver/dgConservationLawWaveEquation.cpp +++ /dev/null @@ -1,144 +0,0 @@ - -#include "dgConservationLaw.h" -#include "dgConservationLawWaveEquation.h" -#include "function.h" - -static double c=1; -static double rho=1; - -class dgConservationLawWaveEquation::hyperbolicFlux : public dataCacheDouble { - dataCacheDouble / - const int _DIM,_nbf; - public: - hyperbolicFlux(dataCacheMap &cacheMap,int DIM): - dataCacheDouble(cacheMap,1,3*(DIM+1)), - sol(cacheMap.get(function::getSolution(), this)),_DIM(DIM),_nbf(DIM+1) - {}; - void _eval () { - int nQP = sol().size1(); - _value.scale(0.); - for(int i=0; i< nQP; i++) { - const double p = sol(i,0); - for (int j=0;j<_DIM;j++){ - _value(i,0 +j*_nbf) = c*c*rho*sol(i,j+1); - _value(i,j+1+j*_nbf) = p/rho; - } - } - } -}; - -class dgConservationLawWaveEquation::maxConvectiveSpeed : public dataCacheDouble { - dataCacheDouble / - public: - maxConvectiveSpeed(dataCacheMap &cacheMap): - dataCacheDouble(cacheMap,1,1), - sol(cacheMap.get(function::getSolution(), this)) - { - }; - void _eval () { - _value.setAll(c); - } -}; - -class dgConservationLawWaveEquation::riemann : public dataCacheDouble { - dataCacheDouble &normals, &solL, &solR; - const int _DIM,_nbf; - public: - riemann(dataCacheMap &cacheMapLeft, dataCacheMap &cacheMapRight, int DIM): - dataCacheDouble(cacheMapLeft,1,2*(DIM+1)), - normals(cacheMapLeft.get(function::getNormals(), this)), - solL(cacheMapLeft.get(function::getSolution(), this)), - solR(cacheMapRight.get(function::getSolution(), this)), - _DIM(DIM),_nbf(DIM+1) - {}; - void _eval () { - int nQP = solL().size1(); - for(int i=0; i< nQP; i++) { - const double n[3] = {normals(0,i),normals(1,i),normals(2,i)}; - double unL=0,unR=0; - for (int j=0;j<_DIM;j++){ - unL += n[j]*solL(i,j+1); - unR += n[j]*solR(i,j+1); - } - double pR = solR(i,0); - double pL = solL(i,0); - - double pRiemann = 0.5 * (pL+pR + (unL-unR)*(rho*c)); - double unRiemann = 0.5 * (unL+unR + (pL-pR)/(rho*c)); - - double Fp = -rho*c*c*unRiemann; - double Fun = -pRiemann/rho; - - _value(i,0) = Fp; - for (int j=0;j<_DIM;j++) - _value(i,j+1) = Fun*n[j]; - for (int j=0;j<_nbf;j++) - _value(i,j+_nbf) = -_value(i,j); - } - } -}; -dataCacheDouble *dgConservationLawWaveEquation::newConvectiveFlux( dataCacheMap &cacheMap) const { - return new hyperbolicFlux(cacheMap,_DIM); -} -dataCacheDouble *dgConservationLawWaveEquation::newMaxConvectiveSpeed( dataCacheMap &cacheMap) const { - return new maxConvectiveSpeed(cacheMap); -} -dataCacheDouble *dgConservationLawWaveEquation::newRiemannSolver( dataCacheMap &cacheMapLeft, dataCacheMap &cacheMapRight) const { - return new riemann(cacheMapLeft, cacheMapRight,_DIM); -} -dataCacheDouble *dgConservationLawWaveEquation::newDiffusiveFlux( dataCacheMap &cacheMap) const { - return 0; -} -dataCacheDouble *dgConservationLawWaveEquation::newSourceTerm (dataCacheMap &cacheMap) const { - return 0; -} -dgConservationLawWaveEquation::dgConservationLawWaveEquation(int DIM) : _DIM(DIM) -{ - _nbf = 1 + _DIM; // H U(=Hu) V(=Hv) -} - -class dgBoundaryConditionWaveEquationWall : public dgBoundaryCondition { - int _DIM; - class term : public dataCacheDouble { - int _DIM; - dataCacheDouble &sol,&normals; - public: - term(dataCacheMap &cacheMap, int DIM): - dataCacheDouble(cacheMap,1,DIM+1), - sol(cacheMap.get(function::getSolution(), this)), - normals(cacheMap.get(function::getNormals(), this)), - _DIM(DIM){} - void _eval () { - int nQP = sol().size1(); - for(int i=0; i< nQP; i++) { - const double n[3] = {normals(0,i),normals(1,i),normals(2,i)}; - double p = sol(i,0); - _value(i,0) = 0; - for (int j=0;j<_DIM;j++) - _value(i,j+1) = -p/rho*n[j]; - } - } - }; - public: - dgBoundaryConditionWaveEquationWall(int DIM, dgConservationLaw *claw):_DIM(DIM),dgBoundaryCondition(claw){} - dataCacheDouble *newBoundaryTerm(dataCacheMap &cacheMapLeft) const { - return new term(cacheMapLeft,_DIM); - } -}; -dgBoundaryCondition *dgConservationLawWaveEquation::newBoundaryWall(){ - return new dgBoundaryConditionWaveEquationWall(_DIM, this); -} - -#include "Bindings.h" -void dgConservationLawWaveEquationRegisterBindings(binding *b){ - classBinding *cb = b->addClass<dgConservationLawWaveEquation> ("dgConservationLawWaveEquation"); - cb->setDescription("Solve the wave equation in dimension 1, 2 or 3.)"); - methodBinding *cm; - cm = cb->addMethod("newBoundaryWall",&dgConservationLawWaveEquation::newBoundaryWall); - cm->setDescription("wall boundary"); - cm = cb->setConstructor<dgConservationLawWaveEquation,int>(); - cm->setArgNames("d",NULL); - cm->setDescription("New wave equation of dimension 'd'"); - - cb->setParentClass<dgConservationLaw>(); -} diff --git a/Solver/dgConservationLawWaveEquation.h b/Solver/dgConservationLawWaveEquation.h deleted file mode 100644 index 8086b61ae7f73fc21899ea1d66c5cbfedd0cb61e..0000000000000000000000000000000000000000 --- a/Solver/dgConservationLawWaveEquation.h +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef _DG_CONSERVATION_LAW_WAVE_EQUATION_H_ -#define _DG_CONSERVATION_LAW_WAVE_EQUATION_H_ -#include "dgConservationLaw.h" -// Linear acoustics -// dp/dt - rho*c^2 div(u,v) = 0 -// du/dt + 1/rho dp/dx = 0 -// dv/dt + 1/rho dp/dy = 0 -class methodBinding; -class constructorBinding; -class dgConservationLawWaveEquation : public dgConservationLaw { - int _DIM; - class hyperbolicFlux; - class maxConvectiveSpeed; - class riemann; - public: - dataCacheDouble *newConvectiveFlux( dataCacheMap &cacheMap) const ; - dataCacheDouble *newRiemannSolver( dataCacheMap &cacheMapLeft, dataCacheMap &cacheMapRight) const; - dataCacheDouble *newDiffusiveFlux( dataCacheMap &cacheMap) const ; - dataCacheDouble *newSourceTerm (dataCacheMap &cacheMap) const ; - dataCacheDouble *newMaxConvectiveSpeed (dataCacheMap &cacheMap) const; - dgBoundaryCondition *newBoundaryWall () ; - dgConservationLawWaveEquation(int DIM); - static const char *className; - static const char *parentClassName; - static methodBinding *methods[]; - static constructorBinding *constructorMethod; -}; -void dgConservationLawWaveEquationRegisterBindings(binding *b); -#endif diff --git a/Solver/dgDofContainer.cpp b/Solver/dgDofContainer.cpp deleted file mode 100644 index cef75b4a78450d9c88e6260a66c15a4118b6b6ff..0000000000000000000000000000000000000000 --- a/Solver/dgDofContainer.cpp +++ /dev/null @@ -1,648 +0,0 @@ -#include "GmshConfig.h" -#include "dgDofContainer.h" -#include "function.h" -#include "dgGroupOfElements.h" -#include "dgConservationLaw.h" -#include "dgAlgorithm.h" -#include "GModel.h" -#ifdef HAVE_MPI -#include "mpi.h" -#else -#include "string.h" -#endif -#include <sstream> -#include "MElement.h" -dgDofContainer::dgDofContainer (dgGroupCollection *groups, int nbFields): - _groups(*groups), _mshStep(0) -{ - int _dataSize = 0; - _dataSizeGhost=0; - _totalNbElements = 0; - _parallelStructureExists = false; - _nbFields = nbFields; - for (int i=0; i< _groups.getNbElementGroups();i++){ - int nbNodes = _groups.getElementGroup(i)->getNbNodes(); - int nbElements = _groups.getElementGroup(i)->getNbElements(); - _totalNbElements +=nbElements; - _dataSize += nbNodes*_nbFields*nbElements; - } - - // allocate the big vectors - _data = new fullVector<double>(_dataSize); - // create proxys for each group - int offset = 0; - _dataProxys.resize(_groups.getNbElementGroups()+_groups.getNbGhostGroups()); - _groupFirstDofId.resize(_groups.getNbElementGroups()+_groups.getNbGhostGroups()); - for (int i=0;i<_groups.getNbElementGroups();i++){ - dgGroupOfElements *group = _groups.getElementGroup(i); - _groupId[group] = i; - int nbNodes = group->getNbNodes(); - int nbElements = group->getNbElements(); - _dataProxys[i] = new fullMatrix<double> (&(*_data)(offset),nbNodes, _nbFields*nbElements); - _groupFirstDofId[i] = offset; - offset += nbNodes*_nbFields*nbElements; - } - - //ghosts - - int totalNbElementsGhost =0; - for (int i=0; i<_groups.getNbGhostGroups(); i++){ - int nbNodes = _groups.getGhostGroup(i)->getNbNodes(); - int nbElements = _groups.getGhostGroup(i)->getNbElements(); - totalNbElementsGhost +=nbElements; - _dataSizeGhost += nbNodes*_nbFields*nbElements; - } - - _ghostData = new fullVector<double>(_dataSizeGhost); - int ghostOffset=0; - for (int i=0;i<_groups.getNbGhostGroups();i++){ - dgGroupOfElements *group = _groups.getGhostGroup(i); - int nbNodes = group->getNbNodes(); - int nbElements = group->getNbElements(); - int gid = i+_groups.getNbElementGroups(); - _groupId[group] = gid; - _dataProxys[gid] = new fullMatrix<double> (&(*_ghostData)(ghostOffset),nbNodes, _nbFields*nbElements); - _groupFirstDofId[gid] = offset; - offset += nbNodes*_nbFields*nbElements; - ghostOffset += nbNodes*_nbFields*nbElements; - } - -} - -dgDofContainer::~dgDofContainer (){ - if(_parallelStructureExists) { - delete []countSend; - delete []countRecv; - delete []shiftSend; - delete []shiftRecv; - delete []groupShiftRecv; - delete []sendBuf; - delete []recvBuf; - } - for (int i=0;i<_dataProxys.size();++i) delete _dataProxys[i]; - delete _data; - delete _ghostData; -} - -void dgDofContainer::buildParallelStructure(){ - if (_parallelStructureExists) - return; - - // MPI all2all buffers - countSend = new int[Msg::GetCommSize()]; - shiftSend = new int[Msg::GetCommSize()]; - countRecv = new int[Msg::GetCommSize()]; - shiftRecv = new int[Msg::GetCommSize()]; - groupShiftRecv = new int[_groups.getNbGhostGroups()]; - for(int i=0;i<Msg::GetCommSize();i++){ - countSend[i]=0; - countRecv[i]=0; - for(size_t j=0;j<_groups.getNbImageElementsOnPartition(i);j++){ - countSend[i] += _groups.getElementGroup(_groups.getImageElementGroup(i,j))->getNbNodes()*_nbFields; - } - } - for(size_t i=0; i<_groups.getNbGhostGroups(); i++){ - dgGroupOfElements *group = _groups.getGhostGroup(i); - groupShiftRecv[i] = countRecv[group->getGhostPartition()]; - countRecv[group->getGhostPartition()]+=group->getNbElements()*group->getNbNodes()*_nbFields; - } - shiftSend[0] = shiftRecv[0]=0; - int totalSend = countSend[0]; - int totalRecv = countRecv[0]; - for(size_t i=1; i<Msg::GetCommSize(); i++){ - shiftSend[i] = shiftSend[i-1]+countSend[i-1]; - shiftRecv[i] = shiftRecv[i-1]+countRecv[i-1]; - totalSend += countSend[i]; - totalRecv += countRecv[i]; - } - for(size_t i=0; i<_groups.getNbGhostGroups(); i++){ - dgGroupOfElements *group = _groups.getGhostGroup(i); - groupShiftRecv[i] += shiftRecv[group->getGhostPartition()]; - } - sendBuf = new double[totalSend]; - recvBuf = new double[totalRecv]; - - _parallelStructureExists = true; -} - -void dgDofContainer::scatter() { - if(!_parallelStructureExists) - buildParallelStructure(); - //1) fill - int index=0; - for(int i=0;i<Msg::GetCommSize();i++){ - for(size_t j=0;j<_groups.getNbImageElementsOnPartition(i);j++){ - fullMatrix<double> &sol = getGroupProxy(_groups.getImageElementGroup(i,j)); - int eid = _groups.getImageElementPositionInGroup(i,j); - for(int l=0;l<_nbFields;l++) { - for(int k=0;k<sol.size1();k++) { - sendBuf[index++] = sol(k, eid *_nbFields+l); - } - } - } - } - //2) send - #ifdef HAVE_MPI - MPI_Alltoallv(sendBuf,countSend,shiftSend,MPI_DOUBLE,recvBuf,countRecv,shiftRecv,MPI_DOUBLE,MPI_COMM_WORLD); - #else - memcpy(recvBuf,sendBuf,countSend[0]*sizeof(double)); - #endif - //3) distribute - for(int i=0; i< _groups.getNbGhostGroups();i++) { - fullMatrix<double> &sol = getGroupProxy(i+_groups.getNbElementGroups()); - fullMatrix<double> recvProxy (recvBuf + groupShiftRecv[i], sol.size1(), sol.size2()); - sol.setAll(recvProxy); - } -} -void dgDofContainer::setAll(double v) { - for(int i=0;i<_data->size();i++) - (*_data)(i)=v; - for(int i=0;i<_ghostData->size();i++) - (*_ghostData)(i)=v; -} -void dgDofContainer::scale(double f) -{ - _data->scale(f); - _ghostData->scale(f); -} -void dgDofContainer::scale(std::vector<dgGroupOfElements*>groupsVector, double f){ - for(int i=0;i<groupsVector.size();i++){ - dgGroupOfElements *g=groupsVector[i]; - fullMatrix<double> &proxy=getGroupProxy(g); - proxy.scale(f); - } -} - -void dgDofContainer::axpy(dgDofContainer &x, double a) -{ - _data->axpy(*x._data,a); - _ghostData->axpy(*x._ghostData,a); -} -void dgDofContainer::axpy(std::vector<dgGroupOfElements*>groupsVector,dgDofContainer &x, double a){ - for(int i=0;i<groupsVector.size();i++){ - dgGroupOfElements *g=groupsVector[i]; - fullMatrix<double> &proxy=getGroupProxy(g); - fullMatrix<double> &xProxy=x.getGroupProxy(g); - proxy.add(xProxy,a); - } -} - -double dgDofContainer::norm() { - double localNorm = _data->norm(); - #ifdef HAVE_MPI - double globalNorm; - MPI_Allreduce(&localNorm, &globalNorm, 1, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD); - return globalNorm; - #else - return localNorm; - #endif -} -double dgDofContainer::norm(std::vector<dgGroupOfElements *>gV){ - double norm=0; - for(int i=0;i<gV.size();i++){ - dgGroupOfElements* g=gV[i]; - fullMatrix<double>&groupData=getGroupProxy(g); - for(int r=0;r<groupData.size1();r++){ - for(int c=0;c<groupData.size1();c++){ - norm+=groupData(r,c)*groupData(r,c); - } - } - } - return norm; -} -void dgDofContainer::save(const std::string name) { - FILE *f = fopen (name.c_str(),"wb"); - _data->binarySave(f); - fclose(f); -} -void dgDofContainer::load(const std::string name) { - FILE *f = fopen (name.c_str(),"rb"); - _data->binaryLoad(f); - fclose(f); -} - -void dgDofContainer::L2Projection(const function *f){ - scale(0.); - dgDofContainer rhs(&_groups, _nbFields); - for (int iGroup=0;iGroup<_groups.getNbElementGroups();iGroup++) { - const dgGroupOfElements &group = *_groups.getElementGroup(iGroup); - fullMatrix<double> Source = fullMatrix<double> (group.getNbIntegrationPoints(),group.getNbElements() * _nbFields); - dataCacheMap cacheMap; - cacheMap.setNbEvaluationPoints(group.getNbIntegrationPoints()); - cacheMap.get(function::getParametricCoordinates(), NULL).set()=group.getIntegrationPointsMatrix(); - dataCacheDouble &sourceTerm = cacheMap.get(f); - fullMatrix<double> source; - for (int iElement=0 ; iElement<group.getNbElements() ;++iElement) { - cacheMap.setElement(group.getElement(iElement)); - source.setAsProxy(Source, iElement*_nbFields, _nbFields); - for (int iPt =0; iPt< group.getNbIntegrationPoints(); iPt++) { - const double detJ = group.getDetJ (iElement, iPt); - for (int k=0;k<_nbFields;k++) - source(iPt,k) = sourceTerm(iPt,k)*detJ; - } - } - rhs.getGroupProxy(iGroup).gemm(group.getSourceRedistributionMatrix(), Source); - dgAlgorithm::multAddInverseMassMatrix(group, rhs.getGroupProxy(iGroup), getGroupProxy(iGroup)); - } -} - -void dgDofContainer::Mesh2Mesh_BuildL2Projection(linearSystemCSRGmm<double> &projector,dgDofContainer &donor){ -// for basis function i -// for integration pts -// search for element in 2d mesh -// for basis function j -// evauate quad -// add to matrix correct indices - - dgGroupCollection* dGroups = donor.getGroups(); - dgGroupCollection* rGroups = this->getGroups(); - if (rGroups->getElementGroup(0)->getDimUVW() > dGroups->getElementGroup(0)->getDimUVW()) - Msg::Fatal("Cannot build projection matrix from lower dim to higher dim. Use the transpose."); - std::vector<int> rGroupsStartIGlobal(rGroups->getNbElementGroups() + 1); - int jGlobal = 0; // indices in global container - rGroupsStartIGlobal[0] = 0; - for (int i = 1; i<rGroupsStartIGlobal.size(); i++) - rGroupsStartIGlobal[i] = rGroupsStartIGlobal[i-1] + rGroups->getElementGroup(i-1)->getNbElements()*rGroups->getElementGroup(i-1)->getNbNodes(); - - projector.allocate(rGroupsStartIGlobal[rGroupsStartIGlobal.size()-1]); - // integration over donor function space - for (int jGroup=0;jGroup<dGroups->getNbElementGroups();jGroup++) {// for donor groups - const dgGroupOfElements &dGroup = *dGroups->getElementGroup(jGroup); - fullMatrix<double> iPtsMatrix = dGroup.getIntegrationPointsMatrix(); - for (int jElement=0 ; jElement<dGroup.getNbElements() ;++jElement) {// for elements - double rShapeFun[256]; - double dShapeFun[256]; - GModel *rModel = rGroups->getModel(); - GModel *dModel = dGroups->getModel(); - MElement* dElem = dGroup.getElement(jElement); - for (int iPt =0; iPt< iPtsMatrix.size1(); iPt++) { - double x=0,y=0,z=0; - dElem->getFunctionSpace()->f(iPtsMatrix(iPt,0),iPtsMatrix(iPt,1),iPtsMatrix(iPt,2),dShapeFun); - for (int iVer=0; iVer < dElem->getNumVertices(); iVer++) { - x += dElem->getVertex(iVer)->x()*dShapeFun[iVer]; - y += dElem->getVertex(iVer)->y()*dShapeFun[iVer]; - z += dElem->getVertex(iVer)->z()*dShapeFun[iVer]; - } - if (rGroups->getElementGroup(0)->getDimUVW() == 2) { - z = 0; // dummy projection to 2d mesh - } - SPoint3 p(x,y,z); // find p in receiver mesh - MElement *rElem = rGroups->getModel()->getMeshElementByCoord(p); - int iGroup,iElement; - rGroups->find(rElem,iGroup,iElement); - if (iElement == -1) - Msg::Fatal("Integration point not found in receiver mesh."); - const dgGroupOfElements &rGroup = *rGroups->getElementGroup(iGroup); - double U[3],X[3]={x,y,z}; - rElem->xyz2uvw(X,U); - dGroup.getFunctionSpace().f(iPtsMatrix(iPt,0),iPtsMatrix(iPt,1),iPtsMatrix(iPt,2),dShapeFun); - rGroup.getFunctionSpace().f(U[0],U[1],U[2],rShapeFun); - const double detJ = dGroup.getDetJ (jElement, iPt); -// int iGlobal = rGroupsStartIGlobal[iGroup]+rGroup.getNbNodes()*iElement; - int iGlobal = this->getDofId(iGroup,iElement,0,0); // works only for one field ! - for (int jNode=0;jNode<dGroup.getNbNodes();jNode++){ - for (int iNode=0;iNode<rGroup.getNbNodes();iNode++){ - double val = rShapeFun[iNode]*dShapeFun[jNode]*iPtsMatrix(iPt,3)*detJ; - projector.addToMatrix(iGlobal+iNode,jGlobal+jNode,val); - } - } - } - jGlobal += dGroup.getNbNodes(); - } - } - multAddInverseMassMatrixL2Projection(projector); -} - -void dgDofContainer::multAddInverseMassMatrixL2Projection(linearSystemCSRGmm<double> &projector){ - dgGroupCollection* rGroups = this->getGroups(); - int *startIndex; - int *columns; - double *values; - projector.getMatrix(startIndex,columns,values); - - int iGlobal = 0; - for (int iGroup=0;iGroup<rGroups->getNbElementGroups();iGroup++) {// for 2d.groups - const dgGroupOfElements &rGroup = *rGroups->getElementGroup(iGroup); - for (int iElement=0 ; iElement<rGroup.getNbElements() ;++iElement) {// for elements - fullMatrix<double> buffer = fullMatrix<double> (rGroup.getNbNodes(),startIndex[iGlobal+1]-startIndex[iGlobal]); - fullMatrix<double> buffer2 = fullMatrix<double> (rGroup.getNbNodes(),startIndex[iGlobal+1]-startIndex[iGlobal]); - fullMatrix<double> iMassEl; - for (int iNode = 0 ; iNode<rGroup.getNbNodes() ;++iNode) { - for (int i = startIndex[iGlobal+iNode]; i < startIndex[iGlobal+iNode+1] ; i++) - buffer(iNode,i-startIndex[iGlobal+iNode]) = values[i]; - } - iMassEl.setAsProxy(rGroup.getInverseMassMatrix(),iElement*rGroup.getNbNodes(),rGroup.getNbNodes()); - buffer2.gemm(iMassEl,buffer); - for (int iNode = 0 ; iNode<rGroup.getNbNodes() ;++iNode) { - for (int i = startIndex[iGlobal+iNode]; i < startIndex[iGlobal+iNode+1] ; i++) - values[i] = buffer2(iNode,i-startIndex[iGlobal+iNode]); - } - iGlobal+=rGroup.getNbNodes(); - } - } -} - -void dgDofContainer::Mesh2Mesh_ApplyL2Projection(linearSystemCSRGmm<double> &projector,dgDofContainer &donor, int transpose, int copy){ - dgDofContainer* dDof = &donor; - dgDofContainer* rDof = this; - if (transpose) { - rDof = &donor; - dDof = this; - } - setAll(0); - - dgGroupCollection* dGroups = dDof->getGroups(); - dgGroupCollection* rGroups = rDof->getGroups(); - std::vector<int> dGroupsStartIGlobal(dGroups->getNbElementGroups() + 1); - int iGlobal = 0; // indices in global container - dGroupsStartIGlobal[0] = 0; - for (int i = 1; i<dGroupsStartIGlobal.size(); i++) - dGroupsStartIGlobal[i] = dGroupsStartIGlobal[i-1] + dGroups->getElementGroup(i-1)->getNbElements()*dGroups->getElementGroup(i-1)->getNbNodes(); - - int *startIndex; - int *columns; - double *values; - projector.getMatrix(startIndex,columns,values); - - int nbFields = 1; // TO DEFINE !!! - - for (int iGroup=0;iGroup<rGroups->getNbElementGroups();iGroup++) {// for 2d.groups - const dgGroupOfElements &rGroup = *rGroups->getElementGroup(iGroup); -// fullMatrix<double> buffer = fullMatrix<double> (rGroup.getNbNodes(),rGroup.getNbElements() * _nbFields); - for (int iElement=0 ; iElement<rGroup.getNbElements() ;++iElement) {// for elements - for (int iNode = 0 ; iNode<rGroup.getNbNodes() ;++iNode) { - int jGroup = 0; - for (int i = startIndex[iGlobal++]; i < startIndex[iGlobal] ; i++){ - int jGlobal = columns[i]; - while (jGlobal > dGroupsStartIGlobal[jGroup+1]) { - jGroup++; - } - int jElement = (jGlobal-dGroupsStartIGlobal[jGroup])/dGroups->getElementGroup(jGroup)->getNbNodes(); - int jNode = jGlobal-dGroupsStartIGlobal[jGroup]-jElement*dGroups->getElementGroup(jGroup)->getNbNodes(); - for (int m = 0; m < nbFields; m++){ - double val = values[i]; - if (copy) val = (fabs(values[i]) > 1e-8) ? 1 : 0; - if (transpose) - this->getGroupProxy(jGroup)(jNode,jElement*nbFields+m) += val*donor.getGroupProxy(iGroup)(iNode,iElement*nbFields+m); - else - this->getGroupProxy(iGroup)(iNode,iElement*nbFields+m) += val*donor.getGroupProxy(jGroup)(jNode,jElement*nbFields+m); -// printf("%d %d %d %f %f %f\n",iGlobal,jGlobal,i, buffer(iNode,iElement*nbFields+m),values[i],(donor.getGroupProxy(jGroup))(jNode,jElement*nbFields+m)); - } - } - } - }//*/ -// buffer.print(); -// dgAlgorithm::multAddInverseMassMatrix(rGroup, buffer, this->getGroupProxy(iGroup)); -// this->getGroupProxy(iGroup).print(); - } -} - -void dgDofContainer::exportGroupIdMsh(){ - // the elementnodedata::export does not work !! - - std::ostringstream name_oss; - name_oss<<"groupsId.msh"; - if(Msg::GetCommSize()>1) - name_oss<<"_"<<Msg::GetCommRank(); - FILE *f = fopen (name_oss.str().c_str(),"w"); - int COUNT = 0; - for (int i=0;i < _groups.getNbElementGroups() ;i++){ - COUNT += _groups.getElementGroup(i)->getNbElements(); - } - fprintf(f,"$MeshFormat\n2.1 0 8\n$EndMeshFormat\n"); - fprintf(f,"$ElementNodeData\n"); - fprintf(f,"1\n"); - fprintf(f,"\"%s\"\n","GroupsIds"); - fprintf(f,"1\n"); - fprintf(f,"0.0\n"); - fprintf(f,"%d\n", Msg::GetCommSize() > 1 ? 4 : 3); - fprintf(f,"0\n 1\n %d\n",COUNT); - if(Msg::GetCommSize() > 1) fprintf(f,"%d\n", Msg::GetCommRank()); - for (int i=0;i < _groups.getNbElementGroups() ;i++){ - dgGroupOfElements *group = _groups.getElementGroup(i); - for (int iElement=0 ; iElement< group->getNbElements() ;++iElement) { - MElement *e = group->getElement(iElement); - int num = e->getNum(); - fullMatrix<double> sol(getGroupProxy(i), iElement*_nbFields,_nbFields); - fprintf(f,"%d %d",num,sol.size1()); - for (int k=0;k<sol.size1();++k) { - fprintf(f," %.16E ",i*1.0); - } - fprintf(f,"\n"); - } - } - fprintf(f,"$EndElementNodeData\n"); - fclose(f); - return; - // we should discuss that : we do a copy of the solution, this should - // be avoided ! - - /*std::map<int, std::vector<double> > data; - - for (int i=0;i < _groups.getNbElementGroups() ;i++){ - dgGroupOfElements *group = _groups.getElementGroup(i); - for (int iElement=0 ; iElement< group->getNbElements() ;++iElement) { - MElement *e = group->getElement(iElement); - int num = e->getNum(); - fullMatrix<double> sol(getGroupProxy(i), iElement*_nbFields,_nbFields); - std::vector<double> val; - // val.resize(sol.size2()*sol.size1()); - val.resize(sol.size1()); - int counter = 0; - // for (int iC=0;iC<sol.size2();iC++) - printf("%g %g %g\n",sol(0,0),sol(1,0),sol(2,0)); - for (int iR=0;iR<sol.size1();iR++)val[counter++] = sol(iR,0); - data[num] = val; - } - } - - PView *pv = new PView (name, "ElementNodeData", _gm, data, 0.0, 1); - pv->getData()->writeMSH(name+".msh", false); - delete pv; - */ -} - -void dgDofContainer::exportMultirateGroupMsh(){ - // the elementnodedata::export does not work !! - - std::ostringstream name_oss; - name_oss<<"groupsMultirateType.msh"; - if(Msg::GetCommSize()>1) - name_oss<<"_"<<Msg::GetCommRank(); - FILE *f = fopen (name_oss.str().c_str(),"w"); - int COUNT = 0; - for (int i=0;i < _groups.getNbElementGroups() ;i++){ - COUNT += _groups.getElementGroup(i)->getNbElements(); - } - fprintf(f,"$MeshFormat\n2.1 0 8\n$EndMeshFormat\n"); - fprintf(f,"$ElementNodeData\n"); - fprintf(f,"1\n"); - fprintf(f,"\"%s\"\n","GroupsIds"); - fprintf(f,"1\n"); - fprintf(f,"0.0\n"); - fprintf(f,"%d\n", Msg::GetCommSize() > 1 ? 4 : 3); - fprintf(f,"0\n 1\n %d\n",COUNT); - if(Msg::GetCommSize() > 1) fprintf(f,"%d\n", Msg::GetCommRank()); - for (int i=0;i < _groups.getNbElementGroups() ;i++){ - dgGroupOfElements *group = _groups.getElementGroup(i); - int groupType=0;//-3*group->getMultirateExponent(); - if(group->getIsInnerMultirateBuffer()) - groupType+=1; - if(group->getIsOuterMultirateBuffer()) - groupType+=2; - for (int iElement=0 ; iElement< group->getNbElements() ;++iElement) { - MElement *e = group->getElement(iElement); - int num = e->getNum(); - fullMatrix<double> sol(getGroupProxy(i), iElement*_nbFields,_nbFields); - fprintf(f,"%d %d",num,sol.size1()); - for (int k=0;k<sol.size1();++k) { - fprintf(f," %.16E ",groupType*1.0); - } - fprintf(f,"\n"); - } - } - fprintf(f,"$EndElementNodeData\n"); - fclose(f); - return; - // we should discuss that : we do a copy of the solution, this should - // be avoided ! - - /*std::map<int, std::vector<double> > data; - - for (int i=0;i < _groups.getNbElementGroups() ;i++){ - dgGroupOfElements *group = _groups.getElementGroup(i); - for (int iElement=0 ; iElement< group->getNbElements() ;++iElement) { - MElement *e = group->getElement(iElement); - int num = e->getNum(); - fullMatrix<double> sol(getGroupProxy(i), iElement*_nbFields,_nbFields); - std::vector<double> val; - // val.resize(sol.size2()*sol.size1()); - val.resize(sol.size1()); - int counter = 0; - // for (int iC=0;iC<sol.size2();iC++) - printf("%g %g %g\n",sol(0,0),sol(1,0),sol(2,0)); - for (int iR=0;iR<sol.size1();iR++)val[counter++] = sol(iR,0); - data[num] = val; - } - } - - PView *pv = new PView (name, "ElementNodeData", _gm, data, 0.0, 1); - pv->getData()->writeMSH(name+".msh", false); - delete pv; - */ -} - -void dgDofContainer::exportMsh(const std::string name) -{ - // the elementnodedata::export does not work !! - - for (int ICOMP = 0; ICOMP<_nbFields;++ICOMP){ - std::ostringstream name_oss, name_view; - name_view<<"comp_"<<ICOMP; - name_oss<<name<<"_COMP_"<<ICOMP<<".msh"; - if(Msg::GetCommSize()>1) - name_oss<<"_"<<Msg::GetCommRank(); - FILE *f = fopen (name_oss.str().c_str(),"w"); - if(!f){ - Msg::Fatal("Unable to open export file '%s'", name.c_str()); - } - - int COUNT = 0; - for (int i=0;i < _groups.getNbElementGroups() ;i++){ - COUNT += _groups.getElementGroup(i)->getNbElements(); - } - fprintf(f,"$MeshFormat\n2.1 0 8\n$EndMeshFormat\n"); - fprintf(f,"$ElementNodeData\n"); - fprintf(f,"1\n"); - fprintf(f,"\"%s\"\n",name_view.str().c_str()); - fprintf(f,"1\n"); - fprintf(f,"%d\n", _mshStep); // should print actual time here - fprintf(f,"%d\n", Msg::GetCommSize() > 1 ? 4 : 3); - fprintf(f,"%d\n 1\n %d\n", _mshStep, COUNT); - if(Msg::GetCommSize() > 1) fprintf(f,"%d\n", Msg::GetCommRank()); - for (int i=0;i < _groups.getNbElementGroups() ;i++){ - dgGroupOfElements *group = _groups.getElementGroup(i); - for (int iElement=0 ; iElement< group->getNbElements() ;++iElement) { - MElement *e = group->getElement(iElement); - int num = e->getNum(); - fullMatrix<double> sol(getGroupProxy(i), iElement*_nbFields,_nbFields); - fprintf(f,"%d %d",num,sol.size1()); - for (int k=0;k<sol.size1();++k) { - fprintf(f," %.16E ",sol(k,ICOMP)); - } - fprintf(f,"\n"); - } - } - fprintf(f,"$EndElementNodeData\n"); - fclose(f); - } - - _mshStep++; - - // we should discuss that : we do a copy of the solution, this should - // be avoided ! - - /*std::map<int, std::vector<double> > data; - - for (int i=0;i < _groups.getNbElementGroups() ;i++){ - dgGroupOfElements *group = _groups.getElementGroup(i); - for (int iElement=0 ; iElement< group->getNbElements() ;++iElement) { - MElement *e = group->getElement(iElement); - int num = e->getNum(); - fullMatrix<double> sol(getGroupProxy(i), iElement*_nbFields,_nbFields); - std::vector<double> val; - // val.resize(sol.size2()*sol.size1()); - val.resize(sol.size1()); - int counter = 0; - // for (int iC=0;iC<sol.size2();iC++) - printf("%g %g %g\n",sol(0,0),sol(1,0),sol(2,0)); - for (int iR=0;iR<sol.size1();iR++)val[counter++] = sol(iR,0); - data[num] = val; - } - } - - PView *pv = new PView (name, "ElementNodeData", _gm, data, 0.0, 1); - pv->getData()->writeMSH(name+".msh", false); - delete pv; - */ -} - -#include "LuaBindings.h" -void dgDofContainer::registerBindings(binding *b){ - classBinding *cb = b->addClass<dgDofContainer>("dgDofContainer"); - cb->setDescription("The DofContainer class provides a vector containing the degree of freedoms"); - methodBinding *cm; - cm = cb->setConstructor<dgDofContainer,dgGroupCollection*,int>(); - cm->setDescription("Build a vector"); - cm->setArgNames("GroupCollection","nbFields",NULL); - cm = cb->addMethod("L2Projection",&dgDofContainer::L2Projection); - cm->setDescription("Project a function onto this vector"); - cm->setArgNames("functionName",NULL); - cm = cb->addMethod("exportMsh",&dgDofContainer::exportMsh); - cm->setDescription("Export the dof for gmsh visualization"); - cm->setArgNames("filename", NULL); - cm = cb->addMethod("exportGroupIdMsh",&dgDofContainer::exportGroupIdMsh); - cm->setDescription("Export the group ids for gmsh visualization"); - cm = cb->addMethod("exportMultirateGroupMsh",&dgDofContainer::exportMultirateGroupMsh); - cm->setDescription("Export the group Multirate properties for gmsh visualization"); - cm = cb->addMethod("norm",(double (dgDofContainer::*)())&dgDofContainer::norm); - cm->setDescription("Returns the norm of the vector"); - cm = cb->addMethod("scale",(void (dgDofContainer::*)(double))&dgDofContainer::scale); - cm->setArgNames("factor",NULL); - cm->setDescription("this=this*scale"); - cm = cb->addMethod("setAll",(void (dgDofContainer::*)(double))&dgDofContainer::setAll); - cm->setArgNames("value",NULL); - cm->setDescription("set same value to all DOFs"); - cm = cb->addMethod("axpy",(void (dgDofContainer::*)(dgDofContainer &,double)) &dgDofContainer::axpy); - cm->setArgNames("dofContainer","a",NULL); - cm->setDescription("this = this+a*dofContainer"); - cm = cb->addMethod("Mesh2Mesh_BuildL2Projection",&dgDofContainer::Mesh2Mesh_BuildL2Projection); - cm->setDescription("Build L2 projection matrix between donor and this dofContainer."); - cm->setArgNames("projector","donor",NULL); - cm = cb->addMethod("Mesh2Mesh_ApplyL2Projection",&dgDofContainer::Mesh2Mesh_ApplyL2Projection); - cm->setDescription("Apply L2 projection matrix from donor to this dofContainer."); - cm->setArgNames("projector","donor","transpose","copy",NULL); - cm = cb->addMethod("getGroupProxy",&dgDofContainer::getGroupProxyBinding); - cm->setDescription("return the proxy to the solution of one group"); - cm->setArgNames("group",NULL); -} diff --git a/Solver/dgDofContainer.h b/Solver/dgDofContainer.h deleted file mode 100644 index 13b1e2ea9842eb9e6b0893859eb88f727cca5435..0000000000000000000000000000000000000000 --- a/Solver/dgDofContainer.h +++ /dev/null @@ -1,68 +0,0 @@ -#ifndef _DG_DOF_CONTAINER_H_ -#define _DG_DOF_CONTAINER_H_ - -#include <vector> -#include "fullMatrix.h" -#include "linearSystemCSR.h" -class dgGroupCollection; -class dgGroupOfElements; -class function; - -class dgDofContainer { -private: - dgDofContainer (const dgDofContainer&); - int _totalNbElements; - int _nbFields; - dgGroupCollection &_groups; - int _dataSizeGhost; - fullVector<double> * _data; // the full data itself - fullVector<double> * _ghostData; - //inline int getDataSize(){return _dataSize;} - // parallel - void buildParallelStructure(); - bool _parallelStructureExists; - int *countSend,*countRecv,*shiftSend,*shiftRecv,*groupShiftRecv; - double *sendBuf, *recvBuf; - std::vector<fullMatrix<double> *> _dataProxys; // proxys - std::map<const dgGroupOfElements*,int> _groupId; - std::vector<int> _groupFirstDofId; - int _mshStep; -public: - void scale(double f); - inline int getDofId (int groupId, int elementId, int fieldId, int nodeId) const { - const fullMatrix<double> &proxy = getGroupProxy(groupId); - return _groupFirstDofId[groupId]+(elementId*_nbFields+fieldId)*proxy.size1()+nodeId; - } - inline int getGroupFirstDofId(int groupId) { - return _groupFirstDofId[groupId]; - } - inline fullVector<double> &getVector() {return *_data;} - void scale(std::vector<dgGroupOfElements*>groups, double f); - double norm(); - double norm(std::vector<dgGroupOfElements*>groups); - void axpy(dgDofContainer &x, double a=1.); - void axpy(std::vector<dgGroupOfElements*>groups,dgDofContainer &x, double a=1.); - inline fullMatrix<double> &getGroupProxy(int gId){ return *(_dataProxys[gId]); } - inline fullMatrix<double> *getGroupProxyBinding(int gId){ return (_dataProxys[gId]); } - inline const fullMatrix<double> &getGroupProxy(int gId) const { return *(_dataProxys[gId]); } - inline fullMatrix<double> &getGroupProxy(const dgGroupOfElements* g){ return *(_dataProxys[_groupId[g]]); } - dgDofContainer (dgGroupCollection *groups, int nbFields); - ~dgDofContainer (); - int getNbElements() {return _totalNbElements;} - int getNbFields() {return _nbFields;} - void scatter(); - void save(const std::string name); - void load(const std::string name); - void setAll(double v); - void L2Projection(const function *f); - void Mesh2Mesh_BuildL2Projection(linearSystemCSRGmm<double> &projector,dgDofContainer &donor); - void multAddInverseMassMatrixL2Projection(linearSystemCSRGmm<double> &projector); // this method should be private - void Mesh2Mesh_ApplyL2Projection(linearSystemCSRGmm<double> &projector,dgDofContainer &donor, int transpose, int copy); - void exportMsh(const std::string name); - void exportGroupIdMsh(); - void exportMultirateGroupMsh(); - - static void registerBindings(binding *b); - inline dgGroupCollection *getGroups() { return &_groups; } -}; -#endif diff --git a/Solver/dgFunctionIntegrator.cpp b/Solver/dgFunctionIntegrator.cpp deleted file mode 100644 index d72984bae92a536afb1d25f8276df033b1028dd2..0000000000000000000000000000000000000000 --- a/Solver/dgFunctionIntegrator.cpp +++ /dev/null @@ -1,51 +0,0 @@ -#include "function.h" -#include "dgFunctionIntegrator.h" -#include "dgDofContainer.h" -#include "fullMatrix.h" -#include "dgGroupOfElements.h" - -#include <stdio.h> - -dgFunctionIntegrator::dgFunctionIntegrator(const function *f):_f(f){} - -void dgFunctionIntegrator::compute(dgDofContainer *sol,fullMatrix<double> &result){ - int nbFields=sol->getNbFields(); - dataCacheMap cacheMap; - dataCacheDouble &UVW=cacheMap.get(function::getParametricCoordinates(),NULL); - dataCacheDouble &solutionQPe=cacheMap.get(function::getSolution(),NULL); - dataCacheDouble &F=cacheMap.get(_f); - int nbRowResult=result.size1(); - result.scale(0.0); - for(int iGroup=0;iGroup<sol->getGroups()->getNbElementGroups();iGroup++){ - dgGroupOfElements &group=*sol->getGroups()->getElementGroup(iGroup); - fullMatrix<double> &solProxy=sol->getGroupProxy(&group); - cacheMap.setNbEvaluationPoints(group.getNbIntegrationPoints()); - UVW.set()=group.getIntegrationPointsMatrix(); - fullMatrix<double> solutionQP (group.getNbIntegrationPoints(),group.getNbElements() * nbFields); - group.getCollocationMatrix().mult(solProxy , solutionQP); - fullMatrix<double> IPMatrix = group.getIntegrationPointsMatrix(); - for (int iElement=0 ; iElement<group.getNbElements() ;++iElement) { - cacheMap.setElement(group.getElement(iElement)); - solutionQPe.set().setAsProxy(solutionQP, iElement*nbFields, nbFields ); - for (int iPt =0; iPt< group.getNbIntegrationPoints(); iPt++) { - const double detJ = group.getDetJ (iElement, iPt); - for (int k=0;k<nbRowResult;k++){ - result(0,k) += F(iPt,k)*detJ*IPMatrix(iPt,3); - } - } - } - } -} - -#include "Bindings.h" -void dgFunctionIntegrator::registerBindings(binding *b){ - classBinding *cb = b->addClass<dgFunctionIntegrator>("dgFunctionIntegrator"); - cb->setDescription("Integrates a function, using the compute function"); - methodBinding *mb; - mb = cb->setConstructor<dgFunctionIntegrator,const function*>(); - mb->setArgNames("function",NULL); - mb->setDescription("a new dgFunctionIntegrator, get the solution using the compute method"); - mb = cb->addMethod("compute", &dgFunctionIntegrator::compute); - mb->setArgNames("dofContainer","result",NULL); - mb->setDescription("compute the integral of the function"); -} diff --git a/Solver/dgFunctionIntegrator.h b/Solver/dgFunctionIntegrator.h deleted file mode 100644 index 3c3d0cbf1a024f00426137fd3faab7c9127e996e..0000000000000000000000000000000000000000 --- a/Solver/dgFunctionIntegrator.h +++ /dev/null @@ -1,11 +0,0 @@ -#include <string> -class dgDofContainer; -class binding; -class function; -class dgFunctionIntegrator{ - const function *_f; - public: - dgFunctionIntegrator(const function *f); - void compute(dgDofContainer *sol,fullMatrix<double> &result); - static void registerBindings(binding *b); -}; diff --git a/Solver/dgGroupOfElements.cpp b/Solver/dgGroupOfElements.cpp deleted file mode 100644 index 79b9942a39059f704e5db5f7c2a8e21090e96bbe..0000000000000000000000000000000000000000 --- a/Solver/dgGroupOfElements.cpp +++ /dev/null @@ -1,1245 +0,0 @@ -#include <algorithm> -#include "GmshConfig.h" -#include "GmshMessage.h" -#include "dgGroupOfElements.h" -#include "dgConservationLaw.h" -#include "dgDofContainer.h" -#include "dgAlgorithm.h" -#include "MElement.h" -#include "polynomialBasis.h" -#include "Numeric.h" -#include "MTriangle.h" -#include "MQuadrangle.h" -#include "MLine.h" -#include "MPoint.h" -#include "GModel.h" -#ifdef HAVE_MPI -#include "mpi.h" -#else -#include <string.h> -#endif -//#define TEST - - -static fullMatrix<double> * dgGetIntegrationRule (MElement *e, int p){ - int npts; - IntPt *pts; - e->getIntegrationPoints(2*p+1, &npts, &pts); - fullMatrix<double> *m = new fullMatrix<double> (npts, 4); - for (int i=0;i<npts;i++){ - (*m)(i,0) = pts[i].pt[0]; - (*m)(i,1) = pts[i].pt[1]; - (*m)(i,2) = pts[i].pt[2]; - (*m)(i,3) = pts[i].weight; - } - return m; -} - -static fullMatrix<double> dgGetFaceIntegrationRuleOnElement ( - const polynomialBasis *fsFace, - const fullMatrix<double> &intgFace, - const polynomialBasis *fsElement, - const std::vector <int> &closure) { - int npts=intgFace.size1(); - fullMatrix<double> intgElement(npts, 4); - double f[256]; - for (int i=0;i<npts;i++){ - fsFace->f(intgFace(i,0),intgFace(i,1),intgFace(i,2),f); - for(size_t j=0; j<closure.size();j++){ - int jNod=closure[j]; - for(int k=0;k<fsElement->points.size2();k++) - intgElement(i,k) += f[j] * fsElement->points(jNod,k); - intgElement(i,3) = intgFace(i,3); - } - } - return intgElement; -} - -dgGroupOfElements::dgGroupOfElements(const std::vector<MElement*> &e, - int polyOrder, - int ghostPartition) - : _elements(e), - _fs(*_elements[0]->getFunctionSpace(polyOrder)), - _integration(dgGetIntegrationRule (_elements[0], polyOrder)), - _ghostPartition(ghostPartition) -{ - _order=polyOrder; - _dimUVW = _dimXYZ = e[0]->getDim(); - // this is the biggest piece of data ... the mappings - int nbNodes = _fs.coefficients.size1(); - int nbQP = _integration->size1(); - _redistributionFluxes[0] = new fullMatrix<double> (nbNodes, nbQP); - _redistributionFluxes[1] = new fullMatrix<double> (nbNodes, nbQP); - _redistributionFluxes[2] = new fullMatrix<double> (nbNodes, nbQP); - _redistributionSource = new fullMatrix<double> (nbNodes, nbQP); - _collocation = new fullMatrix<double> (nbQP, nbNodes); - _mapping = new fullMatrix<double> (e.size(), 10 * nbQP); - _imass = new fullMatrix<double> (nbNodes,nbNodes*e.size()); - _dPsiDx = new fullMatrix<double> ( nbQP*3,nbNodes*e.size()); - _elementVolume = new fullMatrix<double> (e.size(),1); - _innerRadii = new fullMatrix<double> (e.size(),1); - double g[256][3],f[256]; - - for (int i=0;i<_elements.size();i++){ - MElement *e = _elements[i]; - element_to_index[e] = i; - fullMatrix<double> imass(*_imass,nbNodes*i,nbNodes); - (*_innerRadii)(i,0)=e->getInnerRadius(); - for (int j=0;j< nbQP ; j++ ){ - _fs.f((*_integration)(j,0), (*_integration)(j,1), (*_integration)(j,2), f); - _fs.df((*_integration)(j,0), (*_integration)(j,1), (*_integration)(j,2), g); - double jac[3][3],ijac[3][3],detjac; - (*_mapping)(i,10*j + 9) = - e->getJacobian ((*_integration)(j,0), (*_integration)(j,1), (*_integration)(j,2), jac); - (*_elementVolume)(i,0) += (*_mapping)(i,10*j+9)*(*_integration)(j,3); - const double weight = (*_integration)(j,3); - detjac=inv3x3(jac,ijac); - (*_mapping)(i,10*j + 0) = ijac[0][0]; - (*_mapping)(i,10*j + 1) = ijac[0][1]; - (*_mapping)(i,10*j + 2) = ijac[0][2]; - (*_mapping)(i,10*j + 3) = ijac[1][0]; - (*_mapping)(i,10*j + 4) = ijac[1][1]; - (*_mapping)(i,10*j + 5) = ijac[1][2]; - (*_mapping)(i,10*j + 6) = ijac[2][0]; - (*_mapping)(i,10*j + 7) = ijac[2][1]; - (*_mapping)(i,10*j + 8) = ijac[2][2]; - for (int k=0;k<nbNodes;k++){ - for (int l=0;l<nbNodes;l++) { - imass(k,l) += f[k]*f[l]*weight*detjac; - } - // (iQP+iXYZ*nbQP , iElement*NPsi+iPsi) - (*_dPsiDx)(j , i*nbNodes+k) = g[k][0]*ijac[0][0]+g[k][1]*ijac[0][1]+g[k][2]*ijac[0][2]; - (*_dPsiDx)(j+nbQP , i*nbNodes+k) = g[k][0]*ijac[1][0]+g[k][1]*ijac[1][1]+g[k][2]*ijac[1][2]; - (*_dPsiDx)(j+nbQP*2, i*nbNodes+k) = g[k][0]*ijac[2][0]+g[k][1]*ijac[2][1]+g[k][2]*ijac[2][2]; - } - } - imass.invertInPlace(); - } - // redistribution matrix - // quadrature weight x parametric gradients in quadrature points - // redistribition Jacobian Matrix : quadrature weight x parametric gradients x shapefunctions - - _PsiDPsiDXi = fullMatrix<double> (_dimUVW*nbQP, nbNodes*nbNodes); - //reditribution of the diffusive jacobian dimUVW*dimUVW*nbIntegrationPoints x nbNodes*nbNodes - _dPsiDXDPsiDXi = fullMatrix<double> (nbNodes*nbNodes, _dimUVW*_dimUVW*nbQP); - - for (int xi=0;xi<nbQP; xi++) { - _fs.df((*_integration)(xi,0), - (*_integration)(xi,1), - (*_integration)(xi,2), g); - _fs.f((*_integration)(xi,0), - (*_integration)(xi,1), - (*_integration)(xi,2), f); - const double weight = (*_integration)(xi,3); - for (int k=0;k<nbNodes; k++){ - (*_redistributionFluxes[0])(k,xi) = g[k][0] * weight; - (*_redistributionFluxes[1])(k,xi) = g[k][1] * weight; - (*_redistributionFluxes[2])(k,xi) = g[k][2] * weight; - (*_redistributionSource)(k,xi) = f[k] * weight; - (*_collocation)(xi,k) = f[k]; - // for (int l=0;l<_fs.coefficients.size1();l++){ - // (*_redistributionJacobianOfFluxes[0])(l+_fs.coefficients.size1()*k,j) = g[k][0] * f[l] * weight; - // (*_redistributionJacobianOfFluxes[0])(l+_fs.coefficients.size1()*k,j) = g[k][1] * f[l] * weight; - // (*_redistributionJacobianOfFluxes[0])(l+_fs.coefficients.size1()*k,j) = g[k][2] * f[l] * weight; - // } - } - for (int alpha=0; alpha<_dimUVW; alpha++) for (int beta=0; beta<_dimUVW; beta++) { - for (int i=0; i<nbNodes; i++) for (int j=0; j<nbNodes; j++) { - _dPsiDXDPsiDXi(i*nbNodes+j, (alpha*_dimUVW+beta)*nbQP+xi) = g[i][alpha]*g[j][beta]*weight; - } - } - for (int alpha=0; alpha<_dimUVW; alpha++){ - for (int i=0; i<nbNodes; i++) for (int j=0; j<nbNodes; j++) { - _PsiDPsiDXi(alpha*nbQP+xi, i*nbNodes+j) = g[i][alpha]*f[j]*weight; - } - } - } -} - -void dgGroupOfElements::copyPrivateDataFrom(const dgGroupOfElements *from){ - _multirateExponent=from->getMultirateExponent(); - _multirateInnerBuffer=from->getIsInnerMultirateBuffer(); - _multirateOuterBuffer=from->getIsOuterMultirateBuffer(); -} - -dgGroupOfElements::~dgGroupOfElements(){ - delete _integration; - // delete _redistributionJacobianOfFluxes[0]; - // delete _redistributionJacobianOfFluxes[1]; - // delete _redistributionJacobianOfFluxes[2]; - delete _redistributionFluxes[0]; - delete _redistributionFluxes[1]; - delete _redistributionFluxes[2]; - delete _redistributionSource; - delete _dPsiDx; - delete _mapping; - delete _collocation; - delete _imass; - delete _elementVolume; -} - - -dgGroupOfFaces::~dgGroupOfFaces() -{ - if (!_faces.size())return; - delete _redistribution; - delete _collocation; - delete _detJac; - delete _interfaceSurface; -} - - -dgGroupOfConnections::dgGroupOfConnections(const dgGroupOfElements &elementGroup, const dgGroupOfFaces &faceGroup, int pOrder) : - _elementGroup(elementGroup), - _faceGroup(faceGroup) -{ - _fs = _elementGroup.getElement(0)->getFunctionSpace(pOrder); -} - -void dgGroupOfFaces::mapToInterface (int nFields, std::vector<const fullMatrix<double> *> &proxies, fullMatrix<double> &v) -{ - int nbConnections = getNbGroupOfConnections(); - for (int i=0; i<getNbElements(); i++) { - for (int iConnection = 0; iConnection<getNbGroupOfConnections(); iConnection++) { - const std::vector<int> &closure = _connections[iConnection]->getClosure(i); - for (int iField=0; iField<nFields; iField++) { - for(size_t j =0; j < closure.size(); j++) { - v(j, (i*nbConnections+iConnection)*nFields + iField) = - (*proxies[iConnection])(closure[j],_connections[iConnection]->getElementId(i)*nFields + iField); - } - } - } - } -} - -void dgGroupOfFaces::mapFromInterface (int nFields, const fullMatrix<double> &v, std::vector< fullMatrix<double> *> &proxies) -{ - int nbConnections = getNbGroupOfConnections(); - for (int i=0; i<getNbElements(); i++) { - for (int iConnection = 0; iConnection<getNbGroupOfConnections(); iConnection++) { - const std::vector<int> &closure = _connections[iConnection]->getClosure(i); - for (int iField=0; iField<nFields; iField++){ - for(size_t j =0; j < closure.size(); j++) - (*proxies[iConnection])(closure[j], _connections[iConnection]->getElementId(i)*nFields + iField) += - v(j, (i*nbConnections+iConnection)*nFields + iField); - } - } - } -} - -void dgGroupOfFaces::mapLeftFromInterface ( int nFields, - const fullMatrix<double> &v, - fullMatrix<double> &vLeft - ) -{ - for(int i=0; i<getNbElements(); i++) { - const std::vector<int> &closureLeft = _connections[0]->getClosure(i); - for (int iField=0; iField<nFields; iField++){ - for(size_t j =0; j < closureLeft.size(); j++) - vLeft(closureLeft[j], _connections[0]->getElementId(i)*nFields + iField) += v(j, i*2*nFields + iField); - } - } -} -void dgGroupOfFaces::mapRightFromInterface ( int nFields, - const fullMatrix<double> &v, - fullMatrix<double> &vRight - ) -{ - if(_connections.size()==1) - return; - for(int i=0; i<getNbElements(); i++) { - const std::vector<int> &closureRight = _connections[1]->getClosure(i); - for (int iField=0; iField<nFields; iField++){ - for(size_t j =0; j < closureRight.size(); j++) - vRight(closureRight[j], _connections[1]->getElementId(i)*nFields + iField) += v(j, (i*2+1)*nFields + iField); - } - } -} - -void dgGroupOfConnections::init() { - _closures = _fs->closures; - for (size_t i=0; i<_closures.size(); i++) - _integrationPoints.push_back(dgGetFaceIntegrationRuleOnElement( - _faceGroup.getPolynomialBasis(), _faceGroup.getIntegrationPointsMatrix(), - _fs,_closures[i])); - - int nPsi = _fs->points.size1(); - int nQP = _integrationPoints[0].size1(); - int size = _elementId.size(); - // compute data on quadrature points : normals and dPsidX - double g[256][3]; - _normals = fullMatrix<double> (3, nQP*size); - _dPsiDx = fullMatrix<double> (nQP*3, nPsi*size); - int index = 0; - for (size_t i=0; i<size;i++){ - const std::vector<int> &closure = getClosure(i); - const fullMatrix<double> &integration = getIntegrationPointsOnElement(i); - double jac[3][3],ijac[3][3]; - for (int j=0; j<integration.size1(); j++){ - _fs->df(integration(j,0), integration(j,1), integration(j,2),g); - getElement(i)->getJacobian (integration(j,0), integration(j,1), integration(j,2), jac); - inv3x3(jac,ijac); - //compute dPsiDxOnQP - // (iQP+iXYZ*nbQP , iFace*NPsi+iPsi) - for (int iPsi=0; iPsi< nPsi; iPsi++) { - _dPsiDx(j , i*nPsi+iPsi) = g[iPsi][0]*ijac[0][0]+g[iPsi][1]*ijac[0][1]+g[iPsi][2]*ijac[0][2]; - _dPsiDx(j+nQP , i*nPsi+iPsi) = g[iPsi][0]*ijac[1][0]+g[iPsi][1]*ijac[1][1]+g[iPsi][2]*ijac[1][2]; - _dPsiDx(j+nQP*2, i*nPsi+iPsi) = g[iPsi][0]*ijac[2][0]+g[iPsi][1]*ijac[2][1]+g[iPsi][2]*ijac[2][2]; - } - //compute face normals - double &nx=_normals(0,index); - double &ny=_normals(1,index); - double &nz=_normals(2,index); - double nu=0,nv=0,nw=0; - for (size_t k=0; k<closure.size(); k++){ - int inode=closure[k]; - nu += g[inode][0]; - nv += g[inode][1]; - nw += g[inode][2]; - } - nx = nu*ijac[0][0]+nv*ijac[0][1]+nw*ijac[0][2]; - ny = nu*ijac[1][0]+nv*ijac[1][1]+nw*ijac[1][2]; - nz = nu*ijac[2][0]+nv*ijac[2][1]+nw*ijac[2][2]; - double norm = sqrt(nx*nx+ny*ny+nz*nz); - nx/=norm; - ny/=norm; - nz/=norm; - index++; - } - } -} - -// this function creates groups of elements -// First, groups of faces are created on every physical group -// of dimension equal to the dimension of the problem minus one -// Then, groups of elements are created -// -) Elements of different types are separated -// -) Then those groups are split into partitions - -void dgGroupCollection::buildGroupsOfElements(GModel *model, int dim, int order, std::vector<std::string>* physicalTags) -{ - if(_groupsOfElementsBuilt) - return; - _groupsOfElementsBuilt=true; - _model = model; - std::vector<GEntity*> entities; - model->getEntities(entities); - std::map<int, std::vector<MElement *> >localElements; - std::vector<std::map<int, std::vector<MElement *> > >ghostElements(Msg::GetCommSize()); // [partition][elementType] - std::multimap<MElement*, short> &ghostsCells = _model->getGhostCells(); - for(unsigned int i = 0; i < entities.size(); i++){ - GEntity *entity = entities[i]; - bool correctPhysicalTag = false; - if(physicalTags==NULL || physicalTags->size()==0) - correctPhysicalTag = true; - else - for(unsigned int iPhy = 0; iPhy < entity->physicals.size(); iPhy++) - for(unsigned int jPhy = 0; jPhy < physicalTags->size(); jPhy++) - if (_model->getPhysicalName(dim,entity->physicals[iPhy]) == physicalTags->at(jPhy) ) - correctPhysicalTag = true; - - if(entity->dim() == dim && correctPhysicalTag){ - for (int iel=0; iel<entity->getNumMeshElements(); iel++){ - MElement *el=entity->getMeshElement(iel); - if(el->getPartition()==Msg::GetCommRank()+1 || el->getPartition()==0){ - localElements[el->getType()].push_back(el); - } else { - std::multimap<MElement*, short>::iterator ghost=ghostsCells.lower_bound(el); - while(ghost!= ghostsCells.end() && ghost->first==el){ - if(abs(ghost->second)-1==Msg::GetCommRank()){ - ghostElements[el->getPartition()-1][el->getType()].push_back(el); - } - ghost++; - } - } - } - } - } - - // do a group of elements for every element type in the mesh - int id=_elementGroups.size(); - for (std::map<int, std::vector<MElement *> >::iterator it = localElements.begin(); it !=localElements.end() ; ++it){ - dgGroupOfElements *newGroup=new dgGroupOfElements(it->second,order); - _elementGroups.push_back(newGroup); - id++; - } - - //create ghost groups - for(int i=0;i<Msg::GetCommSize();i++){ - for (std::map<int, std::vector<MElement *> >::iterator it = ghostElements[i].begin(); it !=ghostElements[i].end() ; ++it){ - dgGroupOfElements *gof=new dgGroupOfElements(it->second,order,i); - if (gof->getNbElements()) - _ghostGroups.push_back(gof); - else - delete gof; - } - } -} - -class dgMiniConnection -{ - public: - int iGroup, iElement, iClosure; - dgMiniConnection (int iGroup_, int iElement_, int iClosure_) - { - iGroup = iGroup_; - iElement = iElement_; - iClosure = iClosure_; - } - bool operator < (const dgMiniConnection b) const - { - if (iGroup < b.iGroup) return true; - if (iGroup > b.iGroup) return false; - if (iElement < b.iElement) return true; - if (iElement > b.iElement) return false; - if (iClosure < b.iClosure) return true; - return false; - } -}; - -class dgMiniInterface -{ - public: - int physicalTag; - int numVertices; - std::vector<dgMiniConnection> connections; - dgMiniInterface() - { - physicalTag = -1; - } - bool isFullGhost(dgGroupCollection &groups) - { - bool fullGhost = true; - for (size_t i = 0; i<connections.size(); i++) { - fullGhost &= (connections[i].iGroup >= groups.getNbElementGroups()); - } - return fullGhost; - } -}; - -static std::vector<dgMiniInterface> *_createMiniInterfaces(dgGroupCollection &groups) -{ - std::vector<GEntity*> entities; - groups.getModel()->getEntities(entities); - std::map<MVertex*, dgMiniInterface> vertexInterfaces; - std::map<MEdge, dgMiniInterface, Less_Edge> edgeInterfaces; - std::map<MFace, dgMiniInterface, Less_Face> faceInterfaces; - int dim = groups.getElementGroup(0)->getElement(0)->getDim(); - // 1) get tag of existing interfaces - for(unsigned int i = 0; i < entities.size(); i++){ - GEntity *entity = entities[i]; - if(entity->dim() == dim-1){ - for(unsigned int j = 0; j < entity->physicals.size(); j++){ - int physicalTag = entity->physicals[j]; - for (int k = 0; k < entity->getNumMeshElements(); k++) { - MElement *element = entity->getMeshElement(k); - switch(dim) { - case 1: vertexInterfaces[element->getVertex(0)].physicalTag = physicalTag; break; - case 2: edgeInterfaces[element->getEdge(0)].physicalTag = physicalTag; break; - case 3: faceInterfaces[element->getFace(0)].physicalTag = physicalTag; break; - default : throw; - } - } - } - } - } - // 2) build new interfaces - int iClosure; - for (size_t iGroup = 0; iGroup < groups.getNbElementGroups()+groups.getNbGhostGroups(); iGroup++) { - dgGroupOfElements &group = *groups.getElementGroup(iGroup); - for (size_t iElement = 0; iElement < group.getNbElements(); iElement++) { - MElement &element = *group.getElement(iElement); - switch(dim) { - case 1: - for (int iVertex = 0; iVertex < element.getNumVertices(); iVertex++) { - iClosure = element.getFunctionSpace()->getClosureId(iVertex); - vertexInterfaces[element.getVertex(iVertex)].connections.push_back(dgMiniConnection(iGroup,iElement,iClosure)); - } - break; - case 2: - for (int iEdge = 0; iEdge < element.getNumEdges(); iEdge++) { - std::map<MEdge, dgMiniInterface, Less_Edge>::iterator it = - edgeInterfaces.insert(std::pair<MEdge,dgMiniInterface>(element.getEdge(iEdge),dgMiniInterface())).first; - int iEdge_, sign; - element.getEdgeInfo(it->first, iEdge_, sign); - iClosure = element.getFunctionSpace()->getClosureId(iEdge,sign); - it->second.connections.push_back(dgMiniConnection(iGroup,iElement,iClosure)); - } - break; - case 3: - for (int iFace = 0; iFace < element.getNumFaces(); iFace++) { - std::map<MFace, dgMiniInterface, Less_Face>::iterator it = - faceInterfaces.insert(std::pair<MFace,dgMiniInterface>(element.getFace(iFace),dgMiniInterface())).first; - int iFace_, sign, rotation; - element.getFaceInfo(it->first, iFace_, sign, rotation); - iClosure = element.getFunctionSpace ()->getClosureId (iFace, sign, rotation); - it->second.connections.push_back(dgMiniConnection(iGroup,iElement,iClosure)); - } - break; - default : throw; - } - } - } - std::vector<dgMiniInterface> *interfaces = new std::vector<dgMiniInterface>; - switch(dim) { - case 1: - interfaces->reserve(vertexInterfaces.size()); - for(std::map<MVertex*, dgMiniInterface>::iterator it = vertexInterfaces.begin(); it != vertexInterfaces.end(); it++) { - it->second.numVertices = 1; - interfaces->push_back(it->second); - } - break; - case 2: - interfaces->reserve(edgeInterfaces.size()); - for(std::map<MEdge, dgMiniInterface, Less_Edge>::iterator it = edgeInterfaces.begin(); it != edgeInterfaces.end(); it++) { - it->second.numVertices = it->first.getNumVertices(); - interfaces->push_back(it->second); - } - break; - case 3: - interfaces->reserve(faceInterfaces.size()); - for(std::map<MFace, dgMiniInterface,Less_Face>::iterator it = faceInterfaces.begin(); it != faceInterfaces.end(); it++) { - it->second.numVertices = it->first.getNumVertices(); - interfaces->push_back(it->second); - } - break; - } - for (size_t i = 0; i < interfaces->size(); i++) { - std::sort((*interfaces)[i].connections.begin(), (*interfaces)[i].connections.end()); - } - return interfaces; -} - -class dgGroupKey : public std::binary_function<dgMiniInterface, dgMiniInterface, bool> { - const dgGroupCollection &_groups; - public: - dgGroupKey (const dgGroupCollection &groups) : _groups(groups){}; - bool operator ()(const dgMiniInterface &i1, const dgMiniInterface &i2) const - { - // 1 sort by number of connections - if (i1.connections.size() < i2.connections.size()) return true; - if (i1.connections.size() > i2.connections.size()) return false; - // 2 sort by physical tag - if (i1.physicalTag < i2.physicalTag) return true; - if (i1.physicalTag > i2.physicalTag) return false; - // 3 sort by groups of elements - for (size_t i = 0; i < i1.connections.size(); i++) { - if (i1.connections[i].iGroup < i2.connections[i].iGroup) return true; - if (i1.connections[i].iGroup > i2.connections[i].iGroup) return false; - } - // 4 sort by number of vertices in the interface - if (i1.connections.size()>0) { - const dgMiniConnection &c1 = i1.connections[0]; - const dgMiniConnection &c2 = i2.connections[0]; - int closureSize1 = _groups.getElementGroup(c1.iGroup)->getElement(c1.iElement)->getFunctionSpace()->getClosure(c1.iClosure).size(); - int closureSize2 = _groups.getElementGroup(c2.iGroup)->getElement(c2.iElement)->getFunctionSpace()->getClosure(c2.iClosure).size(); - if (closureSize1 < closureSize2) return true; - if (closureSize1 > closureSize2) return false; - } - return false; - } -}; - -void dgGroupCollection::buildGroupsOfInterfaces() -{ - if(_groupsOfInterfacesBuilt) - Msg::Error("groups of interfaces already built"); - _groupsOfInterfacesBuilt=true; - int pOrder = _elementGroups[0]->getOrder(); - std::vector<dgMiniInterface> *interfaces = _createMiniInterfaces(*this); - dgGroupKey sortKey(*this); - std::sort(interfaces->begin(), interfaces->end(), sortKey); - std::vector<dgMiniInterface>::iterator groupStart = interfaces->begin(), groupEnd = groupStart; - do { - groupEnd++; - if (groupEnd==interfaces->end() || sortKey(*groupStart, *groupEnd) || sortKey(*groupEnd, *groupStart)) { - if (!groupStart->isFullGhost(*this)) { - std::vector<dgMiniInterface> group(groupStart, groupEnd); - if (groupStart->connections.size() == 1) { - _faceGroups.push_back (new dgGroupOfFaces (*this, group, pOrder) ); - } else { - _faceGroups.push_back (new dgGroupOfFaces (*this, group, pOrder) ); - } - } - groupStart = groupEnd; - } - } while (groupEnd != interfaces->end()) ; - delete interfaces; - buildParallelStructure(); -} - -void dgGroupOfConnections::addElement (int iElement, int iClosure) { - _elementId.push_back(iElement); - _closuresId.push_back(iClosure); -} - -dgGroupOfFaces::dgGroupOfFaces (dgGroupCollection &groups, std::vector<dgMiniInterface> &interfaces, int pOrder) -{ - dgMiniInterface &first = interfaces.front(); - size_t nconnections = first.connections.size(); - int dim = groups.getElementGroup(first.connections[0].iGroup)->getElement(first.connections[0].iElement)->getDim()-1; - _physicalTag.clear(); - if(first.physicalTag>=0) - _physicalTag = groups.getModel()->getPhysicalName(dim, first.physicalTag); - if(nconnections==1 && (_physicalTag.empty() || _physicalTag=="")) { - /*Msg::Error("boundary face without tag in the mesh"); - throw;*/ - _physicalTag = "none"; - } - for (size_t i=0; i<nconnections; i++) { - _connections.push_back (new dgGroupOfConnections(*groups.getElementGroup(first.connections[i].iGroup), *this, pOrder)); - } - for (size_t i=0; i<interfaces.size(); i++) { - dgMiniInterface &interface = interfaces[i]; - for (size_t j=0; j<nconnections; j++) - _connections[j]->addElement(interface.connections[j].iElement, interface.connections[j].iClosure); - dgMiniConnection &connection = interface.connections[0]; - MElement *el = groups.getElementGroup(connection.iGroup)->getElement(connection.iElement); - const std::vector<int> & geomClosure = el->getFunctionSpace()->getClosure(connection.iClosure); - std::vector<MVertex *> vertices; - for (int j=0; j<geomClosure.size() ; j++) - vertices.push_back( const_cast<MElement*>(el)->getVertex(geomClosure[j]) ); - switch (el->getDim()) { - case 1 : - _faces.push_back (new MPoint (vertices[0])); - break; - case 2 : - switch(vertices.size()) { - case 2 : _faces.push_back (new MLine (vertices)); break; - case 3 : _faces.push_back (new MLine3 (vertices)); break; - default : _faces.push_back (new MLineN (vertices)); break; - } - break; - case 3 : - if (interface.numVertices == 3) { - switch(vertices.size()){ - case 3 : _faces.push_back (new MTriangle (vertices)); break; - case 6 : _faces.push_back (new MTriangle6 (vertices)); break; - case 10 : _faces.push_back (new MTriangleN (vertices, 3)); break; - case 15 : _faces.push_back (new MTriangleN (vertices, 4)); break; - case 21 : _faces.push_back (new MTriangleN (vertices, 5)); break; - default : throw; - } - } else if (interface.numVertices == 4) { - switch(vertices.size()){ - case 4 : _faces.push_back (new MQuadrangle (vertices)); break; - case 8 : _faces.push_back (new MQuadrangle8 (vertices)); break; - case 9 : _faces.push_back (new MQuadrangle9 (vertices)); break; - case 16 : _faces.push_back (new MQuadrangleN (vertices, 4)); break; - case 25 : _faces.push_back (new MQuadrangleN (vertices, 5)); break; - default : throw; - } - } else { - throw; - } - break; - default : - throw; - } - } - _fsFace = _faces[0]->getFunctionSpace (pOrder); - _integration = dgGetIntegrationRule (_faces[0],pOrder); - _redistribution = new fullMatrix<double> (_fsFace->coefficients.size1(),_integration->size1()); - _collocation = new fullMatrix<double> (_integration->size1(), _fsFace->coefficients.size1()); - _detJac = new fullMatrix<double> (_integration->size1(), _faces.size()); - _interfaceSurface = new fullMatrix<double>(_faces.size(),1); - for(int i=0; i<_connections.size(); i++) { - _connections[i]->init(); - } - double f[256]; - for (int j=0;j<_integration->size1();j++) { - _fsFace->f((*_integration)(j,0), (*_integration)(j,1), (*_integration)(j,2), f); - const double weight = (*_integration)(j,3); - for (int k=0;k<_fsFace->coefficients.size1();k++){ - (*_redistribution)(k,j) = f[k] * weight; - (*_collocation)(j,k) = f[k]; - } - } - for (int i=0;i<_faces.size();i++){ - MElement *f = _faces[i]; - for (int j=0;j< _integration->size1() ; j++ ){ - double jac[3][3]; - (*_detJac)(j,i) = f->getJacobian ((*_integration)(j,0), (*_integration)(j,1), (*_integration)(j,2), jac); - (*_interfaceSurface)(i,0) += (*_integration)(j,3)*(*_detJac)(j,i); - } - } -} - -void dgGroupCollection::buildParallelStructure() -{ - // build the ghosts structure - int *nGhostElements = new int[Msg::GetCommSize()]; - int *nParentElements = new int[Msg::GetCommSize()]; - for (int i=0;i<Msg::GetCommSize();i++) { - nGhostElements[i]=0; - } - for (size_t i = 0; i< getNbGhostGroups(); i++){ - dgGroupOfElements *group = getGhostGroup(i); - nGhostElements[group->getGhostPartition()] += group->getNbElements(); - } - #ifdef HAVE_MPI - MPI_Alltoall(nGhostElements,1,MPI_INT,nParentElements,1,MPI_INT,MPI_COMM_WORLD); - #else - nParentElements[0]=nGhostElements[0]; - #endif - int *shiftSend = new int[Msg::GetCommSize()]; - int *shiftRecv = new int[Msg::GetCommSize()]; - int *curShiftSend = new int[Msg::GetCommSize()]; - int totalSend=0,totalRecv=0; - for(int i= 0; i<Msg::GetCommSize();i++){ - shiftSend[i] = (i==0 ? 0 : shiftSend[i-1]+nGhostElements[i-1]); - curShiftSend[i] = shiftSend[i]; - shiftRecv[i] = (i==0 ? 0 : shiftRecv[i-1]+nParentElements[i-1]); - totalSend += nGhostElements[i]; - totalRecv += nParentElements[i]; - } - - int *idSend = new int[totalSend]; - int *idRecv = new int[totalRecv]; - for (int i = 0; i<getNbGhostGroups(); i++){ - dgGroupOfElements *group = getGhostGroup(i); - int part = group->getGhostPartition(); - for (int j=0; j< group->getNbElements() ; j++){ - idSend[curShiftSend[part]++] = group->getElement(j)->getNum(); - } - } - #ifdef HAVE_MPI - MPI_Alltoallv(idSend,nGhostElements,shiftSend,MPI_INT,idRecv,nParentElements,shiftRecv,MPI_INT,MPI_COMM_WORLD); - #else - memcpy(idRecv,idSend,nParentElements[0]*sizeof(int)); - #endif - //create a Map elementNum :: group, position in group - std::map<int, std::pair<int,int> > elementMap; - for(size_t i = 0; i< getNbElementGroups(); i++) { - dgGroupOfElements *group = getElementGroup(i); - for(int j=0; j< group->getNbElements(); j++){ - elementMap[group->getElement(j)->getNum()]=std::pair<int,int>(i,j); - } - } - _elementsToSend.resize(Msg::GetCommSize()); - for(int i = 0; i<Msg::GetCommSize();i++){ - _elementsToSend[i].resize(nParentElements[i]); - for(int j=0;j<nParentElements[i];j++){ - int num = idRecv[shiftRecv[i]+j]; - _elementsToSend[i][j]=elementMap[num]; - } - } - delete []idRecv; - delete []idSend; - delete []curShiftSend; - delete []shiftSend; - delete []shiftRecv; -} - -// Split the groups of elements depending on their local time step -double dgGroupCollection::splitGroupsForMultirate(int maxLevels,int innerBufferSize,int outerBufferSize,dgConservationLaw *claw, dgDofContainer *solution) { - // What are the levels/layers: - // bulk: elements that are time stepped using the "normal" 4 stage Runge-Kutta - // innerBuffer: elements that use the small time step but talks to elements using the big time step - // outerBuffer: elements that use the big time step but talks to elements using the small time step - - - Msg::Info("Splitting Groups for multirate time stepping"); - maxLevels--;// Number becomes maximum id - - // Interfaces are not built yet, so we use a "mini" structure to deduce neighboring information - std::vector<dgMiniInterface> *miniInterfaceV=_createMiniInterfaces(*this); - // elementToNeighbors[oldGroupId][oldElementId][neighborId (i.e. 0 to 2 for triangles)]<neighborOldGroupId,neighborOldElementId> - std::vector<std::vector<std::vector<std::pair<int,int> > > >elementToNeighbors; - // id of the new group, indexed by [oldGroupId][oldElementId] - // -1 if the element is not yet in a new group - // -2 if the element is in a new group whose id is not determined yet - std::vector<std::vector<int> >newGroupIds; - std::vector< dgGroupOfElements* >newGroups;// indexed by newGroupId - // localDt[oldGroupId][oldElementId] - std::vector<std::vector<double> >localDt; - - - std::vector<int>oldGroupIds; - - newGroupIds.resize(getNbElementGroups()); - elementToNeighbors.resize(getNbElementGroups()); - for(int iGroup=0;iGroup<getNbElementGroups();iGroup++){ - dgGroupOfElements *g=getElementGroup(iGroup); - elementToNeighbors[iGroup].resize(g->getNbElements()); - newGroupIds[iGroup].assign(g->getNbElements(),-1); - } - - // Build elementToNeighbors table (needed to have random access to the neighbors) - for(int iInterface=0;iInterface<miniInterfaceV->size();iInterface++){ - dgMiniInterface &interface=miniInterfaceV->at(iInterface); - for(int iConn=0;iConn<interface.connections.size();iConn++){ - int gIdi=interface.connections[iConn].iGroup; - int eIdi=interface.connections[iConn].iElement; - for(int jConn=0;jConn<iConn;jConn++){ - int gIdj=interface.connections[jConn].iGroup; - int eIdj=interface.connections[jConn].iElement; - elementToNeighbors[gIdi][eIdi].push_back(std::pair<int,int>(gIdj,eIdj)); - elementToNeighbors[gIdj][eIdj].push_back(std::pair<int,int>(gIdi,eIdi)); - } - } - } - - // Compute the time step constrain per element - double dtMin = DBL_MAX; - double dtMax = 0; - localDt.resize(getNbElementGroups()); - for (int i=0;i<getNbElementGroups();i++){ - dgAlgorithm::computeElementaryTimeSteps(*claw, *getElementGroup(i), solution->getGroupProxy(i), localDt[i]); - for (int k=0;k<localDt[i].size();k++){ - dtMin = std::min(dtMin,localDt[i][k]); - dtMax = std::max(dtMax,localDt[i][k]); - } - } -#ifdef HAVE_MPI - double dtMin_min; - MPI_Allreduce((void *)&dtMin, &dtMin_min, 1, MPI_DOUBLE, MPI_MIN, MPI_COMM_WORLD); - dtMin=dtMin_min; - double dtMax_max; - MPI_Allreduce((void *)&dtMax, &dtMax_max, 1, MPI_DOUBLE, MPI_MAX, MPI_COMM_WORLD); - dtMax=dtMax_max; -#endif - - Msg::Info("Time step for standard RK should be %e",dtMin); - Msg::Info("Multirate base time step should be %e",dtMax); - - - - // We take the base time step as 80% of the largest elementary time-step. - // This is arbitrary and should be optimized (maybe on the fly...) - double dtRef=dtMax*0.8; - - // time steps are dtRef*2^(-dtExponent), with dtExponent ranging in [0:dtMaxExponent] - int dtMaxExponent=0; - while(dtRef/pow(2.0,(double)dtMaxExponent)>dtMin) - dtMaxExponent++; - if(dtMaxExponent>maxLevels){ - dtRef*=1.0/pow(2.0,(double)(dtMaxExponent-maxLevels)); - dtMaxExponent=maxLevels; - } - _dtMaxExponent=dtMaxExponent; - - - // Bounds to be able to access elements at the previous level (to add the neighbors in the current group) - int lowerLevelGroupIdStart=-1; - int lowerLevelGroupIdEnd=-1; - - bool isOuterBufferLayer=false; - int currentNewGroupId=0; - int loopId=0; - - // We pass two times by each exponent level: one for the normal(bulk) + innerBuffer groups, and one for the outerBuffer groups - for(int currentExponent=dtMaxExponent;currentExponent>=0;(!isOuterBufferLayer)?currentExponent--:currentExponent=currentExponent){ - int currentBufferSize=isOuterBufferLayer?outerBufferSize:innerBufferSize; - double currentDt=dtRef/pow(2.0,(double)currentExponent); - // element for the new groups at this level: - // mapNewGroups[oldGroupId][oldElementId] - std::map<int,std::vector<int> >mapNewGroups; - if(lowerLevelGroupIdStart==-1){ - lowerLevelGroupIdStart=0; - } - else{ - // Add the neighbors elements to the new groups - // For buffer AND non buffer layers - lowerLevelGroupIdStart=lowerLevelGroupIdEnd; - // We add bufferSize elements (most of the time, bufferSize=1 is enough) - for(int iLoop=0;iLoop<currentBufferSize;iLoop++){ - for(int iInterface=0;iInterface<miniInterfaceV->size();iInterface++){ - dgMiniInterface &interface=miniInterfaceV->at(iInterface); - bool toAdd=false; - // if one of the elements adjacent to the interface is mapped to the previous level - // we check all elements adjacent to this interface, and add those that does not - // already have a new group to the current new group - for(int iConn=0;iConn<interface.connections.size();iConn++){ - int gId=interface.connections[iConn].iGroup; - int eId=interface.connections[iConn].iElement; - int newGroupId=newGroupIds[gId][eId]; - if(newGroupId>=0 || ( newGroupId>-2-iLoop && newGroupId<-1) ){ - toAdd=true; - continue; - } - } - if(toAdd){ - for(int iConn=0;iConn<interface.connections.size();iConn++){ - int gId=interface.connections[iConn].iGroup; - int eId=interface.connections[iConn].iElement; - int newGroupId=newGroupIds[gId][eId]; - if(newGroupId==-1){ - mapNewGroups[gId].push_back(eId); - newGroupIds[gId][eId]=-2-iLoop; - } - } - } - } - } - } - if(!isOuterBufferLayer){ - // We add all the elements that are stable with the current time step, but not with twice that time step - for(int iGroup=0;iGroup<getNbElementGroups();iGroup++){ - dgGroupOfElements *elGroup=getElementGroup(iGroup); - for(int iElement=0;iElement<elGroup->getNbElements();iElement++){ - if(localDt[iGroup][iElement]>=currentDt && (localDt[iGroup][iElement]<currentDt*2 || currentExponent==0)){ - if(newGroupIds[iGroup][iElement]==-1){ - mapNewGroups[iGroup].push_back(iElement); - newGroupIds[iGroup][iElement]=-2; - } - } - } - } - - // We split those elements into bulk and innerBuffer (i.e. those who have a neighbor with a bigger time step) - lowerLevelGroupIdStart=currentNewGroupId; - -#define MAXBUFFERSIZE 100000 - if(currentExponent>0){ - for(int iLoop=0;iLoop<currentBufferSize;iLoop++){ - for (std::map<int, std::vector<int> >::iterator it = mapNewGroups.begin(); it !=mapNewGroups.end() ; ++it){ - for(int i=0;i<it->second.size();i++){ - bool inInnerBuffer=false; - int oldGId=it->first; - int oldEId=it->second[i]; - // We only consider elements in the map and not in the inner buffer for a different iLoop - if(newGroupIds[oldGId][oldEId]>-2 || newGroupIds[oldGId][oldEId]<-(MAXBUFFERSIZE-1) ) - continue; - for(int iNeighbor=0;iNeighbor<elementToNeighbors[oldGId][oldEId].size();iNeighbor++){ - std::pair<int,int> neighIds=elementToNeighbors[oldGId][oldEId][iNeighbor]; - if(newGroupIds[neighIds.first][neighIds.second]==-1-iLoop*MAXBUFFERSIZE){ - inInnerBuffer=true; - continue; - } - } - if(inInnerBuffer){ - newGroupIds[oldGId][oldEId]=-1-(iLoop+1)*MAXBUFFERSIZE; - } - } - } - } - } - - for (std::map<int, std::vector<int> >::iterator it = mapNewGroups.begin(); it !=mapNewGroups.end() ; ++it){ - if(!it->second.empty()){ - std::vector<int>forBulk; - std::vector<int>forInnerBuffer; - for(int i=0;i<it->second.size();i++){ - int oldGId=it->first; - int oldEId=it->second[i]; - if( newGroupIds[oldGId][oldEId]>-2 || newGroupIds[oldGId][oldEId]<-(MAXBUFFERSIZE-1) ){ - forInnerBuffer.push_back(oldEId); - } - else{ - forBulk.push_back(oldEId); - } - } - for(int i=0;i<forBulk.size();i++){ - newGroupIds[it->first][forBulk[i]]=currentNewGroupId; - } - dgGroupOfElements *oldGroup=getElementGroup(it->first); - dgGroupOfElements *newGroup; - if(!forBulk.empty()){ - std::vector<MElement*>forBulkV; - for(int i=0;i<forBulk.size();i++){ - forBulkV.push_back(getElementGroup(it->first)->getElement(forBulk[i])); - } - oldGroupIds.resize(currentNewGroupId+1); - oldGroupIds[currentNewGroupId]=it->first; - newGroup=new dgGroupOfElements(forBulkV,oldGroup->getOrder(),oldGroup->getGhostPartition()); - newGroup->copyPrivateDataFrom(oldGroup); - #ifdef TEST - if(currentExponent==0){ - newGroup->_multirateExponent=currentExponent+1; - newGroup->_multirateOuterBuffer=true; - newGroup->_multirateInnerBuffer=false; - } - else{ - newGroup->_multirateExponent=currentExponent; - newGroup->_multirateOuterBuffer=false; - newGroup->_multirateInnerBuffer=true; - } - #else - newGroup->_multirateExponent=currentExponent; - newGroup->_multirateOuterBuffer=false; - newGroup->_multirateInnerBuffer=false; - #endif - newGroups.resize(currentNewGroupId+1); - newGroups[currentNewGroupId]=newGroup; - currentNewGroupId++; - } - - for(int i=0;i<forInnerBuffer.size();i++){ - newGroupIds[it->first][forInnerBuffer[i]]=currentNewGroupId; - } - if(!forInnerBuffer.empty()){ - std::vector<MElement*>forInnerBufferV; - for(int i=0;i<forInnerBuffer.size();i++){ - forInnerBufferV.push_back(getElementGroup(it->first)->getElement(forInnerBuffer[i])); - } - oldGroupIds.resize(currentNewGroupId+1); - oldGroupIds[currentNewGroupId]=it->first; - newGroup=new dgGroupOfElements(forInnerBufferV,oldGroup->getOrder(),oldGroup->getGhostPartition()); - newGroup->copyPrivateDataFrom(oldGroup); - newGroup->_multirateExponent=currentExponent; - newGroup->_multirateOuterBuffer=false; - newGroup->_multirateInnerBuffer=true; - newGroups.resize(currentNewGroupId+1); - newGroups[currentNewGroupId]=newGroup; - currentNewGroupId++; - } - } - else - Msg::Info("Empty Group !!!!!!!!!!!!!!!!!!"); - } - } - else{ - for (std::map<int, std::vector<int> >::iterator it = mapNewGroups.begin(); it !=mapNewGroups.end() ; ++it){ - if(!it->second.empty()){ - for(int i=0;i<it->second.size();i++){ - int oldGId=it->first; - int oldEId=it->second[i]; - newGroupIds[oldGId][oldEId]=currentNewGroupId; - } - dgGroupOfElements *oldGroup=getElementGroup(it->first); - std::vector<MElement *>newGroupV; - for(int i=0;i<it->second.size();i++){ - newGroupV.push_back(getElementGroup(it->first)->getElement(it->second[i])); - } - oldGroupIds.resize(currentNewGroupId+1); - oldGroupIds[currentNewGroupId]=it->first; - dgGroupOfElements *newGroup=new dgGroupOfElements(newGroupV,oldGroup->getOrder(),oldGroup->getGhostPartition()); - newGroup->copyPrivateDataFrom(oldGroup); - newGroup->_multirateExponent=currentExponent; - newGroup->_multirateOuterBuffer=true; - newGroup->_multirateInnerBuffer=false; - newGroups.resize(currentNewGroupId+1); - newGroups[currentNewGroupId]=newGroup; - currentNewGroupId++; - } - else - Msg::Info("Empty Group !!!!!!!!!!!!!!!!!!"); - } - } - lowerLevelGroupIdEnd=currentNewGroupId; - isOuterBufferLayer=!isOuterBufferLayer; - } - // Some stats - int count=0; - for(int i=0;i<newGroups.size();i++){ - Msg::Info("Old group #%d, exponent %d, New group #%d has %d elements",oldGroupIds[i],newGroups[i]->getMultirateExponent(),i,newGroups[i]->getNbElements()); - if(newGroups[i]->getIsInnerMultirateBuffer()) - Msg::Info("InnerBuffer"); - else if(newGroups[i]->getIsOuterMultirateBuffer()) - Msg::Info("OuterBuffer"); - else - Msg::Info("Not Buffer"); - count+=newGroups[i]->getNbElements(); - } - Msg::Info("That makes a total of %d elements",count); - _elementGroups.clear(); - _elementGroups=newGroups; - delete miniInterfaceV; - return dtRef; -} - -// Split the groups of elements into vertical layers (only for primsatic 3D meshes) -void dgGroupCollection::splitGroupsByVerticalLayer(std::vector<std::string> topLevelTags) { - - Msg::Info("Splitting Groups per vertical layers"); - - // Interfaces are not built yet, so we use a "mini" structure to deduce neighboring information - std::vector<dgMiniInterface> *miniInterfaceV=_createMiniInterfaces(*this); - // elementToNeighbors[oldGroupId][oldElementId][neighborId (i.e. 0 to 2 for triangles)]<neighborOldGroupId,neighborOldElementId> - std::vector<std::vector<std::vector<std::pair<int,int> > > >elementToNeighbors; - // id of the new group, indexed by [oldGroupId][oldElementId] - // -1 if the element is not yet in a new group - // -2 if the element is in a new group whose id is not determined yet - std::vector< dgGroupOfElements* >newGroups;// indexed by newGroupId - // isProcessed[oldGroupId][oldElementId] - std::vector<std::vector<int> >isProcessed; - - isProcessed.resize(getNbElementGroups()); - elementToNeighbors.resize(getNbElementGroups()); - for(int iGroup=0;iGroup<getNbElementGroups();iGroup++){ - dgGroupOfElements *g=getElementGroup(iGroup); - elementToNeighbors[iGroup].resize(g->getNbElements()); - isProcessed[iGroup].assign(g->getNbElements(),0); - } - - // Build elementToNeighbors table (needed to have random access to the neighbors) - for(int iInterface=0;iInterface<miniInterfaceV->size();iInterface++){ - dgMiniInterface &interface=miniInterfaceV->at(iInterface); - if (interface.numVertices == 3) { // only accept triangular interfaces - for(int iConn=0;iConn<interface.connections.size();iConn++){ - int gIdi=interface.connections[iConn].iGroup; - int eIdi=interface.connections[iConn].iElement; - for(int jConn=0;jConn<iConn;jConn++){ - int gIdj=interface.connections[jConn].iGroup; - int eIdj=interface.connections[jConn].iElement; - elementToNeighbors[gIdi][eIdi].push_back(std::pair<int,int>(gIdj,eIdj)); - elementToNeighbors[gIdj][eIdj].push_back(std::pair<int,int>(gIdi,eIdi)); - } - } - } - } - - std::vector< std::pair<int,int> > oldGroupElemIds; - std::vector< std::pair<int,int> > newGroupElemIds; - std::vector< std::vector< MElement* > > verticalGroupsVector; - std::vector< MElement* > newGroupElems; - int currentNewGroupId=0; - bool finalLayer = false; - - do { - newGroupElemIds.clear(); - newGroupElems.clear(); - if(currentNewGroupId==0) { - // create first element groups - for(int iInterface=0;iInterface<miniInterfaceV->size();iInterface++){ - dgMiniInterface &interface=miniInterfaceV->at(iInterface); - for(int iConn=0;iConn<interface.connections.size();iConn++){ - int gId=interface.connections[iConn].iGroup; - int eId=interface.connections[iConn].iElement; - bool topLevelTagFound = false; - for (int i = 0; i < topLevelTags.size(); i++) - if (_model->getPhysicalName(2, interface.physicalTag) == topLevelTags.at(i) ) { - topLevelTagFound = true; - break; - } - if (topLevelTagFound) { -// printf("Tag found: %d %d %s \n",gId,eId,_model->getPhysicalName(2, interface.physicalTag).c_str()); - newGroupElems.push_back(getElementGroup(gId)->getElement(eId)); - newGroupElemIds.push_back(std::pair<int,int>(gId,eId)); - isProcessed[gId][eId]=1; - } - } - } - if (newGroupElems.size() == 0) { - std::string errMsg = "No triangular boundary faces found with the given physical tag(s): "; - for (int i = 0; i < topLevelTags.size(); i++) - errMsg += topLevelTags.at(i) += " "; - Msg::Error(errMsg.c_str()); - } - } - else { - // find neighbors in next level - for (int iElems = 0; iElems<oldGroupElemIds.size();iElems++ ) { - int gId = oldGroupElemIds.at(iElems).first; - int eId = oldGroupElemIds.at(iElems).second; - bool newNeighborFound = false; - for (int iNeighbors = 0; iNeighbors < elementToNeighbors[gId][eId].size(); iNeighbors++) { - int nGId = elementToNeighbors[gId][eId].at(iNeighbors).first; - int nEId = elementToNeighbors[gId][eId].at(iNeighbors).second; - if (!isProcessed[nGId][nEId]) { - newGroupElemIds.push_back(std::pair<int,int>(nGId,nEId)); - newGroupElems.push_back(getElementGroup(nGId)->getElement(nEId)); - isProcessed[nGId][nEId]=1; - newNeighborFound = true; -// printf("adding neighbor eId: %d\n",nEId); - } - } - if (!newNeighborFound) { - finalLayer = true; - break; - } - } - } - - -// printf("new elems %d\n",newGroupElems.size()); - if (!finalLayer) { - dgGroupOfElements* oldGroup = getElementGroup(0); - dgGroupOfElements* newGroup=new dgGroupOfElements(newGroupElems,oldGroup->getOrder(),oldGroup->getGhostPartition()); - newGroup->copyPrivateDataFrom(oldGroup); - newGroups.resize(currentNewGroupId+1); - newGroups[currentNewGroupId]=newGroup; - printf("Created a new group ID:%d with %d elements.\n",currentNewGroupId,newGroup->getNbElements()); - currentNewGroupId++; - } - oldGroupElemIds = newGroupElemIds; - } while (!finalLayer); - - _elementGroups.clear(); - _elementGroups=newGroups; - delete miniInterfaceV; - -} - -dgGroupCollection::dgGroupCollection() -{ - _groupsOfElementsBuilt=false;_groupsOfInterfacesBuilt=false; -} - -dgGroupCollection::dgGroupCollection(GModel *model, int dimension, int order) -{ - _groupsOfElementsBuilt=false;_groupsOfInterfacesBuilt=false; - buildGroupsOfElements(model,dimension,order, NULL); -} - -dgGroupCollection::dgGroupCollection(GModel *model, int dimension, int order, std::vector<std::string>* physicalTags) -{ - _groupsOfElementsBuilt=false;_groupsOfInterfacesBuilt=false; - buildGroupsOfElements(model,dimension,order,physicalTags); -} - -dgGroupCollection* dgGroupCollection::newByTag(GModel *model, int dimension, int order, std::vector<std::string> tags){ - Msg::Info("Creating %dD groupCollection by tags.",dimension); - dgGroupCollection* subCollection = new dgGroupCollection(model,dimension,order,&tags); - if (subCollection->getNbElementGroups()==0) - Msg::Warning("groupCollection is empty."); - return subCollection; -} - -dgGroupCollection::~dgGroupCollection() -{ - for (int i=0; i< _elementGroups.size(); i++) - delete _elementGroups[i]; - for (int i=0; i< _faceGroups.size(); i++) - delete _faceGroups[i]; - for (int i=0; i< _ghostGroups.size(); i++) - delete _ghostGroups[i]; -} - -void dgGroupCollection::find (MElement*e, int &ig, int &index) -{ - for (ig=0;ig<_elementGroups.size();ig++) { - index = _elementGroups[ig]->getIndexOfElement(e); - if (index != -1)return; - } -} - -#include "LuaBindings.h" -void dgGroupCollection::registerBindings(binding *b) -{ - classBinding *cb; - methodBinding *cm; - cb = b->addClass<dgGroupOfElements>("dgGroupOfElements"); - cb->setDescription("a group of element sharing the same properties"); - cm = cb->addMethod("getNbElements",&dgGroupOfElements::getNbElements); - cm->setDescription("return the number of elements in the group"); - cb = b->addClass<dgGroupOfFaces>("dgGroupOfFaces"); - cb->setDescription("a group of faces. All faces of this group are either interior of the same group of elements or at the boundary between two group of elements"); - cb = b->addClass<dgGroupCollection>("dgGroupCollection"); - cb->setDescription("The GroupCollection class let you access to group partitioning functions"); - cm = cb->setConstructor<dgGroupCollection,GModel*,int,int>(); - cm->setDescription("Build the group of elements, separated by element type and element order. Additional partitioning can be done using splitGroupsForXXX specific functions"); - cm->setArgNames("model","dimension","order",NULL); - cm = cb->addMethod("buildGroupsOfInterfaces",&dgGroupCollection::buildGroupsOfInterfaces); - cm->setDescription("Build the group of interfaces, i.e. boundary interfaces and inter-element interfaces"); - cm = cb->addMethod("splitGroupsForMultirate",&dgGroupCollection::splitGroupsForMultirate); - cm->setDescription("Split the groups according to their own stable time step"); - cm->setArgNames("maxLevels","innerBufferSize","outerBufferSize","claw","solution",NULL); - cm = cb->addMethod("splitGroupsByVerticalLayer",&dgGroupCollection::splitGroupsByVerticalLayer); - cm->setDescription("Split the groups according vertical layer structure. The first is defined by the topLevelTags."); - cm->setArgNames("topLevelTags",NULL); - cm = cb->addMethod("newByTag",&dgGroupCollection::newByTag); - cm->setDescription("Creates a group collection of elements associated with given physical tag(s)."); - cm->setArgNames("model","dimension","order","tags",NULL); - cm = cb->addMethod("getNbElementGroups", &dgGroupCollection::getNbElementGroups); - cm->setDescription("return the number of dgGroupOfElements"); - cm = cb->addMethod("getNbFaceGroups", &dgGroupCollection::getNbFaceGroups); - cm->setDescription("return the number of dgGroupOfFaces (interior ones, not the domain boundaries)"); - cm = cb->addMethod("getElementGroup", &dgGroupCollection::getElementGroup); - cm->setDescription("get 1 group of elements"); - cm->setArgNames("id", NULL); - cm = cb->addMethod("getFaceGroup", &dgGroupCollection::getFaceGroup); - cm->setDescription("get 1 group of faces"); - cm->setArgNames("id", NULL); -} diff --git a/Solver/dgGroupOfElements.h b/Solver/dgGroupOfElements.h deleted file mode 100644 index 58c08665b76bf416d2a334205f42d22f19b5176e..0000000000000000000000000000000000000000 --- a/Solver/dgGroupOfElements.h +++ /dev/null @@ -1,262 +0,0 @@ -#ifndef _DG_GROUP_OF_ELEMENTS_ -#define _DG_GROUP_OF_ELEMENTS_ - -#include <vector> -#include "fullMatrix.h" -/* - A group of element contains N elements - that are of the same type and of the - same order. All element have the same - number of integration points Np, the same - number of vertices Nv. - - we DO NOT store N, Ni or Nv (matrices and vectors - have the right sizes) -*/ -#include "MFace.h" -#include "MEdge.h" -class MElement; -class polynomialBasis; -class GEntity; -class GModel; - -class binding; -class dgConservationLaw; -class dgDofContainer; - - -class dgMiniInterface; -class dgGroupCollection; -class dgElement { - MElement *_element; - // solution at points - const fullMatrix<double> &_solution, &_integration, &_gradients; -public: - dgElement (MElement *e, const fullMatrix<double> &sol, const fullMatrix<double> &integ) - : _element(e), _solution(sol), _integration(integ), _gradients(sol) - {} - dgElement (MElement *e, const fullMatrix<double> &sol, const fullMatrix<double> &grads, const fullMatrix<double> &integ) - : _element(e), _solution(sol), _integration(integ), _gradients(grads) - {} - const fullMatrix<double> &solution() const { return _solution; } - const fullMatrix<double> &integration() const { return _integration; } - MElement *element() const { return _element;} -}; - -class dgGroupOfFaces; - -// store topological and geometrical data for 1 group for 1 discretisation -class dgGroupOfElements { - int _ghostPartition; // -1 : this is not a ghosted group, otherwise the id of the parent partition - - // N elements in the group - std::vector<MElement*> _elements; - // inverse map that gives the index of an element in the group - std::map<MElement*,int> element_to_index; - // the ONLY function space that is used to - // inerpolated the fields (may be different to the - // one of the elements) - const polynomialBasis &_fs; - // Ni integration points, matrix of size Ni x 4 (u,v,w,weight) - fullMatrix<double> *_integration; - // collocation matrix that maps vertices to integration points. - fullMatrix<double> *_collocation; - // inverse of the mapping and det mapping (00 01 02 10 11 12 20 21 22 det) - fullMatrix<double> *_mapping; - // redistribution of the fluxes to vertices multiplied by - // the gradient of shape functions (in parametric space) - // for both diffusive and convective fluxes - fullMatrix<double> *_redistributionFluxes[3]; - // redistribution of the jacobian of fluxes to vertices - // fullMatrix<double> *_redistributionJacobianOfFluxes[3]; - // redistribution for the source term - fullMatrix<double> *_redistributionSource; - // inverse mass matrix of all elements - fullMatrix<double> *_imass; - // - fullMatrix<double> *_dPsiDx; - //redistributions of the convective jacobian diumUVW*nbIntegrationPoints x nbNodes*nbNodes - fullMatrix<double> _PsiDPsiDXi; - //reditribution of the diffusive jacobian dimUVW*dimUVW*nbIntegrationPoints x nbNodes*nbNodes - fullMatrix<double> _dPsiDXDPsiDXi; - // dimension of the parametric space and of the real space - // may be different if the domain is a surface in 3D (manifold) - int _dimUVW, _dimXYZ; - // polynomial order of the interpolation - int _order; - // - // volume/surface/length of the element (sum_qp w_i detJ_i) - fullMatrix<double> *_elementVolume; - // inradius of the element, i.e. a lengthscale to compute the timestep - fullMatrix<double> *_innerRadii; - // forbid the copy - // dgGroupOfElements (const dgGroupOfElements &e, int order) {} - // dgGroupOfElements & operator = (const dgGroupOfElements &e) {} -protected: - int _multirateExponent; - bool _multirateInnerBuffer; - bool _multirateOuterBuffer; -public: - inline int getMultirateExponent() const {return _multirateExponent;} - inline int getIsInnerMultirateBuffer() const {return _multirateInnerBuffer;} - inline int getIsOuterMultirateBuffer() const {return _multirateOuterBuffer;} - inline int getIsMultirateBuffer()const {return _multirateInnerBuffer || _multirateOuterBuffer;} - dgGroupOfElements (const std::vector<MElement*> &e, int pOrder,int ghostPartition=-1); - virtual ~dgGroupOfElements (); - inline int getNbElements() const {return _elements.size();} - inline int getNbNodes() const {return _collocation->size2();} - inline int getNbIntegrationPoints() const {return _collocation->size1();} - inline int getDimUVW () const {return _dimUVW;} - inline int getDimXYZ () const {return _dimXYZ;} - inline MElement* getElement (int iElement) const {return _elements[iElement];} - inline const polynomialBasis & getFunctionSpace () const {return _fs;} - inline const fullMatrix<double> & getIntegrationPointsMatrix () const {return *_integration;} - inline const fullMatrix<double> & getCollocationMatrix () const {return *_collocation;} - inline const fullMatrix<double> & getFluxRedistributionMatrix (int i) const {return *_redistributionFluxes[i];} - // inline const fullMatrix<double> & getJacobianOfFluxRedistributionMatrix (int i) const {return *_redistributionJacobianOfFluxes[i];} - inline const fullMatrix<double> & getSourceRedistributionMatrix () const {return *_redistributionSource;} - inline const fullMatrix<double> & getDPsiDXDPsiDXi() const {return _dPsiDXDPsiDXi;} - inline const fullMatrix<double> & getPsiDPsiDXi() const {return _PsiDPsiDXi;} - inline double getElementVolume (int iElement)const {return (*_elementVolume)(iElement,0);} - inline double getInnerRadius(int iElement)const {return (*_innerRadii)(iElement,0);} - inline double getDetJ (int iElement, int iGaussPoint) const {return (*_mapping)(iElement, 10*iGaussPoint + 9);} - inline double getInvJ (int iElement, int iGaussPoint, int i, int j) const {return (*_mapping)(iElement, 10*iGaussPoint + i + 3*j);} - inline fullMatrix<double> & getDPsiDx() const { return *_dPsiDx;} - inline fullMatrix<double> &getInverseMassMatrix () const {return *_imass;} - inline const fullMatrix<double> getMapping (int iElement) const {return fullMatrix<double>(*_mapping, iElement, 1);} - inline int getOrder() const {return _order;} - inline int getGhostPartition() const {return _ghostPartition;} - void copyPrivateDataFrom(const dgGroupOfElements *from); - inline int getIndexOfElement (MElement *e) const { - std::map<MElement*,int>::const_iterator it = element_to_index.find(e); - if (it == element_to_index.end())return -1; - return it->second; - } - friend class dgGroupCollection; -}; - -class dgGroupOfFaces; - -class dgGroupOfConnections { - // there is a finite number of combinations of orientations, senses - // and rotations of the faces (typically 24 for tets). Any pair - // is characterized by a single integer which is the combination - // this closure is for the interpolation that MAY BE DIFFERENT THAN THE - // GEOMETRICAL CLOSURE !!! - std::vector<std::vector<int> > _closures; - std::vector<int> _closuresId; - // face integration point in the coordinate of the left and right element (one fullMatrix per closure) - std::vector<fullMatrix<double> > _integrationPoints; - // XYZ gradient of the shape functions of both elements on the integrations points of the face - // (iQP*3+iXYZ , iFace*NPsi+iPsi) - fullMatrix<double> _dPsiDx; - const polynomialBasis *_fs; - const dgGroupOfElements &_elementGroup; - const dgGroupOfFaces &_faceGroup; - std::vector<int>_elementId; - // normals at integration points (N*Ni) x 3 - fullMatrix<double> _normals; - public: - void addElement(int iElement, int iClosure); - dgGroupOfConnections(const dgGroupOfElements &elementGroup, const dgGroupOfFaces &face, int pOrder); - inline const polynomialBasis *getFunctionSpace() const {return _fs;} - inline const dgGroupOfElements &getGroupOfElements() const {return _elementGroup;} - inline int getElementId(int i) const {return _elementId[i];} - inline MElement *getElement(int i) const {return _elementGroup.getElement(_elementId[i]);} - inline const std::vector<int>& getClosure(int i) const {return _closures[_closuresId[i]];} - inline const fullMatrix<double>& getIntegrationPointsOnElement(int i) const {return _integrationPoints[_closuresId[i]];} - inline const fullMatrix<double>& getDPsiDx() const {return _dPsiDx;} - inline const fullMatrix<double>& getNormals() const {return _normals;} - void init(); -}; - -class dgGroupOfFaces { - std::vector<dgGroupOfConnections*> _connections; - // normals always point outside left to right - // only used if this is a group of boundary faces - std::string _physicalTag; - // Two polynomialBases for left and right elements - // the group has always the same types for left and right - const polynomialBasis *_fsFace; - // N elements in the group - std::vector<MElement *>_faces; - // Ni integration points, matrix of size Ni x 3 (u,v,weight) - fullMatrix<double> *_integration; - // detJac at integration points (N*Ni) x 1 - fullMatrix<double> *_detJac; - // collocation matrices \psi_i (GP_j) - fullMatrix<double> *_collocation; - //fullMatrix<double> *_collocationLeft, *_collocationRight; - // redistribution matrices \psi_i (GP_j) * weight_j - fullMatrix<double> *_redistribution; - // surface/length/1 of the interface element (sum_qp w_i detJ_i) - fullMatrix<double> *_interfaceSurface; -public: - dgGroupOfFaces (dgGroupCollection &groups, std::vector<dgMiniInterface> &interfaces, int pOrder); - virtual ~dgGroupOfFaces (); - inline const std::string getPhysicalTag() const {return _physicalTag;} - inline const dgGroupOfConnections &getGroupOfConnections(int i) const {return *_connections[i];} - inline int getNbGroupOfConnections() const {return _connections.size();} - //this part is common with dgGroupOfElements, we should try polymorphism - inline int getNbElements() const {return _faces.size();} - inline int getNbNodes() const {return _collocation->size2();} - inline int getNbIntegrationPoints() const {return _collocation->size1();} - inline const fullMatrix<double> & getCollocationMatrix () const {return *_collocation;} - inline const fullMatrix<double> & getIntegrationPointsMatrix () const {return *_integration;} - inline const fullMatrix<double> & getRedistributionMatrix () const {return *_redistribution;} - inline double getDetJ (int iElement, int iGaussPoint) const {return (*_detJac)(iGaussPoint,iElement);} - inline double getInterfaceSurface (int iFace)const {return (*_interfaceSurface)(iFace,0);} - const polynomialBasis * getPolynomialBasis() const {return _fsFace;} - inline MElement* getFace (int iElement) const {return _faces[iElement];} -public: // should be more generic on the number of connections - void mapToInterface (int nFields, std::vector<const fullMatrix<double> *> &proxies, fullMatrix<double> &v); - void mapFromInterface (int nFields, const fullMatrix<double> &v, std::vector<fullMatrix<double> *> &proxies); - void mapLeftFromInterface(int nFields, const fullMatrix<double> &v, fullMatrix<double> &vLeft); - void mapRightFromInterface(int nFields, const fullMatrix<double> &v, fullMatrix<double> &vRight); -}; - -class dgGroupCollection { - GModel *_model; - std::vector<dgGroupOfElements*> _elementGroups; //volume - std::vector<dgGroupOfFaces*> _faceGroups; //interface - std::vector<dgGroupOfElements*> _ghostGroups; //ghost volume - - //{group,id} of the elements to send to each partition for a scatter operation - std::vector< std::vector<std::pair<int,int> > >_elementsToSend; - bool _groupsOfElementsBuilt; - bool _groupsOfInterfacesBuilt; - - // Multirate stuff - int _dtMaxExponent; - - void buildParallelStructure(); - public: - inline int getDtMaxExponent() const {return _dtMaxExponent;} - inline GModel* getModel() {return _model;} - inline int getNbElementGroups() const {return _elementGroups.size();} - inline int getNbFaceGroups() const {return _faceGroups.size();} - inline int getNbGhostGroups() const {return _ghostGroups.size();} - inline dgGroupOfElements *getElementGroup(int i) const {return i<getNbElementGroups()?_elementGroups[i]:_ghostGroups[i-getNbElementGroups()];} - inline dgGroupOfFaces *getFaceGroup(int i) const {return _faceGroups[i];} - inline dgGroupOfElements *getGhostGroup(int i) const {return _ghostGroups[i];} - - inline int getNbImageElementsOnPartition(int partId) const {return _elementsToSend[partId].size();} - inline int getImageElementGroup(int partId, int i) const {return _elementsToSend[partId][i].first;} - inline int getImageElementPositionInGroup(int partId, int i) const {return _elementsToSend[partId][i].second;} - - void buildGroupsOfElements (GModel *model,int dimension, int order, std::vector<std::string>* physicalTags); - void buildGroupsOfInterfaces (); - - double splitGroupsForMultirate(int maxLevels,int innerBufferSize,int outerBufferSize,dgConservationLaw *claw, dgDofContainer *solution); - void splitGroupsByVerticalLayer(std::vector<std::string> topLevelTags); - - void find (MElement *elementToFind, int &iGroup, int &ithElementOfGroup); - - dgGroupCollection(GModel *model, int dimension, int order); - dgGroupCollection(GModel *model, int dimension, int order, std::vector<std::string>* physicalTags); - dgGroupCollection(); - static dgGroupCollection* newByTag(GModel* model, int dimension, int order, std::vector<std::string> tags); - static void registerBindings(binding *b); - ~dgGroupCollection(); -}; -#endif diff --git a/Solver/dgLimiter.cpp b/Solver/dgLimiter.cpp deleted file mode 100644 index 8d4bba90ed13231df12667eade34953278bc7950..0000000000000000000000000000000000000000 --- a/Solver/dgLimiter.cpp +++ /dev/null @@ -1,149 +0,0 @@ -#include "dgLimiter.h" -#include "dgGroupOfElements.h" -#include "dgSystemOfEquations.h" -#include "function.h" - -//---------------------------------------------------------------------------------- -int dgSlopeLimiter::apply ( dgDofContainer *solution) -{ - dgGroupCollection *groups=solution->getGroups(); - solution->scatter(); - int nbFields =_claw->getNbFields(); - - // first compute max and min of all fields for all stencils - //---------------------------------------------------------- - dgDofContainer MIN(groups, nbFields); - dgDofContainer MAX(groups, nbFields); - - MIN.setAll ( 1.e22); - MAX.setAll (-1.e22); - - int iElementL, iElementR, fSize; - fullMatrix<double> TempL, TempR; - for( int iGFace=0; iGFace<groups->getNbFaceGroups(); iGFace++) { - dgGroupOfFaces* group = groups->getFaceGroup(iGFace); - if (group->getNbGroupOfConnections()!=2) // skip boundaries and bifurcations - continue; - const dgGroupOfConnections &left = group->getGroupOfConnections(0); - const dgGroupOfConnections &right = group->getGroupOfConnections(1); - const dgGroupOfElements *groupLeft = &left.getGroupOfElements(); - const dgGroupOfElements *groupRight = &right.getGroupOfElements(); - - fullMatrix<double> &solleft = solution->getGroupProxy(groupLeft); - fullMatrix<double> &solright = solution->getGroupProxy(groupRight); - fullMatrix<double> &MINLeft = MIN.getGroupProxy(groupLeft); - fullMatrix<double> &MAXLeft = MAX.getGroupProxy(groupLeft); - fullMatrix<double> &MINRight = MIN.getGroupProxy(groupRight); - fullMatrix<double> &MAXRight = MAX.getGroupProxy(groupRight); - - for(int iFace=0 ; iFace<group->getNbElements();iFace++) { - - iElementL = left.getElementId(iFace); - iElementR = right.getElementId(iFace); - - TempL.setAsProxy(solleft, nbFields*iElementL, nbFields ); - TempR.setAsProxy(solright, nbFields*iElementR, nbFields ); - - fSize = TempL.size1(); - for (int k=0; k< nbFields; ++k){ - double AVGL = 0; - double AVGR = 0; - for (int i=0; i<fSize; ++i) { - AVGL += TempL(i,k); - AVGR += TempR(i,k); - } - AVGL /= (double) fSize; - AVGR /= (double) fSize; - MINLeft (0, iElementL*nbFields+k ) = std::min ( AVGR , MINLeft (0, iElementL*nbFields+k ) ); - MAXLeft (0, iElementL*nbFields+k) = std::max ( AVGR , MAXLeft (0, iElementL*nbFields+k ) ); - MINRight (0, iElementR*nbFields+k) = std::min ( AVGL , MINRight (0, iElementR*nbFields+k ) ); - MAXRight (0, iElementR*nbFields+k) = std::max ( AVGL , MAXRight (0, iElementR*nbFields+k ) ); - } - - } - } - - //---------------------------------------------------------- - // then limit the solution - //---------------------------------------------------------- - - for (int iGroup=0 ; iGroup<groups->getNbElementGroups() ; iGroup++) { - dgGroupOfElements &group = *groups->getElementGroup(iGroup); - fullMatrix<double> &sol = solution->getGroupProxy(iGroup); - fullMatrix<double> &MAXG = MAX.getGroupProxy(iGroup); - fullMatrix<double> &MING = MIN.getGroupProxy(iGroup); - fullMatrix<double> Temp; - for (int iElement=0 ; iElement<group.getNbElements() ; ++iElement) { - Temp.setAsProxy(sol, nbFields*iElement, nbFields ); - for (int k=0; k<nbFields; ++k) - { - double AVG = 0.; - double locMax = -1.e22; - double locMin = 1.e22; - double neighMax = MAXG (0, iElement*nbFields+k); - double neighMin = MING (0, iElement*nbFields+k); - for (int i=0; i<fSize; ++i) - { - AVG += Temp(i,k); - locMax = std::max (locMax, Temp (i,k)); - locMin = std::min (locMin, Temp (i,k)); - } - AVG /= (double) fSize; - - //SLOPE LIMITING DG - //------------------- - for (int i=0; i<fSize; ++i)Temp(i,k) -= AVG; - - double slopeLimiterValue = 1.0; - if (locMax != AVG && locMax > neighMax) slopeLimiterValue = (neighMax-AVG) / (locMax-AVG); - if (locMin != AVG && locMin < neighMin) slopeLimiterValue = std::min ( slopeLimiterValue , (AVG-neighMin) / (AVG-locMin) ); - if (AVG < neighMin) slopeLimiterValue = 0; - if (AVG > neighMax) slopeLimiterValue = 0; - - // if (slopeLimiterValue != 1.0) printf("LIMTING %g\n",slopeLimiterValue); - // slopeLimiterValue = 0.0; - - for (int i=0; i<fSize; ++i) Temp(i,k) = AVG + Temp(i,k)*slopeLimiterValue; - } - } - } - // --- CLIPPING: check unphysical values - for (int iG = 0; iG < groups->getNbElementGroups(); iG++){ - dgGroupOfElements* egroup = groups->getElementGroup(iG); - fullMatrix<double> &solGroup = solution->getGroupProxy(iG); - - dataCacheMap cacheMap; - cacheMap.setNbEvaluationPoints(egroup->getNbNodes());//nbdofs for each element - dataCacheDouble &solutionE = cacheMap.get(function::getSolution(), NULL); - dataCacheDouble *solutionEClipped = _claw->newClipToPhysics(cacheMap); - if (solutionEClipped){ - for (int iElement=0 ; iElement<egroup->getNbElements() ;++iElement) { - solutionE.set().setAsProxy(solGroup, iElement*nbFields, nbFields ); - solutionE.set()=(*solutionEClipped)(); - } - } - } - return 1; -} - -#include "Bindings.h" - -void dgLimiter::registerBindings(binding *b) { - classBinding *cb = b->addClass<dgLimiter>("dgLimiter"); - cb->setDescription("Parent class for limiters"); - methodBinding *cm; - cm = cb->addMethod("apply",&dgLimiter::apply); - cm->setArgNames("solution",NULL); - cm->setDescription("apply the limiter on the solution"); -} - -void dgSlopeLimiterRegisterBindings(binding *b) { - classBinding *cb = b->addClass<dgSlopeLimiter>("dgSlopeLimiter"); - cb->setDescription("The usual DG slope limiter: keep the mean, reduces uniformly the slope until it does not overshoot the neighbors' mean"); - methodBinding *cm; - cm = cb->setConstructor<dgSlopeLimiter,dgConservationLaw *>(); - cm->setDescription("A new explicit slope limiter"); - cm->setArgNames("law",NULL); - cb->setParentClass<dgLimiter>(); -} - diff --git a/Solver/dgLimiter.h b/Solver/dgLimiter.h deleted file mode 100644 index d654c286ae1f666a196c97a14e5cef71c204a143..0000000000000000000000000000000000000000 --- a/Solver/dgLimiter.h +++ /dev/null @@ -1,27 +0,0 @@ -#ifndef _DG_LIMITER_H_ -#define _DG_LIMITER_H_ - -#include "fullMatrix.h" -#include <vector> -class dgDofContainer; -class dgGroupCollection; -class dgConservationLaw; -class binding; - -class dgLimiter{ -protected: - dgConservationLaw *_claw; -public: - dgLimiter (dgConservationLaw *claw) : _claw(claw) {} - virtual int apply ( dgDofContainer *sol)=0; - static void registerBindings(binding *b); -}; - -class dgSlopeLimiter : public dgLimiter{ -public : - dgSlopeLimiter (dgConservationLaw *claw) : dgLimiter (claw) {} - virtual int apply ( dgDofContainer *solution); -}; -void dgSlopeLimiterRegisterBindings(binding *b); - -#endif diff --git a/Solver/dgMesh2MeshProjection.cpp b/Solver/dgMesh2MeshProjection.cpp deleted file mode 100644 index 97146a6ecb8d50223b1f4d651b3de12543cec9c9..0000000000000000000000000000000000000000 --- a/Solver/dgMesh2MeshProjection.cpp +++ /dev/null @@ -1,289 +0,0 @@ -#include "dgMesh2MeshProjection.h" -#include "MElementOctree.h" -#include "Octree.h" - -dgMesh2MeshProjection::dgMesh2MeshProjection() -{ - _projectionMatrixIsBuilt = false; - _projectionMatrix = new linearSystemCSRGmm<double>; - _numInDofs = _numOutDofs = _inMaxDim = _outMaxDim = 0; - _inDofPattern = _outDofPattern = NULL; - _useDofContainerOctree = true; - _octree = NULL; -} - -dgMesh2MeshProjection::dgMesh2MeshProjection(dgDofContainer* donor, dgDofContainer* receiver) -{ - _projectionMatrixIsBuilt = false; - _projectionMatrix = new linearSystemCSRGmm<double>; - _numInDofs = _numOutDofs = 0; - _inDofPattern = _outDofPattern = NULL; - _useDofContainerOctree = true; - _octree = NULL; - _buildProjectionMatrix(donor,receiver); -} - -dgMesh2MeshProjection::dofStoragePattern::dofStoragePattern(dgDofContainer* dofContainer) -{ - _nbGroups = dofContainer->getGroups()->getNbElementGroups(); - _nbFields = dofContainer->getNbFields(); - _nbElems.resize(_nbGroups); - _nbNodes.resize(_nbGroups); - _groupFirstProjectionDofId.resize(_nbGroups); - - int offset = 0; - for (int i = 0; i < _nbGroups; i++) { - int nbElems = dofContainer->getGroups()->getElementGroup(i)->getNbElements(); - int nbNodes = dofContainer->getGroups()->getElementGroup(i)->getNbNodes(); - _nbElems[i] = nbElems; - _nbNodes[i] = nbNodes; - _groupFirstProjectionDofId[i] = offset; - offset += nbElems*nbNodes; - } - _nbProjDofs = offset; -} - -bool dgMesh2MeshProjection::dofStoragePattern::operator==(const dgMesh2MeshProjection::dofStoragePattern& other) const -{ - if(this->_nbGroups != other._nbGroups) - return false; - for (int i =0; i<this->_nbGroups; i++) { - if(this->_nbElems[i] != other._nbElems[i]) - return false; - if(this->_nbNodes[i] != other._nbNodes[i]) - return false; - } - return true; -} - -bool dgMesh2MeshProjection::_checkTranspose(dgDofContainer* donor, dgDofContainer* receiver) -{ - // check if transpose is necessary - dofStoragePattern* dDofPattern = new dofStoragePattern(donor); - dofStoragePattern* rDofPattern = new dofStoragePattern(receiver); - bool transpose; - if (*dDofPattern == *_inDofPattern && *rDofPattern == *_outDofPattern) - transpose = false; - else if (*dDofPattern == *_outDofPattern && *rDofPattern == *_inDofPattern) - transpose = true; - else - Msg::Fatal("the DOF storage patterns do not match the projection matrix."); - return transpose; -} - -void dgMesh2MeshProjection::projectFromTo(dgDofContainer* donor, dgDofContainer* receiver) -{ - if(!_projectionMatrixIsBuilt) - _buildProjectionMatrix(donor,receiver); - _applyProjection(donor,receiver,_checkTranspose(donor,receiver),0); -} - -void dgMesh2MeshProjection::copyFromTo(dgDofContainer* donor, dgDofContainer* receiver) -{ - if(!_projectionMatrixIsBuilt) - _buildProjectionMatrix(donor,receiver); - _applyProjection(donor,receiver,_checkTranspose(donor,receiver),1); -} - - -void dgMesh2MeshProjection::_buildReceiverOctree(dgDofContainer* receiver) -{ - std::vector<MElement*> allElements; - for (int i = 0; i < receiver->getGroups()->getNbElementGroups(); i++ ) { - dgGroupOfElements* group = receiver->getGroups()->getElementGroup(i); - for (int iElem = 0; iElem < group->getNbElements(); iElem++ ) { - allElements.push_back(group->getElement(iElem)); - } - } - _octree = buildMElementOctree(allElements); -} - -MElement* dgMesh2MeshProjection::_getReceiverElementByCoord(SPoint3 point) -{ - if (!_octree) - Msg::Fatal("MElement Octree is not built"); - double P[3] = {point.x(), point.y(), point.z()}; - return (MElement*)Octree_Search(P, _octree); -} - -void dgMesh2MeshProjection::_buildProjectionMatrix(dgDofContainer* donor, dgDofContainer* receiver) -{ - _inDofPattern = new dofStoragePattern(donor); - _outDofPattern = new dofStoragePattern(receiver); - _inMaxDim = donor->getGroups()->getElementGroup(0)->getDimUVW(); // not necessary max... - _outMaxDim = receiver->getGroups()->getElementGroup(0)->getDimUVW(); - dgGroupCollection* dGroups = donor->getGroups(); - dgGroupCollection* rGroups = receiver->getGroups(); - if (_outMaxDim == 2, receiver->getGroups()->getModel()->getDim() == 3) { - // need to find 2D elements in 3D geometry, build special octree - _useDofContainerOctree = false; - _buildReceiverOctree(receiver); - } - if (_outMaxDim > _inMaxDim) - Msg::Fatal("Cannot build projection matrix from lower dim to higher dim. Swap donor and receiver."); - - int jProj = 0; // indices in projection matrix - int totalNbOutDofs = 0; - for (int i = 0; i<rGroups->getNbElementGroups(); i++) - totalNbOutDofs += rGroups->getElementGroup(i)->getNbElements()*rGroups->getElementGroup(i)->getNbNodes(); - _projectionMatrix->allocate(totalNbOutDofs); - - // integration over donor function space - for (int jGroup=0;jGroup<dGroups->getNbElementGroups();jGroup++) {// for donor groups - const dgGroupOfElements &dGroup = *dGroups->getElementGroup(jGroup); - fullMatrix<double> iPtsMatrix = dGroup.getIntegrationPointsMatrix(); - for (int jElement=0 ; jElement<dGroup.getNbElements() ;++jElement) {// for elements - double rShapeFun[256]; - double dShapeFun[256]; - GModel *rModel = rGroups->getModel(); - GModel *dModel = dGroups->getModel(); - MElement* dElem = dGroup.getElement(jElement); - for (int iPt =0; iPt< iPtsMatrix.size1(); iPt++) { - double x=0,y=0,z=0; - dElem->getFunctionSpace()->f(iPtsMatrix(iPt,0),iPtsMatrix(iPt,1),iPtsMatrix(iPt,2),dShapeFun); - for (int iVer=0; iVer < dElem->getNumVertices(); iVer++) { - x += dElem->getVertex(iVer)->x()*dShapeFun[iVer]; - y += dElem->getVertex(iVer)->y()*dShapeFun[iVer]; - z += dElem->getVertex(iVer)->z()*dShapeFun[iVer]; - } - if (_inMaxDim==3 && _outMaxDim == 2) { - z = 0; // dummy projection to 2d mesh - } - // find p in receiver mesh - SPoint3 p(x,y,z); - MElement *rElem; - if (_useDofContainerOctree) - rElem = rGroups->getModel()->getMeshElementByCoord(p); - else - rElem = _getReceiverElementByCoord(p); - - int iGroup,iElement; - rGroups->find(rElem,iGroup,iElement); - if (iElement == -1) - Msg::Fatal("Integration point (%g,%g,%g) not found in receiver mesh",p.x(),p.y(),p.z()); - const dgGroupOfElements &rGroup = *rGroups->getElementGroup(iGroup); - double U[3],X[3]={x,y,z}; - rElem->xyz2uvw(X,U); - dGroup.getFunctionSpace().f(iPtsMatrix(iPt,0),iPtsMatrix(iPt,1),iPtsMatrix(iPt,2),dShapeFun); - rGroup.getFunctionSpace().f(U[0],U[1],U[2],rShapeFun); - const double detJ = dGroup.getDetJ (jElement, iPt); - int iProj = _outDofPattern->getProjDofId(iGroup,iElement,0); - for (int jNode=0;jNode<dGroup.getNbNodes();jNode++){ - for (int iNode=0;iNode<rGroup.getNbNodes();iNode++){ - double val = rShapeFun[iNode]*dShapeFun[jNode]*iPtsMatrix(iPt,3)*detJ; - _projectionMatrix->addToMatrix(iProj+iNode,jProj+jNode,val); - } - } - } - jProj += dGroup.getNbNodes(); - } - } - _multiplyByInverseMassMatrix(receiver); - _projectionMatrixIsBuilt = true; -} - -// could be improved by using a better matrix representation and an efficient M*P routine -void dgMesh2MeshProjection::_multiplyByInverseMassMatrix(dgDofContainer* donor) -{ - dgGroupCollection* rGroups = donor->getGroups(); - int *startIndex; - int *columns; - double *values; - _projectionMatrix->getMatrix(startIndex,columns,values); - - int iProj = 0; - for (int iGroup=0;iGroup<rGroups->getNbElementGroups();iGroup++) { - const dgGroupOfElements &rGroup = *rGroups->getElementGroup(iGroup); - for (int iElement=0 ; iElement<rGroup.getNbElements() ;++iElement) { - fullMatrix<double> buffer = fullMatrix<double> (rGroup.getNbNodes(),startIndex[iProj+1]-startIndex[iProj]); - fullMatrix<double> buffer2 = fullMatrix<double> (rGroup.getNbNodes(),startIndex[iProj+1]-startIndex[iProj]); - fullMatrix<double> iMassEl; - for (int iNode = 0 ; iNode<rGroup.getNbNodes() ;++iNode) { - for (int i = startIndex[iProj+iNode]; i < startIndex[iProj+iNode+1] ; i++) - buffer(iNode,i-startIndex[iProj+iNode]) = values[i]; - } - iMassEl.setAsProxy(rGroup.getInverseMassMatrix(),iElement*rGroup.getNbNodes(),rGroup.getNbNodes()); - buffer2.gemm(iMassEl,buffer); - for (int iNode = 0 ; iNode<rGroup.getNbNodes() ;++iNode) { - for (int i = startIndex[iProj+iNode]; i < startIndex[iProj+iNode+1] ; i++) - values[i] = buffer2(iNode,i-startIndex[iProj+iNode]); - } - iProj+=rGroup.getNbNodes(); - } - } -} - -// could be improved by using a better matrix representation and an efficient M*V routine -void dgMesh2MeshProjection::_applyProjection(dgDofContainer* donor, dgDofContainer* receiver, bool transpose, bool copy) -{ - dgDofContainer* dDof = donor; - dgDofContainer* rDof = receiver; - if (transpose) { - rDof = donor; - dDof = receiver; - } - receiver->setAll(0); - - dgGroupCollection* dGroups = dDof->getGroups(); - dgGroupCollection* rGroups = rDof->getGroups(); - std::vector<int> dGroupsStartIGlobal(dGroups->getNbElementGroups() + 1); - int iProj = 0; // indices in projection matrix - dGroupsStartIGlobal[0] = 0; - for (int i = 1; i<dGroupsStartIGlobal.size(); i++) - dGroupsStartIGlobal[i] = dGroupsStartIGlobal[i-1] + dGroups->getElementGroup(i-1)->getNbElements()*dGroups->getElementGroup(i-1)->getNbNodes(); - - int *startIndex; - int *columns; - double *values; - _projectionMatrix->getMatrix(startIndex,columns,values); - - int nbFields = receiver->getNbFields(); - if (nbFields != donor->getNbFields()) - Msg::Fatal("Number of fields in donor and receiver dofContainer must match (for now)"); - // full dofContainer data -// fullVector<double>& rVector = receiver->getVector(); -// fullVector<double>& dVector = donor->getVector(); - - for (int iGroup=0;iGroup<rGroups->getNbElementGroups();iGroup++) { - const dgGroupOfElements &rGroup = *rGroups->getElementGroup(iGroup); - for (int iElement=0 ; iElement<rGroup.getNbElements() ;++iElement) { - for (int iNode = 0 ; iNode<rGroup.getNbNodes() ;++iNode) { - int jGroup = 0; - for (int i = startIndex[iProj++]; i < startIndex[iProj] ; i++){ - int jProj = columns[i]; - while (jProj > dGroupsStartIGlobal[jGroup+1]) { - jGroup++; - } - int jElement = (jProj-dGroupsStartIGlobal[jGroup])/dGroups->getElementGroup(jGroup)->getNbNodes(); - int jNode = jProj-dGroupsStartIGlobal[jGroup]-jElement*dGroups->getElementGroup(jGroup)->getNbNodes(); - for (int m = 0; m < nbFields; m++){ - double val = values[i]; - if (copy) val = (fabs(values[i]) > 1e-8) ? 1 : 0; - if (transpose) - receiver->getGroupProxy(jGroup)(jNode,jElement*nbFields+m) += val*donor->getGroupProxy(iGroup)(iNode,iElement*nbFields+m); -// rVector(jProj) += val*donor->getGroupProxy(iGroup)(iNode,iElement*nbFields+m); // only for one field - else - receiver->getGroupProxy(iGroup)(iNode,iElement*nbFields+m) += val*donor->getGroupProxy(jGroup)(jNode,jElement*nbFields+m); -// receiver->getGroupProxy(iGroup)(iNode,iElement*nbFields+m) += val*dVector(jProj); // only for one field - } - } - } - } - } -} - -#include "LuaBindings.h" -void dgMesh2MeshProjection::registerBindings(binding *b){ - classBinding *cb = b->addClass<dgMesh2MeshProjection>("dgMesh2MeshProjection"); - cb->setDescription("The dgMesh2MeshProjection class provides methods for projecting fields from one mesh on another."); - methodBinding *cm; - cm = cb->setConstructor<dgMesh2MeshProjection,dgDofContainer*,dgDofContainer*>(); - cm->setDescription("Build a projection instance between two dgDofContainers. Integration is performend in the donor Dof function space."); - cm->setArgNames("donorDof","receiverDof",NULL); - cm = cb->addMethod("projectFromTo",&dgMesh2MeshProjection::projectFromTo); - cm->setDescription("Projects all the fields in one container to the other"); - cm->setArgNames("fromContainer","toContainer",NULL); - cm = cb->addMethod("copyFromTo",&dgMesh2MeshProjection::copyFromTo); - cm->setDescription("Copies all the fields on one container to the other (projection with binary projection matrix)"); - cm->setArgNames("fromContainer","toContainer",NULL); -} diff --git a/Solver/dgMesh2MeshProjection.h b/Solver/dgMesh2MeshProjection.h deleted file mode 100644 index 925ec53c219134777c1eeed3331c1a78495559aa..0000000000000000000000000000000000000000 --- a/Solver/dgMesh2MeshProjection.h +++ /dev/null @@ -1,60 +0,0 @@ -#ifndef _DG_MESH2MESH_PROJECTION_H_ -#define _DG_MESH2MESH_PROJECTION_H_ -#include "GmshConfig.h" -#include "dgDofContainer.h" -// #include "function.h" -#include "dgGroupOfElements.h" -// #include "dgConservationLaw.h" -// #include "dgAlgorithm.h" -#include "GModel.h" -#ifdef HAVE_MPI -#include "mpi.h" -#else -#include "string.h" -#endif -// #include <sstream> -#include "MElement.h" -// #include <benchmarks/misc/stipple.pos> - -// TODO: better representation of matrices, faster matrix-vector matrix-matrix products -// projecting 3D integration points to 2D plane, instead of assuming z=0 -// possibility to use spesific integration rules -class dgMesh2MeshProjection { -public: class dofStoragePattern; -private: - bool _projectionMatrixIsBuilt, _useDofContainerOctree; - Octree* _octree; - int _numInDofs, _numOutDofs, _inMaxDim, _outMaxDim; - dofStoragePattern* _inDofPattern; - dofStoragePattern* _outDofPattern; - linearSystemCSRGmm<double>* _projectionMatrix; - void _buildProjectionMatrix(dgDofContainer* donor, dgDofContainer* receiver); - void _multiplyByInverseMassMatrix(dgDofContainer* donor); - void _applyProjection(dgDofContainer* donor, dgDofContainer* receiver, bool transpose, bool copy); - bool _checkTranspose(dgDofContainer* donor,dgDofContainer* receiver); - void _buildReceiverOctree(dgDofContainer* receiver); - MElement* _getReceiverElementByCoord(SPoint3 point); -public: - // Contains the number of groups, elements and nodes to check if DOF containers are mutually compatible - class dofStoragePattern { - private: - int _nbGroups, _nbFields, _nbProjDofs; - std::vector<int> _nbElems, _nbNodes, _groupFirstProjectionDofId; - public: - dofStoragePattern(dgDofContainer* dofContainer); - bool operator == (const dofStoragePattern& other) const; - // indices needed when accessing the projection matrix - inline int getProjDofId (int groupId, int elementId, int nodeId) const { - // this is different from dgDofContainer::getDofId() because nbFields is ignored - return _groupFirstProjectionDofId[groupId]+elementId*_nbNodes[groupId]+nodeId; - } - }; - dgMesh2MeshProjection(); - dgMesh2MeshProjection(dgDofContainer* donor,dgDofContainer* receiver); - void setIntegrationRule(); - void projectFromTo(dgDofContainer* donor,dgDofContainer* receiver); - void copyFromTo(dgDofContainer* donor,dgDofContainer* receiver); - static void registerBindings(binding *b); -}; - -#endif diff --git a/Solver/dgResidual.cpp b/Solver/dgResidual.cpp deleted file mode 100644 index 36bc083ecadab9981e073234f89d6950c36db382..0000000000000000000000000000000000000000 --- a/Solver/dgResidual.cpp +++ /dev/null @@ -1,463 +0,0 @@ -#include "dgResidual.h" -#include "dgConservationLaw.h" -#include "dgGroupOfElements.h" -#include "function.h" -#include "functionDerivator.h" -#include "dgDofContainer.h" -#include "MElement.h" - -dgResidualVolume::dgResidualVolume(const dgConservationLaw &claw): - _cacheMap(new dataCacheMap), - _claw(claw), - _nbFields(_claw.getNbFields()), - _UVW(_cacheMap->get(function::getParametricCoordinates(), NULL)), - _solutionQPe(_cacheMap->get(function::getSolution(), NULL)), - _gradientSolutionQPe(_cacheMap->get(function::getSolutionGradient(),NULL)), - _sourceTerm(_claw.newSourceTerm(*_cacheMap)), - _convectiveFlux(_claw.newConvectiveFlux(*_cacheMap)), - _diffusiveFlux(_claw.newDiffusiveFlux(*_cacheMap)) -{ -} - -dgResidualVolume::~dgResidualVolume() -{ - delete _cacheMap; -} - -void dgResidualVolume::compute1Group(dgGroupOfElements &group, fullMatrix<double> &solution, fullMatrix<double> &residual) -{ - residual.scale(0); - _cacheMap->setNbEvaluationPoints(group.getNbIntegrationPoints()); - _UVW.set()=group.getIntegrationPointsMatrix(); - // ----- 1 ---- get the solution at quadrature points - // ----- 1.1 --- allocate a matrix of size (nbFields * nbElements, nbQuadraturePoints) - fullMatrix<double> solutionQP (group.getNbIntegrationPoints(),group.getNbElements() * _nbFields); - // ----- 1.2 --- multiply the solution by the collocation matrix - group.getCollocationMatrix().mult(solution , solutionQP); - // ----- 2 ---- compute all fluxes (diffusive and convective) at integration points - // ----- 2.1 --- allocate elementary fluxes (compued in XYZ coordinates) - fullMatrix<double> fConv[3] = {fullMatrix<double>( group.getNbIntegrationPoints(), _nbFields ), - fullMatrix<double>( group.getNbIntegrationPoints(), _nbFields ), - fullMatrix<double>( group.getNbIntegrationPoints(), _nbFields )}; - fullMatrix<double> fDiff[3] = {fullMatrix<double>( group.getNbIntegrationPoints(), _nbFields ), - fullMatrix<double>( group.getNbIntegrationPoints(), _nbFields ), - fullMatrix<double>( group.getNbIntegrationPoints(), _nbFields )}; - fullMatrix<double> Source = fullMatrix<double> (group.getNbIntegrationPoints(),group.getNbElements() * _nbFields); - // ----- 2.2 --- allocate parametric fluxes (computed in UVW coordinates) for all elements at all integration points - fullMatrix<double> Fuvw[3] = {fullMatrix<double> ( group.getNbIntegrationPoints(), group.getNbElements() * _nbFields), - fullMatrix<double> (group.getNbIntegrationPoints(), group.getNbElements() * _nbFields), - fullMatrix<double> (group.getNbIntegrationPoints(), group.getNbElements() * _nbFields)}; - fullMatrix<double> fuvwe; - fullMatrix<double> source; - fullMatrix<double> dPsiDx,dofs, gradSolProxy; - _gradientSolutionQPe.set().resize(group.getNbIntegrationPoints(),3*_nbFields); - // ----- 2.3 --- iterate on elements - for (int iElement=0 ; iElement<group.getNbElements() ;++iElement) { - // ----- 2.3.1 --- build a small object that contains elementary solution, jacobians, gmsh element - _cacheMap->setElement(group.getElement(iElement)); - _solutionQPe.set().setAsProxy(solutionQP, iElement*_nbFields, _nbFields ); - if(_gradientSolutionQPe.somethingDependOnMe()){ - dPsiDx.setAsProxy(group.getDPsiDx(),iElement*group.getNbNodes(),group.getNbNodes()); - dofs.setAsProxy(solution, _nbFields*iElement, _nbFields); - gradSolProxy.setAsShapeProxy(_gradientSolutionQPe.set(),group.getNbIntegrationPoints()*3, _nbFields); - dPsiDx.mult(dofs, gradSolProxy); - } - if(_convectiveFlux || _diffusiveFlux) { - // ----- 2.3.3 --- compute fluxes in UVW coordinates - for (int iUVW=0;iUVW<group.getDimUVW();iUVW++) { - // ----- 2.3.3.1 --- get a proxy on the big local flux matrix - fuvwe.setAsProxy(Fuvw[iUVW], iElement*_nbFields,_nbFields); - // ----- 2.3.3.1 --- compute \vec{f}^{UVW} =\vec{f}^{XYZ} J^{-1} and multiply bt detJ - for (int iXYZ=0;iXYZ<group.getDimXYZ();iXYZ++) { - for (int iPt =0; iPt< group.getNbIntegrationPoints(); iPt++) { - // get the right inv jacobian matrix dU/dX element - const double invJ = group.getInvJ (iElement, iPt, iUVW, iXYZ); - // get the detJ at this point - const double detJ = group.getDetJ (iElement, iPt); - const double factor = invJ * detJ; - // compute fluxes in the reference coordinate system at this integration point - for (int k=0;k<_nbFields;k++){ - if(_convectiveFlux) - fuvwe(iPt,k) += ( (*_convectiveFlux)(iPt,iXYZ*_nbFields+k)) * factor; - if(_diffusiveFlux){ - fuvwe(iPt,k) += ( (*_diffusiveFlux)(iPt,iXYZ*_nbFields+k)) * factor; - } - } - } - } - } - } - if (_sourceTerm){ - source.setAsProxy(Source, iElement*_nbFields,_nbFields); - for (int iPt =0; iPt< group.getNbIntegrationPoints(); iPt++) { - const double detJ = group.getDetJ (iElement, iPt); - for (int k=0;k<_nbFields;k++){ - source(iPt,k) = (*_sourceTerm)(iPt,k)*detJ; - } - } - } - } - // ----- 3 ---- do the redistribution at nodes using as many BLAS3 operations as there are local coordinates - if(_convectiveFlux || _diffusiveFlux){ - for (int iUVW=0;iUVW<group.getDimUVW();iUVW++){ - residual.gemm(group.getFluxRedistributionMatrix(iUVW),Fuvw[iUVW]); - } - } - if(_sourceTerm){ - residual.gemm(group.getSourceRedistributionMatrix(),Source); - } -} - -void dgResidualVolume::compute1GroupWithJacobian(dgGroupOfElements &group, fullMatrix<double> &solution, fullMatrix<double> &residual, fullMatrix<double> &jacobian) -{ - residual.scale(0); - _cacheMap->setNbEvaluationPoints(group.getNbIntegrationPoints()); - _UVW.set()=group.getIntegrationPointsMatrix(); - // ----- 1 ---- get the solution at quadrature points - // ----- 1.1 --- allocate a matrix of size (nbFields * nbElements, nbQuadraturePoints) - fullMatrix<double> solutionQP (group.getNbIntegrationPoints(),group.getNbElements() * _nbFields); - // ----- 1.2 --- multiply the solution by the collocation matrix - group.getCollocationMatrix().mult(solution , solutionQP); - // ----- 2 ---- compute all fluxes (diffusive and convective) at integration points - // ----- 2.1 --- allocate elementary fluxes (compued in XYZ coordinates) - fullMatrix<double> fConv[3] = {fullMatrix<double>( group.getNbIntegrationPoints(), _nbFields ), - fullMatrix<double>( group.getNbIntegrationPoints(), _nbFields ), - fullMatrix<double>( group.getNbIntegrationPoints(), _nbFields )}; - fullMatrix<double> fDiff[3] = {fullMatrix<double>( group.getNbIntegrationPoints(), _nbFields ), - fullMatrix<double>( group.getNbIntegrationPoints(), _nbFields ), - fullMatrix<double>( group.getNbIntegrationPoints(), _nbFields )}; - fullMatrix<double> Source = fullMatrix<double> (group.getNbIntegrationPoints(),group.getNbElements() * _nbFields); - // ----- 2.2 --- allocate parametric fluxes (computed in UVW coordinates) for all elements at all integration points - fullMatrix<double> Fuvw[3] = {fullMatrix<double> ( group.getNbIntegrationPoints(), group.getNbElements() * _nbFields), - fullMatrix<double> (group.getNbIntegrationPoints(), group.getNbElements() * _nbFields), - fullMatrix<double> (group.getNbIntegrationPoints(), group.getNbElements() * _nbFields)}; - fullMatrix<double> fuvwe; - fullMatrix<double> source; - fullMatrix<double> dPsiDx, dofs, gradSolProxy; - fullMatrix<double> A (group.getDimUVW()*group.getNbIntegrationPoints(), _nbFields*_nbFields*group.getNbElements()); - fullMatrix<double> B (group.getDimUVW()*group.getDimUVW()*group.getNbIntegrationPoints(), _nbFields*_nbFields*group.getNbElements()); - fullMatrix<double> a, b; - functionDerivator *dDiffusiveFluxdGradU,*dConvectiveFluxdU; - if(_diffusiveFlux) - dDiffusiveFluxdGradU=new functionDerivator(*_diffusiveFlux,_gradientSolutionQPe,1e-6); - if(_convectiveFlux) - dConvectiveFluxdU=new functionDerivator(*_convectiveFlux,_solutionQPe,1e-6); - // ----- 2.3 --- iterate on elements - for (int iElement=0 ; iElement<group.getNbElements() ;++iElement) { - // ----- 2.3.1 --- build a small object that contains elementary solution, jacobians, gmsh element - _solutionQPe.set().setAsProxy(solutionQP, iElement*_nbFields, _nbFields ); - a.setAsProxy(A, iElement*_nbFields*_nbFields, _nbFields*_nbFields); - b.setAsProxy(B, iElement*_nbFields*_nbFields, _nbFields*_nbFields); - - if(_gradientSolutionQPe.somethingDependOnMe()){ - dPsiDx.setAsProxy(group.getDPsiDx(),iElement*group.getNbNodes(),group.getNbNodes()); - dofs.setAsProxy(solution, _nbFields*iElement, _nbFields); - gradSolProxy.setAsShapeProxy(_gradientSolutionQPe.set(),group.getNbIntegrationPoints()*3, _nbFields); - dPsiDx.mult(dofs, gradSolProxy); - } - _cacheMap->setElement(group.getElement(iElement)); - if(_convectiveFlux || _diffusiveFlux) { - // ----- 2.3.3 --- compute fluxes in UVW coordinates - for (int iUVW=0;iUVW<group.getDimUVW();iUVW++) { - // ----- 2.3.3.1 --- get a proxy on the big local flux matrix - fuvwe.setAsProxy(Fuvw[iUVW], iElement*_nbFields,_nbFields); - // ----- 2.3.3.1 --- compute \vec{f}^{UVW} =\vec{f}^{XYZ} J^{-1} and multiply bt detJ - for (int iXYZ=0;iXYZ<group.getDimXYZ();iXYZ++) { - for (int iPt =0; iPt< group.getNbIntegrationPoints(); iPt++) { - // get the right inv jacobian matrix dU/dX element - const double invJ = group.getInvJ (iElement, iPt, iUVW, iXYZ); - // get the detJ at this point - const double detJ = group.getDetJ (iElement, iPt); - const double factor = invJ * detJ; - // compute fluxes in the reference coordinate system at this integration point - for (int k=0;k<_nbFields;k++){ - if(_convectiveFlux) - fuvwe(iPt,k) += ( (*_convectiveFlux)(iPt,iXYZ*_nbFields+k)) * factor; - if(_diffusiveFlux){ - fuvwe(iPt,k) += ( (*_diffusiveFlux)(iPt,iXYZ*_nbFields+k)) * factor; - } - } - } - } - } - } - if (_sourceTerm){ - source.setAsProxy(Source, iElement*_nbFields,_nbFields); - for (int iPt =0; iPt< group.getNbIntegrationPoints(); iPt++) { - const double detJ = group.getDetJ (iElement, iPt); - for (int k=0;k<_nbFields;k++){ - source(iPt,k) = (*_sourceTerm)(iPt,k)*detJ; - } - } - } - int nQP = group.getNbIntegrationPoints(); - int dimUVW = group.getDimUVW(); - int dimXYZ = group.getDimXYZ(); - b.scale(0); - if(_diffusiveFlux) { - dDiffusiveFluxdGradU->compute(); - for (int alpha=0; alpha < dimUVW; alpha++) for (int beta=0; beta < dimUVW; beta++) { - for(int x=0;x <dimXYZ;x++) for(int y=0;y <dimXYZ;y++) { - for (int xi=0; xi <group.getNbIntegrationPoints(); xi++) { - const double invJx = group.getInvJ (iElement, xi, alpha, x); - const double invJy = group.getInvJ (iElement, xi, beta, y); - const double detJ = group.getDetJ (iElement, xi); - const double factor = invJx * invJy * detJ; - for (int k=0; k< _nbFields; k++) for (int l=0; l<_nbFields; l++) { - b((alpha*dimUVW+beta)*nQP+xi,k*_nbFields+l) += dDiffusiveFluxdGradU->get(xi, k*dimXYZ+x, l*dimXYZ+y)*factor; - } - } - } - } - } - /*if(_convectiveFlux) { - dConvectiveFluxdU->compute(); - for (int alpha=0; alpha < dim; alpha++) { - for(int x=0;x <group.getDimXYZ();x++) { - for (int xi=0; xi <group.getNbIntegrationPoints(); xi++){ - const double invJ = group.getInvJ (iElement, xi, alpha, x); - const double detJ = group.getDetJ (iElement, xi); - const double factor = invJ * detJ; - for (int k=0; k< _nbFields; k++) for (int l=0; l<_nbFields; l++){ - a(k*_nbFields+l,alpha*nQP+xi) = dConvectiveFluxdU->get(k*dim+alpha,l,xi)*factor; - } - } - } - } - }*/ - } - - // ----- 3 ---- do the redistribution at nodes using as many BLAS3 operations as there are local coordinates - /*if(_convectiveFlux || _diffusiveFlux){ - for (int iUVW=0;iUVW<group.getDimUVW();iUVW++){ - residual.gemm(group.getFluxRedistributionMatrix(iUVW),Fuvw[iUVW]); - } - } - if(_sourceTerm){ - residual.gemm(group.getSourceRedistributionMatrix(),Source); - }*/ - int nbNodes = group.getNbNodes(); - fullMatrix<double> jacobianK (nbNodes*nbNodes,_nbFields*_nbFields*group.getNbElements()); - /*if (_convectiveFlux) { - jacobianK.gemm(group.getPsiDPsiDXi(),A); - }*/ - if (_diffusiveFlux) { - jacobianK.gemm(group.getDPsiDXDPsiDXi(),B); - } - fullMatrix<double> jacobianE, jacobianKE; - for (int iElement=0 ; iElement<group.getNbElements() ;++iElement) { - jacobianKE.setAsProxy(jacobianK, iElement*_nbFields*_nbFields, _nbFields*_nbFields); - jacobianE.setAsProxy(jacobian, iElement*_nbFields*nbNodes, _nbFields*nbNodes); - for (int k=0; k<_nbFields;k++) for (int l=0;l<_nbFields;l++) { - for(int i=0; i<nbNodes; i++) for(int j=0; j<nbNodes; j++) { - jacobianE(l*nbNodes+j, k*nbNodes+i) = jacobianKE(i*nbNodes+j, k*_nbFields+l); - } - } - } -} - -void dgResidualVolume::computeAndMap1Group(dgGroupOfElements &group, dgDofContainer &solution, dgDofContainer &residual) -{ - compute1Group (group, solution.getGroupProxy(&group), residual.getGroupProxy(&group)); -} - - -dgResidualInterface::dgResidualInterface (const dgConservationLaw &claw): - _claw (claw) -{ - _nbFields = _claw.getNbFields(); -} - -void dgResidualInterface::compute1Group ( //dofManager &dof, // the DOF manager (maybe useless here) - dgGroupOfFaces &group, - const fullMatrix<double> &solution, // solution !! at faces nodes - const std::vector<const fullMatrix<double>*> solutionOnElements, - fullMatrix<double> &residual // residual !! at faces nodes - ) -{ - // A) global operations before entering the loop over the faces - // A1 ) copy locally some references from the group for the sake of lisibility - int nbConnections = group.getNbGroupOfConnections(); - std::vector<dataCacheMap> caches(nbConnections); - std::vector<const dgGroupOfConnections*> connections(nbConnections); - std::vector<const dgGroupOfElements*> elementGroups(nbConnections); - std::vector<dataCacheDouble*> diffusiveFluxes(nbConnections), maximumDiffusivities(nbConnections), solutionGradients(nbConnections), - normals(nbConnections), solutions(nbConnections), parametricCoordinates(nbConnections); - for (int i=0; i<nbConnections; i++) { - connections[i] = &group.getGroupOfConnections(i); - elementGroups[i] = &connections[i]->getGroupOfElements(); - diffusiveFluxes[i] =_claw.newDiffusiveFlux(caches[i]); - maximumDiffusivities[i] = _claw.newMaximumDiffusivity(caches[i]); - parametricCoordinates[i] = &caches[i].get(function::getParametricCoordinates(),NULL); - normals[i] = &caches[i].get(function::getNormals(), NULL); - solutions[i] = &caches[i].get(function::getSolution(), NULL); - solutionGradients[i] = &caches[i].get(function::getSolutionGradient(), NULL); - solutionGradients[i]->set().resize(group.getNbIntegrationPoints(), 3*_nbFields); - caches[i].setNbEvaluationPoints(group.getNbIntegrationPoints()); - } - dataCacheDouble *riemannSolver = NULL, *neumann = NULL, *dirichlet = NULL, *maximumDiffusivityOut = NULL; - if (nbConnections == 1) { - const dgBoundaryCondition *boundaryCondition = _claw.getBoundaryCondition(group.getPhysicalTag()); - riemannSolver = boundaryCondition->newBoundaryTerm(caches[0]); - neumann = boundaryCondition->newDiffusiveNeumannBC(caches[0]); - dirichlet = boundaryCondition->newDiffusiveDirichletBC(caches[0]); - maximumDiffusivityOut = boundaryCondition->newMaximumDiffusivity(caches[0]); - if (!maximumDiffusivityOut) - maximumDiffusivityOut = maximumDiffusivities[0]; - } - if (nbConnections == 2) - riemannSolver = _claw.newRiemannSolver(caches[0], caches[1]); - if (nbConnections == 3) - riemannSolver = _claw.newBifurcationRiemannSolver(caches[0], caches[1], caches[2]); - - // ----- 1 ---- get the solution at quadrature points - int nbFaces = group.getNbElements(); - fullMatrix<double> solutionQP (group.getNbIntegrationPoints(), nbFaces * _nbFields*nbConnections); - group.getCollocationMatrix().mult (solution, solutionQP); - // needed tocompute normal fluxes at integration points - fullMatrix<double> NormalFluxQP (group.getNbIntegrationPoints(), nbFaces*_nbFields*nbConnections); - fullMatrix<double> normalFluxQP, dofs, dPsiDx,gradSolProxy; - int p = elementGroups[0]->getOrder(); - int dim = connections[0]->getElement(0)->getDim(); - for (int iFace=0 ; iFace < nbFaces ; ++iFace) { - for (int i=0; i<nbConnections; i++) { - // B1 ) adjust the proxies for this element - caches[i].setElement(connections[i]->getElement(iFace)); - parametricCoordinates[i]->set() = connections[i]->getIntegrationPointsOnElement(iFace); - solutions[i]->set().setAsProxy(solutionQP, (iFace*nbConnections+i)*_nbFields, _nbFields); - normals[i]->set().setAsProxy(connections[i]->getNormals(), iFace*group.getNbIntegrationPoints(), group.getNbIntegrationPoints()); - // B2 ) compute the gradient of the solution - if(solutionGradients[i]->somethingDependOnMe()) { - dofs.setAsProxy(*solutionOnElements[i], _nbFields*connections[i]->getElementId(iFace), _nbFields); - dPsiDx.setAsProxy(connections[i]->getDPsiDx(),iFace*elementGroups[i]->getNbNodes(),elementGroups[i]->getNbNodes()); - gradSolProxy.setAsShapeProxy(solutionGradients[i]->set(),group.getNbIntegrationPoints()*3, _nbFields); - dPsiDx.mult(dofs, gradSolProxy); - } - } - // proxies for the flux - normalFluxQP.setAsProxy(NormalFluxQP, iFace*_nbFields*nbConnections, _nbFields*nbConnections); - // B3 ) compute fluxes - if (diffusiveFluxes[0]) { // IP only implemented for 2-sides faces (not for bifurcations) - if(nbConnections == 2) { - //just for the lisibility : - const fullMatrix<double> &dfl = (*diffusiveFluxes[0])(); - const fullMatrix<double> &dfr = (*diffusiveFluxes[1])(); - const fullMatrix<double> &n = (*normals[0])(); - for (int iPt =0; iPt< group.getNbIntegrationPoints(); iPt++) { - const double detJ = group.getDetJ (iFace, iPt); - for (int k=0;k<_nbFields;k++) { - double meanNormalFlux = - ((dfl(iPt,k+_nbFields*0)+dfr(iPt,k+_nbFields*0)) * n(0,iPt) - +(dfl(iPt,k+_nbFields*1)+dfr(iPt,k+_nbFields*1)) * n(1,iPt) - +(dfl(iPt,k+_nbFields*2)+dfr(iPt,k+_nbFields*2)) * n(2,iPt))/2; - double minl = std::min(elementGroups[0]->getElementVolume(connections[0]->getElementId(iFace)), - elementGroups[1]->getElementVolume(connections[1]->getElementId(iFace)) - )/group.getInterfaceSurface(iFace); - double nu = std::max((*maximumDiffusivities[1])(iPt,0),(*maximumDiffusivities[0])(iPt,0)); - double mu = (p+1)*(p+dim)/dim*nu/minl; - double solutionJumpPenalty = ((*solutions[0])(iPt,k)-(*solutions[1])(iPt,k))/2*mu; - normalFluxQP(iPt,k) -= (meanNormalFlux+solutionJumpPenalty)*detJ; - normalFluxQP(iPt,k+_nbFields) += (meanNormalFlux+solutionJumpPenalty)*detJ; - } - } - } else if(nbConnections == 1) { - for (int iPt =0; iPt< group.getNbIntegrationPoints(); iPt++) { - const double detJ = group.getDetJ (iFace, iPt); - for (int k=0;k<_nbFields;k++) { - double minl = elementGroups[0]->getElementVolume(connections[0]->getElementId(iFace))/group.getInterfaceSurface(iFace); - double nu = std::max((*maximumDiffusivities[0])(iPt,0),(*maximumDiffusivityOut)(iPt,0)); - double mu = (p+1)*(p+dim)/dim*nu/minl; - double solutionJumpPenalty = ((*solutions[0])(iPt,k)-(*dirichlet)(iPt,k))/2*mu; - normalFluxQP(iPt,k) -= ((*neumann)(iPt,k)+solutionJumpPenalty)*detJ; - } - } - } - } - if (riemannSolver) { - for (int iPt =0; iPt< group.getNbIntegrationPoints(); iPt++) { - const double detJ = group.getDetJ (iFace, iPt); - for (int k=0;k<_nbFields*nbConnections;k++) - normalFluxQP(iPt,k) += (*riemannSolver)(iPt,k)*detJ; - } - } - - } - // C ) redistribute the flux to the residual (at Faces nodes) - if(riemannSolver || diffusiveFluxes[0]) - residual.gemm(group.getRedistributionMatrix(),NormalFluxQP); -} - - -void dgResidualInterface::computeAndMap1Group (dgGroupOfFaces &faces, dgDofContainer &solution, dgDofContainer &residual) -{ - int nbConnections = faces.getNbGroupOfConnections(); - fullMatrix<double> solInterface(faces.getNbNodes(),faces.getNbElements()*_nbFields*nbConnections); - fullMatrix<double> residuInterface(faces.getNbNodes(),faces.getNbElements()*_nbFields*nbConnections); - - std::vector<const dgGroupOfElements *> elGroups(nbConnections); - std::vector<const fullMatrix<double> *> solutionProxies(nbConnections); - std::vector<fullMatrix<double> *> residualProxies(nbConnections); - for (int i=0; i<nbConnections; i++) { - elGroups[i] = &faces.getGroupOfConnections(i).getGroupOfElements(); - solutionProxies[i] = &solution.getGroupProxy(elGroups[i]); - residualProxies[i] = &residual.getGroupProxy(elGroups[i]); - } - faces.mapToInterface(_nbFields, solutionProxies, solInterface); - compute1Group(faces, solInterface, solutionProxies, residuInterface); - faces.mapFromInterface(_nbFields, residuInterface, residualProxies); -} - -dgResidualInterface::~dgResidualInterface () -{ -} - -void dgResidual::compute(dgGroupCollection &groups, dgDofContainer &solution, dgDofContainer &residual) -{ - solution.scatter(); - dgResidualVolume residualVolume(_claw); - for (int i=0; i<groups.getNbElementGroups(); i++) - residualVolume.computeAndMap1Group(*groups.getElementGroup(i), solution, residual); - dgResidualInterface residualInterface(_claw); - for(size_t i=0;i<groups.getNbFaceGroups() ; i++){ - residualInterface.computeAndMap1Group(*groups.getFaceGroup(i), solution, residual); - } -} - -#include "Bindings.h" -void dgResidual::registerBindings (binding *b) -{ - classBinding *cb = b->addClass<dgResidual>("dgResidual"); - cb->setDescription("compute the residual, given a conservation law and a solution dof container"); - methodBinding *mb; - mb = cb->addMethod("compute", &dgResidual::compute); - mb->setDescription("compute the residual"); - mb->setArgNames("groups", "solution", "residual",NULL); - mb = cb->setConstructor<dgResidual, dgConservationLaw*>(); - mb->setDescription("a new object used to compute the residual"); - mb->setArgNames("law",NULL); - - cb = b->addClass<dgResidualVolume>("dgResidualVolume"); - cb->setDescription("compute the residual for one dgGroupOfFaces"); - mb = cb->addMethod("computeAndMap1Group",&dgResidualVolume::computeAndMap1Group); - mb->setDescription("compute the residual for one group given a dgDofContainer solution"); - mb->setArgNames("group", "solution", "residual", NULL); - mb = cb->addMethod("compute1Group", &dgResidualVolume::compute1Group); - mb->setDescription("compute the residual for one group given a fullMatrix proxy to the solution relative to this group"); - mb->setArgNames("group", "solution", "residual", NULL); - mb = cb->setConstructor<dgResidualVolume, const dgConservationLaw&>(); - mb->setDescription("a new object used to compute the residual"); - mb->setArgNames("law",NULL); - - mb = cb->addMethod("compute1GroupWithJacobian", &dgResidualVolume::compute1GroupWithJacobian); - mb->setDescription("compute the residual for one group given a fullMatrix proxy to the solution relative to this group"); - mb->setArgNames("group", "solution", "residual", "jacobian", NULL); - - cb = b->addClass<dgResidualInterface>("dgResidualInterface"); - cb->setDescription("compute the residual for one dgGroupOfElements"); - mb = cb->addMethod("computeAndMap1Group",&dgResidualInterface::computeAndMap1Group); - mb->setDescription("compute the residual for one group given a dgDofContainer solution"); - mb->setArgNames("group", "solution", "residual", NULL); - mb = cb->addMethod("compute1Group", &dgResidualInterface::compute1Group); - mb->setDescription("compute the residual for one group given fullMatrices with the solution at faces nodes and at element nodes"); - mb->setArgNames("group", "solutionFaces", "solutionOnElements", "residual", NULL); -} diff --git a/Solver/dgResidual.h b/Solver/dgResidual.h deleted file mode 100644 index ed3097f7c09317c5b16e82a0224a82c4bfb6839c..0000000000000000000000000000000000000000 --- a/Solver/dgResidual.h +++ /dev/null @@ -1,52 +0,0 @@ -#ifndef _DG_RESIDUAL_H_ -#define _DG_RESIDUAL_H_ -class dgConservationLaw; -class dgGroupCollection; -class dataCacheDouble; -class dataCacheElement; -class dgDofContainer; -class dataCacheMap; -class dgGroupOfElements; -class dgGroupOfFaces; -class binding; -#include "fullMatrix.h" -#include <vector> - -class dgResidualVolume { - dataCacheMap *_cacheMap; - const dgConservationLaw &_claw; - int _nbFields; - dataCacheDouble &_UVW, &_solutionQPe, &_gradientSolutionQPe; - dataCacheDouble *_sourceTerm, *_convectiveFlux, *_diffusiveFlux; - public: - dgResidualVolume (const dgConservationLaw &claw); - ~dgResidualVolume(); - void compute1Group(dgGroupOfElements &group, fullMatrix<double> &solution, fullMatrix<double> &residual); - void compute1GroupWithJacobian(dgGroupOfElements &group, fullMatrix<double> &solution, fullMatrix<double> &residual, fullMatrix<double> &jacobian); - void computeAndMap1Group(dgGroupOfElements &group, dgDofContainer &solution, dgDofContainer &residual); -}; - -class dgResidualInterface { - const dgConservationLaw &_claw; - int _nbFields; - public: - dgResidualInterface (const dgConservationLaw &claw); - void compute1Group ( //dofManager &dof, // the DOF manager (maybe useless here) - dgGroupOfFaces &group, - const fullMatrix<double> &solution, // solution !! at faces nodes - const std::vector<const fullMatrix<double>*> solutionOnElements, - fullMatrix<double> &residual // residual !! at faces nodes - ); - void computeAndMap1Group (dgGroupOfFaces &faces, dgDofContainer &solution, dgDofContainer &residual); - ~dgResidualInterface(); -}; - -class dgResidual { - const dgConservationLaw &_claw; - public: - dgResidual (const dgConservationLaw *claw) : _claw(*claw) {} - void compute(dgGroupCollection &groups, dgDofContainer &solution, dgDofContainer &residual); - static void registerBindings (binding *b); -}; - -#endif diff --git a/Solver/dgRungeKutta.cpp b/Solver/dgRungeKutta.cpp deleted file mode 100644 index d61ffbca6f9de99ccbde3b6e98856515c84e7435..0000000000000000000000000000000000000000 --- a/Solver/dgRungeKutta.cpp +++ /dev/null @@ -1,283 +0,0 @@ -#include <stdlib.h> -#include "dgRungeKutta.h" -#include "dgAlgorithm.h" -#include "dgConservationLaw.h" -#include "dgDofContainer.h" -#include "dgLimiter.h" -#include "dgTransformNodalValue.h" -#include "dgResidual.h" -#include "dgGroupOfElements.h" -#include <limits.h> -#include <stdio.h> -#ifdef HAVE_MPI -#include "mpi.h" -#endif - -double dgRungeKutta::iterateEuler(const dgConservationLaw *claw, double dt, dgDofContainer *solution) { - double A[] = {0}; - double b[] = {1}; - return diagonalRK(claw, dt, solution, 1, A, b); -} - -double dgRungeKutta::iterate22(const dgConservationLaw *claw, double dt, dgDofContainer *solution) { - double A[] = {0, 1}; - double b[] = {1./2, 1./2}; - return diagonalRK(claw, dt, solution, 2, A, b); -} -double dgRungeKutta::iterate33(const dgConservationLaw *claw, double dt, dgDofContainer *solution) { - double A[] = {0, 1./3, 2./3}; - double b[] = {1./4,0, 3./4}; - return diagonalRK(claw, dt, solution, 3, A, b); -} -double dgRungeKutta::iterate44(const dgConservationLaw *claw, double dt, dgDofContainer *solution) { - double A[] = {0, 0.5, 0.5, 1}; - double b[] = {1./6, 1./3, 1./3, 1./6}; - return diagonalRK(claw, dt, solution, 4, A, b); -} - - -double dgRungeKutta::iterate44ThreeEight(const dgConservationLaw *claw, double dt, dgDofContainer *solution) { - // 3/8 RK44 - double A[4][4]={ - {0, 0, 0, 0}, - {1.0/3.0, 0, 0 ,0}, - {-1.0/3.0, 1.0, 0, 0}, - {1, -1, 1, 0} - }; - fullMatrix<double> Afm(4,4); - for(int i=0;i<4;i++){ - for(int j=0;j<4;j++){ - Afm(i,j)=A[i][j]; - } - } - double b[4]={1.0/8.0, 3.0/8.0, 3.0/8.0, 1.0/8.0}; - double c[4]={0, 1.0/3.0, 2.0/3.0, 1}; - return nonDiagonalRK(claw, dt, solution, 4, Afm, b, c); -} - -double dgRungeKutta::iterateRKFehlberg45(const dgConservationLaw *claw, double dt, dgDofContainer *solution){ - double A[6][6]={ - {0,0,0,0,0,0}, - {1.0/4,0,0,0,0,0}, - {3.0/32,9.0/32,0,0,0,0}, - {1932.0/2197,-7200.0/2197,7296.0/2197,0,0,0}, - {439.0/216,-8,3680.0/513,-845.0/4104,0,0}, - {8.0/27,2,-3544.0/2565,-1859.0/4104,-11.0/40,0}, - }; - double c[6]; - fullMatrix<double> Afm(6,6); - for(int i=0;i<6;i++){ - c[i]=0; - for(int j=0;j<6;j++){ - Afm(i,j)=A[i][j]; - c[i]+=A[i][j]; - } - } - double b[6]={16.0/235,6656.0/12825,28561.0/56430,-9.0/50,2.0/55}; - return nonDiagonalRK(claw, dt, solution, 6, Afm, b, c); -} - - -double dgRungeKutta::iterate43SchlegelJCAM2009(const dgConservationLaw *claw, double dt, dgDofContainer *solution) { - // RK43 from Schlegel et al. JCAM 2009 - double A[4][4]={ - {0, 0, 0, 0}, - {1.0/2.0, 0, 0 ,0}, - {-1.0/6.0, 2.0/3.0, 0, 0}, - {1.0/3.0, -1.0/3.0, 1, 0} - }; - fullMatrix<double> Afm(4,4); - for(int i=0;i<4;i++){ - for(int j=0;j<4;j++){ - Afm(i,j)=A[i][j]; - } - } - double b[4]={1.0/6.0, 1.0/3.0, 1.0/3.0, 1.0/6.0}; - double c[4]={0, 1.0/2.0, 1.0/2.0, 1}; - return nonDiagonalRK(claw, dt, solution, 4, Afm, b, c); -} - - - - -double dgRungeKutta::diagonalRK (const dgConservationLaw *claw, - double dt, // time-step - dgDofContainer *sol, - int nStages, double *A, double *b) { - // U_{n+1}=U_n+h*(SUM_i dt*b_i*K_i) - // K_i=M^(-1)R(U_n+dt*A_i*K_{i-1}) - fullMatrix<double> residuEl, KEl; - fullMatrix<double> iMassEl; - - int nbFields = claw->getNbFields(); - dgGroupCollection *groups = sol->getGroups(); - - dgDofContainer K (groups, nbFields); - dgDofContainer Unp (groups, nbFields); - dgDofContainer resd(groups, nbFields); - - - if (_TransformNodalValue) _TransformNodalValue->apply(sol); - - Unp.scale(0.); - Unp.axpy(*sol); - K.scale(0.); - K.axpy(Unp); - - dgResidual residual(claw); - - for(int j=0; j<nStages;j++){ - if(j){ - K.scale(A[j]*dt); - K.axpy(*sol); - } - if (_limiter) _limiter->apply(&K); - if (_TransformNodalValue) _TransformNodalValue->apply_Inverse(&K); - residual.compute(*groups,K,resd); - K.scale(0.); - for(int k=0; k < groups->getNbElementGroups(); k++) { - dgGroupOfElements *group = groups->getElementGroup(k); - int nbNodes = group->getNbNodes(); - for(int i=0;i<group->getNbElements();i++) { - residuEl.setAsProxy(resd.getGroupProxy(k),i*nbFields,nbFields); - KEl.setAsProxy(K.getGroupProxy(k),i*nbFields,nbFields); - iMassEl.setAsProxy(group->getInverseMassMatrix(),i*nbNodes,nbNodes); - iMassEl.mult(residuEl,KEl); - } - } - Unp.axpy(K,b[j]*dt); - } - if (_limiter) _limiter->apply(&Unp); - if (_TransformNodalValue) _TransformNodalValue->apply_Inverse(&Unp); - sol->scale(0.); - sol->axpy(Unp); - return sol->norm(); -} - -double dgRungeKutta::nonDiagonalRK(const dgConservationLaw *claw, - double dt, - dgDofContainer *solution, - int nStages, - fullMatrix<double> &A, // c | A - double *b, // Standard Butcher tableau notation :___|__ - double *c // |b^T - ) -{ - dgGroupCollection *groups=solution->getGroups(); - fullMatrix<double> residuEl, KEl; - fullMatrix<double> iMassEl; - - int nbFields = claw->getNbFields(); - - dgDofContainer **K; - K=new dgDofContainer*[nStages]; - for(int i=0;i<nStages;i++){ - K[i]=new dgDofContainer(groups,nbFields); - K[i]->scale(0.); - } - dgDofContainer Unp (groups,nbFields); - dgDofContainer tmp (groups,nbFields); - dgDofContainer resd(groups,nbFields); - - Unp.scale(0.0); - Unp.axpy(*solution); - dgResidual residual(claw); - for(int i=0; i<nStages;i++){ - tmp.scale(0.0); - tmp.axpy(*solution); - for(int j=0;j<i;j++){ - if(fabs(A(i,j))>1e-12){ - tmp.axpy(*K[j],dt*A(i,j)); - } - } - if (_limiter) _limiter->apply(&tmp); - residual.compute(*groups,tmp,resd); - - // Multiply the spatial residual by the inverse of the mass matrix - for(int k=0; k < groups->getNbElementGroups(); k++) { - dgGroupOfElements *group = groups->getElementGroup(k); - int nbNodes = group->getNbNodes(); - for(int j=0;j<group->getNbElements();j++) { - residuEl.setAsProxy(resd.getGroupProxy(k),j*nbFields,nbFields); - KEl.setAsProxy(K[i]->getGroupProxy(k),j*nbFields,nbFields); - iMassEl.setAsProxy(group->getInverseMassMatrix(),j*nbNodes,nbNodes); - iMassEl.mult(residuEl,KEl); - } - } - //Msg::Info("norm %d %0.16e",i,K[i]->norm()); - Unp.axpy(*K[i],dt*b[i]); - } - if (_limiter) _limiter->apply(&Unp); - solution->scale(0.); - solution->axpy(Unp); - - for(int i=0;i<nStages;i++){ - delete K[i]; - } - delete []K; - return solution->norm(); -} - -double dgRungeKutta::computeInvSpectralRadius(const dgConservationLaw *claw, - dgDofContainer *solution){ - double sr = 1.e22; - dgGroupCollection *groups=solution->getGroups(); - for (int i=0;i<groups->getNbElementGroups();i++){ - std::vector<double> DTS; - dgAlgorithm::computeElementaryTimeSteps(*claw, *(groups->getElementGroup(i)), solution->getGroupProxy(i), DTS); - for (int k=0;k<DTS.size();k++) sr = std::min(sr,DTS[k]); - } - #ifdef HAVE_MPI - double sr_min; - MPI_Allreduce((void *)&sr, &sr_min, 1, MPI_DOUBLE, MPI_MIN, MPI_COMM_WORLD); - return sr_min; - #else - return sr; - #endif -} - - -dgRungeKutta::dgRungeKutta():_limiter(NULL),_TransformNodalValue(NULL){} - - -#include "Bindings.h" - -void dgRungeKutta::registerBindings(binding *b) { - classBinding *cb = b->addClass<dgRungeKutta>("dgRungeKutta"); - cb->setDescription("various explicit Runge-Kutta time stepping schemes"); - methodBinding *cm; - cm = cb->setConstructor<dgRungeKutta>(); - cm->setDescription("A new explicit runge kutta, pass parameters to the iterate function"); - cm = cb->addMethod("iterateEuler",&dgRungeKutta::iterateEuler); - cm->setArgNames("law","dt","solution",NULL); - cm->setDescription("update solution by doing a forward euler step of time step dt for the conservation law"); - cm = cb->addMethod("iterate22",&dgRungeKutta::iterate22); - cm->setArgNames("law","dt","solution",NULL); - cm->setDescription("update solution by doing Heun second order runge-kutta step of time step dt for the conservation law"); - cm = cb->addMethod("iterate33",&dgRungeKutta::iterate33); - cm->setArgNames("law","dt","solution",NULL); - cm->setDescription("update solution by doing classical third order runge-kutta step of time step dt for the conservation law"); - cm = cb->addMethod("iterate44",&dgRungeKutta::iterate44); - cm->setArgNames("law","dt","solution",NULL); - cm->setDescription("update solution by doing classical fourth order runge-kutta step of time step dt for the conservation law"); - cm = cb->addMethod("iterate44ThreeEight",&dgRungeKutta::iterate44ThreeEight); - cm->setArgNames("law","dt","solution",NULL); - cm->setDescription("update solution by doing a fourth order runge-kutta (3/8 rule, not the classical one, see Hairer & Wanner book) step of time step dt for the conservation law"); - cm = cb->addMethod("iterate43SchlegelJCAM2009",&dgRungeKutta::iterate43SchlegelJCAM2009); - cm->setArgNames("law","dt","solution",NULL); - cm->setDescription("update solution by doing a four stage third order runge-kutta (from Schlegel et al. Journal of Computational and Applied Mathematics, 2009) step of time step dt for the conservation law"); - cm = cb->addMethod("iterateRKFehlberg45",&dgRungeKutta::iterateRKFehlberg45); - cm->setArgNames("law","dt","solution",NULL); - cm->setDescription("update solution by doing a six stage fifth order Runge-Kutta-Fehlberg step of time step dt for the conservation law"); - cm = cb->addMethod("setLimiter",&dgRungeKutta::setLimiter); - cm->setArgNames("limiter",NULL); - cm->setDescription("if a limiter is set, it is applied after each RK stage"); - cm = cb->addMethod("computeInvSpectralRadius",&dgRungeKutta::computeInvSpectralRadius); - cm->setArgNames("law","solution",NULL); - cm->setDescription("Returns the inverse of the spectral radius of L(U). Useful for computing stable explicit time step."); - cm = cb->addMethod("setTransformNodalValue",&dgRungeKutta::setTransformNodalValue); - cm->setArgNames("TransformNodalValue",NULL); - cm->setDescription("if the Nodal values is transformed in first step of RK"); - -} - diff --git a/Solver/dgRungeKutta.h b/Solver/dgRungeKutta.h deleted file mode 100644 index 4c178b7499c17eda85af706d15d65085e6d71b16..0000000000000000000000000000000000000000 --- a/Solver/dgRungeKutta.h +++ /dev/null @@ -1,39 +0,0 @@ -#ifndef _DG_RUNGE_KUTTA_H_ -#define _DG_RUNGE_KUTTA_H_ -#include <vector> -#include <map> -class dgConservationLaw; -class dgDofContainer; -class dgLimiter; -class dgAlgorithm; -class dgTransformNodalValue; -class dgGroupCollection; -class dgGroupOfElements; -class dgGroupOfFaces; -class dgResidualVolume; -class dgResidualInterface; -class dgResidualBoundary; -class binding; -#include "fullMatrix.h" -class dgRungeKutta { - double diagonalRK(const dgConservationLaw *claw, double dt, dgDofContainer *solution, int nStages, double *A, double *b); // c == A - double nonDiagonalRK(const dgConservationLaw *claw, double dt, dgDofContainer *solution, int nStages, fullMatrix<double>&A, double *b, double *c); - dgLimiter *_limiter; - dgTransformNodalValue *_TransformNodalValue; - public: - void setLimiter(dgLimiter *limiter) { _limiter = limiter; } - double computeInvSpectralRadius(const dgConservationLaw *claw, dgDofContainer *solution); - void setTransformNodalValue(dgTransformNodalValue *TransformNodalValue) { _TransformNodalValue = TransformNodalValue; } - - double iterateEuler(const dgConservationLaw *claw, double dt, dgDofContainer *solution); - double iterate22(const dgConservationLaw *claw, double dt, dgDofContainer *solution); - double iterate33(const dgConservationLaw *claw, double dt, dgDofContainer *solution); - double iterate44(const dgConservationLaw *claw, double dt, dgDofContainer *solution); - double iterate44ThreeEight(const dgConservationLaw *claw, double dt, dgDofContainer *solution); - double iterate43SchlegelJCAM2009(const dgConservationLaw *claw, double dt, dgDofContainer *solution); - double iterateRKFehlberg45(const dgConservationLaw *claw, double dt, dgDofContainer *solution); - static void registerBindings (binding *b); - dgRungeKutta(); -}; - -#endif diff --git a/Solver/dgRungeKuttaMultirate.cpp b/Solver/dgRungeKuttaMultirate.cpp deleted file mode 100644 index b9de7ab7e869c285bac637b5a929e6e3e331cb49..0000000000000000000000000000000000000000 --- a/Solver/dgRungeKuttaMultirate.cpp +++ /dev/null @@ -1,985 +0,0 @@ -#include "dgRungeKuttaMultirate.h" -#include "Bindings.h" -#include "dgResidual.h" -#include "dgConservationLaw.h" -#include "dgDofContainer.h" -#include "dgGroupOfElements.h" -#include <algorithm> -#include <limits.h> -#include <stdio.h> -//#define MULTIRATEVERBOSE - -//Butcher tables for RK43 (Schlegel) -static double A43[4][4]={ - {0, 0, 0, 0}, - {1.0/2.0, 0, 0 ,0}, - {-1.0/6.0, 2.0/3.0, 0, 0}, - {1.0/3.0, -1.0/3.0, 1, 0} - }; -static double AInner43[10][10]={ - {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, - {1.0/4.0 ,0, 0, 0, 0, 0, 0, 0, 0, 0}, - {-1.0/12.0, 1.0/3.0, 0, 0, 0, 0, 0, 0, 0, 0}, - {1.0/6.0, -1.0/6.0, 1.0/2.0, 0, 0, 0, 0, 0, 0, 0}, - {1.0/12.0, 1.0/6.0, 1.0/6.0, 1.0/12.0, 0, 0, 0, 0, 0, 0}, - {1.0/12.0, 1.0/6.0, 1.0/6.0, 1.0/12.0, 0, 0, 0, 0, 0, 0}, - {1.0/12.0, 1.0/6.0, 1.0/6.0, 1.0/12.0, 0, 1.0/4.0, 0, 0, 0, 0}, - {1.0/12.0, 1.0/6.0, 1.0/6.0, 1.0/12.0, 0, -1.0/12.0, 1.0/3.0, 0, 0, 0}, - {1.0/12.0, 1.0/6.0, 1.0/6.0, 1.0/12.0, 0, 1.0/6.0, -1.0/6.0, 1.0/2.0, 0, 0}, - {1.0/12.0, 1.0/6.0, 1.0/6.0, 1.0/12.0, 0, 1.0/12.0, 1.0/6.0, 1.0/6.0, 1.0/12.0, 0} - }; - - // Big step RK43 -static double AOuter43[10][10]={ - {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, - {1.0/4.0 , 0, 0, 0, 0, 0, 0, 0, 0, 0}, - {1.0/4.0 , 0, 0, 0, 0, 0, 0, 0, 0, 0}, - {1.0/2.0 , 0, 0, 0, 0, 0, 0, 0, 0, 0}, - {1.0/2.0 , 0, 0, 0, 0, 0, 0, 0, 0, 0}, - {-1.0/6.0, 0, 0, 0, 2.0/3.0, 0, 0, 0, 0, 0}, - {1.0/12.0, 0, 0, 0, 1.0/6.0, 1.0/2.0, 0, 0, 0, 0}, - {1.0/12.0, 0, 0, 0, 1.0/6.0, 1.0/2.0, 0, 0, 0, 0}, - {1.0/3.0 , 0, 0, 0, -1.0/3.0, 1, 0, 0, 0, 0}, - {1.0/3.0 , 0, 0, 0, -1.0/3.0, 1, 0, 0, 0, 0}, - }; - -static double b43[4]={1.0/6.0, 1.0/3.0, 1.0/3.0, 1.0/6.0}; -static double c43[4]={0, 1.0/2.0, 1.0/2.0, 1}; -static double bInner43[10]={1.0/12.0, 1.0/6.0, 1.0/6.0,1.0/12.0,0,1.0/12.0, 1.0/6.0, 1.0/6.0,1.0/12.0,0}; -static double cInner43[10]={0, 1.0/4.0, 1.0/4.0, 1.0/2.0, 1.0/2.0, 1.0/2.0, 3.0/4.0, 3.0/4.0, 1, 1 }; -static double bOuter43[10]={1.0/6.0, 0 , 0 , 0 , 1.0/3.0,1.0/3.0, 0 , 0 , 0 , 1.0/6.0}; -static double cOuter43[10]={0, 1.0/4.0, 1.0/4.0, 1.0/2.0, 1.0/2.0, 1.0/2.0, 3.0/4.0, 3.0/4.0, 1, 1 }; - -// Butcher tables for Multirate RK22 (Constantinescu) -static double A22[2][2]={ - {0, 0}, - {1.0, 0} - }; - // Small step RK22 -static double AInner22[4][4]={ - {0, 0, 0, 0}, - {1.0/2.0, 0, 0, 0}, - {1.0/4.0, 1.0/4.0, 0, 0}, - {1.0/4.0, 1.0/4.0, 1.0/2.0, 0} - }; - - // Big step RK22 -static double AOuter22[4][4]={ - {0, 0, 0, 0}, - {1.0, 0, 0, 0}, - {0, 0, 0, 0}, - {0, 0, 1.0, 0} - }; -static double b22[2]={1.0/2.0, 1.0/2.0}; -static double c22[2]={0, 1.0}; -static double bInner22[4]={1.0/4.0, 1.0/4.0, 1.0/4.0, 1.0/4.0}; -static double cInner22[4]={0, 1.0/2.0, 1.0/2.0, 1.0}; -static double bOuter22[4]={1.0/4.0, 1.0/4.0, 1.0/4.0, 1.0/4.0}; -static double cOuter22[4]={0, 1.0, 0, 1.0}; - -dgRungeKuttaMultirate::dgRungeKuttaMultirate(dgGroupCollection* gc,dgConservationLaw *law){ - _law=law; - _residualVolume=new dgResidualVolume(*_law); - _residualInterface=new dgResidualInterface(*_law); - _gc=gc; - _init=false; -} -void dgRungeKuttaMultirate::initialize(int nStages){ - if(_init==false){ - _K=new dgDofContainer*[nStages]; - for(int i=0;i<nStages;i++){ - _K[i]=new dgDofContainer(_gc,_law->getNbFields()); - _K[i]->setAll(0.0); - } - _currentInput=new dgDofContainer(_gc,_law->getNbFields()); - _currentInput->setAll(0.0); - _residual=new dgDofContainer(_gc,_law->getNbFields()); - _residual->setAll(0.0); - _minExponent=INT_MAX; - _maxExponent=0; - for(int iGroup=0;iGroup<_gc->getNbElementGroups();iGroup++){ - dgGroupOfElements *ge=_gc->getElementGroup(iGroup); - _minExponent=std::min(_minExponent,ge->getMultirateExponent()); - _maxExponent=std::max(_maxExponent,ge->getMultirateExponent()); - _innerBufferGroupsOfElements.resize(_maxExponent+1); - _outerBufferGroupsOfElements.resize(_maxExponent+1); - _bulkGroupsOfElements.resize(_maxExponent+1); - if(ge->getIsInnerMultirateBuffer()){ - _innerBufferGroupsOfElements[ge->getMultirateExponent()].first.push_back(ge); - } - else if(ge->getIsOuterMultirateBuffer()){ - _outerBufferGroupsOfElements[ge->getMultirateExponent()].first.push_back(ge); - } - else{ - _bulkGroupsOfElements[ge->getMultirateExponent()].first.push_back(ge); - } - } - for(int iGroup=0;iGroup<_gc->getNbFaceGroups();iGroup++){ - dgGroupOfFaces *gf=_gc->getFaceGroup(iGroup); - for(int i=0;i<gf->getNbGroupOfConnections();i++){ - const dgGroupOfElements *ge = &gf->getGroupOfConnections(i).getGroupOfElements(); - if(ge->getIsInnerMultirateBuffer()){ - _innerBufferGroupsOfElements[ge->getMultirateExponent()].second.push_back(gf); - } - else if(ge->getIsOuterMultirateBuffer()){ - _outerBufferGroupsOfElements[ge->getMultirateExponent()].second.push_back(gf); - }else{ - _bulkGroupsOfElements[ge->getMultirateExponent()].second.push_back(gf); - } - } - } - // Removing duplicate entries - for(int iExp=0;iExp<=_maxExponent;iExp++){ - std::vector<dgGroupOfFaces*>*v[3]; - v[0]=&_innerBufferGroupsOfElements[iExp].second; - v[1]=&_outerBufferGroupsOfElements[iExp].second; - v[2]=&_bulkGroupsOfElements[iExp].second; - for(int i=0;i<3;i++){ - sort(v[i]->begin(),v[i]->end()); - v[i]->erase(unique(v[i]->begin(),v[i]->end()),v[i]->end()); - } - } - _init=true; - } - else - return; - -} -dgRungeKuttaMultirate::~dgRungeKuttaMultirate(){ - for(int i=0;i>10;i++){ - delete _K[i]; - } - delete []_K; - delete _residual; - delete _currentInput; - delete _residualVolume; - delete _residualInterface; -} - -void dgRungeKuttaMultirate::computeK(int iK,int exponent,bool isBuffer){ -#ifdef MULTIRATEVERBOSE - for(int i=0;i<exponent;i++) - printf("\t"); - printf("Exponent %d, %s, compute K%d\n",exponent,isBuffer?" Buffer":"Not buffer",iK); -#endif - if(isBuffer){ - std::vector<dgGroupOfElements *>&vei=_innerBufferGroupsOfElements[exponent].first; - std::vector<dgGroupOfElements *>&veo=_outerBufferGroupsOfElements[exponent].first; - _residual->scale(vei,0.0); - _residual->scale(veo,0.0); - for(int i=0;i<vei.size();i++){ - _residualVolume->computeAndMap1Group(*vei[i], *_currentInput, *_residual); - } - for(int i=0;i<veo.size();i++){ - _residualVolume->computeAndMap1Group(*veo[i], *_currentInput, *_residual); - } - std::vector<dgGroupOfFaces *>& vfi=_innerBufferGroupsOfElements[exponent].second; - std::vector<dgGroupOfFaces *>& vfo=_outerBufferGroupsOfElements[exponent].second; - std::set<dgGroupOfFaces *>gOFSet; - gOFSet.insert(vfo.begin(),vfo.end()); - gOFSet.insert(vfi.begin(),vfi.end()); - for(std::set<dgGroupOfFaces *>::iterator it=gOFSet.begin();it!=gOFSet.end();it++){ - dgGroupOfFaces *faces=*it; - if(faces->getNbGroupOfConnections()==1){ - _residualInterface->computeAndMap1Group(*faces,*_currentInput,*_residual); - } - else{ - const dgGroupOfElements *gL = &faces->getGroupOfConnections(0).getGroupOfElements(); - const dgGroupOfElements *gR = &faces->getGroupOfConnections(1).getGroupOfElements(); - fullMatrix<double> solInterface(faces->getNbNodes(),faces->getNbElements()*2*_law->getNbFields()); - fullMatrix<double> residuInterface(faces->getNbNodes(),faces->getNbElements()*2*_law->getNbFields()); - std::vector<const fullMatrix<double>*> proxies(2); - proxies[0] = &_currentInput->getGroupProxy(gL); - proxies[1] = &_currentInput->getGroupProxy(gR); - faces->mapToInterface(_law->getNbFields(), proxies, solInterface); - _residualInterface->compute1Group(*faces,solInterface, proxies, residuInterface); - if(gL->getMultirateExponent()==exponent && gL->getIsMultirateBuffer()){ - faces->mapLeftFromInterface(_law->getNbFields(), residuInterface,_residual->getGroupProxy(gL)); - } - if(gR->getMultirateExponent()==exponent && gR->getIsMultirateBuffer()){ - faces->mapRightFromInterface(_law->getNbFields(), residuInterface,_residual->getGroupProxy(gR)); - } - } - } - fullMatrix<double> iMassEl, KEl,residuEl; - for(int iGroup=0;iGroup<vei.size();iGroup++){ - dgGroupOfElements *group=vei[iGroup]; - int nbNodes = group->getNbNodes(); - for(int iElem=0;iElem<group->getNbElements();iElem++){ - residuEl.setAsProxy(_residual->getGroupProxy(group),iElem*_law->getNbFields(),_law->getNbFields()); - KEl.setAsProxy(_K[iK]->getGroupProxy(group),iElem*_law->getNbFields(),_law->getNbFields()); - iMassEl.setAsProxy(group->getInverseMassMatrix(),iElem*nbNodes,nbNodes); - iMassEl.mult(residuEl,KEl); - } - } - for(int iGroup=0;iGroup<veo.size();iGroup++){ - dgGroupOfElements *group=veo[iGroup]; - int nbNodes = group->getNbNodes(); - for(int iElem=0;iElem<group->getNbElements();iElem++){ - residuEl.setAsProxy(_residual->getGroupProxy(group),iElem*_law->getNbFields(),_law->getNbFields()); - KEl.setAsProxy(_K[iK]->getGroupProxy(group),iElem*_law->getNbFields(),_law->getNbFields()); - iMassEl.setAsProxy(group->getInverseMassMatrix(),iElem*nbNodes,nbNodes); - iMassEl.mult(residuEl,KEl); - } - } - } - else{ - std::vector<dgGroupOfElements *> &ve=_bulkGroupsOfElements[exponent].first; - _residual->scale(ve,0.0); - for(int i=0;i<ve.size();i++){ - _residualVolume->computeAndMap1Group(*ve[i], *_currentInput, *_residual); - } - std::vector<dgGroupOfFaces *> &vf=_bulkGroupsOfElements[exponent].second; - for(int i=0;i<vf.size();i++){ - dgGroupOfFaces *faces=vf[i]; - if(faces->getNbGroupOfConnections()==1){ - _residualInterface->computeAndMap1Group(*faces,*_currentInput,*_residual); - } - else{ - const dgGroupOfElements *gL = &faces->getGroupOfConnections(0).getGroupOfElements(); - const dgGroupOfElements *gR = &faces->getGroupOfConnections(1).getGroupOfElements(); - fullMatrix<double> solInterface(faces->getNbNodes(),faces->getNbElements()*2*_law->getNbFields()); - fullMatrix<double> residuInterface(faces->getNbNodes(),faces->getNbElements()*2*_law->getNbFields()); - std::vector<const fullMatrix<double>*> proxies(2); - proxies[0] = &_currentInput->getGroupProxy(gL); - proxies[1] = &_currentInput->getGroupProxy(gR); - faces->mapToInterface(_law->getNbFields(), proxies, solInterface); - _residualInterface->compute1Group(*faces,solInterface, proxies, residuInterface); - if(gL->getMultirateExponent()==exponent && !gL->getIsMultirateBuffer()){ - faces->mapLeftFromInterface(_law->getNbFields(), residuInterface,_residual->getGroupProxy(gL)); - } - if(gR->getMultirateExponent()==exponent && !gR->getIsMultirateBuffer()){ - faces->mapRightFromInterface(_law->getNbFields(), residuInterface,_residual->getGroupProxy(gR)); - } - } - } - fullMatrix<double> iMassEl, KEl,residuEl; - for(int iGroup=0;iGroup<ve.size();iGroup++){ - dgGroupOfElements *group=ve[iGroup]; - int nbNodes = group->getNbNodes(); - for(int iElem=0;iElem<group->getNbElements();iElem++){ - residuEl.setAsProxy(_residual->getGroupProxy(group),iElem*_law->getNbFields(),_law->getNbFields()); - KEl.setAsProxy(_K[iK]->getGroupProxy(group),iElem*_law->getNbFields(),_law->getNbFields()); - iMassEl.setAsProxy(group->getInverseMassMatrix(),iElem*nbNodes,nbNodes); - iMassEl.mult(residuEl,KEl); - } - } - } -} - -void dgRungeKuttaMultirate::registerBindings(binding *b) { -/* - classBinding *cb = b->addClass<dgRungeKuttaMultirate>("dgRungeKuttaMultirate"); - cb->setDescription("Multirate explicit Runge-Kutta"); - methodBinding *cm; - cm = cb->setConstructor<dgRungeKuttaMultirate,dgGroupCollection *,dgConservationLaw*>(); - cm->setArgNames("groupCollection","law",NULL); - cm->setDescription("A new multirate explicit runge kutta, pass parameters to the iterate function"); - cm = cb->addMethod("iterate",&dgRungeKuttaMultirate::iterate); - cm->setArgNames("dt","solution",NULL); - cm->setDescription("update solution by doing a multirate RK43 (from Schlegel et al. Journal of Computational and Applied Mathematics, 2009) step of base time step dt for the conservation law"); - cb->setParentClass<dgRungeKutta>(); - */ -} - -dgRungeKuttaMultirate43::dgRungeKuttaMultirate43(dgGroupCollection *gc,dgConservationLaw* law): dgRungeKuttaMultirate(gc,law){} - - -double dgRungeKuttaMultirate43::splitForMultirate(int maxLevels, dgDofContainer *solution){ - double dt = _gc->splitGroupsForMultirate(maxLevels, 1, 1, _law, solution); - _gc->buildGroupsOfInterfaces(); - return dt; -} -double dgRungeKuttaMultirate43::iterate(double dt, dgDofContainer *solution){ - initialize(10); - _solution=solution; - _dt=dt; - computeInputForK(0,0,false); - computeInputForK(1,0,false); - computeInputForK(2,0,false); - computeInputForK(3,0,false); - - return solution->norm(); -} - -void dgRungeKuttaMultirate43::computeInputForK(int iK,int exponent,bool isBuffer){ - if(exponent>_maxExponent){ - return; - } -#ifdef MULTIRATEVERBOSE - for(int i=0;i<exponent;i++) - printf("\t"); - printf("Exponent %d, %s, input K%d\n",exponent,isBuffer?" Buffer":"Not buffer",iK); -#endif - - double localDt=_dt/pow(2.0,(double)exponent); - - if(!isBuffer){ - std::vector<dgGroupOfElements *> &gV=_bulkGroupsOfElements[exponent].first; - _currentInput->scale(gV,0.0); - _currentInput->axpy(gV,*_solution,1.0); - for(int i=0;i<iK;i++){ - if(A43[iK][i]!=0.0){ - _currentInput->axpy(gV,*_K[i],A43[iK][i]*localDt); - } - } - } - else{ - std::vector<dgGroupOfElements *>&gVi=_innerBufferGroupsOfElements[exponent].first; - std::vector<dgGroupOfElements *>&gVo=_outerBufferGroupsOfElements[exponent].first; - _currentInput->scale(gVi,0.0); - _currentInput->scale(gVo,0.0); - _currentInput->axpy(gVi,*_solution,1.0); - _currentInput->axpy(gVo,*_solution,1.0); - for(int i=0;i<iK;i++){ - if(AInner43[iK][i]!=0.0) - _currentInput->axpy(gVi,*_K[i],AInner43[iK][i]*localDt*2); - if(AOuter43[iK][i]!=0.0) - _currentInput->axpy(gVo,*_K[i],AOuter43[iK][i]*localDt*2); - } - /* - NOT NEEDED - // We need to update input for the neighboring elements with bigger time step. - // if there is no corresponding K to be computed - if( (iK>0 && iK<4) || (iK>5 && iK<9) ){ - std::vector<dgGroupOfElements *>&gVbigger=_bulkGroupsOfElements[exponent-1].first; - _currentInput->scale(gVbigger,0.0); - _currentInput->axpy(gVbigger,*_solution,1.0); - int idOuter2Bulk[10]={0,0,0,0,1,2,2,2,2,3}; - for(int i=0;i<iK;i++){ - if(AOuter43[iK][i]!=0.0){ - // ON DIRAIT QUE CETTE LIGNE DE CODE NE FAIT RIEN ... - _currentInput->axpy(gVbigger,*_K[idOuter2Bulk[i]],AOuter43[iK][i]*localDt*2); - } - } - std::vector<dgGroupOfElements *>&gViBigger=_innerBufferGroupsOfElements[exponent-1].first; - _currentInput->scale(gViBigger,0.0); - _currentInput->axpy(gViBigger,*_solution,1.0); - // shift - int s=0; - if(upperLeveliK>=5){ - for(int i=0;i<4;i++){ - _currentInput->axpy(gViBigger,*_K[i],b[i]*localDt*2); - } - s+=5; - } - for(int i=0;i<iK;i++){ - if(AOuter43[iK][i]!=0.0){ - _currentInput->axpy(gViBigger,*_K[idOuter2Bulk[i]+s],AOuter43[iK][i]*localDt*2); - } - } - } - */ - } - - if(!isBuffer){ - switch(iK){ - case 0: - computeInputForK(0,exponent+1,true); - break; - case 1: - computeInputForK(4,exponent+1,true); - break; - case 2: - computeInputForK(5,exponent+1,true); - break; - case 3: - computeInputForK(9,exponent+1,true); - break; - } - } - else{ - if( (iK%5)<4 ){ - computeInputForK(iK%5,exponent,false); - } - } - if(exponent==0){ - computeK(iK,exponent,false); - if(iK==3) - updateSolution(exponent,false); - switch(iK){ - case 0: - for(int i=1;i<4;i++){ - computeInputForK(i,exponent+1,true); - } - break; - case 2: - for(int i=6;i<9;i++){ - computeInputForK(i,exponent+1,true); - } - break; - } - } - if(isBuffer && exponent>0){ - if( (iK%5)<4) - computeK(iK%5,exponent,false); - computeK(iK,exponent,true); - if( (iK%5)==3) - updateSolution(exponent,false); - if(iK==9) - updateSolution(exponent,true); - switch(iK%5){ - case 0: - for(int i=1;i<4;i++){ - computeInputForK(i,exponent+1,true); - } - break; - case 2: - for(int i=6;i<9;i++){ - computeInputForK(i,exponent+1,true); - } - break; - } - } -} - -void dgRungeKuttaMultirate43::updateSolution(int exponent,bool isBuffer){ - -#ifdef MULTIRATEVERBOSE - for(int i=0;i<exponent;i++) - printf("\t"); - printf("Updating solution at level %d %s\n",exponent,isBuffer?"Buffer":"Bulk"); -#endif - double localDt=_dt/pow(2.0,(double)exponent); - if(isBuffer){ - std::vector<dgGroupOfElements *>&gVi=_innerBufferGroupsOfElements[exponent].first; - std::vector<dgGroupOfElements *>&gVo=_outerBufferGroupsOfElements[exponent].first; - for(int i=0;i<10;i++){ - if(bInner43[i]!=0.0) - _solution->axpy(gVi,*_K[i],bInner43[i]*localDt*2); - if(bOuter43[i]!=0.0) - _solution->axpy(gVo,*_K[i],bOuter43[i]*localDt*2); - } - } - else{ - std::vector<dgGroupOfElements *>&gV=_bulkGroupsOfElements[exponent].first; - for(int i=0;i<4;i++){ - if(b43[i]!=0.0) - _solution->axpy(gV,*_K[i],b43[i]*localDt); - } - _currentInput->scale(gV,0.0); - _currentInput->axpy(gV,*_solution,1.0); - } -} - - -void dgRungeKuttaMultirate43::registerBindings(binding *b) { - classBinding *cb = b->addClass<dgRungeKuttaMultirate43>("dgRungeKuttaMultirate43"); - cb->setDescription("Multirate explicit Runge-Kutta with SchlegelJCAM2009 4 stages 3rd order method"); - methodBinding *cm; - cm = cb->setConstructor<dgRungeKuttaMultirate43,dgGroupCollection *,dgConservationLaw*>(); - cm->setArgNames("groupCollection","law",NULL); - cm->setDescription("A new multirate explicit runge kutta, pass parameters to the iterate function"); - cm = cb->addMethod("splitForMultirate",&dgRungeKuttaMultirate43::splitForMultirate); - cm->setArgNames("maxLevels","solution",NULL); - cm->setDescription("Split Groups for Multirate based on CFL condition, with appropriate buffer sizes, and build the corresponding Groups of Interfaces"); - cm = cb->addMethod("iterate",&dgRungeKuttaMultirate43::iterate); - cm->setArgNames("dt","solution",NULL); - cm->setDescription("update the solution by doing a multirate RK43 (from Schlegel et al. Journal of Computational and Applied Mathematics, 2009) step of base time step dt for the conservation law"); -} - -dgRungeKuttaMultirate22::dgRungeKuttaMultirate22(dgGroupCollection *gc,dgConservationLaw* law): dgRungeKuttaMultirate(gc,law){} - - -double dgRungeKuttaMultirate22::splitForMultirate(int maxLevels, dgDofContainer *solution){ - double dt = _gc->splitGroupsForMultirate(maxLevels, 1, 2, _law, solution); - _gc->buildGroupsOfInterfaces(); - return dt; -} -double dgRungeKuttaMultirate22::iterate(double dt, dgDofContainer *solution){ - initialize(4); - _solution=solution; - _dt=dt; - computeInputForK(0,0,false,-1); - computeInputForK(1,0,false,-1); - - return solution->norm(); -} - -void dgRungeKuttaMultirate22::computeInputForK(int iK,int exponent,bool isBuffer,int upperLeveliK){ - if(exponent>_maxExponent){ - return; - } -#ifdef MULTIRATEVERBOSE - for(int i=0;i<exponent;i++) - printf("\t"); - printf("Exponent %d, %s, input K%d\n",exponent,isBuffer?" Buffer":"Not buffer",iK); -#endif - double localDt=_dt/pow(2.0,(double)exponent); - // compute K[iK] for this exponent and buffer - - if(!isBuffer){ - std::vector<dgGroupOfElements *> &gV=_bulkGroupsOfElements[exponent].first; - _currentInput->scale(gV,0.0); - _currentInput->axpy(gV,*_solution,1.0); - for(int i=0;i<iK;i++){ - if(A22[iK][i]!=0.0){ - _currentInput->axpy(gV,*_K[i],A22[iK][i]*localDt); - } - } - } - else{ - std::vector<dgGroupOfElements *>&gVi=_innerBufferGroupsOfElements[exponent].first; - std::vector<dgGroupOfElements *>&gVo=_outerBufferGroupsOfElements[exponent].first; - _currentInput->scale(gVi,0.0); - _currentInput->scale(gVo,0.0); - _currentInput->axpy(gVi,*_solution,1.0); - _currentInput->axpy(gVo,*_solution,1.0); - for(int i=0;i<iK;i++){ - if(AInner22[iK][i]!=0.0){ - _currentInput->axpy(gVi,*_K[i],AInner22[iK][i]*localDt*2);} - if(AOuter22[iK][i]!=0.0) - _currentInput->axpy(gVo,*_K[i],AOuter22[iK][i]*localDt*2); - } - // We need to update input for the neighboring elements with bigger time step. - // if there is no corresponding K to be computed - if( (iK>0 && iK<3) ){ - std::vector<dgGroupOfElements *>&gVbigger=_bulkGroupsOfElements[exponent-1].first; - _currentInput->scale(gVbigger,0.0); - _currentInput->axpy(gVbigger,*_solution,1.0); - int idOuter2Bulk[10]={0,0,0,1}; - for(int i=0;i<iK;i++){ - if(AOuter22[iK][i]!=0.0){ - _currentInput->axpy(gVbigger,*_K[idOuter2Bulk[i]],AOuter22[iK][i]*localDt*2); - } - } - std::vector<dgGroupOfElements *>&gViBigger=_innerBufferGroupsOfElements[exponent-1].first; - _currentInput->scale(gViBigger,0.0); - _currentInput->axpy(gViBigger,*_solution,1.0); - // shift - int s=0; - if(upperLeveliK>=2){ - for(int i=0;i<2;i++){ - _currentInput->axpy(gViBigger,*_K[i],b22[i]*localDt*2); - } - s+=2; - } - for(int i=0;i<iK;i++){ - if(AOuter22[iK][i]!=0.0){ - _currentInput->axpy(gViBigger,*_K[idOuter2Bulk[i]+s],AOuter22[iK][i]*localDt*2); - } - } - } - } - - if(!isBuffer){ - switch(iK){ - case 0: - computeInputForK(0,exponent+1,true,iK); - break; - case 1: - computeInputForK(3,exponent+1,true,iK); - break; - } - } - else{ - computeInputForK(iK%2,exponent,false,iK); - } - - if(exponent==0){ - computeK(iK, exponent, false); - switch(iK){ - case 0: - for(int i=1;i<3;i++){ - computeInputForK(i,exponent+1,true,iK); - } - break; - case 1: - updateSolution(exponent, false); - break; - } - } - - if(isBuffer && exponent>0){ - computeK(iK%2, exponent, false); - computeK(iK, exponent, true); - if(iK%2==1) - updateSolution(exponent, false); - if(iK==3) - updateSolution(exponent, true); - switch(iK%2){ - case 0: - for(int i=1;i<3;i++){ - computeInputForK(i, exponent+1, true,iK); - } - break; - } - } -} - -void dgRungeKuttaMultirate22::updateSolution(int exponent,bool isBuffer){ -#ifdef MULTIRATEVERBOSE - for(int i=0;i<exponent;i++) - printf("\t"); - printf("Updating solution at level %d %s\n",exponent,isBuffer?"Buffer":"Bulk"); -#endif - double localDt=_dt/pow(2.0,(double)exponent); - if(isBuffer){ - std::vector<dgGroupOfElements *>&gVi=_innerBufferGroupsOfElements[exponent].first; - std::vector<dgGroupOfElements *>&gVo=_outerBufferGroupsOfElements[exponent].first; - for(int i=0;i<4;i++){ - if(bInner22[i]!=0.0) - _solution->axpy(gVi,*_K[i],bInner22[i]*localDt*2); - if(bOuter22[i]!=0.0) - _solution->axpy(gVo,*_K[i],bOuter22[i]*localDt*2); - } - } - else{ - std::vector<dgGroupOfElements *>&gV=_bulkGroupsOfElements[exponent].first; - for(int i=0;i<2;i++){ - if(b22[i]!=0.0) - _solution->axpy(gV,*_K[i],b22[i]*localDt); - } - } -} - -void dgRungeKuttaMultirate22::registerBindings(binding *b) { - classBinding *cb = b->addClass<dgRungeKuttaMultirate22>("dgRungeKuttaMultirate22"); - cb->setDescription("Multirate explicit Runge-Kutta with Constantinescu 2 stages 2nd order method"); - methodBinding *cm; - cm = cb->setConstructor<dgRungeKuttaMultirate22,dgGroupCollection *,dgConservationLaw*>(); - cm->setArgNames("groupCollection","law",NULL); - cm->setDescription("A new multirate explicit runge kutta, pass parameters to the iterate function"); - cm = cb->addMethod("splitForMultirate",&dgRungeKuttaMultirate22::splitForMultirate); - cm->setArgNames("maxLevels","solution",NULL); - cm->setDescription("Split Groups for Multirate based on CFL condition, with appropriate buffer sizes, and build the corresponding Groups of Interfaces"); - cm = cb->addMethod("iterate",&dgRungeKuttaMultirate22::iterate); - cm->setArgNames("dt","solution",NULL); - cm->setDescription("update the solution by doing a multirate RK2a (from Constantinescu and Sandu, 'Update on Multirate Timestepping Methods for Hyperbolic Conservation Laws', Computer Sciance Technical Report, 2007) step of base time step dt for the conservation law"); -} - -dgRungeKuttaMultirateConservative::dgRungeKuttaMultirateConservative(dgGroupCollection *gc, dgConservationLaw *law, fullMatrix<double> *A, fullMatrix<double> *b, fullMatrix<double> *c): _A(A), _b(b), _c(c), dgRungeKuttaMultirate(gc, law){ - if(A->size1()!=A->size2() || A->size1()!=b->size2() || A->size1()!=c->size2()) - Msg::Error("The base method's Butcher tables have incompatible sizes"); - //Number of stages of the base method - int bStages = A->size1(); - - //Compute Butcher Table for Outer Buffer - _AOuter=new fullMatrix<double> (2*bStages,2*bStages); - _bOuter=new fullMatrix<double> (1,2*bStages); - _cOuter=new fullMatrix<double> (1,2*bStages); - - //Compute Butcher Table for Inner Buffer - _AInner=new fullMatrix<double> (2*bStages,2*bStages); - _bInner=new fullMatrix<double> (1,2*bStages); - _cInner=new fullMatrix<double> (1,2*bStages); - for(int i=0;i<bStages;i++){ - for(int j=0;j<bStages;j++){ - - (*_AOuter)(i, j)=(*_A)(i, j); - (*_AOuter)(bStages+i,bStages+j)=(*_A)(i, j); - (*_bOuter)(0, i)=0.5*(*_b)(0, i); - (*_bOuter)(0,bStages+i)=0.5*(*_b)(0, i); - (*_cOuter)(0, i)=(*_c)(0, i); - (*_cOuter)(0,bStages+i)=(*_c)(0, i); - - (*_AInner)(i, j)=0.5*(*_A)(i, j); - (*_AInner)(bStages+i,bStages+j)=0.5*(*_A)(i, j); - (*_AInner)(bStages+i,j)=0.5*(*_b)(0, j); - (*_bInner)(0, i)=0.5*(*_b)(0, i); - (*_bInner)(0,bStages+i)=0.5*(*_b)(0, i); - (*_cInner)(0, i)=0.5*(*_c)(0, i); - (*_cInner)(0,bStages+i)=0.5+0.5*(*_c)(0, i); - - } - } -} -void dgRungeKuttaMultirateConservative::printButcher(){ - Msg::Info("------- Printing Inner Butcher Tables --------"); - printf("\n ************************************************** \n"); - _AInner->print("A_inner"); - printf("\n ********************* \n"); - _bInner->print("b_inner"); - printf("\n ********************* \n"); - _cInner->print("c_inner"); - Msg::Info("------- Printing Outer Butcher Tables --------"); - printf("\n ************************************************** \n"); - _AOuter->print("A_outer"); - printf("\n ********************* \n"); - _bOuter->print("b_outer"); - printf("\n ********************* \n"); - _cOuter->print("c_outer"); - - -} - -double dgRungeKuttaMultirateConservative::splitForMultirate(int maxLevels, dgDofContainer *solution){ - double dt = _gc->splitGroupsForMultirate(maxLevels, 1, _b->size2(), _law, solution); - _gc->buildGroupsOfInterfaces(); - return dt; -} - -double dgRungeKuttaMultirateConservative::iterate(double dt, dgDofContainer *solution){ - initialize(4); - _solution=solution; - _dt=dt; - computeInputForK(0,0,false,-1); - computeInputForK(1,0,false,-1); - - return solution->norm(); -} - -void dgRungeKuttaMultirateConservative::computeInputForK(int iK,int exponent,bool isBuffer,int upperLeveliK){ - if(exponent>_maxExponent){ - return; - } -#ifdef MULTIRATEVERBOSE - for(int i=0;i<exponent;i++) - printf("\t"); - printf("Exponent %d, %s, input K%d\n",exponent,isBuffer?" Buffer":"Not buffer",iK); -#endif - double localDt=_dt/pow(2.0,(double)exponent); - // compute K[iK] for this exponent and buffer - - if(!isBuffer){ - std::vector<dgGroupOfElements *> &gV=_bulkGroupsOfElements[exponent].first; - _currentInput->scale(gV,0.0); - _currentInput->axpy(gV,*_solution,1.0); - for(int i=0;i<iK;i++){ - if((*_A)(iK, i)!=0.0){ - _currentInput->axpy(gV,*_K[i],(*_A)(iK, i)*localDt); - } - } - } - else{ - std::vector<dgGroupOfElements *>&gVi=_innerBufferGroupsOfElements[exponent].first; - std::vector<dgGroupOfElements *>&gVo=_outerBufferGroupsOfElements[exponent].first; - _currentInput->scale(gVi,0.0); - _currentInput->scale(gVo,0.0); - _currentInput->axpy(gVi,*_solution,1.0); - _currentInput->axpy(gVo,*_solution,1.0); - for(int i=0;i<iK;i++){ - if((*_AInner)(iK, i)!=0.0){ - _currentInput->axpy(gVi,*_K[i],(*_AInner)(iK, i)*localDt*2);} - if((*_AOuter)(iK, i)!=0.0) - _currentInput->axpy(gVo,*_K[i],(*_AOuter)(iK, i)*localDt*2); - } - // We need to update input for the neighboring elements with bigger time step. - // if there is no corresponding K to be computed - if( (iK>0 && iK<3) ){ - std::vector<dgGroupOfElements *>&gVbigger=_bulkGroupsOfElements[exponent-1].first; - _currentInput->scale(gVbigger,0.0); - _currentInput->axpy(gVbigger,*_solution,1.0); - int idOuter2Bulk[10]={0,0,0,1}; - for(int i=0;i<iK;i++){ - if((*_AOuter)(iK, i)!=0.0){ - _currentInput->axpy(gVbigger,*_K[idOuter2Bulk[i]],(*_AOuter)(iK, i)*localDt*2); - } - } - std::vector<dgGroupOfElements *>&gViBigger=_innerBufferGroupsOfElements[exponent-1].first; - _currentInput->scale(gViBigger,0.0); - _currentInput->axpy(gViBigger,*_solution,1.0); - // shift - int s=0; - if(upperLeveliK>=2){ - for(int i=0;i<2;i++){ - _currentInput->axpy(gViBigger,*_K[i],(*_b)(0, i)*localDt*2); - } - s+=2; - } - for(int i=0;i<iK;i++){ - if((*_AOuter)(iK, i)!=0.0){ - _currentInput->axpy(gViBigger,*_K[idOuter2Bulk[i]+s],(*_AOuter)(iK, i)*localDt*2); - } - } - } - } - - if(!isBuffer){ - switch(iK){ - case 0: - computeInputForK(0,exponent+1,true,iK); - break; - case 1: - computeInputForK(3,exponent+1,true,iK); - break; - } - } - else{ - computeInputForK(iK%2,exponent,false,iK); - } - - if(exponent==0){ - computeK(iK, exponent, false); - switch(iK){ - case 0: - for(int i=1;i<3;i++){ - computeInputForK(i,exponent+1,true,iK); - } - break; - case 1: - updateSolution(exponent, false); - break; - } - } - - if(isBuffer && exponent>0){ - computeK(iK%2, exponent, false); - computeK(iK, exponent, true); - if(iK%2==1) - updateSolution(exponent, false); - if(iK==3) - updateSolution(exponent, true); - switch(iK%2){ - case 0: - for(int i=1;i<3;i++){ - computeInputForK(i, exponent+1, true,iK); - } - break; - } - } -} - -void dgRungeKuttaMultirateConservative::updateSolution(int exponent,bool isBuffer){ -#ifdef MULTIRATEVERBOSE - for(int i=0;i<exponent;i++) - printf("\t"); - printf("Updating solution at level %d %s\n",exponent,isBuffer?"Buffer":"Bulk"); -#endif - double localDt=_dt/pow(2.0,(double)exponent); - if(isBuffer){ - std::vector<dgGroupOfElements *>&gVi=_innerBufferGroupsOfElements[exponent].first; - std::vector<dgGroupOfElements *>&gVo=_outerBufferGroupsOfElements[exponent].first; - for(int i=0;i<4;i++){ - if((*_bInner)(0, i)!=0.0) - _solution->axpy(gVi,*_K[i],(*_bInner)(0, i)*localDt*2); - if((*_bOuter)(0, i)!=0.0) - _solution->axpy(gVo,*_K[i],(*_bOuter)(0, i)*localDt*2); - } - } - else{ - std::vector<dgGroupOfElements *>&gV=_bulkGroupsOfElements[exponent].first; - for(int i=0;i<2;i++){ - if((*_b)(0, i)!=0.0) - _solution->axpy(gV,*_K[i],(*_b)(0, i)*localDt); - } - } -} - -dgRungeKuttaMultirateConservative* dgRungeKuttaMultirateConservative::new44(dgGroupCollection *gc, dgConservationLaw *law){ - Msg::Error("---- Generic Multirate of Constantinescu doesn't work yet for this standard Butcher tables --------"); - fullMatrix<double> *A=new fullMatrix<double>(4, 4); - fullMatrix<double> *b=new fullMatrix<double>(1, 4); - fullMatrix<double> *c=new fullMatrix<double>(1, 4); - - double At[4][4]={ - {0, 0, 0, 0}, - {1.0/2.0, 0, 0, 0}, - {0, 1.0/2.0, 0, 0}, - {0, 0, 1, 0} - }; - double bt[4]={1.0/6.0, 1.0/3.0, 1.0/3.0, 1.0/6.0}; - double ct[4]={0, 1.0/2.0, 1.0/2.0, 1}; - - for(int i=0; i<4; i++){ - for (int j=0; j<4; j++){ - (*A)(i, j)=At[i][j]; - } - (*b)(0, i)=bt[i]; - (*c)(0, i)=ct[i]; - } - - return new dgRungeKuttaMultirateConservative(gc, law, A, b, c); -} -dgRungeKuttaMultirateConservative* dgRungeKuttaMultirateConservative::new43(dgGroupCollection *gc, dgConservationLaw *law){ - Msg::Error("---- Generic Multirate of Constantinescu doesn't work yet for this standard Butcher tables --------"); - fullMatrix<double> *A=new fullMatrix<double>(4, 4); - fullMatrix<double> *b=new fullMatrix<double>(1, 4); - fullMatrix<double> *c=new fullMatrix<double>(1, 4); - - double At[4][4]={ - {0, 0, 0, 0}, - {1.0/2.0, 0, 0, 0}, - {-1.0/6.0, 2.0/3.0, 0, 0}, - {1.0/3.0, -1.0/3.0, 1, 0} - }; - double bt[4]={1.0/6.0, 1.0/3.0, 1.0/3.0, 1.0/6.0}; - double ct[4]={0, 1.0/2.0, 1.0/2.0, 1}; - - for(int i=0; i<4; i++){ - for (int j=0; j<4; j++){ - (*A)(i, j)=At[i][j]; - } - (*b)(0, i)=bt[i]; - (*c)(0, i)=ct[i]; - } - - return new dgRungeKuttaMultirateConservative(gc, law, A, b, c); -} -dgRungeKuttaMultirateConservative* dgRungeKuttaMultirateConservative::new2a(dgGroupCollection *gc, dgConservationLaw *law){ - - fullMatrix<double> *A=new fullMatrix<double>(2, 2); - fullMatrix<double> *b=new fullMatrix<double>(1, 2); - fullMatrix<double> *c=new fullMatrix<double>(1, 2); - - double At[2][2]={ - {0, 0}, - {1, 0} - }; - double bt[2]={0.5, 0.5}; - double ct[2]={0, 1}; - - for(int i=0; i<2; i++){ - for (int j=0; j<2; j++){ - (*A)(i, j)=At[i][j]; - } - (*b)(0, i)=bt[i]; - (*c)(0, i)=ct[i]; - } - - return new dgRungeKuttaMultirateConservative(gc, law, A, b, c); -} -dgRungeKuttaMultirateConservative* dgRungeKuttaMultirateConservative::new2b(dgGroupCollection *gc, dgConservationLaw *law){ - - fullMatrix<double> *A=new fullMatrix<double>(2, 2); - fullMatrix<double> *b=new fullMatrix<double>(1, 2); - fullMatrix<double> *c=new fullMatrix<double>(1, 2); - - double At[2][2]={ - {0, 0}, - {1.0/2.0, 0} - }; - double bt[2]={0, 1}; - double ct[2]={0, 1.0/2.0}; - - for(int i=0; i<2; i++){ - for (int j=0; j<2; j++){ - (*A)(i, j)=At[i][j]; - } - (*b)(0, i)=bt[i]; - (*c)(0, i)=ct[i]; - } - - return new dgRungeKuttaMultirateConservative(gc, law, A, b, c); -} - -void dgRungeKuttaMultirateConservative::registerBindings(binding *b) { - classBinding *cb = b->addClass<dgRungeKuttaMultirateConservative>("dgRungeKuttaMultirateConservative"); - cb->setDescription("Multirate explicit Runge-Kutta with Constantinescu n (base method) stages 2nd order method"); - methodBinding *cm; - cm = cb->setConstructor<dgRungeKuttaMultirateConservative,dgGroupCollection*,dgConservationLaw* , fullMatrix<double>*, fullMatrix<double>*, fullMatrix<double>* >(); - cm->setArgNames("groupCollection","law","A","b","c",NULL); - cm->setDescription("A new multirate explicit runge kutta, pass parameters to the iterate function"); - cm = cb->addMethod("splitForMultirate",&dgRungeKuttaMultirateConservative::splitForMultirate); - cm->setArgNames("maxLevels","solution",NULL); - cm->setDescription("Split Groups for Multirate based on CFL condition, with appropriate buffer sizes, and build the corresponding Groups of Interfaces"); - cm = cb->addMethod("iterate",&dgRungeKuttaMultirateConservative::iterate); - cm->setArgNames("dt","solution",NULL); - cm->setDescription("update the solution by doing a multirate RK constructed from the given Butcher tables (from Constantinescu and Sandu, 'Update on Multirate Timestepping Methods for Hyperbolic Conservation Laws', Computer Sciance Technical Report, 2007) step of base time step dt for the conservation law"); - cm = cb->addMethod("new44", &dgRungeKuttaMultirateConservative::new43); - cm->setDescription("Creates a new Conservative Runge-Kutta scheme based on the base method RK44"); - cm->setArgNames("groupCollection", "law", NULL); - cm = cb->addMethod("new43", &dgRungeKuttaMultirateConservative::new43); - cm->setDescription("Creates a new Conservative Runge-Kutta scheme based on the base method RK43"); - cm->setArgNames("groupCollection", "law", NULL); - cm = cb->addMethod("new2a", &dgRungeKuttaMultirateConservative::new2a); - cm->setDescription("Creates a new Conservative Runge-Kutta scheme based on the base method RK2a"); - cm->setArgNames("groupCollection", "law", NULL); - cm = cb->addMethod("new2b", &dgRungeKuttaMultirateConservative::new2b); - cm->setDescription("Creates a new Conservative Runge-Kutta scheme based on the base method RK2b"); - cm->setArgNames("groupCollection", "law", NULL); - cm = cb->addMethod("printButcher", &dgRungeKuttaMultirateConservative::printButcher); - cm->setDescription("Print the Butcher Tables for Buffers"); - cm->setArgNames(NULL); -} - diff --git a/Solver/dgRungeKuttaMultirate.h b/Solver/dgRungeKuttaMultirate.h deleted file mode 100644 index 41947fd6cad22ed31bfedcfa6a4ba0b5c4aebbd4..0000000000000000000000000000000000000000 --- a/Solver/dgRungeKuttaMultirate.h +++ /dev/null @@ -1,75 +0,0 @@ -#include "dgRungeKutta.h" - -class dgRungeKuttaMultirate: public dgRungeKutta{ - protected: - bool _init; - int _maxExponent; - int _minExponent; - double _dt; - dgConservationLaw *_law; - dgDofContainer *_solution; - dgDofContainer **_K; - dgDofContainer *_currentInput; - dgDofContainer *_residual; - dgResidualVolume *_residualVolume; - dgResidualInterface *_residualInterface; - dgGroupCollection *_gc; - std::vector<std::pair<std::vector<dgGroupOfElements*>,std::vector<dgGroupOfFaces*> > >_bulkGroupsOfElements;// int is the multirateExponent - std::vector<std::pair<std::vector<dgGroupOfElements*>,std::vector<dgGroupOfFaces*> > >_innerBufferGroupsOfElements;// int is the multirateExponent - std::vector<std::pair<std::vector<dgGroupOfElements*>,std::vector<dgGroupOfFaces*> > >_outerBufferGroupsOfElements;// int is the multirateExponent - void initialize(int nStages); - void computeK(int iK,int exponent,bool isBuffer); - virtual void updateSolution(int exponent,bool isBuffer)=0; - void computeResidual(int exponent,bool isBuffer,dgDofContainer *solution, dgDofContainer *residual); - public: - dgRungeKuttaMultirate(dgGroupCollection *gc,dgConservationLaw* law); - virtual ~dgRungeKuttaMultirate(); - virtual double iterate(double dt, dgDofContainer *solution)=0; - virtual double splitForMultirate(int maxLevels, dgDofContainer *solution)=0; - static void registerBindings(binding *b); -}; - -class dgRungeKuttaMultirate43: public dgRungeKuttaMultirate{ - void computeInputForK(int iK,int exponent,bool isBuffer); - void updateSolution(int exponent,bool isBuffer); - public: - double splitForMultirate(int maxLevels, dgDofContainer *solution); - double iterate(double dt, dgDofContainer *solution); - dgRungeKuttaMultirate43(dgGroupCollection *gc,dgConservationLaw *law); - static void registerBindings(binding *b); -}; - -class dgRungeKuttaMultirate22: public dgRungeKuttaMultirate{ - void computeInputForK(int iK,int exponent,bool isBuffer,int upperLeveliK); - void updateSolution(int exponent,bool isBuffer); - public: - double splitForMultirate(int maxLevels, dgDofContainer *solution); - double iterate(double dt, dgDofContainer *solution); - dgRungeKuttaMultirate22(dgGroupCollection *gc,dgConservationLaw *law); - static void registerBindings(binding *b); -}; -class dgRungeKuttaMultirateConservative: public dgRungeKuttaMultirate{ - private: - fullMatrix<double> *_A; - fullMatrix<double> *_b; - fullMatrix<double> *_c; - fullMatrix<double> *_AOuter; - fullMatrix<double> *_bOuter; - fullMatrix<double> *_cOuter; - fullMatrix<double> *_AInner; - fullMatrix<double> *_bInner; - fullMatrix<double> *_cInner; - - void computeInputForK(int iK,int exponent,bool isBuffer,int upperLeveliK); - void updateSolution(int exponent,bool isBuffer); - public: - double splitForMultirate(int maxLevels, dgDofContainer *solution); - double iterate(double dt, dgDofContainer *solution); - dgRungeKuttaMultirateConservative(dgGroupCollection *gc,dgConservationLaw *law, fullMatrix<double> *A, fullMatrix<double> *b,fullMatrix<double> *c); - void printButcher(); - static dgRungeKuttaMultirateConservative* new44(dgGroupCollection *gc, dgConservationLaw *law); - static dgRungeKuttaMultirateConservative* new43(dgGroupCollection *gc, dgConservationLaw *law); - static dgRungeKuttaMultirateConservative* new2a(dgGroupCollection *gc, dgConservationLaw *law); - static dgRungeKuttaMultirateConservative* new2b(dgGroupCollection *gc, dgConservationLaw *law); - static void registerBindings(binding *b); -}; diff --git a/Solver/dgSystemOfEquations.cpp b/Solver/dgSystemOfEquations.cpp deleted file mode 100644 index fb6aba7feed0666a1a1809c291bfe45f5c4a4fe0..0000000000000000000000000000000000000000 --- a/Solver/dgSystemOfEquations.cpp +++ /dev/null @@ -1,199 +0,0 @@ -#include <stdio.h> -#include <stdlib.h> -#include <sstream> -#include "dgSystemOfEquations.h" -#include "dgAlgorithm.h" -#include "function.h" -#include "MElement.h" -#include "PView.h" -#include "PViewData.h" -#include "dgLimiter.h" -#include "dgTransformNodalValue.h" -#include "dgRungeKutta.h" -#ifdef HAVE_MPI -#include "mpi.h" -#endif -dgSystemOfEquations::dgSystemOfEquations(GModel *gm){ - _gm=gm; - _dimension = _gm->getNumRegions() ? 3 : _gm->getNumFaces() ? 2 : 1 ; - _solution = 0; -} - -// set the order of interpolation -void dgSystemOfEquations::setOrder(int o){ - _order = o; -} - -// add a boundary Condition -void dgSystemOfEquations::setConservationLaw (dgConservationLaw *law){ - _claw=law; -} - -#include "Bindings.h" - -static dgSystemOfEquations *myConstructorPtr(GModel* gm){ - return new dgSystemOfEquations(gm); -} - - -void dgSystemOfEquations::registerBindings(binding *b) { - classBinding *cb = b->addClass<dgSystemOfEquations>("dgSystemOfEquations"); - cb->setDescription("a class to rule them all :-) -- bad description, this class will be removed anyway"); - methodBinding *cm; - cm = cb->setConstructor<dgSystemOfEquations,GModel*>(); - cm->setArgNames("model",NULL); - cm->setDescription("A new system of equation on the domain described by 'model'"); - cm = cb->addMethod("setConservationLaw",&dgSystemOfEquations::setConservationLaw); - cm->setArgNames("law",NULL); - cm->setDescription("set the conservation law this system solves"); - cm = cb->addMethod("setup",&dgSystemOfEquations::setup); - cm->setDescription("allocate and init internal stuff, call this function after setOrder and setLaw and before anything else on this instance"); - cm = cb->addMethod("exportSolution",&dgSystemOfEquations::exportSolution); - cm->setArgNames("filename",NULL); - cm->setDescription("Print the solution into a file. This file does not contain the mesh. To visualize the solution in gmsh you have to open the mesh file first."); - cm= cb->addMethod("L2Projection",&dgSystemOfEquations::L2Projection); - cm->setArgNames("functionName",NULL); - cm->setDescription("project the function \"functionName\" on the solution vector"); - cm = cb->addMethod("RK44",&dgSystemOfEquations::RK44); - cm->setArgNames("dt",NULL); - cm->setDescription("Do a runge-kuta temporal iteration with 4 sub-steps and a precision order of 4 with a time step \"dt\". This function returns the sum of the nodal residuals."); - cm = cb->addMethod("ForwardEuler",&dgSystemOfEquations::ForwardEuler); - cm->setArgNames("dt",NULL); - cm->setDescription("do a forward euler temporal iteration with a time step \"dt\" and return the sum of the nodal residuals"); - cm = cb->addMethod("setOrder",&dgSystemOfEquations::setOrder); - cm->setArgNames("order",NULL); - cm->setDescription("set the polynpolynomialomial order of the lagrange shape functions"); - cm = cb->addMethod("limitSolution",&dgSystemOfEquations::limitSolution); - cm->setDescription("apply a slope limiter to the solution (only if polynomial order p = 1 for now)."); - cm = cb->addMethod("computeInvSpectralRadius",&dgSystemOfEquations::computeInvSpectralRadius); - cm->setDescription("returns the inverse of the spectral radius (largest eigenvalue) of L(u). Useful for computing stable explicit time step"); - cm = cb->addMethod("RK44_limiter",&dgSystemOfEquations::RK44_limiter); - cm->setArgNames("dt",NULL); - cm->setDescription("do one RK44 time step with the slope limiter (only for p=1)"); - -cm = cb->addMethod("RK44_TransformNodalValue",&dgSystemOfEquations::RK44_TransformNodalValue); - cm->setArgNames("dt",NULL); - cm->setDescription("do one RK44 time step with a transformation of nodal value"); - - cm = cb->addMethod("RK44_TransformNodalValue_limiter",&dgSystemOfEquations::RK44_TransformNodalValue_limiter); - cm->setArgNames("dt",NULL); - cm->setDescription("do one RK44 time step with a limiter and a transformation of nodal value"); - - - ////cm = cb->addMethod("multirateRK43",&dgSystemOfEquations::multirateRK43); - //cm->setArgNames("dt",NULL); - //cm->setDescription("Do a runge-kuta temporal iteration with 4 sub-steps and a precision order of 3 using different time-step depending on the element size. This function returns the sum of the nodal residuals."); - cm = cb->addMethod("saveSolution",&dgSystemOfEquations::saveSolution); - cm->setArgNames("filename",NULL); - cm->setDescription("dump the solution in binary format"); - cm = cb->addMethod("loadSolution",&dgSystemOfEquations::loadSolution); - cm->setArgNames("filename",NULL); - cm->setDescription("reload a solution in binary format"); -} - -// do a L2 projection -void dgSystemOfEquations::L2Projection (const function *f){ - _solution->L2Projection(f); -} - -// ok, we can setup the groups and create solution vectors -void dgSystemOfEquations::setup(){ - if (!_claw) throw; - _groups.buildGroupsOfElements(_gm,_dimension,_order, NULL); - _groups.buildGroupsOfInterfaces(); - _solution = new dgDofContainer(&_groups,_claw->getNbFields()); - _rightHandSide = new dgDofContainer(&_groups,_claw->getNbFields()); -} - - -double dgSystemOfEquations::RK44(double dt){ - dgRungeKutta rk; - rk.iterate44(_claw, dt, _solution); - return _solution->norm(); -} - -double dgSystemOfEquations::computeInvSpectralRadius(){ - double sr = 1.e22; - for (int i=0;i<_groups.getNbElementGroups();i++){ - std::vector<double> DTS; - dgAlgorithm::computeElementaryTimeSteps(*_claw, *_groups.getElementGroup(i), _solution->getGroupProxy(i), DTS); - for (int k=0;k<DTS.size();k++) sr = std::min(sr,DTS[k]); - } - #ifdef HAVE_MPI - double sr_min; - MPI_Allreduce((void *)&sr, &sr_min, 1, MPI_DOUBLE, MPI_MIN, MPI_COMM_WORLD); - return sr_min; - #else - return sr; - #endif -} - -double dgSystemOfEquations::RK44_limiter(double dt){ - dgLimiter *sl = new dgSlopeLimiter(_claw); - dgRungeKutta rk; - rk.setLimiter(sl); - rk.iterate44(_claw, dt, _solution); - delete sl; - return _solution->norm(); -} - - -double dgSystemOfEquations::RK44_TransformNodalValue(double dt){ - dgTransformNodalValue *tnv = new dgSupraTransformNodalValue(_claw); - dgRungeKutta rk; - rk.setTransformNodalValue(tnv); - rk.iterate44(_claw, dt, _solution); - delete tnv; - return _solution->norm(); -} - - - -double dgSystemOfEquations::RK44_TransformNodalValue_limiter(double dt){ - dgLimiter *sl = new dgSlopeLimiter(_claw); - dgTransformNodalValue *tnv = new dgSupraTransformNodalValue(_claw); - dgRungeKutta rk; - rk.setTransformNodalValue(tnv); - rk.setLimiter(sl); - rk.iterate44(_claw, dt, _solution); - delete sl; - delete tnv; - return _solution->norm(); -} - - -double dgSystemOfEquations::ForwardEuler(double dt){ - dgRungeKutta rk; - rk.iterateEuler(_claw, dt, _solution); - return _solution->norm(); -} -//double dgSystemOfEquations::multirateRK43(double dt){ - //dgAlgorithm::multirateRungeKutta(*_claw, _groups, dt, *_solution, *_rightHandSide); - //return _solution->norm(); -//} - -void dgSystemOfEquations::exportSolution(std::string outputFile){ - _solution->exportMsh(outputFile); -} - -void dgSystemOfEquations::limitSolution(){ - dgLimiter *sl = new dgSlopeLimiter(_claw); - sl->apply(_solution); - - delete sl; -} - -dgSystemOfEquations::~dgSystemOfEquations(){ - if (_solution){ - delete _solution; - delete _rightHandSide; - } -} - -void dgSystemOfEquations::saveSolution (std::string name) { - _solution->save(name); -} - -void dgSystemOfEquations::loadSolution (std::string name){ - _solution->load(name); -} diff --git a/Solver/dgSystemOfEquations.h b/Solver/dgSystemOfEquations.h deleted file mode 100644 index 292515d2449b66e9f991294328a76cff76b6c448..0000000000000000000000000000000000000000 --- a/Solver/dgSystemOfEquations.h +++ /dev/null @@ -1,63 +0,0 @@ -#ifndef _DG_SYSTEM_OF_EQUATIONS_ -#define _DG_SYSTEM_OF_EQUATIONS_ -#include <vector> -#include <utility> -#include "GmshConfig.h" -#include "GModel.h" -#include "dgGroupOfElements.h" -#include "dgConservationLaw.h" -#include "Gmsh.h" -#include "dgLimiter.h" -#include "dgTransformNodalValue.h" -#include "dgDofContainer.h" - - -class binding; - - -class dgSystemOfEquations { - private: - // the mesh and the model - GModel *_gm; - dgGroupCollection _groups; - // the conservation law - dgConservationLaw *_claw; - std::string _cLawName; - // polynomial order (should be more general) - int _order; - // dimension of the problem - int _dimension; - // solution and righ hand sides - dgDofContainer *_solution; - dgDofContainer *_rightHandSide; - dgSystemOfEquations(const dgSystemOfEquations &) {} - double computeTimeStepMethodOfLines () const; -public: - const dgConservationLaw * getLaw() const {return _claw;} - const GModel * getModel() const {return _gm;} - void setOrder (int order); // set the polynomial order - void setConservationLaw (dgConservationLaw *law); // set the conservationLaw - dgSystemOfEquations(GModel *_gm); - void setup (); // setup the groups and allocate - void exportSolution (std::string filename); // export the solution - void limitSolution (); // apply the limiter on the solution - void L2Projection (const function *f); // assign the solution to a given function - double RK44(double dt); - double RK44_limiter(double dt); - double RK44_TransformNodalValue(double dt); - double RK44_TransformNodalValue_limiter(double dt); - - double ForwardEuler(double dt); - - double computeInvSpectralRadius(); - - static void registerBindings(binding *b); - - void saveSolution (std::string fileName) ; - void loadSolution (std::string fileName); - - ~dgSystemOfEquations(); -}; - -#endif // _DG_SYSTEM_OF_EQUATIONS_ - diff --git a/Solver/dgTransformNodalValue.cpp b/Solver/dgTransformNodalValue.cpp deleted file mode 100644 index c4556ba5d0230e068c4f57cac1b62acc4f8095b2..0000000000000000000000000000000000000000 --- a/Solver/dgTransformNodalValue.cpp +++ /dev/null @@ -1,62 +0,0 @@ -#include "dgTransformNodalValue.h" -#include "dgGroupOfElements.h" -#include "dgSystemOfEquations.h" -#include "function.h" - -//---------------------------------------------------------------------------------- -static double n_supra = 20; - -int dgSupraTransformNodalValue::apply ( dgDofContainer *solution) -{ - - - fullVector<double> sol = (*solution).getVector(); - for (int i=0;i< sol.size();i++){ - - if (sol(i)<0) sol(i)=-pow(- sol(i), 1/n_supra); - else sol(i)=pow( sol(i), 1/n_supra); - } - - return 1; -} - -int dgSupraTransformNodalValue::apply_Inverse ( dgDofContainer *solution) -{ - - - fullVector<double> sol = (*solution).getVector(); - for (int i=0;i< sol.size();i++){ - - if (sol(i)<0) sol(i)=-pow(- sol(i), n_supra); - else sol(i)=pow( sol(i), n_supra); - } - - return 1; -} - - -#include "Bindings.h" - -void dgTransformNodalValue::registerBindings(binding *b) { - classBinding *cb = b->addClass<dgTransformNodalValue>("dgTransformNodalValue"); - cb->setDescription("Parent class for transformations of nodal value"); - methodBinding *cm; - cm = cb->addMethod("apply",&dgTransformNodalValue::apply); - cm->setArgNames("solution",NULL); - cm->setDescription("apply a transformation of the solution"); - - cm = cb->addMethod("apply_Inverse",&dgTransformNodalValue::apply_Inverse); - cm->setArgNames("solution",NULL); - cm->setDescription("apply an inverse transformation of the solution"); -} - -void dgSupraTransformNodalValueRegisterBindings(binding *b) { - classBinding *cb = b->addClass<dgSupraTransformNodalValue>("dgSupraTransformNodalValue"); - cb->setDescription("Transformation of nodal value with the power law of superconductors"); - methodBinding *cm; - cm = cb->setConstructor<dgSupraTransformNodalValue,dgConservationLaw *>(); - cm->setDescription("exemple"); - cm->setArgNames("law",NULL); - cb->setParentClass<dgTransformNodalValue>(); -} - diff --git a/Solver/dgTransformNodalValue.h b/Solver/dgTransformNodalValue.h deleted file mode 100644 index cdc62f06debbbc52e91a9a3a1551daa195e64a06..0000000000000000000000000000000000000000 --- a/Solver/dgTransformNodalValue.h +++ /dev/null @@ -1,30 +0,0 @@ -#ifndef _DG_TRANSFORM_NODAL_VALUE_H_ -#define _DG_TRANSFORM_NODAL_VALUE_H_ - -#include "fullMatrix.h" -#include <vector> -class dgDofContainer; -class dgGroupCollection; -class dgConservationLaw; -class binding; - -class dgTransformNodalValue{ -protected: - dgConservationLaw *_claw; -public: - dgTransformNodalValue (dgConservationLaw *claw) : _claw(claw) {} - virtual int apply ( dgDofContainer *sol)=0; - virtual int apply_Inverse ( dgDofContainer *sol)=0; - static void registerBindings(binding *b); -}; - -class dgSupraTransformNodalValue : public dgTransformNodalValue{ -public : - dgSupraTransformNodalValue (dgConservationLaw *claw) : dgTransformNodalValue (claw) {} - virtual int apply ( dgDofContainer *solution); - virtual int apply_Inverse ( dgDofContainer *solution); -}; -void dgSupraTransformNodalValueRegisterBindings(binding *b); - - -#endif diff --git a/Solver/function.cpp b/Solver/function.cpp index 45b985534dbfff4596724c4d7b9857ea1ec34572..4508cdfe41642b4b3490463a30bfbe567fd11c69 100644 --- a/Solver/function.cpp +++ b/Solver/function.cpp @@ -4,8 +4,6 @@ #include "function.h" #include "SPoint3.h" #include "MElement.h" -#include "dgDofContainer.h" -#include "dgGroupOfElements.h" #include "GModel.h" #if defined(HAVE_DLOPEN) #include "dlfcn.h" @@ -308,43 +306,6 @@ class functionLua : public function { #endif -// function that enables to interpolate a DG solution using -// geometrical search in a mesh - -class functionMesh2Mesh : public function { - dgDofContainer *_dofContainer; -public: - functionMesh2Mesh(dgDofContainer *dofc) : function(dofc->getNbFields()), _dofContainer(dofc){} - void call( dataCacheMap *m, const fullMatrix<double> &xyz, fullMatrix<double> &val) { - int nP =xyz.size1(); - val.setAll(0.0); - double fs[256]; - fullMatrix<double> solEl; - GModel *model = _dofContainer->getGroups()->getModel(); - for (int i=0;i<val.size1();i++){ - const double x = xyz(i,0); - const double y = xyz(i,1); - const double z = xyz(i,2); - SPoint3 p(x,y,z); - MElement *e = model->getMeshElementByCoord(p); - int ig,index; - _dofContainer->getGroups()->find (e,ig,index); - dgGroupOfElements *group = _dofContainer->getGroups()->getElementGroup(ig); - double U[3],X[3]={x,y,z}; - e->xyz2uvw (X,U); - group->getFunctionSpace().f(U[0],U[1],U[2],fs); - fullMatrix<double> &sol = _dofContainer->getGroupProxy(ig); - solEl.setAsProxy(sol,index*val.size2(),val.size2()); - int fSize = group->getNbNodes(); - for (int k=0;k<val.size2();k++){ - val(i,k) = 0.0; - for (int j=0;j<fSize;j++){ - val(i,k) += solEl(j,k)*fs[j]; - } - } - } - } -}; void dataCacheMap::setNbEvaluationPoints(int nbEvaluationPoints) { _nbEvaluationPoints = nbEvaluationPoints; @@ -452,13 +413,6 @@ void function::registerBindings(binding *b){ mb->setArgNames("fileName","coordinateFunction",NULL); mb->setDescription("Tri-linearly interpolate through data in file 'fileName' at coordinate given by 'coordinateFunction'.\nThe file format is :\nx0 y0 z0\ndx dy dz\nnx ny nz\nv(0,0,0) v(0,0,1) v(0 0 2) ..."); - cb = b->addClass<functionMesh2Mesh>("functionMesh2Mesh"); - cb->setDescription("A function that can be used to interpolate into a given mesh"); - mb = cb->setConstructor<functionMesh2Mesh,dgDofContainer*>(); - mb->setArgNames("solution",NULL); - mb->setDescription("A solution."); - cb->setParentClass<function>(); - #if defined(HAVE_DLOPEN) cb = b->addClass<functionC>("functionC"); cb->setDescription("A function that compile a C code"); diff --git a/Solver/function.h b/Solver/function.h index 3f5f252fe80a8d94849575b15e4e55cea3ec7123..38a62b98114a8d6bc581b7d81618f497f280259c 100644 --- a/Solver/function.h +++ b/Solver/function.h @@ -10,7 +10,6 @@ class dataCacheMap; class MElement; class binding; -class dgDofContainer; // those classes manage complex function dependencies and keep their values in cache so that they are not recomputed when it is not necessary. To do this, we use three classes : function, dataCache and dataCacheMap. The workflow is : // a) while parsing the input file and during the initialisation of the conservationLaw : all user-defined instance of function are inserted in the function map. (for example an user can create a function named "wind" of the class functionMathex with parameter "0.1*sin(xyz(0)/1e6); 0" and then give the string "wind" as parameter to it's conservation law to let the law know that this is the function to use as wind forcing)