27 #include <fei_iostream.hpp>
29 #include <fei_base.hpp>
30 #include <FEI_Implementation.hpp>
35 #include <test_utils/LibraryFactory.hpp>
36 #include <fei_LibraryWrapper.hpp>
41 #include <test_utils/Poisson_Elem.hpp>
42 #include <test_utils/PoissonData.hpp>
44 #include <test_utils/ElemBlock.hpp>
45 #include <test_utils/CRSet.hpp>
46 #include <test_utils/CommNodeSet.hpp>
47 #include <test_utils/DataReader.hpp>
49 #include <test_utils/SolnCheck.hpp>
51 #include <test_utils/fei_test_utils.hpp>
52 #include <snl_fei_Utils.hpp>
57 #define fei_file "poisson_main.cpp"
58 #include <fei_ErrMacros.hpp>
63 int poisson_main(
int argc,
char** argv,
64 MPI_Comm comm,
int numProcs,
int localProc){
66 int masterProc = 0, err = 0;
70 std::vector<std::string> stdstrings;
74 const char** params = NULL;
81 std::string which_fei;
82 std::string solverName;
91 fei::console_out() <<
"Failed to find one or more required parameters in input-file."
92 << FEI_ENDL <<
"Required parameters:"<<FEI_ENDL
93 <<
"SOLVER_LIBRARY" << FEI_ENDL
94 <<
"WHICH_FEI" << FEI_ENDL
100 int nodes = (L+1)*(L+1);
102 FEI_COUT << FEI_ENDL;
103 FEI_COUT <<
"========================================================"
105 FEI_COUT <<
"Square size L: " << L <<
" elements." << FEI_ENDL;
106 FEI_COUT <<
"Global number of elements: " << L*L << FEI_ENDL;
107 FEI_COUT <<
"Global number of nodes: " << nodes << FEI_ENDL;
108 FEI_COUT <<
"Global number of equations: " << eqns <<FEI_ENDL;
109 FEI_COUT <<
"========================================================"
113 outputLevel = fei_test_utils::whichArg(numParams, params,
"outputLevel 1");
114 if (outputLevel >= 0) outputLevel = 1;
115 if (outputLevel < 0) outputLevel = 0;
117 if ((masterProc == localProc)&&(outputLevel>0)) {
118 fei_test_utils::print_args(argc, argv);
121 if (outputLevel == 1) {
122 if (localProc != 0) outputLevel = 0;
128 PoissonData poissonData(L, numProcs, localProc, outputLevel);
136 if (which_fei ==
"OLDFEI") {
140 catch (std::runtime_error& exc) {
146 else if (which_fei ==
"fei::FEI_Impl") {
150 catch (std::runtime_error& exc) {
157 fei::console_out() <<
"poisson_main ERROR, value of 'WHICH_FEI' must be 'OLDFEI' or 'fei::FEI_Impl'"<< FEI_ENDL;
161 const char* feiVersionString;
162 CHK_ERR( fei->
version(feiVersionString) );
164 if (localProc==0) FEI_COUT << feiVersionString << FEI_ENDL;
167 CHK_ERR( fei->
parameters( numParams, params ) );
171 if (outputLevel>0 && localProc==0) FEI_COUT <<
"setSolveType" << FEI_ENDL;
175 int numFields = poissonData.getNumFields();
176 int* fieldSizes = poissonData.getFieldSizes();
177 int* fieldIDs = poissonData.getFieldIDs();
179 if (outputLevel>0 && localProc==0) FEI_COUT <<
"initFields" << FEI_ENDL;
180 CHK_ERR( fei->
initFields( numFields, fieldSizes, fieldIDs ) );
183 CHK_ERR( init_elem_connectivities(fei.
get(), poissonData) );
185 CHK_ERR( set_shared_nodes(fei.
get(), poissonData) );
188 FEI_COUT.setf(IOS_FIXED, IOS_FLOATFIELD);
190 if (outputLevel>0 && localProc==0) FEI_COUT <<
"initComplete" << FEI_ENDL;
203 CHK_ERR( load_elem_data(fei.
get(), poissonData) );
205 CHK_ERR( load_BC_data(fei.
get(), poissonData) );
214 if (outputLevel>0 && localProc==0) FEI_COUT <<
"solve..." << FEI_ENDL;
216 err = fei->
solve(status);
218 if (localProc==0) FEI_COUT <<
"solve returned err: " << err << FEI_ENDL;
221 double iTime, lTime, sTime, rTime;
226 if (localProc == 0) {
227 FEI_COUT <<
"FEI cpu-times:" << FEI_ENDL
228 <<
" init. phase: " << iTime << FEI_ENDL
229 <<
" load phase: " << lTime << FEI_ENDL
230 <<
" solve time: " << sTime << FEI_ENDL;
234 FEI_COUT.setf(IOS_SCIENTIFIC, IOS_FLOATFIELD);
235 CHK_ERR( fei->
residualNorm(1, 1, &fieldIDs[0], &norm) );
236 if (localProc == 0) {
237 FEI_COUT <<
"returned residual norm: " << norm << FEI_ENDL;
252 int lenNodeIDs = numNodes;
253 GlobalID* nodeIDs =
new GlobalID[lenNodeIDs];
254 double* soln =
new double[lenNodeIDs];
255 if (nodeIDs != NULL && soln != NULL) {
261 for(
int i=0; i<numNodes; i++) {
262 int nID = (int)nodeIDs[i];
263 double x = (1.0* ((nID-1)%(L+1)))/L;
264 double y = (1.0* ((nID-1)/(L+1)))/L;
266 double exactSoln = x*x + y*y;
267 double error = std::abs(exactSoln - soln[i]);
268 if (maxErr < error) maxErr = error;
281 double globalMaxErr = 0.0;
282 MPI_Allreduce(&maxErr, &globalMaxErr, 1, MPI_DOUBLE, MPI_MAX, comm);
283 maxErr = globalMaxErr;
285 bool testPassed =
true;
286 if (maxErr > 1.e-6) testPassed =
false;
288 if (testPassed && localProc == 0) {
289 FEI_COUT <<
"poisson: TEST PASSED, maxErr = " << maxErr <<
", iterations: "
290 << itersTaken << FEI_ENDL;
292 FEI_COUT <<
"SIERRA execution successful" << FEI_ENDL;
294 if (testPassed ==
false && localProc == 0) {
295 FEI_COUT <<
"maxErr = " << maxErr <<
", TEST FAILED" << FEI_ENDL;
296 FEI_COUT <<
"(Test is deemed to have passed if the maximum difference"
297 <<
" between the exact and computed solutions is 1.e-6 or less.)"
304 FEI_COUT.setf(IOS_FIXED, IOS_FLOATFIELD);
306 FEI_COUT <<
"Proc0 cpu times (seconds):" << FEI_ENDL
307 <<
" FEI initialize: " << fei_init_time << FEI_ENDL
308 <<
" FEI load: " << fei_load_time << FEI_ENDL
309 <<
" solve: " << solve_time << FEI_ENDL
310 <<
"Total program time: " << elapsed_cpu_time << FEI_ENDL;
void strings_to_char_ptrs(std::vector< std::string > &stdstrings, int &numStrings, const char **&charPtrs)
virtual int parameters(int numParams, const char *const *paramStrings)=0
virtual int initComplete()=0
fei::SharedPtr< fei::Factory > create_fei_Factory(MPI_Comm comm, const char *libraryName)
virtual int solve(int &status)=0
virtual int getNodalFieldSolution(int fieldID, int numNodes, const GlobalID *nodeIDs, double *results)=0
virtual int getNumLocalNodes(int &numNodes)=0
virtual int version(const char *&versionString)=0
int getStringParamValue(const char *name, std::string ¶mValue) const
int get_filename_and_read_input(int argc, char **argv, MPI_Comm comm, int localProc, std::vector< std::string > &stdstrings)
virtual int initFields(int numFields, const int *fieldSizes, const int *fieldIDs, const int *fieldTypes=NULL)=0
virtual int setSolveType(int solveType)=0
std::ostream & console_out()
void parse_strings(std::vector< std::string > &stdstrings, const char *separator_string, fei::ParameterSet ¶mset)
virtual int residualNorm(int whichNorm, int numFields, int *fieldIDs, double *norms)=0
virtual int iterations(int &itersTaken) const =0
virtual fei::SharedPtr< FEI > createFEI(fei::SharedPtr< LibraryWrapper > wrapper, MPI_Comm comm)
virtual int getLocalNodeIDList(int &numNodes, GlobalID *nodeIDs, int lenNodeIDs)=0
fei::SharedPtr< LibraryWrapper > create_LibraryWrapper(MPI_Comm comm, const char *libraryName)
virtual int cumulative_cpu_times(double &initPhase, double &loadPhase, double &solve, double &solnReturn)=0
int getIntParamValue(const char *name, int ¶mValue) const