00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include <ScalarFunctionReaderMedit.hpp>
00021 #include <ScalarFunctionBase.hpp>
00022
00023 #include <ErrorHandler.hpp>
00024 #include <Mesh.hpp>
00025
00026 #include <ScalarDiscretizationTypeBase.hpp>
00027 #include <Vector.hpp>
00028 #include <FEMFunctionBase.hpp>
00029
00030 #include <FEMFunctionBuilder.hpp>
00031
00032
00033 #include <fstream>
00034
00035 ConstReferenceCounting<ScalarFunctionBase>
00036 ScalarFunctionReaderMedit::
00037 getFunction() const
00038 {
00039 std::ifstream fin(__filename.c_str());
00040 if (not(fin)) {
00041 throw ErrorHandler(__FILE__,__LINE__,
00042 "error: cannot open file '"+__filename+"'",
00043 ErrorHandler::normal);
00044 }
00045
00046 size_t a, numberOfComponents, c, numberOfVertices;
00047 fin >> a >> numberOfComponents >> numberOfVertices >> c;
00048
00049 if (__componentNumber>=numberOfComponents) {
00050 throw ErrorHandler(__FILE__,__LINE__,
00051 "The file '"+__filename+"' does only contain "
00052 +stringify(__componentNumber)+" components.\n"
00053 +"Cannot read component number "+stringify(__componentNumber),
00054 ErrorHandler::normal);
00055
00056 }
00057 const Mesh& mesh = (*__mesh);
00058
00059 if ((a!=3)or(c!=2)) {
00060 throw ErrorHandler(__FILE__,__LINE__,
00061 "Unknown file descriptor while reading file '"+__filename+"'",
00062 ErrorHandler::normal);
00063 }
00064
00065 if (numberOfVertices != mesh.numberOfVertices()) {
00066 throw ErrorHandler(__FILE__,__LINE__,
00067 "Number of vertices does not match mesh while reading '"
00068 +__filename+"'",
00069 ErrorHandler::normal);
00070 }
00071
00072 Vector<real_t> v(numberOfVertices);
00073 Vector<real_t> componentValue(numberOfComponents);
00074 for (size_t i=0; i<numberOfVertices; ++i) {
00075 for (size_t j=0; j<numberOfComponents; ++j) {
00076 fin >> componentValue[j];
00077 }
00078 v[i] = componentValue[__componentNumber];
00079 }
00080
00081 if (fin.bad()) {
00082 throw ErrorHandler(__FILE__,__LINE__,
00083 "cannot read all datas in file '"+__filename+"'",
00084 ErrorHandler::normal);
00085 }
00086
00087 FEMFunctionBuilder builder;
00088 ScalarDiscretizationTypeFEM d(ScalarDiscretizationTypeBase::lagrangianFEM1);
00089 builder.build(d, __mesh, v);
00090 return builder.getBuiltScalarFunction();
00091 }
00092
00093 ScalarFunctionReaderMedit::
00094 ScalarFunctionReaderMedit(const std::string& filename,
00095 ConstReferenceCounting<Mesh> mesh,
00096 const std::string& functionName,
00097 const int& componentNumber)
00098 : ScalarFunctionReaderBase(filename, mesh, functionName, componentNumber)
00099 {
00100 ;
00101 }
00102
00103 ScalarFunctionReaderMedit::
00104 ScalarFunctionReaderMedit(const ScalarFunctionReaderMedit& f)
00105 : ScalarFunctionReaderBase(f)
00106 {
00107 ;
00108 }
00109
00110 ScalarFunctionReaderMedit::
00111 ~ScalarFunctionReaderMedit()
00112 {
00113 ;
00114 }