G+Smo  25.01.0
Geometry + Simulation Modules
 
Loading...
Searching...
No Matches
heatEquation_example.cpp

Annotated source file

Here is the full file examples/heatEquation_example.cpp. Clicking on a function or class name will lead you to its reference documentation.

#include <gismo.h>
using namespace gismo;
int main(int argc, char *argv[])
{
bool plot = false;
gsCmdLine cmd("Testing the heat equation.");
cmd.addSwitch("plot", "Plot the result in ParaView.", plot);
try { cmd.getValues(argc,argv); } catch (int rv) { return rv; }
// Source function
gsInfo<<"Source function is: "<< f << "\n";
// Define Geometry, must be a gsMultiPatch object
patches.computeTopology();
// Boundary conditions
gsConstantFunction<> g_N(1,2); // Neumann
gsConstantFunction<> g_D(0,2); // (Dirichlet
bcInfo.addCondition(0, boundary::west, condition_type::neumann , &g_N);
bcInfo.addCondition(0, boundary::east, condition_type::dirichlet, &g_D);
bcInfo.addCondition(0, boundary::north, condition_type::dirichlet, &g_D);
bcInfo.addCondition(0, boundary::south, condition_type::dirichlet, &g_D);
gsMultiBasis<> refine_bases( patches );
// Number for h-refinement of the computational (trial/test) basis.
int numRefine = 2;
// Number for p-refinement of the computational (trial/test) basis.
int numElevate = 0;
// Elevate and p-refine the basis to order k + numElevate
// where k is the highest degree in the bases
if ( numElevate > -1 )
{
// Find maximum degree with respect to all the variables
int tmp = refine_bases.maxDegree(0);
for (short_t j = 1; j < patches.parDim(); ++j )
if ( tmp < refine_bases.maxDegree(j) )
tmp = refine_bases.maxDegree(j);
// Elevate all degrees uniformly
tmp += numElevate;
refine_bases.setDegree(tmp);
}
// h-refine the basis
for (int i = 0; i < numRefine; ++i)
refine_bases.uniformRefine();
// Determines the theta-scheme used for time integration
// (eg. Forward/backward Euler or Crank Nicolson(theta=0.5)
real_t theta = 0.5;
gsPoissonPde<> pde(patches, bcInfo, f);
// Assembler (constructs stationary matrix and right-hand side vector)
gsPoissonAssembler<> stationary(pde, refine_bases);
stationary.options().setInt("DirichletStrategy", dirichlet::elimination);
stationary.options().setInt("InterfaceStrategy", iFace::glue);
gsHeatEquation<real_t> assembler(stationary);
assembler.setTheta(theta);
gsInfo<<assembler.options()<<"\n";
// A Conjugate Gradient linear solver with a diagonal (Jacobi) preconditionner
gsSparseSolver<>::CGDiagonal solver;
// Generate system matrix and load vector
gsInfo<<"Assembling mass and stiffness...\n";
assembler.assemble();
gsMatrix<> Sol, Rhs;
int ndof = assembler.numDofs();
real_t endTime = 0.1;
int numSteps = 40;
Sol.setZero(ndof, 1); // Initial solution
real_t Dt = endTime / numSteps ;
const std::string baseName("heat_eq_solution");
gsParaviewCollection collection(baseName);
collection.options().setInt("numPoints", 1000);
collection.options().setInt("precision", 5);
if ( plot )
{
//sol = assembler.constructSolution(Sol); // same as next line
gsField<> sol = stationary.constructSolution(Sol);
collection.newTimeStep(&patches);
collection.addField(sol, "Temperature");
collection.saveTimeStep();
}
for ( int i = 1; i<=numSteps; ++i) // for all timesteps
{
// Compute the system for the timestep i (rhs is assumed constant wrt time)
assembler.nextTimeStep(Sol, Dt);
gsInfo<<"Solving timestep "<< i*Dt<<".\n";
// Solve for current timestep, overwrite previous solution
Sol = solver.compute( assembler.matrix() ).solve( assembler.rhs() );
// Obtain current solution as an isogeometric field
//sol = assembler.constructSolution(Sol); // same as next line
gsField<> sol = stationary.constructSolution(Sol);
if ( plot )
{
// Plot the snapshot to paraview
collection.newTimeStep(&patches);
collection.addField(sol, "Temperature");
collection.saveTimeStep();
}
}
//gsInfo<< " time = "<<endTime<<"\n";
if ( plot )
{
collection.save();
gsFileManager::open("heat_eq_solution.pvd");
}
else
gsInfo << "Done. No output created, re-run with --plot to get a ParaView "
"file containing the solution.\n";
return EXIT_SUCCESS;
}
Class containing a set of boundary conditions.
Definition gsBoundaryConditions.h:342
void addCondition(int p, boxSide s, condition_type::type t, gsFunctionSet< T > *f, short_t unknown=0, bool parametric=false, int comp=-1)
Adds another boundary condition.
Definition gsBoundaryConditions.h:650
Class for command-line argument parsing.
Definition gsCmdLine.h:57
Class defining a globally constant function.
Definition gsConstantFunction.h:34
A scalar of vector field defined on a m_parametric geometry.
Definition gsField.h:55
static void open(const std::string &fn)
Opens the file fn using the preferred application of the OS.
Definition gsFileManager.cpp:688
Constructs the assembler for the discretized isogeometric heat equation.
Definition gsHeatEquation.h:34
A matrix with arbitrary coefficient type and fixed or dynamic size.
Definition gsMatrix.h:41
Holds a set of patch-wise bases and their topology information.
Definition gsMultiBasis.h:37
Container class for a set of geometry patches and their topology, that is, the interface connections ...
Definition gsMultiPatch.h:100
This class is used to create a Paraview .pvd (collection) file.
Definition gsParaviewCollection.h:77
Implementation of an (multiple right-hand side) Poisson assembler.
Definition gsPoissonAssembler.h:37
A Poisson PDE.
Definition gsPoissonPde.h:35
Main header to be included by clients using the G+Smo library.
#define short_t
Definition gsConfig.h:35
#define gsInfo
Definition gsDebug.h:43
The G+Smo namespace, containing all definitions for the library.
@ dirichlet
Dirichlet type.
Definition gsBoundaryConditions.h:31
@ neumann
Neumann type.
Definition gsBoundaryConditions.h:33
Class gsNurbsCreator provides some simple examples of Nurbs Geometries.
Definition gsNurbsCreator.h:37