1 |
/******************************************************* |
2 |
* |
3 |
* Copyright 2007 by University of Queensland |
4 |
* |
5 |
* http://esscc.uq.edu.au |
6 |
* Primary Business: Queensland, Australia |
7 |
* Licensed under the Open Software License version 3.0 |
8 |
* http://www.opensource.org/licenses/osl-3.0.php |
9 |
* |
10 |
*******************************************************/ |
11 |
|
12 |
#ifdef PASO_MPI |
13 |
#include <mpi.h> |
14 |
#endif |
15 |
#include "TransportProblemAdapter.h" |
16 |
#include "SystemMatrixAdapter.h" |
17 |
|
18 |
using namespace std; |
19 |
|
20 |
namespace finley { |
21 |
|
22 |
struct null_deleter |
23 |
{ |
24 |
void operator()(void const *ptr) const |
25 |
{ |
26 |
} |
27 |
}; |
28 |
|
29 |
|
30 |
TransportProblemAdapter::TransportProblemAdapter() |
31 |
{ |
32 |
throw FinleyAdapterException("Error - Illegal to generate default TransportProblemAdapter."); |
33 |
} |
34 |
|
35 |
|
36 |
TransportProblemAdapter::TransportProblemAdapter(Paso_FCTransportProblem* transport_problem, |
37 |
const double theta, |
38 |
const double dt_max, |
39 |
const int block_size, |
40 |
const escript::FunctionSpace& functionspace): |
41 |
AbstractTransportProblem(theta, dt_max, block_size, functionspace) |
42 |
{ |
43 |
m_transport_problem.reset(transport_problem,null_deleter()); |
44 |
} |
45 |
|
46 |
TransportProblemAdapter::~TransportProblemAdapter() |
47 |
{ |
48 |
if (m_transport_problem.unique()) { |
49 |
Paso_FCTransportProblem* transp=m_transport_problem.get(); |
50 |
Paso_FCTransportProblem_free(transp); |
51 |
} |
52 |
} |
53 |
|
54 |
Paso_FCTransportProblem* TransportProblemAdapter::getPaso_FCTransportProblem() const |
55 |
{ |
56 |
return m_transport_problem.get(); |
57 |
} |
58 |
|
59 |
|
60 |
void TransportProblemAdapter::setToSolution(escript::Data& out, escript::Data& source, const double dt, const boost::python::dict& options) const |
61 |
{ |
62 |
Paso_FCTransportProblem* transp=getPaso_FCTransportProblem(); |
63 |
Paso_Options paso_options; |
64 |
SystemMatrixAdapter::dictToPasoOptions(&paso_options,options); |
65 |
if ( out.getDataPointSize() != getBlockSize()) { |
66 |
throw FinleyAdapterException("solve : block size of solution does not match block size of transport problems."); |
67 |
} else if ( source.getDataPointSize() != getBlockSize()) { |
68 |
throw FinleyAdapterException("solve : block size of source term does not match block size of transport problems."); |
69 |
} else if ( out.getFunctionSpace() != getFunctionSpace()) { |
70 |
throw FinleyAdapterException("solve : function spaces of solution and of transport problem don't match."); |
71 |
} else if (source.getFunctionSpace() != getFunctionSpace()) { |
72 |
throw FinleyAdapterException("solve : function spaces of source term and of transport problem don't match."); |
73 |
} else if (dt<=0.) { |
74 |
throw FinleyAdapterException("solve : time increment dt needs to be positive."); |
75 |
} |
76 |
out.expand(); |
77 |
source.expand(); |
78 |
double* out_dp=out.getSampleData(0); |
79 |
double* source_dp=source.getSampleData(0); |
80 |
Paso_SolverFCT_solve(transp,out_dp,dt,source_dp,&paso_options); |
81 |
checkPasoError(); |
82 |
} |
83 |
|
84 |
void TransportProblemAdapter::resetTransport() const |
85 |
{ |
86 |
Paso_FCTransportProblem* transp = getPaso_FCTransportProblem(); |
87 |
throw FinleyAdapterException("resetTransport() not implemented yet."); |
88 |
// |
89 |
// |
90 |
// Paso_FCTransportProblem_setValues(transp,0.); |
91 |
// Paso_solve_free(transp); |
92 |
checkPasoError(); |
93 |
} |
94 |
|
95 |
void TransportProblemAdapter::copyInitialValue(escript::Data& u) const |
96 |
{ |
97 |
Paso_FCTransportProblem* transp=getPaso_FCTransportProblem(); |
98 |
if ( u.getDataPointSize() != getBlockSize()) { |
99 |
throw FinleyAdapterException("copyInitialValue : block size of solution does not match block size of transport problems."); |
100 |
} else if ( u.getFunctionSpace() != getFunctionSpace()) { |
101 |
throw FinleyAdapterException("copyInitialValue : function spaces of solution and of transport problem don't match."); |
102 |
} |
103 |
u.expand(); |
104 |
double* u_dp=u.getSampleData(0); |
105 |
Paso_FCTransportProblem_checkinSolution( transp,u_dp); |
106 |
checkPasoError(); |
107 |
} |
108 |
|
109 |
|
110 |
} // end of namespace |