26#include <fei_iostream.hpp>
32#include <fei_base.hpp>
37#include <test_utils/LibraryFactory.hpp>
42#include <test_utils/Poisson_Elem.hpp>
43#include <test_utils/PoissonData.hpp>
45#include <test_utils/ElemBlock.hpp>
46#include <test_utils/CRSet.hpp>
47#include <test_utils/CommNodeSet.hpp>
48#include <test_utils/DataReader.hpp>
50#include <test_utils/SolnCheck.hpp>
51#include <test_utils/fei_test_utils.hpp>
52#include <snl_fei_Utils.hpp>
56#include <fei_ErrMacros.hpp>
62int poisson3_main(
int argc,
char** argv,
63 MPI_Comm comm,
int numProcs,
int localProc){
68 std::vector<std::string> stdstrings;
72 const char** params = NULL;
79 std::string solverName;
89 fei::console_out() <<
"Failed to find one or more required parameters in input-file."
90 << FEI_ENDL <<
"Required parameters:"<<FEI_ENDL
91 <<
"SOLVER_LIBRARY" << FEI_ENDL
97 int nodes = (L+1)*(L+1);
100 FEI_COUT <<
"========================================================"
103 FEI_COUT <<
"Square size L: " << L <<
" elements." << FEI_ENDL;
104 FEI_COUT <<
"Global number of elements: " << L*L << FEI_ENDL;
105 FEI_COUT <<
"Global number of nodes: " << nodes << FEI_ENDL;
106 FEI_COUT <<
"Global number of equations: " << eqns <<FEI_ENDL;
107 FEI_COUT <<
"========================================================"
111 if ((masterProc == localProc)&&(outputLevel>0)) {
112 fei_test_utils::print_args(argc, argv);
115 if (outputLevel == 1) {
116 if (localProc != 0) outputLevel = 0;
122 PoissonData poissonData(L, numProcs, localProc, outputLevel);
131 FEI_COUT <<
"library " << solverName <<
" not available."<<FEI_ENDL;
135 if (factory.
get() == NULL) {
136 FEI_COUT <<
"snl_fei::Factory creation failed." << FEI_ENDL;
140 factory->parameters(paramset);
143 factory->createVectorSpace(comm,
"poisson3");
147 factory->createMatrixGraph(nodeSpace, dummy,
"poisson3");
150 matrixGraph->setParameters(paramset);
153 int numFields = poissonData.getNumFields();
154 int* fieldSizes = poissonData.getFieldSizes();
155 int* fieldIDs = poissonData.getFieldIDs();
158 if (outputLevel>0 && localProc==0) FEI_COUT <<
"defineFields" << FEI_ENDL;
159 nodeSpace->defineFields( numFields, fieldIDs, fieldSizes );
161 if (outputLevel>0 && localProc==0) FEI_COUT <<
"defineIDTypes" << FEI_ENDL;
162 nodeSpace->defineIDTypes( 1, &nodeIDType );
164 CHK_ERR( init_elem_connectivities(matrixGraph.
get(), poissonData) );
166 CHK_ERR( set_shared_nodes(nodeSpace.
get(), poissonData) );
170 FEI_COUT.setf(IOS_FIXED, IOS_FLOATFIELD);
171 if (outputLevel>0 && localProc==0) FEI_COUT <<
"initComplete" << FEI_ENDL;
172 CHK_ERR( matrixGraph->initComplete() );
190 linSys->setMatrix(mat);
191 linSys->setSolutionVector(solnVec);
192 linSys->setRHS(rhsVec);
194 CHK_ERR( linSys->parameters(paramset));
195 CHK_ERR( load_elem_data(matrixGraph.
get(), mat.
get(), rhsVec.
get(), poissonData) );
197 CHK_ERR( load_BC_data(linSys.
get(), poissonData) );
199 CHK_ERR( linSys->loadComplete() );
213 if (outputLevel>0 && localProc==0) FEI_COUT <<
"solve..." << FEI_ENDL;
216 int err = solver->solve(linSys.
get(),
218 paramset, itersTaken, status);
223 if (localProc==0) FEI_COUT <<
"solve returned err: " << err <<
", status: "
224 << status << FEI_ENDL;
227 CHK_ERR( solnVec->scatterToOverlap() );
233 int numNodes = nodeSpace->getNumOwnedAndSharedIDs(nodeIDType);
237 int lenNodeIDs = numNodes;
238 GlobalID* nodeIDs =
new GlobalID[lenNodeIDs];
239 double* soln =
new double[lenNodeIDs];
240 if (nodeIDs != NULL && soln != NULL) {
241 CHK_ERR( nodeSpace->getOwnedAndSharedIDs(nodeIDType, numNodes,
242 nodeIDs, lenNodeIDs) );
245 CHK_ERR( solnVec->copyOutFieldData(fieldID, nodeIDType,
246 numNodes, nodeIDs, soln));
248 for(
int i=0; i<numNodes; i++) {
249 int nID = (int)nodeIDs[i];
250 double x = (1.0* ((nID-1)%(L+1)))/L;
251 double y = (1.0* ((nID-1)/(L+1)))/L;
253 double exactSoln = x*x + y*y;
254 double error = std::abs(exactSoln - soln[i]);
255 if (maxErr < error) maxErr = error;
268 double globalMaxErr = 0.0;
269 MPI_Allreduce(&maxErr, &globalMaxErr, 1, MPI_DOUBLE, MPI_MAX, comm);
270 maxErr = globalMaxErr;
272 bool testPassed =
true;
273 if (maxErr > 1.e-6) testPassed =
false;
279 FEI_COUT.setf(IOS_FIXED, IOS_FLOATFIELD);
281 FEI_COUT <<
"Proc0 cpu times (seconds):" << FEI_ENDL
282 <<
" FEI initialize: " << fei_init_time << FEI_ENDL
283 <<
" FEI load: " << fei_load_time << FEI_ENDL
284 <<
" solve: " << solve_time << FEI_ENDL
285 <<
"Total program time: " << elapsed_cpu_time << FEI_ENDL;
287#if defined(FEI_PLATFORM) && defined(FEI_OPT_LEVEL)
288 double benchmark = fei_init_time+fei_load_time;
289 FEI_OSTRINGSTREAM testname;
290 testname <<
"poisson3_"<<L<<
"_"<<solverName<<
"_np"<<
numProcs<<
"_"
291 <<FEI_PLATFORM<<
"_"<<FEI_OPT_LEVEL;
293 double file_value = 0.0;
294 bool file_value_available =
true;
297 testname.str().c_str());
299 catch(std::runtime_error& exc) {
300 file_value_available =
false;
303 if (file_value_available) {
304 bool test_passed = fei_test_utils::check_and_cout_test_result(testname.str(),
307 returnValue = test_passed ? 0 : 1;
313 if (testPassed && returnValue==0 && localProc == 0) {
314 FEI_COUT.setf(IOS_SCIENTIFIC, IOS_FLOATFIELD);
315 FEI_COUT <<
"poisson: TEST PASSED, maxErr = " << maxErr <<
", iterations: "
316 << itersTaken << FEI_ENDL;
318 FEI_COUT <<
"SIERRA execution successful" << FEI_ENDL;
320 if ((testPassed ==
false || returnValue != 0) && localProc == 0) {
321 if (testPassed==
true) {
322 FEI_COUT <<
"maxErr = " << maxErr <<
", but time-taken outside margin. TEST FAILED" << FEI_ENDL;
325 FEI_COUT <<
"maxErr = " << maxErr <<
", TEST FAILED"<<FEI_ENDL;
327 FEI_COUT <<
"(Test is deemed to have passed if the maximum difference"
328 <<
" between the exact and computed solutions is 1.e-6 or less, *AND*"
329 <<
" time-taken matches file-benchmark if available.)"
int getIntParamValue(const char *name, int ¶mValue) const
int getStringParamValue(const char *name, std::string ¶mValue) const
void parse_strings(std::vector< std::string > &stdstrings, const char *separator_string, fei::ParameterSet ¶mset)
void strings_to_char_ptrs(std::vector< std::string > &stdstrings, int &numStrings, const char **&charPtrs)
int get_filename_and_read_input(int argc, char **argv, MPI_Comm comm, int localProc, std::vector< std::string > &stdstrings)
double get_file_benchmark(const char *filename, const char *testname)
fei::SharedPtr< fei::Factory > create_fei_Factory(MPI_Comm comm, const char *libraryName)
std::ostream & console_out()
int numProcs(MPI_Comm comm)