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>
62 int 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;
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;
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;
195 CHK_ERR( load_elem_data(matrixGraph.
get(), mat.
get(), rhsVec.
get(), poissonData) );
197 CHK_ERR( load_BC_data(linSys.
get(), poissonData) );
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;
237 int lenNodeIDs = numNodes;
238 GlobalID* nodeIDs =
new GlobalID[lenNodeIDs];
239 double* soln =
new double[lenNodeIDs];
240 if (nodeIDs != NULL && soln != NULL) {
242 nodeIDs, lenNodeIDs) );
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.)"
virtual void setMatrix(fei::SharedPtr< fei::Matrix > &matrix)
virtual fei::SharedPtr< fei::Solver > createSolver(const char *name=0)=0
virtual void setParameters(const fei::ParameterSet ¶ms)=0
void strings_to_char_ptrs(std::vector< std::string > &stdstrings, int &numStrings, const char **&charPtrs)
fei::SharedPtr< fei::Factory > create_fei_Factory(MPI_Comm comm, const char *libraryName)
virtual int parameters(int numParams, const char *const *paramStrings)=0
virtual void parameters(const fei::ParameterSet ¶mset)
virtual int copyOutFieldData(int fieldID, int idType, int numIDs, const int *IDs, double *data, int vectorIndex=0)=0
virtual void setSolutionVector(fei::SharedPtr< fei::Vector > &soln)
virtual fei::SharedPtr< fei::LinearSystem > createLinearSystem(fei::SharedPtr< fei::MatrixGraph > &matrixGraph)
void defineFields(int numFields, const int *fieldIDs, const int *fieldSizes, const int *fieldTypes=NULL)
virtual void setRHS(fei::SharedPtr< fei::Vector > &rhs)
virtual int scatterToOverlap()=0
virtual int loadComplete(bool applyBCs=true, bool globalAssemble=true)=0
virtual fei::SharedPtr< VectorSpace > createVectorSpace(MPI_Comm, const char *name)
int getStringParamValue(const char *name, std::string ¶mValue) const
double get_file_benchmark(const char *filename, const char *testname)
int get_filename_and_read_input(int argc, char **argv, MPI_Comm comm, int localProc, std::vector< std::string > &stdstrings)
virtual int initComplete()=0
int getOwnedAndSharedIDs(int idtype, int lenList, int *IDs, int &numOwnedAndSharedIDs)
void defineIDTypes(int numIDTypes, const int *idTypes)
virtual fei::SharedPtr< fei::Vector > createVector(fei::SharedPtr< fei::VectorSpace > vecSpace, int numVectors=1)=0
std::ostream & console_out()
void parse_strings(std::vector< std::string > &stdstrings, const char *separator_string, fei::ParameterSet ¶mset)
int getNumOwnedAndSharedIDs(int idType)
virtual int solve(fei::LinearSystem *linearSystem, fei::Matrix *preconditioningMatrix, const fei::ParameterSet ¶meterSet, int &iterationsTaken, int &status)
virtual fei::SharedPtr< fei::Matrix > createMatrix(fei::SharedPtr< fei::MatrixGraph > matrixGraph)=0
virtual fei::SharedPtr< fei::MatrixGraph > createMatrixGraph(fei::SharedPtr< fei::VectorSpace > rowSpace, fei::SharedPtr< fei::VectorSpace > columnSpace, const char *name)=0
int getIntParamValue(const char *name, int ¶mValue) const